From d0d9683df8398696147e7ee1fcffb2e4e957008c Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sat, 4 Apr 2020 14:39:19 -0700 Subject: Remove vendored dependencies While it appears that by now we actually can get successful builds without Cargo insisting on Internet access by virtue of using the --frozen flag, maintaining vendored dependencies is somewhat of a pain point. This state will also get worse with upcoming changes that replace argparse in favor of structopt and pull in a slew of new dependencies by doing so. Then there is also the repository structure aspect, which is non-standard due to the way we vendor dependencies and a potential source of confusion. In order to fix these problems, this change removes all the vendored dependencies we have. Delete subrepo argparse/:argparse Delete subrepo base32/:base32 Delete subrepo cc/:cc Delete subrepo cfg-if/:cfg-if Delete subrepo getrandom/:getrandom Delete subrepo lazy-static/:lazy-static Delete subrepo libc/:libc Delete subrepo nitrokey-sys/:nitrokey-sys Delete subrepo nitrokey/:nitrokey Delete subrepo rand/:rand --- argparse/.gitignore | 13 - argparse/.travis.yml | 34 - argparse/Cargo.toml | 12 - argparse/LICENSE | 19 - argparse/README.rst | 341 -- argparse/bulk.yaml | 11 - argparse/examples/greeting.rs | 26 - argparse/examples/structure.rs | 38 - argparse/examples/subcommands.rs | 88 - argparse/src/action.rs | 33 - argparse/src/bool.rs | 22 - argparse/src/custom.rs | 95 - argparse/src/from_cli.rs | 100 - argparse/src/generic.rs | 133 - argparse/src/help.rs | 93 - argparse/src/lib.rs | 64 - argparse/src/num.rs | 58 - argparse/src/parser.rs | 967 ----- argparse/src/print.rs | 13 - argparse/src/test_bool.rs | 98 - argparse/src/test_const.rs | 28 - argparse/src/test_enum.rs | 51 - argparse/src/test_env.rs | 43 - argparse/src/test_float.rs | 50 - argparse/src/test_help.rs | 154 - argparse/src/test_int.rs | 107 - argparse/src/test_many.rs | 95 - argparse/src/test_optional.rs | 54 - argparse/src/test_parser.rs | 64 - argparse/src/test_path.rs | 30 - argparse/src/test_pos.rs | 196 - argparse/src/test_str.rs | 28 - argparse/src/test_usage.rs | 57 - argparse/vagga.yaml | 59 - base32/.gitignore | 2 - base32/.travis.yml | 1 - base32/Cargo.toml | 16 - base32/LICENSE-APACHE | 202 - base32/LICENSE-MIT | 19 - base32/README.md | 35 - base32/src/lib.rs | 221 - cc/.github/workflows/main.yml | 124 - cc/.gitignore | 4 - cc/Cargo.toml | 28 - cc/LICENSE-APACHE | 201 - cc/LICENSE-MIT | 25 - cc/README.md | 194 - cc/cc-test/Cargo.toml | 16 - cc/cc-test/build.rs | 88 - cc/cc-test/src/NMakefile | 14 - cc/cc-test/src/aarch64.S | 10 - cc/cc-test/src/bar1.c | 7 - cc/cc-test/src/bar2.c | 6 - cc/cc-test/src/baz.cpp | 9 - cc/cc-test/src/expand.c | 4 - cc/cc-test/src/foo.c | 9 - cc/cc-test/src/i686.S | 9 - cc/cc-test/src/i686.asm | 9 - cc/cc-test/src/include/foo.h | 0 cc/cc-test/src/lib.rs | 16 - cc/cc-test/src/msvc.c | 7 - cc/cc-test/src/opt_linkage.c | 5 - cc/cc-test/src/windows.c | 3 - cc/cc-test/src/x86_64.S | 9 - cc/cc-test/src/x86_64.asm | 8 - cc/cc-test/tests/all.rs | 58 - cc/src/bin/gcc-shim.rs | 48 - cc/src/com.rs | 155 - cc/src/lib.rs | 2666 ------------ cc/src/registry.rs | 204 - cc/src/setup_config.rs | 283 -- cc/src/winapi.rs | 218 - cc/src/windows_registry.rs | 754 ---- cc/tests/cc_env.rs | 118 - cc/tests/cflags.rs | 15 - cc/tests/cxxflags.rs | 15 - cc/tests/support/mod.rs | 161 - cc/tests/test.rs | 377 -- cfg-if/.github/workflows/main.yml | 53 - cfg-if/.gitignore | 2 - cfg-if/Cargo.toml | 25 - cfg-if/LICENSE-APACHE | 201 - cfg-if/LICENSE-MIT | 25 - cfg-if/README.md | 47 - cfg-if/src/lib.rs | 176 - cfg-if/tests/xcrate.rs | 14 - getrandom/.cargo/config | 5 - getrandom/.gitignore | 6 - getrandom/.travis.yml | 221 - getrandom/CHANGELOG.md | 158 - getrandom/Cargo.toml | 45 - getrandom/LICENSE-APACHE | 201 - getrandom/LICENSE-MIT | 26 - getrandom/README.md | 78 - getrandom/appveyor.yml | 52 - getrandom/benches/mod.rs | 23 - getrandom/build.rs | 19 - getrandom/src/bsd_arandom.rs | 49 - getrandom/src/cloudabi.rs | 25 - getrandom/src/dummy.rs | 14 - getrandom/src/error.rs | 178 - getrandom/src/error_impls.rs | 35 - getrandom/src/fuchsia.rs | 20 - getrandom/src/ios.rs | 31 - getrandom/src/lib.rs | 282 -- getrandom/src/linux_android.rs | 44 - getrandom/src/macos.rs | 34 - getrandom/src/openbsd.rs | 23 - getrandom/src/rdrand.rs | 90 - getrandom/src/solaris_illumos.rs | 44 - getrandom/src/use_file.rs | 73 - getrandom/src/util.rs | 96 - getrandom/src/util_libc.rs | 143 - getrandom/src/vxworks.rs | 35 - getrandom/src/wasi.rs | 19 - getrandom/src/wasm32_bindgen.rs | 113 - getrandom/src/wasm32_stdweb.rs | 114 - getrandom/src/windows.rs | 26 - getrandom/src/windows_uwp.rs | 59 - getrandom/tests/common.rs | 68 - getrandom/utils/ci/install.sh | 49 - getrandom/utils/ci/script.sh | 13 - lazy-static/.gitignore | 4 - lazy-static/.travis.yml | 34 - lazy-static/Cargo.toml | 34 - lazy-static/LICENSE-APACHE | 201 - lazy-static/LICENSE-MIT | 25 - lazy-static/README.md | 79 - lazy-static/appveyor.yml | 61 - lazy-static/compiletest/Cargo.toml | 11 - lazy-static/compiletest/src/lib.rs | 11 - .../compiletest/tests/compile-fail/README.md | 22 - .../incorrect_visibility_restriction.rs | 10 - .../tests/compile-fail/static_is_private.rs | 14 - .../tests/compile-fail/static_is_sized.rs | 11 - lazy-static/compiletest/tests/compile_tests.rs | 19 - lazy-static/src/core_lazy.rs | 31 - lazy-static/src/inline_lazy.rs | 57 - lazy-static/src/lib.rs | 215 - lazy-static/tests/no_std.rs | 20 - lazy-static/tests/test.rs | 164 - libc/.cirrus.yml | 43 - libc/.github/issue_template.md | 24 - libc/.gitignore | 4 - libc/CONTRIBUTING.md | 66 - libc/Cargo.toml | 36 - libc/LICENSE-APACHE | 201 - libc/LICENSE-MIT | 25 - libc/README.md | 106 - libc/build.rs | 144 - libc/ci/README.md | 236 - libc/ci/android-install-ndk.sh | 50 - libc/ci/android-install-sdk.sh | 73 - libc/ci/android-sysimage.sh | 56 - libc/ci/azure-install-rust.yml | 82 - libc/ci/azure-master.yml | 22 - libc/ci/azure.yml | 228 - libc/ci/build.sh | 272 -- libc/ci/docker/aarch64-linux-android/Dockerfile | 45 - .../ci/docker/aarch64-unknown-linux-gnu/Dockerfile | 7 - .../docker/aarch64-unknown-linux-musl/Dockerfile | 15 - libc/ci/docker/arm-linux-androideabi/Dockerfile | 45 - .../docker/arm-unknown-linux-gnueabihf/Dockerfile | 7 - .../docker/arm-unknown-linux-musleabihf/Dockerfile | 13 - libc/ci/docker/asmjs-unknown-emscripten/Dockerfile | 21 - libc/ci/docker/i686-linux-android/Dockerfile | 45 - libc/ci/docker/i686-unknown-linux-gnu/Dockerfile | 5 - libc/ci/docker/i686-unknown-linux-musl/Dockerfile | 12 - libc/ci/docker/mips-unknown-linux-gnu/Dockerfile | 10 - libc/ci/docker/mips-unknown-linux-musl/Dockerfile | 24 - .../mips64-unknown-linux-gnuabi64/Dockerfile | 11 - .../mips64-unknown-linux-muslabi64/Dockerfile | 15 - .../mips64el-unknown-linux-gnuabi64/Dockerfile | 11 - .../mips64el-unknown-linux-muslabi64/Dockerfile | 15 - .../ci/docker/mipsel-unknown-linux-musl/Dockerfile | 24 - .../ci/docker/powerpc-unknown-linux-gnu/Dockerfile | 11 - .../docker/powerpc64-unknown-linux-gnu/Dockerfile | 11 - .../powerpc64le-unknown-linux-gnu/Dockerfile | 11 - libc/ci/docker/s390x-unknown-linux-gnu/Dockerfile | 18 - .../ci/docker/sparc64-unknown-linux-gnu/Dockerfile | 18 - .../ci/docker/wasm32-unknown-emscripten/Dockerfile | 28 - .../wasm32-unknown-emscripten/node-wrapper.sh | 15 - libc/ci/docker/wasm32-wasi/Dockerfile | 93 - libc/ci/docker/wasm32-wasi/clang.sh | 2 - libc/ci/docker/x86_64-linux-android/Dockerfile | 26 - libc/ci/docker/x86_64-rumprun-netbsd/Dockerfile | 10 - libc/ci/docker/x86_64-rumprun-netbsd/runtest.rs | 55 - libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile | 9 - .../docker/x86_64-unknown-linux-gnux32/Dockerfile | 5 - .../ci/docker/x86_64-unknown-linux-musl/Dockerfile | 10 - libc/ci/dox.sh | 74 - libc/ci/emscripten-entry.sh | 20 - libc/ci/emscripten.sh | 52 - libc/ci/install-musl.sh | 83 - libc/ci/ios/deploy_and_run_on_ios_simulator.rs | 175 - libc/ci/linux-s390x.sh | 20 - libc/ci/linux-sparc64.sh | 19 - libc/ci/run-docker.sh | 46 - libc/ci/run-qemu.sh | 34 - libc/ci/run.sh | 98 - libc/ci/runtest-android.rs | 47 - libc/ci/semver.sh | 77 - libc/ci/style.rs | 208 - libc/ci/style.sh | 19 - libc/ci/switch.json | 37 - libc/ci/sysinfo_guard.patch | 10 - libc/ci/test-runner-linux | 25 - libc/libc-test/Cargo.toml | 54 - libc/libc-test/build.rs | 2658 ------------ libc/libc-test/src/cmsg.c | 28 - libc/libc-test/test/cmsg.rs | 100 - libc/libc-test/test/linux_elf.rs | 12 - libc/libc-test/test/linux_fcntl.rs | 12 - libc/libc-test/test/linux_ipv6.rs | 12 - libc/libc-test/test/linux_strerror_r.rs | 12 - libc/libc-test/test/linux_termios.rs | 12 - libc/libc-test/test/main.rs | 6 - libc/rustfmt.toml | 3 - libc/src/cloudabi/aarch64.rs | 4 - libc/src/cloudabi/arm.rs | 4 - libc/src/cloudabi/mod.rs | 374 -- libc/src/cloudabi/x86.rs | 4 - libc/src/cloudabi/x86_64.rs | 4 - libc/src/fixed_width_ints.rs | 20 - libc/src/fuchsia/aarch64.rs | 66 - libc/src/fuchsia/align.rs | 142 - libc/src/fuchsia/mod.rs | 4571 -------------------- libc/src/fuchsia/no_align.rs | 129 - libc/src/fuchsia/x86_64.rs | 152 - libc/src/hermit/aarch64.rs | 2 - libc/src/hermit/mod.rs | 74 - libc/src/hermit/x86_64.rs | 2 - libc/src/lib.rs | 157 - libc/src/macros.rs | 275 -- libc/src/sgx.rs | 47 - libc/src/switch.rs | 49 - libc/src/unix/align.rs | 6 - libc/src/unix/bsd/apple/b32/align.rs | 7 - libc/src/unix/bsd/apple/b32/mod.rs | 115 - libc/src/unix/bsd/apple/b64/align.rs | 7 - libc/src/unix/bsd/apple/b64/mod.rs | 120 - libc/src/unix/bsd/apple/mod.rs | 3543 --------------- libc/src/unix/bsd/freebsdlike/dragonfly/errno.rs | 12 - libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs | 1096 ----- libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs | 44 - libc/src/unix/bsd/freebsdlike/freebsd/arm.rs | 47 - .../unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs | 224 - .../bsd/freebsdlike/freebsd/freebsd11/x86_64.rs | 32 - .../unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs | 224 - .../bsd/freebsdlike/freebsd/freebsd12/x86_64.rs | 34 - libc/src/unix/bsd/freebsdlike/freebsd/mod.rs | 1486 ------- libc/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs | 44 - libc/src/unix/bsd/freebsdlike/freebsd/x86.rs | 43 - .../unix/bsd/freebsdlike/freebsd/x86_64/align.rs | 7 - .../src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs | 24 - libc/src/unix/bsd/freebsdlike/mod.rs | 1466 ------- libc/src/unix/bsd/mod.rs | 794 ---- libc/src/unix/bsd/netbsdlike/mod.rs | 765 ---- libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs | 22 - libc/src/unix/bsd/netbsdlike/netbsd/arm.rs | 22 - libc/src/unix/bsd/netbsdlike/netbsd/mod.rs | 1965 --------- libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs | 21 - libc/src/unix/bsd/netbsdlike/netbsd/sparc64.rs | 8 - libc/src/unix/bsd/netbsdlike/netbsd/x86.rs | 15 - libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs | 23 - libc/src/unix/bsd/netbsdlike/openbsd/aarch64.rs | 16 - libc/src/unix/bsd/netbsdlike/openbsd/mod.rs | 1509 ------- libc/src/unix/bsd/netbsdlike/openbsd/sparc64.rs | 8 - libc/src/unix/bsd/netbsdlike/openbsd/x86.rs | 16 - libc/src/unix/bsd/netbsdlike/openbsd/x86_64.rs | 24 - libc/src/unix/haiku/b32.rs | 3 - libc/src/unix/haiku/b64.rs | 3 - libc/src/unix/haiku/mod.rs | 1531 ------- libc/src/unix/hermit/aarch64.rs | 2 - libc/src/unix/hermit/mod.rs | 1049 ----- libc/src/unix/hermit/x86_64.rs | 2 - libc/src/unix/linux_like/android/b32/arm.rs | 357 -- libc/src/unix/linux_like/android/b32/mod.rs | 221 - libc/src/unix/linux_like/android/b32/x86/align.rs | 7 - libc/src/unix/linux_like/android/b32/x86/mod.rs | 422 -- .../unix/linux_like/android/b64/aarch64/align.rs | 7 - .../src/unix/linux_like/android/b64/aarch64/mod.rs | 332 -- libc/src/unix/linux_like/android/b64/mod.rs | 281 -- .../unix/linux_like/android/b64/x86_64/align.rs | 7 - libc/src/unix/linux_like/android/b64/x86_64/mod.rs | 427 -- libc/src/unix/linux_like/android/mod.rs | 2409 ----------- libc/src/unix/linux_like/emscripten/align.rs | 74 - libc/src/unix/linux_like/emscripten/mod.rs | 1917 -------- libc/src/unix/linux_like/emscripten/no_align.rs | 63 - libc/src/unix/linux_like/linux/align.rs | 106 - libc/src/unix/linux_like/linux/gnu/align.rs | 13 - .../src/unix/linux_like/linux/gnu/b32/arm/align.rs | 7 - libc/src/unix/linux_like/linux/gnu/b32/arm/mod.rs | 876 ---- .../unix/linux_like/linux/gnu/b32/mips/align.rs | 7 - libc/src/unix/linux_like/linux/gnu/b32/mips/mod.rs | 901 ---- libc/src/unix/linux_like/linux/gnu/b32/mod.rs | 271 -- libc/src/unix/linux_like/linux/gnu/b32/powerpc.rs | 873 ---- .../unix/linux_like/linux/gnu/b32/sparc/align.rs | 7 - .../src/unix/linux_like/linux/gnu/b32/sparc/mod.rs | 978 ----- .../src/unix/linux_like/linux/gnu/b32/x86/align.rs | 7 - libc/src/unix/linux_like/linux/gnu/b32/x86/mod.rs | 1164 ----- .../unix/linux_like/linux/gnu/b64/aarch64/align.rs | 7 - .../unix/linux_like/linux/gnu/b64/aarch64/mod.rs | 954 ---- .../unix/linux_like/linux/gnu/b64/mips64/align.rs | 7 - .../unix/linux_like/linux/gnu/b64/mips64/mod.rs | 1017 ----- libc/src/unix/linux_like/linux/gnu/b64/mod.rs | 87 - .../linux_like/linux/gnu/b64/powerpc64/align.rs | 7 - .../unix/linux_like/linux/gnu/b64/powerpc64/mod.rs | 1052 ----- .../unix/linux_like/linux/gnu/b64/riscv64/mod.rs | 861 ---- libc/src/unix/linux_like/linux/gnu/b64/s390x.rs | 1029 ----- .../unix/linux_like/linux/gnu/b64/sparc64/align.rs | 7 - .../unix/linux_like/linux/gnu/b64/sparc64/mod.rs | 988 ----- .../unix/linux_like/linux/gnu/b64/x86_64/align.rs | 7 - .../unix/linux_like/linux/gnu/b64/x86_64/mod.rs | 929 ---- .../linux_like/linux/gnu/b64/x86_64/not_x32.rs | 423 -- .../unix/linux_like/linux/gnu/b64/x86_64/x32.rs | 375 -- libc/src/unix/linux_like/linux/gnu/mod.rs | 1057 ----- libc/src/unix/linux_like/linux/gnu/no_align.rs | 10 - libc/src/unix/linux_like/linux/mod.rs | 3194 -------------- .../unix/linux_like/linux/musl/b32/arm/align.rs | 7 - libc/src/unix/linux_like/linux/musl/b32/arm/mod.rs | 845 ---- libc/src/unix/linux_like/linux/musl/b32/hexagon.rs | 797 ---- .../unix/linux_like/linux/musl/b32/mips/align.rs | 7 - .../src/unix/linux_like/linux/musl/b32/mips/mod.rs | 849 ---- libc/src/unix/linux_like/linux/musl/b32/mod.rs | 65 - libc/src/unix/linux_like/linux/musl/b32/powerpc.rs | 863 ---- .../unix/linux_like/linux/musl/b32/x86/align.rs | 7 - libc/src/unix/linux_like/linux/musl/b32/x86/mod.rs | 954 ---- .../linux_like/linux/musl/b64/aarch64/align.rs | 7 - .../unix/linux_like/linux/musl/b64/aarch64/mod.rs | 655 --- libc/src/unix/linux_like/linux/musl/b64/mips64.rs | 754 ---- libc/src/unix/linux_like/linux/musl/b64/mod.rs | 169 - .../unix/linux_like/linux/musl/b64/powerpc64.rs | 739 ---- .../unix/linux_like/linux/musl/b64/x86_64/align.rs | 7 - .../unix/linux_like/linux/musl/b64/x86_64/mod.rs | 961 ---- libc/src/unix/linux_like/linux/musl/mod.rs | 436 -- libc/src/unix/linux_like/linux/no_align.rs | 84 - libc/src/unix/linux_like/mod.rs | 1569 ------- libc/src/unix/mod.rs | 1552 ------- libc/src/unix/newlib/aarch64/mod.rs | 33 - libc/src/unix/newlib/align.rs | 61 - libc/src/unix/newlib/arm/mod.rs | 35 - libc/src/unix/newlib/mod.rs | 725 ---- libc/src/unix/newlib/no_align.rs | 51 - libc/src/unix/no_align.rs | 6 - libc/src/unix/redox/mod.rs | 1114 ----- libc/src/unix/solarish/compat.rs | 32 - libc/src/unix/solarish/mod.rs | 2499 ----------- libc/src/unix/uclibc/align.rs | 66 - libc/src/unix/uclibc/arm/align.rs | 13 - libc/src/unix/uclibc/arm/mod.rs | 1049 ----- libc/src/unix/uclibc/arm/no_align.rs | 10 - libc/src/unix/uclibc/mips/mips32/align.rs | 13 - libc/src/unix/uclibc/mips/mips32/mod.rs | 633 --- libc/src/unix/uclibc/mips/mips32/no_align.rs | 10 - libc/src/unix/uclibc/mips/mips64/align.rs | 10 - libc/src/unix/uclibc/mips/mips64/mod.rs | 213 - libc/src/unix/uclibc/mips/mips64/no_align.rs | 7 - libc/src/unix/uclibc/mips/mod.rs | 479 -- libc/src/unix/uclibc/mod.rs | 2295 ---------- libc/src/unix/uclibc/no_align.rs | 53 - libc/src/unix/uclibc/x86_64/align.rs | 77 - libc/src/unix/uclibc/x86_64/l4re.rs | 48 - libc/src/unix/uclibc/x86_64/mod.rs | 312 -- libc/src/unix/uclibc/x86_64/no_align.rs | 59 - libc/src/unix/uclibc/x86_64/other.rs | 5 - libc/src/vxworks/aarch64.rs | 4 - libc/src/vxworks/arm.rs | 4 - libc/src/vxworks/mod.rs | 2086 --------- libc/src/vxworks/powerpc.rs | 4 - libc/src/vxworks/powerpc64.rs | 4 - libc/src/vxworks/x86.rs | 4 - libc/src/vxworks/x86_64.rs | 4 - libc/src/wasi.rs | 743 ---- libc/src/windows/gnu/align.rs | 19 - libc/src/windows/gnu/mod.rs | 23 - libc/src/windows/mod.rs | 604 --- libc/src/windows/msvc.rs | 17 - libc/tests/const_fn.rs | 5 - nitrocli/CHANGELOG.md | 5 + nitrocli/Cargo.lock | 46 +- nitrocli/Cargo.toml | 13 - nitrokey-sys/.gitignore | 4 - nitrokey-sys/CHANGELOG.md | 76 - nitrokey-sys/Cargo.toml | 16 - nitrokey-sys/LICENSE | 166 - nitrokey-sys/README.md | 35 - nitrokey-sys/build.rs | 94 - .../DeviceCommunicationExceptions.cpp | 24 - nitrokey-sys/libnitrokey-v3.5/LICENSE | 166 - nitrokey-sys/libnitrokey-v3.5/NK_C_API.cc | 910 ---- nitrokey-sys/libnitrokey-v3.5/NK_C_API.h | 1014 ----- nitrokey-sys/libnitrokey-v3.5/NitrokeyManager.cc | 1199 ----- nitrokey-sys/libnitrokey-v3.5/README.md | 291 -- nitrokey-sys/libnitrokey-v3.5/command_id.cc | 188 - nitrokey-sys/libnitrokey-v3.5/device.cc | 345 -- .../libnitrokey/CommandFailedException.h | 76 - .../libnitrokey/DeviceCommunicationExceptions.h | 73 - .../libnitrokey/LibraryException.h | 118 - .../libnitrokey/LongOperationInProgressException.h | 45 - .../libnitrokey-v3.5/libnitrokey/NitrokeyManager.h | 308 -- .../libnitrokey-v3.5/libnitrokey/command.h | 112 - .../libnitrokey-v3.5/libnitrokey/command_id.h | 156 - .../libnitrokey-v3.5/libnitrokey/cxx_semantics.h | 44 - .../libnitrokey-v3.5/libnitrokey/deprecated.h | 35 - nitrokey-sys/libnitrokey-v3.5/libnitrokey/device.h | 224 - .../libnitrokey-v3.5/libnitrokey/device_proto.h | 491 --- .../libnitrokey-v3.5/libnitrokey/dissect.h | 145 - .../libnitrokey-v3.5/libnitrokey/hidapi/hidapi.h | 391 -- nitrokey-sys/libnitrokey-v3.5/libnitrokey/log.h | 109 - nitrokey-sys/libnitrokey-v3.5/libnitrokey/misc.h | 121 - .../libnitrokey/stick10_commands.h | 929 ---- .../libnitrokey/stick10_commands_0.8.h | 348 -- .../libnitrokey/stick20_commands.h | 394 -- .../libnitrokey-v3.5/libnitrokey/version.h | 33 - nitrokey-sys/libnitrokey-v3.5/log.cc | 103 - nitrokey-sys/libnitrokey-v3.5/misc.cc | 123 - nitrokey-sys/libnitrokey-v3.5/version.cc | 37 - nitrokey-sys/libnitrokey-v3.5/version.cc.in | 37 - nitrokey-sys/src/ffi.rs | 1481 ------- nitrokey-sys/src/lib.rs | 31 - nitrokey/.builds/archlinux-msrv.yml | 22 - nitrokey/.builds/archlinux-use-system-lib.yml | 25 - nitrokey/.builds/archlinux.yml | 16 - nitrokey/.builds/lint.yml | 16 - nitrokey/.gitignore | 7 - nitrokey/CHANGELOG.md | 135 - nitrokey/Cargo.toml | 27 - nitrokey/LICENSES/CC0-1.0.txt | 121 - nitrokey/LICENSES/MIT.txt | 24 - nitrokey/README.md | 92 - nitrokey/TODO.md | 26 - nitrokey/src/auth.rs | 437 -- nitrokey/src/config.rs | 106 - nitrokey/src/device/mod.rs | 464 -- nitrokey/src/device/pro.rs | 79 - nitrokey/src/device/storage.rs | 735 ---- nitrokey/src/device/wrapper.rs | 134 - nitrokey/src/error.rs | 269 -- nitrokey/src/lib.rs | 465 -- nitrokey/src/otp.rs | 423 -- nitrokey/src/pws.rs | 391 -- nitrokey/src/util.rs | 99 - nitrokey/tests/device.rs | 575 --- nitrokey/tests/lib.rs | 28 - nitrokey/tests/otp.rs | 287 -- nitrokey/tests/pws.rs | 159 - nitrokey/tests/util/mod.rs | 113 - rand/.github/ISSUE_TEMPLATE/compile-issue.md | 16 - rand/.github/ISSUE_TEMPLATE/feature_request.md | 18 - rand/.github/ISSUE_TEMPLATE/other.md | 10 - rand/.gitignore | 4 - rand/.travis.yml | 315 -- rand/CHANGELOG.md | 568 --- rand/COPYRIGHT | 12 - rand/Cargo.toml | 90 - rand/LICENSE-APACHE | 201 - rand/LICENSE-MIT | 26 - rand/README.md | 118 - rand/appveyor.yml | 49 - rand/benches/generators.rs | 220 - rand/benches/misc.rs | 140 - rand/benches/seq.rs | 177 - rand/benches/weighted.rs | 36 - rand/examples/monte-carlo.rs | 48 - rand/examples/monty-hall.rs | 112 - rand/rand_chacha/CHANGELOG.md | 18 - rand/rand_chacha/COPYRIGHT | 12 - rand/rand_chacha/Cargo.toml | 28 - rand/rand_chacha/LICENSE-APACHE | 201 - rand/rand_chacha/LICENSE-MIT | 26 - rand/rand_chacha/README.md | 49 - rand/rand_chacha/src/chacha.rs | 452 -- rand/rand_chacha/src/lib.rs | 30 - rand/rand_core/CHANGELOG.md | 58 - rand/rand_core/COPYRIGHT | 12 - rand/rand_core/Cargo.toml | 28 - rand/rand_core/LICENSE-APACHE | 201 - rand/rand_core/LICENSE-MIT | 26 - rand/rand_core/README.md | 82 - rand/rand_core/src/block.rs | 437 -- rand/rand_core/src/error.rs | 190 - rand/rand_core/src/impls.rs | 158 - rand/rand_core/src/le.rs | 68 - rand/rand_core/src/lib.rs | 492 --- rand/rand_core/src/os.rs | 85 - rand/rand_distr/CHANGELOG.md | 21 - rand/rand_distr/COPYRIGHT | 12 - rand/rand_distr/Cargo.toml | 27 - rand/rand_distr/LICENSE-APACHE | 201 - rand/rand_distr/LICENSE-MIT | 25 - rand/rand_distr/README.md | 42 - rand/rand_distr/benches/distributions.rs | 316 -- rand/rand_distr/src/binomial.rs | 329 -- rand/rand_distr/src/cauchy.rs | 120 - rand/rand_distr/src/dirichlet.rs | 154 - rand/rand_distr/src/exponential.rs | 145 - rand/rand_distr/src/gamma.rs | 485 --- rand/rand_distr/src/lib.rs | 134 - rand/rand_distr/src/normal.rs | 219 - rand/rand_distr/src/pareto.rs | 89 - rand/rand_distr/src/pert.rs | 132 - rand/rand_distr/src/poisson.rs | 233 - rand/rand_distr/src/triangular.rs | 125 - rand/rand_distr/src/unit_ball.rs | 69 - rand/rand_distr/src/unit_circle.rs | 99 - rand/rand_distr/src/unit_disc.rs | 66 - rand/rand_distr/src/unit_sphere.rs | 94 - rand/rand_distr/src/utils.rs | 234 - rand/rand_distr/src/weibull.rs | 86 - rand/rand_distr/src/ziggurat_tables.rs | 279 -- rand/rand_distr/tests/uniformity.rs | 59 - rand/rand_hc/CHANGELOG.md | 16 - rand/rand_hc/COPYRIGHT | 12 - rand/rand_hc/Cargo.toml | 22 - rand/rand_hc/LICENSE-APACHE | 201 - rand/rand_hc/LICENSE-MIT | 25 - rand/rand_hc/README.md | 45 - rand/rand_hc/src/hc128.rs | 464 -- rand/rand_hc/src/lib.rs | 23 - rand/rand_isaac/CHANGELOG.md | 21 - rand/rand_isaac/COPYRIGHT | 12 - rand/rand_isaac/Cargo.toml | 31 - rand/rand_isaac/LICENSE-APACHE | 201 - rand/rand_isaac/LICENSE-MIT | 26 - rand/rand_isaac/README.md | 47 - rand/rand_isaac/src/isaac.rs | 476 -- rand/rand_isaac/src/isaac64.rs | 466 -- rand/rand_isaac/src/isaac_array.rs | 136 - rand/rand_isaac/src/lib.rs | 27 - rand/rand_jitter/CHANGELOG.md | 32 - rand/rand_jitter/COPYRIGHT | 12 - rand/rand_jitter/Cargo.toml | 30 - rand/rand_jitter/LICENSE-APACHE | 201 - rand/rand_jitter/LICENSE-MIT | 26 - rand/rand_jitter/README.md | 119 - rand/rand_jitter/benches/mod.rs | 17 - rand/rand_jitter/src/error.rs | 77 - rand/rand_jitter/src/lib.rs | 750 ---- rand/rand_jitter/src/platform.rs | 44 - rand/rand_jitter/tests/mod.rs | 28 - rand/rand_os/CHANGELOG.md | 35 - rand/rand_os/COPYRIGHT | 12 - rand/rand_os/Cargo.toml | 26 - rand/rand_os/LICENSE-APACHE | 201 - rand/rand_os/LICENSE-MIT | 26 - rand/rand_os/README.md | 35 - rand/rand_os/src/lib.rs | 106 - rand/rand_pcg/CHANGELOG.md | 24 - rand/rand_pcg/COPYRIGHT | 12 - rand/rand_pcg/Cargo.toml | 32 - rand/rand_pcg/LICENSE-APACHE | 201 - rand/rand_pcg/LICENSE-MIT | 26 - rand/rand_pcg/README.md | 43 - rand/rand_pcg/src/lib.rs | 49 - rand/rand_pcg/src/pcg128.rs | 225 - rand/rand_pcg/src/pcg64.rs | 127 - rand/rand_pcg/tests/lcg128xsl64.rs | 55 - rand/rand_pcg/tests/lcg64xsh32.rs | 54 - rand/rand_pcg/tests/mcg128xsl64.rs | 54 - rand/rand_xorshift/CHANGELOG.md | 19 - rand/rand_xorshift/COPYRIGHT | 12 - rand/rand_xorshift/Cargo.toml | 31 - rand/rand_xorshift/LICENSE-APACHE | 201 - rand/rand_xorshift/LICENSE-MIT | 26 - rand/rand_xorshift/README.md | 45 - rand/rand_xorshift/src/lib.rs | 117 - rand/rand_xorshift/tests/mod.rs | 89 - rand/rand_xoshiro/CHANGELOG.md | 24 - rand/rand_xoshiro/COPYRIGHT | 12 - rand/rand_xoshiro/Cargo.toml | 25 - rand/rand_xoshiro/LICENSE-APACHE | 201 - rand/rand_xoshiro/LICENSE-MIT | 25 - rand/rand_xoshiro/README.md | 34 - rand/rand_xoshiro/src/common.rs | 243 -- rand/rand_xoshiro/src/lib.rs | 94 - rand/rand_xoshiro/src/splitmix64.rs | 149 - rand/rand_xoshiro/src/xoroshiro128plus.rs | 130 - rand/rand_xoshiro/src/xoroshiro128starstar.rs | 127 - rand/rand_xoshiro/src/xoroshiro64star.rs | 102 - rand/rand_xoshiro/src/xoroshiro64starstar.rs | 101 - rand/rand_xoshiro/src/xoshiro128plus.rs | 112 - rand/rand_xoshiro/src/xoshiro128starstar.rs | 111 - rand/rand_xoshiro/src/xoshiro256plus.rs | 131 - rand/rand_xoshiro/src/xoshiro256starstar.rs | 128 - rand/rand_xoshiro/src/xoshiro512plus.rs | 122 - rand/rand_xoshiro/src/xoshiro512starstar.rs | 122 - rand/rand_xoshiro/tests/serde.rs | 83 - rand/rustfmt.toml | 30 - rand/src/distributions/bernoulli.rs | 166 - rand/src/distributions/binomial.rs | 313 -- rand/src/distributions/cauchy.rs | 103 - rand/src/distributions/dirichlet.rs | 128 - rand/src/distributions/exponential.rs | 108 - rand/src/distributions/float.rs | 259 -- rand/src/distributions/gamma.rs | 371 -- rand/src/distributions/integer.rs | 184 - rand/src/distributions/mod.rs | 381 -- rand/src/distributions/normal.rs | 170 - rand/src/distributions/other.rs | 220 - rand/src/distributions/pareto.rs | 67 - rand/src/distributions/poisson.rs | 151 - rand/src/distributions/triangular.rs | 79 - rand/src/distributions/uniform.rs | 1270 ------ rand/src/distributions/unit_circle.rs | 101 - rand/src/distributions/unit_sphere.rs | 96 - rand/src/distributions/utils.rs | 488 --- rand/src/distributions/weibull.rs | 64 - rand/src/distributions/weighted/alias_method.rs | 499 --- rand/src/distributions/weighted/mod.rs | 363 -- rand/src/distributions/ziggurat_tables.rs | 279 -- rand/src/lib.rs | 720 --- rand/src/prelude.rs | 28 - rand/src/rngs/adapter/mod.rs | 15 - rand/src/rngs/adapter/read.rs | 148 - rand/src/rngs/adapter/reseeding.rs | 357 -- rand/src/rngs/entropy.rs | 76 - rand/src/rngs/mock.rs | 64 - rand/src/rngs/mod.rs | 119 - rand/src/rngs/small.rs | 115 - rand/src/rngs/std.rs | 100 - rand/src/rngs/thread.rs | 124 - rand/src/seq/index.rs | 409 -- rand/src/seq/mod.rs | 791 ---- rand/tests/wasm_bindgen/Cargo.toml | 16 - rand/tests/wasm_bindgen/js/index.js | 7 - rand/tests/wasm_bindgen/src/lib.rs | 49 - rand/utils/ci/install.sh | 49 - rand/utils/ci/install_cargo_web.sh | 15 - rand/utils/ci/miri.sh | 23 - rand/utils/ci/script.sh | 27 - rand/utils/ziggurat_tables.py | 125 - 632 files changed, 38 insertions(+), 132162 deletions(-) delete mode 100644 argparse/.gitignore delete mode 100644 argparse/.travis.yml delete mode 100644 argparse/Cargo.toml delete mode 100644 argparse/LICENSE delete mode 100644 argparse/README.rst delete mode 100644 argparse/bulk.yaml delete mode 100644 argparse/examples/greeting.rs delete mode 100644 argparse/examples/structure.rs delete mode 100644 argparse/examples/subcommands.rs delete mode 100644 argparse/src/action.rs delete mode 100644 argparse/src/bool.rs delete mode 100644 argparse/src/custom.rs delete mode 100644 argparse/src/from_cli.rs delete mode 100644 argparse/src/generic.rs delete mode 100644 argparse/src/help.rs delete mode 100644 argparse/src/lib.rs delete mode 100644 argparse/src/num.rs delete mode 100644 argparse/src/parser.rs delete mode 100644 argparse/src/print.rs delete mode 100644 argparse/src/test_bool.rs delete mode 100644 argparse/src/test_const.rs delete mode 100644 argparse/src/test_enum.rs delete mode 100644 argparse/src/test_env.rs delete mode 100644 argparse/src/test_float.rs delete mode 100644 argparse/src/test_help.rs delete mode 100644 argparse/src/test_int.rs delete mode 100644 argparse/src/test_many.rs delete mode 100644 argparse/src/test_optional.rs delete mode 100644 argparse/src/test_parser.rs delete mode 100644 argparse/src/test_path.rs delete mode 100644 argparse/src/test_pos.rs delete mode 100644 argparse/src/test_str.rs delete mode 100644 argparse/src/test_usage.rs delete mode 100644 argparse/vagga.yaml delete mode 100644 base32/.gitignore delete mode 100644 base32/.travis.yml delete mode 100644 base32/Cargo.toml delete mode 100644 base32/LICENSE-APACHE delete mode 100644 base32/LICENSE-MIT delete mode 100644 base32/README.md delete mode 100644 base32/src/lib.rs delete mode 100644 cc/.github/workflows/main.yml delete mode 100644 cc/.gitignore delete mode 100644 cc/Cargo.toml delete mode 100644 cc/LICENSE-APACHE delete mode 100644 cc/LICENSE-MIT delete mode 100644 cc/README.md delete mode 100644 cc/cc-test/Cargo.toml delete mode 100644 cc/cc-test/build.rs delete mode 100644 cc/cc-test/src/NMakefile delete mode 100644 cc/cc-test/src/aarch64.S delete mode 100644 cc/cc-test/src/bar1.c delete mode 100644 cc/cc-test/src/bar2.c delete mode 100644 cc/cc-test/src/baz.cpp delete mode 100644 cc/cc-test/src/expand.c delete mode 100644 cc/cc-test/src/foo.c delete mode 100644 cc/cc-test/src/i686.S delete mode 100644 cc/cc-test/src/i686.asm delete mode 100644 cc/cc-test/src/include/foo.h delete mode 100644 cc/cc-test/src/lib.rs delete mode 100644 cc/cc-test/src/msvc.c delete mode 100644 cc/cc-test/src/opt_linkage.c delete mode 100644 cc/cc-test/src/windows.c delete mode 100644 cc/cc-test/src/x86_64.S delete mode 100644 cc/cc-test/src/x86_64.asm delete mode 100644 cc/cc-test/tests/all.rs delete mode 100644 cc/src/bin/gcc-shim.rs delete mode 100644 cc/src/com.rs delete mode 100644 cc/src/lib.rs delete mode 100644 cc/src/registry.rs delete mode 100644 cc/src/setup_config.rs delete mode 100644 cc/src/winapi.rs delete mode 100644 cc/src/windows_registry.rs delete mode 100644 cc/tests/cc_env.rs delete mode 100644 cc/tests/cflags.rs delete mode 100644 cc/tests/cxxflags.rs delete mode 100644 cc/tests/support/mod.rs delete mode 100644 cc/tests/test.rs delete mode 100644 cfg-if/.github/workflows/main.yml delete mode 100644 cfg-if/.gitignore delete mode 100644 cfg-if/Cargo.toml delete mode 100644 cfg-if/LICENSE-APACHE delete mode 100644 cfg-if/LICENSE-MIT delete mode 100644 cfg-if/README.md delete mode 100644 cfg-if/src/lib.rs delete mode 100644 cfg-if/tests/xcrate.rs delete mode 100644 getrandom/.cargo/config delete mode 100644 getrandom/.gitignore delete mode 100644 getrandom/.travis.yml delete mode 100644 getrandom/CHANGELOG.md delete mode 100644 getrandom/Cargo.toml delete mode 100644 getrandom/LICENSE-APACHE delete mode 100644 getrandom/LICENSE-MIT delete mode 100644 getrandom/README.md delete mode 100644 getrandom/appveyor.yml delete mode 100644 getrandom/benches/mod.rs delete mode 100644 getrandom/build.rs delete mode 100644 getrandom/src/bsd_arandom.rs delete mode 100644 getrandom/src/cloudabi.rs delete mode 100644 getrandom/src/dummy.rs delete mode 100644 getrandom/src/error.rs delete mode 100644 getrandom/src/error_impls.rs delete mode 100644 getrandom/src/fuchsia.rs delete mode 100644 getrandom/src/ios.rs delete mode 100644 getrandom/src/lib.rs delete mode 100644 getrandom/src/linux_android.rs delete mode 100644 getrandom/src/macos.rs delete mode 100644 getrandom/src/openbsd.rs delete mode 100644 getrandom/src/rdrand.rs delete mode 100644 getrandom/src/solaris_illumos.rs delete mode 100644 getrandom/src/use_file.rs delete mode 100644 getrandom/src/util.rs delete mode 100644 getrandom/src/util_libc.rs delete mode 100644 getrandom/src/vxworks.rs delete mode 100644 getrandom/src/wasi.rs delete mode 100644 getrandom/src/wasm32_bindgen.rs delete mode 100644 getrandom/src/wasm32_stdweb.rs delete mode 100644 getrandom/src/windows.rs delete mode 100644 getrandom/src/windows_uwp.rs delete mode 100644 getrandom/tests/common.rs delete mode 100644 getrandom/utils/ci/install.sh delete mode 100644 getrandom/utils/ci/script.sh delete mode 100644 lazy-static/.gitignore delete mode 100644 lazy-static/.travis.yml delete mode 100644 lazy-static/Cargo.toml delete mode 100644 lazy-static/LICENSE-APACHE delete mode 100644 lazy-static/LICENSE-MIT delete mode 100644 lazy-static/README.md delete mode 100644 lazy-static/appveyor.yml delete mode 100644 lazy-static/compiletest/Cargo.toml delete mode 100644 lazy-static/compiletest/src/lib.rs delete mode 100644 lazy-static/compiletest/tests/compile-fail/README.md delete mode 100644 lazy-static/compiletest/tests/compile-fail/incorrect_visibility_restriction.rs delete mode 100644 lazy-static/compiletest/tests/compile-fail/static_is_private.rs delete mode 100644 lazy-static/compiletest/tests/compile-fail/static_is_sized.rs delete mode 100644 lazy-static/compiletest/tests/compile_tests.rs delete mode 100644 lazy-static/src/core_lazy.rs delete mode 100644 lazy-static/src/inline_lazy.rs delete mode 100644 lazy-static/src/lib.rs delete mode 100644 lazy-static/tests/no_std.rs delete mode 100644 lazy-static/tests/test.rs delete mode 100644 libc/.cirrus.yml delete mode 100644 libc/.github/issue_template.md delete mode 100644 libc/.gitignore delete mode 100644 libc/CONTRIBUTING.md delete mode 100644 libc/Cargo.toml delete mode 100644 libc/LICENSE-APACHE delete mode 100644 libc/LICENSE-MIT delete mode 100644 libc/README.md delete mode 100644 libc/build.rs delete mode 100644 libc/ci/README.md delete mode 100644 libc/ci/android-install-ndk.sh delete mode 100644 libc/ci/android-install-sdk.sh delete mode 100644 libc/ci/android-sysimage.sh delete mode 100644 libc/ci/azure-install-rust.yml delete mode 100644 libc/ci/azure-master.yml delete mode 100644 libc/ci/azure.yml delete mode 100644 libc/ci/build.sh delete mode 100644 libc/ci/docker/aarch64-linux-android/Dockerfile delete mode 100644 libc/ci/docker/aarch64-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/aarch64-unknown-linux-musl/Dockerfile delete mode 100644 libc/ci/docker/arm-linux-androideabi/Dockerfile delete mode 100644 libc/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile delete mode 100644 libc/ci/docker/arm-unknown-linux-musleabihf/Dockerfile delete mode 100644 libc/ci/docker/asmjs-unknown-emscripten/Dockerfile delete mode 100644 libc/ci/docker/i686-linux-android/Dockerfile delete mode 100644 libc/ci/docker/i686-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/i686-unknown-linux-musl/Dockerfile delete mode 100644 libc/ci/docker/mips-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/mips-unknown-linux-musl/Dockerfile delete mode 100644 libc/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile delete mode 100644 libc/ci/docker/mips64-unknown-linux-muslabi64/Dockerfile delete mode 100644 libc/ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile delete mode 100644 libc/ci/docker/mips64el-unknown-linux-muslabi64/Dockerfile delete mode 100644 libc/ci/docker/mipsel-unknown-linux-musl/Dockerfile delete mode 100644 libc/ci/docker/powerpc-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/powerpc64-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/s390x-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/sparc64-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/wasm32-unknown-emscripten/Dockerfile delete mode 100755 libc/ci/docker/wasm32-unknown-emscripten/node-wrapper.sh delete mode 100644 libc/ci/docker/wasm32-wasi/Dockerfile delete mode 100755 libc/ci/docker/wasm32-wasi/clang.sh delete mode 100644 libc/ci/docker/x86_64-linux-android/Dockerfile delete mode 100644 libc/ci/docker/x86_64-rumprun-netbsd/Dockerfile delete mode 100644 libc/ci/docker/x86_64-rumprun-netbsd/runtest.rs delete mode 100644 libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile delete mode 100644 libc/ci/docker/x86_64-unknown-linux-gnux32/Dockerfile delete mode 100644 libc/ci/docker/x86_64-unknown-linux-musl/Dockerfile delete mode 100644 libc/ci/dox.sh delete mode 100755 libc/ci/emscripten-entry.sh delete mode 100644 libc/ci/emscripten.sh delete mode 100644 libc/ci/install-musl.sh delete mode 100644 libc/ci/ios/deploy_and_run_on_ios_simulator.rs delete mode 100644 libc/ci/linux-s390x.sh delete mode 100644 libc/ci/linux-sparc64.sh delete mode 100755 libc/ci/run-docker.sh delete mode 100644 libc/ci/run-qemu.sh delete mode 100755 libc/ci/run.sh delete mode 100644 libc/ci/runtest-android.rs delete mode 100644 libc/ci/semver.sh delete mode 100644 libc/ci/style.rs delete mode 100644 libc/ci/style.sh delete mode 100644 libc/ci/switch.json delete mode 100644 libc/ci/sysinfo_guard.patch delete mode 100755 libc/ci/test-runner-linux delete mode 100644 libc/libc-test/Cargo.toml delete mode 100644 libc/libc-test/build.rs delete mode 100644 libc/libc-test/src/cmsg.c delete mode 100644 libc/libc-test/test/cmsg.rs delete mode 100644 libc/libc-test/test/linux_elf.rs delete mode 100644 libc/libc-test/test/linux_fcntl.rs delete mode 100644 libc/libc-test/test/linux_ipv6.rs delete mode 100644 libc/libc-test/test/linux_strerror_r.rs delete mode 100644 libc/libc-test/test/linux_termios.rs delete mode 100644 libc/libc-test/test/main.rs delete mode 100644 libc/rustfmt.toml delete mode 100644 libc/src/cloudabi/aarch64.rs delete mode 100644 libc/src/cloudabi/arm.rs delete mode 100644 libc/src/cloudabi/mod.rs delete mode 100644 libc/src/cloudabi/x86.rs delete mode 100644 libc/src/cloudabi/x86_64.rs delete mode 100644 libc/src/fixed_width_ints.rs delete mode 100644 libc/src/fuchsia/aarch64.rs delete mode 100644 libc/src/fuchsia/align.rs delete mode 100644 libc/src/fuchsia/mod.rs delete mode 100644 libc/src/fuchsia/no_align.rs delete mode 100644 libc/src/fuchsia/x86_64.rs delete mode 100644 libc/src/hermit/aarch64.rs delete mode 100644 libc/src/hermit/mod.rs delete mode 100644 libc/src/hermit/x86_64.rs delete mode 100644 libc/src/lib.rs delete mode 100644 libc/src/macros.rs delete mode 100644 libc/src/sgx.rs delete mode 100644 libc/src/switch.rs delete mode 100644 libc/src/unix/align.rs delete mode 100644 libc/src/unix/bsd/apple/b32/align.rs delete mode 100644 libc/src/unix/bsd/apple/b32/mod.rs delete mode 100644 libc/src/unix/bsd/apple/b64/align.rs delete mode 100644 libc/src/unix/bsd/apple/b64/mod.rs delete mode 100644 libc/src/unix/bsd/apple/mod.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/dragonfly/errno.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/arm.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/freebsd11/x86_64.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/freebsd12/x86_64.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/mod.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/x86.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs delete mode 100644 libc/src/unix/bsd/freebsdlike/mod.rs delete mode 100644 libc/src/unix/bsd/mod.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/mod.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/netbsd/arm.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/netbsd/mod.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/netbsd/sparc64.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/netbsd/x86.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/openbsd/aarch64.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/openbsd/mod.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/openbsd/sparc64.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/openbsd/x86.rs delete mode 100644 libc/src/unix/bsd/netbsdlike/openbsd/x86_64.rs delete mode 100644 libc/src/unix/haiku/b32.rs delete mode 100644 libc/src/unix/haiku/b64.rs delete mode 100644 libc/src/unix/haiku/mod.rs delete mode 100644 libc/src/unix/hermit/aarch64.rs delete mode 100644 libc/src/unix/hermit/mod.rs delete mode 100644 libc/src/unix/hermit/x86_64.rs delete mode 100644 libc/src/unix/linux_like/android/b32/arm.rs delete mode 100644 libc/src/unix/linux_like/android/b32/mod.rs delete mode 100644 libc/src/unix/linux_like/android/b32/x86/align.rs delete mode 100644 libc/src/unix/linux_like/android/b32/x86/mod.rs delete mode 100644 libc/src/unix/linux_like/android/b64/aarch64/align.rs delete mode 100644 libc/src/unix/linux_like/android/b64/aarch64/mod.rs delete mode 100644 libc/src/unix/linux_like/android/b64/mod.rs delete mode 100644 libc/src/unix/linux_like/android/b64/x86_64/align.rs delete mode 100644 libc/src/unix/linux_like/android/b64/x86_64/mod.rs delete mode 100644 libc/src/unix/linux_like/android/mod.rs delete mode 100644 libc/src/unix/linux_like/emscripten/align.rs delete mode 100644 libc/src/unix/linux_like/emscripten/mod.rs delete mode 100644 libc/src/unix/linux_like/emscripten/no_align.rs delete mode 100644 libc/src/unix/linux_like/linux/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/arm/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/arm/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/mips/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/mips/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/powerpc.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/sparc/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/sparc/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/x86/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b32/x86/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/aarch64/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/mips64/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/s390x.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/sparc64/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/x86_64/align.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/gnu/no_align.rs delete mode 100644 libc/src/unix/linux_like/linux/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/arm/align.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/arm/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/hexagon.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/mips/align.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/mips/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/powerpc.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/x86/align.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b32/x86/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b64/aarch64/align.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b64/mips64.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b64/powerpc64.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b64/x86_64/align.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/musl/mod.rs delete mode 100644 libc/src/unix/linux_like/linux/no_align.rs delete mode 100644 libc/src/unix/linux_like/mod.rs delete mode 100644 libc/src/unix/mod.rs delete mode 100644 libc/src/unix/newlib/aarch64/mod.rs delete mode 100644 libc/src/unix/newlib/align.rs delete mode 100644 libc/src/unix/newlib/arm/mod.rs delete mode 100644 libc/src/unix/newlib/mod.rs delete mode 100644 libc/src/unix/newlib/no_align.rs delete mode 100644 libc/src/unix/no_align.rs delete mode 100644 libc/src/unix/redox/mod.rs delete mode 100644 libc/src/unix/solarish/compat.rs delete mode 100644 libc/src/unix/solarish/mod.rs delete mode 100644 libc/src/unix/uclibc/align.rs delete mode 100644 libc/src/unix/uclibc/arm/align.rs delete mode 100644 libc/src/unix/uclibc/arm/mod.rs delete mode 100644 libc/src/unix/uclibc/arm/no_align.rs delete mode 100644 libc/src/unix/uclibc/mips/mips32/align.rs delete mode 100644 libc/src/unix/uclibc/mips/mips32/mod.rs delete mode 100644 libc/src/unix/uclibc/mips/mips32/no_align.rs delete mode 100644 libc/src/unix/uclibc/mips/mips64/align.rs delete mode 100644 libc/src/unix/uclibc/mips/mips64/mod.rs delete mode 100644 libc/src/unix/uclibc/mips/mips64/no_align.rs delete mode 100644 libc/src/unix/uclibc/mips/mod.rs delete mode 100644 libc/src/unix/uclibc/mod.rs delete mode 100644 libc/src/unix/uclibc/no_align.rs delete mode 100644 libc/src/unix/uclibc/x86_64/align.rs delete mode 100644 libc/src/unix/uclibc/x86_64/l4re.rs delete mode 100644 libc/src/unix/uclibc/x86_64/mod.rs delete mode 100644 libc/src/unix/uclibc/x86_64/no_align.rs delete mode 100644 libc/src/unix/uclibc/x86_64/other.rs delete mode 100644 libc/src/vxworks/aarch64.rs delete mode 100644 libc/src/vxworks/arm.rs delete mode 100755 libc/src/vxworks/mod.rs delete mode 100644 libc/src/vxworks/powerpc.rs delete mode 100644 libc/src/vxworks/powerpc64.rs delete mode 100644 libc/src/vxworks/x86.rs delete mode 100644 libc/src/vxworks/x86_64.rs delete mode 100644 libc/src/wasi.rs delete mode 100644 libc/src/windows/gnu/align.rs delete mode 100644 libc/src/windows/gnu/mod.rs delete mode 100644 libc/src/windows/mod.rs delete mode 100644 libc/src/windows/msvc.rs delete mode 100644 libc/tests/const_fn.rs delete mode 100644 nitrokey-sys/.gitignore delete mode 100644 nitrokey-sys/CHANGELOG.md delete mode 100644 nitrokey-sys/Cargo.toml delete mode 100644 nitrokey-sys/LICENSE delete mode 100644 nitrokey-sys/README.md delete mode 100644 nitrokey-sys/build.rs delete mode 100644 nitrokey-sys/libnitrokey-v3.5/DeviceCommunicationExceptions.cpp delete mode 100644 nitrokey-sys/libnitrokey-v3.5/LICENSE delete mode 100644 nitrokey-sys/libnitrokey-v3.5/NK_C_API.cc delete mode 100644 nitrokey-sys/libnitrokey-v3.5/NK_C_API.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/NitrokeyManager.cc delete mode 100644 nitrokey-sys/libnitrokey-v3.5/README.md delete mode 100644 nitrokey-sys/libnitrokey-v3.5/command_id.cc delete mode 100644 nitrokey-sys/libnitrokey-v3.5/device.cc delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/CommandFailedException.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/DeviceCommunicationExceptions.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/LibraryException.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/LongOperationInProgressException.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/NitrokeyManager.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/command.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/command_id.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/cxx_semantics.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/deprecated.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/device.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/device_proto.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/dissect.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/hidapi/hidapi.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/log.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/misc.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick10_commands.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick10_commands_0.8.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick20_commands.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/libnitrokey/version.h delete mode 100644 nitrokey-sys/libnitrokey-v3.5/log.cc delete mode 100644 nitrokey-sys/libnitrokey-v3.5/misc.cc delete mode 100644 nitrokey-sys/libnitrokey-v3.5/version.cc delete mode 100644 nitrokey-sys/libnitrokey-v3.5/version.cc.in delete mode 100644 nitrokey-sys/src/ffi.rs delete mode 100644 nitrokey-sys/src/lib.rs delete mode 100644 nitrokey/.builds/archlinux-msrv.yml delete mode 100644 nitrokey/.builds/archlinux-use-system-lib.yml delete mode 100644 nitrokey/.builds/archlinux.yml delete mode 100644 nitrokey/.builds/lint.yml delete mode 100644 nitrokey/.gitignore delete mode 100644 nitrokey/CHANGELOG.md delete mode 100644 nitrokey/Cargo.toml delete mode 100644 nitrokey/LICENSES/CC0-1.0.txt delete mode 100644 nitrokey/LICENSES/MIT.txt delete mode 100644 nitrokey/README.md delete mode 100644 nitrokey/TODO.md delete mode 100644 nitrokey/src/auth.rs delete mode 100644 nitrokey/src/config.rs delete mode 100644 nitrokey/src/device/mod.rs delete mode 100644 nitrokey/src/device/pro.rs delete mode 100644 nitrokey/src/device/storage.rs delete mode 100644 nitrokey/src/device/wrapper.rs delete mode 100644 nitrokey/src/error.rs delete mode 100644 nitrokey/src/lib.rs delete mode 100644 nitrokey/src/otp.rs delete mode 100644 nitrokey/src/pws.rs delete mode 100644 nitrokey/src/util.rs delete mode 100644 nitrokey/tests/device.rs delete mode 100644 nitrokey/tests/lib.rs delete mode 100644 nitrokey/tests/otp.rs delete mode 100644 nitrokey/tests/pws.rs delete mode 100644 nitrokey/tests/util/mod.rs delete mode 100644 rand/.github/ISSUE_TEMPLATE/compile-issue.md delete mode 100644 rand/.github/ISSUE_TEMPLATE/feature_request.md delete mode 100644 rand/.github/ISSUE_TEMPLATE/other.md delete mode 100644 rand/.gitignore delete mode 100644 rand/.travis.yml delete mode 100644 rand/CHANGELOG.md delete mode 100644 rand/COPYRIGHT delete mode 100644 rand/Cargo.toml delete mode 100644 rand/LICENSE-APACHE delete mode 100644 rand/LICENSE-MIT delete mode 100644 rand/README.md delete mode 100644 rand/appveyor.yml delete mode 100644 rand/benches/generators.rs delete mode 100644 rand/benches/misc.rs delete mode 100644 rand/benches/seq.rs delete mode 100644 rand/benches/weighted.rs delete mode 100644 rand/examples/monte-carlo.rs delete mode 100644 rand/examples/monty-hall.rs delete mode 100644 rand/rand_chacha/CHANGELOG.md delete mode 100644 rand/rand_chacha/COPYRIGHT delete mode 100644 rand/rand_chacha/Cargo.toml delete mode 100644 rand/rand_chacha/LICENSE-APACHE delete mode 100644 rand/rand_chacha/LICENSE-MIT delete mode 100644 rand/rand_chacha/README.md delete mode 100644 rand/rand_chacha/src/chacha.rs delete mode 100644 rand/rand_chacha/src/lib.rs delete mode 100644 rand/rand_core/CHANGELOG.md delete mode 100644 rand/rand_core/COPYRIGHT delete mode 100644 rand/rand_core/Cargo.toml delete mode 100644 rand/rand_core/LICENSE-APACHE delete mode 100644 rand/rand_core/LICENSE-MIT delete mode 100644 rand/rand_core/README.md delete mode 100644 rand/rand_core/src/block.rs delete mode 100644 rand/rand_core/src/error.rs delete mode 100644 rand/rand_core/src/impls.rs delete mode 100644 rand/rand_core/src/le.rs delete mode 100644 rand/rand_core/src/lib.rs delete mode 100644 rand/rand_core/src/os.rs delete mode 100644 rand/rand_distr/CHANGELOG.md delete mode 100644 rand/rand_distr/COPYRIGHT delete mode 100644 rand/rand_distr/Cargo.toml delete mode 100644 rand/rand_distr/LICENSE-APACHE delete mode 100644 rand/rand_distr/LICENSE-MIT delete mode 100644 rand/rand_distr/README.md delete mode 100644 rand/rand_distr/benches/distributions.rs delete mode 100644 rand/rand_distr/src/binomial.rs delete mode 100644 rand/rand_distr/src/cauchy.rs delete mode 100644 rand/rand_distr/src/dirichlet.rs delete mode 100644 rand/rand_distr/src/exponential.rs delete mode 100644 rand/rand_distr/src/gamma.rs delete mode 100644 rand/rand_distr/src/lib.rs delete mode 100644 rand/rand_distr/src/normal.rs delete mode 100644 rand/rand_distr/src/pareto.rs delete mode 100644 rand/rand_distr/src/pert.rs delete mode 100644 rand/rand_distr/src/poisson.rs delete mode 100644 rand/rand_distr/src/triangular.rs delete mode 100644 rand/rand_distr/src/unit_ball.rs delete mode 100644 rand/rand_distr/src/unit_circle.rs delete mode 100644 rand/rand_distr/src/unit_disc.rs delete mode 100644 rand/rand_distr/src/unit_sphere.rs delete mode 100644 rand/rand_distr/src/utils.rs delete mode 100644 rand/rand_distr/src/weibull.rs delete mode 100644 rand/rand_distr/src/ziggurat_tables.rs delete mode 100644 rand/rand_distr/tests/uniformity.rs delete mode 100644 rand/rand_hc/CHANGELOG.md delete mode 100644 rand/rand_hc/COPYRIGHT delete mode 100644 rand/rand_hc/Cargo.toml delete mode 100644 rand/rand_hc/LICENSE-APACHE delete mode 100644 rand/rand_hc/LICENSE-MIT delete mode 100644 rand/rand_hc/README.md delete mode 100644 rand/rand_hc/src/hc128.rs delete mode 100644 rand/rand_hc/src/lib.rs delete mode 100644 rand/rand_isaac/CHANGELOG.md delete mode 100644 rand/rand_isaac/COPYRIGHT delete mode 100644 rand/rand_isaac/Cargo.toml delete mode 100644 rand/rand_isaac/LICENSE-APACHE delete mode 100644 rand/rand_isaac/LICENSE-MIT delete mode 100644 rand/rand_isaac/README.md delete mode 100644 rand/rand_isaac/src/isaac.rs delete mode 100644 rand/rand_isaac/src/isaac64.rs delete mode 100644 rand/rand_isaac/src/isaac_array.rs delete mode 100644 rand/rand_isaac/src/lib.rs delete mode 100644 rand/rand_jitter/CHANGELOG.md delete mode 100644 rand/rand_jitter/COPYRIGHT delete mode 100644 rand/rand_jitter/Cargo.toml delete mode 100644 rand/rand_jitter/LICENSE-APACHE delete mode 100644 rand/rand_jitter/LICENSE-MIT delete mode 100644 rand/rand_jitter/README.md delete mode 100644 rand/rand_jitter/benches/mod.rs delete mode 100644 rand/rand_jitter/src/error.rs delete mode 100644 rand/rand_jitter/src/lib.rs delete mode 100644 rand/rand_jitter/src/platform.rs delete mode 100644 rand/rand_jitter/tests/mod.rs delete mode 100644 rand/rand_os/CHANGELOG.md delete mode 100644 rand/rand_os/COPYRIGHT delete mode 100644 rand/rand_os/Cargo.toml delete mode 100644 rand/rand_os/LICENSE-APACHE delete mode 100644 rand/rand_os/LICENSE-MIT delete mode 100644 rand/rand_os/README.md delete mode 100644 rand/rand_os/src/lib.rs delete mode 100644 rand/rand_pcg/CHANGELOG.md delete mode 100644 rand/rand_pcg/COPYRIGHT delete mode 100644 rand/rand_pcg/Cargo.toml delete mode 100644 rand/rand_pcg/LICENSE-APACHE delete mode 100644 rand/rand_pcg/LICENSE-MIT delete mode 100644 rand/rand_pcg/README.md delete mode 100644 rand/rand_pcg/src/lib.rs delete mode 100644 rand/rand_pcg/src/pcg128.rs delete mode 100644 rand/rand_pcg/src/pcg64.rs delete mode 100644 rand/rand_pcg/tests/lcg128xsl64.rs delete mode 100644 rand/rand_pcg/tests/lcg64xsh32.rs delete mode 100644 rand/rand_pcg/tests/mcg128xsl64.rs delete mode 100644 rand/rand_xorshift/CHANGELOG.md delete mode 100644 rand/rand_xorshift/COPYRIGHT delete mode 100644 rand/rand_xorshift/Cargo.toml delete mode 100644 rand/rand_xorshift/LICENSE-APACHE delete mode 100644 rand/rand_xorshift/LICENSE-MIT delete mode 100644 rand/rand_xorshift/README.md delete mode 100644 rand/rand_xorshift/src/lib.rs delete mode 100644 rand/rand_xorshift/tests/mod.rs delete mode 100644 rand/rand_xoshiro/CHANGELOG.md delete mode 100644 rand/rand_xoshiro/COPYRIGHT delete mode 100644 rand/rand_xoshiro/Cargo.toml delete mode 100644 rand/rand_xoshiro/LICENSE-APACHE delete mode 100644 rand/rand_xoshiro/LICENSE-MIT delete mode 100644 rand/rand_xoshiro/README.md delete mode 100644 rand/rand_xoshiro/src/common.rs delete mode 100644 rand/rand_xoshiro/src/lib.rs delete mode 100644 rand/rand_xoshiro/src/splitmix64.rs delete mode 100644 rand/rand_xoshiro/src/xoroshiro128plus.rs delete mode 100644 rand/rand_xoshiro/src/xoroshiro128starstar.rs delete mode 100644 rand/rand_xoshiro/src/xoroshiro64star.rs delete mode 100644 rand/rand_xoshiro/src/xoroshiro64starstar.rs delete mode 100644 rand/rand_xoshiro/src/xoshiro128plus.rs delete mode 100644 rand/rand_xoshiro/src/xoshiro128starstar.rs delete mode 100644 rand/rand_xoshiro/src/xoshiro256plus.rs delete mode 100644 rand/rand_xoshiro/src/xoshiro256starstar.rs delete mode 100644 rand/rand_xoshiro/src/xoshiro512plus.rs delete mode 100644 rand/rand_xoshiro/src/xoshiro512starstar.rs delete mode 100644 rand/rand_xoshiro/tests/serde.rs delete mode 100644 rand/rustfmt.toml delete mode 100644 rand/src/distributions/bernoulli.rs delete mode 100644 rand/src/distributions/binomial.rs delete mode 100644 rand/src/distributions/cauchy.rs delete mode 100644 rand/src/distributions/dirichlet.rs delete mode 100644 rand/src/distributions/exponential.rs delete mode 100644 rand/src/distributions/float.rs delete mode 100644 rand/src/distributions/gamma.rs delete mode 100644 rand/src/distributions/integer.rs delete mode 100644 rand/src/distributions/mod.rs delete mode 100644 rand/src/distributions/normal.rs delete mode 100644 rand/src/distributions/other.rs delete mode 100644 rand/src/distributions/pareto.rs delete mode 100644 rand/src/distributions/poisson.rs delete mode 100644 rand/src/distributions/triangular.rs delete mode 100644 rand/src/distributions/uniform.rs delete mode 100644 rand/src/distributions/unit_circle.rs delete mode 100644 rand/src/distributions/unit_sphere.rs delete mode 100644 rand/src/distributions/utils.rs delete mode 100644 rand/src/distributions/weibull.rs delete mode 100644 rand/src/distributions/weighted/alias_method.rs delete mode 100644 rand/src/distributions/weighted/mod.rs delete mode 100644 rand/src/distributions/ziggurat_tables.rs delete mode 100644 rand/src/lib.rs delete mode 100644 rand/src/prelude.rs delete mode 100644 rand/src/rngs/adapter/mod.rs delete mode 100644 rand/src/rngs/adapter/read.rs delete mode 100644 rand/src/rngs/adapter/reseeding.rs delete mode 100644 rand/src/rngs/entropy.rs delete mode 100644 rand/src/rngs/mock.rs delete mode 100644 rand/src/rngs/mod.rs delete mode 100644 rand/src/rngs/small.rs delete mode 100644 rand/src/rngs/std.rs delete mode 100644 rand/src/rngs/thread.rs delete mode 100644 rand/src/seq/index.rs delete mode 100644 rand/src/seq/mod.rs delete mode 100644 rand/tests/wasm_bindgen/Cargo.toml delete mode 100644 rand/tests/wasm_bindgen/js/index.js delete mode 100644 rand/tests/wasm_bindgen/src/lib.rs delete mode 100644 rand/utils/ci/install.sh delete mode 100755 rand/utils/ci/install_cargo_web.sh delete mode 100644 rand/utils/ci/miri.sh delete mode 100644 rand/utils/ci/script.sh delete mode 100755 rand/utils/ziggurat_tables.py diff --git a/argparse/.gitignore b/argparse/.gitignore deleted file mode 100644 index 6ae6389..0000000 --- a/argparse/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/.vagga -*.o -*.so -*.rlib -/argparse_test -/target -# examples -/greeting -/structure -/subcommands - -# Cargo files -Cargo.lock diff --git a/argparse/.travis.yml b/argparse/.travis.yml deleted file mode 100644 index 7ccbf43..0000000 --- a/argparse/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -sudo: false -dist: trusty -language: rust - -cache: -- cargo - -before_cache: -- rm -r $TRAVIS_BUILD_DIR/target/debug - -jobs: - include: - - os: linux - rust: stable - - os: linux - rust: beta - - os: linux - rust: nightly - - # deploy - - stage: publish - os: linux - rust: stable - env: - # CARGO_TOKEN - - secure: "tk6bJEv46YfZwAKYzxn9+afzEb6nGym9lo/YJgjYIolv2qsNyMLlmC8ptRSRTHwOQPd3c54Y9XYP+61miMmWjppQSjJ4yvkUqnyiYzzdxzVM5dNIbXcqO6GbTgE2rIx9BOH0c/qrmw1KW2iz8TChxgQu/vv8pmDL1kmyawVy3EE=" - install: true - script: true - - deploy: - - provider: script - script: 'cargo publish --verbose --token=$CARGO_TOKEN' - on: - tags: true diff --git a/argparse/Cargo.toml b/argparse/Cargo.toml deleted file mode 100644 index 7552373..0000000 --- a/argparse/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] - -name = "argparse" -description = "Powerful command-line argument parsing library" -license = "MIT" -readme = "README.rst" -keywords = ["command-line", "cli", "command", "argument"] -categories = ["command-line-interface"] -homepage = "http://github.com/tailhook/rust-argparse" -version = "0.2.2" -authors = ["Paul Colomiets "] - diff --git a/argparse/LICENSE b/argparse/LICENSE deleted file mode 100644 index 3e00de4..0000000 --- a/argparse/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2014-2015 Paul Colomiets - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/argparse/README.rst b/argparse/README.rst deleted file mode 100644 index 8a3fca0..0000000 --- a/argparse/README.rst +++ /dev/null @@ -1,341 +0,0 @@ -======== -Argparse -======== - -The ``rust-argparse`` is command-line parsing module for rust. It's inspired -by python's ``argparse`` module. - -Features: - -* Supports standard (GNU) option conventions -* Properly typed values -* Automatically generated help and usage messages - -Importing -========= -Edit your Cargo.toml to add ``rust-argparse`` to your project. - -.. code-block:: rust - - [dependencies] - argparse = "0.2.2" - - -Example -======= - -The following code is a simple Rust program with command-line arguments: - -.. code-block:: rust - - extern crate argparse; - - use argparse::{ArgumentParser, StoreTrue, Store}; - - fn main() { - let mut verbose = false; - let mut name = "World".to_string(); - { // this block limits scope of borrows by ap.refer() method - let mut ap = ArgumentParser::new(); - ap.set_description("Greet somebody."); - ap.refer(&mut verbose) - .add_option(&["-v", "--verbose"], StoreTrue, - "Be verbose"); - ap.refer(&mut name) - .add_option(&["--name"], Store, - "Name for the greeting"); - ap.parse_args_or_exit(); - } - - if verbose { - println!("name is {}", name); - } - println!("Hello {}!", name); - } - -Assuming the Rust code above is saved into a file ``greeting.rs``, let's see -what we have now:: - - $ rustc greeting.rs - $ ./greeting -h - Usage: - ./greeting [OPTIONS] - - Greet somebody. - - Optional arguments: - -h, --help Show this help message and exit - -v, --verbose - Be verbose - --name NAME Name for the greeting - $ ./greeting - Hello World! - $ ./greeting --name Bob - Hello Bob! - $ ./greeting -v --name Alice - name is Alice - Hello Alice! - - -Basic Workflow -============== - - -Create ArgumentParser ---------------------- - -The argument parser is created empty and is built incrementally. So we create -a mutable variable:: - - extern crate argparse; - use argparse::ArgumentParser; - - let mut parser = ArgumentParser::new(); - - -Customize ---------- - -There are optional customization methods. The most important one is:: - - parser.set_description("My command-line utility") - -The descripion is rewrapped to fit 80 column string nicely. Just like option -descriptions. - -Add Options ------------ - -The ``refer`` method creates a cell variable, which the result will be written -to:: - - let mut verbose = false; - parser.refer(&mut verbose); - -Next we add an options which control the variable: -For example:: - - parser.refer(&mut verbose) - .add_option(&["-v", "--verbose"], StoreTrue, - "Be verbose"); - -You may add multiple options for the same variable:: - - parser.refer(&mut verbose) - .add_option(&["-v", "--verbose"], StoreTrue, - "Be verbose") - .add_option(&["-q", "--quiet"], StoreFalse, - "Be verbose"); - -Similarly positional arguments are added:: - - let mut command = String; - parser.refer(&mut command) - .add_argument("command", Store, - "Command to run"); - - - -Organizing Options ------------------- - -It's often useful to organize options into some kind of structure. You can -easily borrow variables from the structure into option parser. For example:: - - struct Options { - verbose: bool, - } - ... - let mut options = Options { verbose: false }; - parser.refer(&mut options.verbose) - .add_option(&["-v"], StoreTrue, - "Be verbose"); - - -Parsing Arguments ------------------ - -All the complex work is done in ``parser.parse_args()``. But there is -a simpler option:: - - parser.parse_args_or_exit() - -In case you don't want argparse to exit itself, you might use the -``parse_args`` function directly:: - - use std::process::exit; - - match parser.parse_args() { - Ok(()) => {} - Err(x) => { - std::process::exit(x); - } - } - - -ArgumentParser Methods -====================== - -``parser.refer(var: &mut T) -> Ref`` - Attach the variable to argument parser. The options are added to the - returned ``Ref`` object and modify a variable passed to the method. - -``parser.add_option(names: &[&str], action: TypedAction, help: &str)`` - Add a single option which has no parameters. Most options must be added - by ``refer(..)`` and methods on ``Ref`` object (see below). - - Example:: - - ap.add_option(&["-V", "--version"], - Print(env!("CARGO_PKG_VERSION").to_string()), "Show version"); - -``parser.set_description(descr: &str)`` - Set description that is at the top of help message. - -``parser.stop_on_first_argument(val: bool)`` - If called with ``true``, parser will stop searching for options when first - non-option (the one doesn't start with ``-``) argument is encountered. This - is useful if you want to parse following options with another argparser or - external program. - -``parser.silence_double_dash(val: bool)`` - If called with ``true`` (default), parser will not treat *first* double - dash ``--`` as positional argument. Use ``false`` if you need to add some - meaning to the ``--`` marker. - -``parser.print_usage(name: &str, writer: &mut Write)`` - Prints usage string to stderr. - -``parser.print_help(name: &str, writer: &mut Write)`` - Writes help to ``writer``, used by ``--help`` option internally. - -``parser.parse_args()`` - Method that does all the dirty work. And returns ``Result`` - -``parser.parse_args_or_exit()`` - Method that does all the dirty work. And in case of failure just ``exit()`` - - -Variable Reference Methods -========================== - -The ``argparse::Ref`` object is returned from ``parser.refer()``. -The following methods are used to add and customize arguments: - -``option.add_option(names: &[&str], action: TypedAction, help: &str)`` - Add an option. All items in names should be either in format ``-X`` or - ``--long-option`` (i.e. one dash and one char or two dashes and long name). - How this option will be interpreted and whether it will have an argument - dependes on the action. See below list of actions. - -``option.add_argument(name: &str, action: TypedAction, help: &str)`` - Add a positional argument - -``option.metavar(var: &str)`` - A name of the argument in usage messages (for options having argument). - -``option.envvar(var: &str)`` - A name of the environment variable to get option value from. The value - would be parsed with ``FromStr::from_str``, just like an option having - ``Store`` action. - -``option.required()`` - The option or argument is required (it's optional by default). If multiple - options or multiple arguments are defined for this reference at least one - of them is required. - - -Actions -======= - -The following actions are available out of the box. They may be used in either -``add_option`` or ``add_argument``: - -``Store`` - An option has single argument. Stores a value from command-line in a - variable. Any type that has the ``FromStr`` and ``Clone`` traits implemented - may be used. - -``StoreOption`` - As ``Store``, but wrap value with ``Some`` for use with ``Option``. For - example: - - let mut x: Option = None; - ap.refer(&mut x).add_option(&["-x"], StoreOption, "Set var x"); - -``StoreConst(value)`` - An option has no arguments. Store a hard-coded ``value`` into variable, - when specified. Any type with the ``Clone`` trait implemented may be used. - -``PushConst(value)`` - An option has no arguments. Push a hard-coded ``value`` into variable, - when specified. Any type which has the ``Clone`` type implemented may be - used. Option might used for a list of operations to perform, when ``required`` - is set for this variable, at least one operation is required. - -``StoreTrue`` - Stores boolean ``true`` value in a variable. - (shortcut for ``StoreConst(true)``) - -``StoreFalse`` - Stores boolean ``false`` value in a variable. - (shortcut for ``StoreConst(false)``) - - -``IncrBy(num)`` - An option has no arguments. Increments the value stored in a variable by a - value ``num``. Any type which has the ``Add`` and ``Clone`` traits may be used. - -``DecrBy(nym)`` - Decrements the value stored in a variable by a value ``num``. Any type - which has the ``Add`` and ``Clone`` traits may be used. - -``Collect`` - When used for an ``--option``, requires single argument. When used for a - positional argument consumes all remaining arguments. Parsed options are - added to the list. I.e. a ``Collect`` action requires a - ``Vec`` variable. Parses arguments using ``FromStr`` trait. - -``List`` - When used for positional argument, works the same as ``List``. When used - as an option, consumes all remaining arguments. - - Note the usage of ``List`` is strongly discouraged, because of complex - rules below. Use ``Collect`` and positional options if possible. But usage - of ``List`` action may be useful if you need shell expansion of anything - other than last positional argument. - - Let's learn rules by example. For the next options:: - - ap.refer(&mut lst1).add_option(&["-X", "--xx"], List, "List1"); - ap.refer(&mut lst2).add_argument("yy", List, "List2"); - - The following command line:: - - ./run 1 2 3 -X 4 5 6 - - Will return ``[1, 2, 3]`` in the ``lst1`` and the ``[4,5,6]`` in the - ``lst2``. - - Note that using when using ``=`` or equivalent short option mode, the - 'consume all' mode is not enabled. I.e. in the following command-line:: - - ./run 1 2 -X3 4 --xx=5 6 - - The ``lst1`` has ``[3, 5]`` and ``lst2`` has ``[1, 2, 4, 6]``. - The argument consuming also stops on ``--`` or the next option:: - - ./run: -X 1 2 3 -- 4 5 6 - ./run: -X 1 2 --xx=3 4 5 6 - - Both of the above parse ``[4, 5, 6]`` as ``lst1`` and - the ``[1, 2, 3]`` as the ``lst2``. - -``Print(value)`` - Print the text and exit (with status ``0``). Useful for ``--version`` - option:: - - ap.add_option(&["-V", "--version"], - Print(env!("CARGO_PKG_VERSION").to_string()), "Show version"); - - diff --git a/argparse/bulk.yaml b/argparse/bulk.yaml deleted file mode 100644 index 73a7d02..0000000 --- a/argparse/bulk.yaml +++ /dev/null @@ -1,11 +0,0 @@ -minimum-bulk: v0.4.5 - -versions: - -- file: Cargo.toml - block-start: ^\[package\] - block-end: ^\[.*\] - regex: ^version\s*=\s*"(\S+)" - -- file: README.rst - regex: ^\s*argparse\s*=\s*"(\S+)" diff --git a/argparse/examples/greeting.rs b/argparse/examples/greeting.rs deleted file mode 100644 index 77e719c..0000000 --- a/argparse/examples/greeting.rs +++ /dev/null @@ -1,26 +0,0 @@ -extern crate argparse; - -use argparse::{ArgumentParser, StoreTrue, Store, Print}; - -fn main() { - let mut verbose = false; - let mut name = "World".to_string(); - { - let mut ap = ArgumentParser::new(); - ap.set_description("Greet somebody."); - ap.add_option(&["-V", "--version"], - Print(env!("CARGO_PKG_VERSION").to_string()), "Show version"); - ap.refer(&mut verbose) - .add_option(&["-v", "--verbose"], StoreTrue, - "Be verbose"); - ap.refer(&mut name) - .add_option(&["--name"], Store, - "Name for the greeting"); - ap.parse_args_or_exit(); - } - - if verbose { - println!("name is {}", name); - } - println!("Hello {}!", name); -} diff --git a/argparse/examples/structure.rs b/argparse/examples/structure.rs deleted file mode 100644 index 59b9345..0000000 --- a/argparse/examples/structure.rs +++ /dev/null @@ -1,38 +0,0 @@ -extern crate argparse; - -use std::process::exit; - -use argparse::{ArgumentParser, StoreTrue, Store}; - -struct Options { - verbose: bool, - name: String, -} - -fn main() { - let mut options = Options { - verbose: false, - name: "World".to_string(), - }; - { - let mut ap = ArgumentParser::new(); - ap.set_description("Greet somebody."); - ap.refer(&mut options.verbose) - .add_option(&["-v", "--verbose"], StoreTrue, - "Be verbose"); - ap.refer(&mut options.name) - .add_option(&["--name"], Store, - "Name for the greeting"); - match ap.parse_args() { - Ok(()) => {} - Err(x) => { - exit(x); - } - } - } - - if options.verbose { - println!("name is {}", options.name); - } - println!("Hello {}!", options.name); -} diff --git a/argparse/examples/subcommands.rs b/argparse/examples/subcommands.rs deleted file mode 100644 index 8fb061a..0000000 --- a/argparse/examples/subcommands.rs +++ /dev/null @@ -1,88 +0,0 @@ -use std::str::FromStr; -use std::io::{stdout, stderr}; -extern crate argparse; - -use argparse::{ArgumentParser, StoreTrue, Store, List}; - -#[allow(non_camel_case_types)] -#[derive(Debug)] -enum Command { - play, - record, -} - -impl FromStr for Command { - type Err = (); - fn from_str(src: &str) -> Result { - return match src { - "play" => Ok(Command::play), - "record" => Ok(Command::record), - _ => Err(()), - }; - } -} - - - -fn play_command(verbose: bool, args: Vec) { - let mut output = "".to_string(); - { - let mut ap = ArgumentParser::new(); - ap.set_description("Plays a sound"); - ap.refer(&mut output) - .add_option(&["--output"], Store, - r#"Output sink to play to"#); - match ap.parse(args, &mut stdout(), &mut stderr()) { - Ok(()) => {} - Err(x) => { - std::process::exit(x); - } - } - } - println!("Verbosity: {}, Output: {}", verbose, output); -} - -fn record_command(verbose: bool, args: Vec) { - let mut input = "".to_string(); - { - let mut ap = ArgumentParser::new(); - ap.set_description("Records a sound"); - ap.refer(&mut input) - .add_option(&["--input"], Store, - r#"Output source to record from"#); - match ap.parse(args, &mut stdout(), &mut stderr()) { - Ok(()) => {} - Err(x) => { - std::process::exit(x); - } - } - } - println!("Verbosity: {}, Input: {}", verbose, input); -} - -fn main() { - let mut verbose = false; - let mut subcommand = Command::play; - let mut args = vec!(); - { - let mut ap = ArgumentParser::new(); - ap.set_description("Plays or records sound"); - ap.refer(&mut verbose) - .add_option(&["-v", "--verbose"], StoreTrue, - "Be verbose"); - ap.refer(&mut subcommand).required() - .add_argument("command", Store, - r#"Command to run (either "play" or "record")"#); - ap.refer(&mut args) - .add_argument("arguments", List, - r#"Arguments for command"#); - ap.stop_on_first_argument(true); - ap.parse_args_or_exit(); - } - - args.insert(0, format!("subcommand {:?}", subcommand)); - match subcommand { - Command::play => play_command(verbose, args), - Command::record => record_command(verbose, args), - } -} diff --git a/argparse/src/action.rs b/argparse/src/action.rs deleted file mode 100644 index c3a0aff..0000000 --- a/argparse/src/action.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::cell::RefCell; -use std::rc::Rc; - -pub enum ParseResult { - Parsed, - Help, - Exit, - Error(String), -} - - -pub enum Action<'a> { - Flag(Box), - Single(Box), - Push(Box), - Many(Box), -} - -pub trait TypedAction { - fn bind<'x>(&self, Rc>) -> Action<'x>; -} - -pub trait IFlagAction { - fn parse_flag(&self) -> ParseResult; -} - -pub trait IArgAction { - fn parse_arg(&self, arg: &str) -> ParseResult; -} - -pub trait IArgsAction { - fn parse_args(&self, args: &[&str]) -> ParseResult; -} diff --git a/argparse/src/bool.rs b/argparse/src/bool.rs deleted file mode 100644 index 6ada458..0000000 --- a/argparse/src/bool.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::cell::RefCell; -use std::rc::Rc; - -use super::action::Action; -use super::action::TypedAction; -use super::action::Action::Flag; -use super::generic::StoreConstAction; -use super::{StoreTrue, StoreFalse}; - - -impl TypedAction for StoreTrue { - fn bind<'x>(&self, cell: Rc>) -> Action<'x> { - return Flag(Box::new(StoreConstAction { cell: cell, value: true })); - } -} - -impl TypedAction for StoreFalse { - fn bind<'x>(&self, cell: Rc>) -> Action<'x> { - return Flag(Box::new(StoreConstAction { cell: cell, value: false })); - } -} - diff --git a/argparse/src/custom.rs b/argparse/src/custom.rs deleted file mode 100644 index d002ffe..0000000 --- a/argparse/src/custom.rs +++ /dev/null @@ -1,95 +0,0 @@ -use std::cell::RefCell; -use std::rc::Rc; - -use super::{Parse, ParseOption, ParseList, ParseCollect, FromCommandLine}; -use super::action::Action; -use super::action::{TypedAction, IArgAction, IArgsAction}; -use super::action::ParseResult; -use super::action::ParseResult::{Parsed, Error}; -use super::action::Action::{Single, Push, Many}; - -pub struct ParseAction<'a, T: 'a> { - pub cell: Rc>, -} - -pub struct ParseOptionAction<'a, T: 'a> { - cell: Rc>>, -} - -pub struct ParseListAction<'a, T: 'a> { - cell: Rc>>, -} - -impl TypedAction for Parse { - fn bind<'x>(&self, cell: Rc>) -> Action<'x> { - return Single(Box::new(ParseAction { cell: cell })); - } -} - -impl TypedAction> for ParseOption { - fn bind<'x>(&self, cell: Rc>>) -> Action<'x> { - return Single(Box::new(ParseOptionAction { cell: cell })); - } -} - -impl TypedAction> for ParseList { - fn bind<'x>(&self, cell: Rc>>) -> Action<'x> { - return Many(Box::new(ParseListAction { cell: cell })); - } -} - -impl TypedAction> for ParseCollect - where T: 'static + FromCommandLine + Clone -{ - fn bind<'x>(&self, cell: Rc>>) -> Action<'x> { - return Push(Box::new(ParseListAction { cell: cell })) - } -} - -impl<'a, T: FromCommandLine> IArgAction for ParseAction<'a, T> { - fn parse_arg(&self, arg: &str) -> ParseResult { - match FromCommandLine::from_argument(arg) { - Ok(x) => { - **self.cell.borrow_mut() = x; - return Parsed; - } - Err(error) => { - return Error(format!("Bad value {:?}: {}", arg, error)); - } - } - } -} - -impl<'a, T: FromCommandLine> IArgAction for ParseOptionAction<'a, T> { - fn parse_arg(&self, arg: &str) -> ParseResult { - match FromCommandLine::from_argument(arg) { - Ok(x) => { - **self.cell.borrow_mut() = Some(x); - return Parsed; - } - Err(error) => { - return Error(format!("Bad value {:?}: {}", arg, error)); - } - } - } -} - -impl<'a, T: FromCommandLine + Clone> IArgsAction for ParseListAction<'a, T> { - fn parse_args(&self, args: &[&str]) -> ParseResult { - let mut result = vec!(); - for arg in args.iter() { - match FromCommandLine::from_argument(*arg) { - Ok(x) => { - result.push(x); - } - Err(error) => { - return Error(format!("Bad value {:?}: {}", arg, error)); - } - } - } - **self.cell.borrow_mut() = result; - return Parsed; - } -} - - diff --git a/argparse/src/from_cli.rs b/argparse/src/from_cli.rs deleted file mode 100644 index 7ea6d58..0000000 --- a/argparse/src/from_cli.rs +++ /dev/null @@ -1,100 +0,0 @@ -use std::str::FromStr; -use std::path::PathBuf; -use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr}; - -use super::FromCommandLine; - - -impl FromCommandLine for PathBuf { - fn from_argument(s: &str) -> Result { - Ok(From::from(s)) - } -} - -impl FromCommandLine for f32 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for f64 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} - -// TODO(tailhook) implement various radices for integer values -impl FromCommandLine for isize { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for i8 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for i16 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for i32 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for i64 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for usize { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for u8 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for u16 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for u32 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for u64 { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for bool { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for String { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|_| unreachable!()) - } -} -impl FromCommandLine for Ipv4Addr { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for Ipv6Addr { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} -impl FromCommandLine for SocketAddr { - fn from_argument(s: &str) -> Result { - FromStr::from_str(s).map_err(|e| format!("{:?}", e)) - } -} diff --git a/argparse/src/generic.rs b/argparse/src/generic.rs deleted file mode 100644 index 1b1b7dc..0000000 --- a/argparse/src/generic.rs +++ /dev/null @@ -1,133 +0,0 @@ -use std::cell::RefCell; -use std::str::FromStr; -use std::rc::Rc; - -use super::{StoreConst, Store, StoreOption, List, Collect, PushConst}; -use super::action::Action; -use super::action::{TypedAction, IFlagAction, IArgAction, IArgsAction}; -use super::action::ParseResult; -use super::action::ParseResult::{Parsed, Error}; -use super::action::Action::{Flag, Single, Push, Many}; - -pub struct StoreConstAction<'a, T: 'a> { - pub value: T, - pub cell: Rc>, -} - -pub struct PushConstAction<'a, T: 'a> { - pub value: T, - pub cell: Rc>>, -} - -pub struct StoreAction<'a, T: 'a> { - pub cell: Rc>, -} - -pub struct StoreOptionAction<'a, T: 'a> { - cell: Rc>>, -} - -pub struct ListAction<'a, T: 'a> { - cell: Rc>>, -} - -impl TypedAction for StoreConst { - fn bind<'x>(&self, cell: Rc>) -> Action<'x> { - let StoreConst(ref val) = *self; - return Flag(Box::new(StoreConstAction { cell: cell, value: val.clone() })); - } -} - -impl TypedAction> for PushConst { - fn bind<'x>(&self, cell: Rc>>) -> Action<'x> { - let PushConst(ref val) = *self; - return Flag(Box::new(PushConstAction { cell: cell, value: val.clone() })); - } -} - -impl TypedAction for Store { - fn bind<'x>(&self, cell: Rc>) -> Action<'x> { - return Single(Box::new(StoreAction { cell: cell })); - } -} - -impl TypedAction> for StoreOption { - fn bind<'x>(&self, cell: Rc>>) -> Action<'x> { - return Single(Box::new(StoreOptionAction { cell: cell })); - } -} - -impl TypedAction> for List { - fn bind<'x>(&self, cell: Rc>>) -> Action<'x> { - return Many(Box::new(ListAction { cell: cell })); - } -} - -impl TypedAction> for Collect { - fn bind<'x>(&self, cell: Rc>>) -> Action<'x> { - return Push(Box::new(ListAction { cell: cell })); - } -} - -impl<'a, T: Clone> IFlagAction for StoreConstAction<'a, T> { - fn parse_flag(&self) -> ParseResult { - let mut targ = self.cell.borrow_mut(); - **targ = self.value.clone(); - return Parsed; - } -} - -impl<'a, T: Clone> IFlagAction for PushConstAction<'a, T> { - fn parse_flag(&self) -> ParseResult { - let mut targ = self.cell.borrow_mut(); - targ.push(self.value.clone()); - return Parsed; - } -} - -impl<'a, T: FromStr> IArgAction for StoreAction<'a, T> { - fn parse_arg(&self, arg: &str) -> ParseResult { - match FromStr::from_str(arg) { - Ok(x) => { - **self.cell.borrow_mut() = x; - return Parsed; - } - Err(_) => { - return Error(format!("Bad value {}", arg)); - } - } - } -} - -impl<'a, T: FromStr> IArgAction for StoreOptionAction<'a, T> { - fn parse_arg(&self, arg: &str) -> ParseResult { - match FromStr::from_str(arg) { - Ok(x) => { - **self.cell.borrow_mut() = Some(x); - return Parsed; - } - Err(_) => { - return Error(format!("Bad value {}", arg)); - } - } - } -} - -impl<'a, T: FromStr + Clone> IArgsAction for ListAction<'a, T> { - fn parse_args(&self, args: &[&str]) -> ParseResult { - let mut result = vec!(); - for arg in args.iter() { - match FromStr::from_str(*arg) { - Ok(x) => { - result.push(x); - } - Err(_) => { - return Error(format!("Bad value {}", arg)); - } - } - } - **self.cell.borrow_mut() = result; - return Parsed; - } -} - diff --git a/argparse/src/help.rs b/argparse/src/help.rs deleted file mode 100644 index c7145be..0000000 --- a/argparse/src/help.rs +++ /dev/null @@ -1,93 +0,0 @@ -use std::str::CharIndices; -use std::io::Result as IoResult; -use std::io::Write; - -use super::action::{IFlagAction, ParseResult}; -use super::action::ParseResult::Help; - -pub struct HelpAction; - -impl IFlagAction for HelpAction { - fn parse_flag(&self) -> ParseResult { - return Help; - } -} - - -struct WordsIter<'a> { - data: &'a str, - iter: CharIndices<'a>, -} - -impl<'a> WordsIter<'a> { - fn new(data: &'a str) -> WordsIter<'a> { - return WordsIter { - data: data, - iter: data.char_indices(), - }; - } -} - -impl<'a> Iterator for WordsIter<'a> { - type Item = &'a str; - fn next(&mut self) -> Option<&'a str> { - let word_start; - loop { - let (idx, ch) = match self.iter.next() { - None => return None, - Some((idx, ch)) => ((idx, ch)), - }; - match ch { - ' ' | '\t' | '\r' | '\n' => continue, - _ => { - word_start = idx; - break; - } - } - } - loop { - let (idx, ch) = match self.iter.next() { - None => break, - Some((idx, ch)) => ((idx, ch)), - }; - match ch { - ' ' | '\t' | '\r' | '\n' => { - return Some(&self.data[word_start..idx]); - } - _ => continue, - } - } - return Some(&self.data[word_start..self.data.len()]); - } -} - -pub fn wrap_text(buf: &mut Write, data: &str, width: usize, indent: usize) - -> IoResult<()> -{ - let mut witer = WordsIter::new(data); - let mut off = indent; - match witer.next() { - None => { - return Ok(()); - } - Some(word) => { - try!(buf.write(word.as_bytes())); - off += word.len(); - } - } - for word in witer { - if off + word.len() + 1 > width { - try!(buf.write(b"\n")); - for _ in 0..indent { - try!(buf.write(b" ")); - } - off = indent; - } else { - try!(buf.write(b" ")); - off += 1; - } - try!(buf.write(word.as_bytes())); - off += word.len(); - } - return Ok(()); -} diff --git a/argparse/src/lib.rs b/argparse/src/lib.rs deleted file mode 100644 index 62b0cf9..0000000 --- a/argparse/src/lib.rs +++ /dev/null @@ -1,64 +0,0 @@ -#![crate_name = "argparse"] -#![crate_type = "lib"] - -pub use self::parser::{ArgumentParser, Ref}; - -pub mod action; -pub mod parser; -mod generic; -mod custom; -mod help; -mod print; - -mod bool; -mod num; -mod from_cli; - -pub trait FromCommandLine: Sized { - fn from_argument(s: &str) -> Result; -} - -// TODO(tailhook) make consts -pub struct StoreTrue; -pub struct StoreFalse; - -pub struct StoreConst(pub T); - -pub struct PushConst(pub T); - -pub struct Store; -pub struct Parse; - -pub struct StoreOption; -pub struct ParseOption; - -pub struct List; -pub struct ParseList; - -pub struct Collect; -pub struct ParseCollect; - -/// Print string and exit with status 0 -/// -/// Particularly useful for `--version` option and similar -pub struct Print(pub String); - -pub struct IncrBy(pub T); - -pub struct DecrBy(pub T); - - -#[cfg(test)] mod test_parser; -#[cfg(test)] mod test_bool; -#[cfg(test)] mod test_int; -#[cfg(test)] mod test_float; -#[cfg(test)] mod test_str; -#[cfg(test)] mod test_enum; -#[cfg(test)] mod test_pos; -#[cfg(test)] mod test_many; -#[cfg(test)] mod test_optional; -#[cfg(test)] mod test_usage; -#[cfg(test)] mod test_help; -#[cfg(test)] mod test_env; -#[cfg(test)] mod test_const; -#[cfg(test)] mod test_path; diff --git a/argparse/src/num.rs b/argparse/src/num.rs deleted file mode 100644 index 9f34de7..0000000 --- a/argparse/src/num.rs +++ /dev/null @@ -1,58 +0,0 @@ -use std::cell::RefCell; -use std::rc::Rc; -use std::ops::{Add, Sub}; - -use super::{IncrBy, DecrBy}; -use super::action::{TypedAction, Action, ParseResult}; -use super::action::ParseResult::Parsed; -use super::action::IFlagAction; -use super::action::Action::Flag; - -pub struct IncrByAction<'a, T: 'a> { - delta: T, - cell: Rc>, -} - -pub struct DecrByAction<'a, T: 'a> { - delta: T, - cell: Rc>, -} - -impl + Clone> TypedAction for IncrBy { - fn bind<'x>(&self, cell: Rc>) -> Action<'x> { - let IncrBy(ref delta) = *self; - return Flag(Box::new(IncrByAction { cell: cell, delta: delta.clone() })); - } -} - -impl + Clone> TypedAction for DecrBy { - fn bind<'x>(&self, cell: Rc>) -> Action<'x> { - let DecrBy(ref delta) = *self; - return Flag(Box::new(DecrByAction { cell: cell, delta: delta.clone() })); - } -} - -impl<'a, T: Add + Clone> IFlagAction for IncrByAction<'a, T> { - fn parse_flag(&self) -> ParseResult { - let oldval = { - let targ = self.cell.borrow(); - targ.clone() - }; - let mut targ = self.cell.borrow_mut(); - **targ = oldval + self.delta.clone(); - return Parsed; - } -} - -impl<'a, T: Sub + Clone> IFlagAction for DecrByAction<'a, T> { - fn parse_flag(&self) -> ParseResult { - let oldval = { - let targ = self.cell.borrow(); - targ.clone() - }; - let mut targ = self.cell.borrow_mut(); - **targ = oldval - self.delta.clone(); - return Parsed; - } -} - diff --git a/argparse/src/parser.rs b/argparse/src/parser.rs deleted file mode 100644 index ac7e3da..0000000 --- a/argparse/src/parser.rs +++ /dev/null @@ -1,967 +0,0 @@ -use std::env; -use std::io::{Write}; -use std::io::Result as IoResult; -use std::io::{stdout, stderr}; -use std::rc::Rc; -use std::cell::RefCell; -use std::iter::Peekable; -use std::slice::Iter; -use std::hash::Hash; -use std::hash::Hasher; -use std::str::FromStr; -use std::process::exit; - -#[allow(unused_imports)] #[allow(deprecated)] -use std::ascii::AsciiExt; - -use std::collections::HashMap; -use std::collections::hash_map::Entry; -use std::collections::HashSet; - -use super::action::{Action, ParseResult}; -use super::action::ParseResult::{Parsed, Help, Exit, Error}; -use super::action::TypedAction; -use super::action::Action::{Flag, Single, Push, Many}; -use super::action::IArgAction; -use super::generic::StoreAction; -use super::help::{HelpAction, wrap_text}; -use action::IFlagAction; - -use self::ArgumentKind::{Positional, ShortOption, LongOption, Delimiter}; - - -static OPTION_WIDTH: usize = 24; -static TOTAL_WIDTH: usize = 79; - - -enum ArgumentKind { - Positional, - ShortOption, - LongOption, - Delimiter, // Barely "--" -} - - -impl ArgumentKind { - fn check(name: &str) -> ArgumentKind { - let mut iter = name.chars(); - let char1 = iter.next(); - let char2 = iter.next(); - let char3 = iter.next(); - return match char1 { - Some('-') => match char2 { - Some('-') => match char3 { - Some(_) => LongOption, // --opt - None => Delimiter, // just -- - }, - Some(_) => ShortOption, // -opts - None => Positional, // single dash - }, - Some(_) | None => Positional, - } - } -} - -struct GenericArgument<'parser> { - id: usize, - varid: usize, - name: &'parser str, - help: &'parser str, - action: Action<'parser>, -} - -struct GenericOption<'parser> { - id: usize, - varid: Option, - names: Vec<&'parser str>, - help: &'parser str, - action: Action<'parser>, -} - -struct EnvVar<'parser> { - varid: usize, - name: &'parser str, - action: Box, -} - -impl<'a> Hash for GenericOption<'a> { - fn hash(&self, state: &mut H) where H: Hasher { - self.id.hash(state); - } -} - -impl<'a> PartialEq for GenericOption<'a> { - fn eq(&self, other: &GenericOption<'a>) -> bool { - return self.id == other.id; - } -} - -impl<'a> Eq for GenericOption<'a> {} - -impl<'a> Hash for GenericArgument<'a> { - fn hash(&self, state: &mut H) where H: Hasher { - self.id.hash(state); - } -} - -impl<'a> PartialEq for GenericArgument<'a> { - fn eq(&self, other: &GenericArgument<'a>) -> bool { - return self.id == other.id; - } -} - -impl<'a> Eq for GenericArgument<'a> {} - -pub struct Var { - id: usize, - metavar: String, - required: bool, -} - -impl Hash for Var { - fn hash(&self, state: &mut H) where H: Hasher { - self.id.hash(state); - } -} - -impl PartialEq for Var { - fn eq(&self, other: &Var) -> bool { - return self.id == other.id; - } -} - -impl Eq for Var {} - -struct Context<'ctx, 'parser: 'ctx> { - parser: &'ctx ArgumentParser<'parser>, - set_vars: HashSet, - list_options: HashMap>, Vec<&'ctx str>>, - list_arguments: HashMap>, Vec<&'ctx str>>, - arguments: Vec<&'ctx str>, - iter: Peekable>, - stderr: &'ctx mut (Write + 'ctx), -} - -impl<'a, 'b> Context<'a, 'b> { - - fn parse_option(&mut self, opt: Rc>, - optarg: Option<&'a str>) - -> ParseResult - { - let value = match optarg { - Some(value) => value, - None => match self.iter.next() { - Some(value) => { - &value[..] - } - None => { - return match opt.action { - Many(_) => Parsed, - _ => Error(format!( - // TODO(tailhook) is {:?} ok? - "Option {:?} requires an argument", opt.names)), - }; - } - }, - }; - match opt.varid { - Some(varid) => { self.set_vars.insert(varid); } - None => {} - } - match opt.action { - Single(ref action) => { - return action.parse_arg(value); - } - Push(_) => { - (match self.list_options.entry(opt.clone()) { - Entry::Occupied(occ) => occ.into_mut(), - Entry::Vacant(vac) => vac.insert(Vec::new()), - }).push(value); - return Parsed; - } - Many(_) => { - let vec = match self.list_options.entry(opt.clone()) { - Entry::Occupied(occ) => occ.into_mut(), - Entry::Vacant(vac) => vac.insert(Vec::new()), - }; - vec.push(value); - match optarg { - Some(_) => return Parsed, - _ => {} - } - loop { - match self.iter.peek() { - None => { break; } - Some(arg) if arg.starts_with("-") => { - break; - } - Some(value) => { - vec.push(&value[..]); - } - } - self.iter.next(); - } - return Parsed; - } - _ => panic!(), - }; - } - - fn parse_long_option(&mut self, arg: &'a str) -> ParseResult { - let mut equals_iter = arg.splitn(2, '='); - let optname = equals_iter.next().unwrap(); - let valueref = equals_iter.next(); - let opt = self.parser.long_options.get(&optname.to_string()); - match opt { - Some(opt) => { - match opt.action { - Flag(ref action) => { - match valueref { - Some(_) => { - return Error(format!( - "Option {} does not accept an argument", - optname)); - } - None => { - match opt.varid { - Some(varid) => { - self.set_vars.insert(varid); - } - None => {} - } - return action.parse_flag(); - } - } - } - Single(_) | Push(_) | Many(_) => { - return self.parse_option(opt.clone(), valueref); - } - } - } - None => { - return Error(format!("Unknown option {}", arg)); - } - } - } - - fn parse_short_options<'x>(&'x mut self, arg: &'a str) -> ParseResult { - let mut iter = arg.char_indices(); - iter.next(); - for (idx, ch) in iter { - let opt = match self.parser.short_options.get(&ch) { - Some(opt) => { opt } - None => { - return Error(format!("Unknown short option \"{}\"", ch)); - } - }; - let res = match opt.action { - Flag(ref action) => { - match opt.varid { - Some(varid) => { self.set_vars.insert(varid); } - None => {} - } - action.parse_flag() - } - Single(_) | Push(_) | Many(_) => { - let value; - if idx + 1 < arg.len() { - value = Some(&arg[idx+1..arg.len()]); - } else { - value = None; - } - return self.parse_option(opt.clone(), value); - } - }; - match res { - Parsed => { continue; } - x => { return x; } - } - } - return Parsed; - } - - fn postpone_argument(&mut self, arg: &'a str) { - self.arguments.push(arg); - } - - fn parse_options(&mut self) -> ParseResult { - self.iter.next(); // Command name - loop { - let next = self.iter.next(); - let arg = match next { - Some(arg) => { arg } - None => { break; } - }; - let res = match ArgumentKind::check(&arg[..]) { - Positional => { - self.postpone_argument(&arg[..]); - if self.parser.stop_on_first_argument { - break; - } - continue; - } - LongOption => self.parse_long_option(&arg[..]), - ShortOption => self.parse_short_options(&arg[..]), - Delimiter => { - if !self.parser.silence_double_dash { - self.postpone_argument("--"); - } - break; - } - }; - match res { - Parsed => continue, - _ => return res, - } - } - - loop { - match self.iter.next() { - None => break, - Some(arg) => self.postpone_argument(&arg[..]), - } - } - return Parsed; - } - - fn parse_arguments(&mut self) -> ParseResult { - let mut pargs = self.parser.arguments.iter(); - for arg in self.arguments.iter() { - let opt; - loop { - match pargs.next() { - Some(option) => { - if self.set_vars.contains(&option.varid) { - continue; - } - opt = option; - break; - } - None => match self.parser.catchall_argument { - Some(ref option) => { - opt = option; - break; - } - None => return Error(format!( - "Unexpected argument {}", arg)), - } - }; - } - let res = match opt.action { - Single(ref act) => { - self.set_vars.insert(opt.varid); - act.parse_arg(*arg) - }, - Many(_) | Push(_) => { - (match self.list_arguments.entry(opt.clone()) { - Entry::Occupied(occ) => occ.into_mut(), - Entry::Vacant(vac) => vac.insert(Vec::new()), - }).push(*arg); - Parsed - }, - _ => unreachable!(), - }; - match res { - Parsed => continue, - _ => return res, - } - } - return Parsed; - } - - fn parse_list_vars(&mut self) -> ParseResult { - for (opt, lst) in self.list_options.iter() { - match opt.action { - Push(ref act) | Many(ref act) => { - let res = act.parse_args(&lst[..]); - match res { - Parsed => continue, - _ => return res, - } - } - _ => panic!(), - } - } - for (opt, lst) in self.list_arguments.iter() { - match opt.action { - Push(ref act) | Many(ref act) => { - let res = act.parse_args(&lst[..]); - match res { - Parsed => continue, - _ => return res, - } - } - _ => panic!(), - } - } - return Parsed; - } - - fn parse_env_vars(&mut self) -> ParseResult { - for evar in self.parser.env_vars.iter() { - match env::var(evar.name) { - Ok(val) => { - match evar.action.parse_arg(&val[..]) { - Parsed => { - self.set_vars.insert(evar.varid); - continue; - } - Error(err) => { - write!(self.stderr, - "WARNING: Environment variable {}: {}\n", - evar.name, err).ok(); - } - _ => unreachable!(), - } - } - Err(_) => {} - } - } - return Parsed; - } - - fn check_required(&mut self) -> ParseResult { - // Check for required arguments - for var in self.parser.vars.iter() { - if var.required && !self.set_vars.contains(&var.id) { - // First try positional arguments - for opt in self.parser.arguments.iter() { - if opt.varid == var.id { - return Error(format!( - "Argument {} is required", opt.name)); - } - } - // Then options - let mut all_options = vec!(); - for opt in self.parser.options.iter() { - match opt.varid { - Some(varid) if varid == var.id => {} - _ => { continue } - } - all_options.extend(opt.names.clone().into_iter()); - } - if all_options.len() > 1 { - return Error(format!( - "One of the options {:?} is required", all_options)); - } else if all_options.len() == 1 { - return Error(format!( - "Option {:?} is required", all_options)); - } - // Then envvars - for envvar in self.parser.env_vars.iter() { - if envvar.varid == var.id { - return Error(format!( - "Environment var {} is required", envvar.name)); - } - } - } - } - return Parsed; - } - - fn parse(parser: &ArgumentParser, args: &Vec, stderr: &mut Write) - -> ParseResult - { - let mut ctx = Context { - parser: parser, - iter: args.iter().peekable(), - set_vars: HashSet::new(), - list_options: HashMap::new(), - list_arguments: HashMap::new(), - arguments: Vec::new(), - stderr: stderr, - }; - - match ctx.parse_env_vars() { - Parsed => {} - x => { return x; } - } - - match ctx.parse_options() { - Parsed => {} - x => { return x; } - } - - match ctx.parse_arguments() { - Parsed => {} - x => { return x; } - } - - match ctx.parse_list_vars() { - Parsed => {} - x => { return x; } - } - - match ctx.check_required() { - Parsed => {} - x => { return x; } - } - - return Parsed; - } -} - -pub struct Ref<'parser:'refer, 'refer, T: 'parser> { - cell: Rc>, - varid: usize, - parser: &'refer mut ArgumentParser<'parser>, -} - -impl<'parser, 'refer, T> Ref<'parser, 'refer, T> { - - pub fn add_option<'x, A: TypedAction>(&'x mut self, - names: &[&'parser str], action: A, help: &'parser str) - -> &'x mut Ref<'parser, 'refer, T> - { - { - let var = &mut self.parser.vars[self.varid]; - if var.metavar.len() == 0 { - let mut longest_name = names[0]; - let mut llen = longest_name.len(); - for name in names.iter() { - if name.len() > llen { - longest_name = *name; - llen = longest_name.len(); - } - } - if llen > 2 { - var.metavar = longest_name[2..llen] - .to_ascii_uppercase().replace("-", "_"); - } - } - } - self.parser.add_option_for(Some(self.varid), names, - action.bind(self.cell.clone()), - help); - return self; - } - - pub fn add_argument<'x, A: TypedAction>(&'x mut self, - name: &'parser str, action: A, help: &'parser str) - -> &'x mut Ref<'parser, 'refer, T> - { - let act = action.bind(self.cell.clone()); - let opt = Rc::new(GenericArgument { - id: self.parser.arguments.len(), - varid: self.varid, - name: name, - help: help, - action: act, - }); - match opt.action { - Flag(_) => panic!("Flag arguments can't be positional"), - Many(_) | Push(_) => { - match self.parser.catchall_argument { - Some(ref y) => panic!(format!( - "Option {} conflicts with option {}", - name, y.name)), - None => {}, - } - self.parser.catchall_argument = Some(opt); - } - Single(_) => { - self.parser.arguments.push(opt); - } - } - { - let var = &mut self.parser.vars[self.varid]; - if var.metavar.len() == 0 { - var.metavar = name.to_string(); - } - } - return self; - } - - pub fn metavar<'x>(&'x mut self, name: &str) - -> &'x mut Ref<'parser, 'refer, T> - { - { - let var = &mut self.parser.vars[self.varid]; - var.metavar = name.to_string(); - } - return self; - } - - pub fn required<'x>(&'x mut self) - -> &'x mut Ref<'parser, 'refer, T> - { - { - let var = &mut self.parser.vars[self.varid]; - var.required = true; - } - return self; - } -} - -impl<'parser, 'refer, T: 'static + FromStr> Ref<'parser, 'refer, T> { - pub fn envvar<'x>(&'x mut self, varname: &'parser str) - -> &'x mut Ref<'parser, 'refer, T> - { - self.parser.env_vars.push(Rc::new(EnvVar { - varid: self.varid, - name: varname, - action: Box::new(StoreAction { cell: self.cell.clone() }), - })); - return self; - } -} - -/// The main argument parser class -pub struct ArgumentParser<'parser> { - description: &'parser str, - vars: Vec>, - options: Vec>>, - arguments: Vec>>, - env_vars: Vec>>, - catchall_argument: Option>>, - short_options: HashMap>>, - long_options: HashMap>>, - stop_on_first_argument: bool, - silence_double_dash: bool, -} - - - -impl<'parser> ArgumentParser<'parser> { - - /// Create an empty argument parser - pub fn new() -> ArgumentParser<'parser> { - - let mut ap = ArgumentParser { - description: "", - vars: Vec::new(), - env_vars: Vec::new(), - arguments: Vec::new(), - catchall_argument: None, - options: Vec::new(), - short_options: HashMap::new(), - long_options: HashMap::new(), - stop_on_first_argument: false, - silence_double_dash: true, - }; - ap.add_option_for(None, &["-h", "--help"], Flag(Box::new(HelpAction)), - "Show this help message and exit"); - return ap; - } - - /// Borrow mutable variable for an argument - /// - /// This returns `Ref` object which should be used configure the option - pub fn refer<'x, T>(&'x mut self, val: &'parser mut T) - -> Box> - { - let cell = Rc::new(RefCell::new(val)); - let id = self.vars.len(); - self.vars.push(Box::new(Var { - id: id, - required: false, - metavar: "".to_string(), - })); - return Box::new(Ref { - cell: cell.clone(), - varid: id, - parser: self, - }); - } - - /// Add option to argument parser - /// - /// This is only useful for options that don't store value. For - /// example `Print(...)` - pub fn add_option(&mut self, - names: &[&'parser str], action: F, help: &'parser str) - { - self.add_option_for(None, names, Flag(Box::new(action)), help); - } - - /// Set description of the command - pub fn set_description(&mut self, descr: &'parser str) { - self.description = descr; - } - - fn add_option_for(&mut self, var: Option, - names: &[&'parser str], - action: Action<'parser>, help: &'parser str) - { - let opt = Rc::new(GenericOption { - id: self.options.len(), - varid: var, - names: names.to_vec(), - help: help, - action: action, - }); - - if names.len() < 1 { - panic!("At least one name for option must be specified"); - } - for nameptr in names.iter() { - let name = *nameptr; - match ArgumentKind::check(name) { - Positional|Delimiter => { - panic!("Bad argument name {}", name); - } - LongOption => { - self.long_options.insert( - name.to_string(), opt.clone()); - } - ShortOption => { - if name.len() > 2 { - panic!("Bad short argument {}", name); - } - self.short_options.insert( - name.as_bytes()[1] as char, opt.clone()); - } - } - } - self.options.push(opt); - } - - /// Print help - /// - /// Usually command-line option is used for printing help, - /// this is here for any awkward cases - pub fn print_help(&self, name: &str, writer: &mut Write) -> IoResult<()> { - return HelpFormatter::print_help(self, name, writer); - } - - /// Print usage - /// - /// Usually printed into stderr on error of command-line parsing - pub fn print_usage(&self, name: &str, writer: &mut Write) -> IoResult<()> - { - return HelpFormatter::print_usage(self, name, writer); - } - - /// Parse arguments - /// - /// This is most powerful method. Usually you need `parse_args` - /// or `parse_args_or_exit` instead - pub fn parse(&self, args: Vec, - stdout: &mut Write, stderr: &mut Write) - -> Result<(), i32> - { - let name = if args.len() > 0 { &args[0][..] } else { "unknown" }; - match Context::parse(self, &args, stderr) { - Parsed => return Ok(()), - Exit => return Err(0), - Help => { - self.print_help(name, stdout).unwrap(); - return Err(0); - } - Error(message) => { - self.error(&name[..], &message[..], stderr); - return Err(2); - } - } - } - - /// Write an error similar to one produced by the library itself - /// - /// Only needed if you like to do some argument validation that is out - /// of scope of the argparse - pub fn error(&self, command: &str, message: &str, writer: &mut Write) { - self.print_usage(command, writer).unwrap(); - write!(writer, "{}: {}\n", command, message).ok(); - } - - /// Configure parser to ignore options when first non-option argument is - /// encountered. - /// - /// Useful for commands that want to pass following options to the - /// subcommand or subprocess, but need some options to be set before - /// command is specified. - pub fn stop_on_first_argument(&mut self, want_stop: bool) { - self.stop_on_first_argument = want_stop; - } - - /// Do not put double-dash (bare `--`) into argument - /// - /// The double-dash is used to stop parsing options and treat all the - /// following tokens as the arguments regardless of whether they start - /// with dash (minus) or not. - /// - /// The method only useful for `List` arguments. On by default. The method - /// allows to set option to `false` so that `cmd xx -- yy` will get - /// ``xx -- yy`` as arguments instead of ``xx yy`` by default. This is - /// useful if your ``--`` argument is meaningful. Only first double-dash - /// is ignored by default. - pub fn silence_double_dash(&mut self, silence: bool) { - self.silence_double_dash = silence; - } - - /// Convenience method to parse arguments - /// - /// On error returns error code that is supposed to be returned by - /// an application. (i.e. zero on `--help` and `2` on argument error) - pub fn parse_args(&self) -> Result<(), i32> { - // TODO(tailhook) can we get rid of collect? - return self.parse(env::args().collect(), - &mut stdout(), &mut stderr()); - } - - /// The simplest conveninece method - /// - /// The method returns only in case of successful parsing or exits with - /// appropriate code (including successful on `--help`) otherwise. - pub fn parse_args_or_exit(&self) { - // TODO(tailhook) can we get rid of collect? - self.parse(env::args().collect(), &mut stdout(), &mut stderr()) - .map_err(|c| exit(c)) - .ok(); - } -} - -struct HelpFormatter<'a, 'b: 'a> { - name: &'a str, - parser: &'a ArgumentParser<'b>, - buf: &'a mut (Write + 'a), -} - -impl<'a, 'b> HelpFormatter<'a, 'b> { - pub fn print_usage(parser: &ArgumentParser, name: &str, writer: &mut Write) - -> IoResult<()> - { - return HelpFormatter { parser: parser, name: name, buf: writer } - .write_usage(); - } - - pub fn print_help(parser: &ArgumentParser, name: &str, writer: &mut Write) - -> IoResult<()> - { - return HelpFormatter { parser: parser, name: name, buf: writer } - .write_help(); - } - - pub fn print_argument(&mut self, arg: &GenericArgument<'b>) - -> IoResult<()> - { - let mut num = 2; - try!(write!(self.buf, " {}", arg.name)); - num += arg.name.len(); - if num >= OPTION_WIDTH { - try!(write!(self.buf, "\n")); - for _ in 0..OPTION_WIDTH { - try!(write!(self.buf, " ")); - } - } else { - for _ in num..OPTION_WIDTH { - try!(write!(self.buf, " ")); - } - } - try!(wrap_text(self.buf, arg.help, TOTAL_WIDTH, OPTION_WIDTH)); - try!(write!(self.buf, "\n")); - return Ok(()); - } - - pub fn print_option(&mut self, opt: &GenericOption<'b>) -> IoResult<()> { - let mut num = 2; - try!(write!(self.buf, " ")); - let mut niter = opt.names.iter(); - let name = niter.next().unwrap(); - try!(write!(self.buf, "{}", name)); - num += name.len(); - for name in niter { - try!(write!(self.buf, ",")); - try!(write!(self.buf, "{}", name)); - num += name.len() + 1; - } - match opt.action { - Flag(_) => {} - Single(_) | Push(_) | Many(_) => { - try!(write!(self.buf, " ")); - let var = &self.parser.vars[opt.varid.unwrap()]; - try!(write!(self.buf, "{}", &var.metavar[..])); - num += var.metavar.len() + 1; - } - } - if num >= OPTION_WIDTH { - try!(write!(self.buf, "\n")); - for _ in 0..OPTION_WIDTH { - try!(write!(self.buf, " ")); - } - } else { - for _ in num..OPTION_WIDTH { - try!(write!(self.buf, " ")); - } - } - try!(wrap_text(self.buf, opt.help, TOTAL_WIDTH, OPTION_WIDTH)); - try!(write!(self.buf, "\n")); - return Ok(()); - } - - fn write_help(&mut self) -> IoResult<()> { - try!(self.write_usage()); - try!(write!(self.buf, "\n")); - if self.parser.description.len() > 0 { - try!(wrap_text(self.buf, self.parser.description,TOTAL_WIDTH, 0)); - try!(write!(self.buf, "\n")); - } - if self.parser.arguments.len() > 0 - || self.parser.catchall_argument.is_some() - { - try!(write!(self.buf, "\nPositional arguments:\n")); - for arg in self.parser.arguments.iter() { - try!(self.print_argument(&**arg)); - } - match self.parser.catchall_argument { - Some(ref opt) => { - try!(self.print_argument(&**opt)); - } - None => {} - } - } - if self.parser.short_options.len() > 0 - || self.parser.long_options.len() > 0 - { - try!(write!(self.buf, "\nOptional arguments:\n")); - for opt in self.parser.options.iter() { - try!(self.print_option(&**opt)); - } - } - return Ok(()); - } - - fn write_usage(&mut self) -> IoResult<()> { - try!(write!(self.buf, "Usage:\n ")); - try!(write!(self.buf, "{}", self.name)); - if self.parser.options.len() != 0 { - if self.parser.short_options.len() > 1 - || self.parser.long_options.len() > 1 - { - try!(write!(self.buf, " [OPTIONS]")); - } - for opt in self.parser.arguments.iter() { - let var = &self.parser.vars[opt.varid]; - try!(write!(self.buf, " ")); - if !var.required { - try!(write!(self.buf, "[")); - } - try!(write!(self.buf, "{}", - &opt.name.to_ascii_uppercase()[..])); - if !var.required { - try!(write!(self.buf, "]")); - } - } - match self.parser.catchall_argument { - Some(ref opt) => { - let var = &self.parser.vars[opt.varid]; - try!(write!(self.buf, " ")); - if !var.required { - try!(write!(self.buf, "[")); - } - try!(write!(self.buf, "{}", - &opt.name.to_ascii_uppercase()[..])); - if !var.required { - try!(write!(self.buf, " ...]")); - } else { - try!(write!(self.buf, " [...]")); - } - } - None => {} - } - } - try!(write!(self.buf, "\n")); - return Ok(()); - } - -} diff --git a/argparse/src/print.rs b/argparse/src/print.rs deleted file mode 100644 index d0335c5..0000000 --- a/argparse/src/print.rs +++ /dev/null @@ -1,13 +0,0 @@ -use Print; -use action::{IFlagAction, ParseResult}; - -impl IFlagAction for Print { - fn parse_flag(&self) -> ParseResult { - if self.0.ends_with("\n") { - print!("{}", self.0); - } else { - println!("{}", self.0); - } - return ParseResult::Exit; - } -} diff --git a/argparse/src/test_bool.rs b/argparse/src/test_bool.rs deleted file mode 100644 index a30cf3c..0000000 --- a/argparse/src/test_bool.rs +++ /dev/null @@ -1,98 +0,0 @@ -use parser::ArgumentParser; -use super::Store; -use super::{StoreTrue, StoreFalse}; -use test_parser::{check_ok}; - -fn store_true(args: &[&str]) -> bool { - let mut verbose = false; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut verbose) - .add_option(&["-t", "--true"], StoreTrue, - "Store true action"); - check_ok(&ap, args); - } - return verbose; -} - -#[test] -fn test_store_true() { - assert!(!store_true(&["./argparse_test"])); - assert!(store_true(&["./argparse_test", "--true"])); -} - -fn store_false(args: &[&str]) -> bool { - let mut verbose = true; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut verbose) - .add_option(&["-f", "--false"], StoreFalse, - "Store false action"); - check_ok(&ap, args); - } - return verbose; -} -#[test] -fn test_store_false() { - assert!(store_false(&["./argparse_test"])); - assert!(!store_false(&["./argparse_test", "--false"])); -} - -fn store_bool(args: &[&str]) -> bool { - let mut verbose = false; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut verbose) - .add_option(&["-f", "--false"], StoreFalse, - "Store false action") - .add_option(&["-t", "--true"], StoreTrue, - "Store false action"); - check_ok(&ap, args); - } - return verbose; -} - -#[test] -fn test_bool() { - assert!(!store_bool(&["./argparse_test"])); - assert!(store_bool(&["./argparse_test", "-t"])); - assert!(!store_bool(&["./argparse_test", "-f"])); - assert!(store_bool(&["./argparse_test", "-fft"])); - assert!(!store_bool(&["./argparse_test", "-fffft", "-f"])); - assert!(store_bool(&["./argparse_test", "--false", "-fffft", "-f", - "--true"])); -} - -fn set_bool(args: &[&str]) -> bool { - let mut verbose = false; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut verbose) - .add_option(&["-s", "--set"], Store, - "Set boolean value"); - check_ok(&ap, args); - } - return verbose; -} - - -#[test] -fn test_set_bool() { - assert!(!set_bool(&["./argparse_test"])); - assert!(set_bool(&["./argparse_test", "-strue"])); - assert!(!set_bool(&["./argparse_test", "-sfalse"])); - - // Unfortunately other values do not work -} - -#[test] -#[should_panic(expected="Bad value yes")] -fn test_bad_bools1() { - assert!(!set_bool(&["./argparse_test", "-syes"])); -} - -#[test] -#[should_panic(expected="Bad value no")] -fn test_bad_bools2() { - assert!(!set_bool(&["./argparse_test", "-sno"])); -} diff --git a/argparse/src/test_const.rs b/argparse/src/test_const.rs deleted file mode 100644 index b12e3d8..0000000 --- a/argparse/src/test_const.rs +++ /dev/null @@ -1,28 +0,0 @@ -use parser::ArgumentParser; -use super::{PushConst}; -use test_parser::{check_ok}; - - -fn push_const(args: &[&str]) -> Vec { - let mut res = vec!(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut res) - .add_option(&["-o", "--one"], PushConst(1), - "Add one to the list") - .add_option(&["-t", "--two"], PushConst(2), - "Add two to the list") - .add_option(&["-3", "--three"], PushConst(3), - "Add three to the list"); - check_ok(&ap, args); - } - return res; -} - -#[test] -fn test_push() { - assert_eq!(push_const(&["./argparse_test"]), vec!()); - assert_eq!(push_const(&["./argparse_test", "--one"]), vec!(1)); - assert_eq!(push_const(&["./argparse_test", "-3"]), vec!(3)); - assert_eq!(push_const(&["./argparse_test", "-oo3tt"]), vec!(1, 1, 3, 2, 2)); -} diff --git a/argparse/src/test_enum.rs b/argparse/src/test_enum.rs deleted file mode 100644 index 5205738..0000000 --- a/argparse/src/test_enum.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::str::FromStr; - -use parser::ArgumentParser; -use super::Store; -use test_parser::{check_ok}; - -use self::Greeting::{Hello, Hi, NoGreeting}; - - -#[derive(PartialEq, Eq, Debug)] -enum Greeting { - Hello, - Hi, - NoGreeting, -} - -impl FromStr for Greeting { - type Err = (); - fn from_str(src: &str) -> Result { - return match src { - "hello" => Ok(Hello), - "hi" => Ok(Hi), - _ => Err(()), - }; - } -} - -fn parse_enum(args: &[&str]) -> Greeting { - let mut val = NoGreeting; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-g"], Store, - "Greeting"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_parse_enum() { - assert_eq!(parse_enum(&["./argparse_test"]), NoGreeting); - assert_eq!(parse_enum(&["./argparse_test", "-ghello"]), Hello); - assert_eq!(parse_enum(&["./argparse_test", "-ghi"]), Hi); -} - -#[test] -#[should_panic] -fn test_parse_error() { - parse_enum(&["./argparse_test", "-ghell"]); -} diff --git a/argparse/src/test_env.rs b/argparse/src/test_env.rs deleted file mode 100644 index 2e1b649..0000000 --- a/argparse/src/test_env.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::env; - -use parser::ArgumentParser; -use super::Store; -use test_parser::{check_ok}; - - -fn required(args: &[&str]) -> (isize, isize) { - let mut val1 = 1isize; - let mut val2 = 2isize; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val1) - .add_option(&["--v1"], Store, "The value 1") - .add_argument("v1", Store, "The value 1") - .envvar("TEST_ENV_REQUIRED_V1") - .required(); - ap.refer(&mut val2) - .add_argument("v2", Store, "The value 2"); - check_ok(&ap, args); - } - return (val1, val2) -} - -#[test] -#[should_panic] -fn test_required() { - env::set_var("TEST_ENV_REQUIRED_V1", "some_crap"); - required(&["./argparse_test"]); - env::remove_var("TEST_ENV_REQUIRED_V1"); -} - -#[test] -fn test_req() { - env::set_var("TEST_ENV_REQUIRED_V1", "some_crap"); - assert_eq!(required(&["./argparse_test", "10"]), (10, 2)); - assert_eq!(required(&["./argparse_test", "11", "21"]), (11, 21)); - assert_eq!(required(&["./argparse_test", "--v1=7"]), (7, 2)); - env::set_var("TEST_ENV_REQUIRED_V1", "9"); - assert_eq!(required(&["./argparse_test", "10"]), (9, 10)); - assert_eq!(required(&["./argparse_test", "7", "--v1=15"]), (15, 7)); - env::remove_var("TEST_ENV_REQUIRED_V1"); -} diff --git a/argparse/src/test_float.rs b/argparse/src/test_float.rs deleted file mode 100644 index 9ef0f56..0000000 --- a/argparse/src/test_float.rs +++ /dev/null @@ -1,50 +0,0 @@ -use parser::ArgumentParser; -use super::{IncrBy,DecrBy}; -use super::Store; -use test_parser::{check_ok}; - -fn incr_decr(args: &[&str]) -> f32 { - let mut val = 0f32; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-d", "--decr"], DecrBy(0.25f32), - "Decrement value") - .add_option(&["-i", "--incr"], IncrBy(0.5f32), - "Increment value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_incr_decr() { - assert_eq!(incr_decr(&["./argparse_test", - "--incr", "-iii"]), 2.0); - assert_eq!(incr_decr(&["./argparse_test", - "-iiddd", "--incr", "-iii"]), 2.25); -} - -#[test] -fn test_float() { - let mut val = 0.1; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-s", "--set"], Store, - "Set float value"); - check_ok(&ap, &["./argparse_test", "-s", "15.125"]); - } - assert_eq!(val, 15.125); -} - -#[test] -#[should_panic] -fn test_fail() { - let mut val = 0.1; - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-s", "--set"], Store, - "Set float value"); - check_ok(&ap, &["./argparse_test", "-s", "test"]); -} diff --git a/argparse/src/test_help.rs b/argparse/src/test_help.rs deleted file mode 100644 index f23b14b..0000000 --- a/argparse/src/test_help.rs +++ /dev/null @@ -1,154 +0,0 @@ -use std::str::from_utf8; - -use parser::ArgumentParser; -use super::{Store, List}; - -#[test] -fn test_empty() { - let mut ap = ArgumentParser::new(); - let mut buf = Vec::::new(); - ap.set_description("Test program"); - assert!(ap.print_help("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n".to_string() - + " ./argparse_test\n" - + "\n" - + "Test program\n" - + "\n" - + "Optional arguments:\n" - + " -h,--help Show this help message and exit\n" - , from_utf8(&buf[..]).unwrap().to_string()); -} - -#[test] -fn test_options() { - let mut val = 0; - let mut val2 = 0; - let mut ap = ArgumentParser::new(); - ap.set_description("Test program. The description of the program is ought - to be very long, because we want to test how word wrapping works for - it. So some more text would be ok for the test"); - ap.refer(&mut val) - .add_option(&["--value"], Store, - "Set integer value"); - ap.refer(&mut val2) - .add_option(&["-L", "--long-option"], Store, - "Long option value"); - let mut buf = Vec::::new(); - assert!(ap.print_help("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n".to_string() - + " ./argparse_test [OPTIONS] - -Test program. The description of the program is ought to be very long, because -we want to test how word wrapping works for it. So some more text would be ok -for the test\n" - + "\n" - + "Optional arguments:\n" - + " -h,--help Show this help message and exit\n" - + " --value VALUE Set integer value\n" - + " -L,--long-option LONG_OPTION\n" - + " Long option value\n" - , from_utf8(&buf[..]).unwrap().to_string()); -} - -#[test] -fn test_argument() { - let mut val = 0; - let mut ap = ArgumentParser::new(); - ap.set_description("Test program"); - ap.refer(&mut val) - .add_argument("value", Store, - "Integer value"); - let mut buf = Vec::::new(); - assert!(ap.print_help("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n".to_string() - + " ./argparse_test [VALUE]\n" - + "\n" - + "Test program\n" - + "\n" - + "Positional arguments:\n" - + " value Integer value\n" - + "\n" - + "Optional arguments:\n" - + " -h,--help Show this help message and exit\n" - , from_utf8(&buf[..]).unwrap().to_string()); -} - -#[test] -fn test_arguments() { - let mut v1 = 0; - let mut v2 = Vec::::new(); - let mut ap = ArgumentParser::new(); - ap.set_description("Test program"); - ap.refer(&mut v1) - .add_argument("v1", Store, - "Integer value 1"); - ap.refer(&mut v2) - .add_argument("v2", List, - "More values"); - let mut buf = Vec::::new(); - assert!(ap.print_help("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n".to_string() - + " ./argparse_test [V1] [V2 ...]\n" - + "\n" - + "Test program\n" - + "\n" - + "Positional arguments:\n" - + " v1 Integer value 1\n" - + " v2 More values\n" - + "\n" - + "Optional arguments:\n" - + " -h,--help Show this help message and exit\n" - , from_utf8(&buf[..]).unwrap().to_string()); -} - -#[test] -fn test_req_arguments() { - let mut v1 = 0; - let mut v2 = Vec::::new(); - let mut ap = ArgumentParser::new(); - ap.set_description("Test program"); - ap.refer(&mut v1) - .add_argument("v1", Store, - "Integer value 1") - .required(); - ap.refer(&mut v2) - .add_argument("v2", List, - "More values") - .required(); - let mut buf = Vec::::new(); - assert!(ap.print_help("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n".to_string() - + " ./argparse_test V1 V2 [...]\n" - + "\n" - + "Test program\n" - + "\n" - + "Positional arguments:\n" - + " v1 Integer value 1\n" - + " v2 More values\n" - + "\n" - + "Optional arguments:\n" - + " -h,--help Show this help message and exit\n" - , from_utf8(&buf[..]).unwrap().to_string()); -} - -#[test] -fn test_metavar() { - let mut val2 = 0; - let mut ap = ArgumentParser::new(); - ap.set_description("Test program."); - ap.refer(&mut val2) - .add_option(&["-L", "--long-option"], Store, - "Long option value") - .metavar("VAL"); - let mut buf = Vec::::new(); - assert!(ap.print_help("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n".to_string() - + " ./argparse_test [OPTIONS]\n" - + "\n" - + "Test program.\n" - + "\n" - + "Optional arguments:\n" - + " -h,--help Show this help message and exit\n" - + " -L,--long-option VAL Long option value\n" - , from_utf8(&buf[..]).unwrap().to_string()); -} diff --git a/argparse/src/test_int.rs b/argparse/src/test_int.rs deleted file mode 100644 index 1826eaf..0000000 --- a/argparse/src/test_int.rs +++ /dev/null @@ -1,107 +0,0 @@ -use parser::ArgumentParser; -use super::{IncrBy,DecrBy}; -use super::Store; -use test_parser::{check_ok}; - -fn incr_int(args: &[&str]) -> usize { - let mut val = 0; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-i", "--incr"], IncrBy(1usize), - "Increment value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_incr_int() { - assert_eq!(incr_int(&["./argparse_test"]), 0); - assert_eq!(incr_int(&["./argparse_test", "--incr"]), 1); - assert_eq!(incr_int(&["./argparse_test", "-iiiii"]), 5); -} - -fn decr_int(args: &[&str]) -> isize { - let mut val = 5; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-d", "--decr"], DecrBy(1isize), - "Decrement value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_decr_int() { - assert_eq!(decr_int(&["./argparse_test"]), 5); - assert_eq!(decr_int(&["./argparse_test", "--decr"]), 4); - assert_eq!(decr_int(&["./argparse_test", "-dddddd"]), -1); -} - -#[test] -fn test_incr_decr() { - let mut val = 0; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-d", "--decr"], DecrBy(1isize), - "Decrement value") - .add_option(&["-i", "--incr"], IncrBy(1isize), - "Increment value"); - check_ok(&ap, &["./argparse_test", - "-iiddd", "--incr", "-iii"]); - } - assert_eq!(val, 3); -} - -fn set_int(args: &[&str]) -> isize { - let mut val = 0; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-s", "--set"], Store, - "Set integer value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_set_int() { - assert_eq!(set_int(&["./argparse_test", "-s", "10"]), 10); - assert_eq!(set_int(&["./argparse_test", "--set", "99"]), 99); - assert_eq!(set_int(&["./argparse_test", "-s", "7", "-s77"]), 77); - assert_eq!(set_int(&["./argparse_test", "-s333", "--set=123"]), 123); -} - -#[test] -#[should_panic(expected="Bad value 1.5")] -fn test_set_int_bad() { - set_int(&["./argparse_test", "-s1.5"]); -} - -fn set_i16(args: &[&str]) -> i16 { - let mut val = 0; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-s", "--set"], Store, - "Set integer value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_i16() { - assert_eq!(set_i16(&["./argparse_test", "-s", "124"]), 124); -} - -#[test] -#[should_panic(expected="Bad value 1000000")] -fn test_i16_big() { - set_i16(&["./argparse_test", "-s", "1000000"]); -} diff --git a/argparse/src/test_many.rs b/argparse/src/test_many.rs deleted file mode 100644 index 68e2cec..0000000 --- a/argparse/src/test_many.rs +++ /dev/null @@ -1,95 +0,0 @@ -use parser::ArgumentParser; -use super::{List, Store, Collect}; -use test_parser::{check_ok}; - -fn pos_list(args: &[&str]) -> (isize, Vec) { - let mut val1 = 1; - let mut val2 = Vec::new(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val1).add_argument("v1", Store, "The value 1"); - ap.refer(&mut val2).add_argument("v2", List, "The list of vals"); - check_ok(&ap, args); - } - return (val1, val2); -} - -#[test] -fn test_pos_list() { - assert_eq!(pos_list(&["./argparse_test", "10"]), (10, vec!())); - assert_eq!(pos_list(&["./argparse_test", "11", "21"]), (11, vec!(21))); - assert_eq!(pos_list(&["./argparse_test", "10", "20", "30"]), - (10, vec!(20, 30))); -} - -fn pos_collect(args: &[&str]) -> Vec { - let mut lst = Vec::new(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut lst) - .add_argument("v", Collect, "The list of vals"); - check_ok(&ap, args); - } - return lst; -} - -#[test] -fn test_pos_collect() { - assert_eq!(pos_collect(&["./argparse_test", "10"]), vec!(10)); - assert_eq!(pos_collect(&["./argparse_test", "11", "21"]), vec!(11, 21)); - assert_eq!(pos_collect(&["./argparse_test", "10", "20", "30"]), - vec!(10, 20, 30)); -} - -#[test] -#[should_panic] -fn wrong_type() { - pos_collect(&["./argparse_test", "10", "20", "test"]); -} - -fn collect(args: &[&str]) -> Vec { - let mut lst = Vec::new(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut lst).add_option(&["-a", "--add"], Collect, - "The list of vals"); - check_ok(&ap, args); - } - return lst; -} - -#[test] -fn test_collect() { - assert_eq!(collect(&["./argparse_test", "-a10"]), vec!(10)); - assert_eq!(collect(&["./argparse_test", "--add=11", "-a", "21"]), - vec!(11, 21)); - assert_eq!(collect(&["./argparse_test", - "-a", "10", "--add=20", "--add", "30"]), vec!(10, 20, 30)); -} - -#[test] -#[should_panic] -fn test_extra() { - collect(&["./argparse_test", "-a", "10", "20", "30"]); -} - -fn list(args: &[&str]) -> Vec { - let mut vec = Vec::new(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut vec).add_option(&["-a", "--add"], List, - "The list of vals"); - check_ok(&ap, args); - } - return vec; -} - -#[test] -#[should_panic] -fn test_list() { - assert_eq!(list(&["./argparse_test", "-a10"]), vec!(10)); - assert_eq!(list(&["./argparse_test", "--add", "11", "21"]), vec!(11, 21)); - assert_eq!(list(&["./argparse_test", "-a", "10", "20", "30"]), - vec!(10, 20, 30)); - assert_eq!(list(&["./argparse_test", "10", "20", "30"]), vec!(10, 20, 30)); -} diff --git a/argparse/src/test_optional.rs b/argparse/src/test_optional.rs deleted file mode 100644 index 5f4c35e..0000000 --- a/argparse/src/test_optional.rs +++ /dev/null @@ -1,54 +0,0 @@ -use parser::ArgumentParser; -use super::StoreOption; -use test_parser::{check_ok}; - -fn opt(args: &[&str]) -> Option { - let mut val = None; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-s", "--set"], StoreOption, - "Set int value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_opt() { - assert_eq!(opt(&["./argparse_test"]), None); - assert_eq!(opt(&["./argparse_test", "-s", "10"]), Some(10)); - assert_eq!(opt(&["./argparse_test", "--set", "11"]), Some(11)); -} - -#[test] -#[should_panic] -fn test_opt_no_arg() { - opt(&["./argparse_test", "--set"]); -} - -fn optstr(args: &[&str]) -> Option { - let mut val = None; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-s", "--set"], StoreOption, - "Set string value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_str() { - assert_eq!(optstr(&["./argparse_test"]), None); - assert_eq!(optstr(&["./argparse_test", "-s", "10"]), Some(10.to_string())); - assert_eq!(optstr(&["./argparse_test", "--set", "11"]), - Some(11.to_string())); -} - -#[test] -#[should_panic] -fn test_str_no_art() { - optstr(&["./argparse_test", "--set"]); -} diff --git a/argparse/src/test_parser.rs b/argparse/src/test_parser.rs deleted file mode 100644 index f60aa64..0000000 --- a/argparse/src/test_parser.rs +++ /dev/null @@ -1,64 +0,0 @@ - -use parser::ArgumentParser; - -pub fn check_ok(ap: &ArgumentParser, args: &[&str]) { - let mut stdout = Vec::::new(); - let mut stderr = Vec::::new(); - let mut owned_args = Vec::new(); - for x in args.iter() { - owned_args.push(x.to_string()); - } - let res = ap.parse(owned_args, &mut stdout, &mut stderr); - match res { - Ok(()) => return, - Err(x) => panic!( - String::from_utf8(stderr).unwrap() + - &format!("Expected ok, but found Exit({})", x)[..]), - } -} - -pub fn check_exit(ap: &ArgumentParser, args: &[&str]) { - let mut stdout = Vec::::new(); - let mut stderr = Vec::::new(); - let mut owned_args = Vec::new(); - for x in args.iter() { - owned_args.push(x.to_string()); - } - let res = ap.parse(owned_args, &mut stdout, &mut stderr); - match res { - Err(0) => return, - Err(x) => panic!(format!("Expected code {} got {}", 0usize, x)), - Ok(()) => panic!(format!("Expected failure, got success")), - } -} - -pub fn check_err(ap: &ArgumentParser, args: &[&str]) { - let mut stdout = Vec::::new(); - let mut stderr = Vec::::new(); - let mut owned_args = Vec::new(); - for x in args.iter() { - owned_args.push(x.to_string()); - } - let res = ap.parse(owned_args, &mut stdout, &mut stderr); - match res { - Err(2) => return, - Err(x) => panic!(format!("Expected code {} got {}", 2usize, x)), - Ok(()) => panic!(format!("Expected failure, got success")), - } -} - -#[test] -fn test_no_arg() { - let ap = ArgumentParser::new(); - check_ok(&ap, &["./argparse_test"]); - check_err(&ap, &["./argparse_test", "a"]); - check_err(&ap, &["./argparse_test", "-a"]); - check_err(&ap, &["./argparse_test", "--an-option"]); -} - -#[test] -fn test_help() { - let ap = ArgumentParser::new(); - check_ok(&ap, &["./argparse_test"]); - check_exit(&ap, &["./argparse_test", "--help"]); -} diff --git a/argparse/src/test_path.rs b/argparse/src/test_path.rs deleted file mode 100644 index 868ae8c..0000000 --- a/argparse/src/test_path.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::path::PathBuf; -use parser::ArgumentParser; -use super::Parse; -use test_parser::{check_ok}; - -fn parse_str(args: &[&str]) -> PathBuf { - let mut val: PathBuf = From::from(""); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-s", "--set"], Parse, - "Set path value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_path() { - assert_eq!(parse_str(&["./argparse_test", "-s", "/hello"]), - PathBuf::from("/hello")); - assert_eq!(parse_str(&["./argparse_test", "--set", "a///b/../c"]), - PathBuf::from("a/b/../c")); -} - -#[test] -#[should_panic] -fn test_err() { - parse_str(&["./argparse_test", "--set"]); -} diff --git a/argparse/src/test_pos.rs b/argparse/src/test_pos.rs deleted file mode 100644 index 2542050..0000000 --- a/argparse/src/test_pos.rs +++ /dev/null @@ -1,196 +0,0 @@ -use parser::ArgumentParser; -use super::{Store, List}; -use test_parser::{check_ok}; - -fn parse_pos(args: &[&str]) -> isize { - let mut val = 0; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_argument("value", Store, "The value"); - check_ok(&ap, args); - } - return val; -} - - -#[test] -fn test_argument() { - assert_eq!(parse_pos(&["./argparse_test", "10"]), 10); -} - -#[test] -#[should_panic] -fn too_much_args() { - parse_pos(&["./argparse_test", "10", "20"]); -} - -#[test] -#[should_panic] -fn wrong_value() { - parse_pos(&["./argparse_test", "test", "20"]); -} - -#[test] -#[should_panic] -fn float_value() { - parse_pos(&["./argparse_test", "1.5"]); -} - -fn parse_two(args: &[&str]) -> (isize, isize) { - let mut val1 = 1; - let mut val2 = 2; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val1) - .add_argument("v1", Store, "The value 1"); - ap.refer(&mut val2) - .add_argument("v2", Store, "The value 2"); - check_ok(&ap, args); - } - return (val1, val2); -} - -#[test] -fn test_two() { - assert_eq!(parse_two(&["./argparse_test", "10"]), (10, 2)); - assert_eq!(parse_two(&["./argparse_test", "11", "21"]), (11, 21)); -} - -#[test] -#[should_panic] -fn test_two_fail_many() { - parse_two(&["./argparse_test", "10", "20", "30"]); -} - -#[test] -#[should_panic] -fn test_two_fail_value() { - parse_two(&["./argparse_test", "test", "20"]); -} - -#[test] -#[should_panic] -fn test_two_fail_float() { - parse_two(&["./argparse_test", "1.5"]); -} - -fn parse_pos_opt(args: &[&str]) -> (isize, isize) { - let mut val1 = 1; - let mut val2 = 2; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val1) - .add_option(&["--v1"], Store, "The value 1") - .add_argument("v1", Store, "The value 1"); - ap.refer(&mut val2) - .add_argument("v2", Store, "The value 2"); - check_ok(&ap, args); - } - return (val1, val2); -} - -#[test] -fn test_positional_optional() { - assert_eq!(parse_pos_opt(&["./argparse_test", "10"]), (10, 2)); - assert_eq!(parse_pos_opt(&["./argparse_test", "11", "21"]), (11, 21)); - assert_eq!(parse_pos_opt(&["./argparse_test", "--v1=7", "8"]), (7, 8)); - assert_eq!(parse_pos_opt(&["./argparse_test", "10", "--v1=9"]), (9, 10)); -} - -#[test] -#[should_panic] -fn test_pos_opt_err() { - parse_pos_opt(&["./argparse_test", "--v1=10", "20", "30"]); -} - -fn parse_pos_req(args: &[&str]) -> (isize, isize) { - let mut val1 = 1; - let mut val2 = 2; - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val1) - .add_option(&["--v1"], Store, "The value 1") - .add_argument("v1", Store, "The value 1") - .required(); - ap.refer(&mut val2) - .add_argument("v2", Store, "The value 2"); - check_ok(&ap, args); - } - return (val1, val2); -} - -#[test] -fn test_positional_required() { - assert_eq!(parse_pos_req(&["./argparse_test", "10"]), (10, 2)); - assert_eq!(parse_pos_req(&["./argparse_test", "11", "21"]), (11, 21)); - assert_eq!(parse_pos_req(&["./argparse_test", "--v1=7"]), (7, 2)); - assert_eq!(parse_pos_req(&["./argparse_test", "10", "--v1=9"]), (9, 10)); -} - -#[test] -#[should_panic] -fn test_pos_extra() { - parse_pos_req(&["./argparse_test", "--v1=10", "20", "30"]); -} - -#[test] -#[should_panic] -fn test_pos_no_req() { - parse_pos_req(&["./argparse_test"]); -} - -fn pos_stop(args: &[&str]) -> (isize, Vec) { - let mut val1 = 1; - let mut val2 = Vec::new(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val1) - .add_option(&["--v1"], Store, "The value 1") - .add_argument("v1", Store, "The value 1") - .required(); - ap.refer(&mut val2) - .add_argument("v2", List, "The value 2"); - ap.stop_on_first_argument(true); - check_ok(&ap, args); - } - return (val1, val2); -} - -#[test] -fn test_pos_stop() { - assert_eq!(pos_stop(&["./argparse_test", "10"]), (10, vec!())); - assert_eq!(pos_stop(&["./argparse_test", "11", "21"]), - (11, vec!("21".to_string()))); - assert_eq!(pos_stop(&["./argparse_test", "--v1=7"]), (7, vec!())); - assert_eq!(pos_stop(&["./argparse_test", "10", "--v1=9", "--whatever"]), - (10, vec!("--v1=9".to_string(), "--whatever".to_string()))); -} - -#[test] -#[should_panic] -fn test_test() { - pos_stop(&["./argparse_test"]); -} - -fn pos_dash(args: &[&str], dash: bool) -> Vec { - let mut val = Vec::new(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_argument("v1", List, "The value"); - ap.silence_double_dash(dash); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_pos_dash() { - assert_eq!(pos_dash(&["./argparse_test", "1"], true), - vec!("1".to_string())); - assert_eq!(pos_dash(&["./argparse_test", "--", "1"], true), - vec!("1".to_string())); - assert_eq!(pos_dash(&["./argparse_test", "--", "1"], false), - vec!("--".to_string(), "1".to_string())); -} diff --git a/argparse/src/test_str.rs b/argparse/src/test_str.rs deleted file mode 100644 index 42db286..0000000 --- a/argparse/src/test_str.rs +++ /dev/null @@ -1,28 +0,0 @@ -use parser::ArgumentParser; -use super::Store; -use test_parser::{check_ok}; - -fn parse_str(args: &[&str]) -> String { - let mut val: String = "".to_string(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["-s", "--set"], Store, - "Set string value"); - check_ok(&ap, args); - } - return val; -} - -#[test] -fn test_str() { - assert_eq!(parse_str(&["./argparse_test", "-s", "10"]), "10".to_string()); - assert_eq!(parse_str(&["./argparse_test", "--set", "value"]), - "value".to_string()); -} - -#[test] -#[should_panic] -fn test_err() { - parse_str(&["./argparse_test", "--set"]); -} diff --git a/argparse/src/test_usage.rs b/argparse/src/test_usage.rs deleted file mode 100644 index efe89fe..0000000 --- a/argparse/src/test_usage.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::str::from_utf8; - -use parser::ArgumentParser; -use super::{Store, List}; - -#[test] -fn test_empty() { - let ap = ArgumentParser::new(); - let mut buf = Vec::::new(); - assert!(ap.print_usage("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n ./argparse_test\n", from_utf8(&buf[..]).unwrap()); -} - -#[test] -fn test_options() { - let mut val = 0; - let mut buf = Vec::::new(); - { - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_option(&["--value"], Store, - "Set integer value"); - assert!(ap.print_usage("./argparse_test", &mut buf).is_ok()); - } - assert_eq!("Usage:\n ./argparse_test [OPTIONS]\n", - from_utf8(&buf[..]).unwrap()); -} - -#[test] -fn test_argument() { - let mut val = 0; - let mut ap = ArgumentParser::new(); - ap.refer(&mut val) - .add_argument("value", Store, - "Integer value"); - let mut buf = Vec::::new(); - assert!(ap.print_usage("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n ./argparse_test [VALUE]\n", - from_utf8(&buf[..]).unwrap()); -} - -#[test] -fn test_arguments() { - let mut v1 = 0; - let mut v2 = Vec::::new(); - let mut ap = ArgumentParser::new(); - ap.refer(&mut v1) - .add_argument("v1", Store, - "Integer value 1"); - ap.refer(&mut v2) - .add_argument("v2", List, - "More values"); - let mut buf = Vec::::new(); - assert!(ap.print_usage("./argparse_test", &mut buf).is_ok()); - assert_eq!("Usage:\n ./argparse_test [V1] [V2 ...]\n", - from_utf8(&buf[..]).unwrap()); -} diff --git a/argparse/vagga.yaml b/argparse/vagga.yaml deleted file mode 100644 index c6e0c52..0000000 --- a/argparse/vagga.yaml +++ /dev/null @@ -1,59 +0,0 @@ -containers: - - build: - setup: - - !Ubuntu bionic - - !Install [build-essential, ca-certificates, vim] - - !TarInstall - url: https://static.rust-lang.org/dist/rust-1.28.0-x86_64-unknown-linux-gnu.tar.gz - # We install rustc and cargo, but skip rust-docs - script: "./install.sh --prefix=/usr \ - --components=rustc,rust-std-x86_64-unknown-linux-gnu,cargo" - - &bulk !Tar - url: "https://github.com/tailhook/bulk/releases/download/v0.4.12/bulk-v0.4.12.tar.gz" - sha256: 7deeb4895b3909afea46194ef01bafdeb30ff89fc4a7b6497172ba117734040e - path: / - environ: - HOME: /work/run - volumes: - /tmp: !Tmpfs { size: 100Mi } - - -commands: - - make: !Command - description: Build the library - container: build - run: [cargo, build] - - test: !Command - description: Run the tests - container: build - run: [cargo, test] - - cargo: !Command - container: build - run: [cargo] - - example-greeting: !Command - description: Build and run "greeting" example - container: build - accepts-arguments: true - run: [cargo, run, --example, greeting, "--"] - - example-structure: !Command - description: Build and run "structure" example - container: build - accepts-arguments: true - run: [cargo, run, --example, structure, "--"] - - example-subcommands: !Command - description: Build and run "subcommands" example - container: build - accepts-arguments: true - run: [cargo, run, --example, subcommands, "--"] - - _bulk: !Command - description: Run `bulk` command (for version bookkeeping) - container: build - run: [bulk] diff --git a/base32/.gitignore b/base32/.gitignore deleted file mode 100644 index fa8d85a..0000000 --- a/base32/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -Cargo.lock -target diff --git a/base32/.travis.yml b/base32/.travis.yml deleted file mode 100644 index 22761ba..0000000 --- a/base32/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: rust diff --git a/base32/Cargo.toml b/base32/Cargo.toml deleted file mode 100644 index ff63bbe..0000000 --- a/base32/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] - -name = "base32" -version = "0.4.0" -authors = [ "Andreas Ots ", "Tim Dumol " ] -license = "MIT OR Apache-2.0" -repository = "https://github.com/andreasots/base32" -description = "Base32 encoder/decoder for Rust" - -[lib] - -name = "base32" - -[dev-dependencies] -quickcheck = "0.7.1" -rand = "0.5.5" diff --git a/base32/LICENSE-APACHE b/base32/LICENSE-APACHE deleted file mode 100644 index 8f71f43..0000000 --- a/base32/LICENSE-APACHE +++ /dev/null @@ -1,202 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/base32/LICENSE-MIT b/base32/LICENSE-MIT deleted file mode 100644 index 2a55a47..0000000 --- a/base32/LICENSE-MIT +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2015 The base32 Developers - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/base32/README.md b/base32/README.md deleted file mode 100644 index 86d9ad9..0000000 --- a/base32/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# base32 [![Build Status](https://travis-ci.org/andreasots/base32.svg?branch=master)](https://travis-ci.org/andreasots/base32) - -This library lets you encode and decode in either [RFC4648 Base32](http://en.wikipedia.org/wiki/Base32#RFC_4648_Base32_alphabet) or in [Crockford Base32](http://en.wikipedia.org/wiki/Base32#Crockford.27s_Base32). - -# Usage - -```rust -// crockford base32 -assert_eq!(encode(CrockfordBase32, [0xF8, 0x3E, 0x0F, 0x83, 0xE0]), Vec::from_slice("Z0Z0Z0Z0".to_ascii())); -assert_eq!(decode(CrockfordBase32, "Z0Z0Z0Z0".to_ascii()).unwrap(), vec![0xF8, 0x3E, 0x0F, 0x83, 0xE0]); - -// rfc4648 base32 -assert_eq!(encode(RFC4648Base32, [0xF8, 0x3E, 0x7F, 0x83, 0xE7]), Vec::from_slice("7A7H7A7H".to_ascii())); -assert_eq!(decode(RFC4648Base32, "7A7H7A7H".to_ascii()).unwrap(), vec![0xF8, 0x3E, 0x7F, 0x83, 0xE7]); - -// rfc4648 base32 without padding characters (=) -assert_eq!(encode(UnpaddedRFC4648Base32, [0xF8, 0x3E, 0x7F, 0x83, 0xE7]), Vec::from_slice("7A7H7A7H".to_ascii())); -assert_eq!(decode(UnpaddedRFC4648Base32, "7A7H7A7H".to_ascii()).unwrap(), vec![0xF8, 0x3E, 0x7F, 0x83, 0xE7]); -``` - -## License - -Licensed under either of - - * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) - * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally -submitted for inclusion in the work by you, as defined in the Apache-2.0 -license, shall be dual licensed as above, without any additional terms or -conditions. diff --git a/base32/src/lib.rs b/base32/src/lib.rs deleted file mode 100644 index e21cf97..0000000 --- a/base32/src/lib.rs +++ /dev/null @@ -1,221 +0,0 @@ -#[cfg(test)] -extern crate quickcheck; -#[cfg(test)] -extern crate rand; - -use std::cmp::min; - -#[derive(Copy,Clone)] -pub enum Alphabet { - RFC4648 { padding: bool }, - Crockford, -} - -const RFC4648_ALPHABET: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; -const CROCKFORD_ALPHABET: &'static [u8] = b"0123456789ABCDEFGHJKMNPQRSTVWXYZ"; - -pub fn encode(alphabet: Alphabet, data: &[u8]) -> String { - let (alphabet, padding) = match alphabet { - Alphabet::RFC4648 { padding } => (RFC4648_ALPHABET, padding), - Alphabet::Crockford => (CROCKFORD_ALPHABET, false), - }; - let mut ret = Vec::with_capacity((data.len()+3)/4*5); - - for chunk in data.chunks(5) { - let buf = { - let mut buf = [0u8; 5]; - for (i, &b) in chunk.iter().enumerate() { - buf[i] = b; - } - buf - }; - ret.push(alphabet[((buf[0] & 0xF8) >> 3) as usize]); - ret.push(alphabet[(((buf[0] & 0x07) << 2) | ((buf[1] & 0xC0) >> 6)) as usize]); - ret.push(alphabet[((buf[1] & 0x3E) >> 1) as usize]); - ret.push(alphabet[(((buf[1] & 0x01) << 4) | ((buf[2] & 0xF0) >> 4)) as usize]); - ret.push(alphabet[(((buf[2] & 0x0F) << 1) | (buf[3] >> 7)) as usize]); - ret.push(alphabet[((buf[3] & 0x7C) >> 2) as usize]); - ret.push(alphabet[(((buf[3] & 0x03) << 3) | ((buf[4] & 0xE0) >> 5)) as usize]); - ret.push(alphabet[(buf[4] & 0x1F) as usize]); - } - - if data.len() % 5 != 0 { - let len = ret.len(); - let num_extra = 8-(data.len()%5*8+4)/5; - if padding { - for i in 1..num_extra+1 { - ret[len-i] = b'='; - } - } else { - ret.truncate(len-num_extra); - } - } - - String::from_utf8(ret).unwrap() -} - -const RFC4648_INV_ALPHABET: [i8; 43] = [-1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]; -const CROCKFORD_INV_ALPHABET: [i8; 43] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 1, 18, 19, 1, 20, 21, 0, 22, 23, 24, 25, 26, -1, 27, 28, 29, 30, 31]; - -pub fn decode(alphabet: Alphabet, data: &str) -> Option> { - if !data.is_ascii() { - return None; - } - let data = data.as_bytes(); - let alphabet = match alphabet { - Alphabet::RFC4648 {..} => RFC4648_INV_ALPHABET, - Alphabet::Crockford => CROCKFORD_INV_ALPHABET - }; - let mut unpadded_data_length = data.len(); - for i in 1..min(6, data.len())+1 { - if data[data.len() - i] != b'=' { - break; - } - unpadded_data_length -= 1; - } - let output_length = unpadded_data_length*5/8; - let mut ret = Vec::with_capacity((output_length+4)/5*5); - for chunk in data.chunks(8) { - let buf = { - let mut buf = [0u8; 8]; - for (i, &c) in chunk.iter().enumerate() { - match alphabet.get(c.to_ascii_uppercase().wrapping_sub(b'0') as usize) { - Some(&-1) | None => return None, - Some(&value) => buf[i] = value as u8, - }; - } - buf - }; - ret.push((buf[0] << 3) | (buf[1] >> 2)); - ret.push((buf[1] << 6) | (buf[2] << 1) | (buf[3] >> 4)); - ret.push((buf[3] << 4) | (buf[4] >> 1)); - ret.push((buf[4] << 7) | (buf[5] << 2) | (buf[6] >> 3)); - ret.push((buf[6] << 5) | buf[7]); - } - ret.truncate(output_length); - Some(ret) -} - -#[cfg(test)] -#[allow(dead_code, unused_attributes)] -mod test { - use super::{encode, decode}; - use super::Alphabet::{Crockford, RFC4648}; - use quickcheck; - use std; - use rand::Rng; - - #[derive(Clone)] - struct B32 { - c: u8 - } - - impl quickcheck::Arbitrary for B32 { - fn arbitrary(g: &mut G) -> B32 { - let alphabet = b"0123456789ABCDEFGHJKMNPQRSTVWXYZ"; - B32 { - c: alphabet[g.gen_range(0, alphabet.len())] - } - } - } - - impl std::fmt::Debug for B32 { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - (self.c as char).fmt(f) - } - } - - #[test] - fn masks_crockford() { - assert_eq!(encode(Crockford, &[0xF8, 0x3E, 0x0F, 0x83, 0xE0]), "Z0Z0Z0Z0"); - assert_eq!(encode(Crockford, &[0x07, 0xC1, 0xF0, 0x7C, 0x1F]), "0Z0Z0Z0Z"); - assert_eq!(decode(Crockford, "Z0Z0Z0Z0").unwrap(), [0xF8, 0x3E, 0x0F, 0x83, 0xE0]); - assert_eq!(decode(Crockford, "0Z0Z0Z0Z").unwrap(), [0x07, 0xC1, 0xF0, 0x7C, 0x1F]); - } - - #[test] - fn masks_rfc4648() { - assert_eq!(encode(RFC4648 { padding: true }, &[0xF8, 0x3E, 0x7F, 0x83, 0xE7]), "7A7H7A7H"); - assert_eq!(encode(RFC4648 { padding: true }, &[0x77, 0xC1, 0xF7, 0x7C, 0x1F]), "O7A7O7A7"); - assert_eq!(decode(RFC4648 { padding: true }, "7A7H7A7H").unwrap(), [0xF8, 0x3E, 0x7F, 0x83, 0xE7]); - assert_eq!(decode(RFC4648 { padding: true }, "O7A7O7A7").unwrap(), [0x77, 0xC1, 0xF7, 0x7C, 0x1F]); - assert_eq!(encode(RFC4648 { padding: true }, &[0xF8, 0x3E, 0x7F, 0x83]), "7A7H7AY="); - } - - #[test] - fn masks_unpadded_rfc4648() { - assert_eq!(encode(RFC4648 { padding: false }, &[0xF8, 0x3E, 0x7F, 0x83, 0xE7]), "7A7H7A7H"); - assert_eq!(encode(RFC4648 { padding: false }, &[0x77, 0xC1, 0xF7, 0x7C, 0x1F]), "O7A7O7A7"); - assert_eq!(decode(RFC4648 { padding: false }, "7A7H7A7H").unwrap(), [0xF8, 0x3E, 0x7F, 0x83, 0xE7]); - assert_eq!(decode(RFC4648 { padding: false }, "O7A7O7A7").unwrap(), [0x77, 0xC1, 0xF7, 0x7C, 0x1F]); - assert_eq!(encode(RFC4648 { padding: false }, &[0xF8, 0x3E, 0x7F, 0x83]), "7A7H7AY"); - } - - #[test] - fn padding() { - let num_padding = [0, 6, 4, 3, 1]; - for i in 1..6 { - let encoded = encode(RFC4648 { padding: true }, (0..(i as u8)).collect::>().as_ref()); - assert_eq!(encoded.len(), 8); - for j in 0..(num_padding[i % 5]) { - assert_eq!(encoded.as_bytes()[encoded.len()-j-1], b'='); - } - for j in 0..(8 - num_padding[i % 5]) { - assert!(encoded.as_bytes()[j] != b'='); - } - } - } - - #[test] - fn invertible_crockford() { - fn test(data: Vec) -> bool { - decode(Crockford, encode(Crockford, data.as_ref()).as_ref()).unwrap() == data - } - quickcheck::quickcheck(test as fn(Vec) -> bool) - } - - #[test] - fn invertible_rfc4648() { - fn test(data: Vec) -> bool { - decode(RFC4648 { padding: true }, encode(RFC4648 { padding: true }, data.as_ref()).as_ref()).unwrap() == data - } - quickcheck::quickcheck(test as fn(Vec) -> bool) - } - #[test] - fn invertible_unpadded_rfc4648() { - fn test(data: Vec) -> bool { - decode(RFC4648 { padding: false }, encode(RFC4648 { padding: false }, data.as_ref()).as_ref()).unwrap() == data - } - quickcheck::quickcheck(test as fn(Vec) -> bool) - } - - #[test] - fn lower_case() { - fn test(data: Vec) -> bool { - let data: String = data.iter().map(|e| e.c as char).collect(); - decode(Crockford, data.as_ref()) == decode(Crockford, data.to_ascii_lowercase().as_ref()) - } - quickcheck::quickcheck(test as fn(Vec) -> bool) - } - - #[test] - #[allow(non_snake_case)] - fn iIlL1_oO0() { - assert_eq!(decode(Crockford, "IiLlOo"), decode(Crockford, "111100")); - } - - #[test] - fn invalid_chars_crockford() { - assert_eq!(decode(Crockford, ","), None) - } - - #[test] - fn invalid_chars_rfc4648() { - assert_eq!(decode(RFC4648 { padding: true }, ","), None) - } - - #[test] - fn invalid_chars_unpadded_rfc4648() { - assert_eq!(decode(RFC4648 { padding: false }, ","), None) - } -} diff --git a/cc/.github/workflows/main.yml b/cc/.github/workflows/main.yml deleted file mode 100644 index 9c35a41..0000000 --- a/cc/.github/workflows/main.yml +++ /dev/null @@ -1,124 +0,0 @@ -name: CI -on: [push, pull_request] - -jobs: - test: - name: Test - runs-on: ${{ matrix.os }} - strategy: - matrix: - build: [stable, beta, nightly, linux32, macos, aarch64-ios, win32, win64, mingw32, mingw64, windows-2016] - include: - - build: stable - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - - build: beta - os: ubuntu-latest - rust: beta - target: x86_64-unknown-linux-gnu - - build: nightly - os: ubuntu-latest - rust: nightly - target: x86_64-unknown-linux-gnu - - build: linux32 - os: ubuntu-latest - rust: stable - target: i686-unknown-linux-gnu - - build: macos - os: macos-latest - rust: stable - target: x86_64-apple-darwin - - build: aarch64-ios - os: macos-latest - rust: stable - target: aarch64-apple-ios - no_run: --no-run - - build: win32 - os: windows-2016 - rust: stable-i686-msvc - target: i686-pc-windows-msvc - - build: win64 - os: windows-latest - rust: stable - target: x86_64-pc-windows-msvc - - build: mingw32 - os: windows-latest - rust: stable-i686-gnu - target: i686-pc-windows-gnu - - build: mingw64 - os: windows-latest - rust: stable-x86_64-gnu - target: x86_64-pc-windows-gnu - - build: windows-2016 - os: windows-2016 - rust: stable-x86_64 - target: x86_64-pc-windows-msvc - steps: - - uses: actions/checkout@master - - name: Install Rust (rustup) - run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} - if: matrix.os != 'macos-latest' - shell: bash - - name: Install Rust (macos) - run: | - curl https://sh.rustup.rs | sh -s -- -y - echo "##[add-path]$HOME/.cargo/bin" - if: matrix.os == 'macos-latest' - - run: rustup target add ${{ matrix.target }} - - name: Install g++-multilib - run: | - set -e - # Remove the ubuntu-toolchain-r/test PPA, which is added by default. - # Some packages were removed, and this is causing the g++multilib - # install to fail. Similar issue: - # https://github.com/scikit-learn/scikit-learn/issues/13928. - sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test - sudo apt-get install g++-multilib - if: matrix.build == 'linux32' - - run: cargo build - - run: cargo test ${{ matrix.no_run }} - - run: cargo test ${{ matrix.no_run }} --features parallel - - run: cargo test ${{ matrix.no_run }} --manifest-path cc-test/Cargo.toml --target ${{ matrix.target }} - - run: cargo test ${{ matrix.no_run }} --manifest-path cc-test/Cargo.toml --target ${{ matrix.target }} --features parallel - - run: cargo test ${{ matrix.no_run }} --manifest-path cc-test/Cargo.toml --target ${{ matrix.target }} --release - - msrv: - name: MSRV - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest] - steps: - - uses: actions/checkout@master - - name: Install Rust - run: rustup update 1.31.0 --no-self-update && rustup default 1.31.0 - shell: bash - - run: cargo build - - rustfmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Install Rust - run: rustup update stable && rustup default stable && rustup component add rustfmt - - run: cargo fmt -- --check - - publish_docs: - name: Publish Documentation - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Install Rust - run: rustup update stable && rustup default stable - - name: Build documentation - run: cargo doc --no-deps --all-features - - name: Publish documentation - run: | - cd target/doc - git init - git add . - git -c user.name='ci' -c user.email='ci' commit -m init - git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages - if: github.event_name == 'push' && github.event.ref == 'refs/heads/master' diff --git a/cc/.gitignore b/cc/.gitignore deleted file mode 100644 index 3b874ca..0000000 --- a/cc/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -Cargo.lock -.idea -*.iml diff --git a/cc/Cargo.toml b/cc/Cargo.toml deleted file mode 100644 index 88f44eb..0000000 --- a/cc/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "cc" -version = "1.0.48" -authors = ["Alex Crichton "] -license = "MIT/Apache-2.0" -repository = "https://github.com/alexcrichton/cc-rs" -homepage = "https://github.com/alexcrichton/cc-rs" -documentation = "https://docs.rs/cc" -description = """ -A build-time dependency for Cargo build scripts to assist in invoking the native -C compiler to compile native C code into a static archive to be linked into Rust -code. -""" -keywords = ["build-dependencies"] -readme = "README.md" -categories = ["development-tools::build-utils"] -exclude = ["/.travis.yml", "/appveyor.yml"] -edition = "2018" - -[dependencies] -num_cpus = { version = "1.10", optional = true } -jobserver = { version = "0.1.16", optional = true } - -[features] -parallel = ["num_cpus", "jobserver"] - -[dev-dependencies] -tempfile = "3" diff --git a/cc/LICENSE-APACHE b/cc/LICENSE-APACHE deleted file mode 100644 index 16fe87b..0000000 --- a/cc/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/cc/LICENSE-MIT b/cc/LICENSE-MIT deleted file mode 100644 index 39e0ed6..0000000 --- a/cc/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2014 Alex Crichton - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/cc/README.md b/cc/README.md deleted file mode 100644 index 68448ac..0000000 --- a/cc/README.md +++ /dev/null @@ -1,194 +0,0 @@ -# cc-rs - -A library to compile C/C++/assembly into a Rust library/application. - -[Documentation](https://docs.rs/cc) - -A simple library meant to be used as a build dependency with Cargo packages in -order to build a set of C/C++ files into a static archive. This crate calls out -to the most relevant compiler for a platform, for example using `cl` on MSVC. - -> **Note**: this crate was recently renamed from the `gcc` crate, so if you're -> looking for the `gcc` crate you're in the right spot! - -## Using cc-rs - -First, you'll want to both add a build script for your crate (`build.rs`) and -also add this crate to your `Cargo.toml` via: - -```toml -[build-dependencies] -cc = "1.0" -``` - -Next up, you'll want to write a build script like so: - -```rust,no_run -// build.rs - -fn main() { - cc::Build::new() - .file("foo.c") - .file("bar.c") - .compile("foo"); -} -``` - -And that's it! Running `cargo build` should take care of the rest and your Rust -application will now have the C files `foo.c` and `bar.c` compiled into a file -named libfoo.a. You can call the functions in Rust by declaring functions in -your Rust code like so: - -``` -extern { - fn foo_function(); - fn bar_function(); -} - -pub fn call() { - unsafe { - foo_function(); - bar_function(); - } -} - -fn main() { - // ... -} -``` - -## External configuration via environment variables - -To control the programs and flags used for building, the builder can set a -number of different environment variables. - -* `CFLAGS` - a series of space separated flags passed to compilers. Note that - individual flags cannot currently contain spaces, so doing - something like: "-L=foo\ bar" is not possible. -* `CC` - the actual C compiler used. Note that this is used as an exact - executable name, so (for example) no extra flags can be passed inside - this variable, and the builder must ensure that there aren't any - trailing spaces. This compiler must understand the `-c` flag. For - certain `TARGET`s, it also is assumed to know about other flags (most - common is `-fPIC`). -* `AR` - the `ar` (archiver) executable to use to build the static library. -* `CRATE_CC_NO_DEFAULTS` - the default compiler flags may cause conflicts in some cross compiling scenarios. Setting this variable will disable the generation of default compiler flags. - -Each of these variables can also be supplied with certain prefixes and suffixes, -in the following prioritized order: - -1. `_` - for example, `CC_x86_64-unknown-linux-gnu` -2. `_` - for example, `CC_x86_64_unknown_linux_gnu` -3. `_` - for example, `HOST_CC` or `TARGET_CFLAGS` -4. `` - a plain `CC`, `AR` as above. - -If none of these variables exist, cc-rs uses built-in defaults - -In addition to the above optional environment variables, `cc-rs` has some -functions with hard requirements on some variables supplied by [cargo's -build-script driver][cargo] that it has the `TARGET`, `OUT_DIR`, `OPT_LEVEL`, -and `HOST` variables. - -[cargo]: http://doc.crates.io/build-script.html#inputs-to-the-build-script - -## Optional features - -### Parallel - -Currently cc-rs supports parallel compilation (think `make -jN`) but this -feature is turned off by default. To enable cc-rs to compile C/C++ in parallel, -you can change your dependency to: - -```toml -[build-dependencies] -cc = { version = "1.0", features = ["parallel"] } -``` - -By default cc-rs will limit parallelism to `$NUM_JOBS`, or if not present it -will limit it to the number of cpus on the machine. If you are using cargo, -use `-jN` option of `build`, `test` and `run` commands as `$NUM_JOBS` -is supplied by cargo. - -## Compile-time Requirements - -To work properly this crate needs access to a C compiler when the build script -is being run. This crate does not ship a C compiler with it. The compiler -required varies per platform, but there are three broad categories: - -* Unix platforms require `cc` to be the C compiler. This can be found by - installing cc/clang on Linux distributions and Xcode on OSX, for example. -* Windows platforms targeting MSVC (e.g. your target triple ends in `-msvc`) - require `cl.exe` to be available and in `PATH`. This is typically found in - standard Visual Studio installations and the `PATH` can be set up by running - the appropriate developer tools shell. -* Windows platforms targeting MinGW (e.g. your target triple ends in `-gnu`) - require `cc` to be available in `PATH`. We recommend the - [MinGW-w64](http://mingw-w64.org) distribution, which is using the - [Win-builds](http://win-builds.org) installation system. - You may also acquire it via - [MSYS2](http://msys2.github.io), as explained [here][msys2-help]. Make sure - to install the appropriate architecture corresponding to your installation of - rustc. GCC from older [MinGW](http://www.mingw.org) project is compatible - only with 32-bit rust compiler. - -[msys2-help]: http://github.com/rust-lang/rust#building-on-windows - -## C++ support - -`cc-rs` supports C++ libraries compilation by using the `cpp` method on -`Build`: - -```rust,no_run -fn main() { - cc::Build::new() - .cpp(true) // Switch to C++ library compilation. - .file("foo.cpp") - .compile("libfoo.a"); -} -``` - -When using C++ library compilation switch, the `CXX` and `CXXFLAGS` env -variables are used instead of `CC` and `CFLAGS` and the C++ standard library is -linked to the crate target. - -## CUDA C++ support - -`cc-rs` also supports compiling CUDA C++ libraries by using the `cuda` method -on `Build` (currently for GNU/Clang toolchains only): - -```rust,no_run -fn main() { - cc::Build::new() - // Switch to CUDA C++ library compilation using NVCC. - .cuda(true) - // Generate code for Maxwell (GTX 970, 980, 980 Ti, Titan X). - .flag("-gencode").flag("arch=compute_52,code=sm_52") - // Generate code for Maxwell (Jetson TX1). - .flag("-gencode").flag("arch=compute_53,code=sm_53") - // Generate code for Pascal (GTX 1070, 1080, 1080 Ti, Titan Xp). - .flag("-gencode").flag("arch=compute_61,code=sm_61") - // Generate code for Pascal (Tesla P100). - .flag("-gencode").flag("arch=compute_60,code=sm_60") - // Generate code for Pascal (Jetson TX2). - .flag("-gencode").flag("arch=compute_62,code=sm_62") - .file("bar.cu") - .compile("libbar.a"); -} -``` - -## License - -This project is licensed under either of - - * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or - http://www.apache.org/licenses/LICENSE-2.0) - * MIT license ([LICENSE-MIT](LICENSE-MIT) or - http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in cc-rs by you, as defined in the Apache-2.0 license, shall be -dual licensed as above, without any additional terms or conditions. diff --git a/cc/cc-test/Cargo.toml b/cc/cc-test/Cargo.toml deleted file mode 100644 index c25854c..0000000 --- a/cc/cc-test/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "cc-test" -version = "0.1.0" -authors = ["Alex Crichton "] -edition = "2018" - -[lib] -name = "cc_test" -doctest = false -test = false - -[build-dependencies] -cc = { path = ".." } - -[features] -parallel = ["cc/parallel"] diff --git a/cc/cc-test/build.rs b/cc/cc-test/build.rs deleted file mode 100644 index 3065861..0000000 --- a/cc/cc-test/build.rs +++ /dev/null @@ -1,88 +0,0 @@ -use std::env; -use std::fs; -use std::path::PathBuf; - -fn main() { - let out = PathBuf::from(env::var_os("OUT_DIR").unwrap()); - fs::remove_dir_all(&out).unwrap(); - fs::create_dir(&out).unwrap(); - - cc::Build::new() - .file("src/foo.c") - .flag_if_supported("-Wall") - .flag_if_supported("-Wfoo-bar-this-flag-does-not-exist") - .define("FOO", None) - .define("BAR", "1") - .compile("foo"); - - cc::Build::new() - .file("src/bar1.c") - .file("src/bar2.c") - .include("src/include") - .compile("bar"); - - let target = std::env::var("TARGET").unwrap(); - let file = target.split("-").next().unwrap(); - let file = format!( - "src/{}.{}", - file, - if target.contains("msvc") { "asm" } else { "S" } - ); - cc::Build::new().file(file).compile("asm"); - - cc::Build::new() - .file("src/baz.cpp") - .cpp(true) - .compile("baz"); - - if target.contains("windows") { - cc::Build::new().file("src/windows.c").compile("windows"); - } - - // Test that the `windows_registry` module will set PATH by looking for - // nmake which runs vanilla cl, and then also test it after we remove all - // the relevant env vars from our own process. - if target.contains("msvc") { - let out = out.join("tmp"); - fs::create_dir(&out).unwrap(); - println!("nmake 1"); - let status = cc::windows_registry::find(&target, "nmake.exe") - .unwrap() - .env_remove("MAKEFLAGS") - .arg("/fsrc/NMakefile") - .env("OUT_DIR", &out) - .status() - .unwrap(); - assert!(status.success()); - - fs::remove_dir_all(&out).unwrap(); - fs::create_dir(&out).unwrap(); - - env::remove_var("PATH"); - env::remove_var("VCINSTALLDIR"); - env::remove_var("INCLUDE"); - env::remove_var("LIB"); - println!("nmake 2"); - let status = cc::windows_registry::find(&target, "nmake.exe") - .unwrap() - .env_remove("MAKEFLAGS") - .arg("/fsrc/NMakefile") - .env("OUT_DIR", &out) - .status() - .unwrap(); - assert!(status.success()); - println!("cargo:rustc-link-lib=msvc"); - println!("cargo:rustc-link-search={}", out.display()); - } - - // This tests whether we can build a library but not link it to the main - // crate. The test module will do its own linking. - cc::Build::new() - .cargo_metadata(false) - .file("src/opt_linkage.c") - .compile("OptLinkage"); - - let out = cc::Build::new().file("src/expand.c").expand(); - let out = String::from_utf8(out).unwrap(); - assert!(out.contains("hello world")); -} diff --git a/cc/cc-test/src/NMakefile b/cc/cc-test/src/NMakefile deleted file mode 100644 index 03c73df..0000000 --- a/cc/cc-test/src/NMakefile +++ /dev/null @@ -1,14 +0,0 @@ -all: $(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.exe - -$(OUT_DIR)/msvc.lib: $(OUT_DIR)/msvc.o - lib -nologo -out:$(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.o - rc -h - -$(OUT_DIR)/msvc.o: src/msvc.c - $(CC) -nologo -c -Fo:$@ src/msvc.c -MD - -$(OUT_DIR)/msvc.exe: $(OUT_DIR)/msvc2.o - $(CC) -nologo -Fo:$@ $(OUT_DIR)/msvc2.o - -$(OUT_DIR)/msvc2.o: src/msvc.c - $(CC) -nologo -c -Fo:$@ src/msvc.c -DMAIN -MD diff --git a/cc/cc-test/src/aarch64.S b/cc/cc-test/src/aarch64.S deleted file mode 100644 index 1d9062d..0000000 --- a/cc/cc-test/src/aarch64.S +++ /dev/null @@ -1,10 +0,0 @@ -.globl asm -asm: - mov w0, 7 - ret - -.globl _asm -_asm: - mov w0, 7 - ret - diff --git a/cc/cc-test/src/bar1.c b/cc/cc-test/src/bar1.c deleted file mode 100644 index 605be33..0000000 --- a/cc/cc-test/src/bar1.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "foo.h" - -int32_t bar1() { - return 5; -} - diff --git a/cc/cc-test/src/bar2.c b/cc/cc-test/src/bar2.c deleted file mode 100644 index 9be4291..0000000 --- a/cc/cc-test/src/bar2.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int32_t bar2() { - return 6; -} - diff --git a/cc/cc-test/src/baz.cpp b/cc/cc-test/src/baz.cpp deleted file mode 100644 index 2d4b959..0000000 --- a/cc/cc-test/src/baz.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -extern "C" int32_t -baz() { - int *a = new int(8); - int b = *a; - delete a; - return b; -} diff --git a/cc/cc-test/src/expand.c b/cc/cc-test/src/expand.c deleted file mode 100644 index 2b492a2..0000000 --- a/cc/cc-test/src/expand.c +++ /dev/null @@ -1,4 +0,0 @@ -#define HELLO hello -#define WORLD world - -HELLO WORLD diff --git a/cc/cc-test/src/foo.c b/cc/cc-test/src/foo.c deleted file mode 100644 index 541e62c..0000000 --- a/cc/cc-test/src/foo.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#ifdef FOO -#if BAR == 1 -int32_t foo() { - return 4; -} -#endif -#endif diff --git a/cc/cc-test/src/i686.S b/cc/cc-test/src/i686.S deleted file mode 100644 index 3ed9e86..0000000 --- a/cc/cc-test/src/i686.S +++ /dev/null @@ -1,9 +0,0 @@ -.globl asm -asm: - mov $7, %eax - ret - -.globl _asm -_asm: - mov $7, %eax - ret diff --git a/cc/cc-test/src/i686.asm b/cc/cc-test/src/i686.asm deleted file mode 100644 index 6bf9676..0000000 --- a/cc/cc-test/src/i686.asm +++ /dev/null @@ -1,9 +0,0 @@ -.586 -.MODEL FLAT, C -.CODE - -asm PROC - MOV EAX, 7 - RET -asm ENDP -END diff --git a/cc/cc-test/src/include/foo.h b/cc/cc-test/src/include/foo.h deleted file mode 100644 index e69de29..0000000 diff --git a/cc/cc-test/src/lib.rs b/cc/cc-test/src/lib.rs deleted file mode 100644 index b42ebf7..0000000 --- a/cc/cc-test/src/lib.rs +++ /dev/null @@ -1,16 +0,0 @@ -extern "C" { - pub fn foo() -> i32; - - pub fn bar1() -> i32; - pub fn bar2() -> i32; - - pub fn asm() -> i32; - - pub fn baz() -> i32; - - #[cfg(windows)] - pub fn windows(); - - #[cfg(target_env = "msvc")] - pub fn msvc(); -} diff --git a/cc/cc-test/src/msvc.c b/cc/cc-test/src/msvc.c deleted file mode 100644 index dbbc494..0000000 --- a/cc/cc-test/src/msvc.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -void msvc() {} - -#ifdef MAIN -int main() {} -#endif diff --git a/cc/cc-test/src/opt_linkage.c b/cc/cc-test/src/opt_linkage.c deleted file mode 100644 index a74af8c..0000000 --- a/cc/cc-test/src/opt_linkage.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int32_t answer() { - return 42; -} diff --git a/cc/cc-test/src/windows.c b/cc/cc-test/src/windows.c deleted file mode 100644 index 0896aa0..0000000 --- a/cc/cc-test/src/windows.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -void windows() {} diff --git a/cc/cc-test/src/x86_64.S b/cc/cc-test/src/x86_64.S deleted file mode 100644 index 3ed9e86..0000000 --- a/cc/cc-test/src/x86_64.S +++ /dev/null @@ -1,9 +0,0 @@ -.globl asm -asm: - mov $7, %eax - ret - -.globl _asm -_asm: - mov $7, %eax - ret diff --git a/cc/cc-test/src/x86_64.asm b/cc/cc-test/src/x86_64.asm deleted file mode 100644 index 1c03101..0000000 --- a/cc/cc-test/src/x86_64.asm +++ /dev/null @@ -1,8 +0,0 @@ -_TEXT SEGMENT - -asm PROC - MOV EAX, 7 - RET -asm ENDP - -END diff --git a/cc/cc-test/tests/all.rs b/cc/cc-test/tests/all.rs deleted file mode 100644 index a457c72..0000000 --- a/cc/cc-test/tests/all.rs +++ /dev/null @@ -1,58 +0,0 @@ -use cc_test::*; - -#[link(name = "OptLinkage", kind = "static")] -extern "C" { - fn answer() -> i32; -} - -#[test] -fn foo_here() { - unsafe { - assert_eq!(foo(), 4); - } -} - -#[test] -fn bar_here() { - unsafe { - assert_eq!(bar1(), 5); - assert_eq!(bar2(), 6); - } -} - -#[test] -fn asm_here() { - unsafe { - assert_eq!(asm(), 7); - } -} - -#[test] -fn baz_here() { - unsafe { - assert_eq!(baz(), 8); - } -} - -#[test] -#[cfg(windows)] -fn windows_here() { - unsafe { - windows(); - } -} - -#[test] -#[cfg(target_env = "msvc")] -fn msvc_here() { - unsafe { - msvc(); - } -} - -#[test] -fn opt_linkage() { - unsafe { - assert_eq!(answer(), 42); - } -} diff --git a/cc/src/bin/gcc-shim.rs b/cc/src/bin/gcc-shim.rs deleted file mode 100644 index 1731df8..0000000 --- a/cc/src/bin/gcc-shim.rs +++ /dev/null @@ -1,48 +0,0 @@ -#![cfg_attr(test, allow(dead_code))] - -use std::env; -use std::fs::File; -use std::io::prelude::*; -use std::path::PathBuf; - -fn main() { - let mut args = env::args(); - let program = args.next().expect("Unexpected empty args"); - - let out_dir = PathBuf::from( - env::var_os("GCCTEST_OUT_DIR").expect(&format!("{}: GCCTEST_OUT_DIR not found", program)), - ); - - // Find the first nonexistent candidate file to which the program's args can be written. - for i in 0.. { - let candidate = &out_dir.join(format!("out{}", i)); - - // If the file exists, commands have already run. Try again. - if candidate.exists() { - continue; - } - - // Create a file and record the args passed to the command. - let mut f = File::create(candidate).expect(&format!( - "{}: can't create candidate: {}", - program, - candidate.to_string_lossy() - )); - for arg in args { - writeln!(f, "{}", arg).expect(&format!( - "{}: can't write to candidate: {}", - program, - candidate.to_string_lossy() - )); - } - break; - } - - // Create a file used by some tests. - let path = &out_dir.join("libfoo.a"); - File::create(path).expect(&format!( - "{}: can't create libfoo.a: {}", - program, - path.to_string_lossy() - )); -} diff --git a/cc/src/com.rs b/cc/src/com.rs deleted file mode 100644 index a5f2afe..0000000 --- a/cc/src/com.rs +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright © 2017 winapi-rs developers -// Licensed under the Apache License, Version 2.0 -// or the MIT license -// , at your option. -// All files in the project carrying such notice may not be copied, modified, or distributed -// except according to those terms. - -#![allow(unused)] - -use crate::winapi::CoInitializeEx; -use crate::winapi::IUnknown; -use crate::winapi::Interface; -use crate::winapi::BSTR; -use crate::winapi::COINIT_MULTITHREADED; -use crate::winapi::{SysFreeString, SysStringLen}; -use crate::winapi::{HRESULT, S_FALSE, S_OK}; -use std::ffi::{OsStr, OsString}; -use std::mem::forget; -use std::ops::Deref; -use std::os::windows::ffi::{OsStrExt, OsStringExt}; -use std::ptr::null_mut; -use std::slice::from_raw_parts; - -pub fn initialize() -> Result<(), HRESULT> { - let err = unsafe { CoInitializeEx(null_mut(), COINIT_MULTITHREADED) }; - if err != S_OK && err != S_FALSE { - // S_FALSE just means COM is already initialized - return Err(err); - } - Ok(()) -} - -pub struct ComPtr(*mut T) -where - T: Interface; -impl ComPtr -where - T: Interface, -{ - /// Creates a `ComPtr` to wrap a raw pointer. - /// It takes ownership over the pointer which means it does __not__ call `AddRef`. - /// `T` __must__ be a COM interface that inherits from `IUnknown`. - pub unsafe fn from_raw(ptr: *mut T) -> ComPtr { - assert!(!ptr.is_null()); - ComPtr(ptr) - } - /// Casts up the inheritance chain - pub fn up(self) -> ComPtr - where - T: Deref, - U: Interface, - { - ComPtr(self.into_raw() as *mut U) - } - /// Extracts the raw pointer. - /// You are now responsible for releasing it yourself. - pub fn into_raw(self) -> *mut T { - let p = self.0; - forget(self); - p - } - /// For internal use only. - fn as_unknown(&self) -> &IUnknown { - unsafe { &*(self.0 as *mut IUnknown) } - } - /// Performs QueryInterface fun. - pub fn cast(&self) -> Result, i32> - where - U: Interface, - { - let mut obj = null_mut(); - let err = unsafe { self.as_unknown().QueryInterface(&U::uuidof(), &mut obj) }; - if err < 0 { - return Err(err); - } - Ok(unsafe { ComPtr::from_raw(obj as *mut U) }) - } -} -impl Deref for ComPtr -where - T: Interface, -{ - type Target = T; - fn deref(&self) -> &T { - unsafe { &*self.0 } - } -} -impl Clone for ComPtr -where - T: Interface, -{ - fn clone(&self) -> Self { - unsafe { - self.as_unknown().AddRef(); - ComPtr::from_raw(self.0) - } - } -} -impl Drop for ComPtr -where - T: Interface, -{ - fn drop(&mut self) { - unsafe { - self.as_unknown().Release(); - } - } -} -pub struct BStr(BSTR); -impl BStr { - pub unsafe fn from_raw(s: BSTR) -> BStr { - BStr(s) - } - pub fn to_osstring(&self) -> OsString { - let len = unsafe { SysStringLen(self.0) }; - let slice = unsafe { from_raw_parts(self.0, len as usize) }; - OsStringExt::from_wide(slice) - } -} -impl Drop for BStr { - fn drop(&mut self) { - unsafe { SysFreeString(self.0) }; - } -} - -pub trait ToWide { - fn to_wide(&self) -> Vec; - fn to_wide_null(&self) -> Vec; -} -impl ToWide for T -where - T: AsRef, -{ - fn to_wide(&self) -> Vec { - self.as_ref().encode_wide().collect() - } - fn to_wide_null(&self) -> Vec { - self.as_ref().encode_wide().chain(Some(0)).collect() - } -} -pub trait FromWide -where - Self: Sized, -{ - fn from_wide(wide: &[u16]) -> Self; - fn from_wide_null(wide: &[u16]) -> Self { - let len = wide.iter().take_while(|&&c| c != 0).count(); - Self::from_wide(&wide[..len]) - } -} -impl FromWide for OsString { - fn from_wide(wide: &[u16]) -> OsString { - OsStringExt::from_wide(wide) - } -} diff --git a/cc/src/lib.rs b/cc/src/lib.rs deleted file mode 100644 index d795e5a..0000000 --- a/cc/src/lib.rs +++ /dev/null @@ -1,2666 +0,0 @@ -//! A library for build scripts to compile custom C code -//! -//! This library is intended to be used as a `build-dependencies` entry in -//! `Cargo.toml`: -//! -//! ```toml -//! [build-dependencies] -//! cc = "1.0" -//! ``` -//! -//! The purpose of this crate is to provide the utility functions necessary to -//! compile C code into a static archive which is then linked into a Rust crate. -//! Configuration is available through the `Build` struct. -//! -//! This crate will automatically detect situations such as cross compilation or -//! other environment variables set by Cargo and will build code appropriately. -//! -//! The crate is not limited to C code, it can accept any source code that can -//! be passed to a C or C++ compiler. As such, assembly files with extensions -//! `.s` (gcc/clang) and `.asm` (MSVC) can also be compiled. -//! -//! [`Build`]: struct.Build.html -//! -//! # Parallelism -//! -//! To parallelize computation, enable the `parallel` feature for the crate. -//! -//! ```toml -//! [build-dependencies] -//! cc = { version = "1.0", features = ["parallel"] } -//! ``` -//! To specify the max number of concurrent compilation jobs, set the `NUM_JOBS` -//! environment variable to the desired amount. -//! -//! Cargo will also set this environment variable when executed with the `-jN` flag. -//! -//! If `NUM_JOBS` is not set, the `RAYON_NUM_THREADS` environment variable can -//! also specify the build parallelism. -//! -//! # Examples -//! -//! Use the `Build` struct to compile `src/foo.c`: -//! -//! ```no_run -//! fn main() { -//! cc::Build::new() -//! .file("src/foo.c") -//! .define("FOO", Some("bar")) -//! .include("src") -//! .compile("foo"); -//! } -//! ``` - -#![doc(html_root_url = "https://docs.rs/cc/1.0")] -#![cfg_attr(test, deny(warnings))] -#![allow(deprecated)] -#![deny(missing_docs)] - -use std::collections::HashMap; -use std::env; -use std::ffi::{OsStr, OsString}; -use std::fmt::{self, Display}; -use std::fs; -use std::io::{self, BufRead, BufReader, Read, Write}; -use std::path::{Path, PathBuf}; -use std::process::{Child, Command, Stdio}; -use std::sync::{Arc, Mutex}; -use std::thread::{self, JoinHandle}; - -// These modules are all glue to support reading the MSVC version from -// the registry and from COM interfaces -#[cfg(windows)] -mod registry; -#[cfg(windows)] -#[macro_use] -mod winapi; -#[cfg(windows)] -mod com; -#[cfg(windows)] -mod setup_config; - -pub mod windows_registry; - -/// A builder for compilation of a native static library. -/// -/// A `Build` is the main type of the `cc` crate and is used to control all the -/// various configuration options and such of a compile. You'll find more -/// documentation on each method itself. -#[derive(Clone, Debug)] -pub struct Build { - include_directories: Vec, - definitions: Vec<(String, Option)>, - objects: Vec, - flags: Vec, - flags_supported: Vec, - known_flag_support_status: Arc>>, - ar_flags: Vec, - no_default_flags: bool, - files: Vec, - cpp: bool, - cpp_link_stdlib: Option>, - cpp_set_stdlib: Option, - cuda: bool, - target: Option, - host: Option, - out_dir: Option, - opt_level: Option, - debug: Option, - force_frame_pointer: Option, - env: Vec<(OsString, OsString)>, - compiler: Option, - archiver: Option, - cargo_metadata: bool, - pic: Option, - use_plt: Option, - static_crt: Option, - shared_flag: Option, - static_flag: Option, - warnings_into_errors: bool, - warnings: Option, - extra_warnings: Option, - env_cache: Arc>>>, -} - -/// Represents the types of errors that may occur while using cc-rs. -#[derive(Clone, Debug)] -enum ErrorKind { - /// Error occurred while performing I/O. - IOError, - /// Invalid architecture supplied. - ArchitectureInvalid, - /// Environment variable not found, with the var in question as extra info. - EnvVarNotFound, - /// Error occurred while using external tools (ie: invocation of compiler). - ToolExecError, - /// Error occurred due to missing external tools. - ToolNotFound, -} - -/// Represents an internal error that occurred, with an explanation. -#[derive(Clone, Debug)] -pub struct Error { - /// Describes the kind of error that occurred. - kind: ErrorKind, - /// More explanation of error that occurred. - message: String, -} - -impl Error { - fn new(kind: ErrorKind, message: &str) -> Error { - Error { - kind: kind, - message: message.to_owned(), - } - } -} - -impl From for Error { - fn from(e: io::Error) -> Error { - Error::new(ErrorKind::IOError, &format!("{}", e)) - } -} - -impl Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}: {}", self.kind, self.message) - } -} - -/// Configuration used to represent an invocation of a C compiler. -/// -/// This can be used to figure out what compiler is in use, what the arguments -/// to it are, and what the environment variables look like for the compiler. -/// This can be used to further configure other build systems (e.g. forward -/// along CC and/or CFLAGS) or the `to_command` method can be used to run the -/// compiler itself. -#[derive(Clone, Debug)] -pub struct Tool { - path: PathBuf, - cc_wrapper_path: Option, - cc_wrapper_args: Vec, - args: Vec, - env: Vec<(OsString, OsString)>, - family: ToolFamily, - cuda: bool, - removed_args: Vec, -} - -/// Represents the family of tools this tool belongs to. -/// -/// Each family of tools differs in how and what arguments they accept. -/// -/// Detection of a family is done on best-effort basis and may not accurately reflect the tool. -#[derive(Copy, Clone, Debug, PartialEq)] -enum ToolFamily { - /// Tool is GNU Compiler Collection-like. - Gnu, - /// Tool is Clang-like. It differs from the GCC in a sense that it accepts superset of flags - /// and its cross-compilation approach is different. - Clang, - /// Tool is the MSVC cl.exe. - Msvc { clang_cl: bool }, -} - -impl ToolFamily { - /// What the flag to request debug info for this family of tools look like - fn add_debug_flags(&self, cmd: &mut Tool) { - match *self { - ToolFamily::Msvc { .. } => { - cmd.push_cc_arg("-Z7".into()); - } - ToolFamily::Gnu | ToolFamily::Clang => { - cmd.push_cc_arg("-g".into()); - } - } - } - - /// What the flag to force frame pointers. - fn add_force_frame_pointer(&self, cmd: &mut Tool) { - match *self { - ToolFamily::Gnu | ToolFamily::Clang => { - cmd.push_cc_arg("-fno-omit-frame-pointer".into()); - } - _ => (), - } - } - - /// What the flags to enable all warnings - fn warnings_flags(&self) -> &'static str { - match *self { - ToolFamily::Msvc { .. } => "-W4", - ToolFamily::Gnu | ToolFamily::Clang => "-Wall", - } - } - - /// What the flags to enable extra warnings - fn extra_warnings_flags(&self) -> Option<&'static str> { - match *self { - ToolFamily::Msvc { .. } => None, - ToolFamily::Gnu | ToolFamily::Clang => Some("-Wextra"), - } - } - - /// What the flag to turn warning into errors - fn warnings_to_errors_flag(&self) -> &'static str { - match *self { - ToolFamily::Msvc { .. } => "-WX", - ToolFamily::Gnu | ToolFamily::Clang => "-Werror", - } - } - - fn verbose_stderr(&self) -> bool { - *self == ToolFamily::Clang - } -} - -/// Represents an object. -/// -/// This is a source file -> object file pair. -#[derive(Clone, Debug)] -struct Object { - src: PathBuf, - dst: PathBuf, -} - -impl Object { - /// Create a new source file -> object file pair. - fn new(src: PathBuf, dst: PathBuf) -> Object { - Object { src: src, dst: dst } - } -} - -impl Build { - /// Construct a new instance of a blank set of configuration. - /// - /// This builder is finished with the [`compile`] function. - /// - /// [`compile`]: struct.Build.html#method.compile - pub fn new() -> Build { - Build { - include_directories: Vec::new(), - definitions: Vec::new(), - objects: Vec::new(), - flags: Vec::new(), - flags_supported: Vec::new(), - known_flag_support_status: Arc::new(Mutex::new(HashMap::new())), - ar_flags: Vec::new(), - no_default_flags: false, - files: Vec::new(), - shared_flag: None, - static_flag: None, - cpp: false, - cpp_link_stdlib: None, - cpp_set_stdlib: None, - cuda: false, - target: None, - host: None, - out_dir: None, - opt_level: None, - debug: None, - force_frame_pointer: None, - env: Vec::new(), - compiler: None, - archiver: None, - cargo_metadata: true, - pic: None, - use_plt: None, - static_crt: None, - warnings: None, - extra_warnings: None, - warnings_into_errors: false, - env_cache: Arc::new(Mutex::new(HashMap::new())), - } - } - - /// Add a directory to the `-I` or include path for headers - /// - /// # Example - /// - /// ```no_run - /// use std::path::Path; - /// - /// let library_path = Path::new("/path/to/library"); - /// - /// cc::Build::new() - /// .file("src/foo.c") - /// .include(library_path) - /// .include("src") - /// .compile("foo"); - /// ``` - pub fn include>(&mut self, dir: P) -> &mut Build { - self.include_directories.push(dir.as_ref().to_path_buf()); - self - } - - /// Specify a `-D` variable with an optional value. - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .define("FOO", "BAR") - /// .define("BAZ", None) - /// .compile("foo"); - /// ``` - pub fn define<'a, V: Into>>(&mut self, var: &str, val: V) -> &mut Build { - self.definitions - .push((var.to_string(), val.into().map(|s| s.to_string()))); - self - } - - /// Add an arbitrary object file to link in - pub fn object>(&mut self, obj: P) -> &mut Build { - self.objects.push(obj.as_ref().to_path_buf()); - self - } - - /// Add an arbitrary flag to the invocation of the compiler - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .flag("-ffunction-sections") - /// .compile("foo"); - /// ``` - pub fn flag(&mut self, flag: &str) -> &mut Build { - self.flags.push(flag.to_string()); - self - } - - /// Add an arbitrary flag to the invocation of the compiler - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .file("src/bar.c") - /// .ar_flag("/NODEFAULTLIB:libc.dll") - /// .compile("foo"); - /// ``` - - pub fn ar_flag(&mut self, flag: &str) -> &mut Build { - self.ar_flags.push(flag.to_string()); - self - } - - fn ensure_check_file(&self) -> Result { - let out_dir = self.get_out_dir()?; - let src = if self.cuda { - assert!(self.cpp); - out_dir.join("flag_check.cu") - } else if self.cpp { - out_dir.join("flag_check.cpp") - } else { - out_dir.join("flag_check.c") - }; - - if !src.exists() { - let mut f = fs::File::create(&src)?; - write!(f, "int main(void) {{ return 0; }}")?; - } - - Ok(src) - } - - /// Run the compiler to test if it accepts the given flag. - /// - /// For a convenience method for setting flags conditionally, - /// see `flag_if_supported()`. - /// - /// It may return error if it's unable to run the compilier with a test file - /// (e.g. the compiler is missing or a write to the `out_dir` failed). - /// - /// Note: Once computed, the result of this call is stored in the - /// `known_flag_support` field. If `is_flag_supported(flag)` - /// is called again, the result will be read from the hash table. - pub fn is_flag_supported(&self, flag: &str) -> Result { - let mut known_status = self.known_flag_support_status.lock().unwrap(); - if let Some(is_supported) = known_status.get(flag).cloned() { - return Ok(is_supported); - } - - let out_dir = self.get_out_dir()?; - let src = self.ensure_check_file()?; - let obj = out_dir.join("flag_check"); - let target = self.get_target()?; - let host = self.get_host()?; - let mut cfg = Build::new(); - cfg.flag(flag) - .target(&target) - .opt_level(0) - .host(&host) - .debug(false) - .cpp(self.cpp) - .cuda(self.cuda); - let mut compiler = cfg.try_get_compiler()?; - - // Clang uses stderr for verbose output, which yields a false positive - // result if the CFLAGS/CXXFLAGS include -v to aid in debugging. - if compiler.family.verbose_stderr() { - compiler.remove_arg("-v".into()); - } - - let mut cmd = compiler.to_command(); - let is_arm = target.contains("aarch64") || target.contains("arm"); - command_add_output_file( - &mut cmd, - &obj, - self.cuda, - target.contains("msvc"), - false, - is_arm, - ); - - // We need to explicitly tell msvc not to link and create an exe - // in the root directory of the crate - if target.contains("msvc") && !self.cuda { - cmd.arg("-c"); - } - - cmd.arg(&src); - - let output = cmd.output()?; - let is_supported = output.stderr.is_empty(); - - known_status.insert(flag.to_owned(), is_supported); - Ok(is_supported) - } - - /// Add an arbitrary flag to the invocation of the compiler if it supports it - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .flag_if_supported("-Wlogical-op") // only supported by GCC - /// .flag_if_supported("-Wunreachable-code") // only supported by clang - /// .compile("foo"); - /// ``` - pub fn flag_if_supported(&mut self, flag: &str) -> &mut Build { - self.flags_supported.push(flag.to_string()); - self - } - - /// Set the `-shared` flag. - /// - /// When enabled, the compiler will produce a shared object which can - /// then be linked with other objects to form an executable. - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .shared_flag(true) - /// .compile("libfoo.so"); - /// ``` - pub fn shared_flag(&mut self, shared_flag: bool) -> &mut Build { - self.shared_flag = Some(shared_flag); - self - } - - /// Set the `-static` flag. - /// - /// When enabled on systems that support dynamic linking, this prevents - /// linking with the shared libraries. - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .shared_flag(true) - /// .static_flag(true) - /// .compile("foo"); - /// ``` - pub fn static_flag(&mut self, static_flag: bool) -> &mut Build { - self.static_flag = Some(static_flag); - self - } - - /// Disables the generation of default compiler flags. The default compiler - /// flags may cause conflicts in some cross compiling scenarios. - /// - /// Setting the `CRATE_CC_NO_DEFAULTS` environment variable has the same - /// effect as setting this to `true`. The presence of the environment - /// variable and the value of `no_default_flags` will be OR'd together. - pub fn no_default_flags(&mut self, no_default_flags: bool) -> &mut Build { - self.no_default_flags = no_default_flags; - self - } - - /// Add a file which will be compiled - pub fn file>(&mut self, p: P) -> &mut Build { - self.files.push(p.as_ref().to_path_buf()); - self - } - - /// Add files which will be compiled - pub fn files

(&mut self, p: P) -> &mut Build - where - P: IntoIterator, - P::Item: AsRef, - { - for file in p.into_iter() { - self.file(file); - } - self - } - - /// Set C++ support. - /// - /// The other `cpp_*` options will only become active if this is set to - /// `true`. - pub fn cpp(&mut self, cpp: bool) -> &mut Build { - self.cpp = cpp; - self - } - - /// Set CUDA C++ support. - /// - /// Enabling CUDA will pass the detected C/C++ toolchain as an argument to - /// the CUDA compiler, NVCC. NVCC itself accepts some limited GNU-like args; - /// any other arguments for the C/C++ toolchain will be redirected using - /// "-Xcompiler" flags. - /// - /// If enabled, this also implicitly enables C++ support. - pub fn cuda(&mut self, cuda: bool) -> &mut Build { - self.cuda = cuda; - if cuda { - self.cpp = true; - } - self - } - - /// Set warnings into errors flag. - /// - /// Disabled by default. - /// - /// Warning: turning warnings into errors only make sense - /// if you are a developer of the crate using cc-rs. - /// Some warnings only appear on some architecture or - /// specific version of the compiler. Any user of this crate, - /// or any other crate depending on it, could fail during - /// compile time. - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .warnings_into_errors(true) - /// .compile("libfoo.a"); - /// ``` - pub fn warnings_into_errors(&mut self, warnings_into_errors: bool) -> &mut Build { - self.warnings_into_errors = warnings_into_errors; - self - } - - /// Set warnings flags. - /// - /// Adds some flags: - /// - "-Wall" for MSVC. - /// - "-Wall", "-Wextra" for GNU and Clang. - /// - /// Enabled by default. - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .warnings(false) - /// .compile("libfoo.a"); - /// ``` - pub fn warnings(&mut self, warnings: bool) -> &mut Build { - self.warnings = Some(warnings); - self.extra_warnings = Some(warnings); - self - } - - /// Set extra warnings flags. - /// - /// Adds some flags: - /// - nothing for MSVC. - /// - "-Wextra" for GNU and Clang. - /// - /// Enabled by default. - /// - /// # Example - /// - /// ```no_run - /// // Disables -Wextra, -Wall remains enabled: - /// cc::Build::new() - /// .file("src/foo.c") - /// .extra_warnings(false) - /// .compile("libfoo.a"); - /// ``` - pub fn extra_warnings(&mut self, warnings: bool) -> &mut Build { - self.extra_warnings = Some(warnings); - self - } - - /// Set the standard library to link against when compiling with C++ - /// support. - /// - /// The default value of this property depends on the current target: On - /// OS X `Some("c++")` is used, when compiling for a Visual Studio based - /// target `None` is used and for other targets `Some("stdc++")` is used. - /// If the `CXXSTDLIB` environment variable is set, its value will - /// override the default value. - /// - /// A value of `None` indicates that no automatic linking should happen, - /// otherwise cargo will link against the specified library. - /// - /// The given library name must not contain the `lib` prefix. - /// - /// Common values: - /// - `stdc++` for GNU - /// - `c++` for Clang - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .shared_flag(true) - /// .cpp_link_stdlib("stdc++") - /// .compile("libfoo.so"); - /// ``` - pub fn cpp_link_stdlib<'a, V: Into>>( - &mut self, - cpp_link_stdlib: V, - ) -> &mut Build { - self.cpp_link_stdlib = Some(cpp_link_stdlib.into().map(|s| s.into())); - self - } - - /// Force the C++ compiler to use the specified standard library. - /// - /// Setting this option will automatically set `cpp_link_stdlib` to the same - /// value. - /// - /// The default value of this option is always `None`. - /// - /// This option has no effect when compiling for a Visual Studio based - /// target. - /// - /// This option sets the `-stdlib` flag, which is only supported by some - /// compilers (clang, icc) but not by others (gcc). The library will not - /// detect which compiler is used, as such it is the responsibility of the - /// caller to ensure that this option is only used in conjuction with a - /// compiler which supports the `-stdlib` flag. - /// - /// A value of `None` indicates that no specific C++ standard library should - /// be used, otherwise `-stdlib` is added to the compile invocation. - /// - /// The given library name must not contain the `lib` prefix. - /// - /// Common values: - /// - `stdc++` for GNU - /// - `c++` for Clang - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .cpp_set_stdlib("c++") - /// .compile("libfoo.a"); - /// ``` - pub fn cpp_set_stdlib<'a, V: Into>>( - &mut self, - cpp_set_stdlib: V, - ) -> &mut Build { - let cpp_set_stdlib = cpp_set_stdlib.into(); - self.cpp_set_stdlib = cpp_set_stdlib.map(|s| s.into()); - self.cpp_link_stdlib(cpp_set_stdlib); - self - } - - /// Configures the target this configuration will be compiling for. - /// - /// This option is automatically scraped from the `TARGET` environment - /// variable by build scripts, so it's not required to call this function. - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .target("aarch64-linux-android") - /// .compile("foo"); - /// ``` - pub fn target(&mut self, target: &str) -> &mut Build { - self.target = Some(target.to_string()); - self - } - - /// Configures the host assumed by this configuration. - /// - /// This option is automatically scraped from the `HOST` environment - /// variable by build scripts, so it's not required to call this function. - /// - /// # Example - /// - /// ```no_run - /// cc::Build::new() - /// .file("src/foo.c") - /// .host("arm-linux-gnueabihf") - /// .compile("foo"); - /// ``` - pub fn host(&mut self, host: &str) -> &mut Build { - self.host = Some(host.to_string()); - self - } - - /// Configures the optimization level of the generated object files. - /// - /// This option is automatically scraped from the `OPT_LEVEL` environment - /// variable by build scripts, so it's not required to call this function. - pub fn opt_level(&mut self, opt_level: u32) -> &mut Build { - self.opt_level = Some(opt_level.to_string()); - self - } - - /// Configures the optimization level of the generated object files. - /// - /// This option is automatically scraped from the `OPT_LEVEL` environment - /// variable by build scripts, so it's not required to call this function. - pub fn opt_level_str(&mut self, opt_level: &str) -> &mut Build { - self.opt_level = Some(opt_level.to_string()); - self - } - - /// Configures whether the compiler will emit debug information when - /// generating object files. - /// - /// This option is automatically scraped from the `DEBUG` environment - /// variable by build scripts, so it's not required to call this function. - pub fn debug(&mut self, debug: bool) -> &mut Build { - self.debug = Some(debug); - self - } - - /// Configures whether the compiler will emit instructions to store - /// frame pointers during codegen. - /// - /// This option is automatically enabled when debug information is emitted. - /// Otherwise the target platform compiler's default will be used. - /// You can use this option to force a specific setting. - pub fn force_frame_pointer(&mut self, force: bool) -> &mut Build { - self.force_frame_pointer = Some(force); - self - } - - /// Configures the output directory where all object files and static - /// libraries will be located. - /// - /// This option is automatically scraped from the `OUT_DIR` environment - /// variable by build scripts, so it's not required to call this function. - pub fn out_dir>(&mut self, out_dir: P) -> &mut Build { - self.out_dir = Some(out_dir.as_ref().to_owned()); - self - } - - /// Configures the compiler to be used to produce output. - /// - /// This option is automatically determined from the target platform or a - /// number of environment variables, so it's not required to call this - /// function. - pub fn compiler>(&mut self, compiler: P) -> &mut Build { - self.compiler = Some(compiler.as_ref().to_owned()); - self - } - - /// Configures the tool used to assemble archives. - /// - /// This option is automatically determined from the target platform or a - /// number of environment variables, so it's not required to call this - /// function. - pub fn archiver>(&mut self, archiver: P) -> &mut Build { - self.archiver = Some(archiver.as_ref().to_owned()); - self - } - /// Define whether metadata should be emitted for cargo allowing it to - /// automatically link the binary. Defaults to `true`. - /// - /// The emitted metadata is: - /// - /// - `rustc-link-lib=static=`*compiled lib* - /// - `rustc-link-search=native=`*target folder* - /// - When target is MSVC, the ATL-MFC libs are added via `rustc-link-search=native=` - /// - When C++ is enabled, the C++ stdlib is added via `rustc-link-lib` - /// - pub fn cargo_metadata(&mut self, cargo_metadata: bool) -> &mut Build { - self.cargo_metadata = cargo_metadata; - self - } - - /// Configures whether the compiler will emit position independent code. - /// - /// This option defaults to `false` for `windows-gnu` and `riscv` targets and - /// to `true` for all other targets. - pub fn pic(&mut self, pic: bool) -> &mut Build { - self.pic = Some(pic); - self - } - - /// Configures whether the Procedure Linkage Table is used for indirect - /// calls into shared libraries. - /// - /// The PLT is used to provide features like lazy binding, but introduces - /// a small performance loss due to extra pointer indirection. Setting - /// `use_plt` to `false` can provide a small performance increase. - /// - /// Note that skipping the PLT requires a recent version of GCC/Clang. - /// - /// This only applies to ELF targets. It has no effect on other platforms. - pub fn use_plt(&mut self, use_plt: bool) -> &mut Build { - self.use_plt = Some(use_plt); - self - } - - /// Configures whether the /MT flag or the /MD flag will be passed to msvc build tools. - /// - /// This option defaults to `false`, and affect only msvc targets. - pub fn static_crt(&mut self, static_crt: bool) -> &mut Build { - self.static_crt = Some(static_crt); - self - } - - #[doc(hidden)] - pub fn __set_env(&mut self, a: A, b: B) -> &mut Build - where - A: AsRef, - B: AsRef, - { - self.env - .push((a.as_ref().to_owned(), b.as_ref().to_owned())); - self - } - - /// Run the compiler, generating the file `output` - /// - /// This will return a result instead of panicing; see compile() for the complete description. - pub fn try_compile(&self, output: &str) -> Result<(), Error> { - let (lib_name, gnu_lib_name) = if output.starts_with("lib") && output.ends_with(".a") { - (&output[3..output.len() - 2], output.to_owned()) - } else { - let mut gnu = String::with_capacity(5 + output.len()); - gnu.push_str("lib"); - gnu.push_str(&output); - gnu.push_str(".a"); - (output, gnu) - }; - let dst = self.get_out_dir()?; - - let mut objects = Vec::new(); - for file in self.files.iter() { - let obj = dst.join(file).with_extension("o"); - let obj = if !obj.starts_with(&dst) { - dst.join(obj.file_name().ok_or_else(|| { - Error::new(ErrorKind::IOError, "Getting object file details failed.") - })?) - } else { - obj - }; - - match obj.parent() { - Some(s) => fs::create_dir_all(s)?, - None => { - return Err(Error::new( - ErrorKind::IOError, - "Getting object file details failed.", - )); - } - }; - - objects.push(Object::new(file.to_path_buf(), obj)); - } - self.compile_objects(&objects)?; - self.assemble(lib_name, &dst.join(gnu_lib_name), &objects)?; - - if self.get_target()?.contains("msvc") { - let compiler = self.get_base_compiler()?; - let atlmfc_lib = compiler - .env() - .iter() - .find(|&&(ref var, _)| var.as_os_str() == OsStr::new("LIB")) - .and_then(|&(_, ref lib_paths)| { - env::split_paths(lib_paths).find(|path| { - let sub = Path::new("atlmfc/lib"); - path.ends_with(sub) || path.parent().map_or(false, |p| p.ends_with(sub)) - }) - }); - - if let Some(atlmfc_lib) = atlmfc_lib { - self.print(&format!( - "cargo:rustc-link-search=native={}", - atlmfc_lib.display() - )); - } - } - - self.print(&format!("cargo:rustc-link-lib=static={}", lib_name)); - self.print(&format!("cargo:rustc-link-search=native={}", dst.display())); - - // Add specific C++ libraries, if enabled. - if self.cpp { - if let Some(stdlib) = self.get_cpp_link_stdlib()? { - self.print(&format!("cargo:rustc-link-lib={}", stdlib)); - } - } - - Ok(()) - } - - /// Run the compiler, generating the file `output` - /// - /// The name `output` should be the name of the library. For backwards compatibility, - /// the `output` may start with `lib` and end with `.a`. The Rust compilier will create - /// the assembly with the lib prefix and .a extension. MSVC will create a file without prefix, - /// ending with `.lib`. - /// - /// # Panics - /// - /// Panics if `output` is not formatted correctly or if one of the underlying - /// compiler commands fails. It can also panic if it fails reading file names - /// or creating directories. - pub fn compile(&self, output: &str) { - if let Err(e) = self.try_compile(output) { - fail(&e.message); - } - } - - #[cfg(feature = "parallel")] - fn compile_objects<'me>(&'me self, objs: &[Object]) -> Result<(), Error> { - use std::sync::atomic::{AtomicBool, Ordering::SeqCst}; - use std::sync::Once; - - // Limit our parallelism globally with a jobserver. Start off by - // releasing our own token for this process so we can have a bit of an - // easier to write loop below. If this fails, though, then we're likely - // on Windows with the main implicit token, so we just have a bit extra - // parallelism for a bit and don't reacquire later. - let server = jobserver(); - let reacquire = server.release_raw().is_ok(); - - // When compiling objects in parallel we do a few dirty tricks to speed - // things up: - // - // * First is that we use the `jobserver` crate to limit the parallelism - // of this build script. The `jobserver` crate will use a jobserver - // configured by Cargo for build scripts to ensure that parallelism is - // coordinated across C compilations and Rust compilations. Before we - // compile anything we make sure to wait until we acquire a token. - // - // Note that this jobserver is cached globally so we only used one per - // process and only worry about creating it once. - // - // * Next we use a raw `thread::spawn` per thread to actually compile - // objects in parallel. We only actually spawn a thread after we've - // acquired a token to perform some work - // - // * Finally though we want to keep the dependencies of this crate - // pretty light, so we avoid using a safe abstraction like `rayon` and - // instead rely on some bits of `unsafe` code. We know that this stack - // frame persists while everything is compiling so we use all the - // stack-allocated objects without cloning/reallocating. We use a - // transmute to `State` with a `'static` lifetime to persist - // everything we need across the boundary, and the join-on-drop - // semantics of `JoinOnDrop` should ensure that our stack frame is - // alive while threads are alive. - // - // With all that in mind we compile all objects in a loop here, after we - // acquire the appropriate tokens, Once all objects have been compiled - // we join on all the threads and propagate the results of compilation. - // - // Note that as a slight optimization we try to break out as soon as - // possible as soon as any compilation fails to ensure that errors get - // out to the user as fast as possible. - let error = AtomicBool::new(false); - let mut threads = Vec::new(); - for obj in objs { - if error.load(SeqCst) { - break; - } - let token = server.acquire()?; - let state = State { - build: self, - obj, - error: &error, - }; - let state = unsafe { std::mem::transmute::>(state) }; - let thread = thread::spawn(|| { - let state: State<'me> = state; // erase the `'static` lifetime - let result = state.build.compile_object(state.obj); - if result.is_err() { - state.error.store(true, SeqCst); - } - drop(token); // make sure our jobserver token is released after the compile - return result; - }); - threads.push(JoinOnDrop(Some(thread))); - } - - for mut thread in threads { - if let Some(thread) = thread.0.take() { - thread.join().expect("thread should not panic")?; - } - } - - // Reacquire our process's token before we proceed, which we released - // before entering the loop above. - if reacquire { - server.acquire_raw()?; - } - - return Ok(()); - - /// Shared state from the parent thread to the child thread. This - /// package of pointers is temporarily transmuted to a `'static` - /// lifetime to cross the thread boundary and then once the thread is - /// running we erase the `'static` to go back to an anonymous lifetime. - struct State<'a> { - build: &'a Build, - obj: &'a Object, - error: &'a AtomicBool, - } - - /// Returns a suitable `jobserver::Client` used to coordinate - /// parallelism between build scripts. - fn jobserver() -> &'static jobserver::Client { - static INIT: Once = Once::new(); - static mut JOBSERVER: Option = None; - - fn _assert_sync() {} - _assert_sync::(); - - unsafe { - INIT.call_once(|| { - let server = default_jobserver(); - JOBSERVER = Some(server); - }); - JOBSERVER.as_ref().unwrap() - } - } - - unsafe fn default_jobserver() -> jobserver::Client { - // Try to use the environmental jobserver which Cargo typically - // initializes for us... - if let Some(client) = jobserver::Client::from_env() { - return client; - } - - // ... but if that fails for whatever reason fall back to the number - // of cpus on the system or the `NUM_JOBS` env var. - let mut parallelism = num_cpus::get(); - if let Ok(amt) = env::var("NUM_JOBS") { - if let Ok(amt) = amt.parse() { - parallelism = amt; - } - } - - // If we create our own jobserver then be sure to reserve one token - // for ourselves. - let client = jobserver::Client::new(parallelism).expect("failed to create jobserver"); - client.acquire_raw().expect("failed to acquire initial"); - return client; - } - - struct JoinOnDrop(Option>>); - - impl Drop for JoinOnDrop { - fn drop(&mut self) { - if let Some(thread) = self.0.take() { - drop(thread.join()); - } - } - } - } - - #[cfg(not(feature = "parallel"))] - fn compile_objects(&self, objs: &[Object]) -> Result<(), Error> { - for obj in objs { - self.compile_object(obj)?; - } - Ok(()) - } - - fn compile_object(&self, obj: &Object) -> Result<(), Error> { - let is_asm = obj.src.extension().and_then(|s| s.to_str()) == Some("asm"); - let target = self.get_target()?; - let msvc = target.contains("msvc"); - let (mut cmd, name) = if msvc && is_asm { - self.msvc_macro_assembler()? - } else { - let compiler = self.try_get_compiler()?; - let mut cmd = compiler.to_command(); - for &(ref a, ref b) in self.env.iter() { - cmd.env(a, b); - } - ( - cmd, - compiler - .path - .file_name() - .ok_or_else(|| Error::new(ErrorKind::IOError, "Failed to get compiler path."))? - .to_string_lossy() - .into_owned(), - ) - }; - let is_arm = target.contains("aarch64") || target.contains("arm"); - command_add_output_file(&mut cmd, &obj.dst, self.cuda, msvc, is_asm, is_arm); - // armasm and armasm64 don't requrie -c option - if !msvc || !is_asm || !is_arm { - cmd.arg("-c"); - } - cmd.arg(&obj.src); - - run(&mut cmd, &name)?; - Ok(()) - } - - /// This will return a result instead of panicing; see expand() for the complete description. - pub fn try_expand(&self) -> Result, Error> { - let compiler = self.try_get_compiler()?; - let mut cmd = compiler.to_command(); - for &(ref a, ref b) in self.env.iter() { - cmd.env(a, b); - } - cmd.arg("-E"); - - assert!( - self.files.len() <= 1, - "Expand may only be called for a single file" - ); - - for file in self.files.iter() { - cmd.arg(file); - } - - let name = compiler - .path - .file_name() - .ok_or_else(|| Error::new(ErrorKind::IOError, "Failed to get compiler path."))? - .to_string_lossy() - .into_owned(); - - Ok(run_output(&mut cmd, &name)?) - } - - /// Run the compiler, returning the macro-expanded version of the input files. - /// - /// This is only relevant for C and C++ files. - /// - /// # Panics - /// Panics if more than one file is present in the config, or if compiler - /// path has an invalid file name. - /// - /// # Example - /// ```no_run - /// let out = cc::Build::new().file("src/foo.c").expand(); - /// ``` - pub fn expand(&self) -> Vec { - match self.try_expand() { - Err(e) => fail(&e.message), - Ok(v) => v, - } - } - - /// Get the compiler that's in use for this configuration. - /// - /// This function will return a `Tool` which represents the culmination - /// of this configuration at a snapshot in time. The returned compiler can - /// be inspected (e.g. the path, arguments, environment) to forward along to - /// other tools, or the `to_command` method can be used to invoke the - /// compiler itself. - /// - /// This method will take into account all configuration such as debug - /// information, optimization level, include directories, defines, etc. - /// Additionally, the compiler binary in use follows the standard - /// conventions for this path, e.g. looking at the explicitly set compiler, - /// environment variables (a number of which are inspected here), and then - /// falling back to the default configuration. - /// - /// # Panics - /// - /// Panics if an error occurred while determining the architecture. - pub fn get_compiler(&self) -> Tool { - match self.try_get_compiler() { - Ok(tool) => tool, - Err(e) => fail(&e.message), - } - } - - /// Get the compiler that's in use for this configuration. - /// - /// This will return a result instead of panicing; see get_compiler() for the complete description. - pub fn try_get_compiler(&self) -> Result { - let opt_level = self.get_opt_level()?; - let target = self.get_target()?; - - let mut cmd = self.get_base_compiler()?; - let envflags = self.envflags(if self.cpp { "CXXFLAGS" } else { "CFLAGS" }); - - // Disable default flag generation via `no_default_flags` or environment variable - let no_defaults = self.no_default_flags || self.getenv("CRATE_CC_NO_DEFAULTS").is_some(); - - if !no_defaults { - self.add_default_flags(&mut cmd, &target, &opt_level)?; - } else { - println!("Info: default compiler flags are disabled"); - } - - for arg in envflags { - cmd.push_cc_arg(arg.into()); - } - - for directory in self.include_directories.iter() { - cmd.args.push("-I".into()); - cmd.args.push(directory.into()); - } - - // If warnings and/or extra_warnings haven't been explicitly set, - // then we set them only if the environment doesn't already have - // CFLAGS/CXXFLAGS, since those variables presumably already contain - // the desired set of warnings flags. - - if self - .warnings - .unwrap_or(if self.has_flags() { false } else { true }) - { - let wflags = cmd.family.warnings_flags().into(); - cmd.push_cc_arg(wflags); - } - - if self - .extra_warnings - .unwrap_or(if self.has_flags() { false } else { true }) - { - if let Some(wflags) = cmd.family.extra_warnings_flags() { - cmd.push_cc_arg(wflags.into()); - } - } - - for flag in self.flags.iter() { - cmd.args.push(flag.into()); - } - - for flag in self.flags_supported.iter() { - if self.is_flag_supported(flag).unwrap_or(false) { - cmd.push_cc_arg(flag.into()); - } - } - - for &(ref key, ref value) in self.definitions.iter() { - if let Some(ref value) = *value { - cmd.args.push(format!("-D{}={}", key, value).into()); - } else { - cmd.args.push(format!("-D{}", key).into()); - } - } - - if self.warnings_into_errors { - let warnings_to_errors_flag = cmd.family.warnings_to_errors_flag().into(); - cmd.push_cc_arg(warnings_to_errors_flag); - } - - Ok(cmd) - } - - fn add_default_flags( - &self, - cmd: &mut Tool, - target: &str, - opt_level: &str, - ) -> Result<(), Error> { - // Non-target flags - // If the flag is not conditioned on target variable, it belongs here :) - match cmd.family { - ToolFamily::Msvc { .. } => { - cmd.push_cc_arg("-nologo".into()); - - let crt_flag = match self.static_crt { - Some(true) => "-MT", - Some(false) => "-MD", - None => { - let features = self - .getenv("CARGO_CFG_TARGET_FEATURE") - .unwrap_or(String::new()); - if features.contains("crt-static") { - "-MT" - } else { - "-MD" - } - } - }; - cmd.push_cc_arg(crt_flag.into()); - - match &opt_level[..] { - // Msvc uses /O1 to enable all optimizations that minimize code size. - "z" | "s" | "1" => cmd.push_opt_unless_duplicate("-O1".into()), - // -O3 is a valid value for gcc and clang compilers, but not msvc. Cap to /O2. - "2" | "3" => cmd.push_opt_unless_duplicate("-O2".into()), - _ => {} - } - } - ToolFamily::Gnu | ToolFamily::Clang => { - // arm-linux-androideabi-gcc 4.8 shipped with Android NDK does - // not support '-Oz' - if opt_level == "z" && cmd.family != ToolFamily::Clang { - cmd.push_opt_unless_duplicate("-Os".into()); - } else { - cmd.push_opt_unless_duplicate(format!("-O{}", opt_level).into()); - } - - if !target.contains("-ios") { - cmd.push_cc_arg("-ffunction-sections".into()); - cmd.push_cc_arg("-fdata-sections".into()); - } - // Disable generation of PIC on RISC-V for now: rust-lld doesn't support this yet - if self - .pic - .unwrap_or(!target.contains("windows-gnu") && !target.contains("riscv")) - { - cmd.push_cc_arg("-fPIC".into()); - // PLT only applies if code is compiled with PIC support, - // and only for ELF targets. - if target.contains("linux") && !self.use_plt.unwrap_or(true) { - cmd.push_cc_arg("-fno-plt".into()); - } - } - } - } - - if self.get_debug() { - if self.cuda { - // NVCC debug flag - cmd.args.push("-G".into()); - } - let family = cmd.family; - family.add_debug_flags(cmd); - } - - if self.get_force_frame_pointer() { - let family = cmd.family; - family.add_force_frame_pointer(cmd); - } - - // Target flags - match cmd.family { - ToolFamily::Clang => { - cmd.args.push(format!("--target={}", target).into()); - } - ToolFamily::Msvc { clang_cl } => { - // This is an undocumented flag from MSVC but helps with making - // builds more reproducible by avoiding putting timestamps into - // files. - cmd.args.push("-Brepro".into()); - - if clang_cl { - if target.contains("x86_64") { - cmd.args.push("-m64".into()); - } else if target.contains("86") { - cmd.args.push("-m32".into()); - cmd.push_cc_arg("-arch:IA32".into()); - } else { - cmd.push_cc_arg(format!("--target={}", target).into()); - } - } else { - if target.contains("i586") { - cmd.push_cc_arg("-arch:IA32".into()); - } - } - - // There is a check in corecrt.h that will generate a - // compilation error if - // _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE is - // not defined to 1. The check was added in Windows - // 8 days because only store apps were allowed on ARM. - // This changed with the release of Windows 10 IoT Core. - // The check will be going away in future versions of - // the SDK, but for all released versions of the - // Windows SDK it is required. - if target.contains("arm") || target.contains("thumb") { - cmd.args - .push("-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1".into()); - } - } - ToolFamily::Gnu => { - if target.contains("i686") || target.contains("i586") { - cmd.args.push("-m32".into()); - } else if target == "x86_64-unknown-linux-gnux32" { - cmd.args.push("-mx32".into()); - } else if target.contains("x86_64") || target.contains("powerpc64") { - cmd.args.push("-m64".into()); - } - - if self.static_flag.is_none() { - let features = self - .getenv("CARGO_CFG_TARGET_FEATURE") - .unwrap_or(String::new()); - if features.contains("crt-static") { - cmd.args.push("-static".into()); - } - } - - // armv7 targets get to use armv7 instructions - if (target.starts_with("armv7") || target.starts_with("thumbv7")) - && target.contains("-linux-") - { - cmd.args.push("-march=armv7-a".into()); - } - - // (x86 Android doesn't say "eabi") - if target.contains("-androideabi") && target.contains("v7") { - // -march=armv7-a handled above - cmd.args.push("-mthumb".into()); - if !target.contains("neon") { - // On android we can guarantee some extra float instructions - // (specified in the android spec online) - // NEON guarantees even more; see below. - cmd.args.push("-mfpu=vfpv3-d16".into()); - } - cmd.args.push("-mfloat-abi=softfp".into()); - } - - if target.contains("neon") { - cmd.args.push("-mfpu=neon-vfpv4".into()); - } - - if target.starts_with("armv4t-unknown-linux-") { - cmd.args.push("-march=armv4t".into()); - cmd.args.push("-marm".into()); - cmd.args.push("-mfloat-abi=soft".into()); - } - - if target.starts_with("armv5te-unknown-linux-") { - cmd.args.push("-march=armv5te".into()); - cmd.args.push("-marm".into()); - cmd.args.push("-mfloat-abi=soft".into()); - } - - // For us arm == armv6 by default - if target.starts_with("arm-unknown-linux-") { - cmd.args.push("-march=armv6".into()); - cmd.args.push("-marm".into()); - if target.ends_with("hf") { - cmd.args.push("-mfpu=vfp".into()); - } else { - cmd.args.push("-mfloat-abi=soft".into()); - } - } - - // We can guarantee some settings for FRC - if target.starts_with("arm-frc-") { - cmd.args.push("-march=armv7-a".into()); - cmd.args.push("-mcpu=cortex-a9".into()); - cmd.args.push("-mfpu=vfpv3".into()); - cmd.args.push("-mfloat-abi=softfp".into()); - cmd.args.push("-marm".into()); - } - - // Turn codegen down on i586 to avoid some instructions. - if target.starts_with("i586-unknown-linux-") { - cmd.args.push("-march=pentium".into()); - } - - // Set codegen level for i686 correctly - if target.starts_with("i686-unknown-linux-") { - cmd.args.push("-march=i686".into()); - } - - // Looks like `musl-gcc` makes is hard for `-m32` to make its way - // all the way to the linker, so we need to actually instruct the - // linker that we're generating 32-bit executables as well. This'll - // typically only be used for build scripts which transitively use - // these flags that try to compile executables. - if target == "i686-unknown-linux-musl" || target == "i586-unknown-linux-musl" { - cmd.args.push("-Wl,-melf_i386".into()); - } - - if target.starts_with("thumb") { - cmd.args.push("-mthumb".into()); - - if target.ends_with("eabihf") { - cmd.args.push("-mfloat-abi=hard".into()) - } - } - if target.starts_with("thumbv6m") { - cmd.args.push("-march=armv6s-m".into()); - } - if target.starts_with("thumbv7em") { - cmd.args.push("-march=armv7e-m".into()); - - if target.ends_with("eabihf") { - cmd.args.push("-mfpu=fpv4-sp-d16".into()) - } - } - if target.starts_with("thumbv7m") { - cmd.args.push("-march=armv7-m".into()); - } - if target.starts_with("thumbv8m.base") { - cmd.args.push("-march=armv8-m.base".into()); - } - if target.starts_with("thumbv8m.main") { - cmd.args.push("-march=armv8-m.main".into()); - - if target.ends_with("eabihf") { - cmd.args.push("-mfpu=fpv5-sp-d16".into()) - } - } - if target.starts_with("armebv7r") | target.starts_with("armv7r") { - if target.starts_with("armeb") { - cmd.args.push("-mbig-endian".into()); - } else { - cmd.args.push("-mlittle-endian".into()); - } - - // ARM mode - cmd.args.push("-marm".into()); - - // R Profile - cmd.args.push("-march=armv7-r".into()); - - if target.ends_with("eabihf") { - // Calling convention - cmd.args.push("-mfloat-abi=hard".into()); - - // lowest common denominator FPU - // (see Cortex-R4 technical reference manual) - cmd.args.push("-mfpu=vfpv3-d16".into()) - } else { - // Calling convention - cmd.args.push("-mfloat-abi=soft".into()); - } - } - if target.starts_with("riscv32") || target.starts_with("riscv64") { - // get the 32i/32imac/32imc/64gc/64imac/... part - let mut parts = target.split('-'); - if let Some(arch) = parts.next() { - let arch = &arch[5..]; - cmd.args.push(("-march=rv".to_owned() + arch).into()); - if target.contains("linux") && arch.starts_with("64") { - cmd.args.push("-mabi=lp64d".into()); - } else if target.contains("linux") && arch.starts_with("32") { - cmd.args.push("-mabi=ilp32d".into()); - } else if arch.starts_with("64") { - cmd.args.push("-mabi=lp64".into()); - } else { - cmd.args.push("-mabi=ilp32".into()); - } - } - } - } - } - - if target.contains("-ios") { - // FIXME: potential bug. iOS is always compiled with Clang, but Gcc compiler may be - // detected instead. - self.ios_flags(cmd)?; - } - - if self.static_flag.unwrap_or(false) { - cmd.args.push("-static".into()); - } - if self.shared_flag.unwrap_or(false) { - cmd.args.push("-shared".into()); - } - - if self.cpp { - match (self.cpp_set_stdlib.as_ref(), cmd.family) { - (None, _) => {} - (Some(stdlib), ToolFamily::Gnu) | (Some(stdlib), ToolFamily::Clang) => { - cmd.push_cc_arg(format!("-stdlib=lib{}", stdlib).into()); - } - _ => { - println!( - "cargo:warning=cpp_set_stdlib is specified, but the {:?} compiler \ - does not support this option, ignored", - cmd.family - ); - } - } - } - - Ok(()) - } - - fn has_flags(&self) -> bool { - let flags_env_var_name = if self.cpp { "CXXFLAGS" } else { "CFLAGS" }; - let flags_env_var_value = self.get_var(flags_env_var_name); - if let Ok(_) = flags_env_var_value { - true - } else { - false - } - } - - fn msvc_macro_assembler(&self) -> Result<(Command, String), Error> { - let target = self.get_target()?; - let tool = if target.contains("x86_64") { - "ml64.exe" - } else if target.contains("arm") { - "armasm.exe" - } else if target.contains("aarch64") { - "armasm64.exe" - } else { - "ml.exe" - }; - let mut cmd = windows_registry::find(&target, tool).unwrap_or_else(|| self.cmd(tool)); - for directory in self.include_directories.iter() { - cmd.arg("-I").arg(directory); - } - for &(ref key, ref value) in self.definitions.iter() { - if let Some(ref value) = *value { - cmd.arg(&format!("-D{}={}", key, value)); - } else { - cmd.arg(&format!("-D{}", key)); - } - } - - if target.contains("i686") || target.contains("i586") { - cmd.arg("-safeseh"); - } - for flag in self.flags.iter() { - cmd.arg(flag); - } - - Ok((cmd, tool.to_string())) - } - - fn assemble(&self, lib_name: &str, dst: &Path, objs: &[Object]) -> Result<(), Error> { - // Delete the destination if it exists as the `ar` tool at least on Unix - // appends to it, which we don't want. - let _ = fs::remove_file(&dst); - - let objects: Vec<_> = objs.iter().map(|obj| obj.dst.clone()).collect(); - let target = self.get_target()?; - if target.contains("msvc") { - let (mut cmd, program) = self.get_ar()?; - let mut out = OsString::from("-out:"); - out.push(dst); - cmd.arg(out).arg("-nologo"); - for flag in self.ar_flags.iter() { - cmd.arg(flag); - } - - // Similar to https://github.com/rust-lang/rust/pull/47507 - // and https://github.com/rust-lang/rust/pull/48548 - let estimated_command_line_len = objects - .iter() - .chain(&self.objects) - .map(|a| a.as_os_str().len()) - .sum::(); - if estimated_command_line_len > 1024 * 6 { - let mut args = String::from("\u{FEFF}"); // BOM - for arg in objects.iter().chain(&self.objects) { - args.push('"'); - for c in arg.to_str().unwrap().chars() { - if c == '"' { - args.push('\\') - } - args.push(c) - } - args.push('"'); - args.push('\n'); - } - - let mut utf16le = Vec::new(); - for code_unit in args.encode_utf16() { - utf16le.push(code_unit as u8); - utf16le.push((code_unit >> 8) as u8); - } - - let mut args_file = OsString::from(dst); - args_file.push(".args"); - fs::File::create(&args_file) - .unwrap() - .write_all(&utf16le) - .unwrap(); - - let mut args_file_arg = OsString::from("@"); - args_file_arg.push(args_file); - cmd.arg(args_file_arg); - } else { - cmd.args(&objects).args(&self.objects); - } - run(&mut cmd, &program)?; - - // The Rust compiler will look for libfoo.a and foo.lib, but the - // MSVC linker will also be passed foo.lib, so be sure that both - // exist for now. - let lib_dst = dst.with_file_name(format!("{}.lib", lib_name)); - let _ = fs::remove_file(&lib_dst); - match fs::hard_link(&dst, &lib_dst).or_else(|_| { - // if hard-link fails, just copy (ignoring the number of bytes written) - fs::copy(&dst, &lib_dst).map(|_| ()) - }) { - Ok(_) => (), - Err(_) => { - return Err(Error::new( - ErrorKind::IOError, - "Could not copy or create a hard-link to the generated lib file.", - )); - } - }; - } else { - let (mut ar, cmd) = self.get_ar()?; - - // Set an environment variable to tell the OSX archiver to ensure - // that all dates listed in the archive are zero, improving - // determinism of builds. AFAIK there's not really official - // documentation of this but there's a lot of references to it if - // you search google. - // - // You can reproduce this locally on a mac with: - // - // $ touch foo.c - // $ cc -c foo.c -o foo.o - // - // # Notice that these two checksums are different - // $ ar crus libfoo1.a foo.o && sleep 2 && ar crus libfoo2.a foo.o - // $ md5sum libfoo*.a - // - // # Notice that these two checksums are the same - // $ export ZERO_AR_DATE=1 - // $ ar crus libfoo1.a foo.o && sleep 2 && touch foo.o && ar crus libfoo2.a foo.o - // $ md5sum libfoo*.a - // - // In any case if this doesn't end up getting read, it shouldn't - // cause that many issues! - ar.env("ZERO_AR_DATE", "1"); - for flag in self.ar_flags.iter() { - ar.arg(flag); - } - run( - ar.arg("crs").arg(dst).args(&objects).args(&self.objects), - &cmd, - )?; - } - - Ok(()) - } - - fn ios_flags(&self, cmd: &mut Tool) -> Result<(), Error> { - enum ArchSpec { - Device(&'static str), - Simulator(&'static str), - } - - let target = self.get_target()?; - let arch = target.split('-').nth(0).ok_or_else(|| { - Error::new( - ErrorKind::ArchitectureInvalid, - "Unknown architecture for iOS target.", - ) - })?; - let arch = match arch { - "arm" | "armv7" | "thumbv7" => ArchSpec::Device("armv7"), - "armv7s" | "thumbv7s" => ArchSpec::Device("armv7s"), - "arm64" | "aarch64" => ArchSpec::Device("arm64"), - "i386" | "i686" => ArchSpec::Simulator("-m32"), - "x86_64" => ArchSpec::Simulator("-m64"), - _ => { - return Err(Error::new( - ErrorKind::ArchitectureInvalid, - "Unknown architecture for iOS target.", - )); - } - }; - - let min_version = - std::env::var("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or_else(|_| "7.0".into()); - - let sdk = match arch { - ArchSpec::Device(arch) => { - cmd.args.push("-arch".into()); - cmd.args.push(arch.into()); - cmd.args - .push(format!("-miphoneos-version-min={}", min_version).into()); - "iphoneos" - } - ArchSpec::Simulator(arch) => { - cmd.args.push(arch.into()); - cmd.args - .push(format!("-mios-simulator-version-min={}", min_version).into()); - "iphonesimulator" - } - }; - - self.print(&format!("Detecting iOS SDK path for {}", sdk)); - let sdk_path = self - .cmd("xcrun") - .arg("--show-sdk-path") - .arg("--sdk") - .arg(sdk) - .stderr(Stdio::inherit()) - .output()? - .stdout; - - let sdk_path = match String::from_utf8(sdk_path) { - Ok(p) => p, - Err(_) => { - return Err(Error::new( - ErrorKind::IOError, - "Unable to determine iOS SDK path.", - )); - } - }; - - cmd.args.push("-isysroot".into()); - cmd.args.push(sdk_path.trim().into()); - cmd.args.push("-fembed-bitcode".into()); - /* - * TODO we probably ultimatedly want the -fembed-bitcode-marker flag - * but can't have it now because of an issue in LLVM: - * https://github.com/alexcrichton/cc-rs/issues/301 - * https://github.com/rust-lang/rust/pull/48896#comment-372192660 - */ - /* - if self.get_opt_level()? == "0" { - cmd.args.push("-fembed-bitcode-marker".into()); - } - */ - - Ok(()) - } - - fn cmd>(&self, prog: P) -> Command { - let mut cmd = Command::new(prog); - for &(ref a, ref b) in self.env.iter() { - cmd.env(a, b); - } - cmd - } - - fn get_base_compiler(&self) -> Result { - if let Some(ref c) = self.compiler { - return Ok(Tool::new(c.clone())); - } - let host = self.get_host()?; - let target = self.get_target()?; - let (env, msvc, gnu, traditional, clang) = if self.cpp { - ("CXX", "cl.exe", "g++", "c++", "clang++") - } else { - ("CC", "cl.exe", "gcc", "cc", "clang") - }; - - // On Solaris, c++/cc unlikely to exist or be correct. - let default = if host.contains("solaris") { - gnu - } else { - traditional - }; - - let cl_exe = windows_registry::find_tool(&target, "cl.exe"); - - let tool_opt: Option = self - .env_tool(env) - .map(|(tool, wrapper, args)| { - // find the driver mode, if any - const DRIVER_MODE: &str = "--driver-mode="; - let driver_mode = args - .iter() - .find(|a| a.starts_with(DRIVER_MODE)) - .map(|a| &a[DRIVER_MODE.len()..]); - // chop off leading/trailing whitespace to work around - // semi-buggy build scripts which are shared in - // makefiles/configure scripts (where spaces are far more - // lenient) - let mut t = Tool::with_clang_driver(PathBuf::from(tool.trim()), driver_mode); - if let Some(cc) = wrapper { - t.cc_wrapper_path = Some(PathBuf::from(cc)); - } - for arg in args { - t.cc_wrapper_args.push(arg.into()); - } - t - }) - .or_else(|| { - if target.contains("emscripten") { - let tool = if self.cpp { "em++" } else { "emcc" }; - // Windows uses bat file so we have to be a bit more specific - if cfg!(windows) { - let mut t = Tool::new(PathBuf::from("cmd")); - t.args.push("/c".into()); - t.args.push(format!("{}.bat", tool).into()); - Some(t) - } else { - Some(Tool::new(PathBuf::from(tool))) - } - } else { - None - } - }) - .or_else(|| cl_exe.clone()); - - let tool = match tool_opt { - Some(t) => t, - None => { - let compiler = if host.contains("windows") && target.contains("windows") { - if target.contains("msvc") { - msvc.to_string() - } else { - format!("{}.exe", gnu) - } - } else if target.contains("android") { - let target = target - .replace("armv7neon", "arm") - .replace("armv7", "arm") - .replace("thumbv7neon", "arm") - .replace("thumbv7", "arm"); - let gnu_compiler = format!("{}-{}", target, gnu); - let clang_compiler = format!("{}-{}", target, clang); - // Check if gnu compiler is present - // if not, use clang - if Command::new(&gnu_compiler).spawn().is_ok() { - gnu_compiler - } else { - clang_compiler - } - } else if target.contains("cloudabi") { - format!("{}-{}", target, traditional) - } else if target == "wasm32-wasi" - || target == "wasm32-unknown-wasi" - || target == "wasm32-unknown-unknown" - { - "clang".to_string() - } else if target.contains("vxworks") { - "wr-c++".to_string() - } else if self.get_host()? != target { - // CROSS_COMPILE is of the form: "arm-linux-gnueabi-" - let cc_env = self.getenv("CROSS_COMPILE"); - let cross_compile = cc_env.as_ref().map(|s| s.trim_right_matches('-')); - let prefix = cross_compile.or(match &target[..] { - "aarch64-unknown-linux-gnu" => Some("aarch64-linux-gnu"), - "aarch64-unknown-linux-musl" => Some("aarch64-linux-musl"), - "aarch64-unknown-netbsd" => Some("aarch64--netbsd"), - "arm-unknown-linux-gnueabi" => Some("arm-linux-gnueabi"), - "armv4t-unknown-linux-gnueabi" => Some("arm-linux-gnueabi"), - "armv5te-unknown-linux-gnueabi" => Some("arm-linux-gnueabi"), - "arm-frc-linux-gnueabi" => Some("arm-frc-linux-gnueabi"), - "arm-unknown-linux-gnueabihf" => Some("arm-linux-gnueabihf"), - "arm-unknown-linux-musleabi" => Some("arm-linux-musleabi"), - "arm-unknown-linux-musleabihf" => Some("arm-linux-musleabihf"), - "arm-unknown-netbsd-eabi" => Some("arm--netbsdelf-eabi"), - "armv6-unknown-netbsd-eabihf" => Some("armv6--netbsdelf-eabihf"), - "armv7-unknown-linux-gnueabihf" => Some("arm-linux-gnueabihf"), - "armv7-unknown-linux-musleabihf" => Some("arm-linux-musleabihf"), - "armv7neon-unknown-linux-gnueabihf" => Some("arm-linux-gnueabihf"), - "armv7neon-unknown-linux-musleabihf" => Some("arm-linux-musleabihf"), - "thumbv7-unknown-linux-gnueabihf" => Some("arm-linux-gnueabihf"), - "thumbv7-unknown-linux-musleabihf" => Some("arm-linux-musleabihf"), - "thumbv7neon-unknown-linux-gnueabihf" => Some("arm-linux-gnueabihf"), - "thumbv7neon-unknown-linux-musleabihf" => Some("arm-linux-musleabihf"), - "armv7-unknown-netbsd-eabihf" => Some("armv7--netbsdelf-eabihf"), - "i586-unknown-linux-musl" => Some("musl"), - "i686-pc-windows-gnu" => Some("i686-w64-mingw32"), - "i686-uwp-windows-gnu" => Some("i686-w64-mingw32"), - "i686-unknown-linux-musl" => Some("musl"), - "i686-unknown-netbsd" => Some("i486--netbsdelf"), - "mips-unknown-linux-gnu" => Some("mips-linux-gnu"), - "mipsel-unknown-linux-gnu" => Some("mipsel-linux-gnu"), - "mips64-unknown-linux-gnuabi64" => Some("mips64-linux-gnuabi64"), - "mips64el-unknown-linux-gnuabi64" => Some("mips64el-linux-gnuabi64"), - "mipsisa32r6-unknown-linux-gnu" => Some("mipsisa32r6-linux-gnu"), - "mipsisa32r6el-unknown-linux-gnu" => Some("mipsisa32r6el-linux-gnu"), - "mipsisa64r6-unknown-linux-gnuabi64" => Some("mipsisa64r6-linux-gnuabi64"), - "mipsisa64r6el-unknown-linux-gnuabi64" => { - Some("mipsisa64r6el-linux-gnuabi64") - } - "powerpc-unknown-linux-gnu" => Some("powerpc-linux-gnu"), - "powerpc-unknown-linux-gnuspe" => Some("powerpc-linux-gnuspe"), - "powerpc-unknown-netbsd" => Some("powerpc--netbsd"), - "powerpc64-unknown-linux-gnu" => Some("powerpc-linux-gnu"), - "powerpc64le-unknown-linux-gnu" => Some("powerpc64le-linux-gnu"), - "riscv32i-unknown-none-elf" => Some("riscv32-unknown-elf"), - "riscv32imac-unknown-none-elf" => Some("riscv32-unknown-elf"), - "riscv32imc-unknown-none-elf" => Some("riscv32-unknown-elf"), - "riscv64gc-unknown-none-elf" => Some("riscv64-unknown-elf"), - "riscv64imac-unknown-none-elf" => Some("riscv64-unknown-elf"), - "s390x-unknown-linux-gnu" => Some("s390x-linux-gnu"), - "sparc-unknown-linux-gnu" => Some("sparc-linux-gnu"), - "sparc64-unknown-linux-gnu" => Some("sparc64-linux-gnu"), - "sparc64-unknown-netbsd" => Some("sparc64--netbsd"), - "sparcv9-sun-solaris" => Some("sparcv9-sun-solaris"), - "armebv7r-none-eabi" => Some("arm-none-eabi"), - "armebv7r-none-eabihf" => Some("arm-none-eabi"), - "armv7r-none-eabi" => Some("arm-none-eabi"), - "armv7r-none-eabihf" => Some("arm-none-eabi"), - "thumbv6m-none-eabi" => Some("arm-none-eabi"), - "thumbv7em-none-eabi" => Some("arm-none-eabi"), - "thumbv7em-none-eabihf" => Some("arm-none-eabi"), - "thumbv7m-none-eabi" => Some("arm-none-eabi"), - "thumbv8m.base-none-eabi" => Some("arm-none-eabi"), - "thumbv8m.main-none-eabi" => Some("arm-none-eabi"), - "thumbv8m.main-none-eabihf" => Some("arm-none-eabi"), - "x86_64-pc-windows-gnu" => Some("x86_64-w64-mingw32"), - "x86_64-uwp-windows-gnu" => Some("x86_64-w64-mingw32"), - "x86_64-rumprun-netbsd" => Some("x86_64-rumprun-netbsd"), - "x86_64-unknown-linux-musl" => Some("musl"), - "x86_64-unknown-netbsd" => Some("x86_64--netbsd"), - _ => None, - }); - match prefix { - Some(prefix) => format!("{}-{}", prefix, gnu), - None => default.to_string(), - } - } else { - default.to_string() - }; - Tool::new(PathBuf::from(compiler)) - } - }; - - let mut tool = if self.cuda { - assert!( - tool.args.is_empty(), - "CUDA compilation currently assumes empty pre-existing args" - ); - let nvcc = match self.get_var("NVCC") { - Err(_) => "nvcc".into(), - Ok(nvcc) => nvcc, - }; - let mut nvcc_tool = Tool::with_features(PathBuf::from(nvcc), None, self.cuda); - nvcc_tool - .args - .push(format!("-ccbin={}", tool.path.display()).into()); - nvcc_tool.family = tool.family; - nvcc_tool - } else { - tool - }; - - // If we found `cl.exe` in our environment, the tool we're returning is - // an MSVC-like tool, *and* no env vars were set then set env vars for - // the tool that we're returning. - // - // Env vars are needed for things like `link.exe` being put into PATH as - // well as header include paths sometimes. These paths are automatically - // included by default but if the `CC` or `CXX` env vars are set these - // won't be used. This'll ensure that when the env vars are used to - // configure for invocations like `clang-cl` we still get a "works out - // of the box" experience. - if let Some(cl_exe) = cl_exe { - if tool.family == (ToolFamily::Msvc { clang_cl: true }) - && tool.env.len() == 0 - && target.contains("msvc") - { - for &(ref k, ref v) in cl_exe.env.iter() { - tool.env.push((k.to_owned(), v.to_owned())); - } - } - } - - Ok(tool) - } - - fn get_var(&self, var_base: &str) -> Result { - let target = self.get_target()?; - let host = self.get_host()?; - let kind = if host == target { "HOST" } else { "TARGET" }; - let target_u = target.replace("-", "_"); - let res = self - .getenv(&format!("{}_{}", var_base, target)) - .or_else(|| self.getenv(&format!("{}_{}", var_base, target_u))) - .or_else(|| self.getenv(&format!("{}_{}", kind, var_base))) - .or_else(|| self.getenv(var_base)); - - match res { - Some(res) => Ok(res), - None => Err(Error::new( - ErrorKind::EnvVarNotFound, - &format!("Could not find environment variable {}.", var_base), - )), - } - } - - fn envflags(&self, name: &str) -> Vec { - self.get_var(name) - .unwrap_or(String::new()) - .split(|c: char| c.is_whitespace()) - .filter(|s| !s.is_empty()) - .map(|s| s.to_string()) - .collect() - } - - /// Returns compiler path, optional modifier name from whitelist, and arguments vec - fn env_tool(&self, name: &str) -> Option<(String, Option, Vec)> { - let tool = match self.get_var(name) { - Ok(tool) => tool, - Err(_) => return None, - }; - - // If this is an exact path on the filesystem we don't want to do any - // interpretation at all, just pass it on through. This'll hopefully get - // us to support spaces-in-paths. - if Path::new(&tool).exists() { - return Some((tool, None, Vec::new())); - } - - // Ok now we want to handle a couple of scenarios. We'll assume from - // here on out that spaces are splitting separate arguments. Two major - // features we want to support are: - // - // CC='sccache cc' - // - // aka using `sccache` or any other wrapper/caching-like-thing for - // compilations. We want to know what the actual compiler is still, - // though, because our `Tool` API support introspection of it to see - // what compiler is in use. - // - // additionally we want to support - // - // CC='cc -flag' - // - // where the CC env var is used to also pass default flags to the C - // compiler. - // - // It's true that everything here is a bit of a pain, but apparently if - // you're not literally make or bash then you get a lot of bug reports. - let known_wrappers = ["ccache", "distcc", "sccache", "icecc"]; - - let mut parts = tool.split_whitespace(); - let maybe_wrapper = match parts.next() { - Some(s) => s, - None => return None, - }; - - let file_stem = Path::new(maybe_wrapper) - .file_stem() - .unwrap() - .to_str() - .unwrap(); - if known_wrappers.contains(&file_stem) { - if let Some(compiler) = parts.next() { - return Some(( - compiler.to_string(), - Some(maybe_wrapper.to_string()), - parts.map(|s| s.to_string()).collect(), - )); - } - } - - Some(( - maybe_wrapper.to_string(), - None, - parts.map(|s| s.to_string()).collect(), - )) - } - - /// Returns the default C++ standard library for the current target: `libc++` - /// for OS X and `libstdc++` for anything else. - fn get_cpp_link_stdlib(&self) -> Result, Error> { - match self.cpp_link_stdlib.clone() { - Some(s) => Ok(s), - None => { - if let Ok(stdlib) = self.get_var("CXXSTDLIB") { - if stdlib.is_empty() { - Ok(None) - } else { - Ok(Some(stdlib)) - } - } else { - let target = self.get_target()?; - if target.contains("msvc") { - Ok(None) - } else if target.contains("apple") { - Ok(Some("c++".to_string())) - } else if target.contains("freebsd") { - Ok(Some("c++".to_string())) - } else if target.contains("openbsd") { - Ok(Some("c++".to_string())) - } else { - Ok(Some("stdc++".to_string())) - } - } - } - } - } - - fn get_ar(&self) -> Result<(Command, String), Error> { - if let Some(ref p) = self.archiver { - let name = p.file_name().and_then(|s| s.to_str()).unwrap_or("ar"); - return Ok((self.cmd(p), name.to_string())); - } - if let Ok(p) = self.get_var("AR") { - return Ok((self.cmd(&p), p)); - } - let target = self.get_target()?; - let program = if target.contains("android") { - format!("{}-ar", target.replace("armv7", "arm")) - } else if target.contains("emscripten") { - // Windows use bat files so we have to be a bit more specific - if cfg!(windows) { - let mut cmd = self.cmd("cmd"); - cmd.arg("/c").arg("emar.bat"); - return Ok((cmd, "emar.bat".to_string())); - } - - "emar".to_string() - } else if target.contains("msvc") { - match windows_registry::find(&target, "lib.exe") { - Some(t) => return Ok((t, "lib.exe".to_string())), - None => "lib.exe".to_string(), - } - } else { - "ar".to_string() - }; - Ok((self.cmd(&program), program)) - } - - fn get_target(&self) -> Result { - match self.target.clone() { - Some(t) => Ok(t), - None => Ok(self.getenv_unwrap("TARGET")?), - } - } - - fn get_host(&self) -> Result { - match self.host.clone() { - Some(h) => Ok(h), - None => Ok(self.getenv_unwrap("HOST")?), - } - } - - fn get_opt_level(&self) -> Result { - match self.opt_level.as_ref().cloned() { - Some(ol) => Ok(ol), - None => Ok(self.getenv_unwrap("OPT_LEVEL")?), - } - } - - fn get_debug(&self) -> bool { - self.debug.unwrap_or_else(|| match self.getenv("DEBUG") { - Some(s) => s != "false", - None => false, - }) - } - - fn get_force_frame_pointer(&self) -> bool { - self.force_frame_pointer.unwrap_or_else(|| self.get_debug()) - } - - fn get_out_dir(&self) -> Result { - match self.out_dir.clone() { - Some(p) => Ok(p), - None => Ok(env::var_os("OUT_DIR").map(PathBuf::from).ok_or_else(|| { - Error::new( - ErrorKind::EnvVarNotFound, - "Environment variable OUT_DIR not defined.", - ) - })?), - } - } - - fn getenv(&self, v: &str) -> Option { - let mut cache = self.env_cache.lock().unwrap(); - if let Some(val) = cache.get(v) { - return val.clone(); - } - let r = env::var(v).ok(); - self.print(&format!("{} = {:?}", v, r)); - cache.insert(v.to_string(), r.clone()); - r - } - - fn getenv_unwrap(&self, v: &str) -> Result { - match self.getenv(v) { - Some(s) => Ok(s), - None => Err(Error::new( - ErrorKind::EnvVarNotFound, - &format!("Environment variable {} not defined.", v.to_string()), - )), - } - } - - fn print(&self, s: &str) { - if self.cargo_metadata { - println!("{}", s); - } - } -} - -impl Default for Build { - fn default() -> Build { - Build::new() - } -} - -impl Tool { - fn new(path: PathBuf) -> Self { - Tool::with_features(path, None, false) - } - - fn with_clang_driver(path: PathBuf, clang_driver: Option<&str>) -> Self { - Self::with_features(path, clang_driver, false) - } - - fn with_features(path: PathBuf, clang_driver: Option<&str>, cuda: bool) -> Self { - // Try to detect family of the tool from its name, falling back to Gnu. - let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) { - if fname.contains("clang-cl") { - ToolFamily::Msvc { clang_cl: true } - } else if fname.contains("cl") - && !fname.contains("cloudabi") - && !fname.contains("uclibc") - && !fname.contains("clang") - { - ToolFamily::Msvc { clang_cl: false } - } else if fname.contains("clang") { - match clang_driver { - Some("cl") => ToolFamily::Msvc { clang_cl: true }, - _ => ToolFamily::Clang, - } - } else { - ToolFamily::Gnu - } - } else { - ToolFamily::Gnu - }; - - Tool { - path: path, - cc_wrapper_path: None, - cc_wrapper_args: Vec::new(), - args: Vec::new(), - env: Vec::new(), - family: family, - cuda: cuda, - removed_args: Vec::new(), - } - } - - /// Add an argument to be stripped from the final command arguments. - fn remove_arg(&mut self, flag: OsString) { - self.removed_args.push(flag); - } - - /// Add a flag, and optionally prepend the NVCC wrapper flag "-Xcompiler". - /// - /// Currently this is only used for compiling CUDA sources, since NVCC only - /// accepts a limited set of GNU-like flags, and the rest must be prefixed - /// with a "-Xcompiler" flag to get passed to the underlying C++ compiler. - fn push_cc_arg(&mut self, flag: OsString) { - if self.cuda { - self.args.push("-Xcompiler".into()); - } - self.args.push(flag); - } - - fn is_duplicate_opt_arg(&self, flag: &OsString) -> bool { - let flag = flag.to_str().unwrap(); - let mut chars = flag.chars(); - - // Only duplicate check compiler flags - if self.is_like_msvc() { - if chars.next() != Some('/') { - return false; - } - } else if self.is_like_gnu() || self.is_like_clang() { - if chars.next() != Some('-') { - return false; - } - } - - // Check for existing optimization flags (-O, /O) - if chars.next() == Some('O') { - return self - .args() - .iter() - .any(|ref a| a.to_str().unwrap_or("").chars().nth(1) == Some('O')); - } - - // TODO Check for existing -m..., -m...=..., /arch:... flags - return false; - } - - /// Don't push optimization arg if it conflicts with existing args - fn push_opt_unless_duplicate(&mut self, flag: OsString) { - if self.is_duplicate_opt_arg(&flag) { - println!("Info: Ignoring duplicate arg {:?}", &flag); - } else { - self.push_cc_arg(flag); - } - } - - /// Converts this compiler into a `Command` that's ready to be run. - /// - /// This is useful for when the compiler needs to be executed and the - /// command returned will already have the initial arguments and environment - /// variables configured. - pub fn to_command(&self) -> Command { - let mut cmd = match self.cc_wrapper_path { - Some(ref cc_wrapper_path) => { - let mut cmd = Command::new(&cc_wrapper_path); - cmd.arg(&self.path); - cmd - } - None => Command::new(&self.path), - }; - cmd.args(&self.cc_wrapper_args); - - let value = self - .args - .iter() - .filter(|a| !self.removed_args.contains(a)) - .collect::>(); - cmd.args(&value); - - for &(ref k, ref v) in self.env.iter() { - cmd.env(k, v); - } - cmd - } - - /// Returns the path for this compiler. - /// - /// Note that this may not be a path to a file on the filesystem, e.g. "cc", - /// but rather something which will be resolved when a process is spawned. - pub fn path(&self) -> &Path { - &self.path - } - - /// Returns the default set of arguments to the compiler needed to produce - /// executables for the target this compiler generates. - pub fn args(&self) -> &[OsString] { - &self.args - } - - /// Returns the set of environment variables needed for this compiler to - /// operate. - /// - /// This is typically only used for MSVC compilers currently. - pub fn env(&self) -> &[(OsString, OsString)] { - &self.env - } - - /// Returns the compiler command in format of CC environment variable. - /// Or empty string if CC env was not present - /// - /// This is typically used by configure script - pub fn cc_env(&self) -> OsString { - match self.cc_wrapper_path { - Some(ref cc_wrapper_path) => { - let mut cc_env = cc_wrapper_path.as_os_str().to_owned(); - cc_env.push(" "); - cc_env.push(self.path.to_path_buf().into_os_string()); - for arg in self.cc_wrapper_args.iter() { - cc_env.push(" "); - cc_env.push(arg); - } - cc_env - } - None => OsString::from(""), - } - } - - /// Returns the compiler flags in format of CFLAGS environment variable. - /// Important here - this will not be CFLAGS from env, its internal gcc's flags to use as CFLAGS - /// This is typically used by configure script - pub fn cflags_env(&self) -> OsString { - let mut flags = OsString::new(); - for (i, arg) in self.args.iter().enumerate() { - if i > 0 { - flags.push(" "); - } - flags.push(arg); - } - flags - } - - /// Whether the tool is GNU Compiler Collection-like. - pub fn is_like_gnu(&self) -> bool { - self.family == ToolFamily::Gnu - } - - /// Whether the tool is Clang-like. - pub fn is_like_clang(&self) -> bool { - self.family == ToolFamily::Clang - } - - /// Whether the tool is MSVC-like. - pub fn is_like_msvc(&self) -> bool { - match self.family { - ToolFamily::Msvc { .. } => true, - _ => false, - } - } -} - -fn run(cmd: &mut Command, program: &str) -> Result<(), Error> { - let (mut child, print) = spawn(cmd, program)?; - let status = match child.wait() { - Ok(s) => s, - Err(_) => { - return Err(Error::new( - ErrorKind::ToolExecError, - &format!( - "Failed to wait on spawned child process, command {:?} with args {:?}.", - cmd, program - ), - )); - } - }; - print.join().unwrap(); - println!("{}", status); - - if status.success() { - Ok(()) - } else { - Err(Error::new( - ErrorKind::ToolExecError, - &format!( - "Command {:?} with args {:?} did not execute successfully (status code {}).", - cmd, program, status - ), - )) - } -} - -fn run_output(cmd: &mut Command, program: &str) -> Result, Error> { - cmd.stdout(Stdio::piped()); - let (mut child, print) = spawn(cmd, program)?; - let mut stdout = vec![]; - child - .stdout - .take() - .unwrap() - .read_to_end(&mut stdout) - .unwrap(); - let status = match child.wait() { - Ok(s) => s, - Err(_) => { - return Err(Error::new( - ErrorKind::ToolExecError, - &format!( - "Failed to wait on spawned child process, command {:?} with args {:?}.", - cmd, program - ), - )); - } - }; - print.join().unwrap(); - println!("{}", status); - - if status.success() { - Ok(stdout) - } else { - Err(Error::new( - ErrorKind::ToolExecError, - &format!( - "Command {:?} with args {:?} did not execute successfully (status code {}).", - cmd, program, status - ), - )) - } -} - -fn spawn(cmd: &mut Command, program: &str) -> Result<(Child, JoinHandle<()>), Error> { - println!("running: {:?}", cmd); - - // Capture the standard error coming from these programs, and write it out - // with cargo:warning= prefixes. Note that this is a bit wonky to avoid - // requiring the output to be UTF-8, we instead just ship bytes from one - // location to another. - match cmd.stderr(Stdio::piped()).spawn() { - Ok(mut child) => { - let stderr = BufReader::new(child.stderr.take().unwrap()); - let print = thread::spawn(move || { - for line in stderr.split(b'\n').filter_map(|l| l.ok()) { - print!("cargo:warning="); - std::io::stdout().write_all(&line).unwrap(); - println!(""); - } - }); - Ok((child, print)) - } - Err(ref e) if e.kind() == io::ErrorKind::NotFound => { - let extra = if cfg!(windows) { - " (see https://github.com/alexcrichton/cc-rs#compile-time-requirements \ - for help)" - } else { - "" - }; - Err(Error::new( - ErrorKind::ToolNotFound, - &format!("Failed to find tool. Is `{}` installed?{}", program, extra), - )) - } - Err(_) => Err(Error::new( - ErrorKind::ToolExecError, - &format!("Command {:?} with args {:?} failed to start.", cmd, program), - )), - } -} - -fn fail(s: &str) -> ! { - let _ = writeln!(io::stderr(), "\n\nerror occurred: {}\n\n", s); - std::process::exit(1); -} - -fn command_add_output_file( - cmd: &mut Command, - dst: &Path, - cuda: bool, - msvc: bool, - is_asm: bool, - is_arm: bool, -) { - if msvc && !cuda && !(is_asm && is_arm) { - let mut s = OsString::from("-Fo"); - s.push(&dst); - cmd.arg(s); - } else { - cmd.arg("-o").arg(&dst); - } -} diff --git a/cc/src/registry.rs b/cc/src/registry.rs deleted file mode 100644 index 2ac2fa6..0000000 --- a/cc/src/registry.rs +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::ffi::{OsStr, OsString}; -use std::io; -use std::ops::RangeFrom; -use std::os::raw; -use std::os::windows::prelude::*; - -pub struct RegistryKey(Repr); - -type HKEY = *mut u8; -type DWORD = u32; -type LPDWORD = *mut DWORD; -type LPCWSTR = *const u16; -type LPWSTR = *mut u16; -type LONG = raw::c_long; -type PHKEY = *mut HKEY; -type PFILETIME = *mut u8; -type LPBYTE = *mut u8; -type REGSAM = u32; - -const ERROR_SUCCESS: DWORD = 0; -const ERROR_NO_MORE_ITEMS: DWORD = 259; -const HKEY_LOCAL_MACHINE: HKEY = 0x80000002 as HKEY; -const REG_SZ: DWORD = 1; -const KEY_READ: DWORD = 0x20019; -const KEY_WOW64_32KEY: DWORD = 0x200; - -#[link(name = "advapi32")] -extern "system" { - fn RegOpenKeyExW( - key: HKEY, - lpSubKey: LPCWSTR, - ulOptions: DWORD, - samDesired: REGSAM, - phkResult: PHKEY, - ) -> LONG; - fn RegEnumKeyExW( - key: HKEY, - dwIndex: DWORD, - lpName: LPWSTR, - lpcName: LPDWORD, - lpReserved: LPDWORD, - lpClass: LPWSTR, - lpcClass: LPDWORD, - lpftLastWriteTime: PFILETIME, - ) -> LONG; - fn RegQueryValueExW( - hKey: HKEY, - lpValueName: LPCWSTR, - lpReserved: LPDWORD, - lpType: LPDWORD, - lpData: LPBYTE, - lpcbData: LPDWORD, - ) -> LONG; - fn RegCloseKey(hKey: HKEY) -> LONG; -} - -struct OwnedKey(HKEY); - -enum Repr { - Const(HKEY), - Owned(OwnedKey), -} - -pub struct Iter<'a> { - idx: RangeFrom, - key: &'a RegistryKey, -} - -unsafe impl Sync for Repr {} -unsafe impl Send for Repr {} - -pub static LOCAL_MACHINE: RegistryKey = RegistryKey(Repr::Const(HKEY_LOCAL_MACHINE)); - -impl RegistryKey { - fn raw(&self) -> HKEY { - match self.0 { - Repr::Const(val) => val, - Repr::Owned(ref val) => val.0, - } - } - - pub fn open(&self, key: &OsStr) -> io::Result { - let key = key.encode_wide().chain(Some(0)).collect::>(); - let mut ret = 0 as *mut _; - let err = unsafe { - RegOpenKeyExW( - self.raw(), - key.as_ptr(), - 0, - KEY_READ | KEY_WOW64_32KEY, - &mut ret, - ) - }; - if err == ERROR_SUCCESS as LONG { - Ok(RegistryKey(Repr::Owned(OwnedKey(ret)))) - } else { - Err(io::Error::from_raw_os_error(err as i32)) - } - } - - pub fn iter(&self) -> Iter { - Iter { - idx: 0.., - key: self, - } - } - - pub fn query_str(&self, name: &str) -> io::Result { - let name: &OsStr = name.as_ref(); - let name = name.encode_wide().chain(Some(0)).collect::>(); - let mut len = 0; - let mut kind = 0; - unsafe { - let err = RegQueryValueExW( - self.raw(), - name.as_ptr(), - 0 as *mut _, - &mut kind, - 0 as *mut _, - &mut len, - ); - if err != ERROR_SUCCESS as LONG { - return Err(io::Error::from_raw_os_error(err as i32)); - } - if kind != REG_SZ { - return Err(io::Error::new( - io::ErrorKind::Other, - "registry key wasn't a string", - )); - } - - // The length here is the length in bytes, but we're using wide - // characters so we need to be sure to halve it for the capacity - // passed in. - let mut v = Vec::with_capacity(len as usize / 2); - let err = RegQueryValueExW( - self.raw(), - name.as_ptr(), - 0 as *mut _, - 0 as *mut _, - v.as_mut_ptr() as *mut _, - &mut len, - ); - if err != ERROR_SUCCESS as LONG { - return Err(io::Error::from_raw_os_error(err as i32)); - } - v.set_len(len as usize / 2); - - // Some registry keys may have a terminating nul character, but - // we're not interested in that, so chop it off if it's there. - if v[v.len() - 1] == 0 { - v.pop(); - } - Ok(OsString::from_wide(&v)) - } - } -} - -impl Drop for OwnedKey { - fn drop(&mut self) { - unsafe { - RegCloseKey(self.0); - } - } -} - -impl<'a> Iterator for Iter<'a> { - type Item = io::Result; - - fn next(&mut self) -> Option> { - self.idx.next().and_then(|i| unsafe { - let mut v = Vec::with_capacity(256); - let mut len = v.capacity() as DWORD; - let ret = RegEnumKeyExW( - self.key.raw(), - i, - v.as_mut_ptr(), - &mut len, - 0 as *mut _, - 0 as *mut _, - 0 as *mut _, - 0 as *mut _, - ); - if ret == ERROR_NO_MORE_ITEMS as LONG { - None - } else if ret != ERROR_SUCCESS as LONG { - Some(Err(io::Error::from_raw_os_error(ret as i32))) - } else { - v.set_len(len as usize); - Some(Ok(OsString::from_wide(&v))) - } - }) - } -} diff --git a/cc/src/setup_config.rs b/cc/src/setup_config.rs deleted file mode 100644 index bc2b1c2..0000000 --- a/cc/src/setup_config.rs +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright © 2017 winapi-rs developers -// Licensed under the Apache License, Version 2.0 -// or the MIT license -// , at your option. -// All files in the project carrying such notice may not be copied, modified, or distributed -// except according to those terms. - -#![allow(bad_style)] -#![allow(unused)] - -use crate::winapi::Interface; -use crate::winapi::BSTR; -use crate::winapi::LPCOLESTR; -use crate::winapi::LPSAFEARRAY; -use crate::winapi::S_FALSE; -use crate::winapi::{CoCreateInstance, CLSCTX_ALL}; -use crate::winapi::{IUnknown, IUnknownVtbl}; -use crate::winapi::{HRESULT, LCID, LPCWSTR, PULONGLONG}; -use crate::winapi::{LPFILETIME, ULONG}; -use std::ffi::OsString; -use std::ptr::null_mut; - -use crate::com::{BStr, ComPtr}; - -// Bindings to the Setup.Configuration stuff -pub type InstanceState = u32; - -pub const eNone: InstanceState = 0; -pub const eLocal: InstanceState = 1; -pub const eRegistered: InstanceState = 2; -pub const eNoRebootRequired: InstanceState = 4; -pub const eComplete: InstanceState = -1i32 as u32; - -RIDL! {#[uuid(0xb41463c3, 0x8866, 0x43b5, 0xbc, 0x33, 0x2b, 0x06, 0x76, 0xf7, 0xf4, 0x2e)] -interface ISetupInstance(ISetupInstanceVtbl): IUnknown(IUnknownVtbl) { - fn GetInstanceId( - pbstrInstanceId: *mut BSTR, - ) -> HRESULT, - fn GetInstallDate( - pInstallDate: LPFILETIME, - ) -> HRESULT, - fn GetInstallationName( - pbstrInstallationName: *mut BSTR, - ) -> HRESULT, - fn GetInstallationPath( - pbstrInstallationPath: *mut BSTR, - ) -> HRESULT, - fn GetInstallationVersion( - pbstrInstallationVersion: *mut BSTR, - ) -> HRESULT, - fn GetDisplayName( - lcid: LCID, - pbstrDisplayName: *mut BSTR, - ) -> HRESULT, - fn GetDescription( - lcid: LCID, - pbstrDescription: *mut BSTR, - ) -> HRESULT, - fn ResolvePath( - pwszRelativePath: LPCOLESTR, - pbstrAbsolutePath: *mut BSTR, - ) -> HRESULT, -}} - -RIDL! {#[uuid(0x89143c9a, 0x05af, 0x49b0, 0xb7, 0x17, 0x72, 0xe2, 0x18, 0xa2, 0x18, 0x5c)] -interface ISetupInstance2(ISetupInstance2Vtbl): ISetupInstance(ISetupInstanceVtbl) { - fn GetState( - pState: *mut InstanceState, - ) -> HRESULT, - fn GetPackages( - ppsaPackages: *mut LPSAFEARRAY, - ) -> HRESULT, - fn GetProduct( - ppPackage: *mut *mut ISetupPackageReference, - ) -> HRESULT, - fn GetProductPath( - pbstrProductPath: *mut BSTR, - ) -> HRESULT, -}} - -RIDL! {#[uuid(0x6380bcff, 0x41d3, 0x4b2e, 0x8b, 0x2e, 0xbf, 0x8a, 0x68, 0x10, 0xc8, 0x48)] -interface IEnumSetupInstances(IEnumSetupInstancesVtbl): IUnknown(IUnknownVtbl) { - fn Next( - celt: ULONG, - rgelt: *mut *mut ISetupInstance, - pceltFetched: *mut ULONG, - ) -> HRESULT, - fn Skip( - celt: ULONG, - ) -> HRESULT, - fn Reset() -> HRESULT, - fn Clone( - ppenum: *mut *mut IEnumSetupInstances, - ) -> HRESULT, -}} - -RIDL! {#[uuid(0x42843719, 0xdb4c, 0x46c2, 0x8e, 0x7c, 0x64, 0xf1, 0x81, 0x6e, 0xfd, 0x5b)] -interface ISetupConfiguration(ISetupConfigurationVtbl): IUnknown(IUnknownVtbl) { - fn EnumInstances( - ppEnumInstances: *mut *mut IEnumSetupInstances, - ) -> HRESULT, - fn GetInstanceForCurrentProcess( - ppInstance: *mut *mut ISetupInstance, - ) -> HRESULT, - fn GetInstanceForPath( - wzPath: LPCWSTR, - ppInstance: *mut *mut ISetupInstance, - ) -> HRESULT, -}} - -RIDL! {#[uuid(0x26aab78c, 0x4a60, 0x49d6, 0xaf, 0x3b, 0x3c, 0x35, 0xbc, 0x93, 0x36, 0x5d)] -interface ISetupConfiguration2(ISetupConfiguration2Vtbl): - ISetupConfiguration(ISetupConfigurationVtbl) { - fn EnumAllInstances( - ppEnumInstances: *mut *mut IEnumSetupInstances, - ) -> HRESULT, -}} - -RIDL! {#[uuid(0xda8d8a16, 0xb2b6, 0x4487, 0xa2, 0xf1, 0x59, 0x4c, 0xcc, 0xcd, 0x6b, 0xf5)] -interface ISetupPackageReference(ISetupPackageReferenceVtbl): IUnknown(IUnknownVtbl) { - fn GetId( - pbstrId: *mut BSTR, - ) -> HRESULT, - fn GetVersion( - pbstrVersion: *mut BSTR, - ) -> HRESULT, - fn GetChip( - pbstrChip: *mut BSTR, - ) -> HRESULT, - fn GetLanguage( - pbstrLanguage: *mut BSTR, - ) -> HRESULT, - fn GetBranch( - pbstrBranch: *mut BSTR, - ) -> HRESULT, - fn GetType( - pbstrType: *mut BSTR, - ) -> HRESULT, - fn GetUniqueId( - pbstrUniqueId: *mut BSTR, - ) -> HRESULT, -}} - -RIDL! {#[uuid(0x42b21b78, 0x6192, 0x463e, 0x87, 0xbf, 0xd5, 0x77, 0x83, 0x8f, 0x1d, 0x5c)] -interface ISetupHelper(ISetupHelperVtbl): IUnknown(IUnknownVtbl) { - fn ParseVersion( - pwszVersion: LPCOLESTR, - pullVersion: PULONGLONG, - ) -> HRESULT, - fn ParseVersionRange( - pwszVersionRange: LPCOLESTR, - pullMinVersion: PULONGLONG, - pullMaxVersion: PULONGLONG, - ) -> HRESULT, -}} - -DEFINE_GUID! {CLSID_SetupConfiguration, -0x177f0c4a, 0x1cd3, 0x4de7, 0xa3, 0x2c, 0x71, 0xdb, 0xbb, 0x9f, 0xa3, 0x6d} - -// Safe wrapper around the COM interfaces -pub struct SetupConfiguration(ComPtr); - -impl SetupConfiguration { - pub fn new() -> Result { - let mut obj = null_mut(); - let err = unsafe { - CoCreateInstance( - &CLSID_SetupConfiguration, - null_mut(), - CLSCTX_ALL, - &ISetupConfiguration::uuidof(), - &mut obj, - ) - }; - if err < 0 { - return Err(err); - } - let obj = unsafe { ComPtr::from_raw(obj as *mut ISetupConfiguration) }; - Ok(SetupConfiguration(obj)) - } - pub fn get_instance_for_current_process(&self) -> Result { - let mut obj = null_mut(); - let err = unsafe { self.0.GetInstanceForCurrentProcess(&mut obj) }; - if err < 0 { - return Err(err); - } - Ok(unsafe { SetupInstance::from_raw(obj) }) - } - pub fn enum_instances(&self) -> Result { - let mut obj = null_mut(); - let err = unsafe { self.0.EnumInstances(&mut obj) }; - if err < 0 { - return Err(err); - } - Ok(unsafe { EnumSetupInstances::from_raw(obj) }) - } - pub fn enum_all_instances(&self) -> Result { - let mut obj = null_mut(); - let this = self.0.cast::()?; - let err = unsafe { this.EnumAllInstances(&mut obj) }; - if err < 0 { - return Err(err); - } - Ok(unsafe { EnumSetupInstances::from_raw(obj) }) - } -} - -pub struct SetupInstance(ComPtr); - -impl SetupInstance { - pub unsafe fn from_raw(obj: *mut ISetupInstance) -> SetupInstance { - SetupInstance(ComPtr::from_raw(obj)) - } - pub fn instance_id(&self) -> Result { - let mut s = null_mut(); - let err = unsafe { self.0.GetInstanceId(&mut s) }; - let bstr = unsafe { BStr::from_raw(s) }; - if err < 0 { - return Err(err); - } - Ok(bstr.to_osstring()) - } - pub fn installation_name(&self) -> Result { - let mut s = null_mut(); - let err = unsafe { self.0.GetInstallationName(&mut s) }; - let bstr = unsafe { BStr::from_raw(s) }; - if err < 0 { - return Err(err); - } - Ok(bstr.to_osstring()) - } - pub fn installation_path(&self) -> Result { - let mut s = null_mut(); - let err = unsafe { self.0.GetInstallationPath(&mut s) }; - let bstr = unsafe { BStr::from_raw(s) }; - if err < 0 { - return Err(err); - } - Ok(bstr.to_osstring()) - } - pub fn installation_version(&self) -> Result { - let mut s = null_mut(); - let err = unsafe { self.0.GetInstallationVersion(&mut s) }; - let bstr = unsafe { BStr::from_raw(s) }; - if err < 0 { - return Err(err); - } - Ok(bstr.to_osstring()) - } - pub fn product_path(&self) -> Result { - let mut s = null_mut(); - let this = self.0.cast::()?; - let err = unsafe { this.GetProductPath(&mut s) }; - let bstr = unsafe { BStr::from_raw(s) }; - if err < 0 { - return Err(err); - } - Ok(bstr.to_osstring()) - } -} - -pub struct EnumSetupInstances(ComPtr); - -impl EnumSetupInstances { - pub unsafe fn from_raw(obj: *mut IEnumSetupInstances) -> EnumSetupInstances { - EnumSetupInstances(ComPtr::from_raw(obj)) - } -} - -impl Iterator for EnumSetupInstances { - type Item = Result; - fn next(&mut self) -> Option> { - let mut obj = null_mut(); - let err = unsafe { self.0.Next(1, &mut obj, null_mut()) }; - if err < 0 { - return Some(Err(err)); - } - if err == S_FALSE { - return None; - } - Some(Ok(unsafe { SetupInstance::from_raw(obj) })) - } -} diff --git a/cc/src/winapi.rs b/cc/src/winapi.rs deleted file mode 100644 index c416325..0000000 --- a/cc/src/winapi.rs +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright © 2015-2017 winapi-rs developers -// Licensed under the Apache License, Version 2.0 -// or the MIT license -// , at your option. -// All files in the project carrying such notice may not be copied, modified, or distributed -// except according to those terms. - -#![allow(bad_style)] - -use std::os::raw; - -pub type wchar_t = u16; - -pub type UINT = raw::c_uint; -pub type LPUNKNOWN = *mut IUnknown; -pub type REFIID = *const IID; -pub type IID = GUID; -pub type REFCLSID = *const IID; -pub type PVOID = *mut raw::c_void; -pub type USHORT = raw::c_ushort; -pub type ULONG = raw::c_ulong; -pub type LONG = raw::c_long; -pub type DWORD = u32; -pub type LPVOID = *mut raw::c_void; -pub type HRESULT = raw::c_long; -pub type LPFILETIME = *mut FILETIME; -pub type BSTR = *mut OLECHAR; -pub type OLECHAR = WCHAR; -pub type WCHAR = wchar_t; -pub type LPCOLESTR = *const OLECHAR; -pub type LCID = DWORD; -pub type LPCWSTR = *const WCHAR; -pub type PULONGLONG = *mut ULONGLONG; -pub type ULONGLONG = u64; - -pub const S_OK: HRESULT = 0; -pub const S_FALSE: HRESULT = 1; -pub const COINIT_MULTITHREADED: u32 = 0x0; - -pub type CLSCTX = u32; - -pub const CLSCTX_INPROC_SERVER: CLSCTX = 0x1; -pub const CLSCTX_INPROC_HANDLER: CLSCTX = 0x2; -pub const CLSCTX_LOCAL_SERVER: CLSCTX = 0x4; -pub const CLSCTX_REMOTE_SERVER: CLSCTX = 0x10; - -pub const CLSCTX_ALL: CLSCTX = - CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct GUID { - pub Data1: raw::c_ulong, - pub Data2: raw::c_ushort, - pub Data3: raw::c_ushort, - pub Data4: [raw::c_uchar; 8], -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct FILETIME { - pub dwLowDateTime: DWORD, - pub dwHighDateTime: DWORD, -} - -pub trait Interface { - fn uuidof() -> GUID; -} - -#[link(name = "ole32")] -#[link(name = "oleaut32")] -extern "C" {} - -extern "system" { - pub fn CoInitializeEx(pvReserved: LPVOID, dwCoInit: DWORD) -> HRESULT; - pub fn CoCreateInstance( - rclsid: REFCLSID, - pUnkOuter: LPUNKNOWN, - dwClsContext: DWORD, - riid: REFIID, - ppv: *mut LPVOID, - ) -> HRESULT; - pub fn SysFreeString(bstrString: BSTR); - pub fn SysStringLen(pbstr: BSTR) -> UINT; -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct SAFEARRAYBOUND { - pub cElements: ULONG, - pub lLbound: LONG, -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct SAFEARRAY { - pub cDims: USHORT, - pub fFeatures: USHORT, - pub cbElements: ULONG, - pub cLocks: ULONG, - pub pvData: PVOID, - pub rgsabound: [SAFEARRAYBOUND; 1], -} - -pub type LPSAFEARRAY = *mut SAFEARRAY; - -macro_rules! DEFINE_GUID { - ( - $name:ident, $l:expr, $w1:expr, $w2:expr, - $b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr - ) => { - pub const $name: $crate::winapi::GUID = $crate::winapi::GUID { - Data1: $l, - Data2: $w1, - Data3: $w2, - Data4: [$b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8], - }; - }; -} - -macro_rules! RIDL { - (#[uuid($($uuid:expr),+)] - interface $interface:ident ($vtbl:ident) {$( - fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty, - )+}) => ( - #[repr(C)] - pub struct $vtbl { - $(pub $method: unsafe extern "system" fn( - This: *mut $interface, - $($p: $t),* - ) -> $rtr,)+ - } - #[repr(C)] - pub struct $interface { - pub lpVtbl: *const $vtbl, - } - RIDL!{@impl $interface {$(fn $method($($p: $t,)*) -> $rtr,)+}} - RIDL!{@uuid $interface $($uuid),+} - ); - (#[uuid($($uuid:expr),+)] - interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) { - }) => ( - #[repr(C)] - pub struct $vtbl { - pub parent: $pvtbl, - } - #[repr(C)] - pub struct $interface { - pub lpVtbl: *const $vtbl, - } - RIDL!{@deref $interface $pinterface} - RIDL!{@uuid $interface $($uuid),+} - ); - (#[uuid($($uuid:expr),+)] - interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) {$( - fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty, - )+}) => ( - #[repr(C)] - pub struct $vtbl { - pub parent: $pvtbl, - $(pub $method: unsafe extern "system" fn( - This: *mut $interface, - $($p: $t,)* - ) -> $rtr,)+ - } - #[repr(C)] - pub struct $interface { - pub lpVtbl: *const $vtbl, - } - RIDL!{@impl $interface {$(fn $method($($p: $t,)*) -> $rtr,)+}} - RIDL!{@deref $interface $pinterface} - RIDL!{@uuid $interface $($uuid),+} - ); - (@deref $interface:ident $pinterface:ident) => ( - impl ::std::ops::Deref for $interface { - type Target = $pinterface; - #[inline] - fn deref(&self) -> &$pinterface { - unsafe { &*(self as *const $interface as *const $pinterface) } - } - } - ); - (@impl $interface:ident {$( - fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty, - )+}) => ( - impl $interface { - $(#[inline] pub unsafe fn $method(&self, $($p: $t,)*) -> $rtr { - ((*self.lpVtbl).$method)(self as *const _ as *mut _, $($p,)*) - })+ - } - ); - (@uuid $interface:ident - $l:expr, $w1:expr, $w2:expr, - $b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr - ) => ( - impl $crate::winapi::Interface for $interface { - #[inline] - fn uuidof() -> $crate::winapi::GUID { - $crate::winapi::GUID { - Data1: $l, - Data2: $w1, - Data3: $w2, - Data4: [$b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8], - } - } - } - ); -} - -RIDL! {#[uuid(0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)] -interface IUnknown(IUnknownVtbl) { - fn QueryInterface( - riid: REFIID, - ppvObject: *mut *mut raw::c_void, - ) -> HRESULT, - fn AddRef() -> ULONG, - fn Release() -> ULONG, -}} diff --git a/cc/src/windows_registry.rs b/cc/src/windows_registry.rs deleted file mode 100644 index 5af3ff7..0000000 --- a/cc/src/windows_registry.rs +++ /dev/null @@ -1,754 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A helper module to probe the Windows Registry when looking for -//! windows-specific tools. - -use std::process::Command; - -use crate::Tool; - -/// Attempts to find a tool within an MSVC installation using the Windows -/// registry as a point to search from. -/// -/// The `target` argument is the target that the tool should work for (e.g. -/// compile or link for) and the `tool` argument is the tool to find (e.g. -/// `cl.exe` or `link.exe`). -/// -/// This function will return `None` if the tool could not be found, or it will -/// return `Some(cmd)` which represents a command that's ready to execute the -/// tool with the appropriate environment variables set. -/// -/// Note that this function always returns `None` for non-MSVC targets. -pub fn find(target: &str, tool: &str) -> Option { - find_tool(target, tool).map(|c| c.to_command()) -} - -/// Similar to the `find` function above, this function will attempt the same -/// operation (finding a MSVC tool in a local install) but instead returns a -/// `Tool` which may be introspected. -#[cfg(not(windows))] -pub fn find_tool(_target: &str, _tool: &str) -> Option { - None -} - -/// Documented above. -#[cfg(windows)] -pub fn find_tool(target: &str, tool: &str) -> Option { - use std::env; - - // This logic is all tailored for MSVC, if we're not that then bail out - // early. - if !target.contains("msvc") { - return None; - } - - // Looks like msbuild isn't located in the same location as other tools like - // cl.exe and lib.exe. To handle this we probe for it manually with - // dedicated registry keys. - if tool.contains("msbuild") { - return impl_::find_msbuild(target); - } - - if tool.contains("devenv") { - return impl_::find_devenv(target); - } - - // If VCINSTALLDIR is set, then someone's probably already run vcvars and we - // should just find whatever that indicates. - if env::var_os("VCINSTALLDIR").is_some() { - return env::var_os("PATH") - .and_then(|path| { - env::split_paths(&path) - .map(|p| p.join(tool)) - .find(|p| p.exists()) - }) - .map(|path| Tool::new(path.into())); - } - - // Ok, if we're here, now comes the fun part of the probing. Default shells - // or shells like MSYS aren't really configured to execute `cl.exe` and the - // various compiler tools shipped as part of Visual Studio. Here we try to - // first find the relevant tool, then we also have to be sure to fill in - // environment variables like `LIB`, `INCLUDE`, and `PATH` to ensure that - // the tool is actually usable. - - return impl_::find_msvc_15(tool, target) - .or_else(|| impl_::find_msvc_14(tool, target)) - .or_else(|| impl_::find_msvc_12(tool, target)) - .or_else(|| impl_::find_msvc_11(tool, target)); -} - -/// A version of Visual Studio -#[derive(Debug, PartialEq, Eq, Copy, Clone)] -pub enum VsVers { - /// Visual Studio 12 (2013) - Vs12, - /// Visual Studio 14 (2015) - Vs14, - /// Visual Studio 15 (2017) - Vs15, - /// Visual Studio 16 (2019) - Vs16, - - /// Hidden variant that should not be matched on. Callers that want to - /// handle an enumeration of `VsVers` instances should always have a default - /// case meaning that it's a VS version they don't understand. - #[doc(hidden)] - #[allow(bad_style)] - __Nonexhaustive_do_not_match_this_or_your_code_will_break, -} - -/// Find the most recent installed version of Visual Studio -/// -/// This is used by the cmake crate to figure out the correct -/// generator. -#[cfg(not(windows))] -pub fn find_vs_version() -> Result { - Err(format!("not windows")) -} - -/// Documented above -#[cfg(windows)] -pub fn find_vs_version() -> Result { - use std::env; - - match env::var("VisualStudioVersion") { - Ok(version) => match &version[..] { - "16.0" => Ok(VsVers::Vs16), - "15.0" => Ok(VsVers::Vs15), - "14.0" => Ok(VsVers::Vs14), - "12.0" => Ok(VsVers::Vs12), - vers => Err(format!( - "\n\n\ - unsupported or unknown VisualStudio version: {}\n\ - if another version is installed consider running \ - the appropriate vcvars script before building this \ - crate\n\ - ", - vers - )), - }, - _ => { - // Check for the presense of a specific registry key - // that indicates visual studio is installed. - if impl_::has_msbuild_version("16.0") { - Ok(VsVers::Vs16) - } else if impl_::has_msbuild_version("15.0") { - Ok(VsVers::Vs15) - } else if impl_::has_msbuild_version("14.0") { - Ok(VsVers::Vs14) - } else if impl_::has_msbuild_version("12.0") { - Ok(VsVers::Vs12) - } else { - Err(format!( - "\n\n\ - couldn't determine visual studio generator\n\ - if VisualStudio is installed, however, consider \ - running the appropriate vcvars script before building \ - this crate\n\ - " - )) - } - } - } -} - -#[cfg(windows)] -mod impl_ { - use crate::com; - use crate::registry::{RegistryKey, LOCAL_MACHINE}; - use crate::setup_config::{EnumSetupInstances, SetupConfiguration, SetupInstance}; - use std::env; - use std::ffi::OsString; - use std::fs::File; - use std::io::Read; - use std::iter; - use std::mem; - use std::path::{Path, PathBuf}; - - use crate::Tool; - - struct MsvcTool { - tool: PathBuf, - libs: Vec, - path: Vec, - include: Vec, - } - - impl MsvcTool { - fn new(tool: PathBuf) -> MsvcTool { - MsvcTool { - tool: tool, - libs: Vec::new(), - path: Vec::new(), - include: Vec::new(), - } - } - - fn into_tool(self) -> Tool { - let MsvcTool { - tool, - libs, - path, - include, - } = self; - let mut tool = Tool::new(tool.into()); - add_env(&mut tool, "LIB", libs); - add_env(&mut tool, "PATH", path); - add_env(&mut tool, "INCLUDE", include); - tool - } - } - - #[allow(bare_trait_objects)] - fn vs16_instances() -> Box> { - let instances = if let Some(instances) = vs15_instances() { - instances - } else { - return Box::new(iter::empty()); - }; - Box::new(instances.filter_map(|instance| { - let instance = instance.ok()?; - let installation_name = instance.installation_name().ok()?; - if installation_name.to_str()?.starts_with("VisualStudio/16.") { - Some(PathBuf::from(instance.installation_path().ok()?)) - } else { - None - } - })) - } - - fn find_tool_in_vs16_path(tool: &str, target: &str) -> Option { - vs16_instances() - .filter_map(|path| { - let path = path.join(tool); - if !path.is_file() { - return None; - } - let mut tool = Tool::new(path); - if target.contains("x86_64") { - tool.env.push(("Platform".into(), "X64".into())); - } - Some(tool) - }) - .next() - } - - fn find_msbuild_vs16(target: &str) -> Option { - find_tool_in_vs16_path(r"MSBuild\Current\Bin\MSBuild.exe", target) - } - - // In MSVC 15 (2017) MS once again changed the scheme for locating - // the tooling. Now we must go through some COM interfaces, which - // is super fun for Rust. - // - // Note that much of this logic can be found [online] wrt paths, COM, etc. - // - // [online]: https://blogs.msdn.microsoft.com/vcblog/2017/03/06/finding-the-visual-c-compiler-tools-in-visual-studio-2017/ - fn vs15_instances() -> Option { - com::initialize().ok()?; - - let config = SetupConfiguration::new().ok()?; - config.enum_all_instances().ok() - } - - pub fn find_msvc_15(tool: &str, target: &str) -> Option { - let iter = vs15_instances()?; - for instance in iter { - let instance = instance.ok()?; - let tool = tool_from_vs15_instance(tool, target, &instance); - if tool.is_some() { - return tool; - } - } - - None - } - - // While the paths to Visual Studio 2017's devenv and MSBuild could - // potentially be retrieved from the registry, finding them via - // SetupConfiguration has shown to be [more reliable], and is preferred - // according to Microsoft. To help head off potential regressions though, - // we keep the registry method as a fallback option. - // - // [more reliable]: https://github.com/alexcrichton/cc-rs/pull/331 - fn find_tool_in_vs15_path(tool: &str, target: &str) -> Option { - let mut path = match vs15_instances() { - Some(instances) => instances - .filter_map(|instance| { - instance - .ok() - .and_then(|instance| instance.installation_path().ok()) - }) - .map(|path| PathBuf::from(path).join(tool)) - .find(|ref path| path.is_file()), - None => None, - }; - - if path.is_none() { - let key = r"SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VS7"; - path = LOCAL_MACHINE - .open(key.as_ref()) - .ok() - .and_then(|key| key.query_str("15.0").ok()) - .map(|path| PathBuf::from(path).join(tool)) - .and_then(|path| if path.is_file() { Some(path) } else { None }); - } - - path.map(|path| { - let mut tool = Tool::new(path); - if target.contains("x86_64") { - tool.env.push(("Platform".into(), "X64".into())); - } - tool - }) - } - - fn tool_from_vs15_instance(tool: &str, target: &str, instance: &SetupInstance) -> Option { - let (bin_path, host_dylib_path, lib_path, include_path) = vs15_vc_paths(target, instance)?; - let tool_path = bin_path.join(tool); - if !tool_path.exists() { - return None; - }; - - let mut tool = MsvcTool::new(tool_path); - tool.path.push(host_dylib_path); - tool.libs.push(lib_path); - tool.include.push(include_path); - - if let Some((atl_lib_path, atl_include_path)) = atl_paths(target, &bin_path) { - tool.libs.push(atl_lib_path); - tool.include.push(atl_include_path); - } - - add_sdks(&mut tool, target)?; - - Some(tool.into_tool()) - } - - fn vs15_vc_paths( - target: &str, - instance: &SetupInstance, - ) -> Option<(PathBuf, PathBuf, PathBuf, PathBuf)> { - let instance_path: PathBuf = instance.installation_path().ok()?.into(); - let version_path = - instance_path.join(r"VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"); - let mut version_file = File::open(version_path).ok()?; - let mut version = String::new(); - version_file.read_to_string(&mut version).ok()?; - let version = version.trim(); - let host = match host_arch() { - X86 => "X86", - X86_64 => "X64", - _ => return None, - }; - let target = lib_subdir(target)?; - // The directory layout here is MSVC/bin/Host$host/$target/ - let path = instance_path.join(r"VC\Tools\MSVC").join(version); - // This is the path to the toolchain for a particular target, running - // on a given host - let bin_path = path - .join("bin") - .join(&format!("Host{}", host)) - .join(&target); - // But! we also need PATH to contain the target directory for the host - // architecture, because it contains dlls like mspdb140.dll compiled for - // the host architecture. - let host_dylib_path = path - .join("bin") - .join(&format!("Host{}", host)) - .join(&host.to_lowercase()); - let lib_path = path.join("lib").join(&target); - let include_path = path.join("include"); - Some((bin_path, host_dylib_path, lib_path, include_path)) - } - - fn atl_paths(target: &str, path: &Path) -> Option<(PathBuf, PathBuf)> { - let atl_path = path.join("atlfmc"); - let sub = lib_subdir(target)?; - if atl_path.exists() { - Some((atl_path.join("lib").join(sub), atl_path.join("include"))) - } else { - None - } - } - - // For MSVC 14 we need to find the Universal CRT as well as either - // the Windows 10 SDK or Windows 8.1 SDK. - pub fn find_msvc_14(tool: &str, target: &str) -> Option { - let vcdir = get_vc_dir("14.0")?; - let mut tool = get_tool(tool, &vcdir, target)?; - add_sdks(&mut tool, target)?; - Some(tool.into_tool()) - } - - fn add_sdks(tool: &mut MsvcTool, target: &str) -> Option<()> { - let sub = lib_subdir(target)?; - let (ucrt, ucrt_version) = get_ucrt_dir()?; - - tool.path - .push(ucrt.join("bin").join(&ucrt_version).join(sub)); - - let ucrt_include = ucrt.join("include").join(&ucrt_version); - tool.include.push(ucrt_include.join("ucrt")); - - let ucrt_lib = ucrt.join("lib").join(&ucrt_version); - tool.libs.push(ucrt_lib.join("ucrt").join(sub)); - - if let Some((sdk, version)) = get_sdk10_dir() { - tool.path.push(sdk.join("bin").join(sub)); - let sdk_lib = sdk.join("lib").join(&version); - tool.libs.push(sdk_lib.join("um").join(sub)); - let sdk_include = sdk.join("include").join(&version); - tool.include.push(sdk_include.join("um")); - tool.include.push(sdk_include.join("cppwinrt")); - tool.include.push(sdk_include.join("winrt")); - tool.include.push(sdk_include.join("shared")); - } else if let Some(sdk) = get_sdk81_dir() { - tool.path.push(sdk.join("bin").join(sub)); - let sdk_lib = sdk.join("lib").join("winv6.3"); - tool.libs.push(sdk_lib.join("um").join(sub)); - let sdk_include = sdk.join("include"); - tool.include.push(sdk_include.join("um")); - tool.include.push(sdk_include.join("winrt")); - tool.include.push(sdk_include.join("shared")); - } - - Some(()) - } - - // For MSVC 12 we need to find the Windows 8.1 SDK. - pub fn find_msvc_12(tool: &str, target: &str) -> Option { - let vcdir = get_vc_dir("12.0")?; - let mut tool = get_tool(tool, &vcdir, target)?; - let sub = lib_subdir(target)?; - let sdk81 = get_sdk81_dir()?; - tool.path.push(sdk81.join("bin").join(sub)); - let sdk_lib = sdk81.join("lib").join("winv6.3"); - tool.libs.push(sdk_lib.join("um").join(sub)); - let sdk_include = sdk81.join("include"); - tool.include.push(sdk_include.join("shared")); - tool.include.push(sdk_include.join("um")); - tool.include.push(sdk_include.join("winrt")); - Some(tool.into_tool()) - } - - // For MSVC 11 we need to find the Windows 8 SDK. - pub fn find_msvc_11(tool: &str, target: &str) -> Option { - let vcdir = get_vc_dir("11.0")?; - let mut tool = get_tool(tool, &vcdir, target)?; - let sub = lib_subdir(target)?; - let sdk8 = get_sdk8_dir()?; - tool.path.push(sdk8.join("bin").join(sub)); - let sdk_lib = sdk8.join("lib").join("win8"); - tool.libs.push(sdk_lib.join("um").join(sub)); - let sdk_include = sdk8.join("include"); - tool.include.push(sdk_include.join("shared")); - tool.include.push(sdk_include.join("um")); - tool.include.push(sdk_include.join("winrt")); - Some(tool.into_tool()) - } - - fn add_env(tool: &mut Tool, env: &str, paths: Vec) { - let prev = env::var_os(env).unwrap_or(OsString::new()); - let prev = env::split_paths(&prev); - let new = paths.into_iter().chain(prev); - tool.env - .push((env.to_string().into(), env::join_paths(new).unwrap())); - } - - // Given a possible MSVC installation directory, we look for the linker and - // then add the MSVC library path. - fn get_tool(tool: &str, path: &Path, target: &str) -> Option { - bin_subdir(target) - .into_iter() - .map(|(sub, host)| { - ( - path.join("bin").join(sub).join(tool), - path.join("bin").join(host), - ) - }) - .filter(|&(ref path, _)| path.is_file()) - .map(|(path, host)| { - let mut tool = MsvcTool::new(path); - tool.path.push(host); - tool - }) - .filter_map(|mut tool| { - let sub = vc_lib_subdir(target)?; - tool.libs.push(path.join("lib").join(sub)); - tool.include.push(path.join("include")); - let atlmfc_path = path.join("atlmfc"); - if atlmfc_path.exists() { - tool.libs.push(atlmfc_path.join("lib").join(sub)); - tool.include.push(atlmfc_path.join("include")); - } - Some(tool) - }) - .next() - } - - // To find MSVC we look in a specific registry key for the version we are - // trying to find. - fn get_vc_dir(ver: &str) -> Option { - let key = r"SOFTWARE\Microsoft\VisualStudio\SxS\VC7"; - let key = LOCAL_MACHINE.open(key.as_ref()).ok()?; - let path = key.query_str(ver).ok()?; - Some(path.into()) - } - - // To find the Universal CRT we look in a specific registry key for where - // all the Universal CRTs are located and then sort them asciibetically to - // find the newest version. While this sort of sorting isn't ideal, it is - // what vcvars does so that's good enough for us. - // - // Returns a pair of (root, version) for the ucrt dir if found - fn get_ucrt_dir() -> Option<(PathBuf, String)> { - let key = r"SOFTWARE\Microsoft\Windows Kits\Installed Roots"; - let key = LOCAL_MACHINE.open(key.as_ref()).ok()?; - let root = key.query_str("KitsRoot10").ok()?; - let readdir = Path::new(&root).join("lib").read_dir().ok()?; - let max_libdir = readdir - .filter_map(|dir| dir.ok()) - .map(|dir| dir.path()) - .filter(|dir| { - dir.components() - .last() - .and_then(|c| c.as_os_str().to_str()) - .map(|c| c.starts_with("10.") && dir.join("ucrt").is_dir()) - .unwrap_or(false) - }) - .max()?; - let version = max_libdir.components().last().unwrap(); - let version = version.as_os_str().to_str().unwrap().to_string(); - Some((root.into(), version)) - } - - // Vcvars finds the correct version of the Windows 10 SDK by looking - // for the include `um\Windows.h` because sometimes a given version will - // only have UCRT bits without the rest of the SDK. Since we only care about - // libraries and not includes, we instead look for `um\x64\kernel32.lib`. - // Since the 32-bit and 64-bit libraries are always installed together we - // only need to bother checking x64, making this code a tiny bit simpler. - // Like we do for the Universal CRT, we sort the possibilities - // asciibetically to find the newest one as that is what vcvars does. - fn get_sdk10_dir() -> Option<(PathBuf, String)> { - let key = r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0"; - let key = LOCAL_MACHINE.open(key.as_ref()).ok()?; - let root = key.query_str("InstallationFolder").ok()?; - let readdir = Path::new(&root).join("lib").read_dir().ok()?; - let mut dirs = readdir - .filter_map(|dir| dir.ok()) - .map(|dir| dir.path()) - .collect::>(); - dirs.sort(); - let dir = dirs - .into_iter() - .rev() - .filter(|dir| dir.join("um").join("x64").join("kernel32.lib").is_file()) - .next()?; - let version = dir.components().last().unwrap(); - let version = version.as_os_str().to_str().unwrap().to_string(); - Some((root.into(), version)) - } - - // Interestingly there are several subdirectories, `win7` `win8` and - // `winv6.3`. Vcvars seems to only care about `winv6.3` though, so the same - // applies to us. Note that if we were targetting kernel mode drivers - // instead of user mode applications, we would care. - fn get_sdk81_dir() -> Option { - let key = r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1"; - let key = LOCAL_MACHINE.open(key.as_ref()).ok()?; - let root = key.query_str("InstallationFolder").ok()?; - Some(root.into()) - } - - fn get_sdk8_dir() -> Option { - let key = r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0"; - let key = LOCAL_MACHINE.open(key.as_ref()).ok()?; - let root = key.query_str("InstallationFolder").ok()?; - Some(root.into()) - } - - const PROCESSOR_ARCHITECTURE_INTEL: u16 = 0; - const PROCESSOR_ARCHITECTURE_AMD64: u16 = 9; - const X86: u16 = PROCESSOR_ARCHITECTURE_INTEL; - const X86_64: u16 = PROCESSOR_ARCHITECTURE_AMD64; - - // When choosing the tool to use, we have to choose the one which matches - // the target architecture. Otherwise we end up in situations where someone - // on 32-bit Windows is trying to cross compile to 64-bit and it tries to - // invoke the native 64-bit compiler which won't work. - // - // For the return value of this function, the first member of the tuple is - // the folder of the tool we will be invoking, while the second member is - // the folder of the host toolchain for that tool which is essential when - // using a cross linker. We return a Vec since on x64 there are often two - // linkers that can target the architecture we desire. The 64-bit host - // linker is preferred, and hence first, due to 64-bit allowing it more - // address space to work with and potentially being faster. - fn bin_subdir(target: &str) -> Vec<(&'static str, &'static str)> { - let arch = target.split('-').next().unwrap(); - match (arch, host_arch()) { - ("i586", X86) | ("i686", X86) => vec![("", "")], - ("i586", X86_64) | ("i686", X86_64) => vec![("amd64_x86", "amd64"), ("", "")], - ("x86_64", X86) => vec![("x86_amd64", "")], - ("x86_64", X86_64) => vec![("amd64", "amd64"), ("x86_amd64", "")], - ("arm", X86) | ("thumbv7a", X86) => vec![("x86_arm", "")], - ("arm", X86_64) | ("thumbv7a", X86_64) => vec![("amd64_arm", "amd64"), ("x86_arm", "")], - _ => vec![], - } - } - - fn lib_subdir(target: &str) -> Option<&'static str> { - let arch = target.split('-').next().unwrap(); - match arch { - "i586" | "i686" => Some("x86"), - "x86_64" => Some("x64"), - "arm" | "thumbv7a" => Some("arm"), - "aarch64" => Some("arm64"), - _ => None, - } - } - - // MSVC's x86 libraries are not in a subfolder - fn vc_lib_subdir(target: &str) -> Option<&'static str> { - let arch = target.split('-').next().unwrap(); - match arch { - "i586" | "i686" => Some(""), - "x86_64" => Some("amd64"), - "arm" | "thumbv7a" => Some("arm"), - "aarch64" => Some("arm64"), - _ => None, - } - } - - #[allow(bad_style)] - fn host_arch() -> u16 { - type DWORD = u32; - type WORD = u16; - type LPVOID = *mut u8; - type DWORD_PTR = usize; - - #[repr(C)] - struct SYSTEM_INFO { - wProcessorArchitecture: WORD, - _wReserved: WORD, - _dwPageSize: DWORD, - _lpMinimumApplicationAddress: LPVOID, - _lpMaximumApplicationAddress: LPVOID, - _dwActiveProcessorMask: DWORD_PTR, - _dwNumberOfProcessors: DWORD, - _dwProcessorType: DWORD, - _dwAllocationGranularity: DWORD, - _wProcessorLevel: WORD, - _wProcessorRevision: WORD, - } - - extern "system" { - fn GetNativeSystemInfo(lpSystemInfo: *mut SYSTEM_INFO); - } - - unsafe { - let mut info = mem::zeroed(); - GetNativeSystemInfo(&mut info); - info.wProcessorArchitecture - } - } - - // Given a registry key, look at all the sub keys and find the one which has - // the maximal numeric value. - // - // Returns the name of the maximal key as well as the opened maximal key. - fn max_version(key: &RegistryKey) -> Option<(OsString, RegistryKey)> { - let mut max_vers = 0; - let mut max_key = None; - for subkey in key.iter().filter_map(|k| k.ok()) { - let val = subkey - .to_str() - .and_then(|s| s.trim_left_matches("v").replace(".", "").parse().ok()); - let val = match val { - Some(s) => s, - None => continue, - }; - if val > max_vers { - if let Ok(k) = key.open(&subkey) { - max_vers = val; - max_key = Some((subkey, k)); - } - } - } - max_key - } - - pub fn has_msbuild_version(version: &str) -> bool { - match version { - "16.0" => { - find_msbuild_vs16("x86_64-pc-windows-msvc").is_some() - || find_msbuild_vs16("i686-pc-windows-msvc").is_some() - } - "15.0" => { - find_msbuild_vs15("x86_64-pc-windows-msvc").is_some() - || find_msbuild_vs15("i686-pc-windows-msvc").is_some() - } - "12.0" | "14.0" => LOCAL_MACHINE - .open(&OsString::from(format!( - "SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\{}", - version - ))) - .is_ok(), - _ => false, - } - } - - pub fn find_devenv(target: &str) -> Option { - find_devenv_vs15(&target) - } - - fn find_devenv_vs15(target: &str) -> Option { - find_tool_in_vs15_path(r"Common7\IDE\devenv.exe", target) - } - - // see http://stackoverflow.com/questions/328017/path-to-msbuild - pub fn find_msbuild(target: &str) -> Option { - // VS 15 (2017) changed how to locate msbuild - if let Some(r) = find_msbuild_vs16(target) { - return Some(r); - } else if let Some(r) = find_msbuild_vs15(target) { - return Some(r); - } else { - find_old_msbuild(target) - } - } - - fn find_msbuild_vs15(target: &str) -> Option { - find_tool_in_vs15_path(r"MSBuild\15.0\Bin\MSBuild.exe", target) - } - - fn find_old_msbuild(target: &str) -> Option { - let key = r"SOFTWARE\Microsoft\MSBuild\ToolsVersions"; - LOCAL_MACHINE - .open(key.as_ref()) - .ok() - .and_then(|key| { - max_version(&key).and_then(|(_vers, key)| key.query_str("MSBuildToolsPath").ok()) - }) - .map(|path| { - let mut path = PathBuf::from(path); - path.push("MSBuild.exe"); - let mut tool = Tool::new(path); - if target.contains("x86_64") { - tool.env.push(("Platform".into(), "X64".into())); - } - tool - }) - } -} diff --git a/cc/tests/cc_env.rs b/cc/tests/cc_env.rs deleted file mode 100644 index 43eb689..0000000 --- a/cc/tests/cc_env.rs +++ /dev/null @@ -1,118 +0,0 @@ -use std::env; -use std::ffi::OsString; -use std::path::Path; - -mod support; -use crate::support::Test; - -#[test] -fn main() { - ccache(); - distcc(); - ccache_spaces(); - ccache_env_flags(); - leading_spaces(); - extra_flags(); - path_to_ccache(); - more_spaces(); -} - -fn ccache() { - let test = Test::gnu(); - - env::set_var("CC", "ccache cc"); - let compiler = test.gcc().file("foo.c").get_compiler(); - - assert_eq!(compiler.path(), Path::new("cc")); -} - -fn ccache_spaces() { - let test = Test::gnu(); - test.shim("ccache"); - - env::set_var("CC", "ccache cc"); - let compiler = test.gcc().file("foo.c").get_compiler(); - assert_eq!(compiler.path(), Path::new("cc")); -} - -fn distcc() { - let test = Test::gnu(); - test.shim("distcc"); - - env::set_var("CC", "distcc cc"); - let compiler = test.gcc().file("foo.c").get_compiler(); - assert_eq!(compiler.path(), Path::new("cc")); -} - -fn ccache_env_flags() { - let test = Test::gnu(); - test.shim("ccache"); - - env::set_var("CC", "ccache lol-this-is-not-a-compiler"); - let compiler = test.gcc().file("foo.c").get_compiler(); - assert_eq!(compiler.path(), Path::new("lol-this-is-not-a-compiler")); - assert_eq!( - compiler.cc_env(), - OsString::from("ccache lol-this-is-not-a-compiler") - ); - assert!( - compiler - .cflags_env() - .into_string() - .unwrap() - .contains("ccache") - == false - ); - assert!( - compiler - .cflags_env() - .into_string() - .unwrap() - .contains(" lol-this-is-not-a-compiler") - == false - ); - - env::set_var("CC", ""); -} - -fn leading_spaces() { - let test = Test::gnu(); - test.shim("ccache"); - - env::set_var("CC", " test "); - let compiler = test.gcc().file("foo.c").get_compiler(); - assert_eq!(compiler.path(), Path::new("test")); - - env::set_var("CC", ""); -} - -fn extra_flags() { - let test = Test::gnu(); - test.shim("ccache"); - - env::set_var("CC", "ccache cc -m32"); - let compiler = test.gcc().file("foo.c").get_compiler(); - assert_eq!(compiler.path(), Path::new("cc")); -} - -fn path_to_ccache() { - let test = Test::gnu(); - test.shim("ccache"); - - env::set_var("CC", "/path/to/ccache.exe cc -m32"); - let compiler = test.gcc().file("foo.c").get_compiler(); - assert_eq!(compiler.path(), Path::new("cc")); - assert_eq!( - compiler.cc_env(), - OsString::from("/path/to/ccache.exe cc -m32"), - ); -} - -fn more_spaces() { - let test = Test::gnu(); - test.shim("ccache"); - - env::set_var("CC", "cc -m32"); - let compiler = test.gcc().file("foo.c").get_compiler(); - assert_eq!(compiler.path(), Path::new("cc")); -} diff --git a/cc/tests/cflags.rs b/cc/tests/cflags.rs deleted file mode 100644 index caec6ea..0000000 --- a/cc/tests/cflags.rs +++ /dev/null @@ -1,15 +0,0 @@ -mod support; - -use crate::support::Test; -use std::env; - -/// This test is in its own module because it modifies the environment and would affect other tests -/// when run in parallel with them. -#[test] -fn gnu_no_warnings_if_cflags() { - env::set_var("CFLAGS", "-arbitrary"); - let test = Test::gnu(); - test.gcc().file("foo.c").compile("foo"); - - test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra"); -} diff --git a/cc/tests/cxxflags.rs b/cc/tests/cxxflags.rs deleted file mode 100644 index c524c7d..0000000 --- a/cc/tests/cxxflags.rs +++ /dev/null @@ -1,15 +0,0 @@ -mod support; - -use crate::support::Test; -use std::env; - -/// This test is in its own module because it modifies the environment and would affect other tests -/// when run in parallel with them. -#[test] -fn gnu_no_warnings_if_cxxflags() { - env::set_var("CXXFLAGS", "-arbitrary"); - let test = Test::gnu(); - test.gcc().file("foo.cpp").cpp(true).compile("foo"); - - test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra"); -} diff --git a/cc/tests/support/mod.rs b/cc/tests/support/mod.rs deleted file mode 100644 index fe8acde..0000000 --- a/cc/tests/support/mod.rs +++ /dev/null @@ -1,161 +0,0 @@ -#![allow(dead_code)] - -use std::env; -use std::ffi::{OsStr, OsString}; -use std::fs::{self, File}; -use std::io; -use std::io::prelude::*; -use std::path::{Path, PathBuf}; - -use cc; -use tempfile::{Builder, TempDir}; - -pub struct Test { - pub td: TempDir, - pub gcc: PathBuf, - pub msvc: bool, -} - -pub struct Execution { - args: Vec, -} - -impl Test { - pub fn new() -> Test { - let mut gcc = PathBuf::from(env::current_exe().unwrap()); - gcc.pop(); - if gcc.ends_with("deps") { - gcc.pop(); - } - let td = Builder::new().prefix("gcc-test").tempdir_in(&gcc).unwrap(); - gcc.push(format!("gcc-shim{}", env::consts::EXE_SUFFIX)); - Test { - td: td, - gcc: gcc, - msvc: false, - } - } - - pub fn gnu() -> Test { - let t = Test::new(); - t.shim("cc").shim("c++").shim("ar"); - t - } - - pub fn msvc() -> Test { - let mut t = Test::new(); - t.shim("cl").shim("lib.exe"); - t.msvc = true; - t - } - - pub fn shim(&self, name: &str) -> &Test { - link_or_copy( - &self.gcc, - self.td - .path() - .join(&format!("{}{}", name, env::consts::EXE_SUFFIX)), - ) - .unwrap(); - self - } - - pub fn gcc(&self) -> cc::Build { - let mut cfg = cc::Build::new(); - let target = if self.msvc { - "x86_64-pc-windows-msvc" - } else { - "x86_64-unknown-linux-gnu" - }; - - cfg.target(target) - .host(target) - .opt_level(2) - .debug(false) - .out_dir(self.td.path()) - .__set_env("PATH", self.path()) - .__set_env("GCCTEST_OUT_DIR", self.td.path()); - if self.msvc { - cfg.compiler(self.td.path().join("cl")); - cfg.archiver(self.td.path().join("lib.exe")); - } - cfg - } - - fn path(&self) -> OsString { - let mut path = env::split_paths(&env::var_os("PATH").unwrap()).collect::>(); - path.insert(0, self.td.path().to_owned()); - env::join_paths(path).unwrap() - } - - pub fn cmd(&self, i: u32) -> Execution { - let mut s = String::new(); - File::open(self.td.path().join(format!("out{}", i))) - .unwrap() - .read_to_string(&mut s) - .unwrap(); - Execution { - args: s.lines().map(|s| s.to_string()).collect(), - } - } -} - -impl Execution { - pub fn must_have>(&self, p: P) -> &Execution { - if !self.has(p.as_ref()) { - panic!("didn't find {:?} in {:?}", p.as_ref(), self.args); - } else { - self - } - } - - pub fn must_not_have>(&self, p: P) -> &Execution { - if self.has(p.as_ref()) { - panic!("found {:?}", p.as_ref()); - } else { - self - } - } - - pub fn has(&self, p: &OsStr) -> bool { - self.args.iter().any(|arg| OsStr::new(arg) == p) - } - - pub fn must_have_in_order(&self, before: &str, after: &str) -> &Execution { - let before_position = self - .args - .iter() - .rposition(|x| OsStr::new(x) == OsStr::new(before)); - let after_position = self - .args - .iter() - .rposition(|x| OsStr::new(x) == OsStr::new(after)); - match (before_position, after_position) { - (Some(b), Some(a)) if b < a => {} - (b, a) => panic!( - "{:?} (last position: {:?}) did not appear before {:?} (last position: {:?})", - before, b, after, a - ), - }; - self - } -} - -/// Hard link an executable or copy it if that fails. -/// -/// We first try to hard link an executable to save space. If that fails (as on Windows with -/// different mount points, issue #60), we copy. -#[cfg(not(target_os = "macos"))] -fn link_or_copy, Q: AsRef>(from: P, to: Q) -> io::Result<()> { - let from = from.as_ref(); - let to = to.as_ref(); - fs::hard_link(from, to).or_else(|_| fs::copy(from, to).map(|_| ())) -} - -/// Copy an executable. -/// -/// On macOS, hard linking the executable leads to strange failures (issue #419), so we just copy. -#[cfg(target_os = "macos")] -fn link_or_copy, Q: AsRef>(from: P, to: Q) -> io::Result<()> { - fs::copy(from, to).map(|_| ()) -} diff --git a/cc/tests/test.rs b/cc/tests/test.rs deleted file mode 100644 index def11f0..0000000 --- a/cc/tests/test.rs +++ /dev/null @@ -1,377 +0,0 @@ -use crate::support::Test; - -mod support; - -#[test] -fn gnu_smoke() { - let test = Test::gnu(); - test.gcc().file("foo.c").compile("foo"); - - test.cmd(0) - .must_have("-O2") - .must_have("foo.c") - .must_not_have("-g") - .must_have("-c") - .must_have("-ffunction-sections") - .must_have("-fdata-sections"); - test.cmd(1).must_have(test.td.path().join("foo.o")); -} - -#[test] -fn gnu_opt_level_1() { - let test = Test::gnu(); - test.gcc().opt_level(1).file("foo.c").compile("foo"); - - test.cmd(0).must_have("-O1").must_not_have("-O2"); -} - -#[test] -fn gnu_opt_level_s() { - let test = Test::gnu(); - test.gcc().opt_level_str("s").file("foo.c").compile("foo"); - - test.cmd(0) - .must_have("-Os") - .must_not_have("-O1") - .must_not_have("-O2") - .must_not_have("-O3") - .must_not_have("-Oz"); -} - -#[test] -fn gnu_debug_fp_auto() { - let test = Test::gnu(); - test.gcc().debug(true).file("foo.c").compile("foo"); - test.cmd(0).must_have("-g"); - test.cmd(0).must_have("-fno-omit-frame-pointer"); -} - -#[test] -fn gnu_debug_fp() { - let test = Test::gnu(); - test.gcc().debug(true).file("foo.c").compile("foo"); - test.cmd(0).must_have("-g"); - test.cmd(0).must_have("-fno-omit-frame-pointer"); -} - -#[test] -fn gnu_debug_nofp() { - let test = Test::gnu(); - test.gcc() - .debug(true) - .force_frame_pointer(false) - .file("foo.c") - .compile("foo"); - test.cmd(0).must_have("-g"); - test.cmd(0).must_not_have("-fno-omit-frame-pointer"); - - let test = Test::gnu(); - test.gcc() - .force_frame_pointer(false) - .debug(true) - .file("foo.c") - .compile("foo"); - test.cmd(0).must_have("-g"); - test.cmd(0).must_not_have("-fno-omit-frame-pointer"); -} - -#[test] -fn gnu_warnings_into_errors() { - let test = Test::gnu(); - test.gcc() - .warnings_into_errors(true) - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_have("-Werror"); -} - -#[test] -fn gnu_warnings() { - let test = Test::gnu(); - test.gcc() - .warnings(true) - .flag("-Wno-missing-field-initializers") - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_have("-Wall").must_have("-Wextra"); -} - -#[test] -fn gnu_extra_warnings0() { - let test = Test::gnu(); - test.gcc() - .warnings(true) - .extra_warnings(false) - .flag("-Wno-missing-field-initializers") - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_have("-Wall").must_not_have("-Wextra"); -} - -#[test] -fn gnu_extra_warnings1() { - let test = Test::gnu(); - test.gcc() - .warnings(false) - .extra_warnings(true) - .flag("-Wno-missing-field-initializers") - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_not_have("-Wall").must_have("-Wextra"); -} - -#[test] -fn gnu_warnings_overridable() { - let test = Test::gnu(); - test.gcc() - .warnings(true) - .flag("-Wno-missing-field-initializers") - .file("foo.c") - .compile("foo"); - - test.cmd(0) - .must_have_in_order("-Wall", "-Wno-missing-field-initializers"); -} - -#[test] -fn gnu_x86_64() { - for vendor in &["unknown-linux-gnu", "apple-darwin"] { - let target = format!("x86_64-{}", vendor); - let test = Test::gnu(); - test.gcc() - .target(&target) - .host(&target) - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_have("-fPIC").must_have("-m64"); - } -} - -#[test] -fn gnu_x86_64_no_pic() { - for vendor in &["unknown-linux-gnu", "apple-darwin"] { - let target = format!("x86_64-{}", vendor); - let test = Test::gnu(); - test.gcc() - .pic(false) - .target(&target) - .host(&target) - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_not_have("-fPIC"); - } -} - -#[test] -fn gnu_i686() { - for vendor in &["unknown-linux-gnu", "apple-darwin"] { - let target = format!("i686-{}", vendor); - let test = Test::gnu(); - test.gcc() - .target(&target) - .host(&target) - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_have("-m32"); - } -} - -#[test] -fn gnu_i686_pic() { - for vendor in &["unknown-linux-gnu", "apple-darwin"] { - let target = format!("i686-{}", vendor); - let test = Test::gnu(); - test.gcc() - .pic(true) - .target(&target) - .host(&target) - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_have("-fPIC"); - } -} - -#[test] -fn gnu_x86_64_no_plt() { - let target = "x86_64-unknown-linux-gnu"; - let test = Test::gnu(); - test.gcc() - .pic(true) - .use_plt(false) - .target(&target) - .host(&target) - .file("foo.c") - .compile("foo"); - test.cmd(0).must_have("-fno-plt"); -} - -#[test] -fn gnu_set_stdlib() { - let test = Test::gnu(); - test.gcc() - .cpp_set_stdlib(Some("foo")) - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_not_have("-stdlib=foo"); -} - -#[test] -fn gnu_include() { - let test = Test::gnu(); - test.gcc().include("foo/bar").file("foo.c").compile("foo"); - - test.cmd(0).must_have("-I").must_have("foo/bar"); -} - -#[test] -fn gnu_define() { - let test = Test::gnu(); - test.gcc() - .define("FOO", "bar") - .define("BAR", None) - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_have("-DFOO=bar").must_have("-DBAR"); -} - -#[test] -fn gnu_compile_assembly() { - let test = Test::gnu(); - test.gcc().file("foo.S").compile("foo"); - test.cmd(0).must_have("foo.S"); -} - -#[test] -fn gnu_shared() { - let test = Test::gnu(); - test.gcc() - .file("foo.c") - .shared_flag(true) - .static_flag(false) - .compile("foo"); - - test.cmd(0).must_have("-shared").must_not_have("-static"); -} - -#[test] -fn gnu_flag_if_supported() { - if cfg!(windows) { - return; - } - let test = Test::gnu(); - test.gcc() - .file("foo.c") - .flag("-v") - .flag_if_supported("-Wall") - .flag_if_supported("-Wflag-does-not-exist") - .flag_if_supported("-std=c++11") - .compile("foo"); - - test.cmd(0) - .must_have("-v") - .must_have("-Wall") - .must_not_have("-Wflag-does-not-exist") - .must_not_have("-std=c++11"); -} - -#[test] -fn gnu_flag_if_supported_cpp() { - if cfg!(windows) { - return; - } - let test = Test::gnu(); - test.gcc() - .cpp(true) - .file("foo.cpp") - .flag_if_supported("-std=c++11") - .compile("foo"); - - test.cmd(0).must_have("-std=c++11"); -} - -#[test] -fn gnu_static() { - let test = Test::gnu(); - test.gcc() - .file("foo.c") - .shared_flag(false) - .static_flag(true) - .compile("foo"); - - test.cmd(0).must_have("-static").must_not_have("-shared"); -} - -#[test] -fn msvc_smoke() { - let test = Test::msvc(); - test.gcc().file("foo.c").compile("foo"); - - test.cmd(0) - .must_have("-O2") - .must_have("foo.c") - .must_not_have("-Z7") - .must_have("-c") - .must_have("-MD"); - test.cmd(1).must_have(test.td.path().join("foo.o")); -} - -#[test] -fn msvc_opt_level_0() { - let test = Test::msvc(); - test.gcc().opt_level(0).file("foo.c").compile("foo"); - - test.cmd(0).must_not_have("-O2"); -} - -#[test] -fn msvc_debug() { - let test = Test::msvc(); - test.gcc().debug(true).file("foo.c").compile("foo"); - test.cmd(0).must_have("-Z7"); -} - -#[test] -fn msvc_include() { - let test = Test::msvc(); - test.gcc().include("foo/bar").file("foo.c").compile("foo"); - - test.cmd(0).must_have("-I").must_have("foo/bar"); -} - -#[test] -fn msvc_define() { - let test = Test::msvc(); - test.gcc() - .define("FOO", "bar") - .define("BAR", None) - .file("foo.c") - .compile("foo"); - - test.cmd(0).must_have("-DFOO=bar").must_have("-DBAR"); -} - -#[test] -fn msvc_static_crt() { - let test = Test::msvc(); - test.gcc().static_crt(true).file("foo.c").compile("foo"); - - test.cmd(0).must_have("-MT"); -} - -#[test] -fn msvc_no_static_crt() { - let test = Test::msvc(); - test.gcc().static_crt(false).file("foo.c").compile("foo"); - - test.cmd(0).must_have("-MD"); -} diff --git a/cfg-if/.github/workflows/main.yml b/cfg-if/.github/workflows/main.yml deleted file mode 100644 index 411ffe7..0000000 --- a/cfg-if/.github/workflows/main.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: CI -on: [push, pull_request] - -jobs: - test: - name: Test - runs-on: ubuntu-latest - strategy: - matrix: - rust: [stable, beta, nightly] - steps: - - uses: actions/checkout@master - - name: Install Rust Stable - run: | - rustup self update - rustup update ${{ matrix.rust }} - rustup default ${{ matrix.rust }} - rustc -vV - - name: Run tests - run: cargo test - - rustfmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Install Rust Stable - run: | - rustup update stable - rustup default stable - rustup component add rustfmt - - name: Run rustfmt - run: cargo fmt -- --check - - publish_docs: - name: Publish Documentation - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Install Rust Stable - run: | - rustup update stable - rustup default stable - - name: Build documentation - run: cargo doc --no-deps - - name: Publish documentation - run: | - cd target/doc - git init - git add . - git -c user.name='ci' -c user.email='ci' commit -m init - git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages - if: github.event_name == 'push' && github.event.ref == 'refs/heads/master' diff --git a/cfg-if/.gitignore b/cfg-if/.gitignore deleted file mode 100644 index a9d37c5..0000000 --- a/cfg-if/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target -Cargo.lock diff --git a/cfg-if/Cargo.toml b/cfg-if/Cargo.toml deleted file mode 100644 index 01bd1a7..0000000 --- a/cfg-if/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "cfg-if" -version = "0.1.10" -authors = ["Alex Crichton "] -license = "MIT/Apache-2.0" -readme = "README.md" -repository = "https://github.com/alexcrichton/cfg-if" -homepage = "https://github.com/alexcrichton/cfg-if" -documentation = "https://docs.rs/cfg-if" -description = """ -A macro to ergonomically define an item depending on a large number of #[cfg] -parameters. Structured like an if-else chain, the first matching branch is the -item that gets emitted. -""" -edition = "2018" - -[badges] -travis-ci = { repository = "alexcrichton/cfg-if" } - -[dependencies] -core = { version = "1.0.0", optional = true, package = 'rustc-std-workspace-core' } -compiler_builtins = { version = '0.1.2', optional = true } - -[features] -rustc-dep-of-std = ['core', 'compiler_builtins'] diff --git a/cfg-if/LICENSE-APACHE b/cfg-if/LICENSE-APACHE deleted file mode 100644 index 16fe87b..0000000 --- a/cfg-if/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/cfg-if/LICENSE-MIT b/cfg-if/LICENSE-MIT deleted file mode 100644 index 39e0ed6..0000000 --- a/cfg-if/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2014 Alex Crichton - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/cfg-if/README.md b/cfg-if/README.md deleted file mode 100644 index 50b5e3b..0000000 --- a/cfg-if/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# cfg-if - -[Documentation](https://docs.rs/cfg-if) - -A macro to ergonomically define an item depending on a large number of #[cfg] -parameters. Structured like an if-else chain, the first matching branch is the -item that gets emitted. - -```toml -[dependencies] -cfg-if = "0.1" -``` - -## Example - -```rust -cfg_if::cfg_if! { - if #[cfg(unix)] { - fn foo() { /* unix specific functionality */ } - } else if #[cfg(target_pointer_width = "32")] { - fn foo() { /* non-unix, 32-bit functionality */ } - } else { - fn foo() { /* fallback implementation */ } - } -} - -fn main() { - foo(); -} -``` - -# License - -This project is licensed under either of - - * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or - http://www.apache.org/licenses/LICENSE-2.0) - * MIT license ([LICENSE-MIT](LICENSE-MIT) or - http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in `cfg-if` by you, as defined in the Apache-2.0 license, shall be -dual licensed as above, without any additional terms or conditions. diff --git a/cfg-if/src/lib.rs b/cfg-if/src/lib.rs deleted file mode 100644 index 6c5058d..0000000 --- a/cfg-if/src/lib.rs +++ /dev/null @@ -1,176 +0,0 @@ -//! A macro for defining `#[cfg]` if-else statements. -//! -//! The macro provided by this crate, `cfg_if`, is similar to the `if/elif` C -//! preprocessor macro by allowing definition of a cascade of `#[cfg]` cases, -//! emitting the implementation which matches first. -//! -//! This allows you to conveniently provide a long list `#[cfg]`'d blocks of code -//! without having to rewrite each clause multiple times. -//! -//! # Example -//! -//! ``` -//! cfg_if::cfg_if! { -//! if #[cfg(unix)] { -//! fn foo() { /* unix specific functionality */ } -//! } else if #[cfg(target_pointer_width = "32")] { -//! fn foo() { /* non-unix, 32-bit functionality */ } -//! } else { -//! fn foo() { /* fallback implementation */ } -//! } -//! } -//! -//! # fn main() {} -//! ``` - -#![no_std] -#![doc(html_root_url = "https://docs.rs/cfg-if")] -#![deny(missing_docs)] -#![cfg_attr(test, deny(warnings))] - -/// The main macro provided by this crate. See crate documentation for more -/// information. -#[macro_export] -macro_rules! cfg_if { - // match if/else chains with a final `else` - ($( - if #[cfg($($meta:meta),*)] { $($tokens:tt)* } - ) else * else { - $($tokens2:tt)* - }) => { - $crate::cfg_if! { - @__items - () ; - $( ( ($($meta),*) ($($tokens)*) ), )* - ( () ($($tokens2)*) ), - } - }; - - // match if/else chains lacking a final `else` - ( - if #[cfg($($i_met:meta),*)] { $($i_tokens:tt)* } - $( - else if #[cfg($($e_met:meta),*)] { $($e_tokens:tt)* } - )* - ) => { - $crate::cfg_if! { - @__items - () ; - ( ($($i_met),*) ($($i_tokens)*) ), - $( ( ($($e_met),*) ($($e_tokens)*) ), )* - ( () () ), - } - }; - - // Internal and recursive macro to emit all the items - // - // Collects all the negated cfgs in a list at the beginning and after the - // semicolon is all the remaining items - (@__items ($($not:meta,)*) ; ) => {}; - (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($tokens:tt)*) ), $($rest:tt)*) => { - // Emit all items within one block, applying an appropriate #[cfg]. The - // #[cfg] will require all `$m` matchers specified and must also negate - // all previous matchers. - #[cfg(all($($m,)* not(any($($not),*))))] $crate::cfg_if! { @__identity $($tokens)* } - - // Recurse to emit all other items in `$rest`, and when we do so add all - // our `$m` matchers to the list of `$not` matchers as future emissions - // will have to negate everything we just matched as well. - $crate::cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* } - }; - - // Internal macro to make __apply work out right for different match types, - // because of how macros matching/expand stuff. - (@__identity $($tokens:tt)*) => { - $($tokens)* - }; -} - -#[cfg(test)] -mod tests { - cfg_if! { - if #[cfg(test)] { - use core::option::Option as Option2; - fn works1() -> Option2 { Some(1) } - } else { - fn works1() -> Option { None } - } - } - - cfg_if! { - if #[cfg(foo)] { - fn works2() -> bool { false } - } else if #[cfg(test)] { - fn works2() -> bool { true } - } else { - fn works2() -> bool { false } - } - } - - cfg_if! { - if #[cfg(foo)] { - fn works3() -> bool { false } - } else { - fn works3() -> bool { true } - } - } - - cfg_if! { - if #[cfg(test)] { - use core::option::Option as Option3; - fn works4() -> Option3 { Some(1) } - } - } - - cfg_if! { - if #[cfg(foo)] { - fn works5() -> bool { false } - } else if #[cfg(test)] { - fn works5() -> bool { true } - } - } - - #[test] - fn it_works() { - assert!(works1().is_some()); - assert!(works2()); - assert!(works3()); - assert!(works4().is_some()); - assert!(works5()); - } - - #[test] - #[allow(clippy::assertions_on_constants)] - fn test_usage_within_a_function() { - cfg_if! {if #[cfg(debug_assertions)] { - // we want to put more than one thing here to make sure that they - // all get configured properly. - assert!(cfg!(debug_assertions)); - assert_eq!(4, 2+2); - } else { - assert!(works1().is_some()); - assert_eq!(10, 5+5); - }} - } - - trait Trait { - fn blah(&self); - } - - #[allow(dead_code)] - struct Struct; - - impl Trait for Struct { - cfg_if! { - if #[cfg(feature = "blah")] { - fn blah(&self) { - unimplemented!(); - } - } else { - fn blah(&self) { - unimplemented!(); - } - } - } - } -} diff --git a/cfg-if/tests/xcrate.rs b/cfg-if/tests/xcrate.rs deleted file mode 100644 index e7b4a36..0000000 --- a/cfg-if/tests/xcrate.rs +++ /dev/null @@ -1,14 +0,0 @@ -cfg_if::cfg_if! { - if #[cfg(foo)] { - fn works() -> bool { false } - } else if #[cfg(test)] { - fn works() -> bool { true } - } else { - fn works() -> bool { false } - } -} - -#[test] -fn smoke() { - assert!(works()); -} diff --git a/getrandom/.cargo/config b/getrandom/.cargo/config deleted file mode 100644 index 291ce5e..0000000 --- a/getrandom/.cargo/config +++ /dev/null @@ -1,5 +0,0 @@ -[target.wasm32-unknown-unknown] -runner = 'wasm-bindgen-test-runner' - -[target.wasm32-wasi] -runner = 'wasmtime' diff --git a/getrandom/.gitignore b/getrandom/.gitignore deleted file mode 100644 index 435eeee..0000000 --- a/getrandom/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/target -**/*.rs.bk -Cargo.lock -*.ts -*.js -*.wasm diff --git a/getrandom/.travis.yml b/getrandom/.travis.yml deleted file mode 100644 index bdd9e72..0000000 --- a/getrandom/.travis.yml +++ /dev/null @@ -1,221 +0,0 @@ -language: rust -sudo: false - -matrix: - include: - - name: "Linux, 1.32.0" - rust: 1.32.0 - os: linux - - - name: "OSX, 1.32.0" - rust: 1.32.0 - os: osx - - - name: "Linux, stable" - rust: stable - - - name: "OSX+iOS, stable" - rust: stable - os: osx - install: - - rustup target add aarch64-apple-ios - script: - - cargo test - - cargo test --examples - - cargo build --target aarch64-apple-ios - - - name: "Linux, beta" - rust: beta - - - name: "WASM via emscripten, stdweb, wasm-bindgen and WASI" - rust: nightly - addons: - firefox: latest - chrome: stable - install: - - rustup target add wasm32-unknown-unknown - - rustup target add wasm32-unknown-emscripten - - rustup target add asmjs-unknown-emscripten - - rustup target add wasm32-wasi - # Get latest geckodriver - - export VERSION=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | jq -r ".tag_name") - - wget -O geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/$VERSION/geckodriver-$VERSION-linux64.tar.gz - - tar -xzf geckodriver.tar.gz - # Get latest chromedirver - - export VERSION=$(wget -q -O - https://chromedriver.storage.googleapis.com/LATEST_RELEASE) - - wget -O chromedriver.zip https://chromedriver.storage.googleapis.com/$VERSION/chromedriver_linux64.zip - - unzip chromedriver.zip - # Get cargo-web - - export VERSION=0.6.26 # Pin version for stability - - wget -O cargo-web.gz https://github.com/koute/cargo-web/releases/download/$VERSION/cargo-web-x86_64-unknown-linux-gnu.gz - - gunzip cargo-web.gz - - chmod +x cargo-web - # Get wasmtime - - export VERSION=v0.3.0 # Pin version for stability - - wget -O wasmtime.tar.xz https://github.com/CraneStation/wasmtime/releases/download/$VERSION/wasmtime-$VERSION-x86_64-linux.tar.xz - - tar -xf wasmtime.tar.xz --strip-components=1 - # Get wasm-bindgen-test-runner which matches our wasm-bindgen version - - export VERSION=$(cargo metadata --format-version=1 | jq -r '.packages[] | select ( .name == "wasm-bindgen" ) | .version') - - wget -O wasm-bindgen.tar.gz https://github.com/rustwasm/wasm-bindgen/releases/download/$VERSION/wasm-bindgen-$VERSION-x86_64-unknown-linux-musl.tar.gz - - tar -xzf wasm-bindgen.tar.gz --strip-components=1 - # Place the runner binaries in our PATH - - mv cargo-web wasmtime wasm-bindgen-test-runner $HOME/.cargo/bin - # Download and setup emscripten - - cargo web prepare-emscripten - env: EMCC_CFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" - script: - # We cannot run emscripten test binaries (see rust-lang/rust#63649). - # However, we can still build and link all tests to make sure that works. - # This is actually useful as it finds stuff such as rust-random/rand#669 - - cargo web test --target wasm32-unknown-emscripten --no-run - - cargo web test --target asmjs-unknown-emscripten --no-run - # wasi tests - - cargo test --target wasm32-wasi - # stdweb tests (Node, Chrome) - - cargo web test --nodejs --target=wasm32-unknown-unknown --features=stdweb - - cargo web test --target=wasm32-unknown-unknown --features=stdweb - # wasm-bindgen tests (Node, Firefox, Chrome) - - cargo test --target wasm32-unknown-unknown --features=wasm-bindgen - - GECKODRIVER=$PWD/geckodriver cargo test --target wasm32-unknown-unknown --features=test-in-browser - - CHROMEDRIVER=$PWD/chromedriver cargo test --target wasm32-unknown-unknown --features=test-in-browser - - - name: "Linux, nightly, docs" - rust: nightly - os: linux - install: - - cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks - - cargo deadlinks -V - script: - - cargo test - - cargo test --benches - - cargo test --examples - # remove cached documentation, otherwise files from previous PRs can get included - - rm -rf target/doc - - cargo doc --no-deps --all --features=std,log - - cargo deadlinks --dir target/doc - # also test minimum dependency versions are usable - - cargo generate-lockfile -Z minimal-versions - - cargo test - - - name: "OSX, nightly, docs" - rust: nightly - os: osx - install: - - cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks - - cargo deadlinks -V - script: - - cargo test - - cargo test --benches - - cargo test --examples - # remove cached documentation, otherwise files from previous PRs can get included - - rm -rf target/doc - - cargo doc --no-deps --all --features=std,log - - cargo deadlinks --dir target/doc - # also test minimum dependency versions are usable - - cargo generate-lockfile -Z minimal-versions - - cargo test - - - name: "cross-platform build only" - rust: nightly - install: - - rustup target add x86_64-sun-solaris - - rustup target add x86_64-unknown-cloudabi - - rustup target add x86_64-unknown-freebsd - - rustup target add x86_64-fuchsia - - rustup target add x86_64-unknown-netbsd - - rustup target add x86_64-unknown-redox - - rustup target add x86_64-fortanix-unknown-sgx - # For no_std targets - - rustup component add rust-src - - cargo install cargo-xbuild || true - script: - - cargo build --target=x86_64-sun-solaris - - cargo build --target=x86_64-unknown-cloudabi - - cargo build --target=x86_64-unknown-freebsd - - cargo build --target=x86_64-fuchsia - - cargo build --target=x86_64-unknown-netbsd - - cargo build --target=x86_64-unknown-redox - - cargo build --target=x86_64-fortanix-unknown-sgx - - cargo xbuild --target=x86_64-unknown-uefi - - cargo xbuild --target=x86_64-unknown-hermit - - cargo xbuild --target=x86_64-unknown-l4re-uclibc - - cargo xbuild --target=x86_64-wrs-vxworks - # also test minimum dependency versions are usable - - cargo generate-lockfile -Z minimal-versions - - cargo build --target=x86_64-sun-solaris - - cargo build --target=x86_64-unknown-cloudabi - - cargo build --target=x86_64-unknown-freebsd - - cargo build --target=x86_64-fuchsia - - cargo build --target=x86_64-unknown-netbsd - - cargo build --target=x86_64-unknown-redox - - cargo build --target=x86_64-fortanix-unknown-sgx - - cargo xbuild --target=x86_64-unknown-uefi - - cargo xbuild --target=x86_64-unknown-hermit - - cargo xbuild --target=x86_64-unknown-l4re-uclibc - - cargo xbuild --target=x86_64-uwp-windows-gnu - - # Trust cross-built/emulated targets. We must repeat all non-default values. - - name: "Linux (MIPS, big-endian)" - env: TARGET=mips-unknown-linux-gnu - rust: stable - sudo: required - dist: trusty - services: docker - install: - - sh utils/ci/install.sh - - source ~/.cargo/env || true - script: - - bash utils/ci/script.sh - - - name: "Android (ARMv7)" - env: TARGET=armv7-linux-androideabi - rust: stable - sudo: required - dist: trusty - services: docker - install: - - sh utils/ci/install.sh - - source ~/.cargo/env || true - script: - - bash utils/ci/script.sh - - - name: "rustfmt" - rust: stable - install: - - rustup component add rustfmt - script: - - cargo fmt --all -- */*.rs --check - - allow_failures: - # Formatting errors should appear in Travis, but not break the build. - - name: "rustfmt" - -before_install: - - set -e - - rustup self update - -before_script: - - export RUSTFLAGS="-D warnings" - -script: - - cargo test - - cargo test --examples - -after_script: set +e - -cache: - cargo: true - directories: - - .local/share/cargo-web - -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -notifications: - email: - on_success: never - -branches: - only: - - master diff --git a/getrandom/CHANGELOG.md b/getrandom/CHANGELOG.md deleted file mode 100644 index 2f6e9f4..0000000 --- a/getrandom/CHANGELOG.md +++ /dev/null @@ -1,158 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.1.13] - 2019-08-25 -### Added -- VxWorks targets support. [#86] - -### Changed -- If zero-length slice is passed to the `getrandom` function, always return -`Ok(())` immediately without doing any calls to the underlying operating -system. [#104] -- Use the `kern.arandom` sysctl on NetBSD. [#115] - -### Fixed -- Bump `cfg-if` minimum version from 0.1.0 to 0.1.2. [#112] -- Typos and bad doc links. [#117] - -[#86]: https://github.com/rust-random/getrandom/pull/86 -[#104]: https://github.com/rust-random/getrandom/pull/104 -[#112]: https://github.com/rust-random/getrandom/pull/112 -[#115]: https://github.com/rust-random/getrandom/pull/115 -[#117]: https://github.com/rust-random/getrandom/pull/117 - -## [0.1.12] - 2019-08-18 -### Changed -- Update wasi dependency from v0.5 to v0.7. [#100] - -[#100]: https://github.com/rust-random/getrandom/pull/100 - -## [0.1.11] - 2019-08-25 -### Fixed -- Implement `std`-dependent traits for selected targets even if `std` -feature is disabled. (backward compatibility with v0.1.8) [#96] - -[#96]: https://github.com/rust-random/getrandom/pull/96 - -## [0.1.10] - 2019-08-18 [YANKED] -### Changed -- Use the dummy implementation on `wasm32-unknown-unknown` even with the -disabled `dummy` feature. [#90] - -### Fixed -- Fix CSP error for `wasm-bindgen`. [#92] - -[#90]: https://github.com/rust-random/getrandom/pull/90 -[#92]: https://github.com/rust-random/getrandom/pull/92 - -## [0.1.9] - 2019-08-14 [YANKED] -### Changed -- Remove `std` dependency for opening and reading files. [#58] -- Use `wasi` isntead of `libc` on WASI target. [#64] -- By default emit a compile-time error when built for an unsupported target. -This behaviour can be disabled by using the `dummy` feature. [#71] - -### Added -- Add support for UWP targets. [#69] -- Add unstable `rustc-dep-of-std` feature. [#78] - -[#58]: https://github.com/rust-random/getrandom/pull/58 -[#64]: https://github.com/rust-random/getrandom/pull/64 -[#69]: https://github.com/rust-random/getrandom/pull/69 -[#71]: https://github.com/rust-random/getrandom/pull/71 -[#78]: https://github.com/rust-random/getrandom/pull/78 - -## [0.1.8] - 2019-07-29 -### Changed -- Explicitly specify types to arguments of 'libc::syscall'. [#74] - -[#74]: https://github.com/rust-random/getrandom/pull/74 - -## [0.1.7] - 2019-07-29 -### Added -- Support for hermit and l4re. [#61] -- `Error::raw_os_error` method, `Error::INTERNAL_START` and -`Error::CUSTOM_START` constants. Use `libc` for retrieving OS error descriptions. [#54] - -### Changed -- Remove `lazy_static` dependency and use custom structures for lock-free -initialization. [#51] [#52] -- Try `getrandom()` first on FreeBSD. [#57] - -### Removed -- Bitrig support. [#56] - -### Deprecated -- `Error::UNKNOWN`, `Error::UNAVAILABLE`. [#54] - -[#51]: https://github.com/rust-random/getrandom/pull/51 -[#52]: https://github.com/rust-random/getrandom/pull/52 -[#54]: https://github.com/rust-random/getrandom/pull/54 -[#56]: https://github.com/rust-random/getrandom/pull/56 -[#57]: https://github.com/rust-random/getrandom/pull/57 -[#61]: https://github.com/rust-random/getrandom/pull/61 - -## [0.1.6] - 2019-06-30 -### Changed -- Minor change of RDRAND AMD bug handling. [#48] - -[#48]: https://github.com/rust-random/getrandom/pull/48 - -## [0.1.5] - 2019-06-29 -### Fixed -- Use shared `File` instead of shared file descriptor. [#44] -- Workaround for RDRAND hardware bug present on some AMD CPUs. [#43] - -### Changed -- Try `getentropy` and then fallback to `/dev/random` on macOS. [#38] - -[#38]: https://github.com/rust-random/getrandom/issues/38 -[#43]: https://github.com/rust-random/getrandom/pull/43 -[#44]: https://github.com/rust-random/getrandom/issues/44 - -## [0.1.4] - 2019-06-28 -### Added -- Add support for `x86_64-unknown-uefi` target by using RDRAND with CPUID -feature detection. [#30] - -### Fixed -- Fix long buffer issues on Windows and Linux. [#31] [#32] -- Check `EPERM` in addition to `ENOSYS` on Linux. [#37] - -### Changed -- Improve efficiency by sharing file descriptor across threads. [#13] -- Remove `cloudabi`, `winapi`, and `fuchsia-cprng` dependencies. [#40] -- Improve RDRAND implementation. [#24] -- Don't block during syscall detection on Linux. [#26] -- Increase consistency with libc implementation on FreeBSD. [#36] -- Apply `rustfmt`. [#39] - -[#30]: https://github.com/rust-random/getrandom/pull/30 -[#13]: https://github.com/rust-random/getrandom/issues/13 -[#40]: https://github.com/rust-random/getrandom/pull/40 -[#26]: https://github.com/rust-random/getrandom/pull/26 -[#24]: https://github.com/rust-random/getrandom/pull/24 -[#39]: https://github.com/rust-random/getrandom/pull/39 -[#36]: https://github.com/rust-random/getrandom/pull/36 -[#31]: https://github.com/rust-random/getrandom/issues/31 -[#32]: https://github.com/rust-random/getrandom/issues/32 -[#37]: https://github.com/rust-random/getrandom/issues/37 - -## [0.1.3] - 2019-05-15 -- Update for `wasm32-unknown-wasi` being renamed to `wasm32-wasi`, and for - WASI being categorized as an OS. - -## [0.1.2] - 2019-04-06 -- Add support for `wasm32-unknown-wasi` target. - -## [0.1.1] - 2019-04-05 -- Enable std functionality for CloudABI by default. - -## [0.1.0] - 2019-03-23 -Publish initial implementation. - -## [0.0.0] - 2019-01-19 -Publish an empty template library. diff --git a/getrandom/Cargo.toml b/getrandom/Cargo.toml deleted file mode 100644 index b159674..0000000 --- a/getrandom/Cargo.toml +++ /dev/null @@ -1,45 +0,0 @@ -[package] -name = "getrandom" -version = "0.1.13" -edition = "2018" -authors = ["The Rand Project Developers"] -license = "MIT OR Apache-2.0" -description = "A small cross-platform library for retrieving random data from system source" -documentation = "https://docs.rs/getrandom" -repository = "https://github.com/rust-random/getrandom" -categories = ["os", "no-std"] -exclude = ["utils/*", ".*", "appveyor.yml"] - -[badges] -travis-ci = { repository = "rust-random/getrandom" } -appveyor = { repository = "rust-random/getrandom" } - -[dependencies] -log = { version = "0.4", optional = true } -cfg-if = "0.1.2" - -# When built as part of libstd -compiler_builtins = { version = "0.1", optional = true } -core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" } - -[target.'cfg(unix)'.dependencies] -libc = { version = "0.2.64", default-features = false } - -[target.'cfg(target_os = "wasi")'.dependencies] -wasi = "0.7" - -[target.wasm32-unknown-unknown.dependencies] -wasm-bindgen = { version = "0.2.29", optional = true } -stdweb = { version = "0.4.18", optional = true } - -[target.wasm32-unknown-unknown.dev-dependencies] -wasm-bindgen-test = "0.2" - -[features] -std = [] -# Enables dummy implementation for unsupported targets -dummy = [] -# Unstable feature to support being a libstd dependency -rustc-dep-of-std = ["compiler_builtins", "core"] -# Unstable feature for testing -test-in-browser = ["wasm-bindgen"] diff --git a/getrandom/LICENSE-APACHE b/getrandom/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/getrandom/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/getrandom/LICENSE-MIT b/getrandom/LICENSE-MIT deleted file mode 100644 index d93b5ba..0000000 --- a/getrandom/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2018 Developers of the Rand project -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/getrandom/README.md b/getrandom/README.md deleted file mode 100644 index 01bbfb5..0000000 --- a/getrandom/README.md +++ /dev/null @@ -1,78 +0,0 @@ -# getrandom - -[![Build Status](https://travis-ci.org/rust-random/getrandom.svg?branch=master)](https://travis-ci.org/rust-random/getrandom) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/getrandom?svg=true)](https://ci.appveyor.com/project/rust-random/getrandom) -[![Crate](https://img.shields.io/crates/v/getrandom.svg)](https://crates.io/crates/getrandom) -[![Documentation](https://docs.rs/getrandom/badge.svg)](https://docs.rs/getrandom) -[![Dependency status](https://deps.rs/repo/github/rust-random/getrandom/status.svg)](https://deps.rs/repo/github/rust-random/getrandom) - - -A Rust library for retrieving random data from (operating) system source. It is -assumed that system always provides high-quality cryptographically secure random -data, ideally backed by hardware entropy sources. This crate derives its name -from Linux's `getrandom` function, but is cross platform, roughly supporting -the same set of platforms as Rust's `std` lib. - -This is a low-level API. Most users should prefer using high-level random-number -library like [`rand`]. - -[`rand`]: https://crates.io/crates/rand - -## Usage - -Add this to your `Cargo.toml`: - -```toml -[dependencies] -getrandom = "0.1" -``` - -Then invoke the `getrandom` function: - -```rust -fn get_random_buf() -> Result<[u8; 32], getrandom::Error> { - let mut buf = [0u8; 32]; - getrandom::getrandom(&mut buf)?; - Ok(buf) -} -``` - -## Features - -This library is `no_std` for every supported target. However, getting randomness -usually requires calling some external system API. This means most platforms -will require linking against system libraries (i.e. `libc` for Unix, -`Advapi32.dll` for Windows, Security framework on iOS, etc...). - -The `log` library is supported as an optional dependency. If enabled, error -reporting will be improved on some platforms. - -For the `wasm32-unknown-unknown` target, one of the following features should be -enabled: - -- [`wasm-bindgen`](https://crates.io/crates/wasm_bindgen) -- [`stdweb`](https://crates.io/crates/stdweb) - -By default, compiling `getrandom` for an unsupported target will result in -a compilation error. If you want to build an application which uses `getrandom` -for such target, you can either: -- Use [`[replace]`][replace] or [`[patch]`][patch] section in your `Cargo.toml` -to switch to a custom implementation with a support of your target. -- Enable the `dummy` feature to have getrandom use an implementation that always -fails at run-time on unsupported targets. - -[replace]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-replace-section -[patch]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section - -## Minimum Supported Rust Version - -This crate requires Rust 1.32.0 or later. - -# License - -The `getrandom` library is distributed under either of - - * [Apache License, Version 2.0](LICENSE-APACHE) - * [MIT license](LICENSE-MIT) - -at your option. diff --git a/getrandom/appveyor.yml b/getrandom/appveyor.yml deleted file mode 100644 index 7a34e32..0000000 --- a/getrandom/appveyor.yml +++ /dev/null @@ -1,52 +0,0 @@ -environment: - - # At the time this was added AppVeyor was having troubles with checking - # revocation of SSL certificates of sites like static.rust-lang.org and what - # we think is crates.io. The libcurl HTTP client by default checks for - # revocation on Windows and according to a mailing list [1] this can be - # disabled. - # - # The `CARGO_HTTP_CHECK_REVOKE` env var here tells cargo to disable SSL - # revocation checking on Windows in libcurl. Note, though, that rustup, which - # we're using to download Rust here, also uses libcurl as the default backend. - # Unlike Cargo, however, rustup doesn't have a mechanism to disable revocation - # checking. To get rustup working we set `RUSTUP_USE_HYPER` which forces it to - # use the Hyper instead of libcurl backend. Both Hyper and libcurl use - # schannel on Windows but it appears that Hyper configures it slightly - # differently such that revocation checking isn't turned on by default. - # - # [1]: https://curl.haxx.se/mail/lib-2016-03/0202.html - RUSTUP_USE_HYPER: 1 - CARGO_HTTP_CHECK_REVOKE: false - - matrix: - - TARGET: x86_64-pc-windows-msvc - CHANNEL: 1.32.0 - - TARGET: x86_64-pc-windows-msvc - CHANNEL: stable - - TARGET: x86_64-pc-windows-msvc - CHANNEL: nightly - - TARGET: i686-pc-windows-msvc - CHANNEL: nightly - - TARGET: x86_64-pc-windows-gnu - CHANNEL: nightly - - TARGET: i686-pc-windows-gnu - CHANNEL: nightly - -install: - - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - - rustup-init.exe -y --default-host %TARGET% --default-toolchain %CHANNEL% - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - rustc -V - - cargo -V - -build: false - -test_script: - - set RUSTFLAGS=-D warnings - - cargo test - - cargo test --examples - -branches: - only: - - master diff --git a/getrandom/benches/mod.rs b/getrandom/benches/mod.rs deleted file mode 100644 index 07953f1..0000000 --- a/getrandom/benches/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![feature(test)] -extern crate getrandom; -extern crate test; - -#[bench] -fn bench_64(b: &mut test::Bencher) { - let mut buf = [0u8; 64]; - b.iter(|| { - getrandom::getrandom(&mut buf[..]).unwrap(); - test::black_box(&buf); - }); - b.bytes = buf.len() as u64; -} - -#[bench] -fn bench_65536(b: &mut test::Bencher) { - let mut buf = [0u8; 65536]; - b.iter(|| { - getrandom::getrandom(&mut buf[..]).unwrap(); - test::black_box(&buf); - }); - b.bytes = buf.len() as u64; -} diff --git a/getrandom/build.rs b/getrandom/build.rs deleted file mode 100644 index 1beb4ed..0000000 --- a/getrandom/build.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![deny(warnings)] - -use std::env; - -fn main() { - let target = env::var("TARGET").expect("TARGET was not set"); - if target.contains("-uwp-windows-") { - // for BCryptGenRandom - println!("cargo:rustc-link-lib=bcrypt"); - // to work around unavailability of `target_vendor` on Rust 1.33 - println!("cargo:rustc-cfg=getrandom_uwp"); - } else if target.contains("windows") { - // for RtlGenRandom (aka SystemFunction036) - println!("cargo:rustc-link-lib=advapi32"); - } else if target.contains("apple-ios") { - // for SecRandomCopyBytes and kSecRandomDefault - println!("cargo:rustc-link-lib=framework=Security"); - } -} diff --git a/getrandom/src/bsd_arandom.rs b/getrandom/src/bsd_arandom.rs deleted file mode 100644 index eb564ff..0000000 --- a/getrandom/src/bsd_arandom.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for FreeBSD and NetBSD -use crate::util_libc::sys_fill_exact; -use crate::Error; -use core::ptr; - -fn kern_arnd(buf: &mut [u8]) -> libc::ssize_t { - static MIB: [libc::c_int; 2] = [libc::CTL_KERN, libc::KERN_ARND]; - let mut len = buf.len(); - let ret = unsafe { - libc::sysctl( - MIB.as_ptr(), - MIB.len() as libc::c_uint, - buf.as_mut_ptr() as *mut _, - &mut len, - ptr::null(), - 0, - ) - }; - if ret == -1 { - error!("sysctl kern.arandom: syscall failed"); - -1 - } else { - len as libc::ssize_t - } -} - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - #[cfg(target_os = "freebsd")] - { - use crate::util_libc::Weak; - static GETRANDOM: Weak = unsafe { Weak::new("getrandom\0") }; - type GetRandomFn = - unsafe extern "C" fn(*mut u8, libc::size_t, libc::c_uint) -> libc::ssize_t; - - if let Some(fptr) = GETRANDOM.ptr() { - let func: GetRandomFn = unsafe { core::mem::transmute(fptr) }; - return sys_fill_exact(dest, |buf| unsafe { func(buf.as_mut_ptr(), buf.len(), 0) }); - } - } - sys_fill_exact(dest, kern_arnd) -} diff --git a/getrandom/src/cloudabi.rs b/getrandom/src/cloudabi.rs deleted file mode 100644 index d3d0928..0000000 --- a/getrandom/src/cloudabi.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for CloudABI -use crate::Error; -use core::num::NonZeroU32; - -extern "C" { - fn cloudabi_sys_random_get(buf: *mut u8, buf_len: usize) -> u16; -} - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - let errno = unsafe { cloudabi_sys_random_get(dest.as_mut_ptr(), dest.len()) }; - if let Some(code) = NonZeroU32::new(errno as u32) { - error!("cloudabi_sys_random_get: failed with {}", errno); - Err(Error::from(code)) - } else { - Ok(()) // Zero means success for CloudABI - } -} diff --git a/getrandom/src/dummy.rs b/getrandom/src/dummy.rs deleted file mode 100644 index 0c24ba0..0000000 --- a/getrandom/src/dummy.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A dummy implementation for unsupported targets which always fails -use crate::{error::UNSUPPORTED, Error}; - -pub fn getrandom_inner(_: &mut [u8]) -> Result<(), Error> { - Err(UNSUPPORTED) -} diff --git a/getrandom/src/error.rs b/getrandom/src/error.rs deleted file mode 100644 index b2cb9a8..0000000 --- a/getrandom/src/error.rs +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -use core::fmt; -use core::num::NonZeroU32; - -/// A small and `no_std` compatible error type. -/// -/// The [`Error::raw_os_error()`] will indicate if the error is from the OS, and -/// if so, which error code the OS gave the application. If such an error is -/// encountered, please consult with your system documentation. -/// -/// Internally this type is a NonZeroU32, with certain values reserved for -/// certain purposes, see [`Error::INTERNAL_START`] and [`Error::CUSTOM_START`]. -#[derive(Copy, Clone, Eq, PartialEq)] -pub struct Error(NonZeroU32); - -impl Error { - #[deprecated(since = "0.1.7")] - /// Unknown error. - pub const UNKNOWN: Error = UNSUPPORTED; - #[deprecated(since = "0.1.7")] - /// System entropy source is unavailable. - pub const UNAVAILABLE: Error = UNSUPPORTED; - - /// Codes below this point represent OS Errors (i.e. positive i32 values). - /// Codes at or above this point, but below [`Error::CUSTOM_START`] are - /// reserved for use by the `rand` and `getrandom` crates. - pub const INTERNAL_START: u32 = 1 << 31; - - /// Codes at or above this point can be used by users to define their own - /// custom errors. - pub const CUSTOM_START: u32 = (1 << 31) + (1 << 30); - - /// Extract the raw OS error code (if this error came from the OS) - /// - /// This method is identical to `std::io::Error::raw_os_error()`, except - /// that it works in `no_std` contexts. If this method returns `None`, the - /// error value can still be formatted via the `Display` implementation. - #[inline] - pub fn raw_os_error(self) -> Option { - if self.0.get() < Self::INTERNAL_START { - Some(self.0.get() as i32) - } else { - None - } - } - - /// Extract the bare error code. - /// - /// This code can either come from the underlying OS, or be a custom error. - /// Use [`Error::raw_os_error()`] to disambiguate. - #[inline] - pub fn code(self) -> NonZeroU32 { - self.0 - } -} - -cfg_if! { - if #[cfg(unix)] { - fn os_err_desc(errno: i32, buf: &mut [u8]) -> Option<&str> { - let buf_ptr = buf.as_mut_ptr() as *mut libc::c_char; - if unsafe { libc::strerror_r(errno, buf_ptr, buf.len()) } != 0 { - return None; - } - - // Take up to trailing null byte - let n = buf.len(); - let idx = buf.iter().position(|&b| b == 0).unwrap_or(n); - core::str::from_utf8(&buf[..idx]).ok() - } - } else if #[cfg(target_os = "wasi")] { - fn os_err_desc(errno: i32, _buf: &mut [u8]) -> Option<&str> { - core::num::NonZeroU16::new(errno as u16) - .and_then(wasi::wasi_unstable::error_str) - } - } else { - fn os_err_desc(_errno: i32, _buf: &mut [u8]) -> Option<&str> { - None - } - } -} - -impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut dbg = f.debug_struct("Error"); - if let Some(errno) = self.raw_os_error() { - dbg.field("os_error", &errno); - let mut buf = [0u8; 128]; - if let Some(desc) = os_err_desc(errno, &mut buf) { - dbg.field("description", &desc); - } - } else if let Some(desc) = internal_desc(*self) { - dbg.field("internal_code", &self.0.get()); - dbg.field("description", &desc); - } else { - dbg.field("unknown_code", &self.0.get()); - } - dbg.finish() - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let Some(errno) = self.raw_os_error() { - let mut buf = [0u8; 128]; - match os_err_desc(errno, &mut buf) { - Some(desc) => f.write_str(desc), - None => write!(f, "OS Error: {}", errno), - } - } else if let Some(desc) = internal_desc(*self) { - f.write_str(desc) - } else { - write!(f, "Unknown Error: {}", self.0.get()) - } - } -} - -impl From for Error { - fn from(code: NonZeroU32) -> Self { - Self(code) - } -} - -// TODO: Convert to a function when min_version >= 1.33 -macro_rules! internal_error { - ($n:expr) => { - Error(unsafe { NonZeroU32::new_unchecked(Error::INTERNAL_START + $n as u16 as u32) }) - }; -} - -/// Internal Error constants -pub(crate) const UNSUPPORTED: Error = internal_error!(0); -pub(crate) const ERRNO_NOT_POSITIVE: Error = internal_error!(1); -pub(crate) const UNKNOWN_IO_ERROR: Error = internal_error!(2); -pub(crate) const SEC_RANDOM_FAILED: Error = internal_error!(3); -pub(crate) const RTL_GEN_RANDOM_FAILED: Error = internal_error!(4); -pub(crate) const FAILED_RDRAND: Error = internal_error!(5); -pub(crate) const NO_RDRAND: Error = internal_error!(6); -pub(crate) const BINDGEN_CRYPTO_UNDEF: Error = internal_error!(7); -pub(crate) const BINDGEN_GRV_UNDEF: Error = internal_error!(8); -pub(crate) const STDWEB_NO_RNG: Error = internal_error!(9); -pub(crate) const STDWEB_RNG_FAILED: Error = internal_error!(10); -pub(crate) const RAND_SECURE_FATAL: Error = internal_error!(11); - -fn internal_desc(error: Error) -> Option<&'static str> { - match error { - UNSUPPORTED => Some("getrandom: this target is not supported"), - ERRNO_NOT_POSITIVE => Some("errno: did not return a positive value"), - UNKNOWN_IO_ERROR => Some("Unknown std::io::Error"), - SEC_RANDOM_FAILED => Some("SecRandomCopyBytes: call failed"), - RTL_GEN_RANDOM_FAILED => Some("RtlGenRandom: call failed"), - FAILED_RDRAND => Some("RDRAND: failed multiple times: CPU issue likely"), - NO_RDRAND => Some("RDRAND: instruction not supported"), - BINDGEN_CRYPTO_UNDEF => Some("wasm-bindgen: self.crypto is undefined"), - BINDGEN_GRV_UNDEF => Some("wasm-bindgen: crypto.getRandomValues is undefined"), - STDWEB_NO_RNG => Some("stdweb: no randomness source available"), - STDWEB_RNG_FAILED => Some("stdweb: failed to get randomness"), - RAND_SECURE_FATAL => Some("randSecure: random number generator module is not initialized"), - _ => None, - } -} - -#[cfg(test)] -mod tests { - use super::Error; - use core::mem::size_of; - - #[test] - fn test_size() { - assert_eq!(size_of::(), 4); - assert_eq!(size_of::>(), 4); - } -} diff --git a/getrandom/src/error_impls.rs b/getrandom/src/error_impls.rs deleted file mode 100644 index 007472e..0000000 --- a/getrandom/src/error_impls.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -extern crate std; - -use crate::{error::UNKNOWN_IO_ERROR, Error}; -use core::convert::From; -use core::num::NonZeroU32; -use std::io; - -impl From for Error { - fn from(err: io::Error) -> Self { - if let Some(errno) = err.raw_os_error() { - if let Some(code) = NonZeroU32::new(errno as u32) { - return Error::from(code); - } - } - UNKNOWN_IO_ERROR - } -} - -impl From for io::Error { - fn from(err: Error) -> Self { - match err.raw_os_error() { - Some(errno) => io::Error::from_raw_os_error(errno), - None => io::Error::new(io::ErrorKind::Other, err), - } - } -} - -impl std::error::Error for Error {} diff --git a/getrandom/src/fuchsia.rs b/getrandom/src/fuchsia.rs deleted file mode 100644 index 572ff53..0000000 --- a/getrandom/src/fuchsia.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for Fuchsia Zircon -use crate::Error; - -#[link(name = "zircon")] -extern "C" { - fn zx_cprng_draw(buffer: *mut u8, length: usize); -} - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - unsafe { zx_cprng_draw(dest.as_mut_ptr(), dest.len()) } - Ok(()) -} diff --git a/getrandom/src/ios.rs b/getrandom/src/ios.rs deleted file mode 100644 index 30c008c..0000000 --- a/getrandom/src/ios.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for iOS -use crate::{error::SEC_RANDOM_FAILED, Error}; - -// TODO: Make extern once extern_types feature is stabilized. See: -// https://github.com/rust-lang/rust/issues/43467 -#[repr(C)] -struct SecRandom([u8; 0]); - -#[link(name = "Security", kind = "framework")] -extern "C" { - static kSecRandomDefault: *const SecRandom; - - fn SecRandomCopyBytes(rnd: *const SecRandom, count: usize, bytes: *mut u8) -> i32; -} - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - let ret = unsafe { SecRandomCopyBytes(kSecRandomDefault, dest.len(), dest.as_mut_ptr()) }; - if ret == -1 { - Err(SEC_RANDOM_FAILED) - } else { - Ok(()) - } -} diff --git a/getrandom/src/lib.rs b/getrandom/src/lib.rs deleted file mode 100644 index c305406..0000000 --- a/getrandom/src/lib.rs +++ /dev/null @@ -1,282 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Interface to the random number generator of the operating system. -//! -//! # Platform sources -//! -//! | OS | interface -//! |------------------|--------------------------------------------------------- -//! | Linux, Android | [`getrandom`][1] system call if available, otherwise [`/dev/urandom`][2] after successfully polling `/dev/random` -//! | Windows | [`RtlGenRandom`][3] -//! | macOS | [`getentropy()`][19] if available, otherwise [`/dev/random`][20] (identical to `/dev/urandom`) -//! | iOS | [`SecRandomCopyBytes`][4] -//! | FreeBSD | [`getrandom()`][21] if available, otherwise [`kern.arandom`][5] -//! | OpenBSD | [`getentropy`][6] -//! | NetBSD | [`kern.arandom`][7] -//! | Dragonfly BSD | [`/dev/random`][8] -//! | Solaris, illumos | [`getrandom`][9] system call if available, otherwise [`/dev/random`][10] -//! | Fuchsia OS | [`cprng_draw`][11] -//! | Redox | [`rand:`][12] -//! | CloudABI | [`cloudabi_sys_random_get`][13] -//! | Haiku | `/dev/random` (identical to `/dev/urandom`) -//! | L4RE, SGX, UEFI | [RDRAND][18] -//! | Hermit | [RDRAND][18] as [`sys_rand`][22] is currently broken. -//! | VxWorks | `randABytes` after checking entropy pool initialization with `randSecure` -//! | Web browsers | [`Crypto.getRandomValues`][14] (see [Support for WebAssembly and asm.js][16]) -//! | Node.js | [`crypto.randomBytes`][15] (see [Support for WebAssembly and asm.js][16]) -//! | WASI | [`__wasi_random_get`][17] -//! -//! Getrandom doesn't have a blanket implementation for all Unix-like operating -//! systems that reads from `/dev/urandom`. This ensures all supported operating -//! systems are using the recommended interface and respect maximum buffer -//! sizes. -//! -//! ## Unsupported targets -//! -//! By default, compiling `getrandom` for an unsupported target will result in -//! a compilation error. If you want to build an application which uses `getrandom` -//! for such target, you can either: -//! - Use [`[replace]`][replace] or [`[patch]`][patch] section in your `Cargo.toml` -//! to switch to a custom implementation with a support of your target. -//! - Enable the `dummy` feature to have getrandom use an implementation that always -//! fails at run-time on unsupported targets. -//! -//! [replace]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-replace-section -//! [patch]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section -//! -//! ## Support for WebAssembly and asm.js -//! -//! Getrandom supports all of Rust's current `wasm32` targets, and it works with -//! both Node.js and web browsers. The three Emscripten targets -//! `asmjs-unknown-emscripten`, `wasm32-unknown-emscripten`, and -//! `wasm32-experimental-emscripten` use Emscripten's `/dev/random` emulation. -//! The WASI target `wasm32-wasi` uses the [`__wasi_random_get`][17] function -//! defined by the WASI standard. -//! -//! Getrandom also supports `wasm32-unknown-unknown` by directly calling -//! JavaScript methods. Rust currently has two ways to do this: [bindgen] and -//! [stdweb]. Getrandom supports using either one by enabling the -//! `wasm-bindgen` or `stdweb` crate features. Note that if both features are -//! enabled, `wasm-bindgen` will be used. If neither feature is enabled, calls -//! to `getrandom` will always fail at runtime. -//! -//! [bindgen]: https://github.com/rust-lang/rust-bindgen -//! [stdweb]: https://github.com/koute/stdweb -//! -//! ## Early boot -//! -//! It is possible that early in the boot process the OS hasn't had enough time -//! yet to collect entropy to securely seed its RNG, especially on virtual -//! machines. -//! -//! Some operating systems always block the thread until the RNG is securely -//! seeded. This can take anywhere from a few seconds to more than a minute. -//! Others make a best effort to use a seed from before the shutdown and don't -//! document much. -//! -//! A few, Linux, NetBSD and Solaris, offer a choice between blocking and -//! getting an error; in these cases we always choose to block. -//! -//! On Linux (when the `getrandom` system call is not available) and on NetBSD -//! reading from `/dev/urandom` never blocks, even when the OS hasn't collected -//! enough entropy yet. To avoid returning low-entropy bytes, we first read from -//! `/dev/random` and only switch to `/dev/urandom` once this has succeeded. -//! -//! # Error handling -//! -//! We always choose failure over returning insecure "random" bytes. In general, -//! on supported platforms, failure is highly unlikely, though not impossible. -//! If an error does occur, then it is likely that it will occur on every call to -//! `getrandom`, hence after the first successful call one can be reasonably -//! confident that no errors will occur. -//! -//! On unsupported platforms, `getrandom` always fails. See the [`Error`] type -//! for more information on what data is returned on failure. -//! -//! [1]: http://man7.org/linux/man-pages/man2/getrandom.2.html -//! [2]: http://man7.org/linux/man-pages/man4/urandom.4.html -//! [3]: https://docs.microsoft.com/en-us/windows/desktop/api/ntsecapi/nf-ntsecapi-rtlgenrandom -//! [4]: https://developer.apple.com/documentation/security/1399291-secrandomcopybytes?language=objc -//! [5]: https://www.freebsd.org/cgi/man.cgi?query=random&sektion=4 -//! [6]: https://man.openbsd.org/getentropy.2 -//! [7]: https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-8.0 -//! [8]: https://leaf.dragonflybsd.org/cgi/web-man?command=random§ion=4 -//! [9]: https://docs.oracle.com/cd/E88353_01/html/E37841/getrandom-2.html -//! [10]: https://docs.oracle.com/cd/E86824_01/html/E54777/random-7d.html -//! [11]: https://fuchsia.dev/fuchsia-src/zircon/syscalls/cprng_draw -//! [12]: https://github.com/redox-os/randd/blob/master/src/main.rs -//! [13]: https://github.com/nuxinl/cloudabi#random_get -//! [14]: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues -//! [15]: https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback -//! [16]: #support-for-webassembly-and-asmjs -//! [17]: https://github.com/WebAssembly/WASI/blob/master/design/WASI-core.md#__wasi_random_get -//! [18]: https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide -//! [19]: https://www.unix.com/man-page/mojave/2/getentropy/ -//! [20]: https://www.unix.com/man-page/mojave/4/random/ -//! [21]: https://www.freebsd.org/cgi/man.cgi?query=getrandom&manpath=FreeBSD+12.0-stable -//! [22]: https://github.com/hermitcore/libhermit-rs/blob/09c38b0371cee6f56a541400ba453e319e43db53/src/syscalls/random.rs#L21 - -#![doc( - html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/" -)] -#![no_std] -#![cfg_attr(feature = "stdweb", recursion_limit = "128")] -#![warn(rust_2018_idioms, unused_lifetimes, missing_docs)] - -#[macro_use] -extern crate cfg_if; - -cfg_if! { - if #[cfg(feature = "log")] { - #[allow(unused)] - #[macro_use] - extern crate log; - } else { - #[allow(unused)] - macro_rules! error { - ($($x:tt)*) => {}; - } - #[allow(unused)] - macro_rules! warn { - ($($x:tt)*) => {}; - } - #[allow(unused)] - macro_rules! info { - ($($x:tt)*) => {}; - } - } -} - -mod error; -pub use crate::error::Error; - -#[allow(dead_code)] -mod util; - -#[cfg(target_os = "vxworks")] -#[allow(dead_code)] -mod util_libc; - -cfg_if! { - // Unlike the other Unix, Fuchsia and iOS don't use the libc to make any calls. - if #[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "emscripten", - target_os = "freebsd", target_os = "haiku", target_os = "illumos", - target_os = "linux", target_os = "macos", target_os = "netbsd", - target_os = "openbsd", target_os = "redox", target_os = "solaris"))] { - #[allow(dead_code)] - mod util_libc; - // Keep std-only trait definitions for backwards compatibility - mod error_impls; - } else if #[cfg(feature = "std")] { - mod error_impls; - } -} - -// These targets read from a file as a fallback method. -#[cfg(any( - target_os = "android", - target_os = "linux", - target_os = "macos", - target_os = "solaris", - target_os = "illumos", -))] -mod use_file; - -// System-specific implementations. -// -// These should all provide getrandom_inner with the same signature as getrandom. -cfg_if! { - if #[cfg(target_os = "android")] { - #[path = "linux_android.rs"] mod imp; - } else if #[cfg(target_os = "cloudabi")] { - #[path = "cloudabi.rs"] mod imp; - } else if #[cfg(target_os = "dragonfly")] { - #[path = "use_file.rs"] mod imp; - } else if #[cfg(target_os = "emscripten")] { - #[path = "use_file.rs"] mod imp; - } else if #[cfg(target_os = "freebsd")] { - #[path = "bsd_arandom.rs"] mod imp; - } else if #[cfg(target_os = "fuchsia")] { - #[path = "fuchsia.rs"] mod imp; - } else if #[cfg(target_os = "haiku")] { - #[path = "use_file.rs"] mod imp; - } else if #[cfg(target_os = "illumos")] { - #[path = "solaris_illumos.rs"] mod imp; - } else if #[cfg(target_os = "ios")] { - #[path = "ios.rs"] mod imp; - } else if #[cfg(target_os = "linux")] { - #[path = "linux_android.rs"] mod imp; - } else if #[cfg(target_os = "macos")] { - #[path = "macos.rs"] mod imp; - } else if #[cfg(target_os = "netbsd")] { - #[path = "bsd_arandom.rs"] mod imp; - } else if #[cfg(target_os = "openbsd")] { - #[path = "openbsd.rs"] mod imp; - } else if #[cfg(target_os = "redox")] { - #[path = "use_file.rs"] mod imp; - } else if #[cfg(target_os = "solaris")] { - #[path = "solaris_illumos.rs"] mod imp; - } else if #[cfg(target_os = "wasi")] { - #[path = "wasi.rs"] mod imp; - } else if #[cfg(target_os = "vxworks")] { - #[path = "vxworks.rs"] mod imp; - } else if #[cfg(all(windows, getrandom_uwp))] { - #[path = "windows_uwp.rs"] mod imp; - } else if #[cfg(windows)] { - #[path = "windows.rs"] mod imp; - } else if #[cfg(all(target_arch = "x86_64", any( - target_os = "hermit", - target_os = "l4re", - target_os = "uefi", - target_env = "sgx", - )))] { - #[path = "rdrand.rs"] mod imp; - } else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { - cfg_if! { - if #[cfg(feature = "wasm-bindgen")] { - #[path = "wasm32_bindgen.rs"] mod imp; - } else if #[cfg(feature = "stdweb")] { - #[path = "wasm32_stdweb.rs"] mod imp; - } else { - // Always have an implementation for wasm32-unknown-unknown. - // See https://github.com/rust-random/getrandom/issues/87 - #[path = "dummy.rs"] mod imp; - } - } - } else if #[cfg(feature = "dummy")] { - #[path = "dummy.rs"] mod imp; - } else { - compile_error!("\ - target is not supported, for more information see: \ - https://docs.rs/getrandom/#unsupported-targets\ - "); - } -} - -/// Fill `dest` with random bytes from the system's preferred random number -/// source. -/// -/// This function returns an error on any failure, including partial reads. We -/// make no guarantees regarding the contents of `dest` on error. If `dest` is -/// empty, `getrandom` immediately returns success, making no calls to the -/// underlying operating system. -/// -/// Blocking is possible, at least during early boot; see module documentation. -/// -/// In general, `getrandom` will be fast enough for interactive usage, though -/// significantly slower than a user-space CSPRNG; for the latter consider -/// [`rand::thread_rng`](https://docs.rs/rand/*/rand/fn.thread_rng.html). -pub fn getrandom(dest: &mut [u8]) -> Result<(), error::Error> { - if dest.is_empty() { - return Ok(()); - } - imp::getrandom_inner(dest) -} diff --git a/getrandom/src/linux_android.rs b/getrandom/src/linux_android.rs deleted file mode 100644 index a29feb5..0000000 --- a/getrandom/src/linux_android.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for Linux / Android -use crate::util::LazyBool; -use crate::util_libc::{last_os_error, sys_fill_exact}; -use crate::{use_file, Error}; - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - static HAS_GETRANDOM: LazyBool = LazyBool::new(); - if HAS_GETRANDOM.unsync_init(is_getrandom_available) { - sys_fill_exact(dest, |buf| unsafe { - getrandom(buf.as_mut_ptr() as *mut libc::c_void, buf.len(), 0) - }) - } else { - use_file::getrandom_inner(dest) - } -} - -fn is_getrandom_available() -> bool { - let res = unsafe { getrandom(core::ptr::null_mut(), 0, libc::GRND_NONBLOCK) }; - if res < 0 { - match last_os_error().raw_os_error() { - Some(libc::ENOSYS) => false, // No kernel support - Some(libc::EPERM) => false, // Blocked by seccomp - _ => true, - } - } else { - true - } -} - -unsafe fn getrandom( - buf: *mut libc::c_void, - buflen: libc::size_t, - flags: libc::c_uint, -) -> libc::ssize_t { - libc::syscall(libc::SYS_getrandom, buf, buflen, flags) as libc::ssize_t -} diff --git a/getrandom/src/macos.rs b/getrandom/src/macos.rs deleted file mode 100644 index c3bc533..0000000 --- a/getrandom/src/macos.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for macOS -use crate::util_libc::{last_os_error, Weak}; -use crate::{use_file, Error}; -use core::mem; - -type GetEntropyFn = unsafe extern "C" fn(*mut u8, libc::size_t) -> libc::c_int; - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - static GETENTROPY: Weak = unsafe { Weak::new("getentropy\0") }; - if let Some(fptr) = GETENTROPY.ptr() { - let func: GetEntropyFn = unsafe { mem::transmute(fptr) }; - for chunk in dest.chunks_mut(256) { - let ret = unsafe { func(chunk.as_mut_ptr(), chunk.len()) }; - if ret != 0 { - let err = last_os_error(); - error!("getentropy syscall failed"); - return Err(err); - } - } - Ok(()) - } else { - // We fallback to reading from /dev/random instead of SecRandomCopyBytes - // to avoid high startup costs and linking the Security framework. - use_file::getrandom_inner(dest) - } -} diff --git a/getrandom/src/openbsd.rs b/getrandom/src/openbsd.rs deleted file mode 100644 index e1ac179..0000000 --- a/getrandom/src/openbsd.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for OpenBSD -use crate::util_libc::last_os_error; -use crate::Error; - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - for chunk in dest.chunks_mut(256) { - let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) }; - if ret == -1 { - let err = last_os_error(); - error!("libc::getentropy call failed"); - return Err(err); - } - } - Ok(()) -} diff --git a/getrandom/src/rdrand.rs b/getrandom/src/rdrand.rs deleted file mode 100644 index e441682..0000000 --- a/getrandom/src/rdrand.rs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for SGX using RDRAND instruction -use crate::error::{FAILED_RDRAND, NO_RDRAND}; -#[cfg(not(target_feature = "rdrand"))] -use crate::util::LazyBool; -use crate::Error; -use core::arch::x86_64::_rdrand64_step; -use core::mem; - -// Recommendation from "Intel® Digital Random Number Generator (DRNG) Software -// Implementation Guide" - Section 5.2.1 and "Intel® 64 and IA-32 Architectures -// Software Developer’s Manual" - Volume 1 - Section 7.3.17.1. -const RETRY_LIMIT: usize = 10; -const WORD_SIZE: usize = mem::size_of::(); - -#[target_feature(enable = "rdrand")] -unsafe fn rdrand() -> Result<[u8; WORD_SIZE], Error> { - for _ in 0..RETRY_LIMIT { - let mut el = mem::zeroed(); - if _rdrand64_step(&mut el) == 1 { - // AMD CPUs from families 14h to 16h (pre Ryzen) sometimes fail to - // set CF on bogus random data, so we check these values explicitly. - // See https://github.com/systemd/systemd/issues/11810#issuecomment-489727505 - // We perform this check regardless of target to guard against - // any implementation that incorrectly fails to set CF. - if el != 0 && el != !0 { - return Ok(el.to_ne_bytes()); - } - error!("RDRAND returned {:X}, CPU RNG may be broken", el); - // Keep looping in case this was a false positive. - } - } - Err(FAILED_RDRAND) -} - -// "rdrand" target feature requires "+rdrnd" flag, see https://github.com/rust-lang/rust/issues/49653. -#[cfg(all(target_env = "sgx", not(target_feature = "rdrand")))] -compile_error!( - "SGX targets require 'rdrand' target feature. Enable by using -C target-feature=+rdrnd." -); - -#[cfg(target_feature = "rdrand")] -fn is_rdrand_supported() -> bool { - true -} - -// TODO use is_x86_feature_detected!("rdrand") when that works in core. See: -// https://github.com/rust-lang-nursery/stdsimd/issues/464 -#[cfg(not(target_feature = "rdrand"))] -fn is_rdrand_supported() -> bool { - use core::arch::x86_64::__cpuid; - // SAFETY: All x86_64 CPUs support CPUID leaf 1 - const FLAG: u32 = 1 << 30; - static HAS_RDRAND: LazyBool = LazyBool::new(); - HAS_RDRAND.unsync_init(|| unsafe { (__cpuid(1).ecx & FLAG) != 0 }) -} - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - if !is_rdrand_supported() { - return Err(NO_RDRAND); - } - - // SAFETY: After this point, rdrand is supported, so calling the rdrand - // functions is not undefined behavior. - unsafe { rdrand_exact(dest) } -} - -#[target_feature(enable = "rdrand")] -unsafe fn rdrand_exact(dest: &mut [u8]) -> Result<(), Error> { - // We use chunks_exact_mut instead of chunks_mut as it allows almost all - // calls to memcpy to be elided by the compiler. - let mut chunks = dest.chunks_exact_mut(WORD_SIZE); - for chunk in chunks.by_ref() { - chunk.copy_from_slice(&rdrand()?); - } - - let tail = chunks.into_remainder(); - let n = tail.len(); - if n > 0 { - tail.copy_from_slice(&rdrand()?[..n]); - } - Ok(()) -} diff --git a/getrandom/src/solaris_illumos.rs b/getrandom/src/solaris_illumos.rs deleted file mode 100644 index 9473123..0000000 --- a/getrandom/src/solaris_illumos.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for the Solaris family -//! -//! Read from `/dev/random`, with chunks of limited size (256 bytes). -//! `/dev/random` uses the Hash_DRBG with SHA512 algorithm from NIST SP 800-90A. -//! `/dev/urandom` uses the FIPS 186-2 algorithm, which is considered less -//! secure. We choose to read from `/dev/random`. -//! -//! Since Solaris 11.3 and mid-2015 illumos, the `getrandom` syscall is available. -//! To make sure we can compile on both Solaris and its derivatives, as well as -//! function, we check for the existence of getrandom(2) in libc by calling -//! libc::dlsym. -use crate::util_libc::{sys_fill_exact, Weak}; -use crate::{use_file, Error}; -use core::mem; - -#[cfg(target_os = "illumos")] -type GetRandomFn = unsafe extern "C" fn(*mut u8, libc::size_t, libc::c_uint) -> libc::ssize_t; -#[cfg(target_os = "solaris")] -type GetRandomFn = unsafe extern "C" fn(*mut u8, libc::size_t, libc::c_uint) -> libc::c_int; - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - static GETRANDOM: Weak = unsafe { Weak::new("getrandom\0") }; - if let Some(fptr) = GETRANDOM.ptr() { - let func: GetRandomFn = unsafe { mem::transmute(fptr) }; - // 256 bytes is the lowest common denominator across all the Solaris - // derived platforms for atomically obtaining random data. - for chunk in dest.chunks_mut(256) { - sys_fill_exact(chunk, |buf| unsafe { - func(buf.as_mut_ptr(), buf.len(), 0) as libc::ssize_t - })? - } - Ok(()) - } else { - use_file::getrandom_inner(dest) - } -} diff --git a/getrandom/src/use_file.rs b/getrandom/src/use_file.rs deleted file mode 100644 index d3adaf2..0000000 --- a/getrandom/src/use_file.rs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementations that just need to read from a file -use crate::util_libc::{last_os_error, open_readonly, sys_fill_exact, LazyFd}; -use crate::Error; - -#[cfg(target_os = "redox")] -const FILE_PATH: &str = "rand:\0"; -#[cfg(any( - target_os = "dragonfly", - target_os = "emscripten", - target_os = "haiku", - target_os = "macos", - target_os = "solaris", - target_os = "illumos" -))] -const FILE_PATH: &str = "/dev/random\0"; - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - static FD: LazyFd = LazyFd::new(); - let fd = FD.init(init_file).ok_or_else(last_os_error)?; - let read = |buf: &mut [u8]| unsafe { libc::read(fd, buf.as_mut_ptr() as *mut _, buf.len()) }; - - if cfg!(target_os = "emscripten") { - // `Crypto.getRandomValues` documents `dest` should be at most 65536 bytes. - for chunk in dest.chunks_mut(65536) { - sys_fill_exact(chunk, read)?; - } - } else { - sys_fill_exact(dest, read)?; - } - Ok(()) -} - -cfg_if! { - if #[cfg(any(target_os = "android", target_os = "linux"))] { - fn init_file() -> Option { - // Poll /dev/random to make sure it is ok to read from /dev/urandom. - let mut pfd = libc::pollfd { - fd: unsafe { open_readonly("/dev/random\0")? }, - events: libc::POLLIN, - revents: 0, - }; - - let ret = loop { - // A negative timeout means an infinite timeout. - let res = unsafe { libc::poll(&mut pfd, 1, -1) }; - if res == 1 { - break unsafe { open_readonly("/dev/urandom\0") }; - } else if res < 0 { - let e = last_os_error().raw_os_error(); - if e == Some(libc::EINTR) || e == Some(libc::EAGAIN) { - continue; - } - } - // We either hard failed, or poll() returned the wrong pfd. - break None; - }; - unsafe { libc::close(pfd.fd) }; - ret - } - } else { - fn init_file() -> Option { - unsafe { open_readonly(FILE_PATH) } - } - } -} diff --git a/getrandom/src/util.rs b/getrandom/src/util.rs deleted file mode 100644 index e0e9307..0000000 --- a/getrandom/src/util.rs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use core::sync::atomic::{AtomicUsize, Ordering::Relaxed}; - -// This structure represents a lazily initialized static usize value. Useful -// when it is preferable to just rerun initialization instead of locking. -// Both unsync_init and sync_init will invoke an init() function until it -// succeeds, then return the cached value for future calls. -// -// Both methods support init() "failing". If the init() method returns UNINIT, -// that value will be returned as normal, but will not be cached. -// -// Users should only depend on the _value_ returned by init() functions. -// Specifically, for the following init() function: -// fn init() -> usize { -// a(); -// let v = b(); -// c(); -// v -// } -// the effects of c() or writes to shared memory will not necessarily be -// observed and additional synchronization methods with be needed. -pub struct LazyUsize(AtomicUsize); - -impl LazyUsize { - pub const fn new() -> Self { - Self(AtomicUsize::new(Self::UNINIT)) - } - - // The initialization is not completed. - pub const UNINIT: usize = usize::max_value(); - // The initialization is currently running. - pub const ACTIVE: usize = usize::max_value() - 1; - - // Runs the init() function at least once, returning the value of some run - // of init(). Multiple callers can run their init() functions in parallel. - // init() should always return the same value, if it succeeds. - pub fn unsync_init(&self, init: impl FnOnce() -> usize) -> usize { - // Relaxed ordering is fine, as we only have a single atomic variable. - let mut val = self.0.load(Relaxed); - if val == Self::UNINIT { - val = init(); - self.0.store(val, Relaxed); - } - val - } - - // Synchronously runs the init() function. Only one caller will have their - // init() function running at a time, and exactly one successful call will - // be run. init() returning UNINIT or ACTIVE will be considered a failure, - // and future calls to sync_init will rerun their init() function. - pub fn sync_init(&self, init: impl FnOnce() -> usize, mut wait: impl FnMut()) -> usize { - // Common and fast path with no contention. Don't wast time on CAS. - match self.0.load(Relaxed) { - Self::UNINIT | Self::ACTIVE => {} - val => return val, - } - // Relaxed ordering is fine, as we only have a single atomic variable. - loop { - match self.0.compare_and_swap(Self::UNINIT, Self::ACTIVE, Relaxed) { - Self::UNINIT => { - let val = init(); - self.0.store( - match val { - Self::UNINIT | Self::ACTIVE => Self::UNINIT, - val => val, - }, - Relaxed, - ); - return val; - } - Self::ACTIVE => wait(), - val => return val, - } - } - } -} - -// Identical to LazyUsize except with bool instead of usize. -pub struct LazyBool(LazyUsize); - -impl LazyBool { - pub const fn new() -> Self { - Self(LazyUsize::new()) - } - - pub fn unsync_init(&self, init: impl FnOnce() -> bool) -> bool { - self.0.unsync_init(|| init() as usize) != 0 - } -} diff --git a/getrandom/src/util_libc.rs b/getrandom/src/util_libc.rs deleted file mode 100644 index 5a05170..0000000 --- a/getrandom/src/util_libc.rs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -use crate::error::ERRNO_NOT_POSITIVE; -use crate::util::LazyUsize; -use crate::Error; -use core::num::NonZeroU32; -use core::ptr::NonNull; - -cfg_if! { - if #[cfg(any(target_os = "netbsd", target_os = "openbsd", target_os = "android"))] { - use libc::__errno as errno_location; - } else if #[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "redox"))] { - use libc::__errno_location as errno_location; - } else if #[cfg(any(target_os = "solaris", target_os = "illumos"))] { - use libc::___errno as errno_location; - } else if #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly"))] { - use libc::__error as errno_location; - } else if #[cfg(target_os = "haiku")] { - use libc::_errnop as errno_location; - } -} - -pub fn last_os_error() -> Error { - #[cfg(not(target_os = "vxworks"))] - let errno = unsafe { *errno_location() }; - #[cfg(target_os = "vxworks")] - let errno = unsafe { libc::errnoGet() }; - if errno > 0 { - Error::from(NonZeroU32::new(errno as u32).unwrap()) - } else { - ERRNO_NOT_POSITIVE - } -} - -// Fill a buffer by repeatedly invoking a system call. The `sys_fill` function: -// - should return -1 and set errno on failure -// - should return the number of bytes written on success -pub fn sys_fill_exact( - mut buf: &mut [u8], - sys_fill: impl Fn(&mut [u8]) -> libc::ssize_t, -) -> Result<(), Error> { - while !buf.is_empty() { - let res = sys_fill(buf); - if res < 0 { - let err = last_os_error(); - // We should try again if the call was interrupted. - if err.raw_os_error() != Some(libc::EINTR) { - return Err(err); - } - } else { - // We don't check for EOF (ret = 0) as the data we are reading - // should be an infinite stream of random bytes. - buf = &mut buf[(res as usize)..]; - } - } - Ok(()) -} - -// A "weak" binding to a C function that may or may not be present at runtime. -// Used for supporting newer OS features while still building on older systems. -// F must be a function pointer of type `unsafe extern "C" fn`. Based off of the -// weak! macro in libstd. -pub struct Weak { - name: &'static str, - addr: LazyUsize, -} - -impl Weak { - // Construct a binding to a C function with a given name. This function is - // unsafe because `name` _must_ be null terminated. - pub const unsafe fn new(name: &'static str) -> Self { - Self { - name, - addr: LazyUsize::new(), - } - } - - // Return a function pointer if present at runtime. Otherwise, return null. - pub fn ptr(&self) -> Option> { - let addr = self.addr.unsync_init(|| unsafe { - libc::dlsym(libc::RTLD_DEFAULT, self.name.as_ptr() as *const _) as usize - }); - NonNull::new(addr as *mut _) - } -} - -pub struct LazyFd(LazyUsize); - -impl LazyFd { - pub const fn new() -> Self { - Self(LazyUsize::new()) - } - - // If init() returns Some(x), x should be nonnegative. - pub fn init(&self, init: impl FnOnce() -> Option) -> Option { - let fd = self.0.sync_init( - || match init() { - // OK as val >= 0 and val <= c_int::MAX < usize::MAX - Some(val) => val as usize, - None => LazyUsize::UNINIT, - }, - || unsafe { - // We are usually waiting on an open(2) syscall to complete, - // which typically takes < 10us if the file is a device. - // However, we might end up waiting much longer if the entropy - // pool isn't initialized, but even in that case, this loop will - // consume a negligible amount of CPU on most platforms. - libc::usleep(10); - }, - ); - match fd { - LazyUsize::UNINIT => None, - val => Some(val as libc::c_int), - } - } -} - -cfg_if! { - if #[cfg(any(target_os = "linux", target_os = "emscripten"))] { - use libc::open64 as open; - } else { - use libc::open; - } -} - -// SAFETY: path must be null terminated, FD must be manually closed. -pub unsafe fn open_readonly(path: &str) -> Option { - debug_assert!(path.as_bytes().last() == Some(&0)); - let fd = open(path.as_ptr() as *mut _, libc::O_RDONLY | libc::O_CLOEXEC); - if fd < 0 { - return None; - } - // O_CLOEXEC works on all Unix targets except for older Linux kernels (pre - // 2.6.23), so we also use an ioctl to make sure FD_CLOEXEC is set. - #[cfg(target_os = "linux")] - libc::ioctl(fd, libc::FIOCLEX); - Some(fd) -} diff --git a/getrandom/src/vxworks.rs b/getrandom/src/vxworks.rs deleted file mode 100644 index a2fe52a..0000000 --- a/getrandom/src/vxworks.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for VxWorks -use crate::error::{Error, RAND_SECURE_FATAL}; -use crate::util_libc::last_os_error; -use core::sync::atomic::{AtomicBool, Ordering::Relaxed}; - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - static RNG_INIT: AtomicBool = AtomicBool::new(false); - while !RNG_INIT.load(Relaxed) { - let ret = unsafe { libc::randSecure() }; - if ret < 0 { - return Err(RAND_SECURE_FATAL); - } else if ret > 0 { - RNG_INIT.store(true, Relaxed); - break; - } - unsafe { libc::usleep(10) }; - } - - // Prevent overflow of i32 - for chunk in dest.chunks_mut(i32::max_value() as usize) { - let ret = unsafe { libc::randABytes(chunk.as_mut_ptr(), chunk.len() as i32) }; - if ret != 0 { - return Err(last_os_error()); - } - } - Ok(()) -} diff --git a/getrandom/src/wasi.rs b/getrandom/src/wasi.rs deleted file mode 100644 index 713c1ab..0000000 --- a/getrandom/src/wasi.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for WASI -use crate::Error; -use core::num; -use wasi::wasi_unstable::random_get; - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - random_get(dest).map_err(|e: num::NonZeroU16| { - // convert wasi's NonZeroU16 error into getrandom's NonZeroU32 error - num::NonZeroU32::new(e.get() as u32).unwrap().into() - }) -} diff --git a/getrandom/src/wasm32_bindgen.rs b/getrandom/src/wasm32_bindgen.rs deleted file mode 100644 index 86839a0..0000000 --- a/getrandom/src/wasm32_bindgen.rs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for WASM via wasm-bindgen -extern crate std; - -use core::cell::RefCell; -use core::mem; -use std::thread_local; - -use wasm_bindgen::prelude::*; - -use crate::error::{BINDGEN_CRYPTO_UNDEF, BINDGEN_GRV_UNDEF}; -use crate::Error; - -#[derive(Clone, Debug)] -enum RngSource { - Node(NodeCrypto), - Browser(BrowserCrypto), -} - -// JsValues are always per-thread, so we initialize RngSource for each thread. -// See: https://github.com/rustwasm/wasm-bindgen/pull/955 -thread_local!( - static RNG_SOURCE: RefCell> = RefCell::new(None); -); - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - assert_eq!(mem::size_of::(), 4); - - RNG_SOURCE.with(|f| { - let mut source = f.borrow_mut(); - if source.is_none() { - *source = Some(getrandom_init()?); - } - - match source.as_ref().unwrap() { - RngSource::Node(n) => n.random_fill_sync(dest), - RngSource::Browser(n) => { - // see https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues - // - // where it says: - // - // > A QuotaExceededError DOMException is thrown if the - // > requested length is greater than 65536 bytes. - for chunk in dest.chunks_mut(65536) { - n.get_random_values(chunk) - } - } - }; - Ok(()) - }) -} - -fn getrandom_init() -> Result { - if let Ok(self_) = Global::get_self() { - // If `self` is defined then we're in a browser somehow (main window - // or web worker). Here we want to try to use - // `crypto.getRandomValues`, but if `crypto` isn't defined we assume - // we're in an older web browser and the OS RNG isn't available. - - let crypto = self_.crypto(); - if crypto.is_undefined() { - return Err(BINDGEN_CRYPTO_UNDEF); - } - - // Test if `crypto.getRandomValues` is undefined as well - let crypto: BrowserCrypto = crypto.into(); - if crypto.get_random_values_fn().is_undefined() { - return Err(BINDGEN_GRV_UNDEF); - } - - return Ok(RngSource::Browser(crypto)); - } - - return Ok(RngSource::Node(node_require("crypto"))); -} - -#[wasm_bindgen] -extern "C" { - type Global; - #[wasm_bindgen(getter, catch, static_method_of = Global, js_class = self, js_name = self)] - fn get_self() -> Result; - - type Self_; - #[wasm_bindgen(method, getter, structural)] - fn crypto(me: &Self_) -> JsValue; - - #[derive(Clone, Debug)] - type BrowserCrypto; - - // TODO: these `structural` annotations here ideally wouldn't be here to - // avoid a JS shim, but for now with feature detection they're - // unavoidable. - #[wasm_bindgen(method, js_name = getRandomValues, structural, getter)] - fn get_random_values_fn(me: &BrowserCrypto) -> JsValue; - #[wasm_bindgen(method, js_name = getRandomValues, structural)] - fn get_random_values(me: &BrowserCrypto, buf: &mut [u8]); - - #[wasm_bindgen(js_name = require)] - fn node_require(s: &str) -> NodeCrypto; - - #[derive(Clone, Debug)] - type NodeCrypto; - - #[wasm_bindgen(method, js_name = randomFillSync, structural)] - fn random_fill_sync(me: &NodeCrypto, buf: &mut [u8]); -} diff --git a/getrandom/src/wasm32_stdweb.rs b/getrandom/src/wasm32_stdweb.rs deleted file mode 100644 index 6e5e78a..0000000 --- a/getrandom/src/wasm32_stdweb.rs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for WASM via stdweb -extern crate std; - -use core::mem; - -use stdweb::js; -use stdweb::unstable::TryInto; -use stdweb::web::error::Error as WebError; - -use crate::error::{STDWEB_NO_RNG, STDWEB_RNG_FAILED}; -use crate::Error; -use std::sync::Once; - -#[derive(Clone, Copy, Debug)] -enum RngSource { - Browser, - Node, -} - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - assert_eq!(mem::size_of::(), 4); - static ONCE: Once = Once::new(); - static mut RNG_SOURCE: Result = Ok(RngSource::Node); - - // SAFETY: RNG_SOURCE is only written once, before being read. - ONCE.call_once(|| unsafe { - RNG_SOURCE = getrandom_init(); - }); - getrandom_fill(unsafe { RNG_SOURCE }?, dest) -} - -fn getrandom_init() -> Result { - let result = js! { - try { - if ( - typeof self === "object" && - typeof self.crypto === "object" && - typeof self.crypto.getRandomValues === "function" - ) { - return { success: true, ty: 1 }; - } - - if (typeof require("crypto").randomBytes === "function") { - return { success: true, ty: 2 }; - } - - return { success: false, error: new Error("not supported") }; - } catch(err) { - return { success: false, error: err }; - } - }; - - if js! { return @{ result.as_ref() }.success } == true { - let ty = js! { return @{ result }.ty }; - - if ty == 1 { - Ok(RngSource::Browser) - } else if ty == 2 { - Ok(RngSource::Node) - } else { - unreachable!() - } - } else { - let _err: WebError = js! { return @{ result }.error }.try_into().unwrap(); - error!("getrandom unavailable: {}", _err); - Err(STDWEB_NO_RNG) - } -} - -fn getrandom_fill(source: RngSource, dest: &mut [u8]) -> Result<(), Error> { - for chunk in dest.chunks_mut(65536) { - let len = chunk.len() as u32; - let ptr = chunk.as_mut_ptr() as i32; - - let result = match source { - RngSource::Browser => js! { - try { - let array = new Uint8Array(@{ len }); - self.crypto.getRandomValues(array); - HEAPU8.set(array, @{ ptr }); - - return { success: true }; - } catch(err) { - return { success: false, error: err }; - } - }, - RngSource::Node => js! { - try { - let bytes = require("crypto").randomBytes(@{ len }); - HEAPU8.set(new Uint8Array(bytes), @{ ptr }); - - return { success: true }; - } catch(err) { - return { success: false, error: err }; - } - }, - }; - - if js! { return @{ result.as_ref() }.success } != true { - let _err: WebError = js! { return @{ result }.error }.try_into().unwrap(); - error!("getrandom failed: {}", _err); - return Err(STDWEB_RNG_FAILED); - } - } - Ok(()) -} diff --git a/getrandom/src/windows.rs b/getrandom/src/windows.rs deleted file mode 100644 index e1b8df6..0000000 --- a/getrandom/src/windows.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for Windows -use crate::{error::RTL_GEN_RANDOM_FAILED, Error}; - -extern "system" { - #[link_name = "SystemFunction036"] - fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> u8; -} - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - // Prevent overflow of u32 - for chunk in dest.chunks_mut(u32::max_value() as usize) { - let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr(), chunk.len() as u32) }; - if ret == 0 { - return Err(RTL_GEN_RANDOM_FAILED); - } - } - Ok(()) -} diff --git a/getrandom/src/windows_uwp.rs b/getrandom/src/windows_uwp.rs deleted file mode 100644 index 586c6f6..0000000 --- a/getrandom/src/windows_uwp.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implementation for Windows UWP targets. After deprecation of Windows XP -//! and Vista, this can supersede the `RtlGenRandom`-based implementation. -use crate::Error; -use core::{ffi::c_void, num::NonZeroU32, ptr}; - -const BCRYPT_USE_SYSTEM_PREFERRED_RNG: u32 = 0x00000002; - -extern "system" { - fn BCryptGenRandom( - hAlgorithm: *mut c_void, - pBuffer: *mut u8, - cbBuffer: u32, - dwFlags: u32, - ) -> u32; -} - -pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { - // Prevent overflow of u32 - for chunk in dest.chunks_mut(u32::max_value() as usize) { - let ret = unsafe { - BCryptGenRandom( - ptr::null_mut(), - chunk.as_mut_ptr(), - chunk.len() as u32, - BCRYPT_USE_SYSTEM_PREFERRED_RNG, - ) - }; - // NTSTATUS codes use two highest bits for severity status - match ret >> 30 { - 0b01 => { - info!("BCryptGenRandom: information code 0x{:08X}", ret); - } - 0b10 => { - warn!("BCryptGenRandom: warning code 0x{:08X}", ret); - } - 0b11 => { - error!("BCryptGenRandom: failed with 0x{:08X}", ret); - // We zeroize the highest bit, so the error code will reside - // inside the range of designated for OS codes. - let code = ret ^ (1 << 31); - // SAFETY: the second highest bit is always equal to one, - // so it's impossible to get zero. Unfortunately compiler - // is not smart enough to figure out it yet. - let code = unsafe { NonZeroU32::new_unchecked(code) }; - return Err(Error::from(code)); - } - _ => (), - } - } - Ok(()) -} diff --git a/getrandom/tests/common.rs b/getrandom/tests/common.rs deleted file mode 100644 index afefa03..0000000 --- a/getrandom/tests/common.rs +++ /dev/null @@ -1,68 +0,0 @@ -#[cfg(feature = "wasm-bindgen")] -use wasm_bindgen_test::*; - -use getrandom::getrandom; - -#[cfg(feature = "test-in-browser")] -wasm_bindgen_test_configure!(run_in_browser); - -#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen_test)] -#[test] -fn test_zero() { - // Test that APIs are happy with zero-length requests - getrandom(&mut [0u8; 0]).unwrap(); -} - -#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen_test)] -#[test] -fn test_diff() { - let mut v1 = [0u8; 1000]; - getrandom(&mut v1).unwrap(); - - let mut v2 = [0u8; 1000]; - getrandom(&mut v2).unwrap(); - - let mut n_diff_bits = 0; - for i in 0..v1.len() { - n_diff_bits += (v1[i] ^ v2[i]).count_ones(); - } - - // Check at least 1 bit per byte differs. p(failure) < 1e-1000 with random input. - assert!(n_diff_bits >= v1.len() as u32); -} - -#[cfg_attr(feature = "wasm-bindgen", wasm_bindgen_test)] -#[test] -fn test_huge() { - let mut huge = [0u8; 100_000]; - getrandom(&mut huge).unwrap(); -} - -#[cfg(any(unix, windows, target_os = "redox", target_os = "fuchsia"))] -#[test] -fn test_multithreading() { - use std::sync::mpsc::channel; - use std::thread; - - let mut txs = vec![]; - for _ in 0..20 { - let (tx, rx) = channel(); - txs.push(tx); - - thread::spawn(move || { - // wait until all the tasks are ready to go. - rx.recv().unwrap(); - let mut v = [0u8; 1000]; - - for _ in 0..100 { - getrandom(&mut v).unwrap(); - thread::yield_now(); - } - }); - } - - // start all the tasks - for tx in txs.iter() { - tx.send(()).unwrap(); - } -} diff --git a/getrandom/utils/ci/install.sh b/getrandom/utils/ci/install.sh deleted file mode 100644 index 8e636e1..0000000 --- a/getrandom/utils/ci/install.sh +++ /dev/null @@ -1,49 +0,0 @@ -# From https://github.com/japaric/trust - -set -ex - -main() { - local target= - if [ $TRAVIS_OS_NAME = linux ]; then - target=x86_64-unknown-linux-musl - sort=sort - else - target=x86_64-apple-darwin - sort=gsort # for `sort --sort-version`, from brew's coreutils. - fi - - # Builds for iOS are done on OSX, but require the specific target to be - # installed. - case $TARGET in - aarch64-apple-ios) - rustup target install aarch64-apple-ios - ;; - armv7-apple-ios) - rustup target install armv7-apple-ios - ;; - armv7s-apple-ios) - rustup target install armv7s-apple-ios - ;; - i386-apple-ios) - rustup target install i386-apple-ios - ;; - x86_64-apple-ios) - rustup target install x86_64-apple-ios - ;; - esac - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0.1.0-9.]+$' \ - | $sort --version-sort \ - | tail -n1) - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git japaric/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/getrandom/utils/ci/script.sh b/getrandom/utils/ci/script.sh deleted file mode 100644 index b3e80d4..0000000 --- a/getrandom/utils/ci/script.sh +++ /dev/null @@ -1,13 +0,0 @@ -# Derived from https://github.com/japaric/trust - -set -ex - -main() { - cross test --target $TARGET - cross test --target $TARGET --examples -} - -# we don't run the "test phase" when doing deploys -if [ -z $TRAVIS_TAG ]; then - main -fi diff --git a/lazy-static/.gitignore b/lazy-static/.gitignore deleted file mode 100644 index bde55ce..0000000 --- a/lazy-static/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -doc -Cargo.lock -.cargo diff --git a/lazy-static/.travis.yml b/lazy-static/.travis.yml deleted file mode 100644 index e4a0da3..0000000 --- a/lazy-static/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: rust -matrix: - include: - - rust: 1.27.2 - - rust: stable - script: - - cargo test - - cargo test --features spin_no_std - - os: osx - - rust: beta - - rust: nightly - script: - - cargo test - - cargo bench - - cargo test --features spin_no_std - - cargo bench --features spin_no_std - - cd compiletest - - cargo clean - - cargo test - - cd ../ - - - rust: nightly - before_script: - - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH - script: - - cargo doc --no-deps --all-features - after_success: - - travis-cargo --only nightly doc-upload -script: - - cargo test - -env: - global: - - secure: YXu24LptjeYirjWYjWGsMT2m3mB7LvQATE6TVo7VEUXv8GYoy2ORIHD83PeImxC93MmZ01QeUezRzuCW51ZcK92VnNSBttlF60SvIX18VsJrV92tsAhievFstqYQ+fB8DIuQ8noU0jPz7GpI+R9dlTRSImAqWOnVIghA+Wzz7Js= diff --git a/lazy-static/Cargo.toml b/lazy-static/Cargo.toml deleted file mode 100644 index 9c0a177..0000000 --- a/lazy-static/Cargo.toml +++ /dev/null @@ -1,34 +0,0 @@ -[package] -name = "lazy_static" -# NB: When modifying, also modify html_root_url in lib.rs -version = "1.4.0" -authors = ["Marvin Löbel "] -license = "MIT/Apache-2.0" - -description = "A macro for declaring lazily evaluated statics in Rust." -readme = "README.md" -documentation = "https://docs.rs/lazy_static" - -repository = "https://github.com/rust-lang-nursery/lazy-static.rs" -keywords = ["macro", "lazy", "static"] -categories = [ "no-std", "rust-patterns", "memory-management" ] -exclude = ["/.travis.yml", "/appveyor.yml"] - -[dependencies.spin] -version = "0.5.0" -optional = true - -[features] -spin_no_std = ["spin"] - -[dev-dependencies] -doc-comment = "0.3.1" - -[badges] -appveyor = { repository = "rust-lang-nursery/lazy-static.rs" } -travis-ci = { repository = "rust-lang-nursery/lazy-static.rs" } - -is-it-maintained-issue-resolution = { repository = "rust-lang-nursery/lazy-static.rs" } -is-it-maintained-open-issues = { repository = "rust-lang-nursery/lazy-static.rs" } - -maintenance = { status = "passively-maintained" } diff --git a/lazy-static/LICENSE-APACHE b/lazy-static/LICENSE-APACHE deleted file mode 100644 index 16fe87b..0000000 --- a/lazy-static/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/lazy-static/LICENSE-MIT b/lazy-static/LICENSE-MIT deleted file mode 100644 index 25597d5..0000000 --- a/lazy-static/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2010 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/lazy-static/README.md b/lazy-static/README.md deleted file mode 100644 index aa9f828..0000000 --- a/lazy-static/README.md +++ /dev/null @@ -1,79 +0,0 @@ -lazy-static.rs -============== - -A macro for declaring lazily evaluated statics in Rust. - -Using this macro, it is possible to have `static`s that require code to be -executed at runtime in order to be initialized. -This includes anything requiring heap allocations, like vectors or hash maps, -as well as anything that requires non-const function calls to be computed. - -[![Travis-CI Status](https://travis-ci.com/rust-lang-nursery/lazy-static.rs.svg?branch=master)](https://travis-ci.com/rust-lang-nursery/lazy-static.rs) -[![Latest version](https://img.shields.io/crates/v/lazy_static.svg)](https://crates.io/crates/lazy_static) -[![Documentation](https://docs.rs/lazy_static/badge.svg)](https://docs.rs/lazy_static) -[![License](https://img.shields.io/crates/l/lazy_static.svg)](https://github.com/rust-lang-nursery/lazy-static.rs#license) - -## Minimum supported `rustc` - -`1.27.2+` - -This version is explicitly tested in CI and may only be bumped in new minor versions. Any changes to the supported minimum version will be called out in the release notes. - - -# Getting Started - -[lazy-static.rs is available on crates.io](https://crates.io/crates/lazy_static). -It is recommended to look there for the newest released version, as well as links to the newest builds of the docs. - -At the point of the last update of this README, the latest published version could be used like this: - -Add the following dependency to your Cargo manifest... - -```toml -[dependencies] -lazy_static = "1.4.0" -``` - -...and see the [docs](https://docs.rs/lazy_static) for how to use it. - -# Example - -```rust -#[macro_use] -extern crate lazy_static; - -use std::collections::HashMap; - -lazy_static! { - static ref HASHMAP: HashMap = { - let mut m = HashMap::new(); - m.insert(0, "foo"); - m.insert(1, "bar"); - m.insert(2, "baz"); - m - }; -} - -fn main() { - // First access to `HASHMAP` initializes it - println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap()); - - // Any further access to `HASHMAP` just returns the computed value - println!("The entry for `1` is \"{}\".", HASHMAP.get(&1).unwrap()); -} -``` - -## License - -Licensed under either of - - * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) - * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any -additional terms or conditions. diff --git a/lazy-static/appveyor.yml b/lazy-static/appveyor.yml deleted file mode 100644 index b138452..0000000 --- a/lazy-static/appveyor.yml +++ /dev/null @@ -1,61 +0,0 @@ -environment: - global: - PROJECT_NAME: lazy_static - # When this was added there were revocation check failures when using the - # libcurl backend as libcurl checks by default, but rustup doesn't provide the - # switch to turn this off. Switch to Hyper which looks to not check for - # revocation by default like libcurl does. - RUSTUP_USE_REQWEST: 1 - CARGO_HTTP_CHECK_REVOKE: false - matrix: - # Stable channel - - TARGET: i686-pc-windows-gnu - CHANNEL: stable - - TARGET: i686-pc-windows-msvc - CHANNEL: stable - - TARGET: x86_64-pc-windows-gnu - CHANNEL: stable - - TARGET: x86_64-pc-windows-msvc - CHANNEL: stable - # Beta channel - - TARGET: i686-pc-windows-gnu - CHANNEL: beta - - TARGET: i686-pc-windows-msvc - CHANNEL: beta - - TARGET: x86_64-pc-windows-gnu - CHANNEL: beta - - TARGET: x86_64-pc-windows-msvc - CHANNEL: beta - # Nightly channel - - TARGET: i686-pc-windows-gnu - CHANNEL: nightly - - TARGET: i686-pc-windows-msvc - CHANNEL: nightly - - TARGET: x86_64-pc-windows-gnu - CHANNEL: nightly - - TARGET: x86_64-pc-windows-msvc - CHANNEL: nightly - -# Install Rust and Cargo -# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml) -install: - - appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - - rustup-init.exe -y --default-toolchain %CHANNEL% --default-host %TARGET% - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - if "%TARGET%" == "i686-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw32\bin - - if "%TARGET%" == "x86_64-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw64\bin - - rustc -V - - cargo -V - -build: false - -test_script: - - cargo build --verbose - - cargo test - - if [%CHANNEL%]==[nightly] ( - cd compiletest && - cargo clean && - cargo build --verbose && - cargo test && - cd ../ - ) diff --git a/lazy-static/compiletest/Cargo.toml b/lazy-static/compiletest/Cargo.toml deleted file mode 100644 index e25d5a7..0000000 --- a/lazy-static/compiletest/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "lazy_static_compiletest" -version = "0.0.1" -publish = false -authors = ["lazy_static contributors"] - -[dependencies.lazy_static] -path = "../" - -[dependencies.compiletest_rs] -version = "0.3" diff --git a/lazy-static/compiletest/src/lib.rs b/lazy-static/compiletest/src/lib.rs deleted file mode 100644 index 0452765..0000000 --- a/lazy-static/compiletest/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -/* -This library is a shim around `lazy_static` that disambiguates it with the `lazy_static` -that's shipped with the Rust toolchain. We re-export the entire public API of `lazy_static` -under a different crate name so that can be imported in the compile tests. - -This currently appears to use the right local build of `lazy_static`. -*/ - -extern crate lazy_static; - -pub use self::lazy_static::*; diff --git a/lazy-static/compiletest/tests/compile-fail/README.md b/lazy-static/compiletest/tests/compile-fail/README.md deleted file mode 100644 index 58dbc3b..0000000 --- a/lazy-static/compiletest/tests/compile-fail/README.md +++ /dev/null @@ -1,22 +0,0 @@ -This directory contains snippets of code that should yield a -warning/note/help/error at compilation. Syntax of annotations is described in -[rust documentation](https://github.com/rust-lang/rust/blob/master/src/test/COMPILER_TESTS.md). -For more information check out [`compiletest` crate](https://github.com/laumann/compiletest-rs). - -To run compile tests issue `cargo +nightly --test`. - -## Notes on working with `compiletest` crate - -* Currently code that is inside macro should not be annotated, as `compiletest` - crate cannot deal with the fact that macro invocations effectively changes - line numbering. To prevent this add a `// error-pattern:` - on the top of the file and make sure that you set `deny` lint level - if you want to test compiler message different than error. -* `compiletest` crate by default sets `allow(dead_code)` lint level so make sure - that you change it to something suiting your needs even if the warning is - issued prior to any macro invocation. -* If you get a message `error: 0 unexpected errors found, 1 expected errors not found` - despite the fact that some error was bound to occur don't worry - it's a known - issue in the `compiletest` crate and your error was probably not registered - - make sure that your annotations are correct and that you are setting correct - lint levels. diff --git a/lazy-static/compiletest/tests/compile-fail/incorrect_visibility_restriction.rs b/lazy-static/compiletest/tests/compile-fail/incorrect_visibility_restriction.rs deleted file mode 100644 index 360e23d..0000000 --- a/lazy-static/compiletest/tests/compile-fail/incorrect_visibility_restriction.rs +++ /dev/null @@ -1,10 +0,0 @@ -// incorrect visibility restriction -#[macro_use] -extern crate lazy_static_compiletest as lazy_static; - -lazy_static! { - pub(nonsense) static ref WRONG: () = (); - //~^ ERROR incorrect visibility restriction -} - -fn main() { } diff --git a/lazy-static/compiletest/tests/compile-fail/static_is_private.rs b/lazy-static/compiletest/tests/compile-fail/static_is_private.rs deleted file mode 100644 index 6ebc8f5..0000000 --- a/lazy-static/compiletest/tests/compile-fail/static_is_private.rs +++ /dev/null @@ -1,14 +0,0 @@ -#[macro_use] -extern crate lazy_static_compiletest as lazy_static; - -mod outer { - pub mod inner { - lazy_static! { - pub(in outer) static ref FOO: () = (); - } - } -} - -fn main() { - assert_eq!(*outer::inner::FOO, ()); //~ ERROR static `FOO` is private -} diff --git a/lazy-static/compiletest/tests/compile-fail/static_is_sized.rs b/lazy-static/compiletest/tests/compile-fail/static_is_sized.rs deleted file mode 100644 index ac1cad4..0000000 --- a/lazy-static/compiletest/tests/compile-fail/static_is_sized.rs +++ /dev/null @@ -1,11 +0,0 @@ -// error-pattern:the size for values of type `str` cannot be known at compilation time -#[macro_use] -extern crate lazy_static_compiletest as lazy_static; - -lazy_static! { - pub static ref FOO: str = panic!(); -} - - -fn main() { -} diff --git a/lazy-static/compiletest/tests/compile_tests.rs b/lazy-static/compiletest/tests/compile_tests.rs deleted file mode 100644 index d908077..0000000 --- a/lazy-static/compiletest/tests/compile_tests.rs +++ /dev/null @@ -1,19 +0,0 @@ -extern crate compiletest_rs as compiletest; - -fn run_mode(mode: &'static str) { - let mut config = compiletest::Config::default(); - config.mode = mode.parse().expect("Invalid mode"); - config.src_base = ["tests", mode].iter().collect(); - - config.verbose = true; - - config.target_rustcflags = Some("-L target/debug/ -L target/debug/deps/".to_owned()); - config.clean_rmeta(); - - compiletest::run_tests(&config); -} - -#[test] -fn compile_test() { - run_mode("compile-fail"); -} diff --git a/lazy-static/src/core_lazy.rs b/lazy-static/src/core_lazy.rs deleted file mode 100644 index b66c3e0..0000000 --- a/lazy-static/src/core_lazy.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2016 lazy-static.rs Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -extern crate spin; - -use self::spin::Once; - -pub struct Lazy(Once); - -impl Lazy { - pub const INIT: Self = Lazy(Once::INIT); - - #[inline(always)] - pub fn get(&'static self, builder: F) -> &T - where F: FnOnce() -> T - { - self.0.call_once(builder) - } -} - -#[macro_export] -#[doc(hidden)] -macro_rules! __lazy_static_create { - ($NAME:ident, $T:ty) => { - static $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::INIT; - } -} diff --git a/lazy-static/src/inline_lazy.rs b/lazy-static/src/inline_lazy.rs deleted file mode 100644 index 219ce9c..0000000 --- a/lazy-static/src/inline_lazy.rs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2016 lazy-static.rs Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -extern crate core; -extern crate std; - -use self::std::prelude::v1::*; -use self::std::cell::Cell; -use self::std::hint::unreachable_unchecked; -use self::std::sync::Once; -#[allow(deprecated)] -pub use self::std::sync::ONCE_INIT; - -// FIXME: Replace Option with MaybeUninit (stable since 1.36.0) -pub struct Lazy(Cell>, Once); - -impl Lazy { - #[allow(deprecated)] - pub const INIT: Self = Lazy(Cell::new(None), ONCE_INIT); - - #[inline(always)] - pub fn get(&'static self, f: F) -> &T - where - F: FnOnce() -> T, - { - self.1.call_once(|| { - self.0.set(Some(f())); - }); - - // `self.0` is guaranteed to be `Some` by this point - // The `Once` will catch and propagate panics - unsafe { - match *self.0.as_ptr() { - Some(ref x) => x, - None => { - debug_assert!(false, "attempted to derefence an uninitialized lazy static. This is a bug"); - - unreachable_unchecked() - }, - } - } - } -} - -unsafe impl Sync for Lazy {} - -#[macro_export] -#[doc(hidden)] -macro_rules! __lazy_static_create { - ($NAME:ident, $T:ty) => { - static $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::INIT; - }; -} diff --git a/lazy-static/src/lib.rs b/lazy-static/src/lib.rs deleted file mode 100644 index cada0dc..0000000 --- a/lazy-static/src/lib.rs +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2016 lazy-static.rs Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -/*! -A macro for declaring lazily evaluated statics. - -Using this macro, it is possible to have `static`s that require code to be -executed at runtime in order to be initialized. -This includes anything requiring heap allocations, like vectors or hash maps, -as well as anything that requires function calls to be computed. - -# Syntax - -```ignore -lazy_static! { - [pub] static ref NAME_1: TYPE_1 = EXPR_1; - [pub] static ref NAME_2: TYPE_2 = EXPR_2; - ... - [pub] static ref NAME_N: TYPE_N = EXPR_N; -} -``` - -Attributes (including doc comments) are supported as well: - -```rust -# #[macro_use] -# extern crate lazy_static; -# fn main() { -lazy_static! { - /// This is an example for using doc comment attributes - static ref EXAMPLE: u8 = 42; -} -# } -``` - -# Semantics - -For a given `static ref NAME: TYPE = EXPR;`, the macro generates a unique type that -implements `Deref` and stores it in a static with name `NAME`. (Attributes end up -attaching to this type.) - -On first deref, `EXPR` gets evaluated and stored internally, such that all further derefs -can return a reference to the same object. Note that this can lead to deadlocks -if you have multiple lazy statics that depend on each other in their initialization. - -Apart from the lazy initialization, the resulting "static ref" variables -have generally the same properties as regular "static" variables: - -- Any type in them needs to fulfill the `Sync` trait. -- If the type has a destructor, then it will not run when the process exits. - -# Example - -Using the macro: - -```rust -#[macro_use] -extern crate lazy_static; - -use std::collections::HashMap; - -lazy_static! { - static ref HASHMAP: HashMap = { - let mut m = HashMap::new(); - m.insert(0, "foo"); - m.insert(1, "bar"); - m.insert(2, "baz"); - m - }; - static ref COUNT: usize = HASHMAP.len(); - static ref NUMBER: u32 = times_two(21); -} - -fn times_two(n: u32) -> u32 { n * 2 } - -fn main() { - println!("The map has {} entries.", *COUNT); - println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap()); - println!("A expensive calculation on a static results in: {}.", *NUMBER); -} -``` - -# Implementation details - -The `Deref` implementation uses a hidden static variable that is guarded by an atomic check on each access. - -# Cargo features - -This crate provides one cargo feature: - -- `spin_no_std`: This allows using this crate in a no-std environment, by depending on the standalone `spin` crate. - -*/ - -#![doc(html_root_url = "https://docs.rs/lazy_static/1.4.0")] -#![no_std] - -#[cfg(not(feature = "spin_no_std"))] -#[path="inline_lazy.rs"] -#[doc(hidden)] -pub mod lazy; - -#[cfg(test)] -#[macro_use] -extern crate doc_comment; - -#[cfg(test)] -doctest!("../README.md"); - -#[cfg(feature = "spin_no_std")] -#[path="core_lazy.rs"] -#[doc(hidden)] -pub mod lazy; - -#[doc(hidden)] -pub use core::ops::Deref as __Deref; - -#[macro_export(local_inner_macros)] -#[doc(hidden)] -macro_rules! __lazy_static_internal { - // optional visibility restrictions are wrapped in `()` to allow for - // explicitly passing otherwise implicit information about private items - ($(#[$attr:meta])* ($($vis:tt)*) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { - __lazy_static_internal!(@MAKE TY, $(#[$attr])*, ($($vis)*), $N); - __lazy_static_internal!(@TAIL, $N : $T = $e); - lazy_static!($($t)*); - }; - (@TAIL, $N:ident : $T:ty = $e:expr) => { - impl $crate::__Deref for $N { - type Target = $T; - fn deref(&self) -> &$T { - #[inline(always)] - fn __static_ref_initialize() -> $T { $e } - - #[inline(always)] - fn __stability() -> &'static $T { - __lazy_static_create!(LAZY, $T); - LAZY.get(__static_ref_initialize) - } - __stability() - } - } - impl $crate::LazyStatic for $N { - fn initialize(lazy: &Self) { - let _ = &**lazy; - } - } - }; - // `vis` is wrapped in `()` to prevent parsing ambiguity - (@MAKE TY, $(#[$attr:meta])*, ($($vis:tt)*), $N:ident) => { - #[allow(missing_copy_implementations)] - #[allow(non_camel_case_types)] - #[allow(dead_code)] - $(#[$attr])* - $($vis)* struct $N {__private_field: ()} - #[doc(hidden)] - $($vis)* static $N: $N = $N {__private_field: ()}; - }; - () => () -} - -#[macro_export(local_inner_macros)] -macro_rules! lazy_static { - ($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { - // use `()` to explicitly forward the information about private items - __lazy_static_internal!($(#[$attr])* () static ref $N : $T = $e; $($t)*); - }; - ($(#[$attr:meta])* pub static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { - __lazy_static_internal!($(#[$attr])* (pub) static ref $N : $T = $e; $($t)*); - }; - ($(#[$attr:meta])* pub ($($vis:tt)+) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { - __lazy_static_internal!($(#[$attr])* (pub ($($vis)+)) static ref $N : $T = $e; $($t)*); - }; - () => () -} - -/// Support trait for enabling a few common operation on lazy static values. -/// -/// This is implemented by each defined lazy static, and -/// used by the free functions in this crate. -pub trait LazyStatic { - #[doc(hidden)] - fn initialize(lazy: &Self); -} - -/// Takes a shared reference to a lazy static and initializes -/// it if it has not been already. -/// -/// This can be used to control the initialization point of a lazy static. -/// -/// Example: -/// -/// ```rust -/// #[macro_use] -/// extern crate lazy_static; -/// -/// lazy_static! { -/// static ref BUFFER: Vec = (0..255).collect(); -/// } -/// -/// fn main() { -/// lazy_static::initialize(&BUFFER); -/// -/// // ... -/// work_with_initialized_data(&BUFFER); -/// } -/// # fn work_with_initialized_data(_: &[u8]) {} -/// ``` -pub fn initialize(lazy: &T) { - LazyStatic::initialize(lazy); -} diff --git a/lazy-static/tests/no_std.rs b/lazy-static/tests/no_std.rs deleted file mode 100644 index f94a1aa..0000000 --- a/lazy-static/tests/no_std.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![cfg(feature="spin_no_std")] - -#![no_std] - -#[macro_use] -extern crate lazy_static; - -lazy_static! { - /// Documentation! - pub static ref NUMBER: u32 = times_two(3); -} - -fn times_two(n: u32) -> u32 { - n * 2 -} - -#[test] -fn test_basic() { - assert_eq!(*NUMBER, 6); -} diff --git a/lazy-static/tests/test.rs b/lazy-static/tests/test.rs deleted file mode 100644 index 03d0ab6..0000000 --- a/lazy-static/tests/test.rs +++ /dev/null @@ -1,164 +0,0 @@ -#[macro_use] -extern crate lazy_static; -use std::collections::HashMap; - -lazy_static! { - /// Documentation! - pub static ref NUMBER: u32 = times_two(3); - - static ref ARRAY_BOXES: [Box; 3] = [Box::new(1), Box::new(2), Box::new(3)]; - - /// More documentation! - #[allow(unused_variables)] - #[derive(Copy, Clone, Debug)] - pub static ref STRING: String = "hello".to_string(); - - static ref HASHMAP: HashMap = { - let mut m = HashMap::new(); - m.insert(0, "abc"); - m.insert(1, "def"); - m.insert(2, "ghi"); - m - }; - - // This should not compile if the unsafe is removed. - static ref UNSAFE: u32 = unsafe { - std::mem::transmute::(-1) - }; -} - -lazy_static! { - static ref S1: &'static str = "a"; - static ref S2: &'static str = "b"; -} -lazy_static! { - static ref S3: String = [*S1, *S2].join(""); -} - -#[test] -fn s3() { - assert_eq!(&*S3, "ab"); -} - -fn times_two(n: u32) -> u32 { - n * 2 -} - -#[test] -fn test_basic() { - assert_eq!(&**STRING, "hello"); - assert_eq!(*NUMBER, 6); - assert!(HASHMAP.get(&1).is_some()); - assert!(HASHMAP.get(&3).is_none()); - assert_eq!(&*ARRAY_BOXES, &[Box::new(1), Box::new(2), Box::new(3)]); - assert_eq!(*UNSAFE, std::u32::MAX); -} - -#[test] -fn test_repeat() { - assert_eq!(*NUMBER, 6); - assert_eq!(*NUMBER, 6); - assert_eq!(*NUMBER, 6); -} - -#[test] -fn test_meta() { - // this would not compile if STRING were not marked #[derive(Copy, Clone)] - let copy_of_string = STRING; - // just to make sure it was copied - assert!(&STRING as *const _ != ©_of_string as *const _); - - // this would not compile if STRING were not marked #[derive(Debug)] - assert_eq!(format!("{:?}", STRING), "STRING { __private_field: () }".to_string()); -} - -mod visibility { - lazy_static! { - pub static ref FOO: Box = Box::new(0); - static ref BAR: Box = Box::new(98); - } - - pub mod inner { - lazy_static! { - pub(in visibility) static ref BAZ: Box = Box::new(42); - pub(crate) static ref BAG: Box = Box::new(37); - } - } - - #[test] - fn sub_test() { - assert_eq!(**FOO, 0); - assert_eq!(**BAR, 98); - assert_eq!(**inner::BAZ, 42); - assert_eq!(**inner::BAG, 37); - } -} - -#[test] -fn test_visibility() { - assert_eq!(*visibility::FOO, Box::new(0)); - assert_eq!(*visibility::inner::BAG, Box::new(37)); -} - -// This should not cause a warning about a missing Copy implementation -lazy_static! { - pub static ref VAR: i32 = { 0 }; -} - -#[derive(Copy, Clone, Debug, PartialEq)] -struct X; -struct Once(X); -const ONCE_INIT: Once = Once(X); -static DATA: X = X; -static ONCE: X = X; -fn require_sync() -> X { X } -fn transmute() -> X { X } -fn __static_ref_initialize() -> X { X } -fn test(_: Vec) -> X { X } - -// All these names should not be shadowed -lazy_static! { - static ref ITEM_NAME_TEST: X = { - test(vec![X, Once(X).0, ONCE_INIT.0, DATA, ONCE, - require_sync(), transmute(), - // Except this, which will sadly be shadowed by internals: - // __static_ref_initialize() - ]) - }; -} - -#[test] -fn item_name_shadowing() { - assert_eq!(*ITEM_NAME_TEST, X); -} - -use std::sync::atomic::AtomicBool; -#[allow(deprecated)] -use std::sync::atomic::ATOMIC_BOOL_INIT; -use std::sync::atomic::Ordering::SeqCst; - -#[allow(deprecated)] -static PRE_INIT_FLAG: AtomicBool = ATOMIC_BOOL_INIT; - -lazy_static! { - static ref PRE_INIT: () = { - PRE_INIT_FLAG.store(true, SeqCst); - () - }; -} - -#[test] -fn pre_init() { - assert_eq!(PRE_INIT_FLAG.load(SeqCst), false); - lazy_static::initialize(&PRE_INIT); - assert_eq!(PRE_INIT_FLAG.load(SeqCst), true); -} - -lazy_static! { - static ref LIFETIME_NAME: for<'a> fn(&'a u8) = { fn f(_: &u8) {} f }; -} - -#[test] -fn lifetime_name() { - let _ = LIFETIME_NAME; -} diff --git a/libc/.cirrus.yml b/libc/.cirrus.yml deleted file mode 100644 index 2883043..0000000 --- a/libc/.cirrus.yml +++ /dev/null @@ -1,43 +0,0 @@ -task: - name: nightly x86_64-unknown-freebsd-10 - freebsd_instance: - image: freebsd-10-4-release-amd64 - setup_script: - - pkg install -y curl - - curl https://sh.rustup.rs -sSf --output rustup.sh - - sh rustup.sh --default-toolchain nightly -y --profile=minimal - - . $HOME/.cargo/env - - rustup default nightly - test_script: - - . $HOME/.cargo/env - - LIBC_CI=1 sh ci/run.sh x86_64-unknown-freebsd - -task: - name: stable x86_64-unknown-freebsd-11 - freebsd_instance: - image: freebsd-11-3-stable-amd64-v20190801 - setup_script: - - pkg install -y curl - - curl https://sh.rustup.rs -sSf --output rustup.sh - - sh rustup.sh -y --profile=minimal - - . $HOME/.cargo/env - - rustup default stable - test_script: - - . $HOME/.cargo/env - - LIBC_CI=1 sh ci/run.sh x86_64-unknown-freebsd - - sh ci/run.sh x86_64-unknown-freebsd - -task: - name: nightly x86_64-unknown-freebsd-12 - freebsd_instance: - image: freebsd-12-0-release-amd64 - setup_script: - - pkg install -y curl - - curl https://sh.rustup.rs -sSf --output rustup.sh - - sh rustup.sh --default-toolchain nightly -y --profile=minimal - - . $HOME/.cargo/env - - rustup default nightly - test_script: - - . $HOME/.cargo/env - - LIBC_CI=1 sh ci/run.sh x86_64-unknown-freebsd - - sh ci/run.sh x86_64-unknown-freebsd diff --git a/libc/.github/issue_template.md b/libc/.github/issue_template.md deleted file mode 100644 index 435bf35..0000000 --- a/libc/.github/issue_template.md +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/libc/.gitignore b/libc/.gitignore deleted file mode 100644 index bbbad4b..0000000 --- a/libc/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -Cargo.lock -*~ -style diff --git a/libc/CONTRIBUTING.md b/libc/CONTRIBUTING.md deleted file mode 100644 index 052777f..0000000 --- a/libc/CONTRIBUTING.md +++ /dev/null @@ -1,66 +0,0 @@ -# Contributing to `libc` - -Welcome! If you are reading this document, it means you are interested in contributing -to the `libc` crate. - -## Adding an API - -Want to use an API which currently isn't bound in `libc`? It's quite easy to add -one! - -The internal structure of this crate is designed to minimize the number of -`#[cfg]` attributes in order to easily be able to add new items which apply -to all platforms in the future. As a result, the crate is organized -hierarchically based on platform. Each module has a number of `#[cfg]`'d -children, but only one is ever actually compiled. Each module then reexports all -the contents of its children. - -This means that for each platform that libc supports, the path from a -leaf module to the root will contain all bindings for the platform in question. -Consequently, this indicates where an API should be added! Adding an API at a -particular level in the hierarchy means that it is supported on all the child -platforms of that level. For example, when adding a Unix API it should be added -to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to -`src/unix/linux_like/linux/mod.rs`. - -If you're not 100% sure at what level of the hierarchy an API should be added -at, fear not! This crate has CI support which tests any binding against all -platforms supported, so you'll see failures if an API is added at the wrong -level or has different signatures across platforms. - -With that in mind, the steps for adding a new API are: - -1. Determine where in the module hierarchy your API should be added. -2. Add the API. -3. Send a PR to this repo. -4. Wait for CI to pass, fixing errors. -5. Wait for a merge! - -### Test before you commit - -We have two automated tests running on [Azure Pipelines](https://dev.azure.com/rust-lang2/libc/_build?definitionId=1&_a=summary): - -1. [`libc-test`](https://github.com/gnzlbg/ctest) - - `cd libc-test && cargo test` - - Use the `skip_*()` functions in `build.rs` if you really need a workaround. -2. Style checker - - `rustc ci/style.rs && ./style src` - -### Releasing your change to crates.io - -Now that you've done the amazing job of landing your new API or your new -platform in this crate, the next step is to get that sweet, sweet usage from -crates.io! The only next step is to bump the version of libc and then publish -it. If you'd like to get a release out ASAP you can follow these steps: - -1. Update the version number in `Cargo.toml`, you'll just be bumping the patch - version number. -2. Run `cargo update` to regenerate the lockfile to encode your version bump in - the lock file. You may pull in some other updated dependencies, that's ok. -3. Send a PR to this repository. It should [look like this][example], but it'd - also be nice to fill out the description with a small rationale for the - release (any rationale is ok though!) -4. Once merged the release will be tagged and published by one of the libc crate - maintainers. - -[example]: https://github.com/rust-lang/libc/pull/583 diff --git a/libc/Cargo.toml b/libc/Cargo.toml deleted file mode 100644 index c701f41..0000000 --- a/libc/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "libc" -version = "0.2.66" -authors = ["The Rust Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-lang/libc" -homepage = "https://github.com/rust-lang/libc" -documentation = "http://doc.rust-lang.org/libc" -keywords = ["libc", "ffi", "bindings", "operating", "system" ] -categories = ["external-ffi-bindings", "no-std", "os"] -build = "build.rs" -exclude = ["/ci/*", "/azure-pipelines.yml"] -description = """ -Raw FFI bindings to platform libraries like libc. -""" - -[badges] -travis-ci = { repository = "rust-lang/libc" } -appveyor = { repository = "rust-lang/libc", project_name = "rust-lang-libs/libc" } - -[dependencies] -rustc-std-workspace-core = { version = "1.0.0", optional = true } - -[features] -default = ["std"] -std = [] -align = [] -rustc-dep-of-std = ['align', 'rustc-std-workspace-core'] -extra_traits = [] -const-extern-fn = [] -# use_std is deprecated, use `std` instead -use_std = [ 'std' ] - -[workspace] -members = ["libc-test"] diff --git a/libc/LICENSE-APACHE b/libc/LICENSE-APACHE deleted file mode 100644 index 16fe87b..0000000 --- a/libc/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/libc/LICENSE-MIT b/libc/LICENSE-MIT deleted file mode 100644 index 39d4bdb..0000000 --- a/libc/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/libc/README.md b/libc/README.md deleted file mode 100644 index 8a36881..0000000 --- a/libc/README.md +++ /dev/null @@ -1,106 +0,0 @@ -[![Azure Status]][Azure] [![Cirrus CI Status]][Cirrus CI] [![Latest Version]][crates.io] [![Documentation]][docs.rs] ![License] - -libc - Raw FFI bindings to platforms' system libraries -==== - -`libc` provides all of the definitions necessary to easily interoperate with C -code (or "C-like" code) on each of the platforms that Rust supports. This -includes type definitions (e.g. `c_int`), constants (e.g. `EINVAL`) as well as -function headers (e.g. `malloc`). - -This crate exports all underlying platform types, functions, and constants under -the crate root, so all items are accessible as `libc::foo`. The types and values -of all the exported APIs match the platform that libc is compiled for. - -More detailed information about the design of this library can be found in its -[associated RFC][rfc]. - -[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1291-promote-libc.md - -## Usage - -Add the following to your `Cargo.toml`: - -```toml -[dependencies] -libc = "0.2" -``` - -## Features - -* `std`: by default `libc` links to the standard library. Disable this - feature remove this dependency and be able to use `libc` in `#![no_std]` - crates. - -* `extra_traits`: all `struct`s implemented in `libc` are `Copy` and `Clone`. - This feature derives `Debug`, `Eq`, `Hash`, and `PartialEq`. - -* `const-extern-fn`: Changes some `extern fn`s into `const extern fn`s. - This features requires a nightly rustc - -* **deprecated**: `use_std` is deprecated, and is equivalent to `std`. - -## Rust version support - -The minimum supported Rust toolchain version is **Rust 1.13.0** . APIs requiring -newer Rust features are only available on newer Rust toolchains: - -| Feature | Version | -|----------------------|---------| -| `union` | 1.19.0 | -| `const mem::size_of` | 1.24.0 | -| `repr(align)` | 1.25.0 | -| `extra_traits` | 1.25.0 | -| `core::ffi::c_void` | 1.30.0 | -| `repr(packed(N))` | 1.33.0 | - -## Platform support - -[Platform-specific documentation (master branch)][docs.master]. - -See -[`ci/build.sh`](https://github.com/rust-lang/libc/blob/master/ci/build.sh) -for the platforms on which `libc` is guaranteed to build for each Rust -toolchain. The test-matrix at [Azure] and [Cirrus CI] show the -platforms in which `libc` tests are run. - -

- -## License - -This project is licensed under either of - -* [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0) - ([LICENSE-APACHE](LICENSE-APACHE)) - -* [MIT License](https://opensource.org/licenses/MIT) - ([LICENSE-MIT](LICENSE-MIT)) - -at your option. - -## Contributing - -We welcome all people who want to contribute. Please see the [contributing -instructions] for more information. - -[contributing instructions]: CONTRIBUTING.md - -Contributions in any form (issues, pull requests, etc.) to this project -must adhere to Rust's [Code of Conduct]. - -[Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in `libc` by you, as defined in the Apache-2.0 license, shall be -dual licensed as above, without any additional terms or conditions. - -[Azure Status]: https://dev.azure.com/rust-lang2/libc/_apis/build/status/rust-lang.libc?branchName=master -[Azure]: https://dev.azure.com/rust-lang2/libc/_build/latest?definitionId=1&branchName=master -[Cirrus CI]: https://cirrus-ci.com/github/rust-lang/libc -[Cirrus CI Status]: https://api.cirrus-ci.com/github/rust-lang/libc.svg -[crates.io]: https://crates.io/crates/libc -[Latest Version]: https://img.shields.io/crates/v/libc.svg -[Documentation]: https://docs.rs/libc/badge.svg -[docs.rs]: https://docs.rs/libc -[License]: https://img.shields.io/crates/l/libc.svg -[docs.master]: https://rust-lang.github.io/libc/#platform-specific-documentation diff --git a/libc/build.rs b/libc/build.rs deleted file mode 100644 index f447c0e..0000000 --- a/libc/build.rs +++ /dev/null @@ -1,144 +0,0 @@ -use std::env; -use std::process::Command; -use std::str; - -fn main() { - let (rustc_minor_ver, is_nightly) = - rustc_minor_nightly().expect("Failed to get rustc version"); - let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok(); - let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok(); - let const_extern_fn_cargo_feature = - env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok(); - let libc_ci = env::var("LIBC_CI").is_ok(); - - if env::var("CARGO_FEATURE_USE_STD").is_ok() { - println!( - "cargo:warning=\"libc's use_std cargo feature is deprecated since libc 0.2.55; \ - please consider using the `std` cargo feature instead\"" - ); - } - - // The ABI of libc used by libstd is backward compatible with FreeBSD 10. - // The ABI of libc from crates.io is backward compatible with FreeBSD 11. - // - // On CI, we detect the actual FreeBSD version and match its ABI exactly, - // running tests to ensure that the ABI is correct. - match which_freebsd() { - Some(10) if libc_ci || rustc_dep_of_std => { - println!("cargo:rustc-cfg=freebsd10") - } - Some(11) if libc_ci => println!("cargo:rustc-cfg=freebsd11"), - Some(12) if libc_ci => println!("cargo:rustc-cfg=freebsd12"), - Some(13) if libc_ci => println!("cargo:rustc-cfg=freebsd13"), - Some(_) | None => println!("cargo:rustc-cfg=freebsd11"), - } - - // On CI: deny all warnings - if libc_ci { - println!("cargo:rustc-cfg=libc_deny_warnings"); - } - - // Rust >= 1.15 supports private module use: - if rustc_minor_ver >= 15 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_priv_mod_use"); - } - - // Rust >= 1.19 supports unions: - if rustc_minor_ver >= 19 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_union"); - } - - // Rust >= 1.24 supports const mem::size_of: - if rustc_minor_ver >= 24 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_const_size_of"); - } - - // Rust >= 1.25 supports repr(align): - if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature { - println!("cargo:rustc-cfg=libc_align"); - } - - // Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it. - // Otherwise, it defines an incompatible type to retaining - // backwards-compatibility. - if rustc_minor_ver >= 30 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_core_cvoid"); - } - - // Rust >= 1.33 supports repr(packed(N)) - if rustc_minor_ver >= 33 || rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_packedN"); - } - - // #[thread_local] is currently unstable - if rustc_dep_of_std { - println!("cargo:rustc-cfg=libc_thread_local"); - } - - if const_extern_fn_cargo_feature { - if !is_nightly || rustc_minor_ver < 40 { - panic!("const-extern-fn requires a nightly compiler >= 1.40") - } - println!("cargo:rustc-cfg=libc_const_extern_fn"); - } -} - -fn rustc_minor_nightly() -> Option<(u32, bool)> { - macro_rules! otry { - ($e:expr) => { - match $e { - Some(e) => e, - None => return None, - } - }; - } - - let rustc = otry!(env::var_os("RUSTC")); - let output = otry!(Command::new(rustc).arg("--version").output().ok()); - let version = otry!(str::from_utf8(&output.stdout).ok()); - let mut pieces = version.split('.'); - - if pieces.next() != Some("rustc 1") { - return None; - } - - let minor = pieces.next(); - - // If `rustc` was built from a tarball, its version string - // will have neither a git hash nor a commit date - // (e.g. "rustc 1.39.0"). Treat this case as non-nightly, - // since a nightly build should either come from CI - // or a git checkout - let nightly_raw = otry!(pieces.next()).split('-').nth(1); - let nightly = nightly_raw - .map(|raw| raw.starts_with("dev") || raw.starts_with("nightly")) - .unwrap_or(false); - let minor = otry!(otry!(minor).parse().ok()); - - Some((minor, nightly)) -} - -fn which_freebsd() -> Option { - let output = std::process::Command::new("freebsd-version").output().ok(); - if output.is_none() { - return None; - } - let output = output.unwrap(); - if !output.status.success() { - return None; - } - - let stdout = String::from_utf8(output.stdout).ok(); - if stdout.is_none() { - return None; - } - let stdout = stdout.unwrap(); - - match &stdout { - s if s.starts_with("10") => Some(10), - s if s.starts_with("11") => Some(11), - s if s.starts_with("12") => Some(12), - s if s.starts_with("13") => Some(13), - _ => None, - } -} diff --git a/libc/ci/README.md b/libc/ci/README.md deleted file mode 100644 index 3123553..0000000 --- a/libc/ci/README.md +++ /dev/null @@ -1,236 +0,0 @@ -The goal of the libc crate is to have CI running everywhere to have the -strongest guarantees about the definitions that this library contains, and as a -result the CI is pretty complicated and also pretty large! Hopefully this can -serve as a guide through the sea of scripts in this directory and elsewhere in -this project. - -# Files - -First up, let's talk about the files in this directory: - -* `run-docker.sh` - a shell script run by most builders, it will execute - `run.sh` inside a Docker container configured for the target. - -* `run.sh` - the actual script which runs tests for a particular architecture. - -* `dox.sh` - build the documentation of the crate and publish it to gh-pages. - -* `landing-page-*.html` - used by `dox.sh` to generate a landing page for all - architectures' documentation. - -* `run-qemu.sh` - see discussion about QEMU below - -* `mips`, `rumprun` - instructions to build the docker image for each respective - CI target - -# CI Systems - -Currently this repository leverages a combination of Travis CI and AppVeyor for -running tests. The triples tested are: - -* AppVeyor - * `{i686,x86_64}-pc-windows-{msvc,gnu}` -* Travis - * `{i686,x86_64,mips,aarch64}-unknown-linux-gnu` - * `{x86_64,aarch64}-unknown-linux-musl` - * `arm-unknown-linux-gnueabihf` - * `arm-linux-androideabi` - * `{i686,x86_64}-apple-{darwin,ios}` - * `x86_64-rumprun-netbsd` - * `x86_64-unknown-freebsd` - * `x86_64-unknown-openbsd` - -The Windows triples are all pretty standard, they just set up their environment -then run tests, no need for downloading any extra target libs (we just download -the right installer). The Intel Linux/OSX builds are similar in that we just -download the right target libs and run tests. Note that the Intel Linux/OSX -builds are run on stable/beta/nightly, but are the only ones that do so. - -The remaining architectures look like: - -* Android runs in a [docker image][android-docker] with an emulator, the NDK, - and the SDK already set up. The entire build happens within the docker image. -* The MIPS, ARM, and AArch64 builds all use the QEMU userspace emulator to run - the generated binary to actually verify the tests pass. -* The MUSL build just has to download a MUSL compiler and target libraries and - then otherwise runs tests normally. -* iOS builds need an extra linker flag currently, but beyond that they're built - as standard as everything else. -* The rumprun target builds an entire kernel from the test suite and then runs - it inside QEMU using the serial console to test whether it succeeded or - failed. -* The BSD builds, currently OpenBSD and FreeBSD, use QEMU to boot up a system - and compile/run tests. More information on that below. - -[android-docker]: https://github.com/rust-lang/rust-buildbot/blob/master/slaves/android/Dockerfile - -## QEMU - -Lots of the architectures tested here use QEMU in the tests, so it's worth going -over all the crazy capabilities QEMU has and the various flavors in which we use -it! - -First up, QEMU has userspace emulation where it doesn't boot a full kernel, it -just runs a binary from another architecture (using the `qemu-` wrappers). -We provide it the runtime path for the dynamically loaded system libraries, -however. This strategy is used for all Linux architectures that aren't intel. -Note that one downside of this QEMU system is that threads are barely -implemented, so we're careful to not spawn many threads. - -For the rumprun target the only output is a kernel image, so we just use that -plus the `rumpbake` command to create a full kernel image which is then run from -within QEMU. - -Finally, the fun part, the BSDs. Quite a few hoops are jumped through to get CI -working for these platforms, but the gist of it looks like: - -* Cross compiling from Linux to any of the BSDs seems to be quite non-standard. - We may be able to get it working but it might be difficult at that point to - ensure that the libc definitions align with what you'd get on the BSD itself. - As a result, we try to do compiles within the BSD distro. -* On Travis we can't run a VM-in-a-VM, so we resort to userspace emulation - (QEMU). -* Unfortunately on Travis we also can't use KVM, so the emulation is super slow. - -With all that in mind, the way BSD is tested looks like: - -1. Download a pre-prepared image for the OS being tested. -2. Generate the tests for the OS being tested. This involves running the `ctest` - library over libc to generate a Rust file and a C file which will then be - compiled into the final test. -3. Generate a disk image which will later be mounted by the OS being tested. - This image is mostly just the libc directory, but some modifications are made - to compile the generated files from step 2. -4. The kernel is booted in QEMU, and it is configured to detect the libc-test - image being available, run the test script, and then shut down afterwards. -5. Look for whether the tests passed in the serial console output of the kernel. - -There's some pretty specific instructions for setting up each image (detailed -below), but the main gist of this is that we must avoid a vanilla `cargo run` -inside of the `libc-test` directory (which is what it's intended for) because -that would compile `syntex_syntax`, a large library, with userspace emulation. -This invariably times out on Travis, so we can't do that. - -Once all those hoops are jumped through, however, we can be happy that we're -testing almost everything! - -Below are some details of how to set up the initial OS images which are -downloaded. Each image must be enabled have input/output over the serial -console, log in automatically at the serial console, detect if a second drive in -QEMU is available, and if so mount it, run a script (it'll specifically be -`run-qemu.sh` in this folder which is copied into the generated image talked -about above), and then shut down. - -### QEMU Setup - FreeBSD - -1. [Download the latest stable amd64-bootonly release ISO](https://www.freebsd.org/where.html). - E.g. FreeBSD-11.1-RELEASE-amd64-bootonly.iso -2. Create the disk image: `qemu-img create -f qcow2 FreeBSD-11.1-RELEASE-amd64.qcow2 2G` -3. Boot the machine: `qemu-system-x86_64 -cdrom FreeBSD-11.1-RELEASE-amd64-bootonly.iso -drive if=virtio,file=FreeBSD-11.1-RELEASE-amd64.qcow2 -net nic,model=virtio -net user` -4. Run the installer, and install FreeBSD: - 1. Install - 1. Continue with default keymap - 1. Set Hostname: freebsd-ci - 1. Distribution Select: - 1. Uncheck lib32 - 1. Uncheck ports - 1. Network Configuration: vtnet0 - 1. Configure IPv4? Yes - 1. DHCP? Yes - 1. Configure IPv6? No - 1. Resolver Configuration: Ok - 1. Mirror Selection: Main Site - 1. Partitioning: Auto (UFS) - 1. Partition: Entire Disk - 1. Partition Scheme: MBR - 1. App Partition: Ok - 1. Partition Editor: Finish - 1. Confirmation: Commit - 1. Wait for sets to install - 1. Set the root password to nothing (press enter twice) - 1. Set time zone to UTC - 1. Set Date: Skip - 1. Set Time: Skip - 1. System Configuration: - 1. Disable sshd - 1. Disable dumpdev - 1. System Hardening - 1. Disable Sendmail service - 1. Add User Accounts: No - 1. Final Configuration: Exit - 1. Manual Configuration: Yes - 1. `echo 'console="comconsole"' >> /boot/loader.conf` - 1. `echo 'autoboot_delay="0"' >> /boot/loader.conf` - 1. `echo 'ext2fs_load="YES"' >> /boot/loader.conf` - 1. Look at `/etc/ttys`, see what getty argument is for `ttyu0` (E.g. `3wire`) - 1. Edit `/etc/gettytab` (with `vi` for example), look for `ttyu0` argument, - prepend `:al=root` to the line beneath to have the machine auto-login as - root. E.g. - - 3wire:\ - :np:nc:sp#0: - becomes: - - 3wire:\ - :al=root:np:nc:sp#0: - - 1. Edit `/root/.login` and put this in it: - - [ -e /dev/vtbd1 ] || exit 0 - mount -t ext2fs /dev/vtbd1 /mnt - sh /mnt/run.sh /mnt - poweroff - - 1. Exit the post install shell: `exit` - 1. Back in in the installer choose Reboot - 1. If all went well the machine should reboot and show a login prompt. - If you switch to the serial console by choosing View > serial0 in - the qemu menu, you should be logged in as root. - 1. Shutdown the machine: `shutdown -p now` - -Helpful links - -* https://en.wikibooks.org/wiki/QEMU/Images -* https://blog.nekoconeko.nl/blog/2015/06/04/creating-an-openstack-freebsd-image.html -* https://www.freebsd.org/doc/handbook/serialconsole-setup.html - - -### QEMU setup - OpenBSD - -1. Download CD installer -2. `qemu-img create -f qcow2 foo.qcow2 2G` -3. `qemu -cdrom foo.iso -drive if=virtio,file=foo.qcow2 -net nic,model=virtio -net user` -4. run installer -5. `echo 'set tty com0' >> /etc/boot.conf` -6. `echo 'boot' >> /etc/boot.conf` -7. Modify /etc/ttys, change the `tty00` at the end from 'unknown off' to - 'vt220 on secure' -8. Modify same line in /etc/ttys to have `"/root/foo.sh"` as the shell -9. Add this script to `/root/foo.sh` - -``` -#!/bin/sh -exec 1>/dev/tty00 -exec 2>&1 - -if mount -t ext2fs /dev/sd1c /mnt; then - sh /mnt/run.sh /mnt - shutdown -ph now -fi - -# limited shell... -exec /bin/sh < /dev/tty00 -``` - -10. `chmod +x /root/foo.sh` - -Helpful links: - -* https://en.wikibooks.org/wiki/QEMU/Images -* http://www.openbsd.org/faq/faq7.html#SerCon - -# Questions? - -Hopefully that's at least somewhat of an introduction to everything going on -here, and feel free to ping @alexcrichton with questions! - diff --git a/libc/ci/android-install-ndk.sh b/libc/ci/android-install-ndk.sh deleted file mode 100644 index 723e719..0000000 --- a/libc/ci/android-install-ndk.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env sh -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -set -ex - -NDK=android-ndk-r19c -curl --retry 20 -O https://dl.google.com/android/repository/${NDK}-linux-x86_64.zip -unzip -q ${NDK}-linux-x86_64.zip - -case "$1" in - arm) - arch=arm - api=24 - ;; - armv7) - arch=arm - api=24 - ;; - aarch64) - arch=arm64 - api=24 - ;; - i686) - arch=x86 - api=28 - ;; - x86_64) - arch=x86_64 - api=28 - ;; - *) - echo "invalid arch: $1" - exit 1 - ;; -esac; - -${NDK}/build/tools/make_standalone_toolchain.py \ - --install-dir "/android/ndk-${1}" \ - --arch "${arch}" \ - --api ${api} - -rm -rf ./${NDK}-linux-x86_64.zip ./${NDK} diff --git a/libc/ci/android-install-sdk.sh b/libc/ci/android-install-sdk.sh deleted file mode 100644 index 7f21040..0000000 --- a/libc/ci/android-install-sdk.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env sh -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -set -ex - -# Prep the SDK and emulator -# -# Note that the update process requires that we accept a bunch of licenses, and -# we can't just pipe `yes` into it for some reason, so we take the same strategy -# located in https://github.com/appunite/docker by just wrapping it in a script -# which apparently magically accepts the licenses. - -SDK=4333796 -mkdir sdk -curl --retry 20 https://dl.google.com/android/repository/sdk-tools-linux-${SDK}.zip -O -unzip -q -d sdk sdk-tools-linux-${SDK}.zip - -case "$1" in - arm | armv7) - api=24 - image="system-images;android-${api};google_apis;armeabi-v7a" - ;; - aarch64) - api=24 - image="system-images;android-${api};google_apis;arm64-v8a" - ;; - i686) - api=28 - image="system-images;android-${api};default;x86" - ;; - x86_64) - api=28 - image="system-images;android-${api};default;x86_64" - ;; - *) - echo "invalid arch: $1" - exit 1 - ;; -esac; - -# Try to fix warning about missing file. -# See https://askubuntu.com/a/1078784 -mkdir -p /root/.android/ -echo '### User Sources for Android SDK Manager' >> /root/.android/repositories.cfg -echo '#Fri Nov 03 10:11:27 CET 2017 count=0' >> /root/.android/repositories.cfg - -# Print all available packages -# yes | ./sdk/tools/bin/sdkmanager --list --verbose - -# --no_https avoids -# javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found -# -# | grep -v = || true removes the progress bar output from the sdkmanager -# which produces an insane amount of output. -yes | ./sdk/tools/bin/sdkmanager --licenses --no_https | grep -v = || true -yes | ./sdk/tools/bin/sdkmanager --no_https \ - "emulator" \ - "platform-tools" \ - "platforms;android-${api}" \ - "${image}" | grep -v = || true - -echo "no" | - ./sdk/tools/bin/avdmanager create avd \ - --name "${1}" \ - --package "${image}" | grep -v = || true diff --git a/libc/ci/android-sysimage.sh b/libc/ci/android-sysimage.sh deleted file mode 100644 index 9eabd7c..0000000 --- a/libc/ci/android-sysimage.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -set -ex - -URL=https://dl.google.com/android/repository/sys-img/android - -main() { - local arch="${1}" - local name="${2}" - local dest=/system - local td - td="$(mktemp -d)" - - apt-get install --no-install-recommends e2tools - - pushd "${td}" - curl --retry 5 -O "${URL}/${name}" - unzip -q "${name}" - - local system - system="$(find . -name system.img)" - mkdir -p ${dest}/{bin,lib,lib64} - - # Extract android linker and libraries to /system - # This allows android executables to be run directly (or with qemu) - if [ "${arch}" = "x86_64" ] || [ "${arch}" = "arm64" ]; then - e2cp -p "${system}:/bin/linker64" "${dest}/bin/" - e2cp -p "${system}:/lib64/libdl.so" "${dest}/lib64/" - e2cp -p "${system}:/lib64/libc.so" "${dest}/lib64/" - e2cp -p "${system}:/lib64/libm.so" "${dest}/lib64/" - else - e2cp -p "${system}:/bin/linker" "${dest}/bin/" - e2cp -p "${system}:/lib/libdl.so" "${dest}/lib/" - e2cp -p "${system}:/lib/libc.so" "${dest}/lib/" - e2cp -p "${system}:/lib/libm.so" "${dest}/lib/" - fi - - # clean up - apt-get purge --auto-remove -y e2tools - - popd - - rm -rf "${td}" -} - -main "${@}" diff --git a/libc/ci/azure-install-rust.yml b/libc/ci/azure-install-rust.yml deleted file mode 100644 index 31b0714..0000000 --- a/libc/ci/azure-install-rust.yml +++ /dev/null @@ -1,82 +0,0 @@ -steps: - - bash: | - set -ex - toolchain=$TOOLCHAIN - if [ "$toolchain" = "" ]; then - toolchain=nightly - fi - if command -v rustup; then - # Uncomment when rustup on Azure is updated - #rustup set profile minimal - rustup update --force $toolchain - rustup default $toolchain - else - curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $toolchain --profile=minimal - echo "##vso[task.prependpath]$HOME/.cargo/bin" - fi - displayName: Install rust (unix) - condition: ne( variables['Agent.OS'], 'Windows_NT' ) - - script: | - @echo on - if not defined TOOLCHAIN set TOOLCHAIN=nightly - :: Uncomment when rustup on Azure is updated - ::rustup set profile minimal - rustup update --no-self-update %TOOLCHAIN%-%TARGET% - rustup default %TOOLCHAIN%-%TARGET% - displayName: Install rust (windows) - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - - script: | - set -ex - if [ -n "${TARGET}" ]; then - rustup target add $TARGET - fi - condition: ne( variables['Agent.OS'], 'Windows_NT' ) - displayName: Install target (unix) - - script: | - @echo on - if defined TARGET rustup target add %TARGET% - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - displayName: Install target (windows) - - script: | - @echo on - if "%ARCH%" == "i686" choco install mingw --x86 --force - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - displayName: Install MinGW32 (windows) - - bash: | - set -ex - gcc -print-search-dirs - find "C:\ProgramData\Chocolatey" -name "crt2*" - find "C:\ProgramData\Chocolatey" -name "dllcrt2*" - find "C:\ProgramData\Chocolatey" -name "libmsvcrt*" - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - displayName: Find GCC libraries (windows) - - bash: | - set -ex - if [[ -n ${ARCH_BITS} ]]; then - for i in crt2.o dllcrt2.o libmingwex.a libmsvcrt.a ; do - cp -f "/C/ProgramData/Chocolatey/lib/mingw/tools/install/mingw${ARCH_BITS}/${ARCH}-w64-mingw32/lib/$i" "`rustc --print sysroot`/lib/rustlib/${TARGET}/lib" - done - fi - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - displayName: Fix MinGW (windows) - - bash: | - set -ex - rustc -Vv - cargo -V - rustup -Vv - rustup show - which rustc - which cargo - which rustup - displayName: Query rust and cargo versions - - script: | - @echo on - where gcc - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - displayName: Query gcc path - - bash: | - set -ex - cargo generate-lockfile - cargo generate-lockfile --manifest-path libc-test/Cargo.toml - displayName: Generate lockfiles - diff --git a/libc/ci/azure-master.yml b/libc/ci/azure-master.yml deleted file mode 100644 index d7bcb7c..0000000 --- a/libc/ci/azure-master.yml +++ /dev/null @@ -1,22 +0,0 @@ -variables: - - group: secrets -resources: - repositories: - - repository: rustinfra - type: github - name: rust-lang/simpleinfra - endpoint: gnzlbg -trigger: ["master"] -pr: ["master"] - -jobs: - - job: StyleAndDocs - pool: - vmImage: ubuntu-16.04 - steps: - - template: azure-install-rust.yml - - script: LIBC_CI=1 sh ci/dox.sh - displayName: Generate documentation - - template: azure-configs/static-websites.yml@rustinfra - parameters: - deploy_dir: target/doc diff --git a/libc/ci/azure.yml b/libc/ci/azure.yml deleted file mode 100644 index da25a26..0000000 --- a/libc/ci/azure.yml +++ /dev/null @@ -1,228 +0,0 @@ -variables: - - group: secrets -resources: - repositories: - - repository: rustinfra - type: github - name: rust-lang/simpleinfra - endpoint: gnzlbg -trigger: ["auto-libc","try"] -pr: ["master"] - -jobs: - - job: DockerLinuxTier1 - pool: - vmImage: ubuntu-16.04 - steps: - - template: azure-install-rust.yml - - bash: LIBC_CI=1 sh ./ci/run-docker.sh $TARGET - displayName: Execute run-docker.sh - strategy: - matrix: - i686-unknown-linux-gnu: - TARGET: i686-unknown-linux-gnu - x86_64-unknown-linux-gnu: - TARGET: x86_64-unknown-linux-gnu - - - job: DockerLinuxTier2 - #dependsOn: DockerLinuxTier1 - pool: - vmImage: ubuntu-16.04 - steps: - - template: azure-install-rust.yml - - bash: LIBC_CI=1 sh ./ci/run-docker.sh $TARGET - displayName: Execute run-docker.sh - strategy: - matrix: - aarch64-unknown-linux-android: - TARGET: aarch64-linux-android - aarch64-unknown-linux-gnu: - TARGET: aarch64-unknown-linux-gnu - aarch64-unknown-linux-musl: - TARGET: aarch64-unknown-linux-musl - arm-linux-androideabi: - TARGET: arm-linux-androideabi - arm-unknown-linux-gnueabihf: - TARGET: arm-unknown-linux-gnueabihf - arm-unknown-linux-musleabihf: - TARGET: arm-unknown-linux-musleabihf - # Disabled because currently broken, see: - # https://github.com/rust-lang/libc/issues/1591 - # asmjs-unknown-emscripten: - # TARGET: asmjs-unknown-emscripten - i686-linux-android: - TARGET: i686-linux-android - i686-unknown-linux-musl: - TARGET: i686-unknown-linux-musl - mips-unknown-linux-gnu: - TARGET: mips-unknown-linux-gnu - mips-unknown-linux-musl: - TARGET: mips-unknown-linux-musl - mips64-unknown-linux-gnuabi64: - TARGET: mips64-unknown-linux-gnuabi64 - mips64el-unknown-linux-gnuabi64: - TARGET: mips64el-unknown-linux-gnuabi64 - mipsel-unknown-linux-musl: - TARGET: mipsel-unknown-linux-musl - #powerpc-unknown-linux-gnu: - # TARGET: powerpc-unknown-linux-gnu - powerpc64-unknown-linux-gnu: - TARGET: powerpc64-unknown-linux-gnu - powerpc64le-unknown-linux-gnu: - TARGET: powerpc64le-unknown-linux-gnu - #s390x-unknown-linux-gnu: - # TARGET: s390x-unknown-linux-gnu - #wasm32-wasi - # TARGET: wasm32-wasi - sparc64-unknown-linux-gnu: - TARGET: sparc64-unknown-linux-gnu - # Disabled because currently broken, see: - # https://github.com/rust-lang/libc/issues/1591 - # wasm32-unknown-emscripten: - # TARGET: wasm32-unknown-emscripten - x86_64-linux-android: - TARGET: x86_64-linux-android - x86_64-unknown-linux-gnux32: - TARGET: x86_64-unknown-linux-gnux32 - x86_64-unknown-linux-musl: - TARGET: x86_64-unknown-linux-musl - - - job: DockerOSX64 - pool: - vmImage: macos-10.14 - steps: - - template: azure-install-rust.yml - - bash: LIBC_CI=1 sh ./ci/run.sh $TARGET - displayName: Execute run.sh - strategy: - matrix: - x86_64-apple-darwin: - TARGET: x86_64-apple-darwin - - - job: DockerOSX32 - pool: - vmImage: macos-10.13 - steps: - - template: azure-install-rust.yml - - bash: LIBC_CI=1 sh ./ci/run.sh $TARGET - displayName: Execute run.sh - strategy: - matrix: - i686-apple-darwin: - TARGET: i686-apple-darwin - - - job: Windows - pool: - vmImage: vs2017-win2016 - steps: - - template: azure-install-rust.yml - - bash: LIBC_CI=1 sh ./ci/run.sh $TARGET - displayName: Execute run.sh - strategy: - matrix: - x86_64-pc-windows-gnu: - TARGET: x86_64-pc-windows-gnu - ARCH_BITS: 64 - ARCH: x86_64 - x86_64-pc-windows-msvc: - TARGET: x86_64-pc-windows-msvc - # Disabled because broken: - # https://github.com/rust-lang/libc/issues/1592 - #i686-pc-windows-gnu: - # TARGET: i686-pc-windows-gnu - # ARCH_BITS: 32 - # ARCH: i686 - i686-pc-windows-msvc: - TARGET: i686-pc-windows-msvc - - - job: StyleAndDocs - pool: - vmImage: ubuntu-16.04 - steps: - - template: azure-install-rust.yml - - script: sh ci/style.sh - displayName: Check style - - script: LIBC_CI=1 sh ci/dox.sh - displayName: Generate documentation - - template: azure-configs/static-websites.yml@rustinfra - parameters: - deploy_dir: target/doc - - # FIXME: re-enable these after the next release - #- job: SemverLinux - # dependsOn: BuildChannelsLinux - # continueOnError: true - # pool: - # vmImage: ubuntu-16.04 - # steps: - # - template: azure-install-rust.yml - # - script: sh ci/semver.sh linux - # displayName: Check breaking changes - - #- job: SemverOSX - # dependsOn: BuildChannelsOSX - # continueOnError: true - # pool: - # vmImage: macos-10.14 - # steps: - # - template: azure-install-rust.yml - # - script: sh ci/semver.sh osx - # displayName: Check breaking changes - - - job: BuildChannelsLinux - dependsOn: StyleAndDocs - pool: - vmImage: ubuntu-16.04 - steps: - - template: azure-install-rust.yml - - script: LIBC_CI=1 sh ./ci/build.sh - displayName: Execute build.sh - strategy: - matrix: - stable: - TOOLCHAIN: stable - beta: - TOOLCHAIN: beta - nightly: - TOOLCHAIN: nightly - 1.13.0: - TOOLCHAIN: 1.13.0 - 1.19.0: - TOOLCHAIN: 1.19.0 - 1.24.0: - TOOLCHAIN: 1.24.0 - 1.25.0: - TOOLCHAIN: 1.25.0 - 1.30.0: - TOOLCHAIN: 1.30.0 - variables: - OS: linux - - - job: BuildChannelsOSX - dependsOn: StyleAndDocs - pool: - vmImage: macos-10.13 - steps: - - template: azure-install-rust.yml - - script: LIBC_CI=1 sh ./ci/build.sh - displayName: Execute build.sh - strategy: - matrix: - stable: - TOOLCHAIN: stable - beta: - TOOLCHAIN: beta - nightly: - TOOLCHAIN: nightly - 1.13.0: - TOOLCHAIN: 1.13.0 - 1.19.0: - TOOLCHAIN: 1.19.0 - 1.24.0: - TOOLCHAIN: 1.24.0 - 1.25.0: - TOOLCHAIN: 1.25.0 - 1.30.0: - TOOLCHAIN: 1.30.0 - variables: - OS: osx diff --git a/libc/ci/build.sh b/libc/ci/build.sh deleted file mode 100644 index 082f0dc..0000000 --- a/libc/ci/build.sh +++ /dev/null @@ -1,272 +0,0 @@ -#!/usr/bin/env sh - -# Checks that libc builds properly for all supported targets on a particular -# Rust version: -# The FILTER environment variable can be used to select which target(s) to build. -# For example: set FILTER to vxworks to select the targets that has vxworks in name - -set -ex - -: "${TOOLCHAIN?The TOOLCHAIN environment variable must be set.}" -: "${OS?The OS environment variable must be set.}" - -RUST=${TOOLCHAIN} - -echo "Testing Rust ${RUST} on ${OS}" - -if [ "${TOOLCHAIN}" = "nightly" ] ; then - cargo +nightly install cargo-xbuild - rustup component add rust-src -fi - -test_target() { - BUILD_CMD="${1}" - TARGET="${2}" - NO_STD="${3}" - - opt= - if [ "${TARGET}" = "x86_64-unknown-linux-gnux32" ]; then - # FIXME: x86_64-unknown-linux-gnux32 fail to compile without - # --release - # - # See https://github.com/rust-lang/rust/issues/45417 - opt="--release" - fi - # FIXME: https://github.com/rust-lang/rust/issues/61174 - if [ "${TARGET}" = "sparcv9-sun-solaris" ] || - [ "${TARGET}" = "x86_64-sun-solaris" ]; then - return 0 - fi - - # If there is a std component, fetch it: - if [ "${NO_STD}" != "1" ]; then - # FIXME: rustup often fails to download some artifacts due to network - # issues, so we retry this N times. - N=5 - n=0 - until [ $n -ge $N ] - do - if rustup target add "${TARGET}" --toolchain "${RUST}" ; then - break - fi - n=$((n+1)) - sleep 1 - done - fi - - # Test that libc builds without any default features (no libstd) - cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --no-default-features --target "${TARGET}" - - # Test that libc builds with default features (e.g. libstd) - # if the target supports libstd - if [ "$NO_STD" != "1" ]; then - cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --target "${TARGET}" - fi - - # Test that libc builds with the `extra_traits` feature - cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --no-default-features --target "${TARGET}" \ - --features extra_traits - - # Test the 'const-extern-fn' feature on nightly - if [ "${RUST}" = "nightly" ]; then - cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --no-default-features --target "${TARGET}" \ - --features const-extern-fn - fi - - - # Also test that it builds with `extra_traits` and default features: - if [ "$NO_STD" != "1" ]; then - cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --target "${TARGET}" \ - --features extra_traits - fi -} - -RUST_LINUX_TARGETS="\ -aarch64-linux-android \ -aarch64-unknown-linux-gnu \ -arm-linux-androideabi \ -arm-unknown-linux-gnueabi \ -arm-unknown-linux-gnueabihf \ -armv7-linux-androideabi \ -armv7-unknown-linux-gnueabihf \ -i586-unknown-linux-gnu \ -i686-linux-android \ -i686-unknown-freebsd \ -i686-unknown-linux-gnu \ -i686-unknown-linux-musl \ -mips-unknown-linux-gnu \ -mips-unknown-linux-musl \ -mips64-unknown-linux-gnuabi64 \ -mips64el-unknown-linux-gnuabi64 \ -mipsel-unknown-linux-gnu \ -mipsel-unknown-linux-musl \ -powerpc-unknown-linux-gnu \ -powerpc64-unknown-linux-gnu \ -powerpc64le-unknown-linux-gnu \ -s390x-unknown-linux-gnu \ -x86_64-unknown-freebsd \ -x86_64-unknown-linux-gnu \ -x86_64-unknown-linux-musl \ -x86_64-unknown-netbsd \ -" - -RUST_GT_1_13_LINUX_TARGETS="\ -arm-unknown-linux-musleabi \ -arm-unknown-linux-musleabihf \ -armv7-unknown-linux-musleabihf \ -sparc64-unknown-linux-gnu \ -wasm32-unknown-emscripten \ -x86_64-linux-android \ -x86_64-rumprun-netbsd \ -" -RUST_GT_1_19_LINUX_TARGETS="\ -aarch64-unknown-linux-musl \ -sparcv9-sun-solaris \ -wasm32-unknown-unknown \ -x86_64-sun-solaris \ -" -RUST_GT_1_24_LINUX_TARGETS="\ -i586-unknown-linux-musl \ -x86_64-unknown-cloudabi \ -" - -# FIXME: temporarirly disable the redox target -# https://github.com/rust-lang/libc/issues/1457 -# x86_64-unknown-redox -RUST_NIGHTLY_LINUX_TARGETS="\ -aarch64-fuchsia \ -armv5te-unknown-linux-gnueabi \ -armv5te-unknown-linux-musleabi \ -i686-pc-windows-gnu \ -wasm32-wasi \ -x86_64-fortanix-unknown-sgx \ -x86_64-fuchsia \ -x86_64-pc-windows-gnu \ -x86_64-unknown-linux-gnux32 \ -" - -RUST_OSX_TARGETS="\ -aarch64-apple-ios \ -armv7-apple-ios \ -armv7s-apple-ios \ -i386-apple-ios \ -i686-apple-darwin \ -x86_64-apple-darwin \ -x86_64-apple-ios \ -" - -# The targets are listed here alphabetically -TARGETS="" -case "${OS}" in - linux*) - TARGETS="${RUST_LINUX_TARGETS}" - - if [ "${RUST}" != "1.13.0" ]; then - TARGETS="${TARGETS} ${RUST_GT_1_13_LINUX_TARGETS}" - if [ "${RUST}" != "1.19.0" ]; then - TARGETS="${TARGETS} ${RUST_GT_1_19_LINUX_TARGETS}" - if [ "${RUST}" != "1.24.0" ]; then - TARGETS="${TARGETS} ${RUST_GT_1_24_LINUX_TARGETS}" - fi - fi - fi - - if [ "${RUST}" = "nightly" ]; then - TARGETS="${TARGETS} ${RUST_NIGHTLY_LINUX_TARGETS}" - fi - - ;; - osx*) - TARGETS="${RUST_OSX_TARGETS}" - ;; - *) - ;; -esac - -for TARGET in $TARGETS; do - if echo "$TARGET"|grep -q "$FILTER";then - test_target build "$TARGET" - fi -done - -# FIXME: https://github.com/rust-lang/rust/issues/58564 -# sparc-unknown-linux-gnu -# FIXME: https://github.com/rust-lang/rust/issues/62932 -# thumbv6m-none-eabi -RUST_LINUX_NO_CORE_TARGETS="\ -aarch64-pc-windows-msvc \ -aarch64-unknown-cloudabi \ -aarch64-unknown-freebsd \ -aarch64-unknown-hermit \ -aarch64-unknown-netbsd \ -aarch64-unknown-openbsd \ -armebv7r-none-eabi \ -armebv7r-none-eabihf \ -armv7-unknown-cloudabi-eabihf \ -armv7r-none-eabi \ -armv7r-none-eabihf \ -hexagon-unknown-linux-musl \ -i586-pc-windows-msvc \ -i686-pc-windows-msvc \ -i686-unknown-cloudabi \ -i686-unknown-haiku \ -i686-unknown-netbsd \ -i686-unknown-openbsd \ -mips-unknown-linux-uclibc \ -mipsel-unknown-linux-uclibc \ -mips64-unknown-linux-muslabi64 \ -mips64el-unknown-linux-muslabi64 \ -nvptx64-nvidia-cuda \ -powerpc-unknown-linux-gnuspe \ -powerpc-unknown-netbsd \ -powerpc64-unknown-freebsd \ -riscv64gc-unknown-linux-gnu \ -riscv32imac-unknown-none-elf \ -riscv32imc-unknown-none-elf \ -sparc64-unknown-netbsd \ - -thumbv7em-none-eabi \ -thumbv7em-none-eabihf \ -thumbv7m-none-eabi \ -thumbv7neon-linux-androideabi \ -thumbv7neon-unknown-linux-gnueabihf \ -thumbv8m.main-none-eabi \ -x86_64-pc-windows-msvc -x86_64-unknown-dragonfly \ -x86_64-unknown-haiku \ -x86_64-unknown-hermit \ -x86_64-unknown-l4re-uclibc \ -x86_64-unknown-openbsd \ -armv7-wrs-vxworks-eabihf \ -aarch64-wrs-vxworks \ -i686-wrs-vxworks \ -x86_64-wrs-vxworks \ -powerpc-wrs-vxworks \ -powerpc-wrs-vxworks-spe \ -powerpc64-wrs-vxworks \ -" - -if [ "${RUST}" = "nightly" ] && [ "${OS}" = "linux" ]; then - for TARGET in $RUST_LINUX_NO_CORE_TARGETS; do - if echo "$TARGET"|grep -q "$FILTER";then - test_target xbuild "$TARGET" 1 - fi - done - - # Nintendo switch - cargo clean - mkdir -p target - ( - cd target - wget https://github.com/devkitPro/pacman/releases/download/devkitpro-pacman-1.0.1/devkitpro-pacman.deb - sudo dpkg -i devkitpro-pacman.deb - sudo dkp-pacman -Sy - sudo dkp-pacman -Syu - sudo dkp-pacman -S -v --noconfirm switch-dev devkitA64 - ) - cp ci/switch.json switch.json - PATH="$PATH:/opt/devkitpro/devkitA64/bin" - PATH="$PATH:/opt/devkitpro/tools/bin" - cargo xbuild --target switch.json -fi - diff --git a/libc/ci/docker/aarch64-linux-android/Dockerfile b/libc/ci/docker/aarch64-linux-android/Dockerfile deleted file mode 100644 index 6751dd9..0000000 --- a/libc/ci/docker/aarch64-linux-android/Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -FROM ubuntu:19.04 - -RUN dpkg --add-architecture i386 && \ - apt-get update && \ - apt-get install -y --no-install-recommends \ - file \ - curl \ - ca-certificates \ - python \ - unzip \ - expect \ - openjdk-8-jre \ - libstdc++6:i386 \ - libpulse0 \ - gcc \ - libc6-dev - -WORKDIR /android/ -COPY android* /android/ - -ENV ANDROID_ARCH=aarch64 -ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools - -RUN sh /android/android-install-ndk.sh $ANDROID_ARCH -RUN sh /android/android-install-sdk.sh $ANDROID_ARCH -RUN mv /root/.android /tmp -RUN chmod 777 -R /tmp/.android -RUN chmod 755 /android/sdk/tools/* /android/sdk/emulator/qemu/linux-x86_64/* - -ENV PATH=$PATH:/rust/bin \ - CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \ - CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER=/tmp/runtest \ - HOME=/tmp - -ADD runtest-android.rs /tmp/runtest.rs -ENTRYPOINT [ \ - "bash", \ - "-c", \ - # set SHELL so android can detect a 64bits system, see - # http://stackoverflow.com/a/41789144 - "SHELL=/bin/dash /android/sdk/emulator/emulator @aarch64 -no-window & \ - rustc /tmp/runtest.rs -o /tmp/runtest && \ - exec \"$@\"", \ - "--" \ -] diff --git a/libc/ci/docker/aarch64-unknown-linux-gnu/Dockerfile b/libc/ci/docker/aarch64-unknown-linux-gnu/Dockerfile deleted file mode 100644 index 716a445..0000000 --- a/libc/ci/docker/aarch64-unknown-linux-gnu/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM ubuntu:19.04 -RUN apt-get update && apt-get install -y --no-install-recommends \ - gcc libc6-dev ca-certificates \ - gcc-aarch64-linux-gnu libc6-dev-arm64-cross qemu-user -ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \ - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu" \ - PATH=$PATH:/rust/bin diff --git a/libc/ci/docker/aarch64-unknown-linux-musl/Dockerfile b/libc/ci/docker/aarch64-unknown-linux-musl/Dockerfile deleted file mode 100644 index e9634bf..0000000 --- a/libc/ci/docker/aarch64-unknown-linux-musl/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM ubuntu:19.04 - -RUN apt-get update && apt-get install -y --no-install-recommends \ - gcc make libc6-dev git curl ca-certificates \ - gcc-aarch64-linux-gnu qemu-user - -COPY install-musl.sh / -RUN sh /install-musl.sh aarch64 - -# FIXME: shouldn't need the `-lgcc` here, shouldn't that be in libstd? -ENV PATH=$PATH:/musl-aarch64/bin:/rust/bin \ - CC_aarch64_unknown_linux_musl=musl-gcc \ - RUSTFLAGS='-Clink-args=-lgcc' \ - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc \ - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER="qemu-aarch64 -L /musl-aarch64" diff --git a/libc/ci/docker/arm-linux-androideabi/Dockerfile b/libc/ci/docker/arm-linux-androideabi/Dockerfile deleted file mode 100644 index 544d167..0000000 --- a/libc/ci/docker/arm-linux-androideabi/Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -FROM ubuntu:19.04 - -RUN dpkg --add-architecture i386 && \ - apt-get update && \ - apt-get install -y --no-install-recommends \ - file \ - curl \ - ca-certificates \ - python \ - unzip \ - expect \ - openjdk-8-jre \ - libstdc++6:i386 \ - libpulse0 \ - gcc \ - libc6-dev - -WORKDIR /android/ -COPY android* /android/ - -ENV ANDROID_ARCH=arm -ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools - -RUN sh /android/android-install-ndk.sh $ANDROID_ARCH -RUN sh /android/android-install-sdk.sh $ANDROID_ARCH -RUN mv /root/.android /tmp -RUN chmod 777 -R /tmp/.android -RUN chmod 755 /android/sdk/tools/* /android/sdk/emulator/qemu/linux-x86_64/* - -ENV PATH=$PATH:/rust/bin \ - CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \ - CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER=/tmp/runtest \ - HOME=/tmp - -ADD runtest-android.rs /tmp/runtest.rs -ENTRYPOINT [ \ - "bash", \ - "-c", \ - # set SHELL so android can detect a 64bits system, see - # http://stackoverflow.com/a/41789144 - "SHELL=/bin/dash /android/sdk/emulator/emulator @arm -no-window & \ - rustc /tmp/runtest.rs -o /tmp/runtest && \ - exec \"$@\"", \ - "--" \ -] diff --git a/libc/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile b/libc/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile deleted file mode 100644 index bcdbb22..0000000 --- a/libc/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM ubuntu:19.04 -RUN apt-get update && apt-get install -y --no-install-recommends \ - gcc libc6-dev ca-certificates \ - gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user -ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ - CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf" \ - PATH=$PATH:/rust/bin diff --git a/libc/ci/docker/arm-unknown-linux-musleabihf/Dockerfile b/libc/ci/docker/arm-unknown-linux-musleabihf/Dockerfile deleted file mode 100644 index 639b141..0000000 --- a/libc/ci/docker/arm-unknown-linux-musleabihf/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM ubuntu:19.04 - -RUN apt-get update && apt-get install -y --no-install-recommends \ - gcc make libc6-dev git curl ca-certificates \ - gcc-arm-linux-gnueabihf qemu-user - -COPY install-musl.sh / -RUN sh /install-musl.sh arm - -ENV PATH=$PATH:/musl-arm/bin:/rust/bin \ - CC_arm_unknown_linux_musleabihf=musl-gcc \ - CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=musl-gcc \ - CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_RUNNER="qemu-arm -L /musl-arm" diff --git a/libc/ci/docker/asmjs-unknown-emscripten/Dockerfile b/libc/ci/docker/asmjs-unknown-emscripten/Dockerfile deleted file mode 100644 index 64f73aa..0000000 --- a/libc/ci/docker/asmjs-unknown-emscripten/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM ubuntu:19.04 - -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates \ - curl \ - gcc \ - git \ - libc6-dev \ - libxml2 \ - python \ - xz-utils - -COPY emscripten.sh / -RUN bash /emscripten.sh - -ENV PATH=$PATH:/rust/bin \ - CARGO_TARGET_ASMJS_UNKNOWN_EMSCRIPTEN_RUNNER=node - -COPY emscripten-entry.sh / -ENTRYPOINT ["/emscripten-entry.sh"] diff --git a/libc/ci/docker/i686-linux-android/Dockerfile b/libc/ci/docker/i686-linux-android/Dockerfile deleted file mode 100644 index 5403220..0000000 --- a/libc/ci/docker/i686-linux-android/Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -FROM ubuntu:19.04 - -RUN dpkg --add-architecture i386 && \ - apt-get update && \ - apt-get install -y --no-install-recommends \ - file \ - curl \ - ca-certificates \ - python \ - unzip \ - expect \ - openjdk-8-jre \ - libstdc++6:i386 \ - libpulse0 \ - gcc \ - libc6-dev - -WORKDIR /android/ -COPY android* /android/ - -ENV ANDROID_ARCH=i686 -ENV PATH=$PATH:/android/ndk-$ANDROID_ARCH/bin:/android/sdk/tools:/android/sdk/platform-tools - -RUN sh /android/android-install-ndk.sh $ANDROID_ARCH -RUN sh /android/android-install-sdk.sh $ANDROID_ARCH -RUN mv /root/.android /tmp -RUN chmod 777 -R /tmp/.android -RUN chmod 755 /android/sdk/tools/* /android/sdk/emulator/qemu/linux-x86_64/* - -ENV PATH=$PATH:/rust/bin \ - CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \ - CARGO_TARGET_I686_LINUX_ANDROID_RUNNER=/tmp/runtest \ - HOME=/tmp - -ADD runtest-android.rs /tmp/runtest.rs -ENTRYPOINT [ \ - "bash", \ - "-c", \ - # set SHELL so android can detect a 64bits system, see - # http://stackoverflow.com/a/41789144 - "SHELL=/bin/dash /android/sdk/emulator/emulator @i686 -no-window -no-accel & \ - rustc /tmp/runtest.rs -o /tmp/runtest && \ - exec \"$@\"", \ - "--" \ -] diff --git a/libc/ci/docker/i686-unknown-linux-gnu/Dockerfile b/libc/ci/docker/i686-unknown-linux-gnu/Dockerfile deleted file mode 100644 index 5563a7b..0000000 --- a/libc/ci/docker/i686-unknown-linux-gnu/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM ubuntu:19.04 -RUN apt-get update -RUN apt-get install -y --no-install-recommends \ - gcc-multilib libc6-dev ca-certificates -ENV PATH=$PATH:/rust/bin diff --git a/libc/ci/docker/i686-unknown-linux-musl/Dockerfile b/libc/ci/docker/i686-unknown-linux-musl/Dockerfile deleted file mode 100644 index ac76a32..0000000 --- a/libc/ci/docker/i686-unknown-linux-musl/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM ubuntu:19.04 - -RUN dpkg --add-architecture i386 -RUN apt-get update -RUN apt-get install -y --no-install-recommends \ - gcc-multilib make libc6-dev git curl ca-certificates libc6:i386 - -COPY install-musl.sh / -RUN sh /install-musl.sh i686 - -ENV PATH=$PATH:/musl-i686/bin:/rust/bin \ - CC_i686_unknown_linux_musl=musl-gcc diff --git a/libc/ci/docker/mips-unknown-linux-gnu/Dockerfile b/libc/ci/docker/mips-unknown-linux-gnu/Dockerfile deleted file mode 100644 index c8623a5..0000000 --- a/libc/ci/docker/mips-unknown-linux-gnu/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM ubuntu:19.04 - -RUN apt-get update && apt-get install -y --no-install-recommends \ - gcc libc6-dev qemu-user ca-certificates \ - gcc-mips-linux-gnu libc6-dev-mips-cross \ - qemu-system-mips linux-headers-generic - -ENV CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc \ - CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_RUNNER="qemu-mips -L /usr/mips-linux-gnu" \ - PATH=$PATH:/rust/bin diff --git a/libc/ci/docker/mips-unknown-linux-musl/Dockerfile b/libc/ci/docker/mips-unknown-linux-musl/Dockerfile deleted file mode 100644 index a1ec7ff..0000000 --- a/libc/ci/docker/mips-unknown-linux-musl/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM ubuntu:19.04 - -RUN apt-get update && apt-get install -y --no-install-recommends \ - gcc libc6-dev qemu-user ca-certificates qemu-system-mips curl \ - xz-utils patch - -RUN mkdir /toolchain - -# Linux kernel version: 4.14.151 -# See build_dir/target-mips_24kc_musl/linux-ar71xx_generic/linux-4.14.151 -# Musl version: 1.1.24 -# See staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/info.mk -RUN curl --retry 5 -L https://downloads.openwrt.org/releases/19.07.0-rc1/targets/ar71xx/generic/openwrt-sdk-19.07.0-rc1-ar71xx-generic_gcc-7.4.0_musl.Linux-x86_64.tar.xz | \ - tar xJf - -C /toolchain --strip-components=1 - -# See https://lkml.org/lkml/2014/3/14/269 -COPY sysinfo_guard.patch /toolchain -RUN patch /toolchain/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/include/linux/kernel.h ) { - for line in BufReader::new(input).lines() { - let line = line.unwrap(); - println!("{}", line); - if (line.starts_with("PASSED ") && line.contains(" tests")) || - line.starts_with("test result: ok"){ - tx.send(()).unwrap(); - } - } -} diff --git a/libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile b/libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile deleted file mode 100644 index bfa2b17..0000000 --- a/libc/ci/docker/x86_64-unknown-linux-gnu/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM ubuntu:19.04 -RUN apt-get update -RUN apt-get install -y --no-install-recommends \ - gcc libc6-dev ca-certificates linux-headers-generic - -RUN apt search linux-headers -RUN ls /usr/src - -ENV PATH=$PATH:/rust/bin diff --git a/libc/ci/docker/x86_64-unknown-linux-gnux32/Dockerfile b/libc/ci/docker/x86_64-unknown-linux-gnux32/Dockerfile deleted file mode 100644 index 5563a7b..0000000 --- a/libc/ci/docker/x86_64-unknown-linux-gnux32/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM ubuntu:19.04 -RUN apt-get update -RUN apt-get install -y --no-install-recommends \ - gcc-multilib libc6-dev ca-certificates -ENV PATH=$PATH:/rust/bin diff --git a/libc/ci/docker/x86_64-unknown-linux-musl/Dockerfile b/libc/ci/docker/x86_64-unknown-linux-musl/Dockerfile deleted file mode 100644 index 06a081b..0000000 --- a/libc/ci/docker/x86_64-unknown-linux-musl/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM ubuntu:19.04 - -RUN apt-get update -RUN apt-get install -y --no-install-recommends \ - gcc make libc6-dev git curl ca-certificates - -COPY install-musl.sh / -RUN sh /install-musl.sh x86_64 - -ENV PATH=$PATH:/musl-x86_64/bin:/rust/bin diff --git a/libc/ci/dox.sh b/libc/ci/dox.sh deleted file mode 100644 index 271b54b..0000000 --- a/libc/ci/dox.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env sh - -# Builds documentation for all target triples that we have a registered URL for -# in liblibc. This scrapes the list of triples to document from `src/lib.rs` -# which has a bunch of `html_root_url` directives we pick up. - -set -ex - -TARGET_DOC_DIR=target/doc -README=README.md -PLATFORM_SUPPORT=platform-support.md - -rm -rf $TARGET_DOC_DIR -mkdir -p $TARGET_DOC_DIR - -if ! rustc --version | grep -E "nightly" ; then - echo "Building the documentation requires a nightly Rust toolchain" - exit 1 -fi - -rustup component add rust-src -cargo +nightly install cargo-xbuild - -# List all targets that do currently build successfully: -# shellcheck disable=SC1003 -grep '[\d|\w|-]* \\' ci/build.sh > targets -sed -i.bak 's/ \\//g' targets -grep '^[_a-zA-Z0-9-]*$' targets | sort > tmp && mv tmp targets - -# Create a markdown list of supported platforms in $PLATFORM_SUPPORT -rm $PLATFORM_SUPPORT || true - -printf '### Platform-specific documentation\n' >> $PLATFORM_SUPPORT - -while read -r target; do - echo "documenting ${target}" - - case "${target}" in - *apple*) - # FIXME: - # We can't build docs of apple targets from Linux yet. - continue - ;; - *) - ;; - esac - - rustup target add "${target}" || true - - # Enable extra configuration flags: - export RUSTDOCFLAGS="--cfg freebsd11" - - # If cargo doc fails, then try xargo: - if ! cargo doc --target "${target}" \ - --no-default-features --features extra_traits ; then - cargo xdoc --target "${target}" \ - --no-default-features --features extra_traits - fi - - cp -r "target/${target}/doc" "${TARGET_DOC_DIR}/${target}" - - echo "* [${target}](${target}/libc/index.html)" >> $PLATFORM_SUPPORT -done < targets - -# Replace
with the contents of $PLATFORM_SUPPORT -cp $README $TARGET_DOC_DIR -line=$(grep -n '
' $README | cut -d ":" -f 1) - -set +x -{ head -n "$((line-1))" $README; cat $PLATFORM_SUPPORT; tail -n "+$((line+1))" $README; } > $TARGET_DOC_DIR/$README -set -x - -# Copy the licenses -cp LICENSE-* $TARGET_DOC_DIR/ diff --git a/libc/ci/emscripten-entry.sh b/libc/ci/emscripten-entry.sh deleted file mode 100755 index 0016f56..0000000 --- a/libc/ci/emscripten-entry.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2017 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -set -ex - -# shellcheck disable=SC1091 -source /emsdk-portable/emsdk_env.sh &> /dev/null - -# emsdk-portable provides a node binary, but we need version 8 to run wasm -export PATH="/node-v12.3.1-linux-x64/bin:$PATH" - -exec "$@" diff --git a/libc/ci/emscripten.sh b/libc/ci/emscripten.sh deleted file mode 100644 index acec4ca..0000000 --- a/libc/ci/emscripten.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2017 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -set -ex - -hide_output() { - set +x - on_err=" -echo ERROR: An error was encountered with the build. -cat /tmp/build.log -exit 1 -" - trap '$on_err' ERR - bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & - PING_LOOP_PID=$! - "${@}" &> /tmp/build.log - trap - ERR - kill $PING_LOOP_PID - rm -f /tmp/build.log - set -x -} - -git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable -cd /emsdk-portable -# TODO: switch to an upstream install once -# https://github.com/rust-lang/rust/pull/63649 lands -hide_output ./emsdk install 1.38.42 -./emsdk activate 1.38.42 - -# Compile and cache libc -# shellcheck disable=SC1091 -source ./emsdk_env.sh -echo "main(){}" > a.c -HOME=/emsdk-portable/ emcc a.c -rm -f a.* - -# Make emsdk usable by any user -cp /root/.emscripten /emsdk-portable -chmod a+rxw -R /emsdk-portable - -# node 8 is required to run wasm -cd / -curl --retry 5 -L https://nodejs.org/dist/v12.3.1/node-v12.3.1-linux-x64.tar.xz | \ - tar -xJ diff --git a/libc/ci/install-musl.sh b/libc/ci/install-musl.sh deleted file mode 100644 index 88cb4f0..0000000 --- a/libc/ci/install-musl.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env sh -# -# Install musl and musl-sanitized linux kernel headers -# to musl-{$1} directory - -set -ex - -MUSL_VERSION=1.1.24 -MUSL="musl-${MUSL_VERSION}" - -# Download, configure, build, and install musl: -curl --retry 5 https://www.musl-libc.org/releases/${MUSL}.tar.gz | tar xzf - - -cd $MUSL -case ${1} in - aarch64) - musl_arch=aarch64 - kernel_arch=arm64 - CC=aarch64-linux-gnu-gcc \ - ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes - make install -j4 - ;; - arm) - musl_arch=arm - kernel_arch=arm - CC=arm-linux-gnueabihf-gcc CFLAGS="-march=armv6 -marm -mfpu=vfp" \ - ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes - make install -j4 - ;; - i686) - # cross-compile musl for i686 using the system compiler on an x86_64 - # system. - musl_arch=i686 - kernel_arch=i386 - # Specifically pass -m32 in CFLAGS and override CC when running - # ./configure, since otherwise the script will fail to find a compiler. - CC=gcc CFLAGS="-m32" \ - ./configure --prefix="/musl-${musl_arch}" --disable-shared --target=i686 - # unset CROSS_COMPILE when running make; otherwise the makefile will - # call the non-existent binary 'i686-ar'. - make CROSS_COMPILE= install -j4 - ;; - x86_64) - musl_arch=x86_64 - kernel_arch=x86_64 - ./configure --prefix="/musl-${musl_arch}" - make install -j4 - ;; - mips64) - musl_arch=mips64 - kernel_arch=mips - CC=mips64-linux-gnuabi64-gcc CFLAGS="-march=mips64r2 -mabi=64" \ - ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes - make install -j4 - ;; - mips64el) - musl_arch=mips64el - kernel_arch=mips - CC=mips64el-linux-gnuabi64-gcc CFLAGS="-march=mips64r2 -mabi=64" \ - ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes - make install -j4 - ;; - *) - echo "Unknown target arch: \"${1}\"" - exit 1 - ;; -esac - - -# shellcheck disable=SC2103 -cd .. -rm -rf $MUSL - -# Download, configure, build, and install musl-sanitized kernel headers: -KERNEL_HEADER_VER="4.4.2-2" -curl --retry 5 -L \ - "https://github.com/sabotage-linux/kernel-headers/archive/v${KERNEL_HEADER_VER}.tar.gz" | \ - tar xzf - -( - cd kernel-headers-${KERNEL_HEADER_VER} - make ARCH="${kernel_arch}" prefix="/musl-${musl_arch}" install -j4 -) -rm -rf kernel-headers-${KERNEL_HEADER_VER} diff --git a/libc/ci/ios/deploy_and_run_on_ios_simulator.rs b/libc/ci/ios/deploy_and_run_on_ios_simulator.rs deleted file mode 100644 index 2075be6..0000000 --- a/libc/ci/ios/deploy_and_run_on_ios_simulator.rs +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This is a script to deploy and execute a binary on an iOS simulator. -// The primary use of this is to be able to run unit tests on the simulator and -// retrieve the results. -// -// To do this through Cargo instead, use Dinghy -// (https://github.com/snipsco/dinghy): cargo dinghy install, then cargo dinghy -// test. - -use std::env; -use std::fs::{self, File}; -use std::io::Write; -use std::path::Path; -use std::process; -use std::process::Command; - -macro_rules! t { - ($e:expr) => (match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with: {}", stringify!($e), e), - }) -} - -// Step one: Wrap as an app -fn package_as_simulator_app(crate_name: &str, test_binary_path: &Path) { - println!("Packaging simulator app"); - drop(fs::remove_dir_all("ios_simulator_app")); - t!(fs::create_dir("ios_simulator_app")); - t!(fs::copy(test_binary_path, - Path::new("ios_simulator_app").join(crate_name))); - - let mut f = t!(File::create("ios_simulator_app/Info.plist")); - t!(f.write_all(format!(r#" - - - - - CFBundleExecutable - {} - CFBundleIdentifier - com.rust.unittests - - - "#, crate_name).as_bytes())); -} - -// Step two: Start the iOS simulator -fn start_simulator() { - println!("Looking for iOS simulator"); - let output = t!(Command::new("xcrun").arg("simctl").arg("list").output()); - assert!(output.status.success()); - let mut simulator_exists = false; - let mut simulator_booted = false; - let mut found_rust_sim = false; - let stdout = t!(String::from_utf8(output.stdout)); - for line in stdout.lines() { - if line.contains("rust_ios") { - if found_rust_sim { - panic!("Duplicate rust_ios simulators found. Please \ - double-check xcrun simctl list."); - } - simulator_exists = true; - simulator_booted = line.contains("(Booted)"); - found_rust_sim = true; - } - } - - if simulator_exists == false { - println!("Creating iOS simulator"); - Command::new("xcrun") - .arg("simctl") - .arg("create") - .arg("rust_ios") - .arg("com.apple.CoreSimulator.SimDeviceType.iPhone-SE") - .arg("com.apple.CoreSimulator.SimRuntime.iOS-10-2") - .check_status(); - } else if simulator_booted == true { - println!("Shutting down already-booted simulator"); - Command::new("xcrun") - .arg("simctl") - .arg("shutdown") - .arg("rust_ios") - .check_status(); - } - - println!("Starting iOS simulator"); - // We can't uninstall the app (if present) as that will hang if the - // simulator isn't completely booted; just erase the simulator instead. - Command::new("xcrun").arg("simctl").arg("erase").arg("rust_ios").check_status(); - Command::new("xcrun").arg("simctl").arg("boot").arg("rust_ios").check_status(); -} - -// Step three: Install the app -fn install_app_to_simulator() { - println!("Installing app to simulator"); - Command::new("xcrun") - .arg("simctl") - .arg("install") - .arg("booted") - .arg("ios_simulator_app/") - .check_status(); -} - -// Step four: Run the app -fn run_app_on_simulator() { - println!("Running app"); - let output = t!(Command::new("xcrun") - .arg("simctl") - .arg("launch") - .arg("--console") - .arg("booted") - .arg("com.rust.unittests") - .output()); - - println!("status: {}", output.status); - println!("stdout --\n{}\n", String::from_utf8_lossy(&output.stdout)); - println!("stderr --\n{}\n", String::from_utf8_lossy(&output.stderr)); - - let stdout = String::from_utf8_lossy(&output.stdout); - let passed = stdout.lines() - .find(|l| - (l.contains("PASSED") && - l.contains("tests")) || - l.contains("test result: ok") - ) - .unwrap_or(false); - - println!("Shutting down simulator"); - Command::new("xcrun") - .arg("simctl") - .arg("shutdown") - .arg("rust_ios") - .check_status(); - if !passed { - panic!("tests didn't pass"); - } -} - -trait CheckStatus { - fn check_status(&mut self); -} - -impl CheckStatus for Command { - fn check_status(&mut self) { - println!("\trunning: {:?}", self); - assert!(t!(self.status()).success()); - } -} - -fn main() { - let args: Vec = env::args().collect(); - if args.len() != 2 { - println!("Usage: {} ", args[0]); - process::exit(-1); - } - - let test_binary_path = Path::new(&args[1]); - let crate_name = test_binary_path.file_name().unwrap(); - - package_as_simulator_app(crate_name.to_str().unwrap(), test_binary_path); - start_simulator(); - install_app_to_simulator(); - run_app_on_simulator(); -} diff --git a/libc/ci/linux-s390x.sh b/libc/ci/linux-s390x.sh deleted file mode 100644 index 00a7f88..0000000 --- a/libc/ci/linux-s390x.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env sh - -set -ex - -mkdir -m 777 /qemu -cd /qemu - -curl --retry 5 -LO https://github.com/qemu/qemu/raw/master/pc-bios/s390-ccw.img -curl --retry 5 -LO http://ftp.debian.org/debian/dists/testing/main/installer-s390x/20190410/images/generic/kernel.debian -curl --retry 5 -LO http://ftp.debian.org/debian/dists/testing/main/installer-s390x/20190410/images/generic/initrd.debian - -mv kernel.debian kernel -mv initrd.debian initrd.gz - -mkdir init -cd init -gunzip -c ../initrd.gz | cpio -id -rm ../initrd.gz -cp /usr/s390x-linux-gnu/lib/libgcc_s.so.1 usr/lib/ -chmod a+w . diff --git a/libc/ci/linux-sparc64.sh b/libc/ci/linux-sparc64.sh deleted file mode 100644 index 5580a0e..0000000 --- a/libc/ci/linux-sparc64.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh - -set -ex - -mkdir -m 777 /qemu -cd /qemu - -curl --retry 5 -LO https://cdimage.debian.org/cdimage/ports/10.0/sparc64/iso-cd/debian-10.0-sparc64-NETINST-1.iso -7z e debian-10.0-sparc64-NETINST-1.iso boot/initrd.gz -7z e debian-10.0-sparc64-NETINST-1.iso boot/sparc64 -mv sparc64 kernel -rm debian-10.0-sparc64-NETINST-1.iso - -mkdir init -cd init -gunzip -c ../initrd.gz | cpio -id -rm ../initrd.gz -cp /usr/sparc64-linux-gnu/lib/libgcc_s.so.1 usr/lib/ -chmod a+w . diff --git a/libc/ci/run-docker.sh b/libc/ci/run-docker.sh deleted file mode 100755 index 3c0736a..0000000 --- a/libc/ci/run-docker.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env sh - -# Small script to run tests for a target (or all targets) inside all the -# respective docker images. - -set -ex - -echo "${HOME}" -pwd - -run() { - echo "Building docker container for target ${1}" - - # use -f so we can use ci/ as build context - docker build -t libc -f "ci/docker/${1}/Dockerfile" ci/ - mkdir -p target - if [ -w /dev/kvm ]; then - kvm="--volume /dev/kvm:/dev/kvm" - else - kvm="" - fi - - docker run \ - --rm \ - --user "$(id -u)":"$(id -g)" \ - --env LIBC_CI \ - --env CARGO_HOME=/cargo \ - --env CARGO_TARGET_DIR=/checkout/target \ - --volume "$(dirname "$(dirname "$(command -v cargo)")")":/cargo \ - --volume "$(rustc --print sysroot)":/rust:ro \ - --volume "$(pwd)":/checkout:ro \ - --volume "$(pwd)"/target:/checkout/target \ - $kvm \ - --init \ - --workdir /checkout \ - libc \ - sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/run.sh ${1}" -} - -if [ -z "${1}" ]; then - for d in ci/docker/*; do - run "${d}" - done -else - run "${1}" -fi diff --git a/libc/ci/run-qemu.sh b/libc/ci/run-qemu.sh deleted file mode 100644 index 6fba629..0000000 --- a/libc/ci/run-qemu.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env sh - -# Initial script which is run inside of all qemu images. The first argument to -# this script (as arranged by the qemu image itself) is the path to where the -# libc crate is mounted. -# -# For qemu images we currently need to install Rust manually as this wasn't done -# by the initial run-travis.sh script -# -# FIXME: feels like run-travis.sh should be responsible for downloading the -# compiler. - -set -ex - -ROOT="${1}" -cp -r "${ROOT}/libc" /tmp/libc -cd /tmp/libc - -TARGET="$(cat "${ROOT}/TARGET")" -export CARGO_TARGET_DIR=/tmp - -case $TARGET in - *-openbsd) - pkg_add cargo gcc%4.9 rust - export CC=egcc - ;; - - *) - echo "Unknown target: ${TARGET}" - exit 1 - ;; -esac - -exec sh ci/run.sh "${TARGET}" diff --git a/libc/ci/run.sh b/libc/ci/run.sh deleted file mode 100755 index b435122..0000000 --- a/libc/ci/run.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env sh - -# Builds and runs tests for a particular target passed as an argument to this -# script. - -set -ex - -MIRRORS_URL="https://ci-mirrors.rust-lang.org/libc" - -TARGET="${1}" - -# If we're going to run tests inside of a qemu image, then we don't need any of -# the scripts below. Instead, download the image, prepare a filesystem which has -# the current state of this repository, and then run the image. -# -# It's assume that all images, when run with two disks, will run the `run.sh` -# script from the second which we place inside. -if [ "$QEMU" != "" ]; then - tmpdir=/tmp/qemu-img-creation - mkdir -p "${tmpdir}" - - if [ -z "${QEMU#*.gz}" ]; then - # image is .gz : download and uncompress it - qemufile="$(echo "${QEMU%.gz}" | sed 's/\//__/g')" - if [ ! -f "${tmpdir}/${qemufile}" ]; then - curl --retry 5 "${MIRRORS_URL}/${QEMU}" | \ - gunzip -d > "${tmpdir}/${qemufile}" - fi - elif [ -z "${QEMU#*.xz}" ]; then - # image is .xz : download and uncompress it - qemufile="$(echo "${QEMU%.xz}" | sed 's/\//__/g')" - if [ ! -f "${tmpdir}/${qemufile}" ]; then - curl --retry 5 "${MIRRORS_URL}/${QEMU}" | \ - unxz > "${tmpdir}/${qemufile}" - fi - else - # plain qcow2 image: just download it - qemufile="$(echo "${QEMU}" | sed 's/\//__/g')" - if [ ! -f "${tmpdir}/${qemufile}" ]; then - curl --retry 5 "${MIRRORS_URL}/${QEMU}" | \ - > "${tmpdir}/${qemufile}" - fi - fi - - # Create a mount a fresh new filesystem image that we'll later pass to QEMU. - # This will have a `run.sh` script will which use the artifacts inside to run - # on the host. - rm -f "${tmpdir}/libc-test.img" - mkdir "${tmpdir}/mount" - - # Do the standard rigamarole of cross-compiling an executable and then the - # script to run just executes the binary. - cargo build \ - --manifest-path libc-test/Cargo.toml \ - --target "${TARGET}" \ - --test main - rm "${CARGO_TARGET_DIR}/${TARGET}"/debug/main-*.d - cp "${CARGO_TARGET_DIR}/${TARGET}"/debug/main-* "${tmpdir}"/mount/libc-test - # shellcheck disable=SC2016 - echo 'exec $1/libc-test' > "${tmpdir}/mount/run.sh" - - du -sh "${tmpdir}/mount" - genext2fs \ - --root "${tmpdir}/mount" \ - --size-in-blocks 100000 \ - "${tmpdir}/libc-test.img" - - # Pass -snapshot to prevent tampering with the disk images, this helps when - # running this script in development. The two drives are then passed next, - # first is the OS and second is the one we just made. Next the network is - # configured to work (I'm not entirely sure how), and then finally we turn off - # graphics and redirect the serial console output to out.log. - qemu-system-x86_64 \ - -m 1024 \ - -snapshot \ - -drive if=virtio,file="${tmpdir}/${qemufile}" \ - -drive if=virtio,file="${tmpdir}/libc-test.img" \ - -net nic,model=virtio \ - -net user \ - -nographic \ - -vga none 2>&1 | tee "${CARGO_TARGET_DIR}/out.log" - exec egrep "^(PASSED)|(test result: ok)" "${CARGO_TARGET_DIR}/out.log" -fi - -# FIXME: x86_64-unknown-linux-gnux32 fail to compile without --release -# See https://github.com/rust-lang/rust/issues/45417 -opt= -if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then - opt="--release" -fi - -cargo test -vv $opt --no-default-features --manifest-path libc-test/Cargo.toml \ - --target "${TARGET}" - -cargo test -vv $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}" - -cargo test -vv $opt --features extra_traits --manifest-path libc-test/Cargo.toml \ - --target "${TARGET}" diff --git a/libc/ci/runtest-android.rs b/libc/ci/runtest-android.rs deleted file mode 100644 index b8030c4..0000000 --- a/libc/ci/runtest-android.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::env; -use std::process::Command; -use std::path::{Path, PathBuf}; - -fn main() { - let args = env::args_os() - .skip(1) - .filter(|arg| arg != "--quiet") - .collect::>(); - assert_eq!(args.len(), 1); - let test = PathBuf::from(&args[0]); - let dst = Path::new("/data/local/tmp").join(test.file_name().unwrap()); - - let status = Command::new("adb") - .arg("wait-for-device") - .status() - .expect("failed to run: adb wait-for-device"); - assert!(status.success()); - - let status = Command::new("adb") - .arg("push") - .arg(&test) - .arg(&dst) - .status() - .expect("failed to run: adb pushr"); - assert!(status.success()); - - let output = Command::new("adb") - .arg("shell") - .arg(&dst) - .output() - .expect("failed to run: adb shell"); - assert!(status.success()); - - println!("status: {}\nstdout ---\n{}\nstderr ---\n{}", - output.status, - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr)); - - let stdout = String::from_utf8_lossy(&output.stdout); - stdout.lines().find(|l| - (l.starts_with("PASSED ") && l.contains(" tests")) || - l.starts_with("test result: ok") - ).unwrap_or_else(|| { - panic!("failed to find successful test run"); - }); -} diff --git a/libc/ci/semver.sh b/libc/ci/semver.sh deleted file mode 100644 index 7e6ea66..0000000 --- a/libc/ci/semver.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env sh - -# Checks that libc does not contain breaking changes for the following targets. - -set -ex - -OS=${1} - -echo "Testing Semver on ${OS}" - -if ! rustc --version | grep -E "nightly" ; then - echo "Building semverver requires a nightly Rust toolchain" - exit 1 -fi - -cargo +nightly install semverver - -TARGETS= -case "${OS}" in - *linux*) - TARGETS="\ -aarch64-fuchsia \ -aarch64-linux-android \ -aarch64-unknown-linux-gnu \ -aarch64-unknown-linux-musl \ -armv7-linux-androideabi \ -armv7-unknown-linux-gnueabihf \ -i586-unknown-linux-gnu \ -i586-unknown-linux-musl \ -i686-linux-android \ -i686-unknown-freebsd \ -i686-unknown-linux-gnu \ -i686-unknown-linux-musl \ -i686-pc-windows-gnu \ -x86_64-unknown-freebsd \ -x86_64-unknown-linux-gnu \ -x86_64-unknown-linux-musl \ -x86_64-unknown-netbsd \ -x86_64-unknown-cloudabi \ -x86_64-sun-solaris \ -x86_64-fuchsia \ -x86_64-pc-windows-gnu \ -x86_64-unknown-linux-gnux32 \ -x86_64-unknown-redox \ -x86_64-fortanix-unknown-sgx \ -wasm32-unknown-unknown \ -" - ;; - *osx*) - TARGETS="\ -aarch64-apple-ios \ -armv7-apple-ios \ -armv7s-apple-ios \ -i386-apple-ios \ -i686-apple-darwin \ -x86_64-apple-darwin \ -x86_64-apple-ios \ -" - ;; -esac - -for TARGET in $TARGETS; do - # FIXME: rustup often fails to download some artifacts due to network - # issues, so we retry this N times. - N=5 - n=0 - until [ $n -ge $N ] - do - if rustup target add "${TARGET}" ; then - break - fi - n=$((n+1)) - sleep 1 - done - - cargo +nightly semver --api-guidelines --target="${TARGET}" -done diff --git a/libc/ci/style.rs b/libc/ci/style.rs deleted file mode 100644 index dcb3536..0000000 --- a/libc/ci/style.rs +++ /dev/null @@ -1,208 +0,0 @@ -//! Simple script to verify the coding style of this library -//! -//! ## How to run -//! -//! The first argument to this script is the directory to run on, so running -//! this script should be as simple as: -//! -//! ```notrust -//! rustc ci/style.rs -//! ./style src -//! ``` -//! -//! ## Guidelines -//! -//! The current style is: -//! -//! * No trailing whitespace -//! * No tabs -//! * 80-character lines -//! * Specific module layout: -//! 1. use directives -//! 2. typedefs -//! 3. structs -//! 4. constants -//! 5. f! { ... } functions -//! 6. extern functions -//! 7. modules + pub use -//! -//! Things not verified: -//! -//! * alignment -//! * 4-space tabs -//! * leading colons on paths - -use std::env; -use std::fs; -use std::io::prelude::*; -use std::path::Path; - -macro_rules! t { - ($e:expr) => (match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with {}", stringify!($e), e), - }) -} - -fn main() { - let arg = env::args().skip(1).next().unwrap_or(".".to_string()); - - let mut errors = Errors { errs: false }; - walk(Path::new(&arg), &mut errors); - - if errors.errs { - panic!("found some lint errors"); - } else { - println!("good style!"); - } -} - -fn walk(path: &Path, err: &mut Errors) { - for entry in t!(path.read_dir()).map(|e| t!(e)) { - let path = entry.path(); - if t!(entry.file_type()).is_dir() { - walk(&path, err); - continue - } - - let name = entry.file_name().into_string().unwrap(); - match &name[..] { - n if !n.ends_with(".rs") => continue, - - "dox.rs" | - "lib.rs" | - "ctypes.rs" | - "libc.rs" | - "macros.rs" => continue, - - _ => {} - } - - let mut contents = String::new(); - t!(t!(fs::File::open(&path)).read_to_string(&mut contents)); - - check_style(&contents, &path, err); - } -} - -struct Errors { - errs: bool, -} - -#[derive(Clone, Copy, PartialEq)] -enum State { - Start, - Imports, - Typedefs, - Structs, - Constants, - FunctionDefinitions, - Functions, - Modules, -} - -fn check_style(file: &str, path: &Path, err: &mut Errors) { - let mut state = State::Start; - let mut s_macros = 0; - let mut f_macros = 0; - let mut prev_blank = false; - - for (i, line) in file.lines().enumerate() { - if line == "" { - if prev_blank { - err.error(path, i, "double blank line"); - } - prev_blank = true; - } else { - prev_blank = false; - } - if line != line.trim_end() { - err.error(path, i, "trailing whitespace"); - } - if line.contains("\t") { - err.error(path, i, "tab character"); - } - if line.len() > 80 { - err.error(path, i, "line longer than 80 chars"); - } - if line.contains("#[cfg(") && !line.contains(" if ") - && !(line.contains("target_endian") || - line.contains("target_arch")) - { - if state != State::Structs { - err.error(path, i, "use cfg_if! and submodules \ - instead of #[cfg]"); - } - } - - let line = line.trim_start(); - let is_pub = line.starts_with("pub "); - let line = if is_pub {&line[4..]} else {line}; - - let line_state = if line.starts_with("use ") { - if line.contains("c_void") { - continue; - } - if is_pub { - State::Modules - } else { - State::Imports - } - } else if line.starts_with("const ") { - State::Constants - } else if line.starts_with("type ") { - State::Typedefs - } else if line.starts_with("s! {") { - s_macros += 1; - State::Structs - } else if line.starts_with("f! {") { - f_macros += 1; - State::FunctionDefinitions - } else if line.starts_with("extern ") { - State::Functions - } else if line.starts_with("mod ") { - State::Modules - } else { - continue - }; - - if state as usize > line_state as usize { - err.error(path, i, &format!("{} found after {} when \ - it belongs before", - line_state.desc(), state.desc())); - } - - if f_macros == 2 { - f_macros += 1; - err.error(path, i, "multiple f! macros in one module"); - } - if s_macros == 2 { - s_macros += 1; - err.error(path, i, "multiple s! macros in one module"); - } - - state = line_state; - } -} - -impl State { - fn desc(&self) -> &str { - match *self { - State::Start => "start", - State::Imports => "import", - State::Typedefs => "typedef", - State::Structs => "struct", - State::Constants => "constant", - State::FunctionDefinitions => "function definition", - State::Functions => "extern function", - State::Modules => "module", - } - } -} - -impl Errors { - fn error(&mut self, path: &Path, line: usize, msg: &str) { - self.errs = true; - println!("{}:{} - {}", path.display(), line + 1, msg); - } -} diff --git a/libc/ci/style.sh b/libc/ci/style.sh deleted file mode 100644 index a6a0017..0000000 --- a/libc/ci/style.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh - -set -ex - -rustc ci/style.rs && ./style src - -if rustup component add rustfmt-preview ; then - which rustfmt - rustfmt -V - cargo fmt --all -- --check -fi - -if shellcheck --version ; then - shellcheck -e SC2103 ci/*.sh -else - echo "shellcheck not found" - exit 1 -fi - diff --git a/libc/ci/switch.json b/libc/ci/switch.json deleted file mode 100644 index bc18948..0000000 --- a/libc/ci/switch.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "family": "unix", - "env": "newlib", - "target-env": "newlib", - "target-family": "unix", - "target-c-int-width": "32", - "target-endian": "little", - "target-pointer-width": "64", - "os": "horizon", - "arch": "aarch64", - "panic-strategy": "unwind", - "abi-blacklist": [ - "stdcall", - "fastcall", - "vectorcall", - "thiscall", - "win64", - "sysv64" - ], - "dynamic-linking" : false, - "features": "+a53,+strict-align", - "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", - "executables": true, - "position-independent-executables" : true, - "linker-flavor": "gcc", - "llvm-target": "aarch64-unknown-none", - "has-elf-tls" : false, - "linker-is-gnu" : true, - "disable-redzone" : true, - "relocation-model" : "pic", - "max-atomic-width": 128, - "exe-suffix": ".elf", - "staticlib-suffix" : ".a", - "trap-unreachable" : true, - "emit-debug-gdb-scripts" : true, - "requires-uwtable" : true -} \ No newline at end of file diff --git a/libc/ci/sysinfo_guard.patch b/libc/ci/sysinfo_guard.patch deleted file mode 100644 index 69fb795..0000000 --- a/libc/ci/sysinfo_guard.patch +++ /dev/null @@ -1,10 +0,0 @@ -@@ -2,7 +2,9 @@ - #ifndef _LINUX_KERNEL_H - #define _LINUX_KERNEL_H - -+#ifdef __GLIBC__ - #include -+#endif - - /* - * 'kernel.h' contains some often-used function prototypes etc diff --git a/libc/ci/test-runner-linux b/libc/ci/test-runner-linux deleted file mode 100755 index cad31ec..0000000 --- a/libc/ci/test-runner-linux +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -e - -arch=$1 -prog=$2 - -cd /qemu/init -echo "#!/bin/sh\n/prog --color=never" > run_prog.sh -chmod +x run_prog.sh -cp -f $2 prog -find . | cpio --create --format='newc' --quiet | gzip > ../initrd.gz -cd .. - -timeout 30s qemu-system-$arch \ - -m 1024 \ - -nographic \ - -kernel kernel \ - -initrd initrd.gz \ - -append init=/run_prog.sh > output || true - -# remove kernel messages -tr -d '\r' < output | egrep -v '^\[' - -egrep "(PASSED)|(test result: ok)" output > /dev/null diff --git a/libc/libc-test/Cargo.toml b/libc/libc-test/Cargo.toml deleted file mode 100644 index 8d2d903..0000000 --- a/libc/libc-test/Cargo.toml +++ /dev/null @@ -1,54 +0,0 @@ -[package] -name = "libc-test" -version = "0.1.0" -authors = ["Alex Crichton "] -build = "build.rs" - -[dependencies.libc] -path = ".." -default-features = false - -[build-dependencies] -cc = "1.0" -ctest = "0.2" - -[features] -default = [ "std" ] -std = [ "libc/std" ] -align = [ "libc/align" ] -extra_traits = [ "libc/extra_traits" ] - -[[test]] -name = "main" -path = "test/main.rs" -harness = false - -[[test]] -name = "linux-fcntl" -path = "test/linux_fcntl.rs" -harness = false - -[[test]] -name = "linux-ipv6" -path = "test/linux_ipv6.rs" -harness = false - -[[test]] -name = "linux-elf" -path = "test/linux_elf.rs" -harness = false - -[[test]] -name = "linux-strerror_r" -path = "test/linux_strerror_r.rs" -harness = false - -[[test]] -name = "linux-termios" -path = "test/linux_termios.rs" -harness = false - -[[test]] -name = "cmsg" -path = "test/cmsg.rs" -harness = true diff --git a/libc/libc-test/build.rs b/libc/libc-test/build.rs deleted file mode 100644 index 977ff51..0000000 --- a/libc/libc-test/build.rs +++ /dev/null @@ -1,2658 +0,0 @@ -#![deny(warnings)] - -extern crate cc; -extern crate ctest; - -use std::env; - -fn do_cc() { - let target = env::var("TARGET").unwrap(); - if cfg!(unix) && !target.contains("wasi") { - cc::Build::new().file("src/cmsg.c").compile("cmsg"); - } -} - -fn do_ctest() { - match &env::var("TARGET").unwrap() { - t if t.contains("android") => return test_android(t), - t if t.contains("apple") => return test_apple(t), - t if t.contains("cloudabi") => return test_cloudabi(t), - t if t.contains("dragonfly") => return test_dragonflybsd(t), - t if t.contains("emscripten") => return test_emscripten(t), - t if t.contains("freebsd") => return test_freebsd(t), - t if t.contains("linux") => return test_linux(t), - t if t.contains("netbsd") => return test_netbsd(t), - t if t.contains("openbsd") => return test_openbsd(t), - t if t.contains("redox") => return test_redox(t), - t if t.contains("solaris") => return test_solaris(t), - t if t.contains("wasi") => return test_wasi(t), - t if t.contains("windows") => return test_windows(t), - t if t.contains("vxworks") => return test_vxworks(t), - t => panic!("unknown target {}", t), - } -} - -fn ctest_cfg() -> ctest::TestGenerator { - let mut cfg = ctest::TestGenerator::new(); - let libc_cfgs = [ - "libc_priv_mod_use", - "libc_union", - "libc_const_size_of", - "libc_align", - "libc_core_cvoid", - "libc_packedN", - "libc_thread_local", - ]; - for f in &libc_cfgs { - cfg.cfg(f, None); - } - cfg -} - -fn main() { - do_cc(); - do_ctest(); -} - -macro_rules! headers { - ($cfg:ident: [$m:expr]: $header:literal) => { - if $m { - $cfg.header($header); - } - }; - ($cfg:ident: $header:literal) => { - $cfg.header($header); - }; - ($($cfg:ident: $([$c:expr]:)* $header:literal,)*) => { - $(headers!($cfg: $([$c]:)* $header);)* - }; - ($cfg:ident: $( $([$c:expr]:)* $header:literal,)*) => { - headers!($($cfg: $([$c]:)* $header,)*); - }; - ($cfg:ident: $( $([$c:expr]:)* $header:literal),*) => { - headers!($($cfg: $([$c]:)* $header,)*); - }; -} - -fn test_apple(target: &str) { - assert!(target.contains("apple")); - let x86_64 = target.contains("x86_64"); - let i686 = target.contains("i686"); - - let mut cfg = ctest_cfg(); - cfg.flag("-Wno-deprecated-declarations"); - cfg.define("__APPLE_USE_RFC_3542", None); - - headers! { cfg: - "aio.h", - "ctype.h", - "dirent.h", - "dlfcn.h", - "errno.h", - "execinfo.h", - "fcntl.h", - "glob.h", - "grp.h", - "ifaddrs.h", - "langinfo.h", - "limits.h", - "locale.h", - "mach-o/dyld.h", - "mach/mach_time.h", - "malloc/malloc.h", - "net/bpf.h", - "net/if.h", - "net/if_arp.h", - "net/if_dl.h", - "net/if_utun.h", - "net/route.h", - "net/route.h", - "netdb.h", - "netinet/if_ether.h", - "netinet/in.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "poll.h", - "pthread.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "signal.h", - "spawn.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/event.h", - "sys/file.h", - "sys/ioctl.h", - "sys/ipc.h", - "sys/kern_control.h", - "sys/mman.h", - "sys/mount.h", - "sys/proc_info.h", - "sys/ptrace.h", - "sys/quota.h", - "sys/resource.h", - "sys/sem.h", - "sys/shm.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/sys_domain.h", - "sys/sysctl.h", - "sys/time.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/wait.h", - "sys/xattr.h", - "syslog.h", - "termios.h", - "time.h", - "unistd.h", - "util.h", - "utime.h", - "utmpx.h", - "wchar.h", - "xlocale.h", - [x86_64]: "crt_externs.h", - } - - cfg.skip_struct(move |ty| { - match ty { - // FIXME: actually a union - "sigval" => true, - - _ => false, - } - }); - - cfg.skip_const(move |name| { - match name { - // These OSX constants are removed in Sierra. - // https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html - "KERN_KDENABLE_BG_TRACE" | "KERN_KDDISABLE_BG_TRACE" => true, - _ => false, - } - }); - - cfg.skip_fn(move |name| { - // skip those that are manually verified - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" => true, - - // close calls the close_nocancel system call - "close" => true, - - _ => false, - } - }); - - cfg.skip_field_type(move |struct_, field| { - match (struct_, field) { - // FIXME: actually a union - ("sigevent", "sigev_value") => true, - _ => false, - } - }); - - cfg.volatile_item(|i| { - use ctest::VolatileItemKind::*; - match i { - StructField(ref n, ref f) if n == "aiocb" && f == "aio_buf" => { - true - } - _ => false, - } - }); - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "DIR" | "Dl_info" => ty.to_string(), - - // OSX calls this something else - "sighandler_t" => "sig_t".to_string(), - - t if is_union => format!("union {}", t), - t if t.ends_with("_t") => t.to_string(), - t if is_struct => format!("struct {}", t), - t => t.to_string(), - } - }); - - cfg.field_name(move |struct_, field| { - match field { - s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - s.replace("e_nsec", "espec.tv_nsec") - } - // FIXME: sigaction actually contains a union with two variants: - // a sa_sigaction with type: (*)(int, struct __siginfo *, void *) - // a sa_handler with type sig_t - "sa_sigaction" if struct_ == "sigaction" => { - "sa_handler".to_string() - } - s => s.to_string(), - } - }); - - cfg.skip_roundtrip(move |s| match s { - // FIXME: this type has the wrong ABI - "max_align_t" if i686 => true, - _ => false, - }); - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_openbsd(target: &str) { - assert!(target.contains("openbsd")); - - let mut cfg = ctest_cfg(); - cfg.flag("-Wno-deprecated-declarations"); - - headers! { cfg: - "errno.h", - "fcntl.h", - "limits.h", - "locale.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "sys/stat.h", - "sys/types.h", - "time.h", - "wchar.h", - "ctype.h", - "dirent.h", - "sys/socket.h", - "net/if.h", - "net/route.h", - "net/if_arp.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "net/bpf.h", - "resolv.h", - "pthread.h", - "dlfcn.h", - "signal.h", - "string.h", - "sys/file.h", - "sys/ioctl.h", - "sys/mman.h", - "sys/resource.h", - "sys/socket.h", - "sys/time.h", - "sys/un.h", - "sys/wait.h", - "unistd.h", - "utime.h", - "pwd.h", - "grp.h", - "sys/utsname.h", - "sys/ptrace.h", - "sys/mount.h", - "sys/uio.h", - "sched.h", - "termios.h", - "poll.h", - "syslog.h", - "semaphore.h", - "sys/statvfs.h", - "sys/times.h", - "glob.h", - "ifaddrs.h", - "langinfo.h", - "sys/sysctl.h", - "utmp.h", - "sys/event.h", - "net/if_dl.h", - "util.h", - "ufs/ufs/quota.h", - "pthread_np.h", - "sys/syscall.h", - "sys/shm.h", - } - - cfg.skip_struct(move |ty| { - match ty { - // FIXME: actually a union - "sigval" => true, - - _ => false, - } - }); - - cfg.skip_const(move |name| { - match name { - // Removed in OpenBSD 6.0 - "KERN_USERMOUNT" | "KERN_ARND" => true, - _ => false, - } - }); - - cfg.skip_fn(move |name| { - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" | "execvpe" => true, - - // Removed in OpenBSD 6.5 - // https://marc.info/?l=openbsd-cvs&m=154723400730318 - "mincore" => true, - - _ => false, - } - }); - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "DIR" | "Dl_info" => ty.to_string(), - - // OSX calls this something else - "sighandler_t" => "sig_t".to_string(), - - t if is_union => format!("union {}", t), - t if t.ends_with("_t") => t.to_string(), - t if is_struct => format!("struct {}", t), - t => t.to_string(), - } - }); - - cfg.field_name(move |struct_, field| match field { - "st_birthtime" if struct_.starts_with("stat") => { - "__st_birthtime".to_string() - } - "st_birthtime_nsec" if struct_.starts_with("stat") => { - "__st_birthtimensec".to_string() - } - s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - s.replace("e_nsec", ".tv_nsec") - } - "sa_sigaction" if struct_ == "sigaction" => "sa_handler".to_string(), - s => s.to_string(), - }); - - cfg.skip_field_type(move |struct_, field| { - // type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1 - (struct_ == "siginfo_t" && field == "si_addr") - }); - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_windows(target: &str) { - assert!(target.contains("windows")); - let gnu = target.contains("gnu"); - - let mut cfg = ctest_cfg(); - cfg.define("_WIN32_WINNT", Some("0x8000")); - - headers! { cfg: - "direct.h", - "errno.h", - "fcntl.h", - "io.h", - "limits.h", - "locale.h", - "process.h", - "signal.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "sys/stat.h", - "sys/types.h", - "sys/utime.h", - "time.h", - "wchar.h", - [gnu]: "ws2tcpip.h", - [!gnu]: "Winsock2.h", - } - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "DIR" | "Dl_info" => ty.to_string(), - - // FIXME: these don't exist: - "time64_t" => "__time64_t".to_string(), - "ssize_t" => "SSIZE_T".to_string(), - - "sighandler_t" if !gnu => "_crt_signal_t".to_string(), - "sighandler_t" if gnu => "__p_sig_fn_t".to_string(), - - t if is_union => format!("union {}", t), - t if t.ends_with("_t") => t.to_string(), - - // Windows uppercase structs don't have `struct` in front: - t if is_struct => { - if ty.clone().chars().next().unwrap().is_uppercase() { - t.to_string() - } else if t == "stat" { - "struct __stat64".to_string() - } else if t == "utimbuf" { - "struct __utimbuf64".to_string() - } else { - // put `struct` in front of all structs: - format!("struct {}", t) - } - } - t => t.to_string(), - } - }); - - cfg.fn_cname(move |name, cname| cname.unwrap_or(name).to_string()); - - cfg.skip_type(move |name| match name { - "SSIZE_T" if !gnu => true, - "ssize_t" if !gnu => true, - _ => false, - }); - - cfg.skip_const(move |name| { - match name { - // FIXME: API error: - // SIG_ERR type is "void (*)(int)", not "int" - "SIG_ERR" => true, - _ => false, - } - }); - - // FIXME: All functions point to the wrong addresses? - cfg.skip_fn_ptrcheck(|_| true); - - cfg.skip_signededness(move |c| { - match c { - // windows-isms - n if n.starts_with("P") => true, - n if n.starts_with("H") => true, - n if n.starts_with("LP") => true, - "sighandler_t" if gnu => true, - _ => false, - } - }); - - cfg.skip_fn(move |name| { - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" | "execvpe" => true, - - _ => false, - } - }); - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_redox(target: &str) { - assert!(target.contains("redox")); - - let mut cfg = ctest_cfg(); - cfg.flag("-Wno-deprecated-declarations"); - - headers! { - cfg: - "ctype.h", - "dirent.h", - "dlfcn.h", - "errno.h", - "execinfo.h", - "fcntl.h", - "glob.h", - "grp.h", - "ifaddrs.h", - "langinfo.h", - "limits.h", - "locale.h", - "net/if.h", - "net/if_arp.h", - "net/route.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "poll.h", - "pthread.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "string.h", - "strings.h", - "sys/file.h", - "sys/ioctl.h", - "sys/mman.h", - "sys/mount.h", - "sys/ptrace.h", - "sys/quota.h", - "sys/resource.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/sysctl.h", - "sys/time.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/wait.h", - "syslog.h", - "termios.h", - "time.h", - "unistd.h", - "utime.h", - "utmpx.h", - "wchar.h", - } - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_cloudabi(target: &str) { - assert!(target.contains("cloudabi")); - - let mut cfg = ctest_cfg(); - cfg.flag("-Wno-deprecated-declarations"); - - headers! { - cfg: - "execinfo.h", - "glob.h", - "ifaddrs.h", - "langinfo.h", - "sys/ptrace.h", - "sys/quota.h", - "sys/sysctl.h", - "utmpx.h", - "ctype.h", - "dirent.h", - "dlfcn.h", - "errno.h", - "fcntl.h", - "grp.h", - "limits.h", - "locale.h", - "net/if.h", - "net/if_arp.h", - "net/route.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "poll.h", - "pthread.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "signal.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "strings.h", - "sys/file.h", - "sys/ioctl.h", - "sys/mman.h", - "sys/mount.h", - "sys/resource.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/time.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/wait.h", - "syslog.h", - "termios.h", - "time.h", - "unistd.h", - "utime.h", - "wchar.h", - } - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_solaris(target: &str) { - assert!(target.contains("solaris")); - - let mut cfg = ctest_cfg(); - cfg.flag("-Wno-deprecated-declarations"); - - cfg.define("_XOPEN_SOURCE", Some("700")); - cfg.define("__EXTENSIONS__", None); - cfg.define("_LCONV_C99", None); - - headers! { - cfg: - "ctype.h", - "dirent.h", - "dlfcn.h", - "errno.h", - "execinfo.h", - "fcntl.h", - "glob.h", - "grp.h", - "ifaddrs.h", - "langinfo.h", - "limits.h", - "locale.h", - "net/if.h", - "net/if_arp.h", - "net/route.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "poll.h", - "port.h", - "pthread.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "signal.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/epoll.h", - "sys/file.h", - "sys/filio.h", - "sys/ioctl.h", - "sys/loadavg.h", - "sys/mman.h", - "sys/mount.h", - "sys/resource.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/time.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/wait.h", - "syslog.h", - "termios.h", - "time.h", - "ucontext.h", - "unistd.h", - "utime.h", - "utmpx.h", - "wchar.h", - } - - cfg.skip_const(move |name| match name { - "DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG" | "DT_LNK" - | "DT_SOCK" | "USRQUOTA" | "GRPQUOTA" | "PRIO_MIN" | "PRIO_MAX" => { - true - } - - _ => false, - }); - - cfg.skip_fn(move |name| { - // skip those that are manually verified - match name { - // const-ness only added recently - "dladdr" => true, - - // Definition of those functions as changed since unified headers - // from NDK r14b These changes imply some API breaking changes but - // are still ABI compatible. We can wait for the next major release - // to be compliant with the new API. - // - // FIXME: unskip these for next major release - "setpriority" | "personality" => true, - - // signal is defined with sighandler_t, so ignore - "signal" => true, - - "cfmakeraw" | "cfsetspeed" => true, - - // FIXME: mincore is defined with caddr_t on Solaris. - "mincore" => true, - - _ => false, - } - }); - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_netbsd(target: &str) { - assert!(target.contains("netbsd")); - let rumprun = target.contains("rumprun"); - let mut cfg = ctest_cfg(); - - cfg.flag("-Wno-deprecated-declarations"); - cfg.define("_NETBSD_SOURCE", Some("1")); - - headers! { - cfg: - "errno.h", - "fcntl.h", - "limits.h", - "locale.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "sys/stat.h", - "sys/types.h", - "time.h", - "wchar.h", - "aio.h", - "ctype.h", - "dirent.h", - "dlfcn.h", - "glob.h", - "grp.h", - "ifaddrs.h", - "langinfo.h", - "net/if.h", - "net/if_arp.h", - "net/if_dl.h", - "net/route.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "poll.h", - "pthread.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "signal.h", - "string.h", - "sys/extattr.h", - "sys/file.h", - "sys/ioctl.h", - "sys/ioctl_compat.h", - "sys/mman.h", - "sys/mount.h", - "sys/ptrace.h", - "sys/resource.h", - "sys/socket.h", - "sys/statvfs.h", - "sys/sysctl.h", - "sys/time.h", - "sys/times.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/wait.h", - "syslog.h", - "termios.h", - "ufs/ufs/quota.h", - "ufs/ufs/quota1.h", - "unistd.h", - "util.h", - "utime.h", - "mqueue.h", - "netinet/dccp.h", - "sys/event.h", - "sys/quota.h", - "sys/shm.h", - } - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" - | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" - | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" - | "Elf64_Chdr" => ty.to_string(), - - // OSX calls this something else - "sighandler_t" => "sig_t".to_string(), - - t if is_union => format!("union {}", t), - - t if t.ends_with("_t") => t.to_string(), - - // put `struct` in front of all structs:. - t if is_struct => format!("struct {}", t), - - t => t.to_string(), - } - }); - - cfg.field_name(move |struct_, field| { - match field { - // Our stat *_nsec fields normally don't actually exist but are part - // of a timeval struct - s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - s.replace("e_nsec", ".tv_nsec") - } - "u64" if struct_ == "epoll_event" => "data.u64".to_string(), - s => s.to_string(), - } - }); - - cfg.skip_type(move |ty| { - match ty { - // FIXME: sighandler_t is crazy across platforms - "sighandler_t" => true, - _ => false, - } - }); - - cfg.skip_struct(move |ty| { - match ty { - // This is actually a union, not a struct - "sigval" => true, - // These are tested as part of the linux_fcntl tests since there are - // header conflicts when including them with all the other structs. - "termios2" => true, - _ => false, - } - }); - - cfg.skip_signededness(move |c| { - match c { - "LARGE_INTEGER" | "float" | "double" => true, - n if n.starts_with("pthread") => true, - // sem_t is a struct or pointer - "sem_t" => true, - _ => false, - } - }); - - cfg.skip_const(move |name| { - match name { - "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness - "SIGUNUSED" => true, // removed in glibc 2.26 - - // weird signed extension or something like that? - "MS_NOUSER" => true, - "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 - "BOTHER" => true, - - _ => false, - } - }); - - cfg.skip_fn(move |name| { - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" => true, - - "getrlimit" | "getrlimit64" | // non-int in 1st arg - "setrlimit" | "setrlimit64" | // non-int in 1st arg - "prlimit" | "prlimit64" | // non-int in 2nd arg - - // These functions presumably exist on netbsd but don't look like - // they're implemented on rumprun yet, just let them slide for now. - // Some of them look like they have headers but then don't have - // corresponding actual definitions either... - "shm_open" | - "shm_unlink" | - "syscall" | - "mq_open" | - "mq_close" | - "mq_getattr" | - "mq_notify" | - "mq_receive" | - "mq_send" | - "mq_setattr" | - "mq_timedreceive" | - "mq_timedsend" | - "mq_unlink" | - "ptrace" | - "sigaltstack" if rumprun => true, - - _ => false, - } - }); - - cfg.skip_field_type(move |struct_, field| { - // This is a weird union, don't check the type. - (struct_ == "ifaddrs" && field == "ifa_ifu") || - // sighandler_t type is super weird - (struct_ == "sigaction" && field == "sa_sigaction") || - // sigval is actually a union, but we pretend it's a struct - (struct_ == "sigevent" && field == "sigev_value") || - // aio_buf is "volatile void*" and Rust doesn't understand volatile - (struct_ == "aiocb" && field == "aio_buf") - }); - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_dragonflybsd(target: &str) { - assert!(target.contains("dragonfly")); - let mut cfg = ctest_cfg(); - cfg.flag("-Wno-deprecated-declarations"); - - headers! { - cfg: - "aio.h", - "ctype.h", - "dirent.h", - "dlfcn.h", - "errno.h", - "execinfo.h", - "fcntl.h", - "glob.h", - "grp.h", - "ifaddrs.h", - "langinfo.h", - "limits.h", - "locale.h", - "mqueue.h", - "net/if.h", - "net/if_arp.h", - "net/if_dl.h", - "net/route.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "poll.h", - "pthread.h", - "pthread_np.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "signal.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/event.h", - "sys/file.h", - "sys/ioctl.h", - "sys/mman.h", - "sys/mount.h", - "sys/ptrace.h", - "sys/resource.h", - "sys/rtprio.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/sysctl.h", - "sys/time.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/wait.h", - "syslog.h", - "termios.h", - "time.h", - "ufs/ufs/quota.h", - "unistd.h", - "util.h", - "utime.h", - "utmpx.h", - "wchar.h", - } - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" - | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" - | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" - | "Elf64_Chdr" => ty.to_string(), - - // FIXME: OSX calls this something else - "sighandler_t" => "sig_t".to_string(), - - t if is_union => format!("union {}", t), - - t if t.ends_with("_t") => t.to_string(), - - // put `struct` in front of all structs:. - t if is_struct => format!("struct {}", t), - - t => t.to_string(), - } - }); - - cfg.field_name(move |struct_, field| { - match field { - // Our stat *_nsec fields normally don't actually exist but are part - // of a timeval struct - s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - s.replace("e_nsec", ".tv_nsec") - } - "u64" if struct_ == "epoll_event" => "data.u64".to_string(), - // Field is named `type` in C but that is a Rust keyword, - // so these fields are translated to `type_` in the bindings. - "type_" if struct_ == "rtprio" => "type".to_string(), - s => s.to_string(), - } - }); - - cfg.skip_type(move |ty| { - match ty { - // sighandler_t is crazy across platforms - "sighandler_t" => true, - - _ => false, - } - }); - - cfg.skip_struct(move |ty| { - match ty { - // This is actually a union, not a struct - "sigval" => true, - - // FIXME: These are tested as part of the linux_fcntl tests since - // there are header conflicts when including them with all the other - // structs. - "termios2" => true, - - _ => false, - } - }); - - cfg.skip_signededness(move |c| { - match c { - "LARGE_INTEGER" | "float" | "double" => true, - // uuid_t is a struct, not an integer. - "uuid_t" => true, - n if n.starts_with("pthread") => true, - // sem_t is a struct or pointer - "sem_t" => true, - // mqd_t is a pointer on DragonFly - "mqd_t" => true, - - _ => false, - } - }); - - cfg.skip_const(move |name| { - match name { - "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness - - // weird signed extension or something like that? - "MS_NOUSER" => true, - "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 - - // These are defined for Solaris 11, but the crate is tested on - // illumos, where they are currently not defined - "EADI" - | "PORT_SOURCE_POSTWAIT" - | "PORT_SOURCE_SIGNAL" - | "PTHREAD_STACK_MIN" => true, - - _ => false, - } - }); - - cfg.skip_fn(move |name| { - // skip those that are manually verified - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" => true, - - "getrlimit" | "getrlimit64" | // non-int in 1st arg - "setrlimit" | "setrlimit64" | // non-int in 1st arg - "prlimit" | "prlimit64" // non-int in 2nd arg - => true, - - _ => false, - } - }); - - cfg.skip_field_type(move |struct_, field| { - // This is a weird union, don't check the type. - (struct_ == "ifaddrs" && field == "ifa_ifu") || - // sighandler_t type is super weird - (struct_ == "sigaction" && field == "sa_sigaction") || - // sigval is actually a union, but we pretend it's a struct - (struct_ == "sigevent" && field == "sigev_value") || - // aio_buf is "volatile void*" and Rust doesn't understand volatile - (struct_ == "aiocb" && field == "aio_buf") - }); - - cfg.skip_field(move |struct_, field| { - // this is actually a union on linux, so we can't represent it well and - // just insert some padding. - (struct_ == "siginfo_t" && field == "_pad") || - // sigev_notify_thread_id is actually part of a sigev_un union - (struct_ == "sigevent" && field == "sigev_notify_thread_id") - }); - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_wasi(target: &str) { - assert!(target.contains("wasi")); - - let mut cfg = ctest_cfg(); - cfg.define("_GNU_SOURCE", None); - - headers! { cfg: - "ctype.h", - "dirent.h", - "errno.h", - "fcntl.h", - "limits.h", - "locale.h", - "malloc.h", - "poll.h", - "sched.h", - "stdbool.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/resource.h", - "sys/select.h", - "sys/socket.h", - "sys/stat.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/utsname.h", - "time.h", - "unistd.h", - "wasi/core.h", - "wasi/libc.h", - "wasi/libc-find-relpath.h", - "wchar.h", - } - - cfg.type_name(move |ty, is_struct, is_union| match ty { - "FILE" | "fd_set" | "DIR" => ty.to_string(), - t if is_union => format!("union {}", t), - t if t.starts_with("__wasi") && t.ends_with("_u") => { - format!("union {}", t) - } - t if t.starts_with("__wasi") && is_struct => format!("struct {}", t), - t if t.ends_with("_t") => t.to_string(), - t if is_struct => format!("struct {}", t), - t => t.to_string(), - }); - - cfg.field_name(move |_struct, field| { - match field { - // deal with fields as rust keywords - "type_" => "type".to_string(), - s => s.to_string(), - } - }); - - // Looks like LLD doesn't merge duplicate imports, so if the Rust - // code imports from a module and the C code also imports from a - // module we end up with two imports of function pointers which - // import the same thing but have different function pointers - cfg.skip_fn_ptrcheck(|f| f.starts_with("__wasi")); - - // d_name is declared as a flexible array in WASI libc, so it - // doesn't support sizeof. - cfg.skip_field(|s, field| s == "dirent" && field == "d_name"); - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_android(target: &str) { - assert!(target.contains("android")); - let target_pointer_width = match target { - t if t.contains("aarch64") || t.contains("x86_64") => 64, - t if t.contains("i686") || t.contains("arm") => 32, - t => panic!("unsupported target: {}", t), - }; - let x86 = target.contains("i686") || target.contains("x86_64"); - - let mut cfg = ctest_cfg(); - cfg.define("_GNU_SOURCE", None); - - headers! { cfg: - "arpa/inet.h", - "asm/mman.h", - "ctype.h", - "dirent.h", - "dlfcn.h", - "errno.h", - "fcntl.h", - "grp.h", - "ifaddrs.h", - "limits.h", - "linux/dccp.h", - "linux/futex.h", - "linux/fs.h", - "linux/genetlink.h", - "linux/if_alg.h", - "linux/if_ether.h", - "linux/if_tun.h", - "linux/magic.h", - "linux/memfd.h", - "linux/module.h", - "linux/net_tstamp.h", - "linux/netfilter/nfnetlink.h", - "linux/netfilter/nfnetlink_log.h", - "linux/netfilter/nf_tables.h", - "linux/netfilter_ipv4.h", - "linux/netfilter_ipv6.h", - "linux/netlink.h", - "linux/quota.h", - "linux/reboot.h", - "linux/seccomp.h", - "linux/sockios.h", - "locale.h", - "malloc.h", - "net/ethernet.h", - "net/if.h", - "net/if_arp.h", - "net/route.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "netpacket/packet.h", - "poll.h", - "pthread.h", - "pty.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "signal.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/epoll.h", - "sys/eventfd.h", - "sys/file.h", - "sys/fsuid.h", - "sys/inotify.h", - "sys/ioctl.h", - "sys/mman.h", - "sys/mount.h", - "sys/personality.h", - "sys/prctl.h", - "sys/ptrace.h", - "sys/random.h", - "sys/reboot.h", - "sys/resource.h", - "sys/sendfile.h", - "sys/signalfd.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/swap.h", - "sys/syscall.h", - "sys/sysinfo.h", - "sys/time.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/vfs.h", - "sys/xattr.h", - "sys/wait.h", - "syslog.h", - "termios.h", - "time.h", - "unistd.h", - "utime.h", - "utmp.h", - "wchar.h", - "xlocale.h", - // time64_t is not defined for 64-bit targets If included it will - // generate the error 'Your time_t is already 64-bit' - [target_pointer_width == 32]: "time64.h", - [x86]: "sys/reg.h", - } - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "fd_set" | "Dl_info" => ty.to_string(), - - t if is_union => format!("union {}", t), - - t if t.ends_with("_t") => t.to_string(), - - // sigval is a struct in Rust, but a union in C: - "sigval" => format!("union sigval"), - - // put `struct` in front of all structs:. - t if is_struct => format!("struct {}", t), - - t => t.to_string(), - } - }); - - cfg.field_name(move |struct_, field| { - match field { - // Our stat *_nsec fields normally don't actually exist but are part - // of a timeval struct - s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - s.to_string() - } - // FIXME: appears that `epoll_event.data` is an union - "u64" if struct_ == "epoll_event" => "data.u64".to_string(), - s => s.to_string(), - } - }); - - cfg.skip_type(move |ty| { - match ty { - // FIXME: `sighandler_t` type is incorrect, see: - // https://github.com/rust-lang/libc/issues/1359 - "sighandler_t" => true, - _ => false, - } - }); - - cfg.skip_struct(move |ty| { - match ty { - // These are tested as part of the linux_fcntl tests since there are - // header conflicts when including them with all the other structs. - "termios2" => true, - - _ => false, - } - }); - - cfg.skip_const(move |name| { - match name { - // FIXME: deprecated: not available in any header - // See: https://github.com/rust-lang/libc/issues/1356 - "ENOATTR" => true, - - // FIXME: still necessary? - "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness - // FIXME: deprecated - removed in glibc 2.26 - "SIGUNUSED" => true, - - _ => false, - } - }); - - cfg.skip_fn(move |name| { - // skip those that are manually verified - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" | "execvpe" | "fexecve" => true, - - // There are two versions of the sterror_r function, see - // - // https://linux.die.net/man/3/strerror_r - // - // An XSI-compliant version provided if: - // - // (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE - // - // and a GNU specific version provided if _GNU_SOURCE is defined. - // - // libc provides bindings for the XSI-compliant version, which is - // preferred for portable applications. - // - // We skip the test here since here _GNU_SOURCE is defined, and - // test the XSI version below. - "strerror_r" => true, - - _ => false, - } - }); - - cfg.skip_field_type(move |struct_, field| { - // This is a weird union, don't check the type. - (struct_ == "ifaddrs" && field == "ifa_ifu") || - // sigval is actually a union, but we pretend it's a struct - (struct_ == "sigevent" && field == "sigev_value") - }); - - cfg.skip_field(move |struct_, field| { - // this is actually a union on linux, so we can't represent it well and - // just insert some padding. - (struct_ == "siginfo_t" && field == "_pad") || - // FIXME: `sa_sigaction` has type `sighandler_t` but that type is - // incorrect, see: https://github.com/rust-lang/libc/issues/1359 - (struct_ == "sigaction" && field == "sa_sigaction") || - // sigev_notify_thread_id is actually part of a sigev_un union - (struct_ == "sigevent" && field == "sigev_notify_thread_id") || - // signalfd had SIGSYS fields added in Android 4.19, but CI does not have that version yet. - (struct_ == "signalfd_siginfo" && (field == "ssi_syscall" || - field == "ssi_call_addr" || - field == "ssi_arch")) - }); - - cfg.generate("../src/lib.rs", "main.rs"); - - test_linux_like_apis(target); -} - -fn test_freebsd(target: &str) { - assert!(target.contains("freebsd")); - let mut cfg = ctest_cfg(); - - let freebsd_ver = which_freebsd(); - - match freebsd_ver { - Some(10) => cfg.cfg("freebsd10", None), - Some(11) => cfg.cfg("freebsd11", None), - Some(12) => cfg.cfg("freebsd12", None), - Some(13) => cfg.cfg("freebsd13", None), - _ => &mut cfg, - }; - - // Required for `getline`: - cfg.define("_WITH_GETLINE", None); - // Required for making freebsd11_stat available in the headers - match freebsd_ver { - Some(10) => &mut cfg, - _ => cfg.define("_WANT_FREEBSD11_STAT", None), - }; - - headers! { cfg: - "aio.h", - "arpa/inet.h", - "ctype.h", - "dirent.h", - "dlfcn.h", - "errno.h", - "fcntl.h", - "glob.h", - "grp.h", - "ifaddrs.h", - "langinfo.h", - "libutil.h", - "limits.h", - "locale.h", - "mqueue.h", - "net/bpf.h", - "net/if.h", - "net/if_arp.h", - "net/if_dl.h", - "net/route.h", - "netdb.h", - "netinet/ip.h", - "netinet/in.h", - "netinet/tcp.h", - "netinet/udp.h", - "poll.h", - "pthread.h", - "pthread_np.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "signal.h", - "spawn.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/event.h", - "sys/extattr.h", - "sys/file.h", - "sys/ioctl.h", - "sys/ipc.h", - "sys/jail.h", - "sys/mman.h", - "sys/mount.h", - "sys/msg.h", - "sys/procdesc.h", - "sys/ptrace.h", - "sys/resource.h", - "sys/rtprio.h", - "sys/shm.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/sysctl.h", - "sys/time.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/wait.h", - "syslog.h", - "termios.h", - "time.h", - "ufs/ufs/quota.h", - "unistd.h", - "utime.h", - "utmpx.h", - "wchar.h", - } - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "fd_set" | "Dl_info" | "DIR" => ty.to_string(), - - // FIXME: https://github.com/rust-lang/libc/issues/1273 - "sighandler_t" => "sig_t".to_string(), - - t if is_union => format!("union {}", t), - - t if t.ends_with("_t") => t.to_string(), - - // sigval is a struct in Rust, but a union in C: - "sigval" => format!("union sigval"), - - // put `struct` in front of all structs:. - t if is_struct => format!("struct {}", t), - - t => t.to_string(), - } - }); - - cfg.field_name(move |struct_, field| { - match field { - // Our stat *_nsec fields normally don't actually exist but are part - // of a timeval struct - s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - s.replace("e_nsec", ".tv_nsec") - } - // Field is named `type` in C but that is a Rust keyword, - // so these fields are translated to `type_` in the bindings. - "type_" if struct_ == "rtprio" => "type".to_string(), - s => s.to_string(), - } - }); - - cfg.skip_const(move |name| { - match name { - // These constants were introduced in FreeBSD 12: - "SF_USER_READAHEAD" - | "EVFILT_EMPTY" - | "SO_REUSEPORT_LB" - | "IP_ORIGDSTADDR" - | "IP_RECVORIGDSTADDR" - | "IPV6_ORIGDSTADDR" - | "IPV6_RECVORIGDSTADDR" - if Some(11) == freebsd_ver => - { - true - } - - // These constants were introduced in FreeBSD 11: - "SF_USER_READAHEAD" - | "SF_NOCACHE" - | "RLIMIT_KQUEUES" - | "RLIMIT_UMTXP" - | "EVFILT_PROCDESC" - | "EVFILT_SENDFILE" - | "EVFILT_EMPTY" - | "SO_REUSEPORT_LB" - | "TCP_CCALGOOPT" - | "TCP_PCAP_OUT" - | "TCP_PCAP_IN" - | "IP_BINDMULTI" - | "IP_ORIGDSTADDR" - | "IP_RECVORIGDSTADDR" - | "IPV6_ORIGDSTADDR" - | "IPV6_RECVORIGDSTADDR" - | "PD_CLOEXEC" - | "PD_ALLOWED_AT_FORK" - | "IP_RSS_LISTEN_BUCKET" - if Some(10) == freebsd_ver => - { - true - } - - // FIXME: This constant has a different value in FreeBSD 10: - "RLIM_NLIMITS" if Some(10) == freebsd_ver => true, - - // FIXME: There are deprecated - remove in a couple of releases. - // These constants were removed in FreeBSD 11 (svn r273250) but will - // still be accepted and ignored at runtime. - "MAP_RENAME" | "MAP_NORESERVE" if Some(10) != freebsd_ver => true, - - // FIXME: There are deprecated - remove in a couple of releases. - // These constants were removed in FreeBSD 11 (svn r262489), - // and they've never had any legitimate use outside of the - // base system anyway. - "CTL_MAXID" | "KERN_MAXID" | "HW_MAXID" | "USER_MAXID" => true, - - _ => false, - } - }); - - cfg.skip_struct(move |ty| { - match ty { - // `mmsghdr` is not available in FreeBSD 10 - "mmsghdr" if Some(10) == freebsd_ver => true, - - // `max_align_t` is not available in FreeBSD 10 - "max_align_t" if Some(10) == freebsd_ver => true, - - _ => false, - } - }); - - cfg.skip_fn(move |name| { - // skip those that are manually verified - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" | "execvpe" | "fexecve" => true, - - // These functions were added in FreeBSD 11: - "fdatasync" | "mq_getfd_np" | "sendmmsg" | "recvmmsg" - if Some(10) == freebsd_ver => - { - true - } - - // This function changed its return type from `int` in FreeBSD10 to - // `ssize_t` in FreeBSD11: - "aio_waitcomplete" if Some(10) == freebsd_ver => true, - - // The `uname` function in the `utsname.h` FreeBSD header is a C - // inline function (has no symbol) that calls the `__xuname` symbol. - // Therefore the function pointer comparison does not make sense for it. - "uname" => true, - - // FIXME: Our API is unsound. The Rust API allows aliasing - // pointers, but the C API requires pointers not to alias. - // We should probably be at least using `&`/`&mut` here, see: - // https://github.com/gnzlbg/ctest/issues/68 - "lio_listio" => true, - - _ => false, - } - }); - - cfg.skip_signededness(move |c| { - match c { - // FIXME: has a different sign in FreeBSD10 - "blksize_t" if Some(10) == freebsd_ver => true, - _ => false, - } - }); - - cfg.volatile_item(|i| { - use ctest::VolatileItemKind::*; - match i { - // aio_buf is a volatile void** but since we cannot express that in - // Rust types, we have to explicitly tell the checker about it here: - StructField(ref n, ref f) if n == "aiocb" && f == "aio_buf" => { - true - } - _ => false, - } - }); - - cfg.skip_field(move |struct_, field| { - match (struct_, field) { - // FIXME: `sa_sigaction` has type `sighandler_t` but that type is - // incorrect, see: https://github.com/rust-lang/libc/issues/1359 - ("sigaction", "sa_sigaction") => true, - - // FIXME: in FreeBSD10 this field has type `char*` instead of - // `void*`: - ("stack_t", "ss_sp") if Some(10) == freebsd_ver => true, - - _ => false, - } - }); - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_emscripten(target: &str) { - assert!(target.contains("emscripten")); - - let mut cfg = ctest_cfg(); - cfg.define("_GNU_SOURCE", None); // FIXME: ?? - - headers! { cfg: - "aio.h", - "ctype.h", - "dirent.h", - "dlfcn.h", - "errno.h", - "fcntl.h", - "glob.h", - "grp.h", - "ifaddrs.h", - "langinfo.h", - "limits.h", - "locale.h", - "malloc.h", - "mntent.h", - "mqueue.h", - "net/ethernet.h", - "net/if.h", - "net/if_arp.h", - "net/route.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "netpacket/packet.h", - "poll.h", - "pthread.h", - "pty.h", - "pwd.h", - "resolv.h", - "sched.h", - "sched.h", - "semaphore.h", - "shadow.h", - "signal.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/epoll.h", - "sys/eventfd.h", - "sys/file.h", - "sys/ioctl.h", - "sys/ipc.h", - "sys/mman.h", - "sys/mount.h", - "sys/msg.h", - "sys/personality.h", - "sys/prctl.h", - "sys/ptrace.h", - "sys/quota.h", - "sys/reboot.h", - "sys/resource.h", - "sys/sem.h", - "sys/sendfile.h", - "sys/shm.h", - "sys/signalfd.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/swap.h", - "sys/syscall.h", - "sys/sysctl.h", - "sys/sysinfo.h", - "sys/time.h", - "sys/timerfd.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/user.h", - "sys/utsname.h", - "sys/vfs.h", - "sys/wait.h", - "sys/xattr.h", - "syslog.h", - "termios.h", - "time.h", - "ucontext.h", - "unistd.h", - "utime.h", - "utmp.h", - "utmpx.h", - "wchar.h", - } - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "fd_set" | "Dl_info" | "DIR" => ty.to_string(), - - t if is_union => format!("union {}", t), - - t if t.ends_with("_t") => t.to_string(), - - // put `struct` in front of all structs:. - t if is_struct => format!("struct {}", t), - - t => t.to_string(), - } - }); - - cfg.field_name(move |struct_, field| { - match field { - // Our stat *_nsec fields normally don't actually exist but are part - // of a timeval struct - s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - s.replace("e_nsec", ".tv_nsec") - } - // FIXME: appears that `epoll_event.data` is an union - "u64" if struct_ == "epoll_event" => "data.u64".to_string(), - s => s.to_string(), - } - }); - - cfg.skip_type(move |ty| { - match ty { - // sighandler_t is crazy across platforms - // FIXME: is this necessary? - "sighandler_t" => true, - - _ => false, - } - }); - - cfg.skip_struct(move |ty| { - match ty { - // This is actually a union, not a struct - // FIXME: is this necessary? - "sigval" => true, - - _ => false, - } - }); - - cfg.skip_fn(move |name| { - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" | "execvpe" | "fexecve" => true, - - _ => false, - } - }); - - cfg.skip_const(move |name| { - match name { - // FIXME: deprecated - SIGNUNUSED was removed in glibc 2.26 - // users should use SIGSYS instead - "SIGUNUSED" => true, - - // FIXME: emscripten uses different constants to constructs these - n if n.contains("__SIZEOF_PTHREAD") => true, - - _ => false, - } - }); - - cfg.skip_field_type(move |struct_, field| { - // This is a weird union, don't check the type. - // FIXME: is this necessary? - (struct_ == "ifaddrs" && field == "ifa_ifu") || - // sighandler_t type is super weird - // FIXME: is this necessary? - (struct_ == "sigaction" && field == "sa_sigaction") || - // sigval is actually a union, but we pretend it's a struct - // FIXME: is this necessary? - (struct_ == "sigevent" && field == "sigev_value") || - // aio_buf is "volatile void*" and Rust doesn't understand volatile - // FIXME: is this necessary? - (struct_ == "aiocb" && field == "aio_buf") - }); - - cfg.skip_field(move |struct_, field| { - // this is actually a union on linux, so we can't represent it well and - // just insert some padding. - // FIXME: is this necessary? - (struct_ == "siginfo_t" && field == "_pad") || - // musl names this __dummy1 but it's still there - // FIXME: is this necessary? - (struct_ == "glob_t" && field == "gl_flags") || - // musl seems to define this as an *anonymous* bitfield - // FIXME: is this necessary? - (struct_ == "statvfs" && field == "__f_unused") || - // sigev_notify_thread_id is actually part of a sigev_un union - (struct_ == "sigevent" && field == "sigev_notify_thread_id") || - // signalfd had SIGSYS fields added in Linux 4.18, but no libc release has them yet. - (struct_ == "signalfd_siginfo" && (field == "ssi_addr_lsb" || - field == "_pad2" || - field == "ssi_syscall" || - field == "ssi_call_addr" || - field == "ssi_arch")) - }); - - // FIXME: test linux like - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_vxworks(target: &str) { - assert!(target.contains("vxworks")); - - let mut cfg = ctest::TestGenerator::new(); - headers! { cfg: - "vxWorks.h", - "yvals.h", - "nfs/nfsCommon.h", - "rtpLibCommon.h", - "randomNumGen.h", - "taskLib.h", - "sysLib.h", - "ioLib.h", - "inetLib.h", - "socket.h", - "errnoLib.h", - "ctype.h", - "dirent.h", - "dlfcn.h", - "elf.h", - "fcntl.h", - "grp.h", - "sys/poll.h", - "ifaddrs.h", - "langinfo.h", - "limits.h", - "link.h", - "locale.h", - "sys/stat.h", - "netdb.h", - "pthread.h", - "pwd.h", - "sched.h", - "semaphore.h", - "signal.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/file.h", - "sys/ioctl.h", - "sys/socket.h", - "sys/time.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/utsname.h", - "sys/wait.h", - "netinet/tcp.h", - "syslog.h", - "termios.h", - "time.h", - "ucontext.h", - "unistd.h", - "utime.h", - "wchar.h", - "errno.h", - "sys/mman.h", - "pathLib.h", - } - /* Fix me */ - cfg.skip_const(move |name| match name { - // sighandler_t weirdness - "SIG_DFL" | "SIG_ERR" | "SIG_IGN" - // This is not defined in vxWorks - | "RTLD_DEFAULT" => true, - _ => false, - }); - /* Fix me */ - cfg.skip_type(move |ty| match ty { - "stat64" | "sighandler_t" | "off64_t" => true, - _ => false, - }); - - cfg.skip_field_type(move |struct_, field| match (struct_, field) { - ("siginfo_t", "si_value") - | ("stat", "st_size") - | ("sigaction", "sa_u") => true, - _ => false, - }); - - cfg.skip_roundtrip(move |s| match s { - _ => false, - }); - - cfg.type_name(move |ty, is_struct, is_union| match ty { - "DIR" | "FILE" | "Dl_info" | "RTP_DESC" => ty.to_string(), - t if is_union => format!("union {}", t), - t if t.ends_with("_t") => t.to_string(), - t if is_struct => format!("struct {}", t), - t => t.to_string(), - }); - - /* Fix me */ - cfg.skip_fn(move |name| match name { - /* sigval */ - "sigqueue" | "_sigqueue" - /* sighandler_t*/ - | "signal" - /* not used in static linking by default */ - | "dlerror" => true, - _ => false, - }); - - cfg.generate("../src/lib.rs", "main.rs"); -} - -fn test_linux(target: &str) { - assert!(target.contains("linux")); - - // target_env - let gnu = target.contains("gnu"); - let musl = target.contains("musl"); - let uclibc = target.contains("uclibc"); - - match (gnu, musl, uclibc) { - (true, false, false) => (), - (false, true, false) => (), - (false, false, true) => (), - (_, _, _) => panic!( - "linux target lib is gnu: {}, musl: {}, uclibc: {}", - gnu, musl, uclibc - ), - } - - let arm = target.contains("arm"); - let i686 = target.contains("i686"); - let mips = target.contains("mips"); - let mips32 = mips && !target.contains("64"); - let mips64 = mips && target.contains("64"); - let ppc64 = target.contains("powerpc64"); - let s390x = target.contains("s390x"); - let sparc64 = target.contains("sparc64"); - let x32 = target.contains("x32"); - let x86_32 = target.contains("i686"); - let x86_64 = target.contains("x86_64"); - let aarch64_musl = target.contains("aarch64") && musl; - - let mut cfg = ctest_cfg(); - cfg.define("_GNU_SOURCE", None); - // This macro re-deifnes fscanf,scanf,sscanf to link to the symbols that are - // deprecated since glibc >= 2.29. This allows Rust binaries to link against - // glibc versions older than 2.29. - cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None); - - headers! { cfg: - "ctype.h", - "dirent.h", - "dlfcn.h", - "elf.h", - "fcntl.h", - "glob.h", - "grp.h", - "ifaddrs.h", - "langinfo.h", - "limits.h", - "link.h", - "locale.h", - "malloc.h", - "mntent.h", - "mqueue.h", - "net/ethernet.h", - "net/if.h", - "net/if_arp.h", - "net/route.h", - "netdb.h", - "netinet/in.h", - "netinet/ip.h", - "netinet/tcp.h", - "netinet/udp.h", - "netpacket/packet.h", - "poll.h", - "pthread.h", - "pty.h", - "pwd.h", - "resolv.h", - "sched.h", - "semaphore.h", - "shadow.h", - "signal.h", - "spawn.h", - "stddef.h", - "stdint.h", - "stdio.h", - "stdlib.h", - "string.h", - "sys/epoll.h", - "sys/eventfd.h", - "sys/file.h", - "sys/fsuid.h", - "sys/inotify.h", - "sys/ioctl.h", - "sys/ipc.h", - "sys/mman.h", - "sys/mount.h", - "sys/msg.h", - "sys/personality.h", - "sys/prctl.h", - "sys/ptrace.h", - "sys/quota.h", - "sys/random.h", - "sys/reboot.h", - "sys/resource.h", - "sys/sem.h", - "sys/sendfile.h", - "sys/shm.h", - "sys/signalfd.h", - "sys/socket.h", - "sys/stat.h", - "sys/statvfs.h", - "sys/swap.h", - "sys/syscall.h", - "sys/time.h", - "sys/timerfd.h", - "sys/times.h", - "sys/types.h", - "sys/uio.h", - "sys/un.h", - "sys/user.h", - "sys/utsname.h", - "sys/vfs.h", - "sys/wait.h", - "syslog.h", - "termios.h", - "time.h", - "ucontext.h", - "unistd.h", - "utime.h", - "utmp.h", - "utmpx.h", - "wchar.h", - "errno.h", - // `sys/io.h` is only available on x86*, Alpha, IA64, and 32-bit - // ARM: https://bugzilla.redhat.com/show_bug.cgi?id=1116162 - [x86_64 || x86_32 || arm]: "sys/io.h", - // `sys/reg.h` is only available on x86 and x86_64 - [x86_64 || x86_32]: "sys/reg.h", - // sysctl system call is deprecated and not available on musl - // It is also unsupported in x32: - [!(x32 || musl)]: "sys/sysctl.h", - // is not supported by musl: - // https://www.openwall.com/lists/musl/2015/04/09/3 - [!musl]: "execinfo.h", - } - - // Include linux headers at the end: - headers! { - cfg: - "asm/mman.h", - "linux/dccp.h", - "linux/falloc.h", - "linux/fs.h", - "linux/futex.h", - "linux/genetlink.h", - "linux/if.h", - "linux/if_addr.h", - "linux/if_alg.h", - "linux/if_ether.h", - "linux/if_tun.h", - "linux/input.h", - "linux/magic.h", - "linux/memfd.h", - "linux/module.h", - "linux/net_tstamp.h", - "linux/netfilter/nfnetlink.h", - "linux/netfilter/nfnetlink_log.h", - "linux/netfilter/nf_tables.h", - "linux/netfilter_ipv4.h", - "linux/netfilter_ipv6.h", - "linux/netlink.h", - "linux/quota.h", - "linux/random.h", - "linux/reboot.h", - "linux/rtnetlink.h", - "linux/seccomp.h", - "linux/sockios.h", - "linux/vm_sockets.h", - "sys/auxv.h", - } - - // note: aio.h must be included before sys/mount.h - headers! { - cfg: - "sys/xattr.h", - "sys/sysinfo.h", - "aio.h", - } - - cfg.type_name(move |ty, is_struct, is_union| { - match ty { - // Just pass all these through, no need for a "struct" prefix - "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" - | "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym" - | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr" - | "Elf64_Chdr" => ty.to_string(), - - t if is_union => format!("union {}", t), - - t if t.ends_with("_t") => t.to_string(), - - // In MUSL `flock64` is a typedef to `flock`. - "flock64" if musl => format!("struct {}", ty), - - // put `struct` in front of all structs:. - t if is_struct => format!("struct {}", t), - - t => t.to_string(), - } - }); - - cfg.field_name(move |struct_, field| { - match field { - // Our stat *_nsec fields normally don't actually exist but are part - // of a timeval struct - s if s.ends_with("_nsec") && struct_.starts_with("stat") => { - s.replace("e_nsec", ".tv_nsec") - } - // FIXME: epoll_event.data is actuall a union in C, but in Rust - // it is only a u64 because we only expose one field - // http://man7.org/linux/man-pages/man2/epoll_wait.2.html - "u64" if struct_ == "epoll_event" => "data.u64".to_string(), - // The following structs have a field called `type` in C, - // but `type` is a Rust keyword, so these fields are translated - // to `type_` in Rust. - "type_" - if struct_ == "input_event" - || struct_ == "input_mask" - || struct_ == "ff_effect" => - { - "type".to_string() - } - - s => s.to_string(), - } - }); - - cfg.skip_type(move |ty| { - match ty { - // FIXME: `sighandler_t` type is incorrect, see: - // https://github.com/rust-lang/libc/issues/1359 - "sighandler_t" => true, - - // These cannot be tested when "resolv.h" is included and are tested - // in the `linux_elf.rs` file. - "Elf64_Phdr" | "Elf32_Phdr" => true, - - // This type is private on Linux. It is implemented as a C `enum` - // (`c_uint`) and this clashes with the type of the `rlimit` APIs - // which expect a `c_int` even though both are ABI compatible. - "__rlimit_resource_t" => true, - - _ => false, - } - }); - - cfg.skip_struct(move |ty| { - match ty { - // These cannot be tested when "resolv.h" is included and are tested - // in the `linux_elf.rs` file. - "Elf64_Phdr" | "Elf32_Phdr" => true, - - // On Linux, the type of `ut_tv` field of `struct utmpx` - // can be an anonymous struct, so an extra struct, - // which is absent in glibc, has to be defined. - "__timeval" => true, - - // FIXME: This is actually a union, not a struct - "sigval" => true, - - // This type is tested in the `linux_termios.rs` file since there - // are header conflicts when including them with all the other - // structs. - "termios2" => true, - - // FIXME: remove once Ubuntu 20.04 LTS is released, somewhere in 2020. - // ucontext_t added a new field as of glibc 2.28; our struct definition is - // conservative and omits the field, but that means the size doesn't match for newer - // glibcs (see https://github.com/rust-lang/libc/issues/1410) - "ucontext_t" if gnu => true, - - _ => false, - } - }); - - cfg.skip_const(move |name| { - match name { - // These constants are not available if gnu headers have been included - // and can therefore not be tested here - // - // The IPV6 constants are tested in the `linux_ipv6.rs` tests: - | "IPV6_FLOWINFO" - | "IPV6_FLOWLABEL_MGR" - | "IPV6_FLOWINFO_SEND" - | "IPV6_FLOWINFO_FLOWLABEL" - | "IPV6_FLOWINFO_PRIORITY" - // The F_ fnctl constants are tested in the `linux_fnctl.rs` tests: - | "F_CANCELLK" - | "F_ADD_SEALS" - | "F_GET_SEALS" - | "F_SEAL_SEAL" - | "F_SEAL_SHRINK" - | "F_SEAL_GROW" - | "F_SEAL_WRITE" => true, - - // The musl-sanitized kernel headers used in CI - // target the Linux kernel 4.4 and do not contain the - // following constants: - // - // Requires Linux kernel 4.9 - | "FALLOC_FL_UNSHARE_RANGE" - // - // Require Linux kernel 5.x: - | "MSG_COPY" - if musl => true, - // Require Linux kernel 5.1: - "F_SEAL_FUTURE_WRITE" => true, - - // The musl version 1.1.24 used in CI does not - // contain these glibc constants yet: - | "RLIMIT_RTTIME" // should be in `resource.h` - | "TCP_COOKIE_TRANSACTIONS" // should be in the `netinet/tcp.h` header - if musl => true, - - // FIXME: deprecated: not available in any header - // See: https://github.com/rust-lang/libc/issues/1356 - "ENOATTR" => true, - - // FIXME: SIGUNUSED was removed in glibc 2.26 - // Users should use SIGSYS instead. - "SIGUNUSED" => true, - - // FIXME: conflicts with glibc headers and is tested in - // `linux_termios.rs` below: - "BOTHER" => true, - - // FIXME: on musl the pthread types are defined a little differently - // - these constants are used by the glibc implementation. - n if musl && n.contains("__SIZEOF_PTHREAD") => true, - - _ => false, - } - }); - - cfg.skip_fn(move |name| { - // skip those that are manually verified - match name { - // FIXME: https://github.com/rust-lang/libc/issues/1272 - "execv" | "execve" | "execvp" | "execvpe" | "fexecve" => true, - - // There are two versions of the sterror_r function, see - // - // https://linux.die.net/man/3/strerror_r - // - // An XSI-compliant version provided if: - // - // (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) - // && ! _GNU_SOURCE - // - // and a GNU specific version provided if _GNU_SOURCE is defined. - // - // libc provides bindings for the XSI-compliant version, which is - // preferred for portable applications. - // - // We skip the test here since here _GNU_SOURCE is defined, and - // test the XSI version below. - "strerror_r" => true, - - // FIXME: Our API is unsound. The Rust API allows aliasing - // pointers, but the C API requires pointers not to alias. - // We should probably be at least using `&`/`&mut` here, see: - // https://github.com/gnzlbg/ctest/issues/68 - "lio_listio" if musl => true, - - // FIXME: the glibc version used by the Sparc64 build jobs - // which use Debian 10.0 is too old. - "statx" if sparc64 => true, - - _ => false, - } - }); - - cfg.skip_field_type(move |struct_, field| { - // This is a weird union, don't check the type. - (struct_ == "ifaddrs" && field == "ifa_ifu") || - // sighandler_t type is super weird - (struct_ == "sigaction" && field == "sa_sigaction") || - // __timeval type is a patch which doesn't exist in glibc - (struct_ == "utmpx" && field == "ut_tv") || - // sigval is actually a union, but we pretend it's a struct - (struct_ == "sigevent" && field == "sigev_value") || - // this one is an anonymous union - (struct_ == "ff_effect" && field == "u") - }); - - cfg.volatile_item(|i| { - use ctest::VolatileItemKind::*; - match i { - // aio_buf is a volatile void** but since we cannot express that in - // Rust types, we have to explicitly tell the checker about it here: - StructField(ref n, ref f) if n == "aiocb" && f == "aio_buf" => { - true - } - _ => false, - } - }); - - cfg.skip_field(move |struct_, field| { - // this is actually a union on linux, so we can't represent it well and - // just insert some padding. - (struct_ == "siginfo_t" && field == "_pad") || - // musl names this __dummy1 but it's still there - (musl && struct_ == "glob_t" && field == "gl_flags") || - // musl seems to define this as an *anonymous* bitfield - (musl && struct_ == "statvfs" && field == "__f_unused") || - // sigev_notify_thread_id is actually part of a sigev_un union - (struct_ == "sigevent" && field == "sigev_notify_thread_id") || - // signalfd had SIGSYS fields added in Linux 4.18, but no libc release - // has them yet. - (struct_ == "signalfd_siginfo" && (field == "ssi_addr_lsb" || - field == "_pad2" || - field == "ssi_syscall" || - field == "ssi_call_addr" || - field == "ssi_arch")) || - // FIXME: After musl 1.1.24, it have only one field `sched_priority`, - // while other fields become reserved. - (struct_ == "sched_param" && [ - "sched_ss_low_priority", - "sched_ss_repl_period", - "sched_ss_init_budget", - "sched_ss_max_repl", - ].contains(&field) && musl) || - // FIXME: After musl 1.1.24, the type becomes `int` instead of `unsigned short`. - (struct_ == "ipc_perm" && field == "__seq" && aarch64_musl) - }); - - cfg.skip_roundtrip(move |s| match s { - // FIXME: - "utsname" if mips32 || mips64 => true, - // FIXME: - "mcontext_t" if s390x => true, - - "sockaddr_un" | "sembuf" | "ff_constant_effect" - if mips32 && (gnu || musl) => - { - true - } - "ipv6_mreq" - | "ip_mreq_source" - | "sockaddr_in6" - | "sockaddr_ll" - | "in_pktinfo" - | "arpreq" - | "arpreq_old" - | "sockaddr_un" - | "ff_constant_effect" - | "ff_ramp_effect" - | "ff_condition_effect" - | "Elf32_Ehdr" - | "Elf32_Chdr" - | "ucred" - | "in6_pktinfo" - | "sockaddr_nl" - | "termios" - | "nlmsgerr" - if (mips64 || sparc64) && gnu => - { - true - } - - // FIXME: the call ABI of max_align_t is incorrect on these platforms: - "max_align_t" if i686 || mips64 || ppc64 => true, - - _ => false, - }); - - cfg.generate("../src/lib.rs", "main.rs"); - - test_linux_like_apis(target); -} - -// This function tests APIs that are incompatible to test when other APIs -// are included (e.g. because including both sets of headers clashes) -fn test_linux_like_apis(target: &str) { - let musl = target.contains("musl"); - let linux = target.contains("linux"); - let emscripten = target.contains("emscripten"); - let android = target.contains("android"); - assert!(linux || android || emscripten); - - if linux || android || emscripten { - // test strerror_r from the `string.h` header - let mut cfg = ctest_cfg(); - cfg.skip_type(|_| true).skip_static(|_| true); - - headers! { cfg: "string.h" } - cfg.skip_fn(|f| match f { - "strerror_r" => false, - _ => true, - }) - .skip_const(|_| true) - .skip_struct(|_| true); - cfg.generate("../src/lib.rs", "linux_strerror_r.rs"); - } - - if linux || android || emscripten { - // test fcntl - see: - // http://man7.org/linux/man-pages/man2/fcntl.2.html - let mut cfg = ctest_cfg(); - - if musl { - cfg.header("fcntl.h"); - } else { - cfg.header("linux/fcntl.h"); - } - - cfg.skip_type(|_| true) - .skip_static(|_| true) - .skip_struct(|_| true) - .skip_fn(|_| true) - .skip_const(move |name| match name { - // test fcntl constants: - "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" - | "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" - | "F_SEAL_WRITE" => false, - _ => true, - }) - .type_name(move |ty, is_struct, is_union| match ty { - t if is_struct => format!("struct {}", t), - t if is_union => format!("union {}", t), - t => t.to_string(), - }); - - cfg.generate("../src/lib.rs", "linux_fcntl.rs"); - } - - if linux || android { - // test termios - let mut cfg = ctest_cfg(); - cfg.header("asm/termbits.h"); - cfg.skip_type(|_| true) - .skip_static(|_| true) - .skip_fn(|_| true) - .skip_const(|c| c != "BOTHER") - .skip_struct(|s| s != "termios2") - .type_name(move |ty, is_struct, is_union| match ty { - t if is_struct => format!("struct {}", t), - t if is_union => format!("union {}", t), - t => t.to_string(), - }); - cfg.generate("../src/lib.rs", "linux_termios.rs"); - } - - if linux || android { - // test IPV6_ constants: - let mut cfg = ctest_cfg(); - headers! { - cfg: - "linux/in6.h" - } - cfg.skip_type(|_| true) - .skip_static(|_| true) - .skip_fn(|_| true) - .skip_const(|_| true) - .skip_struct(|_| true) - .skip_const(move |name| match name { - "IPV6_FLOWINFO" - | "IPV6_FLOWLABEL_MGR" - | "IPV6_FLOWINFO_SEND" - | "IPV6_FLOWINFO_FLOWLABEL" - | "IPV6_FLOWINFO_PRIORITY" => false, - _ => true, - }) - .type_name(move |ty, is_struct, is_union| match ty { - t if is_struct => format!("struct {}", t), - t if is_union => format!("union {}", t), - t => t.to_string(), - }); - cfg.generate("../src/lib.rs", "linux_ipv6.rs"); - } - - if linux || android { - // Test Elf64_Phdr and Elf32_Phdr - // These types have a field called `p_type`, but including - // "resolve.h" defines a `p_type` macro that expands to `__p_type` - // making the tests for these fails when both are included. - let mut cfg = ctest_cfg(); - cfg.header("elf.h"); - cfg.skip_fn(|_| true) - .skip_static(|_| true) - .skip_fn(|_| true) - .skip_const(|_| true) - .type_name(move |ty, _is_struct, _is_union| ty.to_string()) - .skip_struct(move |ty| match ty { - "Elf64_Phdr" | "Elf32_Phdr" => false, - _ => true, - }) - .skip_type(move |ty| match ty { - "Elf64_Phdr" | "Elf32_Phdr" => false, - _ => true, - }); - cfg.generate("../src/lib.rs", "linux_elf.rs"); - } -} - -fn which_freebsd() -> Option { - let output = std::process::Command::new("freebsd-version") - .output() - .ok()?; - if !output.status.success() { - return None; - } - - let stdout = String::from_utf8(output.stdout).ok()?; - - match &stdout { - s if s.starts_with("10") => Some(10), - s if s.starts_with("11") => Some(11), - s if s.starts_with("12") => Some(12), - s if s.starts_with("13") => Some(13), - _ => None, - } -} diff --git a/libc/libc-test/src/cmsg.c b/libc/libc-test/src/cmsg.c deleted file mode 100644 index a8b1c37..0000000 --- a/libc/libc-test/src/cmsg.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -// Since the cmsg(3) macros are macros instead of functions, they aren't -// available to FFI. libc must reimplement them, which is error-prone. This -// file provides FFI access to the actual macros so they can be tested against -// the Rust reimplementations. - -struct cmsghdr *cmsg_firsthdr(struct msghdr *msgh) { - return CMSG_FIRSTHDR(msgh); -} - -struct cmsghdr *cmsg_nxthdr(struct msghdr *msgh, struct cmsghdr *cmsg) { - return CMSG_NXTHDR(msgh, cmsg); -} - -size_t cmsg_space(size_t length) { - return CMSG_SPACE(length); -} - -size_t cmsg_len(size_t length) { - return CMSG_LEN(length); -} - -unsigned char *cmsg_data(struct cmsghdr *cmsg) { - return CMSG_DATA(cmsg); -} - diff --git a/libc/libc-test/test/cmsg.rs b/libc/libc-test/test/cmsg.rs deleted file mode 100644 index 38a8ce1..0000000 --- a/libc/libc-test/test/cmsg.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! Compare libc's CMSG(3) family of functions against the actual C macros, for -//! various inputs. - -extern crate libc; - -#[cfg(unix)] -mod t { - - use libc::{self, c_uchar, c_uint, c_void, cmsghdr, msghdr}; - use std::mem; - - extern "C" { - pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr; - pub fn cmsg_nxthdr( - mhdr: *const msghdr, - cmsg: *const cmsghdr, - ) -> *mut cmsghdr; - pub fn cmsg_space(length: c_uint) -> usize; - pub fn cmsg_len(length: c_uint) -> usize; - pub fn cmsg_data(cmsg: *const cmsghdr) -> *mut c_uchar; - } - - #[test] - fn test_cmsg_data() { - for l in 0..128 { - let pcmsghdr = l as *const cmsghdr; - unsafe { - assert_eq!(libc::CMSG_DATA(pcmsghdr), cmsg_data(pcmsghdr)); - } - } - } - - #[test] - fn test_cmsg_firsthdr() { - let mut mhdr: msghdr = unsafe { mem::zeroed() }; - mhdr.msg_control = 0xdeadbeef as *mut c_void; - let pmhdr = &mhdr as *const msghdr; - for l in 0..128 { - mhdr.msg_controllen = l; - unsafe { - assert_eq!(libc::CMSG_FIRSTHDR(pmhdr), cmsg_firsthdr(pmhdr)); - } - } - } - - #[test] - fn test_cmsg_len() { - for l in 0..128 { - unsafe { - assert_eq!(libc::CMSG_LEN(l) as usize, cmsg_len(l)); - } - } - } - - // Skip on sparc64 - // https://github.com/rust-lang/libc/issues/1239 - #[cfg(not(target_arch = "sparc64"))] - #[test] - fn test_cmsg_nxthdr() { - use std::ptr; - - let mut buffer = [0u8; 256]; - let mut mhdr: msghdr = unsafe { mem::zeroed() }; - let pmhdr = &mhdr as *const msghdr; - for start_ofs in 0..64 { - let pcmsghdr = &mut buffer[start_ofs] as *mut u8 as *mut cmsghdr; - mhdr.msg_control = pcmsghdr as *mut c_void; - mhdr.msg_controllen = (160 - start_ofs) as _; - for cmsg_len in 0..64 { - for next_cmsg_len in 0..32 { - for i in buffer[start_ofs..].iter_mut() { - *i = 0; - } - unsafe { - (*pcmsghdr).cmsg_len = cmsg_len; - let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr); - let next = cmsg_nxthdr(pmhdr, pcmsghdr); - assert_eq!(libc_next, next); - - if libc_next != ptr::null_mut() { - (*libc_next).cmsg_len = next_cmsg_len; - let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr); - let next = cmsg_nxthdr(pmhdr, pcmsghdr); - assert_eq!(libc_next, next); - } - } - } - } - } - } - - #[test] - fn test_cmsg_space() { - unsafe { - for l in 0..128 { - assert_eq!(libc::CMSG_SPACE(l) as usize, cmsg_space(l)); - } - } - } -} diff --git a/libc/libc-test/test/linux_elf.rs b/libc/libc-test/test/linux_elf.rs deleted file mode 100644 index d149c9a..0000000 --- a/libc/libc-test/test/linux_elf.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(bad_style, improper_ctypes, unused, deprecated)] - -extern crate libc; -use libc::*; - -#[cfg(target_os = "linux")] -include!(concat!(env!("OUT_DIR"), "/linux_elf.rs")); - -#[cfg(not(target_os = "linux"))] -fn main() { - println!("PASSED 0 tests"); -} diff --git a/libc/libc-test/test/linux_fcntl.rs b/libc/libc-test/test/linux_fcntl.rs deleted file mode 100644 index 49c06cc..0000000 --- a/libc/libc-test/test/linux_fcntl.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(bad_style, improper_ctypes, unused, deprecated)] - -extern crate libc; -use libc::*; - -#[cfg(any(target_os = "linux", target_os = "android"))] -include!(concat!(env!("OUT_DIR"), "/linux_fcntl.rs")); - -#[cfg(not(any(target_os = "linux", target_os = "android")))] -fn main() { - println!("PASSED 0 tests"); -} diff --git a/libc/libc-test/test/linux_ipv6.rs b/libc/libc-test/test/linux_ipv6.rs deleted file mode 100644 index 83c389c..0000000 --- a/libc/libc-test/test/linux_ipv6.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(bad_style, improper_ctypes, unused, deprecated)] - -extern crate libc; -use libc::*; - -#[cfg(target_os = "linux")] -include!(concat!(env!("OUT_DIR"), "/linux_ipv6.rs")); - -#[cfg(not(target_os = "linux"))] -fn main() { - println!("PASSED 0 tests"); -} diff --git a/libc/libc-test/test/linux_strerror_r.rs b/libc/libc-test/test/linux_strerror_r.rs deleted file mode 100644 index 17db959..0000000 --- a/libc/libc-test/test/linux_strerror_r.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(bad_style, improper_ctypes, unused, deprecated)] - -extern crate libc; -use libc::*; - -#[cfg(any(target_os = "linux", target_os = "android"))] -include!(concat!(env!("OUT_DIR"), "/linux_strerror_r.rs")); - -#[cfg(not(any(target_os = "linux", target_os = "android")))] -fn main() { - println!("PASSED 0 tests"); -} diff --git a/libc/libc-test/test/linux_termios.rs b/libc/libc-test/test/linux_termios.rs deleted file mode 100644 index 703a9b9..0000000 --- a/libc/libc-test/test/linux_termios.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(bad_style, improper_ctypes, unused, deprecated)] - -extern crate libc; -use libc::*; - -#[cfg(any(target_os = "linux", target_os = "android"))] -include!(concat!(env!("OUT_DIR"), "/linux_termios.rs")); - -#[cfg(not(any(target_os = "linux", target_os = "android")))] -fn main() { - println!("PASSED 0 tests"); -} diff --git a/libc/libc-test/test/main.rs b/libc/libc-test/test/main.rs deleted file mode 100644 index 62a587c..0000000 --- a/libc/libc-test/test/main.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![allow(bad_style, improper_ctypes, deprecated)] -extern crate libc; - -use libc::*; - -include!(concat!(env!("OUT_DIR"), "/main.rs")); diff --git a/libc/rustfmt.toml b/libc/rustfmt.toml deleted file mode 100644 index 7ecc610..0000000 --- a/libc/rustfmt.toml +++ /dev/null @@ -1,3 +0,0 @@ -max_width = 79 -comment_width = 79 -error_on_line_overflow = true \ No newline at end of file diff --git a/libc/src/cloudabi/aarch64.rs b/libc/src/cloudabi/aarch64.rs deleted file mode 100644 index 4caa6d7..0000000 --- a/libc/src/cloudabi/aarch64.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = u8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type wchar_t = u32; diff --git a/libc/src/cloudabi/arm.rs b/libc/src/cloudabi/arm.rs deleted file mode 100644 index eca5360..0000000 --- a/libc/src/cloudabi/arm.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = u8; -pub type c_long = i32; -pub type c_ulong = u32; -pub type wchar_t = u32; diff --git a/libc/src/cloudabi/mod.rs b/libc/src/cloudabi/mod.rs deleted file mode 100644 index b3065d7..0000000 --- a/libc/src/cloudabi/mod.rs +++ /dev/null @@ -1,374 +0,0 @@ -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type size_t = usize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type ssize_t = isize; - -pub type in_addr_t = u32; -pub type in_port_t = u16; -pub type pthread_key_t = usize; -pub type pthread_t = usize; -pub type sa_family_t = u8; -pub type socklen_t = usize; -pub type time_t = i64; - -s! { - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: ::socklen_t, - pub ai_addr: *mut ::sockaddr, - pub ai_canonname: *mut ::c_char, - pub ai_next: *mut addrinfo, - } - - pub struct in_addr { - pub s_addr: in_addr_t, - } - - pub struct in6_addr { - pub s6_addr: [u8; 16], - } - - pub struct pthread_attr_t { - __detachstate: ::c_int, - __stacksize: usize, - } - - pub struct sockaddr { - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 0], - } - - pub struct sockaddr_in { - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - } - - pub struct sockaddr_in6 { - pub sin6_family: sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct sockaddr_storage { - pub ss_family: ::sa_family_t, - __ss_data: [u8; 32], - } -} - -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; - -pub const _SC_NPROCESSORS_ONLN: ::c_int = 52; -pub const _SC_PAGESIZE: ::c_int = 54; - -pub const AF_INET: ::c_int = 1; -pub const AF_INET6: ::c_int = 2; - -pub const EACCES: ::c_int = 2; -pub const EADDRINUSE: ::c_int = 3; -pub const EADDRNOTAVAIL: ::c_int = 4; -pub const EAGAIN: ::c_int = 6; -pub const ECONNABORTED: ::c_int = 13; -pub const ECONNREFUSED: ::c_int = 14; -pub const ECONNRESET: ::c_int = 15; -pub const EEXIST: ::c_int = 20; -pub const EINTR: ::c_int = 27; -pub const EINVAL: ::c_int = 28; -pub const ENOENT: ::c_int = 44; -pub const ENOTCONN: ::c_int = 53; -pub const EPERM: ::c_int = 63; -pub const EPIPE: ::c_int = 64; -pub const ETIMEDOUT: ::c_int = 73; -pub const EWOULDBLOCK: ::c_int = EAGAIN; - -pub const EAI_SYSTEM: ::c_int = 9; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; - -pub const PTHREAD_STACK_MIN: ::size_t = 1024; - -pub const SOCK_DGRAM: ::c_int = 128; -pub const SOCK_STREAM: ::c_int = 130; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum FILE {} -impl ::Copy for FILE {} -impl ::Clone for FILE { - fn clone(&self) -> FILE { - *self - } -} -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos_t {} // TODO: fill this out with a struct -impl ::Copy for fpos_t {} -impl ::Clone for fpos_t { - fn clone(&self) -> fpos_t { - *self - } -} - -extern "C" { - pub fn isalnum(c: c_int) -> c_int; - pub fn isalpha(c: c_int) -> c_int; - pub fn iscntrl(c: c_int) -> c_int; - pub fn isdigit(c: c_int) -> c_int; - pub fn isgraph(c: c_int) -> c_int; - pub fn islower(c: c_int) -> c_int; - pub fn isprint(c: c_int) -> c_int; - pub fn ispunct(c: c_int) -> c_int; - pub fn isspace(c: c_int) -> c_int; - pub fn isupper(c: c_int) -> c_int; - pub fn isxdigit(c: c_int) -> c_int; - pub fn isblank(c: c_int) -> c_int; - pub fn tolower(c: c_int) -> c_int; - pub fn toupper(c: c_int) -> c_int; - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - pub fn freopen( - filename: *const c_char, - mode: *const c_char, - file: *mut FILE, - ) -> *mut FILE; - pub fn fflush(file: *mut FILE) -> c_int; - pub fn fclose(file: *mut FILE) -> c_int; - pub fn remove(filename: *const c_char) -> c_int; - pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; - pub fn tmpfile() -> *mut FILE; - pub fn setvbuf( - stream: *mut FILE, - buffer: *mut c_char, - mode: c_int, - size: size_t, - ) -> c_int; - pub fn setbuf(stream: *mut FILE, buf: *mut c_char); - pub fn getchar() -> c_int; - pub fn putchar(c: c_int) -> c_int; - pub fn fgetc(stream: *mut FILE) -> c_int; - pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) - -> *mut c_char; - pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; - pub fn puts(s: *const c_char) -> c_int; - pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fread( - ptr: *mut c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fwrite( - ptr: *const c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; - pub fn ftell(stream: *mut FILE) -> c_long; - pub fn rewind(stream: *mut FILE); - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; - pub fn feof(stream: *mut FILE) -> c_int; - pub fn ferror(stream: *mut FILE) -> c_int; - pub fn perror(s: *const c_char); - pub fn atoi(s: *const c_char) -> c_int; - pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; - pub fn strtol( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_long; - pub fn strtoul( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_ulong; - pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; - pub fn malloc(size: size_t) -> *mut c_void; - pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; - pub fn free(p: *mut c_void); - pub fn abort() -> !; - pub fn exit(status: c_int) -> !; - pub fn _exit(status: c_int) -> !; - pub fn atexit(cb: extern "C" fn()) -> c_int; - pub fn system(s: *const c_char) -> c_int; - pub fn getenv(s: *const c_char) -> *mut c_char; - pub fn getline( - lineptr: *mut *mut c_char, - n: *mut size_t, - stream: *mut FILE, - ) -> ssize_t; - - pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; - pub fn strncpy( - dst: *mut c_char, - src: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; - pub fn strncat( - s: *mut c_char, - ct: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; - pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strdup(cs: *const c_char) -> *mut c_char; - pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; - pub fn strncasecmp( - s1: *const c_char, - s2: *const c_char, - n: size_t, - ) -> c_int; - pub fn strlen(cs: *const c_char) -> size_t; - pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; - pub fn strerror(n: c_int) -> *mut c_char; - pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; - pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; - pub fn wcslen(buf: *const wchar_t) -> size_t; - pub fn wcstombs( - dest: *mut c_char, - src: *const wchar_t, - n: size_t, - ) -> ::size_t; - - pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memcpy( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memmove( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; - - pub fn abs(i: c_int) -> c_int; - pub fn atof(s: *const c_char) -> c_double; - pub fn labs(i: c_long) -> c_long; - pub fn rand() -> c_int; - pub fn srand(seed: c_uint); - - pub fn arc4random_buf(buf: *const ::c_void, len: ::size_t); - pub fn freeaddrinfo(res: *mut addrinfo); - pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char; - pub fn getaddrinfo( - node: *const c_char, - service: *const c_char, - hints: *const addrinfo, - res: *mut *mut addrinfo, - ) -> ::c_int; - pub fn getsockopt( - sockfd: ::c_int, - level: ::c_int, - optname: ::c_int, - optval: *mut ::c_void, - optlen: *mut ::socklen_t, - ) -> ::c_int; - pub fn posix_memalign( - memptr: *mut *mut ::c_void, - align: ::size_t, - size: ::size_t, - ) -> ::c_int; - pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int; - pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int; - pub fn pthread_attr_setstacksize( - attr: *mut ::pthread_attr_t, - stack_size: ::size_t, - ) -> ::c_int; - pub fn pthread_create( - native: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - pub fn pthread_detach(thread: ::pthread_t) -> ::c_int; - pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void; - pub fn pthread_join( - native: ::pthread_t, - value: *mut *mut ::c_void, - ) -> ::c_int; - pub fn pthread_key_create( - key: *mut pthread_key_t, - dtor: ::Option, - ) -> ::c_int; - pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int; - pub fn pthread_setspecific( - key: pthread_key_t, - value: *const ::c_void, - ) -> ::c_int; - pub fn send( - socket: ::c_int, - buf: *const ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - pub fn sysconf(name: ::c_int) -> ::c_long; -} - -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(any(target_arch = "arm"))] { - mod arm; - pub use self::arm::*; - } else if #[cfg(any(target_arch = "x86"))] { - mod x86; - pub use self::x86::*; - } else if #[cfg(any(target_arch = "x86_64"))] { - mod x86_64; - pub use self::x86_64::*; - } else { - // Unknown target_arch - } -} - -cfg_if! { - if #[cfg(libc_core_cvoid)] { - pub use ::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - #[allow(missing_copy_implementations)] - #[allow(missing_debug_implementations)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} diff --git a/libc/src/cloudabi/x86.rs b/libc/src/cloudabi/x86.rs deleted file mode 100644 index 2f9f39c..0000000 --- a/libc/src/cloudabi/x86.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = i8; -pub type c_long = i32; -pub type c_ulong = u32; -pub type wchar_t = i32; diff --git a/libc/src/cloudabi/x86_64.rs b/libc/src/cloudabi/x86_64.rs deleted file mode 100644 index bb17624..0000000 --- a/libc/src/cloudabi/x86_64.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = i8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type wchar_t = i32; diff --git a/libc/src/fixed_width_ints.rs b/libc/src/fixed_width_ints.rs deleted file mode 100644 index 0146408..0000000 --- a/libc/src/fixed_width_ints.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! This module contains type aliases for C's fixed-width integer types . -//! -//! These aliases are deprecated: use the Rust types instead. - -#[deprecated(since = "0.2.55", note = "Use i8 instead.")] -pub type int8_t = i8; -#[deprecated(since = "0.2.55", note = "Use i16 instead.")] -pub type int16_t = i16; -#[deprecated(since = "0.2.55", note = "Use i32 instead.")] -pub type int32_t = i32; -#[deprecated(since = "0.2.55", note = "Use i64 instead.")] -pub type int64_t = i64; -#[deprecated(since = "0.2.55", note = "Use u8 instead.")] -pub type uint8_t = u8; -#[deprecated(since = "0.2.55", note = "Use u16 instead.")] -pub type uint16_t = u16; -#[deprecated(since = "0.2.55", note = "Use u32 instead.")] -pub type uint32_t = u32; -#[deprecated(since = "0.2.55", note = "Use u64 instead.")] -pub type uint64_t = u64; diff --git a/libc/src/fuchsia/aarch64.rs b/libc/src/fuchsia/aarch64.rs deleted file mode 100644 index 259893c..0000000 --- a/libc/src/fuchsia/aarch64.rs +++ /dev/null @@ -1,66 +0,0 @@ -pub type c_char = u8; -pub type __u64 = ::c_ulonglong; -pub type wchar_t = u32; -pub type nlink_t = ::c_ulong; -pub type blksize_t = ::c_long; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad0: ::c_ulong, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - __pad1: ::c_int, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_uint; 2], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad0: ::c_ulong, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - __pad1: ::c_int, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_uint; 2], - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong, - } -} - -pub const MINSIGSTKSZ: ::size_t = 6144; -pub const SIGSTKSZ: ::size_t = 12288; diff --git a/libc/src/fuchsia/align.rs b/libc/src/fuchsia/align.rs deleted file mode 100644 index 3409bf0..0000000 --- a/libc/src/fuchsia/align.rs +++ /dev/null @@ -1,142 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - #[cfg_attr( - any( - target_pointer_width = "32", - target_arch = "x86_64" - ), - repr(align(4)))] - #[cfg_attr( - not(any( - target_pointer_width = "32", - target_arch = "x86_64" - )), - repr(align(8)))] - pub struct pthread_mutexattr_t { - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[cfg_attr(target_pointer_width = "32", - repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", - repr(align(8)))] - pub struct pthread_rwlockattr_t { - size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - #[repr(align(4))] - pub struct pthread_condattr_t { - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - - s_no_extra_traits! { - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "arm", - target_arch = "x86_64")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "arm", - target_arch = "x86_64"))), - repr(align(8)))] - pub struct pthread_mutex_t { - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "arm", - target_arch = "x86_64")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "arm", - target_arch = "x86_64"))), - repr(align(8)))] - pub struct pthread_rwlock_t { - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - - #[cfg_attr(target_pointer_width = "32", - repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", - repr(align(8)))] - #[cfg_attr(target_arch = "x86", - repr(align(4)))] - #[cfg_attr(not(target_arch = "x86"), - repr(align(8)))] - pub struct pthread_cond_t { - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - } - - cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for pthread_cond_t { - fn eq(&self, other: &pthread_cond_t) -> bool { - self.size - .iter() - .zip(other.size.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_cond_t {} - impl ::fmt::Debug for pthread_cond_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_cond_t") - // FIXME: .field("size", &self.size) - .finish() - } - } - impl ::hash::Hash for pthread_cond_t { - fn hash(&self, state: &mut H) { - self.size.hash(state); - } - } - - impl PartialEq for pthread_mutex_t { - fn eq(&self, other: &pthread_mutex_t) -> bool { - self.size - .iter() - .zip(other.size.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_mutex_t {} - impl ::fmt::Debug for pthread_mutex_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_mutex_t") - // FIXME: .field("size", &self.size) - .finish() - } - } - impl ::hash::Hash for pthread_mutex_t { - fn hash(&self, state: &mut H) { - self.size.hash(state); - } - } - - impl PartialEq for pthread_rwlock_t { - fn eq(&self, other: &pthread_rwlock_t) -> bool { - self.size - .iter() - .zip(other.size.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_rwlock_t {} - impl ::fmt::Debug for pthread_rwlock_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_rwlock_t") - // FIXME: .field("size", &self.size) - .finish() - } - } - impl ::hash::Hash for pthread_rwlock_t { - fn hash(&self, state: &mut H) { - self.size.hash(state); - } - } - } - } - }; -} diff --git a/libc/src/fuchsia/mod.rs b/libc/src/fuchsia/mod.rs deleted file mode 100644 index 7d23e67..0000000 --- a/libc/src/fuchsia/mod.rs +++ /dev/null @@ -1,4571 +0,0 @@ -//! Definitions found commonly among almost all Unix derivatives -//! -//! More functions and definitions can be found in the more specific modules -//! according to the platform in question. - -// PUB_TYPE - -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type locale_t = *mut ::c_void; - -pub type size_t = usize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type ssize_t = isize; - -pub type pid_t = i32; -pub type uid_t = u32; -pub type gid_t = u32; -pub type in_addr_t = u32; -pub type in_port_t = u16; -pub type sighandler_t = ::size_t; -pub type cc_t = ::c_uchar; -pub type sa_family_t = u16; -pub type pthread_key_t = ::c_uint; -pub type speed_t = ::c_uint; -pub type tcflag_t = ::c_uint; -pub type clockid_t = ::c_int; -pub type key_t = ::c_int; -pub type id_t = ::c_uint; -pub type useconds_t = u32; -pub type dev_t = u64; -pub type socklen_t = u32; -pub type pthread_t = c_ulong; -pub type mode_t = u32; -pub type ino64_t = u64; -pub type off64_t = i64; -pub type blkcnt64_t = i64; -pub type rlim64_t = u64; -pub type mqd_t = ::c_int; -pub type nfds_t = ::c_ulong; -pub type nl_item = ::c_int; -pub type idtype_t = ::c_uint; -pub type loff_t = ::c_longlong; - -pub type __u8 = ::c_uchar; -pub type __u16 = ::c_ushort; -pub type __s16 = ::c_short; -pub type __u32 = ::c_uint; -pub type __s32 = ::c_int; - -pub type Elf32_Half = u16; -pub type Elf32_Word = u32; -pub type Elf32_Off = u32; -pub type Elf32_Addr = u32; - -pub type Elf64_Half = u16; -pub type Elf64_Word = u32; -pub type Elf64_Off = u64; -pub type Elf64_Addr = u64; -pub type Elf64_Xword = u64; - -pub type clock_t = c_long; -pub type time_t = c_long; -pub type suseconds_t = c_long; -pub type ino_t = u64; -pub type off_t = i64; -pub type blkcnt_t = i64; - -pub type shmatt_t = ::c_ulong; -pub type msgqnum_t = ::c_ulong; -pub type msglen_t = ::c_ulong; -pub type fsblkcnt_t = ::c_ulonglong; -pub type fsfilcnt_t = ::c_ulonglong; -pub type rlim_t = ::c_ulonglong; - -pub type c_long = i64; -pub type c_ulong = u64; - -// FIXME: why are these uninhabited types? that seems... wrong? -// Presumably these should be `()` or an `extern type` (when that stabilizes). -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum DIR {} -impl ::Copy for DIR {} -impl ::Clone for DIR { - fn clone(&self) -> DIR { - *self - } -} - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos64_t {} // TODO: fill this out with a struct -impl ::Copy for fpos64_t {} -impl ::Clone for fpos64_t { - fn clone(&self) -> fpos64_t { - *self - } -} - -// PUB_STRUCT - -s! { - pub struct group { - pub gr_name: *mut ::c_char, - pub gr_passwd: *mut ::c_char, - pub gr_gid: ::gid_t, - pub gr_mem: *mut *mut ::c_char, - } - - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: ::c_long, - } - - // FIXME: the rlimit and rusage related functions and types don't exist - // within zircon. Are there reasons for keeping them around? - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad1: u32, - pub ru_ixrss: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad2: u32, - pub ru_idrss: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad3: u32, - pub ru_isrss: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad4: u32, - pub ru_minflt: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad5: u32, - pub ru_majflt: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad6: u32, - pub ru_nswap: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad7: u32, - pub ru_inblock: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad8: u32, - pub ru_oublock: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad9: u32, - pub ru_msgsnd: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad10: u32, - pub ru_msgrcv: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad11: u32, - pub ru_nsignals: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad12: u32, - pub ru_nvcsw: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad13: u32, - pub ru_nivcsw: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad14: u32, - } - - pub struct in_addr { - pub s_addr: in_addr_t, - } - - pub struct in6_addr { - pub s6_addr: [u8; 16], - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct ipv6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: ::c_uint, - } - - pub struct hostent { - pub h_name: *mut ::c_char, - pub h_aliases: *mut *mut ::c_char, - pub h_addrtype: ::c_int, - pub h_length: ::c_int, - pub h_addr_list: *mut *mut ::c_char, - } - - pub struct iovec { - pub iov_base: *mut ::c_void, - pub iov_len: ::size_t, - } - - pub struct pollfd { - pub fd: ::c_int, - pub events: ::c_short, - pub revents: ::c_short, - } - - pub struct winsize { - pub ws_row: ::c_ushort, - pub ws_col: ::c_ushort, - pub ws_xpixel: ::c_ushort, - pub ws_ypixel: ::c_ushort, - } - - pub struct linger { - pub l_onoff: ::c_int, - pub l_linger: ::c_int, - } - - pub struct sigval { - // Actually a union of an int and a void* - pub sival_ptr: *mut ::c_void - } - - // - pub struct itimerval { - pub it_interval: ::timeval, - pub it_value: ::timeval, - } - - // - pub struct tms { - pub tms_utime: ::clock_t, - pub tms_stime: ::clock_t, - pub tms_cutime: ::clock_t, - pub tms_cstime: ::clock_t, - } - - pub struct servent { - pub s_name: *mut ::c_char, - pub s_aliases: *mut *mut ::c_char, - pub s_port: ::c_int, - pub s_proto: *mut ::c_char, - } - - pub struct protoent { - pub p_name: *mut ::c_char, - pub p_aliases: *mut *mut ::c_char, - pub p_proto: ::c_int, - } - - pub struct aiocb { - pub aio_fildes: ::c_int, - pub aio_lio_opcode: ::c_int, - pub aio_reqprio: ::c_int, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - pub aio_sigevent: ::sigevent, - __td: *mut ::c_void, - __lock: [::c_int; 2], - __err: ::c_int, - __ret: ::ssize_t, - pub aio_offset: off_t, - __next: *mut ::c_void, - __prev: *mut ::c_void, - #[cfg(target_pointer_width = "32")] - __dummy4: [::c_char; 24], - #[cfg(target_pointer_width = "64")] - __dummy4: [::c_char; 16], - } - - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - pub __c_ispeed: ::speed_t, - pub __c_ospeed: ::speed_t, - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct ucred { - pub pid: ::pid_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - } - - pub struct sockaddr { - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_family: sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [u8; 8], - } - - pub struct sockaddr_in6 { - pub sin6_family: sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: socklen_t, - - pub ai_addr: *mut ::sockaddr, - - pub ai_canonname: *mut c_char, - - pub ai_next: *mut addrinfo, - } - - pub struct sockaddr_ll { - pub sll_family: ::c_ushort, - pub sll_protocol: ::c_ushort, - pub sll_ifindex: ::c_int, - pub sll_hatype: ::c_ushort, - pub sll_pkttype: ::c_uchar, - pub sll_halen: ::c_uchar, - pub sll_addr: [::c_uchar; 8] - } - - pub struct fd_set { - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - pub tm_gmtoff: ::c_long, - pub tm_zone: *const ::c_char, - } - - pub struct sched_param { - pub sched_priority: ::c_int, - pub sched_ss_low_priority: ::c_int, - pub sched_ss_repl_period: ::timespec, - pub sched_ss_init_budget: ::timespec, - pub sched_ss_max_repl: ::c_int, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct epoll_event { - pub events: u32, - pub u64: u64, - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct rlimit64 { - pub rlim_cur: rlim64_t, - pub rlim_max: rlim64_t, - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut c_char, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - } - - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut c_char, - pub ifa_flags: ::c_uint, - pub ifa_addr: *mut ::sockaddr, - pub ifa_netmask: *mut ::sockaddr, - pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union - pub ifa_data: *mut ::c_void - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct spwd { - pub sp_namp: *mut ::c_char, - pub sp_pwdp: *mut ::c_char, - pub sp_lstchg: ::c_long, - pub sp_min: ::c_long, - pub sp_max: ::c_long, - pub sp_warn: ::c_long, - pub sp_inact: ::c_long, - pub sp_expire: ::c_long, - pub sp_flag: ::c_ulong, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - #[cfg(target_endian = "little")] - pub f_fsid: ::c_ulong, - #[cfg(all(target_pointer_width = "32", not(target_arch = "x86_64")))] - __f_unused: ::c_int, - #[cfg(target_endian = "big")] - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct dqblk { - pub dqb_bhardlimit: u64, - pub dqb_bsoftlimit: u64, - pub dqb_curspace: u64, - pub dqb_ihardlimit: u64, - pub dqb_isoftlimit: u64, - pub dqb_curinodes: u64, - pub dqb_btime: u64, - pub dqb_itime: u64, - pub dqb_valid: u32, - } - - pub struct signalfd_siginfo { - pub ssi_signo: u32, - pub ssi_errno: i32, - pub ssi_code: i32, - pub ssi_pid: u32, - pub ssi_uid: u32, - pub ssi_fd: i32, - pub ssi_tid: u32, - pub ssi_band: u32, - pub ssi_overrun: u32, - pub ssi_trapno: u32, - pub ssi_status: i32, - pub ssi_int: i32, - pub ssi_ptr: u64, - pub ssi_utime: u64, - pub ssi_stime: u64, - pub ssi_addr: u64, - pub ssi_addr_lsb: u16, - _pad2: u16, - pub ssi_syscall: i32, - pub ssi_call_addr: u64, - pub ssi_arch: u32, - _pad: [u8; 28], - } - - pub struct itimerspec { - pub it_interval: ::timespec, - pub it_value: ::timespec, - } - - pub struct fsid_t { - __val: [::c_int; 2], - } - - pub struct cpu_set_t { - #[cfg(all(target_pointer_width = "32", - not(target_arch = "x86_64")))] - bits: [u32; 32], - #[cfg(not(all(target_pointer_width = "32", - not(target_arch = "x86_64"))))] - bits: [u64; 16], - } - - pub struct if_nameindex { - pub if_index: ::c_uint, - pub if_name: *mut ::c_char, - } - - // System V IPC - pub struct msginfo { - pub msgpool: ::c_int, - pub msgmap: ::c_int, - pub msgmax: ::c_int, - pub msgmnb: ::c_int, - pub msgmni: ::c_int, - pub msgssz: ::c_int, - pub msgtql: ::c_int, - pub msgseg: ::c_ushort, - } - - pub struct mmsghdr { - pub msg_hdr: ::msghdr, - pub msg_len: ::c_uint, - } - - pub struct sembuf { - pub sem_num: ::c_ushort, - pub sem_op: ::c_short, - pub sem_flg: ::c_short, - } - - pub struct input_event { - pub time: ::timeval, - pub type_: ::__u16, - pub code: ::__u16, - pub value: ::__s32, - } - - pub struct input_id { - pub bustype: ::__u16, - pub vendor: ::__u16, - pub product: ::__u16, - pub version: ::__u16, - } - - pub struct input_absinfo { - pub value: ::__s32, - pub minimum: ::__s32, - pub maximum: ::__s32, - pub fuzz: ::__s32, - pub flat: ::__s32, - pub resolution: ::__s32, - } - - pub struct input_keymap_entry { - pub flags: ::__u8, - pub len: ::__u8, - pub index: ::__u16, - pub keycode: ::__u32, - pub scancode: [::__u8; 32], - } - - pub struct input_mask { - pub type_: ::__u32, - pub codes_size: ::__u32, - pub codes_ptr: ::__u64, - } - - pub struct ff_replay { - pub length: ::__u16, - pub delay: ::__u16, - } - - pub struct ff_trigger { - pub button: ::__u16, - pub interval: ::__u16, - } - - pub struct ff_envelope { - pub attack_length: ::__u16, - pub attack_level: ::__u16, - pub fade_length: ::__u16, - pub fade_level: ::__u16, - } - - pub struct ff_constant_effect { - pub level: ::__s16, - pub envelope: ff_envelope, - } - - pub struct ff_ramp_effect { - pub start_level: ::__s16, - pub end_level: ::__s16, - pub envelope: ff_envelope, - } - - pub struct ff_condition_effect { - pub right_saturation: ::__u16, - pub left_saturation: ::__u16, - - pub right_coeff: ::__s16, - pub left_coeff: ::__s16, - - pub deadband: ::__u16, - pub center: ::__s16, - } - - pub struct ff_periodic_effect { - pub waveform: ::__u16, - pub period: ::__u16, - pub magnitude: ::__s16, - pub offset: ::__s16, - pub phase: ::__u16, - - pub envelope: ff_envelope, - - pub custom_len: ::__u32, - pub custom_data: *mut ::__s16, - } - - pub struct ff_rumble_effect { - pub strong_magnitude: ::__u16, - pub weak_magnitude: ::__u16, - } - - pub struct ff_effect { - pub type_: ::__u16, - pub id: ::__s16, - pub direction: ::__u16, - pub trigger: ff_trigger, - pub replay: ff_replay, - // FIXME this is actually a union - #[cfg(target_pointer_width = "64")] - pub u: [u64; 4], - #[cfg(target_pointer_width = "32")] - pub u: [u32; 7], - } - - pub struct dl_phdr_info { - #[cfg(target_pointer_width = "64")] - pub dlpi_addr: Elf64_Addr, - #[cfg(target_pointer_width = "32")] - pub dlpi_addr: Elf32_Addr, - - pub dlpi_name: *const ::c_char, - - #[cfg(target_pointer_width = "64")] - pub dlpi_phdr: *const Elf64_Phdr, - #[cfg(target_pointer_width = "32")] - pub dlpi_phdr: *const Elf32_Phdr, - - #[cfg(target_pointer_width = "64")] - pub dlpi_phnum: Elf64_Half, - #[cfg(target_pointer_width = "32")] - pub dlpi_phnum: Elf32_Half, - - pub dlpi_adds: ::c_ulonglong, - pub dlpi_subs: ::c_ulonglong, - pub dlpi_tls_modid: ::size_t, - pub dlpi_tls_data: *mut ::c_void, - } - - pub struct Elf32_Phdr { - pub p_type: Elf32_Word, - pub p_offset: Elf32_Off, - pub p_vaddr: Elf32_Addr, - pub p_paddr: Elf32_Addr, - pub p_filesz: Elf32_Word, - pub p_memsz: Elf32_Word, - pub p_flags: Elf32_Word, - pub p_align: Elf32_Word, - } - - pub struct Elf64_Phdr { - pub p_type: Elf64_Word, - pub p_flags: Elf64_Word, - pub p_offset: Elf64_Off, - pub p_vaddr: Elf64_Addr, - pub p_paddr: Elf64_Addr, - pub p_filesz: Elf64_Xword, - pub p_memsz: Elf64_Xword, - pub p_align: Elf64_Xword, - } - - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct pthread_attr_t { - __size: [u64; 7] - } - - pub struct sigset_t { - __val: [::c_ulong; 16], - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - pub msg_rtime: ::time_t, - pub msg_ctime: ::time_t, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - __pad1: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - __pad2: ::socklen_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::socklen_t, - pub __pad1: ::c_int, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct sem_t { - __val: [::c_int; 8], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } -} - -s_no_extra_traits! { - pub struct sysinfo { - pub uptime: ::c_ulong, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub __reserved: [::c_char; 256], - } - - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 108] - } - - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - __ss_align: ::size_t, - __ss_pad2: [u8; 128 - 2 * 8], - } - - pub struct utsname { - pub sysname: [::c_char; 65], - pub nodename: [::c_char; 65], - pub release: [::c_char; 65], - pub version: [::c_char; 65], - pub machine: [::c_char; 65], - pub domainname: [::c_char; 65] - } - - pub struct dirent { - pub d_ino: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - // x32 compatibility - // See https://sourceware.org/bugzilla/show_bug.cgi?id=21279 - pub struct mq_attr { - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub mq_flags: i64, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub mq_maxmsg: i64, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub mq_msgsize: i64, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub mq_curmsgs: i64, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pad: [i64; 4], - - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub mq_flags: ::c_long, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub mq_maxmsg: ::c_long, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub mq_msgsize: ::c_long, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub mq_curmsgs: ::c_long, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pad: [::c_long; 4], - } - - pub struct sockaddr_nl { - pub nl_family: ::sa_family_t, - nl_pad: ::c_ushort, - pub nl_pid: u32, - pub nl_groups: u32 - } - - pub struct sigevent { - pub sigev_value: ::sigval, - pub sigev_signo: ::c_int, - pub sigev_notify: ::c_int, - pub sigev_notify_function: fn(::sigval), - pub sigev_notify_attributes: *mut pthread_attr_t, - pub __pad: [::c_char; 56 - 3 * 8 /* 8 == sizeof(long) */], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for sysinfo { - fn eq(&self, other: &sysinfo) -> bool { - self.uptime == other.uptime - && self.loads == other.loads - && self.totalram == other.totalram - && self.freeram == other.freeram - && self.sharedram == other.sharedram - && self.bufferram == other.bufferram - && self.totalswap == other.totalswap - && self.freeswap == other.freeswap - && self.procs == other.procs - && self.pad == other.pad - && self.totalhigh == other.totalhigh - && self.freehigh == other.freehigh - && self.mem_unit == other.mem_unit - && self - .__reserved - .iter() - .zip(other.__reserved.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sysinfo {} - impl ::fmt::Debug for sysinfo { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sysinfo") - .field("uptime", &self.uptime) - .field("loads", &self.loads) - .field("totalram", &self.totalram) - .field("freeram", &self.freeram) - .field("sharedram", &self.sharedram) - .field("bufferram", &self.bufferram) - .field("totalswap", &self.totalswap) - .field("freeswap", &self.freeswap) - .field("procs", &self.procs) - .field("pad", &self.pad) - .field("totalhigh", &self.totalhigh) - .field("freehigh", &self.freehigh) - .field("mem_unit", &self.mem_unit) - // FIXME: .field("__reserved", &self.__reserved) - .finish() - } - } - impl ::hash::Hash for sysinfo { - fn hash(&self, state: &mut H) { - self.uptime.hash(state); - self.loads.hash(state); - self.totalram.hash(state); - self.freeram.hash(state); - self.sharedram.hash(state); - self.bufferram.hash(state); - self.totalswap.hash(state); - self.freeswap.hash(state); - self.procs.hash(state); - self.pad.hash(state); - self.totalhigh.hash(state); - self.freehigh.hash(state); - self.mem_unit.hash(state); - self.__reserved.hash(state); - } - } - - impl PartialEq for sockaddr_un { - fn eq(&self, other: &sockaddr_un) -> bool { - self.sun_family == other.sun_family - && self - .sun_path - .iter() - .zip(other.sun_path.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr_un {} - impl ::fmt::Debug for sockaddr_un { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_un") - .field("sun_family", &self.sun_family) - // FIXME: .field("sun_path", &self.sun_path) - .finish() - } - } - impl ::hash::Hash for sockaddr_un { - fn hash(&self, state: &mut H) { - self.sun_family.hash(state); - self.sun_path.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_family == other.ss_family - && self.__ss_align == other.__ss_align - && self - .__ss_pad2 - .iter() - .zip(other.__ss_pad2.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for sockaddr_storage {} - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_family", &self.ss_family) - .field("__ss_align", &self.__ss_align) - // FIXME: .field("__ss_pad2", &self.__ss_pad2) - .finish() - } - } - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_family.hash(state); - self.__ss_align.hash(state); - self.__ss_pad2.hash(state); - } - } - - impl PartialEq for utsname { - fn eq(&self, other: &utsname) -> bool { - self.sysname - .iter() - .zip(other.sysname.iter()) - .all(|(a,b)| a == b) - && self - .nodename - .iter() - .zip(other.nodename.iter()) - .all(|(a,b)| a == b) - && self - .release - .iter() - .zip(other.release.iter()) - .all(|(a,b)| a == b) - && self - .version - .iter() - .zip(other.version.iter()) - .all(|(a,b)| a == b) - && self - .machine - .iter() - .zip(other.machine.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for utsname {} - impl ::fmt::Debug for utsname { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utsname") - // FIXME: .field("sysname", &self.sysname) - // FIXME: .field("nodename", &self.nodename) - // FIXME: .field("release", &self.release) - // FIXME: .field("version", &self.version) - // FIXME: .field("machine", &self.machine) - .finish() - } - } - impl ::hash::Hash for utsname { - fn hash(&self, state: &mut H) { - self.sysname.hash(state); - self.nodename.hash(state); - self.release.hash(state); - self.version.hash(state); - self.machine.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for dirent64 { - fn eq(&self, other: &dirent64) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent64 {} - impl ::fmt::Debug for dirent64 { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent64") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent64 { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for mq_attr { - fn eq(&self, other: &mq_attr) -> bool { - self.mq_flags == other.mq_flags && - self.mq_maxmsg == other.mq_maxmsg && - self.mq_msgsize == other.mq_msgsize && - self.mq_curmsgs == other.mq_curmsgs - } - } - impl Eq for mq_attr {} - impl ::fmt::Debug for mq_attr { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("mq_attr") - .field("mq_flags", &self.mq_flags) - .field("mq_maxmsg", &self.mq_maxmsg) - .field("mq_msgsize", &self.mq_msgsize) - .field("mq_curmsgs", &self.mq_curmsgs) - .finish() - } - } - impl ::hash::Hash for mq_attr { - fn hash(&self, state: &mut H) { - self.mq_flags.hash(state); - self.mq_maxmsg.hash(state); - self.mq_msgsize.hash(state); - self.mq_curmsgs.hash(state); - } - } - - impl PartialEq for sockaddr_nl { - fn eq(&self, other: &sockaddr_nl) -> bool { - self.nl_family == other.nl_family && - self.nl_pid == other.nl_pid && - self.nl_groups == other.nl_groups - } - } - impl Eq for sockaddr_nl {} - impl ::fmt::Debug for sockaddr_nl { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_nl") - .field("nl_family", &self.nl_family) - .field("nl_pid", &self.nl_pid) - .field("nl_groups", &self.nl_groups) - .finish() - } - } - impl ::hash::Hash for sockaddr_nl { - fn hash(&self, state: &mut H) { - self.nl_family.hash(state); - self.nl_pid.hash(state); - self.nl_groups.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_value == other.sigev_value - && self.sigev_signo == other.sigev_signo - && self.sigev_notify == other.sigev_notify - && self.sigev_notify_function - == other.sigev_notify_function - && self.sigev_notify_attributes - == other.sigev_notify_attributes - } - } - impl Eq for sigevent {} - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_value", &self.sigev_value) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_notify", &self.sigev_notify) - .field("sigev_notify_function", &self.sigev_notify_function) - .field("sigev_notify_attributes", - &self.sigev_notify_attributes) - .finish() - } - } - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_value.hash(state); - self.sigev_signo.hash(state); - self.sigev_notify.hash(state); - self.sigev_notify_function.hash(state); - self.sigev_notify_attributes.hash(state); - } - } - } -} - -// PUB_CONST - -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; - -pub const SIG_DFL: sighandler_t = 0 as sighandler_t; -pub const SIG_IGN: sighandler_t = 1 as sighandler_t; -pub const SIG_ERR: sighandler_t = !0 as sighandler_t; - -pub const DT_FIFO: u8 = 1; -pub const DT_CHR: u8 = 2; -pub const DT_DIR: u8 = 4; -pub const DT_BLK: u8 = 6; -pub const DT_REG: u8 = 8; -pub const DT_LNK: u8 = 10; -pub const DT_SOCK: u8 = 12; - -pub const FD_CLOEXEC: ::c_int = 0x1; - -pub const USRQUOTA: ::c_int = 0; -pub const GRPQUOTA: ::c_int = 1; - -pub const SIGIOT: ::c_int = 6; - -pub const S_ISUID: ::c_int = 0x800; -pub const S_ISGID: ::c_int = 0x400; -pub const S_ISVTX: ::c_int = 0x200; - -pub const IF_NAMESIZE: ::size_t = 16; - -pub const LOG_EMERG: ::c_int = 0; -pub const LOG_ALERT: ::c_int = 1; -pub const LOG_CRIT: ::c_int = 2; -pub const LOG_ERR: ::c_int = 3; -pub const LOG_WARNING: ::c_int = 4; -pub const LOG_NOTICE: ::c_int = 5; -pub const LOG_INFO: ::c_int = 6; -pub const LOG_DEBUG: ::c_int = 7; - -pub const LOG_KERN: ::c_int = 0; -pub const LOG_USER: ::c_int = 1 << 3; -pub const LOG_MAIL: ::c_int = 2 << 3; -pub const LOG_DAEMON: ::c_int = 3 << 3; -pub const LOG_AUTH: ::c_int = 4 << 3; -pub const LOG_SYSLOG: ::c_int = 5 << 3; -pub const LOG_LPR: ::c_int = 6 << 3; -pub const LOG_NEWS: ::c_int = 7 << 3; -pub const LOG_UUCP: ::c_int = 8 << 3; -pub const LOG_LOCAL0: ::c_int = 16 << 3; -pub const LOG_LOCAL1: ::c_int = 17 << 3; -pub const LOG_LOCAL2: ::c_int = 18 << 3; -pub const LOG_LOCAL3: ::c_int = 19 << 3; -pub const LOG_LOCAL4: ::c_int = 20 << 3; -pub const LOG_LOCAL5: ::c_int = 21 << 3; -pub const LOG_LOCAL6: ::c_int = 22 << 3; -pub const LOG_LOCAL7: ::c_int = 23 << 3; - -pub const LOG_PID: ::c_int = 0x01; -pub const LOG_CONS: ::c_int = 0x02; -pub const LOG_ODELAY: ::c_int = 0x04; -pub const LOG_NDELAY: ::c_int = 0x08; -pub const LOG_NOWAIT: ::c_int = 0x10; - -pub const LOG_PRIMASK: ::c_int = 7; -pub const LOG_FACMASK: ::c_int = 0x3f8; - -pub const PRIO_PROCESS: ::c_int = 0; -pub const PRIO_PGRP: ::c_int = 1; -pub const PRIO_USER: ::c_int = 2; - -pub const PRIO_MIN: ::c_int = -20; -pub const PRIO_MAX: ::c_int = 20; - -pub const IPPROTO_ICMP: ::c_int = 1; -pub const IPPROTO_ICMPV6: ::c_int = 58; -pub const IPPROTO_TCP: ::c_int = 6; -pub const IPPROTO_UDP: ::c_int = 17; -pub const IPPROTO_IP: ::c_int = 0; -pub const IPPROTO_IPV6: ::c_int = 41; - -pub const INADDR_LOOPBACK: in_addr_t = 2130706433; -pub const INADDR_ANY: in_addr_t = 0; -pub const INADDR_BROADCAST: in_addr_t = 4294967295; -pub const INADDR_NONE: in_addr_t = 4294967295; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const RAND_MAX: ::c_int = 2147483647; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 2; -pub const _IOLBF: ::c_int = 1; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; - -// Linux-specific fcntls -pub const F_SETLEASE: ::c_int = 1024; -pub const F_GETLEASE: ::c_int = 1025; -pub const F_NOTIFY: ::c_int = 1026; -pub const F_CANCELLK: ::c_int = 1029; -pub const F_DUPFD_CLOEXEC: ::c_int = 1030; -pub const F_SETPIPE_SZ: ::c_int = 1031; -pub const F_GETPIPE_SZ: ::c_int = 1032; -pub const F_ADD_SEALS: ::c_int = 1033; -pub const F_GET_SEALS: ::c_int = 1034; - -pub const F_SEAL_SEAL: ::c_int = 0x0001; -pub const F_SEAL_SHRINK: ::c_int = 0x0002; -pub const F_SEAL_GROW: ::c_int = 0x0004; -pub const F_SEAL_WRITE: ::c_int = 0x0008; - -// TODO(#235): Include file sealing fcntls once we have a way to verify them. - -pub const SIGTRAP: ::c_int = 5; - -pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0; -pub const PTHREAD_CREATE_DETACHED: ::c_int = 1; - -pub const CLOCK_REALTIME: ::clockid_t = 0; -pub const CLOCK_MONOTONIC: ::clockid_t = 1; -pub const CLOCK_PROCESS_CPUTIME_ID: ::clockid_t = 2; -pub const CLOCK_THREAD_CPUTIME_ID: ::clockid_t = 3; -pub const CLOCK_MONOTONIC_RAW: ::clockid_t = 4; -pub const CLOCK_REALTIME_COARSE: ::clockid_t = 5; -pub const CLOCK_MONOTONIC_COARSE: ::clockid_t = 6; -pub const CLOCK_BOOTTIME: ::clockid_t = 7; -pub const CLOCK_REALTIME_ALARM: ::clockid_t = 8; -pub const CLOCK_BOOTTIME_ALARM: ::clockid_t = 9; -// TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep -// 2014.) See also musl/mod.rs -// pub const CLOCK_SGI_CYCLE: ::clockid_t = 10; -// pub const CLOCK_TAI: ::clockid_t = 11; -pub const TIMER_ABSTIME: ::c_int = 1; - -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_LOCKS: ::c_int = 10; -pub const RLIMIT_SIGPENDING: ::c_int = 11; -pub const RLIMIT_MSGQUEUE: ::c_int = 12; -pub const RLIMIT_NICE: ::c_int = 13; -pub const RLIMIT_RTPRIO: ::c_int = 14; - -pub const RUSAGE_SELF: ::c_int = 0; - -pub const O_RDONLY: ::c_int = 0; -pub const O_WRONLY: ::c_int = 1; -pub const O_RDWR: ::c_int = 2; - -pub const SOCK_CLOEXEC: ::c_int = O_CLOEXEC; - -pub const S_IFIFO: ::mode_t = 4096; -pub const S_IFCHR: ::mode_t = 8192; -pub const S_IFBLK: ::mode_t = 24576; -pub const S_IFDIR: ::mode_t = 16384; -pub const S_IFREG: ::mode_t = 32768; -pub const S_IFLNK: ::mode_t = 40960; -pub const S_IFSOCK: ::mode_t = 49152; -pub const S_IFMT: ::mode_t = 61440; -pub const S_IRWXU: ::mode_t = 448; -pub const S_IXUSR: ::mode_t = 64; -pub const S_IWUSR: ::mode_t = 128; -pub const S_IRUSR: ::mode_t = 256; -pub const S_IRWXG: ::mode_t = 56; -pub const S_IXGRP: ::mode_t = 8; -pub const S_IWGRP: ::mode_t = 16; -pub const S_IRGRP: ::mode_t = 32; -pub const S_IRWXO: ::mode_t = 7; -pub const S_IXOTH: ::mode_t = 1; -pub const S_IWOTH: ::mode_t = 2; -pub const S_IROTH: ::mode_t = 4; -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGABRT: ::c_int = 6; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSEGV: ::c_int = 11; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_READ: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_EXEC: ::c_int = 4; - -pub const LC_CTYPE: ::c_int = 0; -pub const LC_NUMERIC: ::c_int = 1; -pub const LC_TIME: ::c_int = 2; -pub const LC_COLLATE: ::c_int = 3; -pub const LC_MONETARY: ::c_int = 4; -pub const LC_MESSAGES: ::c_int = 5; -pub const LC_ALL: ::c_int = 6; -pub const LC_CTYPE_MASK: ::c_int = (1 << LC_CTYPE); -pub const LC_NUMERIC_MASK: ::c_int = (1 << LC_NUMERIC); -pub const LC_TIME_MASK: ::c_int = (1 << LC_TIME); -pub const LC_COLLATE_MASK: ::c_int = (1 << LC_COLLATE); -pub const LC_MONETARY_MASK: ::c_int = (1 << LC_MONETARY); -pub const LC_MESSAGES_MASK: ::c_int = (1 << LC_MESSAGES); -// LC_ALL_MASK defined per platform - -pub const MAP_FILE: ::c_int = 0x0000; -pub const MAP_SHARED: ::c_int = 0x0001; -pub const MAP_PRIVATE: ::c_int = 0x0002; -pub const MAP_FIXED: ::c_int = 0x0010; - -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -// MS_ flags for msync(2) -pub const MS_ASYNC: ::c_int = 0x0001; -pub const MS_INVALIDATE: ::c_int = 0x0002; -pub const MS_SYNC: ::c_int = 0x0004; - -// MS_ flags for mount(2) -pub const MS_RDONLY: ::c_ulong = 0x01; -pub const MS_NOSUID: ::c_ulong = 0x02; -pub const MS_NODEV: ::c_ulong = 0x04; -pub const MS_NOEXEC: ::c_ulong = 0x08; -pub const MS_SYNCHRONOUS: ::c_ulong = 0x10; -pub const MS_REMOUNT: ::c_ulong = 0x20; -pub const MS_MANDLOCK: ::c_ulong = 0x40; -pub const MS_DIRSYNC: ::c_ulong = 0x80; -pub const MS_NOATIME: ::c_ulong = 0x0400; -pub const MS_NODIRATIME: ::c_ulong = 0x0800; -pub const MS_BIND: ::c_ulong = 0x1000; -pub const MS_MOVE: ::c_ulong = 0x2000; -pub const MS_REC: ::c_ulong = 0x4000; -pub const MS_SILENT: ::c_ulong = 0x8000; -pub const MS_POSIXACL: ::c_ulong = 0x010000; -pub const MS_UNBINDABLE: ::c_ulong = 0x020000; -pub const MS_PRIVATE: ::c_ulong = 0x040000; -pub const MS_SLAVE: ::c_ulong = 0x080000; -pub const MS_SHARED: ::c_ulong = 0x100000; -pub const MS_RELATIME: ::c_ulong = 0x200000; -pub const MS_KERNMOUNT: ::c_ulong = 0x400000; -pub const MS_I_VERSION: ::c_ulong = 0x800000; -pub const MS_STRICTATIME: ::c_ulong = 0x1000000; -pub const MS_ACTIVE: ::c_ulong = 0x40000000; -pub const MS_NOUSER: ::c_ulong = 0x80000000; -pub const MS_MGC_VAL: ::c_ulong = 0xc0ed0000; -pub const MS_MGC_MSK: ::c_ulong = 0xffff0000; -pub const MS_RMT_MASK: ::c_ulong = 0x800051; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EAGAIN: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const ENOTBLK: ::c_int = 15; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const EWOULDBLOCK: ::c_int = EAGAIN; - -pub const SCM_RIGHTS: ::c_int = 0x01; -pub const SCM_CREDENTIALS: ::c_int = 0x02; - -pub const PROT_GROWSDOWN: ::c_int = 0x1000000; -pub const PROT_GROWSUP: ::c_int = 0x2000000; - -pub const MAP_TYPE: ::c_int = 0x000f; - -pub const MADV_NORMAL: ::c_int = 0; -pub const MADV_RANDOM: ::c_int = 1; -pub const MADV_SEQUENTIAL: ::c_int = 2; -pub const MADV_WILLNEED: ::c_int = 3; -pub const MADV_DONTNEED: ::c_int = 4; -pub const MADV_FREE: ::c_int = 8; -pub const MADV_REMOVE: ::c_int = 9; -pub const MADV_DONTFORK: ::c_int = 10; -pub const MADV_DOFORK: ::c_int = 11; -pub const MADV_MERGEABLE: ::c_int = 12; -pub const MADV_UNMERGEABLE: ::c_int = 13; -pub const MADV_HUGEPAGE: ::c_int = 14; -pub const MADV_NOHUGEPAGE: ::c_int = 15; -pub const MADV_DONTDUMP: ::c_int = 16; -pub const MADV_DODUMP: ::c_int = 17; -pub const MADV_HWPOISON: ::c_int = 100; -pub const MADV_SOFT_OFFLINE: ::c_int = 101; - -pub const IFF_UP: ::c_int = 0x1; -pub const IFF_BROADCAST: ::c_int = 0x2; -pub const IFF_DEBUG: ::c_int = 0x4; -pub const IFF_LOOPBACK: ::c_int = 0x8; -pub const IFF_POINTOPOINT: ::c_int = 0x10; -pub const IFF_NOTRAILERS: ::c_int = 0x20; -pub const IFF_RUNNING: ::c_int = 0x40; -pub const IFF_NOARP: ::c_int = 0x80; -pub const IFF_PROMISC: ::c_int = 0x100; -pub const IFF_ALLMULTI: ::c_int = 0x200; -pub const IFF_MASTER: ::c_int = 0x400; -pub const IFF_SLAVE: ::c_int = 0x800; -pub const IFF_MULTICAST: ::c_int = 0x1000; -pub const IFF_PORTSEL: ::c_int = 0x2000; -pub const IFF_AUTOMEDIA: ::c_int = 0x4000; -pub const IFF_DYNAMIC: ::c_int = 0x8000; -pub const IFF_TUN: ::c_int = 0x0001; -pub const IFF_TAP: ::c_int = 0x0002; -pub const IFF_NO_PI: ::c_int = 0x1000; - -pub const SOL_IP: ::c_int = 0; -pub const SOL_TCP: ::c_int = 6; -pub const SOL_UDP: ::c_int = 17; -pub const SOL_IPV6: ::c_int = 41; -pub const SOL_ICMPV6: ::c_int = 58; -pub const SOL_RAW: ::c_int = 255; -pub const SOL_DECNET: ::c_int = 261; -pub const SOL_X25: ::c_int = 262; -pub const SOL_PACKET: ::c_int = 263; -pub const SOL_ATM: ::c_int = 264; -pub const SOL_AAL: ::c_int = 265; -pub const SOL_IRDA: ::c_int = 266; -pub const SOL_NETBEUI: ::c_int = 267; -pub const SOL_LLC: ::c_int = 268; -pub const SOL_DCCP: ::c_int = 269; -pub const SOL_NETLINK: ::c_int = 270; -pub const SOL_TIPC: ::c_int = 271; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_UNIX: ::c_int = 1; -pub const AF_LOCAL: ::c_int = 1; -pub const AF_INET: ::c_int = 2; -pub const AF_AX25: ::c_int = 3; -pub const AF_IPX: ::c_int = 4; -pub const AF_APPLETALK: ::c_int = 5; -pub const AF_NETROM: ::c_int = 6; -pub const AF_BRIDGE: ::c_int = 7; -pub const AF_ATMPVC: ::c_int = 8; -pub const AF_X25: ::c_int = 9; -pub const AF_INET6: ::c_int = 10; -pub const AF_ROSE: ::c_int = 11; -pub const AF_DECnet: ::c_int = 12; -pub const AF_NETBEUI: ::c_int = 13; -pub const AF_SECURITY: ::c_int = 14; -pub const AF_KEY: ::c_int = 15; -pub const AF_NETLINK: ::c_int = 16; -pub const AF_ROUTE: ::c_int = AF_NETLINK; -pub const AF_PACKET: ::c_int = 17; -pub const AF_ASH: ::c_int = 18; -pub const AF_ECONET: ::c_int = 19; -pub const AF_ATMSVC: ::c_int = 20; -pub const AF_RDS: ::c_int = 21; -pub const AF_SNA: ::c_int = 22; -pub const AF_IRDA: ::c_int = 23; -pub const AF_PPPOX: ::c_int = 24; -pub const AF_WANPIPE: ::c_int = 25; -pub const AF_LLC: ::c_int = 26; -pub const AF_CAN: ::c_int = 29; -pub const AF_TIPC: ::c_int = 30; -pub const AF_BLUETOOTH: ::c_int = 31; -pub const AF_IUCV: ::c_int = 32; -pub const AF_RXRPC: ::c_int = 33; -pub const AF_ISDN: ::c_int = 34; -pub const AF_PHONET: ::c_int = 35; -pub const AF_IEEE802154: ::c_int = 36; -pub const AF_CAIF: ::c_int = 37; -pub const AF_ALG: ::c_int = 38; - -pub const PF_UNSPEC: ::c_int = AF_UNSPEC; -pub const PF_UNIX: ::c_int = AF_UNIX; -pub const PF_LOCAL: ::c_int = AF_LOCAL; -pub const PF_INET: ::c_int = AF_INET; -pub const PF_AX25: ::c_int = AF_AX25; -pub const PF_IPX: ::c_int = AF_IPX; -pub const PF_APPLETALK: ::c_int = AF_APPLETALK; -pub const PF_NETROM: ::c_int = AF_NETROM; -pub const PF_BRIDGE: ::c_int = AF_BRIDGE; -pub const PF_ATMPVC: ::c_int = AF_ATMPVC; -pub const PF_X25: ::c_int = AF_X25; -pub const PF_INET6: ::c_int = AF_INET6; -pub const PF_ROSE: ::c_int = AF_ROSE; -pub const PF_DECnet: ::c_int = AF_DECnet; -pub const PF_NETBEUI: ::c_int = AF_NETBEUI; -pub const PF_SECURITY: ::c_int = AF_SECURITY; -pub const PF_KEY: ::c_int = AF_KEY; -pub const PF_NETLINK: ::c_int = AF_NETLINK; -pub const PF_ROUTE: ::c_int = AF_ROUTE; -pub const PF_PACKET: ::c_int = AF_PACKET; -pub const PF_ASH: ::c_int = AF_ASH; -pub const PF_ECONET: ::c_int = AF_ECONET; -pub const PF_ATMSVC: ::c_int = AF_ATMSVC; -pub const PF_RDS: ::c_int = AF_RDS; -pub const PF_SNA: ::c_int = AF_SNA; -pub const PF_IRDA: ::c_int = AF_IRDA; -pub const PF_PPPOX: ::c_int = AF_PPPOX; -pub const PF_WANPIPE: ::c_int = AF_WANPIPE; -pub const PF_LLC: ::c_int = AF_LLC; -pub const PF_CAN: ::c_int = AF_CAN; -pub const PF_TIPC: ::c_int = AF_TIPC; -pub const PF_BLUETOOTH: ::c_int = AF_BLUETOOTH; -pub const PF_IUCV: ::c_int = AF_IUCV; -pub const PF_RXRPC: ::c_int = AF_RXRPC; -pub const PF_ISDN: ::c_int = AF_ISDN; -pub const PF_PHONET: ::c_int = AF_PHONET; -pub const PF_IEEE802154: ::c_int = AF_IEEE802154; -pub const PF_CAIF: ::c_int = AF_CAIF; -pub const PF_ALG: ::c_int = AF_ALG; - -pub const SOMAXCONN: ::c_int = 128; - -pub const MSG_OOB: ::c_int = 1; -pub const MSG_PEEK: ::c_int = 2; -pub const MSG_DONTROUTE: ::c_int = 4; -pub const MSG_CTRUNC: ::c_int = 8; -pub const MSG_TRUNC: ::c_int = 0x20; -pub const MSG_DONTWAIT: ::c_int = 0x40; -pub const MSG_EOR: ::c_int = 0x80; -pub const MSG_WAITALL: ::c_int = 0x100; -pub const MSG_FIN: ::c_int = 0x200; -pub const MSG_SYN: ::c_int = 0x400; -pub const MSG_CONFIRM: ::c_int = 0x800; -pub const MSG_RST: ::c_int = 0x1000; -pub const MSG_ERRQUEUE: ::c_int = 0x2000; -pub const MSG_NOSIGNAL: ::c_int = 0x4000; -pub const MSG_MORE: ::c_int = 0x8000; -pub const MSG_WAITFORONE: ::c_int = 0x10000; -pub const MSG_FASTOPEN: ::c_int = 0x20000000; -pub const MSG_CMSG_CLOEXEC: ::c_int = 0x40000000; - -pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP; - -pub const SOCK_RAW: ::c_int = 3; -pub const SOCK_RDM: ::c_int = 4; -pub const IP_MULTICAST_IF: ::c_int = 32; -pub const IP_MULTICAST_TTL: ::c_int = 33; -pub const IP_MULTICAST_LOOP: ::c_int = 34; -pub const IP_TTL: ::c_int = 2; -pub const IP_HDRINCL: ::c_int = 3; -pub const IP_ADD_MEMBERSHIP: ::c_int = 35; -pub const IP_DROP_MEMBERSHIP: ::c_int = 36; -pub const IP_TRANSPARENT: ::c_int = 19; -pub const IPV6_UNICAST_HOPS: ::c_int = 16; -pub const IPV6_MULTICAST_IF: ::c_int = 17; -pub const IPV6_MULTICAST_HOPS: ::c_int = 18; -pub const IPV6_MULTICAST_LOOP: ::c_int = 19; -pub const IPV6_ADD_MEMBERSHIP: ::c_int = 20; -pub const IPV6_DROP_MEMBERSHIP: ::c_int = 21; -pub const IPV6_V6ONLY: ::c_int = 26; - -pub const TCP_NODELAY: ::c_int = 1; -pub const TCP_MAXSEG: ::c_int = 2; -pub const TCP_CORK: ::c_int = 3; -pub const TCP_KEEPIDLE: ::c_int = 4; -pub const TCP_KEEPINTVL: ::c_int = 5; -pub const TCP_KEEPCNT: ::c_int = 6; -pub const TCP_SYNCNT: ::c_int = 7; -pub const TCP_LINGER2: ::c_int = 8; -pub const TCP_DEFER_ACCEPT: ::c_int = 9; -pub const TCP_WINDOW_CLAMP: ::c_int = 10; -pub const TCP_INFO: ::c_int = 11; -pub const TCP_QUICKACK: ::c_int = 12; -pub const TCP_CONGESTION: ::c_int = 13; - -pub const SO_DEBUG: ::c_int = 1; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const LOCK_SH: ::c_int = 1; -pub const LOCK_EX: ::c_int = 2; -pub const LOCK_NB: ::c_int = 4; -pub const LOCK_UN: ::c_int = 8; - -pub const SS_ONSTACK: ::c_int = 1; -pub const SS_DISABLE: ::c_int = 2; - -pub const PATH_MAX: ::c_int = 4096; - -pub const FD_SETSIZE: usize = 1024; - -pub const EPOLLIN: ::c_int = 0x1; -pub const EPOLLPRI: ::c_int = 0x2; -pub const EPOLLOUT: ::c_int = 0x4; -pub const EPOLLRDNORM: ::c_int = 0x40; -pub const EPOLLRDBAND: ::c_int = 0x80; -pub const EPOLLWRNORM: ::c_int = 0x100; -pub const EPOLLWRBAND: ::c_int = 0x200; -pub const EPOLLMSG: ::c_int = 0x400; -pub const EPOLLERR: ::c_int = 0x8; -pub const EPOLLHUP: ::c_int = 0x10; -pub const EPOLLET: ::c_int = 0x80000000; - -pub const EPOLL_CTL_ADD: ::c_int = 1; -pub const EPOLL_CTL_MOD: ::c_int = 3; -pub const EPOLL_CTL_DEL: ::c_int = 2; - -pub const MNT_DETACH: ::c_int = 0x2; -pub const MNT_EXPIRE: ::c_int = 0x4; - -pub const Q_GETFMT: ::c_int = 0x800004; -pub const Q_GETINFO: ::c_int = 0x800005; -pub const Q_SETINFO: ::c_int = 0x800006; -pub const QIF_BLIMITS: u32 = 1; -pub const QIF_SPACE: u32 = 2; -pub const QIF_ILIMITS: u32 = 4; -pub const QIF_INODES: u32 = 8; -pub const QIF_BTIME: u32 = 16; -pub const QIF_ITIME: u32 = 32; -pub const QIF_LIMITS: u32 = 5; -pub const QIF_USAGE: u32 = 10; -pub const QIF_TIMES: u32 = 48; -pub const QIF_ALL: u32 = 63; - -pub const MNT_FORCE: ::c_int = 0x1; - -pub const Q_SYNC: ::c_int = 0x800001; -pub const Q_QUOTAON: ::c_int = 0x800002; -pub const Q_QUOTAOFF: ::c_int = 0x800003; -pub const Q_GETQUOTA: ::c_int = 0x800007; -pub const Q_SETQUOTA: ::c_int = 0x800008; - -pub const TCIOFF: ::c_int = 2; -pub const TCION: ::c_int = 3; -pub const TCOOFF: ::c_int = 0; -pub const TCOON: ::c_int = 1; -pub const TCIFLUSH: ::c_int = 0; -pub const TCOFLUSH: ::c_int = 1; -pub const TCIOFLUSH: ::c_int = 2; -pub const NL0: ::c_int = 0x00000000; -pub const NL1: ::c_int = 0x00000100; -pub const TAB0: ::c_int = 0x00000000; -pub const CR0: ::c_int = 0x00000000; -pub const FF0: ::c_int = 0x00000000; -pub const BS0: ::c_int = 0x00000000; -pub const VT0: ::c_int = 0x00000000; -pub const VERASE: usize = 2; -pub const VKILL: usize = 3; -pub const VINTR: usize = 0; -pub const VQUIT: usize = 1; -pub const VLNEXT: usize = 15; -pub const IGNBRK: ::tcflag_t = 0x00000001; -pub const BRKINT: ::tcflag_t = 0x00000002; -pub const IGNPAR: ::tcflag_t = 0x00000004; -pub const PARMRK: ::tcflag_t = 0x00000008; -pub const INPCK: ::tcflag_t = 0x00000010; -pub const ISTRIP: ::tcflag_t = 0x00000020; -pub const INLCR: ::tcflag_t = 0x00000040; -pub const IGNCR: ::tcflag_t = 0x00000080; -pub const ICRNL: ::tcflag_t = 0x00000100; -pub const IXANY: ::tcflag_t = 0x00000800; -pub const IMAXBEL: ::tcflag_t = 0x00002000; -pub const OPOST: ::tcflag_t = 0x1; -pub const CS5: ::tcflag_t = 0x00000000; -pub const CRTSCTS: ::tcflag_t = 0x80000000; -pub const ECHO: ::tcflag_t = 0x00000008; -pub const OCRNL: ::tcflag_t = 0o000010; -pub const ONOCR: ::tcflag_t = 0o000020; -pub const ONLRET: ::tcflag_t = 0o000040; -pub const OFILL: ::tcflag_t = 0o000100; -pub const OFDEL: ::tcflag_t = 0o000200; - -pub const CLONE_VM: ::c_int = 0x100; -pub const CLONE_FS: ::c_int = 0x200; -pub const CLONE_FILES: ::c_int = 0x400; -pub const CLONE_SIGHAND: ::c_int = 0x800; -pub const CLONE_PTRACE: ::c_int = 0x2000; -pub const CLONE_VFORK: ::c_int = 0x4000; -pub const CLONE_PARENT: ::c_int = 0x8000; -pub const CLONE_THREAD: ::c_int = 0x10000; -pub const CLONE_NEWNS: ::c_int = 0x20000; -pub const CLONE_SYSVSEM: ::c_int = 0x40000; -pub const CLONE_SETTLS: ::c_int = 0x80000; -pub const CLONE_PARENT_SETTID: ::c_int = 0x100000; -pub const CLONE_CHILD_CLEARTID: ::c_int = 0x200000; -pub const CLONE_DETACHED: ::c_int = 0x400000; -pub const CLONE_UNTRACED: ::c_int = 0x800000; -pub const CLONE_CHILD_SETTID: ::c_int = 0x01000000; -pub const CLONE_NEWUTS: ::c_int = 0x04000000; -pub const CLONE_NEWIPC: ::c_int = 0x08000000; -pub const CLONE_NEWUSER: ::c_int = 0x10000000; -pub const CLONE_NEWPID: ::c_int = 0x20000000; -pub const CLONE_NEWNET: ::c_int = 0x40000000; -pub const CLONE_IO: ::c_int = 0x80000000; -pub const CLONE_NEWCGROUP: ::c_int = 0x02000000; - -pub const WNOHANG: ::c_int = 0x00000001; -pub const WUNTRACED: ::c_int = 0x00000002; -pub const WSTOPPED: ::c_int = WUNTRACED; -pub const WEXITED: ::c_int = 0x00000004; -pub const WCONTINUED: ::c_int = 0x00000008; -pub const WNOWAIT: ::c_int = 0x01000000; - -// ::Options set using PTRACE_SETOPTIONS. -pub const PTRACE_O_TRACESYSGOOD: ::c_int = 0x00000001; -pub const PTRACE_O_TRACEFORK: ::c_int = 0x00000002; -pub const PTRACE_O_TRACEVFORK: ::c_int = 0x00000004; -pub const PTRACE_O_TRACECLONE: ::c_int = 0x00000008; -pub const PTRACE_O_TRACEEXEC: ::c_int = 0x00000010; -pub const PTRACE_O_TRACEVFORKDONE: ::c_int = 0x00000020; -pub const PTRACE_O_TRACEEXIT: ::c_int = 0x00000040; -pub const PTRACE_O_TRACESECCOMP: ::c_int = 0x00000080; -pub const PTRACE_O_EXITKILL: ::c_int = 0x00100000; -pub const PTRACE_O_SUSPEND_SECCOMP: ::c_int = 0x00200000; -pub const PTRACE_O_MASK: ::c_int = 0x003000ff; - -// Wait extended result codes for the above trace options. -pub const PTRACE_EVENT_FORK: ::c_int = 1; -pub const PTRACE_EVENT_VFORK: ::c_int = 2; -pub const PTRACE_EVENT_CLONE: ::c_int = 3; -pub const PTRACE_EVENT_EXEC: ::c_int = 4; -pub const PTRACE_EVENT_VFORK_DONE: ::c_int = 5; -pub const PTRACE_EVENT_EXIT: ::c_int = 6; -pub const PTRACE_EVENT_SECCOMP: ::c_int = 7; -// PTRACE_EVENT_STOP was added to glibc in 2.26 -// pub const PTRACE_EVENT_STOP: ::c_int = 128; - -pub const __WNOTHREAD: ::c_int = 0x20000000; -pub const __WALL: ::c_int = 0x40000000; -pub const __WCLONE: ::c_int = 0x80000000; - -pub const SPLICE_F_MOVE: ::c_uint = 0x01; -pub const SPLICE_F_NONBLOCK: ::c_uint = 0x02; -pub const SPLICE_F_MORE: ::c_uint = 0x04; -pub const SPLICE_F_GIFT: ::c_uint = 0x08; - -pub const RTLD_LOCAL: ::c_int = 0; -pub const RTLD_LAZY: ::c_int = 1; - -pub const POSIX_FADV_NORMAL: ::c_int = 0; -pub const POSIX_FADV_RANDOM: ::c_int = 1; -pub const POSIX_FADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_FADV_WILLNEED: ::c_int = 3; - -pub const AT_FDCWD: ::c_int = -100; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100; -pub const AT_REMOVEDIR: ::c_int = 0x200; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; -pub const AT_NO_AUTOMOUNT: ::c_int = 0x800; -pub const AT_EMPTY_PATH: ::c_int = 0x1000; - -pub const LOG_CRON: ::c_int = 9 << 3; -pub const LOG_AUTHPRIV: ::c_int = 10 << 3; -pub const LOG_FTP: ::c_int = 11 << 3; -pub const LOG_PERROR: ::c_int = 0x20; - -pub const PIPE_BUF: usize = 4096; - -pub const SI_LOAD_SHIFT: ::c_uint = 16; - -pub const SIGEV_SIGNAL: ::c_int = 0; -pub const SIGEV_NONE: ::c_int = 1; -pub const SIGEV_THREAD: ::c_int = 2; - -pub const P_ALL: idtype_t = 0; -pub const P_PID: idtype_t = 1; -pub const P_PGID: idtype_t = 2; - -pub const UTIME_OMIT: c_long = 1073741822; -pub const UTIME_NOW: c_long = 1073741823; - -pub const POLLIN: ::c_short = 0x1; -pub const POLLPRI: ::c_short = 0x2; -pub const POLLOUT: ::c_short = 0x4; -pub const POLLERR: ::c_short = 0x8; -pub const POLLHUP: ::c_short = 0x10; -pub const POLLNVAL: ::c_short = 0x20; -pub const POLLRDNORM: ::c_short = 0x040; -pub const POLLRDBAND: ::c_short = 0x080; - -pub const ABDAY_1: ::nl_item = 0x20000; -pub const ABDAY_2: ::nl_item = 0x20001; -pub const ABDAY_3: ::nl_item = 0x20002; -pub const ABDAY_4: ::nl_item = 0x20003; -pub const ABDAY_5: ::nl_item = 0x20004; -pub const ABDAY_6: ::nl_item = 0x20005; -pub const ABDAY_7: ::nl_item = 0x20006; - -pub const DAY_1: ::nl_item = 0x20007; -pub const DAY_2: ::nl_item = 0x20008; -pub const DAY_3: ::nl_item = 0x20009; -pub const DAY_4: ::nl_item = 0x2000A; -pub const DAY_5: ::nl_item = 0x2000B; -pub const DAY_6: ::nl_item = 0x2000C; -pub const DAY_7: ::nl_item = 0x2000D; - -pub const ABMON_1: ::nl_item = 0x2000E; -pub const ABMON_2: ::nl_item = 0x2000F; -pub const ABMON_3: ::nl_item = 0x20010; -pub const ABMON_4: ::nl_item = 0x20011; -pub const ABMON_5: ::nl_item = 0x20012; -pub const ABMON_6: ::nl_item = 0x20013; -pub const ABMON_7: ::nl_item = 0x20014; -pub const ABMON_8: ::nl_item = 0x20015; -pub const ABMON_9: ::nl_item = 0x20016; -pub const ABMON_10: ::nl_item = 0x20017; -pub const ABMON_11: ::nl_item = 0x20018; -pub const ABMON_12: ::nl_item = 0x20019; - -pub const MON_1: ::nl_item = 0x2001A; -pub const MON_2: ::nl_item = 0x2001B; -pub const MON_3: ::nl_item = 0x2001C; -pub const MON_4: ::nl_item = 0x2001D; -pub const MON_5: ::nl_item = 0x2001E; -pub const MON_6: ::nl_item = 0x2001F; -pub const MON_7: ::nl_item = 0x20020; -pub const MON_8: ::nl_item = 0x20021; -pub const MON_9: ::nl_item = 0x20022; -pub const MON_10: ::nl_item = 0x20023; -pub const MON_11: ::nl_item = 0x20024; -pub const MON_12: ::nl_item = 0x20025; - -pub const AM_STR: ::nl_item = 0x20026; -pub const PM_STR: ::nl_item = 0x20027; - -pub const D_T_FMT: ::nl_item = 0x20028; -pub const D_FMT: ::nl_item = 0x20029; -pub const T_FMT: ::nl_item = 0x2002A; -pub const T_FMT_AMPM: ::nl_item = 0x2002B; - -pub const ERA: ::nl_item = 0x2002C; -pub const ERA_D_FMT: ::nl_item = 0x2002E; -pub const ALT_DIGITS: ::nl_item = 0x2002F; -pub const ERA_D_T_FMT: ::nl_item = 0x20030; -pub const ERA_T_FMT: ::nl_item = 0x20031; - -pub const CODESET: ::nl_item = 14; - -pub const CRNCYSTR: ::nl_item = 0x4000F; - -pub const RUSAGE_THREAD: ::c_int = 1; -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const RADIXCHAR: ::nl_item = 0x10000; -pub const THOUSEP: ::nl_item = 0x10001; - -pub const YESEXPR: ::nl_item = 0x50000; -pub const NOEXPR: ::nl_item = 0x50001; -pub const YESSTR: ::nl_item = 0x50002; -pub const NOSTR: ::nl_item = 0x50003; - -pub const FILENAME_MAX: ::c_uint = 4096; -pub const L_tmpnam: ::c_uint = 20; -pub const _PC_LINK_MAX: ::c_int = 0; -pub const _PC_MAX_CANON: ::c_int = 1; -pub const _PC_MAX_INPUT: ::c_int = 2; -pub const _PC_NAME_MAX: ::c_int = 3; -pub const _PC_PATH_MAX: ::c_int = 4; -pub const _PC_PIPE_BUF: ::c_int = 5; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 6; -pub const _PC_NO_TRUNC: ::c_int = 7; -pub const _PC_VDISABLE: ::c_int = 8; -pub const _PC_SYNC_IO: ::c_int = 9; -pub const _PC_ASYNC_IO: ::c_int = 10; -pub const _PC_PRIO_IO: ::c_int = 11; -pub const _PC_SOCK_MAXBUF: ::c_int = 12; -pub const _PC_FILESIZEBITS: ::c_int = 13; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 14; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 15; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 16; -pub const _PC_REC_XFER_ALIGN: ::c_int = 17; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 18; -pub const _PC_SYMLINK_MAX: ::c_int = 19; -pub const _PC_2_SYMLINKS: ::c_int = 20; - -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_CHILD_MAX: ::c_int = 1; -pub const _SC_CLK_TCK: ::c_int = 2; -pub const _SC_NGROUPS_MAX: ::c_int = 3; -pub const _SC_OPEN_MAX: ::c_int = 4; -pub const _SC_STREAM_MAX: ::c_int = 5; -pub const _SC_TZNAME_MAX: ::c_int = 6; -pub const _SC_JOB_CONTROL: ::c_int = 7; -pub const _SC_SAVED_IDS: ::c_int = 8; -pub const _SC_REALTIME_SIGNALS: ::c_int = 9; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 10; -pub const _SC_TIMERS: ::c_int = 11; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 12; -pub const _SC_PRIORITIZED_IO: ::c_int = 13; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 14; -pub const _SC_FSYNC: ::c_int = 15; -pub const _SC_MAPPED_FILES: ::c_int = 16; -pub const _SC_MEMLOCK: ::c_int = 17; -pub const _SC_MEMLOCK_RANGE: ::c_int = 18; -pub const _SC_MEMORY_PROTECTION: ::c_int = 19; -pub const _SC_MESSAGE_PASSING: ::c_int = 20; -pub const _SC_SEMAPHORES: ::c_int = 21; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 22; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 23; -pub const _SC_AIO_MAX: ::c_int = 24; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 25; -pub const _SC_DELAYTIMER_MAX: ::c_int = 26; -pub const _SC_MQ_OPEN_MAX: ::c_int = 27; -pub const _SC_MQ_PRIO_MAX: ::c_int = 28; -pub const _SC_VERSION: ::c_int = 29; -pub const _SC_PAGESIZE: ::c_int = 30; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_RTSIG_MAX: ::c_int = 31; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 32; -pub const _SC_SEM_VALUE_MAX: ::c_int = 33; -pub const _SC_SIGQUEUE_MAX: ::c_int = 34; -pub const _SC_TIMER_MAX: ::c_int = 35; -pub const _SC_BC_BASE_MAX: ::c_int = 36; -pub const _SC_BC_DIM_MAX: ::c_int = 37; -pub const _SC_BC_SCALE_MAX: ::c_int = 38; -pub const _SC_BC_STRING_MAX: ::c_int = 39; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 40; -pub const _SC_EXPR_NEST_MAX: ::c_int = 42; -pub const _SC_LINE_MAX: ::c_int = 43; -pub const _SC_RE_DUP_MAX: ::c_int = 44; -pub const _SC_2_VERSION: ::c_int = 46; -pub const _SC_2_C_BIND: ::c_int = 47; -pub const _SC_2_C_DEV: ::c_int = 48; -pub const _SC_2_FORT_DEV: ::c_int = 49; -pub const _SC_2_FORT_RUN: ::c_int = 50; -pub const _SC_2_SW_DEV: ::c_int = 51; -pub const _SC_2_LOCALEDEF: ::c_int = 52; -pub const _SC_UIO_MAXIOV: ::c_int = 60; -pub const _SC_IOV_MAX: ::c_int = 60; -pub const _SC_THREADS: ::c_int = 67; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 68; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 69; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 70; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 71; -pub const _SC_TTY_NAME_MAX: ::c_int = 72; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 73; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 74; -pub const _SC_THREAD_STACK_MIN: ::c_int = 75; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 76; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 77; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 78; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 79; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 80; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 81; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 82; -pub const _SC_NPROCESSORS_CONF: ::c_int = 83; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 84; -pub const _SC_PHYS_PAGES: ::c_int = 85; -pub const _SC_AVPHYS_PAGES: ::c_int = 86; -pub const _SC_ATEXIT_MAX: ::c_int = 87; -pub const _SC_PASS_MAX: ::c_int = 88; -pub const _SC_XOPEN_VERSION: ::c_int = 89; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 90; -pub const _SC_XOPEN_UNIX: ::c_int = 91; -pub const _SC_XOPEN_CRYPT: ::c_int = 92; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 93; -pub const _SC_XOPEN_SHM: ::c_int = 94; -pub const _SC_2_CHAR_TERM: ::c_int = 95; -pub const _SC_2_UPE: ::c_int = 97; -pub const _SC_XOPEN_XPG2: ::c_int = 98; -pub const _SC_XOPEN_XPG3: ::c_int = 99; -pub const _SC_XOPEN_XPG4: ::c_int = 100; -pub const _SC_NZERO: ::c_int = 109; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = 125; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = 126; -pub const _SC_XBS5_LP64_OFF64: ::c_int = 127; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = 128; -pub const _SC_XOPEN_LEGACY: ::c_int = 129; -pub const _SC_XOPEN_REALTIME: ::c_int = 130; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 131; -pub const _SC_ADVISORY_INFO: ::c_int = 132; -pub const _SC_BARRIERS: ::c_int = 133; -pub const _SC_CLOCK_SELECTION: ::c_int = 137; -pub const _SC_CPUTIME: ::c_int = 138; -pub const _SC_THREAD_CPUTIME: ::c_int = 139; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 149; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 153; -pub const _SC_SPIN_LOCKS: ::c_int = 154; -pub const _SC_REGEXP: ::c_int = 155; -pub const _SC_SHELL: ::c_int = 157; -pub const _SC_SPAWN: ::c_int = 159; -pub const _SC_SPORADIC_SERVER: ::c_int = 160; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 161; -pub const _SC_TIMEOUTS: ::c_int = 164; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 165; -pub const _SC_2_PBS: ::c_int = 168; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 169; -pub const _SC_2_PBS_LOCATE: ::c_int = 170; -pub const _SC_2_PBS_MESSAGE: ::c_int = 171; -pub const _SC_2_PBS_TRACK: ::c_int = 172; -pub const _SC_SYMLOOP_MAX: ::c_int = 173; -pub const _SC_STREAMS: ::c_int = 174; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 175; -pub const _SC_V6_ILP32_OFF32: ::c_int = 176; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 177; -pub const _SC_V6_LP64_OFF64: ::c_int = 178; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 179; -pub const _SC_HOST_NAME_MAX: ::c_int = 180; -pub const _SC_TRACE: ::c_int = 181; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 182; -pub const _SC_TRACE_INHERIT: ::c_int = 183; -pub const _SC_TRACE_LOG: ::c_int = 184; -pub const _SC_IPV6: ::c_int = 235; -pub const _SC_RAW_SOCKETS: ::c_int = 236; -pub const _SC_V7_ILP32_OFF32: ::c_int = 237; -pub const _SC_V7_ILP32_OFFBIG: ::c_int = 238; -pub const _SC_V7_LP64_OFF64: ::c_int = 239; -pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 240; -pub const _SC_SS_REPL_MAX: ::c_int = 241; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 242; -pub const _SC_TRACE_NAME_MAX: ::c_int = 243; -pub const _SC_TRACE_SYS_MAX: ::c_int = 244; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 245; -pub const _SC_XOPEN_STREAMS: ::c_int = 246; -pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 247; -pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 248; - -pub const RLIM_SAVED_MAX: ::rlim_t = RLIM_INFINITY; -pub const RLIM_SAVED_CUR: ::rlim_t = RLIM_INFINITY; - -pub const GLOB_ERR: ::c_int = 1 << 0; -pub const GLOB_MARK: ::c_int = 1 << 1; -pub const GLOB_NOSORT: ::c_int = 1 << 2; -pub const GLOB_DOOFFS: ::c_int = 1 << 3; -pub const GLOB_NOCHECK: ::c_int = 1 << 4; -pub const GLOB_APPEND: ::c_int = 1 << 5; -pub const GLOB_NOESCAPE: ::c_int = 1 << 6; - -pub const GLOB_NOSPACE: ::c_int = 1; -pub const GLOB_ABORTED: ::c_int = 2; -pub const GLOB_NOMATCH: ::c_int = 3; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; - -pub const S_IEXEC: mode_t = 64; -pub const S_IWRITE: mode_t = 128; -pub const S_IREAD: mode_t = 256; - -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; - -pub const IFF_LOWER_UP: ::c_int = 0x10000; -pub const IFF_DORMANT: ::c_int = 0x20000; -pub const IFF_ECHO: ::c_int = 0x40000; - -pub const ST_RDONLY: ::c_ulong = 1; -pub const ST_NOSUID: ::c_ulong = 2; -pub const ST_NODEV: ::c_ulong = 4; -pub const ST_NOEXEC: ::c_ulong = 8; -pub const ST_SYNCHRONOUS: ::c_ulong = 16; -pub const ST_MANDLOCK: ::c_ulong = 64; -pub const ST_WRITE: ::c_ulong = 128; -pub const ST_APPEND: ::c_ulong = 256; -pub const ST_IMMUTABLE: ::c_ulong = 512; -pub const ST_NOATIME: ::c_ulong = 1024; -pub const ST_NODIRATIME: ::c_ulong = 2048; - -pub const RTLD_NEXT: *mut ::c_void = -1i64 as *mut ::c_void; -pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; -pub const RTLD_NODELETE: ::c_int = 0x1000; -pub const RTLD_NOW: ::c_int = 0x2; - -pub const TCP_MD5SIG: ::c_int = 14; - -align_const! { - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - size: [0; __SIZEOF_PTHREAD_MUTEX_T], - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - size: [0; __SIZEOF_PTHREAD_COND_T], - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - size: [0; __SIZEOF_PTHREAD_RWLOCK_T], - }; -} -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; -pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0; -pub const PTHREAD_PROCESS_SHARED: ::c_int = 1; -pub const __SIZEOF_PTHREAD_COND_T: usize = 48; - -pub const RENAME_NOREPLACE: ::c_int = 1; -pub const RENAME_EXCHANGE: ::c_int = 2; -pub const RENAME_WHITEOUT: ::c_int = 4; - -pub const SCHED_OTHER: ::c_int = 0; -pub const SCHED_FIFO: ::c_int = 1; -pub const SCHED_RR: ::c_int = 2; -pub const SCHED_BATCH: ::c_int = 3; -pub const SCHED_IDLE: ::c_int = 5; - -// netinet/in.h -// NOTE: These are in addition to the constants defined in src/unix/mod.rs - -// IPPROTO_IP defined in src/unix/mod.rs -/// Hop-by-hop option header -pub const IPPROTO_HOPOPTS: ::c_int = 0; -// IPPROTO_ICMP defined in src/unix/mod.rs -/// group mgmt protocol -pub const IPPROTO_IGMP: ::c_int = 2; -/// for compatibility -pub const IPPROTO_IPIP: ::c_int = 4; -// IPPROTO_TCP defined in src/unix/mod.rs -/// exterior gateway protocol -pub const IPPROTO_EGP: ::c_int = 8; -/// pup -pub const IPPROTO_PUP: ::c_int = 12; -// IPPROTO_UDP defined in src/unix/mod.rs -/// xns idp -pub const IPPROTO_IDP: ::c_int = 22; -/// tp-4 w/ class negotiation -pub const IPPROTO_TP: ::c_int = 29; -/// DCCP -pub const IPPROTO_DCCP: ::c_int = 33; -// IPPROTO_IPV6 defined in src/unix/mod.rs -/// IP6 routing header -pub const IPPROTO_ROUTING: ::c_int = 43; -/// IP6 fragmentation header -pub const IPPROTO_FRAGMENT: ::c_int = 44; -/// resource reservation -pub const IPPROTO_RSVP: ::c_int = 46; -/// General Routing Encap. -pub const IPPROTO_GRE: ::c_int = 47; -/// IP6 Encap Sec. Payload -pub const IPPROTO_ESP: ::c_int = 50; -/// IP6 Auth Header -pub const IPPROTO_AH: ::c_int = 51; -// IPPROTO_ICMPV6 defined in src/unix/mod.rs -/// IP6 no next header -pub const IPPROTO_NONE: ::c_int = 59; -/// IP6 destination option -pub const IPPROTO_DSTOPTS: ::c_int = 60; -pub const IPPROTO_MTP: ::c_int = 92; -pub const IPPROTO_BEETPH: ::c_int = 94; -/// encapsulation header -pub const IPPROTO_ENCAP: ::c_int = 98; -/// Protocol indep. multicast -pub const IPPROTO_PIM: ::c_int = 103; -/// IP Payload Comp. Protocol -pub const IPPROTO_COMP: ::c_int = 108; -/// SCTP -pub const IPPROTO_SCTP: ::c_int = 132; -pub const IPPROTO_MH: ::c_int = 135; -pub const IPPROTO_UDPLITE: ::c_int = 136; -pub const IPPROTO_MPLS: ::c_int = 137; -/// raw IP packet -pub const IPPROTO_RAW: ::c_int = 255; -pub const IPPROTO_MAX: ::c_int = 256; - -pub const AF_IB: ::c_int = 27; -pub const AF_MPLS: ::c_int = 28; -pub const AF_NFC: ::c_int = 39; -pub const AF_VSOCK: ::c_int = 40; -pub const PF_IB: ::c_int = AF_IB; -pub const PF_MPLS: ::c_int = AF_MPLS; -pub const PF_NFC: ::c_int = AF_NFC; -pub const PF_VSOCK: ::c_int = AF_VSOCK; - -// System V IPC -pub const IPC_PRIVATE: ::key_t = 0; - -pub const IPC_CREAT: ::c_int = 0o1000; -pub const IPC_EXCL: ::c_int = 0o2000; -pub const IPC_NOWAIT: ::c_int = 0o4000; - -pub const IPC_RMID: ::c_int = 0; -pub const IPC_SET: ::c_int = 1; -pub const IPC_STAT: ::c_int = 2; -pub const IPC_INFO: ::c_int = 3; -pub const MSG_STAT: ::c_int = 11; -pub const MSG_INFO: ::c_int = 12; - -pub const MSG_NOERROR: ::c_int = 0o10000; -pub const MSG_EXCEPT: ::c_int = 0o20000; -pub const MSG_COPY: ::c_int = 0o40000; - -pub const SHM_R: ::c_int = 0o400; -pub const SHM_W: ::c_int = 0o200; - -pub const SHM_RDONLY: ::c_int = 0o10000; -pub const SHM_RND: ::c_int = 0o20000; -pub const SHM_REMAP: ::c_int = 0o40000; -pub const SHM_EXEC: ::c_int = 0o100000; - -pub const SHM_LOCK: ::c_int = 11; -pub const SHM_UNLOCK: ::c_int = 12; - -pub const SHM_HUGETLB: ::c_int = 0o4000; -pub const SHM_NORESERVE: ::c_int = 0o10000; - -pub const EPOLLRDHUP: ::c_int = 0x2000; -pub const EPOLLEXCLUSIVE: ::c_int = 0x10000000; -pub const EPOLLONESHOT: ::c_int = 0x40000000; - -pub const QFMT_VFS_OLD: ::c_int = 1; -pub const QFMT_VFS_V0: ::c_int = 2; -pub const QFMT_VFS_V1: ::c_int = 4; - -pub const EFD_SEMAPHORE: ::c_int = 0x1; - -pub const LOG_NFACILITIES: ::c_int = 24; - -pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; - -pub const RB_AUTOBOOT: ::c_int = 0x01234567u32 as i32; -pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123u32 as i32; -pub const RB_ENABLE_CAD: ::c_int = 0x89abcdefu32 as i32; -pub const RB_DISABLE_CAD: ::c_int = 0x00000000u32 as i32; -pub const RB_POWER_OFF: ::c_int = 0x4321fedcu32 as i32; -pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2u32 as i32; -pub const RB_KEXEC: ::c_int = 0x45584543u32 as i32; - -pub const AI_PASSIVE: ::c_int = 0x0001; -pub const AI_CANONNAME: ::c_int = 0x0002; -pub const AI_NUMERICHOST: ::c_int = 0x0004; -pub const AI_V4MAPPED: ::c_int = 0x0008; -pub const AI_ALL: ::c_int = 0x0010; -pub const AI_ADDRCONFIG: ::c_int = 0x0020; - -pub const AI_NUMERICSERV: ::c_int = 0x0400; - -pub const EAI_BADFLAGS: ::c_int = -1; -pub const EAI_NONAME: ::c_int = -2; -pub const EAI_AGAIN: ::c_int = -3; -pub const EAI_FAIL: ::c_int = -4; -pub const EAI_FAMILY: ::c_int = -6; -pub const EAI_SOCKTYPE: ::c_int = -7; -pub const EAI_SERVICE: ::c_int = -8; -pub const EAI_MEMORY: ::c_int = -10; -pub const EAI_OVERFLOW: ::c_int = -12; - -pub const NI_NUMERICHOST: ::c_int = 1; -pub const NI_NUMERICSERV: ::c_int = 2; -pub const NI_NOFQDN: ::c_int = 4; -pub const NI_NAMEREQD: ::c_int = 8; -pub const NI_DGRAM: ::c_int = 16; - -pub const SYNC_FILE_RANGE_WAIT_BEFORE: ::c_uint = 1; -pub const SYNC_FILE_RANGE_WRITE: ::c_uint = 2; -pub const SYNC_FILE_RANGE_WAIT_AFTER: ::c_uint = 4; - -pub const EAI_SYSTEM: ::c_int = -11; - -pub const AIO_CANCELED: ::c_int = 0; -pub const AIO_NOTCANCELED: ::c_int = 1; -pub const AIO_ALLDONE: ::c_int = 2; -pub const LIO_READ: ::c_int = 0; -pub const LIO_WRITE: ::c_int = 1; -pub const LIO_NOP: ::c_int = 2; -pub const LIO_WAIT: ::c_int = 0; -pub const LIO_NOWAIT: ::c_int = 1; - -pub const MREMAP_MAYMOVE: ::c_int = 1; -pub const MREMAP_FIXED: ::c_int = 2; - -pub const PR_SET_PDEATHSIG: ::c_int = 1; -pub const PR_GET_PDEATHSIG: ::c_int = 2; - -pub const PR_GET_DUMPABLE: ::c_int = 3; -pub const PR_SET_DUMPABLE: ::c_int = 4; - -pub const PR_GET_UNALIGN: ::c_int = 5; -pub const PR_SET_UNALIGN: ::c_int = 6; -pub const PR_UNALIGN_NOPRINT: ::c_int = 1; -pub const PR_UNALIGN_SIGBUS: ::c_int = 2; - -pub const PR_GET_KEEPCAPS: ::c_int = 7; -pub const PR_SET_KEEPCAPS: ::c_int = 8; - -pub const PR_GET_FPEMU: ::c_int = 9; -pub const PR_SET_FPEMU: ::c_int = 10; -pub const PR_FPEMU_NOPRINT: ::c_int = 1; -pub const PR_FPEMU_SIGFPE: ::c_int = 2; - -pub const PR_GET_FPEXC: ::c_int = 11; -pub const PR_SET_FPEXC: ::c_int = 12; -pub const PR_FP_EXC_SW_ENABLE: ::c_int = 0x80; -pub const PR_FP_EXC_DIV: ::c_int = 0x010000; -pub const PR_FP_EXC_OVF: ::c_int = 0x020000; -pub const PR_FP_EXC_UND: ::c_int = 0x040000; -pub const PR_FP_EXC_RES: ::c_int = 0x080000; -pub const PR_FP_EXC_INV: ::c_int = 0x100000; -pub const PR_FP_EXC_DISABLED: ::c_int = 0; -pub const PR_FP_EXC_NONRECOV: ::c_int = 1; -pub const PR_FP_EXC_ASYNC: ::c_int = 2; -pub const PR_FP_EXC_PRECISE: ::c_int = 3; - -pub const PR_GET_TIMING: ::c_int = 13; -pub const PR_SET_TIMING: ::c_int = 14; -pub const PR_TIMING_STATISTICAL: ::c_int = 0; -pub const PR_TIMING_TIMESTAMP: ::c_int = 1; - -pub const PR_SET_NAME: ::c_int = 15; -pub const PR_GET_NAME: ::c_int = 16; - -pub const PR_GET_ENDIAN: ::c_int = 19; -pub const PR_SET_ENDIAN: ::c_int = 20; -pub const PR_ENDIAN_BIG: ::c_int = 0; -pub const PR_ENDIAN_LITTLE: ::c_int = 1; -pub const PR_ENDIAN_PPC_LITTLE: ::c_int = 2; - -pub const PR_GET_SECCOMP: ::c_int = 21; -pub const PR_SET_SECCOMP: ::c_int = 22; - -pub const PR_CAPBSET_READ: ::c_int = 23; -pub const PR_CAPBSET_DROP: ::c_int = 24; - -pub const PR_GET_TSC: ::c_int = 25; -pub const PR_SET_TSC: ::c_int = 26; -pub const PR_TSC_ENABLE: ::c_int = 1; -pub const PR_TSC_SIGSEGV: ::c_int = 2; - -pub const PR_GET_SECUREBITS: ::c_int = 27; -pub const PR_SET_SECUREBITS: ::c_int = 28; - -pub const PR_SET_TIMERSLACK: ::c_int = 29; -pub const PR_GET_TIMERSLACK: ::c_int = 30; - -pub const PR_TASK_PERF_EVENTS_DISABLE: ::c_int = 31; -pub const PR_TASK_PERF_EVENTS_ENABLE: ::c_int = 32; - -pub const PR_MCE_KILL: ::c_int = 33; -pub const PR_MCE_KILL_CLEAR: ::c_int = 0; -pub const PR_MCE_KILL_SET: ::c_int = 1; - -pub const PR_MCE_KILL_LATE: ::c_int = 0; -pub const PR_MCE_KILL_EARLY: ::c_int = 1; -pub const PR_MCE_KILL_DEFAULT: ::c_int = 2; - -pub const PR_MCE_KILL_GET: ::c_int = 34; - -pub const PR_SET_MM: ::c_int = 35; -pub const PR_SET_MM_START_CODE: ::c_int = 1; -pub const PR_SET_MM_END_CODE: ::c_int = 2; -pub const PR_SET_MM_START_DATA: ::c_int = 3; -pub const PR_SET_MM_END_DATA: ::c_int = 4; -pub const PR_SET_MM_START_STACK: ::c_int = 5; -pub const PR_SET_MM_START_BRK: ::c_int = 6; -pub const PR_SET_MM_BRK: ::c_int = 7; -pub const PR_SET_MM_ARG_START: ::c_int = 8; -pub const PR_SET_MM_ARG_END: ::c_int = 9; -pub const PR_SET_MM_ENV_START: ::c_int = 10; -pub const PR_SET_MM_ENV_END: ::c_int = 11; -pub const PR_SET_MM_AUXV: ::c_int = 12; -pub const PR_SET_MM_EXE_FILE: ::c_int = 13; -pub const PR_SET_MM_MAP: ::c_int = 14; -pub const PR_SET_MM_MAP_SIZE: ::c_int = 15; - -pub const PR_SET_PTRACER: ::c_int = 0x59616d61; - -pub const PR_SET_CHILD_SUBREAPER: ::c_int = 36; -pub const PR_GET_CHILD_SUBREAPER: ::c_int = 37; - -pub const PR_SET_NO_NEW_PRIVS: ::c_int = 38; -pub const PR_GET_NO_NEW_PRIVS: ::c_int = 39; - -pub const PR_GET_TID_ADDRESS: ::c_int = 40; - -pub const PR_SET_THP_DISABLE: ::c_int = 41; -pub const PR_GET_THP_DISABLE: ::c_int = 42; - -pub const PR_MPX_ENABLE_MANAGEMENT: ::c_int = 43; -pub const PR_MPX_DISABLE_MANAGEMENT: ::c_int = 44; - -pub const PR_SET_FP_MODE: ::c_int = 45; -pub const PR_GET_FP_MODE: ::c_int = 46; -pub const PR_FP_MODE_FR: ::c_int = 1 << 0; -pub const PR_FP_MODE_FRE: ::c_int = 1 << 1; - -pub const PR_CAP_AMBIENT: ::c_int = 47; -pub const PR_CAP_AMBIENT_IS_SET: ::c_int = 1; -pub const PR_CAP_AMBIENT_RAISE: ::c_int = 2; -pub const PR_CAP_AMBIENT_LOWER: ::c_int = 3; -pub const PR_CAP_AMBIENT_CLEAR_ALL: ::c_int = 4; - -pub const ITIMER_REAL: ::c_int = 0; -pub const ITIMER_VIRTUAL: ::c_int = 1; -pub const ITIMER_PROF: ::c_int = 2; - -pub const TFD_CLOEXEC: ::c_int = O_CLOEXEC; -pub const TFD_NONBLOCK: ::c_int = O_NONBLOCK; -pub const TFD_TIMER_ABSTIME: ::c_int = 1; - -pub const XATTR_CREATE: ::c_int = 0x1; -pub const XATTR_REPLACE: ::c_int = 0x2; - -pub const _POSIX_VDISABLE: ::cc_t = 0; - -pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01; -pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02; -pub const FALLOC_FL_COLLAPSE_RANGE: ::c_int = 0x08; -pub const FALLOC_FL_ZERO_RANGE: ::c_int = 0x10; -pub const FALLOC_FL_INSERT_RANGE: ::c_int = 0x20; -pub const FALLOC_FL_UNSHARE_RANGE: ::c_int = 0x40; - -// On Linux, libc doesn't define this constant, libattr does instead. -// We still define it for Linux as it's defined by libc on other platforms, -// and it's mentioned in the man pages for getxattr and setxattr. -pub const ENOATTR: ::c_int = ::ENODATA; - -pub const SO_ORIGINAL_DST: ::c_int = 80; -pub const IUTF8: ::tcflag_t = 0x00004000; -pub const CMSPAR: ::tcflag_t = 0o10000000000; - -pub const MFD_CLOEXEC: ::c_uint = 0x0001; -pub const MFD_ALLOW_SEALING: ::c_uint = 0x0002; - -// these are used in the p_type field of Elf32_Phdr and Elf64_Phdr, which has -// the type Elf32Word and Elf64Word respectively. Luckily, both of those are u32 -// so we can use that type here to avoid having to cast. -pub const PT_NULL: u32 = 0; -pub const PT_LOAD: u32 = 1; -pub const PT_DYNAMIC: u32 = 2; -pub const PT_INTERP: u32 = 3; -pub const PT_NOTE: u32 = 4; -pub const PT_SHLIB: u32 = 5; -pub const PT_PHDR: u32 = 6; -pub const PT_TLS: u32 = 7; -pub const PT_NUM: u32 = 8; -pub const PT_LOOS: u32 = 0x60000000; -pub const PT_GNU_EH_FRAME: u32 = 0x6474e550; -pub const PT_GNU_STACK: u32 = 0x6474e551; -pub const PT_GNU_RELRO: u32 = 0x6474e552; - -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 0x00040000; -pub const O_NOATIME: ::c_int = 0x00002000; -pub const O_CLOEXEC: ::c_int = 0x00000100; -pub const O_TMPFILE: ::c_int = 0x00004000; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const BUFSIZ: ::c_uint = 1024; -pub const TMP_MAX: ::c_uint = 10000; -pub const FOPEN_MAX: ::c_uint = 1000; -pub const O_PATH: ::c_int = 0x00400000; -pub const O_EXEC: ::c_int = O_PATH; -pub const O_SEARCH: ::c_int = O_PATH; -pub const O_ACCMODE: ::c_int = (03 | O_SEARCH); -pub const O_NDELAY: ::c_int = O_NONBLOCK; -pub const NI_MAXHOST: ::socklen_t = 255; -pub const PTHREAD_STACK_MIN: ::size_t = 2048; -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const POSIX_MADV_DONTNEED: ::c_int = 4; - -pub const RLIM_INFINITY: ::rlim_t = !0; -pub const RLIMIT_RTTIME: ::c_int = 15; -pub const RLIMIT_NLIMITS: ::c_int = 16; - -pub const MAP_ANONYMOUS: ::c_int = MAP_ANON; - -pub const SOCK_DCCP: ::c_int = 6; -pub const SOCK_PACKET: ::c_int = 10; - -pub const TCP_COOKIE_TRANSACTIONS: ::c_int = 15; -pub const TCP_THIN_LINEAR_TIMEOUTS: ::c_int = 16; -pub const TCP_THIN_DUPACK: ::c_int = 17; -pub const TCP_USER_TIMEOUT: ::c_int = 18; -pub const TCP_REPAIR: ::c_int = 19; -pub const TCP_REPAIR_QUEUE: ::c_int = 20; -pub const TCP_QUEUE_SEQ: ::c_int = 21; -pub const TCP_REPAIR_OPTIONS: ::c_int = 22; -pub const TCP_FASTOPEN: ::c_int = 23; -pub const TCP_TIMESTAMP: ::c_int = 24; - -pub const SIGUNUSED: ::c_int = ::SIGSYS; - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; - -pub const CPU_SETSIZE: ::c_int = 128; - -pub const PTRACE_TRACEME: ::c_int = 0; -pub const PTRACE_PEEKTEXT: ::c_int = 1; -pub const PTRACE_PEEKDATA: ::c_int = 2; -pub const PTRACE_PEEKUSER: ::c_int = 3; -pub const PTRACE_POKETEXT: ::c_int = 4; -pub const PTRACE_POKEDATA: ::c_int = 5; -pub const PTRACE_POKEUSER: ::c_int = 6; -pub const PTRACE_CONT: ::c_int = 7; -pub const PTRACE_KILL: ::c_int = 8; -pub const PTRACE_SINGLESTEP: ::c_int = 9; -pub const PTRACE_GETREGS: ::c_int = 12; -pub const PTRACE_SETREGS: ::c_int = 13; -pub const PTRACE_GETFPREGS: ::c_int = 14; -pub const PTRACE_SETFPREGS: ::c_int = 15; -pub const PTRACE_ATTACH: ::c_int = 16; -pub const PTRACE_DETACH: ::c_int = 17; -pub const PTRACE_GETFPXREGS: ::c_int = 18; -pub const PTRACE_SETFPXREGS: ::c_int = 19; -pub const PTRACE_SYSCALL: ::c_int = 24; -pub const PTRACE_SETOPTIONS: ::c_int = 0x4200; -pub const PTRACE_GETEVENTMSG: ::c_int = 0x4201; -pub const PTRACE_GETSIGINFO: ::c_int = 0x4202; -pub const PTRACE_SETSIGINFO: ::c_int = 0x4203; -pub const PTRACE_GETREGSET: ::c_int = 0x4204; -pub const PTRACE_SETREGSET: ::c_int = 0x4205; -pub const PTRACE_SEIZE: ::c_int = 0x4206; -pub const PTRACE_INTERRUPT: ::c_int = 0x4207; -pub const PTRACE_LISTEN: ::c_int = 0x4208; -pub const PTRACE_PEEKSIGINFO: ::c_int = 0x4209; - -pub const EPOLLWAKEUP: ::c_int = 0x20000000; - -pub const EFD_NONBLOCK: ::c_int = ::O_NONBLOCK; - -pub const SFD_NONBLOCK: ::c_int = ::O_NONBLOCK; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCINQ: ::c_int = ::FIONREAD; - -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; - -// TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux -// kernel 3.10). See also notbsd/mod.rs -pub const CLOCK_SGI_CYCLE: ::clockid_t = 10; -pub const CLOCK_TAI: ::clockid_t = 11; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::c_int = 0x00000800; -pub const TAB2: ::c_int = 0x00001000; -pub const TAB3: ::c_int = 0x00001800; -pub const CR1: ::c_int = 0x00000200; -pub const CR2: ::c_int = 0x00000400; -pub const CR3: ::c_int = 0x00000600; -pub const FF1: ::c_int = 0x00008000; -pub const BS1: ::c_int = 0x00002000; -pub const VT1: ::c_int = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_MARK: ::c_int = 36; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_BUSY_POLL: ::c_int = 46; - -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; - -pub const O_ASYNC: ::c_int = 0x00000400; - -pub const FIOCLEX: ::c_int = 0x5451; -pub const FIONBIO: ::c_int = 0x5421; - -pub const RLIMIT_RSS: ::c_int = 5; -pub const RLIMIT_NOFILE: ::c_int = 7; -pub const RLIMIT_AS: ::c_int = 9; -pub const RLIMIT_NPROC: ::c_int = 6; -pub const RLIMIT_MEMLOCK: ::c_int = 8; - -pub const O_APPEND: ::c_int = 0x00100000; -pub const O_CREAT: ::c_int = 0x00010000; -pub const O_EXCL: ::c_int = 0x00020000; -pub const O_NOCTTY: ::c_int = 0x00000200; -pub const O_NONBLOCK: ::c_int = 0x00000010; -pub const O_SYNC: ::c_int = (0x00000040 | O_DSYNC); -pub const O_RSYNC: ::c_int = O_SYNC; -pub const O_DSYNC: ::c_int = 0x00000020; - -pub const SOCK_NONBLOCK: ::c_int = 2048; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_SEQPACKET: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EDEADLOCK: ::c_int = EDEADLK; -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const EXTPROC: ::tcflag_t = 0x00010000; - -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; -pub const F_SETOWN: ::c_int = 8; - -pub const VEOF: usize = 4; -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; - -pub const TCGETS: ::c_int = 0x5401; -pub const TCSETS: ::c_int = 0x5402; -pub const TCSETSW: ::c_int = 0x5403; -pub const TCSETSF: ::c_int = 0x5404; -pub const TCGETA: ::c_int = 0x5405; -pub const TCSETA: ::c_int = 0x5406; -pub const TCSETAW: ::c_int = 0x5407; -pub const TCSETAF: ::c_int = 0x5408; -pub const TCSBRK: ::c_int = 0x5409; -pub const TCXONC: ::c_int = 0x540A; -pub const TCFLSH: ::c_int = 0x540B; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x540F; -pub const TIOCSPGRP: ::c_int = 0x5410; -pub const TIOCOUTQ: ::c_int = 0x5411; -pub const TIOCSTI: ::c_int = 0x5412; -pub const TIOCGWINSZ: ::c_int = 0x5413; -pub const TIOCSWINSZ: ::c_int = 0x5414; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x541B; -pub const TIOCCONS: ::c_int = 0x541D; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -pub const O_DIRECTORY: ::c_int = 0x00080000; -pub const O_DIRECT: ::c_int = 0x00000800; -pub const O_LARGEFILE: ::c_int = 0x00001000; -pub const O_NOFOLLOW: ::c_int = 0x00000080; - -// intentionally not public, only used for fd_set -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - const ULONG_SIZE: usize = 32; - } else if #[cfg(target_pointer_width = "64")] { - const ULONG_SIZE: usize = 64; - } else { - // Unknown target_pointer_width - } -} - -// END_PUB_CONST - -f! { - pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return - } - - pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 - } - - pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return - } - - pub fn FD_ZERO(set: *mut fd_set) -> () { - for slot in (*set).fds_bits.iter_mut() { - *slot = 0; - } - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0xff) == 0x7f - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WIFCONTINUED(status: ::c_int) -> bool { - status == 0xffff - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - ((status & 0x7f) + 1) as i8 >= 2 - } - - pub fn WTERMSIG(status: ::c_int) -> ::c_int { - status & 0x7f - } - - pub fn WIFEXITED(status: ::c_int) -> bool { - (status & 0x7f) == 0 - } - - pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WCOREDUMP(status: ::c_int) -> bool { - (status & 0x80) != 0 - } - - pub fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { - (cmd << 8) | (type_ & 0x00ff) - } - - pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { - for slot in cpuset.bits.iter_mut() { - *slot = 0; - } - } - - pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits - = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] |= 1 << offset; - () - } - - pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits - = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] &= !(1 << offset); - () - } - - pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * ::mem::size_of_val(&cpuset.bits[0]); - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - 0 != (cpuset.bits[idx] & (1 << offset)) - } - - pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool { - set1.bits == set2.bits - } - - pub fn major(dev: ::dev_t) -> ::c_uint { - let mut major = 0; - major |= (dev & 0x00000000000fff00) >> 8; - major |= (dev & 0xfffff00000000000) >> 32; - major as ::c_uint - } - - pub fn minor(dev: ::dev_t) -> ::c_uint { - let mut minor = 0; - minor |= (dev & 0x00000000000000ff) >> 0; - minor |= (dev & 0x00000ffffff00000) >> 12; - minor as ::c_uint - } - - pub fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t { - let major = major as ::dev_t; - let minor = minor as ::dev_t; - let mut dev = 0; - dev |= (major & 0x00000fff) << 8; - dev |= (major & 0xfffff000) << 32; - dev |= (minor & 0x000000ff) << 0; - dev |= (minor & 0xffffff00) << 12; - dev - } -} - -// EXTERN_FN - -#[link(name = "c")] -#[link(name = "fdio")] -extern "C" {} - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum FILE {} -impl ::Copy for FILE {} -impl ::Clone for FILE { - fn clone(&self) -> FILE { - *self - } -} -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos_t {} // TODO: fill this out with a struct -impl ::Copy for fpos_t {} -impl ::Clone for fpos_t { - fn clone(&self) -> fpos_t { - *self - } -} - -extern "C" { - pub fn isalnum(c: c_int) -> c_int; - pub fn isalpha(c: c_int) -> c_int; - pub fn iscntrl(c: c_int) -> c_int; - pub fn isdigit(c: c_int) -> c_int; - pub fn isgraph(c: c_int) -> c_int; - pub fn islower(c: c_int) -> c_int; - pub fn isprint(c: c_int) -> c_int; - pub fn ispunct(c: c_int) -> c_int; - pub fn isspace(c: c_int) -> c_int; - pub fn isupper(c: c_int) -> c_int; - pub fn isxdigit(c: c_int) -> c_int; - pub fn isblank(c: c_int) -> c_int; - pub fn tolower(c: c_int) -> c_int; - pub fn toupper(c: c_int) -> c_int; - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - pub fn freopen( - filename: *const c_char, - mode: *const c_char, - file: *mut FILE, - ) -> *mut FILE; - pub fn fflush(file: *mut FILE) -> c_int; - pub fn fclose(file: *mut FILE) -> c_int; - pub fn remove(filename: *const c_char) -> c_int; - pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; - pub fn tmpfile() -> *mut FILE; - pub fn setvbuf( - stream: *mut FILE, - buffer: *mut c_char, - mode: c_int, - size: size_t, - ) -> c_int; - pub fn setbuf(stream: *mut FILE, buf: *mut c_char); - pub fn getchar() -> c_int; - pub fn putchar(c: c_int) -> c_int; - pub fn fgetc(stream: *mut FILE) -> c_int; - pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) - -> *mut c_char; - pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; - pub fn puts(s: *const c_char) -> c_int; - pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fread( - ptr: *mut c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fwrite( - ptr: *const c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; - pub fn ftell(stream: *mut FILE) -> c_long; - pub fn rewind(stream: *mut FILE); - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; - pub fn feof(stream: *mut FILE) -> c_int; - pub fn ferror(stream: *mut FILE) -> c_int; - pub fn perror(s: *const c_char); - pub fn atoi(s: *const c_char) -> c_int; - pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; - pub fn strtol( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_long; - pub fn strtoul( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_ulong; - pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; - pub fn malloc(size: size_t) -> *mut c_void; - pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; - pub fn free(p: *mut c_void); - pub fn abort() -> !; - pub fn exit(status: c_int) -> !; - pub fn _exit(status: c_int) -> !; - pub fn atexit(cb: extern "C" fn()) -> c_int; - pub fn system(s: *const c_char) -> c_int; - pub fn getenv(s: *const c_char) -> *mut c_char; - - pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; - pub fn strncpy( - dst: *mut c_char, - src: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; - pub fn strncat( - s: *mut c_char, - ct: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; - pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strdup(cs: *const c_char) -> *mut c_char; - pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strlen(cs: *const c_char) -> size_t; - pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; - pub fn strerror(n: c_int) -> *mut c_char; - pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; - pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; - pub fn wcslen(buf: *const wchar_t) -> size_t; - pub fn wcstombs( - dest: *mut c_char, - src: *const wchar_t, - n: size_t, - ) -> ::size_t; - - pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memcpy( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memmove( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; - - pub fn abs(i: c_int) -> c_int; - pub fn atof(s: *const c_char) -> c_double; - pub fn labs(i: c_long) -> c_long; - pub fn rand() -> c_int; - pub fn srand(seed: c_uint); - - pub fn getpwnam(name: *const ::c_char) -> *mut passwd; - pub fn getpwuid(uid: ::uid_t) -> *mut passwd; - - pub fn fprintf( - stream: *mut ::FILE, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn printf(format: *const ::c_char, ...) -> ::c_int; - pub fn snprintf( - s: *mut ::c_char, - n: ::size_t, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int; - pub fn fscanf( - stream: *mut ::FILE, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn scanf(format: *const ::c_char, ...) -> ::c_int; - pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) - -> ::c_int; - pub fn getchar_unlocked() -> ::c_int; - pub fn putchar_unlocked(c: ::c_int) -> ::c_int; - - pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int; - pub fn connect( - socket: ::c_int, - address: *const sockaddr, - len: socklen_t, - ) -> ::c_int; - pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; - pub fn accept( - socket: ::c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ::c_int; - pub fn getpeername( - socket: ::c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ::c_int; - pub fn getsockname( - socket: ::c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ::c_int; - pub fn setsockopt( - socket: ::c_int, - level: ::c_int, - name: ::c_int, - value: *const ::c_void, - option_len: socklen_t, - ) -> ::c_int; - pub fn socketpair( - domain: ::c_int, - type_: ::c_int, - protocol: ::c_int, - socket_vector: *mut ::c_int, - ) -> ::c_int; - pub fn sendto( - socket: ::c_int, - buf: *const ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *const sockaddr, - addrlen: socklen_t, - ) -> ::ssize_t; - pub fn shutdown(socket: ::c_int, how: ::c_int) -> ::c_int; - - pub fn chmod(path: *const c_char, mode: mode_t) -> ::c_int; - pub fn fchmod(fd: ::c_int, mode: mode_t) -> ::c_int; - - pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; - - pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int; - - pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; - - pub fn pclose(stream: *mut ::FILE) -> ::c_int; - pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; - pub fn fileno(stream: *mut ::FILE) -> ::c_int; - - pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; - pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int; - pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int; - - pub fn opendir(dirname: *const c_char) -> *mut ::DIR; - pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; - pub fn readdir_r( - dirp: *mut ::DIR, - entry: *mut ::dirent, - result: *mut *mut ::dirent, - ) -> ::c_int; - pub fn closedir(dirp: *mut ::DIR) -> ::c_int; - pub fn rewinddir(dirp: *mut ::DIR); - - pub fn openat( - dirfd: ::c_int, - pathname: *const ::c_char, - flags: ::c_int, - ... - ) -> ::c_int; - pub fn fchmodat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - flags: ::c_int, - ) -> ::c_int; - pub fn fchown(fd: ::c_int, owner: ::uid_t, group: ::gid_t) -> ::c_int; - pub fn fchownat( - dirfd: ::c_int, - pathname: *const ::c_char, - owner: ::uid_t, - group: ::gid_t, - flags: ::c_int, - ) -> ::c_int; - pub fn fstatat( - dirfd: ::c_int, - pathname: *const ::c_char, - buf: *mut stat, - flags: ::c_int, - ) -> ::c_int; - pub fn linkat( - olddirfd: ::c_int, - oldpath: *const ::c_char, - newdirfd: ::c_int, - newpath: *const ::c_char, - flags: ::c_int, - ) -> ::c_int; - pub fn mkdirat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - pub fn readlinkat( - dirfd: ::c_int, - pathname: *const ::c_char, - buf: *mut ::c_char, - bufsiz: ::size_t, - ) -> ::ssize_t; - pub fn renameat( - olddirfd: ::c_int, - oldpath: *const ::c_char, - newdirfd: ::c_int, - newpath: *const ::c_char, - ) -> ::c_int; - pub fn symlinkat( - target: *const ::c_char, - newdirfd: ::c_int, - linkpath: *const ::c_char, - ) -> ::c_int; - pub fn unlinkat( - dirfd: ::c_int, - pathname: *const ::c_char, - flags: ::c_int, - ) -> ::c_int; - - pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; - pub fn alarm(seconds: ::c_uint) -> ::c_uint; - pub fn chdir(dir: *const c_char) -> ::c_int; - pub fn chown(path: *const c_char, uid: uid_t, gid: gid_t) -> ::c_int; - pub fn lchown(path: *const c_char, uid: uid_t, gid: gid_t) -> ::c_int; - pub fn close(fd: ::c_int) -> ::c_int; - pub fn dup(fd: ::c_int) -> ::c_int; - pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; - pub fn execl(path: *const c_char, arg0: *const c_char, ...) -> ::c_int; - pub fn execle( - path: *const ::c_char, - arg0: *const ::c_char, - ... - ) -> ::c_int; - pub fn execlp( - file: *const ::c_char, - arg0: *const ::c_char, - ... - ) -> ::c_int; - pub fn execv(prog: *const c_char, argv: *const *const c_char) -> ::c_int; - pub fn execve( - prog: *const c_char, - argv: *const *const c_char, - envp: *const *const c_char, - ) -> ::c_int; - pub fn execvp(c: *const c_char, argv: *const *const c_char) -> ::c_int; - pub fn fork() -> pid_t; - pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> c_long; - pub fn getcwd(buf: *mut c_char, size: ::size_t) -> *mut c_char; - pub fn getegid() -> gid_t; - pub fn geteuid() -> uid_t; - pub fn getgid() -> gid_t; - pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t) -> ::c_int; - pub fn getlogin() -> *mut c_char; - pub fn getopt( - argc: ::c_int, - argv: *const *mut c_char, - optstr: *const c_char, - ) -> ::c_int; - pub fn getpgid(pid: pid_t) -> pid_t; - pub fn getpgrp() -> pid_t; - pub fn getpid() -> pid_t; - pub fn getppid() -> pid_t; - pub fn getuid() -> uid_t; - pub fn isatty(fd: ::c_int) -> ::c_int; - pub fn link(src: *const c_char, dst: *const c_char) -> ::c_int; - pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t; - pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long; - pub fn pause() -> ::c_int; - pub fn pipe(fds: *mut ::c_int) -> ::c_int; - pub fn posix_memalign( - memptr: *mut *mut ::c_void, - align: ::size_t, - size: ::size_t, - ) -> ::c_int; - pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) - -> ::ssize_t; - pub fn rmdir(path: *const c_char) -> ::c_int; - pub fn seteuid(uid: uid_t) -> ::c_int; - pub fn setegid(gid: gid_t) -> ::c_int; - pub fn setgid(gid: gid_t) -> ::c_int; - pub fn setpgid(pid: pid_t, pgid: pid_t) -> ::c_int; - pub fn setsid() -> pid_t; - pub fn setuid(uid: uid_t) -> ::c_int; - pub fn sleep(secs: ::c_uint) -> ::c_uint; - pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> ::c_int; - pub fn tcgetpgrp(fd: ::c_int) -> pid_t; - pub fn tcsetpgrp(fd: ::c_int, pgrp: ::pid_t) -> ::c_int; - pub fn ttyname(fd: ::c_int) -> *mut c_char; - pub fn unlink(c: *const c_char) -> ::c_int; - pub fn wait(status: *mut ::c_int) -> pid_t; - pub fn waitpid( - pid: pid_t, - status: *mut ::c_int, - options: ::c_int, - ) -> pid_t; - pub fn write( - fd: ::c_int, - buf: *const ::c_void, - count: ::size_t, - ) -> ::ssize_t; - pub fn pread( - fd: ::c_int, - buf: *mut ::c_void, - count: ::size_t, - offset: off_t, - ) -> ::ssize_t; - pub fn pwrite( - fd: ::c_int, - buf: *const ::c_void, - count: ::size_t, - offset: off_t, - ) -> ::ssize_t; - pub fn umask(mask: mode_t) -> mode_t; - - pub fn utime(file: *const c_char, buf: *const utimbuf) -> ::c_int; - - pub fn kill(pid: pid_t, sig: ::c_int) -> ::c_int; - - pub fn mlock(addr: *const ::c_void, len: ::size_t) -> ::c_int; - pub fn munlock(addr: *const ::c_void, len: ::size_t) -> ::c_int; - pub fn mlockall(flags: ::c_int) -> ::c_int; - pub fn munlockall() -> ::c_int; - - pub fn mmap( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - flags: ::c_int, - fd: ::c_int, - offset: off_t, - ) -> *mut ::c_void; - pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int; - - pub fn if_nametoindex(ifname: *const c_char) -> ::c_uint; - pub fn if_indextoname( - ifindex: ::c_uint, - ifname: *mut ::c_char, - ) -> *mut ::c_char; - - pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int; - - pub fn fsync(fd: ::c_int) -> ::c_int; - - pub fn setenv( - name: *const c_char, - val: *const c_char, - overwrite: ::c_int, - ) -> ::c_int; - pub fn unsetenv(name: *const c_char) -> ::c_int; - - pub fn symlink(path1: *const c_char, path2: *const c_char) -> ::c_int; - - pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int; - - pub fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t; - - pub fn realpath( - pathname: *const ::c_char, - resolved: *mut ::c_char, - ) -> *mut ::c_char; - - pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int; - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn times(buf: *mut ::tms) -> ::clock_t; - - pub fn pthread_self() -> ::pthread_t; - pub fn pthread_join( - native: ::pthread_t, - value: *mut *mut ::c_void, - ) -> ::c_int; - pub fn pthread_exit(value: *mut ::c_void) -> !; - pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int; - pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int; - pub fn pthread_attr_setstacksize( - attr: *mut ::pthread_attr_t, - stack_size: ::size_t, - ) -> ::c_int; - pub fn pthread_attr_setdetachstate( - attr: *mut ::pthread_attr_t, - state: ::c_int, - ) -> ::c_int; - pub fn pthread_detach(thread: ::pthread_t) -> ::c_int; - pub fn sched_yield() -> ::c_int; - pub fn pthread_key_create( - key: *mut pthread_key_t, - dtor: ::Option, - ) -> ::c_int; - pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int; - pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void; - pub fn pthread_setspecific( - key: pthread_key_t, - value: *const ::c_void, - ) -> ::c_int; - pub fn pthread_mutex_init( - lock: *mut pthread_mutex_t, - attr: *const pthread_mutexattr_t, - ) -> ::c_int; - pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> ::c_int; - pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> ::c_int; - pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> ::c_int; - pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> ::c_int; - - pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int; - pub fn pthread_mutexattr_destroy( - attr: *mut pthread_mutexattr_t, - ) -> ::c_int; - pub fn pthread_mutexattr_settype( - attr: *mut pthread_mutexattr_t, - _type: ::c_int, - ) -> ::c_int; - - pub fn pthread_cond_init( - cond: *mut pthread_cond_t, - attr: *const pthread_condattr_t, - ) -> ::c_int; - pub fn pthread_cond_wait( - cond: *mut pthread_cond_t, - lock: *mut pthread_mutex_t, - ) -> ::c_int; - pub fn pthread_cond_timedwait( - cond: *mut pthread_cond_t, - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int; - pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int; - pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int; - pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> ::c_int; - pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> ::c_int; - pub fn pthread_rwlock_init( - lock: *mut pthread_rwlock_t, - attr: *const pthread_rwlockattr_t, - ) -> ::c_int; - pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int; - pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> ::c_int; - pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> ::c_int; - pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> ::c_int; - pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> ::c_int; - pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int; - pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) - -> ::c_int; - pub fn pthread_rwlockattr_destroy( - attr: *mut pthread_rwlockattr_t, - ) -> ::c_int; - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn getsockopt( - sockfd: ::c_int, - level: ::c_int, - optname: ::c_int, - optval: *mut ::c_void, - optlen: *mut ::socklen_t, - ) -> ::c_int; - pub fn raise(signum: ::c_int) -> ::c_int; - pub fn sigaction( - signum: ::c_int, - act: *const sigaction, - oldact: *mut sigaction, - ) -> ::c_int; - - pub fn utimes( - filename: *const ::c_char, - times: *const ::timeval, - ) -> ::c_int; - pub fn dlopen(filename: *const ::c_char, flag: ::c_int) -> *mut ::c_void; - pub fn dlerror() -> *mut ::c_char; - pub fn dlsym( - handle: *mut ::c_void, - symbol: *const ::c_char, - ) -> *mut ::c_void; - pub fn dlclose(handle: *mut ::c_void) -> ::c_int; - pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int; - - pub fn getaddrinfo( - node: *const c_char, - service: *const c_char, - hints: *const addrinfo, - res: *mut *mut addrinfo, - ) -> ::c_int; - pub fn freeaddrinfo(res: *mut addrinfo); - pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char; - pub fn res_init() -> ::c_int; - - pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; - pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; - pub fn mktime(tm: *mut tm) -> time_t; - pub fn time(time: *mut time_t) -> time_t; - pub fn gmtime(time_p: *const time_t) -> *mut tm; - pub fn localtime(time_p: *const time_t) -> *mut tm; - - pub fn mknod( - pathname: *const ::c_char, - mode: ::mode_t, - dev: ::dev_t, - ) -> ::c_int; - pub fn uname(buf: *mut ::utsname) -> ::c_int; - pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int; - pub fn getservbyname( - name: *const ::c_char, - proto: *const ::c_char, - ) -> *mut servent; - pub fn getprotobyname(name: *const ::c_char) -> *mut protoent; - pub fn getprotobynumber(proto: ::c_int) -> *mut protoent; - pub fn usleep(secs: ::c_uint) -> ::c_int; - pub fn send( - socket: ::c_int, - buf: *const ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - pub fn recv( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - pub fn putenv(string: *mut c_char) -> ::c_int; - pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int; - pub fn select( - nfds: ::c_int, - readfs: *mut fd_set, - writefds: *mut fd_set, - errorfds: *mut fd_set, - timeout: *mut timeval, - ) -> ::c_int; - pub fn setlocale( - category: ::c_int, - locale: *const ::c_char, - ) -> *mut ::c_char; - pub fn localeconv() -> *mut lconv; - - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_wait(sem: *mut sem_t) -> ::c_int; - pub fn sem_trywait(sem: *mut sem_t) -> ::c_int; - pub fn sem_post(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int; - pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int; - - pub fn readlink( - path: *const c_char, - buf: *mut c_char, - bufsz: ::size_t, - ) -> ::ssize_t; - - pub fn sigemptyset(set: *mut sigset_t) -> ::c_int; - pub fn sigaddset(set: *mut sigset_t, signum: ::c_int) -> ::c_int; - pub fn sigfillset(set: *mut sigset_t) -> ::c_int; - pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int; - pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int; - - pub fn sigprocmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sigpending(set: *mut sigset_t) -> ::c_int; - - pub fn timegm(tm: *mut ::tm) -> time_t; - - pub fn getsid(pid: pid_t) -> pid_t; - - pub fn sysconf(name: ::c_int) -> ::c_long; - - pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int; - - pub fn pselect( - nfds: ::c_int, - readfs: *mut fd_set, - writefds: *mut fd_set, - errorfds: *mut fd_set, - timeout: *const timespec, - sigmask: *const sigset_t, - ) -> ::c_int; - pub fn fseeko( - stream: *mut ::FILE, - offset: ::off_t, - whence: ::c_int, - ) -> ::c_int; - pub fn ftello(stream: *mut ::FILE) -> ::off_t; - pub fn tcdrain(fd: ::c_int) -> ::c_int; - pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t; - pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t; - pub fn cfmakeraw(termios: *mut ::termios); - pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; - pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; - pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; - pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int; - pub fn tcsetattr( - fd: ::c_int, - optional_actions: ::c_int, - termios: *const ::termios, - ) -> ::c_int; - pub fn tcflow(fd: ::c_int, action: ::c_int) -> ::c_int; - pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int; - pub fn tcgetsid(fd: ::c_int) -> ::pid_t; - pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int; - pub fn mkstemp(template: *mut ::c_char) -> ::c_int; - pub fn mkdtemp(template: *mut ::c_char) -> *mut ::c_char; - - pub fn tmpnam(ptr: *mut ::c_char) -> *mut ::c_char; - - pub fn openlog(ident: *const ::c_char, logopt: ::c_int, facility: ::c_int); - pub fn closelog(); - pub fn setlogmask(maskpri: ::c_int) -> ::c_int; - pub fn syslog(priority: ::c_int, message: *const ::c_char, ...); - - pub fn grantpt(fd: ::c_int) -> ::c_int; - pub fn posix_openpt(flags: ::c_int) -> ::c_int; - pub fn ptsname(fd: ::c_int) -> *mut ::c_char; - pub fn unlockpt(fd: ::c_int) -> ::c_int; - - pub fn fdatasync(fd: ::c_int) -> ::c_int; - pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_settime( - clk_id: ::clockid_t, - tp: *const ::timespec, - ) -> ::c_int; - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - - pub fn pthread_getattr_np( - native: ::pthread_t, - attr: *mut ::pthread_attr_t, - ) -> ::c_int; - pub fn pthread_attr_getstack( - attr: *const ::pthread_attr_t, - stackaddr: *mut *mut ::c_void, - stacksize: *mut ::size_t, - ) -> ::c_int; - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; - pub fn setgroups(ngroups: ::size_t, ptr: *const ::gid_t) -> ::c_int; - pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int; - pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; - pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; - pub fn memrchr( - cx: *const ::c_void, - c: ::c_int, - n: ::size_t, - ) -> *mut ::c_void; - - pub fn posix_fadvise( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - advise: ::c_int, - ) -> ::c_int; - pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; - pub fn utimensat( - dirfd: ::c_int, - path: *const ::c_char, - times: *const ::timespec, - flag: ::c_int, - ) -> ::c_int; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn freelocale(loc: ::locale_t); - pub fn newlocale( - mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t, - ) -> ::locale_t; - pub fn uselocale(loc: ::locale_t) -> ::locale_t; - - pub fn fdopendir(fd: ::c_int) -> *mut ::DIR; - - pub fn mknodat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - dev: dev_t, - ) -> ::c_int; - pub fn pthread_condattr_getclock( - attr: *const pthread_condattr_t, - clock_id: *mut clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_setclock( - attr: *mut pthread_condattr_t, - clock_id: ::clockid_t, - ) -> ::c_int; - pub fn accept4( - fd: ::c_int, - addr: *mut ::sockaddr, - len: *mut ::socklen_t, - flg: ::c_int, - ) -> ::c_int; - pub fn ptsname_r( - fd: ::c_int, - buf: *mut ::c_char, - buflen: ::size_t, - ) -> ::c_int; - pub fn clearenv() -> ::c_int; - pub fn waitid( - idtype: idtype_t, - id: id_t, - infop: *mut ::siginfo_t, - options: ::c_int, - ) -> ::c_int; - pub fn setreuid(ruid: ::uid_t, euid: ::uid_t) -> ::c_int; - pub fn setregid(rgid: ::gid_t, egid: ::gid_t) -> ::c_int; - pub fn getresuid( - ruid: *mut ::uid_t, - euid: *mut ::uid_t, - suid: *mut ::uid_t, - ) -> ::c_int; - pub fn getresgid( - rgid: *mut ::gid_t, - egid: *mut ::gid_t, - sgid: *mut ::gid_t, - ) -> ::c_int; - pub fn acct(filename: *const ::c_char) -> ::c_int; - pub fn brk(addr: *mut ::c_void) -> ::c_int; - pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int; - pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int; - pub fn openpty( - amaster: *mut ::c_int, - aslave: *mut ::c_int, - name: *mut ::c_char, - termp: *const termios, - winp: *const ::winsize, - ) -> ::c_int; - pub fn execvpe( - file: *const ::c_char, - argv: *const *const ::c_char, - envp: *const *const ::c_char, - ) -> ::c_int; - pub fn fexecve( - fd: ::c_int, - argv: *const *const ::c_char, - envp: *const *const ::c_char, - ) -> ::c_int; - - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - - pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; - - pub fn setpwent(); - pub fn endpwent(); - pub fn getpwent() -> *mut passwd; - - pub fn shm_open( - name: *const c_char, - oflag: ::c_int, - mode: mode_t, - ) -> ::c_int; - - // System V IPC - pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int; - pub fn shmat( - shmid: ::c_int, - shmaddr: *const ::c_void, - shmflg: ::c_int, - ) -> *mut ::c_void; - pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int; - pub fn shmctl( - shmid: ::c_int, - cmd: ::c_int, - buf: *mut ::shmid_ds, - ) -> ::c_int; - pub fn ftok(pathname: *const ::c_char, proj_id: ::c_int) -> ::key_t; - pub fn semget(key: ::key_t, nsems: ::c_int, semflag: ::c_int) -> ::c_int; - pub fn semop( - semid: ::c_int, - sops: *mut ::sembuf, - nsops: ::size_t, - ) -> ::c_int; - pub fn semctl( - semid: ::c_int, - semnum: ::c_int, - cmd: ::c_int, - ... - ) -> ::c_int; - pub fn msgctl(msqid: ::c_int, cmd: ::c_int, buf: *mut msqid_ds) - -> ::c_int; - pub fn msgget(key: ::key_t, msgflg: ::c_int) -> ::c_int; - pub fn msgrcv( - msqid: ::c_int, - msgp: *mut ::c_void, - msgsz: ::size_t, - msgtyp: ::c_long, - msgflg: ::c_int, - ) -> ::ssize_t; - pub fn msgsnd( - msqid: ::c_int, - msgp: *const ::c_void, - msgsz: ::size_t, - msgflg: ::c_int, - ) -> ::c_int; - - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn __errno_location() -> *mut ::c_int; - - pub fn fallocate( - fd: ::c_int, - mode: ::c_int, - offset: ::off_t, - len: ::off_t, - ) -> ::c_int; - pub fn posix_fallocate( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - ) -> ::c_int; - pub fn readahead( - fd: ::c_int, - offset: ::off64_t, - count: ::size_t, - ) -> ::ssize_t; - pub fn signalfd( - fd: ::c_int, - mask: *const ::sigset_t, - flags: ::c_int, - ) -> ::c_int; - pub fn timerfd_create(clockid: ::c_int, flags: ::c_int) -> ::c_int; - pub fn timerfd_gettime( - fd: ::c_int, - curr_value: *mut itimerspec, - ) -> ::c_int; - pub fn timerfd_settime( - fd: ::c_int, - flags: ::c_int, - new_value: *const itimerspec, - old_value: *mut itimerspec, - ) -> ::c_int; - pub fn pwritev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn preadv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn quotactl( - cmd: ::c_int, - special: *const ::c_char, - id: ::c_int, - data: *mut ::c_char, - ) -> ::c_int; - pub fn dup3(oldfd: ::c_int, newfd: ::c_int, flags: ::c_int) -> ::c_int; - pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int; - pub fn mkostemps( - template: *mut ::c_char, - suffixlen: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn sigtimedwait( - set: *const sigset_t, - info: *mut siginfo_t, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> ::c_int; - pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) - -> *mut ::c_char; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::socklen_t, - serv: *mut ::c_char, - sevlen: ::socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn reboot(how_to: ::c_int) -> ::c_int; - pub fn setfsgid(gid: ::gid_t) -> ::c_int; - pub fn setfsuid(uid: ::uid_t) -> ::c_int; - - // Not available now on Android - pub fn mkfifoat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - pub fn if_nameindex() -> *mut if_nameindex; - pub fn if_freenameindex(ptr: *mut if_nameindex); - pub fn sync_file_range( - fd: ::c_int, - offset: ::off64_t, - nbytes: ::off64_t, - flags: ::c_uint, - ) -> ::c_int; - pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; - pub fn freeifaddrs(ifa: *mut ::ifaddrs); - - pub fn glob( - pattern: *const c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut ::glob_t, - ) -> ::c_int; - pub fn globfree(pglob: *mut ::glob_t); - - pub fn posix_madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn shm_unlink(name: *const ::c_char) -> ::c_int; - - pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); - - pub fn telldir(dirp: *mut ::DIR) -> ::c_long; - pub fn madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn msync( - addr: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::c_int; - - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; - pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; - pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; - - pub fn bind( - socket: ::c_int, - address: *const ::sockaddr, - address_len: ::socklen_t, - ) -> ::c_int; - - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - - pub fn sendmsg( - fd: ::c_int, - msg: *const ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - pub fn recvmsg( - fd: ::c_int, - msg: *mut ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - pub fn getdomainname(name: *mut ::c_char, len: ::size_t) -> ::c_int; - pub fn setdomainname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn vhangup() -> ::c_int; - pub fn sendmmsg( - sockfd: ::c_int, - msgvec: *mut mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - ) -> ::c_int; - pub fn recvmmsg( - sockfd: ::c_int, - msgvec: *mut mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - timeout: *mut ::timespec, - ) -> ::c_int; - pub fn sync(); - pub fn syscall(num: ::c_long, ...) -> ::c_long; - pub fn sched_getaffinity( - pid: ::pid_t, - cpusetsize: ::size_t, - cpuset: *mut cpu_set_t, - ) -> ::c_int; - pub fn sched_setaffinity( - pid: ::pid_t, - cpusetsize: ::size_t, - cpuset: *const cpu_set_t, - ) -> ::c_int; - pub fn umount(target: *const ::c_char) -> ::c_int; - pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int; - pub fn tee( - fd_in: ::c_int, - fd_out: ::c_int, - len: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn settimeofday( - tv: *const ::timeval, - tz: *const ::timezone, - ) -> ::c_int; - pub fn splice( - fd_in: ::c_int, - off_in: *mut ::loff_t, - fd_out: ::c_int, - off_out: *mut ::loff_t, - len: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int; - pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) - -> ::c_int; - pub fn sem_timedwait( - sem: *mut sem_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; - pub fn sched_setparam( - pid: ::pid_t, - param: *const ::sched_param, - ) -> ::c_int; - pub fn swapoff(puath: *const ::c_char) -> ::c_int; - pub fn vmsplice( - fd: ::c_int, - iov: *const ::iovec, - nr_segs: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn mount( - src: *const ::c_char, - target: *const ::c_char, - fstype: *const ::c_char, - flags: ::c_ulong, - data: *const ::c_void, - ) -> ::c_int; - pub fn personality(persona: ::c_ulong) -> ::c_int; - pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int; - pub fn ppoll( - fds: *mut ::pollfd, - nfds: nfds_t, - timeout: *const ::timespec, - sigmask: *const sigset_t, - ) -> ::c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn clone( - cb: extern "C" fn(*mut ::c_void) -> ::c_int, - child_stack: *mut ::c_void, - flags: ::c_int, - arg: *mut ::c_void, - ... - ) -> ::c_int; - pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int; - pub fn clock_nanosleep( - clk_id: ::clockid_t, - flags: ::c_int, - rqtp: *const ::timespec, - rmtp: *mut ::timespec, - ) -> ::c_int; - pub fn pthread_attr_getguardsize( - attr: *const ::pthread_attr_t, - guardsize: *mut ::size_t, - ) -> ::c_int; - pub fn sethostname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn sched_get_priority_min(policy: ::c_int) -> ::c_int; - pub fn umount2(target: *const ::c_char, flags: ::c_int) -> ::c_int; - pub fn swapon(path: *const ::c_char, swapflags: ::c_int) -> ::c_int; - pub fn sched_setscheduler( - pid: ::pid_t, - policy: ::c_int, - param: *const ::sched_param, - ) -> ::c_int; - pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int; - pub fn getgrgid_r( - gid: ::gid_t, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; - pub fn sem_close(sem: *mut sem_t) -> ::c_int; - pub fn getdtablesize() -> ::c_int; - pub fn getgrnam_r( - name: *const ::c_char, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - pub fn initgroups(user: *const ::c_char, group: ::gid_t) -> ::c_int; - pub fn pthread_sigmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; - pub fn getgrnam(name: *const ::c_char) -> *mut ::group; - pub fn pthread_cancel(thread: ::pthread_t) -> ::c_int; - pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; - pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - pub fn getpwnam_r( - name: *const ::c_char, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn getgrgid(gid: ::gid_t) -> *mut ::group; - pub fn getgrouplist( - user: *const ::c_char, - group: ::gid_t, - groups: *mut ::gid_t, - ngroups: *mut ::c_int, - ) -> ::c_int; - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - pub fn faccessat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn pthread_create( - native: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - pub fn dl_iterate_phdr( - callback: ::Option< - unsafe extern "C" fn( - info: *mut ::dl_phdr_info, - size: ::size_t, - data: *mut ::c_void, - ) -> ::c_int, - >, - data: *mut ::c_void, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(any(target_arch = "x86_64"))] { - mod x86_64; - pub use self::x86_64::*; - } else { - // Unknown target_arch - } -} - -cfg_if! { - if #[cfg(libc_align)] { - #[macro_use] - mod align; - } else { - #[macro_use] - mod no_align; - } -} -expand_align!(); - -cfg_if! { - if #[cfg(libc_core_cvoid)] { - pub use ::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - #[allow(missing_copy_implementations)] - #[allow(missing_debug_implementations)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} diff --git a/libc/src/fuchsia/no_align.rs b/libc/src/fuchsia/no_align.rs deleted file mode 100644 index 7ca90e0..0000000 --- a/libc/src/fuchsia/no_align.rs +++ /dev/null @@ -1,129 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - pub struct pthread_mutexattr_t { - #[cfg(target_arch = "x86_64")] - __align: [::c_int; 0], - #[cfg(not(target_arch = "x86_64"))] - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - pub struct pthread_rwlockattr_t { - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - pub struct pthread_condattr_t { - __align: [::c_int; 0], - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - - s_no_extra_traits! { - pub struct pthread_mutex_t { - #[cfg(any(target_arch = "arm", - all(target_arch = "x86_64", - target_pointer_width = "32")))] - __align: [::c_long; 0], - #[cfg(not(any(target_arch = "arm", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - pub struct pthread_rwlock_t { - __align: [::c_long; 0], - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - - pub struct pthread_cond_t { - __align: [*const ::c_void; 0], - #[cfg(not(target_env = "musl"))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - } - - cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for pthread_cond_t { - fn eq(&self, other: &pthread_cond_t) -> bool { - // Ignore __align field - self.size - .iter() - .zip(other.size.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_cond_t {} - impl ::fmt::Debug for pthread_cond_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_cond_t") - // Ignore __align field - // FIXME: .field("size", &self.size) - .finish() - } - } - impl ::hash::Hash for pthread_cond_t { - fn hash(&self, state: &mut H) { - // Ignore __align field - self.size.hash(state); - } - } - - impl PartialEq for pthread_mutex_t { - fn eq(&self, other: &pthread_mutex_t) -> bool { - // Ignore __align field - self.size - .iter() - .zip(other.size.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_mutex_t {} - impl ::fmt::Debug for pthread_mutex_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_mutex_t") - // Ignore __align field - // FIXME: .field("size", &self.size) - .finish() - } - } - impl ::hash::Hash for pthread_mutex_t { - fn hash(&self, state: &mut H) { - // Ignore __align field - self.size.hash(state); - } - } - - impl PartialEq for pthread_rwlock_t { - fn eq(&self, other: &pthread_rwlock_t) -> bool { - // Ignore __align field - self.size - .iter() - .zip(other.size.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_rwlock_t {} - impl ::fmt::Debug for pthread_rwlock_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_rwlock_t") - // Ignore __align field - // FIXME: .field("size", &self.size) - .finish() - } - } - impl ::hash::Hash for pthread_rwlock_t { - fn hash(&self, state: &mut H) { - // Ignore __align field - self.size.hash(state); - } - } - } - } - }; -} diff --git a/libc/src/fuchsia/x86_64.rs b/libc/src/fuchsia/x86_64.rs deleted file mode 100644 index dca3c24..0000000 --- a/libc/src/fuchsia/x86_64.rs +++ /dev/null @@ -1,152 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; -pub type nlink_t = u64; -pub type blksize_t = ::c_long; -pub type __u64 = ::c_ulonglong; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 3], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __reserved: [::c_long; 3], - } - - pub struct mcontext_t { - __private: [u64; 32], - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __unused1: ::c_long, - __unused2: ::c_long - } -} - -s_no_extra_traits! { - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 512], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for ucontext_t { - fn eq(&self, other: &ucontext_t) -> bool { - self.uc_flags == other.uc_flags - && self.uc_link == other.uc_link - && self.uc_stack == other.uc_stack - && self.uc_mcontext == other.uc_mcontext - && self.uc_sigmask == other.uc_sigmask - && self - .__private - .iter() - .zip(other.__private.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for ucontext_t {} - impl ::fmt::Debug for ucontext_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("ucontext_t") - .field("uc_flags", &self.uc_flags) - .field("uc_link", &self.uc_link) - .field("uc_stack", &self.uc_stack) - .field("uc_mcontext", &self.uc_mcontext) - .field("uc_sigmask", &self.uc_sigmask) - // FIXME: .field("__private", &self.__private) - .finish() - } - } - impl ::hash::Hash for ucontext_t { - fn hash(&self, state: &mut H) { - self.uc_flags.hash(state); - self.uc_link.hash(state); - self.uc_stack.hash(state); - self.uc_mcontext.hash(state); - self.uc_sigmask.hash(state); - self.__private.hash(state); - } - } - } -} - -// offsets in user_regs_structs, from sys/reg.h -pub const R15: ::c_int = 0; -pub const R14: ::c_int = 1; -pub const R13: ::c_int = 2; -pub const R12: ::c_int = 3; -pub const RBP: ::c_int = 4; -pub const RBX: ::c_int = 5; -pub const R11: ::c_int = 6; -pub const R10: ::c_int = 7; -pub const R9: ::c_int = 8; -pub const R8: ::c_int = 9; -pub const RAX: ::c_int = 10; -pub const RCX: ::c_int = 11; -pub const RDX: ::c_int = 12; -pub const RSI: ::c_int = 13; -pub const RDI: ::c_int = 14; -pub const ORIG_RAX: ::c_int = 15; -pub const RIP: ::c_int = 16; -pub const CS: ::c_int = 17; -pub const EFLAGS: ::c_int = 18; -pub const RSP: ::c_int = 19; -pub const SS: ::c_int = 20; -pub const FS_BASE: ::c_int = 21; -pub const GS_BASE: ::c_int = 22; -pub const DS: ::c_int = 23; -pub const ES: ::c_int = 24; -pub const FS: ::c_int = 25; -pub const GS: ::c_int = 26; - -pub const MAP_32BIT: ::c_int = 0x0040; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; diff --git a/libc/src/hermit/aarch64.rs b/libc/src/hermit/aarch64.rs deleted file mode 100644 index 1a92e3b..0000000 --- a/libc/src/hermit/aarch64.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; diff --git a/libc/src/hermit/mod.rs b/libc/src/hermit/mod.rs deleted file mode 100644 index 9880b50..0000000 --- a/libc/src/hermit/mod.rs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// libc port for HermitCore (https://hermitcore.org) -// -// Ported by Colin Fink -// and Stefan Lankes - -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type size_t = usize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type ssize_t = isize; - -pub type c_long = i64; -pub type c_ulong = u64; - -pub type wint_t = u32; -pub type wctype_t = i64; - -pub type regoff_t = size_t; -pub type off_t = c_long; - -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } else { - // Unknown target_arch - } -} - -cfg_if! { - if #[cfg(libc_core_cvoid)] { - pub use ::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - #[allow(missing_copy_implementations)] - #[allow(missing_debug_implementations)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} diff --git a/libc/src/hermit/x86_64.rs b/libc/src/hermit/x86_64.rs deleted file mode 100644 index 76ec3ce..0000000 --- a/libc/src/hermit/x86_64.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; diff --git a/libc/src/lib.rs b/libc/src/lib.rs deleted file mode 100644 index 0b1496a..0000000 --- a/libc/src/lib.rs +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -//! libc - Raw FFI bindings to platforms' system libraries -//! -//! [Documentation for other platforms][pd]. -//! -//! [pd]: https://rust-lang.github.io/libc/#platform-specific-documentation -#![crate_name = "libc"] -#![crate_type = "rlib"] -#![cfg_attr(libc_deny_warnings, deny(warnings))] -#![allow( - bad_style, - overflowing_literals, - improper_ctypes, - unknown_lints, - redundant_semicolon -)] -// Attributes needed when building as part of the standard library -#![cfg_attr( - feature = "rustc-dep-of-std", - feature(cfg_target_vendor, link_cfg, no_core) -)] -#![cfg_attr(libc_thread_local, feature(thread_local))] -// Enable extra lints: -#![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))] -#![deny(missing_copy_implementations, safe_packed_borrows)] -#![no_std] -#![cfg_attr(feature = "rustc-dep-of-std", no_core)] -#![cfg_attr(target_os = "redox", feature(static_nobundle))] -#![cfg_attr(libc_const_extern_fn, feature(const_extern_fn))] - -#[macro_use] -mod macros; - -cfg_if! { - if #[cfg(feature = "rustc-dep-of-std")] { - extern crate rustc_std_workspace_core as core; - #[allow(unused_imports)] - use core::iter; - #[allow(unused_imports)] - use core::option; - } -} - -cfg_if! { - if #[cfg(libc_priv_mod_use)] { - #[cfg(libc_core_cvoid)] - #[allow(unused_imports)] - use core::ffi; - #[allow(unused_imports)] - use core::fmt; - #[allow(unused_imports)] - use core::hash; - #[allow(unused_imports)] - use core::num; - #[allow(unused_imports)] - use core::mem; - #[doc(hidden)] - #[allow(unused_imports)] - use core::clone::Clone; - #[doc(hidden)] - #[allow(unused_imports)] - use core::marker::Copy; - #[doc(hidden)] - #[allow(unused_imports)] - use core::option::Option; - } else { - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::fmt; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::hash; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::num; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::mem; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::clone::Clone; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::marker::Copy; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::option::Option; - } -} - -cfg_if! { - if #[cfg(windows)] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod windows; - pub use windows::*; - } else if #[cfg(target_os = "cloudabi")] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod cloudabi; - pub use cloudabi::*; - } else if #[cfg(target_os = "fuchsia")] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod fuchsia; - pub use fuchsia::*; - } else if #[cfg(target_os = "switch")] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod switch; - pub use switch::*; - } else if #[cfg(target_os = "vxworks")] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod vxworks; - pub use vxworks::*; - } else if #[cfg(unix)] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod unix; - pub use unix::*; - } else if #[cfg(target_os = "hermit")] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod hermit; - pub use hermit::*; - } else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod sgx; - pub use sgx::*; - } else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] { - mod fixed_width_ints; - pub use fixed_width_ints::*; - - mod wasi; - pub use wasi::*; - } else { - // non-supported targets: empty... - } -} diff --git a/libc/src/macros.rs b/libc/src/macros.rs deleted file mode 100644 index f14bbf5..0000000 --- a/libc/src/macros.rs +++ /dev/null @@ -1,275 +0,0 @@ -/// A macro for defining #[cfg] if-else statements. -/// -/// This is similar to the `if/elif` C preprocessor macro by allowing definition -/// of a cascade of `#[cfg]` cases, emitting the implementation which matches -/// first. -/// -/// This allows you to conveniently provide a long list #[cfg]'d blocks of code -/// without having to rewrite each clause multiple times. -#[allow(unused_macros)] -macro_rules! cfg_if { - // match if/else chains with a final `else` - ($( - if #[cfg($($meta:meta),*)] { $($it:item)* } - ) else * else { - $($it2:item)* - }) => { - cfg_if! { - @__items - () ; - $( ( ($($meta),*) ($($it)*) ), )* - ( () ($($it2)*) ), - } - }; - - // match if/else chains lacking a final `else` - ( - if #[cfg($($i_met:meta),*)] { $($i_it:item)* } - $( - else if #[cfg($($e_met:meta),*)] { $($e_it:item)* } - )* - ) => { - cfg_if! { - @__items - () ; - ( ($($i_met),*) ($($i_it)*) ), - $( ( ($($e_met),*) ($($e_it)*) ), )* - ( () () ), - } - }; - - // Internal and recursive macro to emit all the items - // - // Collects all the negated cfgs in a list at the beginning and after the - // semicolon is all the remaining items - (@__items ($($not:meta,)*) ; ) => {}; - (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), - $($rest:tt)*) => { - // Emit all items within one block, applying an approprate #[cfg]. The - // #[cfg] will require all `$m` matchers specified and must also negate - // all previous matchers. - cfg_if! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* } - - // Recurse to emit all other items in `$rest`, and when we do so add all - // our `$m` matchers to the list of `$not` matchers as future emissions - // will have to negate everything we just matched as well. - cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* } - }; - - // Internal macro to Apply a cfg attribute to a list of items - (@__apply $m:meta, $($it:item)*) => { - $(#[$m] $it)* - }; -} - -#[allow(unused_macros)] -macro_rules! s { - ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($( - s!(it: $(#[$attr])* pub $t $i { $($field)* }); - )*); - (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => ( - compile_error!("unions cannot derive extra traits, use s_no_extra_traits instead"); - ); - (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( - __item! { - #[repr(C)] - #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] - #[allow(deprecated)] - $(#[$attr])* - pub struct $i { $($field)* } - } - #[allow(deprecated)] - impl ::Copy for $i {} - #[allow(deprecated)] - impl ::Clone for $i { - fn clone(&self) -> $i { *self } - } - ); -} - -#[allow(unused_macros)] -macro_rules! s_no_extra_traits { - ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($( - s_no_extra_traits!(it: $(#[$attr])* pub $t $i { $($field)* }); - )*); - (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => ( - cfg_if! { - if #[cfg(libc_union)] { - __item! { - #[repr(C)] - $(#[$attr])* - pub union $i { $($field)* } - } - - impl ::Copy for $i {} - impl ::Clone for $i { - fn clone(&self) -> $i { *self } - } - } - } - ); - (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( - __item! { - #[repr(C)] - $(#[$attr])* - pub struct $i { $($field)* } - } - impl ::Copy for $i {} - impl ::Clone for $i { - fn clone(&self) -> $i { *self } - } - ); -} - -// This is a pretty horrible hack to allow us to conditionally mark -// some functions as 'const', without requiring users of this macro -// to care about the "const-extern-fn" feature. -// -// When 'const-extern-fn' is enabled, we emit the captured 'const' keyword -// in the expanded function. -// -// When 'const-extern-fn' is disabled, we always emit a plain 'pub unsafe extern fn'. -// Note that the expression matched by the macro is exactly the same - this allows -// users of this macro to work whether or not 'const-extern-fn' is enabled -// -// Unfortunately, we need to duplicate most of this macro between the 'cfg_if' blocks. -// This is because 'const unsafe extern fn' won't even parse on older compilers, -// so we need to avoid emitting it at all of 'const-extern-fn'. -// -// Specifically, moving the 'cfg_if' into the macro body will *not* work. -// Doing so would cause the '#[cfg(feature = "const-extern-fn")]' to be emiited -// into user code. The 'cfg' gate will not stop Rust from trying to parse the -// 'pub const unsafe extern fn', so users would get a compiler error even when -// the 'const-extern-fn' feature is disabled -// -// Note that users of this macro need to place 'const' in a weird position -// (after the closing ')' for the arguments, but before the return type). -// This was the only way I could satisfy the following two requirements: -// 1. Avoid ambuguity errors from 'macro_rules!' (which happen when writing '$foo:ident fn' -// 2. Allow users of this macro to mix 'pub fn foo' and 'pub const fn bar' within the same -// 'f!' block -cfg_if! { - if #[cfg(libc_const_extern_fn)] { - #[allow(unused_macros)] - macro_rules! f { - ($(pub $({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( - #[inline] - pub $($constness)* unsafe extern fn $i($($arg: $argty),* - ) -> $ret { - $($body);* - } - )*) - } - - #[allow(unused_macros)] - macro_rules! const_fn { - ($($({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( - #[inline] - $($constness)* fn $i($($arg: $argty),* - ) -> $ret { - $($body);* - } - )*) - } - - } else { - #[allow(unused_macros)] - macro_rules! f { - ($(pub $({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( - #[inline] - pub unsafe extern fn $i($($arg: $argty),* - ) -> $ret { - $($body);* - } - )*) - } - - #[allow(unused_macros)] - macro_rules! const_fn { - ($($({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( - #[inline] - fn $i($($arg: $argty),* - ) -> $ret { - $($body);* - } - )*) - } - } -} - -#[allow(unused_macros)] -macro_rules! __item { - ($i:item) => { - $i - }; -} - -#[allow(unused_macros)] -macro_rules! align_const { - ($($(#[$attr:meta])* - pub const $name:ident : $t1:ty - = $t2:ident { $($field:tt)* };)*) => ($( - #[cfg(libc_align)] - $(#[$attr])* - pub const $name : $t1 = $t2 { - $($field)* - }; - #[cfg(not(libc_align))] - $(#[$attr])* - pub const $name : $t1 = $t2 { - $($field)* - __align: [], - }; - )*) -} - -// This macro is used to deprecate items that should be accessed via the mach crate -#[allow(unused_macros)] -macro_rules! deprecated_mach { - (pub const $id:ident: $ty:ty = $expr:expr;) => { - #[deprecated( - since = "0.2.55", - note = "Use the `mach` crate instead", - )] - #[allow(deprecated)] - pub const $id: $ty = $expr; - }; - ($(pub const $id:ident: $ty:ty = $expr:expr;)*) => { - $( - deprecated_mach!( - pub const $id: $ty = $expr; - ); - )* - }; - (pub type $id:ident = $ty:ty;) => { - #[deprecated( - since = "0.2.55", - note = "Use the `mach` crate instead", - )] - #[allow(deprecated)] - pub type $id = $ty; - }; - ($(pub type $id:ident = $ty:ty;)*) => { - $( - deprecated_mach!( - pub type $id = $ty; - ); - )* - } -} diff --git a/libc/src/sgx.rs b/libc/src/sgx.rs deleted file mode 100644 index 7da6269..0000000 --- a/libc/src/sgx.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! SGX C types definition - -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type size_t = usize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type ssize_t = isize; - -pub type c_char = i8; -pub type c_long = i64; -pub type c_ulong = u64; - -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; - -cfg_if! { - if #[cfg(libc_core_cvoid)] { - pub use ::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - #[allow(missing_copy_implementations)] - #[allow(missing_debug_implementations)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} diff --git a/libc/src/switch.rs b/libc/src/switch.rs deleted file mode 100644 index 030ab20..0000000 --- a/libc/src/switch.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! Switch C type definitions - -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type size_t = usize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type ssize_t = isize; - -pub type off_t = i64; -pub type c_char = u8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type wchar_t = u32; - -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; - -cfg_if! { - if #[cfg(libc_core_cvoid)] { - pub use ::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - #[allow(missing_copy_implementations)] - #[allow(missing_debug_implementations)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} diff --git a/libc/src/unix/align.rs b/libc/src/unix/align.rs deleted file mode 100644 index 4fdba9a..0000000 --- a/libc/src/unix/align.rs +++ /dev/null @@ -1,6 +0,0 @@ -s! { - #[repr(align(4))] - pub struct in6_addr { - pub s6_addr: [u8; 16], - } -} diff --git a/libc/src/unix/bsd/apple/b32/align.rs b/libc/src/unix/bsd/apple/b32/align.rs deleted file mode 100644 index ca1fe1c..0000000 --- a/libc/src/unix/bsd/apple/b32/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 2] - } -} diff --git a/libc/src/unix/bsd/apple/b32/mod.rs b/libc/src/unix/bsd/apple/b32/mod.rs deleted file mode 100644 index 9248e3a..0000000 --- a/libc/src/unix/bsd/apple/b32/mod.rs +++ /dev/null @@ -1,115 +0,0 @@ -//! 32-bit specific Apple (ios/darwin) definitions - -pub type c_long = i32; -pub type c_ulong = u32; -pub type boolean_t = ::c_int; - -s! { - pub struct if_data { - pub ifi_type: ::c_uchar, - pub ifi_typelen: ::c_uchar, - pub ifi_physical: ::c_uchar, - pub ifi_addrlen: ::c_uchar, - pub ifi_hdrlen: ::c_uchar, - pub ifi_recvquota: ::c_uchar, - pub ifi_xmitquota: ::c_uchar, - pub ifi_unused1: ::c_uchar, - pub ifi_mtu: u32, - pub ifi_metric: u32, - pub ifi_baudrate: u32, - pub ifi_ipackets: u32, - pub ifi_ierrors: u32, - pub ifi_opackets: u32, - pub ifi_oerrors: u32, - pub ifi_collisions: u32, - pub ifi_ibytes: u32, - pub ifi_obytes: u32, - pub ifi_imcasts: u32, - pub ifi_omcasts: u32, - pub ifi_iqdrops: u32, - pub ifi_noproto: u32, - pub ifi_recvtiming: u32, - pub ifi_xmittiming: u32, - pub ifi_lastchange: ::timeval, - pub ifi_unused2: u32, - pub ifi_hwassist: u32, - pub ifi_reserved1: u32, - pub ifi_reserved2: u32, - } - - pub struct bpf_hdr { - pub bh_tstamp: ::timeval, - pub bh_caplen: u32, - pub bh_datalen: u32, - pub bh_hdrlen: ::c_ushort, - } -} - -s_no_extra_traits! { - pub struct pthread_attr_t { - __sig: c_long, - __opaque: [::c_char; 36] - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for pthread_attr_t { - fn eq(&self, other: &pthread_attr_t) -> bool { - self.__sig == other.__sig - && self.__opaque - .iter() - .zip(other.__opaque.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_attr_t {} - impl ::fmt::Debug for pthread_attr_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_attr_t") - .field("__sig", &self.__sig) - // FIXME: .field("__opaque", &self.__opaque) - .finish() - } - } - impl ::hash::Hash for pthread_attr_t { - fn hash(&self, state: &mut H) { - self.__sig.hash(state); - self.__opaque.hash(state); - } - } - } -} - -#[doc(hidden)] -#[deprecated(since = "0.2.55")] -pub const NET_RT_MAXID: ::c_int = 10; - -pub const __PTHREAD_MUTEX_SIZE__: usize = 40; -pub const __PTHREAD_COND_SIZE__: usize = 24; -pub const __PTHREAD_CONDATTR_SIZE__: usize = 4; -pub const __PTHREAD_RWLOCK_SIZE__: usize = 124; -pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 12; - -pub const TIOCTIMESTAMP: ::c_ulong = 0x40087459; -pub const TIOCDCDTIMESTAMP: ::c_ulong = 0x40087458; - -pub const BIOCSETF: ::c_ulong = 0x80084267; -pub const BIOCSRTIMEOUT: ::c_ulong = 0x8008426d; -pub const BIOCGRTIMEOUT: ::c_ulong = 0x4008426e; -pub const BIOCSETFNR: ::c_ulong = 0x8008427e; - -extern "C" { - pub fn exchangedata( - path1: *const ::c_char, - path2: *const ::c_char, - options: ::c_ulong, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/bsd/apple/b64/align.rs b/libc/src/unix/bsd/apple/b64/align.rs deleted file mode 100644 index ca1fe1c..0000000 --- a/libc/src/unix/bsd/apple/b64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 2] - } -} diff --git a/libc/src/unix/bsd/apple/b64/mod.rs b/libc/src/unix/bsd/apple/b64/mod.rs deleted file mode 100644 index 7f70083..0000000 --- a/libc/src/unix/bsd/apple/b64/mod.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! 64-bit specific Apple (ios/darwin) definitions - -pub type c_long = i64; -pub type c_ulong = u64; -pub type boolean_t = ::c_uint; - -s! { - pub struct timeval32 { - pub tv_sec: i32, - pub tv_usec: i32, - } - - pub struct if_data { - pub ifi_type: ::c_uchar, - pub ifi_typelen: ::c_uchar, - pub ifi_physical: ::c_uchar, - pub ifi_addrlen: ::c_uchar, - pub ifi_hdrlen: ::c_uchar, - pub ifi_recvquota: ::c_uchar, - pub ifi_xmitquota: ::c_uchar, - pub ifi_unused1: ::c_uchar, - pub ifi_mtu: u32, - pub ifi_metric: u32, - pub ifi_baudrate: u32, - pub ifi_ipackets: u32, - pub ifi_ierrors: u32, - pub ifi_opackets: u32, - pub ifi_oerrors: u32, - pub ifi_collisions: u32, - pub ifi_ibytes: u32, - pub ifi_obytes: u32, - pub ifi_imcasts: u32, - pub ifi_omcasts: u32, - pub ifi_iqdrops: u32, - pub ifi_noproto: u32, - pub ifi_recvtiming: u32, - pub ifi_xmittiming: u32, - pub ifi_lastchange: timeval32, - pub ifi_unused2: u32, - pub ifi_hwassist: u32, - pub ifi_reserved1: u32, - pub ifi_reserved2: u32, - } - - pub struct bpf_hdr { - pub bh_tstamp: ::timeval32, - pub bh_caplen: u32, - pub bh_datalen: u32, - pub bh_hdrlen: ::c_ushort, - } -} - -s_no_extra_traits! { - pub struct pthread_attr_t { - __sig: c_long, - __opaque: [::c_char; 56] - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for pthread_attr_t { - fn eq(&self, other: &pthread_attr_t) -> bool { - self.__sig == other.__sig - && self.__opaque - .iter() - .zip(other.__opaque.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_attr_t {} - impl ::fmt::Debug for pthread_attr_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_attr_t") - .field("__sig", &self.__sig) - // FIXME: .field("__opaque", &self.__opaque) - .finish() - } - } - impl ::hash::Hash for pthread_attr_t { - fn hash(&self, state: &mut H) { - self.__sig.hash(state); - self.__opaque.hash(state); - } - } - } -} - -#[doc(hidden)] -#[deprecated(since = "0.2.55")] -pub const NET_RT_MAXID: ::c_int = 11; - -pub const __PTHREAD_MUTEX_SIZE__: usize = 56; -pub const __PTHREAD_COND_SIZE__: usize = 40; -pub const __PTHREAD_CONDATTR_SIZE__: usize = 8; -pub const __PTHREAD_RWLOCK_SIZE__: usize = 192; -pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 16; - -pub const TIOCTIMESTAMP: ::c_ulong = 0x40107459; -pub const TIOCDCDTIMESTAMP: ::c_ulong = 0x40107458; - -pub const BIOCSETF: ::c_ulong = 0x80104267; -pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d; -pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e; -pub const BIOCSETFNR: ::c_ulong = 0x8010427e; - -extern "C" { - pub fn exchangedata( - path1: *const ::c_char, - path2: *const ::c_char, - options: ::c_uint, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/bsd/apple/mod.rs b/libc/src/unix/bsd/apple/mod.rs deleted file mode 100644 index aa3cc1c..0000000 --- a/libc/src/unix/bsd/apple/mod.rs +++ /dev/null @@ -1,3543 +0,0 @@ -//! Apple (ios/darwin)-specific definitions -//! -//! This covers *-apple-* triples currently -pub type c_char = i8; -pub type clock_t = c_ulong; -pub type time_t = c_long; -pub type suseconds_t = i32; -pub type dev_t = i32; -pub type ino_t = u64; -pub type mode_t = u16; -pub type nlink_t = u16; -pub type blksize_t = i32; -pub type rlim_t = u64; -pub type pthread_key_t = c_ulong; -pub type sigset_t = u32; -pub type clockid_t = ::c_uint; -pub type fsblkcnt_t = ::c_uint; -pub type fsfilcnt_t = ::c_uint; -pub type speed_t = ::c_ulong; -pub type tcflag_t = ::c_ulong; -pub type nl_item = ::c_int; -pub type id_t = ::c_uint; -pub type sem_t = ::c_int; -pub type idtype_t = ::c_uint; -pub type integer_t = ::c_int; -pub type cpu_type_t = integer_t; -pub type cpu_subtype_t = integer_t; - -pub type posix_spawnattr_t = *mut ::c_void; -pub type posix_spawn_file_actions_t = *mut ::c_void; -pub type key_t = ::c_int; -pub type shmatt_t = ::c_ushort; - -deprecated_mach! { - pub type vm_prot_t = ::c_int; - pub type vm_size_t = ::uintptr_t; - pub type mach_timebase_info_data_t = mach_timebase_info; -} - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} - -s! { - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct aiocb { - pub aio_fildes: ::c_int, - pub aio_offset: ::off_t, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - pub aio_reqprio: ::c_int, - pub aio_sigevent: sigevent, - pub aio_lio_opcode: ::c_int - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - __unused1: ::c_int, - pub gl_offs: ::size_t, - __unused2: ::c_int, - pub gl_pathv: *mut *mut ::c_char, - - __unused3: *mut ::c_void, - - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - __unused6: *mut ::c_void, - __unused7: *mut ::c_void, - __unused8: *mut ::c_void, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: ::socklen_t, - pub ai_canonname: *mut ::c_char, - pub ai_addr: *mut ::sockaddr, - pub ai_next: *mut addrinfo, - } - - #[deprecated( - since = "0.2.55", - note = "Use the `mach` crate instead", - )] - pub struct mach_timebase_info { - pub numer: u32, - pub denom: u32, - } - - pub struct stat { - pub st_dev: dev_t, - pub st_mode: mode_t, - pub st_nlink: nlink_t, - pub st_ino: ino_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: dev_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_birthtime: time_t, - pub st_birthtime_nsec: c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: blksize_t, - pub st_flags: u32, - pub st_gen: u32, - pub st_lspare: i32, - pub st_qspare: [i64; 2], - } - - pub struct pthread_mutexattr_t { - __sig: ::c_long, - __opaque: [u8; 8], - } - - pub struct pthread_condattr_t { - __sig: ::c_long, - __opaque: [u8; __PTHREAD_CONDATTR_SIZE__], - } - - pub struct pthread_rwlockattr_t { - __sig: ::c_long, - __opaque: [u8; __PTHREAD_RWLOCKATTR_SIZE__], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub si_pid: ::pid_t, - pub si_uid: ::uid_t, - pub si_status: ::c_int, - pub si_addr: *mut ::c_void, - //Requires it to be union for tests - //pub si_value: ::sigval, - _pad: [usize; 9], - } - - pub struct sigaction { - // FIXME: this field is actually a union - pub sa_sigaction: ::sighandler_t, - pub sa_mask: sigset_t, - pub sa_flags: ::c_int, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct fstore_t { - pub fst_flags: ::c_uint, - pub fst_posmode: ::c_int, - pub fst_offset: ::off_t, - pub fst_length: ::off_t, - pub fst_bytesalloc: ::off_t, - } - - pub struct radvisory { - pub ra_offset: ::off_t, - pub ra_count: ::c_int, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [::c_char; 8], - } - - pub struct kevent64_s { - pub ident: u64, - pub filter: i16, - pub flags: u16, - pub fflags: u32, - pub data: i64, - pub udata: u64, - pub ext: [u64; 2], - } - - pub struct dqblk { - pub dqb_bhardlimit: u64, - pub dqb_bsoftlimit: u64, - pub dqb_curbytes: u64, - pub dqb_ihardlimit: u32, - pub dqb_isoftlimit: u32, - pub dqb_curinodes: u32, - pub dqb_btime: u32, - pub dqb_itime: u32, - pub dqb_id: u32, - pub dqb_spare: [u32; 4], - } - - pub struct if_msghdr { - pub ifm_msglen: ::c_ushort, - pub ifm_version: ::c_uchar, - pub ifm_type: ::c_uchar, - pub ifm_addrs: ::c_int, - pub ifm_flags: ::c_int, - pub ifm_index: ::c_ushort, - pub ifm_data: if_data, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_cc: [::cc_t; ::NCCS], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct flock { - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - pub l_type: ::c_short, - pub l_whence: ::c_short, - } - - pub struct sf_hdtr { - pub headers: *mut ::iovec, - pub hdr_cnt: ::c_int, - pub trailers: *mut ::iovec, - pub trl_cnt: ::c_int, - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct proc_taskinfo { - pub pti_virtual_size: u64, - pub pti_resident_size: u64, - pub pti_total_user: u64, - pub pti_total_system: u64, - pub pti_threads_user: u64, - pub pti_threads_system: u64, - pub pti_policy: i32, - pub pti_faults: i32, - pub pti_pageins: i32, - pub pti_cow_faults: i32, - pub pti_messages_sent: i32, - pub pti_messages_received: i32, - pub pti_syscalls_mach: i32, - pub pti_syscalls_unix: i32, - pub pti_csw: i32, - pub pti_threadnum: i32, - pub pti_numrunning: i32, - pub pti_priority: i32, - } - - pub struct proc_bsdinfo { - pub pbi_flags: u32, - pub pbi_status: u32, - pub pbi_xstatus: u32, - pub pbi_pid: u32, - pub pbi_ppid: u32, - pub pbi_uid: ::uid_t, - pub pbi_gid: ::gid_t, - pub pbi_ruid: ::uid_t, - pub pbi_rgid: ::gid_t, - pub pbi_svuid: ::uid_t, - pub pbi_svgid: ::gid_t, - pub rfu_1: u32, - pub pbi_comm: [::c_char; MAXCOMLEN], - pub pbi_name: [::c_char; 32], // MAXCOMLEN * 2, but macro isn't happy... - pub pbi_nfiles: u32, - pub pbi_pgid: u32, - pub pbi_pjobc: u32, - pub e_tdev: u32, - pub e_tpgid: u32, - pub pbi_nice: i32, - pub pbi_start_tvsec: u64, - pub pbi_start_tvusec: u64, - } - - pub struct proc_taskallinfo { - pub pbsd: proc_bsdinfo, - pub ptinfo: proc_taskinfo, - } - - pub struct xsw_usage { - pub xsu_total: u64, - pub xsu_avail: u64, - pub xsu_used: u64, - pub xsu_pagesize: u32, - pub xsu_encrypted: ::boolean_t, - } - - pub struct xucred { - pub cr_version: ::c_uint, - pub cr_uid: ::uid_t, - pub cr_ngroups: ::c_short, - pub cr_groups: [::gid_t;16] - } - - #[deprecated( - since = "0.2.55", - note = "Use the `mach` crate instead", - )] - pub struct mach_header { - pub magic: u32, - pub cputype: cpu_type_t, - pub cpusubtype: cpu_subtype_t, - pub filetype: u32, - pub ncmds: u32, - pub sizeofcmds: u32, - pub flags: u32, - } - - #[deprecated( - since = "0.2.55", - note = "Use the `mach` crate instead", - )] - pub struct mach_header_64 { - pub magic: u32, - pub cputype: cpu_type_t, - pub cpusubtype: cpu_subtype_t, - pub filetype: u32, - pub ncmds: u32, - pub sizeofcmds: u32, - pub flags: u32, - pub reserved: u32, - } - - pub struct segment_command { - pub cmd: u32, - pub cmdsize: u32, - pub segname: [::c_char; 16], - pub vmaddr: u32, - pub vmsize: u32, - pub fileoff: u32, - pub filesize: u32, - pub maxprot: vm_prot_t, - pub initprot: vm_prot_t, - pub nsects: u32, - pub flags: u32, - } - - pub struct segment_command_64 { - pub cmd: u32, - pub cmdsize: u32, - pub segname: [::c_char; 16], - pub vmaddr: u64, - pub vmsize: u64, - pub fileoff: u64, - pub filesize: u64, - pub maxprot: vm_prot_t, - pub initprot: vm_prot_t, - pub nsects: u32, - pub flags: u32, - } - - pub struct load_command { - pub cmd: u32, - pub cmdsize: u32, - } - - pub struct sockaddr_dl { - pub sdl_len: ::c_uchar, - pub sdl_family: ::c_uchar, - pub sdl_index: ::c_ushort, - pub sdl_type: ::c_uchar, - pub sdl_nlen: ::c_uchar, - pub sdl_alen: ::c_uchar, - pub sdl_slen: ::c_uchar, - pub sdl_data: [::c_char; 12], - } - - pub struct sockaddr_inarp { - pub sin_len: ::c_uchar, - pub sin_family: ::c_uchar, - pub sin_port: ::c_ushort, - pub sin_addr: ::in_addr, - pub sin_srcaddr: ::in_addr, - pub sin_tos: ::c_ushort, - pub sin_other: ::c_ushort, - } - - pub struct sockaddr_ctl { - pub sc_len: ::c_uchar, - pub sc_family: ::c_uchar, - pub ss_sysaddr: u16, - pub sc_id: u32, - pub sc_unit: u32, - pub sc_reserved: [u32; 5], - } - - pub struct in_pktinfo { - pub ipi_ifindex: ::c_uint, - pub ipi_spec_dst: ::in_addr, - pub ipi_addr: ::in_addr, - } - - pub struct in6_pktinfo { - pub ipi6_addr: ::in6_addr, - pub ipi6_ifindex: ::c_uint, - } - - // sys/ipc.h: - - pub struct ipc_perm { - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub _seq: ::c_ushort, - pub _key: ::key_t, - } - - // sys/sem.h - - pub struct sembuf { - pub sem_num: ::c_ushort, - pub sem_op: ::c_short, - pub sem_flg: ::c_short, - } - - // sys/shm.h - - pub struct arphdr { - pub ar_hrd: u16, - pub ar_pro: u16, - pub ar_hln: u8, - pub ar_pln: u8, - pub ar_op: u16, - } - - pub struct in_addr { - pub s_addr: ::in_addr_t, - } -} - -s_no_extra_traits! { - #[cfg_attr(libc_packedN, repr(packed(4)))] - pub struct kevent { - pub ident: ::uintptr_t, - pub filter: i16, - pub flags: u16, - pub fflags: u32, - pub data: ::intptr_t, - pub udata: *mut ::c_void, - } - - #[cfg_attr(libc_packedN, repr(packed(4)))] - pub struct semid_ds { - // Note the manpage shows different types than the system header. - pub sem_perm: ipc_perm, - pub sem_base: i32, - pub sem_nsems: ::c_ushort, - pub sem_otime: ::time_t, - pub sem_pad1: i32, - pub sem_ctime: ::time_t, - pub sem_pad2: i32, - pub sem_pad3: [i32; 4], - } - - #[cfg_attr(libc_packedN, repr(packed(4)))] - pub struct shmid_ds { - pub shm_perm: ipc_perm, - pub shm_segsz: ::size_t, - pub shm_lpid: ::pid_t, - pub shm_cpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - pub shm_atime: ::time_t, // FIXME: 64-bit wrong align => wrong offset - pub shm_dtime: ::time_t, // FIXME: 64-bit wrong align => wrong offset - pub shm_ctime: ::time_t, // FIXME: 64-bit wrong align => wrong offset - // FIXME: 64-bit wrong align => wrong offset: - pub shm_internal: *mut ::c_void, - } - - pub struct proc_threadinfo { - pub pth_user_time: u64, - pub pth_system_time: u64, - pub pth_cpu_usage: i32, - pub pth_policy: i32, - pub pth_run_state: i32, - pub pth_flags: i32, - pub pth_sleep_time: i32, - pub pth_curpri: i32, - pub pth_priority: i32, - pub pth_maxpriority: i32, - pub pth_name: [::c_char; MAXTHREADNAMESIZE], - } - - pub struct statfs { - pub f_bsize: u32, - pub f_iosize: i32, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_owner: ::uid_t, - pub f_type: u32, - pub f_flags: u32, - pub f_fssubtype: u32, - pub f_fstypename: [::c_char; 16], - pub f_mntonname: [::c_char; 1024], - pub f_mntfromname: [::c_char; 1024], - pub f_reserved: [u32; 8], - } - - pub struct dirent { - pub d_ino: u64, - pub d_seekoff: u64, - pub d_reclen: u16, - pub d_namlen: u16, - pub d_type: u8, - pub d_name: [::c_char; 1024], - } - - pub struct pthread_rwlock_t { - __sig: ::c_long, - __opaque: [u8; __PTHREAD_RWLOCK_SIZE__], - } - - pub struct pthread_mutex_t { - __sig: ::c_long, - __opaque: [u8; __PTHREAD_MUTEX_SIZE__], - } - - pub struct pthread_cond_t { - __sig: ::c_long, - __opaque: [u8; __PTHREAD_COND_SIZE__], - } - - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_align: i64, - __ss_pad2: [u8; 112], - } - - pub struct utmpx { - pub ut_user: [::c_char; _UTX_USERSIZE], - pub ut_id: [::c_char; _UTX_IDSIZE], - pub ut_line: [::c_char; _UTX_LINESIZE], - pub ut_pid: ::pid_t, - pub ut_type: ::c_short, - pub ut_tv: ::timeval, - pub ut_host: [::c_char; _UTX_HOSTSIZE], - ut_pad: [u32; 16], - } - - pub struct sigevent { - pub sigev_notify: ::c_int, - pub sigev_signo: ::c_int, - pub sigev_value: ::sigval, - __unused1: *mut ::c_void, //actually a function pointer - pub sigev_notify_attributes: *mut ::pthread_attr_t - } -} - -impl siginfo_t { - pub unsafe fn si_addr(&self) -> *mut ::c_void { - self.si_addr - } - - pub unsafe fn si_value(&self) -> ::sigval { - #[repr(C)] - struct siginfo_timer { - _si_signo: ::c_int, - _si_errno: ::c_int, - _si_code: ::c_int, - _si_pid: ::pid_t, - _si_uid: ::uid_t, - _si_status: ::c_int, - _si_addr: *mut ::c_void, - si_value: ::sigval, - } - - (*(self as *const siginfo_t as *const siginfo_timer)).si_value - } -} - -cfg_if! { - if #[cfg(libc_union)] { - s_no_extra_traits! { - pub union semun { - pub val: ::c_int, - pub buf: *mut semid_ds, - pub array: *mut ::c_ushort, - } - } - - cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for semun { - fn eq(&self, other: &semun) -> bool { - unsafe { self.val == other.val } - } - } - impl Eq for semun {} - impl ::fmt::Debug for semun { - fn fmt(&self, f: &mut ::fmt::Formatter) - -> ::fmt::Result { - f.debug_struct("semun") - .field("val", unsafe { &self.val }) - .finish() - } - } - impl ::hash::Hash for semun { - fn hash(&self, state: &mut H) { - unsafe { self.val.hash(state) }; - } - } - } - } - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for kevent { - fn eq(&self, other: &kevent) -> bool { - self.ident == other.ident - && self.filter == other.filter - && self.flags == other.flags - && self.fflags == other.fflags - && self.data == other.data - && self.udata == other.udata - } - } - impl Eq for kevent {} - impl ::fmt::Debug for kevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - let ident = self.ident; - let filter = self.filter; - let flags = self.flags; - let fflags = self.fflags; - let data = self.data; - let udata = self.udata; - f.debug_struct("kevent") - .field("ident", &ident) - .field("filter", &filter) - .field("flags", &flags) - .field("fflags", &fflags) - .field("data", &data) - .field("udata", &udata) - .finish() - } - } - impl ::hash::Hash for kevent { - fn hash(&self, state: &mut H) { - let ident = self.ident; - let filter = self.filter; - let flags = self.flags; - let fflags = self.fflags; - let data = self.data; - let udata = self.udata; - ident.hash(state); - filter.hash(state); - flags.hash(state); - fflags.hash(state); - data.hash(state); - udata.hash(state); - } - } - - impl PartialEq for semid_ds { - fn eq(&self, other: &semid_ds) -> bool { - let sem_perm = self.sem_perm; - let sem_pad3 = self.sem_pad3; - let other_sem_perm = other.sem_perm; - let other_sem_pad3 = other.sem_pad3; - sem_perm == other_sem_perm - && self.sem_base == other.sem_base - && self.sem_nsems == other.sem_nsems - && self.sem_otime == other.sem_otime - && self.sem_pad1 == other.sem_pad1 - && self.sem_ctime == other.sem_ctime - && self.sem_pad2 == other.sem_pad2 - && sem_pad3 == other_sem_pad3 - } - } - impl Eq for semid_ds {} - impl ::fmt::Debug for semid_ds { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - let sem_perm = self.sem_perm; - let sem_base = self.sem_base; - let sem_nsems = self.sem_nsems; - let sem_otime = self.sem_otime; - let sem_pad1 = self.sem_pad1; - let sem_ctime = self.sem_ctime; - let sem_pad2 = self.sem_pad2; - let sem_pad3 = self.sem_pad3; - f.debug_struct("semid_ds") - .field("sem_perm", &sem_perm) - .field("sem_base", &sem_base) - .field("sem_nsems", &sem_nsems) - .field("sem_otime", &sem_otime) - .field("sem_pad1", &sem_pad1) - .field("sem_ctime", &sem_ctime) - .field("sem_pad2", &sem_pad2) - .field("sem_pad3", &sem_pad3) - .finish() - } - } - impl ::hash::Hash for semid_ds { - fn hash(&self, state: &mut H) { - let sem_perm = self.sem_perm; - let sem_base = self.sem_base; - let sem_nsems = self.sem_nsems; - let sem_otime = self.sem_otime; - let sem_pad1 = self.sem_pad1; - let sem_ctime = self.sem_ctime; - let sem_pad2 = self.sem_pad2; - let sem_pad3 = self.sem_pad3; - sem_perm.hash(state); - sem_base.hash(state); - sem_nsems.hash(state); - sem_otime.hash(state); - sem_pad1.hash(state); - sem_ctime.hash(state); - sem_pad2.hash(state); - sem_pad3.hash(state); - } - } - - impl PartialEq for shmid_ds { - fn eq(&self, other: &shmid_ds) -> bool { - let shm_perm = self.shm_perm; - let other_shm_perm = other.shm_perm; - shm_perm == other_shm_perm - && self.shm_segsz == other.shm_segsz - && self.shm_lpid == other.shm_lpid - && self.shm_cpid == other.shm_cpid - && self.shm_nattch == other.shm_nattch - && self.shm_atime == other.shm_atime - && self.shm_dtime == other.shm_dtime - && self.shm_ctime == other.shm_ctime - && self.shm_internal == other.shm_internal - } - } - impl Eq for shmid_ds {} - impl ::fmt::Debug for shmid_ds { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - let shm_perm = self.shm_perm; - let shm_segsz = self.shm_segsz; - let shm_lpid = self.shm_lpid; - let shm_cpid = self.shm_cpid; - let shm_nattch = self.shm_nattch; - let shm_atime = self.shm_atime; - let shm_dtime = self.shm_dtime; - let shm_ctime = self.shm_ctime; - let shm_internal = self.shm_internal; - f.debug_struct("shmid_ds") - .field("shm_perm", &shm_perm) - .field("shm_segsz", &shm_segsz) - .field("shm_lpid", &shm_lpid) - .field("shm_cpid", &shm_cpid) - .field("shm_nattch", &shm_nattch) - .field("shm_atime", &shm_atime) - .field("shm_dtime", &shm_dtime) - .field("shm_ctime", &shm_ctime) - .field("shm_internal", &shm_internal) - .finish() - } - } - impl ::hash::Hash for shmid_ds { - fn hash(&self, state: &mut H) { - let shm_perm = self.shm_perm; - let shm_segsz = self.shm_segsz; - let shm_lpid = self.shm_lpid; - let shm_cpid = self.shm_cpid; - let shm_nattch = self.shm_nattch; - let shm_atime = self.shm_atime; - let shm_dtime = self.shm_dtime; - let shm_ctime = self.shm_ctime; - let shm_internal = self.shm_internal; - shm_perm.hash(state); - shm_segsz.hash(state); - shm_lpid.hash(state); - shm_cpid.hash(state); - shm_nattch.hash(state); - shm_atime.hash(state); - shm_dtime.hash(state); - shm_ctime.hash(state); - shm_internal.hash(state); - } - } - - impl PartialEq for proc_threadinfo { - fn eq(&self, other: &proc_threadinfo) -> bool { - self.pth_user_time == other.pth_user_time - && self.pth_system_time == other.pth_system_time - && self.pth_cpu_usage == other.pth_cpu_usage - && self.pth_policy == other.pth_policy - && self.pth_run_state == other.pth_run_state - && self.pth_flags == other.pth_flags - && self.pth_sleep_time == other.pth_sleep_time - && self.pth_curpri == other.pth_curpri - && self.pth_priority == other.pth_priority - && self.pth_maxpriority == other.pth_maxpriority - && self.pth_name - .iter() - .zip(other.pth_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for proc_threadinfo {} - impl ::fmt::Debug for proc_threadinfo { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("proc_threadinfo") - .field("pth_user_time", &self.pth_user_time) - .field("pth_system_time", &self.pth_system_time) - .field("pth_cpu_usage", &self.pth_cpu_usage) - .field("pth_policy", &self.pth_policy) - .field("pth_run_state", &self.pth_run_state) - .field("pth_flags", &self.pth_flags) - .field("pth_sleep_time", &self.pth_sleep_time) - .field("pth_curpri", &self.pth_curpri) - .field("pth_priority", &self.pth_priority) - .field("pth_maxpriority", &self.pth_maxpriority) - // FIXME: .field("pth_name", &self.pth_name) - .finish() - } - } - impl ::hash::Hash for proc_threadinfo { - fn hash(&self, state: &mut H) { - self.pth_user_time.hash(state); - self.pth_system_time.hash(state); - self.pth_cpu_usage.hash(state); - self.pth_policy.hash(state); - self.pth_run_state.hash(state); - self.pth_flags.hash(state); - self.pth_sleep_time.hash(state); - self.pth_curpri.hash(state); - self.pth_priority.hash(state); - self.pth_maxpriority.hash(state); - self.pth_name.hash(state); - } - } - - impl PartialEq for statfs { - fn eq(&self, other: &statfs) -> bool { - self.f_bsize == other.f_bsize - && self.f_iosize == other.f_iosize - && self.f_blocks == other.f_blocks - && self.f_bfree == other.f_bfree - && self.f_bavail == other.f_bavail - && self.f_files == other.f_files - && self.f_ffree == other.f_ffree - && self.f_fsid == other.f_fsid - && self.f_owner == other.f_owner - && self.f_flags == other.f_flags - && self.f_fssubtype == other.f_fssubtype - && self.f_fstypename == other.f_fstypename - && self.f_type == other.f_type - && self - .f_mntonname - .iter() - .zip(other.f_mntonname.iter()) - .all(|(a,b)| a == b) - && self - .f_mntfromname - .iter() - .zip(other.f_mntfromname.iter()) - .all(|(a,b)| a == b) - && self.f_reserved == other.f_reserved - } - } - - impl Eq for statfs {} - impl ::fmt::Debug for statfs { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("statfs") - .field("f_bsize", &self.f_bsize) - .field("f_iosize", &self.f_iosize) - .field("f_blocks", &self.f_blocks) - .field("f_bfree", &self.f_bfree) - .field("f_bavail", &self.f_bavail) - .field("f_files", &self.f_files) - .field("f_ffree", &self.f_ffree) - .field("f_fsid", &self.f_fsid) - .field("f_owner", &self.f_owner) - .field("f_flags", &self.f_flags) - .field("f_fssubtype", &self.f_fssubtype) - .field("f_fstypename", &self.f_fstypename) - .field("f_type", &self.f_type) - // FIXME: .field("f_mntonname", &self.f_mntonname) - // FIXME: .field("f_mntfromname", &self.f_mntfromname) - .field("f_reserved", &self.f_reserved) - .finish() - } - } - - impl ::hash::Hash for statfs { - fn hash(&self, state: &mut H) { - self.f_bsize.hash(state); - self.f_iosize.hash(state); - self.f_blocks.hash(state); - self.f_bfree.hash(state); - self.f_bavail.hash(state); - self.f_files.hash(state); - self.f_ffree.hash(state); - self.f_fsid.hash(state); - self.f_owner.hash(state); - self.f_flags.hash(state); - self.f_fssubtype.hash(state); - self.f_fstypename.hash(state); - self.f_type.hash(state); - self.f_mntonname.hash(state); - self.f_mntfromname.hash(state); - self.f_reserved.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_ino == other.d_ino - && self.d_seekoff == other.d_seekoff - && self.d_reclen == other.d_reclen - && self.d_namlen == other.d_namlen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_ino", &self.d_ino) - .field("d_seekoff", &self.d_seekoff) - .field("d_reclen", &self.d_reclen) - .field("d_namlen", &self.d_namlen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_seekoff.hash(state); - self.d_reclen.hash(state); - self.d_namlen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - impl PartialEq for pthread_rwlock_t { - fn eq(&self, other: &pthread_rwlock_t) -> bool { - self.__sig == other.__sig - && self. - __opaque - .iter() - .zip(other.__opaque.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_rwlock_t {} - impl ::fmt::Debug for pthread_rwlock_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_rwlock_t") - .field("__sig", &self.__sig) - // FIXME: .field("__opaque", &self.__opaque) - .finish() - } - } - impl ::hash::Hash for pthread_rwlock_t { - fn hash(&self, state: &mut H) { - self.__sig.hash(state); - self.__opaque.hash(state); - } - } - - impl PartialEq for pthread_mutex_t { - fn eq(&self, other: &pthread_mutex_t) -> bool { - self.__sig == other.__sig - && self. - __opaque - .iter() - .zip(other.__opaque.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for pthread_mutex_t {} - - impl ::fmt::Debug for pthread_mutex_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_mutex_t") - .field("__sig", &self.__sig) - // FIXME: .field("__opaque", &self.__opaque) - .finish() - } - } - - impl ::hash::Hash for pthread_mutex_t { - fn hash(&self, state: &mut H) { - self.__sig.hash(state); - self.__opaque.hash(state); - } - } - - impl PartialEq for pthread_cond_t { - fn eq(&self, other: &pthread_cond_t) -> bool { - self.__sig == other.__sig - && self. - __opaque - .iter() - .zip(other.__opaque.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for pthread_cond_t {} - - impl ::fmt::Debug for pthread_cond_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_cond_t") - .field("__sig", &self.__sig) - // FIXME: .field("__opaque", &self.__opaque) - .finish() - } - } - - impl ::hash::Hash for pthread_cond_t { - fn hash(&self, state: &mut H) { - self.__sig.hash(state); - self.__opaque.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_len == other.ss_len - && self.ss_family == other.ss_family - && self - .__ss_pad1 - .iter() - .zip(other.__ss_pad1.iter()) - .all(|(a, b)| a == b) - && self.__ss_align == other.__ss_align - && self - .__ss_pad2 - .iter() - .zip(other.__ss_pad2.iter()) - .all(|(a, b)| a == b) - } - } - - impl Eq for sockaddr_storage {} - - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_len", &self.ss_len) - .field("ss_family", &self.ss_family) - .field("__ss_pad1", &self.__ss_pad1) - .field("__ss_align", &self.__ss_align) - // FIXME: .field("__ss_pad2", &self.__ss_pad2) - .finish() - } - } - - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_len.hash(state); - self.ss_family.hash(state); - self.__ss_pad1.hash(state); - self.__ss_align.hash(state); - self.__ss_pad2.hash(state); - } - } - - impl PartialEq for utmpx { - fn eq(&self, other: &utmpx) -> bool { - self.ut_user - .iter() - .zip(other.ut_user.iter()) - .all(|(a,b)| a == b) - && self.ut_id == other.ut_id - && self.ut_line == other.ut_line - && self.ut_pid == other.ut_pid - && self.ut_type == other.ut_type - && self.ut_tv == other.ut_tv - && self - .ut_host - .iter() - .zip(other.ut_host.iter()) - .all(|(a,b)| a == b) - && self.ut_pad == other.ut_pad - } - } - - impl Eq for utmpx {} - - impl ::fmt::Debug for utmpx { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utmpx") - // FIXME: .field("ut_user", &self.ut_user) - .field("ut_id", &self.ut_id) - .field("ut_line", &self.ut_line) - .field("ut_pid", &self.ut_pid) - .field("ut_type", &self.ut_type) - .field("ut_tv", &self.ut_tv) - // FIXME: .field("ut_host", &self.ut_host) - .field("ut_pad", &self.ut_pad) - .finish() - } - } - - impl ::hash::Hash for utmpx { - fn hash(&self, state: &mut H) { - self.ut_user.hash(state); - self.ut_id.hash(state); - self.ut_line.hash(state); - self.ut_pid.hash(state); - self.ut_type.hash(state); - self.ut_tv.hash(state); - self.ut_host.hash(state); - self.ut_pad.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_notify == other.sigev_notify - && self.sigev_signo == other.sigev_signo - && self.sigev_value == other.sigev_value - && self.sigev_notify_attributes - == other.sigev_notify_attributes - } - } - - impl Eq for sigevent {} - - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_notify", &self.sigev_notify) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_value", &self.sigev_value) - .field("sigev_notify_attributes", - &self.sigev_notify_attributes) - .finish() - } - } - - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_notify.hash(state); - self.sigev_signo.hash(state); - self.sigev_value.hash(state); - self.sigev_notify_attributes.hash(state); - } - } - } -} - -pub const _UTX_USERSIZE: usize = 256; -pub const _UTX_LINESIZE: usize = 32; -pub const _UTX_IDSIZE: usize = 4; -pub const _UTX_HOSTSIZE: usize = 256; - -pub const EMPTY: ::c_short = 0; -pub const RUN_LVL: ::c_short = 1; -pub const BOOT_TIME: ::c_short = 2; -pub const OLD_TIME: ::c_short = 3; -pub const NEW_TIME: ::c_short = 4; -pub const INIT_PROCESS: ::c_short = 5; -pub const LOGIN_PROCESS: ::c_short = 6; -pub const USER_PROCESS: ::c_short = 7; -pub const DEAD_PROCESS: ::c_short = 8; -pub const ACCOUNTING: ::c_short = 9; -pub const SIGNATURE: ::c_short = 10; -pub const SHUTDOWN_TIME: ::c_short = 11; - -pub const LC_COLLATE_MASK: ::c_int = (1 << 0); -pub const LC_CTYPE_MASK: ::c_int = (1 << 1); -pub const LC_MESSAGES_MASK: ::c_int = (1 << 2); -pub const LC_MONETARY_MASK: ::c_int = (1 << 3); -pub const LC_NUMERIC_MASK: ::c_int = (1 << 4); -pub const LC_TIME_MASK: ::c_int = (1 << 5); -pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK - | LC_CTYPE_MASK - | LC_MESSAGES_MASK - | LC_MONETARY_MASK - | LC_NUMERIC_MASK - | LC_TIME_MASK; - -pub const CODESET: ::nl_item = 0; -pub const D_T_FMT: ::nl_item = 1; -pub const D_FMT: ::nl_item = 2; -pub const T_FMT: ::nl_item = 3; -pub const T_FMT_AMPM: ::nl_item = 4; -pub const AM_STR: ::nl_item = 5; -pub const PM_STR: ::nl_item = 6; - -pub const DAY_1: ::nl_item = 7; -pub const DAY_2: ::nl_item = 8; -pub const DAY_3: ::nl_item = 9; -pub const DAY_4: ::nl_item = 10; -pub const DAY_5: ::nl_item = 11; -pub const DAY_6: ::nl_item = 12; -pub const DAY_7: ::nl_item = 13; - -pub const ABDAY_1: ::nl_item = 14; -pub const ABDAY_2: ::nl_item = 15; -pub const ABDAY_3: ::nl_item = 16; -pub const ABDAY_4: ::nl_item = 17; -pub const ABDAY_5: ::nl_item = 18; -pub const ABDAY_6: ::nl_item = 19; -pub const ABDAY_7: ::nl_item = 20; - -pub const MON_1: ::nl_item = 21; -pub const MON_2: ::nl_item = 22; -pub const MON_3: ::nl_item = 23; -pub const MON_4: ::nl_item = 24; -pub const MON_5: ::nl_item = 25; -pub const MON_6: ::nl_item = 26; -pub const MON_7: ::nl_item = 27; -pub const MON_8: ::nl_item = 28; -pub const MON_9: ::nl_item = 29; -pub const MON_10: ::nl_item = 30; -pub const MON_11: ::nl_item = 31; -pub const MON_12: ::nl_item = 32; - -pub const ABMON_1: ::nl_item = 33; -pub const ABMON_2: ::nl_item = 34; -pub const ABMON_3: ::nl_item = 35; -pub const ABMON_4: ::nl_item = 36; -pub const ABMON_5: ::nl_item = 37; -pub const ABMON_6: ::nl_item = 38; -pub const ABMON_7: ::nl_item = 39; -pub const ABMON_8: ::nl_item = 40; -pub const ABMON_9: ::nl_item = 41; -pub const ABMON_10: ::nl_item = 42; -pub const ABMON_11: ::nl_item = 43; -pub const ABMON_12: ::nl_item = 44; - -pub const CLOCK_REALTIME: ::clockid_t = 0; -pub const CLOCK_MONOTONIC: ::clockid_t = 6; -pub const CLOCK_PROCESS_CPUTIME_ID: ::clockid_t = 12; -pub const CLOCK_THREAD_CPUTIME_ID: ::clockid_t = 16; - -pub const ERA: ::nl_item = 45; -pub const ERA_D_FMT: ::nl_item = 46; -pub const ERA_D_T_FMT: ::nl_item = 47; -pub const ERA_T_FMT: ::nl_item = 48; -pub const ALT_DIGITS: ::nl_item = 49; - -pub const RADIXCHAR: ::nl_item = 50; -pub const THOUSEP: ::nl_item = 51; - -pub const YESEXPR: ::nl_item = 52; -pub const NOEXPR: ::nl_item = 53; - -pub const YESSTR: ::nl_item = 54; -pub const NOSTR: ::nl_item = 55; - -pub const CRNCYSTR: ::nl_item = 56; - -pub const D_MD_ORDER: ::nl_item = 57; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const RAND_MAX: ::c_int = 2147483647; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 2; -pub const _IOLBF: ::c_int = 1; -pub const BUFSIZ: ::c_uint = 1024; -pub const FOPEN_MAX: ::c_uint = 20; -pub const FILENAME_MAX: ::c_uint = 1024; -pub const L_tmpnam: ::c_uint = 1024; -pub const TMP_MAX: ::c_uint = 308915776; -pub const _PC_LINK_MAX: ::c_int = 1; -pub const _PC_MAX_CANON: ::c_int = 2; -pub const _PC_MAX_INPUT: ::c_int = 3; -pub const _PC_NAME_MAX: ::c_int = 4; -pub const _PC_PATH_MAX: ::c_int = 5; -pub const _PC_PIPE_BUF: ::c_int = 6; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 7; -pub const _PC_NO_TRUNC: ::c_int = 8; -pub const _PC_VDISABLE: ::c_int = 9; -pub const O_DSYNC: ::c_int = 0x400000; -pub const O_NOCTTY: ::c_int = 0x20000; -pub const O_CLOEXEC: ::c_int = 0x1000000; -pub const O_DIRECTORY: ::c_int = 0x100000; -pub const S_IFIFO: mode_t = 4096; -pub const S_IFCHR: mode_t = 8192; -pub const S_IFBLK: mode_t = 24576; -pub const S_IFDIR: mode_t = 16384; -pub const S_IFREG: mode_t = 32768; -pub const S_IFLNK: mode_t = 40960; -pub const S_IFSOCK: mode_t = 49152; -pub const S_IFMT: mode_t = 61440; -pub const S_IEXEC: mode_t = 64; -pub const S_IWRITE: mode_t = 128; -pub const S_IREAD: mode_t = 256; -pub const S_IRWXU: mode_t = 448; -pub const S_IXUSR: mode_t = 64; -pub const S_IWUSR: mode_t = 128; -pub const S_IRUSR: mode_t = 256; -pub const S_IRWXG: mode_t = 56; -pub const S_IXGRP: mode_t = 8; -pub const S_IWGRP: mode_t = 16; -pub const S_IRGRP: mode_t = 32; -pub const S_IRWXO: mode_t = 7; -pub const S_IXOTH: mode_t = 1; -pub const S_IWOTH: mode_t = 2; -pub const S_IROTH: mode_t = 4; -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; -pub const F_GETLK: ::c_int = 7; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGABRT: ::c_int = 6; -pub const SIGEMT: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSEGV: ::c_int = 11; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_READ: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_EXEC: ::c_int = 4; - -pub const PT_TRACE_ME: ::c_int = 0; -pub const PT_READ_I: ::c_int = 1; -pub const PT_READ_D: ::c_int = 2; -pub const PT_READ_U: ::c_int = 3; -pub const PT_WRITE_I: ::c_int = 4; -pub const PT_WRITE_D: ::c_int = 5; -pub const PT_WRITE_U: ::c_int = 6; -pub const PT_CONTINUE: ::c_int = 7; -pub const PT_KILL: ::c_int = 8; -pub const PT_STEP: ::c_int = 9; -pub const PT_ATTACH: ::c_int = 10; -pub const PT_DETACH: ::c_int = 11; -pub const PT_SIGEXC: ::c_int = 12; -pub const PT_THUPDATE: ::c_int = 13; -pub const PT_ATTACHEXC: ::c_int = 14; - -pub const PT_FORCEQUOTA: ::c_int = 30; -pub const PT_DENY_ATTACH: ::c_int = 31; -pub const PT_FIRSTMACH: ::c_int = 32; - -pub const MAP_FILE: ::c_int = 0x0000; -pub const MAP_SHARED: ::c_int = 0x0001; -pub const MAP_PRIVATE: ::c_int = 0x0002; -pub const MAP_FIXED: ::c_int = 0x0010; -pub const MAP_ANON: ::c_int = 0x1000; -pub const MAP_ANONYMOUS: ::c_int = MAP_ANON; - -deprecated_mach! { - pub const VM_FLAGS_FIXED: ::c_int = 0x0000; - pub const VM_FLAGS_ANYWHERE: ::c_int = 0x0001; - pub const VM_FLAGS_PURGABLE: ::c_int = 0x0002; - pub const VM_FLAGS_RANDOM_ADDR: ::c_int = 0x0008; - pub const VM_FLAGS_NO_CACHE: ::c_int = 0x0010; - pub const VM_FLAGS_RESILIENT_CODESIGN: ::c_int = 0x0020; - pub const VM_FLAGS_RESILIENT_MEDIA: ::c_int = 0x0040; - pub const VM_FLAGS_OVERWRITE: ::c_int = 0x4000; - pub const VM_FLAGS_SUPERPAGE_MASK: ::c_int = 0x70000; - pub const VM_FLAGS_RETURN_DATA_ADDR: ::c_int = 0x100000; - pub const VM_FLAGS_RETURN_4K_DATA_ADDR: ::c_int = 0x800000; - pub const VM_FLAGS_ALIAS_MASK: ::c_int = 0xFF000000; - pub const VM_FLAGS_USER_ALLOCATE: ::c_int = 0xff07401f; - pub const VM_FLAGS_USER_MAP: ::c_int = 0xff97401f; - pub const VM_FLAGS_USER_REMAP: ::c_int = VM_FLAGS_FIXED | - VM_FLAGS_ANYWHERE | - VM_FLAGS_RANDOM_ADDR | - VM_FLAGS_OVERWRITE | - VM_FLAGS_RETURN_DATA_ADDR | - VM_FLAGS_RESILIENT_CODESIGN; - - pub const VM_FLAGS_SUPERPAGE_SHIFT: ::c_int = 16; - pub const SUPERPAGE_NONE: ::c_int = 0; - pub const SUPERPAGE_SIZE_ANY: ::c_int = 1; - pub const VM_FLAGS_SUPERPAGE_NONE: ::c_int = SUPERPAGE_NONE << - VM_FLAGS_SUPERPAGE_SHIFT; - pub const VM_FLAGS_SUPERPAGE_SIZE_ANY: ::c_int = SUPERPAGE_SIZE_ANY << - VM_FLAGS_SUPERPAGE_SHIFT; - pub const SUPERPAGE_SIZE_2MB: ::c_int = 2; - pub const VM_FLAGS_SUPERPAGE_SIZE_2MB: ::c_int = SUPERPAGE_SIZE_2MB << - VM_FLAGS_SUPERPAGE_SHIFT; - - pub const VM_MEMORY_MALLOC: ::c_int = 1; - pub const VM_MEMORY_MALLOC_SMALL: ::c_int = 2; - pub const VM_MEMORY_MALLOC_LARGE: ::c_int = 3; - pub const VM_MEMORY_MALLOC_HUGE: ::c_int = 4; - pub const VM_MEMORY_SBRK: ::c_int = 5; - pub const VM_MEMORY_REALLOC: ::c_int = 6; - pub const VM_MEMORY_MALLOC_TINY: ::c_int = 7; - pub const VM_MEMORY_MALLOC_LARGE_REUSABLE: ::c_int = 8; - pub const VM_MEMORY_MALLOC_LARGE_REUSED: ::c_int = 9; - pub const VM_MEMORY_ANALYSIS_TOOL: ::c_int = 10; - pub const VM_MEMORY_MALLOC_NANO: ::c_int = 11; - pub const VM_MEMORY_MACH_MSG: ::c_int = 20; - pub const VM_MEMORY_IOKIT: ::c_int = 21; - pub const VM_MEMORY_STACK: ::c_int = 30; - pub const VM_MEMORY_GUARD: ::c_int = 31; - pub const VM_MEMORY_SHARED_PMAP: ::c_int = 32; - pub const VM_MEMORY_DYLIB: ::c_int = 33; - pub const VM_MEMORY_OBJC_DISPATCHERS: ::c_int = 34; - pub const VM_MEMORY_UNSHARED_PMAP: ::c_int = 35; - pub const VM_MEMORY_APPKIT: ::c_int = 40; - pub const VM_MEMORY_FOUNDATION: ::c_int = 41; - pub const VM_MEMORY_COREGRAPHICS: ::c_int = 42; - pub const VM_MEMORY_CORESERVICES: ::c_int = 43; - pub const VM_MEMORY_CARBON: ::c_int = VM_MEMORY_CORESERVICES; - pub const VM_MEMORY_JAVA: ::c_int = 44; - pub const VM_MEMORY_COREDATA: ::c_int = 45; - pub const VM_MEMORY_COREDATA_OBJECTIDS: ::c_int = 46; - pub const VM_MEMORY_ATS: ::c_int = 50; - pub const VM_MEMORY_LAYERKIT: ::c_int = 51; - pub const VM_MEMORY_CGIMAGE: ::c_int = 52; - pub const VM_MEMORY_TCMALLOC: ::c_int = 53; - pub const VM_MEMORY_COREGRAPHICS_DATA: ::c_int = 54; - pub const VM_MEMORY_COREGRAPHICS_SHARED: ::c_int = 55; - pub const VM_MEMORY_COREGRAPHICS_FRAMEBUFFERS: ::c_int = 56; - pub const VM_MEMORY_COREGRAPHICS_BACKINGSTORES: ::c_int = 57; - pub const VM_MEMORY_COREGRAPHICS_XALLOC: ::c_int = 58; - pub const VM_MEMORY_COREGRAPHICS_MISC: ::c_int = VM_MEMORY_COREGRAPHICS; - pub const VM_MEMORY_DYLD: ::c_int = 60; - pub const VM_MEMORY_DYLD_MALLOC: ::c_int = 61; - pub const VM_MEMORY_SQLITE: ::c_int = 62; - pub const VM_MEMORY_JAVASCRIPT_CORE: ::c_int = 63; - pub const VM_MEMORY_JAVASCRIPT_JIT_EXECUTABLE_ALLOCATOR: ::c_int = 64; - pub const VM_MEMORY_JAVASCRIPT_JIT_REGISTER_FILE: ::c_int = 65; - pub const VM_MEMORY_GLSL: ::c_int = 66; - pub const VM_MEMORY_OPENCL: ::c_int = 67; - pub const VM_MEMORY_COREIMAGE: ::c_int = 68; - pub const VM_MEMORY_WEBCORE_PURGEABLE_BUFFERS: ::c_int = 69; - pub const VM_MEMORY_IMAGEIO: ::c_int = 70; - pub const VM_MEMORY_COREPROFILE: ::c_int = 71; - pub const VM_MEMORY_ASSETSD: ::c_int = 72; - pub const VM_MEMORY_OS_ALLOC_ONCE: ::c_int = 73; - pub const VM_MEMORY_LIBDISPATCH: ::c_int = 74; - pub const VM_MEMORY_ACCELERATE: ::c_int = 75; - pub const VM_MEMORY_COREUI: ::c_int = 76; - pub const VM_MEMORY_COREUIFILE: ::c_int = 77; - pub const VM_MEMORY_GENEALOGY: ::c_int = 78; - pub const VM_MEMORY_RAWCAMERA: ::c_int = 79; - pub const VM_MEMORY_CORPSEINFO: ::c_int = 80; - pub const VM_MEMORY_ASL: ::c_int = 81; - pub const VM_MEMORY_SWIFT_RUNTIME: ::c_int = 82; - pub const VM_MEMORY_SWIFT_METADATA: ::c_int = 83; - pub const VM_MEMORY_DHMM: ::c_int = 84; - pub const VM_MEMORY_SCENEKIT: ::c_int = 86; - pub const VM_MEMORY_SKYWALK: ::c_int = 87; - pub const VM_MEMORY_APPLICATION_SPECIFIC_1: ::c_int = 240; - pub const VM_MEMORY_APPLICATION_SPECIFIC_16: ::c_int = 255; -} - -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const MS_ASYNC: ::c_int = 0x0001; -pub const MS_INVALIDATE: ::c_int = 0x0002; -pub const MS_SYNC: ::c_int = 0x0010; - -pub const MS_KILLPAGES: ::c_int = 0x0004; -pub const MS_DEACTIVATE: ::c_int = 0x0008; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EDEADLK: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const ENOTBLK: ::c_int = 15; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const EAGAIN: ::c_int = 35; -pub const EWOULDBLOCK: ::c_int = EAGAIN; -pub const EINPROGRESS: ::c_int = 36; -pub const EALREADY: ::c_int = 37; -pub const ENOTSOCK: ::c_int = 38; -pub const EDESTADDRREQ: ::c_int = 39; -pub const EMSGSIZE: ::c_int = 40; -pub const EPROTOTYPE: ::c_int = 41; -pub const ENOPROTOOPT: ::c_int = 42; -pub const EPROTONOSUPPORT: ::c_int = 43; -pub const ESOCKTNOSUPPORT: ::c_int = 44; -pub const ENOTSUP: ::c_int = 45; -pub const EPFNOSUPPORT: ::c_int = 46; -pub const EAFNOSUPPORT: ::c_int = 47; -pub const EADDRINUSE: ::c_int = 48; -pub const EADDRNOTAVAIL: ::c_int = 49; -pub const ENETDOWN: ::c_int = 50; -pub const ENETUNREACH: ::c_int = 51; -pub const ENETRESET: ::c_int = 52; -pub const ECONNABORTED: ::c_int = 53; -pub const ECONNRESET: ::c_int = 54; -pub const ENOBUFS: ::c_int = 55; -pub const EISCONN: ::c_int = 56; -pub const ENOTCONN: ::c_int = 57; -pub const ESHUTDOWN: ::c_int = 58; -pub const ETOOMANYREFS: ::c_int = 59; -pub const ETIMEDOUT: ::c_int = 60; -pub const ECONNREFUSED: ::c_int = 61; -pub const ELOOP: ::c_int = 62; -pub const ENAMETOOLONG: ::c_int = 63; -pub const EHOSTDOWN: ::c_int = 64; -pub const EHOSTUNREACH: ::c_int = 65; -pub const ENOTEMPTY: ::c_int = 66; -pub const EPROCLIM: ::c_int = 67; -pub const EUSERS: ::c_int = 68; -pub const EDQUOT: ::c_int = 69; -pub const ESTALE: ::c_int = 70; -pub const EREMOTE: ::c_int = 71; -pub const EBADRPC: ::c_int = 72; -pub const ERPCMISMATCH: ::c_int = 73; -pub const EPROGUNAVAIL: ::c_int = 74; -pub const EPROGMISMATCH: ::c_int = 75; -pub const EPROCUNAVAIL: ::c_int = 76; -pub const ENOLCK: ::c_int = 77; -pub const ENOSYS: ::c_int = 78; -pub const EFTYPE: ::c_int = 79; -pub const EAUTH: ::c_int = 80; -pub const ENEEDAUTH: ::c_int = 81; -pub const EPWROFF: ::c_int = 82; -pub const EDEVERR: ::c_int = 83; -pub const EOVERFLOW: ::c_int = 84; -pub const EBADEXEC: ::c_int = 85; -pub const EBADARCH: ::c_int = 86; -pub const ESHLIBVERS: ::c_int = 87; -pub const EBADMACHO: ::c_int = 88; -pub const ECANCELED: ::c_int = 89; -pub const EIDRM: ::c_int = 90; -pub const ENOMSG: ::c_int = 91; -pub const EILSEQ: ::c_int = 92; -pub const ENOATTR: ::c_int = 93; -pub const EBADMSG: ::c_int = 94; -pub const EMULTIHOP: ::c_int = 95; -pub const ENODATA: ::c_int = 96; -pub const ENOLINK: ::c_int = 97; -pub const ENOSR: ::c_int = 98; -pub const ENOSTR: ::c_int = 99; -pub const EPROTO: ::c_int = 100; -pub const ETIME: ::c_int = 101; -pub const EOPNOTSUPP: ::c_int = 102; -pub const ENOPOLICY: ::c_int = 103; -pub const ENOTRECOVERABLE: ::c_int = 104; -pub const EOWNERDEAD: ::c_int = 105; -pub const EQFULL: ::c_int = 106; -pub const ELAST: ::c_int = 106; - -pub const EAI_AGAIN: ::c_int = 2; -pub const EAI_BADFLAGS: ::c_int = 3; -pub const EAI_FAIL: ::c_int = 4; -pub const EAI_FAMILY: ::c_int = 5; -pub const EAI_MEMORY: ::c_int = 6; -pub const EAI_NODATA: ::c_int = 7; -pub const EAI_NONAME: ::c_int = 8; -pub const EAI_SERVICE: ::c_int = 9; -pub const EAI_SOCKTYPE: ::c_int = 10; -pub const EAI_SYSTEM: ::c_int = 11; -pub const EAI_OVERFLOW: ::c_int = 14; - -pub const F_DUPFD: ::c_int = 0; -pub const F_DUPFD_CLOEXEC: ::c_int = 67; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; -pub const F_PREALLOCATE: ::c_int = 42; -pub const F_RDADVISE: ::c_int = 44; -pub const F_RDAHEAD: ::c_int = 45; -pub const F_NOCACHE: ::c_int = 48; -pub const F_GETPATH: ::c_int = 50; -pub const F_FULLFSYNC: ::c_int = 51; -pub const F_FREEZE_FS: ::c_int = 53; -pub const F_THAW_FS: ::c_int = 54; -pub const F_GLOBAL_NOCACHE: ::c_int = 55; -pub const F_NODIRECT: ::c_int = 62; - -pub const F_ALLOCATECONTIG: ::c_uint = 0x02; -pub const F_ALLOCATEALL: ::c_uint = 0x04; - -pub const F_PEOFPOSMODE: ::c_int = 3; -pub const F_VOLPOSMODE: ::c_int = 4; - -pub const AT_FDCWD: ::c_int = -2; -pub const AT_EACCESS: ::c_int = 0x0010; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x0020; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x0040; -pub const AT_REMOVEDIR: ::c_int = 0x0080; - -pub const TIOCMODG: ::c_ulong = 0x40047403; -pub const TIOCMODS: ::c_ulong = 0x80047404; -pub const TIOCM_LE: ::c_int = 0x1; -pub const TIOCM_DTR: ::c_int = 0x2; -pub const TIOCM_RTS: ::c_int = 0x4; -pub const TIOCM_ST: ::c_int = 0x8; -pub const TIOCM_SR: ::c_int = 0x10; -pub const TIOCM_CTS: ::c_int = 0x20; -pub const TIOCM_CAR: ::c_int = 0x40; -pub const TIOCM_CD: ::c_int = 0x40; -pub const TIOCM_RNG: ::c_int = 0x80; -pub const TIOCM_RI: ::c_int = 0x80; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCEXCL: ::c_int = 0x2000740d; -pub const TIOCNXCL: ::c_int = 0x2000740e; -pub const TIOCFLUSH: ::c_ulong = 0x80047410; -pub const TIOCGETD: ::c_ulong = 0x4004741a; -pub const TIOCSETD: ::c_ulong = 0x8004741b; -pub const TIOCIXON: ::c_uint = 0x20007481; -pub const TIOCIXOFF: ::c_uint = 0x20007480; -pub const TIOCSBRK: ::c_uint = 0x2000747b; -pub const TIOCCBRK: ::c_uint = 0x2000747a; -pub const TIOCSDTR: ::c_uint = 0x20007479; -pub const TIOCCDTR: ::c_uint = 0x20007478; -pub const TIOCGPGRP: ::c_ulong = 0x40047477; -pub const TIOCSPGRP: ::c_ulong = 0x80047476; -pub const TIOCOUTQ: ::c_ulong = 0x40047473; -pub const TIOCSTI: ::c_ulong = 0x80017472; -pub const TIOCNOTTY: ::c_uint = 0x20007471; -pub const TIOCPKT: ::c_ulong = 0x80047470; -pub const TIOCPKT_DATA: ::c_int = 0x0; -pub const TIOCPKT_FLUSHREAD: ::c_int = 0x1; -pub const TIOCPKT_FLUSHWRITE: ::c_int = 0x2; -pub const TIOCPKT_STOP: ::c_int = 0x4; -pub const TIOCPKT_START: ::c_int = 0x8; -pub const TIOCPKT_NOSTOP: ::c_int = 0x10; -pub const TIOCPKT_DOSTOP: ::c_int = 0x20; -pub const TIOCPKT_IOCTL: ::c_int = 0x40; -pub const TIOCSTOP: ::c_uint = 0x2000746f; -pub const TIOCSTART: ::c_uint = 0x2000746e; -pub const TIOCMSET: ::c_ulong = 0x8004746d; -pub const TIOCMBIS: ::c_ulong = 0x8004746c; -pub const TIOCMBIC: ::c_ulong = 0x8004746b; -pub const TIOCMGET: ::c_ulong = 0x4004746a; -pub const TIOCREMOTE: ::c_ulong = 0x80047469; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const TIOCUCNTL: ::c_ulong = 0x80047466; -pub const TIOCSTAT: ::c_uint = 0x20007465; -pub const TIOCSCONS: ::c_uint = 0x20007463; -pub const TIOCCONS: ::c_ulong = 0x80047462; -pub const TIOCSCTTY: ::c_uint = 0x20007461; -pub const TIOCEXT: ::c_ulong = 0x80047460; -pub const TIOCSIG: ::c_uint = 0x2000745f; -pub const TIOCDRAIN: ::c_uint = 0x2000745e; -pub const TIOCMSDTRWAIT: ::c_ulong = 0x8004745b; -pub const TIOCMGDTRWAIT: ::c_ulong = 0x4004745a; -pub const TIOCSDRAINWAIT: ::c_ulong = 0x80047457; -pub const TIOCGDRAINWAIT: ::c_ulong = 0x40047456; -pub const TIOCDSIMICROCODE: ::c_uint = 0x20007455; -pub const TIOCPTYGRANT: ::c_uint = 0x20007454; -pub const TIOCPTYGNAME: ::c_uint = 0x40807453; -pub const TIOCPTYUNLK: ::c_uint = 0x20007452; - -pub const BIOCGRSIG: ::c_ulong = 0x40044272; -pub const BIOCSRSIG: ::c_ulong = 0x80044273; -pub const BIOCSDLT: ::c_ulong = 0x80044278; -pub const BIOCGSEESENT: ::c_ulong = 0x40044276; -pub const BIOCSSEESENT: ::c_ulong = 0x80044277; -pub const BIOCGDLTLIST: ::c_ulong = 0xc00c4279; - -pub const FIODTYPE: ::c_ulong = 0x4004667a; - -pub const B0: speed_t = 0; -pub const B50: speed_t = 50; -pub const B75: speed_t = 75; -pub const B110: speed_t = 110; -pub const B134: speed_t = 134; -pub const B150: speed_t = 150; -pub const B200: speed_t = 200; -pub const B300: speed_t = 300; -pub const B600: speed_t = 600; -pub const B1200: speed_t = 1200; -pub const B1800: speed_t = 1800; -pub const B2400: speed_t = 2400; -pub const B4800: speed_t = 4800; -pub const B9600: speed_t = 9600; -pub const B19200: speed_t = 19200; -pub const B38400: speed_t = 38400; -pub const B7200: speed_t = 7200; -pub const B14400: speed_t = 14400; -pub const B28800: speed_t = 28800; -pub const B57600: speed_t = 57600; -pub const B76800: speed_t = 76800; -pub const B115200: speed_t = 115200; -pub const B230400: speed_t = 230400; -pub const EXTA: speed_t = 19200; -pub const EXTB: speed_t = 38400; - -pub const SIGTRAP: ::c_int = 5; - -pub const GLOB_APPEND: ::c_int = 0x0001; -pub const GLOB_DOOFFS: ::c_int = 0x0002; -pub const GLOB_ERR: ::c_int = 0x0004; -pub const GLOB_MARK: ::c_int = 0x0008; -pub const GLOB_NOCHECK: ::c_int = 0x0010; -pub const GLOB_NOSORT: ::c_int = 0x0020; -pub const GLOB_NOESCAPE: ::c_int = 0x2000; - -pub const GLOB_NOSPACE: ::c_int = -1; -pub const GLOB_ABORTED: ::c_int = -2; -pub const GLOB_NOMATCH: ::c_int = -3; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; -pub const POSIX_MADV_DONTNEED: ::c_int = 4; - -pub const _SC_IOV_MAX: ::c_int = 56; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 70; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 71; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 73; -pub const _SC_MQ_PRIO_MAX: ::c_int = 75; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 82; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 83; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 85; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 86; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 87; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 88; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 89; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 90; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 91; -pub const _SC_THREAD_STACK_MIN: ::c_int = 93; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 94; -pub const _SC_THREADS: ::c_int = 96; -pub const _SC_TTY_NAME_MAX: ::c_int = 101; -pub const _SC_ATEXIT_MAX: ::c_int = 107; -pub const _SC_XOPEN_CRYPT: ::c_int = 108; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 109; -pub const _SC_XOPEN_LEGACY: ::c_int = 110; -pub const _SC_XOPEN_REALTIME: ::c_int = 111; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 112; -pub const _SC_XOPEN_SHM: ::c_int = 113; -pub const _SC_XOPEN_UNIX: ::c_int = 115; -pub const _SC_XOPEN_VERSION: ::c_int = 116; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 121; -pub const _SC_PHYS_PAGES: ::c_int = 200; - -pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 2; -pub const PTHREAD_PROCESS_SHARED: ::c_int = 1; -pub const PTHREAD_CREATE_JOINABLE: ::c_int = 1; -pub const PTHREAD_CREATE_DETACHED: ::c_int = 2; -pub const PTHREAD_STACK_MIN: ::size_t = 8192; - -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_AS: ::c_int = 5; -pub const RLIMIT_RSS: ::c_int = RLIMIT_AS; -pub const RLIMIT_MEMLOCK: ::c_int = 6; -pub const RLIMIT_NPROC: ::c_int = 7; -pub const RLIMIT_NOFILE: ::c_int = 8; -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] -pub const RLIM_NLIMITS: ::c_int = 9; -pub const _RLIMIT_POSIX_FLAG: ::c_int = 0x1000; - -pub const RLIM_INFINITY: rlim_t = 0x7fff_ffff_ffff_ffff; - -pub const RUSAGE_SELF: ::c_int = 0; -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const MADV_NORMAL: ::c_int = 0; -pub const MADV_RANDOM: ::c_int = 1; -pub const MADV_SEQUENTIAL: ::c_int = 2; -pub const MADV_WILLNEED: ::c_int = 3; -pub const MADV_DONTNEED: ::c_int = 4; -pub const MADV_FREE: ::c_int = 5; -pub const MADV_ZERO_WIRED_PAGES: ::c_int = 6; -pub const MADV_FREE_REUSABLE: ::c_int = 7; -pub const MADV_FREE_REUSE: ::c_int = 8; -pub const MADV_CAN_REUSE: ::c_int = 9; - -pub const MINCORE_INCORE: ::c_int = 0x1; -pub const MINCORE_REFERENCED: ::c_int = 0x2; -pub const MINCORE_MODIFIED: ::c_int = 0x4; -pub const MINCORE_REFERENCED_OTHER: ::c_int = 0x8; -pub const MINCORE_MODIFIED_OTHER: ::c_int = 0x10; - -// -// sys/netinet/in.h -// Protocols (RFC 1700) -// NOTE: These are in addition to the constants defined in src/unix/mod.rs - -// IPPROTO_IP defined in src/unix/mod.rs -/// IP6 hop-by-hop options -pub const IPPROTO_HOPOPTS: ::c_int = 0; -// IPPROTO_ICMP defined in src/unix/mod.rs -/// group mgmt protocol -pub const IPPROTO_IGMP: ::c_int = 2; -/// gateway2 (deprecated) -pub const IPPROTO_GGP: ::c_int = 3; -/// for compatibility -pub const IPPROTO_IPIP: ::c_int = 4; -// IPPROTO_TCP defined in src/unix/mod.rs -/// Stream protocol II. -pub const IPPROTO_ST: ::c_int = 7; -/// exterior gateway protocol -pub const IPPROTO_EGP: ::c_int = 8; -/// private interior gateway -pub const IPPROTO_PIGP: ::c_int = 9; -/// BBN RCC Monitoring -pub const IPPROTO_RCCMON: ::c_int = 10; -/// network voice protocol -pub const IPPROTO_NVPII: ::c_int = 11; -/// pup -pub const IPPROTO_PUP: ::c_int = 12; -/// Argus -pub const IPPROTO_ARGUS: ::c_int = 13; -/// EMCON -pub const IPPROTO_EMCON: ::c_int = 14; -/// Cross Net Debugger -pub const IPPROTO_XNET: ::c_int = 15; -/// Chaos -pub const IPPROTO_CHAOS: ::c_int = 16; -// IPPROTO_UDP defined in src/unix/mod.rs -/// Multiplexing -pub const IPPROTO_MUX: ::c_int = 18; -/// DCN Measurement Subsystems -pub const IPPROTO_MEAS: ::c_int = 19; -/// Host Monitoring -pub const IPPROTO_HMP: ::c_int = 20; -/// Packet Radio Measurement -pub const IPPROTO_PRM: ::c_int = 21; -/// xns idp -pub const IPPROTO_IDP: ::c_int = 22; -/// Trunk-1 -pub const IPPROTO_TRUNK1: ::c_int = 23; -/// Trunk-2 -pub const IPPROTO_TRUNK2: ::c_int = 24; -/// Leaf-1 -pub const IPPROTO_LEAF1: ::c_int = 25; -/// Leaf-2 -pub const IPPROTO_LEAF2: ::c_int = 26; -/// Reliable Data -pub const IPPROTO_RDP: ::c_int = 27; -/// Reliable Transaction -pub const IPPROTO_IRTP: ::c_int = 28; -/// tp-4 w/ class negotiation -pub const IPPROTO_TP: ::c_int = 29; -/// Bulk Data Transfer -pub const IPPROTO_BLT: ::c_int = 30; -/// Network Services -pub const IPPROTO_NSP: ::c_int = 31; -/// Merit Internodal -pub const IPPROTO_INP: ::c_int = 32; -/// Sequential Exchange -pub const IPPROTO_SEP: ::c_int = 33; -/// Third Party Connect -pub const IPPROTO_3PC: ::c_int = 34; -/// InterDomain Policy Routing -pub const IPPROTO_IDPR: ::c_int = 35; -/// XTP -pub const IPPROTO_XTP: ::c_int = 36; -/// Datagram Delivery -pub const IPPROTO_DDP: ::c_int = 37; -/// Control Message Transport -pub const IPPROTO_CMTP: ::c_int = 38; -/// TP++ Transport -pub const IPPROTO_TPXX: ::c_int = 39; -/// IL transport protocol -pub const IPPROTO_IL: ::c_int = 40; -// IPPROTO_IPV6 defined in src/unix/mod.rs -/// Source Demand Routing -pub const IPPROTO_SDRP: ::c_int = 42; -/// IP6 routing header -pub const IPPROTO_ROUTING: ::c_int = 43; -/// IP6 fragmentation header -pub const IPPROTO_FRAGMENT: ::c_int = 44; -/// InterDomain Routing -pub const IPPROTO_IDRP: ::c_int = 45; -/// resource reservation -pub const IPPROTO_RSVP: ::c_int = 46; -/// General Routing Encap. -pub const IPPROTO_GRE: ::c_int = 47; -/// Mobile Host Routing -pub const IPPROTO_MHRP: ::c_int = 48; -/// BHA -pub const IPPROTO_BHA: ::c_int = 49; -/// IP6 Encap Sec. Payload -pub const IPPROTO_ESP: ::c_int = 50; -/// IP6 Auth Header -pub const IPPROTO_AH: ::c_int = 51; -/// Integ. Net Layer Security -pub const IPPROTO_INLSP: ::c_int = 52; -/// IP with encryption -pub const IPPROTO_SWIPE: ::c_int = 53; -/// Next Hop Resolution -pub const IPPROTO_NHRP: ::c_int = 54; -/* 55-57: Unassigned */ -// IPPROTO_ICMPV6 defined in src/unix/mod.rs -/// IP6 no next header -pub const IPPROTO_NONE: ::c_int = 59; -/// IP6 destination option -pub const IPPROTO_DSTOPTS: ::c_int = 60; -/// any host internal protocol -pub const IPPROTO_AHIP: ::c_int = 61; -/// CFTP -pub const IPPROTO_CFTP: ::c_int = 62; -/// "hello" routing protocol -pub const IPPROTO_HELLO: ::c_int = 63; -/// SATNET/Backroom EXPAK -pub const IPPROTO_SATEXPAK: ::c_int = 64; -/// Kryptolan -pub const IPPROTO_KRYPTOLAN: ::c_int = 65; -/// Remote Virtual Disk -pub const IPPROTO_RVD: ::c_int = 66; -/// Pluribus Packet Core -pub const IPPROTO_IPPC: ::c_int = 67; -/// Any distributed FS -pub const IPPROTO_ADFS: ::c_int = 68; -/// Satnet Monitoring -pub const IPPROTO_SATMON: ::c_int = 69; -/// VISA Protocol -pub const IPPROTO_VISA: ::c_int = 70; -/// Packet Core Utility -pub const IPPROTO_IPCV: ::c_int = 71; -/// Comp. Prot. Net. Executive -pub const IPPROTO_CPNX: ::c_int = 72; -/// Comp. Prot. HeartBeat -pub const IPPROTO_CPHB: ::c_int = 73; -/// Wang Span Network -pub const IPPROTO_WSN: ::c_int = 74; -/// Packet Video Protocol -pub const IPPROTO_PVP: ::c_int = 75; -/// BackRoom SATNET Monitoring -pub const IPPROTO_BRSATMON: ::c_int = 76; -/// Sun net disk proto (temp.) -pub const IPPROTO_ND: ::c_int = 77; -/// WIDEBAND Monitoring -pub const IPPROTO_WBMON: ::c_int = 78; -/// WIDEBAND EXPAK -pub const IPPROTO_WBEXPAK: ::c_int = 79; -/// ISO cnlp -pub const IPPROTO_EON: ::c_int = 80; -/// VMTP -pub const IPPROTO_VMTP: ::c_int = 81; -/// Secure VMTP -pub const IPPROTO_SVMTP: ::c_int = 82; -/// Banyon VINES -pub const IPPROTO_VINES: ::c_int = 83; -/// TTP -pub const IPPROTO_TTP: ::c_int = 84; -/// NSFNET-IGP -pub const IPPROTO_IGP: ::c_int = 85; -/// dissimilar gateway prot. -pub const IPPROTO_DGP: ::c_int = 86; -/// TCF -pub const IPPROTO_TCF: ::c_int = 87; -/// Cisco/GXS IGRP -pub const IPPROTO_IGRP: ::c_int = 88; -/// OSPFIGP -pub const IPPROTO_OSPFIGP: ::c_int = 89; -/// Strite RPC protocol -pub const IPPROTO_SRPC: ::c_int = 90; -/// Locus Address Resoloution -pub const IPPROTO_LARP: ::c_int = 91; -/// Multicast Transport -pub const IPPROTO_MTP: ::c_int = 92; -/// AX.25 Frames -pub const IPPROTO_AX25: ::c_int = 93; -/// IP encapsulated in IP -pub const IPPROTO_IPEIP: ::c_int = 94; -/// Mobile Int.ing control -pub const IPPROTO_MICP: ::c_int = 95; -/// Semaphore Comm. security -pub const IPPROTO_SCCSP: ::c_int = 96; -/// Ethernet IP encapsulation -pub const IPPROTO_ETHERIP: ::c_int = 97; -/// encapsulation header -pub const IPPROTO_ENCAP: ::c_int = 98; -/// any private encr. scheme -pub const IPPROTO_APES: ::c_int = 99; -/// GMTP -pub const IPPROTO_GMTP: ::c_int = 100; - -/* 101-254: Partly Unassigned */ -/// Protocol Independent Mcast -pub const IPPROTO_PIM: ::c_int = 103; -/// payload compression (IPComp) -pub const IPPROTO_IPCOMP: ::c_int = 108; -/// PGM -pub const IPPROTO_PGM: ::c_int = 113; -/// SCTP -pub const IPPROTO_SCTP: ::c_int = 132; - -/* 255: Reserved */ -/* BSD Private, local use, namespace incursion */ -/// divert pseudo-protocol -pub const IPPROTO_DIVERT: ::c_int = 254; -/// raw IP packet -pub const IPPROTO_RAW: ::c_int = 255; -pub const IPPROTO_MAX: ::c_int = 256; -/// last return value of *_input(), meaning "all job for this pkt is done". -pub const IPPROTO_DONE: ::c_int = 257; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_LOCAL: ::c_int = 1; -pub const AF_UNIX: ::c_int = AF_LOCAL; -pub const AF_INET: ::c_int = 2; -pub const AF_IMPLINK: ::c_int = 3; -pub const AF_PUP: ::c_int = 4; -pub const AF_CHAOS: ::c_int = 5; -pub const AF_NS: ::c_int = 6; -pub const AF_ISO: ::c_int = 7; -pub const AF_OSI: ::c_int = AF_ISO; -pub const AF_ECMA: ::c_int = 8; -pub const AF_DATAKIT: ::c_int = 9; -pub const AF_CCITT: ::c_int = 10; -pub const AF_SNA: ::c_int = 11; -pub const AF_DECnet: ::c_int = 12; -pub const AF_DLI: ::c_int = 13; -pub const AF_LAT: ::c_int = 14; -pub const AF_HYLINK: ::c_int = 15; -pub const AF_APPLETALK: ::c_int = 16; -pub const AF_ROUTE: ::c_int = 17; -pub const AF_LINK: ::c_int = 18; -pub const pseudo_AF_XTP: ::c_int = 19; -pub const AF_COIP: ::c_int = 20; -pub const AF_CNT: ::c_int = 21; -pub const pseudo_AF_RTIP: ::c_int = 22; -pub const AF_IPX: ::c_int = 23; -pub const AF_SIP: ::c_int = 24; -pub const pseudo_AF_PIP: ::c_int = 25; -pub const AF_ISDN: ::c_int = 28; -pub const AF_E164: ::c_int = AF_ISDN; -pub const pseudo_AF_KEY: ::c_int = 29; -pub const AF_INET6: ::c_int = 30; -pub const AF_NATM: ::c_int = 31; -pub const AF_SYSTEM: ::c_int = 32; -pub const AF_NETBIOS: ::c_int = 33; -pub const AF_PPP: ::c_int = 34; -pub const pseudo_AF_HDRCMPLT: ::c_int = 35; -pub const AF_SYS_CONTROL: ::c_int = 2; - -pub const SYSPROTO_EVENT: ::c_int = 1; -pub const SYSPROTO_CONTROL: ::c_int = 2; - -pub const PF_UNSPEC: ::c_int = AF_UNSPEC; -pub const PF_LOCAL: ::c_int = AF_LOCAL; -pub const PF_UNIX: ::c_int = PF_LOCAL; -pub const PF_INET: ::c_int = AF_INET; -pub const PF_IMPLINK: ::c_int = AF_IMPLINK; -pub const PF_PUP: ::c_int = AF_PUP; -pub const PF_CHAOS: ::c_int = AF_CHAOS; -pub const PF_NS: ::c_int = AF_NS; -pub const PF_ISO: ::c_int = AF_ISO; -pub const PF_OSI: ::c_int = AF_ISO; -pub const PF_ECMA: ::c_int = AF_ECMA; -pub const PF_DATAKIT: ::c_int = AF_DATAKIT; -pub const PF_CCITT: ::c_int = AF_CCITT; -pub const PF_SNA: ::c_int = AF_SNA; -pub const PF_DECnet: ::c_int = AF_DECnet; -pub const PF_DLI: ::c_int = AF_DLI; -pub const PF_LAT: ::c_int = AF_LAT; -pub const PF_HYLINK: ::c_int = AF_HYLINK; -pub const PF_APPLETALK: ::c_int = AF_APPLETALK; -pub const PF_ROUTE: ::c_int = AF_ROUTE; -pub const PF_LINK: ::c_int = AF_LINK; -pub const PF_XTP: ::c_int = pseudo_AF_XTP; -pub const PF_COIP: ::c_int = AF_COIP; -pub const PF_CNT: ::c_int = AF_CNT; -pub const PF_SIP: ::c_int = AF_SIP; -pub const PF_IPX: ::c_int = AF_IPX; -pub const PF_RTIP: ::c_int = pseudo_AF_RTIP; -pub const PF_PIP: ::c_int = pseudo_AF_PIP; -pub const PF_ISDN: ::c_int = AF_ISDN; -pub const PF_KEY: ::c_int = pseudo_AF_KEY; -pub const PF_INET6: ::c_int = AF_INET6; -pub const PF_NATM: ::c_int = AF_NATM; -pub const PF_SYSTEM: ::c_int = AF_SYSTEM; -pub const PF_NETBIOS: ::c_int = AF_NETBIOS; -pub const PF_PPP: ::c_int = AF_PPP; - -pub const NET_RT_DUMP: ::c_int = 1; -pub const NET_RT_FLAGS: ::c_int = 2; -pub const NET_RT_IFLIST: ::c_int = 3; - -pub const SOMAXCONN: ::c_int = 128; - -pub const SOCK_MAXADDRLEN: ::c_int = 255; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_RAW: ::c_int = 3; -pub const SOCK_RDM: ::c_int = 4; -pub const SOCK_SEQPACKET: ::c_int = 5; -pub const IP_TTL: ::c_int = 4; -pub const IP_HDRINCL: ::c_int = 2; -pub const IP_RECVDSTADDR: ::c_int = 7; -pub const IP_ADD_MEMBERSHIP: ::c_int = 12; -pub const IP_DROP_MEMBERSHIP: ::c_int = 13; -pub const IP_RECVIF: ::c_int = 20; -pub const IP_PKTINFO: ::c_int = 26; -pub const IP_RECVTOS: ::c_int = 27; -pub const IPV6_JOIN_GROUP: ::c_int = 12; -pub const IPV6_LEAVE_GROUP: ::c_int = 13; -pub const IPV6_RECVTCLASS: ::c_int = 35; -pub const IPV6_TCLASS: ::c_int = 36; -pub const IPV6_PKTINFO: ::c_int = 46; -pub const IPV6_RECVPKTINFO: ::c_int = 61; - -pub const TCP_NOPUSH: ::c_int = 4; -pub const TCP_NOOPT: ::c_int = 8; -pub const TCP_KEEPALIVE: ::c_int = 0x10; - -pub const SOL_LOCAL: ::c_int = 0; - -pub const LOCAL_PEERCRED: ::c_int = 0x001; -pub const LOCAL_PEERPID: ::c_int = 0x002; -pub const LOCAL_PEEREPID: ::c_int = 0x003; -pub const LOCAL_PEERUUID: ::c_int = 0x004; -pub const LOCAL_PEEREUUID: ::c_int = 0x005; - -pub const SOL_SOCKET: ::c_int = 0xffff; - -pub const SO_DEBUG: ::c_int = 0x01; -pub const SO_ACCEPTCONN: ::c_int = 0x0002; -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_USELOOPBACK: ::c_int = 0x0040; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_TIMESTAMP: ::c_int = 0x0400; -pub const SO_TIMESTAMP_MONOTONIC: ::c_int = 0x0800; -pub const SO_DONTTRUNC: ::c_int = 0x2000; -pub const SO_WANTMORE: ::c_int = 0x4000; -pub const SO_WANTOOBFLAG: ::c_int = 0x8000; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_LABEL: ::c_int = 0x1010; -pub const SO_PEERLABEL: ::c_int = 0x1011; -pub const SO_NREAD: ::c_int = 0x1020; -pub const SO_NKE: ::c_int = 0x1021; -pub const SO_NOSIGPIPE: ::c_int = 0x1022; -pub const SO_NOADDRERR: ::c_int = 0x1023; -pub const SO_NWRITE: ::c_int = 0x1024; -pub const SO_REUSESHAREUID: ::c_int = 0x1025; -pub const SO_NOTIFYCONFLICT: ::c_int = 0x1026; -pub const SO_RANDOMPORT: ::c_int = 0x1082; -pub const SO_NP_EXTENSIONS: ::c_int = 0x1083; - -pub const MSG_OOB: ::c_int = 0x1; -pub const MSG_PEEK: ::c_int = 0x2; -pub const MSG_DONTROUTE: ::c_int = 0x4; -pub const MSG_EOR: ::c_int = 0x8; -pub const MSG_TRUNC: ::c_int = 0x10; -pub const MSG_CTRUNC: ::c_int = 0x20; -pub const MSG_WAITALL: ::c_int = 0x40; -pub const MSG_DONTWAIT: ::c_int = 0x80; -pub const MSG_EOF: ::c_int = 0x100; -pub const MSG_FLUSH: ::c_int = 0x400; -pub const MSG_HOLD: ::c_int = 0x800; -pub const MSG_SEND: ::c_int = 0x1000; -pub const MSG_HAVEMORE: ::c_int = 0x2000; -pub const MSG_RCVMORE: ::c_int = 0x4000; -// pub const MSG_COMPAT: ::c_int = 0x8000; - -pub const SCM_TIMESTAMP: ::c_int = 0x02; -pub const SCM_CREDS: ::c_int = 0x03; - -// https://github.com/aosm/xnu/blob/master/bsd/net/if.h#L140-L156 -pub const IFF_UP: ::c_int = 0x1; // interface is up -pub const IFF_BROADCAST: ::c_int = 0x2; // broadcast address valid -pub const IFF_DEBUG: ::c_int = 0x4; // turn on debugging -pub const IFF_LOOPBACK: ::c_int = 0x8; // is a loopback net -pub const IFF_POINTOPOINT: ::c_int = 0x10; // interface is point-to-point link -pub const IFF_NOTRAILERS: ::c_int = 0x20; // obsolete: avoid use of trailers -pub const IFF_RUNNING: ::c_int = 0x40; // resources allocated -pub const IFF_NOARP: ::c_int = 0x80; // no address resolution protocol -pub const IFF_PROMISC: ::c_int = 0x100; // receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x200; // receive all multicast packets -pub const IFF_OACTIVE: ::c_int = 0x400; // transmission in progress -pub const IFF_SIMPLEX: ::c_int = 0x800; // can't hear own transmissions -pub const IFF_LINK0: ::c_int = 0x1000; // per link layer defined bit -pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit -pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit -pub const IFF_ALTPHYS: ::c_int = IFF_LINK2; // use alternate physical connection -pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const LOCK_SH: ::c_int = 1; -pub const LOCK_EX: ::c_int = 2; -pub const LOCK_NB: ::c_int = 4; -pub const LOCK_UN: ::c_int = 8; - -pub const MAP_COPY: ::c_int = 0x0002; -pub const MAP_RENAME: ::c_int = 0x0020; -pub const MAP_NORESERVE: ::c_int = 0x0040; -pub const MAP_NOEXTEND: ::c_int = 0x0100; -pub const MAP_HASSEMAPHORE: ::c_int = 0x0200; -pub const MAP_NOCACHE: ::c_int = 0x0400; -pub const MAP_JIT: ::c_int = 0x0800; - -pub const _SC_ARG_MAX: ::c_int = 1; -pub const _SC_CHILD_MAX: ::c_int = 2; -pub const _SC_CLK_TCK: ::c_int = 3; -pub const _SC_NGROUPS_MAX: ::c_int = 4; -pub const _SC_OPEN_MAX: ::c_int = 5; -pub const _SC_JOB_CONTROL: ::c_int = 6; -pub const _SC_SAVED_IDS: ::c_int = 7; -pub const _SC_VERSION: ::c_int = 8; -pub const _SC_BC_BASE_MAX: ::c_int = 9; -pub const _SC_BC_DIM_MAX: ::c_int = 10; -pub const _SC_BC_SCALE_MAX: ::c_int = 11; -pub const _SC_BC_STRING_MAX: ::c_int = 12; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 13; -pub const _SC_EXPR_NEST_MAX: ::c_int = 14; -pub const _SC_LINE_MAX: ::c_int = 15; -pub const _SC_RE_DUP_MAX: ::c_int = 16; -pub const _SC_2_VERSION: ::c_int = 17; -pub const _SC_2_C_BIND: ::c_int = 18; -pub const _SC_2_C_DEV: ::c_int = 19; -pub const _SC_2_CHAR_TERM: ::c_int = 20; -pub const _SC_2_FORT_DEV: ::c_int = 21; -pub const _SC_2_FORT_RUN: ::c_int = 22; -pub const _SC_2_LOCALEDEF: ::c_int = 23; -pub const _SC_2_SW_DEV: ::c_int = 24; -pub const _SC_2_UPE: ::c_int = 25; -pub const _SC_STREAM_MAX: ::c_int = 26; -pub const _SC_TZNAME_MAX: ::c_int = 27; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 28; -pub const _SC_PAGESIZE: ::c_int = 29; -pub const _SC_MEMLOCK: ::c_int = 30; -pub const _SC_MEMLOCK_RANGE: ::c_int = 31; -pub const _SC_MEMORY_PROTECTION: ::c_int = 32; -pub const _SC_MESSAGE_PASSING: ::c_int = 33; -pub const _SC_PRIORITIZED_IO: ::c_int = 34; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 35; -pub const _SC_REALTIME_SIGNALS: ::c_int = 36; -pub const _SC_SEMAPHORES: ::c_int = 37; -pub const _SC_FSYNC: ::c_int = 38; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 39; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 40; -pub const _SC_TIMERS: ::c_int = 41; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 42; -pub const _SC_AIO_MAX: ::c_int = 43; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 44; -pub const _SC_DELAYTIMER_MAX: ::c_int = 45; -pub const _SC_MQ_OPEN_MAX: ::c_int = 46; -pub const _SC_MAPPED_FILES: ::c_int = 47; -pub const _SC_RTSIG_MAX: ::c_int = 48; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 49; -pub const _SC_SEM_VALUE_MAX: ::c_int = 50; -pub const _SC_SIGQUEUE_MAX: ::c_int = 51; -pub const _SC_TIMER_MAX: ::c_int = 52; -pub const _SC_NPROCESSORS_CONF: ::c_int = 57; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 58; -pub const _SC_2_PBS: ::c_int = 59; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 60; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 61; -pub const _SC_2_PBS_LOCATE: ::c_int = 62; -pub const _SC_2_PBS_MESSAGE: ::c_int = 63; -pub const _SC_2_PBS_TRACK: ::c_int = 64; -pub const _SC_ADVISORY_INFO: ::c_int = 65; -pub const _SC_BARRIERS: ::c_int = 66; -pub const _SC_CLOCK_SELECTION: ::c_int = 67; -pub const _SC_CPUTIME: ::c_int = 68; -pub const _SC_FILE_LOCKING: ::c_int = 69; -pub const _SC_HOST_NAME_MAX: ::c_int = 72; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 74; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 76; -pub const _SC_REGEXP: ::c_int = 77; -pub const _SC_SHELL: ::c_int = 78; -pub const _SC_SPAWN: ::c_int = 79; -pub const _SC_SPIN_LOCKS: ::c_int = 80; -pub const _SC_SPORADIC_SERVER: ::c_int = 81; -pub const _SC_THREAD_CPUTIME: ::c_int = 84; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 92; -pub const _SC_TIMEOUTS: ::c_int = 95; -pub const _SC_TRACE: ::c_int = 97; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 98; -pub const _SC_TRACE_INHERIT: ::c_int = 99; -pub const _SC_TRACE_LOG: ::c_int = 100; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 102; -pub const _SC_V6_ILP32_OFF32: ::c_int = 103; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 104; -pub const _SC_V6_LP64_OFF64: ::c_int = 105; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 106; -pub const _SC_IPV6: ::c_int = 118; -pub const _SC_RAW_SOCKETS: ::c_int = 119; -pub const _SC_SYMLOOP_MAX: ::c_int = 120; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_XOPEN_STREAMS: ::c_int = 114; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = 122; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = 123; -pub const _SC_XBS5_LP64_OFF64: ::c_int = 124; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = 125; -pub const _SC_SS_REPL_MAX: ::c_int = 126; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 127; -pub const _SC_TRACE_NAME_MAX: ::c_int = 128; -pub const _SC_TRACE_SYS_MAX: ::c_int = 129; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 130; -pub const _SC_PASS_MAX: ::c_int = 131; - -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 1; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; -pub const _PTHREAD_MUTEX_SIG_init: ::c_long = 0x32AAABA7; -pub const _PTHREAD_COND_SIG_init: ::c_long = 0x3CB0B1BB; -pub const _PTHREAD_RWLOCK_SIG_init: ::c_long = 0x2DA8B3B4; -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - __sig: _PTHREAD_MUTEX_SIG_init, - __opaque: [0; __PTHREAD_MUTEX_SIZE__], -}; -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - __sig: _PTHREAD_COND_SIG_init, - __opaque: [0; __PTHREAD_COND_SIZE__], -}; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - __sig: _PTHREAD_RWLOCK_SIG_init, - __opaque: [0; __PTHREAD_RWLOCK_SIZE__], -}; - -pub const SIGSTKSZ: ::size_t = 131072; - -pub const FD_SETSIZE: usize = 1024; - -pub const ST_NOSUID: ::c_ulong = 2; - -pub const EVFILT_READ: i16 = -1; -pub const EVFILT_WRITE: i16 = -2; -pub const EVFILT_AIO: i16 = -3; -pub const EVFILT_VNODE: i16 = -4; -pub const EVFILT_PROC: i16 = -5; -pub const EVFILT_SIGNAL: i16 = -6; -pub const EVFILT_TIMER: i16 = -7; -pub const EVFILT_MACHPORT: i16 = -8; -pub const EVFILT_FS: i16 = -9; -pub const EVFILT_USER: i16 = -10; -pub const EVFILT_VM: i16 = -12; - -pub const EV_ADD: u16 = 0x1; -pub const EV_DELETE: u16 = 0x2; -pub const EV_ENABLE: u16 = 0x4; -pub const EV_DISABLE: u16 = 0x8; -pub const EV_ONESHOT: u16 = 0x10; -pub const EV_CLEAR: u16 = 0x20; -pub const EV_RECEIPT: u16 = 0x40; -pub const EV_DISPATCH: u16 = 0x80; -pub const EV_FLAG0: u16 = 0x1000; -pub const EV_POLL: u16 = 0x1000; -pub const EV_FLAG1: u16 = 0x2000; -pub const EV_OOBAND: u16 = 0x2000; -pub const EV_ERROR: u16 = 0x4000; -pub const EV_EOF: u16 = 0x8000; -pub const EV_SYSFLAGS: u16 = 0xf000; - -pub const NOTE_TRIGGER: u32 = 0x01000000; -pub const NOTE_FFNOP: u32 = 0x00000000; -pub const NOTE_FFAND: u32 = 0x40000000; -pub const NOTE_FFOR: u32 = 0x80000000; -pub const NOTE_FFCOPY: u32 = 0xc0000000; -pub const NOTE_FFCTRLMASK: u32 = 0xc0000000; -pub const NOTE_FFLAGSMASK: u32 = 0x00ffffff; -pub const NOTE_LOWAT: u32 = 0x00000001; -pub const NOTE_DELETE: u32 = 0x00000001; -pub const NOTE_WRITE: u32 = 0x00000002; -pub const NOTE_EXTEND: u32 = 0x00000004; -pub const NOTE_ATTRIB: u32 = 0x00000008; -pub const NOTE_LINK: u32 = 0x00000010; -pub const NOTE_RENAME: u32 = 0x00000020; -pub const NOTE_REVOKE: u32 = 0x00000040; -pub const NOTE_NONE: u32 = 0x00000080; -pub const NOTE_EXIT: u32 = 0x80000000; -pub const NOTE_FORK: u32 = 0x40000000; -pub const NOTE_EXEC: u32 = 0x20000000; -#[doc(hidden)] -#[deprecated(since = "0.2.49", note = "Deprecated since MacOSX 10.9")] -pub const NOTE_REAP: u32 = 0x10000000; -pub const NOTE_SIGNAL: u32 = 0x08000000; -pub const NOTE_EXITSTATUS: u32 = 0x04000000; -pub const NOTE_EXIT_DETAIL: u32 = 0x02000000; -pub const NOTE_PDATAMASK: u32 = 0x000fffff; -pub const NOTE_PCTRLMASK: u32 = 0xfff00000; -#[doc(hidden)] -#[deprecated(since = "0.2.49", note = "Deprecated since MacOSX 10.9")] -pub const NOTE_EXIT_REPARENTED: u32 = 0x00080000; -pub const NOTE_EXIT_DETAIL_MASK: u32 = 0x00070000; -pub const NOTE_EXIT_DECRYPTFAIL: u32 = 0x00010000; -pub const NOTE_EXIT_MEMORY: u32 = 0x00020000; -pub const NOTE_EXIT_CSERROR: u32 = 0x00040000; -pub const NOTE_VM_PRESSURE: u32 = 0x80000000; -pub const NOTE_VM_PRESSURE_TERMINATE: u32 = 0x40000000; -pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE: u32 = 0x20000000; -pub const NOTE_VM_ERROR: u32 = 0x10000000; -pub const NOTE_SECONDS: u32 = 0x00000001; -pub const NOTE_USECONDS: u32 = 0x00000002; -pub const NOTE_NSECONDS: u32 = 0x00000004; -pub const NOTE_ABSOLUTE: u32 = 0x00000008; -pub const NOTE_LEEWAY: u32 = 0x00000010; -pub const NOTE_CRITICAL: u32 = 0x00000020; -pub const NOTE_BACKGROUND: u32 = 0x00000040; -pub const NOTE_TRACK: u32 = 0x00000001; -pub const NOTE_TRACKERR: u32 = 0x00000002; -pub const NOTE_CHILD: u32 = 0x00000004; - -pub const OCRNL: ::tcflag_t = 0x00000010; -pub const ONOCR: ::tcflag_t = 0x00000020; -pub const ONLRET: ::tcflag_t = 0x00000040; -pub const OFILL: ::tcflag_t = 0x00000080; -pub const NLDLY: ::tcflag_t = 0x00000300; -pub const TABDLY: ::tcflag_t = 0x00000c04; -pub const CRDLY: ::tcflag_t = 0x00003000; -pub const FFDLY: ::tcflag_t = 0x00004000; -pub const BSDLY: ::tcflag_t = 0x00008000; -pub const VTDLY: ::tcflag_t = 0x00010000; -pub const OFDEL: ::tcflag_t = 0x00020000; - -pub const NL0: ::tcflag_t = 0x00000000; -pub const NL1: ::tcflag_t = 0x00000100; -pub const TAB0: ::tcflag_t = 0x00000000; -pub const TAB1: ::tcflag_t = 0x00000400; -pub const TAB2: ::tcflag_t = 0x00000800; -pub const CR0: ::tcflag_t = 0x00000000; -pub const CR1: ::tcflag_t = 0x00001000; -pub const CR2: ::tcflag_t = 0x00002000; -pub const CR3: ::tcflag_t = 0x00003000; -pub const FF0: ::tcflag_t = 0x00000000; -pub const FF1: ::tcflag_t = 0x00004000; -pub const BS0: ::tcflag_t = 0x00000000; -pub const BS1: ::tcflag_t = 0x00008000; -pub const TAB3: ::tcflag_t = 0x00000004; -pub const VT0: ::tcflag_t = 0x00000000; -pub const VT1: ::tcflag_t = 0x00010000; -pub const IUTF8: ::tcflag_t = 0x00004000; -pub const CRTSCTS: ::tcflag_t = 0x00030000; - -pub const NI_MAXHOST: ::socklen_t = 1025; -pub const NI_MAXSERV: ::socklen_t = 32; -pub const NI_NOFQDN: ::c_int = 0x00000001; -pub const NI_NUMERICHOST: ::c_int = 0x00000002; -pub const NI_NAMEREQD: ::c_int = 0x00000004; -pub const NI_NUMERICSERV: ::c_int = 0x00000008; -pub const NI_NUMERICSCOPE: ::c_int = 0x00000100; -pub const NI_DGRAM: ::c_int = 0x00000010; - -pub const Q_GETQUOTA: ::c_int = 0x300; -pub const Q_SETQUOTA: ::c_int = 0x400; - -pub const RENAME_SWAP: ::c_uint = 0x00000002; -pub const RENAME_EXCL: ::c_uint = 0x00000004; - -pub const RTLD_LOCAL: ::c_int = 0x4; -pub const RTLD_FIRST: ::c_int = 0x100; -pub const RTLD_NODELETE: ::c_int = 0x80; -pub const RTLD_NOLOAD: ::c_int = 0x10; -pub const RTLD_GLOBAL: ::c_int = 0x8; - -pub const _WSTOPPED: ::c_int = 0o177; - -pub const LOG_NETINFO: ::c_int = 12 << 3; -pub const LOG_REMOTEAUTH: ::c_int = 13 << 3; -pub const LOG_INSTALL: ::c_int = 14 << 3; -pub const LOG_RAS: ::c_int = 15 << 3; -pub const LOG_LAUNCHD: ::c_int = 24 << 3; -pub const LOG_NFACILITIES: ::c_int = 25; - -pub const CTLTYPE: ::c_int = 0xf; -pub const CTLTYPE_NODE: ::c_int = 1; -pub const CTLTYPE_INT: ::c_int = 2; -pub const CTLTYPE_STRING: ::c_int = 3; -pub const CTLTYPE_QUAD: ::c_int = 4; -pub const CTLTYPE_OPAQUE: ::c_int = 5; -pub const CTLTYPE_STRUCT: ::c_int = CTLTYPE_OPAQUE; -pub const CTLFLAG_RD: ::c_int = 0x80000000; -pub const CTLFLAG_WR: ::c_int = 0x40000000; -pub const CTLFLAG_RW: ::c_int = CTLFLAG_RD | CTLFLAG_WR; -pub const CTLFLAG_NOLOCK: ::c_int = 0x20000000; -pub const CTLFLAG_ANYBODY: ::c_int = 0x10000000; -pub const CTLFLAG_SECURE: ::c_int = 0x08000000; -pub const CTLFLAG_MASKED: ::c_int = 0x04000000; -pub const CTLFLAG_NOAUTO: ::c_int = 0x02000000; -pub const CTLFLAG_KERN: ::c_int = 0x01000000; -pub const CTLFLAG_LOCKED: ::c_int = 0x00800000; -pub const CTLFLAG_OID2: ::c_int = 0x00400000; -pub const CTL_UNSPEC: ::c_int = 0; -pub const CTL_KERN: ::c_int = 1; -pub const CTL_VM: ::c_int = 2; -pub const CTL_VFS: ::c_int = 3; -pub const CTL_NET: ::c_int = 4; -pub const CTL_DEBUG: ::c_int = 5; -pub const CTL_HW: ::c_int = 6; -pub const CTL_MACHDEP: ::c_int = 7; -pub const CTL_USER: ::c_int = 8; -pub const CTL_MAXID: ::c_int = 9; -pub const KERN_OSTYPE: ::c_int = 1; -pub const KERN_OSRELEASE: ::c_int = 2; -pub const KERN_OSREV: ::c_int = 3; -pub const KERN_VERSION: ::c_int = 4; -pub const KERN_MAXVNODES: ::c_int = 5; -pub const KERN_MAXPROC: ::c_int = 6; -pub const KERN_MAXFILES: ::c_int = 7; -pub const KERN_ARGMAX: ::c_int = 8; -pub const KERN_SECURELVL: ::c_int = 9; -pub const KERN_HOSTNAME: ::c_int = 10; -pub const KERN_HOSTID: ::c_int = 11; -pub const KERN_CLOCKRATE: ::c_int = 12; -pub const KERN_VNODE: ::c_int = 13; -pub const KERN_PROC: ::c_int = 14; -pub const KERN_FILE: ::c_int = 15; -pub const KERN_PROF: ::c_int = 16; -pub const KERN_POSIX1: ::c_int = 17; -pub const KERN_NGROUPS: ::c_int = 18; -pub const KERN_JOB_CONTROL: ::c_int = 19; -pub const KERN_SAVED_IDS: ::c_int = 20; -pub const KERN_BOOTTIME: ::c_int = 21; -pub const KERN_NISDOMAINNAME: ::c_int = 22; -pub const KERN_DOMAINNAME: ::c_int = KERN_NISDOMAINNAME; -pub const KERN_MAXPARTITIONS: ::c_int = 23; -pub const KERN_KDEBUG: ::c_int = 24; -pub const KERN_UPDATEINTERVAL: ::c_int = 25; -pub const KERN_OSRELDATE: ::c_int = 26; -pub const KERN_NTP_PLL: ::c_int = 27; -pub const KERN_BOOTFILE: ::c_int = 28; -pub const KERN_MAXFILESPERPROC: ::c_int = 29; -pub const KERN_MAXPROCPERUID: ::c_int = 30; -pub const KERN_DUMPDEV: ::c_int = 31; -pub const KERN_IPC: ::c_int = 32; -pub const KERN_DUMMY: ::c_int = 33; -pub const KERN_PS_STRINGS: ::c_int = 34; -pub const KERN_USRSTACK32: ::c_int = 35; -pub const KERN_LOGSIGEXIT: ::c_int = 36; -pub const KERN_SYMFILE: ::c_int = 37; -pub const KERN_PROCARGS: ::c_int = 38; -pub const KERN_NETBOOT: ::c_int = 40; -pub const KERN_SYSV: ::c_int = 42; -pub const KERN_AFFINITY: ::c_int = 43; -pub const KERN_TRANSLATE: ::c_int = 44; -pub const KERN_CLASSIC: ::c_int = KERN_TRANSLATE; -pub const KERN_EXEC: ::c_int = 45; -pub const KERN_CLASSICHANDLER: ::c_int = KERN_EXEC; -pub const KERN_AIOMAX: ::c_int = 46; -pub const KERN_AIOPROCMAX: ::c_int = 47; -pub const KERN_AIOTHREADS: ::c_int = 48; -pub const KERN_COREFILE: ::c_int = 50; -pub const KERN_COREDUMP: ::c_int = 51; -pub const KERN_SUGID_COREDUMP: ::c_int = 52; -pub const KERN_PROCDELAYTERM: ::c_int = 53; -pub const KERN_SHREG_PRIVATIZABLE: ::c_int = 54; -pub const KERN_LOW_PRI_WINDOW: ::c_int = 56; -pub const KERN_LOW_PRI_DELAY: ::c_int = 57; -pub const KERN_POSIX: ::c_int = 58; -pub const KERN_USRSTACK64: ::c_int = 59; -pub const KERN_NX_PROTECTION: ::c_int = 60; -pub const KERN_TFP: ::c_int = 61; -pub const KERN_PROCNAME: ::c_int = 62; -pub const KERN_THALTSTACK: ::c_int = 63; -pub const KERN_SPECULATIVE_READS: ::c_int = 64; -pub const KERN_OSVERSION: ::c_int = 65; -pub const KERN_SAFEBOOT: ::c_int = 66; -pub const KERN_RAGEVNODE: ::c_int = 68; -pub const KERN_TTY: ::c_int = 69; -pub const KERN_CHECKOPENEVT: ::c_int = 70; -pub const KERN_THREADNAME: ::c_int = 71; -pub const KERN_MAXID: ::c_int = 72; -pub const KERN_RAGE_PROC: ::c_int = 1; -pub const KERN_RAGE_THREAD: ::c_int = 2; -pub const KERN_UNRAGE_PROC: ::c_int = 3; -pub const KERN_UNRAGE_THREAD: ::c_int = 4; -pub const KERN_OPENEVT_PROC: ::c_int = 1; -pub const KERN_UNOPENEVT_PROC: ::c_int = 2; -pub const KERN_TFP_POLICY: ::c_int = 1; -pub const KERN_TFP_POLICY_DENY: ::c_int = 0; -pub const KERN_TFP_POLICY_DEFAULT: ::c_int = 2; -pub const KERN_KDEFLAGS: ::c_int = 1; -pub const KERN_KDDFLAGS: ::c_int = 2; -pub const KERN_KDENABLE: ::c_int = 3; -pub const KERN_KDSETBUF: ::c_int = 4; -pub const KERN_KDGETBUF: ::c_int = 5; -pub const KERN_KDSETUP: ::c_int = 6; -pub const KERN_KDREMOVE: ::c_int = 7; -pub const KERN_KDSETREG: ::c_int = 8; -pub const KERN_KDGETREG: ::c_int = 9; -pub const KERN_KDREADTR: ::c_int = 10; -pub const KERN_KDPIDTR: ::c_int = 11; -pub const KERN_KDTHRMAP: ::c_int = 12; -pub const KERN_KDPIDEX: ::c_int = 14; -pub const KERN_KDSETRTCDEC: ::c_int = 15; -pub const KERN_KDGETENTROPY: ::c_int = 16; -pub const KERN_KDWRITETR: ::c_int = 17; -pub const KERN_KDWRITEMAP: ::c_int = 18; -#[doc(hidden)] -#[deprecated(since = "0.2.49", note = "Removed in MacOSX 10.12")] -pub const KERN_KDENABLE_BG_TRACE: ::c_int = 19; -#[doc(hidden)] -#[deprecated(since = "0.2.49", note = "Removed in MacOSX 10.12")] -pub const KERN_KDDISABLE_BG_TRACE: ::c_int = 20; -pub const KERN_KDREADCURTHRMAP: ::c_int = 21; -pub const KERN_KDSET_TYPEFILTER: ::c_int = 22; -pub const KERN_KDBUFWAIT: ::c_int = 23; -pub const KERN_KDCPUMAP: ::c_int = 24; -pub const KERN_PROC_ALL: ::c_int = 0; -pub const KERN_PROC_PID: ::c_int = 1; -pub const KERN_PROC_PGRP: ::c_int = 2; -pub const KERN_PROC_SESSION: ::c_int = 3; -pub const KERN_PROC_TTY: ::c_int = 4; -pub const KERN_PROC_UID: ::c_int = 5; -pub const KERN_PROC_RUID: ::c_int = 6; -pub const KERN_PROC_LCID: ::c_int = 7; -pub const KIPC_MAXSOCKBUF: ::c_int = 1; -pub const KIPC_SOCKBUF_WASTE: ::c_int = 2; -pub const KIPC_SOMAXCONN: ::c_int = 3; -pub const KIPC_MAX_LINKHDR: ::c_int = 4; -pub const KIPC_MAX_PROTOHDR: ::c_int = 5; -pub const KIPC_MAX_HDR: ::c_int = 6; -pub const KIPC_MAX_DATALEN: ::c_int = 7; -pub const KIPC_MBSTAT: ::c_int = 8; -pub const KIPC_NMBCLUSTERS: ::c_int = 9; -pub const KIPC_SOQLIMITCOMPAT: ::c_int = 10; -pub const VM_METER: ::c_int = 1; -pub const VM_LOADAVG: ::c_int = 2; -pub const VM_MACHFACTOR: ::c_int = 4; -pub const VM_SWAPUSAGE: ::c_int = 5; -pub const VM_MAXID: ::c_int = 6; -pub const HW_MACHINE: ::c_int = 1; -pub const HW_MODEL: ::c_int = 2; -pub const HW_NCPU: ::c_int = 3; -pub const HW_BYTEORDER: ::c_int = 4; -pub const HW_PHYSMEM: ::c_int = 5; -pub const HW_USERMEM: ::c_int = 6; -pub const HW_PAGESIZE: ::c_int = 7; -pub const HW_DISKNAMES: ::c_int = 8; -pub const HW_DISKSTATS: ::c_int = 9; -pub const HW_EPOCH: ::c_int = 10; -pub const HW_FLOATINGPT: ::c_int = 11; -pub const HW_MACHINE_ARCH: ::c_int = 12; -pub const HW_VECTORUNIT: ::c_int = 13; -pub const HW_BUS_FREQ: ::c_int = 14; -pub const HW_CPU_FREQ: ::c_int = 15; -pub const HW_CACHELINE: ::c_int = 16; -pub const HW_L1ICACHESIZE: ::c_int = 17; -pub const HW_L1DCACHESIZE: ::c_int = 18; -pub const HW_L2SETTINGS: ::c_int = 19; -pub const HW_L2CACHESIZE: ::c_int = 20; -pub const HW_L3SETTINGS: ::c_int = 21; -pub const HW_L3CACHESIZE: ::c_int = 22; -pub const HW_TB_FREQ: ::c_int = 23; -pub const HW_MEMSIZE: ::c_int = 24; -pub const HW_AVAILCPU: ::c_int = 25; -pub const HW_MAXID: ::c_int = 26; -pub const USER_CS_PATH: ::c_int = 1; -pub const USER_BC_BASE_MAX: ::c_int = 2; -pub const USER_BC_DIM_MAX: ::c_int = 3; -pub const USER_BC_SCALE_MAX: ::c_int = 4; -pub const USER_BC_STRING_MAX: ::c_int = 5; -pub const USER_COLL_WEIGHTS_MAX: ::c_int = 6; -pub const USER_EXPR_NEST_MAX: ::c_int = 7; -pub const USER_LINE_MAX: ::c_int = 8; -pub const USER_RE_DUP_MAX: ::c_int = 9; -pub const USER_POSIX2_VERSION: ::c_int = 10; -pub const USER_POSIX2_C_BIND: ::c_int = 11; -pub const USER_POSIX2_C_DEV: ::c_int = 12; -pub const USER_POSIX2_CHAR_TERM: ::c_int = 13; -pub const USER_POSIX2_FORT_DEV: ::c_int = 14; -pub const USER_POSIX2_FORT_RUN: ::c_int = 15; -pub const USER_POSIX2_LOCALEDEF: ::c_int = 16; -pub const USER_POSIX2_SW_DEV: ::c_int = 17; -pub const USER_POSIX2_UPE: ::c_int = 18; -pub const USER_STREAM_MAX: ::c_int = 19; -pub const USER_TZNAME_MAX: ::c_int = 20; -pub const USER_MAXID: ::c_int = 21; -pub const CTL_DEBUG_NAME: ::c_int = 0; -pub const CTL_DEBUG_VALUE: ::c_int = 1; -pub const CTL_DEBUG_MAXID: ::c_int = 20; - -pub const PRIO_DARWIN_THREAD: ::c_int = 3; -pub const PRIO_DARWIN_PROCESS: ::c_int = 4; -pub const PRIO_DARWIN_BG: ::c_int = 0x1000; -pub const PRIO_DARWIN_NONUI: ::c_int = 0x1001; - -pub const SEM_FAILED: *mut sem_t = -1isize as *mut ::sem_t; - -pub const AI_PASSIVE: ::c_int = 0x00000001; -pub const AI_CANONNAME: ::c_int = 0x00000002; -pub const AI_NUMERICHOST: ::c_int = 0x00000004; -pub const AI_NUMERICSERV: ::c_int = 0x00001000; -pub const AI_MASK: ::c_int = AI_PASSIVE - | AI_CANONNAME - | AI_NUMERICHOST - | AI_NUMERICSERV - | AI_ADDRCONFIG; -pub const AI_ALL: ::c_int = 0x00000100; -pub const AI_V4MAPPED_CFG: ::c_int = 0x00000200; -pub const AI_ADDRCONFIG: ::c_int = 0x00000400; -pub const AI_V4MAPPED: ::c_int = 0x00000800; -pub const AI_DEFAULT: ::c_int = AI_V4MAPPED_CFG | AI_ADDRCONFIG; -pub const AI_UNUSABLE: ::c_int = 0x10000000; - -pub const SIGEV_NONE: ::c_int = 0; -pub const SIGEV_SIGNAL: ::c_int = 1; -pub const SIGEV_THREAD: ::c_int = 3; - -pub const AIO_CANCELED: ::c_int = 2; -pub const AIO_NOTCANCELED: ::c_int = 4; -pub const AIO_ALLDONE: ::c_int = 1; -#[deprecated( - since = "0.2.64", - note = "Can vary at runtime. Use sysconf(3) instead" -)] -pub const AIO_LISTIO_MAX: ::c_int = 16; -pub const LIO_NOP: ::c_int = 0; -pub const LIO_WRITE: ::c_int = 2; -pub const LIO_READ: ::c_int = 1; -pub const LIO_WAIT: ::c_int = 2; -pub const LIO_NOWAIT: ::c_int = 1; - -pub const WEXITED: ::c_int = 0x00000004; -pub const WSTOPPED: ::c_int = 0x00000008; -pub const WCONTINUED: ::c_int = 0x00000010; -pub const WNOWAIT: ::c_int = 0x00000020; - -pub const P_ALL: idtype_t = 0; -pub const P_PID: idtype_t = 1; -pub const P_PGID: idtype_t = 2; - -pub const UTIME_OMIT: c_long = -2; -pub const UTIME_NOW: c_long = -1; - -pub const XATTR_NOFOLLOW: ::c_int = 0x0001; -pub const XATTR_CREATE: ::c_int = 0x0002; -pub const XATTR_REPLACE: ::c_int = 0x0004; -pub const XATTR_NOSECURITY: ::c_int = 0x0008; -pub const XATTR_NODEFAULT: ::c_int = 0x0010; -pub const XATTR_SHOWCOMPRESSION: ::c_int = 0x0020; - -pub const NET_RT_IFLIST2: ::c_int = 0x0006; - -// net/route.h -pub const RTF_UP: ::c_int = 0x1; -pub const RTF_GATEWAY: ::c_int = 0x2; -pub const RTF_HOST: ::c_int = 0x4; -pub const RTF_REJECT: ::c_int = 0x8; -pub const RTF_DYNAMIC: ::c_int = 0x10; -pub const RTF_MODIFIED: ::c_int = 0x20; -pub const RTF_DONE: ::c_int = 0x40; -pub const RTF_DELCLONE: ::c_int = 0x80; -pub const RTF_CLONING: ::c_int = 0x100; -pub const RTF_XRESOLVE: ::c_int = 0x200; -pub const RTF_LLINFO: ::c_int = 0x400; -pub const RTF_STATIC: ::c_int = 0x800; -pub const RTF_BLACKHOLE: ::c_int = 0x1000; -pub const RTF_NOIFREF: ::c_int = 0x2000; -pub const RTF_PROTO2: ::c_int = 0x4000; -pub const RTF_PROTO1: ::c_int = 0x8000; -pub const RTF_PRCLONING: ::c_int = 0x10000; -pub const RTF_WASCLONED: ::c_int = 0x20000; -pub const RTF_PROTO3: ::c_int = 0x40000; -pub const RTF_PINNED: ::c_int = 0x100000; -pub const RTF_LOCAL: ::c_int = 0x200000; -pub const RTF_BROADCAST: ::c_int = 0x400000; -pub const RTF_MULTICAST: ::c_int = 0x800000; -pub const RTF_IFSCOPE: ::c_int = 0x1000000; -pub const RTF_CONDEMNED: ::c_int = 0x2000000; -pub const RTF_IFREF: ::c_int = 0x4000000; -pub const RTF_PROXY: ::c_int = 0x8000000; -pub const RTF_ROUTER: ::c_int = 0x10000000; - -pub const RTM_VERSION: ::c_int = 5; - -// Message types -pub const RTM_ADD: ::c_int = 0x1; -pub const RTM_DELETE: ::c_int = 0x2; -pub const RTM_CHANGE: ::c_int = 0x3; -pub const RTM_GET: ::c_int = 0x4; -pub const RTM_LOSING: ::c_int = 0x5; -pub const RTM_REDIRECT: ::c_int = 0x6; -pub const RTM_MISS: ::c_int = 0x7; -pub const RTM_LOCK: ::c_int = 0x8; -pub const RTM_OLDADD: ::c_int = 0x9; -pub const RTM_OLDDEL: ::c_int = 0xa; -pub const RTM_RESOLVE: ::c_int = 0xb; -pub const RTM_NEWADDR: ::c_int = 0xc; -pub const RTM_DELADDR: ::c_int = 0xd; -pub const RTM_IFINFO: ::c_int = 0xe; -pub const RTM_NEWMADDR: ::c_int = 0xf; -pub const RTM_DELMADDR: ::c_int = 0x10; -pub const RTM_IFINFO2: ::c_int = 0x12; -pub const RTM_NEWMADDR2: ::c_int = 0x13; -pub const RTM_GET2: ::c_int = 0x14; - -// Bitmask values for rtm_inits and rmx_locks. -pub const RTV_MTU: ::c_int = 0x1; -pub const RTV_HOPCOUNT: ::c_int = 0x2; -pub const RTV_EXPIRE: ::c_int = 0x4; -pub const RTV_RPIPE: ::c_int = 0x8; -pub const RTV_SPIPE: ::c_int = 0x10; -pub const RTV_SSTHRESH: ::c_int = 0x20; -pub const RTV_RTT: ::c_int = 0x40; -pub const RTV_RTTVAR: ::c_int = 0x80; - -// Bitmask values for rtm_addrs. -pub const RTA_DST: ::c_int = 0x1; -pub const RTA_GATEWAY: ::c_int = 0x2; -pub const RTA_NETMASK: ::c_int = 0x4; -pub const RTA_GENMASK: ::c_int = 0x8; -pub const RTA_IFP: ::c_int = 0x10; -pub const RTA_IFA: ::c_int = 0x20; -pub const RTA_AUTHOR: ::c_int = 0x40; -pub const RTA_BRD: ::c_int = 0x80; - -// Index offsets for sockaddr array for alternate internal encoding. -pub const RTAX_DST: ::c_int = 0; -pub const RTAX_GATEWAY: ::c_int = 1; -pub const RTAX_NETMASK: ::c_int = 2; -pub const RTAX_GENMASK: ::c_int = 3; -pub const RTAX_IFP: ::c_int = 4; -pub const RTAX_IFA: ::c_int = 5; -pub const RTAX_AUTHOR: ::c_int = 6; -pub const RTAX_BRD: ::c_int = 7; -pub const RTAX_MAX: ::c_int = 8; - -pub const KERN_PROCARGS2: ::c_int = 49; - -pub const PROC_PIDTASKALLINFO: ::c_int = 2; -pub const PROC_PIDTASKINFO: ::c_int = 4; -pub const PROC_PIDTHREADINFO: ::c_int = 5; -pub const MAXCOMLEN: usize = 16; -pub const MAXTHREADNAMESIZE: usize = 64; - -pub const XUCRED_VERSION: ::c_uint = 0; - -pub const LC_SEGMENT: u32 = 0x1; -pub const LC_SEGMENT_64: u32 = 0x19; - -pub const MH_MAGIC: u32 = 0xfeedface; -pub const MH_MAGIC_64: u32 = 0xfeedfacf; - -// net/if_utun.h -pub const UTUN_OPT_FLAGS: ::c_int = 1; -pub const UTUN_OPT_IFNAME: ::c_int = 2; - -// net/bpf.h -pub const DLT_NULL: ::c_uint = 0; // no link-layer encapsulation -pub const DLT_EN10MB: ::c_uint = 1; // Ethernet (10Mb) -pub const DLT_EN3MB: ::c_uint = 2; // Experimental Ethernet (3Mb) -pub const DLT_AX25: ::c_uint = 3; // Amateur Radio AX.25 -pub const DLT_PRONET: ::c_uint = 4; // Proteon ProNET Token Ring -pub const DLT_CHAOS: ::c_uint = 5; // Chaos -pub const DLT_IEEE802: ::c_uint = 6; // IEEE 802 Networks -pub const DLT_ARCNET: ::c_uint = 7; // ARCNET -pub const DLT_SLIP: ::c_uint = 8; // Serial Line IP -pub const DLT_PPP: ::c_uint = 9; // Point-to-point Protocol -pub const DLT_FDDI: ::c_uint = 10; // FDDI -pub const DLT_ATM_RFC1483: ::c_uint = 11; // LLC/SNAP encapsulated atm -pub const DLT_RAW: ::c_uint = 12; // raw IP -pub const DLT_LOOP: ::c_uint = 108; - -// https://github.com/apple/darwin-xnu/blob/master/bsd/net/bpf.h#L100 -// sizeof(i32) -pub const BPF_ALIGNMENT: ::c_int = 4; - -// sys/spawn.h: -pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x01; -pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x02; -pub const POSIX_SPAWN_SETSIGDEF: ::c_int = 0x04; -pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x08; -pub const POSIX_SPAWN_SETEXEC: ::c_int = 0x40; -pub const POSIX_SPAWN_START_SUSPENDED: ::c_int = 0x80; -pub const POSIX_SPAWN_CLOEXEC_DEFAULT: ::c_int = 0x4000; - -// sys/ipc.h: -pub const IPC_CREAT: ::c_int = 0x200; -pub const IPC_EXCL: ::c_int = 0x400; -pub const IPC_NOWAIT: ::c_int = 0x800; -pub const IPC_PRIVATE: key_t = 0; - -pub const IPC_RMID: ::c_int = 0; -pub const IPC_SET: ::c_int = 1; -pub const IPC_STAT: ::c_int = 2; - -pub const IPC_R: ::c_int = 0x100; -pub const IPC_W: ::c_int = 0x80; -pub const IPC_M: ::c_int = 0x1000; - -// sys/sem.h -pub const SEM_UNDO: ::c_int = 0o10000; - -pub const GETNCNT: ::c_int = 3; -pub const GETPID: ::c_int = 4; -pub const GETVAL: ::c_int = 5; -pub const GETALL: ::c_int = 6; -pub const GETZCNT: ::c_int = 7; -pub const SETVAL: ::c_int = 8; -pub const SETALL: ::c_int = 9; - -// sys/shm.h -pub const SHM_RDONLY: ::c_int = 0x1000; -pub const SHM_RND: ::c_int = 0x2000; -pub const SHMLBA: ::c_int = 4096; -pub const SHM_R: ::c_int = IPC_R; -pub const SHM_W: ::c_int = IPC_W; - -// Flags for chflags(2) -pub const UF_SETTABLE: ::c_uint = 0x0000ffff; -pub const UF_NODUMP: ::c_uint = 0x00000001; -pub const UF_IMMUTABLE: ::c_uint = 0x00000002; -pub const UF_APPEND: ::c_uint = 0x00000004; -pub const UF_OPAQUE: ::c_uint = 0x00000008; -pub const UF_COMPRESSED: ::c_uint = 0x00000020; -pub const UF_TRACKED: ::c_uint = 0x00000040; -pub const SF_SETTABLE: ::c_uint = 0xffff0000; -pub const SF_ARCHIVED: ::c_uint = 0x00010000; -pub const SF_IMMUTABLE: ::c_uint = 0x00020000; -pub const SF_APPEND: ::c_uint = 0x00040000; -pub const UF_HIDDEN: ::c_uint = 0x00008000; - -cfg_if! { - if #[cfg(libc_const_size_of)] { - fn __DARWIN_ALIGN32(p: usize) -> usize { - const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::() - 1; - p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 - } - } else { - fn __DARWIN_ALIGN32(p: usize) -> usize { - let __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::() - 1; - p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 - } - } -} - -f! { - pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, - cmsg: *const ::cmsghdr) -> *mut ::cmsghdr { - if cmsg.is_null() { - return ::CMSG_FIRSTHDR(mhdr); - }; - let cmsg_len = (*cmsg).cmsg_len as usize; - let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len as usize); - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next + __DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) > max { - 0 as *mut ::cmsghdr - } else { - next as *mut ::cmsghdr - } - } - - pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { - (cmsg as *mut ::c_uchar) - .offset(__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) as isize) - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) - + __DARWIN_ALIGN32(length as usize)) - as ::c_uint - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - (__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) + length as usize) - as ::c_uint - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - status >> 8 - } - - pub fn _WSTATUS(status: ::c_int) -> ::c_int { - status & 0x7f - } - - pub fn WIFCONTINUED(status: ::c_int) -> bool { - _WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) == 0x13 - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - _WSTATUS(status) != _WSTOPPED && _WSTATUS(status) != 0 - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - _WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) != 0x13 - } -} - -extern "C" { - pub fn setgrent(); - #[doc(hidden)] - #[deprecated(since = "0.2.49", note = "Deprecated in MacOSX 10.5")] - #[link_name = "daemon$1050"] - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - #[doc(hidden)] - #[deprecated(since = "0.2.49", note = "Deprecated in MacOSX 10.10")] - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - #[doc(hidden)] - #[deprecated(since = "0.2.49", note = "Deprecated in MacOSX 10.10")] - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_error(aiocbp: *const aiocb) -> ::c_int; - pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "aio_suspend$UNIX2003" - )] - pub fn aio_suspend( - aiocb_list: *const *const aiocb, - nitems: ::c_int, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn aio_cancel(fd: ::c_int, aiocbp: *mut aiocb) -> ::c_int; - pub fn chflags(path: *const ::c_char, flags: ::c_uint) -> ::c_int; - pub fn fchflags(fd: ::c_int, flags: ::c_uint) -> ::c_int; - pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn lio_listio( - mode: ::c_int, - aiocb_list: *const *mut aiocb, - nitems: ::c_int, - sevp: *mut sigevent, - ) -> ::c_int; - - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - - pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn getutxent() -> *mut utmpx; - pub fn getutxid(ut: *const utmpx) -> *mut utmpx; - pub fn getutxline(ut: *const utmpx) -> *mut utmpx; - pub fn pututxline(ut: *const utmpx) -> *mut utmpx; - pub fn setutxent(); - pub fn endutxent(); - pub fn utmpxname(file: *const ::c_char) -> ::c_int; - - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::socklen_t, - serv: *mut ::c_char, - sevlen: ::socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn mincore( - addr: *const ::c_void, - len: ::size_t, - vec: *mut ::c_char, - ) -> ::c_int; - pub fn sysctlnametomib( - name: *const ::c_char, - mibp: *mut ::c_int, - sizep: *mut ::size_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "mprotect$UNIX2003" - )] - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn semget(key: key_t, nsems: ::c_int, semflg: ::c_int) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "semctl$UNIX2003" - )] - pub fn semctl( - semid: ::c_int, - semnum: ::c_int, - cmd: ::c_int, - ... - ) -> ::c_int; - pub fn semop( - semid: ::c_int, - sops: *mut sembuf, - nsops: ::size_t, - ) -> ::c_int; - pub fn shm_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::c_int; - pub fn ftok(pathname: *const c_char, proj_id: ::c_int) -> key_t; - pub fn shmat( - shmid: ::c_int, - shmaddr: *const ::c_void, - shmflg: ::c_int, - ) -> *mut ::c_void; - pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "shmctl$UNIX2003" - )] - pub fn shmctl( - shmid: ::c_int, - cmd: ::c_int, - buf: *mut ::shmid_ds, - ) -> ::c_int; - pub fn shmget(key: key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int; - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_uint, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; - pub fn sysctlbyname( - name: *const ::c_char, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; - #[deprecated(since = "0.2.55", note = "Use the mach crate")] - pub fn mach_absolute_time() -> u64; - #[deprecated(since = "0.2.55", note = "Use the mach crate")] - #[allow(deprecated)] - pub fn mach_timebase_info(info: *mut ::mach_timebase_info) -> ::c_int; - pub fn pthread_setname_np(name: *const ::c_char) -> ::c_int; - pub fn pthread_getname_np( - thread: ::pthread_t, - name: *mut ::c_char, - len: ::size_t, - ) -> ::c_int; - pub fn pthread_get_stackaddr_np(thread: ::pthread_t) -> *mut ::c_void; - pub fn pthread_get_stacksize_np(thread: ::pthread_t) -> ::size_t; - pub fn pthread_condattr_setpshared( - attr: *mut pthread_condattr_t, - pshared: ::c_int, - ) -> ::c_int; - pub fn pthread_condattr_getpshared( - attr: *const pthread_condattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_mutexattr_setpshared( - attr: *mut pthread_mutexattr_t, - pshared: ::c_int, - ) -> ::c_int; - pub fn pthread_mutexattr_getpshared( - attr: *const pthread_mutexattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_getpshared( - attr: *const pthread_rwlockattr_t, - val: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_setpshared( - attr: *mut pthread_rwlockattr_t, - val: ::c_int, - ) -> ::c_int; - pub fn __error() -> *mut ::c_int; - pub fn backtrace(buf: *mut *mut ::c_void, sz: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "macos", link_name = "statfs$INODE64")] - pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; - #[cfg_attr(target_os = "macos", link_name = "fstatfs$INODE64")] - pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; - pub fn kevent( - kq: ::c_int, - changelist: *const ::kevent, - nchanges: ::c_int, - eventlist: *mut ::kevent, - nevents: ::c_int, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn kevent64( - kq: ::c_int, - changelist: *const ::kevent64_s, - nchanges: ::c_int, - eventlist: *mut ::kevent64_s, - nevents: ::c_int, - flags: ::c_uint, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn mount( - src: *const ::c_char, - target: *const ::c_char, - flags: ::c_int, - data: *mut ::c_void, - ) -> ::c_int; - pub fn ptrace( - request: ::c_int, - pid: ::pid_t, - addr: *mut ::c_char, - data: ::c_int, - ) -> ::c_int; - pub fn quotactl( - special: *const ::c_char, - cmd: ::c_int, - id: ::c_int, - data: *mut ::c_char, - ) -> ::c_int; - pub fn sethostname(name: *const ::c_char, len: ::c_int) -> ::c_int; - pub fn sendfile( - fd: ::c_int, - s: ::c_int, - offset: ::off_t, - len: *mut ::off_t, - hdtr: *mut ::sf_hdtr, - flags: ::c_int, - ) -> ::c_int; - pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; - pub fn utimensat( - dirfd: ::c_int, - path: *const ::c_char, - times: *const ::timespec, - flag: ::c_int, - ) -> ::c_int; - pub fn openpty( - amaster: *mut ::c_int, - aslave: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::c_int; - pub fn forkpty( - amaster: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::pid_t; - pub fn login_tty(fd: ::c_int) -> ::c_int; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn freelocale(loc: ::locale_t) -> ::c_int; - pub fn localeconv_l(loc: ::locale_t) -> *mut lconv; - pub fn newlocale( - mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t, - ) -> ::locale_t; - pub fn uselocale(loc: ::locale_t) -> ::locale_t; - pub fn querylocale(mask: ::c_int, loc: ::locale_t) -> *const ::c_char; - pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int; - pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int; - pub fn getdomainname(name: *mut ::c_char, len: ::c_int) -> ::c_int; - pub fn setdomainname(name: *const ::c_char, len: ::c_int) -> ::c_int; - pub fn getxattr( - path: *const ::c_char, - name: *const ::c_char, - value: *mut ::c_void, - size: ::size_t, - position: u32, - flags: ::c_int, - ) -> ::ssize_t; - pub fn fgetxattr( - filedes: ::c_int, - name: *const ::c_char, - value: *mut ::c_void, - size: ::size_t, - position: u32, - flags: ::c_int, - ) -> ::ssize_t; - pub fn setxattr( - path: *const ::c_char, - name: *const ::c_char, - value: *const ::c_void, - size: ::size_t, - position: u32, - flags: ::c_int, - ) -> ::c_int; - pub fn fsetxattr( - filedes: ::c_int, - name: *const ::c_char, - value: *const ::c_void, - size: ::size_t, - position: u32, - flags: ::c_int, - ) -> ::c_int; - pub fn listxattr( - path: *const ::c_char, - list: *mut ::c_char, - size: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - pub fn flistxattr( - filedes: ::c_int, - list: *mut ::c_char, - size: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - pub fn removexattr( - path: *const ::c_char, - name: *const ::c_char, - flags: ::c_int, - ) -> ::c_int; - pub fn renamex_np( - from: *const ::c_char, - to: *const ::c_char, - flags: ::c_uint, - ) -> ::c_int; - pub fn renameatx_np( - fromfd: ::c_int, - from: *const ::c_char, - tofd: ::c_int, - to: *const ::c_char, - flags: ::c_uint, - ) -> ::c_int; - pub fn fremovexattr( - filedes: ::c_int, - name: *const ::c_char, - flags: ::c_int, - ) -> ::c_int; - - pub fn getgrouplist( - name: *const ::c_char, - basegid: ::c_int, - groups: *mut ::c_int, - ngroups: *mut ::c_int, - ) -> ::c_int; - pub fn initgroups(user: *const ::c_char, basegroup: ::c_int) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "waitid$UNIX2003" - )] - pub fn waitid( - idtype: idtype_t, - id: id_t, - infop: *mut ::siginfo_t, - options: ::c_int, - ) -> ::c_int; - pub fn brk(addr: *const ::c_void) -> *mut ::c_void; - pub fn sbrk(increment: ::c_int) -> *mut ::c_void; - pub fn settimeofday( - tv: *const ::timeval, - tz: *const ::timezone, - ) -> ::c_int; - #[deprecated(since = "0.2.55", note = "Use the mach crate")] - pub fn _dyld_image_count() -> u32; - #[deprecated(since = "0.2.55", note = "Use the mach crate")] - #[allow(deprecated)] - pub fn _dyld_get_image_header(image_index: u32) -> *const mach_header; - #[deprecated(since = "0.2.55", note = "Use the mach crate")] - pub fn _dyld_get_image_vmaddr_slide(image_index: u32) -> ::intptr_t; - #[deprecated(since = "0.2.55", note = "Use the mach crate")] - pub fn _dyld_get_image_name(image_index: u32) -> *const ::c_char; - - pub fn posix_spawn( - pid: *mut ::pid_t, - path: *const ::c_char, - file_actions: *const ::posix_spawn_file_actions_t, - attrp: *const ::posix_spawnattr_t, - argv: *const *mut ::c_char, - envp: *const *mut ::c_char, - ) -> ::c_int; - pub fn posix_spawnp( - pid: *mut ::pid_t, - file: *const ::c_char, - file_actions: *const ::posix_spawn_file_actions_t, - attrp: *const ::posix_spawnattr_t, - argv: *const *mut ::c_char, - envp: *const *mut ::c_char, - ) -> ::c_int; - pub fn posix_spawnattr_init(attr: *mut posix_spawnattr_t) -> ::c_int; - pub fn posix_spawnattr_destroy(attr: *mut posix_spawnattr_t) -> ::c_int; - pub fn posix_spawnattr_getsigdefault( - attr: *const posix_spawnattr_t, - default: *mut ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_setsigdefault( - attr: *mut posix_spawnattr_t, - default: *const ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_getsigmask( - attr: *const posix_spawnattr_t, - default: *mut ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_setsigmask( - attr: *mut posix_spawnattr_t, - default: *const ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_getflags( - attr: *const posix_spawnattr_t, - flags: *mut ::c_short, - ) -> ::c_int; - pub fn posix_spawnattr_setflags( - attr: *mut posix_spawnattr_t, - flags: ::c_short, - ) -> ::c_int; - pub fn posix_spawnattr_getpgroup( - attr: *const posix_spawnattr_t, - flags: *mut ::pid_t, - ) -> ::c_int; - pub fn posix_spawnattr_setpgroup( - attr: *mut posix_spawnattr_t, - flags: ::pid_t, - ) -> ::c_int; - - pub fn posix_spawn_file_actions_init( - actions: *mut posix_spawn_file_actions_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_destroy( - actions: *mut posix_spawn_file_actions_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_addopen( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - path: *const ::c_char, - oflag: ::c_int, - mode: ::mode_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_addclose( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - ) -> ::c_int; - pub fn posix_spawn_file_actions_adddup2( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - newfd: ::c_int, - ) -> ::c_int; - pub fn uname(buf: *mut ::utsname) -> ::c_int; -} - -cfg_if! { - if #[cfg(any(target_arch = "arm", target_arch = "x86"))] { - mod b32; - pub use self::b32::*; - } else if #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] { - mod b64; - pub use self::b64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/bsd/freebsdlike/dragonfly/errno.rs b/libc/src/unix/bsd/freebsdlike/dragonfly/errno.rs deleted file mode 100644 index e9ad63b..0000000 --- a/libc/src/unix/bsd/freebsdlike/dragonfly/errno.rs +++ /dev/null @@ -1,12 +0,0 @@ -// DragonFlyBSD's __error function is declared with "static inline", so it must -// be implemented in the libc crate, as a pointer to a static thread_local. -f! { - pub fn __error() -> *mut ::c_int { - &mut errno - } -} - -extern "C" { - #[thread_local] - pub static mut errno: ::c_int; -} diff --git a/libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs deleted file mode 100644 index 63ca4db..0000000 --- a/libc/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ /dev/null @@ -1,1096 +0,0 @@ -pub type dev_t = u32; -pub type c_char = i8; -pub type clock_t = u64; -pub type ino_t = u64; -pub type lwpid_t = i32; -pub type nlink_t = u32; -pub type blksize_t = i64; -pub type clockid_t = ::c_ulong; - -pub type c_long = i64; -pub type c_ulong = u64; -pub type time_t = i64; -pub type suseconds_t = i64; - -pub type uuid_t = ::uuid; - -pub type fsblkcnt_t = u64; -pub type fsfilcnt_t = u64; - -pub type mqd_t = ::c_int; -pub type sem_t = *mut sem; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum sem {} -impl ::Copy for sem {} -impl ::Clone for sem { - fn clone(&self) -> sem { - *self - } -} - -s! { - pub struct kevent { - pub ident: ::uintptr_t, - pub filter: ::c_short, - pub flags: ::c_ushort, - pub fflags: ::c_uint, - pub data: ::intptr_t, - pub udata: *mut ::c_void, - } - - pub struct exit_status { - pub e_termination: u16, - pub e_exit: u16 - } - - pub struct aiocb { - pub aio_fildes: ::c_int, - pub aio_offset: ::off_t, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - pub aio_sigevent: sigevent, - pub aio_lio_opcode: ::c_int, - pub aio_reqprio: ::c_int, - _aio_val: ::c_int, - _aio_err: ::c_int - } - - pub struct uuid { - pub time_low: u32, - pub time_mid: u16, - pub time_hi_and_version: u16, - pub clock_seq_hi_and_reserved: u8, - pub clock_seq_low: u8, - pub node: [u8; 6], - } - - pub struct mq_attr { - pub mq_flags: ::c_long, - pub mq_maxmsg: ::c_long, - pub mq_msgsize: ::c_long, - pub mq_curmsgs: ::c_long, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - pub f_owner: ::uid_t, - pub f_type: ::c_uint, - pub f_syncreads: u64, - pub f_syncwrites: u64, - pub f_asyncreads: u64, - pub f_asyncwrites: u64, - pub f_fsid_uuid: ::uuid_t, - pub f_uid_uuid: ::uuid_t, - } - - pub struct stat { - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_dev: ::dev_t, - pub st_mode: ::mode_t, - pub st_padding1: u16, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: i64, - pub st_blksize: u32, - pub st_flags: u32, - pub st_gen: u32, - pub st_lspare: i32, - pub st_qspare1: i64, - pub st_qspare2: i64, - } - - pub struct if_data { - pub ifi_type: ::c_uchar, - pub ifi_physical: ::c_uchar, - pub ifi_addrlen: ::c_uchar, - pub ifi_hdrlen: ::c_uchar, - pub ifi_recvquota: ::c_uchar, - pub ifi_xmitquota: ::c_uchar, - pub ifi_mtu: ::c_ulong, - pub ifi_metric: ::c_ulong, - pub ifi_link_state: ::c_ulong, - pub ifi_baudrate: u64, - pub ifi_ipackets: ::c_ulong, - pub ifi_ierrors: ::c_ulong, - pub ifi_opackets: ::c_ulong, - pub ifi_oerrors: ::c_ulong, - pub ifi_collisions: ::c_ulong, - pub ifi_ibytes: ::c_ulong, - pub ifi_obytes: ::c_ulong, - pub ifi_imcasts: ::c_ulong, - pub ifi_omcasts: ::c_ulong, - pub ifi_iqdrops: ::c_ulong, - pub ifi_noproto: ::c_ulong, - pub ifi_hwassist: ::c_ulong, - pub ifi_oqdrops: ::c_ulong, - pub ifi_lastchange: ::timeval, - } - - pub struct if_msghdr { - pub ifm_msglen: ::c_ushort, - pub ifm_version: ::c_uchar, - pub ifm_type: ::c_uchar, - pub ifm_addrs: ::c_int, - pub ifm_flags: ::c_int, - pub ifm_index: ::c_ushort, - pub ifm_data: if_data, - } - - pub struct sockaddr_dl { - pub sdl_len: ::c_uchar, - pub sdl_family: ::c_uchar, - pub sdl_index: ::c_ushort, - pub sdl_type: ::c_uchar, - pub sdl_nlen: ::c_uchar, - pub sdl_alen: ::c_uchar, - pub sdl_slen: ::c_uchar, - pub sdl_data: [::c_char; 12], - pub sdl_rcf: ::c_ushort, - pub sdl_route: [::c_ushort; 16], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_char, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } -} - -s_no_extra_traits! { - pub struct utmpx { - pub ut_name: [::c_char; 32], - pub ut_id: [::c_char; 4], - - pub ut_line: [::c_char; 32], - pub ut_host: [::c_char; 256], - - pub ut_unused: [u8; 16], - pub ut_session: u16, - pub ut_type: u16, - pub ut_pid: ::pid_t, - ut_exit: exit_status, - ut_ss: ::sockaddr_storage, - pub ut_tv: ::timeval, - pub ut_unused2: [u8; 16], - } - - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_namlen: u16, - pub d_type: u8, - __unused1: u8, - __unused2: u32, - pub d_name: [::c_char; 256], - } - - pub struct statfs { - pub f_bsize: ::c_long, - pub f_iosize: ::c_long, - pub f_blocks: ::c_long, - pub f_bfree: ::c_long, - pub f_bavail: ::c_long, - pub f_files: ::c_long, - pub f_ffree: ::c_long, - pub f_fsid: ::fsid_t, - pub f_owner: ::uid_t, - pub f_type: i32, - pub f_flags: i32, - pub f_syncwrites: ::c_long, - pub f_asyncwrites: ::c_long, - pub f_fstypename: [::c_char; 16], - pub f_mntonname: [::c_char; 90], - pub f_syncreads: ::c_long, - pub f_asyncreads: ::c_long, - pub f_mntfromname: [::c_char; 90], - } - - pub struct sigevent { - pub sigev_notify: ::c_int, - // The union is 8-byte in size, so it is aligned at a 8-byte offset. - #[cfg(target_pointer_width = "64")] - __unused1: ::c_int, - pub sigev_signo: ::c_int, //actually a union - // pad the union - #[cfg(target_pointer_width = "64")] - __unused2: ::c_int, - pub sigev_value: ::sigval, - __unused3: *mut ::c_void //actually a function pointer - } - -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for utmpx { - fn eq(&self, other: &utmpx) -> bool { - self.ut_name == other.ut_name - && self.ut_id == other.ut_id - && self.ut_line == other.ut_line - && self - .ut_host - .iter() - .zip(other.ut_host.iter()) - .all(|(a,b)| a == b) - && self.ut_unused == other.ut_unused - && self.ut_session == other.ut_session - && self.ut_type == other.ut_type - && self.ut_pid == other.ut_pid - && self.ut_exit == other.ut_exit - && self.ut_ss == other.ut_ss - && self.ut_tv == other.ut_tv - && self.ut_unused2 == other.ut_unused2 - } - } - impl Eq for utmpx {} - impl ::fmt::Debug for utmpx { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utmpx") - .field("ut_name", &self.ut_name) - .field("ut_id", &self.ut_id) - .field("ut_line", &self.ut_line) - // FIXME: .field("ut_host", &self.ut_host) - .field("ut_unused", &self.ut_unused) - .field("ut_session", &self.ut_session) - .field("ut_type", &self.ut_type) - .field("ut_pid", &self.ut_pid) - .field("ut_exit", &self.ut_exit) - .field("ut_ss", &self.ut_ss) - .field("ut_tv", &self.ut_tv) - .field("ut_unused2", &self.ut_unused2) - .finish() - } - } - impl ::hash::Hash for utmpx { - fn hash(&self, state: &mut H) { - self.ut_name.hash(state); - self.ut_id.hash(state); - self.ut_line.hash(state); - self.ut_host.hash(state); - self.ut_unused.hash(state); - self.ut_session.hash(state); - self.ut_type.hash(state); - self.ut_pid.hash(state); - self.ut_exit.hash(state); - self.ut_ss.hash(state); - self.ut_tv.hash(state); - self.ut_unused2.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_fileno == other.d_fileno - && self.d_namlen == other.d_namlen - && self.d_type == other.d_type - // Ignore __unused1 - // Ignore __unused2 - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_fileno", &self.d_fileno) - .field("d_namlen", &self.d_namlen) - .field("d_type", &self.d_type) - // Ignore __unused1 - // Ignore __unused2 - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_fileno.hash(state); - self.d_namlen.hash(state); - self.d_type.hash(state); - // Ignore __unused1 - // Ignore __unused2 - self.d_name.hash(state); - } - } - - impl PartialEq for statfs { - fn eq(&self, other: &statfs) -> bool { - self.f_bsize == other.f_bsize - && self.f_iosize == other.f_iosize - && self.f_blocks == other.f_blocks - && self.f_bfree == other.f_bfree - && self.f_bavail == other.f_bavail - && self.f_files == other.f_files - && self.f_ffree == other.f_ffree - && self.f_fsid == other.f_fsid - && self.f_owner == other.f_owner - && self.f_type == other.f_type - && self.f_flags == other.f_flags - && self.f_syncwrites == other.f_syncwrites - && self.f_asyncwrites == other.f_asyncwrites - && self.f_fstypename == other.f_fstypename - && self - .f_mntonname - .iter() - .zip(other.f_mntonname.iter()) - .all(|(a,b)| a == b) - && self.f_syncreads == other.f_syncreads - && self.f_asyncreads == other.f_asyncreads - && self - .f_mntfromname - .iter() - .zip(other.f_mntfromname.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for statfs {} - impl ::fmt::Debug for statfs { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("statfs") - .field("f_bsize", &self.f_bsize) - .field("f_iosize", &self.f_iosize) - .field("f_blocks", &self.f_blocks) - .field("f_bfree", &self.f_bfree) - .field("f_bavail", &self.f_bavail) - .field("f_files", &self.f_files) - .field("f_ffree", &self.f_ffree) - .field("f_fsid", &self.f_fsid) - .field("f_owner", &self.f_owner) - .field("f_type", &self.f_type) - .field("f_flags", &self.f_flags) - .field("f_syncwrites", &self.f_syncwrites) - .field("f_asyncwrites", &self.f_asyncwrites) - // FIXME: .field("f_mntonname", &self.f_mntonname) - .field("f_syncreads", &self.f_syncreads) - .field("f_asyncreads", &self.f_asyncreads) - // FIXME: .field("f_mntfromname", &self.f_mntfromname) - .finish() - } - } - impl ::hash::Hash for statfs { - fn hash(&self, state: &mut H) { - self.f_bsize.hash(state); - self.f_iosize.hash(state); - self.f_blocks.hash(state); - self.f_bfree.hash(state); - self.f_bavail.hash(state); - self.f_files.hash(state); - self.f_ffree.hash(state); - self.f_fsid.hash(state); - self.f_owner.hash(state); - self.f_type.hash(state); - self.f_flags.hash(state); - self.f_syncwrites.hash(state); - self.f_asyncwrites.hash(state); - self.f_fstypename.hash(state); - self.f_mntonname.hash(state); - self.f_syncreads.hash(state); - self.f_asyncreads.hash(state); - self.f_mntfromname.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_notify == other.sigev_notify - && self.sigev_signo == other.sigev_signo - && self.sigev_value == other.sigev_value - } - } - impl Eq for sigevent {} - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_notify", &self.sigev_notify) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_value", &self.sigev_value) - .finish() - } - } - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_notify.hash(state); - self.sigev_signo.hash(state); - self.sigev_value.hash(state); - } - } - } -} - -pub const RAND_MAX: ::c_int = 0x7fff_ffff; -pub const PTHREAD_STACK_MIN: ::size_t = 16384; -pub const SIGSTKSZ: ::size_t = 40960; -pub const MADV_INVAL: ::c_int = 10; -pub const MADV_SETMAP: ::c_int = 11; -pub const O_CLOEXEC: ::c_int = 0x00020000; -pub const O_DIRECTORY: ::c_int = 0x08000000; -pub const F_GETLK: ::c_int = 7; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; -pub const ENOMEDIUM: ::c_int = 93; -pub const EASYNC: ::c_int = 99; -pub const ELAST: ::c_int = 99; -pub const RLIMIT_POSIXLOCKS: ::c_int = 11; -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] -pub const RLIM_NLIMITS: ::rlim_t = 12; - -pub const Q_GETQUOTA: ::c_int = 0x300; -pub const Q_SETQUOTA: ::c_int = 0x400; - -pub const CLOCK_REALTIME: ::clockid_t = 0; -pub const CLOCK_VIRTUAL: ::clockid_t = 1; -pub const CLOCK_PROF: ::clockid_t = 2; -pub const CLOCK_MONOTONIC: ::clockid_t = 4; -pub const CLOCK_UPTIME: ::clockid_t = 5; -pub const CLOCK_UPTIME_PRECISE: ::clockid_t = 7; -pub const CLOCK_UPTIME_FAST: ::clockid_t = 8; -pub const CLOCK_REALTIME_PRECISE: ::clockid_t = 9; -pub const CLOCK_REALTIME_FAST: ::clockid_t = 10; -pub const CLOCK_MONOTONIC_PRECISE: ::clockid_t = 11; -pub const CLOCK_MONOTONIC_FAST: ::clockid_t = 12; -pub const CLOCK_SECOND: ::clockid_t = 13; -pub const CLOCK_THREAD_CPUTIME_ID: ::clockid_t = 14; -pub const CLOCK_PROCESS_CPUTIME_ID: ::clockid_t = 15; - -pub const CTL_UNSPEC: ::c_int = 0; -pub const CTL_KERN: ::c_int = 1; -pub const CTL_VM: ::c_int = 2; -pub const CTL_VFS: ::c_int = 3; -pub const CTL_NET: ::c_int = 4; -pub const CTL_DEBUG: ::c_int = 5; -pub const CTL_HW: ::c_int = 6; -pub const CTL_MACHDEP: ::c_int = 7; -pub const CTL_USER: ::c_int = 8; -pub const CTL_P1003_1B: ::c_int = 9; -pub const CTL_LWKT: ::c_int = 10; -pub const CTL_MAXID: ::c_int = 11; -pub const KERN_OSTYPE: ::c_int = 1; -pub const KERN_OSRELEASE: ::c_int = 2; -pub const KERN_OSREV: ::c_int = 3; -pub const KERN_VERSION: ::c_int = 4; -pub const KERN_MAXVNODES: ::c_int = 5; -pub const KERN_MAXPROC: ::c_int = 6; -pub const KERN_MAXFILES: ::c_int = 7; -pub const KERN_ARGMAX: ::c_int = 8; -pub const KERN_SECURELVL: ::c_int = 9; -pub const KERN_HOSTNAME: ::c_int = 10; -pub const KERN_HOSTID: ::c_int = 11; -pub const KERN_CLOCKRATE: ::c_int = 12; -pub const KERN_VNODE: ::c_int = 13; -pub const KERN_PROC: ::c_int = 14; -pub const KERN_FILE: ::c_int = 15; -pub const KERN_PROF: ::c_int = 16; -pub const KERN_POSIX1: ::c_int = 17; -pub const KERN_NGROUPS: ::c_int = 18; -pub const KERN_JOB_CONTROL: ::c_int = 19; -pub const KERN_SAVED_IDS: ::c_int = 20; -pub const KERN_BOOTTIME: ::c_int = 21; -pub const KERN_NISDOMAINNAME: ::c_int = 22; -pub const KERN_UPDATEINTERVAL: ::c_int = 23; -pub const KERN_OSRELDATE: ::c_int = 24; -pub const KERN_NTP_PLL: ::c_int = 25; -pub const KERN_BOOTFILE: ::c_int = 26; -pub const KERN_MAXFILESPERPROC: ::c_int = 27; -pub const KERN_MAXPROCPERUID: ::c_int = 28; -pub const KERN_DUMPDEV: ::c_int = 29; -pub const KERN_IPC: ::c_int = 30; -pub const KERN_DUMMY: ::c_int = 31; -pub const KERN_PS_STRINGS: ::c_int = 32; -pub const KERN_USRSTACK: ::c_int = 33; -pub const KERN_LOGSIGEXIT: ::c_int = 34; -pub const KERN_IOV_MAX: ::c_int = 35; -pub const KERN_MAXPOSIXLOCKSPERUID: ::c_int = 36; -pub const KERN_MAXID: ::c_int = 37; -pub const KERN_PROC_ALL: ::c_int = 0; -pub const KERN_PROC_PID: ::c_int = 1; -pub const KERN_PROC_PGRP: ::c_int = 2; -pub const KERN_PROC_SESSION: ::c_int = 3; -pub const KERN_PROC_TTY: ::c_int = 4; -pub const KERN_PROC_UID: ::c_int = 5; -pub const KERN_PROC_RUID: ::c_int = 6; -pub const KERN_PROC_ARGS: ::c_int = 7; -pub const KERN_PROC_CWD: ::c_int = 8; -pub const KERN_PROC_PATHNAME: ::c_int = 9; -pub const KERN_PROC_FLAGMASK: ::c_int = 0x10; -pub const KERN_PROC_FLAG_LWP: ::c_int = 0x10; -pub const KIPC_MAXSOCKBUF: ::c_int = 1; -pub const KIPC_SOCKBUF_WASTE: ::c_int = 2; -pub const KIPC_SOMAXCONN: ::c_int = 3; -pub const KIPC_MAX_LINKHDR: ::c_int = 4; -pub const KIPC_MAX_PROTOHDR: ::c_int = 5; -pub const KIPC_MAX_HDR: ::c_int = 6; -pub const KIPC_MAX_DATALEN: ::c_int = 7; -pub const KIPC_MBSTAT: ::c_int = 8; -pub const KIPC_NMBCLUSTERS: ::c_int = 9; -pub const HW_MACHINE: ::c_int = 1; -pub const HW_MODEL: ::c_int = 2; -pub const HW_NCPU: ::c_int = 3; -pub const HW_BYTEORDER: ::c_int = 4; -pub const HW_PHYSMEM: ::c_int = 5; -pub const HW_USERMEM: ::c_int = 6; -pub const HW_PAGESIZE: ::c_int = 7; -pub const HW_DISKNAMES: ::c_int = 8; -pub const HW_DISKSTATS: ::c_int = 9; -pub const HW_FLOATINGPT: ::c_int = 10; -pub const HW_MACHINE_ARCH: ::c_int = 11; -pub const HW_MACHINE_PLATFORM: ::c_int = 12; -pub const HW_SENSORS: ::c_int = 13; -pub const HW_MAXID: ::c_int = 14; -pub const USER_CS_PATH: ::c_int = 1; -pub const USER_BC_BASE_MAX: ::c_int = 2; -pub const USER_BC_DIM_MAX: ::c_int = 3; -pub const USER_BC_SCALE_MAX: ::c_int = 4; -pub const USER_BC_STRING_MAX: ::c_int = 5; -pub const USER_COLL_WEIGHTS_MAX: ::c_int = 6; -pub const USER_EXPR_NEST_MAX: ::c_int = 7; -pub const USER_LINE_MAX: ::c_int = 8; -pub const USER_RE_DUP_MAX: ::c_int = 9; -pub const USER_POSIX2_VERSION: ::c_int = 10; -pub const USER_POSIX2_C_BIND: ::c_int = 11; -pub const USER_POSIX2_C_DEV: ::c_int = 12; -pub const USER_POSIX2_CHAR_TERM: ::c_int = 13; -pub const USER_POSIX2_FORT_DEV: ::c_int = 14; -pub const USER_POSIX2_FORT_RUN: ::c_int = 15; -pub const USER_POSIX2_LOCALEDEF: ::c_int = 16; -pub const USER_POSIX2_SW_DEV: ::c_int = 17; -pub const USER_POSIX2_UPE: ::c_int = 18; -pub const USER_STREAM_MAX: ::c_int = 19; -pub const USER_TZNAME_MAX: ::c_int = 20; -pub const USER_MAXID: ::c_int = 21; -pub const CTL_P1003_1B_ASYNCHRONOUS_IO: ::c_int = 1; -pub const CTL_P1003_1B_MAPPED_FILES: ::c_int = 2; -pub const CTL_P1003_1B_MEMLOCK: ::c_int = 3; -pub const CTL_P1003_1B_MEMLOCK_RANGE: ::c_int = 4; -pub const CTL_P1003_1B_MEMORY_PROTECTION: ::c_int = 5; -pub const CTL_P1003_1B_MESSAGE_PASSING: ::c_int = 6; -pub const CTL_P1003_1B_PRIORITIZED_IO: ::c_int = 7; -pub const CTL_P1003_1B_PRIORITY_SCHEDULING: ::c_int = 8; -pub const CTL_P1003_1B_REALTIME_SIGNALS: ::c_int = 9; -pub const CTL_P1003_1B_SEMAPHORES: ::c_int = 10; -pub const CTL_P1003_1B_FSYNC: ::c_int = 11; -pub const CTL_P1003_1B_SHARED_MEMORY_OBJECTS: ::c_int = 12; -pub const CTL_P1003_1B_SYNCHRONIZED_IO: ::c_int = 13; -pub const CTL_P1003_1B_TIMERS: ::c_int = 14; -pub const CTL_P1003_1B_AIO_LISTIO_MAX: ::c_int = 15; -pub const CTL_P1003_1B_AIO_MAX: ::c_int = 16; -pub const CTL_P1003_1B_AIO_PRIO_DELTA_MAX: ::c_int = 17; -pub const CTL_P1003_1B_DELAYTIMER_MAX: ::c_int = 18; -pub const CTL_P1003_1B_UNUSED1: ::c_int = 19; -pub const CTL_P1003_1B_PAGESIZE: ::c_int = 20; -pub const CTL_P1003_1B_RTSIG_MAX: ::c_int = 21; -pub const CTL_P1003_1B_SEM_NSEMS_MAX: ::c_int = 22; -pub const CTL_P1003_1B_SEM_VALUE_MAX: ::c_int = 23; -pub const CTL_P1003_1B_SIGQUEUE_MAX: ::c_int = 24; -pub const CTL_P1003_1B_TIMER_MAX: ::c_int = 25; -pub const CTL_P1003_1B_MAXID: ::c_int = 26; - -pub const EVFILT_READ: i16 = -1; -pub const EVFILT_WRITE: i16 = -2; -pub const EVFILT_AIO: i16 = -3; -pub const EVFILT_VNODE: i16 = -4; -pub const EVFILT_PROC: i16 = -5; -pub const EVFILT_SIGNAL: i16 = -6; -pub const EVFILT_TIMER: i16 = -7; -pub const EVFILT_EXCEPT: i16 = -8; -pub const EVFILT_USER: i16 = -9; -pub const EVFILT_FS: i16 = -10; - -pub const EV_ADD: u16 = 0x1; -pub const EV_DELETE: u16 = 0x2; -pub const EV_ENABLE: u16 = 0x4; -pub const EV_DISABLE: u16 = 0x8; -pub const EV_ONESHOT: u16 = 0x10; -pub const EV_CLEAR: u16 = 0x20; -pub const EV_RECEIPT: u16 = 0x40; -pub const EV_DISPATCH: u16 = 0x80; -pub const EV_NODATA: u16 = 0x1000; -pub const EV_FLAG1: u16 = 0x2000; -pub const EV_ERROR: u16 = 0x4000; -pub const EV_EOF: u16 = 0x8000; -pub const EV_SYSFLAGS: u16 = 0xf000; - -pub const NOTE_TRIGGER: u32 = 0x01000000; -pub const NOTE_FFNOP: u32 = 0x00000000; -pub const NOTE_FFAND: u32 = 0x40000000; -pub const NOTE_FFOR: u32 = 0x80000000; -pub const NOTE_FFCOPY: u32 = 0xc0000000; -pub const NOTE_FFCTRLMASK: u32 = 0xc0000000; -pub const NOTE_FFLAGSMASK: u32 = 0x00ffffff; -pub const NOTE_LOWAT: u32 = 0x00000001; -pub const NOTE_OOB: u32 = 0x00000002; -pub const NOTE_DELETE: u32 = 0x00000001; -pub const NOTE_WRITE: u32 = 0x00000002; -pub const NOTE_EXTEND: u32 = 0x00000004; -pub const NOTE_ATTRIB: u32 = 0x00000008; -pub const NOTE_LINK: u32 = 0x00000010; -pub const NOTE_RENAME: u32 = 0x00000020; -pub const NOTE_REVOKE: u32 = 0x00000040; -pub const NOTE_EXIT: u32 = 0x80000000; -pub const NOTE_FORK: u32 = 0x40000000; -pub const NOTE_EXEC: u32 = 0x20000000; -pub const NOTE_PDATAMASK: u32 = 0x000fffff; -pub const NOTE_PCTRLMASK: u32 = 0xf0000000; -pub const NOTE_TRACK: u32 = 0x00000001; -pub const NOTE_TRACKERR: u32 = 0x00000002; -pub const NOTE_CHILD: u32 = 0x00000004; - -pub const SO_SNDSPACE: ::c_int = 0x100a; -pub const SO_CPUHINT: ::c_int = 0x1030; - -pub const PT_FIRSTMACH: ::c_int = 32; - -// https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/sys/net/if.h#L101 -pub const IFF_UP: ::c_int = 0x1; // interface is up -pub const IFF_BROADCAST: ::c_int = 0x2; // broadcast address valid -pub const IFF_DEBUG: ::c_int = 0x4; // turn on debugging -pub const IFF_LOOPBACK: ::c_int = 0x8; // is a loopback net -pub const IFF_POINTOPOINT: ::c_int = 0x10; // interface is point-to-point link -pub const IFF_SMART: ::c_int = 0x20; // interface manages own routes -pub const IFF_RUNNING: ::c_int = 0x40; // resources allocated -pub const IFF_NOARP: ::c_int = 0x80; // no address resolution protocol -pub const IFF_PROMISC: ::c_int = 0x100; // receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x200; // receive all multicast packets -pub const IFF_OACTIVE_COMPAT: ::c_int = 0x400; // was transmission in progress -pub const IFF_SIMPLEX: ::c_int = 0x800; // can't hear own transmissions -pub const IFF_LINK0: ::c_int = 0x1000; // per link layer defined bit -pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit -pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit -pub const IFF_ALTPHYS: ::c_int = IFF_LINK2; // use alternate physical connection -pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast - // was interface is in polling mode -pub const IFF_POLLING_COMPAT: ::c_int = 0x10000; -pub const IFF_PPROMISC: ::c_int = 0x20000; // user-requested promisc mode -pub const IFF_MONITOR: ::c_int = 0x40000; // user-requested monitor mode -pub const IFF_STATICARP: ::c_int = 0x80000; // static ARP -pub const IFF_NPOLLING: ::c_int = 0x100000; // interface is in polling mode -pub const IFF_IDIRECT: ::c_int = 0x200000; // direct input - -// -// sys/netinet/in.h -// Protocols (RFC 1700) -// NOTE: These are in addition to the constants defined in src/unix/mod.rs - -// IPPROTO_IP defined in src/unix/mod.rs -/// IP6 hop-by-hop options -pub const IPPROTO_HOPOPTS: ::c_int = 0; -// IPPROTO_ICMP defined in src/unix/mod.rs -/// group mgmt protocol -pub const IPPROTO_IGMP: ::c_int = 2; -/// gateway^2 (deprecated) -pub const IPPROTO_GGP: ::c_int = 3; -/// for compatibility -pub const IPPROTO_IPIP: ::c_int = 4; -// IPPROTO_TCP defined in src/unix/mod.rs -/// Stream protocol II. -pub const IPPROTO_ST: ::c_int = 7; -/// exterior gateway protocol -pub const IPPROTO_EGP: ::c_int = 8; -/// private interior gateway -pub const IPPROTO_PIGP: ::c_int = 9; -/// BBN RCC Monitoring -pub const IPPROTO_RCCMON: ::c_int = 10; -/// network voice protocol -pub const IPPROTO_NVPII: ::c_int = 11; -/// pup -pub const IPPROTO_PUP: ::c_int = 12; -/// Argus -pub const IPPROTO_ARGUS: ::c_int = 13; -/// EMCON -pub const IPPROTO_EMCON: ::c_int = 14; -/// Cross Net Debugger -pub const IPPROTO_XNET: ::c_int = 15; -/// Chaos -pub const IPPROTO_CHAOS: ::c_int = 16; -// IPPROTO_UDP defined in src/unix/mod.rs -/// Multiplexing -pub const IPPROTO_MUX: ::c_int = 18; -/// DCN Measurement Subsystems -pub const IPPROTO_MEAS: ::c_int = 19; -/// Host Monitoring -pub const IPPROTO_HMP: ::c_int = 20; -/// Packet Radio Measurement -pub const IPPROTO_PRM: ::c_int = 21; -/// xns idp -pub const IPPROTO_IDP: ::c_int = 22; -/// Trunk-1 -pub const IPPROTO_TRUNK1: ::c_int = 23; -/// Trunk-2 -pub const IPPROTO_TRUNK2: ::c_int = 24; -/// Leaf-1 -pub const IPPROTO_LEAF1: ::c_int = 25; -/// Leaf-2 -pub const IPPROTO_LEAF2: ::c_int = 26; -/// Reliable Data -pub const IPPROTO_RDP: ::c_int = 27; -/// Reliable Transaction -pub const IPPROTO_IRTP: ::c_int = 28; -/// tp-4 w/ class negotiation -pub const IPPROTO_TP: ::c_int = 29; -/// Bulk Data Transfer -pub const IPPROTO_BLT: ::c_int = 30; -/// Network Services -pub const IPPROTO_NSP: ::c_int = 31; -/// Merit Internodal -pub const IPPROTO_INP: ::c_int = 32; -/// Sequential Exchange -pub const IPPROTO_SEP: ::c_int = 33; -/// Third Party Connect -pub const IPPROTO_3PC: ::c_int = 34; -/// InterDomain Policy Routing -pub const IPPROTO_IDPR: ::c_int = 35; -/// XTP -pub const IPPROTO_XTP: ::c_int = 36; -/// Datagram Delivery -pub const IPPROTO_DDP: ::c_int = 37; -/// Control Message Transport -pub const IPPROTO_CMTP: ::c_int = 38; -/// TP++ Transport -pub const IPPROTO_TPXX: ::c_int = 39; -/// IL transport protocol -pub const IPPROTO_IL: ::c_int = 40; -// IPPROTO_IPV6 defined in src/unix/mod.rs -/// Source Demand Routing -pub const IPPROTO_SDRP: ::c_int = 42; -/// IP6 routing header -pub const IPPROTO_ROUTING: ::c_int = 43; -/// IP6 fragmentation header -pub const IPPROTO_FRAGMENT: ::c_int = 44; -/// InterDomain Routing -pub const IPPROTO_IDRP: ::c_int = 45; -/// resource reservation -pub const IPPROTO_RSVP: ::c_int = 46; -/// General Routing Encap. -pub const IPPROTO_GRE: ::c_int = 47; -/// Mobile Host Routing -pub const IPPROTO_MHRP: ::c_int = 48; -/// BHA -pub const IPPROTO_BHA: ::c_int = 49; -/// IP6 Encap Sec. Payload -pub const IPPROTO_ESP: ::c_int = 50; -/// IP6 Auth Header -pub const IPPROTO_AH: ::c_int = 51; -/// Integ. Net Layer Security -pub const IPPROTO_INLSP: ::c_int = 52; -/// IP with encryption -pub const IPPROTO_SWIPE: ::c_int = 53; -/// Next Hop Resolution -pub const IPPROTO_NHRP: ::c_int = 54; -/// IP Mobility -pub const IPPROTO_MOBILE: ::c_int = 55; -/// Transport Layer Security -pub const IPPROTO_TLSP: ::c_int = 56; -/// SKIP -pub const IPPROTO_SKIP: ::c_int = 57; -// IPPROTO_ICMPV6 defined in src/unix/mod.rs -/// IP6 no next header -pub const IPPROTO_NONE: ::c_int = 59; -/// IP6 destination option -pub const IPPROTO_DSTOPTS: ::c_int = 60; -/// any host internal protocol -pub const IPPROTO_AHIP: ::c_int = 61; -/// CFTP -pub const IPPROTO_CFTP: ::c_int = 62; -/// "hello" routing protocol -pub const IPPROTO_HELLO: ::c_int = 63; -/// SATNET/Backroom EXPAK -pub const IPPROTO_SATEXPAK: ::c_int = 64; -/// Kryptolan -pub const IPPROTO_KRYPTOLAN: ::c_int = 65; -/// Remote Virtual Disk -pub const IPPROTO_RVD: ::c_int = 66; -/// Pluribus Packet Core -pub const IPPROTO_IPPC: ::c_int = 67; -/// Any distributed FS -pub const IPPROTO_ADFS: ::c_int = 68; -/// Satnet Monitoring -pub const IPPROTO_SATMON: ::c_int = 69; -/// VISA Protocol -pub const IPPROTO_VISA: ::c_int = 70; -/// Packet Core Utility -pub const IPPROTO_IPCV: ::c_int = 71; -/// Comp. Prot. Net. Executive -pub const IPPROTO_CPNX: ::c_int = 72; -/// Comp. Prot. HeartBeat -pub const IPPROTO_CPHB: ::c_int = 73; -/// Wang Span Network -pub const IPPROTO_WSN: ::c_int = 74; -/// Packet Video Protocol -pub const IPPROTO_PVP: ::c_int = 75; -/// BackRoom SATNET Monitoring -pub const IPPROTO_BRSATMON: ::c_int = 76; -/// Sun net disk proto (temp.) -pub const IPPROTO_ND: ::c_int = 77; -/// WIDEBAND Monitoring -pub const IPPROTO_WBMON: ::c_int = 78; -/// WIDEBAND EXPAK -pub const IPPROTO_WBEXPAK: ::c_int = 79; -/// ISO cnlp -pub const IPPROTO_EON: ::c_int = 80; -/// VMTP -pub const IPPROTO_VMTP: ::c_int = 81; -/// Secure VMTP -pub const IPPROTO_SVMTP: ::c_int = 82; -/// Banyon VINES -pub const IPPROTO_VINES: ::c_int = 83; -/// TTP -pub const IPPROTO_TTP: ::c_int = 84; -/// NSFNET-IGP -pub const IPPROTO_IGP: ::c_int = 85; -/// dissimilar gateway prot. -pub const IPPROTO_DGP: ::c_int = 86; -/// TCF -pub const IPPROTO_TCF: ::c_int = 87; -/// Cisco/GXS IGRP -pub const IPPROTO_IGRP: ::c_int = 88; -/// OSPFIGP -pub const IPPROTO_OSPFIGP: ::c_int = 89; -/// Strite RPC protocol -pub const IPPROTO_SRPC: ::c_int = 90; -/// Locus Address Resoloution -pub const IPPROTO_LARP: ::c_int = 91; -/// Multicast Transport -pub const IPPROTO_MTP: ::c_int = 92; -/// AX.25 Frames -pub const IPPROTO_AX25: ::c_int = 93; -/// IP encapsulated in IP -pub const IPPROTO_IPEIP: ::c_int = 94; -/// Mobile Int.ing control -pub const IPPROTO_MICP: ::c_int = 95; -/// Semaphore Comm. security -pub const IPPROTO_SCCSP: ::c_int = 96; -/// Ethernet IP encapsulation -pub const IPPROTO_ETHERIP: ::c_int = 97; -/// encapsulation header -pub const IPPROTO_ENCAP: ::c_int = 98; -/// any private encr. scheme -pub const IPPROTO_APES: ::c_int = 99; -/// GMTP -pub const IPPROTO_GMTP: ::c_int = 100; -/// payload compression (IPComp) -pub const IPPROTO_IPCOMP: ::c_int = 108; - -/* 101-254: Partly Unassigned */ -/// Protocol Independent Mcast -pub const IPPROTO_PIM: ::c_int = 103; -/// CARP -pub const IPPROTO_CARP: ::c_int = 112; -/// PGM -pub const IPPROTO_PGM: ::c_int = 113; -/// PFSYNC -pub const IPPROTO_PFSYNC: ::c_int = 240; - -/* 255: Reserved */ -/* BSD Private, local use, namespace incursion, no longer used */ -/// divert pseudo-protocol -pub const IPPROTO_DIVERT: ::c_int = 254; -pub const IPPROTO_MAX: ::c_int = 256; -/// last return value of *_input(), meaning "all job for this pkt is done". -pub const IPPROTO_DONE: ::c_int = 257; - -/// Used by RSS: the layer3 protocol is unknown -pub const IPPROTO_UNKNOWN: ::c_int = 258; - -// sys/netinet/tcp.h -pub const TCP_SIGNATURE_ENABLE: ::c_int = 16; -pub const TCP_KEEPINIT: ::c_int = 32; -pub const TCP_FASTKEEP: ::c_int = 128; - -pub const AF_BLUETOOTH: ::c_int = 33; -pub const AF_MPLS: ::c_int = 34; -pub const AF_IEEE80211: ::c_int = 35; - -pub const PF_BLUETOOTH: ::c_int = AF_BLUETOOTH; - -pub const NET_RT_DUMP: ::c_int = 1; -pub const NET_RT_FLAGS: ::c_int = 2; -pub const NET_RT_IFLIST: ::c_int = 3; -pub const NET_RT_MAXID: ::c_int = 4; - -pub const SOMAXOPT_SIZE: ::c_int = 65536; - -pub const MSG_UNUSED09: ::c_int = 0x00000200; -pub const MSG_NOSIGNAL: ::c_int = 0x00000400; -pub const MSG_SYNC: ::c_int = 0x00000800; -pub const MSG_CMSG_CLOEXEC: ::c_int = 0x00001000; -pub const MSG_FBLOCKING: ::c_int = 0x00010000; -pub const MSG_FNONBLOCKING: ::c_int = 0x00020000; -pub const MSG_FMASK: ::c_int = 0xFFFF0000; - -// utmpx entry types -pub const EMPTY: ::c_short = 0; -pub const RUN_LVL: ::c_short = 1; -pub const BOOT_TIME: ::c_short = 2; -pub const OLD_TIME: ::c_short = 3; -pub const NEW_TIME: ::c_short = 4; -pub const INIT_PROCESS: ::c_short = 5; -pub const LOGIN_PROCESS: ::c_short = 6; -pub const USER_PROCESS: ::c_short = 7; -pub const DEAD_PROCESS: ::c_short = 8; -pub const ACCOUNTING: ::c_short = 9; -pub const SIGNATURE: ::c_short = 10; -pub const DOWNTIME: ::c_short = 11; -// utmpx database types -pub const UTX_DB_UTMPX: ::c_uint = 0; -pub const UTX_DB_WTMPX: ::c_uint = 1; -pub const UTX_DB_LASTLOG: ::c_uint = 2; - -pub const LC_COLLATE_MASK: ::c_int = (1 << 0); -pub const LC_CTYPE_MASK: ::c_int = (1 << 1); -pub const LC_MONETARY_MASK: ::c_int = (1 << 2); -pub const LC_NUMERIC_MASK: ::c_int = (1 << 3); -pub const LC_TIME_MASK: ::c_int = (1 << 4); -pub const LC_MESSAGES_MASK: ::c_int = (1 << 5); -pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK - | LC_CTYPE_MASK - | LC_MESSAGES_MASK - | LC_MONETARY_MASK - | LC_NUMERIC_MASK - | LC_TIME_MASK; - -pub const TIOCSIG: ::c_uint = 0x2000745f; -pub const BTUARTDISC: ::c_int = 0x7; -pub const TIOCDCDTIMESTAMP: ::c_uint = 0x40107458; -pub const TIOCISPTMASTER: ::c_uint = 0x20007455; -pub const TIOCMODG: ::c_uint = 0x40047403; -pub const TIOCMODS: ::c_ulong = 0x80047404; -pub const TIOCREMOTE: ::c_ulong = 0x80047469; - -// Constants used by "at" family of system calls. -pub const AT_FDCWD: ::c_int = 0xFFFAFDCD; // invalid file descriptor -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 1; -pub const AT_REMOVEDIR: ::c_int = 2; -pub const AT_EACCESS: ::c_int = 4; -pub const AT_SYMLINK_FOLLOW: ::c_int = 8; - -pub const VCHECKPT: usize = 19; - -pub const _PC_2_SYMLINKS: ::c_int = 22; -pub const _PC_TIMESTAMP_RESOLUTION: ::c_int = 23; - -pub const _SC_V7_ILP32_OFF32: ::c_int = 122; -pub const _SC_V7_ILP32_OFFBIG: ::c_int = 123; -pub const _SC_V7_LP64_OFF64: ::c_int = 124; -pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 125; -pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 126; -pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 127; - -pub const WCONTINUED: ::c_int = 4; -pub const WSTOPPED: ::c_int = 0o177; - -// Values for struct rtprio (type_ field) -pub const RTP_PRIO_REALTIME: ::c_ushort = 0; -pub const RTP_PRIO_NORMAL: ::c_ushort = 1; -pub const RTP_PRIO_IDLE: ::c_ushort = 2; -pub const RTP_PRIO_THREAD: ::c_ushort = 3; - -// Flags for chflags(2) -pub const UF_NOHISTORY: ::c_ulong = 0x00000040; -pub const UF_CACHE: ::c_ulong = 0x00000080; -pub const UF_XLINK: ::c_ulong = 0x00000100; -pub const SF_NOHISTORY: ::c_ulong = 0x00400000; -pub const SF_CACHE: ::c_ulong = 0x00800000; -pub const SF_XLINK: ::c_ulong = 0x01000000; - -// timespec constants -pub const UTIME_OMIT: c_long = -2; -pub const UTIME_NOW: c_long = -1; - -fn _CMSG_ALIGN(n: usize) -> usize { - (n + 3) & !3 -} - -f! { - pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { - (cmsg as *mut ::c_uchar) - .offset(_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - (_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + length as usize) - as ::c_uint - } - - pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) - -> *mut ::cmsghdr - { - let next = cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize) - + _CMSG_ALIGN(::mem::size_of::<::cmsghdr>()); - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next <= max { - (cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize)) - as *mut ::cmsghdr - } else { - 0 as *mut ::cmsghdr - } - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + - _CMSG_ALIGN(length as usize)) as ::c_uint - } -} - -extern "C" { - pub fn setgrent(); - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_settime( - clk_id: ::clockid_t, - tp: *const ::timespec, - ) -> ::c_int; - - pub fn setutxdb(_type: ::c_uint, file: *mut ::c_char) -> ::c_int; - - pub fn aio_waitcomplete( - iocbp: *mut *mut aiocb, - timeout: *mut ::timespec, - ) -> ::c_int; - - pub fn freelocale(loc: ::locale_t); - - pub fn lwp_rtprio( - function: ::c_int, - pid: ::pid_t, - lwpid: lwpid_t, - rtp: *mut super::rtprio, - ) -> ::c_int; - - pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; - pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; - pub fn uname(buf: *mut ::utsname) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_thread_local)] { - mod errno; - pub use self::errno::*; - } -} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs b/libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs deleted file mode 100644 index 22fd2b8..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/aarch64.rs +++ /dev/null @@ -1,44 +0,0 @@ -pub type c_char = u8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type time_t = i64; -pub type suseconds_t = i64; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - } -} - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_longlong>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} - -pub const MAP_32BIT: ::c_int = 0x00080000; diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/arm.rs b/libc/src/unix/bsd/freebsdlike/freebsd/arm.rs deleted file mode 100644 index b7480aa..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/arm.rs +++ /dev/null @@ -1,47 +0,0 @@ -pub type c_char = u8; -pub type c_long = i32; -pub type c_ulong = u32; -pub type time_t = i64; -pub type suseconds_t = i32; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_atime_pad: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_mtime_pad: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ctime_pad: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - pub st_birthtime_pad: ::c_long, - } -} - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 4 - 1; - } -} -pub const MAP_32BIT: ::c_int = 0x00080000; diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs b/libc/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs deleted file mode 100644 index 79a152f..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs +++ /dev/null @@ -1,224 +0,0 @@ -// APIs that had breaking changes after FreeBSD 11 - -// The type of `nlink_t` changed from `u16` to `u64` in FreeBSD 12: -pub type nlink_t = u16; -// Type of `dev_t` changed from `u32` to `u64` in FreeBSD 12: -pub type dev_t = u32; -// Type of `ino_t` changed from `unsigned int` to `unsigned long` in FreeBSD 12: -pub type ino_t = u32; - -s! { - pub struct kevent { - pub ident: ::uintptr_t, - pub filter: ::c_short, - pub flags: ::c_ushort, - pub fflags: ::c_uint, - pub data: ::intptr_t, - pub udata: *mut ::c_void, - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_lpid: ::pid_t, - pub shm_cpid: ::pid_t, - // Type of shm_nattc changed from `int` to `shmatt_t` (aka `unsigned - // int`) in FreeBSD 12: - pub shm_nattch: ::c_int, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - } -} - -s_no_extra_traits! { - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_reclen: u16, - pub d_type: u8, - // Type of `d_namlen` changed from `char` to `u16` in FreeBSD 12: - pub d_namlen: u8, - pub d_name: [::c_char; 256], - } - - pub struct statfs { - pub f_version: u32, - pub f_type: u32, - pub f_flags: u64, - pub f_bsize: u64, - pub f_iosize: u64, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: i64, - pub f_files: u64, - pub f_ffree: i64, - pub f_syncwrites: u64, - pub f_asyncwrites: u64, - pub f_syncreads: u64, - pub f_asyncreads: u64, - f_spare: [u64; 10], - pub f_namemax: u32, - pub f_owner: ::uid_t, - pub f_fsid: ::fsid_t, - f_charspare: [::c_char; 80], - pub f_fstypename: [::c_char; 16], - // Array length changed from 88 to 1024 in FreeBSD 12: - pub f_mntfromname: [::c_char; 88], - // Array length changed from 88 to 1024 in FreeBSD 12: - pub f_mntonname: [::c_char; 88], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for statfs { - fn eq(&self, other: &statfs) -> bool { - self.f_version == other.f_version - && self.f_type == other.f_type - && self.f_flags == other.f_flags - && self.f_bsize == other.f_bsize - && self.f_iosize == other.f_iosize - && self.f_blocks == other.f_blocks - && self.f_bfree == other.f_bfree - && self.f_bavail == other.f_bavail - && self.f_files == other.f_files - && self.f_ffree == other.f_ffree - && self.f_syncwrites == other.f_syncwrites - && self.f_asyncwrites == other.f_asyncwrites - && self.f_syncreads == other.f_syncreads - && self.f_asyncreads == other.f_asyncreads - && self.f_namemax == other.f_namemax - && self.f_owner == other.f_owner - && self.f_fsid == other.f_fsid - && self.f_fstypename == other.f_fstypename - && self - .f_mntfromname - .iter() - .zip(other.f_mntfromname.iter()) - .all(|(a,b)| a == b) - && self - .f_mntonname - .iter() - .zip(other.f_mntonname.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for statfs {} - impl ::fmt::Debug for statfs { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("statfs") - .field("f_bsize", &self.f_bsize) - .field("f_iosize", &self.f_iosize) - .field("f_blocks", &self.f_blocks) - .field("f_bfree", &self.f_bfree) - .field("f_bavail", &self.f_bavail) - .field("f_files", &self.f_files) - .field("f_ffree", &self.f_ffree) - .field("f_syncwrites", &self.f_syncwrites) - .field("f_asyncwrites", &self.f_asyncwrites) - .field("f_syncreads", &self.f_syncreads) - .field("f_asyncreads", &self.f_asyncreads) - .field("f_namemax", &self.f_namemax) - .field("f_owner", &self.f_owner) - .field("f_fsid", &self.f_fsid) - .field("f_fstypename", &self.f_fstypename) - .field("f_mntfromname", &&self.f_mntfromname[..]) - .field("f_mntonname", &&self.f_mntonname[..]) - .finish() - } - } - impl ::hash::Hash for statfs { - fn hash(&self, state: &mut H) { - self.f_version.hash(state); - self.f_type.hash(state); - self.f_flags.hash(state); - self.f_bsize.hash(state); - self.f_iosize.hash(state); - self.f_blocks.hash(state); - self.f_bfree.hash(state); - self.f_bavail.hash(state); - self.f_files.hash(state); - self.f_ffree.hash(state); - self.f_syncwrites.hash(state); - self.f_asyncwrites.hash(state); - self.f_syncreads.hash(state); - self.f_asyncreads.hash(state); - self.f_namemax.hash(state); - self.f_owner.hash(state); - self.f_fsid.hash(state); - self.f_fstypename.hash(state); - self.f_mntfromname.hash(state); - self.f_mntonname.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_fileno == other.d_fileno - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self.d_namlen == other.d_namlen - && self - .d_name[..self.d_namlen as _] - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_fileno", &self.d_fileno) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - .field("d_namlen", &self.d_namlen) - .field("d_name", &&self.d_name[..self.d_namlen as _]) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_fileno.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_namlen.hash(state); - self.d_name[..self.d_namlen as _].hash(state); - } - } - } -} - -pub const ELAST: ::c_int = 96; - -extern "C" { - // Return type ::c_int was removed in FreeBSD 12 - pub fn setgrent() -> ::c_int; - - // Type of `addr` argument changed from `const void*` to `void*` - // in FreeBSD 12 - pub fn mprotect( - addr: *const ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - - // Return type ::c_int was removed in FreeBSD 12 - pub fn freelocale(loc: ::locale_t) -> ::c_int; - - // Return type ::c_int changed to ::ssize_t in FreeBSD 12: - pub fn msgrcv( - msqid: ::c_int, - msgp: *mut ::c_void, - msgsz: ::size_t, - msgtyp: ::c_long, - msgflg: ::c_int, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } -} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/freebsd11/x86_64.rs b/libc/src/unix/bsd/freebsdlike/freebsd/freebsd11/x86_64.rs deleted file mode 100644 index f32128f..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/freebsd11/x86_64.rs +++ /dev/null @@ -1,32 +0,0 @@ -#[repr(C)] -#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] -pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, -} - -impl ::Copy for ::stat {} -impl ::Clone for ::stat { - fn clone(&self) -> ::stat { - *self - } -} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs b/libc/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs deleted file mode 100644 index 6bf7f95..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs +++ /dev/null @@ -1,224 +0,0 @@ -// APIs that changed in FreeBSD12 - -pub type nlink_t = u64; -pub type dev_t = u64; -pub type ino_t = ::c_ulong; -pub type shmatt_t = ::c_uint; - -s! { - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_lpid: ::pid_t, - pub shm_cpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - } - - pub struct kevent { - pub ident: ::uintptr_t, - pub filter: ::c_short, - pub flags: ::c_ushort, - pub fflags: ::c_uint, - pub data: ::intptr_t, - pub udata: *mut ::c_void, - pub ext: [u64; 4], - } -} - -s_no_extra_traits! { - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: u16, - pub d_type: u8, - d_pad0: u8, - pub d_namlen: u16, - d_pad1: u16, - pub d_name: [::c_char; 256], - } - - pub struct statfs { - pub f_version: u32, - pub f_type: u32, - pub f_flags: u64, - pub f_bsize: u64, - pub f_iosize: u64, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: i64, - pub f_files: u64, - pub f_ffree: i64, - pub f_syncwrites: u64, - pub f_asyncwrites: u64, - pub f_syncreads: u64, - pub f_asyncreads: u64, - f_spare: [u64; 10], - pub f_namemax: u32, - pub f_owner: ::uid_t, - pub f_fsid: ::fsid_t, - f_charspare: [::c_char; 80], - pub f_fstypename: [::c_char; 16], - pub f_mntfromname: [::c_char; 1024], - pub f_mntonname: [::c_char; 1024], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for statfs { - fn eq(&self, other: &statfs) -> bool { - self.f_version == other.f_version - && self.f_type == other.f_type - && self.f_flags == other.f_flags - && self.f_bsize == other.f_bsize - && self.f_iosize == other.f_iosize - && self.f_blocks == other.f_blocks - && self.f_bfree == other.f_bfree - && self.f_bavail == other.f_bavail - && self.f_files == other.f_files - && self.f_ffree == other.f_ffree - && self.f_syncwrites == other.f_syncwrites - && self.f_asyncwrites == other.f_asyncwrites - && self.f_syncreads == other.f_syncreads - && self.f_asyncreads == other.f_asyncreads - && self.f_namemax == other.f_namemax - && self.f_owner == other.f_owner - && self.f_fsid == other.f_fsid - && self.f_fstypename == other.f_fstypename - && self - .f_mntfromname - .iter() - .zip(other.f_mntfromname.iter()) - .all(|(a,b)| a == b) - && self - .f_mntonname - .iter() - .zip(other.f_mntonname.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for statfs {} - impl ::fmt::Debug for statfs { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("statfs") - .field("f_bsize", &self.f_bsize) - .field("f_iosize", &self.f_iosize) - .field("f_blocks", &self.f_blocks) - .field("f_bfree", &self.f_bfree) - .field("f_bavail", &self.f_bavail) - .field("f_files", &self.f_files) - .field("f_ffree", &self.f_ffree) - .field("f_syncwrites", &self.f_syncwrites) - .field("f_asyncwrites", &self.f_asyncwrites) - .field("f_syncreads", &self.f_syncreads) - .field("f_asyncreads", &self.f_asyncreads) - .field("f_namemax", &self.f_namemax) - .field("f_owner", &self.f_owner) - .field("f_fsid", &self.f_fsid) - .field("f_fstypename", &self.f_fstypename) - .field("f_mntfromname", &&self.f_mntfromname[..]) - .field("f_mntonname", &&self.f_mntonname[..]) - .finish() - } - } - impl ::hash::Hash for statfs { - fn hash(&self, state: &mut H) { - self.f_version.hash(state); - self.f_type.hash(state); - self.f_flags.hash(state); - self.f_bsize.hash(state); - self.f_iosize.hash(state); - self.f_blocks.hash(state); - self.f_bfree.hash(state); - self.f_bavail.hash(state); - self.f_files.hash(state); - self.f_ffree.hash(state); - self.f_syncwrites.hash(state); - self.f_asyncwrites.hash(state); - self.f_syncreads.hash(state); - self.f_asyncreads.hash(state); - self.f_namemax.hash(state); - self.f_owner.hash(state); - self.f_fsid.hash(state); - self.f_charspare.hash(state); - self.f_fstypename.hash(state); - self.f_mntfromname.hash(state); - self.f_mntonname.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_fileno == other.d_fileno - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self.d_namlen == other.d_namlen - && self - .d_name[..self.d_namlen as _] - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_fileno", &self.d_fileno) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - .field("d_namlen", &self.d_namlen) - .field("d_name", &&self.d_name[..self.d_namlen as _]) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_fileno.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_namlen.hash(state); - self.d_name[..self.d_namlen as _].hash(state); - } - } - } -} - -cfg_if! { - if #[cfg(not(freebsd13))] { - pub const ELAST: ::c_int = 96; - } else { - pub const EINTEGRITY: ::c_int = 97; - pub const ELAST: ::c_int = 97; - } -} - -extern "C" { - pub fn setgrent(); - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn freelocale(loc: ::locale_t); - pub fn msgrcv( - msqid: ::c_int, - msgp: *mut ::c_void, - msgsz: ::size_t, - msgtyp: ::c_long, - msgflg: ::c_int, - ) -> ::ssize_t; -} - -cfg_if! { - if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } -} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/freebsd12/x86_64.rs b/libc/src/unix/bsd/freebsdlike/freebsd/freebsd12/x86_64.rs deleted file mode 100644 index 80c6fa1..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/freebsd12/x86_64.rs +++ /dev/null @@ -1,34 +0,0 @@ -#[repr(C)] -#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] -pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - st_padding0: i16, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - st_padding1: i32, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u64, - pub st_spare: [u64; 10], -} - -impl ::Copy for ::stat {} -impl ::Clone for ::stat { - fn clone(&self) -> ::stat { - *self - } -} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/mod.rs b/libc/src/unix/bsd/freebsdlike/freebsd/mod.rs deleted file mode 100644 index 980caf2..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ /dev/null @@ -1,1486 +0,0 @@ -pub type fflags_t = u32; -pub type clock_t = i32; - -pub type lwpid_t = i32; -pub type blksize_t = i32; -pub type clockid_t = ::c_int; -pub type sem_t = _sem; - -pub type fsblkcnt_t = u64; -pub type fsfilcnt_t = u64; -pub type idtype_t = ::c_uint; - -pub type key_t = ::c_long; -pub type msglen_t = ::c_ulong; -pub type msgqnum_t = ::c_ulong; - -pub type mqd_t = *mut ::c_void; -pub type posix_spawnattr_t = *mut ::c_void; -pub type posix_spawn_file_actions_t = *mut ::c_void; - -s! { - pub struct aiocb { - pub aio_fildes: ::c_int, - pub aio_offset: ::off_t, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - __unused1: [::c_int; 2], - __unused2: *mut ::c_void, - pub aio_lio_opcode: ::c_int, - pub aio_reqprio: ::c_int, - // unused 3 through 5 are the __aiocb_private structure - __unused3: ::c_long, - __unused4: ::c_long, - __unused5: *mut ::c_void, - pub aio_sigevent: sigevent - } - - pub struct jail { - pub version: u32, - pub path: *mut ::c_char, - pub hostname: *mut ::c_char, - pub jailname: *mut ::c_char, - pub ip4s: ::c_uint, - pub ip6s: ::c_uint, - pub ip4: *mut ::in_addr, - pub ip6: *mut ::in6_addr, - } - - pub struct statvfs { - pub f_bavail: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_blocks: ::fsblkcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_bsize: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_fsid: ::c_ulong, - pub f_namemax: ::c_ulong, - } - - // internal structure has changed over time - pub struct _sem { - data: [u32; 4], - } - - pub struct ipc_perm { - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub mode: ::mode_t, - pub seq: ::c_ushort, - pub key: ::key_t, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - pub msg_cbytes: ::msglen_t, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - pub msg_stime: ::time_t, - pub msg_rtime: ::time_t, - pub msg_ctime: ::time_t, - } - - pub struct xucred { - pub cr_version: ::c_uint, - pub cr_uid: ::uid_t, - pub cr_ngroups: ::c_short, - pub cr_groups: [::gid_t;16], - __cr_unused1: *mut ::c_void, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct mmsghdr { - pub msg_hdr: ::msghdr, - pub msg_len: ::ssize_t, - } -} - -s_no_extra_traits! { - pub struct utmpx { - pub ut_type: ::c_short, - pub ut_tv: ::timeval, - pub ut_id: [::c_char; 8], - pub ut_pid: ::pid_t, - pub ut_user: [::c_char; 32], - pub ut_line: [::c_char; 16], - pub ut_host: [::c_char; 128], - pub __ut_spare: [::c_char; 64], - } - - pub struct sockaddr_dl { - pub sdl_len: ::c_uchar, - pub sdl_family: ::c_uchar, - pub sdl_index: ::c_ushort, - pub sdl_type: ::c_uchar, - pub sdl_nlen: ::c_uchar, - pub sdl_alen: ::c_uchar, - pub sdl_slen: ::c_uchar, - pub sdl_data: [::c_char; 46], - } - - pub struct mq_attr { - pub mq_flags: ::c_long, - pub mq_maxmsg: ::c_long, - pub mq_msgsize: ::c_long, - pub mq_curmsgs: ::c_long, - __reserved: [::c_long; 4] - } - - pub struct sigevent { - pub sigev_notify: ::c_int, - pub sigev_signo: ::c_int, - pub sigev_value: ::sigval, - //The rest of the structure is actually a union. We expose only - //sigev_notify_thread_id because it's the most useful union member. - pub sigev_notify_thread_id: ::lwpid_t, - #[cfg(target_pointer_width = "64")] - __unused1: ::c_int, - __unused2: [::c_long; 7] - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for utmpx { - fn eq(&self, other: &utmpx) -> bool { - self.ut_type == other.ut_type - && self.ut_tv == other.ut_tv - && self.ut_id == other.ut_id - && self.ut_pid == other.ut_pid - && self.ut_user == other.ut_user - && self.ut_line == other.ut_line - && self - .ut_host - .iter() - .zip(other.ut_host.iter()) - .all(|(a,b)| a == b) - && self - .__ut_spare - .iter() - .zip(other.__ut_spare.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for utmpx {} - impl ::fmt::Debug for utmpx { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utmpx") - .field("ut_type", &self.ut_type) - .field("ut_tv", &self.ut_tv) - .field("ut_id", &self.ut_id) - .field("ut_pid", &self.ut_pid) - .field("ut_user", &self.ut_user) - .field("ut_line", &self.ut_line) - // FIXME: .field("ut_host", &self.ut_host) - // FIXME: .field("__ut_spare", &self.__ut_spare) - .finish() - } - } - impl ::hash::Hash for utmpx { - fn hash(&self, state: &mut H) { - self.ut_type.hash(state); - self.ut_tv.hash(state); - self.ut_id.hash(state); - self.ut_pid.hash(state); - self.ut_user.hash(state); - self.ut_line.hash(state); - self.ut_host.hash(state); - self.__ut_spare.hash(state); - } - } - - impl PartialEq for sockaddr_dl { - fn eq(&self, other: &sockaddr_dl) -> bool { - self.sdl_len == other.sdl_len - && self.sdl_family == other.sdl_family - && self.sdl_index == other.sdl_index - && self.sdl_type == other.sdl_type - && self.sdl_nlen == other.sdl_nlen - && self.sdl_alen == other.sdl_alen - && self.sdl_slen == other.sdl_slen - && self - .sdl_data - .iter() - .zip(other.sdl_data.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr_dl {} - impl ::fmt::Debug for sockaddr_dl { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_dl") - .field("sdl_len", &self.sdl_len) - .field("sdl_family", &self.sdl_family) - .field("sdl_index", &self.sdl_index) - .field("sdl_type", &self.sdl_type) - .field("sdl_nlen", &self.sdl_nlen) - .field("sdl_alen", &self.sdl_alen) - .field("sdl_slen", &self.sdl_slen) - // FIXME: .field("sdl_data", &self.sdl_data) - .finish() - } - } - impl ::hash::Hash for sockaddr_dl { - fn hash(&self, state: &mut H) { - self.sdl_len.hash(state); - self.sdl_family.hash(state); - self.sdl_index.hash(state); - self.sdl_type.hash(state); - self.sdl_nlen.hash(state); - self.sdl_alen.hash(state); - self.sdl_slen.hash(state); - self.sdl_data.hash(state); - } - } - - impl PartialEq for mq_attr { - fn eq(&self, other: &mq_attr) -> bool { - self.mq_flags == other.mq_flags && - self.mq_maxmsg == other.mq_maxmsg && - self.mq_msgsize == other.mq_msgsize && - self.mq_curmsgs == other.mq_curmsgs - } - } - impl Eq for mq_attr {} - impl ::fmt::Debug for mq_attr { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("mq_attr") - .field("mq_flags", &self.mq_flags) - .field("mq_maxmsg", &self.mq_maxmsg) - .field("mq_msgsize", &self.mq_msgsize) - .field("mq_curmsgs", &self.mq_curmsgs) - .finish() - } - } - impl ::hash::Hash for mq_attr { - fn hash(&self, state: &mut H) { - self.mq_flags.hash(state); - self.mq_maxmsg.hash(state); - self.mq_msgsize.hash(state); - self.mq_curmsgs.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_notify == other.sigev_notify - && self.sigev_signo == other.sigev_signo - && self.sigev_value == other.sigev_value - && self.sigev_notify_thread_id - == other.sigev_notify_thread_id - } - } - impl Eq for sigevent {} - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_notify", &self.sigev_notify) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_value", &self.sigev_value) - .field("sigev_notify_thread_id", - &self.sigev_notify_thread_id) - .finish() - } - } - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_notify.hash(state); - self.sigev_signo.hash(state); - self.sigev_value.hash(state); - self.sigev_notify_thread_id.hash(state); - } - } - } -} - -pub const SIGEV_THREAD_ID: ::c_int = 4; - -pub const EXTATTR_NAMESPACE_EMPTY: ::c_int = 0; -pub const EXTATTR_NAMESPACE_USER: ::c_int = 1; -pub const EXTATTR_NAMESPACE_SYSTEM: ::c_int = 2; - -pub const RAND_MAX: ::c_int = 0x7fff_fffd; -pub const PTHREAD_STACK_MIN: ::size_t = 2048; -pub const PTHREAD_MUTEX_ADAPTIVE_NP: ::c_int = 4; -pub const SIGSTKSZ: ::size_t = 34816; -pub const SF_NODISKIO: ::c_int = 0x00000001; -pub const SF_MNOWAIT: ::c_int = 0x00000002; -pub const SF_SYNC: ::c_int = 0x00000004; -pub const SF_USER_READAHEAD: ::c_int = 0x00000008; -pub const SF_NOCACHE: ::c_int = 0x00000010; -pub const O_CLOEXEC: ::c_int = 0x00100000; -pub const O_DIRECTORY: ::c_int = 0x00020000; -pub const O_EXEC: ::c_int = 0x00040000; -pub const O_TTY_INIT: ::c_int = 0x00080000; -pub const F_GETLK: ::c_int = 11; -pub const F_SETLK: ::c_int = 12; -pub const F_SETLKW: ::c_int = 13; -pub const ENOTCAPABLE: ::c_int = 93; -pub const ECAPMODE: ::c_int = 94; -pub const ENOTRECOVERABLE: ::c_int = 95; -pub const EOWNERDEAD: ::c_int = 96; -pub const RLIMIT_NPTS: ::c_int = 11; -pub const RLIMIT_SWAP: ::c_int = 12; -pub const RLIMIT_KQUEUES: ::c_int = 13; -pub const RLIMIT_UMTXP: ::c_int = 14; -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] -pub const RLIM_NLIMITS: ::rlim_t = 15; - -pub const Q_GETQUOTA: ::c_int = 0x700; -pub const Q_SETQUOTA: ::c_int = 0x800; - -pub const POSIX_FADV_NORMAL: ::c_int = 0; -pub const POSIX_FADV_RANDOM: ::c_int = 1; -pub const POSIX_FADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_FADV_WILLNEED: ::c_int = 3; -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const POLLINIGNEOF: ::c_short = 0x2000; - -pub const EVFILT_READ: i16 = -1; -pub const EVFILT_WRITE: i16 = -2; -pub const EVFILT_AIO: i16 = -3; -pub const EVFILT_VNODE: i16 = -4; -pub const EVFILT_PROC: i16 = -5; -pub const EVFILT_SIGNAL: i16 = -6; -pub const EVFILT_TIMER: i16 = -7; -pub const EVFILT_PROCDESC: i16 = -8; -pub const EVFILT_FS: i16 = -9; -pub const EVFILT_LIO: i16 = -10; -pub const EVFILT_USER: i16 = -11; -pub const EVFILT_SENDFILE: i16 = -12; -pub const EVFILT_EMPTY: i16 = -13; - -pub const EV_ADD: u16 = 0x1; -pub const EV_DELETE: u16 = 0x2; -pub const EV_ENABLE: u16 = 0x4; -pub const EV_DISABLE: u16 = 0x8; -pub const EV_ONESHOT: u16 = 0x10; -pub const EV_CLEAR: u16 = 0x20; -pub const EV_RECEIPT: u16 = 0x40; -pub const EV_DISPATCH: u16 = 0x80; -pub const EV_DROP: u16 = 0x1000; -pub const EV_FLAG1: u16 = 0x2000; -pub const EV_ERROR: u16 = 0x4000; -pub const EV_EOF: u16 = 0x8000; -pub const EV_SYSFLAGS: u16 = 0xf000; - -pub const NOTE_TRIGGER: u32 = 0x01000000; -pub const NOTE_FFNOP: u32 = 0x00000000; -pub const NOTE_FFAND: u32 = 0x40000000; -pub const NOTE_FFOR: u32 = 0x80000000; -pub const NOTE_FFCOPY: u32 = 0xc0000000; -pub const NOTE_FFCTRLMASK: u32 = 0xc0000000; -pub const NOTE_FFLAGSMASK: u32 = 0x00ffffff; -pub const NOTE_LOWAT: u32 = 0x00000001; -pub const NOTE_DELETE: u32 = 0x00000001; -pub const NOTE_WRITE: u32 = 0x00000002; -pub const NOTE_EXTEND: u32 = 0x00000004; -pub const NOTE_ATTRIB: u32 = 0x00000008; -pub const NOTE_LINK: u32 = 0x00000010; -pub const NOTE_RENAME: u32 = 0x00000020; -pub const NOTE_REVOKE: u32 = 0x00000040; -pub const NOTE_EXIT: u32 = 0x80000000; -pub const NOTE_FORK: u32 = 0x40000000; -pub const NOTE_EXEC: u32 = 0x20000000; -pub const NOTE_PDATAMASK: u32 = 0x000fffff; -pub const NOTE_PCTRLMASK: u32 = 0xf0000000; -pub const NOTE_TRACK: u32 = 0x00000001; -pub const NOTE_TRACKERR: u32 = 0x00000002; -pub const NOTE_CHILD: u32 = 0x00000004; -pub const NOTE_SECONDS: u32 = 0x00000001; -pub const NOTE_MSECONDS: u32 = 0x00000002; -pub const NOTE_USECONDS: u32 = 0x00000004; -pub const NOTE_NSECONDS: u32 = 0x00000008; - -pub const MADV_PROTECT: ::c_int = 10; -pub const RUSAGE_THREAD: ::c_int = 1; - -pub const CLOCK_REALTIME: ::clockid_t = 0; -pub const CLOCK_VIRTUAL: ::clockid_t = 1; -pub const CLOCK_PROF: ::clockid_t = 2; -pub const CLOCK_MONOTONIC: ::clockid_t = 4; -pub const CLOCK_UPTIME: ::clockid_t = 5; -pub const CLOCK_UPTIME_PRECISE: ::clockid_t = 7; -pub const CLOCK_UPTIME_FAST: ::clockid_t = 8; -pub const CLOCK_REALTIME_PRECISE: ::clockid_t = 9; -pub const CLOCK_REALTIME_FAST: ::clockid_t = 10; -pub const CLOCK_MONOTONIC_PRECISE: ::clockid_t = 11; -pub const CLOCK_MONOTONIC_FAST: ::clockid_t = 12; -pub const CLOCK_SECOND: ::clockid_t = 13; -pub const CLOCK_THREAD_CPUTIME_ID: ::clockid_t = 14; -pub const CLOCK_PROCESS_CPUTIME_ID: ::clockid_t = 15; - -pub const CTL_UNSPEC: ::c_int = 0; -pub const CTL_KERN: ::c_int = 1; -pub const CTL_VM: ::c_int = 2; -pub const CTL_VFS: ::c_int = 3; -pub const CTL_NET: ::c_int = 4; -pub const CTL_DEBUG: ::c_int = 5; -pub const CTL_HW: ::c_int = 6; -pub const CTL_MACHDEP: ::c_int = 7; -pub const CTL_USER: ::c_int = 8; -pub const CTL_P1003_1B: ::c_int = 9; -pub const KERN_OSTYPE: ::c_int = 1; -pub const KERN_OSRELEASE: ::c_int = 2; -pub const KERN_OSREV: ::c_int = 3; -pub const KERN_VERSION: ::c_int = 4; -pub const KERN_MAXVNODES: ::c_int = 5; -pub const KERN_MAXPROC: ::c_int = 6; -pub const KERN_MAXFILES: ::c_int = 7; -pub const KERN_ARGMAX: ::c_int = 8; -pub const KERN_SECURELVL: ::c_int = 9; -pub const KERN_HOSTNAME: ::c_int = 10; -pub const KERN_HOSTID: ::c_int = 11; -pub const KERN_CLOCKRATE: ::c_int = 12; -pub const KERN_VNODE: ::c_int = 13; -pub const KERN_PROC: ::c_int = 14; -pub const KERN_FILE: ::c_int = 15; -pub const KERN_PROF: ::c_int = 16; -pub const KERN_POSIX1: ::c_int = 17; -pub const KERN_NGROUPS: ::c_int = 18; -pub const KERN_JOB_CONTROL: ::c_int = 19; -pub const KERN_SAVED_IDS: ::c_int = 20; -pub const KERN_BOOTTIME: ::c_int = 21; -pub const KERN_NISDOMAINNAME: ::c_int = 22; -pub const KERN_UPDATEINTERVAL: ::c_int = 23; -pub const KERN_OSRELDATE: ::c_int = 24; -pub const KERN_NTP_PLL: ::c_int = 25; -pub const KERN_BOOTFILE: ::c_int = 26; -pub const KERN_MAXFILESPERPROC: ::c_int = 27; -pub const KERN_MAXPROCPERUID: ::c_int = 28; -pub const KERN_DUMPDEV: ::c_int = 29; -pub const KERN_IPC: ::c_int = 30; -pub const KERN_DUMMY: ::c_int = 31; -pub const KERN_PS_STRINGS: ::c_int = 32; -pub const KERN_USRSTACK: ::c_int = 33; -pub const KERN_LOGSIGEXIT: ::c_int = 34; -pub const KERN_IOV_MAX: ::c_int = 35; -pub const KERN_HOSTUUID: ::c_int = 36; -pub const KERN_ARND: ::c_int = 37; -pub const KERN_PROC_ALL: ::c_int = 0; -pub const KERN_PROC_PID: ::c_int = 1; -pub const KERN_PROC_PGRP: ::c_int = 2; -pub const KERN_PROC_SESSION: ::c_int = 3; -pub const KERN_PROC_TTY: ::c_int = 4; -pub const KERN_PROC_UID: ::c_int = 5; -pub const KERN_PROC_RUID: ::c_int = 6; -pub const KERN_PROC_ARGS: ::c_int = 7; -pub const KERN_PROC_PROC: ::c_int = 8; -pub const KERN_PROC_SV_NAME: ::c_int = 9; -pub const KERN_PROC_RGID: ::c_int = 10; -pub const KERN_PROC_GID: ::c_int = 11; -pub const KERN_PROC_PATHNAME: ::c_int = 12; -pub const KERN_PROC_OVMMAP: ::c_int = 13; -pub const KERN_PROC_OFILEDESC: ::c_int = 14; -pub const KERN_PROC_KSTACK: ::c_int = 15; -pub const KERN_PROC_INC_THREAD: ::c_int = 0x10; -pub const KERN_PROC_VMMAP: ::c_int = 32; -pub const KERN_PROC_FILEDESC: ::c_int = 33; -pub const KERN_PROC_GROUPS: ::c_int = 34; -pub const KERN_PROC_ENV: ::c_int = 35; -pub const KERN_PROC_AUXV: ::c_int = 36; -pub const KERN_PROC_RLIMIT: ::c_int = 37; -pub const KERN_PROC_PS_STRINGS: ::c_int = 38; -pub const KERN_PROC_UMASK: ::c_int = 39; -pub const KERN_PROC_OSREL: ::c_int = 40; -pub const KERN_PROC_SIGTRAMP: ::c_int = 41; -pub const KIPC_MAXSOCKBUF: ::c_int = 1; -pub const KIPC_SOCKBUF_WASTE: ::c_int = 2; -pub const KIPC_SOMAXCONN: ::c_int = 3; -pub const KIPC_MAX_LINKHDR: ::c_int = 4; -pub const KIPC_MAX_PROTOHDR: ::c_int = 5; -pub const KIPC_MAX_HDR: ::c_int = 6; -pub const KIPC_MAX_DATALEN: ::c_int = 7; -pub const HW_MACHINE: ::c_int = 1; -pub const HW_MODEL: ::c_int = 2; -pub const HW_NCPU: ::c_int = 3; -pub const HW_BYTEORDER: ::c_int = 4; -pub const HW_PHYSMEM: ::c_int = 5; -pub const HW_USERMEM: ::c_int = 6; -pub const HW_PAGESIZE: ::c_int = 7; -pub const HW_DISKNAMES: ::c_int = 8; -pub const HW_DISKSTATS: ::c_int = 9; -pub const HW_FLOATINGPT: ::c_int = 10; -pub const HW_MACHINE_ARCH: ::c_int = 11; -pub const HW_REALMEM: ::c_int = 12; -pub const USER_CS_PATH: ::c_int = 1; -pub const USER_BC_BASE_MAX: ::c_int = 2; -pub const USER_BC_DIM_MAX: ::c_int = 3; -pub const USER_BC_SCALE_MAX: ::c_int = 4; -pub const USER_BC_STRING_MAX: ::c_int = 5; -pub const USER_COLL_WEIGHTS_MAX: ::c_int = 6; -pub const USER_EXPR_NEST_MAX: ::c_int = 7; -pub const USER_LINE_MAX: ::c_int = 8; -pub const USER_RE_DUP_MAX: ::c_int = 9; -pub const USER_POSIX2_VERSION: ::c_int = 10; -pub const USER_POSIX2_C_BIND: ::c_int = 11; -pub const USER_POSIX2_C_DEV: ::c_int = 12; -pub const USER_POSIX2_CHAR_TERM: ::c_int = 13; -pub const USER_POSIX2_FORT_DEV: ::c_int = 14; -pub const USER_POSIX2_FORT_RUN: ::c_int = 15; -pub const USER_POSIX2_LOCALEDEF: ::c_int = 16; -pub const USER_POSIX2_SW_DEV: ::c_int = 17; -pub const USER_POSIX2_UPE: ::c_int = 18; -pub const USER_STREAM_MAX: ::c_int = 19; -pub const USER_TZNAME_MAX: ::c_int = 20; -pub const CTL_P1003_1B_ASYNCHRONOUS_IO: ::c_int = 1; -pub const CTL_P1003_1B_MAPPED_FILES: ::c_int = 2; -pub const CTL_P1003_1B_MEMLOCK: ::c_int = 3; -pub const CTL_P1003_1B_MEMLOCK_RANGE: ::c_int = 4; -pub const CTL_P1003_1B_MEMORY_PROTECTION: ::c_int = 5; -pub const CTL_P1003_1B_MESSAGE_PASSING: ::c_int = 6; -pub const CTL_P1003_1B_PRIORITIZED_IO: ::c_int = 7; -pub const CTL_P1003_1B_PRIORITY_SCHEDULING: ::c_int = 8; -pub const CTL_P1003_1B_REALTIME_SIGNALS: ::c_int = 9; -pub const CTL_P1003_1B_SEMAPHORES: ::c_int = 10; -pub const CTL_P1003_1B_FSYNC: ::c_int = 11; -pub const CTL_P1003_1B_SHARED_MEMORY_OBJECTS: ::c_int = 12; -pub const CTL_P1003_1B_SYNCHRONIZED_IO: ::c_int = 13; -pub const CTL_P1003_1B_TIMERS: ::c_int = 14; -pub const CTL_P1003_1B_AIO_LISTIO_MAX: ::c_int = 15; -pub const CTL_P1003_1B_AIO_MAX: ::c_int = 16; -pub const CTL_P1003_1B_AIO_PRIO_DELTA_MAX: ::c_int = 17; -pub const CTL_P1003_1B_DELAYTIMER_MAX: ::c_int = 18; -pub const CTL_P1003_1B_MQ_OPEN_MAX: ::c_int = 19; -pub const CTL_P1003_1B_PAGESIZE: ::c_int = 20; -pub const CTL_P1003_1B_RTSIG_MAX: ::c_int = 21; -pub const CTL_P1003_1B_SEM_NSEMS_MAX: ::c_int = 22; -pub const CTL_P1003_1B_SEM_VALUE_MAX: ::c_int = 23; -pub const CTL_P1003_1B_SIGQUEUE_MAX: ::c_int = 24; -pub const CTL_P1003_1B_TIMER_MAX: ::c_int = 25; -pub const TIOCGPTN: ::c_uint = 0x4004740f; -pub const TIOCPTMASTER: ::c_uint = 0x2000741c; -pub const TIOCSIG: ::c_uint = 0x2004745f; -pub const TIOCM_DCD: ::c_int = 0x40; -pub const H4DISC: ::c_int = 0x7; - -pub const BIOCSETFNR: ::c_ulong = 0x80104282; - -pub const FIONWRITE: ::c_ulong = 0x40046677; -pub const FIONSPACE: ::c_ulong = 0x40046676; -pub const FIOSEEKDATA: ::c_ulong = 0xc0086661; -pub const FIOSEEKHOLE: ::c_ulong = 0xc0086662; - -pub const JAIL_API_VERSION: u32 = 2; -pub const JAIL_CREATE: ::c_int = 0x01; -pub const JAIL_UPDATE: ::c_int = 0x02; -pub const JAIL_ATTACH: ::c_int = 0x04; -pub const JAIL_DYING: ::c_int = 0x08; -pub const JAIL_SET_MASK: ::c_int = 0x0f; -pub const JAIL_GET_MASK: ::c_int = 0x08; -pub const JAIL_SYS_DISABLE: ::c_int = 0; -pub const JAIL_SYS_NEW: ::c_int = 1; -pub const JAIL_SYS_INHERIT: ::c_int = 2; - -pub const SO_BINTIME: ::c_int = 0x2000; -pub const SO_NO_OFFLOAD: ::c_int = 0x4000; -pub const SO_NO_DDP: ::c_int = 0x8000; -pub const SO_REUSEPORT_LB: ::c_int = 0x10000; -pub const SO_LABEL: ::c_int = 0x1009; -pub const SO_PEERLABEL: ::c_int = 0x1010; -pub const SO_LISTENQLIMIT: ::c_int = 0x1011; -pub const SO_LISTENQLEN: ::c_int = 0x1012; -pub const SO_LISTENINCQLEN: ::c_int = 0x1013; -pub const SO_SETFIB: ::c_int = 0x1014; -pub const SO_USER_COOKIE: ::c_int = 0x1015; -pub const SO_PROTOCOL: ::c_int = 0x1016; -pub const SO_PROTOTYPE: ::c_int = SO_PROTOCOL; -pub const SO_VENDOR: ::c_int = 0x80000000; - -pub const LOCAL_PEERCRED: ::c_int = 1; -pub const LOCAL_CREDS: ::c_int = 2; -pub const LOCAL_CONNWAIT: ::c_int = 4; -pub const LOCAL_VENDOR: ::c_int = SO_VENDOR; - -pub const PT_LWPINFO: ::c_int = 13; -pub const PT_GETNUMLWPS: ::c_int = 14; -pub const PT_GETLWPLIST: ::c_int = 15; -pub const PT_CLEARSTEP: ::c_int = 16; -pub const PT_SETSTEP: ::c_int = 17; -pub const PT_SUSPEND: ::c_int = 18; -pub const PT_RESUME: ::c_int = 19; -pub const PT_TO_SCE: ::c_int = 20; -pub const PT_TO_SCX: ::c_int = 21; -pub const PT_SYSCALL: ::c_int = 22; -pub const PT_FOLLOW_FORK: ::c_int = 23; -pub const PT_LWP_EVENTS: ::c_int = 24; -pub const PT_GET_EVENT_MASK: ::c_int = 25; -pub const PT_SET_EVENT_MASK: ::c_int = 26; -pub const PT_GETREGS: ::c_int = 33; -pub const PT_SETREGS: ::c_int = 34; -pub const PT_GETFPREGS: ::c_int = 35; -pub const PT_SETFPREGS: ::c_int = 36; -pub const PT_GETDBREGS: ::c_int = 37; -pub const PT_SETDBREGS: ::c_int = 38; -pub const PT_VM_TIMESTAMP: ::c_int = 40; -pub const PT_VM_ENTRY: ::c_int = 41; -pub const PT_FIRSTMACH: ::c_int = 64; - -pub const PTRACE_EXEC: ::c_int = 0x0001; -pub const PTRACE_SCE: ::c_int = 0x0002; -pub const PTRACE_SCX: ::c_int = 0x0004; -pub const PTRACE_SYSCALL: ::c_int = PTRACE_SCE | PTRACE_SCX; -pub const PTRACE_FORK: ::c_int = 0x0008; -pub const PTRACE_LWP: ::c_int = 0x0010; -pub const PTRACE_VFORK: ::c_int = 0x0020; -pub const PTRACE_DEFAULT: ::c_int = PTRACE_EXEC; - -pub const AF_SLOW: ::c_int = 33; -pub const AF_SCLUSTER: ::c_int = 34; -pub const AF_ARP: ::c_int = 35; -pub const AF_BLUETOOTH: ::c_int = 36; -pub const AF_IEEE80211: ::c_int = 37; -pub const AF_INET_SDP: ::c_int = 40; -pub const AF_INET6_SDP: ::c_int = 42; - -// https://github.com/freebsd/freebsd/blob/master/sys/net/if.h#L140 -pub const IFF_UP: ::c_int = 0x1; // (n) interface is up -pub const IFF_BROADCAST: ::c_int = 0x2; // (i) broadcast address valid -pub const IFF_DEBUG: ::c_int = 0x4; // (n) turn on debugging -pub const IFF_LOOPBACK: ::c_int = 0x8; // (i) is a loopback net -pub const IFF_POINTOPOINT: ::c_int = 0x10; // (i) is a point-to-point link - // 0x20 was IFF_SMART -pub const IFF_RUNNING: ::c_int = 0x40; // (d) resources allocated -#[doc(hidden)] -#[deprecated( - since = "0.2.54", - note = "IFF_DRV_RUNNING is deprecated. Use the portable IFF_RUNNING instead" -)] -pub const IFF_DRV_RUNNING: ::c_int = 0x40; -pub const IFF_NOARP: ::c_int = 0x80; // (n) no address resolution protocol -pub const IFF_PROMISC: ::c_int = 0x100; // (n) receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x200; // (n) receive all multicast packets -pub const IFF_OACTIVE: ::c_int = 0x400; // (d) tx hardware queue is full -#[doc(hidden)] -#[deprecated( - since = "0.2.54", - note = "Use the portable `IFF_OACTIVE` instead" -)] -pub const IFF_DRV_OACTIVE: ::c_int = 0x400; -pub const IFF_SIMPLEX: ::c_int = 0x800; // (i) can't hear own transmissions -pub const IFF_LINK0: ::c_int = 0x1000; // per link layer defined bit -pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit -pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit -pub const IFF_ALTPHYS: ::c_int = IFF_LINK2; // use alternate physical connection -pub const IFF_MULTICAST: ::c_int = 0x8000; // (i) supports multicast - // (i) unconfigurable using ioctl(2) -pub const IFF_CANTCONFIG: ::c_int = 0x10000; -pub const IFF_PPROMISC: ::c_int = 0x20000; // (n) user-requested promisc mode -pub const IFF_MONITOR: ::c_int = 0x40000; // (n) user-requested monitor mode -pub const IFF_STATICARP: ::c_int = 0x80000; // (n) static ARP -pub const IFF_DYING: ::c_int = 0x200000; // (n) interface is winding down -pub const IFF_RENAMING: ::c_int = 0x400000; // (n) interface is being renamed - -// sys/netinet/in.h -// Protocols (RFC 1700) -// NOTE: These are in addition to the constants defined in src/unix/mod.rs - -// IPPROTO_IP defined in src/unix/mod.rs -/// IP6 hop-by-hop options -pub const IPPROTO_HOPOPTS: ::c_int = 0; -// IPPROTO_ICMP defined in src/unix/mod.rs -/// group mgmt protocol -pub const IPPROTO_IGMP: ::c_int = 2; -/// gateway^2 (deprecated) -pub const IPPROTO_GGP: ::c_int = 3; -/// for compatibility -pub const IPPROTO_IPIP: ::c_int = 4; -// IPPROTO_TCP defined in src/unix/mod.rs -/// Stream protocol II. -pub const IPPROTO_ST: ::c_int = 7; -/// exterior gateway protocol -pub const IPPROTO_EGP: ::c_int = 8; -/// private interior gateway -pub const IPPROTO_PIGP: ::c_int = 9; -/// BBN RCC Monitoring -pub const IPPROTO_RCCMON: ::c_int = 10; -/// network voice protocol -pub const IPPROTO_NVPII: ::c_int = 11; -/// pup -pub const IPPROTO_PUP: ::c_int = 12; -/// Argus -pub const IPPROTO_ARGUS: ::c_int = 13; -/// EMCON -pub const IPPROTO_EMCON: ::c_int = 14; -/// Cross Net Debugger -pub const IPPROTO_XNET: ::c_int = 15; -/// Chaos -pub const IPPROTO_CHAOS: ::c_int = 16; -// IPPROTO_UDP defined in src/unix/mod.rs -/// Multiplexing -pub const IPPROTO_MUX: ::c_int = 18; -/// DCN Measurement Subsystems -pub const IPPROTO_MEAS: ::c_int = 19; -/// Host Monitoring -pub const IPPROTO_HMP: ::c_int = 20; -/// Packet Radio Measurement -pub const IPPROTO_PRM: ::c_int = 21; -/// xns idp -pub const IPPROTO_IDP: ::c_int = 22; -/// Trunk-1 -pub const IPPROTO_TRUNK1: ::c_int = 23; -/// Trunk-2 -pub const IPPROTO_TRUNK2: ::c_int = 24; -/// Leaf-1 -pub const IPPROTO_LEAF1: ::c_int = 25; -/// Leaf-2 -pub const IPPROTO_LEAF2: ::c_int = 26; -/// Reliable Data -pub const IPPROTO_RDP: ::c_int = 27; -/// Reliable Transaction -pub const IPPROTO_IRTP: ::c_int = 28; -/// tp-4 w/ class negotiation -pub const IPPROTO_TP: ::c_int = 29; -/// Bulk Data Transfer -pub const IPPROTO_BLT: ::c_int = 30; -/// Network Services -pub const IPPROTO_NSP: ::c_int = 31; -/// Merit Internodal -pub const IPPROTO_INP: ::c_int = 32; -/// Sequential Exchange -pub const IPPROTO_SEP: ::c_int = 33; -/// Third Party Connect -pub const IPPROTO_3PC: ::c_int = 34; -/// InterDomain Policy Routing -pub const IPPROTO_IDPR: ::c_int = 35; -/// XTP -pub const IPPROTO_XTP: ::c_int = 36; -/// Datagram Delivery -pub const IPPROTO_DDP: ::c_int = 37; -/// Control Message Transport -pub const IPPROTO_CMTP: ::c_int = 38; -/// TP++ Transport -pub const IPPROTO_TPXX: ::c_int = 39; -/// IL transport protocol -pub const IPPROTO_IL: ::c_int = 40; -// IPPROTO_IPV6 defined in src/unix/mod.rs -/// Source Demand Routing -pub const IPPROTO_SDRP: ::c_int = 42; -/// IP6 routing header -pub const IPPROTO_ROUTING: ::c_int = 43; -/// IP6 fragmentation header -pub const IPPROTO_FRAGMENT: ::c_int = 44; -/// InterDomain Routing -pub const IPPROTO_IDRP: ::c_int = 45; -/// resource reservation -pub const IPPROTO_RSVP: ::c_int = 46; -/// General Routing Encap. -pub const IPPROTO_GRE: ::c_int = 47; -/// Mobile Host Routing -pub const IPPROTO_MHRP: ::c_int = 48; -/// BHA -pub const IPPROTO_BHA: ::c_int = 49; -/// IP6 Encap Sec. Payload -pub const IPPROTO_ESP: ::c_int = 50; -/// IP6 Auth Header -pub const IPPROTO_AH: ::c_int = 51; -/// Integ. Net Layer Security -pub const IPPROTO_INLSP: ::c_int = 52; -/// IP with encryption -pub const IPPROTO_SWIPE: ::c_int = 53; -/// Next Hop Resolution -pub const IPPROTO_NHRP: ::c_int = 54; -/// IP Mobility -pub const IPPROTO_MOBILE: ::c_int = 55; -/// Transport Layer Security -pub const IPPROTO_TLSP: ::c_int = 56; -/// SKIP -pub const IPPROTO_SKIP: ::c_int = 57; -// IPPROTO_ICMPV6 defined in src/unix/mod.rs -/// IP6 no next header -pub const IPPROTO_NONE: ::c_int = 59; -/// IP6 destination option -pub const IPPROTO_DSTOPTS: ::c_int = 60; -/// any host internal protocol -pub const IPPROTO_AHIP: ::c_int = 61; -/// CFTP -pub const IPPROTO_CFTP: ::c_int = 62; -/// "hello" routing protocol -pub const IPPROTO_HELLO: ::c_int = 63; -/// SATNET/Backroom EXPAK -pub const IPPROTO_SATEXPAK: ::c_int = 64; -/// Kryptolan -pub const IPPROTO_KRYPTOLAN: ::c_int = 65; -/// Remote Virtual Disk -pub const IPPROTO_RVD: ::c_int = 66; -/// Pluribus Packet Core -pub const IPPROTO_IPPC: ::c_int = 67; -/// Any distributed FS -pub const IPPROTO_ADFS: ::c_int = 68; -/// Satnet Monitoring -pub const IPPROTO_SATMON: ::c_int = 69; -/// VISA Protocol -pub const IPPROTO_VISA: ::c_int = 70; -/// Packet Core Utility -pub const IPPROTO_IPCV: ::c_int = 71; -/// Comp. Prot. Net. Executive -pub const IPPROTO_CPNX: ::c_int = 72; -/// Comp. Prot. HeartBeat -pub const IPPROTO_CPHB: ::c_int = 73; -/// Wang Span Network -pub const IPPROTO_WSN: ::c_int = 74; -/// Packet Video Protocol -pub const IPPROTO_PVP: ::c_int = 75; -/// BackRoom SATNET Monitoring -pub const IPPROTO_BRSATMON: ::c_int = 76; -/// Sun net disk proto (temp.) -pub const IPPROTO_ND: ::c_int = 77; -/// WIDEBAND Monitoring -pub const IPPROTO_WBMON: ::c_int = 78; -/// WIDEBAND EXPAK -pub const IPPROTO_WBEXPAK: ::c_int = 79; -/// ISO cnlp -pub const IPPROTO_EON: ::c_int = 80; -/// VMTP -pub const IPPROTO_VMTP: ::c_int = 81; -/// Secure VMTP -pub const IPPROTO_SVMTP: ::c_int = 82; -/// Banyon VINES -pub const IPPROTO_VINES: ::c_int = 83; -/// TTP -pub const IPPROTO_TTP: ::c_int = 84; -/// NSFNET-IGP -pub const IPPROTO_IGP: ::c_int = 85; -/// dissimilar gateway prot. -pub const IPPROTO_DGP: ::c_int = 86; -/// TCF -pub const IPPROTO_TCF: ::c_int = 87; -/// Cisco/GXS IGRP -pub const IPPROTO_IGRP: ::c_int = 88; -/// OSPFIGP -pub const IPPROTO_OSPFIGP: ::c_int = 89; -/// Strite RPC protocol -pub const IPPROTO_SRPC: ::c_int = 90; -/// Locus Address Resoloution -pub const IPPROTO_LARP: ::c_int = 91; -/// Multicast Transport -pub const IPPROTO_MTP: ::c_int = 92; -/// AX.25 Frames -pub const IPPROTO_AX25: ::c_int = 93; -/// IP encapsulated in IP -pub const IPPROTO_IPEIP: ::c_int = 94; -/// Mobile Int.ing control -pub const IPPROTO_MICP: ::c_int = 95; -/// Semaphore Comm. security -pub const IPPROTO_SCCSP: ::c_int = 96; -/// Ethernet IP encapsulation -pub const IPPROTO_ETHERIP: ::c_int = 97; -/// encapsulation header -pub const IPPROTO_ENCAP: ::c_int = 98; -/// any private encr. scheme -pub const IPPROTO_APES: ::c_int = 99; -/// GMTP -pub const IPPROTO_GMTP: ::c_int = 100; -/// payload compression (IPComp) -pub const IPPROTO_IPCOMP: ::c_int = 108; -/// SCTP -pub const IPPROTO_SCTP: ::c_int = 132; -/// IPv6 Mobility Header -pub const IPPROTO_MH: ::c_int = 135; -/// UDP-Lite -pub const IPPROTO_UDPLITE: ::c_int = 136; -/// IP6 Host Identity Protocol -pub const IPPROTO_HIP: ::c_int = 139; -/// IP6 Shim6 Protocol -pub const IPPROTO_SHIM6: ::c_int = 140; - -/* 101-254: Partly Unassigned */ -/// Protocol Independent Mcast -pub const IPPROTO_PIM: ::c_int = 103; -/// CARP -pub const IPPROTO_CARP: ::c_int = 112; -/// PGM -pub const IPPROTO_PGM: ::c_int = 113; -/// MPLS-in-IP -pub const IPPROTO_MPLS: ::c_int = 137; -/// PFSYNC -pub const IPPROTO_PFSYNC: ::c_int = 240; - -/* 255: Reserved */ -/* BSD Private, local use, namespace incursion, no longer used */ -/// OLD divert pseudo-proto -pub const IPPROTO_OLD_DIVERT: ::c_int = 254; -pub const IPPROTO_MAX: ::c_int = 256; -/// last return value of *_input(), meaning "all job for this pkt is done". -pub const IPPROTO_DONE: ::c_int = 257; - -/* Only used internally, so can be outside the range of valid IP protocols. */ -/// divert pseudo-protocol -pub const IPPROTO_DIVERT: ::c_int = 258; -/// SeND pseudo-protocol -pub const IPPROTO_SEND: ::c_int = 259; - -// sys/netinet/TCP.h -pub const TCP_MD5SIG: ::c_int = 16; -pub const TCP_INFO: ::c_int = 32; -pub const TCP_CONGESTION: ::c_int = 64; -pub const TCP_CCALGOOPT: ::c_int = 65; -pub const TCP_KEEPINIT: ::c_int = 128; -pub const TCP_FASTOPEN: ::c_int = 1025; -pub const TCP_PCAP_OUT: ::c_int = 2048; -pub const TCP_PCAP_IN: ::c_int = 4096; - -pub const IP_BINDANY: ::c_int = 24; -pub const IP_BINDMULTI: ::c_int = 25; -pub const IP_RSS_LISTEN_BUCKET: ::c_int = 26; -pub const IP_ORIGDSTADDR: ::c_int = 27; -pub const IP_RECVORIGDSTADDR: ::c_int = IP_ORIGDSTADDR; - -pub const IP_RECVTOS: ::c_int = 68; - -pub const IPV6_ORIGDSTADDR: ::c_int = 72; -pub const IPV6_RECVORIGDSTADDR: ::c_int = IPV6_ORIGDSTADDR; - -pub const PF_SLOW: ::c_int = AF_SLOW; -pub const PF_SCLUSTER: ::c_int = AF_SCLUSTER; -pub const PF_ARP: ::c_int = AF_ARP; -pub const PF_BLUETOOTH: ::c_int = AF_BLUETOOTH; -pub const PF_IEEE80211: ::c_int = AF_IEEE80211; -pub const PF_INET_SDP: ::c_int = AF_INET_SDP; -pub const PF_INET6_SDP: ::c_int = AF_INET6_SDP; - -pub const NET_RT_DUMP: ::c_int = 1; -pub const NET_RT_FLAGS: ::c_int = 2; -pub const NET_RT_IFLIST: ::c_int = 3; -pub const NET_RT_IFMALIST: ::c_int = 4; -pub const NET_RT_IFLISTL: ::c_int = 5; - -// System V IPC -pub const IPC_PRIVATE: ::key_t = 0; -pub const IPC_CREAT: ::c_int = 0o1000; -pub const IPC_EXCL: ::c_int = 0o2000; -pub const IPC_NOWAIT: ::c_int = 0o4000; -pub const IPC_RMID: ::c_int = 0; -pub const IPC_SET: ::c_int = 1; -pub const IPC_STAT: ::c_int = 2; -pub const IPC_INFO: ::c_int = 3; -pub const IPC_R: ::c_int = 0o400; -pub const IPC_W: ::c_int = 0o200; -pub const IPC_M: ::c_int = 0o10000; -pub const MSG_NOERROR: ::c_int = 0o10000; -pub const SHM_RDONLY: ::c_int = 0o10000; -pub const SHM_RND: ::c_int = 0o20000; -pub const SHM_R: ::c_int = 0o400; -pub const SHM_W: ::c_int = 0o200; -pub const SHM_LOCK: ::c_int = 11; -pub const SHM_UNLOCK: ::c_int = 12; -pub const SHM_STAT: ::c_int = 13; -pub const SHM_INFO: ::c_int = 14; -pub const SHM_ANON: *mut ::c_char = 1 as *mut ::c_char; - -// The *_MAXID constants never should've been used outside of the -// FreeBSD base system. And with the exception of CTL_P1003_1B_MAXID, -// they were all removed in svn r262489. They remain here for backwards -// compatibility only, and are scheduled to be removed in libc 1.0.0. -#[doc(hidden)] -#[deprecated(since = "0.2.54", note = "Removed in FreeBSD 11")] -pub const CTL_MAXID: ::c_int = 10; -#[doc(hidden)] -#[deprecated(since = "0.2.54", note = "Removed in FreeBSD 11")] -pub const KERN_MAXID: ::c_int = 38; -#[doc(hidden)] -#[deprecated(since = "0.2.54", note = "Removed in FreeBSD 11")] -pub const HW_MAXID: ::c_int = 13; -#[doc(hidden)] -#[deprecated(since = "0.2.54", note = "Removed in FreeBSD 11")] -pub const USER_MAXID: ::c_int = 21; -#[doc(hidden)] -pub const CTL_P1003_1B_MAXID: ::c_int = 26; - -pub const MSG_NOTIFICATION: ::c_int = 0x00002000; -pub const MSG_NBIO: ::c_int = 0x00004000; -pub const MSG_COMPAT: ::c_int = 0x00008000; -pub const MSG_CMSG_CLOEXEC: ::c_int = 0x00040000; -pub const MSG_NOSIGNAL: ::c_int = 0x20000; - -// utmpx entry types -pub const EMPTY: ::c_short = 0; -pub const BOOT_TIME: ::c_short = 1; -pub const OLD_TIME: ::c_short = 2; -pub const NEW_TIME: ::c_short = 3; -pub const USER_PROCESS: ::c_short = 4; -pub const INIT_PROCESS: ::c_short = 5; -pub const LOGIN_PROCESS: ::c_short = 6; -pub const DEAD_PROCESS: ::c_short = 7; -pub const SHUTDOWN_TIME: ::c_short = 8; -// utmp database types -pub const UTXDB_ACTIVE: ::c_int = 0; -pub const UTXDB_LASTLOGIN: ::c_int = 1; -pub const UTXDB_LOG: ::c_int = 2; - -pub const LC_COLLATE_MASK: ::c_int = (1 << 0); -pub const LC_CTYPE_MASK: ::c_int = (1 << 1); -pub const LC_MONETARY_MASK: ::c_int = (1 << 2); -pub const LC_NUMERIC_MASK: ::c_int = (1 << 3); -pub const LC_TIME_MASK: ::c_int = (1 << 4); -pub const LC_MESSAGES_MASK: ::c_int = (1 << 5); -pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK - | LC_CTYPE_MASK - | LC_MESSAGES_MASK - | LC_MONETARY_MASK - | LC_NUMERIC_MASK - | LC_TIME_MASK; - -pub const WSTOPPED: ::c_int = 2; // same as WUNTRACED -pub const WCONTINUED: ::c_int = 4; -pub const WNOWAIT: ::c_int = 8; -pub const WEXITED: ::c_int = 16; -pub const WTRAPPED: ::c_int = 32; - -// FreeBSD defines a great many more of these, we only expose the -// standardized ones. -pub const P_PID: idtype_t = 0; -pub const P_PGID: idtype_t = 2; -pub const P_ALL: idtype_t = 7; - -pub const UTIME_OMIT: c_long = -2; -pub const UTIME_NOW: c_long = -1; - -pub const B460800: ::speed_t = 460800; -pub const B921600: ::speed_t = 921600; - -pub const AT_FDCWD: ::c_int = -100; -pub const AT_EACCESS: ::c_int = 0x100; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x200; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; -pub const AT_REMOVEDIR: ::c_int = 0x800; - -pub const TABDLY: ::tcflag_t = 0x00000004; -pub const TAB0: ::tcflag_t = 0x00000000; -pub const TAB3: ::tcflag_t = 0x00000004; - -pub const _PC_ACL_NFS4: ::c_int = 64; - -pub const _SC_CPUSET_SIZE: ::c_int = 122; - -pub const XU_NGROUPS: ::c_int = 16; -pub const XUCRED_VERSION: ::c_uint = 0; - -// Flags which can be passed to pdfork(2) -pub const PD_DAEMON: ::c_int = 0x00000001; -pub const PD_CLOEXEC: ::c_int = 0x00000002; -pub const PD_ALLOWED_AT_FORK: ::c_int = PD_DAEMON | PD_CLOEXEC; - -// Values for struct rtprio (type_ field) -pub const RTP_PRIO_REALTIME: ::c_ushort = 2; -pub const RTP_PRIO_NORMAL: ::c_ushort = 3; -pub const RTP_PRIO_IDLE: ::c_ushort = 4; - -pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x01; -pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x02; -pub const POSIX_SPAWN_SETSCHEDPARAM: ::c_int = 0x04; -pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x08; -pub const POSIX_SPAWN_SETSIGDEF: ::c_int = 0x10; -pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x20; - -// Flags for chflags(2) -pub const UF_SYSTEM: ::c_ulong = 0x00000080; -pub const UF_SPARSE: ::c_ulong = 0x00000100; -pub const UF_OFFLINE: ::c_ulong = 0x00000200; -pub const UF_REPARSE: ::c_ulong = 0x00000400; -pub const UF_ARCHIVE: ::c_ulong = 0x00000800; -pub const UF_READONLY: ::c_ulong = 0x00001000; -pub const UF_HIDDEN: ::c_ulong = 0x00008000; -pub const SF_SNAPSHOT: ::c_ulong = 0x00200000; - -fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES -} - -f! { - pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { - (cmsg as *mut ::c_uchar) - .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) - -> *mut ::cmsghdr - { - if cmsg.is_null() { - return ::CMSG_FIRSTHDR(mhdr); - }; - let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) - + _ALIGN(::mem::size_of::<::cmsghdr>()); - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next > max { - 0 as *mut ::cmsghdr - } else { - (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) - as *mut ::cmsghdr - } - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) - as ::c_uint - } - - pub fn uname(buf: *mut ::utsname) -> ::c_int { - __xuname(256, buf as *mut ::c_void) - } -} - -extern "C" { - pub fn __error() -> *mut ::c_int; - - pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_settime( - clk_id: ::clockid_t, - tp: *const ::timespec, - ) -> ::c_int; - - pub fn extattr_delete_fd( - fd: ::c_int, - attrnamespace: ::c_int, - attrname: *const ::c_char, - ) -> ::c_int; - pub fn extattr_delete_file( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - ) -> ::c_int; - pub fn extattr_delete_link( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - ) -> ::c_int; - pub fn extattr_get_fd( - fd: ::c_int, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_get_file( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_get_link( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_list_fd( - fd: ::c_int, - attrnamespace: ::c_int, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_list_file( - path: *const ::c_char, - attrnamespace: ::c_int, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_list_link( - path: *const ::c_char, - attrnamespace: ::c_int, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_set_fd( - fd: ::c_int, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *const ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_set_file( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *const ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_set_link( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *const ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - - pub fn jail(jail: *mut ::jail) -> ::c_int; - pub fn jail_attach(jid: ::c_int) -> ::c_int; - pub fn jail_remove(jid: ::c_int) -> ::c_int; - pub fn jail_get( - iov: *mut ::iovec, - niov: ::c_uint, - flags: ::c_int, - ) -> ::c_int; - pub fn jail_set( - iov: *mut ::iovec, - niov: ::c_uint, - flags: ::c_int, - ) -> ::c_int; - - pub fn fdatasync(fd: ::c_int) -> ::c_int; - pub fn posix_fallocate( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - ) -> ::c_int; - pub fn posix_fadvise( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - advise: ::c_int, - ) -> ::c_int; - pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int; - pub fn mkostemps( - template: *mut ::c_char, - suffixlen: ::c_int, - flags: ::c_int, - ) -> ::c_int; - - pub fn getutxuser(user: *const ::c_char) -> *mut utmpx; - pub fn setutxdb(_type: ::c_int, file: *const ::c_char) -> ::c_int; - - pub fn aio_waitcomplete( - iocbp: *mut *mut aiocb, - timeout: *mut ::timespec, - ) -> ::ssize_t; - pub fn mq_getfd_np(mqd: ::mqd_t) -> ::c_int; - - pub fn waitid( - idtype: idtype_t, - id: ::id_t, - infop: *mut ::siginfo_t, - options: ::c_int, - ) -> ::c_int; - - pub fn ftok(pathname: *const ::c_char, proj_id: ::c_int) -> ::key_t; - pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int; - pub fn shmat( - shmid: ::c_int, - shmaddr: *const ::c_void, - shmflg: ::c_int, - ) -> *mut ::c_void; - pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int; - pub fn shmctl( - shmid: ::c_int, - cmd: ::c_int, - buf: *mut ::shmid_ds, - ) -> ::c_int; - pub fn msgctl( - msqid: ::c_int, - cmd: ::c_int, - buf: *mut ::msqid_ds, - ) -> ::c_int; - pub fn msgget(key: ::key_t, msgflg: ::c_int) -> ::c_int; - pub fn msgsnd( - msqid: ::c_int, - msgp: *const ::c_void, - msgsz: ::size_t, - msgflg: ::c_int, - ) -> ::c_int; - pub fn cfmakesane(termios: *mut ::termios); - pub fn fexecve( - fd: ::c_int, - argv: *const *const ::c_char, - envp: *const *const ::c_char, - ) -> ::c_int; - - pub fn pdfork(fdp: *mut ::c_int, flags: ::c_int) -> ::pid_t; - pub fn pdgetpid(fd: ::c_int, pidp: *mut ::pid_t) -> ::c_int; - pub fn pdkill(fd: ::c_int, signum: ::c_int) -> ::c_int; - - pub fn rtprio_thread( - function: ::c_int, - lwpid: ::lwpid_t, - rtp: *mut super::rtprio, - ) -> ::c_int; - - pub fn posix_spawn( - pid: *mut ::pid_t, - path: *const ::c_char, - file_actions: *const ::posix_spawn_file_actions_t, - attrp: *const ::posix_spawnattr_t, - argv: *const *mut ::c_char, - envp: *const *mut ::c_char, - ) -> ::c_int; - pub fn posix_spawnp( - pid: *mut ::pid_t, - file: *const ::c_char, - file_actions: *const ::posix_spawn_file_actions_t, - attrp: *const ::posix_spawnattr_t, - argv: *const *mut ::c_char, - envp: *const *mut ::c_char, - ) -> ::c_int; - pub fn posix_spawnattr_init(attr: *mut posix_spawnattr_t) -> ::c_int; - pub fn posix_spawnattr_destroy(attr: *mut posix_spawnattr_t) -> ::c_int; - pub fn posix_spawnattr_getsigdefault( - attr: *const posix_spawnattr_t, - default: *mut ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_setsigdefault( - attr: *mut posix_spawnattr_t, - default: *const ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_getsigmask( - attr: *const posix_spawnattr_t, - default: *mut ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_setsigmask( - attr: *mut posix_spawnattr_t, - default: *const ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_getflags( - attr: *const posix_spawnattr_t, - flags: *mut ::c_short, - ) -> ::c_int; - pub fn posix_spawnattr_setflags( - attr: *mut posix_spawnattr_t, - flags: ::c_short, - ) -> ::c_int; - pub fn posix_spawnattr_getpgroup( - attr: *const posix_spawnattr_t, - flags: *mut ::pid_t, - ) -> ::c_int; - pub fn posix_spawnattr_setpgroup( - attr: *mut posix_spawnattr_t, - flags: ::pid_t, - ) -> ::c_int; - pub fn posix_spawnattr_getschedpolicy( - attr: *const posix_spawnattr_t, - flags: *mut ::c_int, - ) -> ::c_int; - pub fn posix_spawnattr_setschedpolicy( - attr: *mut posix_spawnattr_t, - flags: ::c_int, - ) -> ::c_int; - pub fn posix_spawnattr_getschedparam( - attr: *const posix_spawnattr_t, - param: *mut ::sched_param, - ) -> ::c_int; - pub fn posix_spawnattr_setschedparam( - attr: *mut posix_spawnattr_t, - param: *const ::sched_param, - ) -> ::c_int; - - pub fn posix_spawn_file_actions_init( - actions: *mut posix_spawn_file_actions_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_destroy( - actions: *mut posix_spawn_file_actions_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_addopen( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - path: *const ::c_char, - oflag: ::c_int, - mode: ::mode_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_addclose( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - ) -> ::c_int; - pub fn posix_spawn_file_actions_adddup2( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - newfd: ::c_int, - ) -> ::c_int; - - #[cfg_attr( - all(target_os = "freebsd", freebsd11), - link_name = "statfs@FBSD_1.0" - )] - pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; - #[cfg_attr( - all(target_os = "freebsd", freebsd11), - link_name = "fstatfs@FBSD_1.0" - )] - pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; - - pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int; - pub fn __xuname(nmln: ::c_int, buf: *mut ::c_void) -> ::c_int; - - pub fn sendmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - pub fn recvmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::size_t, - flags: ::c_int, - timeout: *const ::timespec, - ) -> ::ssize_t; -} - -#[link(name = "util")] -extern "C" { - pub fn extattr_namespace_to_string( - attrnamespace: ::c_int, - string: *mut *mut ::c_char, - ) -> ::c_int; - pub fn extattr_string_to_namespace( - string: *const ::c_char, - attrnamespace: *mut ::c_int, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(freebsd12)] { - mod freebsd12; - pub use self::freebsd12::*; - } else if #[cfg(freebsd13)] { - mod freebsd12; - pub use self::freebsd12::*; - } else if #[cfg(any(freebsd10, freebsd11))] { - mod freebsd11; - pub use self::freebsd11::*; - } else { - // Unknown freebsd version - } -} - -cfg_if! { - if #[cfg(target_arch = "x86")] { - mod x86; - pub use self::x86::*; - } else if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } else if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(target_arch = "arm")] { - mod arm; - pub use self::arm::*; - } else if #[cfg(target_arch = "powerpc64")] { - mod powerpc64; - pub use self::powerpc64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs b/libc/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs deleted file mode 100644 index 5c0c6e7..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/powerpc64.rs +++ /dev/null @@ -1,44 +0,0 @@ -pub type c_char = u8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type time_t = i64; -pub type suseconds_t = i64; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - } -} - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} - -pub const MAP_32BIT: ::c_int = 0x00080000; diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/x86.rs b/libc/src/unix/bsd/freebsdlike/freebsd/x86.rs deleted file mode 100644 index adec88c..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/x86.rs +++ /dev/null @@ -1,43 +0,0 @@ -pub type c_char = i8; -pub type c_long = i32; -pub type c_ulong = u32; -pub type time_t = i32; -pub type suseconds_t = i32; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: u32, - pub st_lspare: i32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - __unused: [u8; 8], - } -} - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs b/libc/src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs deleted file mode 100644 index 7ca870f..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 4] - } -} diff --git a/libc/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs b/libc/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs deleted file mode 100644 index 0769a22..0000000 --- a/libc/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -pub type c_char = i8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type time_t = i64; -pub type suseconds_t = i64; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} -pub const MAP_32BIT: ::c_int = 0x00080000; - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/bsd/freebsdlike/mod.rs b/libc/src/unix/bsd/freebsdlike/mod.rs deleted file mode 100644 index 1b7804c..0000000 --- a/libc/src/unix/bsd/freebsdlike/mod.rs +++ /dev/null @@ -1,1466 +0,0 @@ -pub type mode_t = u16; -pub type pthread_attr_t = *mut ::c_void; -pub type rlim_t = i64; -pub type pthread_mutex_t = *mut ::c_void; -pub type pthread_mutexattr_t = *mut ::c_void; -pub type pthread_cond_t = *mut ::c_void; -pub type pthread_condattr_t = *mut ::c_void; -pub type pthread_rwlock_t = *mut ::c_void; -pub type pthread_rwlockattr_t = *mut ::c_void; -pub type pthread_key_t = ::c_int; -pub type tcflag_t = ::c_uint; -pub type speed_t = ::c_uint; -pub type nl_item = ::c_int; -pub type id_t = i64; -pub type vm_size_t = ::uintptr_t; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} - -impl siginfo_t { - pub unsafe fn si_addr(&self) -> *mut ::c_void { - self.si_addr - } - - pub unsafe fn si_value(&self) -> ::sigval { - self.si_value - } -} - -s! { - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_matchc: ::size_t, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - pub gl_pathv: *mut *mut ::c_char, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - __unused6: *mut ::c_void, - __unused7: *mut ::c_void, - __unused8: *mut ::c_void, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: ::socklen_t, - pub ai_canonname: *mut ::c_char, - pub ai_addr: *mut ::sockaddr, - pub ai_next: *mut addrinfo, - } - - pub struct sigset_t { - bits: [u32; 4], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub si_pid: ::pid_t, - pub si_uid: ::uid_t, - pub si_status: ::c_int, - pub si_addr: *mut ::c_void, - pub si_value: ::sigval, - _pad1: ::c_long, - _pad2: [::c_int; 7], - } - - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_flags: ::c_int, - pub sa_mask: sigset_t, - } - - pub struct sched_param { - pub sched_priority: ::c_int, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [::c_char; 8], - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_cc: [::cc_t; ::NCCS], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct flock { - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - pub l_type: ::c_short, - pub l_whence: ::c_short, - #[cfg(not(target_os = "dragonfly"))] - pub l_sysid: ::c_int, - } - - pub struct sf_hdtr { - pub headers: *mut ::iovec, - pub hdr_cnt: ::c_int, - pub trailers: *mut ::iovec, - pub trl_cnt: ::c_int, - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct cmsgcred { - pub cmcred_pid: ::pid_t, - pub cmcred_uid: ::uid_t, - pub cmcred_euid: ::uid_t, - pub cmcred_gid: ::gid_t, - pub cmcred_ngroups: ::c_short, - pub cmcred_groups: [::gid_t; CMGROUP_MAX], - } - - pub struct rtprio { - pub type_: ::c_ushort, - pub prio: ::c_ushort, - } - - pub struct in6_pktinfo { - pub ipi6_addr: ::in6_addr, - pub ipi6_ifindex: ::c_uint, - } - - pub struct arphdr { - pub ar_hrd: u16, - pub ar_pro: u16, - pub ar_hln: u8, - pub ar_pln: u8, - pub ar_op: u16, - } -} - -s_no_extra_traits! { - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_align: i64, - __ss_pad2: [u8; 112], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_len == other.ss_len - && self.ss_family == other.ss_family - && self.__ss_pad1 == other.__ss_pad1 - && self.__ss_align == other.__ss_align - && self - .__ss_pad2 - .iter() - .zip(other.__ss_pad2.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for sockaddr_storage {} - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_len", &self.ss_len) - .field("ss_family", &self.ss_family) - .field("__ss_pad1", &self.__ss_pad1) - .field("__ss_align", &self.__ss_align) - // FIXME: .field("__ss_pad2", &self.__ss_pad2) - .finish() - } - } - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_len.hash(state); - self.ss_family.hash(state); - self.__ss_pad1.hash(state); - self.__ss_align.hash(state); - self.__ss_pad2.hash(state); - } - } - } -} - -#[deprecated( - since = "0.2.64", - note = "Can vary at runtime. Use sysconf(3) instead" -)] -pub const AIO_LISTIO_MAX: ::c_int = 16; -pub const AIO_CANCELED: ::c_int = 1; -pub const AIO_NOTCANCELED: ::c_int = 2; -pub const AIO_ALLDONE: ::c_int = 3; -pub const LIO_NOP: ::c_int = 0; -pub const LIO_WRITE: ::c_int = 1; -pub const LIO_READ: ::c_int = 2; -pub const LIO_WAIT: ::c_int = 1; -pub const LIO_NOWAIT: ::c_int = 0; - -pub const SIGEV_NONE: ::c_int = 0; -pub const SIGEV_SIGNAL: ::c_int = 1; -pub const SIGEV_THREAD: ::c_int = 2; -pub const SIGEV_KEVENT: ::c_int = 3; - -pub const CODESET: ::nl_item = 0; -pub const D_T_FMT: ::nl_item = 1; -pub const D_FMT: ::nl_item = 2; -pub const T_FMT: ::nl_item = 3; -pub const T_FMT_AMPM: ::nl_item = 4; -pub const AM_STR: ::nl_item = 5; -pub const PM_STR: ::nl_item = 6; - -pub const DAY_1: ::nl_item = 7; -pub const DAY_2: ::nl_item = 8; -pub const DAY_3: ::nl_item = 9; -pub const DAY_4: ::nl_item = 10; -pub const DAY_5: ::nl_item = 11; -pub const DAY_6: ::nl_item = 12; -pub const DAY_7: ::nl_item = 13; - -pub const ABDAY_1: ::nl_item = 14; -pub const ABDAY_2: ::nl_item = 15; -pub const ABDAY_3: ::nl_item = 16; -pub const ABDAY_4: ::nl_item = 17; -pub const ABDAY_5: ::nl_item = 18; -pub const ABDAY_6: ::nl_item = 19; -pub const ABDAY_7: ::nl_item = 20; - -pub const MON_1: ::nl_item = 21; -pub const MON_2: ::nl_item = 22; -pub const MON_3: ::nl_item = 23; -pub const MON_4: ::nl_item = 24; -pub const MON_5: ::nl_item = 25; -pub const MON_6: ::nl_item = 26; -pub const MON_7: ::nl_item = 27; -pub const MON_8: ::nl_item = 28; -pub const MON_9: ::nl_item = 29; -pub const MON_10: ::nl_item = 30; -pub const MON_11: ::nl_item = 31; -pub const MON_12: ::nl_item = 32; - -pub const ABMON_1: ::nl_item = 33; -pub const ABMON_2: ::nl_item = 34; -pub const ABMON_3: ::nl_item = 35; -pub const ABMON_4: ::nl_item = 36; -pub const ABMON_5: ::nl_item = 37; -pub const ABMON_6: ::nl_item = 38; -pub const ABMON_7: ::nl_item = 39; -pub const ABMON_8: ::nl_item = 40; -pub const ABMON_9: ::nl_item = 41; -pub const ABMON_10: ::nl_item = 42; -pub const ABMON_11: ::nl_item = 43; -pub const ABMON_12: ::nl_item = 44; - -pub const ERA: ::nl_item = 45; -pub const ERA_D_FMT: ::nl_item = 46; -pub const ERA_D_T_FMT: ::nl_item = 47; -pub const ERA_T_FMT: ::nl_item = 48; -pub const ALT_DIGITS: ::nl_item = 49; - -pub const RADIXCHAR: ::nl_item = 50; -pub const THOUSEP: ::nl_item = 51; - -pub const YESEXPR: ::nl_item = 52; -pub const NOEXPR: ::nl_item = 53; - -pub const YESSTR: ::nl_item = 54; -pub const NOSTR: ::nl_item = 55; - -pub const CRNCYSTR: ::nl_item = 56; - -pub const D_MD_ORDER: ::nl_item = 57; - -pub const ALTMON_1: ::nl_item = 58; -pub const ALTMON_2: ::nl_item = 59; -pub const ALTMON_3: ::nl_item = 60; -pub const ALTMON_4: ::nl_item = 61; -pub const ALTMON_5: ::nl_item = 62; -pub const ALTMON_6: ::nl_item = 63; -pub const ALTMON_7: ::nl_item = 64; -pub const ALTMON_8: ::nl_item = 65; -pub const ALTMON_9: ::nl_item = 66; -pub const ALTMON_10: ::nl_item = 67; -pub const ALTMON_11: ::nl_item = 68; -pub const ALTMON_12: ::nl_item = 69; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const SEEK_DATA: ::c_int = 3; -pub const SEEK_HOLE: ::c_int = 4; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 2; -pub const _IOLBF: ::c_int = 1; -pub const BUFSIZ: ::c_uint = 1024; -pub const FOPEN_MAX: ::c_uint = 20; -pub const FILENAME_MAX: ::c_uint = 1024; -pub const L_tmpnam: ::c_uint = 1024; -pub const TMP_MAX: ::c_uint = 308915776; - -pub const O_NOCTTY: ::c_int = 32768; -pub const O_DIRECT: ::c_int = 0x00010000; - -pub const S_IFIFO: mode_t = 4096; -pub const S_IFCHR: mode_t = 8192; -pub const S_IFBLK: mode_t = 24576; -pub const S_IFDIR: mode_t = 16384; -pub const S_IFREG: mode_t = 32768; -pub const S_IFLNK: mode_t = 40960; -pub const S_IFSOCK: mode_t = 49152; -pub const S_IFMT: mode_t = 61440; -pub const S_IEXEC: mode_t = 64; -pub const S_IWRITE: mode_t = 128; -pub const S_IREAD: mode_t = 256; -pub const S_IRWXU: mode_t = 448; -pub const S_IXUSR: mode_t = 64; -pub const S_IWUSR: mode_t = 128; -pub const S_IRUSR: mode_t = 256; -pub const S_IRWXG: mode_t = 56; -pub const S_IXGRP: mode_t = 8; -pub const S_IWGRP: mode_t = 16; -pub const S_IRGRP: mode_t = 32; -pub const S_IRWXO: mode_t = 7; -pub const S_IXOTH: mode_t = 1; -pub const S_IWOTH: mode_t = 2; -pub const S_IROTH: mode_t = 4; -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; -pub const F_DUPFD_CLOEXEC: ::c_int = 17; -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGABRT: ::c_int = 6; -pub const SIGEMT: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSEGV: ::c_int = 11; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_READ: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_EXEC: ::c_int = 4; - -pub const MAP_FILE: ::c_int = 0x0000; -pub const MAP_SHARED: ::c_int = 0x0001; -pub const MAP_PRIVATE: ::c_int = 0x0002; -pub const MAP_FIXED: ::c_int = 0x0010; -pub const MAP_ANON: ::c_int = 0x1000; -pub const MAP_ANONYMOUS: ::c_int = MAP_ANON; - -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const MS_SYNC: ::c_int = 0x0000; -pub const MS_ASYNC: ::c_int = 0x0001; -pub const MS_INVALIDATE: ::c_int = 0x0002; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EDEADLK: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const ENOTBLK: ::c_int = 15; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const EAGAIN: ::c_int = 35; -pub const EWOULDBLOCK: ::c_int = 35; -pub const EINPROGRESS: ::c_int = 36; -pub const EALREADY: ::c_int = 37; -pub const ENOTSOCK: ::c_int = 38; -pub const EDESTADDRREQ: ::c_int = 39; -pub const EMSGSIZE: ::c_int = 40; -pub const EPROTOTYPE: ::c_int = 41; -pub const ENOPROTOOPT: ::c_int = 42; -pub const EPROTONOSUPPORT: ::c_int = 43; -pub const ESOCKTNOSUPPORT: ::c_int = 44; -pub const EOPNOTSUPP: ::c_int = 45; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 46; -pub const EAFNOSUPPORT: ::c_int = 47; -pub const EADDRINUSE: ::c_int = 48; -pub const EADDRNOTAVAIL: ::c_int = 49; -pub const ENETDOWN: ::c_int = 50; -pub const ENETUNREACH: ::c_int = 51; -pub const ENETRESET: ::c_int = 52; -pub const ECONNABORTED: ::c_int = 53; -pub const ECONNRESET: ::c_int = 54; -pub const ENOBUFS: ::c_int = 55; -pub const EISCONN: ::c_int = 56; -pub const ENOTCONN: ::c_int = 57; -pub const ESHUTDOWN: ::c_int = 58; -pub const ETOOMANYREFS: ::c_int = 59; -pub const ETIMEDOUT: ::c_int = 60; -pub const ECONNREFUSED: ::c_int = 61; -pub const ELOOP: ::c_int = 62; -pub const ENAMETOOLONG: ::c_int = 63; -pub const EHOSTDOWN: ::c_int = 64; -pub const EHOSTUNREACH: ::c_int = 65; -pub const ENOTEMPTY: ::c_int = 66; -pub const EPROCLIM: ::c_int = 67; -pub const EUSERS: ::c_int = 68; -pub const EDQUOT: ::c_int = 69; -pub const ESTALE: ::c_int = 70; -pub const EREMOTE: ::c_int = 71; -pub const EBADRPC: ::c_int = 72; -pub const ERPCMISMATCH: ::c_int = 73; -pub const EPROGUNAVAIL: ::c_int = 74; -pub const EPROGMISMATCH: ::c_int = 75; -pub const EPROCUNAVAIL: ::c_int = 76; -pub const ENOLCK: ::c_int = 77; -pub const ENOSYS: ::c_int = 78; -pub const EFTYPE: ::c_int = 79; -pub const EAUTH: ::c_int = 80; -pub const ENEEDAUTH: ::c_int = 81; -pub const EIDRM: ::c_int = 82; -pub const ENOMSG: ::c_int = 83; -pub const EOVERFLOW: ::c_int = 84; -pub const ECANCELED: ::c_int = 85; -pub const EILSEQ: ::c_int = 86; -pub const ENOATTR: ::c_int = 87; -pub const EDOOFUS: ::c_int = 88; -pub const EBADMSG: ::c_int = 89; -pub const EMULTIHOP: ::c_int = 90; -pub const ENOLINK: ::c_int = 91; -pub const EPROTO: ::c_int = 92; - -pub const POLLSTANDARD: ::c_short = ::POLLIN - | ::POLLPRI - | ::POLLOUT - | ::POLLRDNORM - | ::POLLRDBAND - | ::POLLWRBAND - | ::POLLERR - | ::POLLHUP - | ::POLLNVAL; - -pub const EAI_AGAIN: ::c_int = 2; -pub const EAI_BADFLAGS: ::c_int = 3; -pub const EAI_FAIL: ::c_int = 4; -pub const EAI_FAMILY: ::c_int = 5; -pub const EAI_MEMORY: ::c_int = 6; -pub const EAI_NONAME: ::c_int = 8; -pub const EAI_SERVICE: ::c_int = 9; -pub const EAI_SOCKTYPE: ::c_int = 10; -pub const EAI_SYSTEM: ::c_int = 11; -pub const EAI_OVERFLOW: ::c_int = 14; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; - -pub const SIGTRAP: ::c_int = 5; - -pub const GLOB_APPEND: ::c_int = 0x0001; -pub const GLOB_DOOFFS: ::c_int = 0x0002; -pub const GLOB_ERR: ::c_int = 0x0004; -pub const GLOB_MARK: ::c_int = 0x0008; -pub const GLOB_NOCHECK: ::c_int = 0x0010; -pub const GLOB_NOSORT: ::c_int = 0x0020; -pub const GLOB_NOESCAPE: ::c_int = 0x2000; - -pub const GLOB_NOSPACE: ::c_int = -1; -pub const GLOB_ABORTED: ::c_int = -2; -pub const GLOB_NOMATCH: ::c_int = -3; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; -pub const POSIX_MADV_DONTNEED: ::c_int = 4; - -pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0; -pub const PTHREAD_PROCESS_SHARED: ::c_int = 1; -pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0; -pub const PTHREAD_CREATE_DETACHED: ::c_int = 1; - -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_RSS: ::c_int = 5; -pub const RLIMIT_MEMLOCK: ::c_int = 6; -pub const RLIMIT_NPROC: ::c_int = 7; -pub const RLIMIT_NOFILE: ::c_int = 8; -pub const RLIMIT_SBSIZE: ::c_int = 9; -pub const RLIMIT_VMEM: ::c_int = 10; -pub const RLIMIT_AS: ::c_int = RLIMIT_VMEM; -pub const RLIM_INFINITY: rlim_t = 0x7fff_ffff_ffff_ffff; - -pub const RUSAGE_SELF: ::c_int = 0; -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const MADV_NORMAL: ::c_int = 0; -pub const MADV_RANDOM: ::c_int = 1; -pub const MADV_SEQUENTIAL: ::c_int = 2; -pub const MADV_WILLNEED: ::c_int = 3; -pub const MADV_DONTNEED: ::c_int = 4; -pub const MADV_FREE: ::c_int = 5; -pub const MADV_NOSYNC: ::c_int = 6; -pub const MADV_AUTOSYNC: ::c_int = 7; -pub const MADV_NOCORE: ::c_int = 8; -pub const MADV_CORE: ::c_int = 9; - -pub const MINCORE_INCORE: ::c_int = 0x1; -pub const MINCORE_REFERENCED: ::c_int = 0x2; -pub const MINCORE_MODIFIED: ::c_int = 0x4; -pub const MINCORE_REFERENCED_OTHER: ::c_int = 0x8; -pub const MINCORE_MODIFIED_OTHER: ::c_int = 0x10; -pub const MINCORE_SUPER: ::c_int = 0x20; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_LOCAL: ::c_int = 1; -pub const AF_UNIX: ::c_int = AF_LOCAL; -pub const AF_INET: ::c_int = 2; -pub const AF_IMPLINK: ::c_int = 3; -pub const AF_PUP: ::c_int = 4; -pub const AF_CHAOS: ::c_int = 5; -pub const AF_NETBIOS: ::c_int = 6; -pub const AF_ISO: ::c_int = 7; -pub const AF_OSI: ::c_int = AF_ISO; -pub const AF_ECMA: ::c_int = 8; -pub const AF_DATAKIT: ::c_int = 9; -pub const AF_CCITT: ::c_int = 10; -pub const AF_SNA: ::c_int = 11; -pub const AF_DECnet: ::c_int = 12; -pub const AF_DLI: ::c_int = 13; -pub const AF_LAT: ::c_int = 14; -pub const AF_HYLINK: ::c_int = 15; -pub const AF_APPLETALK: ::c_int = 16; -pub const AF_ROUTE: ::c_int = 17; -pub const AF_LINK: ::c_int = 18; -pub const pseudo_AF_XTP: ::c_int = 19; -pub const AF_COIP: ::c_int = 20; -pub const AF_CNT: ::c_int = 21; -pub const pseudo_AF_RTIP: ::c_int = 22; -pub const AF_IPX: ::c_int = 23; -pub const AF_SIP: ::c_int = 24; -pub const pseudo_AF_PIP: ::c_int = 25; -pub const AF_ISDN: ::c_int = 26; -pub const AF_E164: ::c_int = AF_ISDN; -pub const pseudo_AF_KEY: ::c_int = 27; -pub const AF_INET6: ::c_int = 28; -pub const AF_NATM: ::c_int = 29; -pub const AF_ATM: ::c_int = 30; -pub const pseudo_AF_HDRCMPLT: ::c_int = 31; -pub const AF_NETGRAPH: ::c_int = 32; - -pub const PF_UNSPEC: ::c_int = AF_UNSPEC; -pub const PF_LOCAL: ::c_int = AF_LOCAL; -pub const PF_UNIX: ::c_int = PF_LOCAL; -pub const PF_INET: ::c_int = AF_INET; -pub const PF_IMPLINK: ::c_int = AF_IMPLINK; -pub const PF_PUP: ::c_int = AF_PUP; -pub const PF_CHAOS: ::c_int = AF_CHAOS; -pub const PF_NETBIOS: ::c_int = AF_NETBIOS; -pub const PF_ISO: ::c_int = AF_ISO; -pub const PF_OSI: ::c_int = AF_ISO; -pub const PF_ECMA: ::c_int = AF_ECMA; -pub const PF_DATAKIT: ::c_int = AF_DATAKIT; -pub const PF_CCITT: ::c_int = AF_CCITT; -pub const PF_SNA: ::c_int = AF_SNA; -pub const PF_DECnet: ::c_int = AF_DECnet; -pub const PF_DLI: ::c_int = AF_DLI; -pub const PF_LAT: ::c_int = AF_LAT; -pub const PF_HYLINK: ::c_int = AF_HYLINK; -pub const PF_APPLETALK: ::c_int = AF_APPLETALK; -pub const PF_ROUTE: ::c_int = AF_ROUTE; -pub const PF_LINK: ::c_int = AF_LINK; -pub const PF_XTP: ::c_int = pseudo_AF_XTP; -pub const PF_COIP: ::c_int = AF_COIP; -pub const PF_CNT: ::c_int = AF_CNT; -pub const PF_SIP: ::c_int = AF_SIP; -pub const PF_IPX: ::c_int = AF_IPX; -pub const PF_RTIP: ::c_int = pseudo_AF_RTIP; -pub const PF_PIP: ::c_int = pseudo_AF_PIP; -pub const PF_ISDN: ::c_int = AF_ISDN; -pub const PF_KEY: ::c_int = pseudo_AF_KEY; -pub const PF_INET6: ::c_int = AF_INET6; -pub const PF_NATM: ::c_int = AF_NATM; -pub const PF_ATM: ::c_int = AF_ATM; -pub const PF_NETGRAPH: ::c_int = AF_NETGRAPH; - -pub const PT_TRACE_ME: ::c_int = 0; -pub const PT_READ_I: ::c_int = 1; -pub const PT_READ_D: ::c_int = 2; -pub const PT_WRITE_I: ::c_int = 4; -pub const PT_WRITE_D: ::c_int = 5; -pub const PT_CONTINUE: ::c_int = 7; -pub const PT_KILL: ::c_int = 8; -pub const PT_STEP: ::c_int = 9; -pub const PT_ATTACH: ::c_int = 10; -pub const PT_DETACH: ::c_int = 11; -pub const PT_IO: ::c_int = 12; - -pub const SOMAXCONN: ::c_int = 128; - -pub const MSG_OOB: ::c_int = 0x00000001; -pub const MSG_PEEK: ::c_int = 0x00000002; -pub const MSG_DONTROUTE: ::c_int = 0x00000004; -pub const MSG_EOR: ::c_int = 0x00000008; -pub const MSG_TRUNC: ::c_int = 0x00000010; -pub const MSG_CTRUNC: ::c_int = 0x00000020; -pub const MSG_WAITALL: ::c_int = 0x00000040; -pub const MSG_DONTWAIT: ::c_int = 0x00000080; -pub const MSG_EOF: ::c_int = 0x00000100; - -pub const SCM_TIMESTAMP: ::c_int = 0x02; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_RAW: ::c_int = 3; -pub const SOCK_RDM: ::c_int = 4; -pub const SOCK_SEQPACKET: ::c_int = 5; -pub const SOCK_CLOEXEC: ::c_int = 0x10000000; -pub const SOCK_NONBLOCK: ::c_int = 0x20000000; -pub const SOCK_MAXADDRLEN: ::c_int = 255; -pub const IP_TTL: ::c_int = 4; -pub const IP_HDRINCL: ::c_int = 2; -pub const IP_RECVDSTADDR: ::c_int = 7; -pub const IP_SENDSRCADDR: ::c_int = IP_RECVDSTADDR; -pub const IP_ADD_MEMBERSHIP: ::c_int = 12; -pub const IP_DROP_MEMBERSHIP: ::c_int = 13; -pub const IP_RECVIF: ::c_int = 20; -pub const IPV6_JOIN_GROUP: ::c_int = 12; -pub const IPV6_LEAVE_GROUP: ::c_int = 13; -pub const IPV6_RECVPKTINFO: ::c_int = 36; -pub const IPV6_PKTINFO: ::c_int = 46; -pub const IPV6_RECVTCLASS: ::c_int = 57; -pub const IPV6_TCLASS: ::c_int = 61; - -pub const TCP_NOPUSH: ::c_int = 4; -pub const TCP_NOOPT: ::c_int = 8; -pub const TCP_KEEPIDLE: ::c_int = 256; -pub const TCP_KEEPINTVL: ::c_int = 512; -pub const TCP_KEEPCNT: ::c_int = 1024; - -pub const SOL_SOCKET: ::c_int = 0xffff; -pub const SO_DEBUG: ::c_int = 0x01; -pub const SO_ACCEPTCONN: ::c_int = 0x0002; -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_USELOOPBACK: ::c_int = 0x0040; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_TIMESTAMP: ::c_int = 0x0400; -pub const SO_NOSIGPIPE: ::c_int = 0x0800; -pub const SO_ACCEPTFILTER: ::c_int = 0x1000; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_TYPE: ::c_int = 0x1008; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const LOCK_SH: ::c_int = 1; -pub const LOCK_EX: ::c_int = 2; -pub const LOCK_NB: ::c_int = 4; -pub const LOCK_UN: ::c_int = 8; - -pub const MAP_COPY: ::c_int = 0x0002; -#[doc(hidden)] -#[deprecated(since = "0.2.54", note = "Removed in FreeBSD 11")] -pub const MAP_RENAME: ::c_int = 0x0020; -#[doc(hidden)] -#[deprecated(since = "0.2.54", note = "Removed in FreeBSD 11")] -pub const MAP_NORESERVE: ::c_int = 0x0040; -pub const MAP_HASSEMAPHORE: ::c_int = 0x0200; -pub const MAP_STACK: ::c_int = 0x0400; -pub const MAP_NOSYNC: ::c_int = 0x0800; -pub const MAP_NOCORE: ::c_int = 0x020000; - -pub const IPPROTO_RAW: ::c_int = 255; - -pub const _PC_LINK_MAX: ::c_int = 1; -pub const _PC_MAX_CANON: ::c_int = 2; -pub const _PC_MAX_INPUT: ::c_int = 3; -pub const _PC_NAME_MAX: ::c_int = 4; -pub const _PC_PATH_MAX: ::c_int = 5; -pub const _PC_PIPE_BUF: ::c_int = 6; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 7; -pub const _PC_NO_TRUNC: ::c_int = 8; -pub const _PC_VDISABLE: ::c_int = 9; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 10; -pub const _PC_FILESIZEBITS: ::c_int = 12; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 14; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 15; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 16; -pub const _PC_REC_XFER_ALIGN: ::c_int = 17; -pub const _PC_SYMLINK_MAX: ::c_int = 18; -pub const _PC_MIN_HOLE_SIZE: ::c_int = 21; -pub const _PC_ASYNC_IO: ::c_int = 53; -pub const _PC_PRIO_IO: ::c_int = 54; -pub const _PC_SYNC_IO: ::c_int = 55; -pub const _PC_ACL_EXTENDED: ::c_int = 59; -pub const _PC_ACL_PATH_MAX: ::c_int = 60; -pub const _PC_CAP_PRESENT: ::c_int = 61; -pub const _PC_INF_PRESENT: ::c_int = 62; -pub const _PC_MAC_PRESENT: ::c_int = 63; - -pub const _SC_ARG_MAX: ::c_int = 1; -pub const _SC_CHILD_MAX: ::c_int = 2; -pub const _SC_CLK_TCK: ::c_int = 3; -pub const _SC_NGROUPS_MAX: ::c_int = 4; -pub const _SC_OPEN_MAX: ::c_int = 5; -pub const _SC_JOB_CONTROL: ::c_int = 6; -pub const _SC_SAVED_IDS: ::c_int = 7; -pub const _SC_VERSION: ::c_int = 8; -pub const _SC_BC_BASE_MAX: ::c_int = 9; -pub const _SC_BC_DIM_MAX: ::c_int = 10; -pub const _SC_BC_SCALE_MAX: ::c_int = 11; -pub const _SC_BC_STRING_MAX: ::c_int = 12; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 13; -pub const _SC_EXPR_NEST_MAX: ::c_int = 14; -pub const _SC_LINE_MAX: ::c_int = 15; -pub const _SC_RE_DUP_MAX: ::c_int = 16; -pub const _SC_2_VERSION: ::c_int = 17; -pub const _SC_2_C_BIND: ::c_int = 18; -pub const _SC_2_C_DEV: ::c_int = 19; -pub const _SC_2_CHAR_TERM: ::c_int = 20; -pub const _SC_2_FORT_DEV: ::c_int = 21; -pub const _SC_2_FORT_RUN: ::c_int = 22; -pub const _SC_2_LOCALEDEF: ::c_int = 23; -pub const _SC_2_SW_DEV: ::c_int = 24; -pub const _SC_2_UPE: ::c_int = 25; -pub const _SC_STREAM_MAX: ::c_int = 26; -pub const _SC_TZNAME_MAX: ::c_int = 27; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 28; -pub const _SC_MAPPED_FILES: ::c_int = 29; -pub const _SC_MEMLOCK: ::c_int = 30; -pub const _SC_MEMLOCK_RANGE: ::c_int = 31; -pub const _SC_MEMORY_PROTECTION: ::c_int = 32; -pub const _SC_MESSAGE_PASSING: ::c_int = 33; -pub const _SC_PRIORITIZED_IO: ::c_int = 34; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 35; -pub const _SC_REALTIME_SIGNALS: ::c_int = 36; -pub const _SC_SEMAPHORES: ::c_int = 37; -pub const _SC_FSYNC: ::c_int = 38; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 39; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 40; -pub const _SC_TIMERS: ::c_int = 41; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 42; -pub const _SC_AIO_MAX: ::c_int = 43; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 44; -pub const _SC_DELAYTIMER_MAX: ::c_int = 45; -pub const _SC_MQ_OPEN_MAX: ::c_int = 46; -pub const _SC_PAGESIZE: ::c_int = 47; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_RTSIG_MAX: ::c_int = 48; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 49; -pub const _SC_SEM_VALUE_MAX: ::c_int = 50; -pub const _SC_SIGQUEUE_MAX: ::c_int = 51; -pub const _SC_TIMER_MAX: ::c_int = 52; -pub const _SC_IOV_MAX: ::c_int = 56; -pub const _SC_NPROCESSORS_CONF: ::c_int = 57; -pub const _SC_2_PBS: ::c_int = 59; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 60; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 61; -pub const _SC_2_PBS_LOCATE: ::c_int = 62; -pub const _SC_2_PBS_MESSAGE: ::c_int = 63; -pub const _SC_2_PBS_TRACK: ::c_int = 64; -pub const _SC_ADVISORY_INFO: ::c_int = 65; -pub const _SC_BARRIERS: ::c_int = 66; -pub const _SC_CLOCK_SELECTION: ::c_int = 67; -pub const _SC_CPUTIME: ::c_int = 68; -pub const _SC_FILE_LOCKING: ::c_int = 69; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 58; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 70; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 71; -pub const _SC_HOST_NAME_MAX: ::c_int = 72; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 73; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 74; -pub const _SC_MQ_PRIO_MAX: ::c_int = 75; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 76; -pub const _SC_REGEXP: ::c_int = 77; -pub const _SC_SHELL: ::c_int = 78; -pub const _SC_SPAWN: ::c_int = 79; -pub const _SC_SPIN_LOCKS: ::c_int = 80; -pub const _SC_SPORADIC_SERVER: ::c_int = 81; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 82; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 83; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 85; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 86; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 87; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 88; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 89; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 90; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 91; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 92; -pub const _SC_THREAD_STACK_MIN: ::c_int = 93; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 94; -pub const _SC_TIMEOUTS: ::c_int = 95; -pub const _SC_THREADS: ::c_int = 96; -pub const _SC_TRACE: ::c_int = 97; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 98; -pub const _SC_TRACE_INHERIT: ::c_int = 99; -pub const _SC_TRACE_LOG: ::c_int = 100; -pub const _SC_TTY_NAME_MAX: ::c_int = 101; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 102; -pub const _SC_V6_ILP32_OFF32: ::c_int = 103; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 104; -pub const _SC_V6_LP64_OFF64: ::c_int = 105; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 106; -pub const _SC_ATEXIT_MAX: ::c_int = 107; -pub const _SC_XOPEN_CRYPT: ::c_int = 108; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 109; -pub const _SC_XOPEN_LEGACY: ::c_int = 110; -pub const _SC_XOPEN_REALTIME: ::c_int = 111; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 112; -pub const _SC_XOPEN_SHM: ::c_int = 113; -pub const _SC_XOPEN_STREAMS: ::c_int = 114; -pub const _SC_XOPEN_UNIX: ::c_int = 115; -pub const _SC_XOPEN_VERSION: ::c_int = 116; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 117; -pub const _SC_IPV6: ::c_int = 118; -pub const _SC_RAW_SOCKETS: ::c_int = 119; -pub const _SC_SYMLOOP_MAX: ::c_int = 120; -pub const _SC_PHYS_PAGES: ::c_int = 121; - -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0 as *mut _; -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 1; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2; -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 3; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_ERRORCHECK; - -pub const SCHED_FIFO: ::c_int = 1; -pub const SCHED_OTHER: ::c_int = 2; -pub const SCHED_RR: ::c_int = 3; - -pub const FD_SETSIZE: usize = 1024; - -pub const ST_NOSUID: ::c_ulong = 2; - -pub const NI_MAXHOST: ::size_t = 1025; - -pub const RTLD_LOCAL: ::c_int = 0; -pub const RTLD_NODELETE: ::c_int = 0x1000; -pub const RTLD_NOLOAD: ::c_int = 0x2000; -pub const RTLD_GLOBAL: ::c_int = 0x100; - -pub const LOG_NTP: ::c_int = 12 << 3; -pub const LOG_SECURITY: ::c_int = 13 << 3; -pub const LOG_CONSOLE: ::c_int = 14 << 3; -pub const LOG_NFACILITIES: ::c_int = 24; - -pub const TIOCEXCL: ::c_uint = 0x2000740d; -pub const TIOCNXCL: ::c_uint = 0x2000740e; -pub const TIOCFLUSH: ::c_ulong = 0x80047410; -pub const TIOCGETA: ::c_uint = 0x402c7413; -pub const TIOCSETA: ::c_ulong = 0x802c7414; -pub const TIOCSETAW: ::c_ulong = 0x802c7415; -pub const TIOCSETAF: ::c_ulong = 0x802c7416; -pub const TIOCGETD: ::c_uint = 0x4004741a; -pub const TIOCSETD: ::c_ulong = 0x8004741b; -pub const TIOCGDRAINWAIT: ::c_uint = 0x40047456; -pub const TIOCSDRAINWAIT: ::c_ulong = 0x80047457; -pub const TIOCTIMESTAMP: ::c_uint = 0x40107459; -pub const TIOCMGDTRWAIT: ::c_uint = 0x4004745a; -pub const TIOCMSDTRWAIT: ::c_ulong = 0x8004745b; -pub const TIOCDRAIN: ::c_uint = 0x2000745e; -pub const TIOCEXT: ::c_ulong = 0x80047460; -pub const TIOCSCTTY: ::c_uint = 0x20007461; -pub const TIOCCONS: ::c_ulong = 0x80047462; -pub const TIOCGSID: ::c_uint = 0x40047463; -pub const TIOCSTAT: ::c_uint = 0x20007465; -pub const TIOCUCNTL: ::c_ulong = 0x80047466; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const TIOCGWINSZ: ::c_uint = 0x40087468; -pub const TIOCMGET: ::c_uint = 0x4004746a; -pub const TIOCM_LE: ::c_int = 0x1; -pub const TIOCM_DTR: ::c_int = 0x2; -pub const TIOCM_RTS: ::c_int = 0x4; -pub const TIOCM_ST: ::c_int = 0x8; -pub const TIOCM_SR: ::c_int = 0x10; -pub const TIOCM_CTS: ::c_int = 0x20; -pub const TIOCM_RI: ::c_int = 0x80; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = 0x40; -pub const TIOCM_CAR: ::c_int = 0x40; -pub const TIOCM_RNG: ::c_int = 0x80; -pub const TIOCMBIC: ::c_ulong = 0x8004746b; -pub const TIOCMBIS: ::c_ulong = 0x8004746c; -pub const TIOCMSET: ::c_ulong = 0x8004746d; -pub const TIOCSTART: ::c_uint = 0x2000746e; -pub const TIOCSTOP: ::c_uint = 0x2000746f; -pub const TIOCPKT: ::c_ulong = 0x80047470; -pub const TIOCPKT_DATA: ::c_int = 0x0; -pub const TIOCPKT_FLUSHREAD: ::c_int = 0x1; -pub const TIOCPKT_FLUSHWRITE: ::c_int = 0x2; -pub const TIOCPKT_STOP: ::c_int = 0x4; -pub const TIOCPKT_START: ::c_int = 0x8; -pub const TIOCPKT_NOSTOP: ::c_int = 0x10; -pub const TIOCPKT_DOSTOP: ::c_int = 0x20; -pub const TIOCPKT_IOCTL: ::c_int = 0x40; -pub const TIOCNOTTY: ::c_uint = 0x20007471; -pub const TIOCSTI: ::c_ulong = 0x80017472; -pub const TIOCOUTQ: ::c_uint = 0x40047473; -pub const TIOCSPGRP: ::c_ulong = 0x80047476; -pub const TIOCGPGRP: ::c_uint = 0x40047477; -pub const TIOCCDTR: ::c_uint = 0x20007478; -pub const TIOCSDTR: ::c_uint = 0x20007479; -pub const TIOCCBRK: ::c_uint = 0x2000747a; -pub const TIOCSBRK: ::c_uint = 0x2000747b; -pub const TTYDISC: ::c_int = 0x0; -pub const SLIPDISC: ::c_int = 0x4; -pub const PPPDISC: ::c_int = 0x5; -pub const NETGRAPHDISC: ::c_int = 0x6; - -pub const BIOCGRSIG: ::c_ulong = 0x40044272; -pub const BIOCSRSIG: ::c_ulong = 0x80044273; -pub const BIOCSDLT: ::c_ulong = 0x80044278; -pub const BIOCGSEESENT: ::c_ulong = 0x40044276; -pub const BIOCSSEESENT: ::c_ulong = 0x80044277; -pub const BIOCSETF: ::c_ulong = 0x80104267; -pub const BIOCGDLTLIST: ::c_ulong = 0xc0104279; -pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d; -pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e; - -pub const FIODTYPE: ::c_ulong = 0x4004667a; -pub const FIOGETLBA: ::c_ulong = 0x40046679; -pub const FIODGNAME: ::c_ulong = 0x80106678; - -pub const B0: speed_t = 0; -pub const B50: speed_t = 50; -pub const B75: speed_t = 75; -pub const B110: speed_t = 110; -pub const B134: speed_t = 134; -pub const B150: speed_t = 150; -pub const B200: speed_t = 200; -pub const B300: speed_t = 300; -pub const B600: speed_t = 600; -pub const B1200: speed_t = 1200; -pub const B1800: speed_t = 1800; -pub const B2400: speed_t = 2400; -pub const B4800: speed_t = 4800; -pub const B9600: speed_t = 9600; -pub const B19200: speed_t = 19200; -pub const B38400: speed_t = 38400; -pub const B7200: speed_t = 7200; -pub const B14400: speed_t = 14400; -pub const B28800: speed_t = 28800; -pub const B57600: speed_t = 57600; -pub const B76800: speed_t = 76800; -pub const B115200: speed_t = 115200; -pub const B230400: speed_t = 230400; -pub const EXTA: speed_t = 19200; -pub const EXTB: speed_t = 38400; - -pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t; - -pub const CRTSCTS: ::tcflag_t = 0x00030000; -pub const CCTS_OFLOW: ::tcflag_t = 0x00010000; -pub const CRTS_IFLOW: ::tcflag_t = 0x00020000; -pub const CDTR_IFLOW: ::tcflag_t = 0x00040000; -pub const CDSR_OFLOW: ::tcflag_t = 0x00080000; -pub const CCAR_OFLOW: ::tcflag_t = 0x00100000; -pub const VERASE2: usize = 7; -pub const OCRNL: ::tcflag_t = 0x10; -pub const ONOCR: ::tcflag_t = 0x20; -pub const ONLRET: ::tcflag_t = 0x40; - -pub const CMGROUP_MAX: usize = 16; - -// https://github.com/freebsd/freebsd/blob/master/sys/net/bpf.h -// sizeof(long) -pub const BPF_ALIGNMENT: ::c_int = 8; - -// Values for rtprio struct (prio field) and syscall (function argument) -pub const RTP_PRIO_MIN: ::c_ushort = 0; -pub const RTP_PRIO_MAX: ::c_ushort = 31; -pub const RTP_LOOKUP: ::c_int = 0; -pub const RTP_SET: ::c_int = 1; - -// Flags for chflags(2) -pub const UF_SETTABLE: ::c_ulong = 0x0000ffff; -pub const UF_NODUMP: ::c_ulong = 0x00000001; -pub const UF_IMMUTABLE: ::c_ulong = 0x00000002; -pub const UF_APPEND: ::c_ulong = 0x00000004; -pub const UF_OPAQUE: ::c_ulong = 0x00000008; -pub const UF_NOUNLINK: ::c_ulong = 0x00000010; -pub const SF_SETTABLE: ::c_ulong = 0xffff0000; -pub const SF_ARCHIVED: ::c_ulong = 0x00010000; -pub const SF_IMMUTABLE: ::c_ulong = 0x00020000; -pub const SF_APPEND: ::c_ulong = 0x00040000; -pub const SF_NOUNLINK: ::c_ulong = 0x00100000; - -pub const TIMER_ABSTIME: ::c_int = 1; - -f! { - pub fn WIFCONTINUED(status: ::c_int) -> bool { - status == 0x13 - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - status >> 8 - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - (status & 0o177) != 0o177 && (status & 0o177) != 0 - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0o177) == 0o177 - } -} - -extern "C" { - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; - pub fn accept4( - s: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_error(aiocbp: *const aiocb) -> ::c_int; - pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t; - pub fn aio_suspend( - aiocb_list: *const *const aiocb, - nitems: ::c_int, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn aio_cancel(fd: ::c_int, aiocbp: *mut aiocb) -> ::c_int; - pub fn chflags(path: *const ::c_char, flags: ::c_ulong) -> ::c_int; - pub fn chflagsat( - fd: ::c_int, - path: *const ::c_char, - flags: ::c_ulong, - atflag: ::c_int, - ) -> ::c_int; - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn endutxent(); - pub fn fchflags(fd: ::c_int, flags: ::c_ulong) -> ::c_int; - pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; - pub fn getdomainname(name: *mut ::c_char, len: ::c_int) -> ::c_int; - pub fn getgrent_r( - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwent_r50")] - pub fn getpwent_r( - pwd: *mut ::passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::passwd, - ) -> ::c_int; - pub fn getgrouplist( - name: *const ::c_char, - basegid: ::gid_t, - groups: *mut ::gid_t, - ngroups: *mut ::c_int, - ) -> ::c_int; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::size_t, - serv: *mut ::c_char, - servlen: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn getpriority(which: ::c_int, who: ::c_int) -> ::c_int; - pub fn getutxent() -> *mut utmpx; - pub fn getutxid(ut: *const utmpx) -> *mut utmpx; - pub fn getutxline(ut: *const utmpx) -> *mut utmpx; - pub fn initgroups(name: *const ::c_char, basegid: ::gid_t) -> ::c_int; - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "kevent@FBSD_1.0" - )] - pub fn kevent( - kq: ::c_int, - changelist: *const ::kevent, - nchanges: ::c_int, - eventlist: *mut ::kevent, - nevents: ::c_int, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn lchflags(path: *const ::c_char, flags: ::c_ulong) -> ::c_int; - pub fn lio_listio( - mode: ::c_int, - aiocb_list: *const *mut aiocb, - nitems: ::c_int, - sevp: *mut sigevent, - ) -> ::c_int; - pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; - pub fn memrchr( - cx: *const ::c_void, - c: ::c_int, - n: ::size_t, - ) -> *mut ::c_void; - pub fn mkfifoat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "mknodat@FBSD_1.1" - )] - pub fn mknodat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - dev: dev_t, - ) -> ::c_int; - pub fn mq_close(mqd: ::mqd_t) -> ::c_int; - pub fn mq_getattr(mqd: ::mqd_t, attr: *mut ::mq_attr) -> ::c_int; - pub fn mq_notify(mqd: ::mqd_t, notification: *const ::sigevent) - -> ::c_int; - pub fn mq_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::mqd_t; - pub fn mq_receive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - ) -> ::ssize_t; - pub fn mq_send( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - ) -> ::c_int; - pub fn mq_setattr( - mqd: ::mqd_t, - newattr: *const ::mq_attr, - oldattr: *mut ::mq_attr, - ) -> ::c_int; - pub fn mq_timedreceive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - abs_timeout: *const ::timespec, - ) -> ::ssize_t; - pub fn mq_timedsend( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - abs_timeout: *const ::timespec, - ) -> ::c_int; - pub fn mq_unlink(name: *const ::c_char) -> ::c_int; - pub fn mincore( - addr: *const ::c_void, - len: ::size_t, - vec: *mut ::c_char, - ) -> ::c_int; - pub fn newlocale( - mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t, - ) -> ::locale_t; - pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) - -> *mut ::c_char; - pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int; - pub fn ppoll( - fds: *mut ::pollfd, - nfds: ::nfds_t, - timeout: *const ::timespec, - sigmask: *const sigset_t, - ) -> ::c_int; - pub fn preadv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn pthread_attr_get_np( - tid: ::pthread_t, - attr: *mut ::pthread_attr_t, - ) -> ::c_int; - pub fn pthread_attr_getguardsize( - attr: *const ::pthread_attr_t, - guardsize: *mut ::size_t, - ) -> ::c_int; - pub fn pthread_attr_getstack( - attr: *const ::pthread_attr_t, - stackaddr: *mut *mut ::c_void, - stacksize: *mut ::size_t, - ) -> ::c_int; - pub fn pthread_condattr_getclock( - attr: *const pthread_condattr_t, - clock_id: *mut clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_getpshared( - attr: *const pthread_condattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_condattr_setclock( - attr: *mut pthread_condattr_t, - clock_id: ::clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_setpshared( - attr: *mut pthread_condattr_t, - pshared: ::c_int, - ) -> ::c_int; - pub fn pthread_main_np() -> ::c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn pthread_mutexattr_getpshared( - attr: *const pthread_mutexattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_mutexattr_setpshared( - attr: *mut pthread_mutexattr_t, - pshared: ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_getpshared( - attr: *const pthread_rwlockattr_t, - val: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_setpshared( - attr: *mut pthread_rwlockattr_t, - val: ::c_int, - ) -> ::c_int; - pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char); - pub fn ptrace( - request: ::c_int, - pid: ::pid_t, - addr: *mut ::c_char, - data: ::c_int, - ) -> ::c_int; - pub fn pututxline(ut: *const utmpx) -> *mut utmpx; - pub fn pwritev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn querylocale(mask: ::c_int, loc: ::locale_t) -> *const ::c_char; - pub fn rtprio( - function: ::c_int, - pid: ::pid_t, - rtp: *mut rtprio, - ) -> ::c_int; - pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int; - pub fn sched_setscheduler( - pid: ::pid_t, - policy: ::c_int, - param: *const ::sched_param, - ) -> ::c_int; - pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; - pub fn sem_timedwait( - sem: *mut sem_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn sendfile( - fd: ::c_int, - s: ::c_int, - offset: ::off_t, - nbytes: ::size_t, - hdtr: *mut ::sf_hdtr, - sbytes: *mut ::off_t, - flags: ::c_int, - ) -> ::c_int; - pub fn setdomainname(name: *const ::c_char, len: ::c_int) -> ::c_int; - pub fn sethostname(name: *const ::c_char, len: ::c_int) -> ::c_int; - pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) - -> ::c_int; - pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int; - pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int; - pub fn settimeofday( - tv: *const ::timeval, - tz: *const ::timezone, - ) -> ::c_int; - pub fn setutxent(); - pub fn shm_open( - name: *const ::c_char, - oflag: ::c_int, - mode: ::mode_t, - ) -> ::c_int; - pub fn sigtimedwait( - set: *const sigset_t, - info: *mut siginfo_t, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> ::c_int; - pub fn sysctl( - name: *const ::c_int, - namelen: ::c_uint, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *const ::c_void, - newlen: ::size_t, - ) -> ::c_int; - pub fn sysctlbyname( - name: *const ::c_char, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *const ::c_void, - newlen: ::size_t, - ) -> ::c_int; - pub fn sysctlnametomib( - name: *const ::c_char, - mibp: *mut ::c_int, - sizep: *mut ::size_t, - ) -> ::c_int; - pub fn uselocale(loc: ::locale_t) -> ::locale_t; - pub fn utimensat( - dirfd: ::c_int, - path: *const ::c_char, - times: *const ::timespec, - flag: ::c_int, - ) -> ::c_int; -} - -#[link(name = "util")] -extern "C" { - pub fn openpty( - amaster: *mut ::c_int, - aslave: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::c_int; - pub fn forkpty( - amaster: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::pid_t; - pub fn login_tty(fd: ::c_int) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_os = "freebsd")] { - mod freebsd; - pub use self::freebsd::*; - } else if #[cfg(target_os = "dragonfly")] { - mod dragonfly; - pub use self::dragonfly::*; - } else { - // ... - } -} diff --git a/libc/src/unix/bsd/mod.rs b/libc/src/unix/bsd/mod.rs deleted file mode 100644 index cf9f59e..0000000 --- a/libc/src/unix/bsd/mod.rs +++ /dev/null @@ -1,794 +0,0 @@ -pub type wchar_t = i32; -pub type off_t = i64; -pub type useconds_t = u32; -pub type blkcnt_t = i64; -pub type socklen_t = u32; -pub type sa_family_t = u8; -pub type pthread_t = ::uintptr_t; -pub type nfds_t = ::c_uint; - -s! { - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_change: ::time_t, - pub pw_class: *mut ::c_char, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - pub pw_expire: ::time_t, - - #[cfg(not(any(target_os = "macos", - target_os = "ios", - target_os = "netbsd", - target_os = "openbsd")))] - pub pw_fields: ::c_int, - } - - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut ::c_char, - pub ifa_flags: ::c_uint, - pub ifa_addr: *mut ::sockaddr, - pub ifa_netmask: *mut ::sockaddr, - pub ifa_dstaddr: *mut ::sockaddr, - pub ifa_data: *mut ::c_void, - #[cfg(target_os = "netbsd")] - pub ifa_addrflags: ::c_uint - } - - pub struct fd_set { - #[cfg(all(target_pointer_width = "64", - any(target_os = "freebsd", target_os = "dragonfly")))] - fds_bits: [i64; FD_SETSIZE / 64], - #[cfg(not(all(target_pointer_width = "64", - any(target_os = "freebsd", target_os = "dragonfly"))))] - fds_bits: [i32; FD_SETSIZE / 32], - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - pub tm_gmtoff: ::c_long, - pub tm_zone: *mut ::c_char, - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::socklen_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct fsid_t { - __fsid_val: [i32; 2], - } - - pub struct if_nameindex { - pub if_index: ::c_uint, - pub if_name: *mut ::c_char, - } -} - -s_no_extra_traits! { - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [c_char; 104] - } - - pub struct utsname { - #[cfg(not(target_os = "dragonfly"))] - pub sysname: [::c_char; 256], - #[cfg(target_os = "dragonfly")] - pub sysname: [::c_char; 32], - #[cfg(not(target_os = "dragonfly"))] - pub nodename: [::c_char; 256], - #[cfg(target_os = "dragonfly")] - pub nodename: [::c_char; 32], - #[cfg(not(target_os = "dragonfly"))] - pub release: [::c_char; 256], - #[cfg(target_os = "dragonfly")] - pub release: [::c_char; 32], - #[cfg(not(target_os = "dragonfly"))] - pub version: [::c_char; 256], - #[cfg(target_os = "dragonfly")] - pub version: [::c_char; 32], - #[cfg(not(target_os = "dragonfly"))] - pub machine: [::c_char; 256], - #[cfg(target_os = "dragonfly")] - pub machine: [::c_char; 32], - } - -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for sockaddr_un { - fn eq(&self, other: &sockaddr_un) -> bool { - self.sun_len == other.sun_len - && self.sun_family == other.sun_family - && self - .sun_path - .iter() - .zip(other.sun_path.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for sockaddr_un {} - - impl ::fmt::Debug for sockaddr_un { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_un") - .field("sun_len", &self.sun_len) - .field("sun_family", &self.sun_family) - // FIXME: .field("sun_path", &self.sun_path) - .finish() - } - } - - impl ::hash::Hash for sockaddr_un { - fn hash(&self, state: &mut H) { - self.sun_len.hash(state); - self.sun_family.hash(state); - self.sun_path.hash(state); - } - } - - impl PartialEq for utsname { - fn eq(&self, other: &utsname) -> bool { - self.sysname - .iter() - .zip(other.sysname.iter()) - .all(|(a,b)| a == b) - && self - .nodename - .iter() - .zip(other.nodename.iter()) - .all(|(a,b)| a == b) - && self - .release - .iter() - .zip(other.release.iter()) - .all(|(a,b)| a == b) - && self - .version - .iter() - .zip(other.version.iter()) - .all(|(a,b)| a == b) - && self - .machine - .iter() - .zip(other.machine.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for utsname {} - - impl ::fmt::Debug for utsname { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utsname") - // FIXME: .field("sysname", &self.sysname) - // FIXME: .field("nodename", &self.nodename) - // FIXME: .field("release", &self.release) - // FIXME: .field("version", &self.version) - // FIXME: .field("machine", &self.machine) - .finish() - } - } - - impl ::hash::Hash for utsname { - fn hash(&self, state: &mut H) { - self.sysname.hash(state); - self.nodename.hash(state); - self.release.hash(state); - self.version.hash(state); - self.machine.hash(state); - } - } - } -} - -pub const LC_ALL: ::c_int = 0; -pub const LC_COLLATE: ::c_int = 1; -pub const LC_CTYPE: ::c_int = 2; -pub const LC_MONETARY: ::c_int = 3; -pub const LC_NUMERIC: ::c_int = 4; -pub const LC_TIME: ::c_int = 5; -pub const LC_MESSAGES: ::c_int = 6; - -pub const FIOCLEX: ::c_ulong = 0x20006601; -pub const FIONCLEX: ::c_ulong = 0x20006602; -pub const FIONREAD: ::c_ulong = 0x4004667f; -pub const FIONBIO: ::c_ulong = 0x8004667e; -pub const FIOASYNC: ::c_ulong = 0x8004667d; -pub const FIOSETOWN: ::c_ulong = 0x8004667c; -pub const FIOGETOWN: ::c_ulong = 0x4004667b; - -pub const PATH_MAX: ::c_int = 1024; - -pub const SA_ONSTACK: ::c_int = 0x0001; -pub const SA_SIGINFO: ::c_int = 0x0040; -pub const SA_RESTART: ::c_int = 0x0002; -pub const SA_RESETHAND: ::c_int = 0x0004; -pub const SA_NOCLDSTOP: ::c_int = 0x0008; -pub const SA_NODEFER: ::c_int = 0x0010; -pub const SA_NOCLDWAIT: ::c_int = 0x0020; - -pub const SS_ONSTACK: ::c_int = 1; -pub const SS_DISABLE: ::c_int = 4; - -pub const SIGCHLD: ::c_int = 20; -pub const SIGBUS: ::c_int = 10; -pub const SIGUSR1: ::c_int = 30; -pub const SIGUSR2: ::c_int = 31; -pub const SIGCONT: ::c_int = 19; -pub const SIGSTOP: ::c_int = 17; -pub const SIGTSTP: ::c_int = 18; -pub const SIGURG: ::c_int = 16; -pub const SIGIO: ::c_int = 23; -pub const SIGSYS: ::c_int = 12; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGINFO: ::c_int = 29; - -pub const SIG_SETMASK: ::c_int = 3; -pub const SIG_BLOCK: ::c_int = 0x1; -pub const SIG_UNBLOCK: ::c_int = 0x2; - -pub const IP_TOS: ::c_int = 3; -pub const IP_MULTICAST_IF: ::c_int = 9; -pub const IP_MULTICAST_TTL: ::c_int = 10; -pub const IP_MULTICAST_LOOP: ::c_int = 11; - -pub const IPV6_UNICAST_HOPS: ::c_int = 4; -pub const IPV6_MULTICAST_IF: ::c_int = 9; -pub const IPV6_MULTICAST_HOPS: ::c_int = 10; -pub const IPV6_MULTICAST_LOOP: ::c_int = 11; -pub const IPV6_V6ONLY: ::c_int = 27; - -pub const IPTOS_ECN_NOTECT: u8 = 0x00; -pub const IPTOS_ECN_MASK: u8 = 0x03; -pub const IPTOS_ECN_ECT1: u8 = 0x01; -pub const IPTOS_ECN_ECT0: u8 = 0x02; -pub const IPTOS_ECN_CE: u8 = 0x03; - -pub const ST_RDONLY: ::c_ulong = 1; - -pub const SCM_RIGHTS: ::c_int = 0x01; - -pub const NCCS: usize = 20; - -pub const O_ACCMODE: ::c_int = 0x3; -pub const O_RDONLY: ::c_int = 0; -pub const O_WRONLY: ::c_int = 1; -pub const O_RDWR: ::c_int = 2; -pub const O_APPEND: ::c_int = 8; -pub const O_CREAT: ::c_int = 512; -pub const O_TRUNC: ::c_int = 1024; -pub const O_EXCL: ::c_int = 2048; -pub const O_ASYNC: ::c_int = 0x40; -pub const O_SYNC: ::c_int = 0x80; -pub const O_NONBLOCK: ::c_int = 0x4; -pub const O_NOFOLLOW: ::c_int = 0x100; -pub const O_SHLOCK: ::c_int = 0x10; -pub const O_EXLOCK: ::c_int = 0x20; -pub const O_FSYNC: ::c_int = O_SYNC; -pub const O_NDELAY: ::c_int = O_NONBLOCK; - -pub const F_GETOWN: ::c_int = 5; -pub const F_SETOWN: ::c_int = 6; - -pub const F_RDLCK: ::c_short = 1; -pub const F_UNLCK: ::c_short = 2; -pub const F_WRLCK: ::c_short = 3; - -pub const MNT_FORCE: ::c_int = 0x80000; - -pub const Q_SYNC: ::c_int = 0x600; -pub const Q_QUOTAON: ::c_int = 0x100; -pub const Q_QUOTAOFF: ::c_int = 0x200; - -pub const TCIOFF: ::c_int = 3; -pub const TCION: ::c_int = 4; -pub const TCOOFF: ::c_int = 1; -pub const TCOON: ::c_int = 2; -pub const TCIFLUSH: ::c_int = 1; -pub const TCOFLUSH: ::c_int = 2; -pub const TCIOFLUSH: ::c_int = 3; -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; -pub const VEOF: usize = 0; -pub const VEOL: usize = 1; -pub const VEOL2: usize = 2; -pub const VERASE: usize = 3; -pub const VWERASE: usize = 4; -pub const VKILL: usize = 5; -pub const VREPRINT: usize = 6; -pub const VINTR: usize = 8; -pub const VQUIT: usize = 9; -pub const VSUSP: usize = 10; -pub const VDSUSP: usize = 11; -pub const VSTART: usize = 12; -pub const VSTOP: usize = 13; -pub const VLNEXT: usize = 14; -pub const VDISCARD: usize = 15; -pub const VMIN: usize = 16; -pub const VTIME: usize = 17; -pub const VSTATUS: usize = 18; -pub const _POSIX_VDISABLE: ::cc_t = 0xff; -pub const IGNBRK: ::tcflag_t = 0x00000001; -pub const BRKINT: ::tcflag_t = 0x00000002; -pub const IGNPAR: ::tcflag_t = 0x00000004; -pub const PARMRK: ::tcflag_t = 0x00000008; -pub const INPCK: ::tcflag_t = 0x00000010; -pub const ISTRIP: ::tcflag_t = 0x00000020; -pub const INLCR: ::tcflag_t = 0x00000040; -pub const IGNCR: ::tcflag_t = 0x00000080; -pub const ICRNL: ::tcflag_t = 0x00000100; -pub const IXON: ::tcflag_t = 0x00000200; -pub const IXOFF: ::tcflag_t = 0x00000400; -pub const IXANY: ::tcflag_t = 0x00000800; -pub const IMAXBEL: ::tcflag_t = 0x00002000; -pub const OPOST: ::tcflag_t = 0x1; -pub const ONLCR: ::tcflag_t = 0x2; -pub const OXTABS: ::tcflag_t = 0x4; -pub const ONOEOT: ::tcflag_t = 0x8; -pub const CIGNORE: ::tcflag_t = 0x00000001; -pub const CSIZE: ::tcflag_t = 0x00000300; -pub const CS5: ::tcflag_t = 0x00000000; -pub const CS6: ::tcflag_t = 0x00000100; -pub const CS7: ::tcflag_t = 0x00000200; -pub const CS8: ::tcflag_t = 0x00000300; -pub const CSTOPB: ::tcflag_t = 0x00000400; -pub const CREAD: ::tcflag_t = 0x00000800; -pub const PARENB: ::tcflag_t = 0x00001000; -pub const PARODD: ::tcflag_t = 0x00002000; -pub const HUPCL: ::tcflag_t = 0x00004000; -pub const CLOCAL: ::tcflag_t = 0x00008000; -pub const ECHOKE: ::tcflag_t = 0x00000001; -pub const ECHOE: ::tcflag_t = 0x00000002; -pub const ECHOK: ::tcflag_t = 0x00000004; -pub const ECHO: ::tcflag_t = 0x00000008; -pub const ECHONL: ::tcflag_t = 0x00000010; -pub const ECHOPRT: ::tcflag_t = 0x00000020; -pub const ECHOCTL: ::tcflag_t = 0x00000040; -pub const ISIG: ::tcflag_t = 0x00000080; -pub const ICANON: ::tcflag_t = 0x00000100; -pub const ALTWERASE: ::tcflag_t = 0x00000200; -pub const IEXTEN: ::tcflag_t = 0x00000400; -pub const EXTPROC: ::tcflag_t = 0x00000800; -pub const TOSTOP: ::tcflag_t = 0x00400000; -pub const FLUSHO: ::tcflag_t = 0x00800000; -pub const NOKERNINFO: ::tcflag_t = 0x02000000; -pub const PENDIN: ::tcflag_t = 0x20000000; -pub const NOFLSH: ::tcflag_t = 0x80000000; -pub const MDMBUF: ::tcflag_t = 0x00100000; - -pub const WNOHANG: ::c_int = 0x00000001; -pub const WUNTRACED: ::c_int = 0x00000002; - -pub const RTLD_LAZY: ::c_int = 0x1; -pub const RTLD_NOW: ::c_int = 0x2; -pub const RTLD_NEXT: *mut ::c_void = -1isize as *mut ::c_void; -pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void; -pub const RTLD_SELF: *mut ::c_void = -3isize as *mut ::c_void; - -pub const LOG_CRON: ::c_int = 9 << 3; -pub const LOG_AUTHPRIV: ::c_int = 10 << 3; -pub const LOG_FTP: ::c_int = 11 << 3; -pub const LOG_PERROR: ::c_int = 0x20; - -pub const TCP_NODELAY: ::c_int = 1; -pub const TCP_MAXSEG: ::c_int = 2; - -pub const PIPE_BUF: usize = 512; - -pub const POLLIN: ::c_short = 0x1; -pub const POLLPRI: ::c_short = 0x2; -pub const POLLOUT: ::c_short = 0x4; -pub const POLLERR: ::c_short = 0x8; -pub const POLLHUP: ::c_short = 0x10; -pub const POLLNVAL: ::c_short = 0x20; -pub const POLLRDNORM: ::c_short = 0x040; -pub const POLLWRNORM: ::c_short = 0x004; -pub const POLLRDBAND: ::c_short = 0x080; -pub const POLLWRBAND: ::c_short = 0x100; - -pub const BIOCGBLEN: ::c_ulong = 0x40044266; -pub const BIOCSBLEN: ::c_ulong = 0xc0044266; -pub const BIOCFLUSH: ::c_uint = 0x20004268; -pub const BIOCPROMISC: ::c_uint = 0x20004269; -pub const BIOCGDLT: ::c_ulong = 0x4004426a; -pub const BIOCGETIF: ::c_ulong = 0x4020426b; -pub const BIOCSETIF: ::c_ulong = 0x8020426c; -pub const BIOCGSTATS: ::c_ulong = 0x4008426f; -pub const BIOCIMMEDIATE: ::c_ulong = 0x80044270; -pub const BIOCVERSION: ::c_ulong = 0x40044271; -pub const BIOCGHDRCMPLT: ::c_ulong = 0x40044274; -pub const BIOCSHDRCMPLT: ::c_ulong = 0x80044275; -pub const SIOCGIFADDR: ::c_ulong = 0xc0206921; - -f! { - pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr { - if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() { - (*mhdr).msg_control as *mut ::cmsghdr - } else { - 0 as *mut ::cmsghdr - } - } - - pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); - return - } - - pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 - } - - pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - (*set).fds_bits[fd / bits] |= 1 << (fd % bits); - return - } - - pub fn FD_ZERO(set: *mut fd_set) -> () { - for slot in (*set).fds_bits.iter_mut() { - *slot = 0; - } - } - - pub fn WTERMSIG(status: ::c_int) -> ::c_int { - status & 0o177 - } - - pub fn WIFEXITED(status: ::c_int) -> bool { - (status & 0o177) == 0 - } - - pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - status >> 8 - } - - pub fn WCOREDUMP(status: ::c_int) -> bool { - (status & 0o200) != 0 - } - - pub fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { - (cmd << 8) | (type_ & 0x00ff) - } -} - -extern "C" { - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "getrlimit$UNIX2003" - )] - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "setrlimit$UNIX2003" - )] - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; - pub fn rand() -> ::c_int; - pub fn srand(seed: ::c_uint); - - pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; - pub fn freeifaddrs(ifa: *mut ::ifaddrs); - pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int; - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; - pub fn kqueue() -> ::c_int; - pub fn unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int; - pub fn syscall(num: ::c_int, ...) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")] - pub fn getpwent() -> *mut passwd; - pub fn setpwent(); - pub fn endpwent(); - pub fn endgrent(); - pub fn getgrent() -> *mut ::group; - - pub fn getprogname() -> *const ::c_char; - pub fn setprogname(name: *const ::c_char); - pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int; - pub fn if_nameindex() -> *mut if_nameindex; - pub fn if_freenameindex(ptr: *mut if_nameindex); - - pub fn getpeereid( - socket: ::c_int, - euid: *mut ::uid_t, - egid: *mut ::gid_t, - ) -> ::c_int; - - #[cfg_attr(target_os = "macos", link_name = "glob$INODE64")] - #[cfg_attr(target_os = "netbsd", link_name = "__glob30")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "glob@FBSD_1.0" - )] - pub fn glob( - pattern: *const ::c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut ::glob_t, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "globfree@FBSD_1.0" - )] - pub fn globfree(pglob: *mut ::glob_t); - - pub fn posix_madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn shm_unlink(name: *const ::c_char) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86_64"), - link_name = "seekdir$INODE64" - )] - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "seekdir$INODE64$UNIX2003" - )] - pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86_64"), - link_name = "telldir$INODE64" - )] - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "telldir$INODE64$UNIX2003" - )] - pub fn telldir(dirp: *mut ::DIR) -> ::c_long; - pub fn madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "msync$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__msync13")] - pub fn msync( - addr: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "recvfrom$UNIX2003" - )] - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__futimes50")] - pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; - pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "bind$UNIX2003" - )] - pub fn bind( - socket: ::c_int, - address: *const ::sockaddr, - address_len: ::socklen_t, - ) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "writev$UNIX2003" - )] - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "readv$UNIX2003" - )] - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sendmsg$UNIX2003" - )] - pub fn sendmsg( - fd: ::c_int, - msg: *const ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "recvmsg$UNIX2003" - )] - pub fn recvmsg( - fd: ::c_int, - msg: *mut ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - - pub fn sync(); - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r( - gid: ::gid_t, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigaltstack$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] - pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; - pub fn sem_close(sem: *mut sem_t) -> ::c_int; - pub fn getdtablesize() -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")] - pub fn getgrnam_r( - name: *const ::c_char, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_sigmask$UNIX2003" - )] - pub fn pthread_sigmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; - pub fn getgrnam(name: *const ::c_char) -> *mut ::group; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_cancel$UNIX2003" - )] - pub fn pthread_cancel(thread: ::pthread_t) -> ::c_int; - pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; - pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")] - pub fn getpwnam_r( - name: *const ::c_char, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")] - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigwait$UNIX2003" - )] - #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] - pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn getgrgid(gid: ::gid_t) -> *mut ::group; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "popen$UNIX2003" - )] - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - pub fn faccessat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn pthread_create( - native: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - pub fn acct(filename: *const ::c_char) -> ::c_int; -} - -cfg_if! { - if #[cfg(any(target_os = "macos", target_os = "ios"))] { - mod apple; - pub use self::apple::*; - } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] { - mod netbsdlike; - pub use self::netbsdlike::*; - } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { - mod freebsdlike; - pub use self::freebsdlike::*; - } else { - // Unknown target_os - } -} diff --git a/libc/src/unix/bsd/netbsdlike/mod.rs b/libc/src/unix/bsd/netbsdlike/mod.rs deleted file mode 100644 index 970cb23..0000000 --- a/libc/src/unix/bsd/netbsdlike/mod.rs +++ /dev/null @@ -1,765 +0,0 @@ -pub type time_t = i64; -pub type mode_t = u32; -pub type nlink_t = u32; -pub type ino_t = u64; -pub type pthread_key_t = ::c_int; -pub type rlim_t = u64; -pub type speed_t = ::c_uint; -pub type tcflag_t = ::c_uint; -pub type nl_item = c_long; -pub type clockid_t = ::c_int; -pub type id_t = u32; -pub type sem_t = *mut sem; -pub type key_t = c_long; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum sem {} -impl ::Copy for sem {} -impl ::Clone for sem { - fn clone(&self) -> sem { - *self - } -} - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct in6_pktinfo { - pub ipi6_addr: ::in6_addr, - pub ipi6_ifindex: ::c_uint, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_cc: [::cc_t; ::NCCS], - pub c_ispeed: ::c_int, - pub c_ospeed: ::c_int, - } - - pub struct flock { - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - pub l_type: ::c_short, - pub l_whence: ::c_short, - } - - pub struct ipc_perm { - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub mode: ::mode_t, - pub seq: ::c_ushort, - pub key: ::key_t, - } -} - -pub const D_T_FMT: ::nl_item = 0; -pub const D_FMT: ::nl_item = 1; -pub const T_FMT: ::nl_item = 2; -pub const T_FMT_AMPM: ::nl_item = 3; -pub const AM_STR: ::nl_item = 4; -pub const PM_STR: ::nl_item = 5; - -pub const DAY_1: ::nl_item = 6; -pub const DAY_2: ::nl_item = 7; -pub const DAY_3: ::nl_item = 8; -pub const DAY_4: ::nl_item = 9; -pub const DAY_5: ::nl_item = 10; -pub const DAY_6: ::nl_item = 11; -pub const DAY_7: ::nl_item = 12; - -pub const ABDAY_1: ::nl_item = 13; -pub const ABDAY_2: ::nl_item = 14; -pub const ABDAY_3: ::nl_item = 15; -pub const ABDAY_4: ::nl_item = 16; -pub const ABDAY_5: ::nl_item = 17; -pub const ABDAY_6: ::nl_item = 18; -pub const ABDAY_7: ::nl_item = 19; - -pub const MON_1: ::nl_item = 20; -pub const MON_2: ::nl_item = 21; -pub const MON_3: ::nl_item = 22; -pub const MON_4: ::nl_item = 23; -pub const MON_5: ::nl_item = 24; -pub const MON_6: ::nl_item = 25; -pub const MON_7: ::nl_item = 26; -pub const MON_8: ::nl_item = 27; -pub const MON_9: ::nl_item = 28; -pub const MON_10: ::nl_item = 29; -pub const MON_11: ::nl_item = 30; -pub const MON_12: ::nl_item = 31; - -pub const ABMON_1: ::nl_item = 32; -pub const ABMON_2: ::nl_item = 33; -pub const ABMON_3: ::nl_item = 34; -pub const ABMON_4: ::nl_item = 35; -pub const ABMON_5: ::nl_item = 36; -pub const ABMON_6: ::nl_item = 37; -pub const ABMON_7: ::nl_item = 38; -pub const ABMON_8: ::nl_item = 39; -pub const ABMON_9: ::nl_item = 40; -pub const ABMON_10: ::nl_item = 41; -pub const ABMON_11: ::nl_item = 42; -pub const ABMON_12: ::nl_item = 43; - -pub const RADIXCHAR: ::nl_item = 44; -pub const THOUSEP: ::nl_item = 45; -pub const YESSTR: ::nl_item = 46; -pub const YESEXPR: ::nl_item = 47; -pub const NOSTR: ::nl_item = 48; -pub const NOEXPR: ::nl_item = 49; -pub const CRNCYSTR: ::nl_item = 50; - -pub const CODESET: ::nl_item = 51; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const RAND_MAX: ::c_int = 2147483647; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 2; -pub const _IOLBF: ::c_int = 1; -pub const BUFSIZ: ::c_uint = 1024; -pub const FOPEN_MAX: ::c_uint = 20; -pub const FILENAME_MAX: ::c_uint = 1024; -pub const L_tmpnam: ::c_uint = 1024; -pub const O_NOCTTY: ::c_int = 32768; -pub const S_IFIFO: mode_t = 4096; -pub const S_IFCHR: mode_t = 8192; -pub const S_IFBLK: mode_t = 24576; -pub const S_IFDIR: mode_t = 16384; -pub const S_IFREG: mode_t = 32768; -pub const S_IFLNK: mode_t = 40960; -pub const S_IFSOCK: mode_t = 49152; -pub const S_IFMT: mode_t = 61440; -pub const S_IEXEC: mode_t = 64; -pub const S_IWRITE: mode_t = 128; -pub const S_IREAD: mode_t = 256; -pub const S_IRWXU: mode_t = 448; -pub const S_IXUSR: mode_t = 64; -pub const S_IWUSR: mode_t = 128; -pub const S_IRUSR: mode_t = 256; -pub const S_IRWXG: mode_t = 56; -pub const S_IXGRP: mode_t = 8; -pub const S_IWGRP: mode_t = 16; -pub const S_IRGRP: mode_t = 32; -pub const S_IRWXO: mode_t = 7; -pub const S_IXOTH: mode_t = 1; -pub const S_IWOTH: mode_t = 2; -pub const S_IROTH: mode_t = 4; -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; -pub const F_GETLK: ::c_int = 7; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGABRT: ::c_int = 6; -pub const SIGEMT: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSEGV: ::c_int = 11; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_READ: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_EXEC: ::c_int = 4; - -pub const MAP_FILE: ::c_int = 0x0000; -pub const MAP_SHARED: ::c_int = 0x0001; -pub const MAP_PRIVATE: ::c_int = 0x0002; -pub const MAP_FIXED: ::c_int = 0x0010; -pub const MAP_ANON: ::c_int = 0x1000; -pub const MAP_ANONYMOUS: ::c_int = MAP_ANON; - -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -pub const IPC_CREAT: ::c_int = 0o001000; -pub const IPC_EXCL: ::c_int = 0o002000; -pub const IPC_NOWAIT: ::c_int = 0o004000; - -pub const IPC_PRIVATE: ::key_t = 0; - -pub const IPC_RMID: ::c_int = 0; -pub const IPC_SET: ::c_int = 1; -pub const IPC_STAT: ::c_int = 2; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const MS_ASYNC: ::c_int = 0x0001; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EDEADLK: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const ENOTBLK: ::c_int = 15; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const EAGAIN: ::c_int = 35; -pub const EWOULDBLOCK: ::c_int = 35; -pub const EINPROGRESS: ::c_int = 36; -pub const EALREADY: ::c_int = 37; -pub const ENOTSOCK: ::c_int = 38; -pub const EDESTADDRREQ: ::c_int = 39; -pub const EMSGSIZE: ::c_int = 40; -pub const EPROTOTYPE: ::c_int = 41; -pub const ENOPROTOOPT: ::c_int = 42; -pub const EPROTONOSUPPORT: ::c_int = 43; -pub const ESOCKTNOSUPPORT: ::c_int = 44; -pub const EOPNOTSUPP: ::c_int = 45; -pub const EPFNOSUPPORT: ::c_int = 46; -pub const EAFNOSUPPORT: ::c_int = 47; -pub const EADDRINUSE: ::c_int = 48; -pub const EADDRNOTAVAIL: ::c_int = 49; -pub const ENETDOWN: ::c_int = 50; -pub const ENETUNREACH: ::c_int = 51; -pub const ENETRESET: ::c_int = 52; -pub const ECONNABORTED: ::c_int = 53; -pub const ECONNRESET: ::c_int = 54; -pub const ENOBUFS: ::c_int = 55; -pub const EISCONN: ::c_int = 56; -pub const ENOTCONN: ::c_int = 57; -pub const ESHUTDOWN: ::c_int = 58; -pub const ETOOMANYREFS: ::c_int = 59; -pub const ETIMEDOUT: ::c_int = 60; -pub const ECONNREFUSED: ::c_int = 61; -pub const ELOOP: ::c_int = 62; -pub const ENAMETOOLONG: ::c_int = 63; -pub const EHOSTDOWN: ::c_int = 64; -pub const EHOSTUNREACH: ::c_int = 65; -pub const ENOTEMPTY: ::c_int = 66; -pub const EPROCLIM: ::c_int = 67; -pub const EUSERS: ::c_int = 68; -pub const EDQUOT: ::c_int = 69; -pub const ESTALE: ::c_int = 70; -pub const EREMOTE: ::c_int = 71; -pub const EBADRPC: ::c_int = 72; -pub const ERPCMISMATCH: ::c_int = 73; -pub const EPROGUNAVAIL: ::c_int = 74; -pub const EPROGMISMATCH: ::c_int = 75; -pub const EPROCUNAVAIL: ::c_int = 76; -pub const ENOLCK: ::c_int = 77; -pub const ENOSYS: ::c_int = 78; -pub const EFTYPE: ::c_int = 79; -pub const EAUTH: ::c_int = 80; -pub const ENEEDAUTH: ::c_int = 81; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; - -pub const SIGTRAP: ::c_int = 5; - -pub const GLOB_APPEND: ::c_int = 0x0001; -pub const GLOB_DOOFFS: ::c_int = 0x0002; -pub const GLOB_ERR: ::c_int = 0x0004; -pub const GLOB_MARK: ::c_int = 0x0008; -pub const GLOB_NOCHECK: ::c_int = 0x0010; -pub const GLOB_NOSORT: ::c_int = 0x0020; -pub const GLOB_NOESCAPE: ::c_int = 0x1000; - -pub const GLOB_NOSPACE: ::c_int = -1; -pub const GLOB_ABORTED: ::c_int = -2; -pub const GLOB_NOMATCH: ::c_int = -3; -pub const GLOB_NOSYS: ::c_int = -4; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; -pub const POSIX_MADV_DONTNEED: ::c_int = 4; - -pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0; -pub const PTHREAD_CREATE_DETACHED: ::c_int = 1; - -pub const PT_TRACE_ME: ::c_int = 0; -pub const PT_READ_I: ::c_int = 1; -pub const PT_READ_D: ::c_int = 2; -pub const PT_WRITE_I: ::c_int = 4; -pub const PT_WRITE_D: ::c_int = 5; -pub const PT_CONTINUE: ::c_int = 7; -pub const PT_KILL: ::c_int = 8; -pub const PT_ATTACH: ::c_int = 9; -pub const PT_DETACH: ::c_int = 10; -pub const PT_IO: ::c_int = 11; - -// http://man.openbsd.org/OpenBSD-current/man2/clock_getres.2 -// The man page says clock_gettime(3) can accept various values as clockid_t but -// http://fxr.watson.org/fxr/source/kern/kern_time.c?v=OPENBSD;im=excerpts#L161 -// the implementation rejects anything other than the below two -// -// http://netbsd.gw.com/cgi-bin/man-cgi?clock_gettime -// https://github.com/jsonn/src/blob/HEAD/sys/kern/subr_time.c#L222 -// Basically the same goes for NetBSD -pub const CLOCK_REALTIME: ::clockid_t = 0; -pub const CLOCK_MONOTONIC: ::clockid_t = 3; - -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_RSS: ::c_int = 5; -pub const RLIMIT_MEMLOCK: ::c_int = 6; -pub const RLIMIT_NPROC: ::c_int = 7; -pub const RLIMIT_NOFILE: ::c_int = 8; - -pub const RLIM_INFINITY: rlim_t = 0x7fff_ffff_ffff_ffff; -pub const RLIM_SAVED_MAX: rlim_t = RLIM_INFINITY; -pub const RLIM_SAVED_CUR: rlim_t = RLIM_INFINITY; - -pub const RUSAGE_SELF: ::c_int = 0; -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const MADV_NORMAL: ::c_int = 0; -pub const MADV_RANDOM: ::c_int = 1; -pub const MADV_SEQUENTIAL: ::c_int = 2; -pub const MADV_WILLNEED: ::c_int = 3; -pub const MADV_DONTNEED: ::c_int = 4; -pub const MADV_FREE: ::c_int = 6; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_LOCAL: ::c_int = 1; -pub const AF_UNIX: ::c_int = AF_LOCAL; -pub const AF_INET: ::c_int = 2; -pub const AF_IMPLINK: ::c_int = 3; -pub const AF_PUP: ::c_int = 4; -pub const AF_CHAOS: ::c_int = 5; -pub const AF_NS: ::c_int = 6; -pub const AF_ISO: ::c_int = 7; -pub const AF_OSI: ::c_int = AF_ISO; -pub const AF_DATAKIT: ::c_int = 9; -pub const AF_CCITT: ::c_int = 10; -pub const AF_SNA: ::c_int = 11; -pub const AF_DECnet: ::c_int = 12; -pub const AF_DLI: ::c_int = 13; -pub const AF_LAT: ::c_int = 14; -pub const AF_HYLINK: ::c_int = 15; -pub const AF_APPLETALK: ::c_int = 16; -pub const AF_LINK: ::c_int = 18; -pub const pseudo_AF_XTP: ::c_int = 19; -pub const AF_COIP: ::c_int = 20; -pub const AF_CNT: ::c_int = 21; -pub const pseudo_AF_RTIP: ::c_int = 22; -pub const AF_IPX: ::c_int = 23; -pub const AF_INET6: ::c_int = 24; -pub const pseudo_AF_PIP: ::c_int = 25; -pub const AF_ISDN: ::c_int = 26; -pub const AF_E164: ::c_int = AF_ISDN; -pub const AF_NATM: ::c_int = 27; - -pub const PF_UNSPEC: ::c_int = AF_UNSPEC; -pub const PF_LOCAL: ::c_int = AF_LOCAL; -pub const PF_UNIX: ::c_int = PF_LOCAL; -pub const PF_INET: ::c_int = AF_INET; -pub const PF_IMPLINK: ::c_int = AF_IMPLINK; -pub const PF_PUP: ::c_int = AF_PUP; -pub const PF_CHAOS: ::c_int = AF_CHAOS; -pub const PF_NS: ::c_int = AF_NS; -pub const PF_ISO: ::c_int = AF_ISO; -pub const PF_OSI: ::c_int = AF_ISO; -pub const PF_DATAKIT: ::c_int = AF_DATAKIT; -pub const PF_CCITT: ::c_int = AF_CCITT; -pub const PF_SNA: ::c_int = AF_SNA; -pub const PF_DECnet: ::c_int = AF_DECnet; -pub const PF_DLI: ::c_int = AF_DLI; -pub const PF_LAT: ::c_int = AF_LAT; -pub const PF_HYLINK: ::c_int = AF_HYLINK; -pub const PF_APPLETALK: ::c_int = AF_APPLETALK; -pub const PF_LINK: ::c_int = AF_LINK; -pub const PF_XTP: ::c_int = pseudo_AF_XTP; -pub const PF_COIP: ::c_int = AF_COIP; -pub const PF_CNT: ::c_int = AF_CNT; -pub const PF_IPX: ::c_int = AF_IPX; -pub const PF_INET6: ::c_int = AF_INET6; -pub const PF_RTIP: ::c_int = pseudo_AF_RTIP; -pub const PF_PIP: ::c_int = pseudo_AF_PIP; -pub const PF_ISDN: ::c_int = AF_ISDN; -pub const PF_NATM: ::c_int = AF_NATM; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_RAW: ::c_int = 3; -pub const SOCK_RDM: ::c_int = 4; -pub const SOCK_SEQPACKET: ::c_int = 5; -pub const IP_TTL: ::c_int = 4; -pub const IP_HDRINCL: ::c_int = 2; -pub const IP_ADD_MEMBERSHIP: ::c_int = 12; -pub const IP_DROP_MEMBERSHIP: ::c_int = 13; -pub const IPV6_RECVPKTINFO: ::c_int = 36; -pub const IPV6_PKTINFO: ::c_int = 46; -pub const IPV6_RECVTCLASS: ::c_int = 57; -pub const IPV6_TCLASS: ::c_int = 61; - -pub const SOL_SOCKET: ::c_int = 0xffff; -pub const SO_DEBUG: ::c_int = 0x01; -pub const SO_ACCEPTCONN: ::c_int = 0x0002; -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_USELOOPBACK: ::c_int = 0x0040; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_TYPE: ::c_int = 0x1008; - -pub const SOMAXCONN: ::c_int = 128; - -pub const MSG_OOB: ::c_int = 0x1; -pub const MSG_PEEK: ::c_int = 0x2; -pub const MSG_DONTROUTE: ::c_int = 0x4; -pub const MSG_EOR: ::c_int = 0x8; -pub const MSG_TRUNC: ::c_int = 0x10; -pub const MSG_CTRUNC: ::c_int = 0x20; -pub const MSG_WAITALL: ::c_int = 0x40; -pub const MSG_DONTWAIT: ::c_int = 0x80; -pub const MSG_BCAST: ::c_int = 0x100; -pub const MSG_MCAST: ::c_int = 0x200; -pub const MSG_NOSIGNAL: ::c_int = 0x400; -pub const MSG_CMSG_CLOEXEC: ::c_int = 0x800; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const LOCK_SH: ::c_int = 1; -pub const LOCK_EX: ::c_int = 2; -pub const LOCK_NB: ::c_int = 4; -pub const LOCK_UN: ::c_int = 8; - -pub const IPPROTO_RAW: ::c_int = 255; - -pub const _SC_ARG_MAX: ::c_int = 1; -pub const _SC_CHILD_MAX: ::c_int = 2; -pub const _SC_NGROUPS_MAX: ::c_int = 4; -pub const _SC_OPEN_MAX: ::c_int = 5; -pub const _SC_JOB_CONTROL: ::c_int = 6; -pub const _SC_SAVED_IDS: ::c_int = 7; -pub const _SC_VERSION: ::c_int = 8; -pub const _SC_BC_BASE_MAX: ::c_int = 9; -pub const _SC_BC_DIM_MAX: ::c_int = 10; -pub const _SC_BC_SCALE_MAX: ::c_int = 11; -pub const _SC_BC_STRING_MAX: ::c_int = 12; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 13; -pub const _SC_EXPR_NEST_MAX: ::c_int = 14; -pub const _SC_LINE_MAX: ::c_int = 15; -pub const _SC_RE_DUP_MAX: ::c_int = 16; -pub const _SC_2_VERSION: ::c_int = 17; -pub const _SC_2_C_BIND: ::c_int = 18; -pub const _SC_2_C_DEV: ::c_int = 19; -pub const _SC_2_CHAR_TERM: ::c_int = 20; -pub const _SC_2_FORT_DEV: ::c_int = 21; -pub const _SC_2_FORT_RUN: ::c_int = 22; -pub const _SC_2_LOCALEDEF: ::c_int = 23; -pub const _SC_2_SW_DEV: ::c_int = 24; -pub const _SC_2_UPE: ::c_int = 25; -pub const _SC_STREAM_MAX: ::c_int = 26; -pub const _SC_TZNAME_MAX: ::c_int = 27; -pub const _SC_PAGESIZE: ::c_int = 28; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_FSYNC: ::c_int = 29; -pub const _SC_XOPEN_SHM: ::c_int = 30; - -pub const Q_GETQUOTA: ::c_int = 0x300; -pub const Q_SETQUOTA: ::c_int = 0x400; - -pub const RTLD_GLOBAL: ::c_int = 0x100; - -pub const LOG_NFACILITIES: ::c_int = 24; - -pub const HW_NCPU: ::c_int = 3; - -pub const B0: speed_t = 0; -pub const B50: speed_t = 50; -pub const B75: speed_t = 75; -pub const B110: speed_t = 110; -pub const B134: speed_t = 134; -pub const B150: speed_t = 150; -pub const B200: speed_t = 200; -pub const B300: speed_t = 300; -pub const B600: speed_t = 600; -pub const B1200: speed_t = 1200; -pub const B1800: speed_t = 1800; -pub const B2400: speed_t = 2400; -pub const B4800: speed_t = 4800; -pub const B9600: speed_t = 9600; -pub const B19200: speed_t = 19200; -pub const B38400: speed_t = 38400; -pub const B7200: speed_t = 7200; -pub const B14400: speed_t = 14400; -pub const B28800: speed_t = 28800; -pub const B57600: speed_t = 57600; -pub const B76800: speed_t = 76800; -pub const B115200: speed_t = 115200; -pub const B230400: speed_t = 230400; -pub const EXTA: speed_t = 19200; -pub const EXTB: speed_t = 38400; - -pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t; - -pub const CRTSCTS: ::tcflag_t = 0x00010000; -pub const CRTS_IFLOW: ::tcflag_t = CRTSCTS; -pub const CCTS_OFLOW: ::tcflag_t = CRTSCTS; -pub const OCRNL: ::tcflag_t = 0x10; - -pub const TIOCEXCL: ::c_ulong = 0x2000740d; -pub const TIOCNXCL: ::c_ulong = 0x2000740e; -pub const TIOCFLUSH: ::c_ulong = 0x80047410; -pub const TIOCGETA: ::c_ulong = 0x402c7413; -pub const TIOCSETA: ::c_ulong = 0x802c7414; -pub const TIOCSETAW: ::c_ulong = 0x802c7415; -pub const TIOCSETAF: ::c_ulong = 0x802c7416; -pub const TIOCGETD: ::c_ulong = 0x4004741a; -pub const TIOCSETD: ::c_ulong = 0x8004741b; -pub const TIOCMGET: ::c_ulong = 0x4004746a; -pub const TIOCMBIC: ::c_ulong = 0x8004746b; -pub const TIOCMBIS: ::c_ulong = 0x8004746c; -pub const TIOCMSET: ::c_ulong = 0x8004746d; -pub const TIOCSTART: ::c_ulong = 0x2000746e; -pub const TIOCSTOP: ::c_ulong = 0x2000746f; -pub const TIOCSCTTY: ::c_ulong = 0x20007461; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const TIOCM_LE: ::c_int = 0o0001; -pub const TIOCM_DTR: ::c_int = 0o0002; -pub const TIOCM_RTS: ::c_int = 0o0004; -pub const TIOCM_ST: ::c_int = 0o0010; -pub const TIOCM_SR: ::c_int = 0o0020; -pub const TIOCM_CTS: ::c_int = 0o0040; -pub const TIOCM_CAR: ::c_int = 0o0100; -pub const TIOCM_RNG: ::c_int = 0o0200; -pub const TIOCM_DSR: ::c_int = 0o0400; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -// Flags for chflags(2) -pub const UF_SETTABLE: ::c_ulong = 0x0000ffff; -pub const UF_NODUMP: ::c_ulong = 0x00000001; -pub const UF_IMMUTABLE: ::c_ulong = 0x00000002; -pub const UF_APPEND: ::c_ulong = 0x00000004; -pub const UF_OPAQUE: ::c_ulong = 0x00000008; -pub const SF_SETTABLE: ::c_ulong = 0xffff0000; -pub const SF_ARCHIVED: ::c_ulong = 0x00010000; -pub const SF_IMMUTABLE: ::c_ulong = 0x00020000; -pub const SF_APPEND: ::c_ulong = 0x00040000; - -pub const TIMER_ABSTIME: ::c_int = 1; - -#[link(name = "util")] -extern "C" { - pub fn setgrent(); - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - pub fn mincore( - addr: *mut ::c_void, - len: ::size_t, - vec: *mut ::c_char, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__clock_getres50")] - pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__clock_gettime50")] - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__clock_settime50")] - pub fn clock_settime( - clk_id: ::clockid_t, - tp: *const ::timespec, - ) -> ::c_int; - pub fn __errno() -> *mut ::c_int; - pub fn shm_open( - name: *const ::c_char, - oflag: ::c_int, - mode: ::mode_t, - ) -> ::c_int; - pub fn memrchr( - cx: *const ::c_void, - c: ::c_int, - n: ::size_t, - ) -> *mut ::c_void; - pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int; - pub fn mkostemps( - template: *mut ::c_char, - suffixlen: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn pwritev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn preadv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; - pub fn utimensat( - dirfd: ::c_int, - path: *const ::c_char, - times: *const ::timespec, - flag: ::c_int, - ) -> ::c_int; - pub fn fdatasync(fd: ::c_int) -> ::c_int; - pub fn openpty( - amaster: *mut ::c_int, - aslave: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::c_int; - pub fn forkpty( - amaster: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::pid_t; - pub fn login_tty(fd: ::c_int) -> ::c_int; - pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int; - pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int; - - pub fn mknodat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - dev: dev_t, - ) -> ::c_int; - pub fn mkfifoat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - pub fn sem_timedwait( - sem: *mut sem_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; - pub fn pthread_condattr_setclock( - attr: *mut pthread_condattr_t, - clock_id: ::clockid_t, - ) -> ::c_int; - pub fn sethostname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int; - - pub fn getgrouplist( - name: *const ::c_char, - basegid: ::gid_t, - groups: *mut ::gid_t, - ngroups: *mut ::c_int, - ) -> ::c_int; - pub fn initgroups(name: *const ::c_char, basegid: ::gid_t) -> ::c_int; - pub fn getdomainname(name: *mut ::c_char, len: ::size_t) -> ::c_int; - pub fn setdomainname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn uname(buf: *mut ::utsname) -> ::c_int; - - pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int; - pub fn shmat( - shmid: ::c_int, - shmaddr: *const ::c_void, - shmflg: ::c_int, - ) -> *mut ::c_void; - pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int; - pub fn shmctl( - shmid: ::c_int, - cmd: ::c_int, - buf: *mut ::shmid_ds, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_os = "netbsd")] { - mod netbsd; - pub use self::netbsd::*; - } else if #[cfg(target_os = "openbsd")] { - mod openbsd; - pub use self::openbsd::*; - } else { - // Unknown target_os - } -} diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs b/libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs deleted file mode 100644 index 58c4cf7..0000000 --- a/libc/src/unix/bsd/netbsdlike/netbsd/aarch64.rs +++ /dev/null @@ -1,22 +0,0 @@ -use PT_FIRSTMACH; - -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = u8; -pub type __cpu_simple_lock_nv_t = ::c_uchar; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 4 - 1; - } -} - -pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 0; -pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 1; -pub const PT_GETFPREGS: ::c_int = PT_FIRSTMACH + 2; -pub const PT_SETFPREGS: ::c_int = PT_FIRSTMACH + 3; diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/arm.rs b/libc/src/unix/bsd/netbsdlike/netbsd/arm.rs deleted file mode 100644 index 4bf3ccd..0000000 --- a/libc/src/unix/bsd/netbsdlike/netbsd/arm.rs +++ /dev/null @@ -1,22 +0,0 @@ -use PT_FIRSTMACH; - -pub type c_long = i32; -pub type c_ulong = u32; -pub type c_char = u8; -pub type __cpu_simple_lock_nv_t = ::c_int; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_longlong>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} - -pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; -pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 2; -pub const PT_GETFPREGS: ::c_int = PT_FIRSTMACH + 3; -pub const PT_SETFPREGS: ::c_int = PT_FIRSTMACH + 4; diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/mod.rs b/libc/src/unix/bsd/netbsdlike/netbsd/mod.rs deleted file mode 100644 index 422539a..0000000 --- a/libc/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ /dev/null @@ -1,1965 +0,0 @@ -pub type clock_t = ::c_uint; -pub type suseconds_t = ::c_int; -pub type dev_t = u64; -pub type blksize_t = i32; -pub type fsblkcnt_t = u64; -pub type fsfilcnt_t = u64; -pub type idtype_t = ::c_int; -pub type mqd_t = ::c_int; -type __pthread_spin_t = __cpu_simple_lock_nv_t; -pub type vm_size_t = ::uintptr_t; -pub type lwpid_t = ::c_uint; -pub type shmatt_t = ::c_uint; - -impl siginfo_t { - pub unsafe fn si_value(&self) -> ::sigval { - #[repr(C)] - struct siginfo_timer { - _si_signo: ::c_int, - _si_errno: ::c_int, - _si_code: ::c_int, - __pad1: ::c_int, - _pid: ::pid_t, - _uid: ::uid_t, - value: ::sigval, - } - (*(self as *const siginfo_t as *const siginfo_timer)).value - } -} - -s! { - pub struct aiocb { - pub aio_offset: ::off_t, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - pub aio_fildes: ::c_int, - pub aio_lio_opcode: ::c_int, - pub aio_reqprio: ::c_int, - pub aio_sigevent: ::sigevent, - _state: ::c_int, - _errno: ::c_int, - _retval: ::ssize_t - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_matchc: ::size_t, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - pub gl_pathv: *mut *mut ::c_char, - - __unused3: *mut ::c_void, - - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - __unused6: *mut ::c_void, - __unused7: *mut ::c_void, - __unused8: *mut ::c_void, - } - - pub struct mq_attr { - pub mq_flags: ::c_long, - pub mq_maxmsg: ::c_long, - pub mq_msgsize: ::c_long, - pub mq_curmsgs: ::c_long, - } - - pub struct sigset_t { - __bits: [u32; 4], - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_mode: ::mode_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atimensec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtimensec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctimensec: ::c_long, - pub st_birthtime: ::time_t, - pub st_birthtimensec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: u32, - pub st_gen: u32, - pub st_spare: [u32; 2], - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: ::socklen_t, - pub ai_canonname: *mut ::c_char, - pub ai_addr: *mut ::sockaddr, - pub ai_next: *mut ::addrinfo, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - __pad1: ::c_int, - pub si_addr: *mut ::c_void, - __pad2: [u64; 13], - } - - pub struct pthread_attr_t { - pta_magic: ::c_uint, - pta_flags: ::c_int, - pta_private: *mut ::c_void, - } - - pub struct pthread_mutex_t { - ptm_magic: ::c_uint, - ptm_errorcheck: __pthread_spin_t, - #[cfg(any(target_arch = "sparc", target_arch = "sparc64", - target_arch = "x86", target_arch = "x86_64"))] - ptm_pad1: [u8; 3], - // actually a union with a non-unused, 0-initialized field - ptm_unused: __pthread_spin_t, - #[cfg(any(target_arch = "sparc", target_arch = "sparc64", - target_arch = "x86", target_arch = "x86_64"))] - ptm_pad2: [u8; 3], - ptm_owner: ::pthread_t, - ptm_waiters: *mut u8, - ptm_recursed: ::c_uint, - ptm_spare2: *mut ::c_void, - } - - pub struct pthread_mutexattr_t { - ptma_magic: ::c_uint, - ptma_private: *mut ::c_void, - } - - pub struct pthread_rwlockattr_t { - ptra_magic: ::c_uint, - ptra_private: *mut ::c_void, - } - - pub struct pthread_cond_t { - ptc_magic: ::c_uint, - ptc_lock: __pthread_spin_t, - ptc_waiters_first: *mut u8, - ptc_waiters_last: *mut u8, - ptc_mutex: *mut ::pthread_mutex_t, - ptc_private: *mut ::c_void, - } - - pub struct pthread_condattr_t { - ptca_magic: ::c_uint, - ptca_private: *mut ::c_void, - } - - pub struct pthread_rwlock_t { - ptr_magic: ::c_uint, - ptr_interlock: __pthread_spin_t, - ptr_rblocked_first: *mut u8, - ptr_rblocked_last: *mut u8, - ptr_wblocked_first: *mut u8, - ptr_wblocked_last: *mut u8, - ptr_nreaders: ::c_uint, - ptr_owner: ::pthread_t, - ptr_private: *mut ::c_void, - } - - pub struct kevent { - pub ident: ::uintptr_t, - pub filter: u32, - pub flags: u32, - pub fflags: u32, - pub data: i64, - pub udata: ::intptr_t, - } - - pub struct dqblk { - pub dqb_bhardlimit: u32, - pub dqb_bsoftlimit: u32, - pub dqb_curblocks: u32, - pub dqb_ihardlimit: u32, - pub dqb_isoftlimit: u32, - pub dqb_curinodes: u32, - pub dqb_btime: i32, - pub dqb_itime: i32, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *const ::c_void, - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct if_data { - pub ifi_type: ::c_uchar, - pub ifi_addrlen: ::c_uchar, - pub ifi_hdrlen: ::c_uchar, - pub ifi_link_state: ::c_int, - pub ifi_mtu: u64, - pub ifi_metric: u64, - pub ifi_baudrate: u64, - pub ifi_ipackets: u64, - pub ifi_ierrors: u64, - pub ifi_opackets: u64, - pub ifi_oerrors: u64, - pub ifi_collisions: u64, - pub ifi_ibytes: u64, - pub ifi_obytes: u64, - pub ifi_imcasts: u64, - pub ifi_omcasts: u64, - pub ifi_iqdrops: u64, - pub ifi_noproto: u64, - pub ifi_lastchange: ::timespec, - } - - pub struct if_msghdr { - pub ifm_msglen: ::c_ushort, - pub ifm_version: ::c_uchar, - pub ifm_type: ::c_uchar, - pub ifm_addrs: ::c_int, - pub ifm_flags: ::c_int, - pub ifm_index: ::c_ushort, - pub ifm_data: if_data, - } - - pub struct sockcred { - pub sc_pid: ::pid_t, - pub sc_uid: ::uid_t, - pub sc_euid: ::uid_t, - pub sc_gid: ::gid_t, - pub sc_egid: ::gid_t, - pub sc_ngroups: ::c_int, - pub sc_groups: [::gid_t; 1], - } - - pub struct sockaddr_dl { - pub sdl_len: ::c_uchar, - pub sdl_family: ::c_uchar, - pub sdl_index: ::c_ushort, - pub sdl_type: u8, - pub sdl_nlen: u8, - pub sdl_alen: u8, - pub sdl_slen: u8, - pub sdl_data: [::c_char; 12], - } - - pub struct mmsghdr { - pub msg_hdr: ::msghdr, - pub msg_len: ::c_uint, - } - - pub struct __exit_status { - pub e_termination: u16, - pub e_exit: u16, - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_lpid: ::pid_t, - pub shm_cpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - _shm_internal: *mut ::c_void, - } - - pub struct utmp { - pub ut_line: [::c_char; UT_LINESIZE], - pub ut_name: [::c_char; UT_NAMESIZE], - pub ut_host: [::c_char; UT_HOSTSIZE], - pub ut_time: ::time_t - } - - pub struct lastlog { - pub ll_line: [::c_char; UT_LINESIZE], - pub ll_host: [::c_char; UT_HOSTSIZE], - pub ll_time: ::time_t - } -} - -s_no_extra_traits! { - - pub struct utmpx { - pub ut_name: [::c_char; _UTX_USERSIZE], - pub ut_id: [::c_char; _UTX_IDSIZE], - pub ut_line: [::c_char; _UTX_LINESIZE], - pub ut_host: [::c_char; _UTX_HOSTSIZE], - pub ut_session: u16, - pub ut_type: u16, - pub ut_pid: ::pid_t, - pub ut_exit: __exit_status, - pub ut_ss: sockaddr_storage, - pub ut_tv: ::timeval, - pub ut_pad: [u8; _UTX_PADSIZE], - } - - pub struct lastlogx { - pub ll_tv: ::timeval, - pub ll_line: [::c_char; _UTX_LINESIZE], - pub ll_host: [::c_char; _UTX_HOSTSIZE], - pub ll_ss: sockaddr_storage, - } - - pub struct in_pktinfo { - pub ipi_addr: ::in_addr, - pub ipi_ifindex: ::c_uint, - } - - #[repr(packed)] - pub struct arphdr { - pub ar_hrd: u16, - pub ar_pro: u16, - pub ar_hln: u8, - pub ar_pln: u8, - pub ar_op: u16, - } - - #[repr(packed)] - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [i8; 8], - } - - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_reclen: u16, - pub d_namlen: u16, - pub d_type: u8, - pub d_name: [::c_char; 512], - } - - pub struct statvfs { - pub f_flag: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_iosize: ::c_ulong, - - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_bresvd: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fresvd: ::fsfilcnt_t, - - pub f_syncreads: u64, - pub f_syncwrites: u64, - - pub f_asyncreads: u64, - pub f_asyncwrites: u64, - - pub f_fsidx: ::fsid_t, - pub f_fsid: ::c_ulong, - pub f_namemax: ::c_ulong, - pub f_owner: ::uid_t, - - pub f_spare: [u32; 4], - - pub f_fstypename: [::c_char; 32], - pub f_mntonname: [::c_char; 1024], - pub f_mntfromname: [::c_char; 1024], - } - - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_pad2: i64, - __ss_pad3: [u8; 112], - } - - pub struct sigevent { - pub sigev_notify: ::c_int, - pub sigev_signo: ::c_int, - pub sigev_value: ::sigval, - __unused1: *mut ::c_void, //actually a function pointer - pub sigev_notify_attributes: *mut ::c_void - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for utmpx { - fn eq(&self, other: &utmpx) -> bool { - self.ut_type == other.ut_type - && self.ut_pid == other.ut_pid - && self.ut_name == other.ut_name - && self.ut_line == other.ut_line - && self.ut_id == other.ut_id - && self.ut_exit == other.ut_exit - && self.ut_session == other.ut_session - && self.ut_tv == other.ut_tv - && self.ut_ss == other.ut_ss - && self - .ut_pad - .iter() - .zip(other.ut_pad.iter()) - .all(|(a,b)| a == b) - && self - .ut_host - .iter() - .zip(other.ut_host.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for utmpx {} - - impl ::fmt::Debug for utmpx { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utmpx") - .field("ut_name", &self.ut_name) - .field("ut_id", &self.ut_id) - .field("ut_line", &self.ut_line) - // FIXME .field("ut_host", &self.ut_host) - .field("ut_session", &self.ut_session) - .field("ut_type", &self.ut_type) - .field("ut_pid", &self.ut_pid) - .field("ut_exit", &self.ut_exit) - .field("ut_ss", &self.ut_ss) - .field("ut_tv", &self.ut_tv) - // FIXME .field("ut_pad", &self.ut_pad) - .finish() - } - } - - impl ::hash::Hash for utmpx { - fn hash(&self, state: &mut H) { - self.ut_name.hash(state); - self.ut_type.hash(state); - self.ut_pid.hash(state); - self.ut_line.hash(state); - self.ut_id.hash(state); - self.ut_host.hash(state); - self.ut_exit.hash(state); - self.ut_session.hash(state); - self.ut_tv.hash(state); - self.ut_ss.hash(state); - self.ut_pad.hash(state); - } - } - - impl PartialEq for lastlogx { - fn eq(&self, other: &lastlogx) -> bool { - self.ll_tv == other.ll_tv - && self.ll_line == other.ll_line - && self.ll_ss == other.ll_ss - && self - .ll_host - .iter() - .zip(other.ll_host.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for lastlogx {} - - impl ::fmt::Debug for lastlogx { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("lastlogx") - .field("ll_tv", &self.ll_tv) - .field("ll_line", &self.ll_line) - // FIXME.field("ll_host", &self.ll_host) - .field("ll_ss", &self.ll_ss) - .finish() - } - } - - impl ::hash::Hash for lastlogx { - fn hash(&self, state: &mut H) { - self.ll_tv.hash(state); - self.ll_line.hash(state); - self.ll_host.hash(state); - self.ll_ss.hash(state); - } - } - - impl PartialEq for in_pktinfo { - fn eq(&self, other: &in_pktinfo) -> bool { - self.ipi_addr == other.ipi_addr - && self.ipi_ifindex == other.ipi_ifindex - } - } - impl Eq for in_pktinfo {} - impl ::fmt::Debug for in_pktinfo { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("in_pktinfo") - .field("ipi_addr", &self.ipi_addr) - .field("ipi_ifindex", &self.ipi_ifindex) - .finish() - } - } - impl ::hash::Hash for in_pktinfo { - fn hash(&self, state: &mut H) { - self.ipi_addr.hash(state); - self.ipi_ifindex.hash(state); - } - } - - impl PartialEq for arphdr { - fn eq(&self, other: &arphdr) -> bool { - self.ar_hrd == other.ar_hrd - && self.ar_pro == other.ar_pro - && self.ar_hln == other.ar_hln - && self.ar_pln == other.ar_pln - && self.ar_op == other.ar_op - } - } - impl Eq for arphdr {} - impl ::fmt::Debug for arphdr { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - let ar_hrd = self.ar_hrd; - let ar_pro = self.ar_pro; - let ar_op = self.ar_op; - f.debug_struct("arphdr") - .field("ar_hrd", &ar_hrd) - .field("ar_pro", &ar_pro) - .field("ar_hln", &self.ar_hln) - .field("ar_pln", &self.ar_pln) - .field("ar_op", &ar_op) - .finish() - } - } - impl ::hash::Hash for arphdr { - fn hash(&self, state: &mut H) { - let ar_hrd = self.ar_hrd; - let ar_pro = self.ar_pro; - let ar_op = self.ar_op; - ar_hrd.hash(state); - ar_pro.hash(state); - self.ar_hln.hash(state); - self.ar_pln.hash(state); - ar_op.hash(state); - } - } - - impl PartialEq for in_addr { - fn eq(&self, other: &in_addr) -> bool { - self.s_addr == other.s_addr - } - } - impl Eq for in_addr {} - impl ::fmt::Debug for in_addr { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - let s_addr = self.s_addr; - f.debug_struct("in_addr") - .field("s_addr", &s_addr) - .finish() - } - } - impl ::hash::Hash for in_addr { - fn hash(&self, state: &mut H) { - let s_addr = self.s_addr; - s_addr.hash(state); - } - } - - impl PartialEq for ip_mreq { - fn eq(&self, other: &ip_mreq) -> bool { - self.imr_multiaddr == other.imr_multiaddr - && self.imr_interface == other.imr_interface - } - } - impl Eq for ip_mreq {} - impl ::fmt::Debug for ip_mreq { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("ip_mreq") - .field("imr_multiaddr", &self.imr_multiaddr) - .field("imr_interface", &self.imr_interface) - .finish() - } - } - impl ::hash::Hash for ip_mreq { - fn hash(&self, state: &mut H) { - self.imr_multiaddr.hash(state); - self.imr_interface.hash(state); - } - } - - impl PartialEq for sockaddr_in { - fn eq(&self, other: &sockaddr_in) -> bool { - self.sin_len == other.sin_len - && self.sin_family == other.sin_family - && self.sin_port == other.sin_port - && self.sin_addr == other.sin_addr - && self.sin_zero == other.sin_zero - } - } - impl Eq for sockaddr_in {} - impl ::fmt::Debug for sockaddr_in { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_in") - .field("sin_len", &self.sin_len) - .field("sin_family", &self.sin_family) - .field("sin_port", &self.sin_port) - .field("sin_addr", &self.sin_addr) - .field("sin_zero", &self.sin_zero) - .finish() - } - } - impl ::hash::Hash for sockaddr_in { - fn hash(&self, state: &mut H) { - self.sin_len.hash(state); - self.sin_family.hash(state); - self.sin_port.hash(state); - self.sin_addr.hash(state); - self.sin_zero.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_fileno == other.d_fileno - && self.d_reclen == other.d_reclen - && self.d_namlen == other.d_namlen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_fileno", &self.d_fileno) - .field("d_reclen", &self.d_reclen) - .field("d_namlen", &self.d_namlen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_fileno.hash(state); - self.d_reclen.hash(state); - self.d_namlen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for statvfs { - fn eq(&self, other: &statvfs) -> bool { - self.f_flag == other.f_flag - && self.f_bsize == other.f_bsize - && self.f_frsize == other.f_frsize - && self.f_iosize == other.f_iosize - && self.f_blocks == other.f_blocks - && self.f_bfree == other.f_bfree - && self.f_bavail == other.f_bavail - && self.f_bresvd == other.f_bresvd - && self.f_files == other.f_files - && self.f_ffree == other.f_ffree - && self.f_favail == other.f_favail - && self.f_fresvd == other.f_fresvd - && self.f_syncreads == other.f_syncreads - && self.f_syncwrites == other.f_syncwrites - && self.f_asyncreads == other.f_asyncreads - && self.f_asyncwrites == other.f_asyncwrites - && self.f_fsidx == other.f_fsidx - && self.f_fsid == other.f_fsid - && self.f_namemax == other.f_namemax - && self.f_owner == other.f_owner - && self.f_spare == other.f_spare - && self.f_fstypename == other.f_fstypename - && self - .f_mntonname - .iter() - .zip(other.f_mntonname.iter()) - .all(|(a,b)| a == b) - && self - .f_mntfromname - .iter() - .zip(other.f_mntfromname.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for statvfs {} - impl ::fmt::Debug for statvfs { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("statvfs") - .field("f_flag", &self.f_flag) - .field("f_bsize", &self.f_bsize) - .field("f_frsize", &self.f_frsize) - .field("f_iosize", &self.f_iosize) - .field("f_blocks", &self.f_blocks) - .field("f_bfree", &self.f_bfree) - .field("f_bavail", &self.f_bavail) - .field("f_bresvd", &self.f_bresvd) - .field("f_files", &self.f_files) - .field("f_ffree", &self.f_ffree) - .field("f_favail", &self.f_favail) - .field("f_fresvd", &self.f_fresvd) - .field("f_syncreads", &self.f_syncreads) - .field("f_syncwrites", &self.f_syncwrites) - .field("f_asyncreads", &self.f_asyncreads) - .field("f_asyncwrites", &self.f_asyncwrites) - .field("f_fsidx", &self.f_fsidx) - .field("f_fsid", &self.f_fsid) - .field("f_namemax", &self.f_namemax) - .field("f_owner", &self.f_owner) - .field("f_spare", &self.f_spare) - .field("f_fstypename", &self.f_fstypename) - // FIXME: .field("f_mntonname", &self.f_mntonname) - // FIXME: .field("f_mntfromname", &self.f_mntfromname) - .finish() - } - } - impl ::hash::Hash for statvfs { - fn hash(&self, state: &mut H) { - self.f_flag.hash(state); - self.f_bsize.hash(state); - self.f_frsize.hash(state); - self.f_iosize.hash(state); - self.f_blocks.hash(state); - self.f_bfree.hash(state); - self.f_bavail.hash(state); - self.f_bresvd.hash(state); - self.f_files.hash(state); - self.f_ffree.hash(state); - self.f_favail.hash(state); - self.f_fresvd.hash(state); - self.f_syncreads.hash(state); - self.f_syncwrites.hash(state); - self.f_asyncreads.hash(state); - self.f_asyncwrites.hash(state); - self.f_fsidx.hash(state); - self.f_fsid.hash(state); - self.f_namemax.hash(state); - self.f_owner.hash(state); - self.f_spare.hash(state); - self.f_fstypename.hash(state); - self.f_mntonname.hash(state); - self.f_mntfromname.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_len == other.ss_len - && self.ss_family == other.ss_family - && self.__ss_pad1 == other.__ss_pad1 - && self.__ss_pad2 == other.__ss_pad2 - && self - .__ss_pad3 - .iter() - .zip(other.__ss_pad3.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr_storage {} - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_len", &self.ss_len) - .field("ss_family", &self.ss_family) - .field("__ss_pad1", &self.__ss_pad1) - .field("__ss_pad2", &self.__ss_pad2) - // FIXME: .field("__ss_pad3", &self.__ss_pad3) - .finish() - } - } - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_len.hash(state); - self.ss_family.hash(state); - self.__ss_pad1.hash(state); - self.__ss_pad2.hash(state); - self.__ss_pad3.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_notify == other.sigev_notify - && self.sigev_signo == other.sigev_signo - && self.sigev_value == other.sigev_value - && self.sigev_notify_attributes - == other.sigev_notify_attributes - } - } - impl Eq for sigevent {} - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_notify", &self.sigev_notify) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_value", &self.sigev_value) - .field("sigev_notify_attributes", - &self.sigev_notify_attributes) - .finish() - } - } - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_notify.hash(state); - self.sigev_signo.hash(state); - self.sigev_value.hash(state); - self.sigev_notify_attributes.hash(state); - } - } - } -} - -pub const AT_FDCWD: ::c_int = -100; -pub const AT_EACCESS: ::c_int = 0x100; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x200; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; -pub const AT_REMOVEDIR: ::c_int = 0x800; - -pub const EXTATTR_NAMESPACE_USER: ::c_int = 1; -pub const EXTATTR_NAMESPACE_SYSTEM: ::c_int = 2; - -pub const LC_COLLATE_MASK: ::c_int = (1 << ::LC_COLLATE); -pub const LC_CTYPE_MASK: ::c_int = (1 << ::LC_CTYPE); -pub const LC_MONETARY_MASK: ::c_int = (1 << ::LC_MONETARY); -pub const LC_NUMERIC_MASK: ::c_int = (1 << ::LC_NUMERIC); -pub const LC_TIME_MASK: ::c_int = (1 << ::LC_TIME); -pub const LC_MESSAGES_MASK: ::c_int = (1 << ::LC_MESSAGES); -pub const LC_ALL_MASK: ::c_int = !0; - -pub const ERA: ::nl_item = 52; -pub const ERA_D_FMT: ::nl_item = 53; -pub const ERA_D_T_FMT: ::nl_item = 54; -pub const ERA_T_FMT: ::nl_item = 55; -pub const ALT_DIGITS: ::nl_item = 56; - -pub const O_CLOEXEC: ::c_int = 0x400000; -pub const O_ALT_IO: ::c_int = 0x40000; -pub const O_NOSIGPIPE: ::c_int = 0x1000000; -pub const O_SEARCH: ::c_int = 0x800000; -pub const O_DIRECTORY: ::c_int = 0x200000; -pub const O_DIRECT: ::c_int = 0x00080000; -pub const O_RSYNC: ::c_int = 0x00020000; - -pub const MS_SYNC: ::c_int = 0x4; -pub const MS_INVALIDATE: ::c_int = 0x2; - -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] -pub const RLIM_NLIMITS: ::c_int = 12; - -pub const EIDRM: ::c_int = 82; -pub const ENOMSG: ::c_int = 83; -pub const EOVERFLOW: ::c_int = 84; -pub const EILSEQ: ::c_int = 85; -pub const ENOTSUP: ::c_int = 86; -pub const ECANCELED: ::c_int = 87; -pub const EBADMSG: ::c_int = 88; -pub const ENODATA: ::c_int = 89; -pub const ENOSR: ::c_int = 90; -pub const ENOSTR: ::c_int = 91; -pub const ETIME: ::c_int = 92; -pub const ENOATTR: ::c_int = 93; -pub const EMULTIHOP: ::c_int = 94; -pub const ENOLINK: ::c_int = 95; -pub const EPROTO: ::c_int = 96; -pub const ELAST: ::c_int = 96; - -pub const F_DUPFD_CLOEXEC: ::c_int = 12; -pub const F_CLOSEM: ::c_int = 10; -pub const F_GETNOSIGPIPE: ::c_int = 13; -pub const F_SETNOSIGPIPE: ::c_int = 14; -pub const F_MAXFD: ::c_int = 11; - -pub const IP_RECVDSTADDR: ::c_int = 7; -pub const IP_SENDSRCADDR: ::c_int = IP_RECVDSTADDR; -pub const IP_RECVIF: ::c_int = 20; -pub const IP_PKTINFO: ::c_int = 25; -pub const IP_RECVPKTINFO: ::c_int = 26; -pub const IPV6_JOIN_GROUP: ::c_int = 12; -pub const IPV6_LEAVE_GROUP: ::c_int = 13; - -pub const TCP_KEEPIDLE: ::c_int = 3; -pub const TCP_KEEPINTVL: ::c_int = 5; -pub const TCP_KEEPCNT: ::c_int = 6; -pub const TCP_KEEPINIT: ::c_int = 7; -pub const TCP_INFO: ::c_int = 9; -pub const TCP_MD5SIG: ::c_int = 0x10; -pub const TCP_CONGCTL: ::c_int = 0x20; - -pub const SOCK_CONN_DGRAM: ::c_int = 6; -pub const SOCK_DCCP: ::c_int = SOCK_CONN_DGRAM; -pub const SOCK_NOSIGPIPE: ::c_int = 0x40000000; -pub const SOCK_FLAGS_MASK: ::c_int = 0xf0000000; - -pub const SO_SNDTIMEO: ::c_int = 0x100b; -pub const SO_RCVTIMEO: ::c_int = 0x100c; -pub const SO_ACCEPTFILTER: ::c_int = 0x1000; -pub const SO_TIMESTAMP: ::c_int = 0x2000; -pub const SO_OVERFLOWED: ::c_int = 0x1009; -pub const SO_NOHEADER: ::c_int = 0x100a; - -// https://github.com/NetBSD/src/blob/trunk/sys/net/if.h#L373 -pub const IFF_UP: ::c_int = 0x0001; // interface is up -pub const IFF_BROADCAST: ::c_int = 0x0002; // broadcast address valid -pub const IFF_DEBUG: ::c_int = 0x0004; // turn on debugging -pub const IFF_LOOPBACK: ::c_int = 0x0008; // is a loopback net -pub const IFF_POINTOPOINT: ::c_int = 0x0010; // interface is point-to-point link -pub const IFF_NOTRAILERS: ::c_int = 0x0020; // avoid use of trailers -pub const IFF_RUNNING: ::c_int = 0x0040; // resources allocated -pub const IFF_NOARP: ::c_int = 0x0080; // no address resolution protocol -pub const IFF_PROMISC: ::c_int = 0x0100; // receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x0200; // receive all multicast packets -pub const IFF_OACTIVE: ::c_int = 0x0400; // transmission in progress -pub const IFF_SIMPLEX: ::c_int = 0x0800; // can't hear own transmissions -pub const IFF_LINK0: ::c_int = 0x1000; // per link layer defined bit -pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit -pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit -pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast - -// sys/netinet/in.h -// Protocols (RFC 1700) -// NOTE: These are in addition to the constants defined in src/unix/mod.rs - -// IPPROTO_IP defined in src/unix/mod.rs -/// Hop-by-hop option header -pub const IPPROTO_HOPOPTS: ::c_int = 0; -// IPPROTO_ICMP defined in src/unix/mod.rs -/// group mgmt protocol -pub const IPPROTO_IGMP: ::c_int = 2; -/// gateway^2 (deprecated) -pub const IPPROTO_GGP: ::c_int = 3; -/// for compatibility -pub const IPPROTO_IPIP: ::c_int = 4; -// IPPROTO_TCP defined in src/unix/mod.rs -/// exterior gateway protocol -pub const IPPROTO_EGP: ::c_int = 8; -/// pup -pub const IPPROTO_PUP: ::c_int = 12; -// IPPROTO_UDP defined in src/unix/mod.rs -/// xns idp -pub const IPPROTO_IDP: ::c_int = 22; -/// tp-4 w/ class negotiation -pub const IPPROTO_TP: ::c_int = 29; -/// DCCP -pub const IPPROTO_DCCP: ::c_int = 33; -// IPPROTO_IPV6 defined in src/unix/mod.rs -/// IP6 routing header -pub const IPPROTO_ROUTING: ::c_int = 43; -/// IP6 fragmentation header -pub const IPPROTO_FRAGMENT: ::c_int = 44; -/// resource reservation -pub const IPPROTO_RSVP: ::c_int = 46; -/// General Routing Encap. -pub const IPPROTO_GRE: ::c_int = 47; -/// IP6 Encap Sec. Payload -pub const IPPROTO_ESP: ::c_int = 50; -/// IP6 Auth Header -pub const IPPROTO_AH: ::c_int = 51; -/// IP Mobility RFC 2004 -pub const IPPROTO_MOBILE: ::c_int = 55; -/// IPv6 ICMP -pub const IPPROTO_IPV6_ICMP: ::c_int = 58; -// IPPROTO_ICMPV6 defined in src/unix/mod.rs -/// IP6 no next header -pub const IPPROTO_NONE: ::c_int = 59; -/// IP6 destination option -pub const IPPROTO_DSTOPTS: ::c_int = 60; -/// ISO cnlp -pub const IPPROTO_EON: ::c_int = 80; -/// Ethernet-in-IP -pub const IPPROTO_ETHERIP: ::c_int = 97; -/// encapsulation header -pub const IPPROTO_ENCAP: ::c_int = 98; -/// Protocol indep. multicast -pub const IPPROTO_PIM: ::c_int = 103; -/// IP Payload Comp. Protocol -pub const IPPROTO_IPCOMP: ::c_int = 108; -/// VRRP RFC 2338 -pub const IPPROTO_VRRP: ::c_int = 112; -/// Common Address Resolution Protocol -pub const IPPROTO_CARP: ::c_int = 112; -/// L2TPv3 -// TEMP: Disabled for now; this constant was added to NetBSD on 2017-02-16, -// but isn't yet supported by the NetBSD rumprun kernel image used for -// libc testing. -//pub const IPPROTO_L2TP: ::c_int = 115; -/// SCTP -pub const IPPROTO_SCTP: ::c_int = 132; -/// PFSYNC -pub const IPPROTO_PFSYNC: ::c_int = 240; -pub const IPPROTO_MAX: ::c_int = 256; - -/// last return value of *_input(), meaning "all job for this pkt is done". -pub const IPPROTO_DONE: ::c_int = 257; - -/// sysctl placeholder for (FAST_)IPSEC -pub const CTL_IPPROTO_IPSEC: ::c_int = 258; - -pub const AF_OROUTE: ::c_int = 17; -pub const AF_ARP: ::c_int = 28; -pub const pseudo_AF_KEY: ::c_int = 29; -pub const pseudo_AF_HDRCMPLT: ::c_int = 30; -pub const AF_BLUETOOTH: ::c_int = 31; -pub const AF_IEEE80211: ::c_int = 32; -pub const AF_MPLS: ::c_int = 33; -pub const AF_ROUTE: ::c_int = 34; -pub const NET_RT_DUMP: ::c_int = 1; -pub const NET_RT_FLAGS: ::c_int = 2; -pub const NET_RT_OOOIFLIST: ::c_int = 3; -pub const NET_RT_OOIFLIST: ::c_int = 4; -pub const NET_RT_OIFLIST: ::c_int = 5; -pub const NET_RT_IFLIST: ::c_int = 6; -pub const NET_RT_MAXID: ::c_int = 7; - -pub const PF_OROUTE: ::c_int = AF_OROUTE; -pub const PF_ARP: ::c_int = AF_ARP; -pub const PF_KEY: ::c_int = pseudo_AF_KEY; -pub const PF_BLUETOOTH: ::c_int = AF_BLUETOOTH; -pub const PF_MPLS: ::c_int = AF_MPLS; -pub const PF_ROUTE: ::c_int = AF_ROUTE; - -pub const MSG_NBIO: ::c_int = 0x1000; -pub const MSG_WAITFORONE: ::c_int = 0x2000; -pub const MSG_NOTIFICATION: ::c_int = 0x4000; - -pub const SCM_TIMESTAMP: ::c_int = 0x08; -pub const SCM_CREDS: ::c_int = 0x10; - -pub const O_DSYNC: ::c_int = 0x10000; - -pub const MAP_RENAME: ::c_int = 0x20; -pub const MAP_NORESERVE: ::c_int = 0x40; -pub const MAP_HASSEMAPHORE: ::c_int = 0x200; -pub const MAP_WIRED: ::c_int = 0x800; - -pub const DCCP_TYPE_REQUEST: ::c_int = 0; -pub const DCCP_TYPE_RESPONSE: ::c_int = 1; -pub const DCCP_TYPE_DATA: ::c_int = 2; -pub const DCCP_TYPE_ACK: ::c_int = 3; -pub const DCCP_TYPE_DATAACK: ::c_int = 4; -pub const DCCP_TYPE_CLOSEREQ: ::c_int = 5; -pub const DCCP_TYPE_CLOSE: ::c_int = 6; -pub const DCCP_TYPE_RESET: ::c_int = 7; -pub const DCCP_TYPE_MOVE: ::c_int = 8; - -pub const DCCP_FEATURE_CC: ::c_int = 1; -pub const DCCP_FEATURE_ECN: ::c_int = 2; -pub const DCCP_FEATURE_ACKRATIO: ::c_int = 3; -pub const DCCP_FEATURE_ACKVECTOR: ::c_int = 4; -pub const DCCP_FEATURE_MOBILITY: ::c_int = 5; -pub const DCCP_FEATURE_LOSSWINDOW: ::c_int = 6; -pub const DCCP_FEATURE_CONN_NONCE: ::c_int = 8; -pub const DCCP_FEATURE_IDENTREG: ::c_int = 7; - -pub const DCCP_OPT_PADDING: ::c_int = 0; -pub const DCCP_OPT_DATA_DISCARD: ::c_int = 1; -pub const DCCP_OPT_SLOW_RECV: ::c_int = 2; -pub const DCCP_OPT_BUF_CLOSED: ::c_int = 3; -pub const DCCP_OPT_CHANGE_L: ::c_int = 32; -pub const DCCP_OPT_CONFIRM_L: ::c_int = 33; -pub const DCCP_OPT_CHANGE_R: ::c_int = 34; -pub const DCCP_OPT_CONFIRM_R: ::c_int = 35; -pub const DCCP_OPT_INIT_COOKIE: ::c_int = 36; -pub const DCCP_OPT_NDP_COUNT: ::c_int = 37; -pub const DCCP_OPT_ACK_VECTOR0: ::c_int = 38; -pub const DCCP_OPT_ACK_VECTOR1: ::c_int = 39; -pub const DCCP_OPT_RECV_BUF_DROPS: ::c_int = 40; -pub const DCCP_OPT_TIMESTAMP: ::c_int = 41; -pub const DCCP_OPT_TIMESTAMP_ECHO: ::c_int = 42; -pub const DCCP_OPT_ELAPSEDTIME: ::c_int = 43; -pub const DCCP_OPT_DATACHECKSUM: ::c_int = 44; - -pub const DCCP_REASON_UNSPEC: ::c_int = 0; -pub const DCCP_REASON_CLOSED: ::c_int = 1; -pub const DCCP_REASON_INVALID: ::c_int = 2; -pub const DCCP_REASON_OPTION_ERR: ::c_int = 3; -pub const DCCP_REASON_FEA_ERR: ::c_int = 4; -pub const DCCP_REASON_CONN_REF: ::c_int = 5; -pub const DCCP_REASON_BAD_SNAME: ::c_int = 6; -pub const DCCP_REASON_BAD_COOKIE: ::c_int = 7; -pub const DCCP_REASON_INV_MOVE: ::c_int = 8; -pub const DCCP_REASON_UNANSW_CH: ::c_int = 10; -pub const DCCP_REASON_FRUITLESS_NEG: ::c_int = 11; - -pub const DCCP_CCID: ::c_int = 1; -pub const DCCP_CSLEN: ::c_int = 2; -pub const DCCP_MAXSEG: ::c_int = 4; -pub const DCCP_SERVICE: ::c_int = 8; - -pub const DCCP_NDP_LIMIT: ::c_int = 16; -pub const DCCP_SEQ_NUM_LIMIT: ::c_int = 16777216; -pub const DCCP_MAX_OPTIONS: ::c_int = 32; -pub const DCCP_MAX_PKTS: ::c_int = 100; - -pub const _PC_LINK_MAX: ::c_int = 1; -pub const _PC_MAX_CANON: ::c_int = 2; -pub const _PC_MAX_INPUT: ::c_int = 3; -pub const _PC_NAME_MAX: ::c_int = 4; -pub const _PC_PATH_MAX: ::c_int = 5; -pub const _PC_PIPE_BUF: ::c_int = 6; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 7; -pub const _PC_NO_TRUNC: ::c_int = 8; -pub const _PC_VDISABLE: ::c_int = 9; -pub const _PC_SYNC_IO: ::c_int = 10; -pub const _PC_FILESIZEBITS: ::c_int = 11; -pub const _PC_SYMLINK_MAX: ::c_int = 12; -pub const _PC_2_SYMLINKS: ::c_int = 13; -pub const _PC_ACL_EXTENDED: ::c_int = 14; -pub const _PC_MIN_HOLE_SIZE: ::c_int = 15; - -pub const _SC_SYNCHRONIZED_IO: ::c_int = 31; -pub const _SC_IOV_MAX: ::c_int = 32; -pub const _SC_MAPPED_FILES: ::c_int = 33; -pub const _SC_MEMLOCK: ::c_int = 34; -pub const _SC_MEMLOCK_RANGE: ::c_int = 35; -pub const _SC_MEMORY_PROTECTION: ::c_int = 36; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 37; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 38; -pub const _SC_CLK_TCK: ::c_int = 39; -pub const _SC_ATEXIT_MAX: ::c_int = 40; -pub const _SC_THREADS: ::c_int = 41; -pub const _SC_SEMAPHORES: ::c_int = 42; -pub const _SC_BARRIERS: ::c_int = 43; -pub const _SC_TIMERS: ::c_int = 44; -pub const _SC_SPIN_LOCKS: ::c_int = 45; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 46; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 47; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 48; -pub const _SC_CLOCK_SELECTION: ::c_int = 49; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 50; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 51; -pub const _SC_AIO_MAX: ::c_int = 52; -pub const _SC_MESSAGE_PASSING: ::c_int = 53; -pub const _SC_MQ_OPEN_MAX: ::c_int = 54; -pub const _SC_MQ_PRIO_MAX: ::c_int = 55; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 56; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 57; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 58; -pub const _SC_THREAD_STACK_MIN: ::c_int = 59; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 60; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 61; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 62; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 63; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 64; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 65; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 66; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 67; -pub const _SC_TTY_NAME_MAX: ::c_int = 68; -pub const _SC_HOST_NAME_MAX: ::c_int = 69; -pub const _SC_PASS_MAX: ::c_int = 70; -pub const _SC_REGEXP: ::c_int = 71; -pub const _SC_SHELL: ::c_int = 72; -pub const _SC_SYMLOOP_MAX: ::c_int = 73; -pub const _SC_V6_ILP32_OFF32: ::c_int = 74; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 75; -pub const _SC_V6_LP64_OFF64: ::c_int = 76; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 77; -pub const _SC_2_PBS: ::c_int = 80; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 81; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 82; -pub const _SC_2_PBS_LOCATE: ::c_int = 83; -pub const _SC_2_PBS_MESSAGE: ::c_int = 84; -pub const _SC_2_PBS_TRACK: ::c_int = 85; -pub const _SC_SPAWN: ::c_int = 86; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 87; -pub const _SC_TIMER_MAX: ::c_int = 88; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 89; -pub const _SC_CPUTIME: ::c_int = 90; -pub const _SC_THREAD_CPUTIME: ::c_int = 91; -pub const _SC_DELAYTIMER_MAX: ::c_int = 92; -// These two variables will be supported in NetBSD 8.0 -// pub const _SC_SIGQUEUE_MAX : ::c_int = 93; -// pub const _SC_REALTIME_SIGNALS : ::c_int = 94; -pub const _SC_PHYS_PAGES: ::c_int = 121; -pub const _SC_NPROCESSORS_CONF: ::c_int = 1001; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 1002; -pub const _SC_SCHED_RT_TS: ::c_int = 2001; -pub const _SC_SCHED_PRI_MIN: ::c_int = 2002; -pub const _SC_SCHED_PRI_MAX: ::c_int = 2003; - -pub const FD_SETSIZE: usize = 0x100; - -pub const ST_NOSUID: ::c_ulong = 8; - -pub const BIOCGRSIG: ::c_ulong = 0x40044272; -pub const BIOCSRSIG: ::c_ulong = 0x80044273; -pub const BIOCSDLT: ::c_ulong = 0x80044278; -pub const BIOCGSEESENT: ::c_ulong = 0x40044276; -pub const BIOCSSEESENT: ::c_ulong = 0x80044277; - -cfg_if! { - if #[cfg(any(target_arch = "sparc", target_arch = "sparc64", - target_arch = "x86", target_arch = "x86_64"))] { - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t - = pthread_mutex_t { - ptm_magic: 0x33330003, - ptm_errorcheck: 0, - ptm_pad1: [0; 3], - ptm_unused: 0, - ptm_pad2: [0; 3], - ptm_waiters: 0 as *mut _, - ptm_owner: 0, - ptm_recursed: 0, - ptm_spare2: 0 as *mut _, - }; - } else { - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t - = pthread_mutex_t { - ptm_magic: 0x33330003, - ptm_errorcheck: 0, - ptm_unused: 0, - ptm_waiters: 0 as *mut _, - ptm_owner: 0, - ptm_recursed: 0, - ptm_spare2: 0 as *mut _, - }; - } -} - -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - ptc_magic: 0x55550005, - ptc_lock: 0, - ptc_waiters_first: 0 as *mut _, - ptc_waiters_last: 0 as *mut _, - ptc_mutex: 0 as *mut _, - ptc_private: 0 as *mut _, -}; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - ptr_magic: 0x99990009, - ptr_interlock: 0, - ptr_rblocked_first: 0 as *mut _, - ptr_rblocked_last: 0 as *mut _, - ptr_wblocked_first: 0 as *mut _, - ptr_wblocked_last: 0 as *mut _, - ptr_nreaders: 0, - ptr_owner: 0, - ptr_private: 0 as *mut _, -}; -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 1; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; - -pub const EVFILT_AIO: u32 = 2; -pub const EVFILT_PROC: u32 = 4; -pub const EVFILT_READ: u32 = 0; -pub const EVFILT_SIGNAL: u32 = 5; -pub const EVFILT_TIMER: u32 = 6; -pub const EVFILT_VNODE: u32 = 3; -pub const EVFILT_WRITE: u32 = 1; - -pub const EV_ADD: u32 = 0x1; -pub const EV_DELETE: u32 = 0x2; -pub const EV_ENABLE: u32 = 0x4; -pub const EV_DISABLE: u32 = 0x8; -pub const EV_ONESHOT: u32 = 0x10; -pub const EV_CLEAR: u32 = 0x20; -pub const EV_RECEIPT: u32 = 0x40; -pub const EV_DISPATCH: u32 = 0x80; -pub const EV_FLAG1: u32 = 0x2000; -pub const EV_ERROR: u32 = 0x4000; -pub const EV_EOF: u32 = 0x8000; -pub const EV_SYSFLAGS: u32 = 0xf000; - -pub const NOTE_LOWAT: u32 = 0x00000001; -pub const NOTE_DELETE: u32 = 0x00000001; -pub const NOTE_WRITE: u32 = 0x00000002; -pub const NOTE_EXTEND: u32 = 0x00000004; -pub const NOTE_ATTRIB: u32 = 0x00000008; -pub const NOTE_LINK: u32 = 0x00000010; -pub const NOTE_RENAME: u32 = 0x00000020; -pub const NOTE_REVOKE: u32 = 0x00000040; -pub const NOTE_EXIT: u32 = 0x80000000; -pub const NOTE_FORK: u32 = 0x40000000; -pub const NOTE_EXEC: u32 = 0x20000000; -pub const NOTE_PDATAMASK: u32 = 0x000fffff; -pub const NOTE_PCTRLMASK: u32 = 0xf0000000; -pub const NOTE_TRACK: u32 = 0x00000001; -pub const NOTE_TRACKERR: u32 = 0x00000002; -pub const NOTE_CHILD: u32 = 0x00000004; - -pub const TMP_MAX: ::c_uint = 308915776; - -pub const NI_MAXHOST: ::socklen_t = 1025; - -pub const RTLD_NOLOAD: ::c_int = 0x2000; -pub const RTLD_LOCAL: ::c_int = 0x200; - -pub const CTL_MAXNAME: ::c_int = 12; -pub const SYSCTL_NAMELEN: ::c_int = 32; -pub const SYSCTL_DEFSIZE: ::c_int = 8; -pub const CTLTYPE_NODE: ::c_int = 1; -pub const CTLTYPE_INT: ::c_int = 2; -pub const CTLTYPE_STRING: ::c_int = 3; -pub const CTLTYPE_QUAD: ::c_int = 4; -pub const CTLTYPE_STRUCT: ::c_int = 5; -pub const CTLTYPE_BOOL: ::c_int = 6; -pub const CTLFLAG_READONLY: ::c_int = 0x00000000; -pub const CTLFLAG_READWRITE: ::c_int = 0x00000070; -pub const CTLFLAG_ANYWRITE: ::c_int = 0x00000080; -pub const CTLFLAG_PRIVATE: ::c_int = 0x00000100; -pub const CTLFLAG_PERMANENT: ::c_int = 0x00000200; -pub const CTLFLAG_OWNDATA: ::c_int = 0x00000400; -pub const CTLFLAG_IMMEDIATE: ::c_int = 0x00000800; -pub const CTLFLAG_HEX: ::c_int = 0x00001000; -pub const CTLFLAG_ROOT: ::c_int = 0x00002000; -pub const CTLFLAG_ANYNUMBER: ::c_int = 0x00004000; -pub const CTLFLAG_HIDDEN: ::c_int = 0x00008000; -pub const CTLFLAG_ALIAS: ::c_int = 0x00010000; -pub const CTLFLAG_MMAP: ::c_int = 0x00020000; -pub const CTLFLAG_OWNDESC: ::c_int = 0x00040000; -pub const CTLFLAG_UNSIGNED: ::c_int = 0x00080000; -pub const SYSCTL_VERS_MASK: ::c_int = 0xff000000; -pub const SYSCTL_VERS_0: ::c_int = 0x00000000; -pub const SYSCTL_VERS_1: ::c_int = 0x01000000; -pub const SYSCTL_VERSION: ::c_int = SYSCTL_VERS_1; -pub const CTL_EOL: ::c_int = -1; -pub const CTL_QUERY: ::c_int = -2; -pub const CTL_CREATE: ::c_int = -3; -pub const CTL_CREATESYM: ::c_int = -4; -pub const CTL_DESTROY: ::c_int = -5; -pub const CTL_MMAP: ::c_int = -6; -pub const CTL_DESCRIBE: ::c_int = -7; -pub const CTL_UNSPEC: ::c_int = 0; -pub const CTL_KERN: ::c_int = 1; -pub const CTL_VM: ::c_int = 2; -pub const CTL_VFS: ::c_int = 3; -pub const CTL_NET: ::c_int = 4; -pub const CTL_DEBUG: ::c_int = 5; -pub const CTL_HW: ::c_int = 6; -pub const CTL_MACHDEP: ::c_int = 7; -pub const CTL_USER: ::c_int = 8; -pub const CTL_DDB: ::c_int = 9; -pub const CTL_PROC: ::c_int = 10; -pub const CTL_VENDOR: ::c_int = 11; -pub const CTL_EMUL: ::c_int = 12; -pub const CTL_SECURITY: ::c_int = 13; -pub const CTL_MAXID: ::c_int = 14; -pub const KERN_OSTYPE: ::c_int = 1; -pub const KERN_OSRELEASE: ::c_int = 2; -pub const KERN_OSREV: ::c_int = 3; -pub const KERN_VERSION: ::c_int = 4; -pub const KERN_MAXVNODES: ::c_int = 5; -pub const KERN_MAXPROC: ::c_int = 6; -pub const KERN_MAXFILES: ::c_int = 7; -pub const KERN_ARGMAX: ::c_int = 8; -pub const KERN_SECURELVL: ::c_int = 9; -pub const KERN_HOSTNAME: ::c_int = 10; -pub const KERN_HOSTID: ::c_int = 11; -pub const KERN_CLOCKRATE: ::c_int = 12; -pub const KERN_VNODE: ::c_int = 13; -pub const KERN_PROC: ::c_int = 14; -pub const KERN_FILE: ::c_int = 15; -pub const KERN_PROF: ::c_int = 16; -pub const KERN_POSIX1: ::c_int = 17; -pub const KERN_NGROUPS: ::c_int = 18; -pub const KERN_JOB_CONTROL: ::c_int = 19; -pub const KERN_SAVED_IDS: ::c_int = 20; -pub const KERN_OBOOTTIME: ::c_int = 21; -pub const KERN_DOMAINNAME: ::c_int = 22; -pub const KERN_MAXPARTITIONS: ::c_int = 23; -pub const KERN_RAWPARTITION: ::c_int = 24; -pub const KERN_NTPTIME: ::c_int = 25; -pub const KERN_TIMEX: ::c_int = 26; -pub const KERN_AUTONICETIME: ::c_int = 27; -pub const KERN_AUTONICEVAL: ::c_int = 28; -pub const KERN_RTC_OFFSET: ::c_int = 29; -pub const KERN_ROOT_DEVICE: ::c_int = 30; -pub const KERN_MSGBUFSIZE: ::c_int = 31; -pub const KERN_FSYNC: ::c_int = 32; -pub const KERN_OLDSYSVMSG: ::c_int = 33; -pub const KERN_OLDSYSVSEM: ::c_int = 34; -pub const KERN_OLDSYSVSHM: ::c_int = 35; -pub const KERN_OLDSHORTCORENAME: ::c_int = 36; -pub const KERN_SYNCHRONIZED_IO: ::c_int = 37; -pub const KERN_IOV_MAX: ::c_int = 38; -pub const KERN_MBUF: ::c_int = 39; -pub const KERN_MAPPED_FILES: ::c_int = 40; -pub const KERN_MEMLOCK: ::c_int = 41; -pub const KERN_MEMLOCK_RANGE: ::c_int = 42; -pub const KERN_MEMORY_PROTECTION: ::c_int = 43; -pub const KERN_LOGIN_NAME_MAX: ::c_int = 44; -pub const KERN_DEFCORENAME: ::c_int = 45; -pub const KERN_LOGSIGEXIT: ::c_int = 46; -pub const KERN_PROC2: ::c_int = 47; -pub const KERN_PROC_ARGS: ::c_int = 48; -pub const KERN_FSCALE: ::c_int = 49; -pub const KERN_CCPU: ::c_int = 50; -pub const KERN_CP_TIME: ::c_int = 51; -pub const KERN_OLDSYSVIPC_INFO: ::c_int = 52; -pub const KERN_MSGBUF: ::c_int = 53; -pub const KERN_CONSDEV: ::c_int = 54; -pub const KERN_MAXPTYS: ::c_int = 55; -pub const KERN_PIPE: ::c_int = 56; -pub const KERN_MAXPHYS: ::c_int = 57; -pub const KERN_SBMAX: ::c_int = 58; -pub const KERN_TKSTAT: ::c_int = 59; -pub const KERN_MONOTONIC_CLOCK: ::c_int = 60; -pub const KERN_URND: ::c_int = 61; -pub const KERN_LABELSECTOR: ::c_int = 62; -pub const KERN_LABELOFFSET: ::c_int = 63; -pub const KERN_LWP: ::c_int = 64; -pub const KERN_FORKFSLEEP: ::c_int = 65; -pub const KERN_POSIX_THREADS: ::c_int = 66; -pub const KERN_POSIX_SEMAPHORES: ::c_int = 67; -pub const KERN_POSIX_BARRIERS: ::c_int = 68; -pub const KERN_POSIX_TIMERS: ::c_int = 69; -pub const KERN_POSIX_SPIN_LOCKS: ::c_int = 70; -pub const KERN_POSIX_READER_WRITER_LOCKS: ::c_int = 71; -pub const KERN_DUMP_ON_PANIC: ::c_int = 72; -pub const KERN_SOMAXKVA: ::c_int = 73; -pub const KERN_ROOT_PARTITION: ::c_int = 74; -pub const KERN_DRIVERS: ::c_int = 75; -pub const KERN_BUF: ::c_int = 76; -pub const KERN_FILE2: ::c_int = 77; -pub const KERN_VERIEXEC: ::c_int = 78; -pub const KERN_CP_ID: ::c_int = 79; -pub const KERN_HARDCLOCK_TICKS: ::c_int = 80; -pub const KERN_ARND: ::c_int = 81; -pub const KERN_SYSVIPC: ::c_int = 82; -pub const KERN_BOOTTIME: ::c_int = 83; -pub const KERN_EVCNT: ::c_int = 84; -pub const KERN_MAXID: ::c_int = 85; -pub const KERN_PROC_ALL: ::c_int = 0; -pub const KERN_PROC_PID: ::c_int = 1; -pub const KERN_PROC_PGRP: ::c_int = 2; -pub const KERN_PROC_SESSION: ::c_int = 3; -pub const KERN_PROC_TTY: ::c_int = 4; -pub const KERN_PROC_UID: ::c_int = 5; -pub const KERN_PROC_RUID: ::c_int = 6; -pub const KERN_PROC_GID: ::c_int = 7; -pub const KERN_PROC_RGID: ::c_int = 8; -pub const KERN_PROC_ARGV: ::c_int = 1; -pub const KERN_PROC_NARGV: ::c_int = 2; -pub const KERN_PROC_ENV: ::c_int = 3; -pub const KERN_PROC_NENV: ::c_int = 4; -pub const KERN_PROC_PATHNAME: ::c_int = 5; - -pub const EAI_AGAIN: ::c_int = 2; -pub const EAI_BADFLAGS: ::c_int = 3; -pub const EAI_FAIL: ::c_int = 4; -pub const EAI_FAMILY: ::c_int = 5; -pub const EAI_MEMORY: ::c_int = 6; -pub const EAI_NODATA: ::c_int = 7; -pub const EAI_NONAME: ::c_int = 8; -pub const EAI_SERVICE: ::c_int = 9; -pub const EAI_SOCKTYPE: ::c_int = 10; -pub const EAI_SYSTEM: ::c_int = 11; -pub const EAI_OVERFLOW: ::c_int = 14; - -pub const AIO_CANCELED: ::c_int = 1; -pub const AIO_NOTCANCELED: ::c_int = 2; -pub const AIO_ALLDONE: ::c_int = 3; -pub const LIO_NOP: ::c_int = 0; -pub const LIO_WRITE: ::c_int = 1; -pub const LIO_READ: ::c_int = 2; -pub const LIO_WAIT: ::c_int = 1; -pub const LIO_NOWAIT: ::c_int = 0; - -pub const SIGEV_NONE: ::c_int = 0; -pub const SIGEV_SIGNAL: ::c_int = 1; -pub const SIGEV_THREAD: ::c_int = 2; - -pub const WSTOPPED: ::c_int = 0x00000002; // same as WUNTRACED -pub const WCONTINUED: ::c_int = 0x00000010; -pub const WEXITED: ::c_int = 0x000000020; -pub const WNOWAIT: ::c_int = 0x00010000; - -pub const P_ALL: idtype_t = 0; -pub const P_PID: idtype_t = 1; -pub const P_PGID: idtype_t = 4; - -pub const UTIME_OMIT: c_long = 1073741822; -pub const UTIME_NOW: c_long = 1073741823; - -pub const B460800: ::speed_t = 460800; -pub const B921600: ::speed_t = 921600; - -pub const ONOCR: ::tcflag_t = 0x20; -pub const ONLRET: ::tcflag_t = 0x40; -pub const CDTRCTS: ::tcflag_t = 0x00020000; -pub const CHWFLOW: ::tcflag_t = ::MDMBUF | ::CRTSCTS | ::CDTRCTS; - -// pub const _PATH_UTMPX: &[::c_char; 14] = b"/var/run/utmpx"; -// pub const _PATH_WTMPX: &[::c_char; 14] = b"/var/log/wtmpx"; -// pub const _PATH_LASTLOGX: &[::c_char; 17] = b"/var/log/lastlogx"; -// pub const _PATH_UTMP_UPDATE: &[::c_char; 24] = b"/usr/libexec/utmp_update"; -pub const UT_NAMESIZE: usize = 8; -pub const UT_LINESIZE: usize = 8; -pub const UT_HOSTSIZE: usize = 16; -pub const _UTX_USERSIZE: usize = 32; -pub const _UTX_LINESIZE: usize = 32; -pub const _UTX_PADSIZE: usize = 40; -pub const _UTX_IDSIZE: usize = 4; -pub const _UTX_HOSTSIZE: usize = 256; -pub const EMPTY: u16 = 0; -pub const RUN_LVL: u16 = 1; -pub const BOOT_TIME: u16 = 2; -pub const OLD_TIME: u16 = 3; -pub const NEW_TIME: u16 = 4; -pub const INIT_PROCESS: u16 = 5; -pub const LOGIN_PROCESS: u16 = 6; -pub const USER_PROCESS: u16 = 7; -pub const DEAD_PROCESS: u16 = 8; -pub const ACCOUNTING: u16 = 9; -pub const SIGNATURE: u16 = 10; -pub const DOWN_TIME: u16 = 11; - -pub const SOCK_CLOEXEC: ::c_int = 0x10000000; -pub const SOCK_NONBLOCK: ::c_int = 0x20000000; - -// Uncomment on next NetBSD release -// pub const FIOSEEKDATA: ::c_ulong = 0xc0086661; -// pub const FIOSEEKHOLE: ::c_ulong = 0xc0086662; -pub const OFIOGETBMAP: ::c_ulong = 0xc004667a; -pub const FIOGETBMAP: ::c_ulong = 0xc008667a; -pub const FIONWRITE: ::c_ulong = 0x40046679; -pub const FIONSPACE: ::c_ulong = 0x40046678; -pub const FIBMAP: ::c_ulong = 0xc008667a; - -pub const SIGSTKSZ: ::size_t = 40960; - -pub const PT_DUMPCORE: ::c_int = 12; -pub const PT_LWPINFO: ::c_int = 13; -pub const PT_SYSCALL: ::c_int = 14; -pub const PT_SYSCALLEMU: ::c_int = 15; -pub const PT_SET_EVENT_MASK: ::c_int = 16; -pub const PT_GET_EVENT_MASK: ::c_int = 17; -pub const PT_GET_PROCESS_STATE: ::c_int = 18; -pub const PT_FIRSTMACH: ::c_int = 32; - -// Flags for chflags(2) -pub const SF_SNAPSHOT: ::c_ulong = 0x00200000; -pub const SF_LOG: ::c_ulong = 0x00400000; -pub const SF_SNAPINVAL: ::c_ulong = 0x00800000; - -fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES -} - -f! { - pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { - (cmsg as *mut ::c_uchar) - .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) - -> *mut ::cmsghdr - { - if cmsg.is_null() { - return ::CMSG_FIRSTHDR(mhdr); - }; - let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) - + _ALIGN(::mem::size_of::<::cmsghdr>()); - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next > max { - 0 as *mut ::cmsghdr - } else { - (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) - as *mut ::cmsghdr - } - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) - as ::c_uint - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - status >> 8 - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - (status & 0o177) != 0o177 && (status & 0o177) != 0 - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0o177) == 0o177 - } - - // dirfd() is a macro on netbsd to access - // the first field of the struct where dirp points to: - // http://cvsweb.netbsd.org/bsdweb.cgi/src/include/dirent.h?rev=1.36 - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int { - *(dirp as *const ::c_int) - } - - pub fn WIFCONTINUED(status: ::c_int) -> bool { - status == 0xffff - } - - pub fn SOCKCREDSIZE(ngrps: usize) -> usize { - let ngrps = if ngrps > 0 { - ngrps - 1 - } else { - 0 - }; - ::mem::size_of::() + ::mem::size_of::<::gid_t>() * ngrps - } -} - -#[link(name = "rt")] -extern "C" { - pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_error(aiocbp: *const aiocb) -> ::c_int; - pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t; - #[link_name = "__aio_suspend50"] - pub fn aio_suspend( - aiocb_list: *const *const aiocb, - nitems: ::c_int, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn aio_cancel(fd: ::c_int, aiocbp: *mut aiocb) -> ::c_int; - pub fn lio_listio( - mode: ::c_int, - aiocb_list: *const *mut aiocb, - nitems: ::c_int, - sevp: *mut sigevent, - ) -> ::c_int; -} - -extern "C" { - pub fn chflags(path: *const ::c_char, flags: ::c_ulong) -> ::c_int; - pub fn fchflags(fd: ::c_int, flags: ::c_ulong) -> ::c_int; - pub fn lchflags(path: *const ::c_char, flags: ::c_ulong) -> ::c_int; - - pub fn extattr_delete_fd( - fd: ::c_int, - attrnamespace: ::c_int, - attrname: *const ::c_char, - ) -> ::c_int; - pub fn extattr_delete_file( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - ) -> ::c_int; - pub fn extattr_delete_link( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - ) -> ::c_int; - pub fn extattr_get_fd( - fd: ::c_int, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_get_file( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_get_link( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *mut ::c_void, - nbytes: ::size_t, - ) -> ::ssize_t; - pub fn extattr_namespace_to_string( - attrnamespace: ::c_int, - string: *mut *mut ::c_char, - ) -> ::c_int; - pub fn extattr_set_fd( - fd: ::c_int, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *const ::c_void, - nbytes: ::size_t, - ) -> ::c_int; - pub fn extattr_set_file( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *const ::c_void, - nbytes: ::size_t, - ) -> ::c_int; - pub fn extattr_set_link( - path: *const ::c_char, - attrnamespace: ::c_int, - attrname: *const ::c_char, - data: *const ::c_void, - nbytes: ::size_t, - ) -> ::c_int; - pub fn extattr_string_to_namespace( - string: *const ::c_char, - attrnamespace: *mut ::c_int, - ) -> ::c_int; - - #[link_name = "__lutimes50"] - pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; - #[link_name = "__gettimeofday50"] - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::socklen_t, - serv: *mut ::c_char, - sevlen: ::socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn sysctl( - name: *const ::c_int, - namelen: ::c_uint, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *const ::c_void, - newlen: ::size_t, - ) -> ::c_int; - pub fn sysctlbyname( - name: *const ::c_char, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *const ::c_void, - newlen: ::size_t, - ) -> ::c_int; - #[link_name = "__kevent50"] - pub fn kevent( - kq: ::c_int, - changelist: *const ::kevent, - nchanges: ::size_t, - eventlist: *mut ::kevent, - nevents: ::size_t, - timeout: *const ::timespec, - ) -> ::c_int; - #[link_name = "__mount50"] - pub fn mount( - src: *const ::c_char, - target: *const ::c_char, - flags: ::c_int, - data: *mut ::c_void, - size: ::size_t, - ) -> ::c_int; - pub fn mq_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::mqd_t; - pub fn mq_close(mqd: ::mqd_t) -> ::c_int; - pub fn mq_getattr(mqd: ::mqd_t, attr: *mut ::mq_attr) -> ::c_int; - pub fn mq_notify(mqd: ::mqd_t, notification: *const ::sigevent) - -> ::c_int; - pub fn mq_receive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - ) -> ::ssize_t; - pub fn mq_send( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - ) -> ::c_int; - pub fn mq_setattr( - mqd: ::mqd_t, - newattr: *const ::mq_attr, - oldattr: *mut ::mq_attr, - ) -> ::c_int; - #[link_name = "__mq_timedreceive50"] - pub fn mq_timedreceive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - abs_timeout: *const ::timespec, - ) -> ::ssize_t; - #[link_name = "__mq_timedsend50"] - pub fn mq_timedsend( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - abs_timeout: *const ::timespec, - ) -> ::c_int; - pub fn mq_unlink(name: *const ::c_char) -> ::c_int; - pub fn ptrace( - request: ::c_int, - pid: ::pid_t, - addr: *mut ::c_void, - data: ::c_int, - ) -> ::c_int; - pub fn pthread_setname_np( - t: ::pthread_t, - name: *const ::c_char, - arg: *const ::c_void, - ) -> ::c_int; - pub fn pthread_attr_get_np( - thread: ::pthread_t, - attr: *mut ::pthread_attr_t, - ) -> ::c_int; - pub fn pthread_getattr_np( - native: ::pthread_t, - attr: *mut ::pthread_attr_t, - ) -> ::c_int; - pub fn pthread_attr_getguardsize( - attr: *const ::pthread_attr_t, - guardsize: *mut ::size_t, - ) -> ::c_int; - pub fn pthread_attr_getstack( - attr: *const ::pthread_attr_t, - stackaddr: *mut *mut ::c_void, - stacksize: *mut ::size_t, - ) -> ::c_int; - #[link_name = "__sigtimedwait50"] - pub fn sigtimedwait( - set: *const sigset_t, - info: *mut siginfo_t, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> ::c_int; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn freelocale(loc: ::locale_t); - pub fn localeconv_l(loc: ::locale_t) -> *mut lconv; - pub fn newlocale( - mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t, - ) -> ::locale_t; - #[link_name = "__settimeofday50"] - pub fn settimeofday(tv: *const ::timeval, tz: *const ::c_void) -> ::c_int; - - pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int; - - pub fn sendmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - ) -> ::c_int; - pub fn recvmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - timeout: *mut ::timespec, - ) -> ::c_int; - - pub fn _lwp_self() -> lwpid_t; -} - -#[link(name = "util")] -extern "C" { - #[cfg_attr(target_os = "netbsd", link_name = "__getpwent_r50")] - pub fn getpwent_r( - pwd: *mut ::passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::passwd, - ) -> ::c_int; - pub fn getgrent_r( - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - - pub fn updwtmpx(file: *const ::c_char, ut: *const utmpx) -> ::c_int; - pub fn getlastlogx( - fname: *const ::c_char, - uid: ::uid_t, - ll: *mut lastlogx, - ) -> *mut lastlogx; - pub fn updlastlogx( - fname: *const ::c_char, - uid: ::uid_t, - ll: *mut lastlogx, - ) -> ::c_int; - pub fn utmpxname(file: *const ::c_char) -> ::c_int; - pub fn getutxent() -> *mut utmpx; - pub fn getutxid(ut: *const utmpx) -> *mut utmpx; - pub fn getutxline(ut: *const utmpx) -> *mut utmpx; - pub fn pututxline(ut: *const utmpx) -> *mut utmpx; - pub fn setutxent(); - pub fn endutxent(); - - pub fn getutmp(ux: *const utmpx, u: *mut utmp); - pub fn getutmpx(u: *const utmp, ux: *mut utmpx); - - pub fn utpname(file: *const ::c_char) -> ::c_int; - pub fn setutent(); - pub fn endutent(); - pub fn getutent() -> *mut utmp; -} - -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(target_arch = "arm")] { - mod arm; - pub use self::arm::*; - } else if #[cfg(target_arch = "powerpc")] { - mod powerpc; - pub use self::powerpc::*; - } else if #[cfg(target_arch = "sparc64")] { - mod sparc64; - pub use self::sparc64::*; - } else if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } else if #[cfg(target_arch = "x86")] { - mod x86; - pub use self::x86::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs b/libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs deleted file mode 100644 index e12fd5e..0000000 --- a/libc/src/unix/bsd/netbsdlike/netbsd/powerpc.rs +++ /dev/null @@ -1,21 +0,0 @@ -use PT_FIRSTMACH; - -pub type c_long = i32; -pub type c_ulong = u32; -pub type c_char = u8; -pub type __cpu_simple_lock_nv_t = ::c_int; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_double>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} - -pub const PT_STEP: ::c_int = PT_FIRSTMACH + 0; -pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; -pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 2; diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/sparc64.rs b/libc/src/unix/bsd/netbsdlike/netbsd/sparc64.rs deleted file mode 100644 index 6a86759..0000000 --- a/libc/src/unix/bsd/netbsdlike/netbsd/sparc64.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = i8; -pub type __cpu_simple_lock_nv_t = ::c_uchar; - -// should be pub(crate), but that requires Rust 1.18.0 -#[doc(hidden)] -pub const _ALIGNBYTES: usize = 0xf; diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/x86.rs b/libc/src/unix/bsd/netbsdlike/netbsd/x86.rs deleted file mode 100644 index daa89a1..0000000 --- a/libc/src/unix/bsd/netbsdlike/netbsd/x86.rs +++ /dev/null @@ -1,15 +0,0 @@ -pub type c_long = i32; -pub type c_ulong = u32; -pub type c_char = i8; -pub type __cpu_simple_lock_nv_t = ::c_uchar; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 4 - 1; - } -} diff --git a/libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs b/libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs deleted file mode 100644 index 0860d4f..0000000 --- a/libc/src/unix/bsd/netbsdlike/netbsd/x86_64.rs +++ /dev/null @@ -1,23 +0,0 @@ -use PT_FIRSTMACH; - -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = i8; -pub type __cpu_simple_lock_nv_t = ::c_uchar; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} - -pub const PT_STEP: ::c_int = PT_FIRSTMACH + 0; -pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; -pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 2; -pub const PT_GETFPREGS: ::c_int = PT_FIRSTMACH + 3; -pub const PT_SETFPREGS: ::c_int = PT_FIRSTMACH + 4; diff --git a/libc/src/unix/bsd/netbsdlike/openbsd/aarch64.rs b/libc/src/unix/bsd/netbsdlike/openbsd/aarch64.rs deleted file mode 100644 index 99350ec..0000000 --- a/libc/src/unix/bsd/netbsdlike/openbsd/aarch64.rs +++ /dev/null @@ -1,16 +0,0 @@ -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = u8; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} - -pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/libc/src/unix/bsd/netbsdlike/openbsd/mod.rs b/libc/src/unix/bsd/netbsdlike/openbsd/mod.rs deleted file mode 100644 index 89a3354..0000000 --- a/libc/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ /dev/null @@ -1,1509 +0,0 @@ -use unix::bsd::O_SYNC; - -pub type clock_t = i64; -pub type suseconds_t = ::c_long; -pub type dev_t = i32; -pub type sigset_t = ::c_uint; -pub type blksize_t = i32; -pub type fsblkcnt_t = u64; -pub type fsfilcnt_t = u64; -pub type pthread_attr_t = *mut ::c_void; -pub type pthread_mutex_t = *mut ::c_void; -pub type pthread_mutexattr_t = *mut ::c_void; -pub type pthread_cond_t = *mut ::c_void; -pub type pthread_condattr_t = *mut ::c_void; -pub type pthread_rwlock_t = *mut ::c_void; -pub type pthread_rwlockattr_t = *mut ::c_void; -pub type caddr_t = *mut ::c_char; - -s! { - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_matchc: ::size_t, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - pub gl_pathv: *mut *mut ::c_char, - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - __unused6: *mut ::c_void, - __unused7: *mut ::c_void, - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct ufs_args { - pub fspec: *mut ::c_char, - pub export_info: export_args, - } - - pub struct mfs_args { - pub fspec: *mut ::c_char, - pub export_info: export_args, - // https://github.com/openbsd/src/blob/master/sys/sys/types.h#L134 - pub base: *mut ::c_char, - pub size: ::c_ulong, - } - - pub struct iso_args { - pub fspec: *mut ::c_char, - pub export_info: export_args, - pub flags: ::c_int, - pub sess: ::c_int, - } - - pub struct nfs_args { - pub version: ::c_int, - pub addr: *mut ::sockaddr, - pub addrlen: ::c_int, - pub sotype: ::c_int, - pub proto: ::c_int, - pub fh: *mut ::c_uchar, - pub fhsize: ::c_int, - pub flags: ::c_int, - pub wsize: ::c_int, - pub rsize: ::c_int, - pub readdirsize: ::c_int, - pub timeo: ::c_int, - pub retrans: ::c_int, - pub maxgrouplist: ::c_int, - pub readahead: ::c_int, - pub leaseterm: ::c_int, - pub deadthresh: ::c_int, - pub hostname: *mut ::c_char, - pub acregmin: ::c_int, - pub acregmax: ::c_int, - pub acdirmin: ::c_int, - pub acdirmax: ::c_int, - } - - pub struct msdosfs_args { - pub fspec: *mut ::c_char, - pub export_info: export_args, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub mask: ::mode_t, - pub flags: ::c_int, - } - - pub struct ntfs_args { - pub fspec: *mut ::c_char, - pub export_info: export_args, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub mode: ::mode_t, - pub flag: ::c_ulong, - } - - pub struct udf_args { - pub fspec: *mut ::c_char, - pub lastblock: u32, - } - - pub struct tmpfs_args { - pub ta_version: ::c_int, - pub ta_nodes_max: ::ino_t, - pub ta_size_max: ::off_t, - pub ta_root_uid: ::uid_t, - pub ta_root_gid: ::gid_t, - pub ta_root_mode: ::mode_t, - } - - pub struct fusefs_args { - pub name: *mut ::c_char, - pub fd: ::c_int, - pub max_read: ::c_int, - pub allow_other: ::c_int, - } - - pub struct xucred { - pub cr_uid: ::uid_t, - pub cr_gid: ::gid_t, - pub cr_ngroups: ::c_short, - //https://github.com/openbsd/src/blob/master/sys/sys/syslimits.h#L44 - pub cr_groups: [::gid_t; 16], - } - - pub struct export_args { - pub ex_flags: ::c_int, - pub ex_root: ::uid_t, - pub ex_anon: xucred, - pub ex_addr: *mut ::sockaddr, - pub ex_addrlen: ::c_int, - pub ex_mask: *mut ::sockaddr, - pub ex_masklen: ::c_int, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [i8; 8], - } - - pub struct kevent { - pub ident: ::uintptr_t, - pub filter: ::c_short, - pub flags: ::c_ushort, - pub fflags: ::c_uint, - pub data: i64, - pub udata: *mut ::c_void, - } - - pub struct stat { - pub st_mode: ::mode_t, - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: u32, - pub st_gen: u32, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: ::socklen_t, - pub ai_addr: *mut ::sockaddr, - pub ai_canonname: *mut ::c_char, - pub ai_next: *mut ::addrinfo, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct if_data { - pub ifi_type: ::c_uchar, - pub ifi_addrlen: ::c_uchar, - pub ifi_hdrlen: ::c_uchar, - pub ifi_link_state: ::c_uchar, - pub ifi_mtu: u32, - pub ifi_metric: u32, - pub ifi_rdomain: u32, - pub ifi_baudrate: u64, - pub ifi_ipackets: u64, - pub ifi_ierrors: u64, - pub ifi_opackets: u64, - pub ifi_oerrors: u64, - pub ifi_collisions: u64, - pub ifi_ibytes: u64, - pub ifi_obytes: u64, - pub ifi_imcasts: u64, - pub ifi_omcasts: u64, - pub ifi_iqdrops: u64, - pub ifi_oqdrops: u64, - pub ifi_noproto: u64, - pub ifi_capabilities: u32, - pub ifi_lastchange: ::timeval, - } - - pub struct if_msghdr { - pub ifm_msglen: ::c_ushort, - pub ifm_version: ::c_uchar, - pub ifm_type: ::c_uchar, - pub ifm_hdrlen: ::c_ushort, - pub ifm_index: ::c_ushort, - pub ifm_tableid: ::c_ushort, - pub ifm_pad1: ::c_uchar, - pub ifm_pad2: ::c_uchar, - pub ifm_addrs: ::c_int, - pub ifm_flags: ::c_int, - pub ifm_xflags: ::c_int, - pub ifm_data: if_data, - } - - pub struct sockaddr_dl { - pub sdl_len: ::c_uchar, - pub sdl_family: ::c_uchar, - pub sdl_index: ::c_ushort, - pub sdl_type: ::c_uchar, - pub sdl_nlen: ::c_uchar, - pub sdl_alen: ::c_uchar, - pub sdl_slen: ::c_uchar, - pub sdl_data: [::c_char; 24], - } - - pub struct sockpeercred { - pub uid: ::uid_t, - pub gid: ::gid_t, - pub pid: ::pid_t, - } - - pub struct arphdr { - pub ar_hrd: u16, - pub ar_pro: u16, - pub ar_hln: u8, - pub ar_pln: u8, - pub ar_op: u16, - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::c_int, - pub shm_lpid: ::pid_t, - pub shm_cpid: ::pid_t, - pub shm_nattch: ::c_short, - pub shm_atime: ::time_t, - __shm_atimensec: c_long, - pub shm_dtime: ::time_t, - __shm_dtimensec: c_long, - pub shm_ctime: ::time_t, - __shm_ctimensec: c_long, - pub shm_internal: *mut ::c_void, - } -} - -impl siginfo_t { - pub unsafe fn si_value(&self) -> ::sigval { - #[repr(C)] - struct siginfo_timer { - _si_signo: ::c_int, - _si_errno: ::c_int, - _si_code: ::c_int, - _pid: ::pid_t, - _uid: ::uid_t, - value: ::sigval, - } - (*(self as *const siginfo_t as *const siginfo_timer)).value - } -} - -s_no_extra_traits! { - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: u16, - pub d_type: u8, - pub d_namlen: u8, - __d_padding: [u8; 4], - pub d_name: [::c_char; 256], - } - - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_pad2: i64, - __ss_pad3: [u8; 240], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub si_addr: *mut ::c_char, - #[cfg(target_pointer_width = "32")] - __pad: [u8; 112], - #[cfg(target_pointer_width = "64")] - __pad: [u8; 108], - } - - pub struct lastlog { - ll_time: ::time_t, - ll_line: [::c_char; UT_LINESIZE], - ll_host: [::c_char; UT_HOSTSIZE], - } - - pub struct utmp { - pub ut_line: [::c_char; UT_LINESIZE], - pub ut_name: [::c_char; UT_NAMESIZE], - pub ut_host: [::c_char; UT_HOSTSIZE], - pub ut_time: ::time_t, - } - - pub union mount_info { - pub ufs_args: ufs_args, - pub mfs_args: mfs_args, - pub nfs_args: nfs_args, - pub iso_args: iso_args, - pub msdosfs_args: msdosfs_args, - pub ntfs_args: ntfs_args, - pub tmpfs_args: tmpfs_args, - align: [::c_char; 160], - } - -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_fileno == other.d_fileno - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self.d_namlen == other.d_namlen - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for dirent {} - - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_fileno", &self.d_fileno) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - .field("d_namlen", &self.d_namlen) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_fileno.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_namlen.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_len == other.ss_len - && self.ss_family == other.ss_family - } - } - - impl Eq for sockaddr_storage {} - - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_len", &self.ss_len) - .field("ss_family", &self.ss_family) - .finish() - } - } - - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_len.hash(state); - self.ss_family.hash(state); - } - } - - impl PartialEq for siginfo_t { - fn eq(&self, other: &siginfo_t) -> bool { - self.si_signo == other.si_signo - && self.si_code == other.si_code - && self.si_errno == other.si_errno - && self.si_addr == other.si_addr - } - } - - impl Eq for siginfo_t {} - - impl ::fmt::Debug for siginfo_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("siginfo_t") - .field("si_signo", &self.si_signo) - .field("si_code", &self.si_code) - .field("si_errno", &self.si_errno) - .field("si_addr", &self.si_addr) - .finish() - } - } - - impl ::hash::Hash for siginfo_t { - fn hash(&self, state: &mut H) { - self.si_signo.hash(state); - self.si_code.hash(state); - self.si_errno.hash(state); - self.si_addr.hash(state); - } - } - - impl PartialEq for lastlog { - fn eq(&self, other: &lastlog) -> bool { - self.ll_time == other.ll_time - && self - .ll_line - .iter() - .zip(other.ll_line.iter()) - .all(|(a,b)| a == b) - && self - .ll_host - .iter() - .zip(other.ll_host.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for lastlog {} - - impl ::fmt::Debug for lastlog { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("lastlog") - .field("ll_time", &self.ll_time) - // FIXME: .field("ll_line", &self.ll_line) - // FIXME: .field("ll_host", &self.ll_host) - .finish() - } - } - - impl ::hash::Hash for lastlog { - fn hash(&self, state: &mut H) { - self.ll_time.hash(state); - self.ll_line.hash(state); - self.ll_host.hash(state); - } - } - - impl PartialEq for utmp { - fn eq(&self, other: &utmp) -> bool { - self.ut_time == other.ut_time - && self - .ut_line - .iter() - .zip(other.ut_line.iter()) - .all(|(a,b)| a == b) - && self - .ut_name - .iter() - .zip(other.ut_name.iter()) - .all(|(a,b)| a == b) - && self - .ut_host - .iter() - .zip(other.ut_host.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for utmp {} - - impl ::fmt::Debug for utmp { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utmp") - // FIXME: .field("ut_line", &self.ut_line) - // FIXME: .field("ut_name", &self.ut_name) - // FIXME: .field("ut_host", &self.ut_host) - .field("ut_time", &self.ut_time) - .finish() - } - } - - impl ::hash::Hash for utmp { - fn hash(&self, state: &mut H) { - self.ut_line.hash(state); - self.ut_name.hash(state); - self.ut_host.hash(state); - self.ut_time.hash(state); - } - } - - impl PartialEq for mount_info { - fn eq(&self, other: &mount_info) -> bool { - unsafe { - self.align - .iter() - .zip(other.align.iter()) - .all(|(a,b)| a == b) - } - } - } - - impl Eq for mount_info { } - - impl ::fmt::Debug for mount_info { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("mount_info") - // FIXME: .field("align", &self.align) - .finish() - } - } - - impl ::hash::Hash for mount_info { - fn hash(&self, state: &mut H) { - unsafe { self.align.hash(state) }; - } - } - } -} - -cfg_if! { - if #[cfg(libc_union)] { - s_no_extra_traits! { - // This type uses the union mount_info: - pub struct statfs { - pub f_flags: u32, - pub f_bsize: u32, - pub f_iosize: u32, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: i64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: i64, - pub f_syncwrites: u64, - pub f_syncreads: u64, - pub f_asyncwrites: u64, - pub f_asyncreads: u64, - pub f_fsid: ::fsid_t, - pub f_namemax: u32, - pub f_owner: ::uid_t, - pub f_ctime: u64, - pub f_fstypename: [::c_char; 16], - pub f_mntonname: [::c_char; 90], - pub f_mntfromname: [::c_char; 90], - pub f_mntfromspec: [::c_char; 90], - pub mount_info: mount_info, - } - } - - cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for statfs { - fn eq(&self, other: &statfs) -> bool { - self.f_flags == other.f_flags - && self.f_bsize == other.f_bsize - && self.f_iosize == other.f_iosize - && self.f_blocks == other.f_blocks - && self.f_bfree == other.f_bfree - && self.f_bavail == other.f_bavail - && self.f_files == other.f_files - && self.f_ffree == other.f_ffree - && self.f_favail == other.f_favail - && self.f_syncwrites == other.f_syncwrites - && self.f_syncreads == other.f_syncreads - && self.f_asyncwrites == other.f_asyncwrites - && self.f_asyncreads == other.f_asyncreads - && self.f_fsid == other.f_fsid - && self.f_namemax == other.f_namemax - && self.f_owner == other.f_owner - && self.f_ctime == other.f_ctime - && self.f_fstypename - .iter() - .zip(other.f_fstypename.iter()) - .all(|(a,b)| a == b) - && self.f_mntonname - .iter() - .zip(other.f_mntonname.iter()) - .all(|(a,b)| a == b) - && self.f_mntfromname - .iter() - .zip(other.f_mntfromname.iter()) - .all(|(a,b)| a == b) - && self.f_mntfromspec - .iter() - .zip(other.f_mntfromspec.iter()) - .all(|(a,b)| a == b) - && self.mount_info == other.mount_info - } - } - - impl Eq for statfs { } - - impl ::fmt::Debug for statfs { - fn fmt(&self, f: &mut ::fmt::Formatter) - -> ::fmt::Result { - f.debug_struct("statfs") - .field("f_flags", &self.f_flags) - .field("f_bsize", &self.f_bsize) - .field("f_iosize", &self.f_iosize) - .field("f_blocks", &self.f_blocks) - .field("f_bfree", &self.f_bfree) - .field("f_bavail", &self.f_bavail) - .field("f_files", &self.f_files) - .field("f_ffree", &self.f_ffree) - .field("f_favail", &self.f_favail) - .field("f_syncwrites", &self.f_syncwrites) - .field("f_syncreads", &self.f_syncreads) - .field("f_asyncwrites", &self.f_asyncwrites) - .field("f_asyncreads", &self.f_asyncreads) - .field("f_fsid", &self.f_fsid) - .field("f_namemax", &self.f_namemax) - .field("f_owner", &self.f_owner) - .field("f_ctime", &self.f_ctime) - // FIXME: .field("f_fstypename", &self.f_fstypename) - // FIXME: .field("f_mntonname", &self.f_mntonname) - // FIXME: .field("f_mntfromname", &self.f_mntfromname) - // FIXME: .field("f_mntfromspec", &self.f_mntfromspec) - .field("mount_info", &self.mount_info) - .finish() - } - } - - impl ::hash::Hash for statfs { - fn hash(&self, state: &mut H) { - self.f_flags.hash(state); - self.f_bsize.hash(state); - self.f_iosize.hash(state); - self.f_blocks.hash(state); - self.f_bfree.hash(state); - self.f_bavail.hash(state); - self.f_files.hash(state); - self.f_ffree.hash(state); - self.f_favail.hash(state); - self.f_syncwrites.hash(state); - self.f_syncreads.hash(state); - self.f_asyncwrites.hash(state); - self.f_asyncreads.hash(state); - self.f_fsid.hash(state); - self.f_namemax.hash(state); - self.f_owner.hash(state); - self.f_ctime.hash(state); - self.f_fstypename.hash(state); - self.f_mntonname.hash(state); - self.f_mntfromname.hash(state); - self.f_mntfromspec.hash(state); - self.mount_info.hash(state); - } - } - } - } - } -} - -pub const UT_NAMESIZE: usize = 32; -pub const UT_LINESIZE: usize = 8; -pub const UT_HOSTSIZE: usize = 256; - -pub const O_CLOEXEC: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x20000; -pub const O_RSYNC: ::c_int = O_SYNC; - -pub const MS_SYNC: ::c_int = 0x0002; -pub const MS_INVALIDATE: ::c_int = 0x0004; - -pub const POLLNORM: ::c_short = ::POLLRDNORM; - -pub const ENOATTR: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const EOVERFLOW: ::c_int = 87; -pub const ECANCELED: ::c_int = 88; -pub const EIDRM: ::c_int = 89; -pub const ENOMSG: ::c_int = 90; -pub const ENOTSUP: ::c_int = 91; -pub const EBADMSG: ::c_int = 92; -pub const ENOTRECOVERABLE: ::c_int = 93; -pub const EOWNERDEAD: ::c_int = 94; -pub const EPROTO: ::c_int = 95; -pub const ELAST: ::c_int = 95; - -pub const F_DUPFD_CLOEXEC: ::c_int = 10; - -pub const UTIME_OMIT: c_long = -1; -pub const UTIME_NOW: c_long = -2; - -pub const AT_FDCWD: ::c_int = -100; -pub const AT_EACCESS: ::c_int = 0x01; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x02; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x04; -pub const AT_REMOVEDIR: ::c_int = 0x08; - -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] -pub const RLIM_NLIMITS: ::c_int = 9; - -pub const SO_TIMESTAMP: ::c_int = 0x0800; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_BINDANY: ::c_int = 0x1000; -pub const SO_NETPROC: ::c_int = 0x1020; -pub const SO_RTABLE: ::c_int = 0x1021; -pub const SO_PEERCRED: ::c_int = 0x1022; -pub const SO_SPLICE: ::c_int = 0x1023; - -// sys/netinet/in.h -// Protocols (RFC 1700) -// NOTE: These are in addition to the constants defined in src/unix/mod.rs - -// IPPROTO_IP defined in src/unix/mod.rs -/// Hop-by-hop option header -pub const IPPROTO_HOPOPTS: ::c_int = 0; -// IPPROTO_ICMP defined in src/unix/mod.rs -/// group mgmt protocol -pub const IPPROTO_IGMP: ::c_int = 2; -/// gateway^2 (deprecated) -pub const IPPROTO_GGP: ::c_int = 3; -/// for compatibility -pub const IPPROTO_IPIP: ::c_int = 4; -// IPPROTO_TCP defined in src/unix/mod.rs -/// exterior gateway protocol -pub const IPPROTO_EGP: ::c_int = 8; -/// pup -pub const IPPROTO_PUP: ::c_int = 12; -// IPPROTO_UDP defined in src/unix/mod.rs -/// xns idp -pub const IPPROTO_IDP: ::c_int = 22; -/// tp-4 w/ class negotiation -pub const IPPROTO_TP: ::c_int = 29; -// IPPROTO_IPV6 defined in src/unix/mod.rs -/// IP6 routing header -pub const IPPROTO_ROUTING: ::c_int = 43; -/// IP6 fragmentation header -pub const IPPROTO_FRAGMENT: ::c_int = 44; -/// resource reservation -pub const IPPROTO_RSVP: ::c_int = 46; -/// General Routing Encap. -pub const IPPROTO_GRE: ::c_int = 47; -/// IP6 Encap Sec. Payload -pub const IPPROTO_ESP: ::c_int = 50; -/// IP6 Auth Header -pub const IPPROTO_AH: ::c_int = 51; -/// IP Mobility RFC 2004 -pub const IPPROTO_MOBILE: ::c_int = 55; -// IPPROTO_ICMPV6 defined in src/unix/mod.rs -/// IP6 no next header -pub const IPPROTO_NONE: ::c_int = 59; -/// IP6 destination option -pub const IPPROTO_DSTOPTS: ::c_int = 60; -/// ISO cnlp -pub const IPPROTO_EON: ::c_int = 80; -/// Ethernet-in-IP -pub const IPPROTO_ETHERIP: ::c_int = 97; -/// encapsulation header -pub const IPPROTO_ENCAP: ::c_int = 98; -/// Protocol indep. multicast -pub const IPPROTO_PIM: ::c_int = 103; -/// IP Payload Comp. Protocol -pub const IPPROTO_IPCOMP: ::c_int = 108; -/// CARP -pub const IPPROTO_CARP: ::c_int = 112; -/// unicast MPLS packet -pub const IPPROTO_MPLS: ::c_int = 137; -/// PFSYNC -pub const IPPROTO_PFSYNC: ::c_int = 240; -pub const IPPROTO_MAX: ::c_int = 256; - -// Only used internally, so it can be outside the range of valid IP protocols -pub const IPPROTO_DIVERT: ::c_int = 258; - -pub const IP_RECVDSTADDR: ::c_int = 7; -pub const IP_SENDSRCADDR: ::c_int = IP_RECVDSTADDR; -pub const IP_RECVIF: ::c_int = 30; - -// sys/netinet/in.h -pub const TCP_MD5SIG: ::c_int = 0x04; -pub const TCP_NOPUSH: ::c_int = 0x10; - -pub const AF_ECMA: ::c_int = 8; -pub const AF_ROUTE: ::c_int = 17; -pub const AF_ENCAP: ::c_int = 28; -pub const AF_SIP: ::c_int = 29; -pub const AF_KEY: ::c_int = 30; -pub const pseudo_AF_HDRCMPLT: ::c_int = 31; -pub const AF_BLUETOOTH: ::c_int = 32; -pub const AF_MPLS: ::c_int = 33; -pub const pseudo_AF_PFLOW: ::c_int = 34; -pub const pseudo_AF_PIPEX: ::c_int = 35; -pub const NET_RT_DUMP: ::c_int = 1; -pub const NET_RT_FLAGS: ::c_int = 2; -pub const NET_RT_IFLIST: ::c_int = 3; -pub const NET_RT_STATS: ::c_int = 4; -pub const NET_RT_TABLE: ::c_int = 5; -pub const NET_RT_IFNAMES: ::c_int = 6; -#[doc(hidden)] -pub const NET_RT_MAXID: ::c_int = 7; - -pub const IPV6_JOIN_GROUP: ::c_int = 12; -pub const IPV6_LEAVE_GROUP: ::c_int = 13; - -pub const PF_ROUTE: ::c_int = AF_ROUTE; -pub const PF_ECMA: ::c_int = AF_ECMA; -pub const PF_ENCAP: ::c_int = AF_ENCAP; -pub const PF_SIP: ::c_int = AF_SIP; -pub const PF_KEY: ::c_int = AF_KEY; -pub const PF_BPF: ::c_int = pseudo_AF_HDRCMPLT; -pub const PF_BLUETOOTH: ::c_int = AF_BLUETOOTH; -pub const PF_MPLS: ::c_int = AF_MPLS; -pub const PF_PFLOW: ::c_int = pseudo_AF_PFLOW; -pub const PF_PIPEX: ::c_int = pseudo_AF_PIPEX; - -pub const SCM_TIMESTAMP: ::c_int = 0x04; - -pub const O_DSYNC: ::c_int = 128; - -pub const MAP_RENAME: ::c_int = 0x0000; -pub const MAP_NORESERVE: ::c_int = 0x0000; -pub const MAP_HASSEMAPHORE: ::c_int = 0x0000; - -pub const EIPSEC: ::c_int = 82; -pub const ENOMEDIUM: ::c_int = 85; -pub const EMEDIUMTYPE: ::c_int = 86; - -pub const EAI_BADFLAGS: ::c_int = -1; -pub const EAI_NONAME: ::c_int = -2; -pub const EAI_AGAIN: ::c_int = -3; -pub const EAI_FAIL: ::c_int = -4; -pub const EAI_NODATA: ::c_int = -5; -pub const EAI_FAMILY: ::c_int = -6; -pub const EAI_SOCKTYPE: ::c_int = -7; -pub const EAI_SERVICE: ::c_int = -8; -pub const EAI_MEMORY: ::c_int = -10; -pub const EAI_SYSTEM: ::c_int = -11; -pub const EAI_OVERFLOW: ::c_int = -14; - -pub const RUSAGE_THREAD: ::c_int = 1; - -pub const MAP_COPY: ::c_int = 0x0002; -pub const MAP_NOEXTEND: ::c_int = 0x0000; - -pub const _PC_LINK_MAX: ::c_int = 1; -pub const _PC_MAX_CANON: ::c_int = 2; -pub const _PC_MAX_INPUT: ::c_int = 3; -pub const _PC_NAME_MAX: ::c_int = 4; -pub const _PC_PATH_MAX: ::c_int = 5; -pub const _PC_PIPE_BUF: ::c_int = 6; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 7; -pub const _PC_NO_TRUNC: ::c_int = 8; -pub const _PC_VDISABLE: ::c_int = 9; -pub const _PC_2_SYMLINKS: ::c_int = 10; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 11; -pub const _PC_ASYNC_IO: ::c_int = 12; -pub const _PC_FILESIZEBITS: ::c_int = 13; -pub const _PC_PRIO_IO: ::c_int = 14; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 15; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 16; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 17; -pub const _PC_REC_XFER_ALIGN: ::c_int = 18; -pub const _PC_SYMLINK_MAX: ::c_int = 19; -pub const _PC_SYNC_IO: ::c_int = 20; -pub const _PC_TIMESTAMP_RESOLUTION: ::c_int = 21; - -pub const _SC_CLK_TCK: ::c_int = 3; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 31; -pub const _SC_SEM_VALUE_MAX: ::c_int = 32; -pub const _SC_HOST_NAME_MAX: ::c_int = 33; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 34; -pub const _SC_2_PBS: ::c_int = 35; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 36; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 37; -pub const _SC_2_PBS_LOCATE: ::c_int = 38; -pub const _SC_2_PBS_MESSAGE: ::c_int = 39; -pub const _SC_2_PBS_TRACK: ::c_int = 40; -pub const _SC_ADVISORY_INFO: ::c_int = 41; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 42; -pub const _SC_AIO_MAX: ::c_int = 43; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 44; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 45; -pub const _SC_ATEXIT_MAX: ::c_int = 46; -pub const _SC_BARRIERS: ::c_int = 47; -pub const _SC_CLOCK_SELECTION: ::c_int = 48; -pub const _SC_CPUTIME: ::c_int = 49; -pub const _SC_DELAYTIMER_MAX: ::c_int = 50; -pub const _SC_IOV_MAX: ::c_int = 51; -pub const _SC_IPV6: ::c_int = 52; -pub const _SC_MAPPED_FILES: ::c_int = 53; -pub const _SC_MEMLOCK: ::c_int = 54; -pub const _SC_MEMLOCK_RANGE: ::c_int = 55; -pub const _SC_MEMORY_PROTECTION: ::c_int = 56; -pub const _SC_MESSAGE_PASSING: ::c_int = 57; -pub const _SC_MQ_OPEN_MAX: ::c_int = 58; -pub const _SC_MQ_PRIO_MAX: ::c_int = 59; -pub const _SC_PRIORITIZED_IO: ::c_int = 60; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 61; -pub const _SC_RAW_SOCKETS: ::c_int = 62; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 63; -pub const _SC_REALTIME_SIGNALS: ::c_int = 64; -pub const _SC_REGEXP: ::c_int = 65; -pub const _SC_RTSIG_MAX: ::c_int = 66; -pub const _SC_SEMAPHORES: ::c_int = 67; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 68; -pub const _SC_SHELL: ::c_int = 69; -pub const _SC_SIGQUEUE_MAX: ::c_int = 70; -pub const _SC_SPAWN: ::c_int = 71; -pub const _SC_SPIN_LOCKS: ::c_int = 72; -pub const _SC_SPORADIC_SERVER: ::c_int = 73; -pub const _SC_SS_REPL_MAX: ::c_int = 74; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 75; -pub const _SC_SYMLOOP_MAX: ::c_int = 76; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 77; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 78; -pub const _SC_THREAD_CPUTIME: ::c_int = 79; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 80; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 81; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 82; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 83; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 84; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 85; -pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 86; -pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 87; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 88; -pub const _SC_THREAD_STACK_MIN: ::c_int = 89; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 90; -pub const _SC_THREADS: ::c_int = 91; -pub const _SC_TIMEOUTS: ::c_int = 92; -pub const _SC_TIMER_MAX: ::c_int = 93; -pub const _SC_TIMERS: ::c_int = 94; -pub const _SC_TRACE: ::c_int = 95; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 96; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 97; -pub const _SC_TRACE_INHERIT: ::c_int = 98; -pub const _SC_TRACE_LOG: ::c_int = 99; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 100; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 101; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 102; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 103; -pub const _SC_TRACE_NAME_MAX: ::c_int = 104; -pub const _SC_TRACE_SYS_MAX: ::c_int = 105; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 106; -pub const _SC_TTY_NAME_MAX: ::c_int = 107; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 108; -pub const _SC_V6_ILP32_OFF32: ::c_int = 109; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 110; -pub const _SC_V6_LP64_OFF64: ::c_int = 111; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 112; -pub const _SC_V7_ILP32_OFF32: ::c_int = 113; -pub const _SC_V7_ILP32_OFFBIG: ::c_int = 114; -pub const _SC_V7_LP64_OFF64: ::c_int = 115; -pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 116; -pub const _SC_XOPEN_CRYPT: ::c_int = 117; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 118; -pub const _SC_XOPEN_LEGACY: ::c_int = 119; -pub const _SC_XOPEN_REALTIME: ::c_int = 120; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 121; -pub const _SC_XOPEN_STREAMS: ::c_int = 122; -pub const _SC_XOPEN_UNIX: ::c_int = 123; -pub const _SC_XOPEN_UUCP: ::c_int = 124; -pub const _SC_XOPEN_VERSION: ::c_int = 125; -pub const _SC_PHYS_PAGES: ::c_int = 500; -pub const _SC_AVPHYS_PAGES: ::c_int = 501; -pub const _SC_NPROCESSORS_CONF: ::c_int = 502; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 503; - -pub const FD_SETSIZE: usize = 1024; - -pub const ST_NOSUID: ::c_ulong = 2; - -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0 as *mut _; -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _; - -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 1; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2; -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 3; -pub const PTHREAD_MUTEX_STRICT_NP: ::c_int = 4; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_STRICT_NP; - -pub const EVFILT_AIO: i16 = -3; -pub const EVFILT_PROC: i16 = -5; -pub const EVFILT_READ: i16 = -1; -pub const EVFILT_SIGNAL: i16 = -6; -pub const EVFILT_TIMER: i16 = -7; -pub const EVFILT_VNODE: i16 = -4; -pub const EVFILT_WRITE: i16 = -2; - -pub const EV_ADD: u16 = 0x1; -pub const EV_DELETE: u16 = 0x2; -pub const EV_ENABLE: u16 = 0x4; -pub const EV_DISABLE: u16 = 0x8; -pub const EV_ONESHOT: u16 = 0x10; -pub const EV_CLEAR: u16 = 0x20; -pub const EV_RECEIPT: u16 = 0x40; -pub const EV_DISPATCH: u16 = 0x80; -pub const EV_FLAG1: u16 = 0x2000; -pub const EV_ERROR: u16 = 0x4000; -pub const EV_EOF: u16 = 0x8000; -pub const EV_SYSFLAGS: u16 = 0xf000; - -pub const NOTE_LOWAT: u32 = 0x00000001; -pub const NOTE_EOF: u32 = 0x00000002; -pub const NOTE_DELETE: u32 = 0x00000001; -pub const NOTE_WRITE: u32 = 0x00000002; -pub const NOTE_EXTEND: u32 = 0x00000004; -pub const NOTE_ATTRIB: u32 = 0x00000008; -pub const NOTE_LINK: u32 = 0x00000010; -pub const NOTE_RENAME: u32 = 0x00000020; -pub const NOTE_REVOKE: u32 = 0x00000040; -pub const NOTE_TRUNCATE: u32 = 0x00000080; -pub const NOTE_EXIT: u32 = 0x80000000; -pub const NOTE_FORK: u32 = 0x40000000; -pub const NOTE_EXEC: u32 = 0x20000000; -pub const NOTE_PDATAMASK: u32 = 0x000fffff; -pub const NOTE_PCTRLMASK: u32 = 0xf0000000; -pub const NOTE_TRACK: u32 = 0x00000001; -pub const NOTE_TRACKERR: u32 = 0x00000002; -pub const NOTE_CHILD: u32 = 0x00000004; - -pub const TMP_MAX: ::c_uint = 0x7fffffff; - -pub const NI_MAXHOST: ::size_t = 256; - -pub const RTLD_LOCAL: ::c_int = 0; - -pub const CTL_MAXNAME: ::c_int = 12; - -pub const CTLTYPE_NODE: ::c_int = 1; -pub const CTLTYPE_INT: ::c_int = 2; -pub const CTLTYPE_STRING: ::c_int = 3; -pub const CTLTYPE_QUAD: ::c_int = 4; -pub const CTLTYPE_STRUCT: ::c_int = 5; - -pub const CTL_UNSPEC: ::c_int = 0; -pub const CTL_KERN: ::c_int = 1; -pub const CTL_VM: ::c_int = 2; -pub const CTL_FS: ::c_int = 3; -pub const CTL_NET: ::c_int = 4; -pub const CTL_DEBUG: ::c_int = 5; -pub const CTL_HW: ::c_int = 6; -pub const CTL_MACHDEP: ::c_int = 7; -pub const CTL_DDB: ::c_int = 9; -pub const CTL_VFS: ::c_int = 10; -pub const CTL_MAXID: ::c_int = 11; - -pub const HW_NCPUONLINE: ::c_int = 25; - -pub const KERN_OSTYPE: ::c_int = 1; -pub const KERN_OSRELEASE: ::c_int = 2; -pub const KERN_OSREV: ::c_int = 3; -pub const KERN_VERSION: ::c_int = 4; -pub const KERN_MAXVNODES: ::c_int = 5; -pub const KERN_MAXPROC: ::c_int = 6; -pub const KERN_MAXFILES: ::c_int = 7; -pub const KERN_ARGMAX: ::c_int = 8; -pub const KERN_SECURELVL: ::c_int = 9; -pub const KERN_HOSTNAME: ::c_int = 10; -pub const KERN_HOSTID: ::c_int = 11; -pub const KERN_CLOCKRATE: ::c_int = 12; -pub const KERN_PROF: ::c_int = 16; -pub const KERN_POSIX1: ::c_int = 17; -pub const KERN_NGROUPS: ::c_int = 18; -pub const KERN_JOB_CONTROL: ::c_int = 19; -pub const KERN_SAVED_IDS: ::c_int = 20; -pub const KERN_BOOTTIME: ::c_int = 21; -pub const KERN_DOMAINNAME: ::c_int = 22; -pub const KERN_MAXPARTITIONS: ::c_int = 23; -pub const KERN_RAWPARTITION: ::c_int = 24; -pub const KERN_MAXTHREAD: ::c_int = 25; -pub const KERN_NTHREADS: ::c_int = 26; -pub const KERN_OSVERSION: ::c_int = 27; -pub const KERN_SOMAXCONN: ::c_int = 28; -pub const KERN_SOMINCONN: ::c_int = 29; -pub const KERN_USERMOUNT: ::c_int = 30; -pub const KERN_NOSUIDCOREDUMP: ::c_int = 32; -pub const KERN_FSYNC: ::c_int = 33; -pub const KERN_SYSVMSG: ::c_int = 34; -pub const KERN_SYSVSEM: ::c_int = 35; -pub const KERN_SYSVSHM: ::c_int = 36; -pub const KERN_ARND: ::c_int = 37; -pub const KERN_MSGBUFSIZE: ::c_int = 38; -pub const KERN_MALLOCSTATS: ::c_int = 39; -pub const KERN_CPTIME: ::c_int = 40; -pub const KERN_NCHSTATS: ::c_int = 41; -pub const KERN_FORKSTAT: ::c_int = 42; -pub const KERN_NSELCOLL: ::c_int = 43; -pub const KERN_TTY: ::c_int = 44; -pub const KERN_CCPU: ::c_int = 45; -pub const KERN_FSCALE: ::c_int = 46; -pub const KERN_NPROCS: ::c_int = 47; -pub const KERN_MSGBUF: ::c_int = 48; -pub const KERN_POOL: ::c_int = 49; -pub const KERN_STACKGAPRANDOM: ::c_int = 50; -pub const KERN_SYSVIPC_INFO: ::c_int = 51; -pub const KERN_SPLASSERT: ::c_int = 54; -pub const KERN_PROC_ARGS: ::c_int = 55; -pub const KERN_NFILES: ::c_int = 56; -pub const KERN_TTYCOUNT: ::c_int = 57; -pub const KERN_NUMVNODES: ::c_int = 58; -pub const KERN_MBSTAT: ::c_int = 59; -pub const KERN_SEMINFO: ::c_int = 61; -pub const KERN_SHMINFO: ::c_int = 62; -pub const KERN_INTRCNT: ::c_int = 63; -pub const KERN_WATCHDOG: ::c_int = 64; -pub const KERN_PROC: ::c_int = 66; -pub const KERN_MAXCLUSTERS: ::c_int = 67; -pub const KERN_EVCOUNT: ::c_int = 68; -pub const KERN_TIMECOUNTER: ::c_int = 69; -pub const KERN_MAXLOCKSPERUID: ::c_int = 70; -pub const KERN_CPTIME2: ::c_int = 71; -pub const KERN_CACHEPCT: ::c_int = 72; -pub const KERN_FILE: ::c_int = 73; -pub const KERN_CONSDEV: ::c_int = 75; -pub const KERN_NETLIVELOCKS: ::c_int = 76; -pub const KERN_POOL_DEBUG: ::c_int = 77; -pub const KERN_PROC_CWD: ::c_int = 78; -pub const KERN_PROC_NOBROADCASTKILL: ::c_int = 79; -pub const KERN_PROC_VMMAP: ::c_int = 80; -pub const KERN_GLOBAL_PTRACE: ::c_int = 81; -pub const KERN_CONSBUFSIZE: ::c_int = 82; -pub const KERN_CONSBUF: ::c_int = 83; -pub const KERN_AUDIO: ::c_int = 84; -pub const KERN_CPUSTATS: ::c_int = 85; -pub const KERN_PFSTATUS: ::c_int = 86; -pub const KERN_TIMEOUT_STATS: ::c_int = 87; -pub const KERN_MAXID: ::c_int = 88; - -pub const KERN_PROC_ALL: ::c_int = 0; -pub const KERN_PROC_PID: ::c_int = 1; -pub const KERN_PROC_PGRP: ::c_int = 2; -pub const KERN_PROC_SESSION: ::c_int = 3; -pub const KERN_PROC_TTY: ::c_int = 4; -pub const KERN_PROC_UID: ::c_int = 5; -pub const KERN_PROC_RUID: ::c_int = 6; -pub const KERN_PROC_KTHREAD: ::c_int = 7; -pub const KERN_PROC_SHOW_THREADS: ::c_int = 0x40000000; - -pub const KERN_SYSVIPC_MSG_INFO: ::c_int = 1; -pub const KERN_SYSVIPC_SEM_INFO: ::c_int = 2; -pub const KERN_SYSVIPC_SHM_INFO: ::c_int = 3; - -pub const KERN_PROC_ARGV: ::c_int = 1; -pub const KERN_PROC_NARGV: ::c_int = 2; -pub const KERN_PROC_ENV: ::c_int = 3; -pub const KERN_PROC_NENV: ::c_int = 4; - -pub const KI_NGROUPS: ::c_int = 16; -pub const KI_MAXCOMLEN: ::c_int = 24; -pub const KI_WMESGLEN: ::c_int = 8; -pub const KI_MAXLOGNAME: ::c_int = 32; -pub const KI_EMULNAMELEN: ::c_int = 8; - -pub const CHWFLOW: ::tcflag_t = ::MDMBUF | ::CRTSCTS; -pub const OLCUC: ::tcflag_t = 0x20; -pub const ONOCR: ::tcflag_t = 0x40; -pub const ONLRET: ::tcflag_t = 0x80; - -//https://github.com/openbsd/src/blob/master/sys/sys/mount.h -pub const ISOFSMNT_NORRIP: ::c_int = 0x1; // disable Rock Ridge Ext -pub const ISOFSMNT_GENS: ::c_int = 0x2; // enable generation numbers -pub const ISOFSMNT_EXTATT: ::c_int = 0x4; // enable extended attr -pub const ISOFSMNT_NOJOLIET: ::c_int = 0x8; // disable Joliet Ext -pub const ISOFSMNT_SESS: ::c_int = 0x10; // use iso_args.sess - -pub const NFS_ARGSVERSION: ::c_int = 4; // change when nfs_args changes - -pub const NFSMNT_RESVPORT: ::c_int = 0; // always use reserved ports -pub const NFSMNT_SOFT: ::c_int = 0x1; // soft mount (hard is default) -pub const NFSMNT_WSIZE: ::c_int = 0x2; // set write size -pub const NFSMNT_RSIZE: ::c_int = 0x4; // set read size -pub const NFSMNT_TIMEO: ::c_int = 0x8; // set initial timeout -pub const NFSMNT_RETRANS: ::c_int = 0x10; // set number of request retries -pub const NFSMNT_MAXGRPS: ::c_int = 0x20; // set maximum grouplist size -pub const NFSMNT_INT: ::c_int = 0x40; // allow interrupts on hard mount -pub const NFSMNT_NOCONN: ::c_int = 0x80; // Don't Connect the socket -pub const NFSMNT_NQNFS: ::c_int = 0x100; // Use Nqnfs protocol -pub const NFSMNT_NFSV3: ::c_int = 0x200; // Use NFS Version 3 protocol -pub const NFSMNT_KERB: ::c_int = 0x400; // Use Kerberos authentication -pub const NFSMNT_DUMBTIMR: ::c_int = 0x800; // Don't estimate rtt dynamically -pub const NFSMNT_LEASETERM: ::c_int = 0x1000; // set lease term (nqnfs) -pub const NFSMNT_READAHEAD: ::c_int = 0x2000; // set read ahead -pub const NFSMNT_DEADTHRESH: ::c_int = 0x4000; // set dead server retry thresh -pub const NFSMNT_NOAC: ::c_int = 0x8000; // disable attribute cache -pub const NFSMNT_RDIRPLUS: ::c_int = 0x10000; // Use Readdirplus for V3 -pub const NFSMNT_READDIRSIZE: ::c_int = 0x20000; // Set readdir size - -/* Flags valid only in mount syscall arguments */ -pub const NFSMNT_ACREGMIN: ::c_int = 0x40000; // acregmin field valid -pub const NFSMNT_ACREGMAX: ::c_int = 0x80000; // acregmax field valid -pub const NFSMNT_ACDIRMIN: ::c_int = 0x100000; // acdirmin field valid -pub const NFSMNT_ACDIRMAX: ::c_int = 0x200000; // acdirmax field valid - -/* Flags valid only in kernel */ -pub const NFSMNT_INTERNAL: ::c_int = 0xfffc0000; // Bits set internally -pub const NFSMNT_HASWRITEVERF: ::c_int = 0x40000; // Has write verifier for V3 -pub const NFSMNT_GOTPATHCONF: ::c_int = 0x80000; // Got the V3 pathconf info -pub const NFSMNT_GOTFSINFO: ::c_int = 0x100000; // Got the V3 fsinfo -pub const NFSMNT_MNTD: ::c_int = 0x200000; // Mnt server for mnt point -pub const NFSMNT_DISMINPROG: ::c_int = 0x400000; // Dismount in progress -pub const NFSMNT_DISMNT: ::c_int = 0x800000; // Dismounted -pub const NFSMNT_SNDLOCK: ::c_int = 0x1000000; // Send socket lock -pub const NFSMNT_WANTSND: ::c_int = 0x2000000; // Want above -pub const NFSMNT_RCVLOCK: ::c_int = 0x4000000; // Rcv socket lock -pub const NFSMNT_WANTRCV: ::c_int = 0x8000000; // Want above -pub const NFSMNT_WAITAUTH: ::c_int = 0x10000000; // Wait for authentication -pub const NFSMNT_HASAUTH: ::c_int = 0x20000000; // Has authenticator -pub const NFSMNT_WANTAUTH: ::c_int = 0x40000000; // Wants an authenticator -pub const NFSMNT_AUTHERR: ::c_int = 0x80000000; // Authentication error - -pub const MSDOSFSMNT_SHORTNAME: ::c_int = 0x1; // Force old DOS short names only -pub const MSDOSFSMNT_LONGNAME: ::c_int = 0x2; // Force Win'95 long names -pub const MSDOSFSMNT_NOWIN95: ::c_int = 0x4; // Completely ignore Win95 entries - -pub const NTFS_MFLAG_CASEINS: ::c_int = 0x1; -pub const NTFS_MFLAG_ALLNAMES: ::c_int = 0x2; - -pub const TMPFS_ARGS_VERSION: ::c_int = 1; - -pub const MAP_STACK: ::c_int = 0x4000; - -// https://github.com/openbsd/src/blob/master/sys/net/if.h#L187 -pub const IFF_UP: ::c_int = 0x1; // interface is up -pub const IFF_BROADCAST: ::c_int = 0x2; // broadcast address valid -pub const IFF_DEBUG: ::c_int = 0x4; // turn on debugging -pub const IFF_LOOPBACK: ::c_int = 0x8; // is a loopback net -pub const IFF_POINTOPOINT: ::c_int = 0x10; // interface is point-to-point link -pub const IFF_STATICARP: ::c_int = 0x20; // only static ARP -pub const IFF_RUNNING: ::c_int = 0x40; // resources allocated -pub const IFF_NOARP: ::c_int = 0x80; // no address resolution protocol -pub const IFF_PROMISC: ::c_int = 0x100; // receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x200; // receive all multicast packets -pub const IFF_OACTIVE: ::c_int = 0x400; // transmission in progress -pub const IFF_SIMPLEX: ::c_int = 0x800; // can't hear own transmissions -pub const IFF_LINK0: ::c_int = 0x1000; // per link layer defined bit -pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit -pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit -pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast - -pub const PTHREAD_STACK_MIN: ::size_t = (1_usize << _MAX_PAGE_SHIFT); -pub const MINSIGSTKSZ: ::size_t = (3_usize << _MAX_PAGE_SHIFT); -pub const SIGSTKSZ: ::size_t = MINSIGSTKSZ + (1_usize << _MAX_PAGE_SHIFT) * 4; - -pub const PT_FIRSTMACH: ::c_int = 32; - -pub const SOCK_CLOEXEC: ::c_int = 0x8000; -pub const SOCK_NONBLOCK: ::c_int = 0x4000; -pub const SOCK_DNS: ::c_int = 0x1000; - -pub const BIOCGRSIG: ::c_ulong = 0x40044273; -pub const BIOCSRSIG: ::c_ulong = 0x80044272; -pub const BIOCSDLT: ::c_ulong = 0x8004427a; - -pub const PTRACE_FORK: ::c_int = 0x0002; - -pub const WCONTINUED: ::c_int = 8; - -fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES -} - -f! { - pub fn WIFCONTINUED(status: ::c_int) -> bool { - status & 0o177777 == 0o177777 - } - - pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { - (cmsg as *mut ::c_uchar) - .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) - -> *mut ::cmsghdr - { - if cmsg.is_null() { - return ::CMSG_FIRSTHDR(mhdr); - }; - let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) - + _ALIGN(::mem::size_of::<::cmsghdr>()); - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next > max { - 0 as *mut ::cmsghdr - } else { - (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) - as *mut ::cmsghdr - } - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) - as ::c_uint - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - status >> 8 - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - (status & 0o177) != 0o177 && (status & 0o177) != 0 - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0o177) == 0o177 - } -} - -extern "C" { - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; - pub fn settimeofday( - tp: *const ::timeval, - tz: *const ::timezone, - ) -> ::c_int; - pub fn accept4( - s: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn execvpe( - file: *const ::c_char, - argv: *const *const ::c_char, - envp: *const *const ::c_char, - ) -> ::c_int; - pub fn pledge( - promises: *const ::c_char, - execpromises: *const ::c_char, - ) -> ::c_int; - pub fn strtonum( - nptr: *const ::c_char, - minval: ::c_longlong, - maxval: ::c_longlong, - errstr: *mut *const ::c_char, - ) -> ::c_longlong; - pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int; - pub fn chflags(path: *const ::c_char, flags: ::c_uint) -> ::c_int; - pub fn fchflags(fd: ::c_int, flags: ::c_uint) -> ::c_int; - pub fn chflagsat( - fd: ::c_int, - path: *const ::c_char, - flags: ::c_uint, - atflag: ::c_int, - ) -> ::c_int; - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::size_t, - serv: *mut ::c_char, - servlen: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn kevent( - kq: ::c_int, - changelist: *const ::kevent, - nchanges: ::c_int, - eventlist: *mut ::kevent, - nevents: ::c_int, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn pthread_attr_getguardsize( - attr: *const ::pthread_attr_t, - guardsize: *mut ::size_t, - ) -> ::c_int; - pub fn pthread_attr_getstack( - attr: *const ::pthread_attr_t, - stackaddr: *mut *mut ::c_void, - stacksize: *mut ::size_t, - ) -> ::c_int; - pub fn pthread_main_np() -> ::c_int; - pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char); - pub fn pthread_stackseg_np( - thread: ::pthread_t, - sinfo: *mut ::stack_t, - ) -> ::c_int; - pub fn sysctl( - name: *const ::c_int, - namelen: ::c_uint, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; - pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int; - pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int; - pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int; - pub fn ptrace( - request: ::c_int, - pid: ::pid_t, - addr: caddr_t, - data: ::c_int, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_union)] { - extern { - // these functions use statfs which uses the union mount_info: - pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; - pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; - } - } -} - -cfg_if! { - if #[cfg(target_arch = "x86")] { - mod x86; - pub use self::x86::*; - } else if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } else if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(target_arch = "sparc64")] { - mod sparc64; - pub use self::sparc64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/bsd/netbsdlike/openbsd/sparc64.rs b/libc/src/unix/bsd/netbsdlike/openbsd/sparc64.rs deleted file mode 100644 index 070fc93..0000000 --- a/libc/src/unix/bsd/netbsdlike/openbsd/sparc64.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = i8; - -#[doc(hidden)] -pub const _ALIGNBYTES: usize = 0xf; - -pub const _MAX_PAGE_SHIFT: u32 = 13; diff --git a/libc/src/unix/bsd/netbsdlike/openbsd/x86.rs b/libc/src/unix/bsd/netbsdlike/openbsd/x86.rs deleted file mode 100644 index e87d0ff..0000000 --- a/libc/src/unix/bsd/netbsdlike/openbsd/x86.rs +++ /dev/null @@ -1,16 +0,0 @@ -pub type c_long = i32; -pub type c_ulong = u32; -pub type c_char = i8; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 4 - 1; - } -} - -pub const _MAX_PAGE_SHIFT: u32 = 12; diff --git a/libc/src/unix/bsd/netbsdlike/openbsd/x86_64.rs b/libc/src/unix/bsd/netbsdlike/openbsd/x86_64.rs deleted file mode 100644 index 263b6e1..0000000 --- a/libc/src/unix/bsd/netbsdlike/openbsd/x86_64.rs +++ /dev/null @@ -1,24 +0,0 @@ -use PT_FIRSTMACH; - -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = i8; - -// should be pub(crate), but that requires Rust 1.18.0 -cfg_if! { - if #[cfg(libc_const_size_of)] { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1; - } else { - #[doc(hidden)] - pub const _ALIGNBYTES: usize = 8 - 1; - } -} - -pub const _MAX_PAGE_SHIFT: u32 = 12; - -pub const PT_STEP: ::c_int = PT_FIRSTMACH + 0; -pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 1; -pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 2; -pub const PT_GETFPREGS: ::c_int = PT_FIRSTMACH + 3; -pub const PT_SETFPREGS: ::c_int = PT_FIRSTMACH + 4; diff --git a/libc/src/unix/haiku/b32.rs b/libc/src/unix/haiku/b32.rs deleted file mode 100644 index cce8864..0000000 --- a/libc/src/unix/haiku/b32.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub type c_long = i32; -pub type c_ulong = u32; -pub type time_t = i32; diff --git a/libc/src/unix/haiku/b64.rs b/libc/src/unix/haiku/b64.rs deleted file mode 100644 index 3e66f14..0000000 --- a/libc/src/unix/haiku/b64.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub type c_ulong = u64; -pub type c_long = i64; -pub type time_t = i64; diff --git a/libc/src/unix/haiku/mod.rs b/libc/src/unix/haiku/mod.rs deleted file mode 100644 index d704a0b..0000000 --- a/libc/src/unix/haiku/mod.rs +++ /dev/null @@ -1,1531 +0,0 @@ -pub type rlim_t = ::uintptr_t; -pub type sa_family_t = u8; -pub type pthread_key_t = ::c_int; -pub type nfds_t = ::c_long; -pub type tcflag_t = ::c_uint; -pub type speed_t = ::c_uint; -pub type c_char = i8; -pub type clock_t = i32; -pub type clockid_t = i32; -pub type suseconds_t = i32; -pub type wchar_t = i32; -pub type off_t = i64; -pub type ino_t = i64; -pub type blkcnt_t = i64; -pub type blksize_t = i32; -pub type dev_t = i32; -pub type mode_t = u32; -pub type nlink_t = i32; -pub type useconds_t = u32; -pub type socklen_t = u32; -pub type pthread_t = ::uintptr_t; -pub type pthread_mutexattr_t = ::uintptr_t; -pub type pthread_rwlockattr_t = ::uintptr_t; -pub type sigset_t = u64; -pub type fsblkcnt_t = i64; -pub type fsfilcnt_t = i64; -pub type pthread_attr_t = *mut ::c_void; -pub type nl_item = ::c_int; -pub type id_t = i32; -pub type idtype_t = ::c_uint; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} - -s! { - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 30], - } - - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [u8; 24], - } - - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: socklen_t, - pub ai_canonname: *mut c_char, - pub ai_addr: *mut ::sockaddr, - pub ai_next: *mut addrinfo, - } - - pub struct fd_set { - fds_bits: [c_ulong; FD_SETSIZE / ULONG_SIZE], - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - pub tm_gmtoff: ::c_long, - pub tm_zone: *const ::c_char, - } - - pub struct utsname { - pub sysname: [::c_char; 32], - pub nodename: [::c_char; 32], - pub release: [::c_char; 32], - pub version: [::c_char; 32], - pub machine: [::c_char; 32], - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::size_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::c_char, - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - pub c_cc: [::cc_t; ::NCCS], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct stat { - pub st_dev: dev_t, - pub st_ino: ino_t, - pub st_mode: mode_t, - pub st_nlink: nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_size: off_t, - pub st_rdev: dev_t, - pub st_blksize: blksize_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_crtime: time_t, - pub st_crtime_nsec: c_long, - pub st_type: u32, - pub st_blocks: blkcnt_t, - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - __unused1: ::size_t, - pub gl_offs: ::size_t, - __unused2: ::size_t, - pub gl_pathv: *mut *mut c_char, - - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - __unused6: *mut ::c_void, - __unused7: *mut ::c_void, - __unused8: *mut ::c_void, - } - - pub struct pthread_mutex_t { - flags: u32, - lock: i32, - unused: i32, - owner: i32, - owner_count: i32, - } - - pub struct pthread_cond_t { - flags: u32, - unused: i32, - mutex: *mut ::c_void, - waiter_count: i32, - lock: i32, - } - - pub struct pthread_rwlock_t { - flags: u32, - owner: i32, - lock_sem: i32, // this is actually a union - lock_count: i32, - reader_count: i32, - writer_count: i32, - waiters: [*mut ::c_void; 2], - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - pub pw_gecos: *mut ::c_char, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub si_pid: ::pid_t, - pub si_uid: ::uid_t, - pub si_addr: *mut ::c_void, - pub si_status: ::c_int, - pub si_band: c_long, - pub sigval: *mut ::c_void, - } - - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - sa_userdata: *mut ::c_void, - } - - pub struct sem_t { - pub se_type: i32, - pub se_named_id: i32, // this is actually a union - pub se_unnamed: i32, - pub se_padding: [i32; 4], - } - - pub struct pthread_condattr_t { - pub process_shared: bool, - pub clock_id: i32, - } -} - -s_no_extra_traits! { - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 126] - } - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: sa_family_t, - __ss_pad1: [u8; 6], - __ss_pad2: u64, - __ss_pad3: [u8; 112], - } - pub struct dirent { - pub d_dev: dev_t, - pub d_pdev: dev_t, - pub d_ino: ino_t, - pub d_pino: i64, - pub d_reclen: ::c_ushort, - pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX - } - - pub struct sigevent { - pub sigev_notify: ::c_int, - pub sigev_signo: ::c_int, - pub sigev_value: ::sigval, - __unused1: *mut ::c_void, // actually a function pointer - pub sigev_notify_attributes: *mut ::pthread_attr_t, - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for sockaddr_un { - fn eq(&self, other: &sockaddr_un) -> bool { - self.sun_len == other.sun_len - && self.sun_family == other.sun_family - && self - .sun_path - .iter() - .zip(other.sun_path.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr_un {} - impl ::fmt::Debug for sockaddr_un { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_un") - .field("sun_len", &self.sun_len) - .field("sun_family", &self.sun_family) - // FIXME: .field("sun_path", &self.sun_path) - .finish() - } - } - impl ::hash::Hash for sockaddr_un { - fn hash(&self, state: &mut H) { - self.sun_len.hash(state); - self.sun_family.hash(state); - self.sun_path.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_len == other.ss_len - && self.ss_family == other.ss_family - && self - .__ss_pad1 - .iter() - .zip(other.__ss_pad1.iter()) - .all(|(a, b)| a == b) - && self.__ss_pad2 == other.__ss_pad2 - && self - .__ss_pad3 - .iter() - .zip(other.__ss_pad3.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for sockaddr_storage {} - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_len", &self.ss_len) - .field("ss_family", &self.ss_family) - .field("__ss_pad1", &self.__ss_pad1) - .field("__ss_pad2", &self.__ss_pad2) - // FIXME: .field("__ss_pad3", &self.__ss_pad3) - .finish() - } - } - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_len.hash(state); - self.ss_family.hash(state); - self.__ss_pad1.hash(state); - self.__ss_pad2.hash(state); - self.__ss_pad3.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_dev == other.d_dev - && self.d_pdev == other.d_pdev - && self.d_ino == other.d_ino - && self.d_pino == other.d_pino - && self.d_reclen == other.d_reclen - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_dev", &self.d_dev) - .field("d_pdev", &self.d_pdev) - .field("d_ino", &self.d_ino) - .field("d_pino", &self.d_pino) - .field("d_reclen", &self.d_reclen) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_dev.hash(state); - self.d_pdev.hash(state); - self.d_ino.hash(state); - self.d_pino.hash(state); - self.d_reclen.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_notify == other.sigev_notify - && self.sigev_signo == other.sigev_signo - && self.sigev_value == other.sigev_value - && self.sigev_notify_attributes - == other.sigev_notify_attributes - } - } - impl Eq for sigevent {} - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_notify", &self.sigev_notify) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_value", &self.sigev_value) - .field("sigev_notify_attributes", - &self.sigev_notify_attributes) - .finish() - } - } - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_notify.hash(state); - self.sigev_signo.hash(state); - self.sigev_value.hash(state); - self.sigev_notify_attributes.hash(state); - } - } - } -} - -// intentionally not public, only used for fd_set -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - const ULONG_SIZE: usize = 32; - } else if #[cfg(target_pointer_width = "64")] { - const ULONG_SIZE: usize = 64; - } else { - // Unknown target_pointer_width - } -} - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const RAND_MAX: ::c_int = 2147483647; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 2; -pub const _IOLBF: ::c_int = 1; - -pub const F_DUPFD: ::c_int = 0x0001; -pub const F_GETFD: ::c_int = 0x0002; -pub const F_SETFD: ::c_int = 0x0004; -pub const F_GETFL: ::c_int = 0x0008; -pub const F_SETFL: ::c_int = 0x0010; -pub const F_GETLK: ::c_int = 0x0020; -pub const F_SETLK: ::c_int = 0x0080; -pub const F_SETLKW: ::c_int = 0x0100; -pub const F_DUPFD_CLOEXEC: ::c_int = 0x0200; - -pub const F_RDLCK: ::c_int = 0x0040; -pub const F_UNLCK: ::c_int = 0x0200; -pub const F_WRLCK: ::c_int = 0x0400; - -pub const AT_FDCWD: ::c_int = -1; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x01; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x02; -pub const AT_REMOVEDIR: ::c_int = 0x04; -pub const AT_EACCESS: ::c_int = 0x08; - -pub const POLLIN: ::c_short = 0x0001; -pub const POLLOUT: ::c_short = 0x0002; -pub const POLLRDNORM: ::c_short = POLLIN; -pub const POLLWRNORM: ::c_short = POLLOUT; -pub const POLLRDBAND: ::c_short = 0x0008; -pub const POLLWRBAND: ::c_short = 0x0010; -pub const POLLPRI: ::c_short = 0x0020; -pub const POLLERR: ::c_short = 0x0004; -pub const POLLHUP: ::c_short = 0x0080; -pub const POLLNVAL: ::c_short = 0x1000; - -pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0; -pub const PTHREAD_CREATE_DETACHED: ::c_int = 1; - -pub const CLOCK_REALTIME: ::c_int = -1; -pub const CLOCK_MONOTONIC: ::c_int = 0; - -pub const RLIMIT_CORE: ::c_int = 0; -pub const RLIMIT_CPU: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_FSIZE: ::c_int = 3; -pub const RLIMIT_NOFILE: ::c_int = 4; -pub const RLIMIT_STACK: ::c_int = 5; -pub const RLIMIT_AS: ::c_int = 6; -// Haiku specific -pub const RLIMIT_NOVMON: ::c_int = 7; -pub const RLIMIT_NLIMITS: ::c_int = 8; - -pub const RUSAGE_SELF: ::c_int = 0; - -pub const RTLD_LAZY: ::c_int = 0; - -pub const NCCS: usize = 11; - -pub const O_RDONLY: ::c_int = 0x0000; -pub const O_WRONLY: ::c_int = 0x0001; -pub const O_RDWR: ::c_int = 0x0002; -pub const O_ACCMODE: ::c_int = 0x0003; - -pub const O_EXCL: ::c_int = 0x0100; -pub const O_CREAT: ::c_int = 0x0200; -pub const O_TRUNC: ::c_int = 0x0400; -pub const O_NOCTTY: ::c_int = 0x1000; -pub const O_NOTRAVERSE: ::c_int = 0x2000; - -pub const O_CLOEXEC: ::c_int = 0x00000040; -pub const O_NONBLOCK: ::c_int = 0x00000080; -pub const O_APPEND: ::c_int = 0x00000800; -pub const O_SYNC: ::c_int = 0x00010000; -pub const O_RSYNC: ::c_int = 0x00020000; -pub const O_DSYNC: ::c_int = 0x00040000; -pub const O_NOFOLLOW: ::c_int = 0x00080000; -pub const O_NOCACHE: ::c_int = 0x00100000; -pub const O_DIRECTORY: ::c_int = 0x00200000; - -pub const S_IFIFO: ::mode_t = 4096; -pub const S_IFCHR: ::mode_t = 8192; -pub const S_IFBLK: ::mode_t = 24576; -pub const S_IFDIR: ::mode_t = 16384; -pub const S_IFREG: ::mode_t = 32768; -pub const S_IFLNK: ::mode_t = 40960; -pub const S_IFSOCK: ::mode_t = 49152; -pub const S_IFMT: ::mode_t = 61440; -pub const S_IRWXU: ::mode_t = 448; -pub const S_IXUSR: ::mode_t = 64; -pub const S_IWUSR: ::mode_t = 128; -pub const S_IRUSR: ::mode_t = 256; -pub const S_IRWXG: ::mode_t = 70; -pub const S_IXGRP: ::mode_t = 10; -pub const S_IWGRP: ::mode_t = 20; -pub const S_IRGRP: ::mode_t = 40; -pub const S_IRWXO: ::mode_t = 7; -pub const S_IXOTH: ::mode_t = 1; -pub const S_IWOTH: ::mode_t = 2; -pub const S_IROTH: ::mode_t = 4; -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; - -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGCHLD: ::c_int = 5; -pub const SIGABRT: ::c_int = 6; -pub const SIGPIPE: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSTOP: ::c_int = 10; -pub const SIGSEGV: ::c_int = 11; -pub const SIGCONT: ::c_int = 12; -pub const SIGTSTP: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; -pub const SIGTTIN: ::c_int = 16; -pub const SIGTTOU: ::c_int = 17; -pub const SIGUSR1: ::c_int = 18; -pub const SIGUSR2: ::c_int = 19; -pub const SIGWINCH: ::c_int = 20; -pub const SIGKILLTHR: ::c_int = 21; -pub const SIGTRAP: ::c_int = 22; -pub const SIGPOLL: ::c_int = 23; -pub const SIGPROF: ::c_int = 24; -pub const SIGSYS: ::c_int = 25; -pub const SIGURG: ::c_int = 26; -pub const SIGVTALRM: ::c_int = 27; -pub const SIGXCPU: ::c_int = 28; -pub const SIGXFSZ: ::c_int = 29; -pub const SIGBUS: ::c_int = 30; - -pub const SIG_BLOCK: ::c_int = 1; -pub const SIG_UNBLOCK: ::c_int = 2; -pub const SIG_SETMASK: ::c_int = 3; - -pub const SIGEV_NONE: ::c_int = 0; -pub const SIGEV_SIGNAL: ::c_int = 1; -pub const SIGEV_THREAD: ::c_int = 2; - -pub const EAI_AGAIN: ::c_int = 2; -pub const EAI_BADFLAGS: ::c_int = 3; -pub const EAI_FAIL: ::c_int = 4; -pub const EAI_FAMILY: ::c_int = 5; -pub const EAI_MEMORY: ::c_int = 6; -pub const EAI_NODATA: ::c_int = 7; -pub const EAI_NONAME: ::c_int = 8; -pub const EAI_SERVICE: ::c_int = 9; -pub const EAI_SOCKTYPE: ::c_int = 10; -pub const EAI_SYSTEM: ::c_int = 11; -pub const EAI_OVERFLOW: ::c_int = 14; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_READ: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_EXEC: ::c_int = 4; - -pub const LC_ALL: ::c_int = 0; -pub const LC_COLLATE: ::c_int = 1; -pub const LC_CTYPE: ::c_int = 2; -pub const LC_MONETARY: ::c_int = 3; -pub const LC_NUMERIC: ::c_int = 4; -pub const LC_TIME: ::c_int = 5; -pub const LC_MESSAGES: ::c_int = 6; - -// TODO: Haiku does not have MAP_FILE, but libstd/os.rs requires it -pub const MAP_FILE: ::c_int = 0x00; -pub const MAP_SHARED: ::c_int = 0x01; -pub const MAP_PRIVATE: ::c_int = 0x02; -pub const MAP_FIXED: ::c_int = 0x04; -pub const MAP_ANONYMOUS: ::c_int = 0x08; -pub const MAP_ANON: ::c_int = MAP_ANONYMOUS; - -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -pub const MS_ASYNC: ::c_int = 0x01; -pub const MS_INVALIDATE: ::c_int = 0x04; -pub const MS_SYNC: ::c_int = 0x02; - -pub const E2BIG: ::c_int = -2147454975; -pub const ECHILD: ::c_int = -2147454974; -pub const EDEADLK: ::c_int = -2147454973; -pub const EFBIG: ::c_int = -2147454972; -pub const EMLINK: ::c_int = -2147454971; -pub const ENFILE: ::c_int = -2147454970; -pub const ENODEV: ::c_int = -2147454969; -pub const ENOLCK: ::c_int = -2147454968; -pub const ENOSYS: ::c_int = -2147454967; -pub const ENOTTY: ::c_int = -2147454966; -pub const ENXIO: ::c_int = -2147454965; -pub const ESPIPE: ::c_int = -2147454964; -pub const ESRCH: ::c_int = -2147454963; -pub const EFPOS: ::c_int = -2147457962; -pub const ESIGPARM: ::c_int = -2147457961; -pub const EDOM: ::c_int = -2147454960; -pub const ERANGE: ::c_int = -2147454959; -pub const EPROTOTYPE: ::c_int = -2147454958; -pub const EPROTONOSUPPORT: ::c_int = -2147454957; -pub const EPFNOSUPPORT: ::c_int = -2147454956; -pub const EAFNOSUPPORT: ::c_int = -2147454955; -pub const EADDRINUSE: ::c_int = -2147454954; -pub const EADDRNOTAVAIL: ::c_int = -2147454953; -pub const ENETDOWN: ::c_int = -2147454952; -pub const ENETUNREACH: ::c_int = -2147454951; -pub const ENETRESET: ::c_int = -2147454950; -pub const ECONNABORTED: ::c_int = -2147454949; -pub const ECONNRESET: ::c_int = -2147454948; -pub const EISCONN: ::c_int = -2147454947; -pub const ENOTCONN: ::c_int = -2147454946; -pub const ESHUTDOWN: ::c_int = -2147454945; -pub const ECONNREFUSED: ::c_int = -2147454944; -pub const EHOSTUNREACH: ::c_int = -2147454943; -pub const ENOPROTOOPT: ::c_int = -2147454942; -pub const ENOBUFS: ::c_int = -2147454941; -pub const EINPROGRESS: ::c_int = -2147454940; -pub const EALREADY: ::c_int = -2147454939; -pub const EILSEQ: ::c_int = -2147454938; -pub const ENOMSG: ::c_int = -2147454937; -pub const ESTALE: ::c_int = -2147454936; -pub const EOVERFLOW: ::c_int = -2147454935; -pub const EMSGSIZE: ::c_int = -2147454934; -pub const EOPNOTSUPP: ::c_int = -2147454933; -pub const ENOTSOCK: ::c_int = -2147454932; -pub const EHOSTDOWN: ::c_int = -2147454931; -pub const EBADMSG: ::c_int = -2147454930; -pub const ECANCELED: ::c_int = -2147454929; -pub const EDESTADDRREQ: ::c_int = -2147454928; -pub const EDQUOT: ::c_int = -2147454927; -pub const EIDRM: ::c_int = -2147454926; -pub const EMULTIHOP: ::c_int = -2147454925; -pub const ENODATA: ::c_int = -2147454924; -pub const ENOLINK: ::c_int = -2147454923; -pub const ENOSR: ::c_int = -2147454922; -pub const ENOSTR: ::c_int = -2147454921; -pub const ENOTSUP: ::c_int = -2147454920; -pub const EPROTO: ::c_int = -2147454919; -pub const ETIME: ::c_int = -2147454918; -pub const ETXTBSY: ::c_int = -2147454917; -pub const ENOATTR: ::c_int = -2147454916; - -// INT_MIN -pub const ENOMEM: ::c_int = -2147454976; - -// POSIX errors that can be mapped to BeOS error codes -pub const EACCES: ::c_int = -2147483646; -pub const EINTR: ::c_int = -2147483638; -pub const EIO: ::c_int = -2147483647; -pub const EBUSY: ::c_int = -2147483634; -pub const EFAULT: ::c_int = -2147478783; -pub const ETIMEDOUT: ::c_int = -2147483639; -pub const EAGAIN: ::c_int = -2147483637; -pub const EWOULDBLOCK: ::c_int = -2147483637; -pub const EBADF: ::c_int = -2147459072; -pub const EEXIST: ::c_int = -2147459070; -pub const EINVAL: ::c_int = -2147483643; -pub const ENAMETOOLONG: ::c_int = -2147459068; -pub const ENOENT: ::c_int = -2147459069; -pub const EPERM: ::c_int = -2147483633; -pub const ENOTDIR: ::c_int = -2147459067; -pub const EISDIR: ::c_int = -2147459063; -pub const ENOTEMPTY: ::c_int = -2147459066; -pub const ENOSPC: ::c_int = -2147459065; -pub const EROFS: ::c_int = -2147459064; -pub const EMFILE: ::c_int = -2147459062; -pub const EXDEV: ::c_int = -2147459061; -pub const ELOOP: ::c_int = -2147459060; -pub const ENOEXEC: ::c_int = -2147478782; -pub const EPIPE: ::c_int = -2147459059; - -pub const IPPROTO_RAW: ::c_int = 255; - -// These are prefixed with POSIX_ on Haiku -pub const MADV_NORMAL: ::c_int = 1; -pub const MADV_SEQUENTIAL: ::c_int = 2; -pub const MADV_RANDOM: ::c_int = 3; -pub const MADV_WILLNEED: ::c_int = 4; -pub const MADV_DONTNEED: ::c_int = 5; - -// https://github.com/haiku/haiku/blob/master/headers/posix/net/if.h#L80 -pub const IFF_UP: ::c_int = 0x0001; -pub const IFF_BROADCAST: ::c_int = 0x0002; // valid broadcast address -pub const IFF_LOOPBACK: ::c_int = 0x0008; -pub const IFF_POINTOPOINT: ::c_int = 0x0010; // point-to-point link -pub const IFF_NOARP: ::c_int = 0x0040; // no address resolution -pub const IFF_AUTOUP: ::c_int = 0x0080; // auto dial -pub const IFF_PROMISC: ::c_int = 0x0100; // receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x0200; // receive all multicast packets -pub const IFF_SIMPLEX: ::c_int = 0x0800; // doesn't receive own transmissions -pub const IFF_LINK: ::c_int = 0x1000; // has link -pub const IFF_AUTO_CONFIGURED: ::c_int = 0x2000; -pub const IFF_CONFIGURING: ::c_int = 0x4000; -pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast - -pub const AF_UNSEC: ::c_int = 0; -pub const AF_INET: ::c_int = 1; -pub const AF_APPLETALK: ::c_int = 2; -pub const AF_ROUTE: ::c_int = 3; -pub const AF_LINK: ::c_int = 4; -pub const AF_INET6: ::c_int = 5; -pub const AF_DLI: ::c_int = 6; -pub const AF_IPX: ::c_int = 7; -pub const AF_NOTIFY: ::c_int = 8; -pub const AF_LOCAL: ::c_int = 9; -pub const AF_UNIX: ::c_int = AF_LOCAL; -pub const AF_BLUETOOTH: ::c_int = 10; - -pub const IP_OPTIONS: ::c_int = 1; -pub const IP_HDRINCL: ::c_int = 2; -pub const IP_TOS: ::c_int = 3; -pub const IP_TTL: ::c_int = 4; -pub const IP_RECVOPTS: ::c_int = 5; -pub const IP_RECVRETOPTS: ::c_int = 6; -pub const IP_RECVDSTADDR: ::c_int = 7; -pub const IP_RETOPTS: ::c_int = 8; -pub const IP_MULTICAST_IF: ::c_int = 9; -pub const IP_MULTICAST_TTL: ::c_int = 10; -pub const IP_MULTICAST_LOOP: ::c_int = 11; -pub const IP_ADD_MEMBERSHIP: ::c_int = 12; -pub const IP_DROP_MEMBERSHIP: ::c_int = 13; -pub const IP_BLOCK_SOURCE: ::c_int = 14; -pub const IP_UNBLOCK_SOURCE: ::c_int = 15; -pub const IP_ADD_SOURCE_MEMBERSHIP: ::c_int = 16; -pub const IP_DROP_SOURCE_MEMBERSHIP: ::c_int = 17; - -pub const TCP_NODELAY: ::c_int = 0x01; -pub const TCP_MAXSEG: ::c_int = 0x02; -pub const TCP_NOPUSH: ::c_int = 0x04; -pub const TCP_NOOPT: ::c_int = 0x08; - -pub const IPV6_MULTICAST_IF: ::c_int = 24; -pub const IPV6_MULTICAST_HOPS: ::c_int = 25; -pub const IPV6_MULTICAST_LOOP: ::c_int = 26; -pub const IPV6_UNICAST_HOPS: ::c_int = 27; -pub const IPV6_JOIN_GROUP: ::c_int = 28; -pub const IPV6_LEAVE_GROUP: ::c_int = 29; -pub const IPV6_V6ONLY: ::c_int = 30; -pub const IPV6_PKTINFO: ::c_int = 31; -pub const IPV6_RECVPKTINFO: ::c_int = 32; -pub const IPV6_HOPLIMIT: ::c_int = 33; -pub const IPV6_REVCHOPLIMIT: ::c_int = 34; -pub const IPV6_HOPOPTS: ::c_int = 35; -pub const IPV6_DSTOPTS: ::c_int = 36; -pub const IPV6_RTHDR: ::c_int = 37; - -pub const MSG_OOB: ::c_int = 0x0001; -pub const MSG_PEEK: ::c_int = 0x0002; -pub const MSG_DONTROUTE: ::c_int = 0x0004; -pub const MSG_EOR: ::c_int = 0x0008; -pub const MSG_TRUNC: ::c_int = 0x0010; -pub const MSG_CTRUNC: ::c_int = 0x0020; -pub const MSG_WAITALL: ::c_int = 0x0040; -pub const MSG_DONTWAIT: ::c_int = 0x0080; -pub const MSG_BCAST: ::c_int = 0x0100; -pub const MSG_MCAST: ::c_int = 0x0200; -pub const MSG_EOF: ::c_int = 0x0400; -pub const MSG_NOSIGNAL: ::c_int = 0x0800; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const LOCK_SH: ::c_int = 0x01; -pub const LOCK_EX: ::c_int = 0x02; -pub const LOCK_NB: ::c_int = 0x04; -pub const LOCK_UN: ::c_int = 0x08; - -pub const SIGSTKSZ: ::size_t = 16384; - -pub const PATH_MAX: ::c_int = 1024; - -pub const SA_NOCLDSTOP: ::c_int = 0x01; -pub const SA_NOCLDWAIT: ::c_int = 0x02; -pub const SA_RESETHAND: ::c_int = 0x04; -pub const SA_NODEFER: ::c_int = 0x08; -pub const SA_RESTART: ::c_int = 0x10; -pub const SA_ONSTACK: ::c_int = 0x20; -pub const SA_SIGINFO: ::c_int = 0x40; -pub const SA_NOMASK: ::c_int = SA_NODEFER; -pub const SA_STACK: ::c_int = SA_ONSTACK; -pub const SA_ONESHOT: ::c_int = SA_RESETHAND; - -pub const FD_SETSIZE: usize = 1024; - -pub const RTLD_LOCAL: ::c_int = 0x0; -pub const RTLD_NOW: ::c_int = 0x1; -pub const RTLD_GLOBAL: ::c_int = 0x2; -pub const RTLD_DEFAULT: *mut ::c_void = 0isize as *mut ::c_void; - -pub const BUFSIZ: ::c_uint = 8192; -pub const FILENAME_MAX: ::c_uint = 256; -pub const FOPEN_MAX: ::c_uint = 128; -pub const L_tmpnam: ::c_uint = 512; -pub const TMP_MAX: ::c_uint = 32768; - -pub const _PC_CHOWN_RESTRICTED: ::c_int = 1; -pub const _PC_MAX_CANON: ::c_int = 2; -pub const _PC_MAX_INPUT: ::c_int = 3; -pub const _PC_NAME_MAX: ::c_int = 4; -pub const _PC_NO_TRUNC: ::c_int = 5; -pub const _PC_PATH_MAX: ::c_int = 6; -pub const _PC_PIPE_BUF: ::c_int = 7; -pub const _PC_VDISABLE: ::c_int = 8; -pub const _PC_LINK_MAX: ::c_int = 25; -pub const _PC_SYNC_IO: ::c_int = 26; -pub const _PC_ASYNC_IO: ::c_int = 27; -pub const _PC_PRIO_IO: ::c_int = 28; -pub const _PC_SOCK_MAXBUF: ::c_int = 29; -pub const _PC_FILESIZEBITS: ::c_int = 30; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 31; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 32; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 33; -pub const _PC_REC_XFER_ALIGN: ::c_int = 34; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 35; -pub const _PC_SYMLINK_MAX: ::c_int = 36; -pub const _PC_2_SYMLINKS: ::c_int = 37; -pub const _PC_XATTR_EXISTS: ::c_int = 38; -pub const _PC_XATTR_ENABLED: ::c_int = 39; - -pub const FIONBIO: ::c_int = 0xbe000000; - -pub const _SC_ARG_MAX: ::c_int = 15; -pub const _SC_CHILD_MAX: ::c_int = 16; -pub const _SC_CLK_TCK: ::c_int = 17; -pub const _SC_JOB_CONTROL: ::c_int = 18; -pub const _SC_NGROUPS_MAX: ::c_int = 19; -pub const _SC_OPEN_MAX: ::c_int = 20; -pub const _SC_SAVED_IDS: ::c_int = 21; -pub const _SC_STREAM_MAX: ::c_int = 22; -pub const _SC_TZNAME_MAX: ::c_int = 23; -pub const _SC_VERSION: ::c_int = 24; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 25; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 26; -pub const _SC_PAGESIZE: ::c_int = 27; -pub const _SC_PAGE_SIZE: ::c_int = 27; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 28; -pub const _SC_SEM_VALUE_MAX: ::c_int = 29; -pub const _SC_SEMAPHORES: ::c_int = 30; -pub const _SC_THREADS: ::c_int = 31; -pub const _SC_IOV_MAX: ::c_int = 32; -pub const _SC_UIO_MAXIOV: ::c_int = 32; -pub const _SC_NPROCESSORS_CONF: ::c_int = 34; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 35; -pub const _SC_ATEXIT_MAX: ::c_int = 37; -pub const _SC_PASS_MAX: ::c_int = 39; -pub const _SC_PHYS_PAGES: ::c_int = 40; -pub const _SC_AVPHYS_PAGES: ::c_int = 41; -pub const _SC_PIPE: ::c_int = 42; -pub const _SC_SELECT: ::c_int = 43; -pub const _SC_POLL: ::c_int = 44; -pub const _SC_MAPPED_FILES: ::c_int = 45; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 46; -pub const _SC_THREAD_STACK_MIN: ::c_int = 47; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 48; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 49; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 50; -pub const _SC_REALTIME_SIGNALS: ::c_int = 51; -pub const _SC_MEMORY_PROTECTION: ::c_int = 52; -pub const _SC_SIGQUEUE_MAX: ::c_int = 53; -pub const _SC_RTSIG_MAX: ::c_int = 54; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 55; -pub const _SC_DELAYTIMER_MAX: ::c_int = 56; -pub const _SC_TIMER_MAX: ::c_int = 57; -pub const _SC_TIMERS: ::c_int = 58; -pub const _SC_CPUTIME: ::c_int = 59; -pub const _SC_THREAD_CPUTIME: ::c_int = 60; - -pub const PTHREAD_STACK_MIN: ::size_t = 8192; - -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - flags: 0, - lock: 0, - unused: -42, - owner: -1, - owner_count: 0, -}; -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - flags: 0, - unused: -42, - mutex: 0 as *mut _, - waiter_count: 0, - lock: 0, -}; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - flags: 0, - owner: -1, - lock_sem: 0, - lock_count: 0, - reader_count: 0, - writer_count: 0, - waiters: [0 as *mut _; 2], -}; - -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = 0; -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 1; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 3; - -pub const FIOCLEX: c_ulong = 0; // TODO: does not exist on Haiku! - -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_RAW: ::c_int = 3; -pub const SOCK_SEQPACKET: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = -1; -pub const SO_ACCEPTCONN: ::c_int = 0x00000001; -pub const SO_BROADCAST: ::c_int = 0x00000002; -pub const SO_DEBUG: ::c_int = 0x00000004; -pub const SO_DONTROUTE: ::c_int = 0x00000008; -pub const SO_KEEPALIVE: ::c_int = 0x00000010; -pub const SO_OOBINLINE: ::c_int = 0x00000020; -pub const SO_REUSEADDR: ::c_int = 0x00000040; -pub const SO_REUSEPORT: ::c_int = 0x00000080; -pub const SO_USELOOPBACK: ::c_int = 0x00000100; -pub const SO_LINGER: ::c_int = 0x00000200; -pub const SO_SNDBUF: ::c_int = 0x40000001; -pub const SO_SNDLOWAT: ::c_int = 0x40000002; -pub const SO_SNDTIMEO: ::c_int = 0x40000003; -pub const SO_RCVBUF: ::c_int = 0x40000004; -pub const SO_RCVLOWAT: ::c_int = 0x40000005; -pub const SO_RCVTIMEO: ::c_int = 0x40000006; -pub const SO_ERROR: ::c_int = 0x40000007; -pub const SO_TYPE: ::c_int = 0x40000008; -pub const SO_NONBLOCK: ::c_int = 0x40000009; -pub const SO_BINDTODEVICE: ::c_int = 0x4000000a; -pub const SO_PEERCRED: ::c_int = 0x4000000b; - -pub const SCM_RIGHTS: ::c_int = 0x01; - -pub const NI_MAXHOST: ::size_t = 1025; - -pub const WNOHANG: ::c_int = 0x01; -pub const WUNTRACED: ::c_int = 0x02; -pub const WCONTINUED: ::c_int = 0x04; -pub const WEXITED: ::c_int = 0x08; -pub const WSTOPPED: ::c_int = 0x10; -pub const WNOWAIT: ::c_int = 0x20; - -pub const P_ALL: idtype_t = 0; -pub const P_PID: idtype_t = 1; -pub const P_PGID: idtype_t = 2; - -pub const UTIME_OMIT: c_long = 1000000001; -pub const UTIME_NOW: c_long = 1000000000; - -pub const VINTR: usize = 0; -pub const VQUIT: usize = 1; -pub const VERASE: usize = 2; -pub const VKILL: usize = 3; -pub const VEOF: usize = 4; -pub const VEOL: usize = 5; -pub const VMIN: usize = 4; -pub const VTIME: usize = 5; -pub const VEOL2: usize = 6; -pub const VSWTCH: usize = 7; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VSUSP: usize = 10; - -pub const IGNBRK: ::tcflag_t = 0x01; -pub const BRKINT: ::tcflag_t = 0x02; -pub const IGNPAR: ::tcflag_t = 0x04; -pub const PARMRK: ::tcflag_t = 0x08; -pub const INPCK: ::tcflag_t = 0x10; -pub const ISTRIP: ::tcflag_t = 0x20; -pub const INLCR: ::tcflag_t = 0x40; -pub const IGNCR: ::tcflag_t = 0x80; -pub const ICRNL: ::tcflag_t = 0x100; -pub const IUCLC: ::tcflag_t = 0x200; -pub const IXON: ::tcflag_t = 0x400; -pub const IXANY: ::tcflag_t = 0x800; -pub const IXOFF: ::tcflag_t = 0x1000; - -pub const OPOST: ::tcflag_t = 0x00000001; -pub const OLCUC: ::tcflag_t = 0x00000002; -pub const ONLCR: ::tcflag_t = 0x00000004; -pub const OCRNL: ::tcflag_t = 0x00000008; -pub const ONOCR: ::tcflag_t = 0x00000010; -pub const ONLRET: ::tcflag_t = 0x00000020; -pub const OFILL: ::tcflag_t = 0x00000040; -pub const OFDEL: ::tcflag_t = 0x00000080; -pub const NLDLY: ::tcflag_t = 0x00000100; -pub const NL0: ::tcflag_t = 0x00000000; -pub const NL1: ::tcflag_t = 0x00000100; -pub const CRDLY: ::tcflag_t = 0x00000600; -pub const CR0: ::tcflag_t = 0x00000000; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const TABDLY: ::tcflag_t = 0x00001800; -pub const TAB0: ::tcflag_t = 0x00000000; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const BSDLY: ::tcflag_t = 0x00002000; -pub const BS0: ::tcflag_t = 0x00000000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VTDLY: ::tcflag_t = 0x00004000; -pub const VT0: ::tcflag_t = 0x00000000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const FFDLY: ::tcflag_t = 0x00008000; -pub const FF0: ::tcflag_t = 0x00000000; -pub const FF1: ::tcflag_t = 0x00008000; - -pub const CSIZE: ::tcflag_t = 0x00000020; -pub const CS5: ::tcflag_t = 0x00000000; -pub const CS6: ::tcflag_t = 0x00000000; -pub const CS7: ::tcflag_t = 0x00000000; -pub const CS8: ::tcflag_t = 0x00000020; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const XLOBLK: ::tcflag_t = 0x00001000; -pub const CTSFLOW: ::tcflag_t = 0x00002000; -pub const RTSFLOW: ::tcflag_t = 0x00004000; -pub const CRTSCTS: ::tcflag_t = RTSFLOW | CTSFLOW; - -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const XCASE: ::tcflag_t = 0x00000004; -pub const ECHO: ::tcflag_t = 0x00000008; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const IEXTEN: ::tcflag_t = 0x00000200; -pub const ECHOCTL: ::tcflag_t = 0x00000400; -pub const ECHOPRT: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00001000; -pub const FLUSHO: ::tcflag_t = 0x00002000; -pub const PENDIN: ::tcflag_t = 0x00004000; - -pub const TCGB_CTS: ::c_int = 0x01; -pub const TCGB_DSR: ::c_int = 0x02; -pub const TCGB_RI: ::c_int = 0x04; -pub const TCGB_DCD: ::c_int = 0x08; -pub const TIOCM_CTS: ::c_int = TCGB_CTS; -pub const TIOCM_CD: ::c_int = TCGB_DCD; -pub const TIOCM_CAR: ::c_int = TIOCM_CD; -pub const TIOCM_RI: ::c_int = TCGB_RI; -pub const TIOCM_DSR: ::c_int = TCGB_DSR; -pub const TIOCM_DTR: ::c_int = 0x10; -pub const TIOCM_RTS: ::c_int = 0x20; - -pub const B0: speed_t = 0x00; -pub const B50: speed_t = 0x01; -pub const B75: speed_t = 0x02; -pub const B110: speed_t = 0x03; -pub const B134: speed_t = 0x04; -pub const B150: speed_t = 0x05; -pub const B200: speed_t = 0x06; -pub const B300: speed_t = 0x07; -pub const B600: speed_t = 0x08; -pub const B1200: speed_t = 0x09; -pub const B1800: speed_t = 0x0A; -pub const B2400: speed_t = 0x0B; -pub const B4800: speed_t = 0x0C; -pub const B9600: speed_t = 0x0D; -pub const B19200: speed_t = 0x0E; -pub const B38400: speed_t = 0x0F; -pub const B57600: speed_t = 0x10; -pub const B115200: speed_t = 0x11; -pub const B230400: speed_t = 0x12; -pub const B31250: speed_t = 0x13; - -pub const TCSANOW: ::c_int = 0x01; -pub const TCSADRAIN: ::c_int = 0x02; -pub const TCSAFLUSH: ::c_int = 0x04; - -pub const TCOOFF: ::c_int = 0x01; -pub const TCOON: ::c_int = 0x02; -pub const TCIOFF: ::c_int = 0x04; -pub const TCION: ::c_int = 0x08; - -pub const TCIFLUSH: ::c_int = 0x01; -pub const TCOFLUSH: ::c_int = 0x02; -pub const TCIOFLUSH: ::c_int = 0x03; - -pub const TCGETA: ::c_int = 0x8000; -pub const TCSETA: ::c_int = TCGETA + 1; -pub const TCSETAF: ::c_int = TCGETA + 2; -pub const TCSETAW: ::c_int = TCGETA + 3; -pub const TCWAITEVENT: ::c_int = TCGETA + 4; -pub const TCSBRK: ::c_int = TCGETA + 5; -pub const TCFLSH: ::c_int = TCGETA + 6; -pub const TCXONC: ::c_int = TCGETA + 7; -pub const TCQUERYCONNECTED: ::c_int = TCGETA + 8; -pub const TCGETBITS: ::c_int = TCGETA + 9; -pub const TCSETDTR: ::c_int = TCGETA + 10; -pub const TCSETRTS: ::c_int = TCGETA + 11; -pub const TIOCGWINSZ: ::c_int = TCGETA + 12; -pub const TIOCSWINSZ: ::c_int = TCGETA + 13; -pub const TCVTIME: ::c_int = TCGETA + 14; -pub const TIOCGPGRP: ::c_int = TCGETA + 15; -pub const TIOCSPGRP: ::c_int = TCGETA + 16; -pub const TIOCSCTTY: ::c_int = TCGETA + 17; -pub const TIOCMGET: ::c_int = TCGETA + 18; -pub const TIOCMSET: ::c_int = TCGETA + 19; -pub const TIOCSBRK: ::c_int = TCGETA + 20; -pub const TIOCCBRK: ::c_int = TCGETA + 21; -pub const TIOCMBIS: ::c_int = TCGETA + 22; -pub const TIOCMBIC: ::c_int = TCGETA + 23; - -f! { - pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return - } - - pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 - } - - pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return - } - - pub fn FD_ZERO(set: *mut fd_set) -> () { - for slot in (*set).fds_bits.iter_mut() { - *slot = 0; - } - } - - pub fn WIFEXITED(status: ::c_int) -> bool { - (status & !0xff) == 0 - } - - pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - (status & 0xff) - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - ((status >> 8) & 0xff) != 0 - } - - pub fn WTERMSIG(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - ((status >> 16) & 0xff) != 0 - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - (status >> 16) & 0xff - } - - // actually WIFCORED, but this is used everywhere else - pub fn WCOREDUMP(status: ::c_int) -> bool { - (status & 0x10000) != 0 - } - - pub fn WIFCONTINUED(status: ::c_int) -> bool { - (status & 0x20000) != 0 - } -} - -extern "C" { - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - pub fn _errnop() -> *mut ::c_int; - - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; - pub fn rand() -> ::c_int; - pub fn srand(seed: ::c_uint); -} - -#[link(name = "bsd")] -extern "C" { - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - - pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; - pub fn clock_settime(clk_id: ::c_int, tp: *const ::timespec) -> ::c_int; - pub fn pthread_create( - thread: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - pub fn pthread_attr_getguardsize( - attr: *const ::pthread_attr_t, - guardsize: *mut ::size_t, - ) -> ::c_int; - pub fn pthread_attr_getstack( - attr: *const ::pthread_attr_t, - stackaddr: *mut *mut ::c_void, - stacksize: *mut ::size_t, - ) -> ::c_int; - pub fn pthread_condattr_getclock( - attr: *const pthread_condattr_t, - clock_id: *mut clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_setclock( - attr: *mut pthread_condattr_t, - clock_id: ::clockid_t, - ) -> ::c_int; - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; - pub fn setgroups(ngroups: ::size_t, ptr: *const ::gid_t) -> ::c_int; - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - pub fn mprotect( - addr: *const ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::size_t, - serv: *mut ::c_char, - sevlen: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn waitid( - idtype: idtype_t, - id: id_t, - infop: *mut ::siginfo_t, - options: ::c_int, - ) -> ::c_int; - - pub fn glob( - pattern: *const ::c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut ::glob_t, - ) -> ::c_int; - pub fn globfree(pglob: *mut ::glob_t); - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn posix_madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn shm_open( - name: *const ::c_char, - oflag: ::c_int, - mode: ::mode_t, - ) -> ::c_int; - pub fn shm_unlink(name: *const ::c_char) -> ::c_int; - - pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); - - pub fn telldir(dirp: *mut ::DIR) -> ::c_long; - pub fn madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn msync( - addr: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::c_int; - - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; - pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; - pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; - pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; - - pub fn bind( - socket: ::c_int, - address: *const ::sockaddr, - address_len: ::socklen_t, - ) -> ::c_int; - - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - - pub fn sendmsg( - fd: ::c_int, - msg: *const ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - pub fn recvmsg( - fd: ::c_int, - msg: *mut ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - pub fn execvpe( - file: *const ::c_char, - argv: *const *const ::c_char, - environment: *const *const ::c_char, - ) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r( - gid: ::gid_t, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigaltstack$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] - pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; - pub fn sem_close(sem: *mut sem_t) -> ::c_int; - pub fn getdtablesize() -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")] - pub fn getgrnam_r( - name: *const ::c_char, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_sigmask$UNIX2003" - )] - pub fn pthread_sigmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; - pub fn getgrnam(name: *const ::c_char) -> *mut ::group; - pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; - pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")] - pub fn getpwnam_r( - name: *const ::c_char, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")] - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigwait$UNIX2003" - )] - #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] - pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn getgrgid(gid: ::gid_t) -> *mut ::group; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "popen$UNIX2003" - )] - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - pub fn openpty( - amaster: *mut ::c_int, - aslave: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::c_int; - pub fn forkpty( - amaster: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::pid_t; - pub fn sethostname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn uname(buf: *mut ::utsname) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_pointer_width = "64")] { - mod b64; - pub use self::b64::*; - } else { - mod b32; - pub use self::b32::*; - } -} diff --git a/libc/src/unix/hermit/aarch64.rs b/libc/src/unix/hermit/aarch64.rs deleted file mode 100644 index 1a92e3b..0000000 --- a/libc/src/unix/hermit/aarch64.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; diff --git a/libc/src/unix/hermit/mod.rs b/libc/src/unix/hermit/mod.rs deleted file mode 100644 index 83e064e..0000000 --- a/libc/src/unix/hermit/mod.rs +++ /dev/null @@ -1,1049 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// liblibc port for HermitCore (https://hermitcore.org) -// HermitCore is a unikernel based on lwIP, newlib, and -// pthread-embedded. -// Consider these definitions when porting liblibc to another -// lwIP/newlib/pte-based target. -// -// Ported by Colin Finck - -pub type c_long = i64; -pub type c_ulong = u64; - -pub type speed_t = ::c_uint; -pub type mode_t = u32; -pub type dev_t = i16; -pub type nfds_t = ::c_ulong; -pub type socklen_t = u32; -pub type sa_family_t = u8; -pub type clock_t = c_ulong; -pub type time_t = c_long; -pub type suseconds_t = c_long; -pub type off_t = i64; -pub type rlim_t = ::c_ulonglong; -pub type sigset_t = ::c_ulong; -pub type ino_t = u16; -pub type nlink_t = u16; -pub type blksize_t = c_long; -pub type blkcnt_t = c_long; -pub type stat64 = stat; -pub type clockid_t = c_ulong; -pub type pthread_t = pte_handle_t; -pub type pthread_attr_t = usize; -pub type pthread_cond_t = usize; -pub type pthread_condattr_t = usize; -pub type pthread_key_t = usize; -pub type pthread_mutex_t = usize; -pub type pthread_mutexattr_t = usize; -pub type pthread_rwlock_t = usize; -pub type pthread_rwlockattr_t = usize; - -s_no_extra_traits! { - pub struct dirent { - pub d_ino: ::c_long, - pub d_off: off_t, - pub d_reclen: u16, - pub d_name: [::c_char; 256], - } - - // Dummy - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 108], - } - - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [::c_char; 8], - } - - pub struct fd_set { - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], - } - - pub struct sockaddr_storage { - pub s2_len: u8, - pub ss_family: sa_family_t, - pub s2_data1: [::c_char; 2], - pub s2_data2: [u32; 3], - pub s2_data3: [u32; 3], - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: dev_t, - pub st_size: off_t, - pub st_atime: time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: blksize_t, - pub st_blocks: blkcnt_t, - pub st_spare4: [::c_long; 2], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for sockaddr_un { - fn eq(&self, other: &sockaddr_un) -> bool { - self.sun_family == other.sun_family - && self - .sun_path - .iter() - .zip(other.sun_path.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr_un {} - impl ::fmt::Debug for sockaddr_un { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_un") - .field("sun_family", &self.sun_family) - // FIXME: .field("sun_path", &self.sun_path) - .finish() - } - } - impl ::hash::Hash for sockaddr_un { - fn hash(&self, state: &mut H) { - self.sun_family.hash(state); - self.sun_path.hash(state); - } - } - - impl PartialEq for sockaddr { - fn eq(&self, other: &sockaddr) -> bool { - self.sa_len == other.sa_len - && self.sa_family == other.sa_family - && self - .sa_data - .iter() - .zip(other.sa_data.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr {} - impl ::fmt::Debug for sockaddr { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr") - .field("sa_len", &self.sa_len) - .field("sa_family", &self.sa_family) - // FIXME: .field("sa_data", &self.sa_data) - .finish() - } - } - impl ::hash::Hash for sockaddr { - fn hash(&self, state: &mut H) { - self.sa_len.hash(state); - self.sa_family.hash(state); - self.sa_data.hash(state); - } - } - - impl PartialEq for sockaddr_in { - fn eq(&self, other: &sockaddr_in) -> bool { - self.sin_len == other.sin_len - && self.sin_family == other.sin_family - && self.sin_port == other.sin_port - && self.sin_addr == other.sin_addr - && self - .sin_zero - .iter() - .zip(other.sin_zero.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr_in {} - impl ::fmt::Debug for sockaddr_in { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_in") - .field("sin_len", &self.sin_len) - .field("sin_family", &self.sin_family) - .field("sin_port", &self.sin_port) - .field("sin_addr", &self.sin_addr) - // FIXME: .field("sin_zero", &self.sin_zero) - .finish() - } - } - impl ::hash::Hash for sockaddr_in { - fn hash(&self, state: &mut H) { - self.sin_len.hash(state); - self.sin_family.hash(state); - self.sin_port.hash(state); - self.sin_addr.hash(state); - self.sin_zero.hash(state); - } - } - - impl PartialEq for fd_set { - fn eq(&self, other: &fd_set) -> bool { - self.fds_bits - .iter() - .zip(other.fds_bits.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for fd_set {} - impl ::fmt::Debug for fd_set { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("fd_set") - // FIXME: .field("fds_bits", &self.fds_bits) - .finish() - } - } - impl ::hash::Hash for fd_set { - fn hash(&self, state: &mut H) { - self.fds_bits.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.s2_len == other.s2_len - && self.ss_family == other.ss_family - && self.s2_data1 - .iter() - .zip(other.s2_data1.iter()) - .all(|(a,b)| a == b) - && self.s2_data2 - .iter() - .zip(other.s2_data2.iter()) - .all(|(a,b)| a == b) - && self.s2_data3 - .iter() - .zip(other.s2_data3.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr_storage {} - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("s2_len", &self.s2_len) - .field("ss_family", &self.ss_family) - // FIXME: .field("s2_data1", &self.s2_data1) - // FIXME: .field("s2_data2", &self.s2_data2) - // FIXME: .field("s2_data3", &self.s2_data3) - .finish() - } - } - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.s2_len.hash(state); - self.ss_family.hash(state); - self.s2_data1.hash(state); - self.s2_data2.hash(state); - self.s2_data3.hash(state); - } - } - - impl PartialEq for stat { - fn eq(&self, other: &stat) -> bool { - self.st_dev == other.st_dev - && self.st_ino == other.st_ino - && self.st_mode == other.st_mode - && self.st_nlink == other.st_nlink - && self.st_uid == other.st_uid - && self.st_gid == other.st_gid - && self.st_rdev == other.st_rdev - && self.st_size == other.st_size - && self.st_atime == other.st_atime - && self.st_atime_nsec == other.st_atime_nsec - && self.st_mtime == other.st_mtime - && self.st_mtime_nsec == other.st_mtime_nsec - && self.st_ctime == other.st_ctime - && self.st_ctime_nsec == other.st_ctime_nsec - && self.st_blksize == other.st_blksize - && self.st_blocks == other.st_blocks - && self - .st_spare4 - .iter() - .zip(other.st_spare4.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for stat {} - impl ::fmt::Debug for stat { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("stat") - .field("st_dev", &self.st_dev) - .field("st_ino", &self.st_ino) - .field("st_mode", &self.st_mode) - .field("st_nlink", &self.st_nlink) - .field("st_uid", &self.st_uid) - .field("st_gid", &self.st_gid) - .field("st_rdev", &self.st_rdev) - .field("st_size", &self.st_size) - .field("st_atime", &self.st_atime) - .field("st_atime_nsec", &self.st_atime_nsec) - .field("st_mtime", &self.st_mtime) - .field("st_mtime_nsec", &self.st_mtime_nsec) - .field("st_ctime", &self.st_ctime) - .field("st_ctime_nsec", &self.st_ctime_nsec) - .field("st_blksize", &self.st_blksize) - .field("st_blocks", &self.st_blocks) - // FIXME: .field("st_spare4", &self.st_spare4) - .finish() - } - } - impl ::hash::Hash for stat { - fn hash(&self, state: &mut H) { - self.st_dev.hash(state); - self.st_ino.hash(state); - self.st_mode.hash(state); - self.st_nlink.hash(state); - self.st_uid.hash(state); - self.st_gid.hash(state); - self.st_rdev.hash(state); - self.st_size.hash(state); - self.st_atime.hash(state); - self.st_atime_nsec.hash(state); - self.st_mtime.hash(state); - self.st_mtime_nsec.hash(state); - self.st_ctime.hash(state); - self.st_ctime_nsec.hash(state); - self.st_blksize.hash(state); - self.st_blocks.hash(state); - self.st_spare4.hash(state); - } - } - } -} - -s! { - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: socklen_t, - pub ai_addr: *mut ::sockaddr, - pub ai_canonname: *mut c_char, - pub ai_next: *mut addrinfo, - } - - pub struct Dl_info {} - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct passwd { // Unverified - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct pte_handle_t { - pub p: usize, - pub x: ::c_uint, - } - - pub struct sched_param { - pub sched_priority: ::c_int, - } - - pub struct sem_t { - pub value: i32, - pub lock: usize, - pub sem: usize, - } - - pub struct sigaction { - pub sa_flags: ::c_int, - pub sa_mask: sigset_t, - pub sa_handler: usize, - } - - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct statvfs {} - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - } - - pub struct tms { - pub tms_utime: ::clock_t, - pub tms_stime: ::clock_t, - pub tms_cutime: ::clock_t, - pub tms_cstime: ::clock_t, - } - - pub struct termios {} - - pub struct utsname {} -} - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_INET: ::c_int = 2; -pub const AF_INET6: ::c_int = 10; - -// Dummy -pub const AF_UNIX: ::c_int = 1; - -pub const CLOCK_REALTIME: ::clockid_t = 1; -pub const CLOCK_MONOTONIC: ::clockid_t = 4; - -// Dummy -pub const EAI_SYSTEM: ::c_int = -11; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EAGAIN: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const EWOULDBLOCK: ::c_int = EAGAIN; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EDEADLOCK: ::c_int = EDEADLK; -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EMULTIHOP: ::c_int = 72; -pub const EDOTDOT: ::c_int = 73; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; -pub const F_GETOWN: ::c_int = 5; -pub const F_SETOWN: ::c_int = 6; -pub const F_GETLK: ::c_int = 7; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; -pub const F_RGETLK: ::c_int = 10; -pub const F_RSETLK: ::c_int = 11; -pub const F_CNVT: ::c_int = 12; -pub const F_RSETLKW: ::c_int = 13; -pub const F_DUPFD_CLOEXEC: ::c_int = 14; - -pub const FD_SETSIZE: usize = 1024; - -// Dummy -pub const FIOCLEX: ::c_int = 0x5451; - -pub const FIONBIO: ::c_int = 0x8004667e; -pub const FIONREAD: ::c_int = 0x4004667f; - -pub const IP_ADD_MEMBERSHIP: ::c_int = 3; -pub const IP_DROP_MEMBERSHIP: ::c_int = 4; - -pub const IP_TOS: ::c_int = 1; -pub const IP_TTL: ::c_int = 2; - -pub const IP_MULTICAST_TTL: ::c_int = 5; -pub const IP_MULTICAST_IF: ::c_int = 6; -pub const IP_MULTICAST_LOOP: ::c_int = 7; - -pub const IPV6_JOIN_GROUP: ::c_int = 12; -pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12; -pub const IPV6_LEAVE_GROUP: ::c_int = 13; -pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13; -pub const IPV6_V6ONLY: ::c_int = 27; - -// Dummy -pub const IPV6_MULTICAST_LOOP: ::c_int = 7; - -pub const MSG_PEEK: ::c_int = 0x01; -pub const MSG_WAITALL: ::c_int = 0x02; -pub const MSG_OOB: ::c_int = 0x04; -pub const MSG_DONTWAIT: ::c_int = 0x08; -pub const MSG_MORE: ::c_int = 0x10; - -pub const O_ACCMODE: ::c_int = 3; -pub const O_RDONLY: ::c_int = 0; -pub const O_WRONLY: ::c_int = 1; -pub const O_RDWR: ::c_int = 2; -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_TRUNC: ::c_int = 512; -pub const O_CLOEXEC: ::c_int = 524288; - -pub const POLLIN: ::c_short = 0x1; -pub const POLLPRI: ::c_short = 0x2; -pub const POLLOUT: ::c_short = 0x4; -pub const POLLERR: ::c_short = 0x8; -pub const POLLHUP: ::c_short = 0x10; -pub const POLLNVAL: ::c_short = 0x20; - -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = usize::max_value(); -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = usize::max_value(); -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = usize::max_value(); - -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_STACK_MIN: ::size_t = 0; - -// Dummy -pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; - -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_CHILD_MAX: ::c_int = 1; -pub const _SC_CLK_TCK: ::c_int = 2; -pub const _SC_NGROUPS_MAX: ::c_int = 3; -pub const _SC_OPEN_MAX: ::c_int = 4; -pub const _SC_JOB_CONTROL: ::c_int = 5; -pub const _SC_SAVED_IDS: ::c_int = 6; -pub const _SC_VERSION: ::c_int = 7; -pub const _SC_PAGESIZE: ::c_int = 8; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_NPROCESSORS_CONF: ::c_int = 9; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 10; -pub const _SC_PHYS_PAGES: ::c_int = 11; -pub const _SC_AVPHYS_PAGES: ::c_int = 12; -pub const _SC_MQ_OPEN_MAX: ::c_int = 13; -pub const _SC_MQ_PRIO_MAX: ::c_int = 14; -pub const _SC_RTSIG_MAX: ::c_int = 15; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 16; -pub const _SC_SEM_VALUE_MAX: ::c_int = 17; -pub const _SC_SIGQUEUE_MAX: ::c_int = 18; -pub const _SC_TIMER_MAX: ::c_int = 19; -pub const _SC_TZNAME_MAX: ::c_int = 20; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 21; -pub const _SC_FSYNC: ::c_int = 22; -pub const _SC_MAPPED_FILES: ::c_int = 23; -pub const _SC_MEMLOCK: ::c_int = 24; -pub const _SC_MEMLOCK_RANGE: ::c_int = 25; -pub const _SC_MEMORY_PROTECTION: ::c_int = 26; -pub const _SC_MESSAGE_PASSING: ::c_int = 27; -pub const _SC_PRIORITIZED_IO: ::c_int = 28; -pub const _SC_REALTIME_SIGNALS: ::c_int = 29; -pub const _SC_SEMAPHORES: ::c_int = 30; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 31; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 32; -pub const _SC_TIMERS: ::c_int = 33; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 34; -pub const _SC_AIO_MAX: ::c_int = 35; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 36; -pub const _SC_DELAYTIMER_MAX: ::c_int = 37; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 38; -pub const _SC_THREAD_STACK_MIN: ::c_int = 39; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 40; -pub const _SC_TTY_NAME_MAX: ::c_int = 41; -pub const _SC_THREADS: ::c_int = 42; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 43; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 44; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 45; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 46; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 47; -pub const _SC_THREAD_PRIO_CEILING: ::c_int = _SC_THREAD_PRIO_PROTECT; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 48; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 49; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 50; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 52; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 53; -pub const _SC_ADVISORY_INFO: ::c_int = 54; -pub const _SC_ATEXIT_MAX: ::c_int = 55; -pub const _SC_BARRIERS: ::c_int = 56; -pub const _SC_BC_BASE_MAX: ::c_int = 57; -pub const _SC_BC_DIM_MAX: ::c_int = 58; -pub const _SC_BC_SCALE_MAX: ::c_int = 59; -pub const _SC_BC_STRING_MAX: ::c_int = 60; -pub const _SC_CLOCK_SELECTION: ::c_int = 61; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 62; -pub const _SC_CPUTIME: ::c_int = 63; -pub const _SC_EXPR_NEST_MAX: ::c_int = 64; -pub const _SC_HOST_NAME_MAX: ::c_int = 65; -pub const _SC_IOV_MAX: ::c_int = 66; -pub const _SC_IPV6: ::c_int = 67; -pub const _SC_LINE_MAX: ::c_int = 68; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 69; -pub const _SC_RAW_SOCKETS: ::c_int = 70; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 71; -pub const _SC_REGEXP: ::c_int = 72; -pub const _SC_RE_DUP_MAX: ::c_int = 73; -pub const _SC_SHELL: ::c_int = 74; -pub const _SC_SPAWN: ::c_int = 75; -pub const _SC_SPIN_LOCKS: ::c_int = 76; -pub const _SC_SPORADIC_SERVER: ::c_int = 77; -pub const _SC_SS_REPL_MAX: ::c_int = 78; -pub const _SC_SYMLOOP_MAX: ::c_int = 79; -pub const _SC_THREAD_CPUTIME: ::c_int = 80; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 81; -pub const _SC_TIMEOUTS: ::c_int = 82; -pub const _SC_TRACE: ::c_int = 83; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 84; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 85; -pub const _SC_TRACE_INHERIT: ::c_int = 86; -pub const _SC_TRACE_LOG: ::c_int = 87; -pub const _SC_TRACE_NAME_MAX: ::c_int = 88; -pub const _SC_TRACE_SYS_MAX: ::c_int = 89; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 90; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 91; -pub const _SC_V7_ILP32_OFF32: ::c_int = 92; -pub const _SC_V6_ILP32_OFF32: ::c_int = _SC_V7_ILP32_OFF32; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = _SC_V7_ILP32_OFF32; -pub const _SC_V7_ILP32_OFFBIG: ::c_int = 93; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = _SC_V7_ILP32_OFFBIG; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = _SC_V7_ILP32_OFFBIG; -pub const _SC_V7_LP64_OFF64: ::c_int = 94; -pub const _SC_V6_LP64_OFF64: ::c_int = _SC_V7_LP64_OFF64; -pub const _SC_XBS5_LP64_OFF64: ::c_int = _SC_V7_LP64_OFF64; -pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 95; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = _SC_V7_LPBIG_OFFBIG; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = _SC_V7_LPBIG_OFFBIG; -pub const _SC_XOPEN_CRYPT: ::c_int = 96; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 97; -pub const _SC_XOPEN_LEGACY: ::c_int = 98; -pub const _SC_XOPEN_REALTIME: ::c_int = 99; -pub const _SC_STREAM_MAX: ::c_int = 100; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 101; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 102; -pub const _SC_XOPEN_SHM: ::c_int = 103; -pub const _SC_XOPEN_STREAMS: ::c_int = 104; -pub const _SC_XOPEN_UNIX: ::c_int = 105; -pub const _SC_XOPEN_VERSION: ::c_int = 106; -pub const _SC_2_CHAR_TERM: ::c_int = 107; -pub const _SC_2_C_BIND: ::c_int = 108; -pub const _SC_2_C_DEV: ::c_int = 109; -pub const _SC_2_FORT_DEV: ::c_int = 110; -pub const _SC_2_FORT_RUN: ::c_int = 111; -pub const _SC_2_LOCALEDEF: ::c_int = 112; -pub const _SC_2_PBS: ::c_int = 113; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 114; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 115; -pub const _SC_2_PBS_LOCATE: ::c_int = 116; -pub const _SC_2_PBS_MESSAGE: ::c_int = 117; -pub const _SC_2_PBS_TRACK: ::c_int = 118; -pub const _SC_2_SW_DEV: ::c_int = 119; -pub const _SC_2_UPE: ::c_int = 120; -pub const _SC_2_VERSION: ::c_int = 121; -pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 122; -pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 123; -pub const _SC_XOPEN_UUCP: ::c_int = 124; -pub const _SC_LEVEL1_ICACHE_SIZE: ::c_int = 125; -pub const _SC_LEVEL1_ICACHE_ASSOC: ::c_int = 126; -pub const _SC_LEVEL1_ICACHE_LINESIZE: ::c_int = 127; -pub const _SC_LEVEL1_DCACHE_SIZE: ::c_int = 128; -pub const _SC_LEVEL1_DCACHE_ASSOC: ::c_int = 129; -pub const _SC_LEVEL1_DCACHE_LINESIZE: ::c_int = 130; -pub const _SC_LEVEL2_CACHE_SIZE: ::c_int = 131; -pub const _SC_LEVEL2_CACHE_ASSOC: ::c_int = 132; -pub const _SC_LEVEL2_CACHE_LINESIZE: ::c_int = 133; -pub const _SC_LEVEL3_CACHE_SIZE: ::c_int = 134; -pub const _SC_LEVEL3_CACHE_ASSOC: ::c_int = 135; -pub const _SC_LEVEL3_CACHE_LINESIZE: ::c_int = 136; -pub const _SC_LEVEL4_CACHE_SIZE: ::c_int = 137; -pub const _SC_LEVEL4_CACHE_ASSOC: ::c_int = 138; -pub const _SC_LEVEL4_CACHE_LINESIZE: ::c_int = 139; - -pub const S_BLKSIZE: ::mode_t = 1024; -pub const S_IREAD: ::mode_t = 256; -pub const S_IWRITE: ::mode_t = 128; -pub const S_IEXEC: ::mode_t = 64; -pub const S_ENFMT: ::mode_t = 1024; -pub const S_IFMT: ::mode_t = 61440; -pub const S_IFDIR: ::mode_t = 16384; -pub const S_IFCHR: ::mode_t = 8192; -pub const S_IFBLK: ::mode_t = 24576; -pub const S_IFREG: ::mode_t = 32768; -pub const S_IFLNK: ::mode_t = 40960; -pub const S_IFSOCK: ::mode_t = 49152; -pub const S_IFIFO: ::mode_t = 4096; -pub const S_IRUSR: ::mode_t = 256; -pub const S_IWUSR: ::mode_t = 128; -pub const S_IXUSR: ::mode_t = 64; -pub const S_IRGRP: ::mode_t = 32; -pub const S_IWGRP: ::mode_t = 16; -pub const S_IXGRP: ::mode_t = 8; -pub const S_IROTH: ::mode_t = 4; -pub const S_IWOTH: ::mode_t = 2; -pub const S_IXOTH: ::mode_t = 1; - -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const SIG_SETMASK: ::c_int = 0; - -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGABRT: ::c_int = 6; -pub const SIGEMT: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSEGV: ::c_int = 11; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; - -pub const SO_DEBUG: ::c_int = 0x0001; -pub const SO_ACCEPTCONN: ::c_int = 0x0002; -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_USELOOPBACK: ::c_int = 0x0040; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_CONTIMEO: ::c_int = 0x1009; -pub const SO_NO_CHECK: ::c_int = 0x100a; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_RAW: ::c_int = 3; - -pub const SOL_SOCKET: ::c_int = 0xfff; - -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; - -pub const TCP_NODELAY: ::c_int = 0x01; -pub const TCP_KEEPALIVE: ::c_int = 0x02; -pub const TCP_KEEPIDLE: ::c_int = 0x03; -pub const TCP_KEEPINTVL: ::c_int = 0x04; -pub const TCP_KEEPCNT: ::c_int = 0x05; - -const ULONG_SIZE: usize = 64; - -pub const WNOHANG: ::c_int = 0x00000001; - -f! { - pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WIFEXITED(status: ::c_int) -> bool { - (status & 0xff) == 0 - } - - pub fn WTERMSIG(status: ::c_int) -> ::c_int { - status & 0x7f - } -} - -extern "C" { - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; - pub fn rand() -> ::c_int; - pub fn srand(seed: ::c_uint); - - pub fn bind( - s: ::c_int, - name: *const ::sockaddr, - namelen: ::socklen_t, - ) -> ::c_int; - - pub fn clock_gettime( - clock_id: ::clockid_t, - tp: *mut ::timespec, - ) -> ::c_int; - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - - // Dummy - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - - pub fn memalign(align: ::size_t, nbytes: ::size_t) -> *mut ::c_void; - - pub fn pthread_create( - tid: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - start: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - arg: *mut ::c_void, - ) -> ::c_int; - - pub fn pthread_sigmask( - how: ::c_int, - set: *const ::sigset_t, - oset: *mut ::sigset_t, - ) -> ::c_int; - - pub fn recvfrom( - s: ::c_int, - mem: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - from: *mut ::sockaddr, - fromlen: *mut ::socklen_t, - ) -> ::c_int; - - pub fn setgroups(ngroups: ::c_int, grouplist: *const ::gid_t) -> ::c_int; - pub fn uname(buf: *mut ::utsname) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/hermit/x86_64.rs b/libc/src/unix/hermit/x86_64.rs deleted file mode 100644 index 76ec3ce..0000000 --- a/libc/src/unix/hermit/x86_64.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; diff --git a/libc/src/unix/linux_like/android/b32/arm.rs b/libc/src/unix/linux_like/android/b32/arm.rs deleted file mode 100644 index 1320b16..0000000 --- a/libc/src/unix/linux_like/android/b32/arm.rs +++ /dev/null @@ -1,357 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; - -pub const O_DIRECT: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_LARGEFILE: ::c_int = 0o400000; - -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_pause: ::c_long = 29; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS_getdents: ::c_long = 141; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_poll: ::c_long = 168; -pub const SYS_nfsservctl: ::c_long = 169; -pub const SYS_setresgid: ::c_long = 170; -pub const SYS_getresgid: ::c_long = 171; -pub const SYS_prctl: ::c_long = 172; -pub const SYS_rt_sigreturn: ::c_long = 173; -pub const SYS_rt_sigaction: ::c_long = 174; -pub const SYS_rt_sigprocmask: ::c_long = 175; -pub const SYS_rt_sigpending: ::c_long = 176; -pub const SYS_rt_sigtimedwait: ::c_long = 177; -pub const SYS_rt_sigqueueinfo: ::c_long = 178; -pub const SYS_rt_sigsuspend: ::c_long = 179; -pub const SYS_pread64: ::c_long = 180; -pub const SYS_pwrite64: ::c_long = 181; -pub const SYS_chown: ::c_long = 182; -pub const SYS_getcwd: ::c_long = 183; -pub const SYS_capget: ::c_long = 184; -pub const SYS_capset: ::c_long = 185; -pub const SYS_sigaltstack: ::c_long = 186; -pub const SYS_sendfile: ::c_long = 187; -pub const SYS_vfork: ::c_long = 190; -pub const SYS_ugetrlimit: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_lchown32: ::c_long = 198; -pub const SYS_getuid32: ::c_long = 199; -pub const SYS_getgid32: ::c_long = 200; -pub const SYS_geteuid32: ::c_long = 201; -pub const SYS_getegid32: ::c_long = 202; -pub const SYS_setreuid32: ::c_long = 203; -pub const SYS_setregid32: ::c_long = 204; -pub const SYS_getgroups32: ::c_long = 205; -pub const SYS_setgroups32: ::c_long = 206; -pub const SYS_fchown32: ::c_long = 207; -pub const SYS_setresuid32: ::c_long = 208; -pub const SYS_getresuid32: ::c_long = 209; -pub const SYS_setresgid32: ::c_long = 210; -pub const SYS_getresgid32: ::c_long = 211; -pub const SYS_chown32: ::c_long = 212; -pub const SYS_setuid32: ::c_long = 213; -pub const SYS_setgid32: ::c_long = 214; -pub const SYS_setfsuid32: ::c_long = 215; -pub const SYS_setfsgid32: ::c_long = 216; -pub const SYS_getdents64: ::c_long = 217; -pub const SYS_pivot_root: ::c_long = 218; -pub const SYS_mincore: ::c_long = 219; -pub const SYS_madvise: ::c_long = 220; -pub const SYS_fcntl64: ::c_long = 221; -pub const SYS_gettid: ::c_long = 224; -pub const SYS_readahead: ::c_long = 225; -pub const SYS_setxattr: ::c_long = 226; -pub const SYS_lsetxattr: ::c_long = 227; -pub const SYS_fsetxattr: ::c_long = 228; -pub const SYS_getxattr: ::c_long = 229; -pub const SYS_lgetxattr: ::c_long = 230; -pub const SYS_fgetxattr: ::c_long = 231; -pub const SYS_listxattr: ::c_long = 232; -pub const SYS_llistxattr: ::c_long = 233; -pub const SYS_flistxattr: ::c_long = 234; -pub const SYS_removexattr: ::c_long = 235; -pub const SYS_lremovexattr: ::c_long = 236; -pub const SYS_fremovexattr: ::c_long = 237; -pub const SYS_tkill: ::c_long = 238; -pub const SYS_sendfile64: ::c_long = 239; -pub const SYS_futex: ::c_long = 240; -pub const SYS_sched_setaffinity: ::c_long = 241; -pub const SYS_sched_getaffinity: ::c_long = 242; -pub const SYS_io_setup: ::c_long = 243; -pub const SYS_io_destroy: ::c_long = 244; -pub const SYS_io_getevents: ::c_long = 245; -pub const SYS_io_submit: ::c_long = 246; -pub const SYS_io_cancel: ::c_long = 247; -pub const SYS_exit_group: ::c_long = 248; -pub const SYS_lookup_dcookie: ::c_long = 249; -pub const SYS_epoll_create: ::c_long = 250; -pub const SYS_epoll_ctl: ::c_long = 251; -pub const SYS_epoll_wait: ::c_long = 252; -pub const SYS_remap_file_pages: ::c_long = 253; -pub const SYS_set_tid_address: ::c_long = 256; -pub const SYS_timer_create: ::c_long = 257; -pub const SYS_timer_settime: ::c_long = 258; -pub const SYS_timer_gettime: ::c_long = 259; -pub const SYS_timer_getoverrun: ::c_long = 260; -pub const SYS_timer_delete: ::c_long = 261; -pub const SYS_clock_settime: ::c_long = 262; -pub const SYS_clock_gettime: ::c_long = 263; -pub const SYS_clock_getres: ::c_long = 264; -pub const SYS_clock_nanosleep: ::c_long = 265; -pub const SYS_statfs64: ::c_long = 266; -pub const SYS_fstatfs64: ::c_long = 267; -pub const SYS_tgkill: ::c_long = 268; -pub const SYS_utimes: ::c_long = 269; -pub const SYS_arm_fadvise64_64: ::c_long = 270; -pub const SYS_pciconfig_iobase: ::c_long = 271; -pub const SYS_pciconfig_read: ::c_long = 272; -pub const SYS_pciconfig_write: ::c_long = 273; -pub const SYS_mq_open: ::c_long = 274; -pub const SYS_mq_unlink: ::c_long = 275; -pub const SYS_mq_timedsend: ::c_long = 276; -pub const SYS_mq_timedreceive: ::c_long = 277; -pub const SYS_mq_notify: ::c_long = 278; -pub const SYS_mq_getsetattr: ::c_long = 279; -pub const SYS_waitid: ::c_long = 280; -pub const SYS_socket: ::c_long = 281; -pub const SYS_bind: ::c_long = 282; -pub const SYS_connect: ::c_long = 283; -pub const SYS_listen: ::c_long = 284; -pub const SYS_accept: ::c_long = 285; -pub const SYS_getsockname: ::c_long = 286; -pub const SYS_getpeername: ::c_long = 287; -pub const SYS_socketpair: ::c_long = 288; -pub const SYS_send: ::c_long = 289; -pub const SYS_sendto: ::c_long = 290; -pub const SYS_recv: ::c_long = 291; -pub const SYS_recvfrom: ::c_long = 292; -pub const SYS_shutdown: ::c_long = 293; -pub const SYS_setsockopt: ::c_long = 294; -pub const SYS_getsockopt: ::c_long = 295; -pub const SYS_sendmsg: ::c_long = 296; -pub const SYS_recvmsg: ::c_long = 297; -pub const SYS_semop: ::c_long = 298; -pub const SYS_semget: ::c_long = 299; -pub const SYS_semctl: ::c_long = 300; -pub const SYS_msgsnd: ::c_long = 301; -pub const SYS_msgrcv: ::c_long = 302; -pub const SYS_msgget: ::c_long = 303; -pub const SYS_msgctl: ::c_long = 304; -pub const SYS_shmat: ::c_long = 305; -pub const SYS_shmdt: ::c_long = 306; -pub const SYS_shmget: ::c_long = 307; -pub const SYS_shmctl: ::c_long = 308; -pub const SYS_add_key: ::c_long = 309; -pub const SYS_request_key: ::c_long = 310; -pub const SYS_keyctl: ::c_long = 311; -pub const SYS_semtimedop: ::c_long = 312; -pub const SYS_vserver: ::c_long = 313; -pub const SYS_ioprio_set: ::c_long = 314; -pub const SYS_ioprio_get: ::c_long = 315; -pub const SYS_inotify_init: ::c_long = 316; -pub const SYS_inotify_add_watch: ::c_long = 317; -pub const SYS_inotify_rm_watch: ::c_long = 318; -pub const SYS_mbind: ::c_long = 319; -pub const SYS_get_mempolicy: ::c_long = 320; -pub const SYS_set_mempolicy: ::c_long = 321; -pub const SYS_openat: ::c_long = 322; -pub const SYS_mkdirat: ::c_long = 323; -pub const SYS_mknodat: ::c_long = 324; -pub const SYS_fchownat: ::c_long = 325; -pub const SYS_futimesat: ::c_long = 326; -pub const SYS_fstatat64: ::c_long = 327; -pub const SYS_unlinkat: ::c_long = 328; -pub const SYS_renameat: ::c_long = 329; -pub const SYS_linkat: ::c_long = 330; -pub const SYS_symlinkat: ::c_long = 331; -pub const SYS_readlinkat: ::c_long = 332; -pub const SYS_fchmodat: ::c_long = 333; -pub const SYS_faccessat: ::c_long = 334; -pub const SYS_pselect6: ::c_long = 335; -pub const SYS_ppoll: ::c_long = 336; -pub const SYS_unshare: ::c_long = 337; -pub const SYS_set_robust_list: ::c_long = 338; -pub const SYS_get_robust_list: ::c_long = 339; -pub const SYS_splice: ::c_long = 340; -pub const SYS_arm_sync_file_range: ::c_long = 341; -pub const SYS_tee: ::c_long = 342; -pub const SYS_vmsplice: ::c_long = 343; -pub const SYS_move_pages: ::c_long = 344; -pub const SYS_getcpu: ::c_long = 345; -pub const SYS_epoll_pwait: ::c_long = 346; -pub const SYS_kexec_load: ::c_long = 347; -pub const SYS_utimensat: ::c_long = 348; -pub const SYS_signalfd: ::c_long = 349; -pub const SYS_timerfd_create: ::c_long = 350; -pub const SYS_eventfd: ::c_long = 351; -pub const SYS_fallocate: ::c_long = 352; -pub const SYS_timerfd_settime: ::c_long = 353; -pub const SYS_timerfd_gettime: ::c_long = 354; -pub const SYS_signalfd4: ::c_long = 355; -pub const SYS_eventfd2: ::c_long = 356; -pub const SYS_epoll_create1: ::c_long = 357; -pub const SYS_dup3: ::c_long = 358; -pub const SYS_pipe2: ::c_long = 359; -pub const SYS_inotify_init1: ::c_long = 360; -pub const SYS_preadv: ::c_long = 361; -pub const SYS_pwritev: ::c_long = 362; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 363; -pub const SYS_perf_event_open: ::c_long = 364; -pub const SYS_recvmmsg: ::c_long = 365; -pub const SYS_accept4: ::c_long = 366; -pub const SYS_fanotify_init: ::c_long = 367; -pub const SYS_fanotify_mark: ::c_long = 368; -pub const SYS_prlimit64: ::c_long = 369; -pub const SYS_name_to_handle_at: ::c_long = 370; -pub const SYS_open_by_handle_at: ::c_long = 371; -pub const SYS_clock_adjtime: ::c_long = 372; -pub const SYS_syncfs: ::c_long = 373; -pub const SYS_sendmmsg: ::c_long = 374; -pub const SYS_setns: ::c_long = 375; -pub const SYS_process_vm_readv: ::c_long = 376; -pub const SYS_process_vm_writev: ::c_long = 377; -pub const SYS_kcmp: ::c_long = 378; -pub const SYS_finit_module: ::c_long = 379; -pub const SYS_sched_setattr: ::c_long = 380; -pub const SYS_sched_getattr: ::c_long = 381; -pub const SYS_renameat2: ::c_long = 382; -pub const SYS_seccomp: ::c_long = 383; -pub const SYS_getrandom: ::c_long = 384; -pub const SYS_memfd_create: ::c_long = 385; -pub const SYS_bpf: ::c_long = 386; -pub const SYS_execveat: ::c_long = 387; -pub const SYS_userfaultfd: ::c_long = 388; -pub const SYS_membarrier: ::c_long = 389; -pub const SYS_mlock2: ::c_long = 390; -pub const SYS_copy_file_range: ::c_long = 391; -pub const SYS_preadv2: ::c_long = 392; -pub const SYS_pwritev2: ::c_long = 393; -pub const SYS_pkey_mprotect: ::c_long = 394; -pub const SYS_pkey_alloc: ::c_long = 395; -pub const SYS_pkey_free: ::c_long = 396; diff --git a/libc/src/unix/linux_like/android/b32/mod.rs b/libc/src/unix/linux_like/android/b32/mod.rs deleted file mode 100644 index e5c97e9..0000000 --- a/libc/src/unix/linux_like/android/b32/mod.rs +++ /dev/null @@ -1,221 +0,0 @@ -// The following definitions are correct for arm and i686, -// but may be wrong for mips - -pub type c_long = i32; -pub type c_ulong = u32; -pub type mode_t = u16; -pub type off64_t = ::c_longlong; -pub type sigset_t = ::c_ulong; -pub type socklen_t = i32; -pub type time64_t = i64; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct rlimit64 { - pub rlim_cur: u64, - pub rlim_max: u64, - } - - pub struct stat { - pub st_dev: ::c_ulonglong, - __pad0: [::c_uchar; 4], - __st_ino: ::ino_t, - pub st_mode: ::c_uint, - pub st_nlink: ::c_uint, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulonglong, - __pad3: [::c_uchar; 4], - pub st_size: ::c_longlong, - pub st_blksize: ::blksize_t, - pub st_blocks: ::c_ulonglong, - pub st_atime: ::c_long, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::c_long, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::c_long, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::c_ulonglong, - } - - pub struct stat64 { - pub st_dev: ::c_ulonglong, - __pad0: [::c_uchar; 4], - __st_ino: ::ino_t, - pub st_mode: ::c_uint, - pub st_nlink: ::c_uint, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulonglong, - __pad3: [::c_uchar; 4], - pub st_size: ::c_longlong, - pub st_blksize: ::blksize_t, - pub st_blocks: ::c_ulonglong, - pub st_atime: ::c_long, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::c_long, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::c_long, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::c_ulonglong, - } - - pub struct statfs64 { - pub f_type: u32, - pub f_bsize: u32, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - f_fsid: [u32; 2], - pub f_namelen: u32, - pub f_frsize: u32, - pub f_flags: u32, - pub f_spare: [u32; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::c_ulong, - pub f_bfree: ::c_ulong, - pub f_bavail: ::c_ulong, - pub f_files: ::c_ulong, - pub f_ffree: ::c_ulong, - pub f_favail: ::c_ulong, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - } - - pub struct pthread_attr_t { - pub flags: u32, - pub stack_base: *mut ::c_void, - pub stack_size: ::size_t, - pub guard_size: ::size_t, - pub sched_policy: i32, - pub sched_priority: i32, - } - - pub struct pthread_mutex_t { value: ::c_int } - - pub struct pthread_cond_t { value: ::c_int } - - pub struct pthread_rwlock_t { - lock: pthread_mutex_t, - cond: pthread_cond_t, - numLocks: ::c_int, - writerThreadId: ::c_int, - pendingReaders: ::c_int, - pendingWriters: ::c_int, - attr: i32, - __reserved: [::c_char; 12], - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct statfs { - pub f_type: u32, - pub f_bsize: u32, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::__fsid_t, - pub f_namelen: u32, - pub f_frsize: u32, - pub f_flags: u32, - pub f_spare: [u32; 4], - } - - pub struct sysinfo { - pub uptime: ::c_long, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub _f: [::c_char; 8], - } -} - -// These constants must be of the same type of sigaction.sa_flags -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; - -pub const RTLD_GLOBAL: ::c_int = 2; -pub const RTLD_NOW: ::c_int = 0; -pub const RTLD_DEFAULT: *mut ::c_void = -1isize as *mut ::c_void; - -pub const PTRACE_GETFPREGS: ::c_int = 14; -pub const PTRACE_SETFPREGS: ::c_int = 15; -pub const PTRACE_GETREGS: ::c_int = 12; -pub const PTRACE_SETREGS: ::c_int = 13; - -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = - pthread_mutex_t { value: 0 }; -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = - pthread_cond_t { value: 0 }; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - lock: PTHREAD_MUTEX_INITIALIZER, - cond: PTHREAD_COND_INITIALIZER, - numLocks: 0, - writerThreadId: 0, - pendingReaders: 0, - pendingWriters: 0, - attr: 0, - __reserved: [0; 12], -}; -pub const PTHREAD_STACK_MIN: ::size_t = 4096 * 2; -pub const CPU_SETSIZE: ::size_t = 32; -pub const __CPU_BITS: ::size_t = 32; - -pub const UT_LINESIZE: usize = 8; -pub const UT_NAMESIZE: usize = 8; -pub const UT_HOSTSIZE: usize = 16; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; - -extern "C" { - pub fn timegm64(tm: *const ::tm) -> ::time64_t; -} - -cfg_if! { - if #[cfg(target_arch = "x86")] { - mod x86; - pub use self::x86::*; - } else if #[cfg(target_arch = "arm")] { - mod arm; - pub use self::arm::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/linux_like/android/b32/x86/align.rs b/libc/src/unix/linux_like/android/b32/x86/align.rs deleted file mode 100644 index 04df4a0..0000000 --- a/libc/src/unix/linux_like/android/b32/x86/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(8))] - pub struct max_align_t { - priv_: [f64; 2] - } -} diff --git a/libc/src/unix/linux_like/android/b32/x86/mod.rs b/libc/src/unix/linux_like/android/b32/x86/mod.rs deleted file mode 100644 index 101bf2d..0000000 --- a/libc/src/unix/linux_like/android/b32/x86/mod.rs +++ /dev/null @@ -1,422 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; - -pub const O_DIRECT: ::c_int = 0x4000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; -pub const O_LARGEFILE: ::c_int = 0o0100000; - -pub const MAP_32BIT: ::c_int = 0x40; - -// Syscall table -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_waitpid: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_time: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_break: ::c_long = 17; -pub const SYS_oldstat: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_umount: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_stime: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_oldfstat: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_stty: ::c_long = 31; -pub const SYS_gtty: ::c_long = 32; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_ftime: ::c_long = 35; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_prof: ::c_long = 44; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_lock: ::c_long = 53; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_mpx: ::c_long = 56; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_ulimit: ::c_long = 58; -pub const SYS_oldolduname: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_sgetmask: ::c_long = 68; -pub const SYS_ssetmask: ::c_long = 69; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrlimit: ::c_long = 76; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_select: ::c_long = 82; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_oldlstat: ::c_long = 84; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_readdir: ::c_long = 89; -pub const SYS_mmap: ::c_long = 90; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_profil: ::c_long = 98; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_ioperm: ::c_long = 101; -pub const SYS_socketcall: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_olduname: ::c_long = 109; -pub const SYS_iopl: ::c_long = 110; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_idle: ::c_long = 112; -pub const SYS_vm86old: ::c_long = 113; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_ipc: ::c_long = 117; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_modify_ldt: ::c_long = 123; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_create_module: ::c_long = 127; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_get_kernel_syms: ::c_long = 130; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_afs_syscall: ::c_long = 137; -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -// FIXME: SYS__llseek is in the NDK sources but for some reason is -// not available in the tests -// pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -// FIXME: SYS__newselect is in the NDK sources but for some reason is -// not available in the tests -// pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -// FIXME: SYS__llseek is in the NDK sources but for some reason is -// not available in the tests -// pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_vm86: ::c_long = 166; -pub const SYS_query_module: ::c_long = 167; -pub const SYS_poll: ::c_long = 168; -pub const SYS_nfsservctl: ::c_long = 169; -pub const SYS_setresgid: ::c_long = 170; -pub const SYS_getresgid: ::c_long = 171; -pub const SYS_prctl: ::c_long = 172; -pub const SYS_rt_sigreturn: ::c_long = 173; -pub const SYS_rt_sigaction: ::c_long = 174; -pub const SYS_rt_sigprocmask: ::c_long = 175; -pub const SYS_rt_sigpending: ::c_long = 176; -pub const SYS_rt_sigtimedwait: ::c_long = 177; -pub const SYS_rt_sigqueueinfo: ::c_long = 178; -pub const SYS_rt_sigsuspend: ::c_long = 179; -pub const SYS_pread64: ::c_long = 180; -pub const SYS_pwrite64: ::c_long = 181; -pub const SYS_chown: ::c_long = 182; -pub const SYS_getcwd: ::c_long = 183; -pub const SYS_capget: ::c_long = 184; -pub const SYS_capset: ::c_long = 185; -pub const SYS_sigaltstack: ::c_long = 186; -pub const SYS_sendfile: ::c_long = 187; -pub const SYS_getpmsg: ::c_long = 188; -pub const SYS_putpmsg: ::c_long = 189; -pub const SYS_vfork: ::c_long = 190; -pub const SYS_ugetrlimit: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_lchown32: ::c_long = 198; -pub const SYS_getuid32: ::c_long = 199; -pub const SYS_getgid32: ::c_long = 200; -pub const SYS_geteuid32: ::c_long = 201; -pub const SYS_getegid32: ::c_long = 202; -pub const SYS_setreuid32: ::c_long = 203; -pub const SYS_setregid32: ::c_long = 204; -pub const SYS_getgroups32: ::c_long = 205; -pub const SYS_setgroups32: ::c_long = 206; -pub const SYS_fchown32: ::c_long = 207; -pub const SYS_setresuid32: ::c_long = 208; -pub const SYS_getresuid32: ::c_long = 209; -pub const SYS_setresgid32: ::c_long = 210; -pub const SYS_getresgid32: ::c_long = 211; -pub const SYS_chown32: ::c_long = 212; -pub const SYS_setuid32: ::c_long = 213; -pub const SYS_setgid32: ::c_long = 214; -pub const SYS_setfsuid32: ::c_long = 215; -pub const SYS_setfsgid32: ::c_long = 216; -pub const SYS_pivot_root: ::c_long = 217; -pub const SYS_mincore: ::c_long = 218; -pub const SYS_madvise: ::c_long = 219; -pub const SYS_getdents64: ::c_long = 220; -pub const SYS_fcntl64: ::c_long = 221; -pub const SYS_gettid: ::c_long = 224; -pub const SYS_readahead: ::c_long = 225; -pub const SYS_setxattr: ::c_long = 226; -pub const SYS_lsetxattr: ::c_long = 227; -pub const SYS_fsetxattr: ::c_long = 228; -pub const SYS_getxattr: ::c_long = 229; -pub const SYS_lgetxattr: ::c_long = 230; -pub const SYS_fgetxattr: ::c_long = 231; -pub const SYS_listxattr: ::c_long = 232; -pub const SYS_llistxattr: ::c_long = 233; -pub const SYS_flistxattr: ::c_long = 234; -pub const SYS_removexattr: ::c_long = 235; -pub const SYS_lremovexattr: ::c_long = 236; -pub const SYS_fremovexattr: ::c_long = 237; -pub const SYS_tkill: ::c_long = 238; -pub const SYS_sendfile64: ::c_long = 239; -pub const SYS_futex: ::c_long = 240; -pub const SYS_sched_setaffinity: ::c_long = 241; -pub const SYS_sched_getaffinity: ::c_long = 242; -pub const SYS_set_thread_area: ::c_long = 243; -pub const SYS_get_thread_area: ::c_long = 244; -pub const SYS_io_setup: ::c_long = 245; -pub const SYS_io_destroy: ::c_long = 246; -pub const SYS_io_getevents: ::c_long = 247; -pub const SYS_io_submit: ::c_long = 248; -pub const SYS_io_cancel: ::c_long = 249; -pub const SYS_fadvise64: ::c_long = 250; -pub const SYS_exit_group: ::c_long = 252; -pub const SYS_lookup_dcookie: ::c_long = 253; -pub const SYS_epoll_create: ::c_long = 254; -pub const SYS_epoll_ctl: ::c_long = 255; -pub const SYS_epoll_wait: ::c_long = 256; -pub const SYS_remap_file_pages: ::c_long = 257; -pub const SYS_set_tid_address: ::c_long = 258; -pub const SYS_timer_create: ::c_long = 259; -pub const SYS_timer_settime: ::c_long = 260; -pub const SYS_timer_gettime: ::c_long = 261; -pub const SYS_timer_getoverrun: ::c_long = 262; -pub const SYS_timer_delete: ::c_long = 263; -pub const SYS_clock_settime: ::c_long = 264; -pub const SYS_clock_gettime: ::c_long = 265; -pub const SYS_clock_getres: ::c_long = 266; -pub const SYS_clock_nanosleep: ::c_long = 267; -pub const SYS_statfs64: ::c_long = 268; -pub const SYS_fstatfs64: ::c_long = 269; -pub const SYS_tgkill: ::c_long = 270; -pub const SYS_utimes: ::c_long = 271; -pub const SYS_fadvise64_64: ::c_long = 272; -pub const SYS_vserver: ::c_long = 273; -pub const SYS_mbind: ::c_long = 274; -pub const SYS_get_mempolicy: ::c_long = 275; -pub const SYS_set_mempolicy: ::c_long = 276; -pub const SYS_mq_open: ::c_long = 277; -pub const SYS_mq_unlink: ::c_long = 278; -pub const SYS_mq_timedsend: ::c_long = 279; -pub const SYS_mq_timedreceive: ::c_long = 280; -pub const SYS_mq_notify: ::c_long = 281; -pub const SYS_mq_getsetattr: ::c_long = 282; -pub const SYS_kexec_load: ::c_long = 283; -pub const SYS_waitid: ::c_long = 284; -pub const SYS_add_key: ::c_long = 286; -pub const SYS_request_key: ::c_long = 287; -pub const SYS_keyctl: ::c_long = 288; -pub const SYS_ioprio_set: ::c_long = 289; -pub const SYS_ioprio_get: ::c_long = 290; -pub const SYS_inotify_init: ::c_long = 291; -pub const SYS_inotify_add_watch: ::c_long = 292; -pub const SYS_inotify_rm_watch: ::c_long = 293; -pub const SYS_migrate_pages: ::c_long = 294; -pub const SYS_openat: ::c_long = 295; -pub const SYS_mkdirat: ::c_long = 296; -pub const SYS_mknodat: ::c_long = 297; -pub const SYS_fchownat: ::c_long = 298; -pub const SYS_futimesat: ::c_long = 299; -pub const SYS_fstatat64: ::c_long = 300; -pub const SYS_unlinkat: ::c_long = 301; -pub const SYS_renameat: ::c_long = 302; -pub const SYS_linkat: ::c_long = 303; -pub const SYS_symlinkat: ::c_long = 304; -pub const SYS_readlinkat: ::c_long = 305; -pub const SYS_fchmodat: ::c_long = 306; -pub const SYS_faccessat: ::c_long = 307; -pub const SYS_pselect6: ::c_long = 308; -pub const SYS_ppoll: ::c_long = 309; -pub const SYS_unshare: ::c_long = 310; -pub const SYS_set_robust_list: ::c_long = 311; -pub const SYS_get_robust_list: ::c_long = 312; -pub const SYS_splice: ::c_long = 313; -pub const SYS_sync_file_range: ::c_long = 314; -pub const SYS_tee: ::c_long = 315; -pub const SYS_vmsplice: ::c_long = 316; -pub const SYS_move_pages: ::c_long = 317; -pub const SYS_getcpu: ::c_long = 318; -pub const SYS_epoll_pwait: ::c_long = 319; -pub const SYS_utimensat: ::c_long = 320; -pub const SYS_signalfd: ::c_long = 321; -pub const SYS_timerfd_create: ::c_long = 322; -pub const SYS_eventfd: ::c_long = 323; -pub const SYS_fallocate: ::c_long = 324; -pub const SYS_timerfd_settime: ::c_long = 325; -pub const SYS_timerfd_gettime: ::c_long = 326; -pub const SYS_signalfd4: ::c_long = 327; -pub const SYS_eventfd2: ::c_long = 328; -pub const SYS_epoll_create1: ::c_long = 329; -pub const SYS_dup3: ::c_long = 330; -pub const SYS_pipe2: ::c_long = 331; -pub const SYS_inotify_init1: ::c_long = 332; -pub const SYS_preadv: ::c_long = 333; -pub const SYS_pwritev: ::c_long = 334; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 335; -pub const SYS_perf_event_open: ::c_long = 336; -pub const SYS_recvmmsg: ::c_long = 337; -pub const SYS_fanotify_init: ::c_long = 338; -pub const SYS_fanotify_mark: ::c_long = 339; -pub const SYS_prlimit64: ::c_long = 340; -pub const SYS_name_to_handle_at: ::c_long = 341; -pub const SYS_open_by_handle_at: ::c_long = 342; -pub const SYS_clock_adjtime: ::c_long = 343; -pub const SYS_syncfs: ::c_long = 344; -pub const SYS_sendmmsg: ::c_long = 345; -pub const SYS_setns: ::c_long = 346; -pub const SYS_process_vm_readv: ::c_long = 347; -pub const SYS_process_vm_writev: ::c_long = 348; -pub const SYS_kcmp: ::c_long = 349; -pub const SYS_finit_module: ::c_long = 350; -pub const SYS_sched_setattr: ::c_long = 351; -pub const SYS_sched_getattr: ::c_long = 352; -pub const SYS_renameat2: ::c_long = 353; -pub const SYS_seccomp: ::c_long = 354; -pub const SYS_getrandom: ::c_long = 355; -pub const SYS_memfd_create: ::c_long = 356; -pub const SYS_bpf: ::c_long = 357; -pub const SYS_execveat: ::c_long = 358; -pub const SYS_socket: ::c_long = 359; -pub const SYS_socketpair: ::c_long = 360; -pub const SYS_bind: ::c_long = 361; -pub const SYS_connect: ::c_long = 362; -pub const SYS_listen: ::c_long = 363; -pub const SYS_accept4: ::c_long = 364; -pub const SYS_getsockopt: ::c_long = 365; -pub const SYS_setsockopt: ::c_long = 366; -pub const SYS_getsockname: ::c_long = 367; -pub const SYS_getpeername: ::c_long = 368; -pub const SYS_sendto: ::c_long = 369; -pub const SYS_sendmsg: ::c_long = 370; -pub const SYS_recvfrom: ::c_long = 371; -pub const SYS_recvmsg: ::c_long = 372; -pub const SYS_shutdown: ::c_long = 373; -pub const SYS_userfaultfd: ::c_long = 374; -pub const SYS_membarrier: ::c_long = 375; -pub const SYS_mlock2: ::c_long = 376; -pub const SYS_copy_file_range: ::c_long = 377; -pub const SYS_preadv2: ::c_long = 378; -pub const SYS_pwritev2: ::c_long = 379; -pub const SYS_pkey_mprotect: ::c_long = 380; -pub const SYS_pkey_alloc: ::c_long = 381; -pub const SYS_pkey_free: ::c_long = 382; - -// offsets in user_regs_structs, from sys/reg.h -pub const EBX: ::c_int = 0; -pub const ECX: ::c_int = 1; -pub const EDX: ::c_int = 2; -pub const ESI: ::c_int = 3; -pub const EDI: ::c_int = 4; -pub const EBP: ::c_int = 5; -pub const EAX: ::c_int = 6; -pub const DS: ::c_int = 7; -pub const ES: ::c_int = 8; -pub const FS: ::c_int = 9; -pub const GS: ::c_int = 10; -pub const ORIG_EAX: ::c_int = 11; -pub const EIP: ::c_int = 12; -pub const CS: ::c_int = 13; -pub const EFL: ::c_int = 14; -pub const UESP: ::c_int = 15; -pub const SS: ::c_int = 16; - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/android/b64/aarch64/align.rs b/libc/src/unix/linux_like/android/b64/aarch64/align.rs deleted file mode 100644 index 8e94996..0000000 --- a/libc/src/unix/linux_like/android/b64/aarch64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f32; 8] - } -} diff --git a/libc/src/unix/linux_like/android/b64/aarch64/mod.rs b/libc/src/unix/linux_like/android/b64/aarch64/mod.rs deleted file mode 100644 index b2b9188..0000000 --- a/libc/src/unix/linux_like/android/b64/aarch64/mod.rs +++ /dev/null @@ -1,332 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::c_uint, - pub st_nlink: ::c_uint, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad1: ::c_ulong, - pub st_size: ::off64_t, - pub st_blksize: ::c_int, - __pad2: ::c_int, - pub st_blocks: ::c_long, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused4: ::c_uint, - __unused5: ::c_uint, - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::c_uint, - pub st_nlink: ::c_uint, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad1: ::c_ulong, - pub st_size: ::off64_t, - pub st_blksize: ::c_int, - __pad2: ::c_int, - pub st_blocks: ::c_long, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused4: ::c_uint, - __unused5: ::c_uint, - } -} - -pub const O_DIRECT: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_LARGEFILE: ::c_int = 0o400000; - -pub const SIGSTKSZ: ::size_t = 16384; -pub const MINSIGSTKSZ: ::size_t = 5120; - -pub const SYS_io_setup: ::c_long = 0; -pub const SYS_io_destroy: ::c_long = 1; -pub const SYS_io_submit: ::c_long = 2; -pub const SYS_io_cancel: ::c_long = 3; -pub const SYS_io_getevents: ::c_long = 4; -pub const SYS_setxattr: ::c_long = 5; -pub const SYS_lsetxattr: ::c_long = 6; -pub const SYS_fsetxattr: ::c_long = 7; -pub const SYS_getxattr: ::c_long = 8; -pub const SYS_lgetxattr: ::c_long = 9; -pub const SYS_fgetxattr: ::c_long = 10; -pub const SYS_listxattr: ::c_long = 11; -pub const SYS_llistxattr: ::c_long = 12; -pub const SYS_flistxattr: ::c_long = 13; -pub const SYS_removexattr: ::c_long = 14; -pub const SYS_lremovexattr: ::c_long = 15; -pub const SYS_fremovexattr: ::c_long = 16; -pub const SYS_getcwd: ::c_long = 17; -pub const SYS_lookup_dcookie: ::c_long = 18; -pub const SYS_eventfd2: ::c_long = 19; -pub const SYS_epoll_create1: ::c_long = 20; -pub const SYS_epoll_ctl: ::c_long = 21; -pub const SYS_epoll_pwait: ::c_long = 22; -pub const SYS_dup: ::c_long = 23; -pub const SYS_dup3: ::c_long = 24; -pub const SYS_inotify_init1: ::c_long = 26; -pub const SYS_inotify_add_watch: ::c_long = 27; -pub const SYS_inotify_rm_watch: ::c_long = 28; -pub const SYS_ioctl: ::c_long = 29; -pub const SYS_ioprio_set: ::c_long = 30; -pub const SYS_ioprio_get: ::c_long = 31; -pub const SYS_flock: ::c_long = 32; -pub const SYS_mknodat: ::c_long = 33; -pub const SYS_mkdirat: ::c_long = 34; -pub const SYS_unlinkat: ::c_long = 35; -pub const SYS_symlinkat: ::c_long = 36; -pub const SYS_linkat: ::c_long = 37; -pub const SYS_renameat: ::c_long = 38; -pub const SYS_umount2: ::c_long = 39; -pub const SYS_mount: ::c_long = 40; -pub const SYS_pivot_root: ::c_long = 41; -pub const SYS_nfsservctl: ::c_long = 42; -pub const SYS_fallocate: ::c_long = 47; -pub const SYS_faccessat: ::c_long = 48; -pub const SYS_chdir: ::c_long = 49; -pub const SYS_fchdir: ::c_long = 50; -pub const SYS_chroot: ::c_long = 51; -pub const SYS_fchmod: ::c_long = 52; -pub const SYS_fchmodat: ::c_long = 53; -pub const SYS_fchownat: ::c_long = 54; -pub const SYS_fchown: ::c_long = 55; -pub const SYS_openat: ::c_long = 56; -pub const SYS_close: ::c_long = 57; -pub const SYS_vhangup: ::c_long = 58; -pub const SYS_pipe2: ::c_long = 59; -pub const SYS_quotactl: ::c_long = 60; -pub const SYS_getdents64: ::c_long = 61; -pub const SYS_read: ::c_long = 63; -pub const SYS_write: ::c_long = 64; -pub const SYS_readv: ::c_long = 65; -pub const SYS_writev: ::c_long = 66; -pub const SYS_pread64: ::c_long = 67; -pub const SYS_pwrite64: ::c_long = 68; -pub const SYS_preadv: ::c_long = 69; -pub const SYS_pwritev: ::c_long = 70; -pub const SYS_pselect6: ::c_long = 72; -pub const SYS_ppoll: ::c_long = 73; -pub const SYS_signalfd4: ::c_long = 74; -pub const SYS_vmsplice: ::c_long = 75; -pub const SYS_splice: ::c_long = 76; -pub const SYS_tee: ::c_long = 77; -pub const SYS_readlinkat: ::c_long = 78; -pub const SYS_sync: ::c_long = 81; -pub const SYS_fsync: ::c_long = 82; -pub const SYS_fdatasync: ::c_long = 83; -pub const SYS_sync_file_range: ::c_long = 84; -pub const SYS_timerfd_create: ::c_long = 85; -pub const SYS_timerfd_settime: ::c_long = 86; -pub const SYS_timerfd_gettime: ::c_long = 87; -pub const SYS_utimensat: ::c_long = 88; -pub const SYS_acct: ::c_long = 89; -pub const SYS_capget: ::c_long = 90; -pub const SYS_capset: ::c_long = 91; -pub const SYS_personality: ::c_long = 92; -pub const SYS_exit: ::c_long = 93; -pub const SYS_exit_group: ::c_long = 94; -pub const SYS_waitid: ::c_long = 95; -pub const SYS_set_tid_address: ::c_long = 96; -pub const SYS_unshare: ::c_long = 97; -pub const SYS_futex: ::c_long = 98; -pub const SYS_set_robust_list: ::c_long = 99; -pub const SYS_get_robust_list: ::c_long = 100; -pub const SYS_nanosleep: ::c_long = 101; -pub const SYS_getitimer: ::c_long = 102; -pub const SYS_setitimer: ::c_long = 103; -pub const SYS_kexec_load: ::c_long = 104; -pub const SYS_init_module: ::c_long = 105; -pub const SYS_delete_module: ::c_long = 106; -pub const SYS_timer_create: ::c_long = 107; -pub const SYS_timer_gettime: ::c_long = 108; -pub const SYS_timer_getoverrun: ::c_long = 109; -pub const SYS_timer_settime: ::c_long = 110; -pub const SYS_timer_delete: ::c_long = 111; -pub const SYS_clock_settime: ::c_long = 112; -pub const SYS_clock_gettime: ::c_long = 113; -pub const SYS_clock_getres: ::c_long = 114; -pub const SYS_clock_nanosleep: ::c_long = 115; -pub const SYS_syslog: ::c_long = 116; -pub const SYS_ptrace: ::c_long = 117; -pub const SYS_sched_setparam: ::c_long = 118; -pub const SYS_sched_setscheduler: ::c_long = 119; -pub const SYS_sched_getscheduler: ::c_long = 120; -pub const SYS_sched_getparam: ::c_long = 121; -pub const SYS_sched_setaffinity: ::c_long = 122; -pub const SYS_sched_getaffinity: ::c_long = 123; -pub const SYS_sched_yield: ::c_long = 124; -pub const SYS_sched_get_priority_max: ::c_long = 125; -pub const SYS_sched_get_priority_min: ::c_long = 126; -pub const SYS_sched_rr_get_interval: ::c_long = 127; -pub const SYS_restart_syscall: ::c_long = 128; -pub const SYS_kill: ::c_long = 129; -pub const SYS_tkill: ::c_long = 130; -pub const SYS_tgkill: ::c_long = 131; -pub const SYS_sigaltstack: ::c_long = 132; -pub const SYS_rt_sigsuspend: ::c_long = 133; -pub const SYS_rt_sigaction: ::c_long = 134; -pub const SYS_rt_sigprocmask: ::c_long = 135; -pub const SYS_rt_sigpending: ::c_long = 136; -pub const SYS_rt_sigtimedwait: ::c_long = 137; -pub const SYS_rt_sigqueueinfo: ::c_long = 138; -pub const SYS_rt_sigreturn: ::c_long = 139; -pub const SYS_setpriority: ::c_long = 140; -pub const SYS_getpriority: ::c_long = 141; -pub const SYS_reboot: ::c_long = 142; -pub const SYS_setregid: ::c_long = 143; -pub const SYS_setgid: ::c_long = 144; -pub const SYS_setreuid: ::c_long = 145; -pub const SYS_setuid: ::c_long = 146; -pub const SYS_setresuid: ::c_long = 147; -pub const SYS_getresuid: ::c_long = 148; -pub const SYS_setresgid: ::c_long = 149; -pub const SYS_getresgid: ::c_long = 150; -pub const SYS_setfsuid: ::c_long = 151; -pub const SYS_setfsgid: ::c_long = 152; -pub const SYS_times: ::c_long = 153; -pub const SYS_setpgid: ::c_long = 154; -pub const SYS_getpgid: ::c_long = 155; -pub const SYS_getsid: ::c_long = 156; -pub const SYS_setsid: ::c_long = 157; -pub const SYS_getgroups: ::c_long = 158; -pub const SYS_setgroups: ::c_long = 159; -pub const SYS_uname: ::c_long = 160; -pub const SYS_sethostname: ::c_long = 161; -pub const SYS_setdomainname: ::c_long = 162; -pub const SYS_getrlimit: ::c_long = 163; -pub const SYS_setrlimit: ::c_long = 164; -pub const SYS_getrusage: ::c_long = 165; -pub const SYS_umask: ::c_long = 166; -pub const SYS_prctl: ::c_long = 167; -pub const SYS_getcpu: ::c_long = 168; -pub const SYS_gettimeofday: ::c_long = 169; -pub const SYS_settimeofday: ::c_long = 170; -pub const SYS_adjtimex: ::c_long = 171; -pub const SYS_getpid: ::c_long = 172; -pub const SYS_getppid: ::c_long = 173; -pub const SYS_getuid: ::c_long = 174; -pub const SYS_geteuid: ::c_long = 175; -pub const SYS_getgid: ::c_long = 176; -pub const SYS_getegid: ::c_long = 177; -pub const SYS_gettid: ::c_long = 178; -pub const SYS_sysinfo: ::c_long = 179; -pub const SYS_mq_open: ::c_long = 180; -pub const SYS_mq_unlink: ::c_long = 181; -pub const SYS_mq_timedsend: ::c_long = 182; -pub const SYS_mq_timedreceive: ::c_long = 183; -pub const SYS_mq_notify: ::c_long = 184; -pub const SYS_mq_getsetattr: ::c_long = 185; -pub const SYS_msgget: ::c_long = 186; -pub const SYS_msgctl: ::c_long = 187; -pub const SYS_msgrcv: ::c_long = 188; -pub const SYS_msgsnd: ::c_long = 189; -pub const SYS_semget: ::c_long = 190; -pub const SYS_semctl: ::c_long = 191; -pub const SYS_semtimedop: ::c_long = 192; -pub const SYS_semop: ::c_long = 193; -pub const SYS_shmget: ::c_long = 194; -pub const SYS_shmctl: ::c_long = 195; -pub const SYS_shmat: ::c_long = 196; -pub const SYS_shmdt: ::c_long = 197; -pub const SYS_socket: ::c_long = 198; -pub const SYS_socketpair: ::c_long = 199; -pub const SYS_bind: ::c_long = 200; -pub const SYS_listen: ::c_long = 201; -pub const SYS_accept: ::c_long = 202; -pub const SYS_connect: ::c_long = 203; -pub const SYS_getsockname: ::c_long = 204; -pub const SYS_getpeername: ::c_long = 205; -pub const SYS_sendto: ::c_long = 206; -pub const SYS_recvfrom: ::c_long = 207; -pub const SYS_setsockopt: ::c_long = 208; -pub const SYS_getsockopt: ::c_long = 209; -pub const SYS_shutdown: ::c_long = 210; -pub const SYS_sendmsg: ::c_long = 211; -pub const SYS_recvmsg: ::c_long = 212; -pub const SYS_readahead: ::c_long = 213; -pub const SYS_brk: ::c_long = 214; -pub const SYS_munmap: ::c_long = 215; -pub const SYS_mremap: ::c_long = 216; -pub const SYS_add_key: ::c_long = 217; -pub const SYS_request_key: ::c_long = 218; -pub const SYS_keyctl: ::c_long = 219; -pub const SYS_clone: ::c_long = 220; -pub const SYS_execve: ::c_long = 221; -pub const SYS_swapon: ::c_long = 224; -pub const SYS_swapoff: ::c_long = 225; -pub const SYS_mprotect: ::c_long = 226; -pub const SYS_msync: ::c_long = 227; -pub const SYS_mlock: ::c_long = 228; -pub const SYS_munlock: ::c_long = 229; -pub const SYS_mlockall: ::c_long = 230; -pub const SYS_munlockall: ::c_long = 231; -pub const SYS_mincore: ::c_long = 232; -pub const SYS_madvise: ::c_long = 233; -pub const SYS_remap_file_pages: ::c_long = 234; -pub const SYS_mbind: ::c_long = 235; -pub const SYS_get_mempolicy: ::c_long = 236; -pub const SYS_set_mempolicy: ::c_long = 237; -pub const SYS_migrate_pages: ::c_long = 238; -pub const SYS_move_pages: ::c_long = 239; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 240; -pub const SYS_perf_event_open: ::c_long = 241; -pub const SYS_accept4: ::c_long = 242; -pub const SYS_recvmmsg: ::c_long = 243; -pub const SYS_arch_specific_syscall: ::c_long = 244; -pub const SYS_wait4: ::c_long = 260; -pub const SYS_prlimit64: ::c_long = 261; -pub const SYS_fanotify_init: ::c_long = 262; -pub const SYS_fanotify_mark: ::c_long = 263; -pub const SYS_name_to_handle_at: ::c_long = 264; -pub const SYS_open_by_handle_at: ::c_long = 265; -pub const SYS_clock_adjtime: ::c_long = 266; -pub const SYS_syncfs: ::c_long = 267; -pub const SYS_setns: ::c_long = 268; -pub const SYS_sendmmsg: ::c_long = 269; -pub const SYS_process_vm_readv: ::c_long = 270; -pub const SYS_process_vm_writev: ::c_long = 271; -pub const SYS_kcmp: ::c_long = 272; -pub const SYS_finit_module: ::c_long = 273; -pub const SYS_sched_setattr: ::c_long = 274; -pub const SYS_sched_getattr: ::c_long = 275; -pub const SYS_renameat2: ::c_long = 276; -pub const SYS_seccomp: ::c_long = 277; -pub const SYS_getrandom: ::c_long = 278; -pub const SYS_memfd_create: ::c_long = 279; -pub const SYS_bpf: ::c_long = 280; -pub const SYS_execveat: ::c_long = 281; -pub const SYS_userfaultfd: ::c_long = 282; -pub const SYS_membarrier: ::c_long = 283; -pub const SYS_mlock2: ::c_long = 284; -pub const SYS_copy_file_range: ::c_long = 285; -pub const SYS_preadv2: ::c_long = 286; -pub const SYS_pwritev2: ::c_long = 287; -pub const SYS_pkey_mprotect: ::c_long = 288; -pub const SYS_pkey_alloc: ::c_long = 289; -pub const SYS_pkey_free: ::c_long = 290; -pub const SYS_syscalls: ::c_long = 292; - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/android/b64/mod.rs b/libc/src/unix/linux_like/android/b64/mod.rs deleted file mode 100644 index 9826bb9..0000000 --- a/libc/src/unix/linux_like/android/b64/mod.rs +++ /dev/null @@ -1,281 +0,0 @@ -// The following definitions are correct for aarch64 and x86_64, -// but may be wrong for mips64 - -pub type c_long = i64; -pub type c_ulong = u64; -pub type mode_t = u32; -pub type off64_t = i64; -pub type socklen_t = u32; - -s! { - pub struct sigset_t { - __val: [::c_ulong; 1], - } - - pub struct sigaction { - pub sa_flags: ::c_int, - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_restorer: ::Option, - } - - pub struct rlimit64 { - pub rlim_cur: ::c_ulonglong, - pub rlim_max: ::c_ulonglong, - } - - pub struct pthread_attr_t { - pub flags: u32, - pub stack_base: *mut ::c_void, - pub stack_size: ::size_t, - pub guard_size: ::size_t, - pub sched_policy: i32, - pub sched_priority: i32, - __reserved: [::c_char; 16], - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct statfs { - pub f_type: u64, - pub f_bsize: u64, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::__fsid_t, - pub f_namelen: u64, - pub f_frsize: u64, - pub f_flags: u64, - pub f_spare: [u64; 4], - } - - pub struct sysinfo { - pub uptime: ::c_long, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub _f: [::c_char; 0], - } - - pub struct statfs64 { - pub f_type: u64, - pub f_bsize: u64, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - f_fsid: [u32; 2], - pub f_namelen: u64, - pub f_frsize: u64, - pub f_flags: u64, - pub f_spare: [u64; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } -} - -s_no_extra_traits! { - pub struct pthread_mutex_t { - value: ::c_int, - __reserved: [::c_char; 36], - } - - pub struct pthread_cond_t { - value: ::c_int, - __reserved: [::c_char; 44], - } - - pub struct pthread_rwlock_t { - numLocks: ::c_int, - writerThreadId: ::c_int, - pendingReaders: ::c_int, - pendingWriters: ::c_int, - attr: i32, - __reserved: [::c_char; 36], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for pthread_mutex_t { - fn eq(&self, other: &pthread_mutex_t) -> bool { - self.value == other.value - && self - .__reserved - .iter() - .zip(other.__reserved.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for pthread_mutex_t {} - - impl ::fmt::Debug for pthread_mutex_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_mutex_t") - .field("value", &self.value) - // FIXME: .field("__reserved", &self.__reserved) - .finish() - } - } - - impl ::hash::Hash for pthread_mutex_t { - fn hash(&self, state: &mut H) { - self.value.hash(state); - self.__reserved.hash(state); - } - } - - impl PartialEq for pthread_cond_t { - fn eq(&self, other: &pthread_cond_t) -> bool { - self.value == other.value - && self - .__reserved - .iter() - .zip(other.__reserved.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for pthread_cond_t {} - - impl ::fmt::Debug for pthread_cond_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_cond_t") - .field("value", &self.value) - // FIXME: .field("__reserved", &self.__reserved) - .finish() - } - } - - impl ::hash::Hash for pthread_cond_t { - fn hash(&self, state: &mut H) { - self.value.hash(state); - self.__reserved.hash(state); - } - } - - impl PartialEq for pthread_rwlock_t { - fn eq(&self, other: &pthread_rwlock_t) -> bool { - self.numLocks == other.numLocks - && self.writerThreadId == other.writerThreadId - && self.pendingReaders == other.pendingReaders - && self.pendingWriters == other.pendingWriters - && self.attr == other.attr - && self - .__reserved - .iter() - .zip(other.__reserved.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for pthread_rwlock_t {} - - impl ::fmt::Debug for pthread_rwlock_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_rwlock_t") - .field("numLocks", &self.numLocks) - .field("writerThreadId", &self.writerThreadId) - .field("pendingReaders", &self.pendingReaders) - .field("pendingWriters", &self.pendingWriters) - .field("attr", &self.attr) - // FIXME: .field("__reserved", &self.__reserved) - .finish() - } - } - - impl ::hash::Hash for pthread_rwlock_t { - fn hash(&self, state: &mut H) { - self.numLocks.hash(state); - self.writerThreadId.hash(state); - self.pendingReaders.hash(state); - self.pendingWriters.hash(state); - self.attr.hash(state); - self.__reserved.hash(state); - } - } - } -} - -// These constants must be of the same type of sigaction.sa_flags -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; - -pub const RTLD_GLOBAL: ::c_int = 0x00100; -pub const RTLD_NOW: ::c_int = 2; -pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; - -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - value: 0, - __reserved: [0; 36], -}; -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - value: 0, - __reserved: [0; 44], -}; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - numLocks: 0, - writerThreadId: 0, - pendingReaders: 0, - pendingWriters: 0, - attr: 0, - __reserved: [0; 36], -}; -pub const PTHREAD_STACK_MIN: ::size_t = 4096 * 4; -pub const CPU_SETSIZE: ::size_t = 1024; -pub const __CPU_BITS: ::size_t = 64; - -pub const UT_LINESIZE: usize = 32; -pub const UT_NAMESIZE: usize = 32; -pub const UT_HOSTSIZE: usize = 256; - -cfg_if! { - if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } else if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/linux_like/android/b64/x86_64/align.rs b/libc/src/unix/linux_like/android/b64/x86_64/align.rs deleted file mode 100644 index 7ca870f..0000000 --- a/libc/src/unix/linux_like/android/b64/x86_64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 4] - } -} diff --git a/libc/src/unix/linux_like/android/b64/x86_64/mod.rs b/libc/src/unix/linux_like/android/b64/x86_64/mod.rs deleted file mode 100644 index f5b8b16..0000000 --- a/libc/src/unix/linux_like/android/b64/x86_64/mod.rs +++ /dev/null @@ -1,427 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::c_ulong, - pub st_mode: ::c_uint, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_size: ::off64_t, - pub st_blksize: ::c_long, - pub st_blocks: ::c_long, - pub st_atime: ::c_long, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::c_long, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::c_long, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 3], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::c_ulong, - pub st_mode: ::c_uint, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_size: ::off64_t, - pub st_blksize: ::c_long, - pub st_blocks: ::c_long, - pub st_atime: ::c_long, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::c_long, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::c_long, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 3], - } -} - -pub const O_DIRECT: ::c_int = 0x4000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; -pub const O_LARGEFILE: ::c_int = 0o0100000; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; - -pub const MAP_32BIT: ::c_int = 0x40; - -// Syscall table - -pub const SYS_read: ::c_long = 0; -pub const SYS_write: ::c_long = 1; -pub const SYS_open: ::c_long = 2; -pub const SYS_close: ::c_long = 3; -pub const SYS_stat: ::c_long = 4; -pub const SYS_fstat: ::c_long = 5; -pub const SYS_lstat: ::c_long = 6; -pub const SYS_poll: ::c_long = 7; -pub const SYS_lseek: ::c_long = 8; -pub const SYS_mmap: ::c_long = 9; -pub const SYS_mprotect: ::c_long = 10; -pub const SYS_munmap: ::c_long = 11; -pub const SYS_brk: ::c_long = 12; -pub const SYS_rt_sigaction: ::c_long = 13; -pub const SYS_rt_sigprocmask: ::c_long = 14; -pub const SYS_rt_sigreturn: ::c_long = 15; -pub const SYS_ioctl: ::c_long = 16; -pub const SYS_pread64: ::c_long = 17; -pub const SYS_pwrite64: ::c_long = 18; -pub const SYS_readv: ::c_long = 19; -pub const SYS_writev: ::c_long = 20; -pub const SYS_access: ::c_long = 21; -pub const SYS_pipe: ::c_long = 22; -pub const SYS_select: ::c_long = 23; -pub const SYS_sched_yield: ::c_long = 24; -pub const SYS_mremap: ::c_long = 25; -pub const SYS_msync: ::c_long = 26; -pub const SYS_mincore: ::c_long = 27; -pub const SYS_madvise: ::c_long = 28; -pub const SYS_shmget: ::c_long = 29; -pub const SYS_shmat: ::c_long = 30; -pub const SYS_shmctl: ::c_long = 31; -pub const SYS_dup: ::c_long = 32; -pub const SYS_dup2: ::c_long = 33; -pub const SYS_pause: ::c_long = 34; -pub const SYS_nanosleep: ::c_long = 35; -pub const SYS_getitimer: ::c_long = 36; -pub const SYS_alarm: ::c_long = 37; -pub const SYS_setitimer: ::c_long = 38; -pub const SYS_getpid: ::c_long = 39; -pub const SYS_sendfile: ::c_long = 40; -pub const SYS_socket: ::c_long = 41; -pub const SYS_connect: ::c_long = 42; -pub const SYS_accept: ::c_long = 43; -pub const SYS_sendto: ::c_long = 44; -pub const SYS_recvfrom: ::c_long = 45; -pub const SYS_sendmsg: ::c_long = 46; -pub const SYS_recvmsg: ::c_long = 47; -pub const SYS_shutdown: ::c_long = 48; -pub const SYS_bind: ::c_long = 49; -pub const SYS_listen: ::c_long = 50; -pub const SYS_getsockname: ::c_long = 51; -pub const SYS_getpeername: ::c_long = 52; -pub const SYS_socketpair: ::c_long = 53; -pub const SYS_setsockopt: ::c_long = 54; -pub const SYS_getsockopt: ::c_long = 55; -pub const SYS_clone: ::c_long = 56; -pub const SYS_fork: ::c_long = 57; -pub const SYS_vfork: ::c_long = 58; -pub const SYS_execve: ::c_long = 59; -pub const SYS_exit: ::c_long = 60; -pub const SYS_wait4: ::c_long = 61; -pub const SYS_kill: ::c_long = 62; -pub const SYS_uname: ::c_long = 63; -pub const SYS_semget: ::c_long = 64; -pub const SYS_semop: ::c_long = 65; -pub const SYS_semctl: ::c_long = 66; -pub const SYS_shmdt: ::c_long = 67; -pub const SYS_msgget: ::c_long = 68; -pub const SYS_msgsnd: ::c_long = 69; -pub const SYS_msgrcv: ::c_long = 70; -pub const SYS_msgctl: ::c_long = 71; -pub const SYS_fcntl: ::c_long = 72; -pub const SYS_flock: ::c_long = 73; -pub const SYS_fsync: ::c_long = 74; -pub const SYS_fdatasync: ::c_long = 75; -pub const SYS_truncate: ::c_long = 76; -pub const SYS_ftruncate: ::c_long = 77; -pub const SYS_getdents: ::c_long = 78; -pub const SYS_getcwd: ::c_long = 79; -pub const SYS_chdir: ::c_long = 80; -pub const SYS_fchdir: ::c_long = 81; -pub const SYS_rename: ::c_long = 82; -pub const SYS_mkdir: ::c_long = 83; -pub const SYS_rmdir: ::c_long = 84; -pub const SYS_creat: ::c_long = 85; -pub const SYS_link: ::c_long = 86; -pub const SYS_unlink: ::c_long = 87; -pub const SYS_symlink: ::c_long = 88; -pub const SYS_readlink: ::c_long = 89; -pub const SYS_chmod: ::c_long = 90; -pub const SYS_fchmod: ::c_long = 91; -pub const SYS_chown: ::c_long = 92; -pub const SYS_fchown: ::c_long = 93; -pub const SYS_lchown: ::c_long = 94; -pub const SYS_umask: ::c_long = 95; -pub const SYS_gettimeofday: ::c_long = 96; -pub const SYS_getrlimit: ::c_long = 97; -pub const SYS_getrusage: ::c_long = 98; -pub const SYS_sysinfo: ::c_long = 99; -pub const SYS_times: ::c_long = 100; -pub const SYS_ptrace: ::c_long = 101; -pub const SYS_getuid: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_getgid: ::c_long = 104; -pub const SYS_setuid: ::c_long = 105; -pub const SYS_setgid: ::c_long = 106; -pub const SYS_geteuid: ::c_long = 107; -pub const SYS_getegid: ::c_long = 108; -pub const SYS_setpgid: ::c_long = 109; -pub const SYS_getppid: ::c_long = 110; -pub const SYS_getpgrp: ::c_long = 111; -pub const SYS_setsid: ::c_long = 112; -pub const SYS_setreuid: ::c_long = 113; -pub const SYS_setregid: ::c_long = 114; -pub const SYS_getgroups: ::c_long = 115; -pub const SYS_setgroups: ::c_long = 116; -pub const SYS_setresuid: ::c_long = 117; -pub const SYS_getresuid: ::c_long = 118; -pub const SYS_setresgid: ::c_long = 119; -pub const SYS_getresgid: ::c_long = 120; -pub const SYS_getpgid: ::c_long = 121; -pub const SYS_setfsuid: ::c_long = 122; -pub const SYS_setfsgid: ::c_long = 123; -pub const SYS_getsid: ::c_long = 124; -pub const SYS_capget: ::c_long = 125; -pub const SYS_capset: ::c_long = 126; -pub const SYS_rt_sigpending: ::c_long = 127; -pub const SYS_rt_sigtimedwait: ::c_long = 128; -pub const SYS_rt_sigqueueinfo: ::c_long = 129; -pub const SYS_rt_sigsuspend: ::c_long = 130; -pub const SYS_sigaltstack: ::c_long = 131; -pub const SYS_utime: ::c_long = 132; -pub const SYS_mknod: ::c_long = 133; -pub const SYS_uselib: ::c_long = 134; -pub const SYS_personality: ::c_long = 135; -pub const SYS_ustat: ::c_long = 136; -pub const SYS_statfs: ::c_long = 137; -pub const SYS_fstatfs: ::c_long = 138; -pub const SYS_sysfs: ::c_long = 139; -pub const SYS_getpriority: ::c_long = 140; -pub const SYS_setpriority: ::c_long = 141; -pub const SYS_sched_setparam: ::c_long = 142; -pub const SYS_sched_getparam: ::c_long = 143; -pub const SYS_sched_setscheduler: ::c_long = 144; -pub const SYS_sched_getscheduler: ::c_long = 145; -pub const SYS_sched_get_priority_max: ::c_long = 146; -pub const SYS_sched_get_priority_min: ::c_long = 147; -pub const SYS_sched_rr_get_interval: ::c_long = 148; -pub const SYS_mlock: ::c_long = 149; -pub const SYS_munlock: ::c_long = 150; -pub const SYS_mlockall: ::c_long = 151; -pub const SYS_munlockall: ::c_long = 152; -pub const SYS_vhangup: ::c_long = 153; -pub const SYS_modify_ldt: ::c_long = 154; -pub const SYS_pivot_root: ::c_long = 155; -// FIXME: SYS__sysctl is in the NDK sources but for some reason is -// not available in the tests -// pub const SYS__sysctl: ::c_long = 156; -pub const SYS_prctl: ::c_long = 157; -pub const SYS_arch_prctl: ::c_long = 158; -pub const SYS_adjtimex: ::c_long = 159; -pub const SYS_setrlimit: ::c_long = 160; -pub const SYS_chroot: ::c_long = 161; -pub const SYS_sync: ::c_long = 162; -pub const SYS_acct: ::c_long = 163; -pub const SYS_settimeofday: ::c_long = 164; -pub const SYS_mount: ::c_long = 165; -pub const SYS_umount2: ::c_long = 166; -pub const SYS_swapon: ::c_long = 167; -pub const SYS_swapoff: ::c_long = 168; -pub const SYS_reboot: ::c_long = 169; -pub const SYS_sethostname: ::c_long = 170; -pub const SYS_setdomainname: ::c_long = 171; -pub const SYS_iopl: ::c_long = 172; -pub const SYS_ioperm: ::c_long = 173; -pub const SYS_create_module: ::c_long = 174; -pub const SYS_init_module: ::c_long = 175; -pub const SYS_delete_module: ::c_long = 176; -pub const SYS_get_kernel_syms: ::c_long = 177; -pub const SYS_query_module: ::c_long = 178; -pub const SYS_quotactl: ::c_long = 179; -pub const SYS_nfsservctl: ::c_long = 180; -pub const SYS_getpmsg: ::c_long = 181; -pub const SYS_putpmsg: ::c_long = 182; -pub const SYS_afs_syscall: ::c_long = 183; -pub const SYS_tuxcall: ::c_long = 184; -pub const SYS_security: ::c_long = 185; -pub const SYS_gettid: ::c_long = 186; -pub const SYS_readahead: ::c_long = 187; -pub const SYS_setxattr: ::c_long = 188; -pub const SYS_lsetxattr: ::c_long = 189; -pub const SYS_fsetxattr: ::c_long = 190; -pub const SYS_getxattr: ::c_long = 191; -pub const SYS_lgetxattr: ::c_long = 192; -pub const SYS_fgetxattr: ::c_long = 193; -pub const SYS_listxattr: ::c_long = 194; -pub const SYS_llistxattr: ::c_long = 195; -pub const SYS_flistxattr: ::c_long = 196; -pub const SYS_removexattr: ::c_long = 197; -pub const SYS_lremovexattr: ::c_long = 198; -pub const SYS_fremovexattr: ::c_long = 199; -pub const SYS_tkill: ::c_long = 200; -pub const SYS_time: ::c_long = 201; -pub const SYS_futex: ::c_long = 202; -pub const SYS_sched_setaffinity: ::c_long = 203; -pub const SYS_sched_getaffinity: ::c_long = 204; -pub const SYS_set_thread_area: ::c_long = 205; -pub const SYS_io_setup: ::c_long = 206; -pub const SYS_io_destroy: ::c_long = 207; -pub const SYS_io_getevents: ::c_long = 208; -pub const SYS_io_submit: ::c_long = 209; -pub const SYS_io_cancel: ::c_long = 210; -pub const SYS_get_thread_area: ::c_long = 211; -pub const SYS_lookup_dcookie: ::c_long = 212; -pub const SYS_epoll_create: ::c_long = 213; -pub const SYS_epoll_ctl_old: ::c_long = 214; -pub const SYS_epoll_wait_old: ::c_long = 215; -pub const SYS_remap_file_pages: ::c_long = 216; -pub const SYS_getdents64: ::c_long = 217; -pub const SYS_set_tid_address: ::c_long = 218; -pub const SYS_restart_syscall: ::c_long = 219; -pub const SYS_semtimedop: ::c_long = 220; -pub const SYS_fadvise64: ::c_long = 221; -pub const SYS_timer_create: ::c_long = 222; -pub const SYS_timer_settime: ::c_long = 223; -pub const SYS_timer_gettime: ::c_long = 224; -pub const SYS_timer_getoverrun: ::c_long = 225; -pub const SYS_timer_delete: ::c_long = 226; -pub const SYS_clock_settime: ::c_long = 227; -pub const SYS_clock_gettime: ::c_long = 228; -pub const SYS_clock_getres: ::c_long = 229; -pub const SYS_clock_nanosleep: ::c_long = 230; -pub const SYS_exit_group: ::c_long = 231; -pub const SYS_epoll_wait: ::c_long = 232; -pub const SYS_epoll_ctl: ::c_long = 233; -pub const SYS_tgkill: ::c_long = 234; -pub const SYS_utimes: ::c_long = 235; -pub const SYS_vserver: ::c_long = 236; -pub const SYS_mbind: ::c_long = 237; -pub const SYS_set_mempolicy: ::c_long = 238; -pub const SYS_get_mempolicy: ::c_long = 239; -pub const SYS_mq_open: ::c_long = 240; -pub const SYS_mq_unlink: ::c_long = 241; -pub const SYS_mq_timedsend: ::c_long = 242; -pub const SYS_mq_timedreceive: ::c_long = 243; -pub const SYS_mq_notify: ::c_long = 244; -pub const SYS_mq_getsetattr: ::c_long = 245; -pub const SYS_kexec_load: ::c_long = 246; -pub const SYS_waitid: ::c_long = 247; -pub const SYS_add_key: ::c_long = 248; -pub const SYS_request_key: ::c_long = 249; -pub const SYS_keyctl: ::c_long = 250; -pub const SYS_ioprio_set: ::c_long = 251; -pub const SYS_ioprio_get: ::c_long = 252; -pub const SYS_inotify_init: ::c_long = 253; -pub const SYS_inotify_add_watch: ::c_long = 254; -pub const SYS_inotify_rm_watch: ::c_long = 255; -pub const SYS_migrate_pages: ::c_long = 256; -pub const SYS_openat: ::c_long = 257; -pub const SYS_mkdirat: ::c_long = 258; -pub const SYS_mknodat: ::c_long = 259; -pub const SYS_fchownat: ::c_long = 260; -pub const SYS_futimesat: ::c_long = 261; -pub const SYS_newfstatat: ::c_long = 262; -pub const SYS_unlinkat: ::c_long = 263; -pub const SYS_renameat: ::c_long = 264; -pub const SYS_linkat: ::c_long = 265; -pub const SYS_symlinkat: ::c_long = 266; -pub const SYS_readlinkat: ::c_long = 267; -pub const SYS_fchmodat: ::c_long = 268; -pub const SYS_faccessat: ::c_long = 269; -pub const SYS_pselect6: ::c_long = 270; -pub const SYS_ppoll: ::c_long = 271; -pub const SYS_unshare: ::c_long = 272; -pub const SYS_set_robust_list: ::c_long = 273; -pub const SYS_get_robust_list: ::c_long = 274; -pub const SYS_splice: ::c_long = 275; -pub const SYS_tee: ::c_long = 276; -pub const SYS_sync_file_range: ::c_long = 277; -pub const SYS_vmsplice: ::c_long = 278; -pub const SYS_move_pages: ::c_long = 279; -pub const SYS_utimensat: ::c_long = 280; -pub const SYS_epoll_pwait: ::c_long = 281; -pub const SYS_signalfd: ::c_long = 282; -pub const SYS_timerfd_create: ::c_long = 283; -pub const SYS_eventfd: ::c_long = 284; -pub const SYS_fallocate: ::c_long = 285; -pub const SYS_timerfd_settime: ::c_long = 286; -pub const SYS_timerfd_gettime: ::c_long = 287; -pub const SYS_accept4: ::c_long = 288; -pub const SYS_signalfd4: ::c_long = 289; -pub const SYS_eventfd2: ::c_long = 290; -pub const SYS_epoll_create1: ::c_long = 291; -pub const SYS_dup3: ::c_long = 292; -pub const SYS_pipe2: ::c_long = 293; -pub const SYS_inotify_init1: ::c_long = 294; -pub const SYS_preadv: ::c_long = 295; -pub const SYS_pwritev: ::c_long = 296; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 297; -pub const SYS_perf_event_open: ::c_long = 298; -pub const SYS_recvmmsg: ::c_long = 299; -pub const SYS_fanotify_init: ::c_long = 300; -pub const SYS_fanotify_mark: ::c_long = 301; -pub const SYS_prlimit64: ::c_long = 302; -pub const SYS_name_to_handle_at: ::c_long = 303; -pub const SYS_open_by_handle_at: ::c_long = 304; -pub const SYS_clock_adjtime: ::c_long = 305; -pub const SYS_syncfs: ::c_long = 306; -pub const SYS_sendmmsg: ::c_long = 307; -pub const SYS_setns: ::c_long = 308; -pub const SYS_getcpu: ::c_long = 309; -pub const SYS_process_vm_readv: ::c_long = 310; -pub const SYS_process_vm_writev: ::c_long = 311; -pub const SYS_kcmp: ::c_long = 312; -pub const SYS_finit_module: ::c_long = 313; -pub const SYS_sched_setattr: ::c_long = 314; -pub const SYS_sched_getattr: ::c_long = 315; -pub const SYS_renameat2: ::c_long = 316; -pub const SYS_seccomp: ::c_long = 317; -pub const SYS_getrandom: ::c_long = 318; -pub const SYS_memfd_create: ::c_long = 319; -pub const SYS_kexec_file_load: ::c_long = 320; -pub const SYS_bpf: ::c_long = 321; -pub const SYS_execveat: ::c_long = 322; -pub const SYS_userfaultfd: ::c_long = 323; -pub const SYS_membarrier: ::c_long = 324; -pub const SYS_mlock2: ::c_long = 325; -pub const SYS_copy_file_range: ::c_long = 326; -pub const SYS_preadv2: ::c_long = 327; -pub const SYS_pwritev2: ::c_long = 328; -pub const SYS_pkey_mprotect: ::c_long = 329; -pub const SYS_pkey_alloc: ::c_long = 330; -pub const SYS_pkey_free: ::c_long = 331; - -// offsets in user_regs_structs, from sys/reg.h -pub const R15: ::c_int = 0; -pub const R14: ::c_int = 1; -pub const R13: ::c_int = 2; -pub const R12: ::c_int = 3; -pub const RBP: ::c_int = 4; -pub const RBX: ::c_int = 5; -pub const R11: ::c_int = 6; -pub const R10: ::c_int = 7; -pub const R9: ::c_int = 8; -pub const R8: ::c_int = 9; -pub const RAX: ::c_int = 10; -pub const RCX: ::c_int = 11; -pub const RDX: ::c_int = 12; -pub const RSI: ::c_int = 13; -pub const RDI: ::c_int = 14; -pub const ORIG_RAX: ::c_int = 15; -pub const RIP: ::c_int = 16; -pub const CS: ::c_int = 17; -pub const EFLAGS: ::c_int = 18; -pub const RSP: ::c_int = 19; -pub const SS: ::c_int = 20; -pub const FS_BASE: ::c_int = 21; -pub const GS_BASE: ::c_int = 22; -pub const DS: ::c_int = 23; -pub const ES: ::c_int = 24; -pub const FS: ::c_int = 25; -pub const GS: ::c_int = 26; - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/android/mod.rs b/libc/src/unix/linux_like/android/mod.rs deleted file mode 100644 index a40b77e..0000000 --- a/libc/src/unix/linux_like/android/mod.rs +++ /dev/null @@ -1,2409 +0,0 @@ -//! Android-specific definitions for linux-like values - -pub type clock_t = ::c_long; -pub type time_t = ::c_long; -pub type suseconds_t = ::c_long; -pub type off_t = ::c_long; -pub type blkcnt_t = ::c_ulong; -pub type blksize_t = ::c_ulong; -pub type nlink_t = u32; -pub type useconds_t = u32; -pub type pthread_t = ::c_long; -pub type pthread_mutexattr_t = ::c_long; -pub type pthread_rwlockattr_t = ::c_long; -pub type pthread_condattr_t = ::c_long; -pub type pthread_key_t = ::c_int; -pub type fsfilcnt_t = ::c_ulong; -pub type fsblkcnt_t = ::c_ulong; -pub type nfds_t = ::c_uint; -pub type rlim_t = ::c_ulong; -pub type dev_t = ::c_ulong; -pub type ino_t = ::c_ulong; -pub type __CPU_BITTYPE = ::c_ulong; -pub type idtype_t = ::c_int; -pub type loff_t = ::c_longlong; -pub type __kernel_loff_t = ::c_longlong; -pub type __kernel_pid_t = ::c_int; - -s! { - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct __fsid_t { - __val: [::c_int; 2], - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::size_t, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::size_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::size_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::__kernel_loff_t, - pub l_len: ::__kernel_loff_t, - pub l_pid: ::__kernel_pid_t, - } - - pub struct cpu_set_t { - #[cfg(target_pointer_width = "64")] - __bits: [__CPU_BITTYPE; 16], - #[cfg(target_pointer_width = "32")] - __bits: [__CPU_BITTYPE; 1], - } - - pub struct sem_t { - count: ::c_uint, - #[cfg(target_pointer_width = "64")] - __reserved: [::c_int; 3], - } - - pub struct exit_status { - pub e_termination: ::c_short, - pub e_exit: ::c_short, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - #[cfg(target_pointer_width = "64")] - __f_reserved: [u32; 6], - } - - pub struct signalfd_siginfo { - pub ssi_signo: u32, - pub ssi_errno: i32, - pub ssi_code: i32, - pub ssi_pid: u32, - pub ssi_uid: u32, - pub ssi_fd: i32, - pub ssi_tid: u32, - pub ssi_band: u32, - pub ssi_overrun: u32, - pub ssi_trapno: u32, - pub ssi_status: i32, - pub ssi_int: i32, - pub ssi_ptr: ::c_ulonglong, - pub ssi_utime: ::c_ulonglong, - pub ssi_stime: ::c_ulonglong, - pub ssi_addr: ::c_ulonglong, - pub ssi_addr_lsb: u16, - _pad2: u16, - pub ssi_syscall: i32, - pub ssi_call_addr: u64, - pub ssi_arch: u32, - _pad: [u8; 28], - } - - pub struct ucred { - pub pid: ::pid_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - } - - pub struct genlmsghdr { - pub cmd: u8, - pub version: u8, - pub reserved: u16, - } - - pub struct nlmsghdr { - pub nlmsg_len: u32, - pub nlmsg_type: u16, - pub nlmsg_flags: u16, - pub nlmsg_seq: u32, - pub nlmsg_pid: u32, - } - - pub struct nlmsgerr { - pub error: ::c_int, - pub msg: nlmsghdr, - } - - pub struct nl_pktinfo { - pub group: u32, - } - - pub struct nl_mmap_req { - pub nm_block_size: ::c_uint, - pub nm_block_nr: ::c_uint, - pub nm_frame_size: ::c_uint, - pub nm_frame_nr: ::c_uint, - } - - pub struct nl_mmap_hdr { - pub nm_status: ::c_uint, - pub nm_len: ::c_uint, - pub nm_group: u32, - pub nm_pid: u32, - pub nm_uid: u32, - pub nm_gid: u32, - } - - pub struct nlattr { - pub nla_len: u16, - pub nla_type: u16, - } - - pub struct in6_pktinfo { - pub ipi6_addr: ::in6_addr, - pub ipi6_ifindex: ::c_int, - } - - pub struct inotify_event { - pub wd: ::c_int, - pub mask: u32, - pub cookie: u32, - pub len: u32 - } -} - -s_no_extra_traits! { - pub struct sockaddr_nl { - pub nl_family: ::sa_family_t, - nl_pad: ::c_ushort, - pub nl_pid: u32, - pub nl_groups: u32 - } - - pub struct dirent { - pub d_ino: u64, - pub d_off: i64, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct dirent64 { - pub d_ino: u64, - pub d_off: i64, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct lastlog { - ll_time: ::time_t, - ll_line: [::c_char; UT_LINESIZE], - ll_host: [::c_char; UT_HOSTSIZE], - } - - pub struct utmp { - pub ut_type: ::c_short, - pub ut_pid: ::pid_t, - pub ut_line: [::c_char; UT_LINESIZE], - pub ut_id: [::c_char; 4], - pub ut_user: [::c_char; UT_NAMESIZE], - pub ut_host: [::c_char; UT_HOSTSIZE], - pub ut_exit: exit_status, - pub ut_session: ::c_long, - pub ut_tv: ::timeval, - pub ut_addr_v6: [i32; 4], - unused: [::c_char; 20], - } - - pub struct sockaddr_alg { - pub salg_family: ::sa_family_t, - pub salg_type: [::c_uchar; 14], - pub salg_feat: u32, - pub salg_mask: u32, - pub salg_name: [::c_uchar; 64], - } - - pub struct af_alg_iv { - pub ivlen: u32, - pub iv: [::c_uchar; 0], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for sockaddr_nl { - fn eq(&self, other: &sockaddr_nl) -> bool { - self.nl_family == other.nl_family && - self.nl_pid == other.nl_pid && - self.nl_groups == other.nl_groups - } - } - impl Eq for sockaddr_nl {} - impl ::fmt::Debug for sockaddr_nl { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_nl") - .field("nl_family", &self.nl_family) - .field("nl_pid", &self.nl_pid) - .field("nl_groups", &self.nl_groups) - .finish() - } - } - impl ::hash::Hash for sockaddr_nl { - fn hash(&self, state: &mut H) { - self.nl_family.hash(state); - self.nl_pid.hash(state); - self.nl_groups.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for dirent {} - - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for dirent64 { - fn eq(&self, other: &dirent64) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for dirent64 {} - - impl ::fmt::Debug for dirent64 { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent64") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - - impl ::hash::Hash for dirent64 { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for siginfo_t { - fn eq(&self, other: &siginfo_t) -> bool { - self.si_signo == other.si_signo - && self.si_errno == other.si_errno - && self.si_code == other.si_code - // Ignore _pad - // Ignore _align - } - } - - impl Eq for siginfo_t {} - - impl ::fmt::Debug for siginfo_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("siginfo_t") - .field("si_signo", &self.si_signo) - .field("si_errno", &self.si_errno) - .field("si_code", &self.si_code) - // Ignore _pad - // Ignore _align - .finish() - } - } - - impl ::hash::Hash for siginfo_t { - fn hash(&self, state: &mut H) { - self.si_signo.hash(state); - self.si_errno.hash(state); - self.si_code.hash(state); - // Ignore _pad - // Ignore _align - } - } - - impl PartialEq for lastlog { - fn eq(&self, other: &lastlog) -> bool { - self.ll_time == other.ll_time - && self - .ll_line - .iter() - .zip(other.ll_line.iter()) - .all(|(a,b)| a == b) - && self - .ll_host - .iter() - .zip(other.ll_host.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for lastlog {} - - impl ::fmt::Debug for lastlog { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("lastlog") - .field("ll_time", &self.ll_time) - .field("ll_line", &self.ll_line) - // FIXME: .field("ll_host", &self.ll_host) - .finish() - } - } - - impl ::hash::Hash for lastlog { - fn hash(&self, state: &mut H) { - self.ll_time.hash(state); - self.ll_line.hash(state); - self.ll_host.hash(state); - } - } - - impl PartialEq for utmp { - fn eq(&self, other: &utmp) -> bool { - self.ut_type == other.ut_type - && self.ut_pid == other.ut_pid - && self - .ut_line - .iter() - .zip(other.ut_line.iter()) - .all(|(a,b)| a == b) - && self.ut_id == other.ut_id - && self - .ut_user - .iter() - .zip(other.ut_user.iter()) - .all(|(a,b)| a == b) - && self - .ut_host - .iter() - .zip(other.ut_host.iter()) - .all(|(a,b)| a == b) - && self.ut_exit == other.ut_exit - && self.ut_session == other.ut_session - && self.ut_tv == other.ut_tv - && self.ut_addr_v6 == other.ut_addr_v6 - && self.unused == other.unused - } - } - - impl Eq for utmp {} - - impl ::fmt::Debug for utmp { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utmp") - .field("ut_type", &self.ut_type) - .field("ut_pid", &self.ut_pid) - .field("ut_line", &self.ut_line) - .field("ut_id", &self.ut_id) - .field("ut_user", &self.ut_user) - // FIXME: .field("ut_host", &self.ut_host) - .field("ut_exit", &self.ut_exit) - .field("ut_session", &self.ut_session) - .field("ut_tv", &self.ut_tv) - .field("ut_addr_v6", &self.ut_addr_v6) - .field("unused", &self.unused) - .finish() - } - } - - impl ::hash::Hash for utmp { - fn hash(&self, state: &mut H) { - self.ut_type.hash(state); - self.ut_pid.hash(state); - self.ut_line.hash(state); - self.ut_id.hash(state); - self.ut_user.hash(state); - self.ut_host.hash(state); - self.ut_exit.hash(state); - self.ut_session.hash(state); - self.ut_tv.hash(state); - self.ut_addr_v6.hash(state); - self.unused.hash(state); - } - } - - impl PartialEq for sockaddr_alg { - fn eq(&self, other: &sockaddr_alg) -> bool { - self.salg_family == other.salg_family - && self - .salg_type - .iter() - .zip(other.salg_type.iter()) - .all(|(a, b)| a == b) - && self.salg_feat == other.salg_feat - && self.salg_mask == other.salg_mask - && self - .salg_name - .iter() - .zip(other.salg_name.iter()) - .all(|(a, b)| a == b) - } - } - - impl Eq for sockaddr_alg {} - - impl ::fmt::Debug for sockaddr_alg { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_alg") - .field("salg_family", &self.salg_family) - .field("salg_type", &self.salg_type) - .field("salg_feat", &self.salg_feat) - .field("salg_mask", &self.salg_mask) - .field("salg_name", &&self.salg_name[..]) - .finish() - } - } - - impl ::hash::Hash for sockaddr_alg { - fn hash(&self, state: &mut H) { - self.salg_family.hash(state); - self.salg_type.hash(state); - self.salg_feat.hash(state); - self.salg_mask.hash(state); - self.salg_name.hash(state); - } - } - - impl af_alg_iv { - fn as_slice(&self) -> &[u8] { - unsafe { - ::core::slice::from_raw_parts( - self.iv.as_ptr(), - self.ivlen as usize - ) - } - } - } - - impl PartialEq for af_alg_iv { - fn eq(&self, other: &af_alg_iv) -> bool { - *self.as_slice() == *other.as_slice() - } - } - - impl Eq for af_alg_iv {} - - impl ::fmt::Debug for af_alg_iv { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("af_alg_iv") - .field("iv", &self.as_slice()) - .finish() - } - } - - impl ::hash::Hash for af_alg_iv { - fn hash(&self, state: &mut H) { - self.as_slice().hash(state); - } - } - } -} - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MS_NOUSER: ::c_ulong = 0xffffffff80000000; -pub const MS_RMT_MASK: ::c_ulong = 0x02800051; - -pub const O_TRUNC: ::c_int = 512; -pub const O_CLOEXEC: ::c_int = 0x80000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_NOATIME: ::c_int = 0o1000000; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; -pub const EPOLLONESHOT: ::c_int = 0x40000000; -pub const EPOLLRDHUP: ::c_int = 0x00002000; -pub const EPOLLWAKEUP: ::c_int = 0x20000000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const USER_PROCESS: ::c_short = 7; - -pub const FALLOC_FL_COLLAPSE_RANGE: ::c_int = 0x08; - -pub const BUFSIZ: ::c_uint = 1024; -pub const FILENAME_MAX: ::c_uint = 4096; -pub const FOPEN_MAX: ::c_uint = 20; -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; -pub const L_tmpnam: ::c_uint = 4096; -pub const TMP_MAX: ::c_uint = 308915776; -pub const _PC_LINK_MAX: ::c_int = 1; -pub const _PC_MAX_CANON: ::c_int = 2; -pub const _PC_MAX_INPUT: ::c_int = 3; -pub const _PC_NAME_MAX: ::c_int = 4; -pub const _PC_PATH_MAX: ::c_int = 5; -pub const _PC_PIPE_BUF: ::c_int = 6; -pub const _PC_2_SYMLINKS: ::c_int = 7; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 8; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 9; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 10; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 11; -pub const _PC_REC_XFER_ALIGN: ::c_int = 12; -pub const _PC_SYMLINK_MAX: ::c_int = 13; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 14; -pub const _PC_NO_TRUNC: ::c_int = 15; -pub const _PC_VDISABLE: ::c_int = 16; -pub const _PC_ASYNC_IO: ::c_int = 17; -pub const _PC_PRIO_IO: ::c_int = 18; -pub const _PC_SYNC_IO: ::c_int = 19; - -pub const FIONBIO: ::c_int = 0x5421; - -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_BC_BASE_MAX: ::c_int = 1; -pub const _SC_BC_DIM_MAX: ::c_int = 2; -pub const _SC_BC_SCALE_MAX: ::c_int = 3; -pub const _SC_BC_STRING_MAX: ::c_int = 4; -pub const _SC_CHILD_MAX: ::c_int = 5; -pub const _SC_CLK_TCK: ::c_int = 6; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 7; -pub const _SC_EXPR_NEST_MAX: ::c_int = 8; -pub const _SC_LINE_MAX: ::c_int = 9; -pub const _SC_NGROUPS_MAX: ::c_int = 10; -pub const _SC_OPEN_MAX: ::c_int = 11; -pub const _SC_PASS_MAX: ::c_int = 12; -pub const _SC_2_C_BIND: ::c_int = 13; -pub const _SC_2_C_DEV: ::c_int = 14; -pub const _SC_2_C_VERSION: ::c_int = 15; -pub const _SC_2_CHAR_TERM: ::c_int = 16; -pub const _SC_2_FORT_DEV: ::c_int = 17; -pub const _SC_2_FORT_RUN: ::c_int = 18; -pub const _SC_2_LOCALEDEF: ::c_int = 19; -pub const _SC_2_SW_DEV: ::c_int = 20; -pub const _SC_2_UPE: ::c_int = 21; -pub const _SC_2_VERSION: ::c_int = 22; -pub const _SC_JOB_CONTROL: ::c_int = 23; -pub const _SC_SAVED_IDS: ::c_int = 24; -pub const _SC_VERSION: ::c_int = 25; -pub const _SC_RE_DUP_MAX: ::c_int = 26; -pub const _SC_STREAM_MAX: ::c_int = 27; -pub const _SC_TZNAME_MAX: ::c_int = 28; -pub const _SC_XOPEN_CRYPT: ::c_int = 29; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 30; -pub const _SC_XOPEN_SHM: ::c_int = 31; -pub const _SC_XOPEN_VERSION: ::c_int = 32; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 33; -pub const _SC_XOPEN_REALTIME: ::c_int = 34; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 35; -pub const _SC_XOPEN_LEGACY: ::c_int = 36; -pub const _SC_ATEXIT_MAX: ::c_int = 37; -pub const _SC_IOV_MAX: ::c_int = 38; -pub const _SC_PAGESIZE: ::c_int = 39; -pub const _SC_PAGE_SIZE: ::c_int = 40; -pub const _SC_XOPEN_UNIX: ::c_int = 41; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = 42; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = 43; -pub const _SC_XBS5_LP64_OFF64: ::c_int = 44; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = 45; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 46; -pub const _SC_AIO_MAX: ::c_int = 47; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 48; -pub const _SC_DELAYTIMER_MAX: ::c_int = 49; -pub const _SC_MQ_OPEN_MAX: ::c_int = 50; -pub const _SC_MQ_PRIO_MAX: ::c_int = 51; -pub const _SC_RTSIG_MAX: ::c_int = 52; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 53; -pub const _SC_SEM_VALUE_MAX: ::c_int = 54; -pub const _SC_SIGQUEUE_MAX: ::c_int = 55; -pub const _SC_TIMER_MAX: ::c_int = 56; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 57; -pub const _SC_FSYNC: ::c_int = 58; -pub const _SC_MAPPED_FILES: ::c_int = 59; -pub const _SC_MEMLOCK: ::c_int = 60; -pub const _SC_MEMLOCK_RANGE: ::c_int = 61; -pub const _SC_MEMORY_PROTECTION: ::c_int = 62; -pub const _SC_MESSAGE_PASSING: ::c_int = 63; -pub const _SC_PRIORITIZED_IO: ::c_int = 64; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 65; -pub const _SC_REALTIME_SIGNALS: ::c_int = 66; -pub const _SC_SEMAPHORES: ::c_int = 67; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 68; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 69; -pub const _SC_TIMERS: ::c_int = 70; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 71; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 72; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 73; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 74; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 75; -pub const _SC_THREAD_STACK_MIN: ::c_int = 76; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 77; -pub const _SC_TTY_NAME_MAX: ::c_int = 78; -pub const _SC_THREADS: ::c_int = 79; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 80; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 81; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 82; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 83; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 84; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 85; -pub const _SC_NPROCESSORS_CONF: ::c_int = 96; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 97; -pub const _SC_PHYS_PAGES: ::c_int = 98; -pub const _SC_AVPHYS_PAGES: ::c_int = 99; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 100; - -pub const _SC_2_PBS: ::c_int = 101; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 102; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 103; -pub const _SC_2_PBS_LOCATE: ::c_int = 104; -pub const _SC_2_PBS_MESSAGE: ::c_int = 105; -pub const _SC_2_PBS_TRACK: ::c_int = 106; -pub const _SC_ADVISORY_INFO: ::c_int = 107; -pub const _SC_BARRIERS: ::c_int = 108; -pub const _SC_CLOCK_SELECTION: ::c_int = 109; -pub const _SC_CPUTIME: ::c_int = 110; -pub const _SC_HOST_NAME_MAX: ::c_int = 111; -pub const _SC_IPV6: ::c_int = 112; -pub const _SC_RAW_SOCKETS: ::c_int = 113; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 114; -pub const _SC_REGEXP: ::c_int = 115; -pub const _SC_SHELL: ::c_int = 116; -pub const _SC_SPAWN: ::c_int = 117; -pub const _SC_SPIN_LOCKS: ::c_int = 118; -pub const _SC_SPORADIC_SERVER: ::c_int = 119; -pub const _SC_SS_REPL_MAX: ::c_int = 120; -pub const _SC_SYMLOOP_MAX: ::c_int = 121; -pub const _SC_THREAD_CPUTIME: ::c_int = 122; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 123; -pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 124; -pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 125; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 126; -pub const _SC_TIMEOUTS: ::c_int = 127; -pub const _SC_TRACE: ::c_int = 128; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 129; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 130; -pub const _SC_TRACE_INHERIT: ::c_int = 131; -pub const _SC_TRACE_LOG: ::c_int = 132; -pub const _SC_TRACE_NAME_MAX: ::c_int = 133; -pub const _SC_TRACE_SYS_MAX: ::c_int = 134; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 135; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 136; -pub const _SC_V7_ILP32_OFF32: ::c_int = 137; -pub const _SC_V7_ILP32_OFFBIG: ::c_int = 138; -pub const _SC_V7_LP64_OFF64: ::c_int = 139; -pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 140; -pub const _SC_XOPEN_STREAMS: ::c_int = 141; -pub const _SC_XOPEN_UUCP: ::c_int = 142; - -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; - -pub const FIOCLEX: ::c_int = 0x5451; -pub const FIONCLEX: ::c_int = 0x5450; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = 31; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const LC_PAPER: ::c_int = 7; -pub const LC_NAME: ::c_int = 8; -pub const LC_ADDRESS: ::c_int = 9; -pub const LC_TELEPHONE: ::c_int = 10; -pub const LC_MEASUREMENT: ::c_int = 11; -pub const LC_IDENTIFICATION: ::c_int = 12; -pub const LC_PAPER_MASK: ::c_int = (1 << LC_PAPER); -pub const LC_NAME_MASK: ::c_int = (1 << LC_NAME); -pub const LC_ADDRESS_MASK: ::c_int = (1 << LC_ADDRESS); -pub const LC_TELEPHONE_MASK: ::c_int = (1 << LC_TELEPHONE); -pub const LC_MEASUREMENT_MASK: ::c_int = (1 << LC_MEASUREMENT); -pub const LC_IDENTIFICATION_MASK: ::c_int = (1 << LC_IDENTIFICATION); -pub const LC_ALL_MASK: ::c_int = ::LC_CTYPE_MASK - | ::LC_NUMERIC_MASK - | ::LC_TIME_MASK - | ::LC_COLLATE_MASK - | ::LC_MONETARY_MASK - | ::LC_MESSAGES_MASK - | LC_PAPER_MASK - | LC_NAME_MASK - | LC_ADDRESS_MASK - | LC_TELEPHONE_MASK - | LC_MEASUREMENT_MASK - | LC_IDENTIFICATION_MASK; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; - -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; - -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_SEQPACKET: ::c_int = 5; -pub const SOCK_DCCP: ::c_int = 6; -pub const SOCK_PACKET: ::c_int = 10; - -pub const SOL_SOCKET: ::c_int = 1; -pub const SOL_SCTP: ::c_int = 132; -pub const SOL_IPX: ::c_int = 256; -pub const SOL_AX25: ::c_int = 257; -pub const SOL_ATALK: ::c_int = 258; -pub const SOL_NETROM: ::c_int = 259; -pub const SOL_ROSE: ::c_int = 260; - -/* DCCP socket options */ -pub const DCCP_SOCKOPT_PACKET_SIZE: ::c_int = 1; -pub const DCCP_SOCKOPT_SERVICE: ::c_int = 2; -pub const DCCP_SOCKOPT_CHANGE_L: ::c_int = 3; -pub const DCCP_SOCKOPT_CHANGE_R: ::c_int = 4; -pub const DCCP_SOCKOPT_GET_CUR_MPS: ::c_int = 5; -pub const DCCP_SOCKOPT_SERVER_TIMEWAIT: ::c_int = 6; -pub const DCCP_SOCKOPT_SEND_CSCOV: ::c_int = 10; -pub const DCCP_SOCKOPT_RECV_CSCOV: ::c_int = 11; -pub const DCCP_SOCKOPT_AVAILABLE_CCIDS: ::c_int = 12; -pub const DCCP_SOCKOPT_CCID: ::c_int = 13; -pub const DCCP_SOCKOPT_TX_CCID: ::c_int = 14; -pub const DCCP_SOCKOPT_RX_CCID: ::c_int = 15; -pub const DCCP_SOCKOPT_QPOLICY_ID: ::c_int = 16; -pub const DCCP_SOCKOPT_QPOLICY_TXQLEN: ::c_int = 17; -pub const DCCP_SOCKOPT_CCID_RX_INFO: ::c_int = 128; -pub const DCCP_SOCKOPT_CCID_TX_INFO: ::c_int = 192; - -/// maximum number of services provided on the same listening port -pub const DCCP_SERVICE_LIST_MAX_LEN: ::c_int = 32; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_MARK: ::c_int = 36; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_BUSY_POLL: ::c_int = 46; - -pub const IPTOS_ECN_NOTECT: u8 = 0x00; - -pub const O_ACCMODE: ::c_int = 3; -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 0x101000; -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_NDELAY: ::c_int = 0x800; -pub const O_DSYNC: ::c_int = 4096; - -pub const NI_MAXHOST: ::size_t = 1025; - -pub const NCCS: usize = 19; -pub const TCSBRKP: ::c_int = 0x5425; -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 0x1; -pub const TCSAFLUSH: ::c_int = 0x2; -pub const VEOF: usize = 4; -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; -pub const EXTPROC: ::tcflag_t = 0o200000; - -pub const ADFS_SUPER_MAGIC: ::c_long = 0x0000adf5; -pub const AFFS_SUPER_MAGIC: ::c_long = 0x0000adff; -pub const CODA_SUPER_MAGIC: ::c_long = 0x73757245; -pub const CRAMFS_MAGIC: ::c_long = 0x28cd3d45; -pub const EFS_SUPER_MAGIC: ::c_long = 0x00414a53; -pub const EXT2_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const EXT3_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const EXT4_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const HPFS_SUPER_MAGIC: ::c_long = 0xf995e849; -pub const HUGETLBFS_MAGIC: ::c_long = 0x958458f6; -pub const ISOFS_SUPER_MAGIC: ::c_long = 0x00009660; -pub const JFFS2_SUPER_MAGIC: ::c_long = 0x000072b6; -pub const MINIX_SUPER_MAGIC: ::c_long = 0x0000137f; -pub const MINIX_SUPER_MAGIC2: ::c_long = 0x0000138f; -pub const MINIX2_SUPER_MAGIC: ::c_long = 0x00002468; -pub const MINIX2_SUPER_MAGIC2: ::c_long = 0x00002478; -pub const MSDOS_SUPER_MAGIC: ::c_long = 0x00004d44; -pub const NCP_SUPER_MAGIC: ::c_long = 0x0000564c; -pub const NFS_SUPER_MAGIC: ::c_long = 0x00006969; -pub const OPENPROM_SUPER_MAGIC: ::c_long = 0x00009fa1; -pub const PROC_SUPER_MAGIC: ::c_long = 0x00009fa0; -pub const QNX4_SUPER_MAGIC: ::c_long = 0x0000002f; -pub const REISERFS_SUPER_MAGIC: ::c_long = 0x52654973; -pub const SMB_SUPER_MAGIC: ::c_long = 0x0000517b; -pub const TMPFS_MAGIC: ::c_long = 0x01021994; -pub const USBDEVICE_SUPER_MAGIC: ::c_long = 0x00009fa2; - -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const PTRACE_TRACEME: ::c_int = 0; -pub const PTRACE_PEEKTEXT: ::c_int = 1; -pub const PTRACE_PEEKDATA: ::c_int = 2; -pub const PTRACE_PEEKUSER: ::c_int = 3; -pub const PTRACE_POKETEXT: ::c_int = 4; -pub const PTRACE_POKEDATA: ::c_int = 5; -pub const PTRACE_POKEUSER: ::c_int = 6; -pub const PTRACE_CONT: ::c_int = 7; -pub const PTRACE_KILL: ::c_int = 8; -pub const PTRACE_SINGLESTEP: ::c_int = 9; -pub const PTRACE_ATTACH: ::c_int = 16; -pub const PTRACE_DETACH: ::c_int = 17; -pub const PTRACE_SYSCALL: ::c_int = 24; -pub const PTRACE_SETOPTIONS: ::c_int = 0x4200; -pub const PTRACE_GETEVENTMSG: ::c_int = 0x4201; -pub const PTRACE_GETSIGINFO: ::c_int = 0x4202; -pub const PTRACE_SETSIGINFO: ::c_int = 0x4203; - -pub const EFD_NONBLOCK: ::c_int = 0x800; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; - -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_LOCKS: ::c_int = 10; -pub const RLIMIT_SIGPENDING: ::c_int = 11; -pub const RLIMIT_MSGQUEUE: ::c_int = 12; -pub const RLIMIT_NICE: ::c_int = 13; -pub const RLIMIT_RTPRIO: ::c_int = 14; - -pub const RLIM_INFINITY: ::rlim_t = !0; - -pub const TCGETS: ::c_int = 0x5401; -pub const TCSETS: ::c_int = 0x5402; -pub const TCSETSW: ::c_int = 0x5403; -pub const TCSETSF: ::c_int = 0x5404; -pub const TCGETA: ::c_int = 0x5405; -pub const TCSETA: ::c_int = 0x5406; -pub const TCSETAW: ::c_int = 0x5407; -pub const TCSETAF: ::c_int = 0x5408; -pub const TCSBRK: ::c_int = 0x5409; -pub const TCXONC: ::c_int = 0x540A; -pub const TCFLSH: ::c_int = 0x540B; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCINQ: ::c_int = 0x541B; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x540F; -pub const TIOCSPGRP: ::c_int = 0x5410; -pub const TIOCOUTQ: ::c_int = 0x5411; -pub const TIOCSTI: ::c_int = 0x5412; -pub const TIOCGWINSZ: ::c_int = 0x5413; -pub const TIOCSWINSZ: ::c_int = 0x5414; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x541B; -pub const TIOCCONS: ::c_int = 0x541D; - -pub const ST_RDONLY: ::c_ulong = 1; -pub const ST_NOSUID: ::c_ulong = 2; -pub const ST_NODEV: ::c_ulong = 4; -pub const ST_NOEXEC: ::c_ulong = 8; -pub const ST_SYNCHRONOUS: ::c_ulong = 16; -pub const ST_MANDLOCK: ::c_ulong = 64; -pub const ST_NOATIME: ::c_ulong = 1024; -pub const ST_NODIRATIME: ::c_ulong = 2048; -pub const ST_RELATIME: ::c_ulong = 4096; - -pub const RTLD_NOLOAD: ::c_int = 0x4; - -pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t; - -pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead; -pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793; -pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278; -pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448; -pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216; - -pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567; -pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123; -pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF; -pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000; -pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC; -pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4; -pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2; -pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const EAI_AGAIN: ::c_int = 2; -pub const EAI_BADFLAGS: ::c_int = 3; -pub const EAI_FAIL: ::c_int = 4; -pub const EAI_FAMILY: ::c_int = 5; -pub const EAI_MEMORY: ::c_int = 6; -pub const EAI_NODATA: ::c_int = 7; -pub const EAI_NONAME: ::c_int = 8; -pub const EAI_SERVICE: ::c_int = 9; -pub const EAI_SOCKTYPE: ::c_int = 10; -pub const EAI_SYSTEM: ::c_int = 11; -pub const EAI_OVERFLOW: ::c_int = 14; - -pub const NETLINK_ROUTE: ::c_int = 0; -pub const NETLINK_UNUSED: ::c_int = 1; -pub const NETLINK_USERSOCK: ::c_int = 2; -pub const NETLINK_FIREWALL: ::c_int = 3; -pub const NETLINK_SOCK_DIAG: ::c_int = 4; -pub const NETLINK_NFLOG: ::c_int = 5; -pub const NETLINK_XFRM: ::c_int = 6; -pub const NETLINK_SELINUX: ::c_int = 7; -pub const NETLINK_ISCSI: ::c_int = 8; -pub const NETLINK_AUDIT: ::c_int = 9; -pub const NETLINK_FIB_LOOKUP: ::c_int = 10; -pub const NETLINK_CONNECTOR: ::c_int = 11; -pub const NETLINK_NETFILTER: ::c_int = 12; -pub const NETLINK_IP6_FW: ::c_int = 13; -pub const NETLINK_DNRTMSG: ::c_int = 14; -pub const NETLINK_KOBJECT_UEVENT: ::c_int = 15; -pub const NETLINK_GENERIC: ::c_int = 16; -pub const NETLINK_SCSITRANSPORT: ::c_int = 18; -pub const NETLINK_ECRYPTFS: ::c_int = 19; -pub const NETLINK_RDMA: ::c_int = 20; -pub const NETLINK_CRYPTO: ::c_int = 21; -pub const NETLINK_INET_DIAG: ::c_int = NETLINK_SOCK_DIAG; - -pub const MAX_LINKS: ::c_int = 32; - -pub const NLM_F_REQUEST: ::c_int = 1; -pub const NLM_F_MULTI: ::c_int = 2; -pub const NLM_F_ACK: ::c_int = 4; -pub const NLM_F_ECHO: ::c_int = 8; -pub const NLM_F_DUMP_INTR: ::c_int = 16; - -pub const NLM_F_ROOT: ::c_int = 0x100; -pub const NLM_F_MATCH: ::c_int = 0x200; -pub const NLM_F_ATOMIC: ::c_int = 0x400; -pub const NLM_F_DUMP: ::c_int = NLM_F_ROOT | NLM_F_MATCH; - -pub const NLM_F_REPLACE: ::c_int = 0x100; -pub const NLM_F_EXCL: ::c_int = 0x200; -pub const NLM_F_CREATE: ::c_int = 0x400; -pub const NLM_F_APPEND: ::c_int = 0x800; - -pub const NLMSG_NOOP: ::c_int = 0x1; -pub const NLMSG_ERROR: ::c_int = 0x2; -pub const NLMSG_DONE: ::c_int = 0x3; -pub const NLMSG_OVERRUN: ::c_int = 0x4; -pub const NLMSG_MIN_TYPE: ::c_int = 0x10; - -// linux/netfilter/nfnetlink.h -pub const NFNLGRP_NONE: ::c_int = 0; -pub const NFNLGRP_CONNTRACK_NEW: ::c_int = 1; -pub const NFNLGRP_CONNTRACK_UPDATE: ::c_int = 2; -pub const NFNLGRP_CONNTRACK_DESTROY: ::c_int = 3; -pub const NFNLGRP_CONNTRACK_EXP_NEW: ::c_int = 4; -pub const NFNLGRP_CONNTRACK_EXP_UPDATE: ::c_int = 5; -pub const NFNLGRP_CONNTRACK_EXP_DESTROY: ::c_int = 6; -pub const NFNLGRP_NFTABLES: ::c_int = 7; -pub const NFNLGRP_ACCT_QUOTA: ::c_int = 8; - -pub const NFNETLINK_V0: ::c_int = 0; - -pub const NFNL_SUBSYS_NONE: ::c_int = 0; -pub const NFNL_SUBSYS_CTNETLINK: ::c_int = 1; -pub const NFNL_SUBSYS_CTNETLINK_EXP: ::c_int = 2; -pub const NFNL_SUBSYS_QUEUE: ::c_int = 3; -pub const NFNL_SUBSYS_ULOG: ::c_int = 4; -pub const NFNL_SUBSYS_OSF: ::c_int = 5; -pub const NFNL_SUBSYS_IPSET: ::c_int = 6; -pub const NFNL_SUBSYS_ACCT: ::c_int = 7; -pub const NFNL_SUBSYS_CTNETLINK_TIMEOUT: ::c_int = 8; -pub const NFNL_SUBSYS_CTHELPER: ::c_int = 9; -pub const NFNL_SUBSYS_NFTABLES: ::c_int = 10; -pub const NFNL_SUBSYS_NFT_COMPAT: ::c_int = 11; -pub const NFNL_SUBSYS_COUNT: ::c_int = 12; - -pub const NFNL_MSG_BATCH_BEGIN: ::c_int = NLMSG_MIN_TYPE; -pub const NFNL_MSG_BATCH_END: ::c_int = NLMSG_MIN_TYPE + 1; - -// linux/netfilter/nfnetlink_log.h -pub const NFULNL_MSG_PACKET: ::c_int = 0; -pub const NFULNL_MSG_CONFIG: ::c_int = 1; - -pub const NFULA_UNSPEC: ::c_int = 0; -pub const NFULA_PACKET_HDR: ::c_int = 1; -pub const NFULA_MARK: ::c_int = 2; -pub const NFULA_TIMESTAMP: ::c_int = 3; -pub const NFULA_IFINDEX_INDEV: ::c_int = 4; -pub const NFULA_IFINDEX_OUTDEV: ::c_int = 5; -pub const NFULA_IFINDEX_PHYSINDEV: ::c_int = 6; -pub const NFULA_IFINDEX_PHYSOUTDEV: ::c_int = 7; -pub const NFULA_HWADDR: ::c_int = 8; -pub const NFULA_PAYLOAD: ::c_int = 9; -pub const NFULA_PREFIX: ::c_int = 10; -pub const NFULA_UID: ::c_int = 11; -pub const NFULA_SEQ: ::c_int = 12; -pub const NFULA_SEQ_GLOBAL: ::c_int = 13; -pub const NFULA_GID: ::c_int = 14; -pub const NFULA_HWTYPE: ::c_int = 15; -pub const NFULA_HWHEADER: ::c_int = 16; -pub const NFULA_HWLEN: ::c_int = 17; -pub const NFULA_CT: ::c_int = 18; -pub const NFULA_CT_INFO: ::c_int = 19; - -pub const NFULNL_CFG_CMD_NONE: ::c_int = 0; -pub const NFULNL_CFG_CMD_BIND: ::c_int = 1; -pub const NFULNL_CFG_CMD_UNBIND: ::c_int = 2; -pub const NFULNL_CFG_CMD_PF_BIND: ::c_int = 3; -pub const NFULNL_CFG_CMD_PF_UNBIND: ::c_int = 4; - -pub const NFULA_CFG_UNSPEC: ::c_int = 0; -pub const NFULA_CFG_CMD: ::c_int = 1; -pub const NFULA_CFG_MODE: ::c_int = 2; -pub const NFULA_CFG_NLBUFSIZ: ::c_int = 3; -pub const NFULA_CFG_TIMEOUT: ::c_int = 4; -pub const NFULA_CFG_QTHRESH: ::c_int = 5; -pub const NFULA_CFG_FLAGS: ::c_int = 6; - -pub const NFULNL_COPY_NONE: ::c_int = 0x00; -pub const NFULNL_COPY_META: ::c_int = 0x01; -pub const NFULNL_COPY_PACKET: ::c_int = 0x02; - -pub const NFULNL_CFG_F_SEQ: ::c_int = 0x0001; -pub const NFULNL_CFG_F_SEQ_GLOBAL: ::c_int = 0x0002; -pub const NFULNL_CFG_F_CONNTRACK: ::c_int = 0x0004; - -pub const GENL_NAMSIZ: ::c_int = 16; - -pub const GENL_MIN_ID: ::c_int = NLMSG_MIN_TYPE; -pub const GENL_MAX_ID: ::c_int = 1023; - -pub const GENL_ADMIN_PERM: ::c_int = 0x01; -pub const GENL_CMD_CAP_DO: ::c_int = 0x02; -pub const GENL_CMD_CAP_DUMP: ::c_int = 0x04; -pub const GENL_CMD_CAP_HASPOL: ::c_int = 0x08; -pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10; - -pub const GENL_ID_CTRL: ::c_int = NLMSG_MIN_TYPE; -pub const GENL_ID_VFS_DQUOT: ::c_int = NLMSG_MIN_TYPE + 1; -pub const GENL_ID_PMCRAID: ::c_int = NLMSG_MIN_TYPE + 2; - -pub const CTRL_CMD_UNSPEC: ::c_int = 0; -pub const CTRL_CMD_NEWFAMILY: ::c_int = 1; -pub const CTRL_CMD_DELFAMILY: ::c_int = 2; -pub const CTRL_CMD_GETFAMILY: ::c_int = 3; -pub const CTRL_CMD_NEWOPS: ::c_int = 4; -pub const CTRL_CMD_DELOPS: ::c_int = 5; -pub const CTRL_CMD_GETOPS: ::c_int = 6; -pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7; -pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8; -pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9; - -pub const CTRL_ATTR_UNSPEC: ::c_int = 0; -pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1; -pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2; -pub const CTRL_ATTR_VERSION: ::c_int = 3; -pub const CTRL_ATTR_HDRSIZE: ::c_int = 4; -pub const CTRL_ATTR_MAXATTR: ::c_int = 5; -pub const CTRL_ATTR_OPS: ::c_int = 6; -pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7; - -pub const CTRL_ATTR_OP_UNSPEC: ::c_int = 0; -pub const CTRL_ATTR_OP_ID: ::c_int = 1; -pub const CTRL_ATTR_OP_FLAGS: ::c_int = 2; - -pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0; -pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1; -pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2; - -pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1; -pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2; -pub const NETLINK_PKTINFO: ::c_int = 3; -pub const NETLINK_BROADCAST_ERROR: ::c_int = 4; -pub const NETLINK_NO_ENOBUFS: ::c_int = 5; -pub const NETLINK_RX_RING: ::c_int = 6; -pub const NETLINK_TX_RING: ::c_int = 7; - -pub const GRND_NONBLOCK: ::c_uint = 0x0001; -pub const GRND_RANDOM: ::c_uint = 0x0002; - -pub const SECCOMP_MODE_DISABLED: ::c_uint = 0; -pub const SECCOMP_MODE_STRICT: ::c_uint = 1; -pub const SECCOMP_MODE_FILTER: ::c_uint = 2; - -pub const NLA_F_NESTED: ::c_int = 1 << 15; -pub const NLA_F_NET_BYTEORDER: ::c_int = 1 << 14; -pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER); - -pub const NLA_ALIGNTO: ::c_int = 4; - -pub const SIGEV_THREAD_ID: ::c_int = 4; - -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const SFD_CLOEXEC: ::c_int = O_CLOEXEC; -pub const SFD_NONBLOCK: ::c_int = O_NONBLOCK; - -pub const SOCK_NONBLOCK: ::c_int = O_NONBLOCK; - -pub const SO_ORIGINAL_DST: ::c_int = 80; -pub const IP_ORIGDSTADDR: ::c_int = 20; -pub const IP_RECVORIGDSTADDR: ::c_int = IP_ORIGDSTADDR; -pub const IPV6_ORIGDSTADDR: ::c_int = 74; -pub const IPV6_RECVORIGDSTADDR: ::c_int = IPV6_ORIGDSTADDR; -pub const IPV6_FLOWLABEL_MGR: ::c_int = 32; -pub const IPV6_FLOWINFO_SEND: ::c_int = 33; -pub const IPV6_FLOWINFO_FLOWLABEL: ::c_int = 0x000fffff; -pub const IPV6_FLOWINFO_PRIORITY: ::c_int = 0x0ff00000; - -pub const IUTF8: ::tcflag_t = 0x00004000; -pub const CMSPAR: ::tcflag_t = 0o10000000000; -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; - -pub const MFD_CLOEXEC: ::c_uint = 0x0001; -pub const MFD_ALLOW_SEALING: ::c_uint = 0x0002; -pub const MFD_HUGETLB: ::c_uint = 0x0004; - -// linux/netfilter.h -pub const NF_DROP: ::c_int = 0; -pub const NF_ACCEPT: ::c_int = 1; -pub const NF_STOLEN: ::c_int = 2; -pub const NF_QUEUE: ::c_int = 3; -pub const NF_REPEAT: ::c_int = 4; -pub const NF_STOP: ::c_int = 5; -pub const NF_MAX_VERDICT: ::c_int = NF_STOP; - -pub const NF_VERDICT_MASK: ::c_int = 0x000000ff; -pub const NF_VERDICT_FLAG_QUEUE_BYPASS: ::c_int = 0x00008000; - -pub const NF_VERDICT_QMASK: ::c_int = 0xffff0000; -pub const NF_VERDICT_QBITS: ::c_int = 16; - -pub const NF_VERDICT_BITS: ::c_int = 16; - -pub const NF_INET_PRE_ROUTING: ::c_int = 0; -pub const NF_INET_LOCAL_IN: ::c_int = 1; -pub const NF_INET_FORWARD: ::c_int = 2; -pub const NF_INET_LOCAL_OUT: ::c_int = 3; -pub const NF_INET_POST_ROUTING: ::c_int = 4; -pub const NF_INET_NUMHOOKS: ::c_int = 5; - -pub const NF_NETDEV_INGRESS: ::c_int = 0; -pub const NF_NETDEV_NUMHOOKS: ::c_int = 1; - -pub const NFPROTO_UNSPEC: ::c_int = 0; -pub const NFPROTO_INET: ::c_int = 1; -pub const NFPROTO_IPV4: ::c_int = 2; -pub const NFPROTO_ARP: ::c_int = 3; -pub const NFPROTO_NETDEV: ::c_int = 5; -pub const NFPROTO_BRIDGE: ::c_int = 7; -pub const NFPROTO_IPV6: ::c_int = 10; -pub const NFPROTO_DECNET: ::c_int = 12; -pub const NFPROTO_NUMPROTO: ::c_int = 13; - -// linux/netfilter_ipv4.h -pub const NF_IP_PRE_ROUTING: ::c_int = 0; -pub const NF_IP_LOCAL_IN: ::c_int = 1; -pub const NF_IP_FORWARD: ::c_int = 2; -pub const NF_IP_LOCAL_OUT: ::c_int = 3; -pub const NF_IP_POST_ROUTING: ::c_int = 4; -pub const NF_IP_NUMHOOKS: ::c_int = 5; - -pub const NF_IP_PRI_FIRST: ::c_int = ::INT_MIN; -pub const NF_IP_PRI_CONNTRACK_DEFRAG: ::c_int = -400; -pub const NF_IP_PRI_RAW: ::c_int = -300; -pub const NF_IP_PRI_SELINUX_FIRST: ::c_int = -225; -pub const NF_IP_PRI_CONNTRACK: ::c_int = -200; -pub const NF_IP_PRI_MANGLE: ::c_int = -150; -pub const NF_IP_PRI_NAT_DST: ::c_int = -100; -pub const NF_IP_PRI_FILTER: ::c_int = 0; -pub const NF_IP_PRI_SECURITY: ::c_int = 50; -pub const NF_IP_PRI_NAT_SRC: ::c_int = 100; -pub const NF_IP_PRI_SELINUX_LAST: ::c_int = 225; -pub const NF_IP_PRI_CONNTRACK_HELPER: ::c_int = 300; -pub const NF_IP_PRI_CONNTRACK_CONFIRM: ::c_int = ::INT_MAX; -pub const NF_IP_PRI_LAST: ::c_int = ::INT_MAX; - -// linux/netfilter_ipv6.h -pub const NF_IP6_PRE_ROUTING: ::c_int = 0; -pub const NF_IP6_LOCAL_IN: ::c_int = 1; -pub const NF_IP6_FORWARD: ::c_int = 2; -pub const NF_IP6_LOCAL_OUT: ::c_int = 3; -pub const NF_IP6_POST_ROUTING: ::c_int = 4; -pub const NF_IP6_NUMHOOKS: ::c_int = 5; - -pub const NF_IP6_PRI_FIRST: ::c_int = ::INT_MIN; -pub const NF_IP6_PRI_CONNTRACK_DEFRAG: ::c_int = -400; -pub const NF_IP6_PRI_RAW: ::c_int = -300; -pub const NF_IP6_PRI_SELINUX_FIRST: ::c_int = -225; -pub const NF_IP6_PRI_CONNTRACK: ::c_int = -200; -pub const NF_IP6_PRI_MANGLE: ::c_int = -150; -pub const NF_IP6_PRI_NAT_DST: ::c_int = -100; -pub const NF_IP6_PRI_FILTER: ::c_int = 0; -pub const NF_IP6_PRI_SECURITY: ::c_int = 50; -pub const NF_IP6_PRI_NAT_SRC: ::c_int = 100; -pub const NF_IP6_PRI_SELINUX_LAST: ::c_int = 225; -pub const NF_IP6_PRI_CONNTRACK_HELPER: ::c_int = 300; -pub const NF_IP6_PRI_LAST: ::c_int = ::INT_MAX; - -// linux/netfilter/nf_tables.h -pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256; -pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 256; -pub const NFT_SET_MAXNAMELEN: ::c_int = 256; -pub const NFT_OBJ_MAXNAMELEN: ::c_int = 256; -pub const NFT_USERDATA_MAXLEN: ::c_int = 256; - -pub const NFT_REG_VERDICT: ::c_int = 0; -pub const NFT_REG_1: ::c_int = 1; -pub const NFT_REG_2: ::c_int = 2; -pub const NFT_REG_3: ::c_int = 3; -pub const NFT_REG_4: ::c_int = 4; -pub const __NFT_REG_MAX: ::c_int = 5; -pub const NFT_REG32_00: ::c_int = 8; -pub const NFT_REG32_01: ::c_int = 9; -pub const NFT_REG32_02: ::c_int = 10; -pub const NFT_REG32_03: ::c_int = 11; -pub const NFT_REG32_04: ::c_int = 12; -pub const NFT_REG32_05: ::c_int = 13; -pub const NFT_REG32_06: ::c_int = 14; -pub const NFT_REG32_07: ::c_int = 15; -pub const NFT_REG32_08: ::c_int = 16; -pub const NFT_REG32_09: ::c_int = 17; -pub const NFT_REG32_10: ::c_int = 18; -pub const NFT_REG32_11: ::c_int = 19; -pub const NFT_REG32_12: ::c_int = 20; -pub const NFT_REG32_13: ::c_int = 21; -pub const NFT_REG32_14: ::c_int = 22; -pub const NFT_REG32_15: ::c_int = 23; - -pub const NFT_REG_SIZE: ::c_int = 16; -pub const NFT_REG32_SIZE: ::c_int = 4; - -pub const NFT_CONTINUE: ::c_int = -1; -pub const NFT_BREAK: ::c_int = -2; -pub const NFT_JUMP: ::c_int = -3; -pub const NFT_GOTO: ::c_int = -4; -pub const NFT_RETURN: ::c_int = -5; - -pub const NFT_MSG_NEWTABLE: ::c_int = 0; -pub const NFT_MSG_GETTABLE: ::c_int = 1; -pub const NFT_MSG_DELTABLE: ::c_int = 2; -pub const NFT_MSG_NEWCHAIN: ::c_int = 3; -pub const NFT_MSG_GETCHAIN: ::c_int = 4; -pub const NFT_MSG_DELCHAIN: ::c_int = 5; -pub const NFT_MSG_NEWRULE: ::c_int = 6; -pub const NFT_MSG_GETRULE: ::c_int = 7; -pub const NFT_MSG_DELRULE: ::c_int = 8; -pub const NFT_MSG_NEWSET: ::c_int = 9; -pub const NFT_MSG_GETSET: ::c_int = 10; -pub const NFT_MSG_DELSET: ::c_int = 11; -pub const NFT_MSG_NEWSETELEM: ::c_int = 12; -pub const NFT_MSG_GETSETELEM: ::c_int = 13; -pub const NFT_MSG_DELSETELEM: ::c_int = 14; -pub const NFT_MSG_NEWGEN: ::c_int = 15; -pub const NFT_MSG_GETGEN: ::c_int = 16; -pub const NFT_MSG_TRACE: ::c_int = 17; -pub const NFT_MSG_NEWOBJ: ::c_int = 18; -pub const NFT_MSG_GETOBJ: ::c_int = 19; -pub const NFT_MSG_DELOBJ: ::c_int = 20; -pub const NFT_MSG_GETOBJ_RESET: ::c_int = 21; -pub const NFT_MSG_MAX: ::c_int = 25; - -pub const NFT_SET_ANONYMOUS: ::c_int = 0x1; -pub const NFT_SET_CONSTANT: ::c_int = 0x2; -pub const NFT_SET_INTERVAL: ::c_int = 0x4; -pub const NFT_SET_MAP: ::c_int = 0x8; -pub const NFT_SET_TIMEOUT: ::c_int = 0x10; -pub const NFT_SET_EVAL: ::c_int = 0x20; - -pub const NFT_SET_POL_PERFORMANCE: ::c_int = 0; -pub const NFT_SET_POL_MEMORY: ::c_int = 1; - -pub const NFT_SET_ELEM_INTERVAL_END: ::c_int = 0x1; - -pub const NFT_DATA_VALUE: ::c_uint = 0; -pub const NFT_DATA_VERDICT: ::c_uint = 0xffffff00; - -pub const NFT_DATA_RESERVED_MASK: ::c_uint = 0xffffff00; - -pub const NFT_DATA_VALUE_MAXLEN: ::c_int = 64; - -pub const NFT_BYTEORDER_NTOH: ::c_int = 0; -pub const NFT_BYTEORDER_HTON: ::c_int = 1; - -pub const NFT_CMP_EQ: ::c_int = 0; -pub const NFT_CMP_NEQ: ::c_int = 1; -pub const NFT_CMP_LT: ::c_int = 2; -pub const NFT_CMP_LTE: ::c_int = 3; -pub const NFT_CMP_GT: ::c_int = 4; -pub const NFT_CMP_GTE: ::c_int = 5; - -pub const NFT_RANGE_EQ: ::c_int = 0; -pub const NFT_RANGE_NEQ: ::c_int = 1; - -pub const NFT_LOOKUP_F_INV: ::c_int = (1 << 0); - -pub const NFT_DYNSET_OP_ADD: ::c_int = 0; -pub const NFT_DYNSET_OP_UPDATE: ::c_int = 1; - -pub const NFT_DYNSET_F_INV: ::c_int = (1 << 0); - -pub const NFT_PAYLOAD_LL_HEADER: ::c_int = 0; -pub const NFT_PAYLOAD_NETWORK_HEADER: ::c_int = 1; -pub const NFT_PAYLOAD_TRANSPORT_HEADER: ::c_int = 2; - -pub const NFT_PAYLOAD_CSUM_NONE: ::c_int = 0; -pub const NFT_PAYLOAD_CSUM_INET: ::c_int = 1; - -pub const NFT_META_LEN: ::c_int = 0; -pub const NFT_META_PROTOCOL: ::c_int = 1; -pub const NFT_META_PRIORITY: ::c_int = 2; -pub const NFT_META_MARK: ::c_int = 3; -pub const NFT_META_IIF: ::c_int = 4; -pub const NFT_META_OIF: ::c_int = 5; -pub const NFT_META_IIFNAME: ::c_int = 6; -pub const NFT_META_OIFNAME: ::c_int = 7; -pub const NFT_META_IIFTYPE: ::c_int = 8; -pub const NFT_META_OIFTYPE: ::c_int = 9; -pub const NFT_META_SKUID: ::c_int = 10; -pub const NFT_META_SKGID: ::c_int = 11; -pub const NFT_META_NFTRACE: ::c_int = 12; -pub const NFT_META_RTCLASSID: ::c_int = 13; -pub const NFT_META_SECMARK: ::c_int = 14; -pub const NFT_META_NFPROTO: ::c_int = 15; -pub const NFT_META_L4PROTO: ::c_int = 16; -pub const NFT_META_BRI_IIFNAME: ::c_int = 17; -pub const NFT_META_BRI_OIFNAME: ::c_int = 18; -pub const NFT_META_PKTTYPE: ::c_int = 19; -pub const NFT_META_CPU: ::c_int = 20; -pub const NFT_META_IIFGROUP: ::c_int = 21; -pub const NFT_META_OIFGROUP: ::c_int = 22; -pub const NFT_META_CGROUP: ::c_int = 23; -pub const NFT_META_PRANDOM: ::c_int = 24; - -pub const NFT_CT_STATE: ::c_int = 0; -pub const NFT_CT_DIRECTION: ::c_int = 1; -pub const NFT_CT_STATUS: ::c_int = 2; -pub const NFT_CT_MARK: ::c_int = 3; -pub const NFT_CT_SECMARK: ::c_int = 4; -pub const NFT_CT_EXPIRATION: ::c_int = 5; -pub const NFT_CT_HELPER: ::c_int = 6; -pub const NFT_CT_L3PROTOCOL: ::c_int = 7; -pub const NFT_CT_SRC: ::c_int = 8; -pub const NFT_CT_DST: ::c_int = 9; -pub const NFT_CT_PROTOCOL: ::c_int = 10; -pub const NFT_CT_PROTO_SRC: ::c_int = 11; -pub const NFT_CT_PROTO_DST: ::c_int = 12; -pub const NFT_CT_LABELS: ::c_int = 13; -pub const NFT_CT_PKTS: ::c_int = 14; -pub const NFT_CT_BYTES: ::c_int = 15; - -pub const NFT_LIMIT_PKTS: ::c_int = 0; -pub const NFT_LIMIT_PKT_BYTES: ::c_int = 1; - -pub const NFT_LIMIT_F_INV: ::c_int = (1 << 0); - -pub const NFT_QUEUE_FLAG_BYPASS: ::c_int = 0x01; -pub const NFT_QUEUE_FLAG_CPU_FANOUT: ::c_int = 0x02; -pub const NFT_QUEUE_FLAG_MASK: ::c_int = 0x03; - -pub const NFT_QUOTA_F_INV: ::c_int = (1 << 0); - -pub const NFT_REJECT_ICMP_UNREACH: ::c_int = 0; -pub const NFT_REJECT_TCP_RST: ::c_int = 1; -pub const NFT_REJECT_ICMPX_UNREACH: ::c_int = 2; - -pub const NFT_REJECT_ICMPX_NO_ROUTE: ::c_int = 0; -pub const NFT_REJECT_ICMPX_PORT_UNREACH: ::c_int = 1; -pub const NFT_REJECT_ICMPX_HOST_UNREACH: ::c_int = 2; -pub const NFT_REJECT_ICMPX_ADMIN_PROHIBITED: ::c_int = 3; - -pub const NFT_NAT_SNAT: ::c_int = 0; -pub const NFT_NAT_DNAT: ::c_int = 1; - -pub const NFT_TRACETYPE_UNSPEC: ::c_int = 0; -pub const NFT_TRACETYPE_POLICY: ::c_int = 1; -pub const NFT_TRACETYPE_RETURN: ::c_int = 2; -pub const NFT_TRACETYPE_RULE: ::c_int = 3; - -pub const NFT_NG_INCREMENTAL: ::c_int = 0; -pub const NFT_NG_RANDOM: ::c_int = 1; - -pub const IFF_TUN: ::c_int = 0x0001; -pub const IFF_TAP: ::c_int = 0x0002; -pub const IFF_NO_PI: ::c_int = 0x1000; - -// start android/platform/bionic/libc/kernel/uapi/linux/if_ether.h -// from https://android.googlesource.com/ -// platform/bionic/+/master/libc/kernel/uapi/linux/if_ether.h -pub const ETH_ALEN: ::c_int = 6; -pub const ETH_HLEN: ::c_int = 14; -pub const ETH_ZLEN: ::c_int = 60; -pub const ETH_DATA_LEN: ::c_int = 1500; -pub const ETH_FRAME_LEN: ::c_int = 1514; -pub const ETH_FCS_LEN: ::c_int = 4; -pub const ETH_MIN_MTU: ::c_int = 68; -pub const ETH_MAX_MTU: ::c_int = 0xFFFF; -pub const ETH_P_LOOP: ::c_int = 0x0060; -pub const ETH_P_PUP: ::c_int = 0x0200; -pub const ETH_P_PUPAT: ::c_int = 0x0201; -pub const ETH_P_TSN: ::c_int = 0x22F0; -pub const ETH_P_IP: ::c_int = 0x0800; -pub const ETH_P_X25: ::c_int = 0x0805; -pub const ETH_P_ARP: ::c_int = 0x0806; -pub const ETH_P_BPQ: ::c_int = 0x08FF; -pub const ETH_P_IEEEPUP: ::c_int = 0x0a00; -pub const ETH_P_IEEEPUPAT: ::c_int = 0x0a01; -pub const ETH_P_BATMAN: ::c_int = 0x4305; -pub const ETH_P_DEC: ::c_int = 0x6000; -pub const ETH_P_DNA_DL: ::c_int = 0x6001; -pub const ETH_P_DNA_RC: ::c_int = 0x6002; -pub const ETH_P_DNA_RT: ::c_int = 0x6003; -pub const ETH_P_LAT: ::c_int = 0x6004; -pub const ETH_P_DIAG: ::c_int = 0x6005; -pub const ETH_P_CUST: ::c_int = 0x6006; -pub const ETH_P_SCA: ::c_int = 0x6007; -pub const ETH_P_TEB: ::c_int = 0x6558; -pub const ETH_P_RARP: ::c_int = 0x8035; -pub const ETH_P_ATALK: ::c_int = 0x809B; -pub const ETH_P_AARP: ::c_int = 0x80F3; -pub const ETH_P_8021Q: ::c_int = 0x8100; -/* see rust-lang/libc#924 pub const ETH_P_ERSPAN: ::c_int = 0x88BE;*/ -pub const ETH_P_IPX: ::c_int = 0x8137; -pub const ETH_P_IPV6: ::c_int = 0x86DD; -pub const ETH_P_PAUSE: ::c_int = 0x8808; -pub const ETH_P_SLOW: ::c_int = 0x8809; -pub const ETH_P_WCCP: ::c_int = 0x883E; -pub const ETH_P_MPLS_UC: ::c_int = 0x8847; -pub const ETH_P_MPLS_MC: ::c_int = 0x8848; -pub const ETH_P_ATMMPOA: ::c_int = 0x884c; -pub const ETH_P_PPP_DISC: ::c_int = 0x8863; -pub const ETH_P_PPP_SES: ::c_int = 0x8864; -pub const ETH_P_LINK_CTL: ::c_int = 0x886c; -pub const ETH_P_ATMFATE: ::c_int = 0x8884; -pub const ETH_P_PAE: ::c_int = 0x888E; -pub const ETH_P_AOE: ::c_int = 0x88A2; -pub const ETH_P_8021AD: ::c_int = 0x88A8; -pub const ETH_P_802_EX1: ::c_int = 0x88B5; -pub const ETH_P_TIPC: ::c_int = 0x88CA; -pub const ETH_P_MACSEC: ::c_int = 0x88E5; -pub const ETH_P_8021AH: ::c_int = 0x88E7; -pub const ETH_P_MVRP: ::c_int = 0x88F5; -pub const ETH_P_1588: ::c_int = 0x88F7; -pub const ETH_P_NCSI: ::c_int = 0x88F8; -pub const ETH_P_PRP: ::c_int = 0x88FB; -pub const ETH_P_FCOE: ::c_int = 0x8906; -/* see rust-lang/libc#924 pub const ETH_P_IBOE: ::c_int = 0x8915;*/ -pub const ETH_P_TDLS: ::c_int = 0x890D; -pub const ETH_P_FIP: ::c_int = 0x8914; -pub const ETH_P_80221: ::c_int = 0x8917; -pub const ETH_P_HSR: ::c_int = 0x892F; -/* see rust-lang/libc#924 pub const ETH_P_NSH: ::c_int = 0x894F;*/ -pub const ETH_P_LOOPBACK: ::c_int = 0x9000; -pub const ETH_P_QINQ1: ::c_int = 0x9100; -pub const ETH_P_QINQ2: ::c_int = 0x9200; -pub const ETH_P_QINQ3: ::c_int = 0x9300; -pub const ETH_P_EDSA: ::c_int = 0xDADA; -/* see rust-lang/libc#924 pub const ETH_P_IFE: ::c_int = 0xED3E;*/ -pub const ETH_P_AF_IUCV: ::c_int = 0xFBFB; -pub const ETH_P_802_3_MIN: ::c_int = 0x0600; -pub const ETH_P_802_3: ::c_int = 0x0001; -pub const ETH_P_AX25: ::c_int = 0x0002; -pub const ETH_P_ALL: ::c_int = 0x0003; -pub const ETH_P_802_2: ::c_int = 0x0004; -pub const ETH_P_SNAP: ::c_int = 0x0005; -pub const ETH_P_DDCMP: ::c_int = 0x0006; -pub const ETH_P_WAN_PPP: ::c_int = 0x0007; -pub const ETH_P_PPP_MP: ::c_int = 0x0008; -pub const ETH_P_LOCALTALK: ::c_int = 0x0009; -pub const ETH_P_CAN: ::c_int = 0x000C; -pub const ETH_P_CANFD: ::c_int = 0x000D; -pub const ETH_P_PPPTALK: ::c_int = 0x0010; -pub const ETH_P_TR_802_2: ::c_int = 0x0011; -pub const ETH_P_MOBITEX: ::c_int = 0x0015; -pub const ETH_P_CONTROL: ::c_int = 0x0016; -pub const ETH_P_IRDA: ::c_int = 0x0017; -pub const ETH_P_ECONET: ::c_int = 0x0018; -pub const ETH_P_HDLC: ::c_int = 0x0019; -pub const ETH_P_ARCNET: ::c_int = 0x001A; -pub const ETH_P_DSA: ::c_int = 0x001B; -pub const ETH_P_TRAILER: ::c_int = 0x001C; -pub const ETH_P_PHONET: ::c_int = 0x00F5; -pub const ETH_P_IEEE802154: ::c_int = 0x00F6; -pub const ETH_P_CAIF: ::c_int = 0x00F7; -pub const ETH_P_XDSA: ::c_int = 0x00F8; -/* see rust-lang/libc#924 pub const ETH_P_MAP: ::c_int = 0x00F9;*/ -// end android/platform/bionic/libc/kernel/uapi/linux/if_ether.h - -pub const SIOCADDRT: ::c_ulong = 0x0000890B; -pub const SIOCDELRT: ::c_ulong = 0x0000890C; -pub const SIOCGIFNAME: ::c_ulong = 0x00008910; -pub const SIOCSIFLINK: ::c_ulong = 0x00008911; -pub const SIOCGIFCONF: ::c_ulong = 0x00008912; -pub const SIOCGIFFLAGS: ::c_ulong = 0x00008913; -pub const SIOCSIFFLAGS: ::c_ulong = 0x00008914; -pub const SIOCGIFADDR: ::c_ulong = 0x00008915; -pub const SIOCSIFADDR: ::c_ulong = 0x00008916; -pub const SIOCGIFDSTADDR: ::c_ulong = 0x00008917; -pub const SIOCSIFDSTADDR: ::c_ulong = 0x00008918; -pub const SIOCGIFBRDADDR: ::c_ulong = 0x00008919; -pub const SIOCSIFBRDADDR: ::c_ulong = 0x0000891A; -pub const SIOCGIFNETMASK: ::c_ulong = 0x0000891B; -pub const SIOCSIFNETMASK: ::c_ulong = 0x0000891C; -pub const SIOCGIFMETRIC: ::c_ulong = 0x0000891D; -pub const SIOCSIFMETRIC: ::c_ulong = 0x0000891E; -pub const SIOCGIFMEM: ::c_ulong = 0x0000891F; -pub const SIOCSIFMEM: ::c_ulong = 0x00008920; -pub const SIOCGIFMTU: ::c_ulong = 0x00008921; -pub const SIOCSIFMTU: ::c_ulong = 0x00008922; -pub const SIOCSIFHWADDR: ::c_ulong = 0x00008924; -pub const SIOCGIFENCAP: ::c_ulong = 0x00008925; -pub const SIOCSIFENCAP: ::c_ulong = 0x00008926; -pub const SIOCGIFHWADDR: ::c_ulong = 0x00008927; -pub const SIOCGIFSLAVE: ::c_ulong = 0x00008929; -pub const SIOCSIFSLAVE: ::c_ulong = 0x00008930; -pub const SIOCADDMULTI: ::c_ulong = 0x00008931; -pub const SIOCDELMULTI: ::c_ulong = 0x00008932; -pub const SIOCDARP: ::c_ulong = 0x00008953; -pub const SIOCGARP: ::c_ulong = 0x00008954; -pub const SIOCSARP: ::c_ulong = 0x00008955; -pub const SIOCDRARP: ::c_ulong = 0x00008960; -pub const SIOCGRARP: ::c_ulong = 0x00008961; -pub const SIOCSRARP: ::c_ulong = 0x00008962; -pub const SIOCGIFMAP: ::c_ulong = 0x00008970; -pub const SIOCSIFMAP: ::c_ulong = 0x00008971; - -// linux/module.h -pub const MODULE_INIT_IGNORE_MODVERSIONS: ::c_uint = 0x0001; -pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002; - -#[deprecated( - since = "0.2.55", - note = "ENOATTR is not available on Android; use ENODATA instead" -)] -pub const ENOATTR: ::c_int = ::ENODATA; - -// linux/if_alg.h -pub const ALG_SET_KEY: ::c_int = 1; -pub const ALG_SET_IV: ::c_int = 2; -pub const ALG_SET_OP: ::c_int = 3; -pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4; -pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5; - -pub const ALG_OP_DECRYPT: ::c_int = 0; -pub const ALG_OP_ENCRYPT: ::c_int = 1; - -// uapi/linux/inotify.h -pub const IN_ACCESS: u32 = 0x0000_0001; -pub const IN_MODIFY: u32 = 0x0000_0002; -pub const IN_ATTRIB: u32 = 0x0000_0004; -pub const IN_CLOSE_WRITE: u32 = 0x0000_0008; -pub const IN_CLOSE_NOWRITE: u32 = 0x0000_0010; -pub const IN_CLOSE: u32 = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE); -pub const IN_OPEN: u32 = 0x0000_0020; -pub const IN_MOVED_FROM: u32 = 0x0000_0040; -pub const IN_MOVED_TO: u32 = 0x0000_0080; -pub const IN_MOVE: u32 = (IN_MOVED_FROM | IN_MOVED_TO); -pub const IN_CREATE: u32 = 0x0000_0100; -pub const IN_DELETE: u32 = 0x0000_0200; -pub const IN_DELETE_SELF: u32 = 0x0000_0400; -pub const IN_MOVE_SELF: u32 = 0x0000_0800; -pub const IN_UNMOUNT: u32 = 0x0000_2000; -pub const IN_Q_OVERFLOW: u32 = 0x0000_4000; -pub const IN_IGNORED: u32 = 0x0000_8000; -pub const IN_ONLYDIR: u32 = 0x0100_0000; -pub const IN_DONT_FOLLOW: u32 = 0x0200_0000; -// pub const IN_EXCL_UNLINK: u32 = 0x0400_0000; - -// pub const IN_MASK_CREATE: u32 = 0x1000_0000; -// pub const IN_MASK_ADD: u32 = 0x2000_0000; -pub const IN_ISDIR: u32 = 0x4000_0000; -pub const IN_ONESHOT: u32 = 0x8000_0000; - -pub const IN_ALL_EVENTS: u32 = (IN_ACCESS - | IN_MODIFY - | IN_ATTRIB - | IN_CLOSE_WRITE - | IN_CLOSE_NOWRITE - | IN_OPEN - | IN_MOVED_FROM - | IN_MOVED_TO - | IN_DELETE - | IN_CREATE - | IN_DELETE_SELF - | IN_MOVE_SELF); - -pub const IN_CLOEXEC: ::c_int = O_CLOEXEC; -pub const IN_NONBLOCK: ::c_int = O_NONBLOCK; - -pub const FUTEX_WAIT: ::c_int = 0; -pub const FUTEX_WAKE: ::c_int = 1; -pub const FUTEX_FD: ::c_int = 2; -pub const FUTEX_REQUEUE: ::c_int = 3; -pub const FUTEX_CMP_REQUEUE: ::c_int = 4; -pub const FUTEX_WAKE_OP: ::c_int = 5; -pub const FUTEX_LOCK_PI: ::c_int = 6; -pub const FUTEX_UNLOCK_PI: ::c_int = 7; -pub const FUTEX_TRYLOCK_PI: ::c_int = 8; -pub const FUTEX_WAIT_BITSET: ::c_int = 9; -pub const FUTEX_WAKE_BITSET: ::c_int = 10; -pub const FUTEX_WAIT_REQUEUE_PI: ::c_int = 11; -pub const FUTEX_CMP_REQUEUE_PI: ::c_int = 12; - -pub const FUTEX_PRIVATE_FLAG: ::c_int = 128; -pub const FUTEX_CLOCK_REALTIME: ::c_int = 256; -pub const FUTEX_CMD_MASK: ::c_int = - !(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME); - -f! { - pub fn CMSG_NXTHDR(mhdr: *const msghdr, - cmsg: *const cmsghdr) -> *mut cmsghdr { - let next = (cmsg as usize - + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) - as *mut cmsghdr; - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if (next.offset(1)) as usize > max { - 0 as *mut cmsghdr - } else { - next as *mut cmsghdr - } - } - - pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { - for slot in cpuset.__bits.iter_mut() { - *slot = 0; - } - } - - pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in___bits = 8 * ::mem::size_of_val(&cpuset.__bits[0]); - let (idx, offset) = (cpu / size_in___bits, cpu % size_in___bits); - cpuset.__bits[idx] |= 1 << offset; - () - } - - pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in___bits = 8 * ::mem::size_of_val(&cpuset.__bits[0]); - let (idx, offset) = (cpu / size_in___bits, cpu % size_in___bits); - cpuset.__bits[idx] &= !(1 << offset); - () - } - - pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in___bits = 8 * ::mem::size_of_val(&cpuset.__bits[0]); - let (idx, offset) = (cpu / size_in___bits, cpu % size_in___bits); - 0 != (cpuset.__bits[idx] & (1 << offset)) - } - - pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool { - set1.__bits == set2.__bits - } - pub fn major(dev: ::dev_t) -> ::c_int { - ((dev >> 8) & 0xfff) as ::c_int - } - pub fn minor(dev: ::dev_t) -> ::c_int { - ((dev & 0xff) | ((dev >> 12) & 0xfff00)) as ::c_int - } - pub fn makedev(ma: ::c_int, mi: ::c_int) -> ::dev_t { - let ma = ma as ::dev_t; - let mi = mi as ::dev_t; - ((ma & 0xfff) << 8) | (mi & 0xff) | ((mi & 0xfff00) << 12) - } - - pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { - return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1) - } -} - -extern "C" { - pub fn getrlimit64(resource: ::c_int, rlim: *mut rlimit64) -> ::c_int; - pub fn setrlimit64(resource: ::c_int, rlim: *const rlimit64) -> ::c_int; - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; - pub fn madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - pub fn msync( - addr: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::size_t, - serv: *mut ::c_char, - sevlen: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn ptrace(request: ::c_int, ...) -> ::c_long; - pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int; - pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int; - pub fn __sched_cpualloc(count: ::size_t) -> *mut ::cpu_set_t; - pub fn __sched_cpufree(set: *mut ::cpu_set_t); - pub fn __sched_cpucount( - setsize: ::size_t, - set: *const cpu_set_t, - ) -> ::c_int; - pub fn sched_getcpu() -> ::c_int; - - pub fn utmpname(name: *const ::c_char) -> ::c_int; - pub fn setutent(); - pub fn getutent() -> *mut utmp; - - pub fn posix_fallocate( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - ) -> ::c_int; - pub fn signalfd( - fd: ::c_int, - mask: *const ::sigset_t, - flags: ::c_int, - ) -> ::c_int; - pub fn syscall(num: ::c_long, ...) -> ::c_long; - pub fn sched_getaffinity( - pid: ::pid_t, - cpusetsize: ::size_t, - cpuset: *mut cpu_set_t, - ) -> ::c_int; - pub fn sched_setaffinity( - pid: ::pid_t, - cpusetsize: ::size_t, - cpuset: *const cpu_set_t, - ) -> ::c_int; - pub fn epoll_create(size: ::c_int) -> ::c_int; - pub fn epoll_create1(flags: ::c_int) -> ::c_int; - pub fn epoll_wait( - epfd: ::c_int, - events: *mut ::epoll_event, - maxevents: ::c_int, - timeout: ::c_int, - ) -> ::c_int; - pub fn epoll_ctl( - epfd: ::c_int, - op: ::c_int, - fd: ::c_int, - event: *mut ::epoll_event, - ) -> ::c_int; - pub fn pthread_getschedparam( - native: ::pthread_t, - policy: *mut ::c_int, - param: *mut ::sched_param, - ) -> ::c_int; - pub fn unshare(flags: ::c_int) -> ::c_int; - pub fn umount(target: *const ::c_char) -> ::c_int; - pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int; - pub fn tee( - fd_in: ::c_int, - fd_out: ::c_int, - len: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn settimeofday( - tv: *const ::timeval, - tz: *const ::timezone, - ) -> ::c_int; - pub fn splice( - fd_in: ::c_int, - off_in: *mut ::loff_t, - fd_out: ::c_int, - off_out: *mut ::loff_t, - len: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int; - pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) - -> ::c_int; - pub fn sem_timedwait( - sem: *mut sem_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; - pub fn sched_setparam( - pid: ::pid_t, - param: *const ::sched_param, - ) -> ::c_int; - pub fn setns(fd: ::c_int, nstype: ::c_int) -> ::c_int; - pub fn swapoff(puath: *const ::c_char) -> ::c_int; - pub fn vmsplice( - fd: ::c_int, - iov: *const ::iovec, - nr_segs: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn mount( - src: *const ::c_char, - target: *const ::c_char, - fstype: *const ::c_char, - flags: ::c_ulong, - data: *const ::c_void, - ) -> ::c_int; - pub fn personality(persona: ::c_uint) -> ::c_int; - pub fn prctl(option: ::c_int, ...) -> ::c_int; - pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int; - pub fn ppoll( - fds: *mut ::pollfd, - nfds: nfds_t, - timeout: *const ::timespec, - sigmask: *const sigset_t, - ) -> ::c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn clone( - cb: extern "C" fn(*mut ::c_void) -> ::c_int, - child_stack: *mut ::c_void, - flags: ::c_int, - arg: *mut ::c_void, - ... - ) -> ::c_int; - pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int; - pub fn clock_nanosleep( - clk_id: ::clockid_t, - flags: ::c_int, - rqtp: *const ::timespec, - rmtp: *mut ::timespec, - ) -> ::c_int; - pub fn pthread_attr_getguardsize( - attr: *const ::pthread_attr_t, - guardsize: *mut ::size_t, - ) -> ::c_int; - pub fn sethostname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn sched_get_priority_min(policy: ::c_int) -> ::c_int; - pub fn pthread_condattr_getpshared( - attr: *const pthread_condattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - pub fn sysinfo(info: *mut ::sysinfo) -> ::c_int; - pub fn umount2(target: *const ::c_char, flags: ::c_int) -> ::c_int; - pub fn pthread_setschedparam( - native: ::pthread_t, - policy: ::c_int, - param: *const ::sched_param, - ) -> ::c_int; - pub fn swapon(path: *const ::c_char, swapflags: ::c_int) -> ::c_int; - pub fn sched_setscheduler( - pid: ::pid_t, - policy: ::c_int, - param: *const ::sched_param, - ) -> ::c_int; - pub fn sendfile( - out_fd: ::c_int, - in_fd: ::c_int, - offset: *mut off_t, - count: ::size_t, - ) -> ::ssize_t; - pub fn setfsgid(gid: ::gid_t) -> ::c_int; - pub fn setfsuid(uid: ::uid_t) -> ::c_int; - pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r( - gid: ::gid_t, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigaltstack$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] - pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; - pub fn sem_close(sem: *mut sem_t) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")] - pub fn getgrnam_r( - name: *const ::c_char, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_sigmask$UNIX2003" - )] - pub fn pthread_sigmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; - pub fn getgrnam(name: *const ::c_char) -> *mut ::group; - pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; - pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")] - pub fn getpwnam_r( - name: *const ::c_char, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")] - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigwait$UNIX2003" - )] - #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] - pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn getgrgid(gid: ::gid_t) -> *mut ::group; - pub fn getgrouplist( - user: *const ::c_char, - group: ::gid_t, - groups: *mut ::gid_t, - ngroups: *mut ::c_int, - ) -> ::c_int; - pub fn initgroups(user: *const ::c_char, group: ::gid_t) -> ::c_int; - pub fn pthread_mutexattr_getpshared( - attr: *const pthread_mutexattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "popen$UNIX2003" - )] - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - pub fn faccessat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn pthread_create( - native: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - pub fn __errno() -> *mut ::c_int; - pub fn inotify_rm_watch(fd: ::c_int, wd: u32) -> ::c_int; - pub fn sendmmsg( - sockfd: ::c_int, - msgvec: *const ::mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - ) -> ::c_int; - pub fn recvmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn inotify_init() -> ::c_int; - pub fn inotify_init1(flags: ::c_int) -> ::c_int; - pub fn inotify_add_watch( - fd: ::c_int, - path: *const ::c_char, - mask: u32, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - mod b32; - pub use self::b32::*; - } else if #[cfg(target_pointer_width = "64")] { - mod b64; - pub use self::b64::*; - } else { - // Unknown target_pointer_width - } -} - -impl siginfo_t { - pub unsafe fn si_value(&self) -> ::sigval { - #[repr(C)] - struct siginfo_timer { - _si_signo: ::c_int, - _si_errno: ::c_int, - _si_code: ::c_int, - _si_tid: ::c_int, - _si_overrun: ::c_int, - si_sigval: ::sigval, - } - (*(self as *const siginfo_t as *const siginfo_timer)).si_sigval - } -} diff --git a/libc/src/unix/linux_like/emscripten/align.rs b/libc/src/unix/linux_like/emscripten/align.rs deleted file mode 100644 index 141570f..0000000 --- a/libc/src/unix/linux_like/emscripten/align.rs +++ /dev/null @@ -1,74 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - #[allow(missing_debug_implementations)] - #[repr(align(4))] - pub struct pthread_mutex_t { - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - #[repr(align(4))] - pub struct pthread_rwlock_t { - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - - #[repr(align(4))] - pub struct pthread_mutexattr_t { - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[repr(align(4))] - pub struct pthread_rwlockattr_t { - size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - #[repr(align(4))] - pub struct pthread_condattr_t { - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - - s_no_extra_traits! { - #[cfg_attr(target_pointer_width = "32", - repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", - repr(align(8)))] - pub struct pthread_cond_t { - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - #[allow(missing_debug_implementations)] - #[repr(align(8))] - pub struct max_align_t { - priv_: [f64; 2] - } - - } - - cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for pthread_cond_t { - fn eq(&self, other: &pthread_cond_t) -> bool { - self.size - .iter() - .zip(other.size.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_cond_t {} - impl ::fmt::Debug for pthread_cond_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_cond_t") - // FIXME: .field("size", &self.size) - .finish() - } - } - impl ::hash::Hash for pthread_cond_t { - fn hash(&self, state: &mut H) { - self.size.hash(state); - } - } - } - } - }; -} diff --git a/libc/src/unix/linux_like/emscripten/mod.rs b/libc/src/unix/linux_like/emscripten/mod.rs deleted file mode 100644 index 3fc47bb..0000000 --- a/libc/src/unix/linux_like/emscripten/mod.rs +++ /dev/null @@ -1,1917 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; -pub type useconds_t = u32; -pub type dev_t = u32; -pub type socklen_t = u32; -pub type pthread_t = c_ulong; -pub type mode_t = u32; -pub type ino64_t = u64; -pub type off64_t = i64; -pub type blkcnt64_t = i32; -pub type rlim64_t = u64; -pub type shmatt_t = ::c_ulong; -pub type mqd_t = ::c_int; -pub type msgqnum_t = ::c_ulong; -pub type msglen_t = ::c_ulong; -pub type nfds_t = ::c_ulong; -pub type nl_item = ::c_int; -pub type idtype_t = ::c_uint; -pub type loff_t = i64; -pub type pthread_key_t = ::c_uint; - -pub type clock_t = c_long; -pub type time_t = c_long; -pub type suseconds_t = c_long; -pub type ino_t = u64; -pub type off_t = i64; -pub type blkcnt_t = i32; - -pub type blksize_t = c_long; -pub type fsblkcnt_t = u32; -pub type fsfilcnt_t = u32; -pub type rlim_t = ::c_ulonglong; -pub type c_long = i32; -pub type c_ulong = u32; -pub type nlink_t = u32; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos64_t {} // TODO: fill this out with a struct -impl ::Copy for fpos64_t {} -impl ::Clone for fpos64_t { - fn clone(&self) -> fpos64_t { - *self - } -} - -s! { - pub struct rlimit64 { - pub rlim_cur: rlim64_t, - pub rlim_max: rlim64_t, - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut c_char, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct spwd { - pub sp_namp: *mut ::c_char, - pub sp_pwdp: *mut ::c_char, - pub sp_lstchg: ::c_long, - pub sp_min: ::c_long, - pub sp_max: ::c_long, - pub sp_warn: ::c_long, - pub sp_inact: ::c_long, - pub sp_expire: ::c_long, - pub sp_flag: ::c_ulong, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct dqblk { - pub dqb_bhardlimit: u64, - pub dqb_bsoftlimit: u64, - pub dqb_curspace: u64, - pub dqb_ihardlimit: u64, - pub dqb_isoftlimit: u64, - pub dqb_curinodes: u64, - pub dqb_btime: u64, - pub dqb_itime: u64, - pub dqb_valid: u32, - } - - pub struct signalfd_siginfo { - pub ssi_signo: u32, - pub ssi_errno: i32, - pub ssi_code: i32, - pub ssi_pid: u32, - pub ssi_uid: u32, - pub ssi_fd: i32, - pub ssi_tid: u32, - pub ssi_band: u32, - pub ssi_overrun: u32, - pub ssi_trapno: u32, - pub ssi_status: i32, - pub ssi_int: i32, - pub ssi_ptr: u64, - pub ssi_utime: u64, - pub ssi_stime: u64, - pub ssi_addr: u64, - pub ssi_addr_lsb: u16, - _pad2: u16, - pub ssi_syscall: i32, - pub ssi_call_addr: u64, - pub ssi_arch: u32, - _pad: [u8; 28], - } - - pub struct fsid_t { - __val: [::c_int; 2], - } - - pub struct cpu_set_t { - bits: [u32; 32], - } - - pub struct if_nameindex { - pub if_index: ::c_uint, - pub if_name: *mut ::c_char, - } - - // System V IPC - pub struct msginfo { - pub msgpool: ::c_int, - pub msgmap: ::c_int, - pub msgmax: ::c_int, - pub msgmnb: ::c_int, - pub msgmni: ::c_int, - pub msgssz: ::c_int, - pub msgtql: ::c_int, - pub msgseg: ::c_ushort, - } - - pub struct sembuf { - pub sem_num: ::c_ushort, - pub sem_op: ::c_short, - pub sem_flg: ::c_short, - } - - pub struct aiocb { - pub aio_fildes: ::c_int, - pub aio_lio_opcode: ::c_int, - pub aio_reqprio: ::c_int, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - pub aio_sigevent: ::sigevent, - __td: *mut ::c_void, - __lock: [::c_int; 2], - __err: ::c_int, - __ret: ::ssize_t, - pub aio_offset: off_t, - __next: *mut ::c_void, - __prev: *mut ::c_void, - __dummy4: [::c_char; 24], - } - - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __unused1: ::c_long, - __unused2: ::c_long - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - pub __c_ispeed: ::speed_t, - pub __c_ospeed: ::speed_t, - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct pthread_attr_t { - __size: [u32; 11] - } - - pub struct sigset_t { - __val: [::c_ulong; 32], - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::socklen_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct sem_t { - __val: [::c_int; 4], - } - pub struct stat { - pub st_dev: ::dev_t, - __st_dev_padding: ::c_int, - __st_ino_truncated: ::c_long, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_int, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino_t, - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __st_dev_padding: ::c_int, - __st_ino_truncated: ::c_long, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_int, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino_t, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - __unused1: ::c_int, - pub shm_dtime: ::time_t, - __unused2: ::c_int, - pub shm_ctime: ::time_t, - __unused3: ::c_int, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - __unused1: ::c_int, - pub msg_rtime: ::time_t, - __unused2: ::c_int, - pub msg_ctime: ::time_t, - __unused3: ::c_int, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u32, - pub f_bfree: u32, - pub f_bavail: u32, - pub f_files: u32, - pub f_ffree: u32, - pub f_favail: u32, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct arpd_request { - pub req: ::c_ushort, - pub ip: u32, - pub dev: ::c_ulong, - pub stamp: ::c_ulong, - pub updated: ::c_ulong, - pub ha: [::c_uchar; ::MAX_ADDR_LEN], - } -} - -s_no_extra_traits! { - pub struct dirent { - pub d_ino: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct sysinfo { - pub uptime: ::c_ulong, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub __reserved: [::c_char; 256], - } - - pub struct mq_attr { - pub mq_flags: ::c_long, - pub mq_maxmsg: ::c_long, - pub mq_msgsize: ::c_long, - pub mq_curmsgs: ::c_long, - pad: [::c_long; 4] - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent {} - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for dirent64 { - fn eq(&self, other: &dirent64) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for dirent64 {} - impl ::fmt::Debug for dirent64 { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent64") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - impl ::hash::Hash for dirent64 { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for sysinfo { - fn eq(&self, other: &sysinfo) -> bool { - self.uptime == other.uptime - && self.loads == other.loads - && self.totalram == other.totalram - && self.freeram == other.freeram - && self.sharedram == other.sharedram - && self.bufferram == other.bufferram - && self.totalswap == other.totalswap - && self.freeswap == other.freeswap - && self.procs == other.procs - && self.pad == other.pad - && self.totalhigh == other.totalhigh - && self.freehigh == other.freehigh - && self.mem_unit == other.mem_unit - && self - .__reserved - .iter() - .zip(other.__reserved.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sysinfo {} - impl ::fmt::Debug for sysinfo { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sysinfo") - .field("uptime", &self.uptime) - .field("loads", &self.loads) - .field("totalram", &self.totalram) - .field("freeram", &self.freeram) - .field("sharedram", &self.sharedram) - .field("bufferram", &self.bufferram) - .field("totalswap", &self.totalswap) - .field("freeswap", &self.freeswap) - .field("procs", &self.procs) - .field("pad", &self.pad) - .field("totalhigh", &self.totalhigh) - .field("freehigh", &self.freehigh) - .field("mem_unit", &self.mem_unit) - // FIXME: .field("__reserved", &self.__reserved) - .finish() - } - } - impl ::hash::Hash for sysinfo { - fn hash(&self, state: &mut H) { - self.uptime.hash(state); - self.loads.hash(state); - self.totalram.hash(state); - self.freeram.hash(state); - self.sharedram.hash(state); - self.bufferram.hash(state); - self.totalswap.hash(state); - self.freeswap.hash(state); - self.procs.hash(state); - self.pad.hash(state); - self.totalhigh.hash(state); - self.freehigh.hash(state); - self.mem_unit.hash(state); - self.__reserved.hash(state); - } - } - - impl PartialEq for mq_attr { - fn eq(&self, other: &mq_attr) -> bool { - self.mq_flags == other.mq_flags && - self.mq_maxmsg == other.mq_maxmsg && - self.mq_msgsize == other.mq_msgsize && - self.mq_curmsgs == other.mq_curmsgs - } - } - impl Eq for mq_attr {} - impl ::fmt::Debug for mq_attr { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("mq_attr") - .field("mq_flags", &self.mq_flags) - .field("mq_maxmsg", &self.mq_maxmsg) - .field("mq_msgsize", &self.mq_msgsize) - .field("mq_curmsgs", &self.mq_curmsgs) - .finish() - } - } - impl ::hash::Hash for mq_attr { - fn hash(&self, state: &mut H) { - self.mq_flags.hash(state); - self.mq_maxmsg.hash(state); - self.mq_msgsize.hash(state); - self.mq_curmsgs.hash(state); - } - } - } -} - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MS_NOUSER: ::c_ulong = 0x80000000; -pub const MS_RMT_MASK: ::c_ulong = 0x02800051; - -pub const ABDAY_1: ::nl_item = 0x20000; -pub const ABDAY_2: ::nl_item = 0x20001; -pub const ABDAY_3: ::nl_item = 0x20002; -pub const ABDAY_4: ::nl_item = 0x20003; -pub const ABDAY_5: ::nl_item = 0x20004; -pub const ABDAY_6: ::nl_item = 0x20005; -pub const ABDAY_7: ::nl_item = 0x20006; - -pub const DAY_1: ::nl_item = 0x20007; -pub const DAY_2: ::nl_item = 0x20008; -pub const DAY_3: ::nl_item = 0x20009; -pub const DAY_4: ::nl_item = 0x2000A; -pub const DAY_5: ::nl_item = 0x2000B; -pub const DAY_6: ::nl_item = 0x2000C; -pub const DAY_7: ::nl_item = 0x2000D; - -pub const ABMON_1: ::nl_item = 0x2000E; -pub const ABMON_2: ::nl_item = 0x2000F; -pub const ABMON_3: ::nl_item = 0x20010; -pub const ABMON_4: ::nl_item = 0x20011; -pub const ABMON_5: ::nl_item = 0x20012; -pub const ABMON_6: ::nl_item = 0x20013; -pub const ABMON_7: ::nl_item = 0x20014; -pub const ABMON_8: ::nl_item = 0x20015; -pub const ABMON_9: ::nl_item = 0x20016; -pub const ABMON_10: ::nl_item = 0x20017; -pub const ABMON_11: ::nl_item = 0x20018; -pub const ABMON_12: ::nl_item = 0x20019; - -pub const MON_1: ::nl_item = 0x2001A; -pub const MON_2: ::nl_item = 0x2001B; -pub const MON_3: ::nl_item = 0x2001C; -pub const MON_4: ::nl_item = 0x2001D; -pub const MON_5: ::nl_item = 0x2001E; -pub const MON_6: ::nl_item = 0x2001F; -pub const MON_7: ::nl_item = 0x20020; -pub const MON_8: ::nl_item = 0x20021; -pub const MON_9: ::nl_item = 0x20022; -pub const MON_10: ::nl_item = 0x20023; -pub const MON_11: ::nl_item = 0x20024; -pub const MON_12: ::nl_item = 0x20025; - -pub const AM_STR: ::nl_item = 0x20026; -pub const PM_STR: ::nl_item = 0x20027; - -pub const D_T_FMT: ::nl_item = 0x20028; -pub const D_FMT: ::nl_item = 0x20029; -pub const T_FMT: ::nl_item = 0x2002A; -pub const T_FMT_AMPM: ::nl_item = 0x2002B; - -pub const ERA: ::nl_item = 0x2002C; -pub const ERA_D_FMT: ::nl_item = 0x2002E; -pub const ALT_DIGITS: ::nl_item = 0x2002F; -pub const ERA_D_T_FMT: ::nl_item = 0x20030; -pub const ERA_T_FMT: ::nl_item = 0x20031; - -pub const CODESET: ::nl_item = 14; - -pub const CRNCYSTR: ::nl_item = 0x4000F; - -pub const RUSAGE_THREAD: ::c_int = 1; -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const RADIXCHAR: ::nl_item = 0x10000; -pub const THOUSEP: ::nl_item = 0x10001; - -pub const YESEXPR: ::nl_item = 0x50000; -pub const NOEXPR: ::nl_item = 0x50001; -pub const YESSTR: ::nl_item = 0x50002; -pub const NOSTR: ::nl_item = 0x50003; - -pub const FILENAME_MAX: ::c_uint = 4096; -pub const L_tmpnam: ::c_uint = 20; -pub const _PC_LINK_MAX: ::c_int = 0; -pub const _PC_MAX_CANON: ::c_int = 1; -pub const _PC_MAX_INPUT: ::c_int = 2; -pub const _PC_NAME_MAX: ::c_int = 3; -pub const _PC_PATH_MAX: ::c_int = 4; -pub const _PC_PIPE_BUF: ::c_int = 5; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 6; -pub const _PC_NO_TRUNC: ::c_int = 7; -pub const _PC_VDISABLE: ::c_int = 8; -pub const _PC_SYNC_IO: ::c_int = 9; -pub const _PC_ASYNC_IO: ::c_int = 10; -pub const _PC_PRIO_IO: ::c_int = 11; -pub const _PC_SOCK_MAXBUF: ::c_int = 12; -pub const _PC_FILESIZEBITS: ::c_int = 13; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 14; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 15; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 16; -pub const _PC_REC_XFER_ALIGN: ::c_int = 17; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 18; -pub const _PC_SYMLINK_MAX: ::c_int = 19; -pub const _PC_2_SYMLINKS: ::c_int = 20; - -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_CHILD_MAX: ::c_int = 1; -pub const _SC_CLK_TCK: ::c_int = 2; -pub const _SC_NGROUPS_MAX: ::c_int = 3; -pub const _SC_OPEN_MAX: ::c_int = 4; -pub const _SC_STREAM_MAX: ::c_int = 5; -pub const _SC_TZNAME_MAX: ::c_int = 6; -pub const _SC_JOB_CONTROL: ::c_int = 7; -pub const _SC_SAVED_IDS: ::c_int = 8; -pub const _SC_REALTIME_SIGNALS: ::c_int = 9; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 10; -pub const _SC_TIMERS: ::c_int = 11; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 12; -pub const _SC_PRIORITIZED_IO: ::c_int = 13; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 14; -pub const _SC_FSYNC: ::c_int = 15; -pub const _SC_MAPPED_FILES: ::c_int = 16; -pub const _SC_MEMLOCK: ::c_int = 17; -pub const _SC_MEMLOCK_RANGE: ::c_int = 18; -pub const _SC_MEMORY_PROTECTION: ::c_int = 19; -pub const _SC_MESSAGE_PASSING: ::c_int = 20; -pub const _SC_SEMAPHORES: ::c_int = 21; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 22; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 23; -pub const _SC_AIO_MAX: ::c_int = 24; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 25; -pub const _SC_DELAYTIMER_MAX: ::c_int = 26; -pub const _SC_MQ_OPEN_MAX: ::c_int = 27; -pub const _SC_MQ_PRIO_MAX: ::c_int = 28; -pub const _SC_VERSION: ::c_int = 29; -pub const _SC_PAGESIZE: ::c_int = 30; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_RTSIG_MAX: ::c_int = 31; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 32; -pub const _SC_SEM_VALUE_MAX: ::c_int = 33; -pub const _SC_SIGQUEUE_MAX: ::c_int = 34; -pub const _SC_TIMER_MAX: ::c_int = 35; -pub const _SC_BC_BASE_MAX: ::c_int = 36; -pub const _SC_BC_DIM_MAX: ::c_int = 37; -pub const _SC_BC_SCALE_MAX: ::c_int = 38; -pub const _SC_BC_STRING_MAX: ::c_int = 39; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 40; -pub const _SC_EXPR_NEST_MAX: ::c_int = 42; -pub const _SC_LINE_MAX: ::c_int = 43; -pub const _SC_RE_DUP_MAX: ::c_int = 44; -pub const _SC_2_VERSION: ::c_int = 46; -pub const _SC_2_C_BIND: ::c_int = 47; -pub const _SC_2_C_DEV: ::c_int = 48; -pub const _SC_2_FORT_DEV: ::c_int = 49; -pub const _SC_2_FORT_RUN: ::c_int = 50; -pub const _SC_2_SW_DEV: ::c_int = 51; -pub const _SC_2_LOCALEDEF: ::c_int = 52; -pub const _SC_UIO_MAXIOV: ::c_int = 60; -pub const _SC_IOV_MAX: ::c_int = 60; -pub const _SC_THREADS: ::c_int = 67; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 68; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 69; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 70; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 71; -pub const _SC_TTY_NAME_MAX: ::c_int = 72; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 73; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 74; -pub const _SC_THREAD_STACK_MIN: ::c_int = 75; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 76; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 77; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 78; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 79; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 80; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 81; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 82; -pub const _SC_NPROCESSORS_CONF: ::c_int = 83; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 84; -pub const _SC_PHYS_PAGES: ::c_int = 85; -pub const _SC_AVPHYS_PAGES: ::c_int = 86; -pub const _SC_ATEXIT_MAX: ::c_int = 87; -pub const _SC_PASS_MAX: ::c_int = 88; -pub const _SC_XOPEN_VERSION: ::c_int = 89; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 90; -pub const _SC_XOPEN_UNIX: ::c_int = 91; -pub const _SC_XOPEN_CRYPT: ::c_int = 92; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 93; -pub const _SC_XOPEN_SHM: ::c_int = 94; -pub const _SC_2_CHAR_TERM: ::c_int = 95; -pub const _SC_2_UPE: ::c_int = 97; -pub const _SC_XOPEN_XPG2: ::c_int = 98; -pub const _SC_XOPEN_XPG3: ::c_int = 99; -pub const _SC_XOPEN_XPG4: ::c_int = 100; -pub const _SC_NZERO: ::c_int = 109; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = 125; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = 126; -pub const _SC_XBS5_LP64_OFF64: ::c_int = 127; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = 128; -pub const _SC_XOPEN_LEGACY: ::c_int = 129; -pub const _SC_XOPEN_REALTIME: ::c_int = 130; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 131; -pub const _SC_ADVISORY_INFO: ::c_int = 132; -pub const _SC_BARRIERS: ::c_int = 133; -pub const _SC_CLOCK_SELECTION: ::c_int = 137; -pub const _SC_CPUTIME: ::c_int = 138; -pub const _SC_THREAD_CPUTIME: ::c_int = 139; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 149; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 153; -pub const _SC_SPIN_LOCKS: ::c_int = 154; -pub const _SC_REGEXP: ::c_int = 155; -pub const _SC_SHELL: ::c_int = 157; -pub const _SC_SPAWN: ::c_int = 159; -pub const _SC_SPORADIC_SERVER: ::c_int = 160; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 161; -pub const _SC_TIMEOUTS: ::c_int = 164; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 165; -pub const _SC_2_PBS: ::c_int = 168; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 169; -pub const _SC_2_PBS_LOCATE: ::c_int = 170; -pub const _SC_2_PBS_MESSAGE: ::c_int = 171; -pub const _SC_2_PBS_TRACK: ::c_int = 172; -pub const _SC_SYMLOOP_MAX: ::c_int = 173; -pub const _SC_STREAMS: ::c_int = 174; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 175; -pub const _SC_V6_ILP32_OFF32: ::c_int = 176; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 177; -pub const _SC_V6_LP64_OFF64: ::c_int = 178; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 179; -pub const _SC_HOST_NAME_MAX: ::c_int = 180; -pub const _SC_TRACE: ::c_int = 181; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 182; -pub const _SC_TRACE_INHERIT: ::c_int = 183; -pub const _SC_TRACE_LOG: ::c_int = 184; -pub const _SC_IPV6: ::c_int = 235; -pub const _SC_RAW_SOCKETS: ::c_int = 236; -pub const _SC_V7_ILP32_OFF32: ::c_int = 237; -pub const _SC_V7_ILP32_OFFBIG: ::c_int = 238; -pub const _SC_V7_LP64_OFF64: ::c_int = 239; -pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 240; -pub const _SC_SS_REPL_MAX: ::c_int = 241; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 242; -pub const _SC_TRACE_NAME_MAX: ::c_int = 243; -pub const _SC_TRACE_SYS_MAX: ::c_int = 244; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 245; -pub const _SC_XOPEN_STREAMS: ::c_int = 246; -pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 247; -pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 248; - -pub const RLIM_SAVED_MAX: ::rlim_t = RLIM_INFINITY; -pub const RLIM_SAVED_CUR: ::rlim_t = RLIM_INFINITY; - -pub const GLOB_ERR: ::c_int = 1 << 0; -pub const GLOB_MARK: ::c_int = 1 << 1; -pub const GLOB_NOSORT: ::c_int = 1 << 2; -pub const GLOB_DOOFFS: ::c_int = 1 << 3; -pub const GLOB_NOCHECK: ::c_int = 1 << 4; -pub const GLOB_APPEND: ::c_int = 1 << 5; -pub const GLOB_NOESCAPE: ::c_int = 1 << 6; - -pub const GLOB_NOSPACE: ::c_int = 1; -pub const GLOB_ABORTED: ::c_int = 2; -pub const GLOB_NOMATCH: ::c_int = 3; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; - -pub const S_IEXEC: mode_t = 64; -pub const S_IWRITE: mode_t = 128; -pub const S_IREAD: mode_t = 256; - -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; - -pub const ST_RDONLY: ::c_ulong = 1; -pub const ST_NOSUID: ::c_ulong = 2; -pub const ST_NODEV: ::c_ulong = 4; -pub const ST_NOEXEC: ::c_ulong = 8; -pub const ST_SYNCHRONOUS: ::c_ulong = 16; -pub const ST_MANDLOCK: ::c_ulong = 64; -pub const ST_WRITE: ::c_ulong = 128; -pub const ST_APPEND: ::c_ulong = 256; -pub const ST_IMMUTABLE: ::c_ulong = 512; -pub const ST_NOATIME: ::c_ulong = 1024; -pub const ST_NODIRATIME: ::c_ulong = 2048; - -pub const RTLD_NEXT: *mut ::c_void = -1i64 as *mut ::c_void; -pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; -pub const RTLD_NODELETE: ::c_int = 0x1000; -pub const RTLD_NOW: ::c_int = 0x2; - -pub const TCP_MD5SIG: ::c_int = 14; - -align_const! { - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - size: [0; __SIZEOF_PTHREAD_MUTEX_T], - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - size: [0; __SIZEOF_PTHREAD_COND_T], - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - size: [0; __SIZEOF_PTHREAD_RWLOCK_T], - }; -} - -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; -pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0; -pub const PTHREAD_PROCESS_SHARED: ::c_int = 1; -pub const __SIZEOF_PTHREAD_COND_T: usize = 48; - -pub const SCHED_OTHER: ::c_int = 0; -pub const SCHED_FIFO: ::c_int = 1; -pub const SCHED_RR: ::c_int = 2; -pub const SCHED_BATCH: ::c_int = 3; -pub const SCHED_IDLE: ::c_int = 5; - -pub const AF_IB: ::c_int = 27; -pub const AF_MPLS: ::c_int = 28; -pub const AF_NFC: ::c_int = 39; -pub const AF_VSOCK: ::c_int = 40; -pub const PF_IB: ::c_int = AF_IB; -pub const PF_MPLS: ::c_int = AF_MPLS; -pub const PF_NFC: ::c_int = AF_NFC; -pub const PF_VSOCK: ::c_int = AF_VSOCK; - -// System V IPC -pub const IPC_PRIVATE: ::key_t = 0; - -pub const IPC_CREAT: ::c_int = 0o1000; -pub const IPC_EXCL: ::c_int = 0o2000; -pub const IPC_NOWAIT: ::c_int = 0o4000; - -pub const IPC_RMID: ::c_int = 0; -pub const IPC_SET: ::c_int = 1; -pub const IPC_STAT: ::c_int = 2; -pub const IPC_INFO: ::c_int = 3; -pub const MSG_STAT: ::c_int = 11; -pub const MSG_INFO: ::c_int = 12; - -pub const MSG_NOERROR: ::c_int = 0o10000; -pub const MSG_EXCEPT: ::c_int = 0o20000; - -pub const SHM_R: ::c_int = 0o400; -pub const SHM_W: ::c_int = 0o200; - -pub const SHM_RDONLY: ::c_int = 0o10000; -pub const SHM_RND: ::c_int = 0o20000; -pub const SHM_REMAP: ::c_int = 0o40000; -pub const SHM_EXEC: ::c_int = 0o100000; - -pub const SHM_LOCK: ::c_int = 11; -pub const SHM_UNLOCK: ::c_int = 12; - -pub const SHM_HUGETLB: ::c_int = 0o4000; -pub const SHM_NORESERVE: ::c_int = 0o10000; - -pub const EPOLLRDHUP: ::c_int = 0x2000; -pub const EPOLLEXCLUSIVE: ::c_int = 0x10000000; -pub const EPOLLONESHOT: ::c_int = 0x40000000; - -pub const QFMT_VFS_OLD: ::c_int = 1; -pub const QFMT_VFS_V0: ::c_int = 2; - -pub const EFD_SEMAPHORE: ::c_int = 0x1; - -pub const LOG_NFACILITIES: ::c_int = 24; - -pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; - -pub const RB_AUTOBOOT: ::c_int = 0x01234567u32 as i32; -pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123u32 as i32; -pub const RB_ENABLE_CAD: ::c_int = 0x89abcdefu32 as i32; -pub const RB_DISABLE_CAD: ::c_int = 0x00000000u32 as i32; -pub const RB_POWER_OFF: ::c_int = 0x4321fedcu32 as i32; -pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2u32 as i32; -pub const RB_KEXEC: ::c_int = 0x45584543u32 as i32; - -pub const AI_PASSIVE: ::c_int = 0x0001; -pub const AI_CANONNAME: ::c_int = 0x0002; -pub const AI_NUMERICHOST: ::c_int = 0x0004; -pub const AI_V4MAPPED: ::c_int = 0x0008; -pub const AI_ALL: ::c_int = 0x0010; -pub const AI_ADDRCONFIG: ::c_int = 0x0020; - -pub const AI_NUMERICSERV: ::c_int = 0x0400; - -pub const EAI_BADFLAGS: ::c_int = -1; -pub const EAI_NONAME: ::c_int = -2; -pub const EAI_AGAIN: ::c_int = -3; -pub const EAI_FAIL: ::c_int = -4; -pub const EAI_FAMILY: ::c_int = -6; -pub const EAI_SOCKTYPE: ::c_int = -7; -pub const EAI_SERVICE: ::c_int = -8; -pub const EAI_MEMORY: ::c_int = -10; -pub const EAI_OVERFLOW: ::c_int = -12; - -pub const NI_NUMERICHOST: ::c_int = 1; -pub const NI_NUMERICSERV: ::c_int = 2; -pub const NI_NOFQDN: ::c_int = 4; -pub const NI_NAMEREQD: ::c_int = 8; -pub const NI_DGRAM: ::c_int = 16; - -pub const SYNC_FILE_RANGE_WAIT_BEFORE: ::c_uint = 1; -pub const SYNC_FILE_RANGE_WRITE: ::c_uint = 2; -pub const SYNC_FILE_RANGE_WAIT_AFTER: ::c_uint = 4; - -pub const EAI_SYSTEM: ::c_int = -11; - -pub const AIO_CANCELED: ::c_int = 0; -pub const AIO_NOTCANCELED: ::c_int = 1; -pub const AIO_ALLDONE: ::c_int = 2; -pub const LIO_READ: ::c_int = 0; -pub const LIO_WRITE: ::c_int = 1; -pub const LIO_NOP: ::c_int = 2; -pub const LIO_WAIT: ::c_int = 0; -pub const LIO_NOWAIT: ::c_int = 1; - -pub const MREMAP_MAYMOVE: ::c_int = 1; -pub const MREMAP_FIXED: ::c_int = 2; - -pub const PR_SET_PDEATHSIG: ::c_int = 1; -pub const PR_GET_PDEATHSIG: ::c_int = 2; - -pub const PR_GET_DUMPABLE: ::c_int = 3; -pub const PR_SET_DUMPABLE: ::c_int = 4; - -pub const PR_GET_UNALIGN: ::c_int = 5; -pub const PR_SET_UNALIGN: ::c_int = 6; -pub const PR_UNALIGN_NOPRINT: ::c_int = 1; -pub const PR_UNALIGN_SIGBUS: ::c_int = 2; - -pub const PR_GET_KEEPCAPS: ::c_int = 7; -pub const PR_SET_KEEPCAPS: ::c_int = 8; - -pub const PR_GET_FPEMU: ::c_int = 9; -pub const PR_SET_FPEMU: ::c_int = 10; -pub const PR_FPEMU_NOPRINT: ::c_int = 1; -pub const PR_FPEMU_SIGFPE: ::c_int = 2; - -pub const PR_GET_FPEXC: ::c_int = 11; -pub const PR_SET_FPEXC: ::c_int = 12; -pub const PR_FP_EXC_SW_ENABLE: ::c_int = 0x80; -pub const PR_FP_EXC_DIV: ::c_int = 0x010000; -pub const PR_FP_EXC_OVF: ::c_int = 0x020000; -pub const PR_FP_EXC_UND: ::c_int = 0x040000; -pub const PR_FP_EXC_RES: ::c_int = 0x080000; -pub const PR_FP_EXC_INV: ::c_int = 0x100000; -pub const PR_FP_EXC_DISABLED: ::c_int = 0; -pub const PR_FP_EXC_NONRECOV: ::c_int = 1; -pub const PR_FP_EXC_ASYNC: ::c_int = 2; -pub const PR_FP_EXC_PRECISE: ::c_int = 3; - -pub const PR_GET_TIMING: ::c_int = 13; -pub const PR_SET_TIMING: ::c_int = 14; -pub const PR_TIMING_STATISTICAL: ::c_int = 0; -pub const PR_TIMING_TIMESTAMP: ::c_int = 1; - -pub const PR_SET_NAME: ::c_int = 15; -pub const PR_GET_NAME: ::c_int = 16; - -pub const PR_GET_ENDIAN: ::c_int = 19; -pub const PR_SET_ENDIAN: ::c_int = 20; -pub const PR_ENDIAN_BIG: ::c_int = 0; -pub const PR_ENDIAN_LITTLE: ::c_int = 1; -pub const PR_ENDIAN_PPC_LITTLE: ::c_int = 2; - -pub const PR_GET_SECCOMP: ::c_int = 21; -pub const PR_SET_SECCOMP: ::c_int = 22; - -pub const PR_CAPBSET_READ: ::c_int = 23; -pub const PR_CAPBSET_DROP: ::c_int = 24; - -pub const PR_GET_TSC: ::c_int = 25; -pub const PR_SET_TSC: ::c_int = 26; -pub const PR_TSC_ENABLE: ::c_int = 1; -pub const PR_TSC_SIGSEGV: ::c_int = 2; - -pub const PR_GET_SECUREBITS: ::c_int = 27; -pub const PR_SET_SECUREBITS: ::c_int = 28; - -pub const PR_SET_TIMERSLACK: ::c_int = 29; -pub const PR_GET_TIMERSLACK: ::c_int = 30; - -pub const PR_TASK_PERF_EVENTS_DISABLE: ::c_int = 31; -pub const PR_TASK_PERF_EVENTS_ENABLE: ::c_int = 32; - -pub const PR_MCE_KILL: ::c_int = 33; -pub const PR_MCE_KILL_CLEAR: ::c_int = 0; -pub const PR_MCE_KILL_SET: ::c_int = 1; - -pub const PR_MCE_KILL_LATE: ::c_int = 0; -pub const PR_MCE_KILL_EARLY: ::c_int = 1; -pub const PR_MCE_KILL_DEFAULT: ::c_int = 2; - -pub const PR_MCE_KILL_GET: ::c_int = 34; - -pub const PR_SET_MM: ::c_int = 35; -pub const PR_SET_MM_START_CODE: ::c_int = 1; -pub const PR_SET_MM_END_CODE: ::c_int = 2; -pub const PR_SET_MM_START_DATA: ::c_int = 3; -pub const PR_SET_MM_END_DATA: ::c_int = 4; -pub const PR_SET_MM_START_STACK: ::c_int = 5; -pub const PR_SET_MM_START_BRK: ::c_int = 6; -pub const PR_SET_MM_BRK: ::c_int = 7; -pub const PR_SET_MM_ARG_START: ::c_int = 8; -pub const PR_SET_MM_ARG_END: ::c_int = 9; -pub const PR_SET_MM_ENV_START: ::c_int = 10; -pub const PR_SET_MM_ENV_END: ::c_int = 11; -pub const PR_SET_MM_AUXV: ::c_int = 12; -pub const PR_SET_MM_EXE_FILE: ::c_int = 13; -pub const PR_SET_MM_MAP: ::c_int = 14; -pub const PR_SET_MM_MAP_SIZE: ::c_int = 15; - -pub const PR_SET_PTRACER: ::c_int = 0x59616d61; - -pub const PR_SET_CHILD_SUBREAPER: ::c_int = 36; -pub const PR_GET_CHILD_SUBREAPER: ::c_int = 37; - -pub const PR_SET_NO_NEW_PRIVS: ::c_int = 38; -pub const PR_GET_NO_NEW_PRIVS: ::c_int = 39; - -pub const PR_GET_TID_ADDRESS: ::c_int = 40; - -pub const PR_SET_THP_DISABLE: ::c_int = 41; -pub const PR_GET_THP_DISABLE: ::c_int = 42; - -pub const PR_MPX_ENABLE_MANAGEMENT: ::c_int = 43; -pub const PR_MPX_DISABLE_MANAGEMENT: ::c_int = 44; - -pub const PR_SET_FP_MODE: ::c_int = 45; -pub const PR_GET_FP_MODE: ::c_int = 46; -pub const PR_FP_MODE_FR: ::c_int = 1 << 0; -pub const PR_FP_MODE_FRE: ::c_int = 1 << 1; - -pub const PR_CAP_AMBIENT: ::c_int = 47; -pub const PR_CAP_AMBIENT_IS_SET: ::c_int = 1; -pub const PR_CAP_AMBIENT_RAISE: ::c_int = 2; -pub const PR_CAP_AMBIENT_LOWER: ::c_int = 3; -pub const PR_CAP_AMBIENT_CLEAR_ALL: ::c_int = 4; - -pub const ITIMER_REAL: ::c_int = 0; -pub const ITIMER_VIRTUAL: ::c_int = 1; -pub const ITIMER_PROF: ::c_int = 2; - -pub const XATTR_CREATE: ::c_int = 0x1; -pub const XATTR_REPLACE: ::c_int = 0x2; - -pub const _POSIX_VDISABLE: ::cc_t = 0; - -pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01; -pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02; - -// On Linux, libc doesn't define this constant, libattr does instead. -// We still define it for Linux as it's defined by libc on other platforms, -// and it's mentioned in the man pages for getxattr and setxattr. -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; -pub const O_NOATIME: ::c_int = 0o1000000; -pub const O_CLOEXEC: ::c_int = 0x80000; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const BUFSIZ: ::c_uint = 1024; -pub const TMP_MAX: ::c_uint = 10000; -pub const FOPEN_MAX: ::c_uint = 1000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_EXEC: ::c_int = 0o10000000; -pub const O_SEARCH: ::c_int = 0o10000000; -pub const O_ACCMODE: ::c_int = 0o10000003; -pub const O_NDELAY: ::c_int = O_NONBLOCK; -pub const NI_MAXHOST: ::socklen_t = 255; -pub const PTHREAD_STACK_MIN: ::size_t = 2048; -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const POSIX_MADV_DONTNEED: ::c_int = 0; - -pub const RLIM_INFINITY: ::rlim_t = !0; -pub const RLIMIT_NLIMITS: ::c_int = 15; - -pub const MAP_ANONYMOUS: ::c_int = MAP_ANON; - -pub const TCP_THIN_LINEAR_TIMEOUTS: ::c_int = 16; -pub const TCP_THIN_DUPACK: ::c_int = 17; -pub const TCP_USER_TIMEOUT: ::c_int = 18; -pub const TCP_REPAIR: ::c_int = 19; -pub const TCP_REPAIR_QUEUE: ::c_int = 20; -pub const TCP_QUEUE_SEQ: ::c_int = 21; -pub const TCP_REPAIR_OPTIONS: ::c_int = 22; -pub const TCP_FASTOPEN: ::c_int = 23; -pub const TCP_TIMESTAMP: ::c_int = 24; - -#[doc(hidden)] -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = ::SIGSYS; - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; - -pub const CPU_SETSIZE: ::c_int = 128; - -pub const QFMT_VFS_V1: ::c_int = 4; - -pub const PTRACE_TRACEME: ::c_int = 0; -pub const PTRACE_PEEKTEXT: ::c_int = 1; -pub const PTRACE_PEEKDATA: ::c_int = 2; -pub const PTRACE_PEEKUSER: ::c_int = 3; -pub const PTRACE_POKETEXT: ::c_int = 4; -pub const PTRACE_POKEDATA: ::c_int = 5; -pub const PTRACE_POKEUSER: ::c_int = 6; -pub const PTRACE_CONT: ::c_int = 7; -pub const PTRACE_KILL: ::c_int = 8; -pub const PTRACE_SINGLESTEP: ::c_int = 9; -pub const PTRACE_ATTACH: ::c_int = 16; -pub const PTRACE_DETACH: ::c_int = 17; -pub const PTRACE_SYSCALL: ::c_int = 24; -pub const PTRACE_SETOPTIONS: ::c_int = 0x4200; -pub const PTRACE_GETEVENTMSG: ::c_int = 0x4201; -pub const PTRACE_GETSIGINFO: ::c_int = 0x4202; -pub const PTRACE_SETSIGINFO: ::c_int = 0x4203; -pub const PTRACE_GETREGSET: ::c_int = 0x4204; -pub const PTRACE_SETREGSET: ::c_int = 0x4205; -pub const PTRACE_SEIZE: ::c_int = 0x4206; -pub const PTRACE_INTERRUPT: ::c_int = 0x4207; -pub const PTRACE_LISTEN: ::c_int = 0x4208; -pub const PTRACE_PEEKSIGINFO: ::c_int = 0x4209; - -pub const EPOLLWAKEUP: ::c_int = 0x20000000; - -pub const PTRACE_GETFPREGS: ::c_uint = 14; -pub const PTRACE_SETFPREGS: ::c_uint = 15; -pub const PTRACE_GETFPXREGS: ::c_uint = 18; -pub const PTRACE_SETFPXREGS: ::c_uint = 19; -pub const PTRACE_GETREGS: ::c_uint = 12; -pub const PTRACE_SETREGS: ::c_uint = 13; - -pub const EFD_NONBLOCK: ::c_int = ::O_NONBLOCK; - -pub const SFD_NONBLOCK: ::c_int = ::O_NONBLOCK; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCINQ: ::c_int = ::FIONREAD; - -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; - -// TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux -// kernel 3.10). See also linux_like/mod.rs -pub const CLOCK_SGI_CYCLE: ::clockid_t = 10; -pub const CLOCK_TAI: ::clockid_t = 11; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::c_int = 0x00000800; -pub const TAB2: ::c_int = 0x00001000; -pub const TAB3: ::c_int = 0x00001800; -pub const CR1: ::c_int = 0x00000200; -pub const CR2: ::c_int = 0x00000400; -pub const CR3: ::c_int = 0x00000600; -pub const FF1: ::c_int = 0x00008000; -pub const BS1: ::c_int = 0x00002000; -pub const VT1: ::c_int = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_MARK: ::c_int = 36; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_BUSY_POLL: ::c_int = 46; - -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 28; - -pub const O_DIRECT: ::c_int = 0x4000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; -pub const O_ASYNC: ::c_int = 0x2000; - -pub const FIOCLEX: ::c_int = 0x5451; -pub const FIONBIO: ::c_int = 0x5421; - -pub const RLIMIT_RSS: ::c_int = 5; -pub const RLIMIT_NOFILE: ::c_int = 7; -pub const RLIMIT_AS: ::c_int = 9; -pub const RLIMIT_NPROC: ::c_int = 6; -pub const RLIMIT_MEMLOCK: ::c_int = 8; -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_LOCKS: ::c_int = 10; -pub const RLIMIT_SIGPENDING: ::c_int = 11; -pub const RLIMIT_MSGQUEUE: ::c_int = 12; -pub const RLIMIT_NICE: ::c_int = 13; -pub const RLIMIT_RTPRIO: ::c_int = 14; - -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; - -pub const SOCK_NONBLOCK: ::c_int = 2048; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_SEQPACKET: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EDEADLOCK: ::c_int = EDEADLK; -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_LINGER: ::c_int = 13; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_ACCEPTCONN: ::c_int = 30; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const EXTPROC: ::tcflag_t = 0x00010000; - -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const F_GETLK: ::c_int = 12; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETLK: ::c_int = 13; -pub const F_SETLKW: ::c_int = 14; -pub const F_SETOWN: ::c_int = 8; - -pub const VEOF: usize = 4; -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; - -pub const TCGETS: ::c_int = 0x5401; -pub const TCSETS: ::c_int = 0x5402; -pub const TCSETSW: ::c_int = 0x5403; -pub const TCSETSF: ::c_int = 0x5404; -pub const TCGETA: ::c_int = 0x5405; -pub const TCSETA: ::c_int = 0x5406; -pub const TCSETAW: ::c_int = 0x5407; -pub const TCSETAF: ::c_int = 0x5408; -pub const TCSBRK: ::c_int = 0x5409; -pub const TCXONC: ::c_int = 0x540A; -pub const TCFLSH: ::c_int = 0x540B; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x540F; -pub const TIOCSPGRP: ::c_int = 0x5410; -pub const TIOCOUTQ: ::c_int = 0x5411; -pub const TIOCSTI: ::c_int = 0x5412; -pub const TIOCGWINSZ: ::c_int = 0x5413; -pub const TIOCSWINSZ: ::c_int = 0x5414; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x541B; -pub const TIOCCONS: ::c_int = 0x541D; - -pub const SYS_gettid: ::c_long = 224; // Valid for arm (32-bit) and x86 (32-bit) - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; -pub const O_TMPFILE: ::c_int = 0x400000; - -pub const MAX_ADDR_LEN: usize = 7; -pub const ARPD_UPDATE: ::c_ushort = 0x01; -pub const ARPD_LOOKUP: ::c_ushort = 0x02; -pub const ARPD_FLUSH: ::c_ushort = 0x03; -pub const ATF_MAGIC: ::c_int = 0x80; - -f! { - pub fn CMSG_NXTHDR(mhdr: *const msghdr, - cmsg: *const cmsghdr) -> *mut cmsghdr { - if ((*cmsg).cmsg_len as usize) < ::mem::size_of::() { - return 0 as *mut cmsghdr; - }; - let next = (cmsg as usize + - super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) - as *mut cmsghdr; - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if (next.offset(1)) as usize > max { - 0 as *mut cmsghdr - } else { - next as *mut cmsghdr - } - } - - pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { - for slot in cpuset.bits.iter_mut() { - *slot = 0; - } - } - - pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits - = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] |= 1 << offset; - () - } - - pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits - = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] &= !(1 << offset); - () - } - - pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * ::mem::size_of_val(&cpuset.bits[0]); - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - 0 != (cpuset.bits[idx] & (1 << offset)) - } - - pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool { - set1.bits == set2.bits - } - - pub fn major(dev: ::dev_t) -> ::c_uint { - // see - // https://github.com/kripken/emscripten/blob/ - // master/system/include/libc/sys/sysmacros.h - let mut major = 0; - major |= (dev & 0x00000fff) >> 8; - major |= (dev & 0xfffff000) >> 31 >> 1; - major as ::c_uint - } - - pub fn minor(dev: ::dev_t) -> ::c_uint { - // see - // https://github.com/kripken/emscripten/blob/ - // master/system/include/libc/sys/sysmacros.h - let mut minor = 0; - minor |= (dev & 0x000000ff) >> 0; - minor |= (dev & 0xffffff00) >> 12; - minor as ::c_uint - } - - pub fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t { - let major = major as ::dev_t; - let minor = minor as ::dev_t; - let mut dev = 0; - dev |= (major & 0x00000fff) << 8; - dev |= (major & 0xfffff000) << 31 << 1; - dev |= (minor & 0x000000ff) << 0; - dev |= (minor & 0xffffff00) << 12; - dev - } -} - -extern "C" { - pub fn getrlimit64(resource: ::c_int, rlim: *mut rlimit64) -> ::c_int; - pub fn setrlimit64(resource: ::c_int, rlim: *const rlimit64) -> ::c_int; - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; - pub fn rand() -> ::c_int; - pub fn srand(seed: ::c_uint); - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - - pub fn setpwent(); - pub fn endpwent(); - pub fn getpwent() -> *mut passwd; - - pub fn shm_open( - name: *const c_char, - oflag: ::c_int, - mode: mode_t, - ) -> ::c_int; - - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn __errno_location() -> *mut ::c_int; - - pub fn fopen64( - filename: *const c_char, - mode: *const c_char, - ) -> *mut ::FILE; - pub fn freopen64( - filename: *const c_char, - mode: *const c_char, - file: *mut ::FILE, - ) -> *mut ::FILE; - pub fn tmpfile64() -> *mut ::FILE; - pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int; - pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int; - pub fn fseeko64( - stream: *mut ::FILE, - offset: ::off64_t, - whence: ::c_int, - ) -> ::c_int; - pub fn ftello64(stream: *mut ::FILE) -> ::off64_t; - pub fn posix_fallocate( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - ) -> ::c_int; - pub fn pwritev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn preadv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn dup3(oldfd: ::c_int, newfd: ::c_int, flags: ::c_int) -> ::c_int; - pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int; - pub fn mkostemps( - template: *mut ::c_char, - suffixlen: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) - -> *mut ::c_char; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::socklen_t, - serv: *mut ::c_char, - sevlen: ::socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int; - - // Not available now on Android - pub fn mkfifoat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - pub fn if_nameindex() -> *mut if_nameindex; - pub fn if_freenameindex(ptr: *mut if_nameindex); - - pub fn mremap( - addr: *mut ::c_void, - len: ::size_t, - new_len: ::size_t, - flags: ::c_int, - ... - ) -> *mut ::c_void; - - pub fn glob( - pattern: *const c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut ::glob_t, - ) -> ::c_int; - pub fn globfree(pglob: *mut ::glob_t); - - pub fn posix_madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn shm_unlink(name: *const ::c_char) -> ::c_int; - - pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); - - pub fn telldir(dirp: *mut ::DIR) -> ::c_long; - pub fn madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn msync( - addr: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::c_int; - - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; - pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; - - pub fn getdomainname(name: *mut ::c_char, len: ::size_t) -> ::c_int; - pub fn setdomainname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn sendmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_uint, - ) -> ::c_int; - pub fn recvmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_uint, - timeout: *mut ::timespec, - ) -> ::c_int; - pub fn sync(); - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int; - pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int; - pub fn pthread_create( - native: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - #[macro_use] - mod align; - } else { - #[macro_use] - mod no_align; - } -} -expand_align!(); diff --git a/libc/src/unix/linux_like/emscripten/no_align.rs b/libc/src/unix/linux_like/emscripten/no_align.rs deleted file mode 100644 index 768dc73..0000000 --- a/libc/src/unix/linux_like/emscripten/no_align.rs +++ /dev/null @@ -1,63 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - pub struct pthread_mutex_t { - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - pub struct pthread_rwlock_t { - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - - pub struct pthread_mutexattr_t { - __align: [::c_int; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - pub struct pthread_rwlockattr_t { - __align: [::c_int; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - pub struct pthread_condattr_t { - __align: [::c_int; 0], - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - - s_no_extra_traits! { - pub struct pthread_cond_t { - __align: [*const ::c_void; 0], - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - } - - cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for pthread_cond_t { - fn eq(&self, other: &pthread_cond_t) -> bool { - self.size - .iter() - .zip(other.size.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for pthread_cond_t {} - impl ::fmt::Debug for pthread_cond_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_cond_t") - // FIXME: .field("size", &self.size) - .finish() - } - } - impl ::hash::Hash for pthread_cond_t { - fn hash(&self, state: &mut H) { - self.size.hash(state); - } - } - } - } - }; -} diff --git a/libc/src/unix/linux_like/linux/align.rs b/libc/src/unix/linux_like/linux/align.rs deleted file mode 100644 index 6000b41..0000000 --- a/libc/src/unix/linux_like/linux/align.rs +++ /dev/null @@ -1,106 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - #[cfg_attr(any(target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64", - target_arch = "aarch64"), - repr(align(4)))] - #[cfg_attr(not(any(target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64", - target_arch = "aarch64")), - repr(align(8)))] - pub struct pthread_mutexattr_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[cfg_attr(any(target_env = "musl", target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(not(target_env = "musl"), - target_pointer_width = "64"), - repr(align(8)))] - pub struct pthread_rwlockattr_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - #[repr(align(4))] - pub struct pthread_condattr_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - - s_no_extra_traits! { - #[cfg_attr(all(target_env = "musl", - target_pointer_width = "32"), - repr(align(4)))] - #[cfg_attr(all(target_env = "musl", - target_pointer_width = "64"), - repr(align(8)))] - #[cfg_attr(all(not(target_env = "musl"), - target_arch = "x86"), - repr(align(4)))] - #[cfg_attr(all(not(target_env = "musl"), - not(target_arch = "x86")), - repr(align(8)))] - pub struct pthread_cond_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86"))), - repr(align(8)))] - pub struct pthread_mutex_t { - #[doc(hidden)] - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "hexagon", - target_arch = "powerpc", - target_arch = "sparc", - target_arch = "x86_64", - target_arch = "x86"))), - repr(align(8)))] - pub struct pthread_rwlock_t { - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - } - }; -} diff --git a/libc/src/unix/linux_like/linux/gnu/align.rs b/libc/src/unix/linux_like/linux/gnu/align.rs deleted file mode 100644 index 4a0e074..0000000 --- a/libc/src/unix/linux_like/linux/gnu/align.rs +++ /dev/null @@ -1,13 +0,0 @@ -s! { - // FIXME this is actually a union - #[cfg_attr(target_pointer_width = "32", - repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", - repr(align(8)))] - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/arm/align.rs b/libc/src/unix/linux_like/linux/gnu/b32/arm/align.rs deleted file mode 100644 index 825546b..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/arm/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(8))] - pub struct max_align_t { - priv_: [i64; 2] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/arm/mod.rs b/libc/src/unix/linux_like/linux/gnu/b32/arm/mod.rs deleted file mode 100644 index 0a5fc85..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/arm/mod.rs +++ /dev/null @@ -1,876 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statfs { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - f_spare: [::__fsword_t; 5], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_ushort, - __pad1: ::c_ushort, - pub __seq: ::c_ushort, - __pad2: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __pad1: ::c_uint, - __st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: ::c_uint, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino64_t, - } - - pub struct statfs64 { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - pub f_flags: ::__fsword_t, - pub f_spare: [::__fsword_t; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - __unused1: ::c_ulong, - pub shm_dtime: ::time_t, - __unused2: ::c_ulong, - pub shm_ctime: ::time_t, - __unused3: ::c_ulong, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - __glibc_reserved1: ::c_ulong, - pub msg_rtime: ::time_t, - __glibc_reserved2: ::c_ulong, - pub msg_ctime: ::time_t, - __glibc_reserved3: ::c_ulong, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __glibc_reserved4: ::c_ulong, - __glibc_reserved5: ::c_ulong, - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since="0.2.54", - note="Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } -} - -pub const RLIM_INFINITY: ::rlim_t = !0; -pub const VEOF: usize = 4; -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const O_DIRECT: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_LARGEFILE: ::c_int = 0o400000; -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_FSYNC: ::c_int = 0x101000; -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_NDELAY: ::c_int = 0x800; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 6; -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const EDEADLOCK: ::c_int = 35; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EBADMSG: ::c_int = 74; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const EHWPOISON: ::c_int = 133; -pub const ERFKILL: ::c_int = 132; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_LINGER: ::c_int = 13; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; - -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const FIOCLEX: ::c_ulong = 0x5451; -pub const FIONCLEX: ::c_ulong = 0x5450; -pub const FIONBIO: ::c_ulong = 0x5421; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; - -pub const EFD_NONBLOCK: ::c_int = 0x800; -pub const SFD_NONBLOCK: ::c_int = 0x0800; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = 31; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; -pub const EXTPROC: ::tcflag_t = 0x00010000; -pub const TCGETS: ::c_ulong = 0x5401; -pub const TCSETS: ::c_ulong = 0x5402; -pub const TCSETSW: ::c_ulong = 0x5403; -pub const TCSETSF: ::c_ulong = 0x5404; -pub const TCGETA: ::c_ulong = 0x5405; -pub const TCSETA: ::c_ulong = 0x5406; -pub const TCSETAW: ::c_ulong = 0x5407; -pub const TCSETAF: ::c_ulong = 0x5408; -pub const TCSBRK: ::c_ulong = 0x5409; -pub const TCXONC: ::c_ulong = 0x540A; -pub const TCFLSH: ::c_ulong = 0x540B; -pub const TIOCINQ: ::c_ulong = 0x541B; -pub const TIOCGPGRP: ::c_ulong = 0x540F; -pub const TIOCSPGRP: ::c_ulong = 0x5410; -pub const TIOCOUTQ: ::c_ulong = 0x5411; -pub const TIOCGWINSZ: ::c_ulong = 0x5413; -pub const TIOCSWINSZ: ::c_ulong = 0x5414; -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; -pub const FIONREAD: ::c_ulong = 0x541B; - -pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; -pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; -pub const TIOCEXCL: ::c_ulong = 0x540C; -pub const TIOCNXCL: ::c_ulong = 0x540D; -pub const TIOCSCTTY: ::c_ulong = 0x540E; -pub const TIOCSTI: ::c_ulong = 0x5412; -pub const TIOCMGET: ::c_ulong = 0x5415; -pub const TIOCMBIS: ::c_ulong = 0x5416; -pub const TIOCMBIC: ::c_ulong = 0x5417; -pub const TIOCMSET: ::c_ulong = 0x5418; -pub const TIOCCONS: ::c_ulong = 0x541D; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -// Syscall table -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_pause: ::c_long = 29; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_poll: ::c_long = 168; -pub const SYS_nfsservctl: ::c_long = 169; -pub const SYS_setresgid: ::c_long = 170; -pub const SYS_getresgid: ::c_long = 171; -pub const SYS_prctl: ::c_long = 172; -pub const SYS_rt_sigreturn: ::c_long = 173; -pub const SYS_rt_sigaction: ::c_long = 174; -pub const SYS_rt_sigprocmask: ::c_long = 175; -pub const SYS_rt_sigpending: ::c_long = 176; -pub const SYS_rt_sigtimedwait: ::c_long = 177; -pub const SYS_rt_sigqueueinfo: ::c_long = 178; -pub const SYS_rt_sigsuspend: ::c_long = 179; -pub const SYS_pread64: ::c_long = 180; -pub const SYS_pwrite64: ::c_long = 181; -pub const SYS_chown: ::c_long = 182; -pub const SYS_getcwd: ::c_long = 183; -pub const SYS_capget: ::c_long = 184; -pub const SYS_capset: ::c_long = 185; -pub const SYS_sigaltstack: ::c_long = 186; -pub const SYS_sendfile: ::c_long = 187; -pub const SYS_vfork: ::c_long = 190; -pub const SYS_ugetrlimit: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_lchown32: ::c_long = 198; -pub const SYS_getuid32: ::c_long = 199; -pub const SYS_getgid32: ::c_long = 200; -pub const SYS_geteuid32: ::c_long = 201; -pub const SYS_getegid32: ::c_long = 202; -pub const SYS_setreuid32: ::c_long = 203; -pub const SYS_setregid32: ::c_long = 204; -pub const SYS_getgroups32: ::c_long = 205; -pub const SYS_setgroups32: ::c_long = 206; -pub const SYS_fchown32: ::c_long = 207; -pub const SYS_setresuid32: ::c_long = 208; -pub const SYS_getresuid32: ::c_long = 209; -pub const SYS_setresgid32: ::c_long = 210; -pub const SYS_getresgid32: ::c_long = 211; -pub const SYS_chown32: ::c_long = 212; -pub const SYS_setuid32: ::c_long = 213; -pub const SYS_setgid32: ::c_long = 214; -pub const SYS_setfsuid32: ::c_long = 215; -pub const SYS_setfsgid32: ::c_long = 216; -pub const SYS_getdents64: ::c_long = 217; -pub const SYS_pivot_root: ::c_long = 218; -pub const SYS_mincore: ::c_long = 219; -pub const SYS_madvise: ::c_long = 220; -pub const SYS_fcntl64: ::c_long = 221; -pub const SYS_gettid: ::c_long = 224; -pub const SYS_readahead: ::c_long = 225; -pub const SYS_setxattr: ::c_long = 226; -pub const SYS_lsetxattr: ::c_long = 227; -pub const SYS_fsetxattr: ::c_long = 228; -pub const SYS_getxattr: ::c_long = 229; -pub const SYS_lgetxattr: ::c_long = 230; -pub const SYS_fgetxattr: ::c_long = 231; -pub const SYS_listxattr: ::c_long = 232; -pub const SYS_llistxattr: ::c_long = 233; -pub const SYS_flistxattr: ::c_long = 234; -pub const SYS_removexattr: ::c_long = 235; -pub const SYS_lremovexattr: ::c_long = 236; -pub const SYS_fremovexattr: ::c_long = 237; -pub const SYS_tkill: ::c_long = 238; -pub const SYS_sendfile64: ::c_long = 239; -pub const SYS_futex: ::c_long = 240; -pub const SYS_sched_setaffinity: ::c_long = 241; -pub const SYS_sched_getaffinity: ::c_long = 242; -pub const SYS_io_setup: ::c_long = 243; -pub const SYS_io_destroy: ::c_long = 244; -pub const SYS_io_getevents: ::c_long = 245; -pub const SYS_io_submit: ::c_long = 246; -pub const SYS_io_cancel: ::c_long = 247; -pub const SYS_exit_group: ::c_long = 248; -pub const SYS_lookup_dcookie: ::c_long = 249; -pub const SYS_epoll_create: ::c_long = 250; -pub const SYS_epoll_ctl: ::c_long = 251; -pub const SYS_epoll_wait: ::c_long = 252; -pub const SYS_remap_file_pages: ::c_long = 253; -pub const SYS_set_tid_address: ::c_long = 256; -pub const SYS_timer_create: ::c_long = 257; -pub const SYS_timer_settime: ::c_long = 258; -pub const SYS_timer_gettime: ::c_long = 259; -pub const SYS_timer_getoverrun: ::c_long = 260; -pub const SYS_timer_delete: ::c_long = 261; -pub const SYS_clock_settime: ::c_long = 262; -pub const SYS_clock_gettime: ::c_long = 263; -pub const SYS_clock_getres: ::c_long = 264; -pub const SYS_clock_nanosleep: ::c_long = 265; -pub const SYS_statfs64: ::c_long = 266; -pub const SYS_fstatfs64: ::c_long = 267; -pub const SYS_tgkill: ::c_long = 268; -pub const SYS_utimes: ::c_long = 269; -pub const SYS_arm_fadvise64_64: ::c_long = 270; -pub const SYS_pciconfig_iobase: ::c_long = 271; -pub const SYS_pciconfig_read: ::c_long = 272; -pub const SYS_pciconfig_write: ::c_long = 273; -pub const SYS_mq_open: ::c_long = 274; -pub const SYS_mq_unlink: ::c_long = 275; -pub const SYS_mq_timedsend: ::c_long = 276; -pub const SYS_mq_timedreceive: ::c_long = 277; -pub const SYS_mq_notify: ::c_long = 278; -pub const SYS_mq_getsetattr: ::c_long = 279; -pub const SYS_waitid: ::c_long = 280; -pub const SYS_socket: ::c_long = 281; -pub const SYS_bind: ::c_long = 282; -pub const SYS_connect: ::c_long = 283; -pub const SYS_listen: ::c_long = 284; -pub const SYS_accept: ::c_long = 285; -pub const SYS_getsockname: ::c_long = 286; -pub const SYS_getpeername: ::c_long = 287; -pub const SYS_socketpair: ::c_long = 288; -pub const SYS_send: ::c_long = 289; -pub const SYS_sendto: ::c_long = 290; -pub const SYS_recv: ::c_long = 291; -pub const SYS_recvfrom: ::c_long = 292; -pub const SYS_shutdown: ::c_long = 293; -pub const SYS_setsockopt: ::c_long = 294; -pub const SYS_getsockopt: ::c_long = 295; -pub const SYS_sendmsg: ::c_long = 296; -pub const SYS_recvmsg: ::c_long = 297; -pub const SYS_semop: ::c_long = 298; -pub const SYS_semget: ::c_long = 299; -pub const SYS_semctl: ::c_long = 300; -pub const SYS_msgsnd: ::c_long = 301; -pub const SYS_msgrcv: ::c_long = 302; -pub const SYS_msgget: ::c_long = 303; -pub const SYS_msgctl: ::c_long = 304; -pub const SYS_shmat: ::c_long = 305; -pub const SYS_shmdt: ::c_long = 306; -pub const SYS_shmget: ::c_long = 307; -pub const SYS_shmctl: ::c_long = 308; -pub const SYS_add_key: ::c_long = 309; -pub const SYS_request_key: ::c_long = 310; -pub const SYS_keyctl: ::c_long = 311; -pub const SYS_semtimedop: ::c_long = 312; -pub const SYS_vserver: ::c_long = 313; -pub const SYS_ioprio_set: ::c_long = 314; -pub const SYS_ioprio_get: ::c_long = 315; -pub const SYS_inotify_init: ::c_long = 316; -pub const SYS_inotify_add_watch: ::c_long = 317; -pub const SYS_inotify_rm_watch: ::c_long = 318; -pub const SYS_mbind: ::c_long = 319; -pub const SYS_get_mempolicy: ::c_long = 320; -pub const SYS_set_mempolicy: ::c_long = 321; -pub const SYS_openat: ::c_long = 322; -pub const SYS_mkdirat: ::c_long = 323; -pub const SYS_mknodat: ::c_long = 324; -pub const SYS_fchownat: ::c_long = 325; -pub const SYS_futimesat: ::c_long = 326; -pub const SYS_fstatat64: ::c_long = 327; -pub const SYS_unlinkat: ::c_long = 328; -pub const SYS_renameat: ::c_long = 329; -pub const SYS_linkat: ::c_long = 330; -pub const SYS_symlinkat: ::c_long = 331; -pub const SYS_readlinkat: ::c_long = 332; -pub const SYS_fchmodat: ::c_long = 333; -pub const SYS_faccessat: ::c_long = 334; -pub const SYS_pselect6: ::c_long = 335; -pub const SYS_ppoll: ::c_long = 336; -pub const SYS_unshare: ::c_long = 337; -pub const SYS_set_robust_list: ::c_long = 338; -pub const SYS_get_robust_list: ::c_long = 339; -pub const SYS_splice: ::c_long = 340; -pub const SYS_arm_sync_file_range: ::c_long = 341; -pub const SYS_tee: ::c_long = 342; -pub const SYS_vmsplice: ::c_long = 343; -pub const SYS_move_pages: ::c_long = 344; -pub const SYS_getcpu: ::c_long = 345; -pub const SYS_epoll_pwait: ::c_long = 346; -pub const SYS_kexec_load: ::c_long = 347; -pub const SYS_utimensat: ::c_long = 348; -pub const SYS_signalfd: ::c_long = 349; -pub const SYS_timerfd_create: ::c_long = 350; -pub const SYS_eventfd: ::c_long = 351; -pub const SYS_fallocate: ::c_long = 352; -pub const SYS_timerfd_settime: ::c_long = 353; -pub const SYS_timerfd_gettime: ::c_long = 354; -pub const SYS_signalfd4: ::c_long = 355; -pub const SYS_eventfd2: ::c_long = 356; -pub const SYS_epoll_create1: ::c_long = 357; -pub const SYS_dup3: ::c_long = 358; -pub const SYS_pipe2: ::c_long = 359; -pub const SYS_inotify_init1: ::c_long = 360; -pub const SYS_preadv: ::c_long = 361; -pub const SYS_pwritev: ::c_long = 362; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 363; -pub const SYS_perf_event_open: ::c_long = 364; -pub const SYS_recvmmsg: ::c_long = 365; -pub const SYS_accept4: ::c_long = 366; -pub const SYS_fanotify_init: ::c_long = 367; -pub const SYS_fanotify_mark: ::c_long = 368; -pub const SYS_prlimit64: ::c_long = 369; -pub const SYS_name_to_handle_at: ::c_long = 370; -pub const SYS_open_by_handle_at: ::c_long = 371; -pub const SYS_clock_adjtime: ::c_long = 372; -pub const SYS_syncfs: ::c_long = 373; -pub const SYS_sendmmsg: ::c_long = 374; -pub const SYS_setns: ::c_long = 375; -pub const SYS_process_vm_readv: ::c_long = 376; -pub const SYS_process_vm_writev: ::c_long = 377; -pub const SYS_kcmp: ::c_long = 378; -pub const SYS_finit_module: ::c_long = 379; -pub const SYS_sched_setattr: ::c_long = 380; -pub const SYS_sched_getattr: ::c_long = 381; -pub const SYS_renameat2: ::c_long = 382; -pub const SYS_seccomp: ::c_long = 383; -pub const SYS_getrandom: ::c_long = 384; -pub const SYS_memfd_create: ::c_long = 385; -pub const SYS_bpf: ::c_long = 386; -pub const SYS_execveat: ::c_long = 387; -pub const SYS_userfaultfd: ::c_long = 388; -pub const SYS_membarrier: ::c_long = 389; -pub const SYS_mlock2: ::c_long = 390; -pub const SYS_copy_file_range: ::c_long = 391; -pub const SYS_preadv2: ::c_long = 392; -pub const SYS_pwritev2: ::c_long = 393; -pub const SYS_pkey_mprotect: ::c_long = 394; -pub const SYS_pkey_alloc: ::c_long = 395; -pub const SYS_pkey_free: ::c_long = 396; -pub const SYS_statx: ::c_long = 397; - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/mips/align.rs b/libc/src/unix/linux_like/linux/gnu/b32/mips/align.rs deleted file mode 100644 index 8c228eb..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/mips/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(8))] - pub struct max_align_t { - priv_: [f32; 4] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/mips/mod.rs b/libc/src/unix/linux_like/linux/gnu/b32/mips/mod.rs deleted file mode 100644 index 4a3b600..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/mips/mod.rs +++ /dev/null @@ -1,901 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; - -s! { - pub struct stat64 { - pub st_dev: ::c_ulong, - st_pad1: [::c_long; 3], - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulong, - st_pad2: [::c_long; 2], - pub st_size: ::off64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - st_pad3: ::c_long, - pub st_blocks: ::blkcnt64_t, - st_pad5: [::c_long; 14], - } - - pub struct statfs { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_frsize: ::c_long, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_files: ::fsblkcnt_t, - pub f_ffree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::c_long, - f_spare: [::c_long; 6], - } - - pub struct statfs64 { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_frsize: ::c_long, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_bavail: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_long, - pub f_flags: ::c_long, - pub f_spare: [::c_long; 5], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct sigaction { - pub sa_flags: ::c_int, - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_restorer: ::Option, - _resv: [::c_int; 1], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub _pad: [::c_int; 29], - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_uint, - pub __seq: ::c_ushort, - __pad1: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - #[cfg(target_endian = "big")] - __glibc_reserved1: ::c_ulong, - pub msg_stime: ::time_t, - #[cfg(target_endian = "little")] - __glibc_reserved1: ::c_ulong, - #[cfg(target_endian = "big")] - __glibc_reserved2: ::c_ulong, - pub msg_rtime: ::time_t, - #[cfg(target_endian = "little")] - __glibc_reserved2: ::c_ulong, - #[cfg(target_endian = "big")] - __glibc_reserved3: ::c_ulong, - pub msg_ctime: ::time_t, - #[cfg(target_endian = "little")] - __glibc_reserved3: ::c_ulong, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __glibc_reserved4: ::c_ulong, - __glibc_reserved5: ::c_ulong, - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_sysid: ::c_long, - pub l_pid: ::pid_t, - pad: [::c_long; 4], - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 23], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } -} - -pub const O_LARGEFILE: ::c_int = 0x2000; - -pub const SYS_syscall: ::c_long = 4000 + 0; -pub const SYS_exit: ::c_long = 4000 + 1; -pub const SYS_fork: ::c_long = 4000 + 2; -pub const SYS_read: ::c_long = 4000 + 3; -pub const SYS_write: ::c_long = 4000 + 4; -pub const SYS_open: ::c_long = 4000 + 5; -pub const SYS_close: ::c_long = 4000 + 6; -pub const SYS_waitpid: ::c_long = 4000 + 7; -pub const SYS_creat: ::c_long = 4000 + 8; -pub const SYS_link: ::c_long = 4000 + 9; -pub const SYS_unlink: ::c_long = 4000 + 10; -pub const SYS_execve: ::c_long = 4000 + 11; -pub const SYS_chdir: ::c_long = 4000 + 12; -pub const SYS_time: ::c_long = 4000 + 13; -pub const SYS_mknod: ::c_long = 4000 + 14; -pub const SYS_chmod: ::c_long = 4000 + 15; -pub const SYS_lchown: ::c_long = 4000 + 16; -pub const SYS_break: ::c_long = 4000 + 17; -pub const SYS_lseek: ::c_long = 4000 + 19; -pub const SYS_getpid: ::c_long = 4000 + 20; -pub const SYS_mount: ::c_long = 4000 + 21; -pub const SYS_umount: ::c_long = 4000 + 22; -pub const SYS_setuid: ::c_long = 4000 + 23; -pub const SYS_getuid: ::c_long = 4000 + 24; -pub const SYS_stime: ::c_long = 4000 + 25; -pub const SYS_ptrace: ::c_long = 4000 + 26; -pub const SYS_alarm: ::c_long = 4000 + 27; -pub const SYS_pause: ::c_long = 4000 + 29; -pub const SYS_utime: ::c_long = 4000 + 30; -pub const SYS_stty: ::c_long = 4000 + 31; -pub const SYS_gtty: ::c_long = 4000 + 32; -pub const SYS_access: ::c_long = 4000 + 33; -pub const SYS_nice: ::c_long = 4000 + 34; -pub const SYS_ftime: ::c_long = 4000 + 35; -pub const SYS_sync: ::c_long = 4000 + 36; -pub const SYS_kill: ::c_long = 4000 + 37; -pub const SYS_rename: ::c_long = 4000 + 38; -pub const SYS_mkdir: ::c_long = 4000 + 39; -pub const SYS_rmdir: ::c_long = 4000 + 40; -pub const SYS_dup: ::c_long = 4000 + 41; -pub const SYS_pipe: ::c_long = 4000 + 42; -pub const SYS_times: ::c_long = 4000 + 43; -pub const SYS_prof: ::c_long = 4000 + 44; -pub const SYS_brk: ::c_long = 4000 + 45; -pub const SYS_setgid: ::c_long = 4000 + 46; -pub const SYS_getgid: ::c_long = 4000 + 47; -pub const SYS_signal: ::c_long = 4000 + 48; -pub const SYS_geteuid: ::c_long = 4000 + 49; -pub const SYS_getegid: ::c_long = 4000 + 50; -pub const SYS_acct: ::c_long = 4000 + 51; -pub const SYS_umount2: ::c_long = 4000 + 52; -pub const SYS_lock: ::c_long = 4000 + 53; -pub const SYS_ioctl: ::c_long = 4000 + 54; -pub const SYS_fcntl: ::c_long = 4000 + 55; -pub const SYS_mpx: ::c_long = 4000 + 56; -pub const SYS_setpgid: ::c_long = 4000 + 57; -pub const SYS_ulimit: ::c_long = 4000 + 58; -pub const SYS_umask: ::c_long = 4000 + 60; -pub const SYS_chroot: ::c_long = 4000 + 61; -pub const SYS_ustat: ::c_long = 4000 + 62; -pub const SYS_dup2: ::c_long = 4000 + 63; -pub const SYS_getppid: ::c_long = 4000 + 64; -pub const SYS_getpgrp: ::c_long = 4000 + 65; -pub const SYS_setsid: ::c_long = 4000 + 66; -pub const SYS_sigaction: ::c_long = 4000 + 67; -pub const SYS_sgetmask: ::c_long = 4000 + 68; -pub const SYS_ssetmask: ::c_long = 4000 + 69; -pub const SYS_setreuid: ::c_long = 4000 + 70; -pub const SYS_setregid: ::c_long = 4000 + 71; -pub const SYS_sigsuspend: ::c_long = 4000 + 72; -pub const SYS_sigpending: ::c_long = 4000 + 73; -pub const SYS_sethostname: ::c_long = 4000 + 74; -pub const SYS_setrlimit: ::c_long = 4000 + 75; -pub const SYS_getrlimit: ::c_long = 4000 + 76; -pub const SYS_getrusage: ::c_long = 4000 + 77; -pub const SYS_gettimeofday: ::c_long = 4000 + 78; -pub const SYS_settimeofday: ::c_long = 4000 + 79; -pub const SYS_getgroups: ::c_long = 4000 + 80; -pub const SYS_setgroups: ::c_long = 4000 + 81; -pub const SYS_symlink: ::c_long = 4000 + 83; -pub const SYS_readlink: ::c_long = 4000 + 85; -pub const SYS_uselib: ::c_long = 4000 + 86; -pub const SYS_swapon: ::c_long = 4000 + 87; -pub const SYS_reboot: ::c_long = 4000 + 88; -pub const SYS_readdir: ::c_long = 4000 + 89; -pub const SYS_mmap: ::c_long = 4000 + 90; -pub const SYS_munmap: ::c_long = 4000 + 91; -pub const SYS_truncate: ::c_long = 4000 + 92; -pub const SYS_ftruncate: ::c_long = 4000 + 93; -pub const SYS_fchmod: ::c_long = 4000 + 94; -pub const SYS_fchown: ::c_long = 4000 + 95; -pub const SYS_getpriority: ::c_long = 4000 + 96; -pub const SYS_setpriority: ::c_long = 4000 + 97; -pub const SYS_profil: ::c_long = 4000 + 98; -pub const SYS_statfs: ::c_long = 4000 + 99; -pub const SYS_fstatfs: ::c_long = 4000 + 100; -pub const SYS_ioperm: ::c_long = 4000 + 101; -pub const SYS_socketcall: ::c_long = 4000 + 102; -pub const SYS_syslog: ::c_long = 4000 + 103; -pub const SYS_setitimer: ::c_long = 4000 + 104; -pub const SYS_getitimer: ::c_long = 4000 + 105; -pub const SYS_stat: ::c_long = 4000 + 106; -pub const SYS_lstat: ::c_long = 4000 + 107; -pub const SYS_fstat: ::c_long = 4000 + 108; -pub const SYS_iopl: ::c_long = 4000 + 110; -pub const SYS_vhangup: ::c_long = 4000 + 111; -pub const SYS_idle: ::c_long = 4000 + 112; -pub const SYS_vm86: ::c_long = 4000 + 113; -pub const SYS_wait4: ::c_long = 4000 + 114; -pub const SYS_swapoff: ::c_long = 4000 + 115; -pub const SYS_sysinfo: ::c_long = 4000 + 116; -pub const SYS_ipc: ::c_long = 4000 + 117; -pub const SYS_fsync: ::c_long = 4000 + 118; -pub const SYS_sigreturn: ::c_long = 4000 + 119; -pub const SYS_clone: ::c_long = 4000 + 120; -pub const SYS_setdomainname: ::c_long = 4000 + 121; -pub const SYS_uname: ::c_long = 4000 + 122; -pub const SYS_modify_ldt: ::c_long = 4000 + 123; -pub const SYS_adjtimex: ::c_long = 4000 + 124; -pub const SYS_mprotect: ::c_long = 4000 + 125; -pub const SYS_sigprocmask: ::c_long = 4000 + 126; -pub const SYS_create_module: ::c_long = 4000 + 127; -pub const SYS_init_module: ::c_long = 4000 + 128; -pub const SYS_delete_module: ::c_long = 4000 + 129; -pub const SYS_get_kernel_syms: ::c_long = 4000 + 130; -pub const SYS_quotactl: ::c_long = 4000 + 131; -pub const SYS_getpgid: ::c_long = 4000 + 132; -pub const SYS_fchdir: ::c_long = 4000 + 133; -pub const SYS_bdflush: ::c_long = 4000 + 134; -pub const SYS_sysfs: ::c_long = 4000 + 135; -pub const SYS_personality: ::c_long = 4000 + 136; -pub const SYS_afs_syscall: ::c_long = 4000 + 137; -pub const SYS_setfsuid: ::c_long = 4000 + 138; -pub const SYS_setfsgid: ::c_long = 4000 + 139; -pub const SYS__llseek: ::c_long = 4000 + 140; -pub const SYS_getdents: ::c_long = 4000 + 141; -pub const SYS__newselect: ::c_long = 4000 + 142; -pub const SYS_flock: ::c_long = 4000 + 143; -pub const SYS_msync: ::c_long = 4000 + 144; -pub const SYS_readv: ::c_long = 4000 + 145; -pub const SYS_writev: ::c_long = 4000 + 146; -pub const SYS_cacheflush: ::c_long = 4000 + 147; -pub const SYS_cachectl: ::c_long = 4000 + 148; -pub const SYS_sysmips: ::c_long = 4000 + 149; -pub const SYS_getsid: ::c_long = 4000 + 151; -pub const SYS_fdatasync: ::c_long = 4000 + 152; -pub const SYS__sysctl: ::c_long = 4000 + 153; -pub const SYS_mlock: ::c_long = 4000 + 154; -pub const SYS_munlock: ::c_long = 4000 + 155; -pub const SYS_mlockall: ::c_long = 4000 + 156; -pub const SYS_munlockall: ::c_long = 4000 + 157; -pub const SYS_sched_setparam: ::c_long = 4000 + 158; -pub const SYS_sched_getparam: ::c_long = 4000 + 159; -pub const SYS_sched_setscheduler: ::c_long = 4000 + 160; -pub const SYS_sched_getscheduler: ::c_long = 4000 + 161; -pub const SYS_sched_yield: ::c_long = 4000 + 162; -pub const SYS_sched_get_priority_max: ::c_long = 4000 + 163; -pub const SYS_sched_get_priority_min: ::c_long = 4000 + 164; -pub const SYS_sched_rr_get_interval: ::c_long = 4000 + 165; -pub const SYS_nanosleep: ::c_long = 4000 + 166; -pub const SYS_mremap: ::c_long = 4000 + 167; -pub const SYS_accept: ::c_long = 4000 + 168; -pub const SYS_bind: ::c_long = 4000 + 169; -pub const SYS_connect: ::c_long = 4000 + 170; -pub const SYS_getpeername: ::c_long = 4000 + 171; -pub const SYS_getsockname: ::c_long = 4000 + 172; -pub const SYS_getsockopt: ::c_long = 4000 + 173; -pub const SYS_listen: ::c_long = 4000 + 174; -pub const SYS_recv: ::c_long = 4000 + 175; -pub const SYS_recvfrom: ::c_long = 4000 + 176; -pub const SYS_recvmsg: ::c_long = 4000 + 177; -pub const SYS_send: ::c_long = 4000 + 178; -pub const SYS_sendmsg: ::c_long = 4000 + 179; -pub const SYS_sendto: ::c_long = 4000 + 180; -pub const SYS_setsockopt: ::c_long = 4000 + 181; -pub const SYS_shutdown: ::c_long = 4000 + 182; -pub const SYS_socket: ::c_long = 4000 + 183; -pub const SYS_socketpair: ::c_long = 4000 + 184; -pub const SYS_setresuid: ::c_long = 4000 + 185; -pub const SYS_getresuid: ::c_long = 4000 + 186; -pub const SYS_query_module: ::c_long = 4000 + 187; -pub const SYS_poll: ::c_long = 4000 + 188; -pub const SYS_nfsservctl: ::c_long = 4000 + 189; -pub const SYS_setresgid: ::c_long = 4000 + 190; -pub const SYS_getresgid: ::c_long = 4000 + 191; -pub const SYS_prctl: ::c_long = 4000 + 192; -pub const SYS_rt_sigreturn: ::c_long = 4000 + 193; -pub const SYS_rt_sigaction: ::c_long = 4000 + 194; -pub const SYS_rt_sigprocmask: ::c_long = 4000 + 195; -pub const SYS_rt_sigpending: ::c_long = 4000 + 196; -pub const SYS_rt_sigtimedwait: ::c_long = 4000 + 197; -pub const SYS_rt_sigqueueinfo: ::c_long = 4000 + 198; -pub const SYS_rt_sigsuspend: ::c_long = 4000 + 199; -pub const SYS_pread64: ::c_long = 4000 + 200; -pub const SYS_pwrite64: ::c_long = 4000 + 201; -pub const SYS_chown: ::c_long = 4000 + 202; -pub const SYS_getcwd: ::c_long = 4000 + 203; -pub const SYS_capget: ::c_long = 4000 + 204; -pub const SYS_capset: ::c_long = 4000 + 205; -pub const SYS_sigaltstack: ::c_long = 4000 + 206; -pub const SYS_sendfile: ::c_long = 4000 + 207; -pub const SYS_getpmsg: ::c_long = 4000 + 208; -pub const SYS_putpmsg: ::c_long = 4000 + 209; -pub const SYS_mmap2: ::c_long = 4000 + 210; -pub const SYS_truncate64: ::c_long = 4000 + 211; -pub const SYS_ftruncate64: ::c_long = 4000 + 212; -pub const SYS_stat64: ::c_long = 4000 + 213; -pub const SYS_lstat64: ::c_long = 4000 + 214; -pub const SYS_fstat64: ::c_long = 4000 + 215; -pub const SYS_pivot_root: ::c_long = 4000 + 216; -pub const SYS_mincore: ::c_long = 4000 + 217; -pub const SYS_madvise: ::c_long = 4000 + 218; -pub const SYS_getdents64: ::c_long = 4000 + 219; -pub const SYS_fcntl64: ::c_long = 4000 + 220; -pub const SYS_gettid: ::c_long = 4000 + 222; -pub const SYS_readahead: ::c_long = 4000 + 223; -pub const SYS_setxattr: ::c_long = 4000 + 224; -pub const SYS_lsetxattr: ::c_long = 4000 + 225; -pub const SYS_fsetxattr: ::c_long = 4000 + 226; -pub const SYS_getxattr: ::c_long = 4000 + 227; -pub const SYS_lgetxattr: ::c_long = 4000 + 228; -pub const SYS_fgetxattr: ::c_long = 4000 + 229; -pub const SYS_listxattr: ::c_long = 4000 + 230; -pub const SYS_llistxattr: ::c_long = 4000 + 231; -pub const SYS_flistxattr: ::c_long = 4000 + 232; -pub const SYS_removexattr: ::c_long = 4000 + 233; -pub const SYS_lremovexattr: ::c_long = 4000 + 234; -pub const SYS_fremovexattr: ::c_long = 4000 + 235; -pub const SYS_tkill: ::c_long = 4000 + 236; -pub const SYS_sendfile64: ::c_long = 4000 + 237; -pub const SYS_futex: ::c_long = 4000 + 238; -pub const SYS_sched_setaffinity: ::c_long = 4000 + 239; -pub const SYS_sched_getaffinity: ::c_long = 4000 + 240; -pub const SYS_io_setup: ::c_long = 4000 + 241; -pub const SYS_io_destroy: ::c_long = 4000 + 242; -pub const SYS_io_getevents: ::c_long = 4000 + 243; -pub const SYS_io_submit: ::c_long = 4000 + 244; -pub const SYS_io_cancel: ::c_long = 4000 + 245; -pub const SYS_exit_group: ::c_long = 4000 + 246; -pub const SYS_lookup_dcookie: ::c_long = 4000 + 247; -pub const SYS_epoll_create: ::c_long = 4000 + 248; -pub const SYS_epoll_ctl: ::c_long = 4000 + 249; -pub const SYS_epoll_wait: ::c_long = 4000 + 250; -pub const SYS_remap_file_pages: ::c_long = 4000 + 251; -pub const SYS_set_tid_address: ::c_long = 4000 + 252; -pub const SYS_restart_syscall: ::c_long = 4000 + 253; -pub const SYS_fadvise64: ::c_long = 4000 + 254; -pub const SYS_statfs64: ::c_long = 4000 + 255; -pub const SYS_fstatfs64: ::c_long = 4000 + 256; -pub const SYS_timer_create: ::c_long = 4000 + 257; -pub const SYS_timer_settime: ::c_long = 4000 + 258; -pub const SYS_timer_gettime: ::c_long = 4000 + 259; -pub const SYS_timer_getoverrun: ::c_long = 4000 + 260; -pub const SYS_timer_delete: ::c_long = 4000 + 261; -pub const SYS_clock_settime: ::c_long = 4000 + 262; -pub const SYS_clock_gettime: ::c_long = 4000 + 263; -pub const SYS_clock_getres: ::c_long = 4000 + 264; -pub const SYS_clock_nanosleep: ::c_long = 4000 + 265; -pub const SYS_tgkill: ::c_long = 4000 + 266; -pub const SYS_utimes: ::c_long = 4000 + 267; -pub const SYS_mbind: ::c_long = 4000 + 268; -pub const SYS_get_mempolicy: ::c_long = 4000 + 269; -pub const SYS_set_mempolicy: ::c_long = 4000 + 270; -pub const SYS_mq_open: ::c_long = 4000 + 271; -pub const SYS_mq_unlink: ::c_long = 4000 + 272; -pub const SYS_mq_timedsend: ::c_long = 4000 + 273; -pub const SYS_mq_timedreceive: ::c_long = 4000 + 274; -pub const SYS_mq_notify: ::c_long = 4000 + 275; -pub const SYS_mq_getsetattr: ::c_long = 4000 + 276; -pub const SYS_vserver: ::c_long = 4000 + 277; -pub const SYS_waitid: ::c_long = 4000 + 278; -/* pub const SYS_sys_setaltroot: ::c_long = 4000 + 279; */ -pub const SYS_add_key: ::c_long = 4000 + 280; -pub const SYS_request_key: ::c_long = 4000 + 281; -pub const SYS_keyctl: ::c_long = 4000 + 282; -pub const SYS_set_thread_area: ::c_long = 4000 + 283; -pub const SYS_inotify_init: ::c_long = 4000 + 284; -pub const SYS_inotify_add_watch: ::c_long = 4000 + 285; -pub const SYS_inotify_rm_watch: ::c_long = 4000 + 286; -pub const SYS_migrate_pages: ::c_long = 4000 + 287; -pub const SYS_openat: ::c_long = 4000 + 288; -pub const SYS_mkdirat: ::c_long = 4000 + 289; -pub const SYS_mknodat: ::c_long = 4000 + 290; -pub const SYS_fchownat: ::c_long = 4000 + 291; -pub const SYS_futimesat: ::c_long = 4000 + 292; -pub const SYS_fstatat64: ::c_long = 4000 + 293; -pub const SYS_unlinkat: ::c_long = 4000 + 294; -pub const SYS_renameat: ::c_long = 4000 + 295; -pub const SYS_linkat: ::c_long = 4000 + 296; -pub const SYS_symlinkat: ::c_long = 4000 + 297; -pub const SYS_readlinkat: ::c_long = 4000 + 298; -pub const SYS_fchmodat: ::c_long = 4000 + 299; -pub const SYS_faccessat: ::c_long = 4000 + 300; -pub const SYS_pselect6: ::c_long = 4000 + 301; -pub const SYS_ppoll: ::c_long = 4000 + 302; -pub const SYS_unshare: ::c_long = 4000 + 303; -pub const SYS_splice: ::c_long = 4000 + 304; -pub const SYS_sync_file_range: ::c_long = 4000 + 305; -pub const SYS_tee: ::c_long = 4000 + 306; -pub const SYS_vmsplice: ::c_long = 4000 + 307; -pub const SYS_move_pages: ::c_long = 4000 + 308; -pub const SYS_set_robust_list: ::c_long = 4000 + 309; -pub const SYS_get_robust_list: ::c_long = 4000 + 310; -pub const SYS_kexec_load: ::c_long = 4000 + 311; -pub const SYS_getcpu: ::c_long = 4000 + 312; -pub const SYS_epoll_pwait: ::c_long = 4000 + 313; -pub const SYS_ioprio_set: ::c_long = 4000 + 314; -pub const SYS_ioprio_get: ::c_long = 4000 + 315; -pub const SYS_utimensat: ::c_long = 4000 + 316; -pub const SYS_signalfd: ::c_long = 4000 + 317; -pub const SYS_timerfd: ::c_long = 4000 + 318; -pub const SYS_eventfd: ::c_long = 4000 + 319; -pub const SYS_fallocate: ::c_long = 4000 + 320; -pub const SYS_timerfd_create: ::c_long = 4000 + 321; -pub const SYS_timerfd_gettime: ::c_long = 4000 + 322; -pub const SYS_timerfd_settime: ::c_long = 4000 + 323; -pub const SYS_signalfd4: ::c_long = 4000 + 324; -pub const SYS_eventfd2: ::c_long = 4000 + 325; -pub const SYS_epoll_create1: ::c_long = 4000 + 326; -pub const SYS_dup3: ::c_long = 4000 + 327; -pub const SYS_pipe2: ::c_long = 4000 + 328; -pub const SYS_inotify_init1: ::c_long = 4000 + 329; -pub const SYS_preadv: ::c_long = 4000 + 330; -pub const SYS_pwritev: ::c_long = 4000 + 331; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 4000 + 332; -pub const SYS_perf_event_open: ::c_long = 4000 + 333; -pub const SYS_accept4: ::c_long = 4000 + 334; -pub const SYS_recvmmsg: ::c_long = 4000 + 335; -pub const SYS_fanotify_init: ::c_long = 4000 + 336; -pub const SYS_fanotify_mark: ::c_long = 4000 + 337; -pub const SYS_prlimit64: ::c_long = 4000 + 338; -pub const SYS_name_to_handle_at: ::c_long = 4000 + 339; -pub const SYS_open_by_handle_at: ::c_long = 4000 + 340; -pub const SYS_clock_adjtime: ::c_long = 4000 + 341; -pub const SYS_syncfs: ::c_long = 4000 + 342; -pub const SYS_sendmmsg: ::c_long = 4000 + 343; -pub const SYS_setns: ::c_long = 4000 + 344; -pub const SYS_process_vm_readv: ::c_long = 4000 + 345; -pub const SYS_process_vm_writev: ::c_long = 4000 + 346; -pub const SYS_kcmp: ::c_long = 4000 + 347; -pub const SYS_finit_module: ::c_long = 4000 + 348; -pub const SYS_sched_setattr: ::c_long = 4000 + 349; -pub const SYS_sched_getattr: ::c_long = 4000 + 350; -pub const SYS_renameat2: ::c_long = 4000 + 351; -pub const SYS_seccomp: ::c_long = 4000 + 352; -pub const SYS_getrandom: ::c_long = 4000 + 353; -pub const SYS_memfd_create: ::c_long = 4000 + 354; -pub const SYS_bpf: ::c_long = 4000 + 355; -pub const SYS_execveat: ::c_long = 4000 + 356; -pub const SYS_userfaultfd: ::c_long = 4000 + 357; -pub const SYS_membarrier: ::c_long = 4000 + 358; -pub const SYS_mlock2: ::c_long = 4000 + 359; -pub const SYS_copy_file_range: ::c_long = 4000 + 360; -pub const SYS_preadv2: ::c_long = 4000 + 361; -pub const SYS_pwritev2: ::c_long = 4000 + 362; -pub const SYS_pkey_mprotect: ::c_long = 4000 + 363; -pub const SYS_pkey_alloc: ::c_long = 4000 + 364; -pub const SYS_pkey_free: ::c_long = 4000 + 365; -pub const SYS_statx: ::c_long = 4000 + 366; - -pub const O_DIRECT: ::c_int = 0x8000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; - -pub const RLIM_INFINITY: ::rlim_t = 0x7fffffff; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 6; -pub const RLIMIT_RSS: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 8; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 9; - -pub const O_APPEND: ::c_int = 8; -pub const O_CREAT: ::c_int = 256; -pub const O_EXCL: ::c_int = 1024; -pub const O_NOCTTY: ::c_int = 2048; -pub const O_NONBLOCK: ::c_int = 128; -pub const O_SYNC: ::c_int = 0x4010; -pub const O_RSYNC: ::c_int = 0x4010; -pub const O_DSYNC: ::c_int = 0x10; -pub const O_FSYNC: ::c_int = 0x4010; -pub const O_ASYNC: ::c_int = 0x1000; -pub const O_NDELAY: ::c_int = 0x80; - -pub const EDEADLK: ::c_int = 45; -pub const ENAMETOOLONG: ::c_int = 78; -pub const ENOLCK: ::c_int = 46; -pub const ENOSYS: ::c_int = 89; -pub const ENOTEMPTY: ::c_int = 93; -pub const ELOOP: ::c_int = 90; -pub const ENOMSG: ::c_int = 35; -pub const EIDRM: ::c_int = 36; -pub const ECHRNG: ::c_int = 37; -pub const EL2NSYNC: ::c_int = 38; -pub const EL3HLT: ::c_int = 39; -pub const EL3RST: ::c_int = 40; -pub const ELNRNG: ::c_int = 41; -pub const EUNATCH: ::c_int = 42; -pub const ENOCSI: ::c_int = 43; -pub const EL2HLT: ::c_int = 44; -pub const EBADE: ::c_int = 50; -pub const EBADR: ::c_int = 51; -pub const EXFULL: ::c_int = 52; -pub const ENOANO: ::c_int = 53; -pub const EBADRQC: ::c_int = 54; -pub const EBADSLT: ::c_int = 55; -pub const EDEADLOCK: ::c_int = 56; -pub const EMULTIHOP: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 79; -pub const ENOTUNIQ: ::c_int = 80; -pub const EBADFD: ::c_int = 81; -pub const EBADMSG: ::c_int = 77; -pub const EREMCHG: ::c_int = 82; -pub const ELIBACC: ::c_int = 83; -pub const ELIBBAD: ::c_int = 84; -pub const ELIBSCN: ::c_int = 85; -pub const ELIBMAX: ::c_int = 86; -pub const ELIBEXEC: ::c_int = 87; -pub const EILSEQ: ::c_int = 88; -pub const ERESTART: ::c_int = 91; -pub const ESTRPIPE: ::c_int = 92; -pub const EUSERS: ::c_int = 94; -pub const ENOTSOCK: ::c_int = 95; -pub const EDESTADDRREQ: ::c_int = 96; -pub const EMSGSIZE: ::c_int = 97; -pub const EPROTOTYPE: ::c_int = 98; -pub const ENOPROTOOPT: ::c_int = 99; -pub const EPROTONOSUPPORT: ::c_int = 120; -pub const ESOCKTNOSUPPORT: ::c_int = 121; -pub const EOPNOTSUPP: ::c_int = 122; -pub const EPFNOSUPPORT: ::c_int = 123; -pub const EAFNOSUPPORT: ::c_int = 124; -pub const EADDRINUSE: ::c_int = 125; -pub const EADDRNOTAVAIL: ::c_int = 126; -pub const ENETDOWN: ::c_int = 127; -pub const ENETUNREACH: ::c_int = 128; -pub const ENETRESET: ::c_int = 129; -pub const ECONNABORTED: ::c_int = 130; -pub const ECONNRESET: ::c_int = 131; -pub const ENOBUFS: ::c_int = 132; -pub const EISCONN: ::c_int = 133; -pub const ENOTCONN: ::c_int = 134; -pub const ESHUTDOWN: ::c_int = 143; -pub const ETOOMANYREFS: ::c_int = 144; -pub const ETIMEDOUT: ::c_int = 145; -pub const ECONNREFUSED: ::c_int = 146; -pub const EHOSTDOWN: ::c_int = 147; -pub const EHOSTUNREACH: ::c_int = 148; -pub const EALREADY: ::c_int = 149; -pub const EINPROGRESS: ::c_int = 150; -pub const ESTALE: ::c_int = 151; -pub const EUCLEAN: ::c_int = 135; -pub const ENOTNAM: ::c_int = 137; -pub const ENAVAIL: ::c_int = 138; -pub const EISNAM: ::c_int = 139; -pub const EREMOTEIO: ::c_int = 140; -pub const EDQUOT: ::c_int = 1133; -pub const ENOMEDIUM: ::c_int = 159; -pub const EMEDIUMTYPE: ::c_int = 160; -pub const ECANCELED: ::c_int = 158; -pub const ENOKEY: ::c_int = 161; -pub const EKEYEXPIRED: ::c_int = 162; -pub const EKEYREVOKED: ::c_int = 163; -pub const EKEYREJECTED: ::c_int = 164; -pub const EOWNERDEAD: ::c_int = 165; -pub const ENOTRECOVERABLE: ::c_int = 166; -pub const ERFKILL: ::c_int = 167; - -pub const MAP_NORESERVE: ::c_int = 0x400; -pub const MAP_ANON: ::c_int = 0x800; -pub const MAP_ANONYMOUS: ::c_int = 0x800; -pub const MAP_GROWSDOWN: ::c_int = 0x1000; -pub const MAP_DENYWRITE: ::c_int = 0x2000; -pub const MAP_EXECUTABLE: ::c_int = 0x4000; -pub const MAP_LOCKED: ::c_int = 0x8000; -pub const MAP_POPULATE: ::c_int = 0x10000; -pub const MAP_NONBLOCK: ::c_int = 0x20000; -pub const MAP_STACK: ::c_int = 0x40000; - -pub const SOCK_STREAM: ::c_int = 2; -pub const SOCK_DGRAM: ::c_int = 1; - -pub const SOL_SOCKET: ::c_int = 0xffff; - -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_STYLE: ::c_int = SO_TYPE; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ACCEPTCONN: ::c_int = 0x1009; -pub const SO_PROTOCOL: ::c_int = 0x1028; -pub const SO_DOMAIN: ::c_int = 0x1029; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PASSCRED: ::c_int = 17; -pub const SO_PEERCRED: ::c_int = 18; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_PEERSEC: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 31; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; -pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS; - -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; -pub const SO_INCOMING_CPU: ::c_int = 49; -pub const SO_ATTACH_BPF: ::c_int = 50; -pub const SO_DETACH_BPF: ::c_int = SO_DETACH_FILTER; - -pub const FIOCLEX: ::c_ulong = 0x6601; -pub const FIONCLEX: ::c_ulong = 0x6602; -pub const FIONBIO: ::c_ulong = 0x667e; - -pub const SA_SIGINFO: ::c_int = 0x00000008; -pub const SA_NOCLDWAIT: ::c_int = 0x00010000; - -pub const SIGCHLD: ::c_int = 18; -pub const SIGBUS: ::c_int = 10; -pub const SIGTTIN: ::c_int = 26; -pub const SIGTTOU: ::c_int = 27; -pub const SIGXCPU: ::c_int = 30; -pub const SIGXFSZ: ::c_int = 31; -pub const SIGVTALRM: ::c_int = 28; -pub const SIGPROF: ::c_int = 29; -pub const SIGWINCH: ::c_int = 20; -pub const SIGUSR1: ::c_int = 16; -pub const SIGUSR2: ::c_int = 17; -pub const SIGCONT: ::c_int = 25; -pub const SIGSTOP: ::c_int = 23; -pub const SIGTSTP: ::c_int = 24; -pub const SIGURG: ::c_int = 21; -pub const SIGIO: ::c_int = 22; -pub const SIGSYS: ::c_int = 12; -pub const SIGPOLL: ::c_int = 22; -pub const SIGPWR: ::c_int = 19; -pub const SIG_SETMASK: ::c_int = 3; -pub const SIG_BLOCK: ::c_int = 0x1; -pub const SIG_UNBLOCK: ::c_int = 0x2; - -pub const POLLWRNORM: ::c_short = 0x004; -pub const POLLWRBAND: ::c_short = 0x100; - -pub const VEOF: usize = 16; -pub const VEOL: usize = 17; -pub const VEOL2: usize = 6; -pub const VMIN: usize = 4; -pub const IEXTEN: ::tcflag_t = 0x00000100; -pub const TOSTOP: ::tcflag_t = 0x00008000; -pub const FLUSHO: ::tcflag_t = 0x00002000; -pub const EXTPROC: ::tcflag_t = 0o200000; -pub const TCSANOW: ::c_int = 0x540e; -pub const TCSADRAIN: ::c_int = 0x540f; -pub const TCSAFLUSH: ::c_int = 0x5410; - -pub const PTRACE_GETFPXREGS: ::c_uint = 18; -pub const PTRACE_SETFPXREGS: ::c_uint = 19; - -pub const MAP_HUGETLB: ::c_int = 0x080000; - -pub const EFD_NONBLOCK: ::c_int = 0x80; - -pub const F_GETLK: ::c_int = 14; -pub const F_GETOWN: ::c_int = 23; -pub const F_SETOWN: ::c_int = 24; - -pub const SFD_NONBLOCK: ::c_int = 0x80; - -pub const TCGETS: ::c_ulong = 0x540d; -pub const TCSETS: ::c_ulong = 0x540e; -pub const TCSETSW: ::c_ulong = 0x540f; -pub const TCSETSF: ::c_ulong = 0x5410; -pub const TCGETA: ::c_ulong = 0x5401; -pub const TCSETA: ::c_ulong = 0x5402; -pub const TCSETAW: ::c_ulong = 0x5403; -pub const TCSETAF: ::c_ulong = 0x5404; -pub const TCSBRK: ::c_ulong = 0x5405; -pub const TCXONC: ::c_ulong = 0x5406; -pub const TCFLSH: ::c_ulong = 0x5407; -pub const TIOCGSOFTCAR: ::c_ulong = 0x5481; -pub const TIOCSSOFTCAR: ::c_ulong = 0x5482; -pub const TIOCINQ: ::c_ulong = 0x467f; -pub const TIOCLINUX: ::c_ulong = 0x5483; -pub const TIOCGSERIAL: ::c_ulong = 0x5484; -pub const TIOCEXCL: ::c_ulong = 0x740d; -pub const TIOCNXCL: ::c_ulong = 0x740e; -pub const TIOCSCTTY: ::c_ulong = 0x5480; -pub const TIOCGPGRP: ::c_ulong = 0x40047477; -pub const TIOCSPGRP: ::c_ulong = 0x80047476; -pub const TIOCOUTQ: ::c_ulong = 0x7472; -pub const TIOCSTI: ::c_ulong = 0x5472; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const TIOCMGET: ::c_ulong = 0x741d; -pub const TIOCMBIS: ::c_ulong = 0x741b; -pub const TIOCMBIC: ::c_ulong = 0x741c; -pub const TIOCMSET: ::c_ulong = 0x741a; -pub const FIONREAD: ::c_ulong = 0x467f; -pub const TIOCCONS: ::c_ulong = 0x80047478; - -pub const RTLD_DEEPBIND: ::c_int = 0x10; -pub const RTLD_GLOBAL: ::c_int = 0x4; -pub const RTLD_NOLOAD: ::c_int = 0x8; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const TIOCM_ST: ::c_int = 0x010; -pub const TIOCM_SR: ::c_int = 0x020; -pub const TIOCM_CTS: ::c_int = 0x040; -pub const TIOCM_CAR: ::c_int = 0x100; -pub const TIOCM_RNG: ::c_int = 0x200; -pub const TIOCM_DSR: ::c_int = 0x400; - -pub const EHWPOISON: ::c_int = 168; - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/mod.rs b/libc/src/unix/linux_like/linux/gnu/b32/mod.rs deleted file mode 100644 index cc6b636..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/mod.rs +++ /dev/null @@ -1,271 +0,0 @@ -//! 32-bit specific definitions for linux-like values - -use pthread_mutex_t; - -pub type c_long = i32; -pub type c_ulong = u32; -pub type clock_t = i32; -pub type time_t = i32; -pub type suseconds_t = i32; -pub type ino_t = u32; -pub type off_t = i32; -pub type blkcnt_t = i32; - -pub type fsblkcnt_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; -pub type rlim_t = c_ulong; -pub type shmatt_t = ::c_ulong; -pub type msgqnum_t = ::c_ulong; -pub type msglen_t = ::c_ulong; -pub type blksize_t = i32; -pub type nlink_t = u32; -pub type __u64 = ::c_ulonglong; -pub type __fsword_t = i32; - -s! { - pub struct stat { - #[cfg(not(target_arch = "mips"))] - pub st_dev: ::dev_t, - #[cfg(target_arch = "mips")] - pub st_dev: ::c_ulong, - - #[cfg(not(target_arch = "mips"))] - __pad1: ::c_short, - #[cfg(target_arch = "mips")] - st_pad1: [::c_long; 3], - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - #[cfg(not(target_arch = "mips"))] - pub st_rdev: ::dev_t, - #[cfg(target_arch = "mips")] - pub st_rdev: ::c_ulong, - #[cfg(not(target_arch = "mips"))] - __pad2: ::c_short, - #[cfg(target_arch = "mips")] - st_pad2: [::c_long; 2], - pub st_size: ::off_t, - #[cfg(target_arch = "mips")] - st_pad3: ::c_long, - #[cfg(not(target_arch = "mips"))] - pub st_blksize: ::blksize_t, - #[cfg(not(target_arch = "mips"))] - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - #[cfg(not(target_arch = "mips"))] - __unused4: ::c_long, - #[cfg(not(target_arch = "mips"))] - __unused5: ::c_long, - #[cfg(target_arch = "mips")] - pub st_blksize: ::blksize_t, - #[cfg(target_arch = "mips")] - pub st_blocks: ::blkcnt_t, - #[cfg(target_arch = "mips")] - st_pad5: [::c_long; 14], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct pthread_attr_t { - __size: [u32; 9] - } - - pub struct sigset_t { - __val: [::c_ulong; 32], - } - - pub struct sysinfo { - pub uptime: ::c_long, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - #[deprecated( - since = "0.2.58", - note = "This padding field might become private in the future" - )] - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub _f: [::c_char; 8], - } -} - -pub const O_NOATIME: ::c_int = 0o1000000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; - -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_MARK: ::c_int = 36; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_BUSY_POLL: ::c_int = 46; - -pub const SA_ONSTACK: ::c_int = 0x08000000; - -pub const PTRACE_DETACH: ::c_uint = 17; -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; - -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; - -pub const O_CLOEXEC: ::c_int = 0x80000; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; - -align_const! { - #[cfg(target_endian = "little")] - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, - ], - }; - #[cfg(target_endian = "little")] - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, - ], - }; - #[cfg(target_endian = "little")] - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, - 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, - 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, - 0, 0, 0, - ], - }; -} - -pub const PTRACE_GETFPREGS: ::c_uint = 14; -pub const PTRACE_SETFPREGS: ::c_uint = 15; -pub const PTRACE_GETREGS: ::c_uint = 12; -pub const PTRACE_SETREGS: ::c_uint = 13; - -#[link(name = "util")] -extern "C" { - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_arch = "x86")] { - mod x86; - pub use self::x86::*; - } else if #[cfg(target_arch = "arm")] { - mod arm; - pub use self::arm::*; - } else if #[cfg(target_arch = "mips")] { - mod mips; - pub use self::mips::*; - } else if #[cfg(target_arch = "powerpc")] { - mod powerpc; - pub use self::powerpc::*; - } else if #[cfg(target_arch = "sparc")] { - mod sparc; - pub use self::sparc::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/powerpc.rs b/libc/src/unix/linux_like/linux/gnu/b32/powerpc.rs deleted file mode 100644 index 7644428..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/powerpc.rs +++ /dev/null @@ -1,873 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = i32; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statfs { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - f_spare: [::__fsword_t; 5], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct ipc_perm { - __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - __seq: u32, - __pad1: u32, - __glibc_reserved1: u64, - __glibc_reserved2: u64, - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: ::c_ushort, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __glibc_reserved4: ::c_ulong, - __glibc_reserved5: ::c_ulong, - } - - pub struct statfs64 { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - pub f_flags: ::__fsword_t, - pub f_spare: [::__fsword_t; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - __glibc_reserved1: ::c_uint, - pub shm_atime: ::time_t, - __glibc_reserved2: ::c_uint, - pub shm_dtime: ::time_t, - __glibc_reserved3: ::c_uint, - pub shm_ctime: ::time_t, - __glibc_reserved4: ::c_uint, - pub shm_segsz: ::size_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __glibc_reserved5: ::c_ulong, - __glibc_reserved6: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - __glibc_reserved1: ::c_uint, - pub msg_stime: ::time_t, - __glibc_reserved2: ::c_uint, - pub msg_rtime: ::time_t, - __glibc_reserved3: ::c_uint, - pub msg_ctime: ::time_t, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __glibc_reserved4: ::c_ulong, - __glibc_reserved5: ::c_ulong, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since="0.2.54", - note="Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } -} - -pub const RLIM_INFINITY: ::rlim_t = !0; -pub const VEOF: usize = 4; -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const O_DIRECT: ::c_int = 0x20000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_LARGEFILE: ::c_int = 0o200000; -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_FSYNC: ::c_int = 0x101000; -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_NDELAY: ::c_int = 0x800; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 6; -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_LOCKED: ::c_int = 0x00080; -pub const MAP_NORESERVE: ::c_int = 0x00040; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const EDEADLOCK: ::c_int = 58; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EBADMSG: ::c_int = 74; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const EHWPOISON: ::c_int = 133; -pub const ERFKILL: ::c_int = 132; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_LINGER: ::c_int = 13; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_RCVLOWAT: ::c_int = 16; -pub const SO_SNDLOWAT: ::c_int = 17; -pub const SO_RCVTIMEO: ::c_int = 18; -pub const SO_SNDTIMEO: ::c_int = 19; -pub const SO_PASSCRED: ::c_int = 20; -pub const SO_PEERCRED: ::c_int = 21; - -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const FIOCLEX: ::c_ulong = 0x20006601; -pub const FIONCLEX: ::c_ulong = 0x20006602; -pub const FIONBIO: ::c_ulong = 0x8004667e; - -pub const MCL_CURRENT: ::c_int = 0x2000; -pub const MCL_FUTURE: ::c_int = 0x4000; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; - -pub const EFD_NONBLOCK: ::c_int = 0x800; -pub const SFD_NONBLOCK: ::c_int = 0x0800; - -pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; -pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; -pub const TIOCEXCL: ::c_ulong = 0x540C; -pub const TIOCNXCL: ::c_ulong = 0x540D; -pub const TIOCSCTTY: ::c_ulong = 0x540E; -pub const TIOCSTI: ::c_ulong = 0x5412; -pub const TIOCMGET: ::c_ulong = 0x5415; -pub const TIOCMBIS: ::c_ulong = 0x5416; -pub const TIOCMBIC: ::c_ulong = 0x5417; -pub const TIOCMSET: ::c_ulong = 0x5418; -pub const TIOCCONS: ::c_ulong = 0x541D; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = 31; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGSTKSZ: ::size_t = 0x4000; -pub const MINSIGSTKSZ: ::size_t = 4096; -pub const CBAUD: ::tcflag_t = 0xff; -pub const TAB1: ::tcflag_t = 0x400; -pub const TAB2: ::tcflag_t = 0x800; -pub const TAB3: ::tcflag_t = 0xc00; -pub const CR1: ::tcflag_t = 0x1000; -pub const CR2: ::tcflag_t = 0x2000; -pub const CR3: ::tcflag_t = 0x3000; -pub const FF1: ::tcflag_t = 0x4000; -pub const BS1: ::tcflag_t = 0x8000; -pub const VT1: ::tcflag_t = 0x10000; -pub const VWERASE: usize = 0xa; -pub const VREPRINT: usize = 0xb; -pub const VSUSP: usize = 0xc; -pub const VSTART: usize = 0xd; -pub const VSTOP: usize = 0xe; -pub const VDISCARD: usize = 0x10; -pub const VTIME: usize = 0x7; -pub const IXON: ::tcflag_t = 0x200; -pub const IXOFF: ::tcflag_t = 0x400; -pub const ONLCR: ::tcflag_t = 0x2; -pub const CSIZE: ::tcflag_t = 0x300; -pub const CS6: ::tcflag_t = 0x100; -pub const CS7: ::tcflag_t = 0x200; -pub const CS8: ::tcflag_t = 0x300; -pub const CSTOPB: ::tcflag_t = 0x400; -pub const CREAD: ::tcflag_t = 0x800; -pub const PARENB: ::tcflag_t = 0x1000; -pub const PARODD: ::tcflag_t = 0x2000; -pub const HUPCL: ::tcflag_t = 0x4000; -pub const CLOCAL: ::tcflag_t = 0x8000; -pub const ECHOKE: ::tcflag_t = 0x1; -pub const ECHOE: ::tcflag_t = 0x2; -pub const ECHOK: ::tcflag_t = 0x4; -pub const ECHONL: ::tcflag_t = 0x10; -pub const ECHOPRT: ::tcflag_t = 0x20; -pub const ECHOCTL: ::tcflag_t = 0x40; -pub const ISIG: ::tcflag_t = 0x80; -pub const ICANON: ::tcflag_t = 0x100; -pub const PENDIN: ::tcflag_t = 0x20000000; -pub const NOFLSH: ::tcflag_t = 0x80000000; -pub const VSWTC: usize = 9; -pub const OLCUC: ::tcflag_t = 0o000004; -pub const NLDLY: ::tcflag_t = 0o001400; -pub const CRDLY: ::tcflag_t = 0o030000; -pub const TABDLY: ::tcflag_t = 0o006000; -pub const BSDLY: ::tcflag_t = 0o100000; -pub const FFDLY: ::tcflag_t = 0o040000; -pub const VTDLY: ::tcflag_t = 0o200000; -pub const XTABS: ::tcflag_t = 0o006000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const CBAUDEX: ::speed_t = 0o000020; -pub const B57600: ::speed_t = 0o0020; -pub const B115200: ::speed_t = 0o0021; -pub const B230400: ::speed_t = 0o0022; -pub const B460800: ::speed_t = 0o0023; -pub const B500000: ::speed_t = 0o0024; -pub const B576000: ::speed_t = 0o0025; -pub const B921600: ::speed_t = 0o0026; -pub const B1000000: ::speed_t = 0o0027; -pub const B1152000: ::speed_t = 0o0030; -pub const B1500000: ::speed_t = 0o0031; -pub const B2000000: ::speed_t = 0o0032; -pub const B2500000: ::speed_t = 0o0033; -pub const B3000000: ::speed_t = 0o0034; -pub const B3500000: ::speed_t = 0o0035; -pub const B4000000: ::speed_t = 0o0036; -pub const BOTHER: ::speed_t = 0o0037; - -pub const VEOL: usize = 6; -pub const VEOL2: usize = 8; -pub const VMIN: usize = 5; -pub const IEXTEN: ::tcflag_t = 0x400; -pub const TOSTOP: ::tcflag_t = 0x400000; -pub const FLUSHO: ::tcflag_t = 0x800000; -pub const EXTPROC: ::tcflag_t = 0x10000000; -pub const TCGETS: ::c_ulong = 0x403c7413; -pub const TCSETS: ::c_ulong = 0x803c7414; -pub const TCSETSW: ::c_ulong = 0x803c7415; -pub const TCSETSF: ::c_ulong = 0x803c7416; -pub const TCGETA: ::c_ulong = 0x40147417; -pub const TCSETA: ::c_ulong = 0x80147418; -pub const TCSETAW: ::c_ulong = 0x80147419; -pub const TCSETAF: ::c_ulong = 0x8014741c; -pub const TCSBRK: ::c_ulong = 0x2000741d; -pub const TCXONC: ::c_ulong = 0x2000741e; -pub const TCFLSH: ::c_ulong = 0x2000741f; -pub const TIOCINQ: ::c_ulong = 0x4004667f; -pub const TIOCGPGRP: ::c_ulong = 0x40047477; -pub const TIOCSPGRP: ::c_ulong = 0x80047476; -pub const TIOCOUTQ: ::c_ulong = 0x40047473; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const TIOCGRS485: ::c_int = 0x542e; -pub const TIOCSRS485: ::c_int = 0x542f; -pub const FIONREAD: ::c_ulong = 0x4004667f; - -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_waitpid: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_time: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_break: ::c_long = 17; -pub const SYS_oldstat: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_umount: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_stime: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_oldfstat: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_stty: ::c_long = 31; -pub const SYS_gtty: ::c_long = 32; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_ftime: ::c_long = 35; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_prof: ::c_long = 44; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_lock: ::c_long = 53; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_mpx: ::c_long = 56; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_ulimit: ::c_long = 58; -pub const SYS_oldolduname: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_sgetmask: ::c_long = 68; -pub const SYS_ssetmask: ::c_long = 69; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrlimit: ::c_long = 76; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_select: ::c_long = 82; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_oldlstat: ::c_long = 84; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_readdir: ::c_long = 89; -pub const SYS_mmap: ::c_long = 90; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_profil: ::c_long = 98; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_ioperm: ::c_long = 101; -pub const SYS_socketcall: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_olduname: ::c_long = 109; -pub const SYS_iopl: ::c_long = 110; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_idle: ::c_long = 112; -pub const SYS_vm86: ::c_long = 113; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_ipc: ::c_long = 117; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_modify_ldt: ::c_long = 123; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_create_module: ::c_long = 127; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_get_kernel_syms: ::c_long = 130; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_afs_syscall: ::c_long = 137; /* Syscall for Andrew File System */ -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_query_module: ::c_long = 166; -pub const SYS_poll: ::c_long = 167; -pub const SYS_nfsservctl: ::c_long = 168; -pub const SYS_setresgid: ::c_long = 169; -pub const SYS_getresgid: ::c_long = 170; -pub const SYS_prctl: ::c_long = 171; -pub const SYS_rt_sigreturn: ::c_long = 172; -pub const SYS_rt_sigaction: ::c_long = 173; -pub const SYS_rt_sigprocmask: ::c_long = 174; -pub const SYS_rt_sigpending: ::c_long = 175; -pub const SYS_rt_sigtimedwait: ::c_long = 176; -pub const SYS_rt_sigqueueinfo: ::c_long = 177; -pub const SYS_rt_sigsuspend: ::c_long = 178; -pub const SYS_pread64: ::c_long = 179; -pub const SYS_pwrite64: ::c_long = 180; -pub const SYS_chown: ::c_long = 181; -pub const SYS_getcwd: ::c_long = 182; -pub const SYS_capget: ::c_long = 183; -pub const SYS_capset: ::c_long = 184; -pub const SYS_sigaltstack: ::c_long = 185; -pub const SYS_sendfile: ::c_long = 186; -pub const SYS_getpmsg: ::c_long = 187; /* some people actually want streams */ -pub const SYS_putpmsg: ::c_long = 188; /* some people actually want streams */ -pub const SYS_vfork: ::c_long = 189; -pub const SYS_ugetrlimit: ::c_long = 190; /* SuS compliant getrlimit */ -pub const SYS_readahead: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_pciconfig_read: ::c_long = 198; -pub const SYS_pciconfig_write: ::c_long = 199; -pub const SYS_pciconfig_iobase: ::c_long = 200; -pub const SYS_multiplexer: ::c_long = 201; -pub const SYS_getdents64: ::c_long = 202; -pub const SYS_pivot_root: ::c_long = 203; -pub const SYS_fcntl64: ::c_long = 204; -pub const SYS_madvise: ::c_long = 205; -pub const SYS_mincore: ::c_long = 206; -pub const SYS_gettid: ::c_long = 207; -pub const SYS_tkill: ::c_long = 208; -pub const SYS_setxattr: ::c_long = 209; -pub const SYS_lsetxattr: ::c_long = 210; -pub const SYS_fsetxattr: ::c_long = 211; -pub const SYS_getxattr: ::c_long = 212; -pub const SYS_lgetxattr: ::c_long = 213; -pub const SYS_fgetxattr: ::c_long = 214; -pub const SYS_listxattr: ::c_long = 215; -pub const SYS_llistxattr: ::c_long = 216; -pub const SYS_flistxattr: ::c_long = 217; -pub const SYS_removexattr: ::c_long = 218; -pub const SYS_lremovexattr: ::c_long = 219; -pub const SYS_fremovexattr: ::c_long = 220; -pub const SYS_futex: ::c_long = 221; -pub const SYS_sched_setaffinity: ::c_long = 222; -pub const SYS_sched_getaffinity: ::c_long = 223; -pub const SYS_tuxcall: ::c_long = 225; -pub const SYS_sendfile64: ::c_long = 226; -pub const SYS_io_setup: ::c_long = 227; -pub const SYS_io_destroy: ::c_long = 228; -pub const SYS_io_getevents: ::c_long = 229; -pub const SYS_io_submit: ::c_long = 230; -pub const SYS_io_cancel: ::c_long = 231; -pub const SYS_set_tid_address: ::c_long = 232; -pub const SYS_fadvise64: ::c_long = 233; -pub const SYS_exit_group: ::c_long = 234; -pub const SYS_lookup_dcookie: ::c_long = 235; -pub const SYS_epoll_create: ::c_long = 236; -pub const SYS_epoll_ctl: ::c_long = 237; -pub const SYS_epoll_wait: ::c_long = 238; -pub const SYS_remap_file_pages: ::c_long = 239; -pub const SYS_timer_create: ::c_long = 240; -pub const SYS_timer_settime: ::c_long = 241; -pub const SYS_timer_gettime: ::c_long = 242; -pub const SYS_timer_getoverrun: ::c_long = 243; -pub const SYS_timer_delete: ::c_long = 244; -pub const SYS_clock_settime: ::c_long = 245; -pub const SYS_clock_gettime: ::c_long = 246; -pub const SYS_clock_getres: ::c_long = 247; -pub const SYS_clock_nanosleep: ::c_long = 248; -pub const SYS_swapcontext: ::c_long = 249; -pub const SYS_tgkill: ::c_long = 250; -pub const SYS_utimes: ::c_long = 251; -pub const SYS_statfs64: ::c_long = 252; -pub const SYS_fstatfs64: ::c_long = 253; -pub const SYS_fadvise64_64: ::c_long = 254; -pub const SYS_rtas: ::c_long = 255; -pub const SYS_sys_debug_setcontext: ::c_long = 256; -pub const SYS_migrate_pages: ::c_long = 258; -pub const SYS_mbind: ::c_long = 259; -pub const SYS_get_mempolicy: ::c_long = 260; -pub const SYS_set_mempolicy: ::c_long = 261; -pub const SYS_mq_open: ::c_long = 262; -pub const SYS_mq_unlink: ::c_long = 263; -pub const SYS_mq_timedsend: ::c_long = 264; -pub const SYS_mq_timedreceive: ::c_long = 265; -pub const SYS_mq_notify: ::c_long = 266; -pub const SYS_mq_getsetattr: ::c_long = 267; -pub const SYS_kexec_load: ::c_long = 268; -pub const SYS_add_key: ::c_long = 269; -pub const SYS_request_key: ::c_long = 270; -pub const SYS_keyctl: ::c_long = 271; -pub const SYS_waitid: ::c_long = 272; -pub const SYS_ioprio_set: ::c_long = 273; -pub const SYS_ioprio_get: ::c_long = 274; -pub const SYS_inotify_init: ::c_long = 275; -pub const SYS_inotify_add_watch: ::c_long = 276; -pub const SYS_inotify_rm_watch: ::c_long = 277; -pub const SYS_spu_run: ::c_long = 278; -pub const SYS_spu_create: ::c_long = 279; -pub const SYS_pselect6: ::c_long = 280; -pub const SYS_ppoll: ::c_long = 281; -pub const SYS_unshare: ::c_long = 282; -pub const SYS_splice: ::c_long = 283; -pub const SYS_tee: ::c_long = 284; -pub const SYS_vmsplice: ::c_long = 285; -pub const SYS_openat: ::c_long = 286; -pub const SYS_mkdirat: ::c_long = 287; -pub const SYS_mknodat: ::c_long = 288; -pub const SYS_fchownat: ::c_long = 289; -pub const SYS_futimesat: ::c_long = 290; -pub const SYS_fstatat64: ::c_long = 291; -pub const SYS_unlinkat: ::c_long = 292; -pub const SYS_renameat: ::c_long = 293; -pub const SYS_linkat: ::c_long = 294; -pub const SYS_symlinkat: ::c_long = 295; -pub const SYS_readlinkat: ::c_long = 296; -pub const SYS_fchmodat: ::c_long = 297; -pub const SYS_faccessat: ::c_long = 298; -pub const SYS_get_robust_list: ::c_long = 299; -pub const SYS_set_robust_list: ::c_long = 300; -pub const SYS_move_pages: ::c_long = 301; -pub const SYS_getcpu: ::c_long = 302; -pub const SYS_epoll_pwait: ::c_long = 303; -pub const SYS_utimensat: ::c_long = 304; -pub const SYS_signalfd: ::c_long = 305; -pub const SYS_timerfd_create: ::c_long = 306; -pub const SYS_eventfd: ::c_long = 307; -pub const SYS_sync_file_range2: ::c_long = 308; -pub const SYS_fallocate: ::c_long = 309; -pub const SYS_subpage_prot: ::c_long = 310; -pub const SYS_timerfd_settime: ::c_long = 311; -pub const SYS_timerfd_gettime: ::c_long = 312; -pub const SYS_signalfd4: ::c_long = 313; -pub const SYS_eventfd2: ::c_long = 314; -pub const SYS_epoll_create1: ::c_long = 315; -pub const SYS_dup3: ::c_long = 316; -pub const SYS_pipe2: ::c_long = 317; -pub const SYS_inotify_init1: ::c_long = 318; -pub const SYS_perf_event_open: ::c_long = 319; -pub const SYS_preadv: ::c_long = 320; -pub const SYS_pwritev: ::c_long = 321; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 322; -pub const SYS_fanotify_init: ::c_long = 323; -pub const SYS_fanotify_mark: ::c_long = 324; -pub const SYS_prlimit64: ::c_long = 325; -pub const SYS_socket: ::c_long = 326; -pub const SYS_bind: ::c_long = 327; -pub const SYS_connect: ::c_long = 328; -pub const SYS_listen: ::c_long = 329; -pub const SYS_accept: ::c_long = 330; -pub const SYS_getsockname: ::c_long = 331; -pub const SYS_getpeername: ::c_long = 332; -pub const SYS_socketpair: ::c_long = 333; -pub const SYS_send: ::c_long = 334; -pub const SYS_sendto: ::c_long = 335; -pub const SYS_recv: ::c_long = 336; -pub const SYS_recvfrom: ::c_long = 337; -pub const SYS_shutdown: ::c_long = 338; -pub const SYS_setsockopt: ::c_long = 339; -pub const SYS_getsockopt: ::c_long = 340; -pub const SYS_sendmsg: ::c_long = 341; -pub const SYS_recvmsg: ::c_long = 342; -pub const SYS_recvmmsg: ::c_long = 343; -pub const SYS_accept4: ::c_long = 344; -pub const SYS_name_to_handle_at: ::c_long = 345; -pub const SYS_open_by_handle_at: ::c_long = 346; -pub const SYS_clock_adjtime: ::c_long = 347; -pub const SYS_syncfs: ::c_long = 348; -pub const SYS_sendmmsg: ::c_long = 349; -pub const SYS_setns: ::c_long = 350; -pub const SYS_process_vm_readv: ::c_long = 351; -pub const SYS_process_vm_writev: ::c_long = 352; -pub const SYS_finit_module: ::c_long = 353; -pub const SYS_kcmp: ::c_long = 354; -pub const SYS_sched_setattr: ::c_long = 355; -pub const SYS_sched_getattr: ::c_long = 356; -pub const SYS_renameat2: ::c_long = 357; -pub const SYS_seccomp: ::c_long = 358; -pub const SYS_getrandom: ::c_long = 359; -pub const SYS_memfd_create: ::c_long = 360; -pub const SYS_bpf: ::c_long = 361; -pub const SYS_execveat: ::c_long = 362; -pub const SYS_switch_endian: ::c_long = 363; -pub const SYS_userfaultfd: ::c_long = 364; -pub const SYS_membarrier: ::c_long = 365; -pub const SYS_mlock2: ::c_long = 378; -pub const SYS_copy_file_range: ::c_long = 379; -pub const SYS_preadv2: ::c_long = 380; -pub const SYS_pwritev2: ::c_long = 381; -pub const SYS_kexec_file_load: ::c_long = 382; -pub const SYS_statx: ::c_long = 383; diff --git a/libc/src/unix/linux_like/linux/gnu/b32/sparc/align.rs b/libc/src/unix/linux_like/linux/gnu/b32/sparc/align.rs deleted file mode 100644 index 98fda88..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/sparc/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(8))] - pub struct max_align_t { - priv_: [i64; 3] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/sparc/mod.rs b/libc/src/unix/linux_like/linux/gnu/b32/sparc/mod.rs deleted file mode 100644 index f670b34..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/sparc/mod.rs +++ /dev/null @@ -1,978 +0,0 @@ -//! SPARC-specific definitions for 32-bit linux-like values - -pub type c_char = u8; -pub type wchar_t = i32; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statfs { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - f_spare: [::__fsword_t; 5], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - __reserved: ::c_short, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: ::c_ushort, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 2], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: ::c_ushort, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __reserved: [::c_long; 2], - } - - pub struct statfs64 { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - pub f_flags: ::__fsword_t, - pub f_spare: [::__fsword_t; 4], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - __pad1: ::c_ushort, - pub mode: ::c_ushort, - __pad2: ::c_ushort, - pub __seq: ::c_ushort, - __unused1: ::c_ulonglong, - __unused2: ::c_ulonglong, - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - __pad1: ::c_uint, - pub shm_atime: ::time_t, - __pad2: ::c_uint, - pub shm_dtime: ::time_t, - __pad3: ::c_uint, - pub shm_ctime: ::time_t, - pub shm_segsz: ::size_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __reserved1: ::c_ulong, - __reserved2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - __pad1: ::c_uint, - pub msg_stime: ::time_t, - __pad2: ::c_uint, - pub msg_rtime: ::time_t, - __pad3: ::c_uint, - pub msg_ctime: ::time_t, - __msg_cbytes: ::c_ushort, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __glibc_reserved1: ::c_ulong, - __glibc_reserved2: ::c_ulong, - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } -} - -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const RLIM_INFINITY: ::rlim_t = !0; -pub const VEOF: usize = 4; -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; - -pub const TIOCGSOFTCAR: ::c_ulong = 0x40047464; -pub const TIOCSSOFTCAR: ::c_ulong = 0x80047465; - -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 6; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 7; - -pub const O_APPEND: ::c_int = 0x8; -pub const O_CREAT: ::c_int = 0x200; -pub const O_EXCL: ::c_int = 0x800; -pub const O_NOCTTY: ::c_int = 0x8000; -pub const O_NONBLOCK: ::c_int = 0x4000; -pub const O_SYNC: ::c_int = 0x802000; -pub const O_RSYNC: ::c_int = 0x802000; -pub const O_DSYNC: ::c_int = 0x2000; -pub const O_FSYNC: ::c_int = 0x802000; -pub const O_NOATIME: ::c_int = 0x200000; -pub const O_PATH: ::c_int = 0x1000000; -pub const O_TMPFILE: ::c_int = 0x2000000 | O_DIRECTORY; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_GROWSDOWN: ::c_int = 0x0200; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const EDEADLK: ::c_int = 78; -pub const ENAMETOOLONG: ::c_int = 63; -pub const ENOLCK: ::c_int = 79; -pub const ENOSYS: ::c_int = 90; -pub const ENOTEMPTY: ::c_int = 66; -pub const ELOOP: ::c_int = 62; -pub const ENOMSG: ::c_int = 75; -pub const EIDRM: ::c_int = 77; -pub const ECHRNG: ::c_int = 94; -pub const EL2NSYNC: ::c_int = 95; -pub const EL3HLT: ::c_int = 96; -pub const EL3RST: ::c_int = 97; -pub const ELNRNG: ::c_int = 98; -pub const EUNATCH: ::c_int = 99; -pub const ENOCSI: ::c_int = 100; -pub const EL2HLT: ::c_int = 101; -pub const EBADE: ::c_int = 102; -pub const EBADR: ::c_int = 103; -pub const EXFULL: ::c_int = 104; -pub const ENOANO: ::c_int = 105; -pub const EBADRQC: ::c_int = 106; -pub const EBADSLT: ::c_int = 107; -pub const EMULTIHOP: ::c_int = 87; -pub const EOVERFLOW: ::c_int = 92; -pub const ENOTUNIQ: ::c_int = 115; -pub const EBADFD: ::c_int = 93; -pub const EBADMSG: ::c_int = 76; -pub const EREMCHG: ::c_int = 89; -pub const ELIBACC: ::c_int = 114; -pub const ELIBBAD: ::c_int = 112; -pub const ELIBSCN: ::c_int = 124; -pub const ELIBMAX: ::c_int = 123; -pub const ELIBEXEC: ::c_int = 110; -pub const EILSEQ: ::c_int = 122; -pub const ERESTART: ::c_int = 116; -pub const ESTRPIPE: ::c_int = 91; -pub const EUSERS: ::c_int = 68; -pub const ENOTSOCK: ::c_int = 38; -pub const EDESTADDRREQ: ::c_int = 39; -pub const EMSGSIZE: ::c_int = 40; -pub const EPROTOTYPE: ::c_int = 41; -pub const ENOPROTOOPT: ::c_int = 42; -pub const EPROTONOSUPPORT: ::c_int = 43; -pub const ESOCKTNOSUPPORT: ::c_int = 44; -pub const EOPNOTSUPP: ::c_int = 45; -pub const EPFNOSUPPORT: ::c_int = 46; -pub const EAFNOSUPPORT: ::c_int = 47; -pub const EADDRINUSE: ::c_int = 48; -pub const EADDRNOTAVAIL: ::c_int = 49; -pub const ENETDOWN: ::c_int = 50; -pub const ENETUNREACH: ::c_int = 51; -pub const ENETRESET: ::c_int = 52; -pub const ECONNABORTED: ::c_int = 53; -pub const ECONNRESET: ::c_int = 54; -pub const ENOBUFS: ::c_int = 55; -pub const EISCONN: ::c_int = 56; -pub const ENOTCONN: ::c_int = 57; -pub const ESHUTDOWN: ::c_int = 58; -pub const ETOOMANYREFS: ::c_int = 59; -pub const ETIMEDOUT: ::c_int = 60; -pub const ECONNREFUSED: ::c_int = 61; -pub const EHOSTDOWN: ::c_int = 64; -pub const EHOSTUNREACH: ::c_int = 65; -pub const EALREADY: ::c_int = 37; -pub const EINPROGRESS: ::c_int = 36; -pub const ESTALE: ::c_int = 70; -pub const EDQUOT: ::c_int = 69; -pub const ENOMEDIUM: ::c_int = 125; -pub const EMEDIUMTYPE: ::c_int = 126; -pub const ECANCELED: ::c_int = 127; -pub const ENOKEY: ::c_int = 128; -pub const EKEYEXPIRED: ::c_int = 129; -pub const EKEYREVOKED: ::c_int = 130; -pub const EKEYREJECTED: ::c_int = 131; -pub const EOWNERDEAD: ::c_int = 132; -pub const ENOTRECOVERABLE: ::c_int = 133; -pub const EHWPOISON: ::c_int = 135; -pub const ERFKILL: ::c_int = 134; - -pub const SOL_SOCKET: ::c_int = 0xffff; - -pub const SO_PASSCRED: ::c_int = 2; -pub const SO_REUSEADDR: ::c_int = 4; -pub const SO_BINDTODEVICE: ::c_int = 0x000d; -pub const SO_TIMESTAMP: ::c_int = 0x001d; -pub const SO_MARK: ::c_int = 0x0022; -pub const SO_RXQ_OVFL: ::c_int = 0x0024; -pub const SO_PEEK_OFF: ::c_int = 0x0026; -pub const SO_BUSY_POLL: ::c_int = 0x0030; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_DONTROUTE: ::c_int = 16; -pub const SO_BROADCAST: ::c_int = 32; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDBUFFORCE: ::c_int = 0x100a; -pub const SO_RCVBUFFORCE: ::c_int = 0x100b; -pub const SO_DOMAIN: ::c_int = 0x1029; -pub const SO_KEEPALIVE: ::c_int = 8; -pub const SO_OOBINLINE: ::c_int = 0x100; -pub const SO_LINGER: ::c_int = 128; -pub const SO_REUSEPORT: ::c_int = 0x200; -pub const SO_ACCEPTCONN: ::c_int = 0x8000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const SA_ONSTACK: ::c_int = 1; -pub const SA_SIGINFO: ::c_int = 0x200; -pub const SA_NOCLDWAIT: ::c_int = 0x100; - -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGCHLD: ::c_int = 20; -pub const SIGBUS: ::c_int = 10; -pub const SIGUSR1: ::c_int = 30; -pub const SIGUSR2: ::c_int = 31; -pub const SIGCONT: ::c_int = 19; -pub const SIGSTOP: ::c_int = 17; -pub const SIGTSTP: ::c_int = 18; -pub const SIGURG: ::c_int = 16; -pub const SIGIO: ::c_int = 23; -pub const SIGSYS: ::c_int = 12; -pub const SIGPOLL: ::c_int = 23; -pub const SIGPWR: ::c_int = 29; -pub const SIG_SETMASK: ::c_int = 4; -pub const SIG_BLOCK: ::c_int = 1; -pub const SIG_UNBLOCK: ::c_int = 2; - -pub const POLLWRNORM: ::c_short = 4; -pub const POLLWRBAND: ::c_short = 0x100; - -pub const O_ASYNC: ::c_int = 0x40; -pub const O_NDELAY: ::c_int = 0x4004; - -pub const PTRACE_DETACH: ::c_uint = 11; - -pub const EFD_NONBLOCK: ::c_int = 0x4000; - -pub const F_GETLK: ::c_int = 7; -pub const F_GETOWN: ::c_int = 5; -pub const F_SETOWN: ::c_int = 6; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; - -pub const F_RDLCK: ::c_int = 1; -pub const F_WRLCK: ::c_int = 2; -pub const F_UNLCK: ::c_int = 3; - -pub const SFD_NONBLOCK: ::c_int = 0x4000; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; -pub const TIOCEXCL: ::c_ulong = 0x2000740d; -pub const TIOCNXCL: ::c_ulong = 0x2000740e; -pub const TIOCSCTTY: ::c_ulong = 0x20007484; -pub const TIOCSTI: ::c_ulong = 0x80017472; -pub const TIOCMGET: ::c_ulong = 0x4004746a; -pub const TIOCMBIS: ::c_ulong = 0x8004746c; -pub const TIOCMBIC: ::c_ulong = 0x8004746b; -pub const TIOCMSET: ::c_ulong = 0x8004746d; -pub const TIOCCONS: ::c_ulong = 0x20007424; - -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -pub const SFD_CLOEXEC: ::c_int = 0x400000; - -pub const NCCS: usize = 17; -pub const O_TRUNC: ::c_int = 0x400; - -pub const O_CLOEXEC: ::c_int = 0x400000; - -pub const EBFONT: ::c_int = 109; -pub const ENOSTR: ::c_int = 72; -pub const ENODATA: ::c_int = 111; -pub const ETIME: ::c_int = 73; -pub const ENOSR: ::c_int = 74; -pub const ENONET: ::c_int = 80; -pub const ENOPKG: ::c_int = 113; -pub const EREMOTE: ::c_int = 71; -pub const ENOLINK: ::c_int = 82; -pub const EADV: ::c_int = 83; -pub const ESRMNT: ::c_int = 84; -pub const ECOMM: ::c_int = 85; -pub const EPROTO: ::c_int = 86; -pub const EDOTDOT: ::c_int = 88; - -pub const SA_NODEFER: ::c_int = 0x20; -pub const SA_RESETHAND: ::c_int = 0x4; -pub const SA_RESTART: ::c_int = 0x2; -pub const SA_NOCLDSTOP: ::c_int = 0x00000008; - -pub const EPOLL_CLOEXEC: ::c_int = 0x400000; - -pub const EFD_CLOEXEC: ::c_int = 0x400000; - -pub const O_DIRECTORY: ::c_int = 0o200000; -pub const O_NOFOLLOW: ::c_int = 0o400000; -pub const O_LARGEFILE: ::c_int = 0x40000; -pub const O_DIRECT: ::c_int = 0x100000; - -pub const MAP_LOCKED: ::c_int = 0x0100; -pub const MAP_NORESERVE: ::c_int = 0x00040; - -pub const EDEADLOCK: ::c_int = 108; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; - -pub const SO_PEERCRED: ::c_int = 0x40; -pub const SO_RCVLOWAT: ::c_int = 0x800; -pub const SO_SNDLOWAT: ::c_int = 0x1000; -pub const SO_RCVTIMEO: ::c_int = 0x2000; -pub const SO_SNDTIMEO: ::c_int = 0x4000; - -pub const FIOCLEX: ::c_ulong = 0x20006601; -pub const FIONCLEX: ::c_ulong = 0x20006602; -pub const FIONBIO: ::c_ulong = 0x8004667e; - -pub const MCL_CURRENT: ::c_int = 0x2000; -pub const MCL_FUTURE: ::c_int = 0x4000; - -pub const SIGSTKSZ: ::size_t = 16384; -pub const MINSIGSTKSZ: ::size_t = 4096; -pub const CBAUD: ::tcflag_t = 0x0000100f; -pub const TAB1: ::tcflag_t = 0x800; -pub const TAB2: ::tcflag_t = 0x1000; -pub const TAB3: ::tcflag_t = 0x1800; -pub const CR1: ::tcflag_t = 0x200; -pub const CR2: ::tcflag_t = 0x400; -pub const CR3: ::tcflag_t = 0x600; -pub const FF1: ::tcflag_t = 0x8000; -pub const BS1: ::tcflag_t = 0x2000; -pub const VT1: ::tcflag_t = 0x4000; -pub const VWERASE: usize = 0xe; -pub const VREPRINT: usize = 0xc; -pub const VSUSP: usize = 0xa; -pub const VSTART: usize = 0x8; -pub const VSTOP: usize = 0x9; -pub const VDISCARD: usize = 0xd; -pub const VTIME: usize = 0x5; -pub const IXON: ::tcflag_t = 0x400; -pub const IXOFF: ::tcflag_t = 0x1000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x30; -pub const CS6: ::tcflag_t = 0x10; -pub const CS7: ::tcflag_t = 0x20; -pub const CS8: ::tcflag_t = 0x30; -pub const CSTOPB: ::tcflag_t = 0x40; -pub const CREAD: ::tcflag_t = 0x80; -pub const PARENB: ::tcflag_t = 0x100; -pub const PARODD: ::tcflag_t = 0x200; -pub const HUPCL: ::tcflag_t = 0x400; -pub const CLOCAL: ::tcflag_t = 0x800; -pub const ECHOKE: ::tcflag_t = 0x800; -pub const ECHOE: ::tcflag_t = 0x10; -pub const ECHOK: ::tcflag_t = 0x20; -pub const ECHONL: ::tcflag_t = 0x40; -pub const ECHOPRT: ::tcflag_t = 0x400; -pub const ECHOCTL: ::tcflag_t = 0x200; -pub const ISIG: ::tcflag_t = 0x1; -pub const ICANON: ::tcflag_t = 0x2; -pub const PENDIN: ::tcflag_t = 0x4000; -pub const NOFLSH: ::tcflag_t = 0x80; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0x00001000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0x1000; -pub const B57600: ::speed_t = 0x1001; -pub const B115200: ::speed_t = 0x1002; -pub const B230400: ::speed_t = 0x1003; -pub const B460800: ::speed_t = 0x1004; -pub const B76800: ::speed_t = 0x1005; -pub const B153600: ::speed_t = 0x1006; -pub const B307200: ::speed_t = 0x1007; -pub const B614400: ::speed_t = 0x1008; -pub const B921600: ::speed_t = 0x1009; -pub const B500000: ::speed_t = 0x100a; -pub const B576000: ::speed_t = 0x100b; -pub const B1000000: ::speed_t = 0x100c; -pub const B1152000: ::speed_t = 0x100d; -pub const B1500000: ::speed_t = 0x100e; -pub const B2000000: ::speed_t = 0x100f; - -pub const VEOL: usize = 5; -pub const VEOL2: usize = 6; -pub const VMIN: usize = 4; -pub const IEXTEN: ::tcflag_t = 0x8000; -pub const TOSTOP: ::tcflag_t = 0x100; -pub const FLUSHO: ::tcflag_t = 0x1000; -pub const EXTPROC: ::tcflag_t = 0x10000; -pub const TCGETS: ::c_ulong = 0x40245408; -pub const TCSETS: ::c_ulong = 0x80245409; -pub const TCSETSW: ::c_ulong = 0x8024540a; -pub const TCSETSF: ::c_ulong = 0x8024540b; -pub const TCGETA: ::c_ulong = 0x40125401; -pub const TCSETA: ::c_ulong = 0x80125402; -pub const TCSETAW: ::c_ulong = 0x80125403; -pub const TCSETAF: ::c_ulong = 0x80125404; -pub const TCSBRK: ::c_ulong = 0x20005405; -pub const TCXONC: ::c_ulong = 0x20005406; -pub const TCFLSH: ::c_ulong = 0x20005407; -pub const TIOCINQ: ::c_ulong = 0x4004667f; -pub const TIOCGPGRP: ::c_ulong = 0x40047483; -pub const TIOCSPGRP: ::c_ulong = 0x80047482; -pub const TIOCOUTQ: ::c_ulong = 0x40047473; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const FIONREAD: ::c_ulong = 0x4004667f; - -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_wait4: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execv: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_chown: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_brk: ::c_long = 17; -pub const SYS_perfctr: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_capget: ::c_long = 21; -pub const SYS_capset: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_vmsplice: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_sigaltstack: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_lchown32: ::c_long = 31; -pub const SYS_fchown32: ::c_long = 32; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_chown32: ::c_long = 35; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_stat: ::c_long = 38; -pub const SYS_sendfile: ::c_long = 39; -pub const SYS_lstat: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_getuid32: ::c_long = 44; -pub const SYS_umount2: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_getgid32: ::c_long = 53; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_reboot: ::c_long = 55; -pub const SYS_mmap2: ::c_long = 56; -pub const SYS_symlink: ::c_long = 57; -pub const SYS_readlink: ::c_long = 58; -pub const SYS_execve: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_fstat: ::c_long = 62; -pub const SYS_fstat64: ::c_long = 63; -pub const SYS_getpagesize: ::c_long = 64; -pub const SYS_msync: ::c_long = 65; -pub const SYS_vfork: ::c_long = 66; -pub const SYS_pread64: ::c_long = 67; -pub const SYS_pwrite64: ::c_long = 68; -pub const SYS_geteuid32: ::c_long = 69; -pub const SYS_getegid32: ::c_long = 70; -pub const SYS_mmap: ::c_long = 71; -pub const SYS_setreuid32: ::c_long = 72; -pub const SYS_munmap: ::c_long = 73; -pub const SYS_mprotect: ::c_long = 74; -pub const SYS_madvise: ::c_long = 75; -pub const SYS_vhangup: ::c_long = 76; -pub const SYS_truncate64: ::c_long = 77; -pub const SYS_mincore: ::c_long = 78; -pub const SYS_getgroups: ::c_long = 79; -pub const SYS_setgroups: ::c_long = 80; -pub const SYS_getpgrp: ::c_long = 81; -pub const SYS_setgroups32: ::c_long = 82; -pub const SYS_setitimer: ::c_long = 83; -pub const SYS_ftruncate64: ::c_long = 84; -pub const SYS_swapon: ::c_long = 85; -pub const SYS_getitimer: ::c_long = 86; -pub const SYS_setuid32: ::c_long = 87; -pub const SYS_sethostname: ::c_long = 88; -pub const SYS_setgid32: ::c_long = 89; -pub const SYS_dup2: ::c_long = 90; -pub const SYS_setfsuid32: ::c_long = 91; -pub const SYS_fcntl: ::c_long = 92; -pub const SYS_select: ::c_long = 93; -pub const SYS_setfsgid32: ::c_long = 94; -pub const SYS_fsync: ::c_long = 95; -pub const SYS_setpriority: ::c_long = 96; -pub const SYS_socket: ::c_long = 97; -pub const SYS_connect: ::c_long = 98; -pub const SYS_accept: ::c_long = 99; -pub const SYS_getpriority: ::c_long = 100; -pub const SYS_rt_sigreturn: ::c_long = 101; -pub const SYS_rt_sigaction: ::c_long = 102; -pub const SYS_rt_sigprocmask: ::c_long = 103; -pub const SYS_rt_sigpending: ::c_long = 104; -pub const SYS_rt_sigtimedwait: ::c_long = 105; -pub const SYS_rt_sigqueueinfo: ::c_long = 106; -pub const SYS_rt_sigsuspend: ::c_long = 107; -pub const SYS_setresuid32: ::c_long = 108; -pub const SYS_getresuid32: ::c_long = 109; -pub const SYS_setresgid32: ::c_long = 110; -pub const SYS_getresgid32: ::c_long = 111; -pub const SYS_setregid32: ::c_long = 112; -pub const SYS_recvmsg: ::c_long = 113; -pub const SYS_sendmsg: ::c_long = 114; -pub const SYS_getgroups32: ::c_long = 115; -pub const SYS_gettimeofday: ::c_long = 116; -pub const SYS_getrusage: ::c_long = 117; -pub const SYS_getsockopt: ::c_long = 118; -pub const SYS_getcwd: ::c_long = 119; -pub const SYS_readv: ::c_long = 120; -pub const SYS_writev: ::c_long = 121; -pub const SYS_settimeofday: ::c_long = 122; -pub const SYS_fchown: ::c_long = 123; -pub const SYS_fchmod: ::c_long = 124; -pub const SYS_recvfrom: ::c_long = 125; -pub const SYS_setreuid: ::c_long = 126; -pub const SYS_setregid: ::c_long = 127; -pub const SYS_rename: ::c_long = 128; -pub const SYS_truncate: ::c_long = 129; -pub const SYS_ftruncate: ::c_long = 130; -pub const SYS_flock: ::c_long = 131; -pub const SYS_lstat64: ::c_long = 132; -pub const SYS_sendto: ::c_long = 133; -pub const SYS_shutdown: ::c_long = 134; -pub const SYS_socketpair: ::c_long = 135; -pub const SYS_mkdir: ::c_long = 136; -pub const SYS_rmdir: ::c_long = 137; -pub const SYS_utimes: ::c_long = 138; -pub const SYS_stat64: ::c_long = 139; -pub const SYS_sendfile64: ::c_long = 140; -pub const SYS_getpeername: ::c_long = 141; -pub const SYS_futex: ::c_long = 142; -pub const SYS_gettid: ::c_long = 143; -pub const SYS_getrlimit: ::c_long = 144; -pub const SYS_setrlimit: ::c_long = 145; -pub const SYS_pivot_root: ::c_long = 146; -pub const SYS_prctl: ::c_long = 147; -pub const SYS_pciconfig_read: ::c_long = 148; -pub const SYS_pciconfig_write: ::c_long = 149; -pub const SYS_getsockname: ::c_long = 150; -pub const SYS_inotify_init: ::c_long = 151; -pub const SYS_inotify_add_watch: ::c_long = 152; -pub const SYS_poll: ::c_long = 153; -pub const SYS_getdents64: ::c_long = 154; -pub const SYS_fcntl64: ::c_long = 155; -pub const SYS_inotify_rm_watch: ::c_long = 156; -pub const SYS_statfs: ::c_long = 157; -pub const SYS_fstatfs: ::c_long = 158; -pub const SYS_umount: ::c_long = 159; -pub const SYS_sched_set_affinity: ::c_long = 160; -pub const SYS_sched_get_affinity: ::c_long = 161; -pub const SYS_getdomainname: ::c_long = 162; -pub const SYS_setdomainname: ::c_long = 163; -pub const SYS_quotactl: ::c_long = 165; -pub const SYS_set_tid_address: ::c_long = 166; -pub const SYS_mount: ::c_long = 167; -pub const SYS_ustat: ::c_long = 168; -pub const SYS_setxattr: ::c_long = 169; -pub const SYS_lsetxattr: ::c_long = 170; -pub const SYS_fsetxattr: ::c_long = 171; -pub const SYS_getxattr: ::c_long = 172; -pub const SYS_lgetxattr: ::c_long = 173; -pub const SYS_getdents: ::c_long = 174; -pub const SYS_setsid: ::c_long = 175; -pub const SYS_fchdir: ::c_long = 176; -pub const SYS_fgetxattr: ::c_long = 177; -pub const SYS_listxattr: ::c_long = 178; -pub const SYS_llistxattr: ::c_long = 179; -pub const SYS_flistxattr: ::c_long = 180; -pub const SYS_removexattr: ::c_long = 181; -pub const SYS_lremovexattr: ::c_long = 182; -pub const SYS_sigpending: ::c_long = 183; -pub const SYS_query_module: ::c_long = 184; -pub const SYS_setpgid: ::c_long = 185; -pub const SYS_fremovexattr: ::c_long = 186; -pub const SYS_tkill: ::c_long = 187; -pub const SYS_exit_group: ::c_long = 188; -pub const SYS_uname: ::c_long = 189; -pub const SYS_init_module: ::c_long = 190; -pub const SYS_personality: ::c_long = 191; -pub const SYS_remap_file_pages: ::c_long = 192; -pub const SYS_epoll_create: ::c_long = 193; -pub const SYS_epoll_ctl: ::c_long = 194; -pub const SYS_epoll_wait: ::c_long = 195; -pub const SYS_ioprio_set: ::c_long = 196; -pub const SYS_getppid: ::c_long = 197; -pub const SYS_sigaction: ::c_long = 198; -pub const SYS_sgetmask: ::c_long = 199; -pub const SYS_ssetmask: ::c_long = 200; -pub const SYS_sigsuspend: ::c_long = 201; -pub const SYS_oldlstat: ::c_long = 202; -pub const SYS_uselib: ::c_long = 203; -pub const SYS_readdir: ::c_long = 204; -pub const SYS_readahead: ::c_long = 205; -pub const SYS_socketcall: ::c_long = 206; -pub const SYS_syslog: ::c_long = 207; -pub const SYS_lookup_dcookie: ::c_long = 208; -pub const SYS_fadvise64: ::c_long = 209; -pub const SYS_fadvise64_64: ::c_long = 210; -pub const SYS_tgkill: ::c_long = 211; -pub const SYS_waitpid: ::c_long = 212; -pub const SYS_swapoff: ::c_long = 213; -pub const SYS_sysinfo: ::c_long = 214; -pub const SYS_ipc: ::c_long = 215; -pub const SYS_sigreturn: ::c_long = 216; -pub const SYS_clone: ::c_long = 217; -pub const SYS_ioprio_get: ::c_long = 218; -pub const SYS_adjtimex: ::c_long = 219; -pub const SYS_sigprocmask: ::c_long = 220; -pub const SYS_create_module: ::c_long = 221; -pub const SYS_delete_module: ::c_long = 222; -pub const SYS_get_kernel_syms: ::c_long = 223; -pub const SYS_getpgid: ::c_long = 224; -pub const SYS_bdflush: ::c_long = 225; -pub const SYS_sysfs: ::c_long = 226; -pub const SYS_afs_syscall: ::c_long = 227; -pub const SYS_setfsuid: ::c_long = 228; -pub const SYS_setfsgid: ::c_long = 229; -pub const SYS__newselect: ::c_long = 230; -pub const SYS_time: ::c_long = 231; -pub const SYS_splice: ::c_long = 232; -pub const SYS_stime: ::c_long = 233; -pub const SYS_statfs64: ::c_long = 234; -pub const SYS_fstatfs64: ::c_long = 235; -pub const SYS__llseek: ::c_long = 236; -pub const SYS_mlock: ::c_long = 237; -pub const SYS_munlock: ::c_long = 238; -pub const SYS_mlockall: ::c_long = 239; -pub const SYS_munlockall: ::c_long = 240; -pub const SYS_sched_setparam: ::c_long = 241; -pub const SYS_sched_getparam: ::c_long = 242; -pub const SYS_sched_setscheduler: ::c_long = 243; -pub const SYS_sched_getscheduler: ::c_long = 244; -pub const SYS_sched_yield: ::c_long = 245; -pub const SYS_sched_get_priority_max: ::c_long = 246; -pub const SYS_sched_get_priority_min: ::c_long = 247; -pub const SYS_sched_rr_get_interval: ::c_long = 248; -pub const SYS_nanosleep: ::c_long = 249; -pub const SYS_mremap: ::c_long = 250; -pub const SYS__sysctl: ::c_long = 251; -pub const SYS_getsid: ::c_long = 252; -pub const SYS_fdatasync: ::c_long = 253; -pub const SYS_nfsservctl: ::c_long = 254; -pub const SYS_sync_file_range: ::c_long = 255; -pub const SYS_clock_settime: ::c_long = 256; -pub const SYS_clock_gettime: ::c_long = 257; -pub const SYS_clock_getres: ::c_long = 258; -pub const SYS_clock_nanosleep: ::c_long = 259; -pub const SYS_sched_getaffinity: ::c_long = 260; -pub const SYS_sched_setaffinity: ::c_long = 261; -pub const SYS_timer_settime: ::c_long = 262; -pub const SYS_timer_gettime: ::c_long = 263; -pub const SYS_timer_getoverrun: ::c_long = 264; -pub const SYS_timer_delete: ::c_long = 265; -pub const SYS_timer_create: ::c_long = 266; -pub const SYS_io_setup: ::c_long = 268; -pub const SYS_io_destroy: ::c_long = 269; -pub const SYS_io_submit: ::c_long = 270; -pub const SYS_io_cancel: ::c_long = 271; -pub const SYS_io_getevents: ::c_long = 272; -pub const SYS_mq_open: ::c_long = 273; -pub const SYS_mq_unlink: ::c_long = 274; -pub const SYS_mq_timedsend: ::c_long = 275; -pub const SYS_mq_timedreceive: ::c_long = 276; -pub const SYS_mq_notify: ::c_long = 277; -pub const SYS_mq_getsetattr: ::c_long = 278; -pub const SYS_waitid: ::c_long = 279; -pub const SYS_tee: ::c_long = 280; -pub const SYS_add_key: ::c_long = 281; -pub const SYS_request_key: ::c_long = 282; -pub const SYS_keyctl: ::c_long = 283; -pub const SYS_openat: ::c_long = 284; -pub const SYS_mkdirat: ::c_long = 285; -pub const SYS_mknodat: ::c_long = 286; -pub const SYS_fchownat: ::c_long = 287; -pub const SYS_futimesat: ::c_long = 288; -pub const SYS_fstatat64: ::c_long = 289; -pub const SYS_unlinkat: ::c_long = 290; -pub const SYS_renameat: ::c_long = 291; -pub const SYS_linkat: ::c_long = 292; -pub const SYS_symlinkat: ::c_long = 293; -pub const SYS_readlinkat: ::c_long = 294; -pub const SYS_fchmodat: ::c_long = 295; -pub const SYS_faccessat: ::c_long = 296; -pub const SYS_pselect6: ::c_long = 297; -pub const SYS_ppoll: ::c_long = 298; -pub const SYS_unshare: ::c_long = 299; -pub const SYS_set_robust_list: ::c_long = 300; -pub const SYS_get_robust_list: ::c_long = 301; -pub const SYS_migrate_pages: ::c_long = 302; -pub const SYS_mbind: ::c_long = 303; -pub const SYS_get_mempolicy: ::c_long = 304; -pub const SYS_set_mempolicy: ::c_long = 305; -pub const SYS_kexec_load: ::c_long = 306; -pub const SYS_move_pages: ::c_long = 307; -pub const SYS_getcpu: ::c_long = 308; -pub const SYS_epoll_pwait: ::c_long = 309; -pub const SYS_utimensat: ::c_long = 310; -pub const SYS_signalfd: ::c_long = 311; -pub const SYS_timerfd_create: ::c_long = 312; -pub const SYS_eventfd: ::c_long = 313; -pub const SYS_fallocate: ::c_long = 314; -pub const SYS_timerfd_settime: ::c_long = 315; -pub const SYS_timerfd_gettime: ::c_long = 316; -pub const SYS_signalfd4: ::c_long = 317; -pub const SYS_eventfd2: ::c_long = 318; -pub const SYS_epoll_create1: ::c_long = 319; -pub const SYS_dup3: ::c_long = 320; -pub const SYS_pipe2: ::c_long = 321; -pub const SYS_inotify_init1: ::c_long = 322; -pub const SYS_accept4: ::c_long = 323; -pub const SYS_preadv: ::c_long = 324; -pub const SYS_pwritev: ::c_long = 325; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 326; -pub const SYS_perf_event_open: ::c_long = 327; -pub const SYS_recvmmsg: ::c_long = 328; -pub const SYS_fanotify_init: ::c_long = 329; -pub const SYS_fanotify_mark: ::c_long = 330; -pub const SYS_prlimit64: ::c_long = 331; -pub const SYS_name_to_handle_at: ::c_long = 332; -pub const SYS_open_by_handle_at: ::c_long = 333; -pub const SYS_clock_adjtime: ::c_long = 334; -pub const SYS_syncfs: ::c_long = 335; -pub const SYS_sendmmsg: ::c_long = 336; -pub const SYS_setns: ::c_long = 337; -pub const SYS_process_vm_readv: ::c_long = 338; -pub const SYS_process_vm_writev: ::c_long = 339; -pub const SYS_kern_features: ::c_long = 340; -pub const SYS_kcmp: ::c_long = 341; -pub const SYS_finit_module: ::c_long = 342; -pub const SYS_sched_setattr: ::c_long = 343; -pub const SYS_sched_getattr: ::c_long = 344; -pub const SYS_renameat2: ::c_long = 345; -pub const SYS_seccomp: ::c_long = 346; -pub const SYS_getrandom: ::c_long = 347; -pub const SYS_memfd_create: ::c_long = 348; -pub const SYS_bpf: ::c_long = 349; -pub const SYS_execveat: ::c_long = 350; -pub const SYS_membarrier: ::c_long = 351; -pub const SYS_userfaultfd: ::c_long = 352; -pub const SYS_bind: ::c_long = 353; -pub const SYS_listen: ::c_long = 354; -pub const SYS_setsockopt: ::c_long = 355; -pub const SYS_mlock2: ::c_long = 356; -pub const SYS_copy_file_range: ::c_long = 357; -pub const SYS_preadv2: ::c_long = 358; -pub const SYS_pwritev2: ::c_long = 359; -pub const SYS_statx: ::c_long = 360; - -#[link(name = "util")] -extern "C" { - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/x86/align.rs b/libc/src/unix/linux_like/linux/gnu/b32/x86/align.rs deleted file mode 100644 index 9663474..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/x86/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 6] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b32/x86/mod.rs b/libc/src/unix/linux_like/linux/gnu/b32/x86/mod.rs deleted file mode 100644 index f5f7cac..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b32/x86/mod.rs +++ /dev/null @@ -1,1164 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; -pub type greg_t = i32; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statfs { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - f_spare: [::__fsword_t; 5], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct _libc_fpreg { - pub significand: [u16; 4], - pub exponent: u16, - } - - pub struct _libc_fpstate { - pub cw: ::c_ulong, - pub sw: ::c_ulong, - pub tag: ::c_ulong, - pub ipoff: ::c_ulong, - pub cssel: ::c_ulong, - pub dataoff: ::c_ulong, - pub datasel: ::c_ulong, - pub _st: [_libc_fpreg; 8], - pub status: ::c_ulong, - } - - pub struct user_fpregs_struct { - pub cwd: ::c_long, - pub swd: ::c_long, - pub twd: ::c_long, - pub fip: ::c_long, - pub fcs: ::c_long, - pub foo: ::c_long, - pub fos: ::c_long, - pub st_space: [::c_long; 20], - } - - pub struct user_regs_struct { - pub ebx: ::c_long, - pub ecx: ::c_long, - pub edx: ::c_long, - pub esi: ::c_long, - pub edi: ::c_long, - pub ebp: ::c_long, - pub eax: ::c_long, - pub xds: ::c_long, - pub xes: ::c_long, - pub xfs: ::c_long, - pub xgs: ::c_long, - pub orig_eax: ::c_long, - pub eip: ::c_long, - pub xcs: ::c_long, - pub eflags: ::c_long, - pub esp: ::c_long, - pub xss: ::c_long, - } - - pub struct user { - pub regs: user_regs_struct, - pub u_fpvalid: ::c_int, - pub i387: user_fpregs_struct, - pub u_tsize: ::c_ulong, - pub u_dsize: ::c_ulong, - pub u_ssize: ::c_ulong, - pub start_code: ::c_ulong, - pub start_stack: ::c_ulong, - pub signal: ::c_long, - __reserved: ::c_int, - pub u_ar0: *mut user_regs_struct, - pub u_fpstate: *mut user_fpregs_struct, - pub magic: ::c_ulong, - pub u_comm: [c_char; 32], - pub u_debugreg: [::c_int; 8], - } - - pub struct mcontext_t { - pub gregs: [greg_t; 19], - pub fpregs: *mut _libc_fpstate, - pub oldmask: ::c_ulong, - pub cr2: ::c_ulong, - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_ushort, - __pad1: ::c_ushort, - pub __seq: ::c_ushort, - __pad2: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __pad1: ::c_uint, - __st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: ::c_uint, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino64_t, - } - - pub struct statfs64 { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - pub f_flags: ::__fsword_t, - pub f_spare: [::__fsword_t; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - __unused1: ::c_ulong, - pub shm_dtime: ::time_t, - __unused2: ::c_ulong, - pub shm_ctime: ::time_t, - __unused3: ::c_ulong, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - __glibc_reserved1: ::c_ulong, - pub msg_rtime: ::time_t, - __glibc_reserved2: ::c_ulong, - pub msg_ctime: ::time_t, - __glibc_reserved3: ::c_ulong, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __glibc_reserved4: ::c_ulong, - __glibc_reserved5: ::c_ulong, - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since="0.2.54", - note="Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } -} - -s_no_extra_traits! { - pub struct user_fpxregs_struct { - pub cwd: ::c_ushort, - pub swd: ::c_ushort, - pub twd: ::c_ushort, - pub fop: ::c_ushort, - pub fip: ::c_long, - pub fcs: ::c_long, - pub foo: ::c_long, - pub fos: ::c_long, - pub mxcsr: ::c_long, - __reserved: ::c_long, - pub st_space: [::c_long; 32], - pub xmm_space: [::c_long; 32], - padding: [::c_long; 56], - } - - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 112], - __ssp: [::c_ulong; 4], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for user_fpxregs_struct { - fn eq(&self, other: &user_fpxregs_struct) -> bool { - self.cwd == other.cwd - && self.swd == other.swd - && self.twd == other.twd - && self.fop == other.fop - && self.fip == other.fip - && self.fcs == other.fcs - && self.foo == other.foo - && self.fos == other.fos - && self.mxcsr == other.mxcsr - // Ignore __reserved field - && self.st_space == other.st_space - && self.xmm_space == other.xmm_space - // Ignore padding field - } - } - - impl Eq for user_fpxregs_struct {} - - impl ::fmt::Debug for user_fpxregs_struct { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("user_fpxregs_struct") - .field("cwd", &self.cwd) - .field("swd", &self.swd) - .field("twd", &self.twd) - .field("fop", &self.fop) - .field("fip", &self.fip) - .field("fcs", &self.fcs) - .field("foo", &self.foo) - .field("fos", &self.fos) - .field("mxcsr", &self.mxcsr) - // Ignore __reserved field - .field("st_space", &self.st_space) - .field("xmm_space", &self.xmm_space) - // Ignore padding field - .finish() - } - } - - impl ::hash::Hash for user_fpxregs_struct { - fn hash(&self, state: &mut H) { - self.cwd.hash(state); - self.swd.hash(state); - self.twd.hash(state); - self.fop.hash(state); - self.fip.hash(state); - self.fcs.hash(state); - self.foo.hash(state); - self.fos.hash(state); - self.mxcsr.hash(state); - // Ignore __reserved field - self.st_space.hash(state); - self.xmm_space.hash(state); - // Ignore padding field - } - } - - impl PartialEq for ucontext_t { - fn eq(&self, other: &ucontext_t) -> bool { - self.uc_flags == other.uc_flags - && self.uc_link == other.uc_link - && self.uc_stack == other.uc_stack - && self.uc_mcontext == other.uc_mcontext - && self.uc_sigmask == other.uc_sigmask - // Ignore __private field - } - } - - impl Eq for ucontext_t {} - - impl ::fmt::Debug for ucontext_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("ucontext_t") - .field("uc_flags", &self.uc_flags) - .field("uc_link", &self.uc_link) - .field("uc_stack", &self.uc_stack) - .field("uc_mcontext", &self.uc_mcontext) - .field("uc_sigmask", &self.uc_sigmask) - // Ignore __private field - .finish() - } - } - - impl ::hash::Hash for ucontext_t { - fn hash(&self, state: &mut H) { - self.uc_flags.hash(state); - self.uc_link.hash(state); - self.uc_stack.hash(state); - self.uc_mcontext.hash(state); - self.uc_sigmask.hash(state); - // Ignore __private field - } - } - } -} - -pub const RLIM_INFINITY: ::rlim_t = !0; -pub const VEOF: usize = 4; -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const O_DIRECT: ::c_int = 0x4000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; -pub const O_LARGEFILE: ::c_int = 0o0100000; -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_FSYNC: ::c_int = 0x101000; -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_NDELAY: ::c_int = 0x800; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 6; -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_32BIT: ::c_int = 0x0040; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; - -pub const EDEADLOCK: ::c_int = 35; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EBADMSG: ::c_int = 74; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const EHWPOISON: ::c_int = 133; -pub const ERFKILL: ::c_int = 132; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_LINGER: ::c_int = 13; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; - -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; - -pub const FIOCLEX: ::c_ulong = 0x5451; -pub const FIONCLEX: ::c_ulong = 0x5450; -pub const FIONBIO: ::c_ulong = 0x5421; - -pub const PTRACE_GETFPXREGS: ::c_uint = 18; -pub const PTRACE_SETFPXREGS: ::c_uint = 19; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const EFD_NONBLOCK: ::c_int = 0x800; -pub const SFD_NONBLOCK: ::c_int = 0x0800; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = 31; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; -pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; -pub const TIOCEXCL: ::c_ulong = 0x540C; -pub const TIOCNXCL: ::c_ulong = 0x540D; -pub const TIOCSCTTY: ::c_ulong = 0x540E; -pub const TIOCSTI: ::c_ulong = 0x5412; -pub const TIOCMGET: ::c_ulong = 0x5415; -pub const TIOCMBIS: ::c_ulong = 0x5416; -pub const TIOCMBIC: ::c_ulong = 0x5417; -pub const TIOCMSET: ::c_ulong = 0x5418; -pub const TIOCCONS: ::c_ulong = 0x541D; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; -pub const EXTPROC: ::tcflag_t = 0x00010000; -pub const TCGETS: ::c_ulong = 0x5401; -pub const TCSETS: ::c_ulong = 0x5402; -pub const TCSETSW: ::c_ulong = 0x5403; -pub const TCSETSF: ::c_ulong = 0x5404; -pub const TCGETA: ::c_ulong = 0x5405; -pub const TCSETA: ::c_ulong = 0x5406; -pub const TCSETAW: ::c_ulong = 0x5407; -pub const TCSETAF: ::c_ulong = 0x5408; -pub const TCSBRK: ::c_ulong = 0x5409; -pub const TCXONC: ::c_ulong = 0x540A; -pub const TCFLSH: ::c_ulong = 0x540B; -pub const TIOCINQ: ::c_ulong = 0x541B; -pub const TIOCGPGRP: ::c_ulong = 0x540F; -pub const TIOCSPGRP: ::c_ulong = 0x5410; -pub const TIOCOUTQ: ::c_ulong = 0x5411; -pub const TIOCGWINSZ: ::c_ulong = 0x5413; -pub const TIOCSWINSZ: ::c_ulong = 0x5414; -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; -pub const FIONREAD: ::c_ulong = 0x541B; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -// Syscall table -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_waitpid: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_time: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_break: ::c_long = 17; -pub const SYS_oldstat: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_umount: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_stime: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_oldfstat: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_stty: ::c_long = 31; -pub const SYS_gtty: ::c_long = 32; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_ftime: ::c_long = 35; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_prof: ::c_long = 44; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_lock: ::c_long = 53; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_mpx: ::c_long = 56; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_ulimit: ::c_long = 58; -pub const SYS_oldolduname: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_sgetmask: ::c_long = 68; -pub const SYS_ssetmask: ::c_long = 69; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrlimit: ::c_long = 76; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_select: ::c_long = 82; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_oldlstat: ::c_long = 84; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_readdir: ::c_long = 89; -pub const SYS_mmap: ::c_long = 90; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_profil: ::c_long = 98; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_ioperm: ::c_long = 101; -pub const SYS_socketcall: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_olduname: ::c_long = 109; -pub const SYS_iopl: ::c_long = 110; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_idle: ::c_long = 112; -pub const SYS_vm86old: ::c_long = 113; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_ipc: ::c_long = 117; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_modify_ldt: ::c_long = 123; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_create_module: ::c_long = 127; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_get_kernel_syms: ::c_long = 130; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_afs_syscall: ::c_long = 137; -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_vm86: ::c_long = 166; -pub const SYS_query_module: ::c_long = 167; -pub const SYS_poll: ::c_long = 168; -pub const SYS_nfsservctl: ::c_long = 169; -pub const SYS_setresgid: ::c_long = 170; -pub const SYS_getresgid: ::c_long = 171; -pub const SYS_prctl: ::c_long = 172; -pub const SYS_rt_sigreturn: ::c_long = 173; -pub const SYS_rt_sigaction: ::c_long = 174; -pub const SYS_rt_sigprocmask: ::c_long = 175; -pub const SYS_rt_sigpending: ::c_long = 176; -pub const SYS_rt_sigtimedwait: ::c_long = 177; -pub const SYS_rt_sigqueueinfo: ::c_long = 178; -pub const SYS_rt_sigsuspend: ::c_long = 179; -pub const SYS_pread64: ::c_long = 180; -pub const SYS_pwrite64: ::c_long = 181; -pub const SYS_chown: ::c_long = 182; -pub const SYS_getcwd: ::c_long = 183; -pub const SYS_capget: ::c_long = 184; -pub const SYS_capset: ::c_long = 185; -pub const SYS_sigaltstack: ::c_long = 186; -pub const SYS_sendfile: ::c_long = 187; -pub const SYS_getpmsg: ::c_long = 188; -pub const SYS_putpmsg: ::c_long = 189; -pub const SYS_vfork: ::c_long = 190; -pub const SYS_ugetrlimit: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_lchown32: ::c_long = 198; -pub const SYS_getuid32: ::c_long = 199; -pub const SYS_getgid32: ::c_long = 200; -pub const SYS_geteuid32: ::c_long = 201; -pub const SYS_getegid32: ::c_long = 202; -pub const SYS_setreuid32: ::c_long = 203; -pub const SYS_setregid32: ::c_long = 204; -pub const SYS_getgroups32: ::c_long = 205; -pub const SYS_setgroups32: ::c_long = 206; -pub const SYS_fchown32: ::c_long = 207; -pub const SYS_setresuid32: ::c_long = 208; -pub const SYS_getresuid32: ::c_long = 209; -pub const SYS_setresgid32: ::c_long = 210; -pub const SYS_getresgid32: ::c_long = 211; -pub const SYS_chown32: ::c_long = 212; -pub const SYS_setuid32: ::c_long = 213; -pub const SYS_setgid32: ::c_long = 214; -pub const SYS_setfsuid32: ::c_long = 215; -pub const SYS_setfsgid32: ::c_long = 216; -pub const SYS_pivot_root: ::c_long = 217; -pub const SYS_mincore: ::c_long = 218; -pub const SYS_madvise: ::c_long = 219; -pub const SYS_getdents64: ::c_long = 220; -pub const SYS_fcntl64: ::c_long = 221; -pub const SYS_gettid: ::c_long = 224; -pub const SYS_readahead: ::c_long = 225; -pub const SYS_setxattr: ::c_long = 226; -pub const SYS_lsetxattr: ::c_long = 227; -pub const SYS_fsetxattr: ::c_long = 228; -pub const SYS_getxattr: ::c_long = 229; -pub const SYS_lgetxattr: ::c_long = 230; -pub const SYS_fgetxattr: ::c_long = 231; -pub const SYS_listxattr: ::c_long = 232; -pub const SYS_llistxattr: ::c_long = 233; -pub const SYS_flistxattr: ::c_long = 234; -pub const SYS_removexattr: ::c_long = 235; -pub const SYS_lremovexattr: ::c_long = 236; -pub const SYS_fremovexattr: ::c_long = 237; -pub const SYS_tkill: ::c_long = 238; -pub const SYS_sendfile64: ::c_long = 239; -pub const SYS_futex: ::c_long = 240; -pub const SYS_sched_setaffinity: ::c_long = 241; -pub const SYS_sched_getaffinity: ::c_long = 242; -pub const SYS_set_thread_area: ::c_long = 243; -pub const SYS_get_thread_area: ::c_long = 244; -pub const SYS_io_setup: ::c_long = 245; -pub const SYS_io_destroy: ::c_long = 246; -pub const SYS_io_getevents: ::c_long = 247; -pub const SYS_io_submit: ::c_long = 248; -pub const SYS_io_cancel: ::c_long = 249; -pub const SYS_fadvise64: ::c_long = 250; -pub const SYS_exit_group: ::c_long = 252; -pub const SYS_lookup_dcookie: ::c_long = 253; -pub const SYS_epoll_create: ::c_long = 254; -pub const SYS_epoll_ctl: ::c_long = 255; -pub const SYS_epoll_wait: ::c_long = 256; -pub const SYS_remap_file_pages: ::c_long = 257; -pub const SYS_set_tid_address: ::c_long = 258; -pub const SYS_timer_create: ::c_long = 259; -pub const SYS_timer_settime: ::c_long = 260; -pub const SYS_timer_gettime: ::c_long = 261; -pub const SYS_timer_getoverrun: ::c_long = 262; -pub const SYS_timer_delete: ::c_long = 263; -pub const SYS_clock_settime: ::c_long = 264; -pub const SYS_clock_gettime: ::c_long = 265; -pub const SYS_clock_getres: ::c_long = 266; -pub const SYS_clock_nanosleep: ::c_long = 267; -pub const SYS_statfs64: ::c_long = 268; -pub const SYS_fstatfs64: ::c_long = 269; -pub const SYS_tgkill: ::c_long = 270; -pub const SYS_utimes: ::c_long = 271; -pub const SYS_fadvise64_64: ::c_long = 272; -pub const SYS_vserver: ::c_long = 273; -pub const SYS_mbind: ::c_long = 274; -pub const SYS_get_mempolicy: ::c_long = 275; -pub const SYS_set_mempolicy: ::c_long = 276; -pub const SYS_mq_open: ::c_long = 277; -pub const SYS_mq_unlink: ::c_long = 278; -pub const SYS_mq_timedsend: ::c_long = 279; -pub const SYS_mq_timedreceive: ::c_long = 280; -pub const SYS_mq_notify: ::c_long = 281; -pub const SYS_mq_getsetattr: ::c_long = 282; -pub const SYS_kexec_load: ::c_long = 283; -pub const SYS_waitid: ::c_long = 284; -pub const SYS_add_key: ::c_long = 286; -pub const SYS_request_key: ::c_long = 287; -pub const SYS_keyctl: ::c_long = 288; -pub const SYS_ioprio_set: ::c_long = 289; -pub const SYS_ioprio_get: ::c_long = 290; -pub const SYS_inotify_init: ::c_long = 291; -pub const SYS_inotify_add_watch: ::c_long = 292; -pub const SYS_inotify_rm_watch: ::c_long = 293; -pub const SYS_migrate_pages: ::c_long = 294; -pub const SYS_openat: ::c_long = 295; -pub const SYS_mkdirat: ::c_long = 296; -pub const SYS_mknodat: ::c_long = 297; -pub const SYS_fchownat: ::c_long = 298; -pub const SYS_futimesat: ::c_long = 299; -pub const SYS_fstatat64: ::c_long = 300; -pub const SYS_unlinkat: ::c_long = 301; -pub const SYS_renameat: ::c_long = 302; -pub const SYS_linkat: ::c_long = 303; -pub const SYS_symlinkat: ::c_long = 304; -pub const SYS_readlinkat: ::c_long = 305; -pub const SYS_fchmodat: ::c_long = 306; -pub const SYS_faccessat: ::c_long = 307; -pub const SYS_pselect6: ::c_long = 308; -pub const SYS_ppoll: ::c_long = 309; -pub const SYS_unshare: ::c_long = 310; -pub const SYS_set_robust_list: ::c_long = 311; -pub const SYS_get_robust_list: ::c_long = 312; -pub const SYS_splice: ::c_long = 313; -pub const SYS_sync_file_range: ::c_long = 314; -pub const SYS_tee: ::c_long = 315; -pub const SYS_vmsplice: ::c_long = 316; -pub const SYS_move_pages: ::c_long = 317; -pub const SYS_getcpu: ::c_long = 318; -pub const SYS_epoll_pwait: ::c_long = 319; -pub const SYS_utimensat: ::c_long = 320; -pub const SYS_signalfd: ::c_long = 321; -pub const SYS_timerfd_create: ::c_long = 322; -pub const SYS_eventfd: ::c_long = 323; -pub const SYS_fallocate: ::c_long = 324; -pub const SYS_timerfd_settime: ::c_long = 325; -pub const SYS_timerfd_gettime: ::c_long = 326; -pub const SYS_signalfd4: ::c_long = 327; -pub const SYS_eventfd2: ::c_long = 328; -pub const SYS_epoll_create1: ::c_long = 329; -pub const SYS_dup3: ::c_long = 330; -pub const SYS_pipe2: ::c_long = 331; -pub const SYS_inotify_init1: ::c_long = 332; -pub const SYS_preadv: ::c_long = 333; -pub const SYS_pwritev: ::c_long = 334; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 335; -pub const SYS_perf_event_open: ::c_long = 336; -pub const SYS_recvmmsg: ::c_long = 337; -pub const SYS_fanotify_init: ::c_long = 338; -pub const SYS_fanotify_mark: ::c_long = 339; -pub const SYS_prlimit64: ::c_long = 340; -pub const SYS_name_to_handle_at: ::c_long = 341; -pub const SYS_open_by_handle_at: ::c_long = 342; -pub const SYS_clock_adjtime: ::c_long = 343; -pub const SYS_syncfs: ::c_long = 344; -pub const SYS_sendmmsg: ::c_long = 345; -pub const SYS_setns: ::c_long = 346; -pub const SYS_process_vm_readv: ::c_long = 347; -pub const SYS_process_vm_writev: ::c_long = 348; -pub const SYS_kcmp: ::c_long = 349; -pub const SYS_finit_module: ::c_long = 350; -pub const SYS_sched_setattr: ::c_long = 351; -pub const SYS_sched_getattr: ::c_long = 352; -pub const SYS_renameat2: ::c_long = 353; -pub const SYS_seccomp: ::c_long = 354; -pub const SYS_getrandom: ::c_long = 355; -pub const SYS_memfd_create: ::c_long = 356; -pub const SYS_bpf: ::c_long = 357; -pub const SYS_execveat: ::c_long = 358; -pub const SYS_socket: ::c_long = 359; -pub const SYS_socketpair: ::c_long = 360; -pub const SYS_bind: ::c_long = 361; -pub const SYS_connect: ::c_long = 362; -pub const SYS_listen: ::c_long = 363; -pub const SYS_accept4: ::c_long = 364; -pub const SYS_getsockopt: ::c_long = 365; -pub const SYS_setsockopt: ::c_long = 366; -pub const SYS_getsockname: ::c_long = 367; -pub const SYS_getpeername: ::c_long = 368; -pub const SYS_sendto: ::c_long = 369; -pub const SYS_sendmsg: ::c_long = 370; -pub const SYS_recvfrom: ::c_long = 371; -pub const SYS_recvmsg: ::c_long = 372; -pub const SYS_shutdown: ::c_long = 373; -pub const SYS_userfaultfd: ::c_long = 374; -pub const SYS_membarrier: ::c_long = 375; -pub const SYS_mlock2: ::c_long = 376; -pub const SYS_copy_file_range: ::c_long = 377; -pub const SYS_preadv2: ::c_long = 378; -pub const SYS_pwritev2: ::c_long = 379; -pub const SYS_pkey_mprotect: ::c_long = 380; -pub const SYS_pkey_alloc: ::c_long = 381; -pub const SYS_pkey_free: ::c_long = 382; -pub const SYS_statx: ::c_long = 383; - -// offsets in user_regs_structs, from sys/reg.h -pub const EBX: ::c_int = 0; -pub const ECX: ::c_int = 1; -pub const EDX: ::c_int = 2; -pub const ESI: ::c_int = 3; -pub const EDI: ::c_int = 4; -pub const EBP: ::c_int = 5; -pub const EAX: ::c_int = 6; -pub const DS: ::c_int = 7; -pub const ES: ::c_int = 8; -pub const FS: ::c_int = 9; -pub const GS: ::c_int = 10; -pub const ORIG_EAX: ::c_int = 11; -pub const EIP: ::c_int = 12; -pub const CS: ::c_int = 13; -pub const EFL: ::c_int = 14; -pub const UESP: ::c_int = 15; -pub const SS: ::c_int = 16; - -// offsets in mcontext_t.gregs from sys/ucontext.h -pub const REG_GS: ::c_int = 0; -pub const REG_FS: ::c_int = 1; -pub const REG_ES: ::c_int = 2; -pub const REG_DS: ::c_int = 3; -pub const REG_EDI: ::c_int = 4; -pub const REG_ESI: ::c_int = 5; -pub const REG_EBP: ::c_int = 6; -pub const REG_ESP: ::c_int = 7; -pub const REG_EBX: ::c_int = 8; -pub const REG_EDX: ::c_int = 9; -pub const REG_ECX: ::c_int = 10; -pub const REG_EAX: ::c_int = 11; -pub const REG_TRAPNO: ::c_int = 12; -pub const REG_ERR: ::c_int = 13; -pub const REG_EIP: ::c_int = 14; -pub const REG_CS: ::c_int = 15; -pub const REG_EFL: ::c_int = 16; -pub const REG_UESP: ::c_int = 17; -pub const REG_SS: ::c_int = 18; - -extern "C" { - pub fn getcontext(ucp: *mut ucontext_t) -> ::c_int; - pub fn setcontext(ucp: *const ucontext_t) -> ::c_int; - pub fn makecontext( - ucp: *mut ucontext_t, - func: extern "C" fn(), - argc: ::c_int, - ... - ); - pub fn swapcontext( - uocp: *mut ucontext_t, - ucp: *const ucontext_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/aarch64/align.rs b/libc/src/unix/linux_like/linux/gnu/b64/aarch64/align.rs deleted file mode 100644 index 8e94996..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/aarch64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f32; 8] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs b/libc/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs deleted file mode 100644 index 93f0f2b..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs +++ /dev/null @@ -1,954 +0,0 @@ -//! AArch64-specific definitions for 64-bit linux-like values - -use pthread_mutex_t; - -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = u8; -pub type wchar_t = u32; -pub type nlink_t = u32; -pub type blksize_t = i32; -pub type suseconds_t = i64; -pub type __u64 = ::c_ulonglong; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - #[cfg(target_arch = "sparc64")] - __reserved0: ::c_int, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statfs { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - f_spare: [::__fsword_t; 5], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad1: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - __pad2: ::c_int, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_int; 2], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad1: ::dev_t, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - __pad2: ::c_int, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_int; 2], - } - - pub struct statfs64 { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - pub f_flags: ::__fsword_t, - pub f_spare: [::__fsword_t; 4], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct pthread_attr_t { - __size: [u64; 8] - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_uint, - pub __seq: ::c_ushort, - __pad1: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since="0.2.54", - note="Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } -} - -pub const VEOF: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; - -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; - -pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; -pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; - -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 6; - -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_FSYNC: ::c_int = 0x101000; -pub const O_NOATIME: ::c_int = 0o1000000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; - -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EBADMSG: ::c_int = 74; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const EHWPOISON: ::c_int = 133; -pub const ERFKILL: ::c_int = 132; - -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_PEERSEC: ::c_int = 31; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; -pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS; -pub const SO_MARK: ::c_int = 36; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_BUSY_POLL: ::c_int = 46; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; -pub const SO_INCOMING_CPU: ::c_int = 49; -pub const SO_ATTACH_BPF: ::c_int = 50; -pub const SO_DETACH_BPF: ::c_int = SO_DETACH_FILTER; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = 31; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_NDELAY: ::c_int = 0x800; - -pub const PTRACE_DETACH: ::c_uint = 17; - -pub const EFD_NONBLOCK: ::c_int = 0x800; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; - -pub const SFD_NONBLOCK: ::c_int = 0x0800; - -pub const TIOCEXCL: ::c_ulong = 0x540C; -pub const TIOCNXCL: ::c_ulong = 0x540D; -pub const TIOCSCTTY: ::c_ulong = 0x540E; -pub const TIOCSTI: ::c_ulong = 0x5412; -pub const TIOCMGET: ::c_ulong = 0x5415; -pub const TIOCMBIS: ::c_ulong = 0x5416; -pub const TIOCMBIC: ::c_ulong = 0x5417; -pub const TIOCMSET: ::c_ulong = 0x5418; -pub const TIOCCONS: ::c_ulong = 0x541D; - -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; - -pub const O_CLOEXEC: ::c_int = 0x80000; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 48; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 8; - -align_const! { - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - ], - }; - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - ], - }; - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - ], - }; -} - -pub const O_DIRECT: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; - -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const EDEADLOCK: ::c_int = 35; - -pub const FIOCLEX: ::c_ulong = 0x5451; -pub const FIONCLEX: ::c_ulong = 0x5450; -pub const FIONBIO: ::c_ulong = 0x5421; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const SIGSTKSZ: ::size_t = 16384; -pub const MINSIGSTKSZ: ::size_t = 5120; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; -pub const EXTPROC: ::tcflag_t = 0x00010000; -pub const TCGETS: ::c_ulong = 0x5401; -pub const TCSETS: ::c_ulong = 0x5402; -pub const TCSETSW: ::c_ulong = 0x5403; -pub const TCSETSF: ::c_ulong = 0x5404; -pub const TCGETA: ::c_ulong = 0x5405; -pub const TCSETA: ::c_ulong = 0x5406; -pub const TCSETAW: ::c_ulong = 0x5407; -pub const TCSETAF: ::c_ulong = 0x5408; -pub const TCSBRK: ::c_ulong = 0x5409; -pub const TCXONC: ::c_ulong = 0x540A; -pub const TCFLSH: ::c_ulong = 0x540B; -pub const TIOCINQ: ::c_ulong = 0x541B; -pub const TIOCGPGRP: ::c_ulong = 0x540F; -pub const TIOCSPGRP: ::c_ulong = 0x5410; -pub const TIOCOUTQ: ::c_ulong = 0x5411; -pub const TIOCGWINSZ: ::c_ulong = 0x5413; -pub const TIOCSWINSZ: ::c_ulong = 0x5414; -pub const FIONREAD: ::c_ulong = 0x541B; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; - -// Syscall table -pub const SYS_io_setup: ::c_long = 0; -pub const SYS_io_destroy: ::c_long = 1; -pub const SYS_io_submit: ::c_long = 2; -pub const SYS_io_cancel: ::c_long = 3; -pub const SYS_io_getevents: ::c_long = 4; -pub const SYS_setxattr: ::c_long = 5; -pub const SYS_lsetxattr: ::c_long = 6; -pub const SYS_fsetxattr: ::c_long = 7; -pub const SYS_getxattr: ::c_long = 8; -pub const SYS_lgetxattr: ::c_long = 9; -pub const SYS_fgetxattr: ::c_long = 10; -pub const SYS_listxattr: ::c_long = 11; -pub const SYS_llistxattr: ::c_long = 12; -pub const SYS_flistxattr: ::c_long = 13; -pub const SYS_removexattr: ::c_long = 14; -pub const SYS_lremovexattr: ::c_long = 15; -pub const SYS_fremovexattr: ::c_long = 16; -pub const SYS_getcwd: ::c_long = 17; -pub const SYS_lookup_dcookie: ::c_long = 18; -pub const SYS_eventfd2: ::c_long = 19; -pub const SYS_epoll_create1: ::c_long = 20; -pub const SYS_epoll_ctl: ::c_long = 21; -pub const SYS_epoll_pwait: ::c_long = 22; -pub const SYS_dup: ::c_long = 23; -pub const SYS_dup3: ::c_long = 24; -pub const SYS_fcntl: ::c_long = 25; -pub const SYS_inotify_init1: ::c_long = 26; -pub const SYS_inotify_add_watch: ::c_long = 27; -pub const SYS_inotify_rm_watch: ::c_long = 28; -pub const SYS_ioctl: ::c_long = 29; -pub const SYS_ioprio_set: ::c_long = 30; -pub const SYS_ioprio_get: ::c_long = 31; -pub const SYS_flock: ::c_long = 32; -pub const SYS_mknodat: ::c_long = 33; -pub const SYS_mkdirat: ::c_long = 34; -pub const SYS_unlinkat: ::c_long = 35; -pub const SYS_symlinkat: ::c_long = 36; -pub const SYS_linkat: ::c_long = 37; -pub const SYS_renameat: ::c_long = 38; -pub const SYS_umount2: ::c_long = 39; -pub const SYS_mount: ::c_long = 40; -pub const SYS_pivot_root: ::c_long = 41; -pub const SYS_nfsservctl: ::c_long = 42; -pub const SYS_fallocate: ::c_long = 47; -pub const SYS_faccessat: ::c_long = 48; -pub const SYS_chdir: ::c_long = 49; -pub const SYS_fchdir: ::c_long = 50; -pub const SYS_chroot: ::c_long = 51; -pub const SYS_fchmod: ::c_long = 52; -pub const SYS_fchmodat: ::c_long = 53; -pub const SYS_fchownat: ::c_long = 54; -pub const SYS_fchown: ::c_long = 55; -pub const SYS_openat: ::c_long = 56; -pub const SYS_close: ::c_long = 57; -pub const SYS_vhangup: ::c_long = 58; -pub const SYS_pipe2: ::c_long = 59; -pub const SYS_quotactl: ::c_long = 60; -pub const SYS_getdents64: ::c_long = 61; -pub const SYS_lseek: ::c_long = 62; -pub const SYS_read: ::c_long = 63; -pub const SYS_write: ::c_long = 64; -pub const SYS_readv: ::c_long = 65; -pub const SYS_writev: ::c_long = 66; -pub const SYS_pread64: ::c_long = 67; -pub const SYS_pwrite64: ::c_long = 68; -pub const SYS_preadv: ::c_long = 69; -pub const SYS_pwritev: ::c_long = 70; -pub const SYS_pselect6: ::c_long = 72; -pub const SYS_ppoll: ::c_long = 73; -pub const SYS_signalfd4: ::c_long = 74; -pub const SYS_vmsplice: ::c_long = 75; -pub const SYS_splice: ::c_long = 76; -pub const SYS_tee: ::c_long = 77; -pub const SYS_readlinkat: ::c_long = 78; -pub const SYS_newfstatat: ::c_long = 79; -pub const SYS_fstat: ::c_long = 80; -pub const SYS_sync: ::c_long = 81; -pub const SYS_fsync: ::c_long = 82; -pub const SYS_fdatasync: ::c_long = 83; -pub const SYS_sync_file_range: ::c_long = 84; -pub const SYS_timerfd_create: ::c_long = 85; -pub const SYS_timerfd_settime: ::c_long = 86; -pub const SYS_timerfd_gettime: ::c_long = 87; -pub const SYS_utimensat: ::c_long = 88; -pub const SYS_acct: ::c_long = 89; -pub const SYS_capget: ::c_long = 90; -pub const SYS_capset: ::c_long = 91; -pub const SYS_personality: ::c_long = 92; -pub const SYS_exit: ::c_long = 93; -pub const SYS_exit_group: ::c_long = 94; -pub const SYS_waitid: ::c_long = 95; -pub const SYS_set_tid_address: ::c_long = 96; -pub const SYS_unshare: ::c_long = 97; -pub const SYS_futex: ::c_long = 98; -pub const SYS_set_robust_list: ::c_long = 99; -pub const SYS_get_robust_list: ::c_long = 100; -pub const SYS_nanosleep: ::c_long = 101; -pub const SYS_getitimer: ::c_long = 102; -pub const SYS_setitimer: ::c_long = 103; -pub const SYS_kexec_load: ::c_long = 104; -pub const SYS_init_module: ::c_long = 105; -pub const SYS_delete_module: ::c_long = 106; -pub const SYS_timer_create: ::c_long = 107; -pub const SYS_timer_gettime: ::c_long = 108; -pub const SYS_timer_getoverrun: ::c_long = 109; -pub const SYS_timer_settime: ::c_long = 110; -pub const SYS_timer_delete: ::c_long = 111; -pub const SYS_clock_settime: ::c_long = 112; -pub const SYS_clock_gettime: ::c_long = 113; -pub const SYS_clock_getres: ::c_long = 114; -pub const SYS_clock_nanosleep: ::c_long = 115; -pub const SYS_syslog: ::c_long = 116; -pub const SYS_ptrace: ::c_long = 117; -pub const SYS_sched_setparam: ::c_long = 118; -pub const SYS_sched_setscheduler: ::c_long = 119; -pub const SYS_sched_getscheduler: ::c_long = 120; -pub const SYS_sched_getparam: ::c_long = 121; -pub const SYS_sched_setaffinity: ::c_long = 122; -pub const SYS_sched_getaffinity: ::c_long = 123; -pub const SYS_sched_yield: ::c_long = 124; -pub const SYS_sched_get_priority_max: ::c_long = 125; -pub const SYS_sched_get_priority_min: ::c_long = 126; -pub const SYS_sched_rr_get_interval: ::c_long = 127; -pub const SYS_restart_syscall: ::c_long = 128; -pub const SYS_kill: ::c_long = 129; -pub const SYS_tkill: ::c_long = 130; -pub const SYS_tgkill: ::c_long = 131; -pub const SYS_sigaltstack: ::c_long = 132; -pub const SYS_rt_sigsuspend: ::c_long = 133; -pub const SYS_rt_sigaction: ::c_long = 134; -pub const SYS_rt_sigprocmask: ::c_long = 135; -pub const SYS_rt_sigpending: ::c_long = 136; -pub const SYS_rt_sigtimedwait: ::c_long = 137; -pub const SYS_rt_sigqueueinfo: ::c_long = 138; -pub const SYS_rt_sigreturn: ::c_long = 139; -pub const SYS_setpriority: ::c_long = 140; -pub const SYS_getpriority: ::c_long = 141; -pub const SYS_reboot: ::c_long = 142; -pub const SYS_setregid: ::c_long = 143; -pub const SYS_setgid: ::c_long = 144; -pub const SYS_setreuid: ::c_long = 145; -pub const SYS_setuid: ::c_long = 146; -pub const SYS_setresuid: ::c_long = 147; -pub const SYS_getresuid: ::c_long = 148; -pub const SYS_setresgid: ::c_long = 149; -pub const SYS_getresgid: ::c_long = 150; -pub const SYS_setfsuid: ::c_long = 151; -pub const SYS_setfsgid: ::c_long = 152; -pub const SYS_times: ::c_long = 153; -pub const SYS_setpgid: ::c_long = 154; -pub const SYS_getpgid: ::c_long = 155; -pub const SYS_getsid: ::c_long = 156; -pub const SYS_setsid: ::c_long = 157; -pub const SYS_getgroups: ::c_long = 158; -pub const SYS_setgroups: ::c_long = 159; -pub const SYS_uname: ::c_long = 160; -pub const SYS_sethostname: ::c_long = 161; -pub const SYS_setdomainname: ::c_long = 162; -pub const SYS_getrlimit: ::c_long = 163; -pub const SYS_setrlimit: ::c_long = 164; -pub const SYS_getrusage: ::c_long = 165; -pub const SYS_umask: ::c_long = 166; -pub const SYS_prctl: ::c_long = 167; -pub const SYS_getcpu: ::c_long = 168; -pub const SYS_gettimeofday: ::c_long = 169; -pub const SYS_settimeofday: ::c_long = 170; -pub const SYS_adjtimex: ::c_long = 171; -pub const SYS_getpid: ::c_long = 172; -pub const SYS_getppid: ::c_long = 173; -pub const SYS_getuid: ::c_long = 174; -pub const SYS_geteuid: ::c_long = 175; -pub const SYS_getgid: ::c_long = 176; -pub const SYS_getegid: ::c_long = 177; -pub const SYS_gettid: ::c_long = 178; -pub const SYS_sysinfo: ::c_long = 179; -pub const SYS_mq_open: ::c_long = 180; -pub const SYS_mq_unlink: ::c_long = 181; -pub const SYS_mq_timedsend: ::c_long = 182; -pub const SYS_mq_timedreceive: ::c_long = 183; -pub const SYS_mq_notify: ::c_long = 184; -pub const SYS_mq_getsetattr: ::c_long = 185; -pub const SYS_msgget: ::c_long = 186; -pub const SYS_msgctl: ::c_long = 187; -pub const SYS_msgrcv: ::c_long = 188; -pub const SYS_msgsnd: ::c_long = 189; -pub const SYS_semget: ::c_long = 190; -pub const SYS_semctl: ::c_long = 191; -pub const SYS_semtimedop: ::c_long = 192; -pub const SYS_semop: ::c_long = 193; -pub const SYS_shmget: ::c_long = 194; -pub const SYS_shmctl: ::c_long = 195; -pub const SYS_shmat: ::c_long = 196; -pub const SYS_shmdt: ::c_long = 197; -pub const SYS_socket: ::c_long = 198; -pub const SYS_socketpair: ::c_long = 199; -pub const SYS_bind: ::c_long = 200; -pub const SYS_listen: ::c_long = 201; -pub const SYS_accept: ::c_long = 202; -pub const SYS_connect: ::c_long = 203; -pub const SYS_getsockname: ::c_long = 204; -pub const SYS_getpeername: ::c_long = 205; -pub const SYS_sendto: ::c_long = 206; -pub const SYS_recvfrom: ::c_long = 207; -pub const SYS_setsockopt: ::c_long = 208; -pub const SYS_getsockopt: ::c_long = 209; -pub const SYS_shutdown: ::c_long = 210; -pub const SYS_sendmsg: ::c_long = 211; -pub const SYS_recvmsg: ::c_long = 212; -pub const SYS_readahead: ::c_long = 213; -pub const SYS_brk: ::c_long = 214; -pub const SYS_munmap: ::c_long = 215; -pub const SYS_mremap: ::c_long = 216; -pub const SYS_add_key: ::c_long = 217; -pub const SYS_request_key: ::c_long = 218; -pub const SYS_keyctl: ::c_long = 219; -pub const SYS_clone: ::c_long = 220; -pub const SYS_execve: ::c_long = 221; -pub const SYS_mmap: ::c_long = 222; -pub const SYS_swapon: ::c_long = 224; -pub const SYS_swapoff: ::c_long = 225; -pub const SYS_mprotect: ::c_long = 226; -pub const SYS_msync: ::c_long = 227; -pub const SYS_mlock: ::c_long = 228; -pub const SYS_munlock: ::c_long = 229; -pub const SYS_mlockall: ::c_long = 230; -pub const SYS_munlockall: ::c_long = 231; -pub const SYS_mincore: ::c_long = 232; -pub const SYS_madvise: ::c_long = 233; -pub const SYS_remap_file_pages: ::c_long = 234; -pub const SYS_mbind: ::c_long = 235; -pub const SYS_get_mempolicy: ::c_long = 236; -pub const SYS_set_mempolicy: ::c_long = 237; -pub const SYS_migrate_pages: ::c_long = 238; -pub const SYS_move_pages: ::c_long = 239; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 240; -pub const SYS_perf_event_open: ::c_long = 241; -pub const SYS_accept4: ::c_long = 242; -pub const SYS_recvmmsg: ::c_long = 243; -pub const SYS_wait4: ::c_long = 260; -pub const SYS_prlimit64: ::c_long = 261; -pub const SYS_fanotify_init: ::c_long = 262; -pub const SYS_fanotify_mark: ::c_long = 263; -pub const SYS_name_to_handle_at: ::c_long = 264; -pub const SYS_open_by_handle_at: ::c_long = 265; -pub const SYS_clock_adjtime: ::c_long = 266; -pub const SYS_syncfs: ::c_long = 267; -pub const SYS_setns: ::c_long = 268; -pub const SYS_sendmmsg: ::c_long = 269; -pub const SYS_process_vm_readv: ::c_long = 270; -pub const SYS_process_vm_writev: ::c_long = 271; -pub const SYS_kcmp: ::c_long = 272; -pub const SYS_finit_module: ::c_long = 273; -pub const SYS_sched_setattr: ::c_long = 274; -pub const SYS_sched_getattr: ::c_long = 275; -pub const SYS_renameat2: ::c_long = 276; -pub const SYS_seccomp: ::c_long = 277; -pub const SYS_getrandom: ::c_long = 278; -pub const SYS_memfd_create: ::c_long = 279; -pub const SYS_bpf: ::c_long = 280; -pub const SYS_execveat: ::c_long = 281; -pub const SYS_userfaultfd: ::c_long = 282; -pub const SYS_membarrier: ::c_long = 283; -pub const SYS_mlock2: ::c_long = 284; -pub const SYS_copy_file_range: ::c_long = 285; -pub const SYS_preadv2: ::c_long = 286; -pub const SYS_pwritev2: ::c_long = 287; -pub const SYS_pkey_mprotect: ::c_long = 288; -pub const SYS_pkey_alloc: ::c_long = 289; -pub const SYS_pkey_free: ::c_long = 290; -pub const SYS_statx: ::c_long = 291; - -#[link(name = "util")] -extern "C" { - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/mips64/align.rs b/libc/src/unix/linux_like/linux/gnu/b64/mips64/align.rs deleted file mode 100644 index 7ca870f..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/mips64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 4] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs b/libc/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs deleted file mode 100644 index a59554b..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/mips64/mod.rs +++ /dev/null @@ -1,1017 +0,0 @@ -use pthread_mutex_t; - -pub type blksize_t = i64; -pub type c_char = i8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type nlink_t = u64; -pub type suseconds_t = i64; -pub type wchar_t = i32; -pub type __u64 = ::c_ulong; - -s! { - pub struct stat { - pub st_dev: ::c_ulong, - st_pad1: [::c_long; 2], - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulong, - st_pad2: [::c_ulong; 1], - pub st_size: ::off_t, - st_pad3: ::c_long, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - st_pad4: ::c_long, - pub st_blocks: ::blkcnt_t, - st_pad5: [::c_long; 7], - } - - pub struct statfs { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_frsize: ::c_long, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_files: ::fsblkcnt_t, - pub f_ffree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::c_long, - f_spare: [::c_long; 6], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct stat64 { - pub st_dev: ::c_ulong, - st_pad1: [::c_long; 2], - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulong, - st_pad2: [::c_long; 2], - pub st_size: ::off64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - st_pad3: ::c_long, - pub st_blocks: ::blkcnt64_t, - st_pad5: [::c_long; 7], - } - - pub struct statfs64 { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_frsize: ::c_long, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_bavail: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_long, - pub f_flags: ::c_long, - pub f_spare: [::c_long; 5], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct pthread_attr_t { - __size: [::c_ulong; 7] - } - - pub struct sigaction { - pub sa_flags: ::c_int, - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_restorer: ::Option, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - _pad: ::c_int, - _pad2: [::c_long; 14], - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_uint, - pub __seq: ::c_ushort, - __pad1: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 23], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } -} - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; - -align_const! { - #[cfg(target_endian = "little")] - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "little")] - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "little")] - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; -} - -pub const SYS_read: ::c_long = 5000 + 0; -pub const SYS_write: ::c_long = 5000 + 1; -pub const SYS_open: ::c_long = 5000 + 2; -pub const SYS_close: ::c_long = 5000 + 3; -pub const SYS_stat: ::c_long = 5000 + 4; -pub const SYS_fstat: ::c_long = 5000 + 5; -pub const SYS_lstat: ::c_long = 5000 + 6; -pub const SYS_poll: ::c_long = 5000 + 7; -pub const SYS_lseek: ::c_long = 5000 + 8; -pub const SYS_mmap: ::c_long = 5000 + 9; -pub const SYS_mprotect: ::c_long = 5000 + 10; -pub const SYS_munmap: ::c_long = 5000 + 11; -pub const SYS_brk: ::c_long = 5000 + 12; -pub const SYS_rt_sigaction: ::c_long = 5000 + 13; -pub const SYS_rt_sigprocmask: ::c_long = 5000 + 14; -pub const SYS_ioctl: ::c_long = 5000 + 15; -pub const SYS_pread64: ::c_long = 5000 + 16; -pub const SYS_pwrite64: ::c_long = 5000 + 17; -pub const SYS_readv: ::c_long = 5000 + 18; -pub const SYS_writev: ::c_long = 5000 + 19; -pub const SYS_access: ::c_long = 5000 + 20; -pub const SYS_pipe: ::c_long = 5000 + 21; -pub const SYS__newselect: ::c_long = 5000 + 22; -pub const SYS_sched_yield: ::c_long = 5000 + 23; -pub const SYS_mremap: ::c_long = 5000 + 24; -pub const SYS_msync: ::c_long = 5000 + 25; -pub const SYS_mincore: ::c_long = 5000 + 26; -pub const SYS_madvise: ::c_long = 5000 + 27; -pub const SYS_shmget: ::c_long = 5000 + 28; -pub const SYS_shmat: ::c_long = 5000 + 29; -pub const SYS_shmctl: ::c_long = 5000 + 30; -pub const SYS_dup: ::c_long = 5000 + 31; -pub const SYS_dup2: ::c_long = 5000 + 32; -pub const SYS_pause: ::c_long = 5000 + 33; -pub const SYS_nanosleep: ::c_long = 5000 + 34; -pub const SYS_getitimer: ::c_long = 5000 + 35; -pub const SYS_setitimer: ::c_long = 5000 + 36; -pub const SYS_alarm: ::c_long = 5000 + 37; -pub const SYS_getpid: ::c_long = 5000 + 38; -pub const SYS_sendfile: ::c_long = 5000 + 39; -pub const SYS_socket: ::c_long = 5000 + 40; -pub const SYS_connect: ::c_long = 5000 + 41; -pub const SYS_accept: ::c_long = 5000 + 42; -pub const SYS_sendto: ::c_long = 5000 + 43; -pub const SYS_recvfrom: ::c_long = 5000 + 44; -pub const SYS_sendmsg: ::c_long = 5000 + 45; -pub const SYS_recvmsg: ::c_long = 5000 + 46; -pub const SYS_shutdown: ::c_long = 5000 + 47; -pub const SYS_bind: ::c_long = 5000 + 48; -pub const SYS_listen: ::c_long = 5000 + 49; -pub const SYS_getsockname: ::c_long = 5000 + 50; -pub const SYS_getpeername: ::c_long = 5000 + 51; -pub const SYS_socketpair: ::c_long = 5000 + 52; -pub const SYS_setsockopt: ::c_long = 5000 + 53; -pub const SYS_getsockopt: ::c_long = 5000 + 54; -pub const SYS_clone: ::c_long = 5000 + 55; -pub const SYS_fork: ::c_long = 5000 + 56; -pub const SYS_execve: ::c_long = 5000 + 57; -pub const SYS_exit: ::c_long = 5000 + 58; -pub const SYS_wait4: ::c_long = 5000 + 59; -pub const SYS_kill: ::c_long = 5000 + 60; -pub const SYS_uname: ::c_long = 5000 + 61; -pub const SYS_semget: ::c_long = 5000 + 62; -pub const SYS_semop: ::c_long = 5000 + 63; -pub const SYS_semctl: ::c_long = 5000 + 64; -pub const SYS_shmdt: ::c_long = 5000 + 65; -pub const SYS_msgget: ::c_long = 5000 + 66; -pub const SYS_msgsnd: ::c_long = 5000 + 67; -pub const SYS_msgrcv: ::c_long = 5000 + 68; -pub const SYS_msgctl: ::c_long = 5000 + 69; -pub const SYS_fcntl: ::c_long = 5000 + 70; -pub const SYS_flock: ::c_long = 5000 + 71; -pub const SYS_fsync: ::c_long = 5000 + 72; -pub const SYS_fdatasync: ::c_long = 5000 + 73; -pub const SYS_truncate: ::c_long = 5000 + 74; -pub const SYS_ftruncate: ::c_long = 5000 + 75; -pub const SYS_getdents: ::c_long = 5000 + 76; -pub const SYS_getcwd: ::c_long = 5000 + 77; -pub const SYS_chdir: ::c_long = 5000 + 78; -pub const SYS_fchdir: ::c_long = 5000 + 79; -pub const SYS_rename: ::c_long = 5000 + 80; -pub const SYS_mkdir: ::c_long = 5000 + 81; -pub const SYS_rmdir: ::c_long = 5000 + 82; -pub const SYS_creat: ::c_long = 5000 + 83; -pub const SYS_link: ::c_long = 5000 + 84; -pub const SYS_unlink: ::c_long = 5000 + 85; -pub const SYS_symlink: ::c_long = 5000 + 86; -pub const SYS_readlink: ::c_long = 5000 + 87; -pub const SYS_chmod: ::c_long = 5000 + 88; -pub const SYS_fchmod: ::c_long = 5000 + 89; -pub const SYS_chown: ::c_long = 5000 + 90; -pub const SYS_fchown: ::c_long = 5000 + 91; -pub const SYS_lchown: ::c_long = 5000 + 92; -pub const SYS_umask: ::c_long = 5000 + 93; -pub const SYS_gettimeofday: ::c_long = 5000 + 94; -pub const SYS_getrlimit: ::c_long = 5000 + 95; -pub const SYS_getrusage: ::c_long = 5000 + 96; -pub const SYS_sysinfo: ::c_long = 5000 + 97; -pub const SYS_times: ::c_long = 5000 + 98; -pub const SYS_ptrace: ::c_long = 5000 + 99; -pub const SYS_getuid: ::c_long = 5000 + 100; -pub const SYS_syslog: ::c_long = 5000 + 101; -pub const SYS_getgid: ::c_long = 5000 + 102; -pub const SYS_setuid: ::c_long = 5000 + 103; -pub const SYS_setgid: ::c_long = 5000 + 104; -pub const SYS_geteuid: ::c_long = 5000 + 105; -pub const SYS_getegid: ::c_long = 5000 + 106; -pub const SYS_setpgid: ::c_long = 5000 + 107; -pub const SYS_getppid: ::c_long = 5000 + 108; -pub const SYS_getpgrp: ::c_long = 5000 + 109; -pub const SYS_setsid: ::c_long = 5000 + 110; -pub const SYS_setreuid: ::c_long = 5000 + 111; -pub const SYS_setregid: ::c_long = 5000 + 112; -pub const SYS_getgroups: ::c_long = 5000 + 113; -pub const SYS_setgroups: ::c_long = 5000 + 114; -pub const SYS_setresuid: ::c_long = 5000 + 115; -pub const SYS_getresuid: ::c_long = 5000 + 116; -pub const SYS_setresgid: ::c_long = 5000 + 117; -pub const SYS_getresgid: ::c_long = 5000 + 118; -pub const SYS_getpgid: ::c_long = 5000 + 119; -pub const SYS_setfsuid: ::c_long = 5000 + 120; -pub const SYS_setfsgid: ::c_long = 5000 + 121; -pub const SYS_getsid: ::c_long = 5000 + 122; -pub const SYS_capget: ::c_long = 5000 + 123; -pub const SYS_capset: ::c_long = 5000 + 124; -pub const SYS_rt_sigpending: ::c_long = 5000 + 125; -pub const SYS_rt_sigtimedwait: ::c_long = 5000 + 126; -pub const SYS_rt_sigqueueinfo: ::c_long = 5000 + 127; -pub const SYS_rt_sigsuspend: ::c_long = 5000 + 128; -pub const SYS_sigaltstack: ::c_long = 5000 + 129; -pub const SYS_utime: ::c_long = 5000 + 130; -pub const SYS_mknod: ::c_long = 5000 + 131; -pub const SYS_personality: ::c_long = 5000 + 132; -pub const SYS_ustat: ::c_long = 5000 + 133; -pub const SYS_statfs: ::c_long = 5000 + 134; -pub const SYS_fstatfs: ::c_long = 5000 + 135; -pub const SYS_sysfs: ::c_long = 5000 + 136; -pub const SYS_getpriority: ::c_long = 5000 + 137; -pub const SYS_setpriority: ::c_long = 5000 + 138; -pub const SYS_sched_setparam: ::c_long = 5000 + 139; -pub const SYS_sched_getparam: ::c_long = 5000 + 140; -pub const SYS_sched_setscheduler: ::c_long = 5000 + 141; -pub const SYS_sched_getscheduler: ::c_long = 5000 + 142; -pub const SYS_sched_get_priority_max: ::c_long = 5000 + 143; -pub const SYS_sched_get_priority_min: ::c_long = 5000 + 144; -pub const SYS_sched_rr_get_interval: ::c_long = 5000 + 145; -pub const SYS_mlock: ::c_long = 5000 + 146; -pub const SYS_munlock: ::c_long = 5000 + 147; -pub const SYS_mlockall: ::c_long = 5000 + 148; -pub const SYS_munlockall: ::c_long = 5000 + 149; -pub const SYS_vhangup: ::c_long = 5000 + 150; -pub const SYS_pivot_root: ::c_long = 5000 + 151; -pub const SYS__sysctl: ::c_long = 5000 + 152; -pub const SYS_prctl: ::c_long = 5000 + 153; -pub const SYS_adjtimex: ::c_long = 5000 + 154; -pub const SYS_setrlimit: ::c_long = 5000 + 155; -pub const SYS_chroot: ::c_long = 5000 + 156; -pub const SYS_sync: ::c_long = 5000 + 157; -pub const SYS_acct: ::c_long = 5000 + 158; -pub const SYS_settimeofday: ::c_long = 5000 + 159; -pub const SYS_mount: ::c_long = 5000 + 160; -pub const SYS_umount2: ::c_long = 5000 + 161; -pub const SYS_swapon: ::c_long = 5000 + 162; -pub const SYS_swapoff: ::c_long = 5000 + 163; -pub const SYS_reboot: ::c_long = 5000 + 164; -pub const SYS_sethostname: ::c_long = 5000 + 165; -pub const SYS_setdomainname: ::c_long = 5000 + 166; -pub const SYS_create_module: ::c_long = 5000 + 167; -pub const SYS_init_module: ::c_long = 5000 + 168; -pub const SYS_delete_module: ::c_long = 5000 + 169; -pub const SYS_get_kernel_syms: ::c_long = 5000 + 170; -pub const SYS_query_module: ::c_long = 5000 + 171; -pub const SYS_quotactl: ::c_long = 5000 + 172; -pub const SYS_nfsservctl: ::c_long = 5000 + 173; -pub const SYS_getpmsg: ::c_long = 5000 + 174; -pub const SYS_putpmsg: ::c_long = 5000 + 175; -pub const SYS_afs_syscall: ::c_long = 5000 + 176; -pub const SYS_gettid: ::c_long = 5000 + 178; -pub const SYS_readahead: ::c_long = 5000 + 179; -pub const SYS_setxattr: ::c_long = 5000 + 180; -pub const SYS_lsetxattr: ::c_long = 5000 + 181; -pub const SYS_fsetxattr: ::c_long = 5000 + 182; -pub const SYS_getxattr: ::c_long = 5000 + 183; -pub const SYS_lgetxattr: ::c_long = 5000 + 184; -pub const SYS_fgetxattr: ::c_long = 5000 + 185; -pub const SYS_listxattr: ::c_long = 5000 + 186; -pub const SYS_llistxattr: ::c_long = 5000 + 187; -pub const SYS_flistxattr: ::c_long = 5000 + 188; -pub const SYS_removexattr: ::c_long = 5000 + 189; -pub const SYS_lremovexattr: ::c_long = 5000 + 190; -pub const SYS_fremovexattr: ::c_long = 5000 + 191; -pub const SYS_tkill: ::c_long = 5000 + 192; -pub const SYS_futex: ::c_long = 5000 + 194; -pub const SYS_sched_setaffinity: ::c_long = 5000 + 195; -pub const SYS_sched_getaffinity: ::c_long = 5000 + 196; -pub const SYS_cacheflush: ::c_long = 5000 + 197; -pub const SYS_cachectl: ::c_long = 5000 + 198; -pub const SYS_sysmips: ::c_long = 5000 + 199; -pub const SYS_io_setup: ::c_long = 5000 + 200; -pub const SYS_io_destroy: ::c_long = 5000 + 201; -pub const SYS_io_getevents: ::c_long = 5000 + 202; -pub const SYS_io_submit: ::c_long = 5000 + 203; -pub const SYS_io_cancel: ::c_long = 5000 + 204; -pub const SYS_exit_group: ::c_long = 5000 + 205; -pub const SYS_lookup_dcookie: ::c_long = 5000 + 206; -pub const SYS_epoll_create: ::c_long = 5000 + 207; -pub const SYS_epoll_ctl: ::c_long = 5000 + 208; -pub const SYS_epoll_wait: ::c_long = 5000 + 209; -pub const SYS_remap_file_pages: ::c_long = 5000 + 210; -pub const SYS_rt_sigreturn: ::c_long = 5000 + 211; -pub const SYS_set_tid_address: ::c_long = 5000 + 212; -pub const SYS_restart_syscall: ::c_long = 5000 + 213; -pub const SYS_semtimedop: ::c_long = 5000 + 214; -pub const SYS_fadvise64: ::c_long = 5000 + 215; -pub const SYS_timer_create: ::c_long = 5000 + 216; -pub const SYS_timer_settime: ::c_long = 5000 + 217; -pub const SYS_timer_gettime: ::c_long = 5000 + 218; -pub const SYS_timer_getoverrun: ::c_long = 5000 + 219; -pub const SYS_timer_delete: ::c_long = 5000 + 220; -pub const SYS_clock_settime: ::c_long = 5000 + 221; -pub const SYS_clock_gettime: ::c_long = 5000 + 222; -pub const SYS_clock_getres: ::c_long = 5000 + 223; -pub const SYS_clock_nanosleep: ::c_long = 5000 + 224; -pub const SYS_tgkill: ::c_long = 5000 + 225; -pub const SYS_utimes: ::c_long = 5000 + 226; -pub const SYS_mbind: ::c_long = 5000 + 227; -pub const SYS_get_mempolicy: ::c_long = 5000 + 228; -pub const SYS_set_mempolicy: ::c_long = 5000 + 229; -pub const SYS_mq_open: ::c_long = 5000 + 230; -pub const SYS_mq_unlink: ::c_long = 5000 + 231; -pub const SYS_mq_timedsend: ::c_long = 5000 + 232; -pub const SYS_mq_timedreceive: ::c_long = 5000 + 233; -pub const SYS_mq_notify: ::c_long = 5000 + 234; -pub const SYS_mq_getsetattr: ::c_long = 5000 + 235; -pub const SYS_vserver: ::c_long = 5000 + 236; -pub const SYS_waitid: ::c_long = 5000 + 237; -/* pub const SYS_sys_setaltroot: ::c_long = 5000 + 238; */ -pub const SYS_add_key: ::c_long = 5000 + 239; -pub const SYS_request_key: ::c_long = 5000 + 240; -pub const SYS_keyctl: ::c_long = 5000 + 241; -pub const SYS_set_thread_area: ::c_long = 5000 + 242; -pub const SYS_inotify_init: ::c_long = 5000 + 243; -pub const SYS_inotify_add_watch: ::c_long = 5000 + 244; -pub const SYS_inotify_rm_watch: ::c_long = 5000 + 245; -pub const SYS_migrate_pages: ::c_long = 5000 + 246; -pub const SYS_openat: ::c_long = 5000 + 247; -pub const SYS_mkdirat: ::c_long = 5000 + 248; -pub const SYS_mknodat: ::c_long = 5000 + 249; -pub const SYS_fchownat: ::c_long = 5000 + 250; -pub const SYS_futimesat: ::c_long = 5000 + 251; -pub const SYS_newfstatat: ::c_long = 5000 + 252; -pub const SYS_unlinkat: ::c_long = 5000 + 253; -pub const SYS_renameat: ::c_long = 5000 + 254; -pub const SYS_linkat: ::c_long = 5000 + 255; -pub const SYS_symlinkat: ::c_long = 5000 + 256; -pub const SYS_readlinkat: ::c_long = 5000 + 257; -pub const SYS_fchmodat: ::c_long = 5000 + 258; -pub const SYS_faccessat: ::c_long = 5000 + 259; -pub const SYS_pselect6: ::c_long = 5000 + 260; -pub const SYS_ppoll: ::c_long = 5000 + 261; -pub const SYS_unshare: ::c_long = 5000 + 262; -pub const SYS_splice: ::c_long = 5000 + 263; -pub const SYS_sync_file_range: ::c_long = 5000 + 264; -pub const SYS_tee: ::c_long = 5000 + 265; -pub const SYS_vmsplice: ::c_long = 5000 + 266; -pub const SYS_move_pages: ::c_long = 5000 + 267; -pub const SYS_set_robust_list: ::c_long = 5000 + 268; -pub const SYS_get_robust_list: ::c_long = 5000 + 269; -pub const SYS_kexec_load: ::c_long = 5000 + 270; -pub const SYS_getcpu: ::c_long = 5000 + 271; -pub const SYS_epoll_pwait: ::c_long = 5000 + 272; -pub const SYS_ioprio_set: ::c_long = 5000 + 273; -pub const SYS_ioprio_get: ::c_long = 5000 + 274; -pub const SYS_utimensat: ::c_long = 5000 + 275; -pub const SYS_signalfd: ::c_long = 5000 + 276; -pub const SYS_timerfd: ::c_long = 5000 + 277; -pub const SYS_eventfd: ::c_long = 5000 + 278; -pub const SYS_fallocate: ::c_long = 5000 + 279; -pub const SYS_timerfd_create: ::c_long = 5000 + 280; -pub const SYS_timerfd_gettime: ::c_long = 5000 + 281; -pub const SYS_timerfd_settime: ::c_long = 5000 + 282; -pub const SYS_signalfd4: ::c_long = 5000 + 283; -pub const SYS_eventfd2: ::c_long = 5000 + 284; -pub const SYS_epoll_create1: ::c_long = 5000 + 285; -pub const SYS_dup3: ::c_long = 5000 + 286; -pub const SYS_pipe2: ::c_long = 5000 + 287; -pub const SYS_inotify_init1: ::c_long = 5000 + 288; -pub const SYS_preadv: ::c_long = 5000 + 289; -pub const SYS_pwritev: ::c_long = 5000 + 290; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 5000 + 291; -pub const SYS_perf_event_open: ::c_long = 5000 + 292; -pub const SYS_accept4: ::c_long = 5000 + 293; -pub const SYS_recvmmsg: ::c_long = 5000 + 294; -pub const SYS_fanotify_init: ::c_long = 5000 + 295; -pub const SYS_fanotify_mark: ::c_long = 5000 + 296; -pub const SYS_prlimit64: ::c_long = 5000 + 297; -pub const SYS_name_to_handle_at: ::c_long = 5000 + 298; -pub const SYS_open_by_handle_at: ::c_long = 5000 + 299; -pub const SYS_clock_adjtime: ::c_long = 5000 + 300; -pub const SYS_syncfs: ::c_long = 5000 + 301; -pub const SYS_sendmmsg: ::c_long = 5000 + 302; -pub const SYS_setns: ::c_long = 5000 + 303; -pub const SYS_process_vm_readv: ::c_long = 5000 + 304; -pub const SYS_process_vm_writev: ::c_long = 5000 + 305; -pub const SYS_kcmp: ::c_long = 5000 + 306; -pub const SYS_finit_module: ::c_long = 5000 + 307; -pub const SYS_getdents64: ::c_long = 5000 + 308; -pub const SYS_sched_setattr: ::c_long = 5000 + 309; -pub const SYS_sched_getattr: ::c_long = 5000 + 310; -pub const SYS_renameat2: ::c_long = 5000 + 311; -pub const SYS_seccomp: ::c_long = 5000 + 312; -pub const SYS_getrandom: ::c_long = 5000 + 313; -pub const SYS_memfd_create: ::c_long = 5000 + 314; -pub const SYS_bpf: ::c_long = 5000 + 315; -pub const SYS_execveat: ::c_long = 5000 + 316; -pub const SYS_userfaultfd: ::c_long = 5000 + 317; -pub const SYS_membarrier: ::c_long = 5000 + 318; -pub const SYS_mlock2: ::c_long = 5000 + 319; -pub const SYS_copy_file_range: ::c_long = 5000 + 320; -pub const SYS_preadv2: ::c_long = 5000 + 321; -pub const SYS_pwritev2: ::c_long = 5000 + 322; -pub const SYS_pkey_mprotect: ::c_long = 5000 + 323; -pub const SYS_pkey_alloc: ::c_long = 5000 + 324; -pub const SYS_pkey_free: ::c_long = 5000 + 325; -pub const SYS_statx: ::c_long = 5000 + 326; - -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; - -pub const O_NOATIME: ::c_int = 0o1000000; -pub const O_CLOEXEC: ::c_int = 0x80000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const O_DIRECT: ::c_int = 0x8000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; - -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 6; -pub const RLIMIT_RSS: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 8; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 9; - -pub const O_APPEND: ::c_int = 8; -pub const O_CREAT: ::c_int = 256; -pub const O_EXCL: ::c_int = 1024; -pub const O_NOCTTY: ::c_int = 2048; -pub const O_NONBLOCK: ::c_int = 128; -pub const O_SYNC: ::c_int = 0x4010; -pub const O_RSYNC: ::c_int = 0x4010; -pub const O_DSYNC: ::c_int = 0x10; -pub const O_FSYNC: ::c_int = 0x4010; -pub const O_ASYNC: ::c_int = 0x1000; -pub const O_NDELAY: ::c_int = 0x80; - -pub const EDEADLK: ::c_int = 45; -pub const ENAMETOOLONG: ::c_int = 78; -pub const ENOLCK: ::c_int = 46; -pub const ENOSYS: ::c_int = 89; -pub const ENOTEMPTY: ::c_int = 93; -pub const ELOOP: ::c_int = 90; -pub const ENOMSG: ::c_int = 35; -pub const EIDRM: ::c_int = 36; -pub const ECHRNG: ::c_int = 37; -pub const EL2NSYNC: ::c_int = 38; -pub const EL3HLT: ::c_int = 39; -pub const EL3RST: ::c_int = 40; -pub const ELNRNG: ::c_int = 41; -pub const EUNATCH: ::c_int = 42; -pub const ENOCSI: ::c_int = 43; -pub const EL2HLT: ::c_int = 44; -pub const EBADE: ::c_int = 50; -pub const EBADR: ::c_int = 51; -pub const EXFULL: ::c_int = 52; -pub const ENOANO: ::c_int = 53; -pub const EBADRQC: ::c_int = 54; -pub const EBADSLT: ::c_int = 55; -pub const EDEADLOCK: ::c_int = 56; -pub const EMULTIHOP: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 79; -pub const ENOTUNIQ: ::c_int = 80; -pub const EBADFD: ::c_int = 81; -pub const EBADMSG: ::c_int = 77; -pub const EREMCHG: ::c_int = 82; -pub const ELIBACC: ::c_int = 83; -pub const ELIBBAD: ::c_int = 84; -pub const ELIBSCN: ::c_int = 85; -pub const ELIBMAX: ::c_int = 86; -pub const ELIBEXEC: ::c_int = 87; -pub const EILSEQ: ::c_int = 88; -pub const ERESTART: ::c_int = 91; -pub const ESTRPIPE: ::c_int = 92; -pub const EUSERS: ::c_int = 94; -pub const ENOTSOCK: ::c_int = 95; -pub const EDESTADDRREQ: ::c_int = 96; -pub const EMSGSIZE: ::c_int = 97; -pub const EPROTOTYPE: ::c_int = 98; -pub const ENOPROTOOPT: ::c_int = 99; -pub const EPROTONOSUPPORT: ::c_int = 120; -pub const ESOCKTNOSUPPORT: ::c_int = 121; -pub const EOPNOTSUPP: ::c_int = 122; -pub const EPFNOSUPPORT: ::c_int = 123; -pub const EAFNOSUPPORT: ::c_int = 124; -pub const EADDRINUSE: ::c_int = 125; -pub const EADDRNOTAVAIL: ::c_int = 126; -pub const ENETDOWN: ::c_int = 127; -pub const ENETUNREACH: ::c_int = 128; -pub const ENETRESET: ::c_int = 129; -pub const ECONNABORTED: ::c_int = 130; -pub const ECONNRESET: ::c_int = 131; -pub const ENOBUFS: ::c_int = 132; -pub const EISCONN: ::c_int = 133; -pub const ENOTCONN: ::c_int = 134; -pub const ESHUTDOWN: ::c_int = 143; -pub const ETOOMANYREFS: ::c_int = 144; -pub const ETIMEDOUT: ::c_int = 145; -pub const ECONNREFUSED: ::c_int = 146; -pub const EHOSTDOWN: ::c_int = 147; -pub const EHOSTUNREACH: ::c_int = 148; -pub const EALREADY: ::c_int = 149; -pub const EINPROGRESS: ::c_int = 150; -pub const ESTALE: ::c_int = 151; -pub const EUCLEAN: ::c_int = 135; -pub const ENOTNAM: ::c_int = 137; -pub const ENAVAIL: ::c_int = 138; -pub const EISNAM: ::c_int = 139; -pub const EREMOTEIO: ::c_int = 140; -pub const EDQUOT: ::c_int = 1133; -pub const ENOMEDIUM: ::c_int = 159; -pub const EMEDIUMTYPE: ::c_int = 160; -pub const ECANCELED: ::c_int = 158; -pub const ENOKEY: ::c_int = 161; -pub const EKEYEXPIRED: ::c_int = 162; -pub const EKEYREVOKED: ::c_int = 163; -pub const EKEYREJECTED: ::c_int = 164; -pub const EOWNERDEAD: ::c_int = 165; -pub const ENOTRECOVERABLE: ::c_int = 166; -pub const ERFKILL: ::c_int = 167; - -pub const MAP_NORESERVE: ::c_int = 0x400; -pub const MAP_ANON: ::c_int = 0x800; -pub const MAP_ANONYMOUS: ::c_int = 0x800; -pub const MAP_GROWSDOWN: ::c_int = 0x1000; -pub const MAP_DENYWRITE: ::c_int = 0x2000; -pub const MAP_EXECUTABLE: ::c_int = 0x4000; -pub const MAP_LOCKED: ::c_int = 0x8000; -pub const MAP_POPULATE: ::c_int = 0x10000; -pub const MAP_NONBLOCK: ::c_int = 0x20000; -pub const MAP_STACK: ::c_int = 0x40000; -pub const MAP_HUGETLB: ::c_int = 0x080000; - -pub const SOCK_STREAM: ::c_int = 2; -pub const SOCK_DGRAM: ::c_int = 1; - -pub const SOL_SOCKET: ::c_int = 0xffff; - -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_STYLE: ::c_int = SO_TYPE; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ACCEPTCONN: ::c_int = 0x1009; -pub const SO_PROTOCOL: ::c_int = 0x1028; -pub const SO_DOMAIN: ::c_int = 0x1029; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_PASSCRED: ::c_int = 17; -pub const SO_PEERCRED: ::c_int = 18; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_PEERSEC: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 31; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; -pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS; -pub const SO_MARK: ::c_int = 36; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_BUSY_POLL: ::c_int = 46; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; -pub const SO_INCOMING_CPU: ::c_int = 49; -pub const SO_ATTACH_BPF: ::c_int = 50; -pub const SO_DETACH_BPF: ::c_int = SO_DETACH_FILTER; - -pub const FIOCLEX: ::c_ulong = 0x6601; -pub const FIONCLEX: ::c_ulong = 0x6602; -pub const FIONBIO: ::c_ulong = 0x667e; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000008; -pub const SA_NOCLDWAIT: ::c_int = 0x00010000; - -pub const SIGCHLD: ::c_int = 18; -pub const SIGBUS: ::c_int = 10; -pub const SIGTTIN: ::c_int = 26; -pub const SIGTTOU: ::c_int = 27; -pub const SIGXCPU: ::c_int = 30; -pub const SIGXFSZ: ::c_int = 31; -pub const SIGVTALRM: ::c_int = 28; -pub const SIGPROF: ::c_int = 29; -pub const SIGWINCH: ::c_int = 20; -pub const SIGUSR1: ::c_int = 16; -pub const SIGUSR2: ::c_int = 17; -pub const SIGCONT: ::c_int = 25; -pub const SIGSTOP: ::c_int = 23; -pub const SIGTSTP: ::c_int = 24; -pub const SIGURG: ::c_int = 21; -pub const SIGIO: ::c_int = 22; -pub const SIGSYS: ::c_int = 12; -pub const SIGPOLL: ::c_int = 22; -pub const SIGPWR: ::c_int = 19; -pub const SIG_SETMASK: ::c_int = 3; -pub const SIG_BLOCK: ::c_int = 0x1; -pub const SIG_UNBLOCK: ::c_int = 0x2; - -pub const POLLWRNORM: ::c_short = 0x004; -pub const POLLWRBAND: ::c_short = 0x100; - -pub const VEOF: usize = 16; -pub const VEOL: usize = 17; -pub const VEOL2: usize = 6; -pub const VMIN: usize = 4; -pub const IEXTEN: ::tcflag_t = 0x00000100; -pub const TOSTOP: ::tcflag_t = 0x00008000; -pub const FLUSHO: ::tcflag_t = 0x00002000; -pub const EXTPROC: ::tcflag_t = 0o200000; -pub const TCSANOW: ::c_int = 0x540e; -pub const TCSADRAIN: ::c_int = 0x540f; -pub const TCSAFLUSH: ::c_int = 0x5410; - -pub const PTRACE_GETFPREGS: ::c_uint = 14; -pub const PTRACE_SETFPREGS: ::c_uint = 15; -pub const PTRACE_DETACH: ::c_uint = 17; -pub const PTRACE_GETFPXREGS: ::c_uint = 18; -pub const PTRACE_SETFPXREGS: ::c_uint = 19; -pub const PTRACE_GETREGS: ::c_uint = 12; -pub const PTRACE_SETREGS: ::c_uint = 13; - -pub const EFD_NONBLOCK: ::c_int = 0x80; - -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; -pub const F_GETLK: ::c_int = 14; -pub const F_GETOWN: ::c_int = 23; -pub const F_SETOWN: ::c_int = 24; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -pub const SFD_NONBLOCK: ::c_int = 0x80; - -pub const TCGETS: ::c_ulong = 0x540d; -pub const TCSETS: ::c_ulong = 0x540e; -pub const TCSETSW: ::c_ulong = 0x540f; -pub const TCSETSF: ::c_ulong = 0x5410; -pub const TCGETA: ::c_ulong = 0x5401; -pub const TCSETA: ::c_ulong = 0x5402; -pub const TCSETAW: ::c_ulong = 0x5403; -pub const TCSETAF: ::c_ulong = 0x5404; -pub const TCSBRK: ::c_ulong = 0x5405; -pub const TCXONC: ::c_ulong = 0x5406; -pub const TCFLSH: ::c_ulong = 0x5407; -pub const TIOCGSOFTCAR: ::c_ulong = 0x5481; -pub const TIOCSSOFTCAR: ::c_ulong = 0x5482; -pub const TIOCINQ: ::c_ulong = 0x467f; -pub const TIOCLINUX: ::c_ulong = 0x5483; -pub const TIOCGSERIAL: ::c_ulong = 0x5484; -pub const TIOCEXCL: ::c_ulong = 0x740d; -pub const TIOCNXCL: ::c_ulong = 0x740e; -pub const TIOCSCTTY: ::c_ulong = 0x5480; -pub const TIOCGPGRP: ::c_ulong = 0x40047477; -pub const TIOCSPGRP: ::c_ulong = 0x80047476; -pub const TIOCOUTQ: ::c_ulong = 0x7472; -pub const TIOCSTI: ::c_ulong = 0x5472; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const TIOCMGET: ::c_ulong = 0x741d; -pub const TIOCMBIS: ::c_ulong = 0x741b; -pub const TIOCMBIC: ::c_ulong = 0x741c; -pub const TIOCMSET: ::c_ulong = 0x741a; -pub const FIONREAD: ::c_ulong = 0x467f; -pub const TIOCCONS: ::c_ulong = 0x80047478; - -pub const RTLD_DEEPBIND: ::c_int = 0x10; -pub const RTLD_GLOBAL: ::c_int = 0x4; -pub const RTLD_NOLOAD: ::c_int = 0x8; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const TIOCM_ST: ::c_int = 0x010; -pub const TIOCM_SR: ::c_int = 0x020; -pub const TIOCM_CTS: ::c_int = 0x040; -pub const TIOCM_CAR: ::c_int = 0x100; -pub const TIOCM_RNG: ::c_int = 0x200; -pub const TIOCM_DSR: ::c_int = 0x400; - -pub const EHWPOISON: ::c_int = 168; - -#[link(name = "util")] -extern "C" { - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/mod.rs b/libc/src/unix/linux_like/linux/gnu/b64/mod.rs deleted file mode 100644 index 40ce844..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/mod.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! 64-bit specific definitions for linux-like values - -pub type clock_t = i64; -pub type time_t = i64; -pub type ino_t = u64; -pub type off_t = i64; -pub type blkcnt_t = i64; -pub type shmatt_t = u64; -pub type msgqnum_t = u64; -pub type msglen_t = u64; -pub type fsblkcnt_t = u64; -pub type fsfilcnt_t = u64; -pub type rlim_t = u64; -pub type __fsword_t = i64; - -s! { - pub struct sigset_t { - #[cfg(target_pointer_width = "32")] - __val: [u32; 32], - #[cfg(target_pointer_width = "64")] - __val: [u64; 16], - } - - pub struct sysinfo { - pub uptime: i64, - pub loads: [u64; 3], - pub totalram: u64, - pub freeram: u64, - pub sharedram: u64, - pub bufferram: u64, - pub totalswap: u64, - pub freeswap: u64, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: u64, - pub freehigh: u64, - pub mem_unit: ::c_uint, - pub _f: [::c_char; 0], - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - pub msg_rtime: ::time_t, - pub msg_ctime: ::time_t, - __msg_cbytes: u64, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __glibc_reserved4: u64, - __glibc_reserved5: u64, - } - -} - -pub const RLIM_INFINITY: ::rlim_t = !0; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; - -pub const O_LARGEFILE: ::c_int = 0; - -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(any(target_arch = "powerpc64"))] { - mod powerpc64; - pub use self::powerpc64::*; - } else if #[cfg(any(target_arch = "sparc64"))] { - mod sparc64; - pub use self::sparc64::*; - } else if #[cfg(any(target_arch = "mips64"))] { - mod mips64; - pub use self::mips64::*; - } else if #[cfg(any(target_arch = "s390x"))] { - mod s390x; - pub use self::s390x::*; - } else if #[cfg(any(target_arch = "x86_64"))] { - mod x86_64; - pub use self::x86_64::*; - } else if #[cfg(any(target_arch = "riscv64"))] { - mod riscv64; - pub use self::riscv64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs b/libc/src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs deleted file mode 100644 index 29d1e1c..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [i64; 4] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs b/libc/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs deleted file mode 100644 index 22507d7..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs +++ /dev/null @@ -1,1052 +0,0 @@ -//! PowerPC64-specific definitions for 64-bit linux-like values - -use pthread_mutex_t; - -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = u8; -pub type wchar_t = i32; -pub type nlink_t = u64; -pub type blksize_t = i64; -pub type suseconds_t = i64; -pub type __u64 = ::c_ulong; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - #[cfg(target_arch = "sparc64")] - __reserved0: ::c_int, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statfs { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - f_spare: [::__fsword_t; 5], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 3], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __reserved: [::c_long; 3], - } - - pub struct statfs64 { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - pub f_flags: ::__fsword_t, - pub f_spare: [::__fsword_t; 4], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct pthread_attr_t { - __size: [u64; 7] - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: u32, - __pad1: u32, - __unused1: u64, - __unused2: ::c_ulong, - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_segsz: ::size_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since="0.2.54", - note="Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } -} - -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const VEOF: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; - -pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; -pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; - -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 6; - -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_FSYNC: ::c_int = 0x101000; -pub const O_NOATIME: ::c_int = 0o1000000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EBADMSG: ::c_int = 74; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const EHWPOISON: ::c_int = 133; -pub const ERFKILL: ::c_int = 132; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 20; -pub const SO_PEERCRED: ::c_int = 21; -pub const SO_RCVLOWAT: ::c_int = 16; -pub const SO_SNDLOWAT: ::c_int = 17; -pub const SO_RCVTIMEO: ::c_int = 18; -pub const SO_SNDTIMEO: ::c_int = 19; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_PEERSEC: ::c_int = 31; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; -pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS; -pub const SO_MARK: ::c_int = 36; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_BUSY_POLL: ::c_int = 46; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; -pub const SO_INCOMING_CPU: ::c_int = 49; -pub const SO_ATTACH_BPF: ::c_int = 50; -pub const SO_DETACH_BPF: ::c_int = SO_DETACH_FILTER; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = 31; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_NDELAY: ::c_int = 0x800; - -pub const PTRACE_DETACH: ::c_uint = 17; - -pub const EFD_NONBLOCK: ::c_int = 0x800; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; - -pub const SFD_NONBLOCK: ::c_int = 0x0800; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; -pub const TIOCEXCL: ::c_ulong = 0x540C; -pub const TIOCNXCL: ::c_ulong = 0x540D; -pub const TIOCSCTTY: ::c_ulong = 0x540E; -pub const TIOCSTI: ::c_ulong = 0x5412; -pub const TIOCMGET: ::c_ulong = 0x5415; -pub const TIOCMBIS: ::c_ulong = 0x5416; -pub const TIOCMBIC: ::c_ulong = 0x5417; -pub const TIOCMSET: ::c_ulong = 0x5418; -pub const TIOCCONS: ::c_ulong = 0x541D; -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; - -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; - -pub const O_CLOEXEC: ::c_int = 0x80000; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; - -align_const! { - #[cfg(target_endian = "little")] - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "little")] - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "little")] - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; -} - -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_DIRECT: ::c_int = 0x20000; - -pub const MAP_LOCKED: ::c_int = 0x00080; -pub const MAP_NORESERVE: ::c_int = 0x00040; - -pub const EDEADLOCK: ::c_int = 58; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; - -pub const FIOCLEX: ::c_ulong = 0x20006601; -pub const FIONCLEX: ::c_ulong = 0x20006602; -pub const FIONBIO: ::c_ulong = 0x8004667e; - -pub const MCL_CURRENT: ::c_int = 0x2000; -pub const MCL_FUTURE: ::c_int = 0x4000; - -pub const SIGSTKSZ: ::size_t = 0x4000; -pub const MINSIGSTKSZ: ::size_t = 4096; -pub const CBAUD: ::tcflag_t = 0xff; -pub const TAB1: ::tcflag_t = 0x400; -pub const TAB2: ::tcflag_t = 0x800; -pub const TAB3: ::tcflag_t = 0xc00; -pub const CR1: ::tcflag_t = 0x1000; -pub const CR2: ::tcflag_t = 0x2000; -pub const CR3: ::tcflag_t = 0x3000; -pub const FF1: ::tcflag_t = 0x4000; -pub const BS1: ::tcflag_t = 0x8000; -pub const VT1: ::tcflag_t = 0x10000; -pub const VWERASE: usize = 0xa; -pub const VREPRINT: usize = 0xb; -pub const VSUSP: usize = 0xc; -pub const VSTART: usize = 0xd; -pub const VSTOP: usize = 0xe; -pub const VDISCARD: usize = 0x10; -pub const VTIME: usize = 0x7; -pub const IXON: ::tcflag_t = 0x200; -pub const IXOFF: ::tcflag_t = 0x400; -pub const ONLCR: ::tcflag_t = 0x2; -pub const CSIZE: ::tcflag_t = 0x300; -pub const CS6: ::tcflag_t = 0x100; -pub const CS7: ::tcflag_t = 0x200; -pub const CS8: ::tcflag_t = 0x300; -pub const CSTOPB: ::tcflag_t = 0x400; -pub const CREAD: ::tcflag_t = 0x800; -pub const PARENB: ::tcflag_t = 0x1000; -pub const PARODD: ::tcflag_t = 0x2000; -pub const HUPCL: ::tcflag_t = 0x4000; -pub const CLOCAL: ::tcflag_t = 0x8000; -pub const ECHOKE: ::tcflag_t = 0x1; -pub const ECHOE: ::tcflag_t = 0x2; -pub const ECHOK: ::tcflag_t = 0x4; -pub const ECHONL: ::tcflag_t = 0x10; -pub const ECHOPRT: ::tcflag_t = 0x20; -pub const ECHOCTL: ::tcflag_t = 0x40; -pub const ISIG: ::tcflag_t = 0x80; -pub const ICANON: ::tcflag_t = 0x100; -pub const PENDIN: ::tcflag_t = 0x20000000; -pub const NOFLSH: ::tcflag_t = 0x80000000; -pub const VSWTC: usize = 9; -pub const OLCUC: ::tcflag_t = 0o000004; -pub const NLDLY: ::tcflag_t = 0o001400; -pub const CRDLY: ::tcflag_t = 0o030000; -pub const TABDLY: ::tcflag_t = 0o006000; -pub const BSDLY: ::tcflag_t = 0o100000; -pub const FFDLY: ::tcflag_t = 0o040000; -pub const VTDLY: ::tcflag_t = 0o200000; -pub const XTABS: ::tcflag_t = 0o006000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const CBAUDEX: ::speed_t = 0o000020; -pub const B57600: ::speed_t = 0o0020; -pub const B115200: ::speed_t = 0o0021; -pub const B230400: ::speed_t = 0o0022; -pub const B460800: ::speed_t = 0o0023; -pub const B500000: ::speed_t = 0o0024; -pub const B576000: ::speed_t = 0o0025; -pub const B921600: ::speed_t = 0o0026; -pub const B1000000: ::speed_t = 0o0027; -pub const B1152000: ::speed_t = 0o0030; -pub const B1500000: ::speed_t = 0o0031; -pub const B2000000: ::speed_t = 0o0032; -pub const B2500000: ::speed_t = 0o0033; -pub const B3000000: ::speed_t = 0o0034; -pub const B3500000: ::speed_t = 0o0035; -pub const B4000000: ::speed_t = 0o0036; -pub const BOTHER: ::speed_t = 0o0037; - -pub const VEOL: usize = 6; -pub const VEOL2: usize = 8; -pub const VMIN: usize = 5; -pub const IEXTEN: ::tcflag_t = 0x400; -pub const TOSTOP: ::tcflag_t = 0x400000; -pub const FLUSHO: ::tcflag_t = 0x800000; -pub const EXTPROC: ::tcflag_t = 0x10000000; -pub const TCGETS: ::c_ulong = 0x403c7413; -pub const TCSETS: ::c_ulong = 0x803c7414; -pub const TCSETSW: ::c_ulong = 0x803c7415; -pub const TCSETSF: ::c_ulong = 0x803c7416; -pub const TCGETA: ::c_ulong = 0x40147417; -pub const TCSETA: ::c_ulong = 0x80147418; -pub const TCSETAW: ::c_ulong = 0x80147419; -pub const TCSETAF: ::c_ulong = 0x8014741c; -pub const TCSBRK: ::c_ulong = 0x2000741d; -pub const TCXONC: ::c_ulong = 0x2000741e; -pub const TCFLSH: ::c_ulong = 0x2000741f; -pub const TIOCINQ: ::c_ulong = 0x4004667f; -pub const TIOCGPGRP: ::c_ulong = 0x40047477; -pub const TIOCSPGRP: ::c_ulong = 0x80047476; -pub const TIOCOUTQ: ::c_ulong = 0x40047473; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const FIONREAD: ::c_ulong = 0x4004667f; - -// Syscall table -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_waitpid: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_time: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_break: ::c_long = 17; -pub const SYS_oldstat: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_umount: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_stime: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_oldfstat: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_stty: ::c_long = 31; -pub const SYS_gtty: ::c_long = 32; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_ftime: ::c_long = 35; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_prof: ::c_long = 44; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_lock: ::c_long = 53; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_mpx: ::c_long = 56; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_ulimit: ::c_long = 58; -pub const SYS_oldolduname: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_sgetmask: ::c_long = 68; -pub const SYS_ssetmask: ::c_long = 69; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrlimit: ::c_long = 76; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_select: ::c_long = 82; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_oldlstat: ::c_long = 84; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_readdir: ::c_long = 89; -pub const SYS_mmap: ::c_long = 90; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_profil: ::c_long = 98; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_ioperm: ::c_long = 101; -pub const SYS_socketcall: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_olduname: ::c_long = 109; -pub const SYS_iopl: ::c_long = 110; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_idle: ::c_long = 112; -pub const SYS_vm86: ::c_long = 113; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_ipc: ::c_long = 117; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_modify_ldt: ::c_long = 123; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_create_module: ::c_long = 127; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_get_kernel_syms: ::c_long = 130; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_afs_syscall: ::c_long = 137; /* Syscall for Andrew File System */ -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_query_module: ::c_long = 166; -pub const SYS_poll: ::c_long = 167; -pub const SYS_nfsservctl: ::c_long = 168; -pub const SYS_setresgid: ::c_long = 169; -pub const SYS_getresgid: ::c_long = 170; -pub const SYS_prctl: ::c_long = 171; -pub const SYS_rt_sigreturn: ::c_long = 172; -pub const SYS_rt_sigaction: ::c_long = 173; -pub const SYS_rt_sigprocmask: ::c_long = 174; -pub const SYS_rt_sigpending: ::c_long = 175; -pub const SYS_rt_sigtimedwait: ::c_long = 176; -pub const SYS_rt_sigqueueinfo: ::c_long = 177; -pub const SYS_rt_sigsuspend: ::c_long = 178; -pub const SYS_pread64: ::c_long = 179; -pub const SYS_pwrite64: ::c_long = 180; -pub const SYS_chown: ::c_long = 181; -pub const SYS_getcwd: ::c_long = 182; -pub const SYS_capget: ::c_long = 183; -pub const SYS_capset: ::c_long = 184; -pub const SYS_sigaltstack: ::c_long = 185; -pub const SYS_sendfile: ::c_long = 186; -pub const SYS_getpmsg: ::c_long = 187; /* some people actually want streams */ -pub const SYS_putpmsg: ::c_long = 188; /* some people actually want streams */ -pub const SYS_vfork: ::c_long = 189; -pub const SYS_ugetrlimit: ::c_long = 190; /* SuS compliant getrlimit */ -pub const SYS_readahead: ::c_long = 191; -pub const SYS_pciconfig_read: ::c_long = 198; -pub const SYS_pciconfig_write: ::c_long = 199; -pub const SYS_pciconfig_iobase: ::c_long = 200; -pub const SYS_multiplexer: ::c_long = 201; -pub const SYS_getdents64: ::c_long = 202; -pub const SYS_pivot_root: ::c_long = 203; -pub const SYS_madvise: ::c_long = 205; -pub const SYS_mincore: ::c_long = 206; -pub const SYS_gettid: ::c_long = 207; -pub const SYS_tkill: ::c_long = 208; -pub const SYS_setxattr: ::c_long = 209; -pub const SYS_lsetxattr: ::c_long = 210; -pub const SYS_fsetxattr: ::c_long = 211; -pub const SYS_getxattr: ::c_long = 212; -pub const SYS_lgetxattr: ::c_long = 213; -pub const SYS_fgetxattr: ::c_long = 214; -pub const SYS_listxattr: ::c_long = 215; -pub const SYS_llistxattr: ::c_long = 216; -pub const SYS_flistxattr: ::c_long = 217; -pub const SYS_removexattr: ::c_long = 218; -pub const SYS_lremovexattr: ::c_long = 219; -pub const SYS_fremovexattr: ::c_long = 220; -pub const SYS_futex: ::c_long = 221; -pub const SYS_sched_setaffinity: ::c_long = 222; -pub const SYS_sched_getaffinity: ::c_long = 223; -pub const SYS_tuxcall: ::c_long = 225; -pub const SYS_io_setup: ::c_long = 227; -pub const SYS_io_destroy: ::c_long = 228; -pub const SYS_io_getevents: ::c_long = 229; -pub const SYS_io_submit: ::c_long = 230; -pub const SYS_io_cancel: ::c_long = 231; -pub const SYS_set_tid_address: ::c_long = 232; -pub const SYS_exit_group: ::c_long = 234; -pub const SYS_lookup_dcookie: ::c_long = 235; -pub const SYS_epoll_create: ::c_long = 236; -pub const SYS_epoll_ctl: ::c_long = 237; -pub const SYS_epoll_wait: ::c_long = 238; -pub const SYS_remap_file_pages: ::c_long = 239; -pub const SYS_timer_create: ::c_long = 240; -pub const SYS_timer_settime: ::c_long = 241; -pub const SYS_timer_gettime: ::c_long = 242; -pub const SYS_timer_getoverrun: ::c_long = 243; -pub const SYS_timer_delete: ::c_long = 244; -pub const SYS_clock_settime: ::c_long = 245; -pub const SYS_clock_gettime: ::c_long = 246; -pub const SYS_clock_getres: ::c_long = 247; -pub const SYS_clock_nanosleep: ::c_long = 248; -pub const SYS_swapcontext: ::c_long = 249; -pub const SYS_tgkill: ::c_long = 250; -pub const SYS_utimes: ::c_long = 251; -pub const SYS_statfs64: ::c_long = 252; -pub const SYS_fstatfs64: ::c_long = 253; -pub const SYS_rtas: ::c_long = 255; -pub const SYS_sys_debug_setcontext: ::c_long = 256; -pub const SYS_migrate_pages: ::c_long = 258; -pub const SYS_mbind: ::c_long = 259; -pub const SYS_get_mempolicy: ::c_long = 260; -pub const SYS_set_mempolicy: ::c_long = 261; -pub const SYS_mq_open: ::c_long = 262; -pub const SYS_mq_unlink: ::c_long = 263; -pub const SYS_mq_timedsend: ::c_long = 264; -pub const SYS_mq_timedreceive: ::c_long = 265; -pub const SYS_mq_notify: ::c_long = 266; -pub const SYS_mq_getsetattr: ::c_long = 267; -pub const SYS_kexec_load: ::c_long = 268; -pub const SYS_add_key: ::c_long = 269; -pub const SYS_request_key: ::c_long = 270; -pub const SYS_keyctl: ::c_long = 271; -pub const SYS_waitid: ::c_long = 272; -pub const SYS_ioprio_set: ::c_long = 273; -pub const SYS_ioprio_get: ::c_long = 274; -pub const SYS_inotify_init: ::c_long = 275; -pub const SYS_inotify_add_watch: ::c_long = 276; -pub const SYS_inotify_rm_watch: ::c_long = 277; -pub const SYS_spu_run: ::c_long = 278; -pub const SYS_spu_create: ::c_long = 279; -pub const SYS_pselect6: ::c_long = 280; -pub const SYS_ppoll: ::c_long = 281; -pub const SYS_unshare: ::c_long = 282; -pub const SYS_splice: ::c_long = 283; -pub const SYS_tee: ::c_long = 284; -pub const SYS_vmsplice: ::c_long = 285; -pub const SYS_openat: ::c_long = 286; -pub const SYS_mkdirat: ::c_long = 287; -pub const SYS_mknodat: ::c_long = 288; -pub const SYS_fchownat: ::c_long = 289; -pub const SYS_futimesat: ::c_long = 290; -pub const SYS_newfstatat: ::c_long = 291; -pub const SYS_unlinkat: ::c_long = 292; -pub const SYS_renameat: ::c_long = 293; -pub const SYS_linkat: ::c_long = 294; -pub const SYS_symlinkat: ::c_long = 295; -pub const SYS_readlinkat: ::c_long = 296; -pub const SYS_fchmodat: ::c_long = 297; -pub const SYS_faccessat: ::c_long = 298; -pub const SYS_get_robust_list: ::c_long = 299; -pub const SYS_set_robust_list: ::c_long = 300; -pub const SYS_move_pages: ::c_long = 301; -pub const SYS_getcpu: ::c_long = 302; -pub const SYS_epoll_pwait: ::c_long = 303; -pub const SYS_utimensat: ::c_long = 304; -pub const SYS_signalfd: ::c_long = 305; -pub const SYS_timerfd_create: ::c_long = 306; -pub const SYS_eventfd: ::c_long = 307; -pub const SYS_sync_file_range2: ::c_long = 308; -pub const SYS_fallocate: ::c_long = 309; -pub const SYS_subpage_prot: ::c_long = 310; -pub const SYS_timerfd_settime: ::c_long = 311; -pub const SYS_timerfd_gettime: ::c_long = 312; -pub const SYS_signalfd4: ::c_long = 313; -pub const SYS_eventfd2: ::c_long = 314; -pub const SYS_epoll_create1: ::c_long = 315; -pub const SYS_dup3: ::c_long = 316; -pub const SYS_pipe2: ::c_long = 317; -pub const SYS_inotify_init1: ::c_long = 318; -pub const SYS_perf_event_open: ::c_long = 319; -pub const SYS_preadv: ::c_long = 320; -pub const SYS_pwritev: ::c_long = 321; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 322; -pub const SYS_fanotify_init: ::c_long = 323; -pub const SYS_fanotify_mark: ::c_long = 324; -pub const SYS_prlimit64: ::c_long = 325; -pub const SYS_socket: ::c_long = 326; -pub const SYS_bind: ::c_long = 327; -pub const SYS_connect: ::c_long = 328; -pub const SYS_listen: ::c_long = 329; -pub const SYS_accept: ::c_long = 330; -pub const SYS_getsockname: ::c_long = 331; -pub const SYS_getpeername: ::c_long = 332; -pub const SYS_socketpair: ::c_long = 333; -pub const SYS_send: ::c_long = 334; -pub const SYS_sendto: ::c_long = 335; -pub const SYS_recv: ::c_long = 336; -pub const SYS_recvfrom: ::c_long = 337; -pub const SYS_shutdown: ::c_long = 338; -pub const SYS_setsockopt: ::c_long = 339; -pub const SYS_getsockopt: ::c_long = 340; -pub const SYS_sendmsg: ::c_long = 341; -pub const SYS_recvmsg: ::c_long = 342; -pub const SYS_recvmmsg: ::c_long = 343; -pub const SYS_accept4: ::c_long = 344; -pub const SYS_name_to_handle_at: ::c_long = 345; -pub const SYS_open_by_handle_at: ::c_long = 346; -pub const SYS_clock_adjtime: ::c_long = 347; -pub const SYS_syncfs: ::c_long = 348; -pub const SYS_sendmmsg: ::c_long = 349; -pub const SYS_setns: ::c_long = 350; -pub const SYS_process_vm_readv: ::c_long = 351; -pub const SYS_process_vm_writev: ::c_long = 352; -pub const SYS_finit_module: ::c_long = 353; -pub const SYS_kcmp: ::c_long = 354; -pub const SYS_sched_setattr: ::c_long = 355; -pub const SYS_sched_getattr: ::c_long = 356; -pub const SYS_renameat2: ::c_long = 357; -pub const SYS_seccomp: ::c_long = 358; -pub const SYS_getrandom: ::c_long = 359; -pub const SYS_memfd_create: ::c_long = 360; -pub const SYS_bpf: ::c_long = 361; -pub const SYS_execveat: ::c_long = 362; -pub const SYS_switch_endian: ::c_long = 363; -pub const SYS_userfaultfd: ::c_long = 364; -pub const SYS_membarrier: ::c_long = 365; -pub const SYS_mlock2: ::c_long = 378; -pub const SYS_copy_file_range: ::c_long = 379; -pub const SYS_preadv2: ::c_long = 380; -pub const SYS_pwritev2: ::c_long = 381; -pub const SYS_kexec_file_load: ::c_long = 382; -pub const SYS_statx: ::c_long = 383; - -#[link(name = "util")] -extern "C" { - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs b/libc/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs deleted file mode 100644 index c45c5b2..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs +++ /dev/null @@ -1,861 +0,0 @@ -//! RISC-V-specific definitions for 64-bit linux-like values - -pub type c_char = u8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type wchar_t = ::c_int; -pub type time_t = ::c_long; - -pub type dev_t = ::c_ulong; -pub type uid_t = ::c_uint; -pub type gid_t = ::c_uint; -pub type ino_t = ::c_ulong; -pub type ino64_t = ::c_ulong; -pub type mode_t = ::c_uint; -pub type nlink_t = ::c_uint; -pub type off_t = ::c_long; -pub type off64_t = ::c_long; -pub type pid_t = ::c_int; -pub type blksize_t = ::c_int; -pub type blkcnt_t = ::c_long; -pub type fsblkcnt_t = ::c_ulong; -pub type fsblkcnt64_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; -pub type fsfilcnt64_t = ::c_ulong; -pub type suseconds_t = i64; -pub type __u64 = ::c_ulonglong; - -s! { - pub struct pthread_attr_t { - __size: [::c_ulong; 7], - } - - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: ::c_long, - } - - pub struct stat { - pub st_dev: dev_t, - pub st_ino: ino_t, - pub st_mode: mode_t, - pub st_nlink: nlink_t, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: dev_t, - pub __pad1: dev_t, - pub st_size: off_t, - pub st_blksize: blksize_t, - pub __pad2: ::c_int, - pub st_blocks: blkcnt_t, - pub st_atime: time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: ::c_long, - pub __unused: [::c_int; 2usize], - } - - pub struct stat64 { - pub st_dev: dev_t, - pub st_ino: ino64_t, - pub st_mode: mode_t, - pub st_nlink: nlink_t, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: dev_t, - pub __pad1: dev_t, - pub st_size: off64_t, - pub st_blksize: blksize_t, - pub __pad2: ::c_int, - pub st_blocks: blkcnt_t, - pub st_atime: time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: ::c_long, - pub __unused: [::c_int; 2], - } - - pub struct statfs { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_blocks: fsblkcnt_t, - pub f_bfree: fsblkcnt_t, - pub f_bavail: fsblkcnt_t, - pub f_files: fsfilcnt_t, - pub f_ffree: fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_long, - pub f_frsize: ::c_long, - pub f_flags: ::c_long, - pub f_spare: [::c_long; 4], - } - - pub struct statfs64 { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_blocks: fsblkcnt64_t, - pub f_bfree: fsblkcnt64_t, - pub f_bavail: fsblkcnt64_t, - pub f_files: fsfilcnt64_t, - pub f_ffree: fsfilcnt64_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_long, - pub f_frsize: ::c_long, - pub f_flags: ::c_long, - pub f_spare: [::c_long; 4], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: fsblkcnt_t, - pub f_bfree: fsblkcnt_t, - pub f_bavail: fsblkcnt_t, - pub f_files: fsfilcnt_t, - pub f_ffree: fsfilcnt_t, - pub f_favail: fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - pub __f_spare: [::c_int; 6], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: fsblkcnt64_t, - pub f_bfree: fsblkcnt64_t, - pub f_bavail: fsblkcnt64_t, - pub f_files: fsfilcnt64_t, - pub f_ffree: fsfilcnt64_t, - pub f_favail: fsfilcnt64_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - pub __f_spare: [::c_int; 6], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since="0.2.54", - note="Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [u64; 0], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t, - } - - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct sigset_t { - pub __val: [::c_ulong; 16], - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: uid_t, - pub gid: gid_t, - pub cuid: uid_t, - pub cgid: gid_t, - pub mode: ::c_ushort, - pub __pad1: ::c_ushort, - pub __seq: ::c_ushort, - pub __pad2: ::c_ushort, - pub __unused1: ::c_ulong, - pub __unused2: ::c_ulong, - } - - pub struct shmid_ds { - pub shm_perm: ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: time_t, - pub shm_dtime: time_t, - pub shm_ctime: time_t, - pub shm_cpid: pid_t, - pub shm_lpid: pid_t, - pub shm_nattch: ::shmatt_t, - pub __unused5: ::c_ulong, - pub __unused6: ::c_ulong, - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } -} - -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; -pub const VEOF: usize = 4; -pub const TIOCGSOFTCAR: ::c_ulong = 21529; -pub const TIOCSSOFTCAR: ::c_ulong = 21530; -pub const TIOCGRS485: ::c_int = 21550; -pub const TIOCSRS485: ::c_int = 21551; -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_FSYNC: ::c_int = 1052672; -pub const O_NOATIME: ::c_int = 262144; -pub const O_PATH: ::c_int = 2097152; -pub const O_TMPFILE: ::c_int = 4259840; -pub const MAP_GROWSDOWN: ::c_int = 256; -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EBADMSG: ::c_int = 74; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const EHWPOISON: ::c_int = 133; -pub const ERFKILL: ::c_int = 132; -pub const SOL_SOCKET: ::c_int = 1; -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_GET_FILTER: ::c_int = 26; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_PEERSEC: ::c_int = 31; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; -pub const SCM_TIMESTAMPNS: ::c_int = 35; -pub const SO_MARK: ::c_int = 36; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SCM_WIFI_STATUS: ::c_int = 41; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_BUSY_POLL: ::c_int = 46; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; -pub const SO_INCOMING_CPU: ::c_int = 49; -pub const SO_ATTACH_BPF: ::c_int = 50; -pub const SO_DETACH_BPF: ::c_int = 27; -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SA_ONSTACK: ::c_int = 134217728; -pub const SA_SIGINFO: ::c_int = 4; -pub const SA_NOCLDWAIT: ::c_int = 2; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0; -pub const SIG_UNBLOCK: ::c_int = 1; -pub const POLLWRNORM: ::c_short = 256; -pub const POLLWRBAND: ::c_short = 512; -pub const O_ASYNC: ::c_int = 8192; -pub const O_NDELAY: ::c_int = 2048; -pub const PTRACE_DETACH: ::c_uint = 17; -pub const EFD_NONBLOCK: ::c_int = 2048; -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; -pub const SFD_NONBLOCK: ::c_int = 2048; -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; -pub const TIOCLINUX: ::c_ulong = 21532; -pub const TIOCGSERIAL: ::c_ulong = 21534; -pub const TIOCEXCL: ::c_ulong = 21516; -pub const TIOCNXCL: ::c_ulong = 21517; -pub const TIOCSCTTY: ::c_ulong = 21518; -pub const TIOCSTI: ::c_ulong = 21522; -pub const TIOCMGET: ::c_ulong = 21525; -pub const TIOCMBIS: ::c_ulong = 21526; -pub const TIOCMBIC: ::c_ulong = 21527; -pub const TIOCMSET: ::c_ulong = 21528; -pub const TIOCCONS: ::c_ulong = 21533; -pub const TIOCM_ST: ::c_int = 8; -pub const TIOCM_SR: ::c_int = 16; -pub const TIOCM_CTS: ::c_int = 32; -pub const TIOCM_CAR: ::c_int = 64; -pub const TIOCM_RNG: ::c_int = 128; -pub const TIOCM_DSR: ::c_int = 256; -pub const SFD_CLOEXEC: ::c_int = 524288; -pub const NCCS: usize = 32; -pub const O_TRUNC: ::c_int = 512; -pub const O_CLOEXEC: ::c_int = 524288; -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; -pub const SA_NODEFER: ::c_int = 1073741824; -pub const SA_RESETHAND: ::c_int = -2147483648; -pub const SA_RESTART: ::c_int = 268435456; -pub const SA_NOCLDSTOP: ::c_int = 1; -pub const EPOLL_CLOEXEC: ::c_int = 524288; -pub const EFD_CLOEXEC: ::c_int = 524288; -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const O_DIRECT: ::c_int = 16384; -pub const O_DIRECTORY: ::c_int = 65536; -pub const O_NOFOLLOW: ::c_int = 131072; -pub const MAP_HUGETLB: ::c_int = 262144; -pub const MAP_LOCKED: ::c_int = 8192; -pub const MAP_NORESERVE: ::c_int = 16384; -pub const MAP_ANON: ::c_int = 32; -pub const MAP_ANONYMOUS: ::c_int = 32; -pub const MAP_DENYWRITE: ::c_int = 2048; -pub const MAP_EXECUTABLE: ::c_int = 4096; -pub const MAP_POPULATE: ::c_int = 32768; -pub const MAP_NONBLOCK: ::c_int = 65536; -pub const MAP_STACK: ::c_int = 131072; -pub const EDEADLOCK: ::c_int = 35; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const FIOCLEX: ::c_ulong = 21585; -pub const FIONCLEX: ::c_ulong = 21584; -pub const FIONBIO: ::c_ulong = 21537; -pub const MCL_CURRENT: ::c_int = 1; -pub const MCL_FUTURE: ::c_int = 2; -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; -pub const CBAUD: ::tcflag_t = 4111; -pub const TAB1: ::tcflag_t = 2048; -pub const TAB2: ::tcflag_t = 4096; -pub const TAB3: ::tcflag_t = 6144; -pub const CR1: ::tcflag_t = 512; -pub const CR2: ::tcflag_t = 1024; -pub const CR3: ::tcflag_t = 1536; -pub const FF1: ::tcflag_t = 32768; -pub const BS1: ::tcflag_t = 8192; -pub const VT1: ::tcflag_t = 16384; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 1024; -pub const IXOFF: ::tcflag_t = 4096; -pub const ONLCR: ::tcflag_t = 4; -pub const CSIZE: ::tcflag_t = 48; -pub const CS6: ::tcflag_t = 16; -pub const CS7: ::tcflag_t = 32; -pub const CS8: ::tcflag_t = 48; -pub const CSTOPB: ::tcflag_t = 64; -pub const CREAD: ::tcflag_t = 128; -pub const PARENB: ::tcflag_t = 256; -pub const PARODD: ::tcflag_t = 512; -pub const HUPCL: ::tcflag_t = 1024; -pub const CLOCAL: ::tcflag_t = 2048; -pub const ECHOKE: ::tcflag_t = 2048; -pub const ECHOE: ::tcflag_t = 16; -pub const ECHOK: ::tcflag_t = 32; -pub const ECHONL: ::tcflag_t = 64; -pub const ECHOPRT: ::tcflag_t = 1024; -pub const ECHOCTL: ::tcflag_t = 512; -pub const ISIG: ::tcflag_t = 1; -pub const ICANON: ::tcflag_t = 2; -pub const PENDIN: ::tcflag_t = 16384; -pub const NOFLSH: ::tcflag_t = 128; -pub const CIBAUD: ::tcflag_t = 269418496; -pub const CBAUDEX: ::tcflag_t = 4096; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 2; -pub const NLDLY: ::tcflag_t = 256; -pub const CRDLY: ::tcflag_t = 1536; -pub const TABDLY: ::tcflag_t = 6144; -pub const BSDLY: ::tcflag_t = 8192; -pub const FFDLY: ::tcflag_t = 32768; -pub const VTDLY: ::tcflag_t = 16384; -pub const XTABS: ::tcflag_t = 6144; -pub const B0: ::speed_t = 0; -pub const B50: ::speed_t = 1; -pub const B75: ::speed_t = 2; -pub const B110: ::speed_t = 3; -pub const B134: ::speed_t = 4; -pub const B150: ::speed_t = 5; -pub const B200: ::speed_t = 6; -pub const B300: ::speed_t = 7; -pub const B600: ::speed_t = 8; -pub const B1200: ::speed_t = 9; -pub const B1800: ::speed_t = 10; -pub const B2400: ::speed_t = 11; -pub const B4800: ::speed_t = 12; -pub const B9600: ::speed_t = 13; -pub const B19200: ::speed_t = 14; -pub const B38400: ::speed_t = 15; -pub const EXTA: ::speed_t = 14; -pub const EXTB: ::speed_t = 15; -pub const B57600: ::speed_t = 4097; -pub const B115200: ::speed_t = 4098; -pub const B230400: ::speed_t = 4099; -pub const B460800: ::speed_t = 4100; -pub const B500000: ::speed_t = 4101; -pub const B576000: ::speed_t = 4102; -pub const B921600: ::speed_t = 4103; -pub const B1000000: ::speed_t = 4104; -pub const B1152000: ::speed_t = 4105; -pub const B1500000: ::speed_t = 4106; -pub const B2000000: ::speed_t = 4107; -pub const B2500000: ::speed_t = 4108; -pub const B3000000: ::speed_t = 4109; -pub const B3500000: ::speed_t = 4110; -pub const B4000000: ::speed_t = 4111; -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 32768; -pub const TOSTOP: ::tcflag_t = 256; -pub const FLUSHO: ::tcflag_t = 4096; -pub const EXTPROC: ::tcflag_t = 65536; -pub const TCGETS: ::c_ulong = 21505; -pub const TCSETS: ::c_ulong = 21506; -pub const TCSETSW: ::c_ulong = 21507; -pub const TCSETSF: ::c_ulong = 21508; -pub const TCGETA: ::c_ulong = 21509; -pub const TCSETA: ::c_ulong = 21510; -pub const TCSETAW: ::c_ulong = 21511; -pub const TCSETAF: ::c_ulong = 21512; -pub const TCSBRK: ::c_ulong = 21513; -pub const TCXONC: ::c_ulong = 21514; -pub const TCFLSH: ::c_ulong = 21515; -pub const TIOCINQ: ::c_ulong = 21531; -pub const TIOCGPGRP: ::c_ulong = 21519; -pub const TIOCSPGRP: ::c_ulong = 21520; -pub const TIOCOUTQ: ::c_ulong = 21521; -pub const TIOCGWINSZ: ::c_ulong = 21523; -pub const TIOCSWINSZ: ::c_ulong = 21524; -pub const FIONREAD: ::c_ulong = 21531; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; -pub const SYS_read: ::c_long = 63; -pub const SYS_write: ::c_long = 64; -pub const SYS_close: ::c_long = 57; -pub const SYS_fstat: ::c_long = 80; -pub const SYS_lseek: ::c_long = 62; -pub const SYS_mmap: ::c_long = 222; -pub const SYS_mprotect: ::c_long = 226; -pub const SYS_munmap: ::c_long = 215; -pub const SYS_brk: ::c_long = 214; -pub const SYS_rt_sigaction: ::c_long = 134; -pub const SYS_rt_sigprocmask: ::c_long = 135; -pub const SYS_rt_sigreturn: ::c_long = 139; -pub const SYS_ioctl: ::c_long = 29; -pub const SYS_pread64: ::c_long = 67; -pub const SYS_pwrite64: ::c_long = 68; -pub const SYS_readv: ::c_long = 65; -pub const SYS_writev: ::c_long = 66; -pub const SYS_sched_yield: ::c_long = 124; -pub const SYS_mremap: ::c_long = 216; -pub const SYS_msync: ::c_long = 227; -pub const SYS_mincore: ::c_long = 232; -pub const SYS_madvise: ::c_long = 233; -pub const SYS_shmget: ::c_long = 194; -pub const SYS_shmat: ::c_long = 196; -pub const SYS_shmctl: ::c_long = 195; -pub const SYS_dup: ::c_long = 23; -pub const SYS_nanosleep: ::c_long = 101; -pub const SYS_getitimer: ::c_long = 102; -pub const SYS_setitimer: ::c_long = 103; -pub const SYS_getpid: ::c_long = 172; -pub const SYS_sendfile: ::c_long = 71; -pub const SYS_socket: ::c_long = 198; -pub const SYS_connect: ::c_long = 203; -pub const SYS_accept: ::c_long = 202; -pub const SYS_sendto: ::c_long = 206; -pub const SYS_recvfrom: ::c_long = 207; -pub const SYS_sendmsg: ::c_long = 211; -pub const SYS_recvmsg: ::c_long = 212; -pub const SYS_shutdown: ::c_long = 210; -pub const SYS_bind: ::c_long = 200; -pub const SYS_listen: ::c_long = 201; -pub const SYS_getsockname: ::c_long = 204; -pub const SYS_getpeername: ::c_long = 205; -pub const SYS_socketpair: ::c_long = 199; -pub const SYS_setsockopt: ::c_long = 208; -pub const SYS_getsockopt: ::c_long = 209; -pub const SYS_clone: ::c_long = 220; -pub const SYS_execve: ::c_long = 221; -pub const SYS_exit: ::c_long = 93; -pub const SYS_wait4: ::c_long = 260; -pub const SYS_kill: ::c_long = 129; -pub const SYS_uname: ::c_long = 160; -pub const SYS_semget: ::c_long = 190; -pub const SYS_semop: ::c_long = 193; -pub const SYS_semctl: ::c_long = 191; -pub const SYS_shmdt: ::c_long = 197; -pub const SYS_msgget: ::c_long = 186; -pub const SYS_msgsnd: ::c_long = 189; -pub const SYS_msgrcv: ::c_long = 188; -pub const SYS_msgctl: ::c_long = 187; -pub const SYS_fcntl: ::c_long = 25; -pub const SYS_flock: ::c_long = 32; -pub const SYS_fsync: ::c_long = 82; -pub const SYS_fdatasync: ::c_long = 83; -pub const SYS_truncate: ::c_long = 45; -pub const SYS_ftruncate: ::c_long = 46; -pub const SYS_getcwd: ::c_long = 17; -pub const SYS_chdir: ::c_long = 49; -pub const SYS_fchdir: ::c_long = 50; -pub const SYS_fchmod: ::c_long = 52; -pub const SYS_fchown: ::c_long = 55; -pub const SYS_umask: ::c_long = 166; -pub const SYS_gettimeofday: ::c_long = 169; -pub const SYS_getrlimit: ::c_long = 163; -pub const SYS_getrusage: ::c_long = 165; -pub const SYS_sysinfo: ::c_long = 179; -pub const SYS_times: ::c_long = 153; -pub const SYS_ptrace: ::c_long = 117; -pub const SYS_getuid: ::c_long = 174; -pub const SYS_syslog: ::c_long = 116; -pub const SYS_getgid: ::c_long = 176; -pub const SYS_setuid: ::c_long = 146; -pub const SYS_setgid: ::c_long = 144; -pub const SYS_geteuid: ::c_long = 175; -pub const SYS_getegid: ::c_long = 177; -pub const SYS_setpgid: ::c_long = 154; -pub const SYS_getppid: ::c_long = 173; -pub const SYS_setsid: ::c_long = 157; -pub const SYS_setreuid: ::c_long = 145; -pub const SYS_setregid: ::c_long = 143; -pub const SYS_getgroups: ::c_long = 158; -pub const SYS_setgroups: ::c_long = 159; -pub const SYS_setresuid: ::c_long = 147; -pub const SYS_getresuid: ::c_long = 148; -pub const SYS_setresgid: ::c_long = 149; -pub const SYS_getresgid: ::c_long = 150; -pub const SYS_getpgid: ::c_long = 155; -pub const SYS_setfsuid: ::c_long = 151; -pub const SYS_setfsgid: ::c_long = 152; -pub const SYS_getsid: ::c_long = 156; -pub const SYS_capget: ::c_long = 90; -pub const SYS_capset: ::c_long = 91; -pub const SYS_rt_sigpending: ::c_long = 136; -pub const SYS_rt_sigtimedwait: ::c_long = 137; -pub const SYS_rt_sigqueueinfo: ::c_long = 138; -pub const SYS_rt_sigsuspend: ::c_long = 133; -pub const SYS_sigaltstack: ::c_long = 132; -pub const SYS_personality: ::c_long = 92; -pub const SYS_statfs: ::c_long = 43; -pub const SYS_fstatfs: ::c_long = 44; -pub const SYS_getpriority: ::c_long = 141; -pub const SYS_setpriority: ::c_long = 140; -pub const SYS_sched_setparam: ::c_long = 118; -pub const SYS_sched_getparam: ::c_long = 121; -pub const SYS_sched_setscheduler: ::c_long = 119; -pub const SYS_sched_getscheduler: ::c_long = 120; -pub const SYS_sched_get_priority_max: ::c_long = 125; -pub const SYS_sched_get_priority_min: ::c_long = 126; -pub const SYS_sched_rr_get_interval: ::c_long = 127; -pub const SYS_mlock: ::c_long = 228; -pub const SYS_munlock: ::c_long = 229; -pub const SYS_mlockall: ::c_long = 230; -pub const SYS_munlockall: ::c_long = 231; -pub const SYS_vhangup: ::c_long = 58; -pub const SYS_pivot_root: ::c_long = 41; -pub const SYS_prctl: ::c_long = 167; -pub const SYS_adjtimex: ::c_long = 171; -pub const SYS_setrlimit: ::c_long = 164; -pub const SYS_chroot: ::c_long = 51; -pub const SYS_sync: ::c_long = 81; -pub const SYS_acct: ::c_long = 89; -pub const SYS_settimeofday: ::c_long = 170; -pub const SYS_mount: ::c_long = 40; -pub const SYS_umount2: ::c_long = 39; -pub const SYS_swapon: ::c_long = 224; -pub const SYS_swapoff: ::c_long = 225; -pub const SYS_reboot: ::c_long = 142; -pub const SYS_sethostname: ::c_long = 161; -pub const SYS_setdomainname: ::c_long = 162; -pub const SYS_init_module: ::c_long = 105; -pub const SYS_delete_module: ::c_long = 106; -pub const SYS_quotactl: ::c_long = 60; -pub const SYS_nfsservctl: ::c_long = 42; -pub const SYS_gettid: ::c_long = 178; -pub const SYS_readahead: ::c_long = 213; -pub const SYS_setxattr: ::c_long = 5; -pub const SYS_lsetxattr: ::c_long = 6; -pub const SYS_fsetxattr: ::c_long = 7; -pub const SYS_getxattr: ::c_long = 8; -pub const SYS_lgetxattr: ::c_long = 9; -pub const SYS_fgetxattr: ::c_long = 10; -pub const SYS_listxattr: ::c_long = 11; -pub const SYS_llistxattr: ::c_long = 12; -pub const SYS_flistxattr: ::c_long = 13; -pub const SYS_removexattr: ::c_long = 14; -pub const SYS_lremovexattr: ::c_long = 15; -pub const SYS_fremovexattr: ::c_long = 16; -pub const SYS_tkill: ::c_long = 130; -pub const SYS_futex: ::c_long = 98; -pub const SYS_sched_setaffinity: ::c_long = 122; -pub const SYS_sched_getaffinity: ::c_long = 123; -pub const SYS_io_setup: ::c_long = 0; -pub const SYS_io_destroy: ::c_long = 1; -pub const SYS_io_getevents: ::c_long = 4; -pub const SYS_io_submit: ::c_long = 2; -pub const SYS_io_cancel: ::c_long = 3; -pub const SYS_lookup_dcookie: ::c_long = 18; -pub const SYS_remap_file_pages: ::c_long = 234; -pub const SYS_getdents64: ::c_long = 61; -pub const SYS_set_tid_address: ::c_long = 96; -pub const SYS_restart_syscall: ::c_long = 128; -pub const SYS_semtimedop: ::c_long = 192; -pub const SYS_fadvise64: ::c_long = 223; -pub const SYS_timer_create: ::c_long = 107; -pub const SYS_timer_settime: ::c_long = 110; -pub const SYS_timer_gettime: ::c_long = 108; -pub const SYS_timer_getoverrun: ::c_long = 109; -pub const SYS_timer_delete: ::c_long = 111; -pub const SYS_clock_settime: ::c_long = 112; -pub const SYS_clock_gettime: ::c_long = 113; -pub const SYS_clock_getres: ::c_long = 114; -pub const SYS_clock_nanosleep: ::c_long = 115; -pub const SYS_exit_group: ::c_long = 94; -pub const SYS_epoll_ctl: ::c_long = 21; -pub const SYS_tgkill: ::c_long = 131; -pub const SYS_mbind: ::c_long = 235; -pub const SYS_set_mempolicy: ::c_long = 237; -pub const SYS_get_mempolicy: ::c_long = 236; -pub const SYS_mq_open: ::c_long = 180; -pub const SYS_mq_unlink: ::c_long = 181; -pub const SYS_mq_timedsend: ::c_long = 182; -pub const SYS_mq_timedreceive: ::c_long = 183; -pub const SYS_mq_notify: ::c_long = 184; -pub const SYS_mq_getsetattr: ::c_long = 185; -pub const SYS_kexec_load: ::c_long = 104; -pub const SYS_waitid: ::c_long = 95; -pub const SYS_add_key: ::c_long = 217; -pub const SYS_request_key: ::c_long = 218; -pub const SYS_keyctl: ::c_long = 219; -pub const SYS_ioprio_set: ::c_long = 30; -pub const SYS_ioprio_get: ::c_long = 31; -pub const SYS_inotify_add_watch: ::c_long = 27; -pub const SYS_inotify_rm_watch: ::c_long = 28; -pub const SYS_migrate_pages: ::c_long = 238; -pub const SYS_openat: ::c_long = 56; -pub const SYS_mkdirat: ::c_long = 34; -pub const SYS_mknodat: ::c_long = 33; -pub const SYS_fchownat: ::c_long = 54; -pub const SYS_newfstatat: ::c_long = 79; -pub const SYS_unlinkat: ::c_long = 35; -pub const SYS_linkat: ::c_long = 37; -pub const SYS_symlinkat: ::c_long = 36; -pub const SYS_readlinkat: ::c_long = 78; -pub const SYS_fchmodat: ::c_long = 53; -pub const SYS_faccessat: ::c_long = 48; -pub const SYS_pselect6: ::c_long = 72; -pub const SYS_ppoll: ::c_long = 73; -pub const SYS_unshare: ::c_long = 97; -pub const SYS_set_robust_list: ::c_long = 99; -pub const SYS_get_robust_list: ::c_long = 100; -pub const SYS_splice: ::c_long = 76; -pub const SYS_tee: ::c_long = 77; -pub const SYS_sync_file_range: ::c_long = 84; -pub const SYS_vmsplice: ::c_long = 75; -pub const SYS_move_pages: ::c_long = 239; -pub const SYS_utimensat: ::c_long = 88; -pub const SYS_epoll_pwait: ::c_long = 22; -pub const SYS_timerfd_create: ::c_long = 85; -pub const SYS_fallocate: ::c_long = 47; -pub const SYS_timerfd_settime: ::c_long = 86; -pub const SYS_timerfd_gettime: ::c_long = 87; -pub const SYS_accept4: ::c_long = 242; -pub const SYS_signalfd4: ::c_long = 74; -pub const SYS_eventfd2: ::c_long = 19; -pub const SYS_epoll_create1: ::c_long = 20; -pub const SYS_dup3: ::c_long = 24; -pub const SYS_pipe2: ::c_long = 59; -pub const SYS_inotify_init1: ::c_long = 26; -pub const SYS_preadv: ::c_long = 69; -pub const SYS_pwritev: ::c_long = 70; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 240; -pub const SYS_perf_event_open: ::c_long = 241; -pub const SYS_recvmmsg: ::c_long = 243; -pub const SYS_fanotify_init: ::c_long = 262; -pub const SYS_fanotify_mark: ::c_long = 263; -pub const SYS_prlimit64: ::c_long = 261; -pub const SYS_name_to_handle_at: ::c_long = 264; -pub const SYS_open_by_handle_at: ::c_long = 265; -pub const SYS_clock_adjtime: ::c_long = 266; -pub const SYS_syncfs: ::c_long = 267; -pub const SYS_sendmmsg: ::c_long = 269; -pub const SYS_setns: ::c_long = 268; -pub const SYS_getcpu: ::c_long = 168; -pub const SYS_process_vm_readv: ::c_long = 270; -pub const SYS_process_vm_writev: ::c_long = 271; -pub const SYS_kcmp: ::c_long = 272; -pub const SYS_finit_module: ::c_long = 273; -pub const SYS_sched_setattr: ::c_long = 274; -pub const SYS_sched_getattr: ::c_long = 275; -pub const SYS_renameat2: ::c_long = 276; -pub const SYS_seccomp: ::c_long = 277; -pub const SYS_getrandom: ::c_long = 278; -pub const SYS_memfd_create: ::c_long = 279; -pub const SYS_bpf: ::c_long = 280; -pub const SYS_execveat: ::c_long = 281; -pub const SYS_userfaultfd: ::c_long = 282; -pub const SYS_membarrier: ::c_long = 283; -pub const SYS_mlock2: ::c_long = 284; -pub const SYS_copy_file_range: ::c_long = 285; -pub const SYS_preadv2: ::c_long = 286; -pub const SYS_pwritev2: ::c_long = 287; -pub const SYS_pkey_mprotect: ::c_long = 288; -pub const SYS_pkey_alloc: ::c_long = 289; -pub const SYS_pkey_free: ::c_long = 290; -pub const SYS_statx: ::c_long = 291; diff --git a/libc/src/unix/linux_like/linux/gnu/b64/s390x.rs b/libc/src/unix/linux_like/linux/gnu/b64/s390x.rs deleted file mode 100644 index cf0612a..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/s390x.rs +++ /dev/null @@ -1,1029 +0,0 @@ -//! s390x - -use pthread_mutex_t; - -pub type blksize_t = i64; -pub type c_char = u8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type nlink_t = u64; -pub type suseconds_t = i64; -pub type wchar_t = i32; -pub type greg_t = u64; -pub type __u64 = u64; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - __glibc_reserved0: ::c_int, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - pub sa_mask: ::sigset_t, - } - - pub struct statfs { - pub f_type: ::c_uint, - pub f_bsize: ::c_uint, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_uint, - pub f_frsize: ::c_uint, - pub f_flags: ::c_uint, - f_spare: [::c_uint; 4], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - _pad: ::c_int, - _pad2: [::c_long; 14], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - st_pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - __glibc_reserved: [::c_long; 3], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - st_pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - __glibc_reserved: [::c_long; 3], - } - - pub struct pthread_attr_t { - __size: [::c_ulong; 7] - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_ushort, - __pad1: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct __psw_t { - pub mask: u64, - pub addr: u64, - } - - pub struct fpregset_t { - pub fpc: u32, - __pad: u32, - pub fprs: [fpreg_t; 16], - } - - pub struct mcontext_t { - pub psw: __psw_t, - pub gregs: [u64; 16], - pub aregs: [u32; 16], - pub fpregs: fpregset_t, - } - - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - } - - pub struct statfs64 { - pub f_type: ::c_uint, - pub f_bsize: ::c_uint, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_uint, - pub f_frsize: ::c_uint, - pub f_flags: ::c_uint, - pub f_spare: [::c_uint; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } -} - -s_no_extra_traits! { - // FIXME: This is actually a union. - pub struct fpreg_t { - pub d: ::c_double, - // f: ::c_float, - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for fpreg_t { - fn eq(&self, other: &fpreg_t) -> bool { - self.d == other.d - } - } - - impl Eq for fpreg_t {} - - impl ::fmt::Debug for fpreg_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("fpreg_t") - .field("d", &self.d) - .finish() - } - } - - impl ::hash::Hash for fpreg_t { - fn hash(&self, state: &mut H) { - let d: u64 = unsafe { ::mem::transmute(self.d) }; - d.hash(state); - } - } - } -} - -pub const POSIX_FADV_DONTNEED: ::c_int = 6; -pub const POSIX_FADV_NOREUSE: ::c_int = 7; - -pub const VEOF: usize = 4; -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; -pub const O_NOATIME: ::c_int = 0o1000000; -pub const O_CLOEXEC: ::c_int = 0x80000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; - -align_const! { - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; -} - -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNREFUSED: ::c_int = 111; -pub const ECONNRESET: ::c_int = 104; -pub const EDEADLK: ::c_int = 35; -pub const ENOSYS: ::c_int = 38; -pub const ENOTCONN: ::c_int = 107; -pub const ETIMEDOUT: ::c_int = 110; -pub const FIOCLEX: ::c_ulong = 0x5451; -pub const FIONCLEX: ::c_ulong = 0x5450; -pub const FIONBIO: ::c_ulong = 0x5421; -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NONBLOCK: ::c_int = 2048; -pub const SA_NOCLDWAIT: ::c_int = 2; -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 4; -pub const SIGBUS: ::c_int = 7; -pub const SIGSTKSZ: ::size_t = 0x2000; -pub const MINSIGSTKSZ: ::size_t = 2048; -pub const SIG_SETMASK: ::c_int = 2; -pub const SOL_SOCKET: ::c_int = 1; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_ERROR: ::c_int = 4; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_MARK: ::c_int = 36; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_BUSY_POLL: ::c_int = 46; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 6; - -pub const O_NOCTTY: ::c_int = 256; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_FSYNC: ::c_int = 0x101000; -pub const O_DIRECT: ::c_int = 0x4000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const EDEADLOCK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EBADMSG: ::c_int = 74; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const EHWPOISON: ::c_int = 133; -pub const ERFKILL: ::c_int = 132; - -pub const SO_TYPE: ::c_int = 3; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; - -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGCHLD: ::c_int = 17; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = 31; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_NDELAY: ::c_int = 0x800; - -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; - -pub const EXTPROC: ::tcflag_t = 0x00010000; - -pub const PTRACE_DETACH: ::c_uint = 17; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const EFD_NONBLOCK: ::c_int = 0x800; - -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -pub const SFD_NONBLOCK: ::c_int = 0x0800; - -pub const TCGETS: ::c_ulong = 0x5401; -pub const TCSETS: ::c_ulong = 0x5402; -pub const TCSETSW: ::c_ulong = 0x5403; -pub const TCSETSF: ::c_ulong = 0x5404; -pub const TCGETA: ::c_ulong = 0x5405; -pub const TCSETA: ::c_ulong = 0x5406; -pub const TCSETAW: ::c_ulong = 0x5407; -pub const TCSETAF: ::c_ulong = 0x5408; -pub const TCSBRK: ::c_ulong = 0x5409; -pub const TCXONC: ::c_ulong = 0x540A; -pub const TCFLSH: ::c_ulong = 0x540B; -pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; -pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; -pub const TIOCINQ: ::c_ulong = 0x541B; -pub const TIOCEXCL: ::c_ulong = 0x540C; -pub const TIOCNXCL: ::c_ulong = 0x540D; -pub const TIOCSCTTY: ::c_ulong = 0x540E; -pub const TIOCGPGRP: ::c_ulong = 0x540F; -pub const TIOCSPGRP: ::c_ulong = 0x5410; -pub const TIOCOUTQ: ::c_ulong = 0x5411; -pub const TIOCSTI: ::c_ulong = 0x5412; -pub const TIOCGWINSZ: ::c_ulong = 0x5413; -pub const TIOCSWINSZ: ::c_ulong = 0x5414; -pub const TIOCMGET: ::c_ulong = 0x5415; -pub const TIOCMBIS: ::c_ulong = 0x5416; -pub const TIOCMBIC: ::c_ulong = 0x5417; -pub const TIOCMSET: ::c_ulong = 0x5418; -pub const FIONREAD: ::c_ulong = 0x541B; -pub const TIOCCONS: ::c_ulong = 0x541D; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -pub const VTIME: usize = 5; -pub const VSWTC: usize = 7; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VSUSP: usize = 10; -pub const VREPRINT: usize = 12; -pub const VDISCARD: usize = 13; -pub const VWERASE: usize = 14; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const ONLCR: ::tcflag_t = 0o000004; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const FF1: ::tcflag_t = 0x00008000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const CBAUD: ::speed_t = 0o010017; -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const CSIZE: ::tcflag_t = 0o000060; -pub const CS6: ::tcflag_t = 0o000020; -pub const CS7: ::tcflag_t = 0o000040; -pub const CS8: ::tcflag_t = 0o000060; -pub const CSTOPB: ::tcflag_t = 0o000100; -pub const CREAD: ::tcflag_t = 0o000200; -pub const PARENB: ::tcflag_t = 0o000400; -pub const PARODD: ::tcflag_t = 0o001000; -pub const HUPCL: ::tcflag_t = 0o002000; -pub const CLOCAL: ::tcflag_t = 0o004000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; -pub const CIBAUD: ::tcflag_t = 0o02003600000; - -pub const ISIG: ::tcflag_t = 0o000001; -pub const ICANON: ::tcflag_t = 0o000002; -pub const XCASE: ::tcflag_t = 0o000004; -pub const ECHOE: ::tcflag_t = 0o000020; -pub const ECHOK: ::tcflag_t = 0o000040; -pub const ECHONL: ::tcflag_t = 0o000100; -pub const NOFLSH: ::tcflag_t = 0o000200; -pub const ECHOCTL: ::tcflag_t = 0o001000; -pub const ECHOPRT: ::tcflag_t = 0o002000; -pub const ECHOKE: ::tcflag_t = 0o004000; -pub const PENDIN: ::tcflag_t = 0o040000; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const IXON: ::tcflag_t = 0o002000; -pub const IXOFF: ::tcflag_t = 0o010000; - -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_restart_syscall: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_umount: ::c_long = 22; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_brk: ::c_long = 45; -pub const SYS_signal: ::c_long = 48; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_readdir: ::c_long = 89; -pub const SYS_mmap: ::c_long = 90; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_socketcall: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_lookup_dcookie: ::c_long = 110; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_idle: ::c_long = 112; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_ipc: ::c_long = 117; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_create_module: ::c_long = 127; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_get_kernel_syms: ::c_long = 130; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_afs_syscall: ::c_long = 137; /* Syscall for Andrew File System */ -pub const SYS_getdents: ::c_long = 141; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_query_module: ::c_long = 167; -pub const SYS_poll: ::c_long = 168; -pub const SYS_nfsservctl: ::c_long = 169; -pub const SYS_prctl: ::c_long = 172; -pub const SYS_rt_sigreturn: ::c_long = 173; -pub const SYS_rt_sigaction: ::c_long = 174; -pub const SYS_rt_sigprocmask: ::c_long = 175; -pub const SYS_rt_sigpending: ::c_long = 176; -pub const SYS_rt_sigtimedwait: ::c_long = 177; -pub const SYS_rt_sigqueueinfo: ::c_long = 178; -pub const SYS_rt_sigsuspend: ::c_long = 179; -pub const SYS_pread64: ::c_long = 180; -pub const SYS_pwrite64: ::c_long = 181; -pub const SYS_getcwd: ::c_long = 183; -pub const SYS_capget: ::c_long = 184; -pub const SYS_capset: ::c_long = 185; -pub const SYS_sigaltstack: ::c_long = 186; -pub const SYS_sendfile: ::c_long = 187; -pub const SYS_getpmsg: ::c_long = 188; -pub const SYS_putpmsg: ::c_long = 189; -pub const SYS_vfork: ::c_long = 190; -pub const SYS_pivot_root: ::c_long = 217; -pub const SYS_mincore: ::c_long = 218; -pub const SYS_madvise: ::c_long = 219; -pub const SYS_getdents64: ::c_long = 220; -pub const SYS_readahead: ::c_long = 222; -pub const SYS_setxattr: ::c_long = 224; -pub const SYS_lsetxattr: ::c_long = 225; -pub const SYS_fsetxattr: ::c_long = 226; -pub const SYS_getxattr: ::c_long = 227; -pub const SYS_lgetxattr: ::c_long = 228; -pub const SYS_fgetxattr: ::c_long = 229; -pub const SYS_listxattr: ::c_long = 230; -pub const SYS_llistxattr: ::c_long = 231; -pub const SYS_flistxattr: ::c_long = 232; -pub const SYS_removexattr: ::c_long = 233; -pub const SYS_lremovexattr: ::c_long = 234; -pub const SYS_fremovexattr: ::c_long = 235; -pub const SYS_gettid: ::c_long = 236; -pub const SYS_tkill: ::c_long = 237; -pub const SYS_futex: ::c_long = 238; -pub const SYS_sched_setaffinity: ::c_long = 239; -pub const SYS_sched_getaffinity: ::c_long = 240; -pub const SYS_tgkill: ::c_long = 241; -pub const SYS_io_setup: ::c_long = 243; -pub const SYS_io_destroy: ::c_long = 244; -pub const SYS_io_getevents: ::c_long = 245; -pub const SYS_io_submit: ::c_long = 246; -pub const SYS_io_cancel: ::c_long = 247; -pub const SYS_exit_group: ::c_long = 248; -pub const SYS_epoll_create: ::c_long = 249; -pub const SYS_epoll_ctl: ::c_long = 250; -pub const SYS_epoll_wait: ::c_long = 251; -pub const SYS_set_tid_address: ::c_long = 252; -pub const SYS_fadvise64: ::c_long = 253; -pub const SYS_timer_create: ::c_long = 254; -pub const SYS_timer_settime: ::c_long = 255; -pub const SYS_timer_gettime: ::c_long = 256; -pub const SYS_timer_getoverrun: ::c_long = 257; -pub const SYS_timer_delete: ::c_long = 258; -pub const SYS_clock_settime: ::c_long = 259; -pub const SYS_clock_gettime: ::c_long = 260; -pub const SYS_clock_getres: ::c_long = 261; -pub const SYS_clock_nanosleep: ::c_long = 262; -pub const SYS_statfs64: ::c_long = 265; -pub const SYS_fstatfs64: ::c_long = 266; -pub const SYS_remap_file_pages: ::c_long = 267; -pub const SYS_mbind: ::c_long = 268; -pub const SYS_get_mempolicy: ::c_long = 269; -pub const SYS_set_mempolicy: ::c_long = 270; -pub const SYS_mq_open: ::c_long = 271; -pub const SYS_mq_unlink: ::c_long = 272; -pub const SYS_mq_timedsend: ::c_long = 273; -pub const SYS_mq_timedreceive: ::c_long = 274; -pub const SYS_mq_notify: ::c_long = 275; -pub const SYS_mq_getsetattr: ::c_long = 276; -pub const SYS_kexec_load: ::c_long = 277; -pub const SYS_add_key: ::c_long = 278; -pub const SYS_request_key: ::c_long = 279; -pub const SYS_keyctl: ::c_long = 280; -pub const SYS_waitid: ::c_long = 281; -pub const SYS_ioprio_set: ::c_long = 282; -pub const SYS_ioprio_get: ::c_long = 283; -pub const SYS_inotify_init: ::c_long = 284; -pub const SYS_inotify_add_watch: ::c_long = 285; -pub const SYS_inotify_rm_watch: ::c_long = 286; -pub const SYS_migrate_pages: ::c_long = 287; -pub const SYS_openat: ::c_long = 288; -pub const SYS_mkdirat: ::c_long = 289; -pub const SYS_mknodat: ::c_long = 290; -pub const SYS_fchownat: ::c_long = 291; -pub const SYS_futimesat: ::c_long = 292; -pub const SYS_unlinkat: ::c_long = 294; -pub const SYS_renameat: ::c_long = 295; -pub const SYS_linkat: ::c_long = 296; -pub const SYS_symlinkat: ::c_long = 297; -pub const SYS_readlinkat: ::c_long = 298; -pub const SYS_fchmodat: ::c_long = 299; -pub const SYS_faccessat: ::c_long = 300; -pub const SYS_pselect6: ::c_long = 301; -pub const SYS_ppoll: ::c_long = 302; -pub const SYS_unshare: ::c_long = 303; -pub const SYS_set_robust_list: ::c_long = 304; -pub const SYS_get_robust_list: ::c_long = 305; -pub const SYS_splice: ::c_long = 306; -pub const SYS_sync_file_range: ::c_long = 307; -pub const SYS_tee: ::c_long = 308; -pub const SYS_vmsplice: ::c_long = 309; -pub const SYS_move_pages: ::c_long = 310; -pub const SYS_getcpu: ::c_long = 311; -pub const SYS_epoll_pwait: ::c_long = 312; -pub const SYS_utimes: ::c_long = 313; -pub const SYS_fallocate: ::c_long = 314; -pub const SYS_utimensat: ::c_long = 315; -pub const SYS_signalfd: ::c_long = 316; -pub const SYS_timerfd: ::c_long = 317; -pub const SYS_eventfd: ::c_long = 318; -pub const SYS_timerfd_create: ::c_long = 319; -pub const SYS_timerfd_settime: ::c_long = 320; -pub const SYS_timerfd_gettime: ::c_long = 321; -pub const SYS_signalfd4: ::c_long = 322; -pub const SYS_eventfd2: ::c_long = 323; -pub const SYS_inotify_init1: ::c_long = 324; -pub const SYS_pipe2: ::c_long = 325; -pub const SYS_dup3: ::c_long = 326; -pub const SYS_epoll_create1: ::c_long = 327; -pub const SYS_preadv: ::c_long = 328; -pub const SYS_pwritev: ::c_long = 329; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 330; -pub const SYS_perf_event_open: ::c_long = 331; -pub const SYS_fanotify_init: ::c_long = 332; -pub const SYS_fanotify_mark: ::c_long = 333; -pub const SYS_prlimit64: ::c_long = 334; -pub const SYS_name_to_handle_at: ::c_long = 335; -pub const SYS_open_by_handle_at: ::c_long = 336; -pub const SYS_clock_adjtime: ::c_long = 337; -pub const SYS_syncfs: ::c_long = 338; -pub const SYS_setns: ::c_long = 339; -pub const SYS_process_vm_readv: ::c_long = 340; -pub const SYS_process_vm_writev: ::c_long = 341; -pub const SYS_s390_runtime_instr: ::c_long = 342; -pub const SYS_kcmp: ::c_long = 343; -pub const SYS_finit_module: ::c_long = 344; -pub const SYS_sched_setattr: ::c_long = 345; -pub const SYS_sched_getattr: ::c_long = 346; -pub const SYS_renameat2: ::c_long = 347; -pub const SYS_seccomp: ::c_long = 348; -pub const SYS_getrandom: ::c_long = 349; -pub const SYS_memfd_create: ::c_long = 350; -pub const SYS_bpf: ::c_long = 351; -pub const SYS_s390_pci_mmio_write: ::c_long = 352; -pub const SYS_s390_pci_mmio_read: ::c_long = 353; -pub const SYS_execveat: ::c_long = 354; -pub const SYS_userfaultfd: ::c_long = 355; -pub const SYS_membarrier: ::c_long = 356; -pub const SYS_recvmmsg: ::c_long = 357; -pub const SYS_sendmmsg: ::c_long = 358; -pub const SYS_socket: ::c_long = 359; -pub const SYS_socketpair: ::c_long = 360; -pub const SYS_bind: ::c_long = 361; -pub const SYS_connect: ::c_long = 362; -pub const SYS_listen: ::c_long = 363; -pub const SYS_accept4: ::c_long = 364; -pub const SYS_getsockopt: ::c_long = 365; -pub const SYS_setsockopt: ::c_long = 366; -pub const SYS_getsockname: ::c_long = 367; -pub const SYS_getpeername: ::c_long = 368; -pub const SYS_sendto: ::c_long = 369; -pub const SYS_sendmsg: ::c_long = 370; -pub const SYS_recvfrom: ::c_long = 371; -pub const SYS_recvmsg: ::c_long = 372; -pub const SYS_shutdown: ::c_long = 373; -pub const SYS_mlock2: ::c_long = 374; -pub const SYS_copy_file_range: ::c_long = 375; -pub const SYS_preadv2: ::c_long = 376; -pub const SYS_pwritev2: ::c_long = 377; -pub const SYS_lchown: ::c_long = 198; -pub const SYS_setuid: ::c_long = 213; -pub const SYS_getuid: ::c_long = 199; -pub const SYS_setgid: ::c_long = 214; -pub const SYS_getgid: ::c_long = 200; -pub const SYS_geteuid: ::c_long = 201; -pub const SYS_setreuid: ::c_long = 203; -pub const SYS_setregid: ::c_long = 204; -pub const SYS_getrlimit: ::c_long = 191; -pub const SYS_getgroups: ::c_long = 205; -pub const SYS_fchown: ::c_long = 207; -pub const SYS_setresuid: ::c_long = 208; -pub const SYS_setresgid: ::c_long = 210; -pub const SYS_getresgid: ::c_long = 211; -pub const SYS_select: ::c_long = 142; -pub const SYS_getegid: ::c_long = 202; -pub const SYS_setgroups: ::c_long = 206; -pub const SYS_getresuid: ::c_long = 209; -pub const SYS_chown: ::c_long = 212; -pub const SYS_setfsuid: ::c_long = 215; -pub const SYS_setfsgid: ::c_long = 216; -pub const SYS_newfstatat: ::c_long = 293; -pub const SYS_statx: ::c_long = 379; - -#[link(name = "util")] -extern "C" { - - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; - pub fn getcontext(ucp: *mut ::ucontext_t) -> ::c_int; - pub fn setcontext(ucp: *const ::ucontext_t) -> ::c_int; - pub fn makecontext( - ucp: *mut ::ucontext_t, - func: extern "C" fn(), - argc: ::c_int, - ... - ); - pub fn swapcontext( - uocp: *mut ::ucontext_t, - ucp: *const ::ucontext_t, - ) -> ::c_int; -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/sparc64/align.rs b/libc/src/unix/linux_like/linux/gnu/b64/sparc64/align.rs deleted file mode 100644 index 29d1e1c..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/sparc64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [i64; 4] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs b/libc/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs deleted file mode 100644 index 651ada3..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs +++ /dev/null @@ -1,988 +0,0 @@ -//! SPARC64-specific definitions for 64-bit linux-like values - -use pthread_mutex_t; - -pub type c_long = i64; -pub type c_ulong = u64; -pub type c_char = i8; -pub type wchar_t = i32; -pub type nlink_t = u32; -pub type blksize_t = i64; -pub type suseconds_t = i32; -pub type __u64 = ::c_ulonglong; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - #[cfg(target_arch = "sparc64")] - __reserved0: ::c_int, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statfs { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - f_spare: [::__fsword_t; 5], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since="0.2.54", - note="Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - __reserved: ::c_short, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct stat { - pub st_dev: ::dev_t, - __pad0: u64, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad1: u64, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 2], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __pad0: u64, - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: ::c_int, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __reserved: [::c_long; 2], - } - - pub struct statfs64 { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - pub f_flags: ::__fsword_t, - pub f_spare: [::__fsword_t; 4], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct pthread_attr_t { - __size: [u64; 7] - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - __pad0: u16, - pub __seq: ::c_ushort, - __unused1: ::c_ulonglong, - __unused2: ::c_ulonglong, - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_segsz: ::size_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __reserved1: ::c_ulong, - __reserved2: ::c_ulong - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } -} - -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const VEOF: usize = 4; -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; - -pub const TIOCGSOFTCAR: ::c_ulong = 0x40047464; -pub const TIOCSSOFTCAR: ::c_ulong = 0x80047465; - -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 6; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 7; - -pub const O_APPEND: ::c_int = 0x8; -pub const O_CREAT: ::c_int = 0x200; -pub const O_EXCL: ::c_int = 0x800; -pub const O_NOCTTY: ::c_int = 0x8000; -pub const O_NONBLOCK: ::c_int = 0x4000; -pub const O_SYNC: ::c_int = 0x802000; -pub const O_RSYNC: ::c_int = 0x802000; -pub const O_DSYNC: ::c_int = 0x2000; -pub const O_FSYNC: ::c_int = 0x802000; -pub const O_NOATIME: ::c_int = 0x200000; -pub const O_PATH: ::c_int = 0x1000000; -pub const O_TMPFILE: ::c_int = 0x2000000 | O_DIRECTORY; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_GROWSDOWN: ::c_int = 0x0200; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const EDEADLK: ::c_int = 78; -pub const ENAMETOOLONG: ::c_int = 63; -pub const ENOLCK: ::c_int = 79; -pub const ENOSYS: ::c_int = 90; -pub const ENOTEMPTY: ::c_int = 66; -pub const ELOOP: ::c_int = 62; -pub const ENOMSG: ::c_int = 75; -pub const EIDRM: ::c_int = 77; -pub const ECHRNG: ::c_int = 94; -pub const EL2NSYNC: ::c_int = 95; -pub const EL3HLT: ::c_int = 96; -pub const EL3RST: ::c_int = 97; -pub const ELNRNG: ::c_int = 98; -pub const EUNATCH: ::c_int = 99; -pub const ENOCSI: ::c_int = 100; -pub const EL2HLT: ::c_int = 101; -pub const EBADE: ::c_int = 102; -pub const EBADR: ::c_int = 103; -pub const EXFULL: ::c_int = 104; -pub const ENOANO: ::c_int = 105; -pub const EBADRQC: ::c_int = 106; -pub const EBADSLT: ::c_int = 107; -pub const EMULTIHOP: ::c_int = 87; -pub const EOVERFLOW: ::c_int = 92; -pub const ENOTUNIQ: ::c_int = 115; -pub const EBADFD: ::c_int = 93; -pub const EBADMSG: ::c_int = 76; -pub const EREMCHG: ::c_int = 89; -pub const ELIBACC: ::c_int = 114; -pub const ELIBBAD: ::c_int = 112; -pub const ELIBSCN: ::c_int = 124; -pub const ELIBMAX: ::c_int = 123; -pub const ELIBEXEC: ::c_int = 110; -pub const EILSEQ: ::c_int = 122; -pub const ERESTART: ::c_int = 116; -pub const ESTRPIPE: ::c_int = 91; -pub const EUSERS: ::c_int = 68; -pub const ENOTSOCK: ::c_int = 38; -pub const EDESTADDRREQ: ::c_int = 39; -pub const EMSGSIZE: ::c_int = 40; -pub const EPROTOTYPE: ::c_int = 41; -pub const ENOPROTOOPT: ::c_int = 42; -pub const EPROTONOSUPPORT: ::c_int = 43; -pub const ESOCKTNOSUPPORT: ::c_int = 44; -pub const EOPNOTSUPP: ::c_int = 45; -pub const EPFNOSUPPORT: ::c_int = 46; -pub const EAFNOSUPPORT: ::c_int = 47; -pub const EADDRINUSE: ::c_int = 48; -pub const EADDRNOTAVAIL: ::c_int = 49; -pub const ENETDOWN: ::c_int = 50; -pub const ENETUNREACH: ::c_int = 51; -pub const ENETRESET: ::c_int = 52; -pub const ECONNABORTED: ::c_int = 53; -pub const ECONNRESET: ::c_int = 54; -pub const ENOBUFS: ::c_int = 55; -pub const EISCONN: ::c_int = 56; -pub const ENOTCONN: ::c_int = 57; -pub const ESHUTDOWN: ::c_int = 58; -pub const ETOOMANYREFS: ::c_int = 59; -pub const ETIMEDOUT: ::c_int = 60; -pub const ECONNREFUSED: ::c_int = 61; -pub const EHOSTDOWN: ::c_int = 64; -pub const EHOSTUNREACH: ::c_int = 65; -pub const EALREADY: ::c_int = 37; -pub const EINPROGRESS: ::c_int = 36; -pub const ESTALE: ::c_int = 70; -pub const EDQUOT: ::c_int = 69; -pub const ENOMEDIUM: ::c_int = 125; -pub const EMEDIUMTYPE: ::c_int = 126; -pub const ECANCELED: ::c_int = 127; -pub const ENOKEY: ::c_int = 128; -pub const EKEYEXPIRED: ::c_int = 129; -pub const EKEYREVOKED: ::c_int = 130; -pub const EKEYREJECTED: ::c_int = 131; -pub const EOWNERDEAD: ::c_int = 132; -pub const ENOTRECOVERABLE: ::c_int = 133; -pub const EHWPOISON: ::c_int = 135; -pub const ERFKILL: ::c_int = 134; - -pub const SOL_SOCKET: ::c_int = 0xffff; - -pub const SO_PASSCRED: ::c_int = 2; -pub const SO_REUSEADDR: ::c_int = 4; -pub const SO_BINDTODEVICE: ::c_int = 0x000d; -pub const SO_TIMESTAMP: ::c_int = 0x001d; -pub const SO_MARK: ::c_int = 0x0022; -pub const SO_RXQ_OVFL: ::c_int = 0x0024; -pub const SO_PEEK_OFF: ::c_int = 0x0026; -pub const SO_BUSY_POLL: ::c_int = 0x0030; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_DONTROUTE: ::c_int = 16; -pub const SO_BROADCAST: ::c_int = 32; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDBUFFORCE: ::c_int = 0x100a; -pub const SO_RCVBUFFORCE: ::c_int = 0x100b; -pub const SO_DOMAIN: ::c_int = 0x1029; -pub const SO_KEEPALIVE: ::c_int = 8; -pub const SO_OOBINLINE: ::c_int = 0x100; -pub const SO_LINGER: ::c_int = 128; -pub const SO_REUSEPORT: ::c_int = 0x200; -pub const SO_ACCEPTCONN: ::c_int = 0x8000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const SA_ONSTACK: ::c_int = 1; -pub const SA_SIGINFO: ::c_int = 0x200; -pub const SA_NOCLDWAIT: ::c_int = 0x100; - -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGCHLD: ::c_int = 20; -pub const SIGBUS: ::c_int = 10; -pub const SIGUSR1: ::c_int = 30; -pub const SIGUSR2: ::c_int = 31; -pub const SIGCONT: ::c_int = 19; -pub const SIGSTOP: ::c_int = 17; -pub const SIGTSTP: ::c_int = 18; -pub const SIGURG: ::c_int = 16; -pub const SIGIO: ::c_int = 23; -pub const SIGSYS: ::c_int = 12; -pub const SIGPOLL: ::c_int = 23; -pub const SIGPWR: ::c_int = 29; -pub const SIG_SETMASK: ::c_int = 4; -pub const SIG_BLOCK: ::c_int = 1; -pub const SIG_UNBLOCK: ::c_int = 2; - -pub const POLLWRNORM: ::c_short = 4; -pub const POLLWRBAND: ::c_short = 0x100; - -pub const O_ASYNC: ::c_int = 0x40; -pub const O_NDELAY: ::c_int = 0x4004; - -pub const PTRACE_DETACH: ::c_uint = 11; - -pub const EFD_NONBLOCK: ::c_int = 0x4000; - -pub const F_GETLK: ::c_int = 7; -pub const F_GETOWN: ::c_int = 5; -pub const F_SETOWN: ::c_int = 6; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; - -pub const F_RDLCK: ::c_int = 1; -pub const F_WRLCK: ::c_int = 2; -pub const F_UNLCK: ::c_int = 3; - -pub const SFD_NONBLOCK: ::c_int = 0x4000; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; -pub const TIOCEXCL: ::c_ulong = 0x2000740d; -pub const TIOCNXCL: ::c_ulong = 0x2000740e; -pub const TIOCSCTTY: ::c_ulong = 0x20007484; -pub const TIOCSTI: ::c_ulong = 0x80017472; -pub const TIOCMGET: ::c_ulong = 0x4004746a; -pub const TIOCMBIS: ::c_ulong = 0x8004746c; -pub const TIOCMBIC: ::c_ulong = 0x8004746b; -pub const TIOCMSET: ::c_ulong = 0x8004746d; -pub const TIOCCONS: ::c_ulong = 0x20007424; - -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -pub const SFD_CLOEXEC: ::c_int = 0x400000; - -pub const NCCS: usize = 17; -pub const O_TRUNC: ::c_int = 0x400; - -pub const O_CLOEXEC: ::c_int = 0x400000; - -pub const EBFONT: ::c_int = 109; -pub const ENOSTR: ::c_int = 72; -pub const ENODATA: ::c_int = 111; -pub const ETIME: ::c_int = 73; -pub const ENOSR: ::c_int = 74; -pub const ENONET: ::c_int = 80; -pub const ENOPKG: ::c_int = 113; -pub const EREMOTE: ::c_int = 71; -pub const ENOLINK: ::c_int = 82; -pub const EADV: ::c_int = 83; -pub const ESRMNT: ::c_int = 84; -pub const ECOMM: ::c_int = 85; -pub const EPROTO: ::c_int = 86; -pub const EDOTDOT: ::c_int = 88; - -pub const SA_NODEFER: ::c_int = 0x20; -pub const SA_RESETHAND: ::c_int = 0x4; -pub const SA_RESTART: ::c_int = 0x2; -pub const SA_NOCLDSTOP: ::c_int = 0x00000008; - -pub const EPOLL_CLOEXEC: ::c_int = 0x400000; - -pub const EFD_CLOEXEC: ::c_int = 0x400000; -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; - -align_const! { - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; -} - -pub const O_DIRECTORY: ::c_int = 0o200000; -pub const O_NOFOLLOW: ::c_int = 0o400000; -pub const O_DIRECT: ::c_int = 0x100000; - -pub const MAP_LOCKED: ::c_int = 0x0100; -pub const MAP_NORESERVE: ::c_int = 0x00040; - -pub const EDEADLOCK: ::c_int = 108; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; - -pub const SO_PEERCRED: ::c_int = 0x40; -pub const SO_RCVLOWAT: ::c_int = 0x800; -pub const SO_SNDLOWAT: ::c_int = 0x1000; -pub const SO_RCVTIMEO: ::c_int = 0x2000; -pub const SO_SNDTIMEO: ::c_int = 0x4000; - -pub const FIOCLEX: ::c_ulong = 0x20006601; -pub const FIONCLEX: ::c_ulong = 0x20006602; -pub const FIONBIO: ::c_ulong = 0x8004667e; - -pub const MCL_CURRENT: ::c_int = 0x2000; -pub const MCL_FUTURE: ::c_int = 0x4000; - -pub const SIGSTKSZ: ::size_t = 16384; -pub const MINSIGSTKSZ: ::size_t = 4096; -pub const CBAUD: ::tcflag_t = 0x0000100f; -pub const TAB1: ::tcflag_t = 0x800; -pub const TAB2: ::tcflag_t = 0x1000; -pub const TAB3: ::tcflag_t = 0x1800; -pub const CR1: ::tcflag_t = 0x200; -pub const CR2: ::tcflag_t = 0x400; -pub const CR3: ::tcflag_t = 0x600; -pub const FF1: ::tcflag_t = 0x8000; -pub const BS1: ::tcflag_t = 0x2000; -pub const VT1: ::tcflag_t = 0x4000; -pub const VWERASE: usize = 0xe; -pub const VREPRINT: usize = 0xc; -pub const VSUSP: usize = 0xa; -pub const VSTART: usize = 0x8; -pub const VSTOP: usize = 0x9; -pub const VDISCARD: usize = 0xd; -pub const VTIME: usize = 0x5; -pub const IXON: ::tcflag_t = 0x400; -pub const IXOFF: ::tcflag_t = 0x1000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x30; -pub const CS6: ::tcflag_t = 0x10; -pub const CS7: ::tcflag_t = 0x20; -pub const CS8: ::tcflag_t = 0x30; -pub const CSTOPB: ::tcflag_t = 0x40; -pub const CREAD: ::tcflag_t = 0x80; -pub const PARENB: ::tcflag_t = 0x100; -pub const PARODD: ::tcflag_t = 0x200; -pub const HUPCL: ::tcflag_t = 0x400; -pub const CLOCAL: ::tcflag_t = 0x800; -pub const ECHOKE: ::tcflag_t = 0x800; -pub const ECHOE: ::tcflag_t = 0x10; -pub const ECHOK: ::tcflag_t = 0x20; -pub const ECHONL: ::tcflag_t = 0x40; -pub const ECHOPRT: ::tcflag_t = 0x400; -pub const ECHOCTL: ::tcflag_t = 0x200; -pub const ISIG: ::tcflag_t = 0x1; -pub const ICANON: ::tcflag_t = 0x2; -pub const PENDIN: ::tcflag_t = 0x4000; -pub const NOFLSH: ::tcflag_t = 0x80; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0x00001000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0x1000; -pub const B57600: ::speed_t = 0x1001; -pub const B115200: ::speed_t = 0x1002; -pub const B230400: ::speed_t = 0x1003; -pub const B460800: ::speed_t = 0x1004; -pub const B76800: ::speed_t = 0x1005; -pub const B153600: ::speed_t = 0x1006; -pub const B307200: ::speed_t = 0x1007; -pub const B614400: ::speed_t = 0x1008; -pub const B921600: ::speed_t = 0x1009; -pub const B500000: ::speed_t = 0x100a; -pub const B576000: ::speed_t = 0x100b; -pub const B1000000: ::speed_t = 0x100c; -pub const B1152000: ::speed_t = 0x100d; -pub const B1500000: ::speed_t = 0x100e; -pub const B2000000: ::speed_t = 0x100f; - -pub const VEOL: usize = 5; -pub const VEOL2: usize = 6; -pub const VMIN: usize = 4; -pub const IEXTEN: ::tcflag_t = 0x8000; -pub const TOSTOP: ::tcflag_t = 0x100; -pub const FLUSHO: ::tcflag_t = 0x1000; -pub const EXTPROC: ::tcflag_t = 0x10000; -pub const TCGETS: ::c_ulong = 0x40245408; -pub const TCSETS: ::c_ulong = 0x80245409; -pub const TCSETSW: ::c_ulong = 0x8024540a; -pub const TCSETSF: ::c_ulong = 0x8024540b; -pub const TCGETA: ::c_ulong = 0x40125401; -pub const TCSETA: ::c_ulong = 0x80125402; -pub const TCSETAW: ::c_ulong = 0x80125403; -pub const TCSETAF: ::c_ulong = 0x80125404; -pub const TCSBRK: ::c_ulong = 0x20005405; -pub const TCXONC: ::c_ulong = 0x20005406; -pub const TCFLSH: ::c_ulong = 0x20005407; -pub const TIOCINQ: ::c_ulong = 0x4004667f; -pub const TIOCGPGRP: ::c_ulong = 0x40047483; -pub const TIOCSPGRP: ::c_ulong = 0x80047482; -pub const TIOCOUTQ: ::c_ulong = 0x40047473; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const FIONREAD: ::c_ulong = 0x4004667f; - -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_wait4: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execv: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_chown: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_brk: ::c_long = 17; -pub const SYS_perfctr: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_capget: ::c_long = 21; -pub const SYS_capset: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_vmsplice: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_sigaltstack: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_stat: ::c_long = 38; -pub const SYS_sendfile: ::c_long = 39; -pub const SYS_lstat: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_umount2: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_memory_ordering: ::c_long = 52; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_reboot: ::c_long = 55; -pub const SYS_symlink: ::c_long = 57; -pub const SYS_readlink: ::c_long = 58; -pub const SYS_execve: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_fstat: ::c_long = 62; -pub const SYS_fstat64: ::c_long = 63; -pub const SYS_getpagesize: ::c_long = 64; -pub const SYS_msync: ::c_long = 65; -pub const SYS_vfork: ::c_long = 66; -pub const SYS_pread64: ::c_long = 67; -pub const SYS_pwrite64: ::c_long = 68; -pub const SYS_mmap: ::c_long = 71; -pub const SYS_munmap: ::c_long = 73; -pub const SYS_mprotect: ::c_long = 74; -pub const SYS_madvise: ::c_long = 75; -pub const SYS_vhangup: ::c_long = 76; -pub const SYS_mincore: ::c_long = 78; -pub const SYS_getgroups: ::c_long = 79; -pub const SYS_setgroups: ::c_long = 80; -pub const SYS_getpgrp: ::c_long = 81; -pub const SYS_setitimer: ::c_long = 83; -pub const SYS_swapon: ::c_long = 85; -pub const SYS_getitimer: ::c_long = 86; -pub const SYS_sethostname: ::c_long = 88; -pub const SYS_dup2: ::c_long = 90; -pub const SYS_fcntl: ::c_long = 92; -pub const SYS_select: ::c_long = 93; -pub const SYS_fsync: ::c_long = 95; -pub const SYS_setpriority: ::c_long = 96; -pub const SYS_socket: ::c_long = 97; -pub const SYS_connect: ::c_long = 98; -pub const SYS_accept: ::c_long = 99; -pub const SYS_getpriority: ::c_long = 100; -pub const SYS_rt_sigreturn: ::c_long = 101; -pub const SYS_rt_sigaction: ::c_long = 102; -pub const SYS_rt_sigprocmask: ::c_long = 103; -pub const SYS_rt_sigpending: ::c_long = 104; -pub const SYS_rt_sigtimedwait: ::c_long = 105; -pub const SYS_rt_sigqueueinfo: ::c_long = 106; -pub const SYS_rt_sigsuspend: ::c_long = 107; -pub const SYS_setresuid: ::c_long = 108; -pub const SYS_getresuid: ::c_long = 109; -pub const SYS_setresgid: ::c_long = 110; -pub const SYS_getresgid: ::c_long = 111; -pub const SYS_recvmsg: ::c_long = 113; -pub const SYS_sendmsg: ::c_long = 114; -pub const SYS_gettimeofday: ::c_long = 116; -pub const SYS_getrusage: ::c_long = 117; -pub const SYS_getsockopt: ::c_long = 118; -pub const SYS_getcwd: ::c_long = 119; -pub const SYS_readv: ::c_long = 120; -pub const SYS_writev: ::c_long = 121; -pub const SYS_settimeofday: ::c_long = 122; -pub const SYS_fchown: ::c_long = 123; -pub const SYS_fchmod: ::c_long = 124; -pub const SYS_recvfrom: ::c_long = 125; -pub const SYS_setreuid: ::c_long = 126; -pub const SYS_setregid: ::c_long = 127; -pub const SYS_rename: ::c_long = 128; -pub const SYS_truncate: ::c_long = 129; -pub const SYS_ftruncate: ::c_long = 130; -pub const SYS_flock: ::c_long = 131; -pub const SYS_lstat64: ::c_long = 132; -pub const SYS_sendto: ::c_long = 133; -pub const SYS_shutdown: ::c_long = 134; -pub const SYS_socketpair: ::c_long = 135; -pub const SYS_mkdir: ::c_long = 136; -pub const SYS_rmdir: ::c_long = 137; -pub const SYS_utimes: ::c_long = 138; -pub const SYS_stat64: ::c_long = 139; -pub const SYS_sendfile64: ::c_long = 140; -pub const SYS_getpeername: ::c_long = 141; -pub const SYS_futex: ::c_long = 142; -pub const SYS_gettid: ::c_long = 143; -pub const SYS_getrlimit: ::c_long = 144; -pub const SYS_setrlimit: ::c_long = 145; -pub const SYS_pivot_root: ::c_long = 146; -pub const SYS_prctl: ::c_long = 147; -pub const SYS_pciconfig_read: ::c_long = 148; -pub const SYS_pciconfig_write: ::c_long = 149; -pub const SYS_getsockname: ::c_long = 150; -pub const SYS_inotify_init: ::c_long = 151; -pub const SYS_inotify_add_watch: ::c_long = 152; -pub const SYS_poll: ::c_long = 153; -pub const SYS_getdents64: ::c_long = 154; -pub const SYS_inotify_rm_watch: ::c_long = 156; -pub const SYS_statfs: ::c_long = 157; -pub const SYS_fstatfs: ::c_long = 158; -pub const SYS_umount: ::c_long = 159; -pub const SYS_sched_set_affinity: ::c_long = 160; -pub const SYS_sched_get_affinity: ::c_long = 161; -pub const SYS_getdomainname: ::c_long = 162; -pub const SYS_setdomainname: ::c_long = 163; -pub const SYS_utrap_install: ::c_long = 164; -pub const SYS_quotactl: ::c_long = 165; -pub const SYS_set_tid_address: ::c_long = 166; -pub const SYS_mount: ::c_long = 167; -pub const SYS_ustat: ::c_long = 168; -pub const SYS_setxattr: ::c_long = 169; -pub const SYS_lsetxattr: ::c_long = 170; -pub const SYS_fsetxattr: ::c_long = 171; -pub const SYS_getxattr: ::c_long = 172; -pub const SYS_lgetxattr: ::c_long = 173; -pub const SYS_getdents: ::c_long = 174; -pub const SYS_setsid: ::c_long = 175; -pub const SYS_fchdir: ::c_long = 176; -pub const SYS_fgetxattr: ::c_long = 177; -pub const SYS_listxattr: ::c_long = 178; -pub const SYS_llistxattr: ::c_long = 179; -pub const SYS_flistxattr: ::c_long = 180; -pub const SYS_removexattr: ::c_long = 181; -pub const SYS_lremovexattr: ::c_long = 182; -pub const SYS_sigpending: ::c_long = 183; -pub const SYS_query_module: ::c_long = 184; -pub const SYS_setpgid: ::c_long = 185; -pub const SYS_fremovexattr: ::c_long = 186; -pub const SYS_tkill: ::c_long = 187; -pub const SYS_exit_group: ::c_long = 188; -pub const SYS_uname: ::c_long = 189; -pub const SYS_init_module: ::c_long = 190; -pub const SYS_personality: ::c_long = 191; -pub const SYS_remap_file_pages: ::c_long = 192; -pub const SYS_epoll_create: ::c_long = 193; -pub const SYS_epoll_ctl: ::c_long = 194; -pub const SYS_epoll_wait: ::c_long = 195; -pub const SYS_ioprio_set: ::c_long = 196; -pub const SYS_getppid: ::c_long = 197; -pub const SYS_sigaction: ::c_long = 198; -pub const SYS_sgetmask: ::c_long = 199; -pub const SYS_ssetmask: ::c_long = 200; -pub const SYS_sigsuspend: ::c_long = 201; -pub const SYS_oldlstat: ::c_long = 202; -pub const SYS_uselib: ::c_long = 203; -pub const SYS_readdir: ::c_long = 204; -pub const SYS_readahead: ::c_long = 205; -pub const SYS_socketcall: ::c_long = 206; -pub const SYS_syslog: ::c_long = 207; -pub const SYS_lookup_dcookie: ::c_long = 208; -pub const SYS_fadvise64: ::c_long = 209; -pub const SYS_fadvise64_64: ::c_long = 210; -pub const SYS_tgkill: ::c_long = 211; -pub const SYS_waitpid: ::c_long = 212; -pub const SYS_swapoff: ::c_long = 213; -pub const SYS_sysinfo: ::c_long = 214; -pub const SYS_ipc: ::c_long = 215; -pub const SYS_sigreturn: ::c_long = 216; -pub const SYS_clone: ::c_long = 217; -pub const SYS_ioprio_get: ::c_long = 218; -pub const SYS_adjtimex: ::c_long = 219; -pub const SYS_sigprocmask: ::c_long = 220; -pub const SYS_create_module: ::c_long = 221; -pub const SYS_delete_module: ::c_long = 222; -pub const SYS_get_kernel_syms: ::c_long = 223; -pub const SYS_getpgid: ::c_long = 224; -pub const SYS_bdflush: ::c_long = 225; -pub const SYS_sysfs: ::c_long = 226; -pub const SYS_afs_syscall: ::c_long = 227; -pub const SYS_setfsuid: ::c_long = 228; -pub const SYS_setfsgid: ::c_long = 229; -pub const SYS__newselect: ::c_long = 230; -pub const SYS_splice: ::c_long = 232; -pub const SYS_stime: ::c_long = 233; -pub const SYS_statfs64: ::c_long = 234; -pub const SYS_fstatfs64: ::c_long = 235; -pub const SYS__llseek: ::c_long = 236; -pub const SYS_mlock: ::c_long = 237; -pub const SYS_munlock: ::c_long = 238; -pub const SYS_mlockall: ::c_long = 239; -pub const SYS_munlockall: ::c_long = 240; -pub const SYS_sched_setparam: ::c_long = 241; -pub const SYS_sched_getparam: ::c_long = 242; -pub const SYS_sched_setscheduler: ::c_long = 243; -pub const SYS_sched_getscheduler: ::c_long = 244; -pub const SYS_sched_yield: ::c_long = 245; -pub const SYS_sched_get_priority_max: ::c_long = 246; -pub const SYS_sched_get_priority_min: ::c_long = 247; -pub const SYS_sched_rr_get_interval: ::c_long = 248; -pub const SYS_nanosleep: ::c_long = 249; -pub const SYS_mremap: ::c_long = 250; -pub const SYS__sysctl: ::c_long = 251; -pub const SYS_getsid: ::c_long = 252; -pub const SYS_fdatasync: ::c_long = 253; -pub const SYS_nfsservctl: ::c_long = 254; -pub const SYS_sync_file_range: ::c_long = 255; -pub const SYS_clock_settime: ::c_long = 256; -pub const SYS_clock_gettime: ::c_long = 257; -pub const SYS_clock_getres: ::c_long = 258; -pub const SYS_clock_nanosleep: ::c_long = 259; -pub const SYS_sched_getaffinity: ::c_long = 260; -pub const SYS_sched_setaffinity: ::c_long = 261; -pub const SYS_timer_settime: ::c_long = 262; -pub const SYS_timer_gettime: ::c_long = 263; -pub const SYS_timer_getoverrun: ::c_long = 264; -pub const SYS_timer_delete: ::c_long = 265; -pub const SYS_timer_create: ::c_long = 266; -pub const SYS_io_setup: ::c_long = 268; -pub const SYS_io_destroy: ::c_long = 269; -pub const SYS_io_submit: ::c_long = 270; -pub const SYS_io_cancel: ::c_long = 271; -pub const SYS_io_getevents: ::c_long = 272; -pub const SYS_mq_open: ::c_long = 273; -pub const SYS_mq_unlink: ::c_long = 274; -pub const SYS_mq_timedsend: ::c_long = 275; -pub const SYS_mq_timedreceive: ::c_long = 276; -pub const SYS_mq_notify: ::c_long = 277; -pub const SYS_mq_getsetattr: ::c_long = 278; -pub const SYS_waitid: ::c_long = 279; -pub const SYS_tee: ::c_long = 280; -pub const SYS_add_key: ::c_long = 281; -pub const SYS_request_key: ::c_long = 282; -pub const SYS_keyctl: ::c_long = 283; -pub const SYS_openat: ::c_long = 284; -pub const SYS_mkdirat: ::c_long = 285; -pub const SYS_mknodat: ::c_long = 286; -pub const SYS_fchownat: ::c_long = 287; -pub const SYS_futimesat: ::c_long = 288; -pub const SYS_fstatat64: ::c_long = 289; -pub const SYS_unlinkat: ::c_long = 290; -pub const SYS_renameat: ::c_long = 291; -pub const SYS_linkat: ::c_long = 292; -pub const SYS_symlinkat: ::c_long = 293; -pub const SYS_readlinkat: ::c_long = 294; -pub const SYS_fchmodat: ::c_long = 295; -pub const SYS_faccessat: ::c_long = 296; -pub const SYS_pselect6: ::c_long = 297; -pub const SYS_ppoll: ::c_long = 298; -pub const SYS_unshare: ::c_long = 299; -pub const SYS_set_robust_list: ::c_long = 300; -pub const SYS_get_robust_list: ::c_long = 301; -pub const SYS_migrate_pages: ::c_long = 302; -pub const SYS_mbind: ::c_long = 303; -pub const SYS_get_mempolicy: ::c_long = 304; -pub const SYS_set_mempolicy: ::c_long = 305; -pub const SYS_kexec_load: ::c_long = 306; -pub const SYS_move_pages: ::c_long = 307; -pub const SYS_getcpu: ::c_long = 308; -pub const SYS_epoll_pwait: ::c_long = 309; -pub const SYS_utimensat: ::c_long = 310; -pub const SYS_signalfd: ::c_long = 311; -pub const SYS_timerfd_create: ::c_long = 312; -pub const SYS_eventfd: ::c_long = 313; -pub const SYS_fallocate: ::c_long = 314; -pub const SYS_timerfd_settime: ::c_long = 315; -pub const SYS_timerfd_gettime: ::c_long = 316; -pub const SYS_signalfd4: ::c_long = 317; -pub const SYS_eventfd2: ::c_long = 318; -pub const SYS_epoll_create1: ::c_long = 319; -pub const SYS_dup3: ::c_long = 320; -pub const SYS_pipe2: ::c_long = 321; -pub const SYS_inotify_init1: ::c_long = 322; -pub const SYS_accept4: ::c_long = 323; -pub const SYS_preadv: ::c_long = 324; -pub const SYS_pwritev: ::c_long = 325; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 326; -pub const SYS_perf_event_open: ::c_long = 327; -pub const SYS_recvmmsg: ::c_long = 328; -pub const SYS_fanotify_init: ::c_long = 329; -pub const SYS_fanotify_mark: ::c_long = 330; -pub const SYS_prlimit64: ::c_long = 331; -pub const SYS_name_to_handle_at: ::c_long = 332; -pub const SYS_open_by_handle_at: ::c_long = 333; -pub const SYS_clock_adjtime: ::c_long = 334; -pub const SYS_syncfs: ::c_long = 335; -pub const SYS_sendmmsg: ::c_long = 336; -pub const SYS_setns: ::c_long = 337; -pub const SYS_process_vm_readv: ::c_long = 338; -pub const SYS_process_vm_writev: ::c_long = 339; -pub const SYS_kern_features: ::c_long = 340; -pub const SYS_kcmp: ::c_long = 341; -pub const SYS_finit_module: ::c_long = 342; -pub const SYS_sched_setattr: ::c_long = 343; -pub const SYS_sched_getattr: ::c_long = 344; -pub const SYS_renameat2: ::c_long = 345; -pub const SYS_seccomp: ::c_long = 346; -pub const SYS_getrandom: ::c_long = 347; -pub const SYS_memfd_create: ::c_long = 348; -pub const SYS_bpf: ::c_long = 349; -pub const SYS_execveat: ::c_long = 350; -pub const SYS_membarrier: ::c_long = 351; -pub const SYS_userfaultfd: ::c_long = 352; -pub const SYS_bind: ::c_long = 353; -pub const SYS_listen: ::c_long = 354; -pub const SYS_setsockopt: ::c_long = 355; -pub const SYS_mlock2: ::c_long = 356; -pub const SYS_copy_file_range: ::c_long = 357; -pub const SYS_preadv2: ::c_long = 358; -pub const SYS_pwritev2: ::c_long = 359; -pub const SYS_statx: ::c_long = 360; - -#[link(name = "util")] -extern "C" { - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/x86_64/align.rs b/libc/src/unix/linux_like/linux/gnu/b64/x86_64/align.rs deleted file mode 100644 index 7ca870f..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/x86_64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 4] - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs b/libc/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs deleted file mode 100644 index 34e4da8..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs +++ /dev/null @@ -1,929 +0,0 @@ -//! x86_64-specific definitions for 64-bit linux-like values - -pub type c_char = i8; -pub type wchar_t = i32; -pub type nlink_t = u64; -pub type blksize_t = i64; -pub type greg_t = i64; -pub type suseconds_t = i64; -pub type __u64 = ::c_ulonglong; - -s! { - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - #[cfg(target_arch = "sparc64")] - __reserved0: ::c_int, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statfs { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - f_spare: [::__fsword_t; 5], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct flock64 { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off64_t, - pub l_len: ::off64_t, - pub l_pid: ::pid_t, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - #[doc(hidden)] - #[deprecated( - since="0.2.54", - note="Please leave a comment on \ - https://github.com/rust-lang/libc/pull/1316 if you're using \ - this field" - )] - pub _pad: [::c_int; 29], - _align: [u64; 0], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: i64, - pub st_mtime: ::time_t, - pub st_mtime_nsec: i64, - pub st_ctime: ::time_t, - pub st_ctime_nsec: i64, - __unused: [i64; 3], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: i64, - pub st_mtime: ::time_t, - pub st_mtime_nsec: i64, - pub st_ctime: ::time_t, - pub st_ctime_nsec: i64, - __reserved: [i64; 3], - } - - pub struct statfs64 { - pub f_type: ::__fsword_t, - pub f_bsize: ::__fsword_t, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_fsid: ::fsid_t, - pub f_namelen: ::__fsword_t, - pub f_frsize: ::__fsword_t, - pub f_flags: ::__fsword_t, - pub f_spare: [::__fsword_t; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct pthread_attr_t { - #[cfg(target_pointer_width = "32")] - __size: [u32; 8], - #[cfg(target_pointer_width = "64")] - __size: [u64; 7] - } - - pub struct _libc_fpxreg { - pub significand: [u16; 4], - pub exponent: u16, - __private: [u16; 3], - } - - pub struct _libc_xmmreg { - pub element: [u32; 4], - } - - pub struct _libc_fpstate { - pub cwd: u16, - pub swd: u16, - pub ftw: u16, - pub fop: u16, - pub rip: u64, - pub rdp: u64, - pub mxcsr: u32, - pub mxcr_mask: u32, - pub _st: [_libc_fpxreg; 8], - pub _xmm: [_libc_xmmreg; 16], - __private: [u64; 12], - } - - pub struct user_regs_struct { - pub r15: ::c_ulonglong, - pub r14: ::c_ulonglong, - pub r13: ::c_ulonglong, - pub r12: ::c_ulonglong, - pub rbp: ::c_ulonglong, - pub rbx: ::c_ulonglong, - pub r11: ::c_ulonglong, - pub r10: ::c_ulonglong, - pub r9: ::c_ulonglong, - pub r8: ::c_ulonglong, - pub rax: ::c_ulonglong, - pub rcx: ::c_ulonglong, - pub rdx: ::c_ulonglong, - pub rsi: ::c_ulonglong, - pub rdi: ::c_ulonglong, - pub orig_rax: ::c_ulonglong, - pub rip: ::c_ulonglong, - pub cs: ::c_ulonglong, - pub eflags: ::c_ulonglong, - pub rsp: ::c_ulonglong, - pub ss: ::c_ulonglong, - pub fs_base: ::c_ulonglong, - pub gs_base: ::c_ulonglong, - pub ds: ::c_ulonglong, - pub es: ::c_ulonglong, - pub fs: ::c_ulonglong, - pub gs: ::c_ulonglong, - } - - pub struct user { - pub regs: user_regs_struct, - pub u_fpvalid: ::c_int, - pub i387: user_fpregs_struct, - pub u_tsize: ::c_ulonglong, - pub u_dsize: ::c_ulonglong, - pub u_ssize: ::c_ulonglong, - pub start_code: ::c_ulonglong, - pub start_stack: ::c_ulonglong, - pub signal: ::c_longlong, - __reserved: ::c_int, - #[cfg(target_pointer_width = "32")] - __pad1: u32, - pub u_ar0: *mut user_regs_struct, - #[cfg(target_pointer_width = "32")] - __pad2: u32, - pub u_fpstate: *mut user_fpregs_struct, - pub magic: ::c_ulonglong, - pub u_comm: [::c_char; 32], - pub u_debugreg: [::c_ulonglong; 8], - } - - pub struct mcontext_t { - pub gregs: [greg_t; 23], - pub fpregs: *mut _libc_fpstate, - __private: [u64; 8], - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_ushort, - __pad1: ::c_ushort, - pub __seq: ::c_ushort, - __pad2: ::c_ushort, - __unused1: u64, - __unused2: u64 - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: u64, - __unused5: u64 - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct ip_mreqn { - pub imr_multiaddr: ::in_addr, - pub imr_address: ::in_addr, - pub imr_ifindex: ::c_int, - } -} - -s_no_extra_traits! { - pub struct user_fpregs_struct { - pub cwd: ::c_ushort, - pub swd: ::c_ushort, - pub ftw: ::c_ushort, - pub fop: ::c_ushort, - pub rip: ::c_ulonglong, - pub rdp: ::c_ulonglong, - pub mxcsr: ::c_uint, - pub mxcr_mask: ::c_uint, - pub st_space: [::c_uint; 32], - pub xmm_space: [::c_uint; 64], - padding: [::c_uint; 24], - } - - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 512], - // FIXME: the shadow stack field requires glibc >= 2.28. - // Re-add once we drop compatibility with glibc versions older than - // 2.28. - // - // __ssp: [::c_ulonglong; 4], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for user_fpregs_struct { - fn eq(&self, other: &user_fpregs_struct) -> bool { - self.cwd == other.cwd - && self.swd == other.swd - && self.ftw == other.ftw - && self.fop == other.fop - && self.rip == other.rip - && self.rdp == other.rdp - && self.mxcsr == other.mxcsr - && self.mxcr_mask == other.mxcr_mask - && self.st_space == other.st_space - && self - .xmm_space - .iter() - .zip(other.xmm_space.iter()) - .all(|(a,b)| a == b) - // Ignore padding field - } - } - - impl Eq for user_fpregs_struct {} - - impl ::fmt::Debug for user_fpregs_struct { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("user_fpregs_struct") - .field("cwd", &self.cwd) - .field("ftw", &self.ftw) - .field("fop", &self.fop) - .field("rip", &self.rip) - .field("rdp", &self.rdp) - .field("mxcsr", &self.mxcsr) - .field("mxcr_mask", &self.mxcr_mask) - .field("st_space", &self.st_space) - // FIXME: .field("xmm_space", &self.xmm_space) - // Ignore padding field - .finish() - } - } - - impl ::hash::Hash for user_fpregs_struct { - fn hash(&self, state: &mut H) { - self.cwd.hash(state); - self.ftw.hash(state); - self.fop.hash(state); - self.rip.hash(state); - self.rdp.hash(state); - self.mxcsr.hash(state); - self.mxcr_mask.hash(state); - self.st_space.hash(state); - self.xmm_space.hash(state); - // Ignore padding field - } - } - - impl PartialEq for ucontext_t { - fn eq(&self, other: &ucontext_t) -> bool { - self.uc_flags == other.uc_flags - && self.uc_link == other.uc_link - && self.uc_stack == other.uc_stack - && self.uc_mcontext == other.uc_mcontext - && self.uc_sigmask == other.uc_sigmask - // Ignore __private field - } - } - - impl Eq for ucontext_t {} - - impl ::fmt::Debug for ucontext_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("ucontext_t") - .field("uc_flags", &self.uc_flags) - .field("uc_link", &self.uc_link) - .field("uc_stack", &self.uc_stack) - .field("uc_mcontext", &self.uc_mcontext) - .field("uc_sigmask", &self.uc_sigmask) - // Ignore __private field - .finish() - } - } - - impl ::hash::Hash for ucontext_t { - fn hash(&self, state: &mut H) { - self.uc_flags.hash(state); - self.uc_link.hash(state); - self.uc_stack.hash(state); - self.uc_mcontext.hash(state); - self.uc_sigmask.hash(state); - // Ignore __private field - } - } - } -} - -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const VEOF: usize = 4; -pub const RTLD_DEEPBIND: ::c_int = 0x8; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const TIOCGSOFTCAR: ::c_ulong = 0x5419; -pub const TIOCSSOFTCAR: ::c_ulong = 0x541A; -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; - -pub const RLIMIT_RSS: ::__rlimit_resource_t = 5; -pub const RLIMIT_AS: ::__rlimit_resource_t = 9; -pub const RLIMIT_MEMLOCK: ::__rlimit_resource_t = 8; -pub const RLIMIT_NOFILE: ::__rlimit_resource_t = 7; -pub const RLIMIT_NPROC: ::__rlimit_resource_t = 6; - -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_FSYNC: ::c_int = 0x101000; -pub const O_NOATIME: ::c_int = 0o1000000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; - -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EBADMSG: ::c_int = 74; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const EHWPOISON: ::c_int = 133; -pub const ERFKILL: ::c_int = 132; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_PEERSEC: ::c_int = 31; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; -pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS; -pub const SO_MARK: ::c_int = 36; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_BUSY_POLL: ::c_int = 46; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; -pub const SO_INCOMING_CPU: ::c_int = 49; -pub const SO_ATTACH_BPF: ::c_int = 50; -pub const SO_DETACH_BPF: ::c_int = SO_DETACH_FILTER; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = 31; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_NDELAY: ::c_int = 0x800; - -pub const PTRACE_DETACH: ::c_uint = 17; - -pub const EFD_NONBLOCK: ::c_int = 0x800; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETOWN: ::c_int = 8; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; - -pub const SFD_NONBLOCK: ::c_int = 0x0800; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const TIOCLINUX: ::c_ulong = 0x541C; -pub const TIOCGSERIAL: ::c_ulong = 0x541E; -pub const TIOCEXCL: ::c_ulong = 0x540C; -pub const TIOCNXCL: ::c_ulong = 0x540D; -pub const TIOCSCTTY: ::c_ulong = 0x540E; -pub const TIOCSTI: ::c_ulong = 0x5412; -pub const TIOCMGET: ::c_ulong = 0x5415; -pub const TIOCMBIS: ::c_ulong = 0x5416; -pub const TIOCMBIC: ::c_ulong = 0x5417; -pub const TIOCMSET: ::c_ulong = 0x5418; -pub const TIOCCONS: ::c_ulong = 0x541D; - -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; - -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; - -pub const O_CLOEXEC: ::c_int = 0x80000; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; - -pub const O_DIRECT: ::c_int = 0x4000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; - -pub const MAP_HUGETLB: ::c_int = 0x040000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_32BIT: ::c_int = 0x0040; -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_ANONYMOUS: ::c_int = 0x0020; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; - -pub const EDEADLOCK: ::c_int = 35; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; - -pub const FIOCLEX: ::c_ulong = 0x5451; -pub const FIONCLEX: ::c_ulong = 0x5450; -pub const FIONBIO: ::c_ulong = 0x5421; - -pub const PTRACE_GETFPREGS: ::c_uint = 14; -pub const PTRACE_SETFPREGS: ::c_uint = 15; -pub const PTRACE_GETFPXREGS: ::c_uint = 18; -pub const PTRACE_SETFPXREGS: ::c_uint = 19; -pub const PTRACE_GETREGS: ::c_uint = 12; -pub const PTRACE_SETREGS: ::c_uint = 13; -pub const PTRACE_PEEKSIGINFO_SHARED: ::c_uint = 1; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; -pub const EXTPROC: ::tcflag_t = 0x00010000; -pub const TCGETS: ::c_ulong = 0x5401; -pub const TCSETS: ::c_ulong = 0x5402; -pub const TCSETSW: ::c_ulong = 0x5403; -pub const TCSETSF: ::c_ulong = 0x5404; -pub const TCGETA: ::c_ulong = 0x5405; -pub const TCSETA: ::c_ulong = 0x5406; -pub const TCSETAW: ::c_ulong = 0x5407; -pub const TCSETAF: ::c_ulong = 0x5408; -pub const TCSBRK: ::c_ulong = 0x5409; -pub const TCXONC: ::c_ulong = 0x540A; -pub const TCFLSH: ::c_ulong = 0x540B; -pub const TIOCINQ: ::c_ulong = 0x541B; -pub const TIOCGPGRP: ::c_ulong = 0x540F; -pub const TIOCSPGRP: ::c_ulong = 0x5410; -pub const TIOCOUTQ: ::c_ulong = 0x5411; -pub const TIOCGWINSZ: ::c_ulong = 0x5413; -pub const TIOCSWINSZ: ::c_ulong = 0x5414; -pub const FIONREAD: ::c_ulong = 0x541B; - -// offsets in user_regs_structs, from sys/reg.h -pub const R15: ::c_int = 0; -pub const R14: ::c_int = 1; -pub const R13: ::c_int = 2; -pub const R12: ::c_int = 3; -pub const RBP: ::c_int = 4; -pub const RBX: ::c_int = 5; -pub const R11: ::c_int = 6; -pub const R10: ::c_int = 7; -pub const R9: ::c_int = 8; -pub const R8: ::c_int = 9; -pub const RAX: ::c_int = 10; -pub const RCX: ::c_int = 11; -pub const RDX: ::c_int = 12; -pub const RSI: ::c_int = 13; -pub const RDI: ::c_int = 14; -pub const ORIG_RAX: ::c_int = 15; -pub const RIP: ::c_int = 16; -pub const CS: ::c_int = 17; -pub const EFLAGS: ::c_int = 18; -pub const RSP: ::c_int = 19; -pub const SS: ::c_int = 20; -pub const FS_BASE: ::c_int = 21; -pub const GS_BASE: ::c_int = 22; -pub const DS: ::c_int = 23; -pub const ES: ::c_int = 24; -pub const FS: ::c_int = 25; -pub const GS: ::c_int = 26; - -// offsets in mcontext_t.gregs from sys/ucontext.h -pub const REG_R8: ::c_int = 0; -pub const REG_R9: ::c_int = 1; -pub const REG_R10: ::c_int = 2; -pub const REG_R11: ::c_int = 3; -pub const REG_R12: ::c_int = 4; -pub const REG_R13: ::c_int = 5; -pub const REG_R14: ::c_int = 6; -pub const REG_R15: ::c_int = 7; -pub const REG_RDI: ::c_int = 8; -pub const REG_RSI: ::c_int = 9; -pub const REG_RBP: ::c_int = 10; -pub const REG_RBX: ::c_int = 11; -pub const REG_RDX: ::c_int = 12; -pub const REG_RAX: ::c_int = 13; -pub const REG_RCX: ::c_int = 14; -pub const REG_RSP: ::c_int = 15; -pub const REG_RIP: ::c_int = 16; -pub const REG_EFL: ::c_int = 17; -pub const REG_CSGSFS: ::c_int = 18; -pub const REG_ERR: ::c_int = 19; -pub const REG_TRAPNO: ::c_int = 20; -pub const REG_OLDMASK: ::c_int = 21; -pub const REG_CR2: ::c_int = 22; - -extern "C" { - pub fn getcontext(ucp: *mut ucontext_t) -> ::c_int; - pub fn setcontext(ucp: *const ucontext_t) -> ::c_int; - pub fn makecontext( - ucp: *mut ucontext_t, - func: extern "C" fn(), - argc: ::c_int, - ... - ); - pub fn swapcontext( - uocp: *mut ucontext_t, - ucp: *const ucontext_t, - ) -> ::c_int; - pub fn iopl(level: ::c_int) -> ::c_int; - pub fn ioperm( - from: ::c_ulong, - num: ::c_ulong, - turn_on: ::c_int, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - mod x32; - pub use self::x32::*; - } else { - mod not_x32; - pub use self::not_x32::*; - } -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs b/libc/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs deleted file mode 100644 index 64a6de9..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs +++ /dev/null @@ -1,423 +0,0 @@ -use pthread_mutex_t; - -pub type c_long = i64; -pub type c_ulong = u64; - -s! { - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } -} - -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; - -align_const! { - #[cfg(target_endian = "little")] - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "little")] - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "little")] - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - #[cfg(target_endian = "big")] - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; -} - -// Syscall table - -pub const SYS_read: ::c_long = 0; -pub const SYS_write: ::c_long = 1; -pub const SYS_open: ::c_long = 2; -pub const SYS_close: ::c_long = 3; -pub const SYS_stat: ::c_long = 4; -pub const SYS_fstat: ::c_long = 5; -pub const SYS_lstat: ::c_long = 6; -pub const SYS_poll: ::c_long = 7; -pub const SYS_lseek: ::c_long = 8; -pub const SYS_mmap: ::c_long = 9; -pub const SYS_mprotect: ::c_long = 10; -pub const SYS_munmap: ::c_long = 11; -pub const SYS_brk: ::c_long = 12; -pub const SYS_rt_sigaction: ::c_long = 13; -pub const SYS_rt_sigprocmask: ::c_long = 14; -pub const SYS_rt_sigreturn: ::c_long = 15; -pub const SYS_ioctl: ::c_long = 16; -pub const SYS_pread64: ::c_long = 17; -pub const SYS_pwrite64: ::c_long = 18; -pub const SYS_readv: ::c_long = 19; -pub const SYS_writev: ::c_long = 20; -pub const SYS_access: ::c_long = 21; -pub const SYS_pipe: ::c_long = 22; -pub const SYS_select: ::c_long = 23; -pub const SYS_sched_yield: ::c_long = 24; -pub const SYS_mremap: ::c_long = 25; -pub const SYS_msync: ::c_long = 26; -pub const SYS_mincore: ::c_long = 27; -pub const SYS_madvise: ::c_long = 28; -pub const SYS_shmget: ::c_long = 29; -pub const SYS_shmat: ::c_long = 30; -pub const SYS_shmctl: ::c_long = 31; -pub const SYS_dup: ::c_long = 32; -pub const SYS_dup2: ::c_long = 33; -pub const SYS_pause: ::c_long = 34; -pub const SYS_nanosleep: ::c_long = 35; -pub const SYS_getitimer: ::c_long = 36; -pub const SYS_alarm: ::c_long = 37; -pub const SYS_setitimer: ::c_long = 38; -pub const SYS_getpid: ::c_long = 39; -pub const SYS_sendfile: ::c_long = 40; -pub const SYS_socket: ::c_long = 41; -pub const SYS_connect: ::c_long = 42; -pub const SYS_accept: ::c_long = 43; -pub const SYS_sendto: ::c_long = 44; -pub const SYS_recvfrom: ::c_long = 45; -pub const SYS_sendmsg: ::c_long = 46; -pub const SYS_recvmsg: ::c_long = 47; -pub const SYS_shutdown: ::c_long = 48; -pub const SYS_bind: ::c_long = 49; -pub const SYS_listen: ::c_long = 50; -pub const SYS_getsockname: ::c_long = 51; -pub const SYS_getpeername: ::c_long = 52; -pub const SYS_socketpair: ::c_long = 53; -pub const SYS_setsockopt: ::c_long = 54; -pub const SYS_getsockopt: ::c_long = 55; -pub const SYS_clone: ::c_long = 56; -pub const SYS_fork: ::c_long = 57; -pub const SYS_vfork: ::c_long = 58; -pub const SYS_execve: ::c_long = 59; -pub const SYS_exit: ::c_long = 60; -pub const SYS_wait4: ::c_long = 61; -pub const SYS_kill: ::c_long = 62; -pub const SYS_uname: ::c_long = 63; -pub const SYS_semget: ::c_long = 64; -pub const SYS_semop: ::c_long = 65; -pub const SYS_semctl: ::c_long = 66; -pub const SYS_shmdt: ::c_long = 67; -pub const SYS_msgget: ::c_long = 68; -pub const SYS_msgsnd: ::c_long = 69; -pub const SYS_msgrcv: ::c_long = 70; -pub const SYS_msgctl: ::c_long = 71; -pub const SYS_fcntl: ::c_long = 72; -pub const SYS_flock: ::c_long = 73; -pub const SYS_fsync: ::c_long = 74; -pub const SYS_fdatasync: ::c_long = 75; -pub const SYS_truncate: ::c_long = 76; -pub const SYS_ftruncate: ::c_long = 77; -pub const SYS_getdents: ::c_long = 78; -pub const SYS_getcwd: ::c_long = 79; -pub const SYS_chdir: ::c_long = 80; -pub const SYS_fchdir: ::c_long = 81; -pub const SYS_rename: ::c_long = 82; -pub const SYS_mkdir: ::c_long = 83; -pub const SYS_rmdir: ::c_long = 84; -pub const SYS_creat: ::c_long = 85; -pub const SYS_link: ::c_long = 86; -pub const SYS_unlink: ::c_long = 87; -pub const SYS_symlink: ::c_long = 88; -pub const SYS_readlink: ::c_long = 89; -pub const SYS_chmod: ::c_long = 90; -pub const SYS_fchmod: ::c_long = 91; -pub const SYS_chown: ::c_long = 92; -pub const SYS_fchown: ::c_long = 93; -pub const SYS_lchown: ::c_long = 94; -pub const SYS_umask: ::c_long = 95; -pub const SYS_gettimeofday: ::c_long = 96; -pub const SYS_getrlimit: ::c_long = 97; -pub const SYS_getrusage: ::c_long = 98; -pub const SYS_sysinfo: ::c_long = 99; -pub const SYS_times: ::c_long = 100; -pub const SYS_ptrace: ::c_long = 101; -pub const SYS_getuid: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_getgid: ::c_long = 104; -pub const SYS_setuid: ::c_long = 105; -pub const SYS_setgid: ::c_long = 106; -pub const SYS_geteuid: ::c_long = 107; -pub const SYS_getegid: ::c_long = 108; -pub const SYS_setpgid: ::c_long = 109; -pub const SYS_getppid: ::c_long = 110; -pub const SYS_getpgrp: ::c_long = 111; -pub const SYS_setsid: ::c_long = 112; -pub const SYS_setreuid: ::c_long = 113; -pub const SYS_setregid: ::c_long = 114; -pub const SYS_getgroups: ::c_long = 115; -pub const SYS_setgroups: ::c_long = 116; -pub const SYS_setresuid: ::c_long = 117; -pub const SYS_getresuid: ::c_long = 118; -pub const SYS_setresgid: ::c_long = 119; -pub const SYS_getresgid: ::c_long = 120; -pub const SYS_getpgid: ::c_long = 121; -pub const SYS_setfsuid: ::c_long = 122; -pub const SYS_setfsgid: ::c_long = 123; -pub const SYS_getsid: ::c_long = 124; -pub const SYS_capget: ::c_long = 125; -pub const SYS_capset: ::c_long = 126; -pub const SYS_rt_sigpending: ::c_long = 127; -pub const SYS_rt_sigtimedwait: ::c_long = 128; -pub const SYS_rt_sigqueueinfo: ::c_long = 129; -pub const SYS_rt_sigsuspend: ::c_long = 130; -pub const SYS_sigaltstack: ::c_long = 131; -pub const SYS_utime: ::c_long = 132; -pub const SYS_mknod: ::c_long = 133; -pub const SYS_uselib: ::c_long = 134; -pub const SYS_personality: ::c_long = 135; -pub const SYS_ustat: ::c_long = 136; -pub const SYS_statfs: ::c_long = 137; -pub const SYS_fstatfs: ::c_long = 138; -pub const SYS_sysfs: ::c_long = 139; -pub const SYS_getpriority: ::c_long = 140; -pub const SYS_setpriority: ::c_long = 141; -pub const SYS_sched_setparam: ::c_long = 142; -pub const SYS_sched_getparam: ::c_long = 143; -pub const SYS_sched_setscheduler: ::c_long = 144; -pub const SYS_sched_getscheduler: ::c_long = 145; -pub const SYS_sched_get_priority_max: ::c_long = 146; -pub const SYS_sched_get_priority_min: ::c_long = 147; -pub const SYS_sched_rr_get_interval: ::c_long = 148; -pub const SYS_mlock: ::c_long = 149; -pub const SYS_munlock: ::c_long = 150; -pub const SYS_mlockall: ::c_long = 151; -pub const SYS_munlockall: ::c_long = 152; -pub const SYS_vhangup: ::c_long = 153; -pub const SYS_modify_ldt: ::c_long = 154; -pub const SYS_pivot_root: ::c_long = 155; -pub const SYS__sysctl: ::c_long = 156; -pub const SYS_prctl: ::c_long = 157; -pub const SYS_arch_prctl: ::c_long = 158; -pub const SYS_adjtimex: ::c_long = 159; -pub const SYS_setrlimit: ::c_long = 160; -pub const SYS_chroot: ::c_long = 161; -pub const SYS_sync: ::c_long = 162; -pub const SYS_acct: ::c_long = 163; -pub const SYS_settimeofday: ::c_long = 164; -pub const SYS_mount: ::c_long = 165; -pub const SYS_umount2: ::c_long = 166; -pub const SYS_swapon: ::c_long = 167; -pub const SYS_swapoff: ::c_long = 168; -pub const SYS_reboot: ::c_long = 169; -pub const SYS_sethostname: ::c_long = 170; -pub const SYS_setdomainname: ::c_long = 171; -pub const SYS_iopl: ::c_long = 172; -pub const SYS_ioperm: ::c_long = 173; -pub const SYS_create_module: ::c_long = 174; -pub const SYS_init_module: ::c_long = 175; -pub const SYS_delete_module: ::c_long = 176; -pub const SYS_get_kernel_syms: ::c_long = 177; -pub const SYS_query_module: ::c_long = 178; -pub const SYS_quotactl: ::c_long = 179; -pub const SYS_nfsservctl: ::c_long = 180; -pub const SYS_getpmsg: ::c_long = 181; -pub const SYS_putpmsg: ::c_long = 182; -pub const SYS_afs_syscall: ::c_long = 183; -pub const SYS_tuxcall: ::c_long = 184; -pub const SYS_security: ::c_long = 185; -pub const SYS_gettid: ::c_long = 186; -pub const SYS_readahead: ::c_long = 187; -pub const SYS_setxattr: ::c_long = 188; -pub const SYS_lsetxattr: ::c_long = 189; -pub const SYS_fsetxattr: ::c_long = 190; -pub const SYS_getxattr: ::c_long = 191; -pub const SYS_lgetxattr: ::c_long = 192; -pub const SYS_fgetxattr: ::c_long = 193; -pub const SYS_listxattr: ::c_long = 194; -pub const SYS_llistxattr: ::c_long = 195; -pub const SYS_flistxattr: ::c_long = 196; -pub const SYS_removexattr: ::c_long = 197; -pub const SYS_lremovexattr: ::c_long = 198; -pub const SYS_fremovexattr: ::c_long = 199; -pub const SYS_tkill: ::c_long = 200; -pub const SYS_time: ::c_long = 201; -pub const SYS_futex: ::c_long = 202; -pub const SYS_sched_setaffinity: ::c_long = 203; -pub const SYS_sched_getaffinity: ::c_long = 204; -pub const SYS_set_thread_area: ::c_long = 205; -pub const SYS_io_setup: ::c_long = 206; -pub const SYS_io_destroy: ::c_long = 207; -pub const SYS_io_getevents: ::c_long = 208; -pub const SYS_io_submit: ::c_long = 209; -pub const SYS_io_cancel: ::c_long = 210; -pub const SYS_get_thread_area: ::c_long = 211; -pub const SYS_lookup_dcookie: ::c_long = 212; -pub const SYS_epoll_create: ::c_long = 213; -pub const SYS_epoll_ctl_old: ::c_long = 214; -pub const SYS_epoll_wait_old: ::c_long = 215; -pub const SYS_remap_file_pages: ::c_long = 216; -pub const SYS_getdents64: ::c_long = 217; -pub const SYS_set_tid_address: ::c_long = 218; -pub const SYS_restart_syscall: ::c_long = 219; -pub const SYS_semtimedop: ::c_long = 220; -pub const SYS_fadvise64: ::c_long = 221; -pub const SYS_timer_create: ::c_long = 222; -pub const SYS_timer_settime: ::c_long = 223; -pub const SYS_timer_gettime: ::c_long = 224; -pub const SYS_timer_getoverrun: ::c_long = 225; -pub const SYS_timer_delete: ::c_long = 226; -pub const SYS_clock_settime: ::c_long = 227; -pub const SYS_clock_gettime: ::c_long = 228; -pub const SYS_clock_getres: ::c_long = 229; -pub const SYS_clock_nanosleep: ::c_long = 230; -pub const SYS_exit_group: ::c_long = 231; -pub const SYS_epoll_wait: ::c_long = 232; -pub const SYS_epoll_ctl: ::c_long = 233; -pub const SYS_tgkill: ::c_long = 234; -pub const SYS_utimes: ::c_long = 235; -pub const SYS_vserver: ::c_long = 236; -pub const SYS_mbind: ::c_long = 237; -pub const SYS_set_mempolicy: ::c_long = 238; -pub const SYS_get_mempolicy: ::c_long = 239; -pub const SYS_mq_open: ::c_long = 240; -pub const SYS_mq_unlink: ::c_long = 241; -pub const SYS_mq_timedsend: ::c_long = 242; -pub const SYS_mq_timedreceive: ::c_long = 243; -pub const SYS_mq_notify: ::c_long = 244; -pub const SYS_mq_getsetattr: ::c_long = 245; -pub const SYS_kexec_load: ::c_long = 246; -pub const SYS_waitid: ::c_long = 247; -pub const SYS_add_key: ::c_long = 248; -pub const SYS_request_key: ::c_long = 249; -pub const SYS_keyctl: ::c_long = 250; -pub const SYS_ioprio_set: ::c_long = 251; -pub const SYS_ioprio_get: ::c_long = 252; -pub const SYS_inotify_init: ::c_long = 253; -pub const SYS_inotify_add_watch: ::c_long = 254; -pub const SYS_inotify_rm_watch: ::c_long = 255; -pub const SYS_migrate_pages: ::c_long = 256; -pub const SYS_openat: ::c_long = 257; -pub const SYS_mkdirat: ::c_long = 258; -pub const SYS_mknodat: ::c_long = 259; -pub const SYS_fchownat: ::c_long = 260; -pub const SYS_futimesat: ::c_long = 261; -pub const SYS_newfstatat: ::c_long = 262; -pub const SYS_unlinkat: ::c_long = 263; -pub const SYS_renameat: ::c_long = 264; -pub const SYS_linkat: ::c_long = 265; -pub const SYS_symlinkat: ::c_long = 266; -pub const SYS_readlinkat: ::c_long = 267; -pub const SYS_fchmodat: ::c_long = 268; -pub const SYS_faccessat: ::c_long = 269; -pub const SYS_pselect6: ::c_long = 270; -pub const SYS_ppoll: ::c_long = 271; -pub const SYS_unshare: ::c_long = 272; -pub const SYS_set_robust_list: ::c_long = 273; -pub const SYS_get_robust_list: ::c_long = 274; -pub const SYS_splice: ::c_long = 275; -pub const SYS_tee: ::c_long = 276; -pub const SYS_sync_file_range: ::c_long = 277; -pub const SYS_vmsplice: ::c_long = 278; -pub const SYS_move_pages: ::c_long = 279; -pub const SYS_utimensat: ::c_long = 280; -pub const SYS_epoll_pwait: ::c_long = 281; -pub const SYS_signalfd: ::c_long = 282; -pub const SYS_timerfd_create: ::c_long = 283; -pub const SYS_eventfd: ::c_long = 284; -pub const SYS_fallocate: ::c_long = 285; -pub const SYS_timerfd_settime: ::c_long = 286; -pub const SYS_timerfd_gettime: ::c_long = 287; -pub const SYS_accept4: ::c_long = 288; -pub const SYS_signalfd4: ::c_long = 289; -pub const SYS_eventfd2: ::c_long = 290; -pub const SYS_epoll_create1: ::c_long = 291; -pub const SYS_dup3: ::c_long = 292; -pub const SYS_pipe2: ::c_long = 293; -pub const SYS_inotify_init1: ::c_long = 294; -pub const SYS_preadv: ::c_long = 295; -pub const SYS_pwritev: ::c_long = 296; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 297; -pub const SYS_perf_event_open: ::c_long = 298; -pub const SYS_recvmmsg: ::c_long = 299; -pub const SYS_fanotify_init: ::c_long = 300; -pub const SYS_fanotify_mark: ::c_long = 301; -pub const SYS_prlimit64: ::c_long = 302; -pub const SYS_name_to_handle_at: ::c_long = 303; -pub const SYS_open_by_handle_at: ::c_long = 304; -pub const SYS_clock_adjtime: ::c_long = 305; -pub const SYS_syncfs: ::c_long = 306; -pub const SYS_sendmmsg: ::c_long = 307; -pub const SYS_setns: ::c_long = 308; -pub const SYS_getcpu: ::c_long = 309; -pub const SYS_process_vm_readv: ::c_long = 310; -pub const SYS_process_vm_writev: ::c_long = 311; -pub const SYS_kcmp: ::c_long = 312; -pub const SYS_finit_module: ::c_long = 313; -pub const SYS_sched_setattr: ::c_long = 314; -pub const SYS_sched_getattr: ::c_long = 315; -pub const SYS_renameat2: ::c_long = 316; -pub const SYS_seccomp: ::c_long = 317; -pub const SYS_getrandom: ::c_long = 318; -pub const SYS_memfd_create: ::c_long = 319; -pub const SYS_kexec_file_load: ::c_long = 320; -pub const SYS_bpf: ::c_long = 321; -pub const SYS_execveat: ::c_long = 322; -pub const SYS_userfaultfd: ::c_long = 323; -pub const SYS_membarrier: ::c_long = 324; -pub const SYS_mlock2: ::c_long = 325; -pub const SYS_copy_file_range: ::c_long = 326; -pub const SYS_preadv2: ::c_long = 327; -pub const SYS_pwritev2: ::c_long = 328; -pub const SYS_pkey_mprotect: ::c_long = 329; -pub const SYS_pkey_alloc: ::c_long = 330; -pub const SYS_pkey_free: ::c_long = 331; -pub const SYS_statx: ::c_long = 332; - -#[link(name = "util")] -extern "C" { - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; -} diff --git a/libc/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs b/libc/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs deleted file mode 100644 index 3746881..0000000 --- a/libc/src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs +++ /dev/null @@ -1,375 +0,0 @@ -use pthread_mutex_t; - -pub type c_long = i32; -pub type c_ulong = u32; - -s! { - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } -} - -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 32; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 44; - -align_const! { - pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; - pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t = - pthread_mutex_t { - size: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ], - }; -} - -// Syscall table - -pub const __X32_SYSCALL_BIT: ::c_long = 0x40000000; - -pub const SYS_read: ::c_long = __X32_SYSCALL_BIT + 0; -pub const SYS_write: ::c_long = __X32_SYSCALL_BIT + 1; -pub const SYS_open: ::c_long = __X32_SYSCALL_BIT + 2; -pub const SYS_close: ::c_long = __X32_SYSCALL_BIT + 3; -pub const SYS_stat: ::c_long = __X32_SYSCALL_BIT + 4; -pub const SYS_fstat: ::c_long = __X32_SYSCALL_BIT + 5; -pub const SYS_lstat: ::c_long = __X32_SYSCALL_BIT + 6; -pub const SYS_poll: ::c_long = __X32_SYSCALL_BIT + 7; -pub const SYS_lseek: ::c_long = __X32_SYSCALL_BIT + 8; -pub const SYS_mmap: ::c_long = __X32_SYSCALL_BIT + 9; -pub const SYS_mprotect: ::c_long = __X32_SYSCALL_BIT + 10; -pub const SYS_munmap: ::c_long = __X32_SYSCALL_BIT + 11; -pub const SYS_brk: ::c_long = __X32_SYSCALL_BIT + 12; -pub const SYS_rt_sigprocmask: ::c_long = __X32_SYSCALL_BIT + 14; -pub const SYS_pread64: ::c_long = __X32_SYSCALL_BIT + 17; -pub const SYS_pwrite64: ::c_long = __X32_SYSCALL_BIT + 18; -pub const SYS_access: ::c_long = __X32_SYSCALL_BIT + 21; -pub const SYS_pipe: ::c_long = __X32_SYSCALL_BIT + 22; -pub const SYS_select: ::c_long = __X32_SYSCALL_BIT + 23; -pub const SYS_sched_yield: ::c_long = __X32_SYSCALL_BIT + 24; -pub const SYS_mremap: ::c_long = __X32_SYSCALL_BIT + 25; -pub const SYS_msync: ::c_long = __X32_SYSCALL_BIT + 26; -pub const SYS_mincore: ::c_long = __X32_SYSCALL_BIT + 27; -pub const SYS_madvise: ::c_long = __X32_SYSCALL_BIT + 28; -pub const SYS_shmget: ::c_long = __X32_SYSCALL_BIT + 29; -pub const SYS_shmat: ::c_long = __X32_SYSCALL_BIT + 30; -pub const SYS_shmctl: ::c_long = __X32_SYSCALL_BIT + 31; -pub const SYS_dup: ::c_long = __X32_SYSCALL_BIT + 32; -pub const SYS_dup2: ::c_long = __X32_SYSCALL_BIT + 33; -pub const SYS_pause: ::c_long = __X32_SYSCALL_BIT + 34; -pub const SYS_nanosleep: ::c_long = __X32_SYSCALL_BIT + 35; -pub const SYS_getitimer: ::c_long = __X32_SYSCALL_BIT + 36; -pub const SYS_alarm: ::c_long = __X32_SYSCALL_BIT + 37; -pub const SYS_setitimer: ::c_long = __X32_SYSCALL_BIT + 38; -pub const SYS_getpid: ::c_long = __X32_SYSCALL_BIT + 39; -pub const SYS_sendfile: ::c_long = __X32_SYSCALL_BIT + 40; -pub const SYS_socket: ::c_long = __X32_SYSCALL_BIT + 41; -pub const SYS_connect: ::c_long = __X32_SYSCALL_BIT + 42; -pub const SYS_accept: ::c_long = __X32_SYSCALL_BIT + 43; -pub const SYS_sendto: ::c_long = __X32_SYSCALL_BIT + 44; -pub const SYS_shutdown: ::c_long = __X32_SYSCALL_BIT + 48; -pub const SYS_bind: ::c_long = __X32_SYSCALL_BIT + 49; -pub const SYS_listen: ::c_long = __X32_SYSCALL_BIT + 50; -pub const SYS_getsockname: ::c_long = __X32_SYSCALL_BIT + 51; -pub const SYS_getpeername: ::c_long = __X32_SYSCALL_BIT + 52; -pub const SYS_socketpair: ::c_long = __X32_SYSCALL_BIT + 53; -pub const SYS_clone: ::c_long = __X32_SYSCALL_BIT + 56; -pub const SYS_fork: ::c_long = __X32_SYSCALL_BIT + 57; -pub const SYS_vfork: ::c_long = __X32_SYSCALL_BIT + 58; -pub const SYS_exit: ::c_long = __X32_SYSCALL_BIT + 60; -pub const SYS_wait4: ::c_long = __X32_SYSCALL_BIT + 61; -pub const SYS_kill: ::c_long = __X32_SYSCALL_BIT + 62; -pub const SYS_uname: ::c_long = __X32_SYSCALL_BIT + 63; -pub const SYS_semget: ::c_long = __X32_SYSCALL_BIT + 64; -pub const SYS_semop: ::c_long = __X32_SYSCALL_BIT + 65; -pub const SYS_semctl: ::c_long = __X32_SYSCALL_BIT + 66; -pub const SYS_shmdt: ::c_long = __X32_SYSCALL_BIT + 67; -pub const SYS_msgget: ::c_long = __X32_SYSCALL_BIT + 68; -pub const SYS_msgsnd: ::c_long = __X32_SYSCALL_BIT + 69; -pub const SYS_msgrcv: ::c_long = __X32_SYSCALL_BIT + 70; -pub const SYS_msgctl: ::c_long = __X32_SYSCALL_BIT + 71; -pub const SYS_fcntl: ::c_long = __X32_SYSCALL_BIT + 72; -pub const SYS_flock: ::c_long = __X32_SYSCALL_BIT + 73; -pub const SYS_fsync: ::c_long = __X32_SYSCALL_BIT + 74; -pub const SYS_fdatasync: ::c_long = __X32_SYSCALL_BIT + 75; -pub const SYS_truncate: ::c_long = __X32_SYSCALL_BIT + 76; -pub const SYS_ftruncate: ::c_long = __X32_SYSCALL_BIT + 77; -pub const SYS_getdents: ::c_long = __X32_SYSCALL_BIT + 78; -pub const SYS_getcwd: ::c_long = __X32_SYSCALL_BIT + 79; -pub const SYS_chdir: ::c_long = __X32_SYSCALL_BIT + 80; -pub const SYS_fchdir: ::c_long = __X32_SYSCALL_BIT + 81; -pub const SYS_rename: ::c_long = __X32_SYSCALL_BIT + 82; -pub const SYS_mkdir: ::c_long = __X32_SYSCALL_BIT + 83; -pub const SYS_rmdir: ::c_long = __X32_SYSCALL_BIT + 84; -pub const SYS_creat: ::c_long = __X32_SYSCALL_BIT + 85; -pub const SYS_link: ::c_long = __X32_SYSCALL_BIT + 86; -pub const SYS_unlink: ::c_long = __X32_SYSCALL_BIT + 87; -pub const SYS_symlink: ::c_long = __X32_SYSCALL_BIT + 88; -pub const SYS_readlink: ::c_long = __X32_SYSCALL_BIT + 89; -pub const SYS_chmod: ::c_long = __X32_SYSCALL_BIT + 90; -pub const SYS_fchmod: ::c_long = __X32_SYSCALL_BIT + 91; -pub const SYS_chown: ::c_long = __X32_SYSCALL_BIT + 92; -pub const SYS_fchown: ::c_long = __X32_SYSCALL_BIT + 93; -pub const SYS_lchown: ::c_long = __X32_SYSCALL_BIT + 94; -pub const SYS_umask: ::c_long = __X32_SYSCALL_BIT + 95; -pub const SYS_gettimeofday: ::c_long = __X32_SYSCALL_BIT + 96; -pub const SYS_getrlimit: ::c_long = __X32_SYSCALL_BIT + 97; -pub const SYS_getrusage: ::c_long = __X32_SYSCALL_BIT + 98; -pub const SYS_sysinfo: ::c_long = __X32_SYSCALL_BIT + 99; -pub const SYS_times: ::c_long = __X32_SYSCALL_BIT + 100; -pub const SYS_getuid: ::c_long = __X32_SYSCALL_BIT + 102; -pub const SYS_syslog: ::c_long = __X32_SYSCALL_BIT + 103; -pub const SYS_getgid: ::c_long = __X32_SYSCALL_BIT + 104; -pub const SYS_setuid: ::c_long = __X32_SYSCALL_BIT + 105; -pub const SYS_setgid: ::c_long = __X32_SYSCALL_BIT + 106; -pub const SYS_geteuid: ::c_long = __X32_SYSCALL_BIT + 107; -pub const SYS_getegid: ::c_long = __X32_SYSCALL_BIT + 108; -pub const SYS_setpgid: ::c_long = __X32_SYSCALL_BIT + 109; -pub const SYS_getppid: ::c_long = __X32_SYSCALL_BIT + 110; -pub const SYS_getpgrp: ::c_long = __X32_SYSCALL_BIT + 111; -pub const SYS_setsid: ::c_long = __X32_SYSCALL_BIT + 112; -pub const SYS_setreuid: ::c_long = __X32_SYSCALL_BIT + 113; -pub const SYS_setregid: ::c_long = __X32_SYSCALL_BIT + 114; -pub const SYS_getgroups: ::c_long = __X32_SYSCALL_BIT + 115; -pub const SYS_setgroups: ::c_long = __X32_SYSCALL_BIT + 116; -pub const SYS_setresuid: ::c_long = __X32_SYSCALL_BIT + 117; -pub const SYS_getresuid: ::c_long = __X32_SYSCALL_BIT + 118; -pub const SYS_setresgid: ::c_long = __X32_SYSCALL_BIT + 119; -pub const SYS_getresgid: ::c_long = __X32_SYSCALL_BIT + 120; -pub const SYS_getpgid: ::c_long = __X32_SYSCALL_BIT + 121; -pub const SYS_setfsuid: ::c_long = __X32_SYSCALL_BIT + 122; -pub const SYS_setfsgid: ::c_long = __X32_SYSCALL_BIT + 123; -pub const SYS_getsid: ::c_long = __X32_SYSCALL_BIT + 124; -pub const SYS_capget: ::c_long = __X32_SYSCALL_BIT + 125; -pub const SYS_capset: ::c_long = __X32_SYSCALL_BIT + 126; -pub const SYS_rt_sigsuspend: ::c_long = __X32_SYSCALL_BIT + 130; -pub const SYS_utime: ::c_long = __X32_SYSCALL_BIT + 132; -pub const SYS_mknod: ::c_long = __X32_SYSCALL_BIT + 133; -pub const SYS_personality: ::c_long = __X32_SYSCALL_BIT + 135; -pub const SYS_ustat: ::c_long = __X32_SYSCALL_BIT + 136; -pub const SYS_statfs: ::c_long = __X32_SYSCALL_BIT + 137; -pub const SYS_fstatfs: ::c_long = __X32_SYSCALL_BIT + 138; -pub const SYS_sysfs: ::c_long = __X32_SYSCALL_BIT + 139; -pub const SYS_getpriority: ::c_long = __X32_SYSCALL_BIT + 140; -pub const SYS_setpriority: ::c_long = __X32_SYSCALL_BIT + 141; -pub const SYS_sched_setparam: ::c_long = __X32_SYSCALL_BIT + 142; -pub const SYS_sched_getparam: ::c_long = __X32_SYSCALL_BIT + 143; -pub const SYS_sched_setscheduler: ::c_long = __X32_SYSCALL_BIT + 144; -pub const SYS_sched_getscheduler: ::c_long = __X32_SYSCALL_BIT + 145; -pub const SYS_sched_get_priority_max: ::c_long = __X32_SYSCALL_BIT + 146; -pub const SYS_sched_get_priority_min: ::c_long = __X32_SYSCALL_BIT + 147; -pub const SYS_sched_rr_get_interval: ::c_long = __X32_SYSCALL_BIT + 148; -pub const SYS_mlock: ::c_long = __X32_SYSCALL_BIT + 149; -pub const SYS_munlock: ::c_long = __X32_SYSCALL_BIT + 150; -pub const SYS_mlockall: ::c_long = __X32_SYSCALL_BIT + 151; -pub const SYS_munlockall: ::c_long = __X32_SYSCALL_BIT + 152; -pub const SYS_vhangup: ::c_long = __X32_SYSCALL_BIT + 153; -pub const SYS_modify_ldt: ::c_long = __X32_SYSCALL_BIT + 154; -pub const SYS_pivot_root: ::c_long = __X32_SYSCALL_BIT + 155; -pub const SYS_prctl: ::c_long = __X32_SYSCALL_BIT + 157; -pub const SYS_arch_prctl: ::c_long = __X32_SYSCALL_BIT + 158; -pub const SYS_adjtimex: ::c_long = __X32_SYSCALL_BIT + 159; -pub const SYS_setrlimit: ::c_long = __X32_SYSCALL_BIT + 160; -pub const SYS_chroot: ::c_long = __X32_SYSCALL_BIT + 161; -pub const SYS_sync: ::c_long = __X32_SYSCALL_BIT + 162; -pub const SYS_acct: ::c_long = __X32_SYSCALL_BIT + 163; -pub const SYS_settimeofday: ::c_long = __X32_SYSCALL_BIT + 164; -pub const SYS_mount: ::c_long = __X32_SYSCALL_BIT + 165; -pub const SYS_umount2: ::c_long = __X32_SYSCALL_BIT + 166; -pub const SYS_swapon: ::c_long = __X32_SYSCALL_BIT + 167; -pub const SYS_swapoff: ::c_long = __X32_SYSCALL_BIT + 168; -pub const SYS_reboot: ::c_long = __X32_SYSCALL_BIT + 169; -pub const SYS_sethostname: ::c_long = __X32_SYSCALL_BIT + 170; -pub const SYS_setdomainname: ::c_long = __X32_SYSCALL_BIT + 171; -pub const SYS_iopl: ::c_long = __X32_SYSCALL_BIT + 172; -pub const SYS_ioperm: ::c_long = __X32_SYSCALL_BIT + 173; -pub const SYS_init_module: ::c_long = __X32_SYSCALL_BIT + 175; -pub const SYS_delete_module: ::c_long = __X32_SYSCALL_BIT + 176; -pub const SYS_quotactl: ::c_long = __X32_SYSCALL_BIT + 179; -pub const SYS_getpmsg: ::c_long = __X32_SYSCALL_BIT + 181; -pub const SYS_putpmsg: ::c_long = __X32_SYSCALL_BIT + 182; -pub const SYS_afs_syscall: ::c_long = __X32_SYSCALL_BIT + 183; -pub const SYS_tuxcall: ::c_long = __X32_SYSCALL_BIT + 184; -pub const SYS_security: ::c_long = __X32_SYSCALL_BIT + 185; -pub const SYS_gettid: ::c_long = __X32_SYSCALL_BIT + 186; -pub const SYS_readahead: ::c_long = __X32_SYSCALL_BIT + 187; -pub const SYS_setxattr: ::c_long = __X32_SYSCALL_BIT + 188; -pub const SYS_lsetxattr: ::c_long = __X32_SYSCALL_BIT + 189; -pub const SYS_fsetxattr: ::c_long = __X32_SYSCALL_BIT + 190; -pub const SYS_getxattr: ::c_long = __X32_SYSCALL_BIT + 191; -pub const SYS_lgetxattr: ::c_long = __X32_SYSCALL_BIT + 192; -pub const SYS_fgetxattr: ::c_long = __X32_SYSCALL_BIT + 193; -pub const SYS_listxattr: ::c_long = __X32_SYSCALL_BIT + 194; -pub const SYS_llistxattr: ::c_long = __X32_SYSCALL_BIT + 195; -pub const SYS_flistxattr: ::c_long = __X32_SYSCALL_BIT + 196; -pub const SYS_removexattr: ::c_long = __X32_SYSCALL_BIT + 197; -pub const SYS_lremovexattr: ::c_long = __X32_SYSCALL_BIT + 198; -pub const SYS_fremovexattr: ::c_long = __X32_SYSCALL_BIT + 199; -pub const SYS_tkill: ::c_long = __X32_SYSCALL_BIT + 200; -pub const SYS_time: ::c_long = __X32_SYSCALL_BIT + 201; -pub const SYS_futex: ::c_long = __X32_SYSCALL_BIT + 202; -pub const SYS_sched_setaffinity: ::c_long = __X32_SYSCALL_BIT + 203; -pub const SYS_sched_getaffinity: ::c_long = __X32_SYSCALL_BIT + 204; -pub const SYS_io_destroy: ::c_long = __X32_SYSCALL_BIT + 207; -pub const SYS_io_getevents: ::c_long = __X32_SYSCALL_BIT + 208; -pub const SYS_io_cancel: ::c_long = __X32_SYSCALL_BIT + 210; -pub const SYS_lookup_dcookie: ::c_long = __X32_SYSCALL_BIT + 212; -pub const SYS_epoll_create: ::c_long = __X32_SYSCALL_BIT + 213; -pub const SYS_remap_file_pages: ::c_long = __X32_SYSCALL_BIT + 216; -pub const SYS_getdents64: ::c_long = __X32_SYSCALL_BIT + 217; -pub const SYS_set_tid_address: ::c_long = __X32_SYSCALL_BIT + 218; -pub const SYS_restart_syscall: ::c_long = __X32_SYSCALL_BIT + 219; -pub const SYS_semtimedop: ::c_long = __X32_SYSCALL_BIT + 220; -pub const SYS_fadvise64: ::c_long = __X32_SYSCALL_BIT + 221; -pub const SYS_timer_settime: ::c_long = __X32_SYSCALL_BIT + 223; -pub const SYS_timer_gettime: ::c_long = __X32_SYSCALL_BIT + 224; -pub const SYS_timer_getoverrun: ::c_long = __X32_SYSCALL_BIT + 225; -pub const SYS_timer_delete: ::c_long = __X32_SYSCALL_BIT + 226; -pub const SYS_clock_settime: ::c_long = __X32_SYSCALL_BIT + 227; -pub const SYS_clock_gettime: ::c_long = __X32_SYSCALL_BIT + 228; -pub const SYS_clock_getres: ::c_long = __X32_SYSCALL_BIT + 229; -pub const SYS_clock_nanosleep: ::c_long = __X32_SYSCALL_BIT + 230; -pub const SYS_exit_group: ::c_long = __X32_SYSCALL_BIT + 231; -pub const SYS_epoll_wait: ::c_long = __X32_SYSCALL_BIT + 232; -pub const SYS_epoll_ctl: ::c_long = __X32_SYSCALL_BIT + 233; -pub const SYS_tgkill: ::c_long = __X32_SYSCALL_BIT + 234; -pub const SYS_utimes: ::c_long = __X32_SYSCALL_BIT + 235; -pub const SYS_mbind: ::c_long = __X32_SYSCALL_BIT + 237; -pub const SYS_set_mempolicy: ::c_long = __X32_SYSCALL_BIT + 238; -pub const SYS_get_mempolicy: ::c_long = __X32_SYSCALL_BIT + 239; -pub const SYS_mq_open: ::c_long = __X32_SYSCALL_BIT + 240; -pub const SYS_mq_unlink: ::c_long = __X32_SYSCALL_BIT + 241; -pub const SYS_mq_timedsend: ::c_long = __X32_SYSCALL_BIT + 242; -pub const SYS_mq_timedreceive: ::c_long = __X32_SYSCALL_BIT + 243; -pub const SYS_mq_getsetattr: ::c_long = __X32_SYSCALL_BIT + 245; -pub const SYS_add_key: ::c_long = __X32_SYSCALL_BIT + 248; -pub const SYS_request_key: ::c_long = __X32_SYSCALL_BIT + 249; -pub const SYS_keyctl: ::c_long = __X32_SYSCALL_BIT + 250; -pub const SYS_ioprio_set: ::c_long = __X32_SYSCALL_BIT + 251; -pub const SYS_ioprio_get: ::c_long = __X32_SYSCALL_BIT + 252; -pub const SYS_inotify_init: ::c_long = __X32_SYSCALL_BIT + 253; -pub const SYS_inotify_add_watch: ::c_long = __X32_SYSCALL_BIT + 254; -pub const SYS_inotify_rm_watch: ::c_long = __X32_SYSCALL_BIT + 255; -pub const SYS_migrate_pages: ::c_long = __X32_SYSCALL_BIT + 256; -pub const SYS_openat: ::c_long = __X32_SYSCALL_BIT + 257; -pub const SYS_mkdirat: ::c_long = __X32_SYSCALL_BIT + 258; -pub const SYS_mknodat: ::c_long = __X32_SYSCALL_BIT + 259; -pub const SYS_fchownat: ::c_long = __X32_SYSCALL_BIT + 260; -pub const SYS_futimesat: ::c_long = __X32_SYSCALL_BIT + 261; -pub const SYS_newfstatat: ::c_long = __X32_SYSCALL_BIT + 262; -pub const SYS_unlinkat: ::c_long = __X32_SYSCALL_BIT + 263; -pub const SYS_renameat: ::c_long = __X32_SYSCALL_BIT + 264; -pub const SYS_linkat: ::c_long = __X32_SYSCALL_BIT + 265; -pub const SYS_symlinkat: ::c_long = __X32_SYSCALL_BIT + 266; -pub const SYS_readlinkat: ::c_long = __X32_SYSCALL_BIT + 267; -pub const SYS_fchmodat: ::c_long = __X32_SYSCALL_BIT + 268; -pub const SYS_faccessat: ::c_long = __X32_SYSCALL_BIT + 269; -pub const SYS_pselect6: ::c_long = __X32_SYSCALL_BIT + 270; -pub const SYS_ppoll: ::c_long = __X32_SYSCALL_BIT + 271; -pub const SYS_unshare: ::c_long = __X32_SYSCALL_BIT + 272; -pub const SYS_splice: ::c_long = __X32_SYSCALL_BIT + 275; -pub const SYS_tee: ::c_long = __X32_SYSCALL_BIT + 276; -pub const SYS_sync_file_range: ::c_long = __X32_SYSCALL_BIT + 277; -pub const SYS_utimensat: ::c_long = __X32_SYSCALL_BIT + 280; -pub const SYS_epoll_pwait: ::c_long = __X32_SYSCALL_BIT + 281; -pub const SYS_signalfd: ::c_long = __X32_SYSCALL_BIT + 282; -pub const SYS_timerfd_create: ::c_long = __X32_SYSCALL_BIT + 283; -pub const SYS_eventfd: ::c_long = __X32_SYSCALL_BIT + 284; -pub const SYS_fallocate: ::c_long = __X32_SYSCALL_BIT + 285; -pub const SYS_timerfd_settime: ::c_long = __X32_SYSCALL_BIT + 286; -pub const SYS_timerfd_gettime: ::c_long = __X32_SYSCALL_BIT + 287; -pub const SYS_accept4: ::c_long = __X32_SYSCALL_BIT + 288; -pub const SYS_signalfd4: ::c_long = __X32_SYSCALL_BIT + 289; -pub const SYS_eventfd2: ::c_long = __X32_SYSCALL_BIT + 290; -pub const SYS_epoll_create1: ::c_long = __X32_SYSCALL_BIT + 291; -pub const SYS_dup3: ::c_long = __X32_SYSCALL_BIT + 292; -pub const SYS_pipe2: ::c_long = __X32_SYSCALL_BIT + 293; -pub const SYS_inotify_init1: ::c_long = __X32_SYSCALL_BIT + 294; -pub const SYS_perf_event_open: ::c_long = __X32_SYSCALL_BIT + 298; -pub const SYS_fanotify_init: ::c_long = __X32_SYSCALL_BIT + 300; -pub const SYS_fanotify_mark: ::c_long = __X32_SYSCALL_BIT + 301; -pub const SYS_prlimit64: ::c_long = __X32_SYSCALL_BIT + 302; -pub const SYS_name_to_handle_at: ::c_long = __X32_SYSCALL_BIT + 303; -pub const SYS_open_by_handle_at: ::c_long = __X32_SYSCALL_BIT + 304; -pub const SYS_clock_adjtime: ::c_long = __X32_SYSCALL_BIT + 305; -pub const SYS_syncfs: ::c_long = __X32_SYSCALL_BIT + 306; -pub const SYS_setns: ::c_long = __X32_SYSCALL_BIT + 308; -pub const SYS_getcpu: ::c_long = __X32_SYSCALL_BIT + 309; -pub const SYS_kcmp: ::c_long = __X32_SYSCALL_BIT + 312; -pub const SYS_finit_module: ::c_long = __X32_SYSCALL_BIT + 313; -pub const SYS_sched_setattr: ::c_long = __X32_SYSCALL_BIT + 314; -pub const SYS_sched_getattr: ::c_long = __X32_SYSCALL_BIT + 315; -pub const SYS_renameat2: ::c_long = __X32_SYSCALL_BIT + 316; -pub const SYS_seccomp: ::c_long = __X32_SYSCALL_BIT + 317; -pub const SYS_getrandom: ::c_long = __X32_SYSCALL_BIT + 318; -pub const SYS_memfd_create: ::c_long = __X32_SYSCALL_BIT + 319; -pub const SYS_kexec_file_load: ::c_long = __X32_SYSCALL_BIT + 320; -pub const SYS_bpf: ::c_long = __X32_SYSCALL_BIT + 321; -pub const SYS_userfaultfd: ::c_long = __X32_SYSCALL_BIT + 323; -pub const SYS_membarrier: ::c_long = __X32_SYSCALL_BIT + 324; -pub const SYS_mlock2: ::c_long = __X32_SYSCALL_BIT + 325; -pub const SYS_copy_file_range: ::c_long = __X32_SYSCALL_BIT + 326; -pub const SYS_pkey_mprotect: ::c_long = __X32_SYSCALL_BIT + 329; -pub const SYS_pkey_alloc: ::c_long = __X32_SYSCALL_BIT + 330; -pub const SYS_pkey_free: ::c_long = __X32_SYSCALL_BIT + 331; -pub const SYS_statx: ::c_long = __X32_SYSCALL_BIT + 332; -pub const SYS_rt_sigaction: ::c_long = __X32_SYSCALL_BIT + 512; -pub const SYS_rt_sigreturn: ::c_long = __X32_SYSCALL_BIT + 513; -pub const SYS_ioctl: ::c_long = __X32_SYSCALL_BIT + 514; -pub const SYS_readv: ::c_long = __X32_SYSCALL_BIT + 515; -pub const SYS_writev: ::c_long = __X32_SYSCALL_BIT + 516; -pub const SYS_recvfrom: ::c_long = __X32_SYSCALL_BIT + 517; -pub const SYS_sendmsg: ::c_long = __X32_SYSCALL_BIT + 518; -pub const SYS_recvmsg: ::c_long = __X32_SYSCALL_BIT + 519; -pub const SYS_execve: ::c_long = __X32_SYSCALL_BIT + 520; -pub const SYS_ptrace: ::c_long = __X32_SYSCALL_BIT + 521; -pub const SYS_rt_sigpending: ::c_long = __X32_SYSCALL_BIT + 522; -pub const SYS_rt_sigtimedwait: ::c_long = __X32_SYSCALL_BIT + 523; -pub const SYS_rt_sigqueueinfo: ::c_long = __X32_SYSCALL_BIT + 524; -pub const SYS_sigaltstack: ::c_long = __X32_SYSCALL_BIT + 525; -pub const SYS_timer_create: ::c_long = __X32_SYSCALL_BIT + 526; -pub const SYS_mq_notify: ::c_long = __X32_SYSCALL_BIT + 527; -pub const SYS_kexec_load: ::c_long = __X32_SYSCALL_BIT + 528; -pub const SYS_waitid: ::c_long = __X32_SYSCALL_BIT + 529; -pub const SYS_set_robust_list: ::c_long = __X32_SYSCALL_BIT + 530; -pub const SYS_get_robust_list: ::c_long = __X32_SYSCALL_BIT + 531; -pub const SYS_vmsplice: ::c_long = __X32_SYSCALL_BIT + 532; -pub const SYS_move_pages: ::c_long = __X32_SYSCALL_BIT + 533; -pub const SYS_preadv: ::c_long = __X32_SYSCALL_BIT + 534; -pub const SYS_pwritev: ::c_long = __X32_SYSCALL_BIT + 535; -pub const SYS_rt_tgsigqueueinfo: ::c_long = __X32_SYSCALL_BIT + 536; -pub const SYS_recvmmsg: ::c_long = __X32_SYSCALL_BIT + 537; -pub const SYS_sendmmsg: ::c_long = __X32_SYSCALL_BIT + 538; -pub const SYS_process_vm_readv: ::c_long = __X32_SYSCALL_BIT + 539; -pub const SYS_process_vm_writev: ::c_long = __X32_SYSCALL_BIT + 540; -pub const SYS_setsockopt: ::c_long = __X32_SYSCALL_BIT + 541; -pub const SYS_getsockopt: ::c_long = __X32_SYSCALL_BIT + 542; -pub const SYS_io_setup: ::c_long = __X32_SYSCALL_BIT + 543; -pub const SYS_io_submit: ::c_long = __X32_SYSCALL_BIT + 544; -pub const SYS_execveat: ::c_long = __X32_SYSCALL_BIT + 545; -pub const SYS_preadv2: ::c_long = __X32_SYSCALL_BIT + 546; -pub const SYS_pwritev2: ::c_long = __X32_SYSCALL_BIT + 547; diff --git a/libc/src/unix/linux_like/linux/gnu/mod.rs b/libc/src/unix/linux_like/linux/gnu/mod.rs deleted file mode 100644 index 1d3e0ab..0000000 --- a/libc/src/unix/linux_like/linux/gnu/mod.rs +++ /dev/null @@ -1,1057 +0,0 @@ -pub type pthread_t = c_ulong; -pub type __priority_which_t = ::c_uint; -pub type __rlimit_resource_t = ::c_uint; - -s! { - pub struct statx { - pub stx_mask: u32, - pub stx_blksize: u32, - pub stx_attributes: u64, - pub stx_nlink: u32, - pub stx_uid: u32, - pub stx_gid: u32, - pub stx_mode: u16, - pub __statx_pad1: [u16; 1], - pub stx_ino: u64, - pub stx_size: u64, - pub stx_blocks: u64, - pub stx_attributes_mask: u64, - pub stx_atime: ::statx_timestamp, - pub stx_btime: ::statx_timestamp, - pub stx_ctime: ::statx_timestamp, - pub stx_mtime: ::statx_timestamp, - pub stx_rdev_major: u32, - pub stx_rdev_minor: u32, - pub stx_dev_major: u32, - pub stx_dev_minor: u32, - pub __statx_pad2: [u64; 14], - } - - pub struct statx_timestamp { - pub tv_sec: i64, - pub tv_nsec: u32, - pub __statx_timestamp_pad1: [i32; 1], - } - - pub struct aiocb { - pub aio_fildes: ::c_int, - pub aio_lio_opcode: ::c_int, - pub aio_reqprio: ::c_int, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - pub aio_sigevent: ::sigevent, - __next_prio: *mut aiocb, - __abs_prio: ::c_int, - __policy: ::c_int, - __error_code: ::c_int, - __return_value: ::ssize_t, - pub aio_offset: off_t, - #[cfg(all(not(target_arch = "x86_64"), target_pointer_width = "32"))] - __unused1: [::c_char; 4], - __glibc_reserved: [::c_char; 32] - } - - pub struct __exit_status { - pub e_termination: ::c_short, - pub e_exit: ::c_short, - } - - pub struct __timeval { - pub tv_sec: i32, - pub tv_usec: i32, - } - - pub struct glob64_t { - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut ::c_char, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::size_t, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::size_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::size_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - #[cfg(not(any( - target_arch = "sparc", - target_arch = "sparc64", - target_arch = "mips", - target_arch = "mips64")))] - pub c_ispeed: ::speed_t, - #[cfg(not(any( - target_arch = "sparc", - target_arch = "sparc64", - target_arch = "mips", - target_arch = "mips64")))] - pub c_ospeed: ::speed_t, - } - - pub struct mallinfo { - pub arena: ::c_int, - pub ordblks: ::c_int, - pub smblks: ::c_int, - pub hblks: ::c_int, - pub hblkhd: ::c_int, - pub usmblks: ::c_int, - pub fsmblks: ::c_int, - pub uordblks: ::c_int, - pub fordblks: ::c_int, - pub keepcost: ::c_int, - } - - pub struct nlmsghdr { - pub nlmsg_len: u32, - pub nlmsg_type: u16, - pub nlmsg_flags: u16, - pub nlmsg_seq: u32, - pub nlmsg_pid: u32, - } - - pub struct nlmsgerr { - pub error: ::c_int, - pub msg: nlmsghdr, - } - - pub struct nl_pktinfo { - pub group: u32, - } - - pub struct nl_mmap_req { - pub nm_block_size: ::c_uint, - pub nm_block_nr: ::c_uint, - pub nm_frame_size: ::c_uint, - pub nm_frame_nr: ::c_uint, - } - - pub struct nl_mmap_hdr { - pub nm_status: ::c_uint, - pub nm_len: ::c_uint, - pub nm_group: u32, - pub nm_pid: u32, - pub nm_uid: u32, - pub nm_gid: u32, - } - - pub struct nlattr { - pub nla_len: u16, - pub nla_type: u16, - } - - pub struct rtentry { - pub rt_pad1: ::c_ulong, - pub rt_dst: ::sockaddr, - pub rt_gateway: ::sockaddr, - pub rt_genmask: ::sockaddr, - pub rt_flags: ::c_ushort, - pub rt_pad2: ::c_short, - pub rt_pad3: ::c_ulong, - pub rt_tos: ::c_uchar, - pub rt_class: ::c_uchar, - #[cfg(target_pointer_width = "64")] - pub rt_pad4: [::c_short; 3usize], - #[cfg(not(target_pointer_width = "64"))] - pub rt_pad4: ::c_short, - pub rt_metric: ::c_short, - pub rt_dev: *mut ::c_char, - pub rt_mtu: ::c_ulong, - pub rt_window: ::c_ulong, - pub rt_irtt: ::c_ushort, - } -} - -impl siginfo_t { - pub unsafe fn si_addr(&self) -> *mut ::c_void { - #[repr(C)] - struct siginfo_sigfault { - _si_signo: ::c_int, - _si_errno: ::c_int, - _si_code: ::c_int, - si_addr: *mut ::c_void, - } - (*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr - } - - pub unsafe fn si_value(&self) -> ::sigval { - #[repr(C)] - struct siginfo_timer { - _si_signo: ::c_int, - _si_errno: ::c_int, - _si_code: ::c_int, - _si_tid: ::c_int, - _si_overrun: ::c_int, - si_sigval: ::sigval, - } - (*(self as *const siginfo_t as *const siginfo_timer)).si_sigval - } -} - -s_no_extra_traits! { - pub struct utmpx { - pub ut_type: ::c_short, - pub ut_pid: ::pid_t, - pub ut_line: [::c_char; __UT_LINESIZE], - pub ut_id: [::c_char; 4], - - pub ut_user: [::c_char; __UT_NAMESIZE], - pub ut_host: [::c_char; __UT_HOSTSIZE], - pub ut_exit: __exit_status, - - #[cfg(any(target_arch = "aarch64", - target_arch = "s390x", - all(target_pointer_width = "32", - not(target_arch = "x86_64"))))] - pub ut_session: ::c_long, - #[cfg(any(target_arch = "aarch64", - target_arch = "s390x", - all(target_pointer_width = "32", - not(target_arch = "x86_64"))))] - pub ut_tv: ::timeval, - - #[cfg(not(any(target_arch = "aarch64", - target_arch = "s390x", - all(target_pointer_width = "32", - not(target_arch = "x86_64")))))] - pub ut_session: i32, - #[cfg(not(any(target_arch = "aarch64", - target_arch = "s390x", - all(target_pointer_width = "32", - not(target_arch = "x86_64")))))] - pub ut_tv: __timeval, - - pub ut_addr_v6: [i32; 4], - __glibc_reserved: [::c_char; 20], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for utmpx { - fn eq(&self, other: &utmpx) -> bool { - self.ut_type == other.ut_type - && self.ut_pid == other.ut_pid - && self.ut_line == other.ut_line - && self.ut_id == other.ut_id - && self.ut_user == other.ut_user - && self - .ut_host - .iter() - .zip(other.ut_host.iter()) - .all(|(a,b)| a == b) - && self.ut_exit == other.ut_exit - && self.ut_session == other.ut_session - && self.ut_tv == other.ut_tv - && self.ut_addr_v6 == other.ut_addr_v6 - && self.__glibc_reserved == other.__glibc_reserved - } - } - - impl Eq for utmpx {} - - impl ::fmt::Debug for utmpx { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utmpx") - .field("ut_type", &self.ut_type) - .field("ut_pid", &self.ut_pid) - .field("ut_line", &self.ut_line) - .field("ut_id", &self.ut_id) - .field("ut_user", &self.ut_user) - // FIXME: .field("ut_host", &self.ut_host) - .field("ut_exit", &self.ut_exit) - .field("ut_session", &self.ut_session) - .field("ut_tv", &self.ut_tv) - .field("ut_addr_v6", &self.ut_addr_v6) - .field("__glibc_reserved", &self.__glibc_reserved) - .finish() - } - } - - impl ::hash::Hash for utmpx { - fn hash(&self, state: &mut H) { - self.ut_type.hash(state); - self.ut_pid.hash(state); - self.ut_line.hash(state); - self.ut_id.hash(state); - self.ut_user.hash(state); - self.ut_host.hash(state); - self.ut_exit.hash(state); - self.ut_session.hash(state); - self.ut_tv.hash(state); - self.ut_addr_v6.hash(state); - self.__glibc_reserved.hash(state); - } - } - } -} - -pub const RLIMIT_CPU: ::__rlimit_resource_t = 0; -pub const RLIMIT_FSIZE: ::__rlimit_resource_t = 1; -pub const RLIMIT_DATA: ::__rlimit_resource_t = 2; -pub const RLIMIT_STACK: ::__rlimit_resource_t = 3; -pub const RLIMIT_CORE: ::__rlimit_resource_t = 4; -pub const RLIMIT_LOCKS: ::__rlimit_resource_t = 10; -pub const RLIMIT_SIGPENDING: ::__rlimit_resource_t = 11; -pub const RLIMIT_MSGQUEUE: ::__rlimit_resource_t = 12; -pub const RLIMIT_NICE: ::__rlimit_resource_t = 13; -pub const RLIMIT_RTPRIO: ::__rlimit_resource_t = 14; -pub const RLIMIT_RTTIME: ::__rlimit_resource_t = 15; -pub const RLIMIT_NLIMITS: ::__rlimit_resource_t = 16; - -pub const MS_RMT_MASK: ::c_ulong = 0x02800051; - -pub const __UT_LINESIZE: usize = 32; -pub const __UT_NAMESIZE: usize = 32; -pub const __UT_HOSTSIZE: usize = 256; -pub const EMPTY: ::c_short = 0; -pub const RUN_LVL: ::c_short = 1; -pub const BOOT_TIME: ::c_short = 2; -pub const NEW_TIME: ::c_short = 3; -pub const OLD_TIME: ::c_short = 4; -pub const INIT_PROCESS: ::c_short = 5; -pub const LOGIN_PROCESS: ::c_short = 6; -pub const USER_PROCESS: ::c_short = 7; -pub const DEAD_PROCESS: ::c_short = 8; -pub const ACCOUNTING: ::c_short = 9; - -pub const SOCK_NONBLOCK: ::c_int = O_NONBLOCK; - -pub const SOL_RXRPC: ::c_int = 272; -pub const SOL_PPPOL2TP: ::c_int = 273; -pub const SOL_PNPIPE: ::c_int = 275; -pub const SOL_RDS: ::c_int = 276; -pub const SOL_IUCV: ::c_int = 277; -pub const SOL_CAIF: ::c_int = 278; -pub const SOL_NFC: ::c_int = 280; -pub const SOL_XDP: ::c_int = 283; - -pub const MSG_TRYHARD: ::c_int = 4; - -pub const LC_PAPER: ::c_int = 7; -pub const LC_NAME: ::c_int = 8; -pub const LC_ADDRESS: ::c_int = 9; -pub const LC_TELEPHONE: ::c_int = 10; -pub const LC_MEASUREMENT: ::c_int = 11; -pub const LC_IDENTIFICATION: ::c_int = 12; -pub const LC_PAPER_MASK: ::c_int = (1 << LC_PAPER); -pub const LC_NAME_MASK: ::c_int = (1 << LC_NAME); -pub const LC_ADDRESS_MASK: ::c_int = (1 << LC_ADDRESS); -pub const LC_TELEPHONE_MASK: ::c_int = (1 << LC_TELEPHONE); -pub const LC_MEASUREMENT_MASK: ::c_int = (1 << LC_MEASUREMENT); -pub const LC_IDENTIFICATION_MASK: ::c_int = (1 << LC_IDENTIFICATION); -pub const LC_ALL_MASK: ::c_int = ::LC_CTYPE_MASK - | ::LC_NUMERIC_MASK - | ::LC_TIME_MASK - | ::LC_COLLATE_MASK - | ::LC_MONETARY_MASK - | ::LC_MESSAGES_MASK - | LC_PAPER_MASK - | LC_NAME_MASK - | LC_ADDRESS_MASK - | LC_TELEPHONE_MASK - | LC_MEASUREMENT_MASK - | LC_IDENTIFICATION_MASK; - -pub const MAP_SHARED_VALIDATE: ::c_int = 0x3; -pub const MAP_FIXED_NOREPLACE: ::c_int = 0x100000; - -pub const ENOTSUP: ::c_int = EOPNOTSUPP; - -pub const SOCK_SEQPACKET: ::c_int = 5; -pub const SOCK_DCCP: ::c_int = 6; -pub const SOCK_PACKET: ::c_int = 10; - -pub const TCP_COOKIE_TRANSACTIONS: ::c_int = 15; -pub const TCP_THIN_LINEAR_TIMEOUTS: ::c_int = 16; -pub const TCP_THIN_DUPACK: ::c_int = 17; -pub const TCP_USER_TIMEOUT: ::c_int = 18; -pub const TCP_REPAIR: ::c_int = 19; -pub const TCP_REPAIR_QUEUE: ::c_int = 20; -pub const TCP_QUEUE_SEQ: ::c_int = 21; -pub const TCP_REPAIR_OPTIONS: ::c_int = 22; -pub const TCP_FASTOPEN: ::c_int = 23; -pub const TCP_TIMESTAMP: ::c_int = 24; - -/* DCCP socket options */ -pub const DCCP_SOCKOPT_PACKET_SIZE: ::c_int = 1; -pub const DCCP_SOCKOPT_SERVICE: ::c_int = 2; -pub const DCCP_SOCKOPT_CHANGE_L: ::c_int = 3; -pub const DCCP_SOCKOPT_CHANGE_R: ::c_int = 4; -pub const DCCP_SOCKOPT_GET_CUR_MPS: ::c_int = 5; -pub const DCCP_SOCKOPT_SERVER_TIMEWAIT: ::c_int = 6; -pub const DCCP_SOCKOPT_SEND_CSCOV: ::c_int = 10; -pub const DCCP_SOCKOPT_RECV_CSCOV: ::c_int = 11; -pub const DCCP_SOCKOPT_AVAILABLE_CCIDS: ::c_int = 12; -pub const DCCP_SOCKOPT_CCID: ::c_int = 13; -pub const DCCP_SOCKOPT_TX_CCID: ::c_int = 14; -pub const DCCP_SOCKOPT_RX_CCID: ::c_int = 15; -pub const DCCP_SOCKOPT_QPOLICY_ID: ::c_int = 16; -pub const DCCP_SOCKOPT_QPOLICY_TXQLEN: ::c_int = 17; -pub const DCCP_SOCKOPT_CCID_RX_INFO: ::c_int = 128; -pub const DCCP_SOCKOPT_CCID_TX_INFO: ::c_int = 192; - -/// maximum number of services provided on the same listening port -pub const DCCP_SERVICE_LIST_MAX_LEN: ::c_int = 32; - -pub const SIGEV_THREAD_ID: ::c_int = 4; - -pub const BUFSIZ: ::c_uint = 8192; -pub const TMP_MAX: ::c_uint = 238328; -pub const FOPEN_MAX: ::c_uint = 16; -pub const POSIX_MADV_DONTNEED: ::c_int = 4; -pub const _SC_EQUIV_CLASS_MAX: ::c_int = 41; -pub const _SC_CHARCLASS_NAME_MAX: ::c_int = 45; -pub const _SC_PII: ::c_int = 53; -pub const _SC_PII_XTI: ::c_int = 54; -pub const _SC_PII_SOCKET: ::c_int = 55; -pub const _SC_PII_INTERNET: ::c_int = 56; -pub const _SC_PII_OSI: ::c_int = 57; -pub const _SC_POLL: ::c_int = 58; -pub const _SC_SELECT: ::c_int = 59; -pub const _SC_PII_INTERNET_STREAM: ::c_int = 61; -pub const _SC_PII_INTERNET_DGRAM: ::c_int = 62; -pub const _SC_PII_OSI_COTS: ::c_int = 63; -pub const _SC_PII_OSI_CLTS: ::c_int = 64; -pub const _SC_PII_OSI_M: ::c_int = 65; -pub const _SC_T_IOV_MAX: ::c_int = 66; -pub const _SC_2_C_VERSION: ::c_int = 96; -pub const _SC_CHAR_BIT: ::c_int = 101; -pub const _SC_CHAR_MAX: ::c_int = 102; -pub const _SC_CHAR_MIN: ::c_int = 103; -pub const _SC_INT_MAX: ::c_int = 104; -pub const _SC_INT_MIN: ::c_int = 105; -pub const _SC_LONG_BIT: ::c_int = 106; -pub const _SC_WORD_BIT: ::c_int = 107; -pub const _SC_MB_LEN_MAX: ::c_int = 108; -pub const _SC_SSIZE_MAX: ::c_int = 110; -pub const _SC_SCHAR_MAX: ::c_int = 111; -pub const _SC_SCHAR_MIN: ::c_int = 112; -pub const _SC_SHRT_MAX: ::c_int = 113; -pub const _SC_SHRT_MIN: ::c_int = 114; -pub const _SC_UCHAR_MAX: ::c_int = 115; -pub const _SC_UINT_MAX: ::c_int = 116; -pub const _SC_ULONG_MAX: ::c_int = 117; -pub const _SC_USHRT_MAX: ::c_int = 118; -pub const _SC_NL_ARGMAX: ::c_int = 119; -pub const _SC_NL_LANGMAX: ::c_int = 120; -pub const _SC_NL_MSGMAX: ::c_int = 121; -pub const _SC_NL_NMAX: ::c_int = 122; -pub const _SC_NL_SETMAX: ::c_int = 123; -pub const _SC_NL_TEXTMAX: ::c_int = 124; -pub const _SC_BASE: ::c_int = 134; -pub const _SC_C_LANG_SUPPORT: ::c_int = 135; -pub const _SC_C_LANG_SUPPORT_R: ::c_int = 136; -pub const _SC_DEVICE_IO: ::c_int = 140; -pub const _SC_DEVICE_SPECIFIC: ::c_int = 141; -pub const _SC_DEVICE_SPECIFIC_R: ::c_int = 142; -pub const _SC_FD_MGMT: ::c_int = 143; -pub const _SC_FIFO: ::c_int = 144; -pub const _SC_PIPE: ::c_int = 145; -pub const _SC_FILE_ATTRIBUTES: ::c_int = 146; -pub const _SC_FILE_LOCKING: ::c_int = 147; -pub const _SC_FILE_SYSTEM: ::c_int = 148; -pub const _SC_MULTI_PROCESS: ::c_int = 150; -pub const _SC_SINGLE_PROCESS: ::c_int = 151; -pub const _SC_NETWORKING: ::c_int = 152; -pub const _SC_REGEX_VERSION: ::c_int = 156; -pub const _SC_SIGNALS: ::c_int = 158; -pub const _SC_SYSTEM_DATABASE: ::c_int = 162; -pub const _SC_SYSTEM_DATABASE_R: ::c_int = 163; -pub const _SC_USER_GROUPS: ::c_int = 166; -pub const _SC_USER_GROUPS_R: ::c_int = 167; -pub const _SC_LEVEL1_ICACHE_SIZE: ::c_int = 185; -pub const _SC_LEVEL1_ICACHE_ASSOC: ::c_int = 186; -pub const _SC_LEVEL1_ICACHE_LINESIZE: ::c_int = 187; -pub const _SC_LEVEL1_DCACHE_SIZE: ::c_int = 188; -pub const _SC_LEVEL1_DCACHE_ASSOC: ::c_int = 189; -pub const _SC_LEVEL1_DCACHE_LINESIZE: ::c_int = 190; -pub const _SC_LEVEL2_CACHE_SIZE: ::c_int = 191; -pub const _SC_LEVEL2_CACHE_ASSOC: ::c_int = 192; -pub const _SC_LEVEL2_CACHE_LINESIZE: ::c_int = 193; -pub const _SC_LEVEL3_CACHE_SIZE: ::c_int = 194; -pub const _SC_LEVEL3_CACHE_ASSOC: ::c_int = 195; -pub const _SC_LEVEL3_CACHE_LINESIZE: ::c_int = 196; -pub const _SC_LEVEL4_CACHE_SIZE: ::c_int = 197; -pub const _SC_LEVEL4_CACHE_ASSOC: ::c_int = 198; -pub const _SC_LEVEL4_CACHE_LINESIZE: ::c_int = 199; -pub const O_ACCMODE: ::c_int = 3; -pub const ST_RELATIME: ::c_ulong = 4096; -pub const NI_MAXHOST: ::socklen_t = 1025; - -pub const ADFS_SUPER_MAGIC: ::c_long = 0x0000adf5; -pub const AFFS_SUPER_MAGIC: ::c_long = 0x0000adff; -pub const CODA_SUPER_MAGIC: ::c_long = 0x73757245; -pub const CRAMFS_MAGIC: ::c_long = 0x28cd3d45; -pub const EFS_SUPER_MAGIC: ::c_long = 0x00414a53; -pub const EXT2_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const EXT3_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const EXT4_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const HPFS_SUPER_MAGIC: ::c_long = 0xf995e849; -pub const HUGETLBFS_MAGIC: ::c_long = 0x958458f6; -pub const ISOFS_SUPER_MAGIC: ::c_long = 0x00009660; -pub const JFFS2_SUPER_MAGIC: ::c_long = 0x000072b6; -pub const MINIX_SUPER_MAGIC: ::c_long = 0x0000137f; -pub const MINIX_SUPER_MAGIC2: ::c_long = 0x0000138f; -pub const MINIX2_SUPER_MAGIC: ::c_long = 0x00002468; -pub const MINIX2_SUPER_MAGIC2: ::c_long = 0x00002478; -pub const MSDOS_SUPER_MAGIC: ::c_long = 0x00004d44; -pub const NCP_SUPER_MAGIC: ::c_long = 0x0000564c; -pub const NFS_SUPER_MAGIC: ::c_long = 0x00006969; -pub const OPENPROM_SUPER_MAGIC: ::c_long = 0x00009fa1; -pub const PROC_SUPER_MAGIC: ::c_long = 0x00009fa0; -pub const QNX4_SUPER_MAGIC: ::c_long = 0x0000002f; -pub const REISERFS_SUPER_MAGIC: ::c_long = 0x52654973; -pub const SMB_SUPER_MAGIC: ::c_long = 0x0000517b; -pub const TMPFS_MAGIC: ::c_long = 0x01021994; -pub const USBDEVICE_SUPER_MAGIC: ::c_long = 0x00009fa2; - -pub const CPU_SETSIZE: ::c_int = 0x400; - -pub const PTRACE_TRACEME: ::c_uint = 0; -pub const PTRACE_PEEKTEXT: ::c_uint = 1; -pub const PTRACE_PEEKDATA: ::c_uint = 2; -pub const PTRACE_PEEKUSER: ::c_uint = 3; -pub const PTRACE_POKETEXT: ::c_uint = 4; -pub const PTRACE_POKEDATA: ::c_uint = 5; -pub const PTRACE_POKEUSER: ::c_uint = 6; -pub const PTRACE_CONT: ::c_uint = 7; -pub const PTRACE_KILL: ::c_uint = 8; -pub const PTRACE_SINGLESTEP: ::c_uint = 9; -pub const PTRACE_ATTACH: ::c_uint = 16; -pub const PTRACE_SYSCALL: ::c_uint = 24; -pub const PTRACE_SETOPTIONS: ::c_uint = 0x4200; -pub const PTRACE_GETEVENTMSG: ::c_uint = 0x4201; -pub const PTRACE_GETSIGINFO: ::c_uint = 0x4202; -pub const PTRACE_SETSIGINFO: ::c_uint = 0x4203; -pub const PTRACE_GETREGSET: ::c_uint = 0x4204; -pub const PTRACE_SETREGSET: ::c_uint = 0x4205; -pub const PTRACE_SEIZE: ::c_uint = 0x4206; -pub const PTRACE_INTERRUPT: ::c_uint = 0x4207; -pub const PTRACE_LISTEN: ::c_uint = 0x4208; -pub const PTRACE_PEEKSIGINFO: ::c_uint = 0x4209; - -pub const EPOLLWAKEUP: ::c_int = 0x20000000; - -pub const SEEK_DATA: ::c_int = 3; -pub const SEEK_HOLE: ::c_int = 4; - -pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead; -pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793; -pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278; -pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448; -pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216; - -pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567; -pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123; -pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF; -pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000; -pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC; -pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4; -pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2; -pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543; - -// linux/rtnetlink.h -pub const TCA_PAD: ::c_ushort = 9; -pub const TCA_DUMP_INVISIBLE: ::c_ushort = 10; -pub const TCA_CHAIN: ::c_ushort = 11; -pub const TCA_HW_OFFLOAD: ::c_ushort = 12; - -pub const RTM_DELNETCONF: u16 = 81; -pub const RTM_NEWSTATS: u16 = 92; -pub const RTM_GETSTATS: u16 = 94; -pub const RTM_NEWCACHEREPORT: u16 = 96; - -pub const RTM_F_LOOKUP_TABLE: ::c_uint = 0x1000; -pub const RTM_F_FIB_MATCH: ::c_uint = 0x2000; - -pub const RTA_VIA: ::c_ushort = 18; -pub const RTA_NEWDST: ::c_ushort = 19; -pub const RTA_PREF: ::c_ushort = 20; -pub const RTA_ENCAP_TYPE: ::c_ushort = 21; -pub const RTA_ENCAP: ::c_ushort = 22; -pub const RTA_EXPIRES: ::c_ushort = 23; -pub const RTA_PAD: ::c_ushort = 24; -pub const RTA_UID: ::c_ushort = 25; -pub const RTA_TTL_PROPAGATE: ::c_ushort = 26; - -// linux/neighbor.h -pub const NTF_EXT_LEARNED: u8 = 0x10; -pub const NTF_OFFLOADED: u8 = 0x20; - -pub const NDA_MASTER: ::c_ushort = 9; -pub const NDA_LINK_NETNSID: ::c_ushort = 10; -pub const NDA_SRC_VNI: ::c_ushort = 11; - -// linux/if_addr.h -pub const IFA_FLAGS: ::c_ushort = 8; - -pub const IFA_F_MANAGETEMPADDR: u32 = 0x100; -pub const IFA_F_NOPREFIXROUTE: u32 = 0x200; -pub const IFA_F_MCAUTOJOIN: u32 = 0x400; -pub const IFA_F_STABLE_PRIVACY: u32 = 0x800; - -pub const MAX_LINKS: ::c_int = 32; - -pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10; - -pub const GENL_ID_VFS_DQUOT: ::c_int = ::NLMSG_MIN_TYPE + 1; -pub const GENL_ID_PMCRAID: ::c_int = ::NLMSG_MIN_TYPE + 2; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -pub const NF_NETDEV_INGRESS: ::c_int = 0; -pub const NF_NETDEV_NUMHOOKS: ::c_int = 1; - -pub const NFPROTO_INET: ::c_int = 1; -pub const NFPROTO_NETDEV: ::c_int = 5; - -// linux/netfilter/nf_tables.h -pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256; -pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 256; -pub const NFT_SET_MAXNAMELEN: ::c_int = 256; -pub const NFT_OBJ_MAXNAMELEN: ::c_int = 256; -pub const NFT_USERDATA_MAXLEN: ::c_int = 256; - -pub const NFT_REG_VERDICT: ::c_int = 0; -pub const NFT_REG_1: ::c_int = 1; -pub const NFT_REG_2: ::c_int = 2; -pub const NFT_REG_3: ::c_int = 3; -pub const NFT_REG_4: ::c_int = 4; -pub const __NFT_REG_MAX: ::c_int = 5; -pub const NFT_REG32_00: ::c_int = 8; -pub const NFT_REG32_01: ::c_int = 9; -pub const NFT_REG32_02: ::c_int = 10; -pub const NFT_REG32_03: ::c_int = 11; -pub const NFT_REG32_04: ::c_int = 12; -pub const NFT_REG32_05: ::c_int = 13; -pub const NFT_REG32_06: ::c_int = 14; -pub const NFT_REG32_07: ::c_int = 15; -pub const NFT_REG32_08: ::c_int = 16; -pub const NFT_REG32_09: ::c_int = 17; -pub const NFT_REG32_10: ::c_int = 18; -pub const NFT_REG32_11: ::c_int = 19; -pub const NFT_REG32_12: ::c_int = 20; -pub const NFT_REG32_13: ::c_int = 21; -pub const NFT_REG32_14: ::c_int = 22; -pub const NFT_REG32_15: ::c_int = 23; - -pub const NFT_REG_SIZE: ::c_int = 16; -pub const NFT_REG32_SIZE: ::c_int = 4; - -pub const NFT_CONTINUE: ::c_int = -1; -pub const NFT_BREAK: ::c_int = -2; -pub const NFT_JUMP: ::c_int = -3; -pub const NFT_GOTO: ::c_int = -4; -pub const NFT_RETURN: ::c_int = -5; - -pub const NFT_MSG_NEWTABLE: ::c_int = 0; -pub const NFT_MSG_GETTABLE: ::c_int = 1; -pub const NFT_MSG_DELTABLE: ::c_int = 2; -pub const NFT_MSG_NEWCHAIN: ::c_int = 3; -pub const NFT_MSG_GETCHAIN: ::c_int = 4; -pub const NFT_MSG_DELCHAIN: ::c_int = 5; -pub const NFT_MSG_NEWRULE: ::c_int = 6; -pub const NFT_MSG_GETRULE: ::c_int = 7; -pub const NFT_MSG_DELRULE: ::c_int = 8; -pub const NFT_MSG_NEWSET: ::c_int = 9; -pub const NFT_MSG_GETSET: ::c_int = 10; -pub const NFT_MSG_DELSET: ::c_int = 11; -pub const NFT_MSG_NEWSETELEM: ::c_int = 12; -pub const NFT_MSG_GETSETELEM: ::c_int = 13; -pub const NFT_MSG_DELSETELEM: ::c_int = 14; -pub const NFT_MSG_NEWGEN: ::c_int = 15; -pub const NFT_MSG_GETGEN: ::c_int = 16; -pub const NFT_MSG_TRACE: ::c_int = 17; -cfg_if! { - if #[cfg(not(target_arch = "sparc64"))] { - pub const NFT_MSG_NEWOBJ: ::c_int = 18; - pub const NFT_MSG_GETOBJ: ::c_int = 19; - pub const NFT_MSG_DELOBJ: ::c_int = 20; - pub const NFT_MSG_GETOBJ_RESET: ::c_int = 21; - } -} -pub const NFT_MSG_MAX: ::c_int = 25; - -pub const NFT_SET_ANONYMOUS: ::c_int = 0x1; -pub const NFT_SET_CONSTANT: ::c_int = 0x2; -pub const NFT_SET_INTERVAL: ::c_int = 0x4; -pub const NFT_SET_MAP: ::c_int = 0x8; -pub const NFT_SET_TIMEOUT: ::c_int = 0x10; -pub const NFT_SET_EVAL: ::c_int = 0x20; - -pub const NFT_SET_POL_PERFORMANCE: ::c_int = 0; -pub const NFT_SET_POL_MEMORY: ::c_int = 1; - -pub const NFT_SET_ELEM_INTERVAL_END: ::c_int = 0x1; - -pub const NFT_DATA_VALUE: ::c_uint = 0; -pub const NFT_DATA_VERDICT: ::c_uint = 0xffffff00; - -pub const NFT_DATA_RESERVED_MASK: ::c_uint = 0xffffff00; - -pub const NFT_DATA_VALUE_MAXLEN: ::c_int = 64; - -pub const NFT_BYTEORDER_NTOH: ::c_int = 0; -pub const NFT_BYTEORDER_HTON: ::c_int = 1; - -pub const NFT_CMP_EQ: ::c_int = 0; -pub const NFT_CMP_NEQ: ::c_int = 1; -pub const NFT_CMP_LT: ::c_int = 2; -pub const NFT_CMP_LTE: ::c_int = 3; -pub const NFT_CMP_GT: ::c_int = 4; -pub const NFT_CMP_GTE: ::c_int = 5; - -pub const NFT_RANGE_EQ: ::c_int = 0; -pub const NFT_RANGE_NEQ: ::c_int = 1; - -pub const NFT_LOOKUP_F_INV: ::c_int = (1 << 0); - -pub const NFT_DYNSET_OP_ADD: ::c_int = 0; -pub const NFT_DYNSET_OP_UPDATE: ::c_int = 1; - -pub const NFT_DYNSET_F_INV: ::c_int = (1 << 0); - -pub const NFT_PAYLOAD_LL_HEADER: ::c_int = 0; -pub const NFT_PAYLOAD_NETWORK_HEADER: ::c_int = 1; -pub const NFT_PAYLOAD_TRANSPORT_HEADER: ::c_int = 2; - -pub const NFT_PAYLOAD_CSUM_NONE: ::c_int = 0; -pub const NFT_PAYLOAD_CSUM_INET: ::c_int = 1; - -pub const NFT_META_LEN: ::c_int = 0; -pub const NFT_META_PROTOCOL: ::c_int = 1; -pub const NFT_META_PRIORITY: ::c_int = 2; -pub const NFT_META_MARK: ::c_int = 3; -pub const NFT_META_IIF: ::c_int = 4; -pub const NFT_META_OIF: ::c_int = 5; -pub const NFT_META_IIFNAME: ::c_int = 6; -pub const NFT_META_OIFNAME: ::c_int = 7; -pub const NFT_META_IIFTYPE: ::c_int = 8; -pub const NFT_META_OIFTYPE: ::c_int = 9; -pub const NFT_META_SKUID: ::c_int = 10; -pub const NFT_META_SKGID: ::c_int = 11; -pub const NFT_META_NFTRACE: ::c_int = 12; -pub const NFT_META_RTCLASSID: ::c_int = 13; -pub const NFT_META_SECMARK: ::c_int = 14; -pub const NFT_META_NFPROTO: ::c_int = 15; -pub const NFT_META_L4PROTO: ::c_int = 16; -pub const NFT_META_BRI_IIFNAME: ::c_int = 17; -pub const NFT_META_BRI_OIFNAME: ::c_int = 18; -pub const NFT_META_PKTTYPE: ::c_int = 19; -pub const NFT_META_CPU: ::c_int = 20; -pub const NFT_META_IIFGROUP: ::c_int = 21; -pub const NFT_META_OIFGROUP: ::c_int = 22; -pub const NFT_META_CGROUP: ::c_int = 23; -pub const NFT_META_PRANDOM: ::c_int = 24; - -pub const NFT_CT_STATE: ::c_int = 0; -pub const NFT_CT_DIRECTION: ::c_int = 1; -pub const NFT_CT_STATUS: ::c_int = 2; -pub const NFT_CT_MARK: ::c_int = 3; -pub const NFT_CT_SECMARK: ::c_int = 4; -pub const NFT_CT_EXPIRATION: ::c_int = 5; -pub const NFT_CT_HELPER: ::c_int = 6; -pub const NFT_CT_L3PROTOCOL: ::c_int = 7; -pub const NFT_CT_SRC: ::c_int = 8; -pub const NFT_CT_DST: ::c_int = 9; -pub const NFT_CT_PROTOCOL: ::c_int = 10; -pub const NFT_CT_PROTO_SRC: ::c_int = 11; -pub const NFT_CT_PROTO_DST: ::c_int = 12; -pub const NFT_CT_LABELS: ::c_int = 13; -pub const NFT_CT_PKTS: ::c_int = 14; -pub const NFT_CT_BYTES: ::c_int = 15; - -pub const NFT_LIMIT_PKTS: ::c_int = 0; -pub const NFT_LIMIT_PKT_BYTES: ::c_int = 1; - -pub const NFT_LIMIT_F_INV: ::c_int = (1 << 0); - -pub const NFT_QUEUE_FLAG_BYPASS: ::c_int = 0x01; -pub const NFT_QUEUE_FLAG_CPU_FANOUT: ::c_int = 0x02; -pub const NFT_QUEUE_FLAG_MASK: ::c_int = 0x03; - -pub const NFT_QUOTA_F_INV: ::c_int = (1 << 0); - -pub const NFT_REJECT_ICMP_UNREACH: ::c_int = 0; -pub const NFT_REJECT_TCP_RST: ::c_int = 1; -pub const NFT_REJECT_ICMPX_UNREACH: ::c_int = 2; - -pub const NFT_REJECT_ICMPX_NO_ROUTE: ::c_int = 0; -pub const NFT_REJECT_ICMPX_PORT_UNREACH: ::c_int = 1; -pub const NFT_REJECT_ICMPX_HOST_UNREACH: ::c_int = 2; -pub const NFT_REJECT_ICMPX_ADMIN_PROHIBITED: ::c_int = 3; - -pub const NFT_NAT_SNAT: ::c_int = 0; -pub const NFT_NAT_DNAT: ::c_int = 1; - -pub const NFT_TRACETYPE_UNSPEC: ::c_int = 0; -pub const NFT_TRACETYPE_POLICY: ::c_int = 1; -pub const NFT_TRACETYPE_RETURN: ::c_int = 2; -pub const NFT_TRACETYPE_RULE: ::c_int = 3; - -pub const NFT_NG_INCREMENTAL: ::c_int = 0; -pub const NFT_NG_RANDOM: ::c_int = 1; - -pub const M_MXFAST: ::c_int = 1; -pub const M_NLBLKS: ::c_int = 2; -pub const M_GRAIN: ::c_int = 3; -pub const M_KEEP: ::c_int = 4; -pub const M_TRIM_THRESHOLD: ::c_int = -1; -pub const M_TOP_PAD: ::c_int = -2; -pub const M_MMAP_THRESHOLD: ::c_int = -3; -pub const M_MMAP_MAX: ::c_int = -4; -pub const M_CHECK_ACTION: ::c_int = -5; -pub const M_PERTURB: ::c_int = -6; -pub const M_ARENA_TEST: ::c_int = -7; -pub const M_ARENA_MAX: ::c_int = -8; - -pub const AT_STATX_SYNC_TYPE: ::c_int = 0x6000; -pub const AT_STATX_SYNC_AS_STAT: ::c_int = 0x0000; -pub const AT_STATX_FORCE_SYNC: ::c_int = 0x2000; -pub const AT_STATX_DONT_SYNC: ::c_int = 0x4000; -pub const STATX_TYPE: ::c_uint = 0x0001; -pub const STATX_MODE: ::c_uint = 0x0002; -pub const STATX_NLINK: ::c_uint = 0x0004; -pub const STATX_UID: ::c_uint = 0x0008; -pub const STATX_GID: ::c_uint = 0x0010; -pub const STATX_ATIME: ::c_uint = 0x0020; -pub const STATX_MTIME: ::c_uint = 0x0040; -pub const STATX_CTIME: ::c_uint = 0x0080; -pub const STATX_INO: ::c_uint = 0x0100; -pub const STATX_SIZE: ::c_uint = 0x0200; -pub const STATX_BLOCKS: ::c_uint = 0x0400; -pub const STATX_BASIC_STATS: ::c_uint = 0x07ff; -pub const STATX_BTIME: ::c_uint = 0x0800; -pub const STATX_ALL: ::c_uint = 0x0fff; -pub const STATX__RESERVED: ::c_int = 0x80000000; -pub const STATX_ATTR_COMPRESSED: ::c_int = 0x0004; -pub const STATX_ATTR_IMMUTABLE: ::c_int = 0x0010; -pub const STATX_ATTR_APPEND: ::c_int = 0x0020; -pub const STATX_ATTR_NODUMP: ::c_int = 0x0040; -pub const STATX_ATTR_ENCRYPTED: ::c_int = 0x0800; -pub const STATX_ATTR_AUTOMOUNT: ::c_int = 0x1000; - -cfg_if! { - if #[cfg(any( - target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64", - target_arch = "s390x" - ))] { - pub const PTHREAD_STACK_MIN: ::size_t = 16384; - } else if #[cfg(any( - target_arch = "sparc", - target_arch = "sparc64" - ))] { - pub const PTHREAD_STACK_MIN: ::size_t = 0x6000; - } else { - pub const PTHREAD_STACK_MIN: ::size_t = 131072; - } -} -pub const PTHREAD_MUTEX_ADAPTIVE_NP: ::c_int = 3; - -extern "C" { - pub fn sendmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - ) -> ::c_int; - pub fn recvmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_int, - timeout: *mut ::timespec, - ) -> ::c_int; - - pub fn getrlimit64( - resource: ::__rlimit_resource_t, - rlim: *mut ::rlimit64, - ) -> ::c_int; - pub fn setrlimit64( - resource: ::__rlimit_resource_t, - rlim: *const ::rlimit64, - ) -> ::c_int; - pub fn getrlimit( - resource: ::__rlimit_resource_t, - rlim: *mut ::rlimit, - ) -> ::c_int; - pub fn setrlimit( - resource: ::__rlimit_resource_t, - rlim: *const ::rlimit, - ) -> ::c_int; - pub fn prlimit( - pid: ::pid_t, - resource: ::__rlimit_resource_t, - new_limit: *const ::rlimit, - old_limit: *mut ::rlimit, - ) -> ::c_int; - pub fn prlimit64( - pid: ::pid_t, - resource: ::__rlimit_resource_t, - new_limit: *const ::rlimit64, - old_limit: *mut ::rlimit64, - ) -> ::c_int; - pub fn utmpname(file: *const ::c_char) -> ::c_int; - pub fn utmpxname(file: *const ::c_char) -> ::c_int; - pub fn getutxent() -> *mut utmpx; - pub fn getutxid(ut: *const utmpx) -> *mut utmpx; - pub fn getutxline(ut: *const utmpx) -> *mut utmpx; - pub fn pututxline(ut: *const utmpx) -> *mut utmpx; - pub fn setutxent(); - pub fn endutxent(); - pub fn getpt() -> ::c_int; - pub fn mallopt(param: ::c_int, value: ::c_int) -> ::c_int; - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; - pub fn statx( - dirfd: ::c_int, - pathname: *const c_char, - flags: ::c_int, - mask: ::c_uint, - statxbuf: *mut statx, - ) -> ::c_int; - pub fn getrandom( - buf: *mut ::c_void, - buflen: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; -} - -#[link(name = "util")] -extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; - pub fn backtrace(buf: *mut *mut ::c_void, sz: ::c_int) -> ::c_int; - pub fn glob64( - pattern: *const ::c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut glob64_t, - ) -> ::c_int; - pub fn globfree64(pglob: *mut glob64_t); - pub fn ptrace(request: ::c_uint, ...) -> ::c_long; - pub fn pthread_attr_getaffinity_np( - attr: *const ::pthread_attr_t, - cpusetsize: ::size_t, - cpuset: *mut ::cpu_set_t, - ) -> ::c_int; - pub fn pthread_attr_setaffinity_np( - attr: *mut ::pthread_attr_t, - cpusetsize: ::size_t, - cpuset: *const ::cpu_set_t, - ) -> ::c_int; - pub fn getpriority(which: ::__priority_which_t, who: ::id_t) -> ::c_int; - pub fn setpriority( - which: ::__priority_which_t, - who: ::id_t, - prio: ::c_int, - ) -> ::c_int; - pub fn pthread_getaffinity_np( - thread: ::pthread_t, - cpusetsize: ::size_t, - cpuset: *mut ::cpu_set_t, - ) -> ::c_int; - pub fn pthread_setaffinity_np( - thread: ::pthread_t, - cpusetsize: ::size_t, - cpuset: *const ::cpu_set_t, - ) -> ::c_int; - pub fn pthread_rwlockattr_getkind_np( - attr: *const ::pthread_rwlockattr_t, - val: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_setkind_np( - attr: *mut ::pthread_rwlockattr_t, - val: ::c_int, - ) -> ::c_int; - pub fn sched_getcpu() -> ::c_int; - pub fn mallinfo() -> ::mallinfo; - pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t; - pub fn getauxval(type_: ::c_ulong) -> ::c_ulong; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwent_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwent_r")] - pub fn getpwent_r( - pwd: *mut ::passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::passwd, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getgrent_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrent_r")] - pub fn getgrent_r( - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - pub fn pthread_getname_np( - thread: ::pthread_t, - name: *mut ::c_char, - len: ::size_t, - ) -> ::c_int; - pub fn pthread_setname_np( - thread: ::pthread_t, - name: *const ::c_char, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(any(target_arch = "x86", - target_arch = "arm", - target_arch = "mips", - target_arch = "powerpc", - target_arch = "sparc"))] { - mod b32; - pub use self::b32::*; - } else if #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64", - target_arch = "riscv64"))] { - mod b64; - pub use self::b64::*; - } else { - // Unknown target_arch - } -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } else { - mod no_align; - pub use self::no_align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/gnu/no_align.rs b/libc/src/unix/linux_like/linux/gnu/no_align.rs deleted file mode 100644 index e32bf67..0000000 --- a/libc/src/unix/linux_like/linux/gnu/no_align.rs +++ /dev/null @@ -1,10 +0,0 @@ -s! { - // FIXME this is actually a union - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - __align: [::c_long; 0], - } -} diff --git a/libc/src/unix/linux_like/linux/mod.rs b/libc/src/unix/linux_like/linux/mod.rs deleted file mode 100644 index 80505ff..0000000 --- a/libc/src/unix/linux_like/linux/mod.rs +++ /dev/null @@ -1,3194 +0,0 @@ -//! Linux-specific definitions for linux-like values - -pub type useconds_t = u32; -pub type dev_t = u64; -pub type socklen_t = u32; -pub type mode_t = u32; -pub type ino64_t = u64; -pub type off64_t = i64; -pub type blkcnt64_t = i64; -pub type rlim64_t = u64; -pub type mqd_t = ::c_int; -pub type nfds_t = ::c_ulong; -pub type nl_item = ::c_int; -pub type idtype_t = ::c_uint; -pub type loff_t = ::c_longlong; -pub type pthread_key_t = ::c_uint; - -pub type __u8 = ::c_uchar; -pub type __u16 = ::c_ushort; -pub type __s16 = ::c_short; -pub type __u32 = ::c_uint; -pub type __s32 = ::c_int; - -pub type Elf32_Half = u16; -pub type Elf32_Word = u32; -pub type Elf32_Off = u32; -pub type Elf32_Addr = u32; - -pub type Elf64_Half = u16; -pub type Elf64_Word = u32; -pub type Elf64_Off = u64; -pub type Elf64_Addr = u64; -pub type Elf64_Xword = u64; -pub type Elf64_Sxword = i64; - -pub type Elf32_Section = u16; -pub type Elf64_Section = u16; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos64_t {} // TODO: fill this out with a struct -impl ::Copy for fpos64_t {} -impl ::Clone for fpos64_t { - fn clone(&self) -> fpos64_t { - *self - } -} - -s! { - pub struct rlimit64 { - pub rlim_cur: rlim64_t, - pub rlim_max: rlim64_t, - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut c_char, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct spwd { - pub sp_namp: *mut ::c_char, - pub sp_pwdp: *mut ::c_char, - pub sp_lstchg: ::c_long, - pub sp_min: ::c_long, - pub sp_max: ::c_long, - pub sp_warn: ::c_long, - pub sp_inact: ::c_long, - pub sp_expire: ::c_long, - pub sp_flag: ::c_ulong, - } - - pub struct dqblk { - pub dqb_bhardlimit: u64, - pub dqb_bsoftlimit: u64, - pub dqb_curspace: u64, - pub dqb_ihardlimit: u64, - pub dqb_isoftlimit: u64, - pub dqb_curinodes: u64, - pub dqb_btime: u64, - pub dqb_itime: u64, - pub dqb_valid: u32, - } - - pub struct signalfd_siginfo { - pub ssi_signo: u32, - pub ssi_errno: i32, - pub ssi_code: i32, - pub ssi_pid: u32, - pub ssi_uid: u32, - pub ssi_fd: i32, - pub ssi_tid: u32, - pub ssi_band: u32, - pub ssi_overrun: u32, - pub ssi_trapno: u32, - pub ssi_status: i32, - pub ssi_int: i32, - pub ssi_ptr: u64, - pub ssi_utime: u64, - pub ssi_stime: u64, - pub ssi_addr: u64, - pub ssi_addr_lsb: u16, - _pad2: u16, - pub ssi_syscall: i32, - pub ssi_call_addr: u64, - pub ssi_arch: u32, - _pad: [u8; 28], - } - - pub struct itimerspec { - pub it_interval: ::timespec, - pub it_value: ::timespec, - } - - pub struct fsid_t { - __val: [::c_int; 2], - } - - pub struct packet_mreq { - pub mr_ifindex: ::c_int, - pub mr_type: ::c_ushort, - pub mr_alen: ::c_ushort, - pub mr_address: [::c_uchar; 8], - } - - pub struct cpu_set_t { - #[cfg(all(target_pointer_width = "32", - not(target_arch = "x86_64")))] - bits: [u32; 32], - #[cfg(not(all(target_pointer_width = "32", - not(target_arch = "x86_64"))))] - bits: [u64; 16], - } - - pub struct if_nameindex { - pub if_index: ::c_uint, - pub if_name: *mut ::c_char, - } - - // System V IPC - pub struct msginfo { - pub msgpool: ::c_int, - pub msgmap: ::c_int, - pub msgmax: ::c_int, - pub msgmnb: ::c_int, - pub msgmni: ::c_int, - pub msgssz: ::c_int, - pub msgtql: ::c_int, - pub msgseg: ::c_ushort, - } - - pub struct sembuf { - pub sem_num: ::c_ushort, - pub sem_op: ::c_short, - pub sem_flg: ::c_short, - } - - pub struct input_event { - pub time: ::timeval, - pub type_: ::__u16, - pub code: ::__u16, - pub value: ::__s32, - } - - pub struct input_id { - pub bustype: ::__u16, - pub vendor: ::__u16, - pub product: ::__u16, - pub version: ::__u16, - } - - pub struct input_absinfo { - pub value: ::__s32, - pub minimum: ::__s32, - pub maximum: ::__s32, - pub fuzz: ::__s32, - pub flat: ::__s32, - pub resolution: ::__s32, - } - - pub struct input_keymap_entry { - pub flags: ::__u8, - pub len: ::__u8, - pub index: ::__u16, - pub keycode: ::__u32, - pub scancode: [::__u8; 32], - } - - pub struct input_mask { - pub type_: ::__u32, - pub codes_size: ::__u32, - pub codes_ptr: ::__u64, - } - - pub struct ff_replay { - pub length: ::__u16, - pub delay: ::__u16, - } - - pub struct ff_trigger { - pub button: ::__u16, - pub interval: ::__u16, - } - - pub struct ff_envelope { - pub attack_length: ::__u16, - pub attack_level: ::__u16, - pub fade_length: ::__u16, - pub fade_level: ::__u16, - } - - pub struct ff_constant_effect { - pub level: ::__s16, - pub envelope: ff_envelope, - } - - pub struct ff_ramp_effect { - pub start_level: ::__s16, - pub end_level: ::__s16, - pub envelope: ff_envelope, - } - - pub struct ff_condition_effect { - pub right_saturation: ::__u16, - pub left_saturation: ::__u16, - - pub right_coeff: ::__s16, - pub left_coeff: ::__s16, - - pub deadband: ::__u16, - pub center: ::__s16, - } - - pub struct ff_periodic_effect { - pub waveform: ::__u16, - pub period: ::__u16, - pub magnitude: ::__s16, - pub offset: ::__s16, - pub phase: ::__u16, - - pub envelope: ff_envelope, - - pub custom_len: ::__u32, - pub custom_data: *mut ::__s16, - } - - pub struct ff_rumble_effect { - pub strong_magnitude: ::__u16, - pub weak_magnitude: ::__u16, - } - - pub struct ff_effect { - pub type_: ::__u16, - pub id: ::__s16, - pub direction: ::__u16, - pub trigger: ff_trigger, - pub replay: ff_replay, - // FIXME this is actually a union - #[cfg(target_pointer_width = "64")] - pub u: [u64; 4], - #[cfg(target_pointer_width = "32")] - pub u: [u32; 7], - } - - pub struct dl_phdr_info { - #[cfg(target_pointer_width = "64")] - pub dlpi_addr: Elf64_Addr, - #[cfg(target_pointer_width = "32")] - pub dlpi_addr: Elf32_Addr, - - pub dlpi_name: *const ::c_char, - - #[cfg(target_pointer_width = "64")] - pub dlpi_phdr: *const Elf64_Phdr, - #[cfg(target_pointer_width = "32")] - pub dlpi_phdr: *const Elf32_Phdr, - - #[cfg(target_pointer_width = "64")] - pub dlpi_phnum: Elf64_Half, - #[cfg(target_pointer_width = "32")] - pub dlpi_phnum: Elf32_Half, - - pub dlpi_adds: ::c_ulonglong, - pub dlpi_subs: ::c_ulonglong, - pub dlpi_tls_modid: ::size_t, - pub dlpi_tls_data: *mut ::c_void, - } - - pub struct Elf32_Ehdr { - pub e_ident: [::c_uchar; 16], - pub e_type: Elf32_Half, - pub e_machine: Elf32_Half, - pub e_version: Elf32_Word, - pub e_entry: Elf32_Addr, - pub e_phoff: Elf32_Off, - pub e_shoff: Elf32_Off, - pub e_flags: Elf32_Word, - pub e_ehsize: Elf32_Half, - pub e_phentsize: Elf32_Half, - pub e_phnum: Elf32_Half, - pub e_shentsize: Elf32_Half, - pub e_shnum: Elf32_Half, - pub e_shstrndx: Elf32_Half, - } - - pub struct Elf64_Ehdr { - pub e_ident: [::c_uchar; 16], - pub e_type: Elf64_Half, - pub e_machine: Elf64_Half, - pub e_version: Elf64_Word, - pub e_entry: Elf64_Addr, - pub e_phoff: Elf64_Off, - pub e_shoff: Elf64_Off, - pub e_flags: Elf64_Word, - pub e_ehsize: Elf64_Half, - pub e_phentsize: Elf64_Half, - pub e_phnum: Elf64_Half, - pub e_shentsize: Elf64_Half, - pub e_shnum: Elf64_Half, - pub e_shstrndx: Elf64_Half, - } - - pub struct Elf32_Sym { - pub st_name: Elf32_Word, - pub st_value: Elf32_Addr, - pub st_size: Elf32_Word, - pub st_info: ::c_uchar, - pub st_other: ::c_uchar, - pub st_shndx: Elf32_Section, - } - - pub struct Elf64_Sym { - pub st_name: Elf64_Word, - pub st_info: ::c_uchar, - pub st_other: ::c_uchar, - pub st_shndx: Elf64_Section, - pub st_value: Elf64_Addr, - pub st_size: Elf64_Xword, - } - - pub struct Elf32_Phdr { - pub p_type: Elf32_Word, - pub p_offset: Elf32_Off, - pub p_vaddr: Elf32_Addr, - pub p_paddr: Elf32_Addr, - pub p_filesz: Elf32_Word, - pub p_memsz: Elf32_Word, - pub p_flags: Elf32_Word, - pub p_align: Elf32_Word, - } - - pub struct Elf64_Phdr { - pub p_type: Elf64_Word, - pub p_flags: Elf64_Word, - pub p_offset: Elf64_Off, - pub p_vaddr: Elf64_Addr, - pub p_paddr: Elf64_Addr, - pub p_filesz: Elf64_Xword, - pub p_memsz: Elf64_Xword, - pub p_align: Elf64_Xword, - } - - pub struct Elf32_Shdr { - pub sh_name: Elf32_Word, - pub sh_type: Elf32_Word, - pub sh_flags: Elf32_Word, - pub sh_addr: Elf32_Addr, - pub sh_offset: Elf32_Off, - pub sh_size: Elf32_Word, - pub sh_link: Elf32_Word, - pub sh_info: Elf32_Word, - pub sh_addralign: Elf32_Word, - pub sh_entsize: Elf32_Word, - } - - pub struct Elf64_Shdr { - pub sh_name: Elf64_Word, - pub sh_type: Elf64_Word, - pub sh_flags: Elf64_Xword, - pub sh_addr: Elf64_Addr, - pub sh_offset: Elf64_Off, - pub sh_size: Elf64_Xword, - pub sh_link: Elf64_Word, - pub sh_info: Elf64_Word, - pub sh_addralign: Elf64_Xword, - pub sh_entsize: Elf64_Xword, - } - - pub struct Elf32_Chdr { - pub ch_type: Elf32_Word, - pub ch_size: Elf32_Word, - pub ch_addralign: Elf32_Word, - } - - pub struct Elf64_Chdr { - pub ch_type: Elf64_Word, - pub ch_reserved: Elf64_Word, - pub ch_size: Elf64_Xword, - pub ch_addralign: Elf64_Xword, - } - - pub struct ucred { - pub pid: ::pid_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - } - - pub struct mntent { - pub mnt_fsname: *mut ::c_char, - pub mnt_dir: *mut ::c_char, - pub mnt_type: *mut ::c_char, - pub mnt_opts: *mut ::c_char, - pub mnt_freq: ::c_int, - pub mnt_passno: ::c_int, - } - - pub struct posix_spawn_file_actions_t { - __allocated: ::c_int, - __used: ::c_int, - __actions: *mut ::c_int, - __pad: [::c_int; 16], - } - - pub struct posix_spawnattr_t { - __flags: ::c_short, - __pgrp: ::pid_t, - __sd: ::sigset_t, - __ss: ::sigset_t, - #[cfg(target_env = "musl")] - __prio: ::c_int, - #[cfg(not(target_env = "musl"))] - __sp: ::sched_param, - __policy: ::c_int, - __pad: [::c_int; 16], - } - - pub struct genlmsghdr { - pub cmd: u8, - pub version: u8, - pub reserved: u16, - } - - pub struct in6_pktinfo { - pub ipi6_addr: ::in6_addr, - pub ipi6_ifindex: ::c_uint, - } - - pub struct arpd_request { - pub req: ::c_ushort, - pub ip: u32, - pub dev: ::c_ulong, - pub stamp: ::c_ulong, - pub updated: ::c_ulong, - pub ha: [::c_uchar; ::MAX_ADDR_LEN], - } - - pub struct inotify_event { - pub wd: ::c_int, - pub mask: u32, - pub cookie: u32, - pub len: u32 - } - - pub struct sockaddr_vm { - pub svm_family: ::sa_family_t, - pub svm_reserved1: ::c_ushort, - pub svm_port: ::c_uint, - pub svm_cid: ::c_uint, - pub svm_zero: [u8; 4] - } -} - -s_no_extra_traits! { - pub struct sockaddr_nl { - pub nl_family: ::sa_family_t, - nl_pad: ::c_ushort, - pub nl_pid: u32, - pub nl_groups: u32 - } - - pub struct dirent { - pub d_ino: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct sockaddr_alg { - pub salg_family: ::sa_family_t, - pub salg_type: [::c_uchar; 14], - pub salg_feat: u32, - pub salg_mask: u32, - pub salg_name: [::c_uchar; 64], - } - - pub struct af_alg_iv { - pub ivlen: u32, - pub iv: [::c_uchar; 0], - } - - // x32 compatibility - // See https://sourceware.org/bugzilla/show_bug.cgi?id=21279 - pub struct mq_attr { - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub mq_flags: i64, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub mq_maxmsg: i64, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub mq_msgsize: i64, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub mq_curmsgs: i64, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pad: [i64; 4], - - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub mq_flags: ::c_long, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub mq_maxmsg: ::c_long, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub mq_msgsize: ::c_long, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub mq_curmsgs: ::c_long, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pad: [::c_long; 4], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for sockaddr_nl { - fn eq(&self, other: &sockaddr_nl) -> bool { - self.nl_family == other.nl_family && - self.nl_pid == other.nl_pid && - self.nl_groups == other.nl_groups - } - } - impl Eq for sockaddr_nl {} - impl ::fmt::Debug for sockaddr_nl { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_nl") - .field("nl_family", &self.nl_family) - .field("nl_pid", &self.nl_pid) - .field("nl_groups", &self.nl_groups) - .finish() - } - } - impl ::hash::Hash for sockaddr_nl { - fn hash(&self, state: &mut H) { - self.nl_family.hash(state); - self.nl_pid.hash(state); - self.nl_groups.hash(state); - } - } - - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for dirent {} - - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for dirent64 { - fn eq(&self, other: &dirent64) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for dirent64 {} - - impl ::fmt::Debug for dirent64 { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent64") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - - impl ::hash::Hash for dirent64 { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for pthread_cond_t { - fn eq(&self, other: &pthread_cond_t) -> bool { - self.size.iter().zip(other.size.iter()).all(|(a,b)| a == b) - } - } - - impl Eq for pthread_cond_t {} - - impl ::fmt::Debug for pthread_cond_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_cond_t") - // FIXME: .field("size", &self.size) - .finish() - } - } - - impl ::hash::Hash for pthread_cond_t { - fn hash(&self, state: &mut H) { - self.size.hash(state); - } - } - - impl PartialEq for pthread_mutex_t { - fn eq(&self, other: &pthread_mutex_t) -> bool { - self.size.iter().zip(other.size.iter()).all(|(a,b)| a == b) - } - } - - impl Eq for pthread_mutex_t {} - - impl ::fmt::Debug for pthread_mutex_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_mutex_t") - // FIXME: .field("size", &self.size) - .finish() - } - } - - impl ::hash::Hash for pthread_mutex_t { - fn hash(&self, state: &mut H) { - self.size.hash(state); - } - } - - impl PartialEq for pthread_rwlock_t { - fn eq(&self, other: &pthread_rwlock_t) -> bool { - self.size.iter().zip(other.size.iter()).all(|(a,b)| a == b) - } - } - - impl Eq for pthread_rwlock_t {} - - impl ::fmt::Debug for pthread_rwlock_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("pthread_rwlock_t") - // FIXME: .field("size", &self.size) - .finish() - } - } - - impl ::hash::Hash for pthread_rwlock_t { - fn hash(&self, state: &mut H) { - self.size.hash(state); - } - } - - impl PartialEq for sockaddr_alg { - fn eq(&self, other: &sockaddr_alg) -> bool { - self.salg_family == other.salg_family - && self - .salg_type - .iter() - .zip(other.salg_type.iter()) - .all(|(a, b)| a == b) - && self.salg_feat == other.salg_feat - && self.salg_mask == other.salg_mask - && self - .salg_name - .iter() - .zip(other.salg_name.iter()) - .all(|(a, b)| a == b) - } - } - - impl Eq for sockaddr_alg {} - - impl ::fmt::Debug for sockaddr_alg { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_alg") - .field("salg_family", &self.salg_family) - .field("salg_type", &self.salg_type) - .field("salg_feat", &self.salg_feat) - .field("salg_mask", &self.salg_mask) - .field("salg_name", &&self.salg_name[..]) - .finish() - } - } - - impl ::hash::Hash for sockaddr_alg { - fn hash(&self, state: &mut H) { - self.salg_family.hash(state); - self.salg_type.hash(state); - self.salg_feat.hash(state); - self.salg_mask.hash(state); - self.salg_name.hash(state); - } - } - - impl af_alg_iv { - fn as_slice(&self) -> &[u8] { - unsafe { - ::core::slice::from_raw_parts( - self.iv.as_ptr(), - self.ivlen as usize - ) - } - } - } - - impl PartialEq for af_alg_iv { - fn eq(&self, other: &af_alg_iv) -> bool { - *self.as_slice() == *other.as_slice() - } - } - - impl Eq for af_alg_iv {} - - impl ::fmt::Debug for af_alg_iv { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("af_alg_iv") - .field("iv", &self.as_slice()) - .finish() - } - } - - impl ::hash::Hash for af_alg_iv { - fn hash(&self, state: &mut H) { - self.as_slice().hash(state); - } - } - - impl PartialEq for mq_attr { - fn eq(&self, other: &mq_attr) -> bool { - self.mq_flags == other.mq_flags && - self.mq_maxmsg == other.mq_maxmsg && - self.mq_msgsize == other.mq_msgsize && - self.mq_curmsgs == other.mq_curmsgs - } - } - impl Eq for mq_attr {} - impl ::fmt::Debug for mq_attr { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("mq_attr") - .field("mq_flags", &self.mq_flags) - .field("mq_maxmsg", &self.mq_maxmsg) - .field("mq_msgsize", &self.mq_msgsize) - .field("mq_curmsgs", &self.mq_curmsgs) - .finish() - } - } - impl ::hash::Hash for mq_attr { - fn hash(&self, state: &mut H) { - self.mq_flags.hash(state); - self.mq_maxmsg.hash(state); - self.mq_msgsize.hash(state); - self.mq_curmsgs.hash(state); - } - } - } -} - -pub const ABDAY_1: ::nl_item = 0x20000; -pub const ABDAY_2: ::nl_item = 0x20001; -pub const ABDAY_3: ::nl_item = 0x20002; -pub const ABDAY_4: ::nl_item = 0x20003; -pub const ABDAY_5: ::nl_item = 0x20004; -pub const ABDAY_6: ::nl_item = 0x20005; -pub const ABDAY_7: ::nl_item = 0x20006; - -pub const DAY_1: ::nl_item = 0x20007; -pub const DAY_2: ::nl_item = 0x20008; -pub const DAY_3: ::nl_item = 0x20009; -pub const DAY_4: ::nl_item = 0x2000A; -pub const DAY_5: ::nl_item = 0x2000B; -pub const DAY_6: ::nl_item = 0x2000C; -pub const DAY_7: ::nl_item = 0x2000D; - -pub const ABMON_1: ::nl_item = 0x2000E; -pub const ABMON_2: ::nl_item = 0x2000F; -pub const ABMON_3: ::nl_item = 0x20010; -pub const ABMON_4: ::nl_item = 0x20011; -pub const ABMON_5: ::nl_item = 0x20012; -pub const ABMON_6: ::nl_item = 0x20013; -pub const ABMON_7: ::nl_item = 0x20014; -pub const ABMON_8: ::nl_item = 0x20015; -pub const ABMON_9: ::nl_item = 0x20016; -pub const ABMON_10: ::nl_item = 0x20017; -pub const ABMON_11: ::nl_item = 0x20018; -pub const ABMON_12: ::nl_item = 0x20019; - -pub const MON_1: ::nl_item = 0x2001A; -pub const MON_2: ::nl_item = 0x2001B; -pub const MON_3: ::nl_item = 0x2001C; -pub const MON_4: ::nl_item = 0x2001D; -pub const MON_5: ::nl_item = 0x2001E; -pub const MON_6: ::nl_item = 0x2001F; -pub const MON_7: ::nl_item = 0x20020; -pub const MON_8: ::nl_item = 0x20021; -pub const MON_9: ::nl_item = 0x20022; -pub const MON_10: ::nl_item = 0x20023; -pub const MON_11: ::nl_item = 0x20024; -pub const MON_12: ::nl_item = 0x20025; - -pub const AM_STR: ::nl_item = 0x20026; -pub const PM_STR: ::nl_item = 0x20027; - -pub const D_T_FMT: ::nl_item = 0x20028; -pub const D_FMT: ::nl_item = 0x20029; -pub const T_FMT: ::nl_item = 0x2002A; -pub const T_FMT_AMPM: ::nl_item = 0x2002B; - -pub const ERA: ::nl_item = 0x2002C; -pub const ERA_D_FMT: ::nl_item = 0x2002E; -pub const ALT_DIGITS: ::nl_item = 0x2002F; -pub const ERA_D_T_FMT: ::nl_item = 0x20030; -pub const ERA_T_FMT: ::nl_item = 0x20031; - -pub const CODESET: ::nl_item = 14; - -pub const CRNCYSTR: ::nl_item = 0x4000F; - -pub const RUSAGE_THREAD: ::c_int = 1; -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const RADIXCHAR: ::nl_item = 0x10000; -pub const THOUSEP: ::nl_item = 0x10001; - -pub const YESEXPR: ::nl_item = 0x50000; -pub const NOEXPR: ::nl_item = 0x50001; -pub const YESSTR: ::nl_item = 0x50002; -pub const NOSTR: ::nl_item = 0x50003; - -pub const FILENAME_MAX: ::c_uint = 4096; -pub const L_tmpnam: ::c_uint = 20; -pub const _PC_LINK_MAX: ::c_int = 0; -pub const _PC_MAX_CANON: ::c_int = 1; -pub const _PC_MAX_INPUT: ::c_int = 2; -pub const _PC_NAME_MAX: ::c_int = 3; -pub const _PC_PATH_MAX: ::c_int = 4; -pub const _PC_PIPE_BUF: ::c_int = 5; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 6; -pub const _PC_NO_TRUNC: ::c_int = 7; -pub const _PC_VDISABLE: ::c_int = 8; -pub const _PC_SYNC_IO: ::c_int = 9; -pub const _PC_ASYNC_IO: ::c_int = 10; -pub const _PC_PRIO_IO: ::c_int = 11; -pub const _PC_SOCK_MAXBUF: ::c_int = 12; -pub const _PC_FILESIZEBITS: ::c_int = 13; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 14; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 15; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 16; -pub const _PC_REC_XFER_ALIGN: ::c_int = 17; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 18; -pub const _PC_SYMLINK_MAX: ::c_int = 19; -pub const _PC_2_SYMLINKS: ::c_int = 20; - -pub const MS_NOUSER: ::c_ulong = 0xffffffff80000000; - -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_CHILD_MAX: ::c_int = 1; -pub const _SC_CLK_TCK: ::c_int = 2; -pub const _SC_NGROUPS_MAX: ::c_int = 3; -pub const _SC_OPEN_MAX: ::c_int = 4; -pub const _SC_STREAM_MAX: ::c_int = 5; -pub const _SC_TZNAME_MAX: ::c_int = 6; -pub const _SC_JOB_CONTROL: ::c_int = 7; -pub const _SC_SAVED_IDS: ::c_int = 8; -pub const _SC_REALTIME_SIGNALS: ::c_int = 9; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 10; -pub const _SC_TIMERS: ::c_int = 11; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 12; -pub const _SC_PRIORITIZED_IO: ::c_int = 13; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 14; -pub const _SC_FSYNC: ::c_int = 15; -pub const _SC_MAPPED_FILES: ::c_int = 16; -pub const _SC_MEMLOCK: ::c_int = 17; -pub const _SC_MEMLOCK_RANGE: ::c_int = 18; -pub const _SC_MEMORY_PROTECTION: ::c_int = 19; -pub const _SC_MESSAGE_PASSING: ::c_int = 20; -pub const _SC_SEMAPHORES: ::c_int = 21; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 22; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 23; -pub const _SC_AIO_MAX: ::c_int = 24; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 25; -pub const _SC_DELAYTIMER_MAX: ::c_int = 26; -pub const _SC_MQ_OPEN_MAX: ::c_int = 27; -pub const _SC_MQ_PRIO_MAX: ::c_int = 28; -pub const _SC_VERSION: ::c_int = 29; -pub const _SC_PAGESIZE: ::c_int = 30; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_RTSIG_MAX: ::c_int = 31; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 32; -pub const _SC_SEM_VALUE_MAX: ::c_int = 33; -pub const _SC_SIGQUEUE_MAX: ::c_int = 34; -pub const _SC_TIMER_MAX: ::c_int = 35; -pub const _SC_BC_BASE_MAX: ::c_int = 36; -pub const _SC_BC_DIM_MAX: ::c_int = 37; -pub const _SC_BC_SCALE_MAX: ::c_int = 38; -pub const _SC_BC_STRING_MAX: ::c_int = 39; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 40; -pub const _SC_EXPR_NEST_MAX: ::c_int = 42; -pub const _SC_LINE_MAX: ::c_int = 43; -pub const _SC_RE_DUP_MAX: ::c_int = 44; -pub const _SC_2_VERSION: ::c_int = 46; -pub const _SC_2_C_BIND: ::c_int = 47; -pub const _SC_2_C_DEV: ::c_int = 48; -pub const _SC_2_FORT_DEV: ::c_int = 49; -pub const _SC_2_FORT_RUN: ::c_int = 50; -pub const _SC_2_SW_DEV: ::c_int = 51; -pub const _SC_2_LOCALEDEF: ::c_int = 52; -pub const _SC_UIO_MAXIOV: ::c_int = 60; -pub const _SC_IOV_MAX: ::c_int = 60; -pub const _SC_THREADS: ::c_int = 67; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 68; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 69; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 70; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 71; -pub const _SC_TTY_NAME_MAX: ::c_int = 72; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 73; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 74; -pub const _SC_THREAD_STACK_MIN: ::c_int = 75; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 76; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 77; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 78; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 79; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 80; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 81; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 82; -pub const _SC_NPROCESSORS_CONF: ::c_int = 83; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 84; -pub const _SC_PHYS_PAGES: ::c_int = 85; -pub const _SC_AVPHYS_PAGES: ::c_int = 86; -pub const _SC_ATEXIT_MAX: ::c_int = 87; -pub const _SC_PASS_MAX: ::c_int = 88; -pub const _SC_XOPEN_VERSION: ::c_int = 89; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 90; -pub const _SC_XOPEN_UNIX: ::c_int = 91; -pub const _SC_XOPEN_CRYPT: ::c_int = 92; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 93; -pub const _SC_XOPEN_SHM: ::c_int = 94; -pub const _SC_2_CHAR_TERM: ::c_int = 95; -pub const _SC_2_UPE: ::c_int = 97; -pub const _SC_XOPEN_XPG2: ::c_int = 98; -pub const _SC_XOPEN_XPG3: ::c_int = 99; -pub const _SC_XOPEN_XPG4: ::c_int = 100; -pub const _SC_NZERO: ::c_int = 109; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = 125; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = 126; -pub const _SC_XBS5_LP64_OFF64: ::c_int = 127; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = 128; -pub const _SC_XOPEN_LEGACY: ::c_int = 129; -pub const _SC_XOPEN_REALTIME: ::c_int = 130; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 131; -pub const _SC_ADVISORY_INFO: ::c_int = 132; -pub const _SC_BARRIERS: ::c_int = 133; -pub const _SC_CLOCK_SELECTION: ::c_int = 137; -pub const _SC_CPUTIME: ::c_int = 138; -pub const _SC_THREAD_CPUTIME: ::c_int = 139; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 149; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 153; -pub const _SC_SPIN_LOCKS: ::c_int = 154; -pub const _SC_REGEXP: ::c_int = 155; -pub const _SC_SHELL: ::c_int = 157; -pub const _SC_SPAWN: ::c_int = 159; -pub const _SC_SPORADIC_SERVER: ::c_int = 160; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 161; -pub const _SC_TIMEOUTS: ::c_int = 164; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 165; -pub const _SC_2_PBS: ::c_int = 168; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 169; -pub const _SC_2_PBS_LOCATE: ::c_int = 170; -pub const _SC_2_PBS_MESSAGE: ::c_int = 171; -pub const _SC_2_PBS_TRACK: ::c_int = 172; -pub const _SC_SYMLOOP_MAX: ::c_int = 173; -pub const _SC_STREAMS: ::c_int = 174; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 175; -pub const _SC_V6_ILP32_OFF32: ::c_int = 176; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 177; -pub const _SC_V6_LP64_OFF64: ::c_int = 178; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 179; -pub const _SC_HOST_NAME_MAX: ::c_int = 180; -pub const _SC_TRACE: ::c_int = 181; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 182; -pub const _SC_TRACE_INHERIT: ::c_int = 183; -pub const _SC_TRACE_LOG: ::c_int = 184; -pub const _SC_IPV6: ::c_int = 235; -pub const _SC_RAW_SOCKETS: ::c_int = 236; -pub const _SC_V7_ILP32_OFF32: ::c_int = 237; -pub const _SC_V7_ILP32_OFFBIG: ::c_int = 238; -pub const _SC_V7_LP64_OFF64: ::c_int = 239; -pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 240; -pub const _SC_SS_REPL_MAX: ::c_int = 241; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 242; -pub const _SC_TRACE_NAME_MAX: ::c_int = 243; -pub const _SC_TRACE_SYS_MAX: ::c_int = 244; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 245; -pub const _SC_XOPEN_STREAMS: ::c_int = 246; -pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 247; -pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 248; - -pub const RLIM_SAVED_MAX: ::rlim_t = RLIM_INFINITY; -pub const RLIM_SAVED_CUR: ::rlim_t = RLIM_INFINITY; - -pub const GLOB_ERR: ::c_int = 1 << 0; -pub const GLOB_MARK: ::c_int = 1 << 1; -pub const GLOB_NOSORT: ::c_int = 1 << 2; -pub const GLOB_DOOFFS: ::c_int = 1 << 3; -pub const GLOB_NOCHECK: ::c_int = 1 << 4; -pub const GLOB_APPEND: ::c_int = 1 << 5; -pub const GLOB_NOESCAPE: ::c_int = 1 << 6; - -pub const GLOB_NOSPACE: ::c_int = 1; -pub const GLOB_ABORTED: ::c_int = 2; -pub const GLOB_NOMATCH: ::c_int = 3; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; - -pub const S_IEXEC: mode_t = 64; -pub const S_IWRITE: mode_t = 128; -pub const S_IREAD: mode_t = 256; - -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; - -pub const F_SEAL_FUTURE_WRITE: ::c_int = 0x0010; - -pub const IFF_LOWER_UP: ::c_int = 0x10000; -pub const IFF_DORMANT: ::c_int = 0x20000; -pub const IFF_ECHO: ::c_int = 0x40000; - -// linux/if_addr.h -pub const IFA_UNSPEC: ::c_ushort = 0; -pub const IFA_ADDRESS: ::c_ushort = 1; -pub const IFA_LOCAL: ::c_ushort = 2; -pub const IFA_LABEL: ::c_ushort = 3; -pub const IFA_BROADCAST: ::c_ushort = 4; -pub const IFA_ANYCAST: ::c_ushort = 5; -pub const IFA_CACHEINFO: ::c_ushort = 6; -pub const IFA_MULTICAST: ::c_ushort = 7; - -pub const IFA_F_SECONDARY: u32 = 0x01; -pub const IFA_F_TEMPORARY: u32 = 0x01; -pub const IFA_F_NODAD: u32 = 0x02; -pub const IFA_F_OPTIMISTIC: u32 = 0x04; -pub const IFA_F_DADFAILED: u32 = 0x08; -pub const IFA_F_HOMEADDRESS: u32 = 0x10; -pub const IFA_F_DEPRECATED: u32 = 0x20; -pub const IFA_F_TENTATIVE: u32 = 0x40; -pub const IFA_F_PERMANENT: u32 = 0x80; - -// linux/if_link.h -pub const IFLA_UNSPEC: ::c_ushort = 0; -pub const IFLA_ADDRESS: ::c_ushort = 1; -pub const IFLA_BROADCAST: ::c_ushort = 2; -pub const IFLA_IFNAME: ::c_ushort = 3; -pub const IFLA_MTU: ::c_ushort = 4; -pub const IFLA_LINK: ::c_ushort = 5; -pub const IFLA_QDISC: ::c_ushort = 6; -pub const IFLA_STATS: ::c_ushort = 7; -pub const IFLA_COST: ::c_ushort = 8; -pub const IFLA_PRIORITY: ::c_ushort = 9; -pub const IFLA_MASTER: ::c_ushort = 10; -pub const IFLA_WIRELESS: ::c_ushort = 11; -pub const IFLA_PROTINFO: ::c_ushort = 12; -pub const IFLA_TXQLEN: ::c_ushort = 13; -pub const IFLA_MAP: ::c_ushort = 14; -pub const IFLA_WEIGHT: ::c_ushort = 15; -pub const IFLA_OPERSTATE: ::c_ushort = 16; -pub const IFLA_LINKMODE: ::c_ushort = 17; -pub const IFLA_LINKINFO: ::c_ushort = 18; -pub const IFLA_NET_NS_PID: ::c_ushort = 19; -pub const IFLA_IFALIAS: ::c_ushort = 20; -pub const IFLA_NUM_VF: ::c_ushort = 21; -pub const IFLA_VFINFO_LIST: ::c_ushort = 22; -pub const IFLA_STATS64: ::c_ushort = 23; -pub const IFLA_VF_PORTS: ::c_ushort = 24; -pub const IFLA_PORT_SELF: ::c_ushort = 25; -pub const IFLA_AF_SPEC: ::c_ushort = 26; -pub const IFLA_GROUP: ::c_ushort = 27; -pub const IFLA_NET_NS_FD: ::c_ushort = 28; -pub const IFLA_EXT_MASK: ::c_ushort = 29; -pub const IFLA_PROMISCUITY: ::c_ushort = 30; -pub const IFLA_NUM_TX_QUEUES: ::c_ushort = 31; -pub const IFLA_NUM_RX_QUEUES: ::c_ushort = 32; -pub const IFLA_CARRIER: ::c_ushort = 33; -pub const IFLA_PHYS_PORT_ID: ::c_ushort = 34; -pub const IFLA_CARRIER_CHANGES: ::c_ushort = 35; -pub const IFLA_PHYS_SWITCH_ID: ::c_ushort = 36; -pub const IFLA_LINK_NETNSID: ::c_ushort = 37; -pub const IFLA_PHYS_PORT_NAME: ::c_ushort = 38; -pub const IFLA_PROTO_DOWN: ::c_ushort = 39; - -pub const IFLA_INFO_UNSPEC: ::c_ushort = 0; -pub const IFLA_INFO_KIND: ::c_ushort = 1; -pub const IFLA_INFO_DATA: ::c_ushort = 2; -pub const IFLA_INFO_XSTATS: ::c_ushort = 3; -pub const IFLA_INFO_SLAVE_KIND: ::c_ushort = 4; -pub const IFLA_INFO_SLAVE_DATA: ::c_ushort = 5; - -// linux/if_tun.h -pub const IFF_TUN: ::c_int = 0x0001; -pub const IFF_TAP: ::c_int = 0x0002; -pub const IFF_NO_PI: ::c_int = 0x1000; -// Read queue size -pub const TUN_READQ_SIZE: ::c_short = 500; -// TUN device type flags: deprecated. Use IFF_TUN/IFF_TAP instead. -pub const TUN_TUN_DEV: ::c_short = ::IFF_TUN as ::c_short; -pub const TUN_TAP_DEV: ::c_short = ::IFF_TAP as ::c_short; -pub const TUN_TYPE_MASK: ::c_short = 0x000f; -// This flag has no real effect -pub const IFF_ONE_QUEUE: ::c_int = 0x2000; -pub const IFF_VNET_HDR: ::c_int = 0x4000; -pub const IFF_TUN_EXCL: ::c_int = 0x8000; -pub const IFF_MULTI_QUEUE: ::c_int = 0x0100; -pub const IFF_ATTACH_QUEUE: ::c_int = 0x0200; -pub const IFF_DETACH_QUEUE: ::c_int = 0x0400; -// read-only flag -pub const IFF_PERSIST: ::c_int = 0x0800; -pub const IFF_NOFILTER: ::c_int = 0x1000; - -pub const ST_RDONLY: ::c_ulong = 1; -pub const ST_NOSUID: ::c_ulong = 2; -pub const ST_NODEV: ::c_ulong = 4; -pub const ST_NOEXEC: ::c_ulong = 8; -pub const ST_SYNCHRONOUS: ::c_ulong = 16; -pub const ST_MANDLOCK: ::c_ulong = 64; -pub const ST_WRITE: ::c_ulong = 128; -pub const ST_APPEND: ::c_ulong = 256; -pub const ST_IMMUTABLE: ::c_ulong = 512; -pub const ST_NOATIME: ::c_ulong = 1024; -pub const ST_NODIRATIME: ::c_ulong = 2048; - -pub const RTLD_NEXT: *mut ::c_void = -1i64 as *mut ::c_void; -pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; -pub const RTLD_NODELETE: ::c_int = 0x1000; -pub const RTLD_NOW: ::c_int = 0x2; - -pub const TCP_MD5SIG: ::c_int = 14; - -align_const! { - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - size: [0; __SIZEOF_PTHREAD_MUTEX_T], - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - size: [0; __SIZEOF_PTHREAD_COND_T], - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - size: [0; __SIZEOF_PTHREAD_RWLOCK_T], - }; -} -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; -pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0; -pub const PTHREAD_PROCESS_SHARED: ::c_int = 1; -pub const __SIZEOF_PTHREAD_COND_T: usize = 48; - -pub const RENAME_NOREPLACE: ::c_int = 1; -pub const RENAME_EXCHANGE: ::c_int = 2; -pub const RENAME_WHITEOUT: ::c_int = 4; - -pub const SCHED_OTHER: ::c_int = 0; -pub const SCHED_FIFO: ::c_int = 1; -pub const SCHED_RR: ::c_int = 2; -pub const SCHED_BATCH: ::c_int = 3; -pub const SCHED_IDLE: ::c_int = 5; - -pub const SCHED_RESET_ON_FORK: ::c_int = 0x40000000; - -// netinet/in.h -// NOTE: These are in addition to the constants defined in src/unix/mod.rs - -// IPPROTO_IP defined in src/unix/mod.rs -/// Hop-by-hop option header -pub const IPPROTO_HOPOPTS: ::c_int = 0; -// IPPROTO_ICMP defined in src/unix/mod.rs -/// group mgmt protocol -pub const IPPROTO_IGMP: ::c_int = 2; -/// for compatibility -pub const IPPROTO_IPIP: ::c_int = 4; -// IPPROTO_TCP defined in src/unix/mod.rs -/// exterior gateway protocol -pub const IPPROTO_EGP: ::c_int = 8; -/// pup -pub const IPPROTO_PUP: ::c_int = 12; -// IPPROTO_UDP defined in src/unix/mod.rs -/// xns idp -pub const IPPROTO_IDP: ::c_int = 22; -/// tp-4 w/ class negotiation -pub const IPPROTO_TP: ::c_int = 29; -/// DCCP -pub const IPPROTO_DCCP: ::c_int = 33; -// IPPROTO_IPV6 defined in src/unix/mod.rs -/// IP6 routing header -pub const IPPROTO_ROUTING: ::c_int = 43; -/// IP6 fragmentation header -pub const IPPROTO_FRAGMENT: ::c_int = 44; -/// resource reservation -pub const IPPROTO_RSVP: ::c_int = 46; -/// General Routing Encap. -pub const IPPROTO_GRE: ::c_int = 47; -/// IP6 Encap Sec. Payload -pub const IPPROTO_ESP: ::c_int = 50; -/// IP6 Auth Header -pub const IPPROTO_AH: ::c_int = 51; -// IPPROTO_ICMPV6 defined in src/unix/mod.rs -/// IP6 no next header -pub const IPPROTO_NONE: ::c_int = 59; -/// IP6 destination option -pub const IPPROTO_DSTOPTS: ::c_int = 60; -pub const IPPROTO_MTP: ::c_int = 92; -pub const IPPROTO_BEETPH: ::c_int = 94; -/// encapsulation header -pub const IPPROTO_ENCAP: ::c_int = 98; -/// Protocol indep. multicast -pub const IPPROTO_PIM: ::c_int = 103; -/// IP Payload Comp. Protocol -pub const IPPROTO_COMP: ::c_int = 108; -/// SCTP -pub const IPPROTO_SCTP: ::c_int = 132; -pub const IPPROTO_MH: ::c_int = 135; -pub const IPPROTO_UDPLITE: ::c_int = 136; -pub const IPPROTO_MPLS: ::c_int = 137; -/// raw IP packet -pub const IPPROTO_RAW: ::c_int = 255; -pub const IPPROTO_MAX: ::c_int = 256; - -pub const AF_IB: ::c_int = 27; -pub const AF_MPLS: ::c_int = 28; -pub const AF_NFC: ::c_int = 39; -pub const AF_VSOCK: ::c_int = 40; -pub const AF_XDP: ::c_int = 44; -pub const PF_IB: ::c_int = AF_IB; -pub const PF_MPLS: ::c_int = AF_MPLS; -pub const PF_NFC: ::c_int = AF_NFC; -pub const PF_VSOCK: ::c_int = AF_VSOCK; -pub const PF_XDP: ::c_int = AF_XDP; - -// System V IPC -pub const IPC_PRIVATE: ::key_t = 0; - -pub const IPC_CREAT: ::c_int = 0o1000; -pub const IPC_EXCL: ::c_int = 0o2000; -pub const IPC_NOWAIT: ::c_int = 0o4000; - -pub const IPC_RMID: ::c_int = 0; -pub const IPC_SET: ::c_int = 1; -pub const IPC_STAT: ::c_int = 2; -pub const IPC_INFO: ::c_int = 3; -pub const MSG_STAT: ::c_int = 11; -pub const MSG_INFO: ::c_int = 12; - -pub const MSG_NOERROR: ::c_int = 0o10000; -pub const MSG_EXCEPT: ::c_int = 0o20000; -pub const MSG_COPY: ::c_int = 0o40000; - -pub const SHM_R: ::c_int = 0o400; -pub const SHM_W: ::c_int = 0o200; - -pub const SHM_RDONLY: ::c_int = 0o10000; -pub const SHM_RND: ::c_int = 0o20000; -pub const SHM_REMAP: ::c_int = 0o40000; -pub const SHM_EXEC: ::c_int = 0o100000; - -pub const SHM_LOCK: ::c_int = 11; -pub const SHM_UNLOCK: ::c_int = 12; - -pub const SHM_HUGETLB: ::c_int = 0o4000; -pub const SHM_NORESERVE: ::c_int = 0o10000; - -pub const EPOLLRDHUP: ::c_int = 0x2000; -pub const EPOLLEXCLUSIVE: ::c_int = 0x10000000; -pub const EPOLLONESHOT: ::c_int = 0x40000000; - -pub const QFMT_VFS_OLD: ::c_int = 1; -pub const QFMT_VFS_V0: ::c_int = 2; -pub const QFMT_VFS_V1: ::c_int = 4; - -pub const EFD_SEMAPHORE: ::c_int = 0x1; - -pub const LOG_NFACILITIES: ::c_int = 24; - -pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; - -pub const RB_AUTOBOOT: ::c_int = 0x01234567u32 as i32; -pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123u32 as i32; -pub const RB_ENABLE_CAD: ::c_int = 0x89abcdefu32 as i32; -pub const RB_DISABLE_CAD: ::c_int = 0x00000000u32 as i32; -pub const RB_POWER_OFF: ::c_int = 0x4321fedcu32 as i32; -pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2u32 as i32; -pub const RB_KEXEC: ::c_int = 0x45584543u32 as i32; - -pub const AI_PASSIVE: ::c_int = 0x0001; -pub const AI_CANONNAME: ::c_int = 0x0002; -pub const AI_NUMERICHOST: ::c_int = 0x0004; -pub const AI_V4MAPPED: ::c_int = 0x0008; -pub const AI_ALL: ::c_int = 0x0010; -pub const AI_ADDRCONFIG: ::c_int = 0x0020; - -pub const AI_NUMERICSERV: ::c_int = 0x0400; - -pub const EAI_BADFLAGS: ::c_int = -1; -pub const EAI_NONAME: ::c_int = -2; -pub const EAI_AGAIN: ::c_int = -3; -pub const EAI_FAIL: ::c_int = -4; -pub const EAI_NODATA: ::c_int = -5; -pub const EAI_FAMILY: ::c_int = -6; -pub const EAI_SOCKTYPE: ::c_int = -7; -pub const EAI_SERVICE: ::c_int = -8; -pub const EAI_MEMORY: ::c_int = -10; -pub const EAI_SYSTEM: ::c_int = -11; -pub const EAI_OVERFLOW: ::c_int = -12; - -pub const NI_NUMERICHOST: ::c_int = 1; -pub const NI_NUMERICSERV: ::c_int = 2; -pub const NI_NOFQDN: ::c_int = 4; -pub const NI_NAMEREQD: ::c_int = 8; -pub const NI_DGRAM: ::c_int = 16; - -pub const SYNC_FILE_RANGE_WAIT_BEFORE: ::c_uint = 1; -pub const SYNC_FILE_RANGE_WRITE: ::c_uint = 2; -pub const SYNC_FILE_RANGE_WAIT_AFTER: ::c_uint = 4; - -pub const AIO_CANCELED: ::c_int = 0; -pub const AIO_NOTCANCELED: ::c_int = 1; -pub const AIO_ALLDONE: ::c_int = 2; -pub const LIO_READ: ::c_int = 0; -pub const LIO_WRITE: ::c_int = 1; -pub const LIO_NOP: ::c_int = 2; -pub const LIO_WAIT: ::c_int = 0; -pub const LIO_NOWAIT: ::c_int = 1; - -pub const MREMAP_MAYMOVE: ::c_int = 1; -pub const MREMAP_FIXED: ::c_int = 2; - -pub const PR_SET_PDEATHSIG: ::c_int = 1; -pub const PR_GET_PDEATHSIG: ::c_int = 2; - -pub const PR_GET_DUMPABLE: ::c_int = 3; -pub const PR_SET_DUMPABLE: ::c_int = 4; - -pub const PR_GET_UNALIGN: ::c_int = 5; -pub const PR_SET_UNALIGN: ::c_int = 6; -pub const PR_UNALIGN_NOPRINT: ::c_int = 1; -pub const PR_UNALIGN_SIGBUS: ::c_int = 2; - -pub const PR_GET_KEEPCAPS: ::c_int = 7; -pub const PR_SET_KEEPCAPS: ::c_int = 8; - -pub const PR_GET_FPEMU: ::c_int = 9; -pub const PR_SET_FPEMU: ::c_int = 10; -pub const PR_FPEMU_NOPRINT: ::c_int = 1; -pub const PR_FPEMU_SIGFPE: ::c_int = 2; - -pub const PR_GET_FPEXC: ::c_int = 11; -pub const PR_SET_FPEXC: ::c_int = 12; -pub const PR_FP_EXC_SW_ENABLE: ::c_int = 0x80; -pub const PR_FP_EXC_DIV: ::c_int = 0x010000; -pub const PR_FP_EXC_OVF: ::c_int = 0x020000; -pub const PR_FP_EXC_UND: ::c_int = 0x040000; -pub const PR_FP_EXC_RES: ::c_int = 0x080000; -pub const PR_FP_EXC_INV: ::c_int = 0x100000; -pub const PR_FP_EXC_DISABLED: ::c_int = 0; -pub const PR_FP_EXC_NONRECOV: ::c_int = 1; -pub const PR_FP_EXC_ASYNC: ::c_int = 2; -pub const PR_FP_EXC_PRECISE: ::c_int = 3; - -pub const PR_GET_TIMING: ::c_int = 13; -pub const PR_SET_TIMING: ::c_int = 14; -pub const PR_TIMING_STATISTICAL: ::c_int = 0; -pub const PR_TIMING_TIMESTAMP: ::c_int = 1; - -pub const PR_SET_NAME: ::c_int = 15; -pub const PR_GET_NAME: ::c_int = 16; - -pub const PR_GET_ENDIAN: ::c_int = 19; -pub const PR_SET_ENDIAN: ::c_int = 20; -pub const PR_ENDIAN_BIG: ::c_int = 0; -pub const PR_ENDIAN_LITTLE: ::c_int = 1; -pub const PR_ENDIAN_PPC_LITTLE: ::c_int = 2; - -pub const PR_GET_SECCOMP: ::c_int = 21; -pub const PR_SET_SECCOMP: ::c_int = 22; - -pub const PR_CAPBSET_READ: ::c_int = 23; -pub const PR_CAPBSET_DROP: ::c_int = 24; - -pub const PR_GET_TSC: ::c_int = 25; -pub const PR_SET_TSC: ::c_int = 26; -pub const PR_TSC_ENABLE: ::c_int = 1; -pub const PR_TSC_SIGSEGV: ::c_int = 2; - -pub const PR_GET_SECUREBITS: ::c_int = 27; -pub const PR_SET_SECUREBITS: ::c_int = 28; - -pub const PR_SET_TIMERSLACK: ::c_int = 29; -pub const PR_GET_TIMERSLACK: ::c_int = 30; - -pub const PR_TASK_PERF_EVENTS_DISABLE: ::c_int = 31; -pub const PR_TASK_PERF_EVENTS_ENABLE: ::c_int = 32; - -pub const PR_MCE_KILL: ::c_int = 33; -pub const PR_MCE_KILL_CLEAR: ::c_int = 0; -pub const PR_MCE_KILL_SET: ::c_int = 1; - -pub const PR_MCE_KILL_LATE: ::c_int = 0; -pub const PR_MCE_KILL_EARLY: ::c_int = 1; -pub const PR_MCE_KILL_DEFAULT: ::c_int = 2; - -pub const PR_MCE_KILL_GET: ::c_int = 34; - -pub const PR_SET_MM: ::c_int = 35; -pub const PR_SET_MM_START_CODE: ::c_int = 1; -pub const PR_SET_MM_END_CODE: ::c_int = 2; -pub const PR_SET_MM_START_DATA: ::c_int = 3; -pub const PR_SET_MM_END_DATA: ::c_int = 4; -pub const PR_SET_MM_START_STACK: ::c_int = 5; -pub const PR_SET_MM_START_BRK: ::c_int = 6; -pub const PR_SET_MM_BRK: ::c_int = 7; -pub const PR_SET_MM_ARG_START: ::c_int = 8; -pub const PR_SET_MM_ARG_END: ::c_int = 9; -pub const PR_SET_MM_ENV_START: ::c_int = 10; -pub const PR_SET_MM_ENV_END: ::c_int = 11; -pub const PR_SET_MM_AUXV: ::c_int = 12; -pub const PR_SET_MM_EXE_FILE: ::c_int = 13; -pub const PR_SET_MM_MAP: ::c_int = 14; -pub const PR_SET_MM_MAP_SIZE: ::c_int = 15; - -pub const PR_SET_PTRACER: ::c_int = 0x59616d61; - -pub const PR_SET_CHILD_SUBREAPER: ::c_int = 36; -pub const PR_GET_CHILD_SUBREAPER: ::c_int = 37; - -pub const PR_SET_NO_NEW_PRIVS: ::c_int = 38; -pub const PR_GET_NO_NEW_PRIVS: ::c_int = 39; - -pub const PR_GET_TID_ADDRESS: ::c_int = 40; - -pub const PR_SET_THP_DISABLE: ::c_int = 41; -pub const PR_GET_THP_DISABLE: ::c_int = 42; - -pub const PR_MPX_ENABLE_MANAGEMENT: ::c_int = 43; -pub const PR_MPX_DISABLE_MANAGEMENT: ::c_int = 44; - -pub const PR_SET_FP_MODE: ::c_int = 45; -pub const PR_GET_FP_MODE: ::c_int = 46; -pub const PR_FP_MODE_FR: ::c_int = 1 << 0; -pub const PR_FP_MODE_FRE: ::c_int = 1 << 1; - -pub const PR_CAP_AMBIENT: ::c_int = 47; -pub const PR_CAP_AMBIENT_IS_SET: ::c_int = 1; -pub const PR_CAP_AMBIENT_RAISE: ::c_int = 2; -pub const PR_CAP_AMBIENT_LOWER: ::c_int = 3; -pub const PR_CAP_AMBIENT_CLEAR_ALL: ::c_int = 4; - -pub const GRND_NONBLOCK: ::c_uint = 0x0001; -pub const GRND_RANDOM: ::c_uint = 0x0002; - -pub const SECCOMP_MODE_DISABLED: ::c_uint = 0; -pub const SECCOMP_MODE_STRICT: ::c_uint = 1; -pub const SECCOMP_MODE_FILTER: ::c_uint = 2; - -pub const ITIMER_REAL: ::c_int = 0; -pub const ITIMER_VIRTUAL: ::c_int = 1; -pub const ITIMER_PROF: ::c_int = 2; - -pub const TFD_CLOEXEC: ::c_int = O_CLOEXEC; -pub const TFD_NONBLOCK: ::c_int = O_NONBLOCK; -pub const TFD_TIMER_ABSTIME: ::c_int = 1; - -pub const XATTR_CREATE: ::c_int = 0x1; -pub const XATTR_REPLACE: ::c_int = 0x2; - -pub const _POSIX_VDISABLE: ::cc_t = 0; - -pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01; -pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02; -pub const FALLOC_FL_COLLAPSE_RANGE: ::c_int = 0x08; -pub const FALLOC_FL_ZERO_RANGE: ::c_int = 0x10; -pub const FALLOC_FL_INSERT_RANGE: ::c_int = 0x20; -pub const FALLOC_FL_UNSHARE_RANGE: ::c_int = 0x40; - -#[deprecated( - since = "0.2.55", - note = "ENOATTR is not available on Linux; use ENODATA instead" -)] -pub const ENOATTR: ::c_int = ::ENODATA; - -pub const SO_ORIGINAL_DST: ::c_int = 80; -pub const IP_ORIGDSTADDR: ::c_int = 20; -pub const IP_RECVORIGDSTADDR: ::c_int = IP_ORIGDSTADDR; -pub const IPV6_ORIGDSTADDR: ::c_int = 74; -pub const IPV6_RECVORIGDSTADDR: ::c_int = IPV6_ORIGDSTADDR; -pub const IPV6_FLOWLABEL_MGR: ::c_int = 32; -pub const IPV6_FLOWINFO_SEND: ::c_int = 33; -pub const IPV6_FLOWINFO_FLOWLABEL: ::c_int = 0x000fffff; -pub const IPV6_FLOWINFO_PRIORITY: ::c_int = 0x0ff00000; - -pub const IUTF8: ::tcflag_t = 0x00004000; -pub const CMSPAR: ::tcflag_t = 0o10000000000; - -pub const MFD_CLOEXEC: ::c_uint = 0x0001; -pub const MFD_ALLOW_SEALING: ::c_uint = 0x0002; -pub const MFD_HUGETLB: ::c_uint = 0x0004; - -// these are used in the p_type field of Elf32_Phdr and Elf64_Phdr, which has -// the type Elf32Word and Elf64Word respectively. Luckily, both of those are u32 -// so we can use that type here to avoid having to cast. -pub const PT_NULL: u32 = 0; -pub const PT_LOAD: u32 = 1; -pub const PT_DYNAMIC: u32 = 2; -pub const PT_INTERP: u32 = 3; -pub const PT_NOTE: u32 = 4; -pub const PT_SHLIB: u32 = 5; -pub const PT_PHDR: u32 = 6; -pub const PT_TLS: u32 = 7; -pub const PT_NUM: u32 = 8; -pub const PT_LOOS: u32 = 0x60000000; -pub const PT_GNU_EH_FRAME: u32 = 0x6474e550; -pub const PT_GNU_STACK: u32 = 0x6474e551; -pub const PT_GNU_RELRO: u32 = 0x6474e552; - -// linux/if_ether.h -pub const ETH_ALEN: ::c_int = 6; -pub const ETH_HLEN: ::c_int = 14; -pub const ETH_ZLEN: ::c_int = 60; -pub const ETH_DATA_LEN: ::c_int = 1500; -pub const ETH_FRAME_LEN: ::c_int = 1514; -pub const ETH_FCS_LEN: ::c_int = 4; - -// These are the defined Ethernet Protocol ID's. -pub const ETH_P_LOOP: ::c_int = 0x0060; -pub const ETH_P_PUP: ::c_int = 0x0200; -pub const ETH_P_PUPAT: ::c_int = 0x0201; -pub const ETH_P_IP: ::c_int = 0x0800; -pub const ETH_P_X25: ::c_int = 0x0805; -pub const ETH_P_ARP: ::c_int = 0x0806; -pub const ETH_P_BPQ: ::c_int = 0x08FF; -pub const ETH_P_IEEEPUP: ::c_int = 0x0a00; -pub const ETH_P_IEEEPUPAT: ::c_int = 0x0a01; -pub const ETH_P_BATMAN: ::c_int = 0x4305; -pub const ETH_P_DEC: ::c_int = 0x6000; -pub const ETH_P_DNA_DL: ::c_int = 0x6001; -pub const ETH_P_DNA_RC: ::c_int = 0x6002; -pub const ETH_P_DNA_RT: ::c_int = 0x6003; -pub const ETH_P_LAT: ::c_int = 0x6004; -pub const ETH_P_DIAG: ::c_int = 0x6005; -pub const ETH_P_CUST: ::c_int = 0x6006; -pub const ETH_P_SCA: ::c_int = 0x6007; -pub const ETH_P_TEB: ::c_int = 0x6558; -pub const ETH_P_RARP: ::c_int = 0x8035; -pub const ETH_P_ATALK: ::c_int = 0x809B; -pub const ETH_P_AARP: ::c_int = 0x80F3; -pub const ETH_P_8021Q: ::c_int = 0x8100; -pub const ETH_P_IPX: ::c_int = 0x8137; -pub const ETH_P_IPV6: ::c_int = 0x86DD; -pub const ETH_P_PAUSE: ::c_int = 0x8808; -pub const ETH_P_SLOW: ::c_int = 0x8809; -pub const ETH_P_WCCP: ::c_int = 0x883E; -pub const ETH_P_MPLS_UC: ::c_int = 0x8847; -pub const ETH_P_MPLS_MC: ::c_int = 0x8848; -pub const ETH_P_ATMMPOA: ::c_int = 0x884c; -pub const ETH_P_PPP_DISC: ::c_int = 0x8863; -pub const ETH_P_PPP_SES: ::c_int = 0x8864; -pub const ETH_P_LINK_CTL: ::c_int = 0x886c; -pub const ETH_P_ATMFATE: ::c_int = 0x8884; -pub const ETH_P_PAE: ::c_int = 0x888E; -pub const ETH_P_AOE: ::c_int = 0x88A2; -pub const ETH_P_8021AD: ::c_int = 0x88A8; -pub const ETH_P_802_EX1: ::c_int = 0x88B5; -pub const ETH_P_TIPC: ::c_int = 0x88CA; -pub const ETH_P_MACSEC: ::c_int = 0x88E5; -pub const ETH_P_8021AH: ::c_int = 0x88E7; -pub const ETH_P_MVRP: ::c_int = 0x88F5; -pub const ETH_P_1588: ::c_int = 0x88F7; -pub const ETH_P_PRP: ::c_int = 0x88FB; -pub const ETH_P_FCOE: ::c_int = 0x8906; -pub const ETH_P_TDLS: ::c_int = 0x890D; -pub const ETH_P_FIP: ::c_int = 0x8914; -pub const ETH_P_80221: ::c_int = 0x8917; -pub const ETH_P_LOOPBACK: ::c_int = 0x9000; -pub const ETH_P_QINQ1: ::c_int = 0x9100; -pub const ETH_P_QINQ2: ::c_int = 0x9200; -pub const ETH_P_QINQ3: ::c_int = 0x9300; -pub const ETH_P_EDSA: ::c_int = 0xDADA; -pub const ETH_P_AF_IUCV: ::c_int = 0xFBFB; - -pub const ETH_P_802_3_MIN: ::c_int = 0x0600; - -// Non DIX types. Won't clash for 1500 types. -pub const ETH_P_802_3: ::c_int = 0x0001; -pub const ETH_P_AX25: ::c_int = 0x0002; -pub const ETH_P_ALL: ::c_int = 0x0003; -pub const ETH_P_802_2: ::c_int = 0x0004; -pub const ETH_P_SNAP: ::c_int = 0x0005; -pub const ETH_P_DDCMP: ::c_int = 0x0006; -pub const ETH_P_WAN_PPP: ::c_int = 0x0007; -pub const ETH_P_PPP_MP: ::c_int = 0x0008; -pub const ETH_P_LOCALTALK: ::c_int = 0x0009; -pub const ETH_P_CANFD: ::c_int = 0x000D; -pub const ETH_P_PPPTALK: ::c_int = 0x0010; -pub const ETH_P_TR_802_2: ::c_int = 0x0011; -pub const ETH_P_MOBITEX: ::c_int = 0x0015; -pub const ETH_P_CONTROL: ::c_int = 0x0016; -pub const ETH_P_IRDA: ::c_int = 0x0017; -pub const ETH_P_ECONET: ::c_int = 0x0018; -pub const ETH_P_HDLC: ::c_int = 0x0019; -pub const ETH_P_ARCNET: ::c_int = 0x001A; -pub const ETH_P_DSA: ::c_int = 0x001B; -pub const ETH_P_TRAILER: ::c_int = 0x001C; -pub const ETH_P_PHONET: ::c_int = 0x00F5; -pub const ETH_P_IEEE802154: ::c_int = 0x00F6; -pub const ETH_P_CAIF: ::c_int = 0x00F7; - -pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x01; -pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x02; -pub const POSIX_SPAWN_SETSIGDEF: ::c_int = 0x04; -pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x08; -pub const POSIX_SPAWN_SETSCHEDPARAM: ::c_int = 0x10; -pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x20; - -pub const NLMSG_NOOP: ::c_int = 0x1; -pub const NLMSG_ERROR: ::c_int = 0x2; -pub const NLMSG_DONE: ::c_int = 0x3; -pub const NLMSG_OVERRUN: ::c_int = 0x4; -pub const NLMSG_MIN_TYPE: ::c_int = 0x10; - -// linux/netfilter/nfnetlink.h -pub const NFNLGRP_NONE: ::c_int = 0; -pub const NFNLGRP_CONNTRACK_NEW: ::c_int = 1; -pub const NFNLGRP_CONNTRACK_UPDATE: ::c_int = 2; -pub const NFNLGRP_CONNTRACK_DESTROY: ::c_int = 3; -pub const NFNLGRP_CONNTRACK_EXP_NEW: ::c_int = 4; -pub const NFNLGRP_CONNTRACK_EXP_UPDATE: ::c_int = 5; -pub const NFNLGRP_CONNTRACK_EXP_DESTROY: ::c_int = 6; -pub const NFNLGRP_NFTABLES: ::c_int = 7; -pub const NFNLGRP_ACCT_QUOTA: ::c_int = 8; - -pub const NFNETLINK_V0: ::c_int = 0; - -pub const NFNL_SUBSYS_NONE: ::c_int = 0; -pub const NFNL_SUBSYS_CTNETLINK: ::c_int = 1; -pub const NFNL_SUBSYS_CTNETLINK_EXP: ::c_int = 2; -pub const NFNL_SUBSYS_QUEUE: ::c_int = 3; -pub const NFNL_SUBSYS_ULOG: ::c_int = 4; -pub const NFNL_SUBSYS_OSF: ::c_int = 5; -pub const NFNL_SUBSYS_IPSET: ::c_int = 6; -pub const NFNL_SUBSYS_ACCT: ::c_int = 7; -pub const NFNL_SUBSYS_CTNETLINK_TIMEOUT: ::c_int = 8; -pub const NFNL_SUBSYS_CTHELPER: ::c_int = 9; -pub const NFNL_SUBSYS_NFTABLES: ::c_int = 10; -pub const NFNL_SUBSYS_NFT_COMPAT: ::c_int = 11; -pub const NFNL_SUBSYS_COUNT: ::c_int = 12; - -pub const NFNL_MSG_BATCH_BEGIN: ::c_int = NLMSG_MIN_TYPE; -pub const NFNL_MSG_BATCH_END: ::c_int = NLMSG_MIN_TYPE + 1; - -// linux/netfilter/nfnetlink_log.h -pub const NFULNL_MSG_PACKET: ::c_int = 0; -pub const NFULNL_MSG_CONFIG: ::c_int = 1; - -pub const NFULA_UNSPEC: ::c_int = 0; -pub const NFULA_PACKET_HDR: ::c_int = 1; -pub const NFULA_MARK: ::c_int = 2; -pub const NFULA_TIMESTAMP: ::c_int = 3; -pub const NFULA_IFINDEX_INDEV: ::c_int = 4; -pub const NFULA_IFINDEX_OUTDEV: ::c_int = 5; -pub const NFULA_IFINDEX_PHYSINDEV: ::c_int = 6; -pub const NFULA_IFINDEX_PHYSOUTDEV: ::c_int = 7; -pub const NFULA_HWADDR: ::c_int = 8; -pub const NFULA_PAYLOAD: ::c_int = 9; -pub const NFULA_PREFIX: ::c_int = 10; -pub const NFULA_UID: ::c_int = 11; -pub const NFULA_SEQ: ::c_int = 12; -pub const NFULA_SEQ_GLOBAL: ::c_int = 13; -pub const NFULA_GID: ::c_int = 14; -pub const NFULA_HWTYPE: ::c_int = 15; -pub const NFULA_HWHEADER: ::c_int = 16; -pub const NFULA_HWLEN: ::c_int = 17; -pub const NFULA_CT: ::c_int = 18; -pub const NFULA_CT_INFO: ::c_int = 19; - -pub const NFULNL_CFG_CMD_NONE: ::c_int = 0; -pub const NFULNL_CFG_CMD_BIND: ::c_int = 1; -pub const NFULNL_CFG_CMD_UNBIND: ::c_int = 2; -pub const NFULNL_CFG_CMD_PF_BIND: ::c_int = 3; -pub const NFULNL_CFG_CMD_PF_UNBIND: ::c_int = 4; - -pub const NFULA_CFG_UNSPEC: ::c_int = 0; -pub const NFULA_CFG_CMD: ::c_int = 1; -pub const NFULA_CFG_MODE: ::c_int = 2; -pub const NFULA_CFG_NLBUFSIZ: ::c_int = 3; -pub const NFULA_CFG_TIMEOUT: ::c_int = 4; -pub const NFULA_CFG_QTHRESH: ::c_int = 5; -pub const NFULA_CFG_FLAGS: ::c_int = 6; - -pub const NFULNL_COPY_NONE: ::c_int = 0x00; -pub const NFULNL_COPY_META: ::c_int = 0x01; -pub const NFULNL_COPY_PACKET: ::c_int = 0x02; - -pub const NFULNL_CFG_F_SEQ: ::c_int = 0x0001; -pub const NFULNL_CFG_F_SEQ_GLOBAL: ::c_int = 0x0002; -pub const NFULNL_CFG_F_CONNTRACK: ::c_int = 0x0004; - -pub const GENL_NAMSIZ: ::c_int = 16; - -pub const GENL_MIN_ID: ::c_int = NLMSG_MIN_TYPE; -pub const GENL_MAX_ID: ::c_int = 1023; - -pub const GENL_ADMIN_PERM: ::c_int = 0x01; -pub const GENL_CMD_CAP_DO: ::c_int = 0x02; -pub const GENL_CMD_CAP_DUMP: ::c_int = 0x04; -pub const GENL_CMD_CAP_HASPOL: ::c_int = 0x08; - -pub const GENL_ID_CTRL: ::c_int = NLMSG_MIN_TYPE; - -pub const CTRL_CMD_UNSPEC: ::c_int = 0; -pub const CTRL_CMD_NEWFAMILY: ::c_int = 1; -pub const CTRL_CMD_DELFAMILY: ::c_int = 2; -pub const CTRL_CMD_GETFAMILY: ::c_int = 3; -pub const CTRL_CMD_NEWOPS: ::c_int = 4; -pub const CTRL_CMD_DELOPS: ::c_int = 5; -pub const CTRL_CMD_GETOPS: ::c_int = 6; -pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7; -pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8; -pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9; - -pub const CTRL_ATTR_UNSPEC: ::c_int = 0; -pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1; -pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2; -pub const CTRL_ATTR_VERSION: ::c_int = 3; -pub const CTRL_ATTR_HDRSIZE: ::c_int = 4; -pub const CTRL_ATTR_MAXATTR: ::c_int = 5; -pub const CTRL_ATTR_OPS: ::c_int = 6; -pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7; - -pub const CTRL_ATTR_OP_UNSPEC: ::c_int = 0; -pub const CTRL_ATTR_OP_ID: ::c_int = 1; -pub const CTRL_ATTR_OP_FLAGS: ::c_int = 2; - -pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0; -pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1; -pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2; - -// linux/if_packet.h -pub const PACKET_ADD_MEMBERSHIP: ::c_int = 1; -pub const PACKET_DROP_MEMBERSHIP: ::c_int = 2; - -pub const PACKET_MR_MULTICAST: ::c_int = 0; -pub const PACKET_MR_PROMISC: ::c_int = 1; -pub const PACKET_MR_ALLMULTI: ::c_int = 2; -pub const PACKET_MR_UNICAST: ::c_int = 3; - -// linux/netfilter.h -pub const NF_DROP: ::c_int = 0; -pub const NF_ACCEPT: ::c_int = 1; -pub const NF_STOLEN: ::c_int = 2; -pub const NF_QUEUE: ::c_int = 3; -pub const NF_REPEAT: ::c_int = 4; -pub const NF_STOP: ::c_int = 5; -pub const NF_MAX_VERDICT: ::c_int = NF_STOP; - -pub const NF_VERDICT_MASK: ::c_int = 0x000000ff; -pub const NF_VERDICT_FLAG_QUEUE_BYPASS: ::c_int = 0x00008000; - -pub const NF_VERDICT_QMASK: ::c_int = 0xffff0000; -pub const NF_VERDICT_QBITS: ::c_int = 16; - -pub const NF_VERDICT_BITS: ::c_int = 16; - -pub const NF_INET_PRE_ROUTING: ::c_int = 0; -pub const NF_INET_LOCAL_IN: ::c_int = 1; -pub const NF_INET_FORWARD: ::c_int = 2; -pub const NF_INET_LOCAL_OUT: ::c_int = 3; -pub const NF_INET_POST_ROUTING: ::c_int = 4; -pub const NF_INET_NUMHOOKS: ::c_int = 5; - -// Some NFPROTO are not compatible with musl and are defined in submodules. -pub const NFPROTO_UNSPEC: ::c_int = 0; -pub const NFPROTO_IPV4: ::c_int = 2; -pub const NFPROTO_ARP: ::c_int = 3; -pub const NFPROTO_BRIDGE: ::c_int = 7; -pub const NFPROTO_IPV6: ::c_int = 10; -pub const NFPROTO_DECNET: ::c_int = 12; -pub const NFPROTO_NUMPROTO: ::c_int = 13; - -// linux/netfilter_ipv4.h -pub const NF_IP_PRE_ROUTING: ::c_int = 0; -pub const NF_IP_LOCAL_IN: ::c_int = 1; -pub const NF_IP_FORWARD: ::c_int = 2; -pub const NF_IP_LOCAL_OUT: ::c_int = 3; -pub const NF_IP_POST_ROUTING: ::c_int = 4; -pub const NF_IP_NUMHOOKS: ::c_int = 5; - -pub const NF_IP_PRI_FIRST: ::c_int = ::INT_MIN; -pub const NF_IP_PRI_CONNTRACK_DEFRAG: ::c_int = -400; -pub const NF_IP_PRI_RAW: ::c_int = -300; -pub const NF_IP_PRI_SELINUX_FIRST: ::c_int = -225; -pub const NF_IP_PRI_CONNTRACK: ::c_int = -200; -pub const NF_IP_PRI_MANGLE: ::c_int = -150; -pub const NF_IP_PRI_NAT_DST: ::c_int = -100; -pub const NF_IP_PRI_FILTER: ::c_int = 0; -pub const NF_IP_PRI_SECURITY: ::c_int = 50; -pub const NF_IP_PRI_NAT_SRC: ::c_int = 100; -pub const NF_IP_PRI_SELINUX_LAST: ::c_int = 225; -pub const NF_IP_PRI_CONNTRACK_HELPER: ::c_int = 300; -pub const NF_IP_PRI_CONNTRACK_CONFIRM: ::c_int = ::INT_MAX; -pub const NF_IP_PRI_LAST: ::c_int = ::INT_MAX; - -// linux/netfilter_ipv6.h -pub const NF_IP6_PRE_ROUTING: ::c_int = 0; -pub const NF_IP6_LOCAL_IN: ::c_int = 1; -pub const NF_IP6_FORWARD: ::c_int = 2; -pub const NF_IP6_LOCAL_OUT: ::c_int = 3; -pub const NF_IP6_POST_ROUTING: ::c_int = 4; -pub const NF_IP6_NUMHOOKS: ::c_int = 5; - -pub const NF_IP6_PRI_FIRST: ::c_int = ::INT_MIN; -pub const NF_IP6_PRI_CONNTRACK_DEFRAG: ::c_int = -400; -pub const NF_IP6_PRI_RAW: ::c_int = -300; -pub const NF_IP6_PRI_SELINUX_FIRST: ::c_int = -225; -pub const NF_IP6_PRI_CONNTRACK: ::c_int = -200; -pub const NF_IP6_PRI_MANGLE: ::c_int = -150; -pub const NF_IP6_PRI_NAT_DST: ::c_int = -100; -pub const NF_IP6_PRI_FILTER: ::c_int = 0; -pub const NF_IP6_PRI_SECURITY: ::c_int = 50; -pub const NF_IP6_PRI_NAT_SRC: ::c_int = 100; -pub const NF_IP6_PRI_SELINUX_LAST: ::c_int = 225; -pub const NF_IP6_PRI_CONNTRACK_HELPER: ::c_int = 300; -pub const NF_IP6_PRI_LAST: ::c_int = ::INT_MAX; - -pub const SIOCADDRT: ::c_ulong = 0x0000890B; -pub const SIOCDELRT: ::c_ulong = 0x0000890C; -pub const SIOCGIFNAME: ::c_ulong = 0x00008910; -pub const SIOCSIFLINK: ::c_ulong = 0x00008911; -pub const SIOCGIFCONF: ::c_ulong = 0x00008912; -pub const SIOCGIFFLAGS: ::c_ulong = 0x00008913; -pub const SIOCSIFFLAGS: ::c_ulong = 0x00008914; -pub const SIOCGIFADDR: ::c_ulong = 0x00008915; -pub const SIOCSIFADDR: ::c_ulong = 0x00008916; -pub const SIOCGIFDSTADDR: ::c_ulong = 0x00008917; -pub const SIOCSIFDSTADDR: ::c_ulong = 0x00008918; -pub const SIOCGIFBRDADDR: ::c_ulong = 0x00008919; -pub const SIOCSIFBRDADDR: ::c_ulong = 0x0000891A; -pub const SIOCGIFNETMASK: ::c_ulong = 0x0000891B; -pub const SIOCSIFNETMASK: ::c_ulong = 0x0000891C; -pub const SIOCGIFMETRIC: ::c_ulong = 0x0000891D; -pub const SIOCSIFMETRIC: ::c_ulong = 0x0000891E; -pub const SIOCGIFMEM: ::c_ulong = 0x0000891F; -pub const SIOCSIFMEM: ::c_ulong = 0x00008920; -pub const SIOCGIFMTU: ::c_ulong = 0x00008921; -pub const SIOCSIFMTU: ::c_ulong = 0x00008922; -pub const SIOCSIFHWADDR: ::c_ulong = 0x00008924; -pub const SIOCGIFENCAP: ::c_ulong = 0x00008925; -pub const SIOCSIFENCAP: ::c_ulong = 0x00008926; -pub const SIOCGIFHWADDR: ::c_ulong = 0x00008927; -pub const SIOCGIFSLAVE: ::c_ulong = 0x00008929; -pub const SIOCSIFSLAVE: ::c_ulong = 0x00008930; -pub const SIOCADDMULTI: ::c_ulong = 0x00008931; -pub const SIOCDELMULTI: ::c_ulong = 0x00008932; -pub const SIOCDARP: ::c_ulong = 0x00008953; -pub const SIOCGARP: ::c_ulong = 0x00008954; -pub const SIOCSARP: ::c_ulong = 0x00008955; -pub const SIOCDRARP: ::c_ulong = 0x00008960; -pub const SIOCGRARP: ::c_ulong = 0x00008961; -pub const SIOCSRARP: ::c_ulong = 0x00008962; -pub const SIOCGIFMAP: ::c_ulong = 0x00008970; -pub const SIOCSIFMAP: ::c_ulong = 0x00008971; - -pub const IPTOS_TOS_MASK: u8 = 0x1E; -pub const IPTOS_PREC_MASK: u8 = 0xE0; - -pub const IPTOS_ECN_NOT_ECT: u8 = 0x00; - -pub const RTF_UP: ::c_ushort = 0x0001; -pub const RTF_GATEWAY: ::c_ushort = 0x0002; - -pub const RTF_HOST: ::c_ushort = 0x0004; -pub const RTF_REINSTATE: ::c_ushort = 0x0008; -pub const RTF_DYNAMIC: ::c_ushort = 0x0010; -pub const RTF_MODIFIED: ::c_ushort = 0x0020; -pub const RTF_MTU: ::c_ushort = 0x0040; -pub const RTF_MSS: ::c_ushort = RTF_MTU; -pub const RTF_WINDOW: ::c_ushort = 0x0080; -pub const RTF_IRTT: ::c_ushort = 0x0100; -pub const RTF_REJECT: ::c_ushort = 0x0200; -pub const RTF_STATIC: ::c_ushort = 0x0400; -pub const RTF_XRESOLVE: ::c_ushort = 0x0800; -pub const RTF_NOFORWARD: ::c_ushort = 0x1000; -pub const RTF_THROW: ::c_ushort = 0x2000; -pub const RTF_NOPMTUDISC: ::c_ushort = 0x4000; - -pub const RTF_DEFAULT: u32 = 0x00010000; -pub const RTF_ALLONLINK: u32 = 0x00020000; -pub const RTF_ADDRCONF: u32 = 0x00040000; -pub const RTF_LINKRT: u32 = 0x00100000; -pub const RTF_NONEXTHOP: u32 = 0x00200000; -pub const RTF_CACHE: u32 = 0x01000000; -pub const RTF_FLOW: u32 = 0x02000000; -pub const RTF_POLICY: u32 = 0x04000000; - -pub const RTCF_VALVE: u32 = 0x00200000; -pub const RTCF_MASQ: u32 = 0x00400000; -pub const RTCF_NAT: u32 = 0x00800000; -pub const RTCF_DOREDIRECT: u32 = 0x01000000; -pub const RTCF_LOG: u32 = 0x02000000; -pub const RTCF_DIRECTSRC: u32 = 0x04000000; - -pub const RTF_LOCAL: u32 = 0x80000000; -pub const RTF_INTERFACE: u32 = 0x40000000; -pub const RTF_MULTICAST: u32 = 0x20000000; -pub const RTF_BROADCAST: u32 = 0x10000000; -pub const RTF_NAT: u32 = 0x08000000; -pub const RTF_ADDRCLASSMASK: u32 = 0xF8000000; - -pub const RT_CLASS_UNSPEC: u8 = 0; -pub const RT_CLASS_DEFAULT: u8 = 253; -pub const RT_CLASS_MAIN: u8 = 254; -pub const RT_CLASS_LOCAL: u8 = 255; -pub const RT_CLASS_MAX: u8 = 255; - -// linux/neighbor.h -pub const NUD_NONE: u16 = 0x00; -pub const NUD_INCOMPLETE: u16 = 0x01; -pub const NUD_REACHABLE: u16 = 0x02; -pub const NUD_STALE: u16 = 0x04; -pub const NUD_DELAY: u16 = 0x08; -pub const NUD_PROBE: u16 = 0x10; -pub const NUD_FAILED: u16 = 0x20; -pub const NUD_NOARP: u16 = 0x40; -pub const NUD_PERMANENT: u16 = 0x80; - -pub const NTF_USE: u8 = 0x01; -pub const NTF_SELF: u8 = 0x02; -pub const NTF_MASTER: u8 = 0x04; -pub const NTF_PROXY: u8 = 0x08; -pub const NTF_ROUTER: u8 = 0x80; - -pub const NDA_UNSPEC: ::c_ushort = 0; -pub const NDA_DST: ::c_ushort = 1; -pub const NDA_LLADDR: ::c_ushort = 2; -pub const NDA_CACHEINFO: ::c_ushort = 3; -pub const NDA_PROBES: ::c_ushort = 4; -pub const NDA_VLAN: ::c_ushort = 5; -pub const NDA_PORT: ::c_ushort = 6; -pub const NDA_VNI: ::c_ushort = 7; -pub const NDA_IFINDEX: ::c_ushort = 8; - -// linux/netlink.h -pub const NLA_ALIGNTO: ::c_int = 4; - -pub const NETLINK_ROUTE: ::c_int = 0; -pub const NETLINK_UNUSED: ::c_int = 1; -pub const NETLINK_USERSOCK: ::c_int = 2; -pub const NETLINK_FIREWALL: ::c_int = 3; -pub const NETLINK_SOCK_DIAG: ::c_int = 4; -pub const NETLINK_NFLOG: ::c_int = 5; -pub const NETLINK_XFRM: ::c_int = 6; -pub const NETLINK_SELINUX: ::c_int = 7; -pub const NETLINK_ISCSI: ::c_int = 8; -pub const NETLINK_AUDIT: ::c_int = 9; -pub const NETLINK_FIB_LOOKUP: ::c_int = 10; -pub const NETLINK_CONNECTOR: ::c_int = 11; -pub const NETLINK_NETFILTER: ::c_int = 12; -pub const NETLINK_IP6_FW: ::c_int = 13; -pub const NETLINK_DNRTMSG: ::c_int = 14; -pub const NETLINK_KOBJECT_UEVENT: ::c_int = 15; -pub const NETLINK_GENERIC: ::c_int = 16; -pub const NETLINK_SCSITRANSPORT: ::c_int = 18; -pub const NETLINK_ECRYPTFS: ::c_int = 19; -pub const NETLINK_RDMA: ::c_int = 20; -pub const NETLINK_CRYPTO: ::c_int = 21; -pub const NETLINK_INET_DIAG: ::c_int = NETLINK_SOCK_DIAG; - -pub const NLM_F_REQUEST: ::c_int = 1; -pub const NLM_F_MULTI: ::c_int = 2; -pub const NLM_F_ACK: ::c_int = 4; -pub const NLM_F_ECHO: ::c_int = 8; -pub const NLM_F_DUMP_INTR: ::c_int = 16; -pub const NLM_F_DUMP_FILTERED: ::c_int = 32; - -pub const NLM_F_ROOT: ::c_int = 0x100; -pub const NLM_F_MATCH: ::c_int = 0x200; -pub const NLM_F_ATOMIC: ::c_int = 0x400; -pub const NLM_F_DUMP: ::c_int = NLM_F_ROOT | NLM_F_MATCH; - -pub const NLM_F_REPLACE: ::c_int = 0x100; -pub const NLM_F_EXCL: ::c_int = 0x200; -pub const NLM_F_CREATE: ::c_int = 0x400; -pub const NLM_F_APPEND: ::c_int = 0x800; - -pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1; -pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2; -pub const NETLINK_PKTINFO: ::c_int = 3; -pub const NETLINK_BROADCAST_ERROR: ::c_int = 4; -pub const NETLINK_NO_ENOBUFS: ::c_int = 5; -pub const NETLINK_RX_RING: ::c_int = 6; -pub const NETLINK_TX_RING: ::c_int = 7; -pub const NETLINK_LISTEN_ALL_NSID: ::c_int = 8; -pub const NETLINK_LIST_MEMBERSHIPS: ::c_int = 9; -pub const NETLINK_CAP_ACK: ::c_int = 10; - -pub const NLA_F_NESTED: ::c_int = 1 << 15; -pub const NLA_F_NET_BYTEORDER: ::c_int = 1 << 14; -pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER); - -// linux/rtnetlink.h -pub const TCA_UNSPEC: ::c_ushort = 0; -pub const TCA_KIND: ::c_ushort = 1; -pub const TCA_OPTIONS: ::c_ushort = 2; -pub const TCA_STATS: ::c_ushort = 3; -pub const TCA_XSTATS: ::c_ushort = 4; -pub const TCA_RATE: ::c_ushort = 5; -pub const TCA_FCNT: ::c_ushort = 6; -pub const TCA_STATS2: ::c_ushort = 7; -pub const TCA_STAB: ::c_ushort = 8; - -pub const RTM_NEWLINK: u16 = 16; -pub const RTM_DELLINK: u16 = 17; -pub const RTM_GETLINK: u16 = 18; -pub const RTM_SETLINK: u16 = 19; -pub const RTM_NEWADDR: u16 = 20; -pub const RTM_DELADDR: u16 = 21; -pub const RTM_GETADDR: u16 = 22; -pub const RTM_NEWROUTE: u16 = 24; -pub const RTM_DELROUTE: u16 = 25; -pub const RTM_GETROUTE: u16 = 26; -pub const RTM_NEWNEIGH: u16 = 28; -pub const RTM_DELNEIGH: u16 = 29; -pub const RTM_GETNEIGH: u16 = 30; -pub const RTM_NEWRULE: u16 = 32; -pub const RTM_DELRULE: u16 = 33; -pub const RTM_GETRULE: u16 = 34; -pub const RTM_NEWQDISC: u16 = 36; -pub const RTM_DELQDISC: u16 = 37; -pub const RTM_GETQDISC: u16 = 38; -pub const RTM_NEWTCLASS: u16 = 40; -pub const RTM_DELTCLASS: u16 = 41; -pub const RTM_GETTCLASS: u16 = 42; -pub const RTM_NEWTFILTER: u16 = 44; -pub const RTM_DELTFILTER: u16 = 45; -pub const RTM_GETTFILTER: u16 = 46; -pub const RTM_NEWACTION: u16 = 48; -pub const RTM_DELACTION: u16 = 49; -pub const RTM_GETACTION: u16 = 50; -pub const RTM_NEWPREFIX: u16 = 52; -pub const RTM_GETMULTICAST: u16 = 58; -pub const RTM_GETANYCAST: u16 = 62; -pub const RTM_NEWNEIGHTBL: u16 = 64; -pub const RTM_GETNEIGHTBL: u16 = 66; -pub const RTM_SETNEIGHTBL: u16 = 67; -pub const RTM_NEWNDUSEROPT: u16 = 68; -pub const RTM_NEWADDRLABEL: u16 = 72; -pub const RTM_DELADDRLABEL: u16 = 73; -pub const RTM_GETADDRLABEL: u16 = 74; -pub const RTM_GETDCB: u16 = 78; -pub const RTM_SETDCB: u16 = 79; -pub const RTM_NEWNETCONF: u16 = 80; -pub const RTM_GETNETCONF: u16 = 82; -pub const RTM_NEWMDB: u16 = 84; -pub const RTM_DELMDB: u16 = 85; -pub const RTM_GETMDB: u16 = 86; -pub const RTM_NEWNSID: u16 = 88; -pub const RTM_DELNSID: u16 = 89; -pub const RTM_GETNSID: u16 = 90; - -pub const RTM_F_NOTIFY: ::c_uint = 0x100; -pub const RTM_F_CLONED: ::c_uint = 0x200; -pub const RTM_F_EQUALIZE: ::c_uint = 0x400; -pub const RTM_F_PREFIX: ::c_uint = 0x800; - -pub const RTA_UNSPEC: ::c_ushort = 0; -pub const RTA_DST: ::c_ushort = 1; -pub const RTA_SRC: ::c_ushort = 2; -pub const RTA_IIF: ::c_ushort = 3; -pub const RTA_OIF: ::c_ushort = 4; -pub const RTA_GATEWAY: ::c_ushort = 5; -pub const RTA_PRIORITY: ::c_ushort = 6; -pub const RTA_PREFSRC: ::c_ushort = 7; -pub const RTA_METRICS: ::c_ushort = 8; -pub const RTA_MULTIPATH: ::c_ushort = 9; -pub const RTA_PROTOINFO: ::c_ushort = 10; // No longer used -pub const RTA_FLOW: ::c_ushort = 11; -pub const RTA_CACHEINFO: ::c_ushort = 12; -pub const RTA_SESSION: ::c_ushort = 13; // No longer used -pub const RTA_MP_ALGO: ::c_ushort = 14; // No longer used -pub const RTA_TABLE: ::c_ushort = 15; -pub const RTA_MARK: ::c_ushort = 16; -pub const RTA_MFC_STATS: ::c_ushort = 17; - -pub const RTN_UNSPEC: ::c_uchar = 0; -pub const RTN_UNICAST: ::c_uchar = 1; -pub const RTN_LOCAL: ::c_uchar = 2; -pub const RTN_BROADCAST: ::c_uchar = 3; -pub const RTN_ANYCAST: ::c_uchar = 4; -pub const RTN_MULTICAST: ::c_uchar = 5; -pub const RTN_BLACKHOLE: ::c_uchar = 6; -pub const RTN_UNREACHABLE: ::c_uchar = 7; -pub const RTN_PROHIBIT: ::c_uchar = 8; -pub const RTN_THROW: ::c_uchar = 9; -pub const RTN_NAT: ::c_uchar = 10; -pub const RTN_XRESOLVE: ::c_uchar = 11; - -pub const RTPROT_UNSPEC: ::c_uchar = 0; -pub const RTPROT_REDIRECT: ::c_uchar = 1; -pub const RTPROT_KERNEL: ::c_uchar = 2; -pub const RTPROT_BOOT: ::c_uchar = 3; -pub const RTPROT_STATIC: ::c_uchar = 4; - -pub const RT_SCOPE_UNIVERSE: ::c_uchar = 0; -pub const RT_SCOPE_SITE: ::c_uchar = 200; -pub const RT_SCOPE_LINK: ::c_uchar = 253; -pub const RT_SCOPE_HOST: ::c_uchar = 254; -pub const RT_SCOPE_NOWHERE: ::c_uchar = 255; - -pub const RT_TABLE_UNSPEC: ::c_uchar = 0; -pub const RT_TABLE_COMPAT: ::c_uchar = 252; -pub const RT_TABLE_DEFAULT: ::c_uchar = 253; -pub const RT_TABLE_MAIN: ::c_uchar = 254; -pub const RT_TABLE_LOCAL: ::c_uchar = 255; - -pub const RTMSG_OVERRUN: u32 = ::NLMSG_OVERRUN as u32; -pub const RTMSG_NEWDEVICE: u32 = 0x11; -pub const RTMSG_DELDEVICE: u32 = 0x12; -pub const RTMSG_NEWROUTE: u32 = 0x21; -pub const RTMSG_DELROUTE: u32 = 0x22; -pub const RTMSG_NEWRULE: u32 = 0x31; -pub const RTMSG_DELRULE: u32 = 0x32; -pub const RTMSG_CONTROL: u32 = 0x40; -pub const RTMSG_AR_FAILED: u32 = 0x51; - -pub const MAX_ADDR_LEN: usize = 7; -pub const ARPD_UPDATE: ::c_ushort = 0x01; -pub const ARPD_LOOKUP: ::c_ushort = 0x02; -pub const ARPD_FLUSH: ::c_ushort = 0x03; -pub const ATF_MAGIC: ::c_int = 0x80; - -#[cfg(not(target_arch = "sparc64"))] -pub const SO_TIMESTAMPING: ::c_int = 37; -#[cfg(target_arch = "sparc64")] -pub const SO_TIMESTAMPING: ::c_int = 35; -pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING; - -// linux/module.h -pub const MODULE_INIT_IGNORE_MODVERSIONS: ::c_uint = 0x0001; -pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002; - -// linux/net_tstamp.h -pub const SOF_TIMESTAMPING_TX_HARDWARE: ::c_uint = 1 << 0; -pub const SOF_TIMESTAMPING_TX_SOFTWARE: ::c_uint = 1 << 1; -pub const SOF_TIMESTAMPING_RX_HARDWARE: ::c_uint = 1 << 2; -pub const SOF_TIMESTAMPING_RX_SOFTWARE: ::c_uint = 1 << 3; -pub const SOF_TIMESTAMPING_SOFTWARE: ::c_uint = 1 << 4; -pub const SOF_TIMESTAMPING_SYS_HARDWARE: ::c_uint = 1 << 5; -pub const SOF_TIMESTAMPING_RAW_HARDWARE: ::c_uint = 1 << 6; - -// linux/if_alg.h -pub const ALG_SET_KEY: ::c_int = 1; -pub const ALG_SET_IV: ::c_int = 2; -pub const ALG_SET_OP: ::c_int = 3; -pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4; -pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5; - -pub const ALG_OP_DECRYPT: ::c_int = 0; -pub const ALG_OP_ENCRYPT: ::c_int = 1; - -// uapi/linux/vm_sockets.h -pub const VMADDR_CID_ANY: ::c_uint = 0xFFFFFFFF; -pub const VMADDR_CID_HYPERVISOR: ::c_uint = 0; -pub const VMADDR_CID_RESERVED: ::c_uint = 1; -pub const VMADDR_CID_HOST: ::c_uint = 2; -pub const VMADDR_PORT_ANY: ::c_uint = 0xFFFFFFFF; - -// uapi/linux/inotify.h -pub const IN_ACCESS: u32 = 0x0000_0001; -pub const IN_MODIFY: u32 = 0x0000_0002; -pub const IN_ATTRIB: u32 = 0x0000_0004; -pub const IN_CLOSE_WRITE: u32 = 0x0000_0008; -pub const IN_CLOSE_NOWRITE: u32 = 0x0000_0010; -pub const IN_CLOSE: u32 = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE); -pub const IN_OPEN: u32 = 0x0000_0020; -pub const IN_MOVED_FROM: u32 = 0x0000_0040; -pub const IN_MOVED_TO: u32 = 0x0000_0080; -pub const IN_MOVE: u32 = (IN_MOVED_FROM | IN_MOVED_TO); -pub const IN_CREATE: u32 = 0x0000_0100; -pub const IN_DELETE: u32 = 0x0000_0200; -pub const IN_DELETE_SELF: u32 = 0x0000_0400; -pub const IN_MOVE_SELF: u32 = 0x0000_0800; -pub const IN_UNMOUNT: u32 = 0x0000_2000; -pub const IN_Q_OVERFLOW: u32 = 0x0000_4000; -pub const IN_IGNORED: u32 = 0x0000_8000; -pub const IN_ONLYDIR: u32 = 0x0100_0000; -pub const IN_DONT_FOLLOW: u32 = 0x0200_0000; -// pub const IN_EXCL_UNLINK: u32 = 0x0400_0000; - -// pub const IN_MASK_CREATE: u32 = 0x1000_0000; -// pub const IN_MASK_ADD: u32 = 0x2000_0000; -pub const IN_ISDIR: u32 = 0x4000_0000; -pub const IN_ONESHOT: u32 = 0x8000_0000; - -pub const IN_ALL_EVENTS: u32 = (IN_ACCESS - | IN_MODIFY - | IN_ATTRIB - | IN_CLOSE_WRITE - | IN_CLOSE_NOWRITE - | IN_OPEN - | IN_MOVED_FROM - | IN_MOVED_TO - | IN_DELETE - | IN_CREATE - | IN_DELETE_SELF - | IN_MOVE_SELF); - -pub const IN_CLOEXEC: ::c_int = O_CLOEXEC; -pub const IN_NONBLOCK: ::c_int = O_NONBLOCK; - -pub const FUTEX_WAIT: ::c_int = 0; -pub const FUTEX_WAKE: ::c_int = 1; -pub const FUTEX_FD: ::c_int = 2; -pub const FUTEX_REQUEUE: ::c_int = 3; -pub const FUTEX_CMP_REQUEUE: ::c_int = 4; -pub const FUTEX_WAKE_OP: ::c_int = 5; -pub const FUTEX_LOCK_PI: ::c_int = 6; -pub const FUTEX_UNLOCK_PI: ::c_int = 7; -pub const FUTEX_TRYLOCK_PI: ::c_int = 8; -pub const FUTEX_WAIT_BITSET: ::c_int = 9; -pub const FUTEX_WAKE_BITSET: ::c_int = 10; -pub const FUTEX_WAIT_REQUEUE_PI: ::c_int = 11; -pub const FUTEX_CMP_REQUEUE_PI: ::c_int = 12; - -pub const FUTEX_PRIVATE_FLAG: ::c_int = 128; -pub const FUTEX_CLOCK_REALTIME: ::c_int = 256; -pub const FUTEX_CMD_MASK: ::c_int = - !(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME); - -f! { - pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { - return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1) - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, - cmsg: *const cmsghdr) -> *mut cmsghdr { - if ((*cmsg).cmsg_len as usize) < ::mem::size_of::() { - return 0 as *mut cmsghdr; - }; - let next = (cmsg as usize + - super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) - as *mut cmsghdr; - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if (next.offset(1)) as usize > max || - next as usize + super::CMSG_ALIGN((*next).cmsg_len as usize) > max - { - 0 as *mut cmsghdr - } else { - next as *mut cmsghdr - } - } - - pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { - for slot in cpuset.bits.iter_mut() { - *slot = 0; - } - } - - pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits - = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] |= 1 << offset; - () - } - - pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits - = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] &= !(1 << offset); - () - } - - pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * ::mem::size_of_val(&cpuset.bits[0]); - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - 0 != (cpuset.bits[idx] & (1 << offset)) - } - - pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool { - set1.bits == set2.bits - } - - pub fn major(dev: ::dev_t) -> ::c_uint { - let mut major = 0; - major |= (dev & 0x00000000000fff00) >> 8; - major |= (dev & 0xfffff00000000000) >> 32; - major as ::c_uint - } - - pub fn minor(dev: ::dev_t) -> ::c_uint { - let mut minor = 0; - minor |= (dev & 0x00000000000000ff) >> 0; - minor |= (dev & 0x00000ffffff00000) >> 12; - minor as ::c_uint - } - - pub fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t { - let major = major as ::dev_t; - let minor = minor as ::dev_t; - let mut dev = 0; - dev |= (major & 0x00000fff) << 8; - dev |= (major & 0xfffff000) << 32; - dev |= (minor & 0x000000ff) << 0; - dev |= (minor & 0xffffff00) << 12; - dev - } - - pub fn IPTOS_TOS(tos: u8) -> u8 { - tos & IPTOS_TOS_MASK - } - - pub fn IPTOS_PREC(tos: u8) -> u8 { - tos & IPTOS_PREC_MASK - } - - pub fn RT_TOS(tos: u8) -> u8 { - tos & ::IPTOS_TOS_MASK - } - - pub fn RT_ADDRCLASS(flags: u32) -> u32 { - flags >> 23 - } - - pub fn RT_LOCALADDR(flags: u32) -> bool { - (flags & RTF_ADDRCLASSMASK) == (RTF_LOCAL | RTF_INTERFACE) - } -} - -extern "C" { - #[cfg_attr(not(target_env = "musl"), link_name = "__xpg_strerror_r")] - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; - pub fn rand() -> ::c_int; - pub fn srand(seed: ::c_uint); - - pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int; - pub fn aio_error(aiocbp: *const aiocb) -> ::c_int; - pub fn aio_return(aiocbp: *mut aiocb) -> ::ssize_t; - pub fn aio_suspend( - aiocb_list: *const *const aiocb, - nitems: ::c_int, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn aio_cancel(fd: ::c_int, aiocbp: *mut aiocb) -> ::c_int; - pub fn lio_listio( - mode: ::c_int, - aiocb_list: *const *mut aiocb, - nitems: ::c_int, - sevp: *mut ::sigevent, - ) -> ::c_int; - - pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; - - pub fn setpwent(); - pub fn endpwent(); - pub fn getpwent() -> *mut passwd; - pub fn setgrent(); - pub fn endgrent(); - pub fn getgrent() -> *mut ::group; - pub fn setspent(); - pub fn endspent(); - pub fn getspent() -> *mut spwd; - - pub fn getspnam(__name: *const ::c_char) -> *mut spwd; - - pub fn shm_open( - name: *const c_char, - oflag: ::c_int, - mode: mode_t, - ) -> ::c_int; - - // System V IPC - pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int; - pub fn shmat( - shmid: ::c_int, - shmaddr: *const ::c_void, - shmflg: ::c_int, - ) -> *mut ::c_void; - pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int; - pub fn shmctl( - shmid: ::c_int, - cmd: ::c_int, - buf: *mut ::shmid_ds, - ) -> ::c_int; - pub fn ftok(pathname: *const ::c_char, proj_id: ::c_int) -> ::key_t; - pub fn semget(key: ::key_t, nsems: ::c_int, semflag: ::c_int) -> ::c_int; - pub fn semop( - semid: ::c_int, - sops: *mut ::sembuf, - nsops: ::size_t, - ) -> ::c_int; - pub fn semctl( - semid: ::c_int, - semnum: ::c_int, - cmd: ::c_int, - ... - ) -> ::c_int; - pub fn msgctl(msqid: ::c_int, cmd: ::c_int, buf: *mut msqid_ds) - -> ::c_int; - pub fn msgget(key: ::key_t, msgflg: ::c_int) -> ::c_int; - pub fn msgrcv( - msqid: ::c_int, - msgp: *mut ::c_void, - msgsz: ::size_t, - msgtyp: ::c_long, - msgflg: ::c_int, - ) -> ::ssize_t; - pub fn msgsnd( - msqid: ::c_int, - msgp: *const ::c_void, - msgsz: ::size_t, - msgflg: ::c_int, - ) -> ::c_int; - - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn __errno_location() -> *mut ::c_int; - - pub fn fopen64( - filename: *const c_char, - mode: *const c_char, - ) -> *mut ::FILE; - pub fn freopen64( - filename: *const c_char, - mode: *const c_char, - file: *mut ::FILE, - ) -> *mut ::FILE; - pub fn tmpfile64() -> *mut ::FILE; - pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int; - pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int; - pub fn fseeko64( - stream: *mut ::FILE, - offset: ::off64_t, - whence: ::c_int, - ) -> ::c_int; - pub fn ftello64(stream: *mut ::FILE) -> ::off64_t; - pub fn fallocate( - fd: ::c_int, - mode: ::c_int, - offset: ::off_t, - len: ::off_t, - ) -> ::c_int; - pub fn fallocate64( - fd: ::c_int, - mode: ::c_int, - offset: ::off64_t, - len: ::off64_t, - ) -> ::c_int; - pub fn posix_fallocate( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - ) -> ::c_int; - pub fn posix_fallocate64( - fd: ::c_int, - offset: ::off64_t, - len: ::off64_t, - ) -> ::c_int; - pub fn readahead( - fd: ::c_int, - offset: ::off64_t, - count: ::size_t, - ) -> ::ssize_t; - pub fn getxattr( - path: *const c_char, - name: *const c_char, - value: *mut ::c_void, - size: ::size_t, - ) -> ::ssize_t; - pub fn lgetxattr( - path: *const c_char, - name: *const c_char, - value: *mut ::c_void, - size: ::size_t, - ) -> ::ssize_t; - pub fn fgetxattr( - filedes: ::c_int, - name: *const c_char, - value: *mut ::c_void, - size: ::size_t, - ) -> ::ssize_t; - pub fn setxattr( - path: *const c_char, - name: *const c_char, - value: *const ::c_void, - size: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn lsetxattr( - path: *const c_char, - name: *const c_char, - value: *const ::c_void, - size: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn fsetxattr( - filedes: ::c_int, - name: *const c_char, - value: *const ::c_void, - size: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn listxattr( - path: *const c_char, - list: *mut c_char, - size: ::size_t, - ) -> ::ssize_t; - pub fn llistxattr( - path: *const c_char, - list: *mut c_char, - size: ::size_t, - ) -> ::ssize_t; - pub fn flistxattr( - filedes: ::c_int, - list: *mut c_char, - size: ::size_t, - ) -> ::ssize_t; - pub fn removexattr(path: *const c_char, name: *const c_char) -> ::c_int; - pub fn lremovexattr(path: *const c_char, name: *const c_char) -> ::c_int; - pub fn fremovexattr(filedes: ::c_int, name: *const c_char) -> ::c_int; - pub fn signalfd( - fd: ::c_int, - mask: *const ::sigset_t, - flags: ::c_int, - ) -> ::c_int; - pub fn timerfd_create(clockid: ::c_int, flags: ::c_int) -> ::c_int; - pub fn timerfd_gettime( - fd: ::c_int, - curr_value: *mut itimerspec, - ) -> ::c_int; - pub fn timerfd_settime( - fd: ::c_int, - flags: ::c_int, - new_value: *const itimerspec, - old_value: *mut itimerspec, - ) -> ::c_int; - pub fn pwritev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn preadv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn quotactl( - cmd: ::c_int, - special: *const ::c_char, - id: ::c_int, - data: *mut ::c_char, - ) -> ::c_int; - pub fn mq_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::mqd_t; - pub fn mq_close(mqd: ::mqd_t) -> ::c_int; - pub fn mq_unlink(name: *const ::c_char) -> ::c_int; - pub fn mq_receive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - ) -> ::ssize_t; - pub fn mq_timedreceive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - abs_timeout: *const ::timespec, - ) -> ::ssize_t; - pub fn mq_send( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - ) -> ::c_int; - pub fn mq_timedsend( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - abs_timeout: *const ::timespec, - ) -> ::c_int; - pub fn mq_getattr(mqd: ::mqd_t, attr: *mut ::mq_attr) -> ::c_int; - pub fn mq_setattr( - mqd: ::mqd_t, - newattr: *const ::mq_attr, - oldattr: *mut ::mq_attr, - ) -> ::c_int; - pub fn epoll_pwait( - epfd: ::c_int, - events: *mut ::epoll_event, - maxevents: ::c_int, - timeout: ::c_int, - sigmask: *const ::sigset_t, - ) -> ::c_int; - pub fn dup3(oldfd: ::c_int, newfd: ::c_int, flags: ::c_int) -> ::c_int; - pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int; - pub fn mkostemps( - template: *mut ::c_char, - suffixlen: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn sigtimedwait( - set: *const sigset_t, - info: *mut siginfo_t, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> ::c_int; - pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) - -> *mut ::c_char; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::socklen_t, - serv: *mut ::c_char, - sevlen: ::socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn pthread_setschedprio( - native: ::pthread_t, - priority: ::c_int, - ) -> ::c_int; - pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int; - pub fn process_vm_readv( - pid: ::pid_t, - local_iov: *const ::iovec, - liovcnt: ::c_ulong, - remote_iov: *const ::iovec, - riovcnt: ::c_ulong, - flags: ::c_ulong, - ) -> isize; - pub fn process_vm_writev( - pid: ::pid_t, - local_iov: *const ::iovec, - liovcnt: ::c_ulong, - remote_iov: *const ::iovec, - riovcnt: ::c_ulong, - flags: ::c_ulong, - ) -> isize; - pub fn reboot(how_to: ::c_int) -> ::c_int; - pub fn setfsgid(gid: ::gid_t) -> ::c_int; - pub fn setfsuid(uid: ::uid_t) -> ::c_int; - - // Not available now on Android - pub fn mkfifoat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - pub fn if_nameindex() -> *mut if_nameindex; - pub fn if_freenameindex(ptr: *mut if_nameindex); - pub fn sync_file_range( - fd: ::c_int, - offset: ::off64_t, - nbytes: ::off64_t, - flags: ::c_uint, - ) -> ::c_int; - pub fn mremap( - addr: *mut ::c_void, - len: ::size_t, - new_len: ::size_t, - flags: ::c_int, - ... - ) -> *mut ::c_void; - - pub fn glob( - pattern: *const c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut ::glob_t, - ) -> ::c_int; - pub fn globfree(pglob: *mut ::glob_t); - - pub fn posix_madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn shm_unlink(name: *const ::c_char) -> ::c_int; - - pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); - - pub fn telldir(dirp: *mut ::DIR) -> ::c_long; - pub fn madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn msync( - addr: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn remap_file_pages( - addr: *mut ::c_void, - size: ::size_t, - prot: ::c_int, - pgoff: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; - pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int; - pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; - - pub fn getdomainname(name: *mut ::c_char, len: ::size_t) -> ::c_int; - pub fn setdomainname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn vhangup() -> ::c_int; - pub fn sync(); - pub fn syscall(num: ::c_long, ...) -> ::c_long; - pub fn sched_getaffinity( - pid: ::pid_t, - cpusetsize: ::size_t, - cpuset: *mut cpu_set_t, - ) -> ::c_int; - pub fn sched_setaffinity( - pid: ::pid_t, - cpusetsize: ::size_t, - cpuset: *const cpu_set_t, - ) -> ::c_int; - pub fn epoll_create(size: ::c_int) -> ::c_int; - pub fn epoll_create1(flags: ::c_int) -> ::c_int; - pub fn epoll_wait( - epfd: ::c_int, - events: *mut ::epoll_event, - maxevents: ::c_int, - timeout: ::c_int, - ) -> ::c_int; - pub fn epoll_ctl( - epfd: ::c_int, - op: ::c_int, - fd: ::c_int, - event: *mut ::epoll_event, - ) -> ::c_int; - pub fn pthread_getschedparam( - native: ::pthread_t, - policy: *mut ::c_int, - param: *mut ::sched_param, - ) -> ::c_int; - pub fn unshare(flags: ::c_int) -> ::c_int; - pub fn umount(target: *const ::c_char) -> ::c_int; - pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int; - pub fn tee( - fd_in: ::c_int, - fd_out: ::c_int, - len: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn settimeofday( - tv: *const ::timeval, - tz: *const ::timezone, - ) -> ::c_int; - pub fn splice( - fd_in: ::c_int, - off_in: *mut ::loff_t, - fd_out: ::c_int, - off_out: *mut ::loff_t, - len: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int; - pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) - -> ::c_int; - pub fn sem_timedwait( - sem: *mut sem_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; - pub fn sched_setparam( - pid: ::pid_t, - param: *const ::sched_param, - ) -> ::c_int; - pub fn setns(fd: ::c_int, nstype: ::c_int) -> ::c_int; - pub fn swapoff(puath: *const ::c_char) -> ::c_int; - pub fn vmsplice( - fd: ::c_int, - iov: *const ::iovec, - nr_segs: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn mount( - src: *const ::c_char, - target: *const ::c_char, - fstype: *const ::c_char, - flags: ::c_ulong, - data: *const ::c_void, - ) -> ::c_int; - pub fn personality(persona: ::c_ulong) -> ::c_int; - pub fn prctl(option: ::c_int, ...) -> ::c_int; - pub fn sched_getparam(pid: ::pid_t, param: *mut ::sched_param) -> ::c_int; - pub fn ppoll( - fds: *mut ::pollfd, - nfds: nfds_t, - timeout: *const ::timespec, - sigmask: *const sigset_t, - ) -> ::c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn clone( - cb: extern "C" fn(*mut ::c_void) -> ::c_int, - child_stack: *mut ::c_void, - flags: ::c_int, - arg: *mut ::c_void, - ... - ) -> ::c_int; - pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int; - pub fn clock_nanosleep( - clk_id: ::clockid_t, - flags: ::c_int, - rqtp: *const ::timespec, - rmtp: *mut ::timespec, - ) -> ::c_int; - pub fn pthread_attr_getguardsize( - attr: *const ::pthread_attr_t, - guardsize: *mut ::size_t, - ) -> ::c_int; - pub fn sethostname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn sched_get_priority_min(policy: ::c_int) -> ::c_int; - pub fn pthread_condattr_getpshared( - attr: *const pthread_condattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - pub fn sysinfo(info: *mut ::sysinfo) -> ::c_int; - pub fn umount2(target: *const ::c_char, flags: ::c_int) -> ::c_int; - pub fn pthread_setschedparam( - native: ::pthread_t, - policy: ::c_int, - param: *const ::sched_param, - ) -> ::c_int; - pub fn swapon(path: *const ::c_char, swapflags: ::c_int) -> ::c_int; - pub fn sched_setscheduler( - pid: ::pid_t, - policy: ::c_int, - param: *const ::sched_param, - ) -> ::c_int; - pub fn sendfile( - out_fd: ::c_int, - in_fd: ::c_int, - offset: *mut off_t, - count: ::size_t, - ) -> ::ssize_t; - pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r( - gid: ::gid_t, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigaltstack$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] - pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; - pub fn sem_close(sem: *mut sem_t) -> ::c_int; - pub fn getdtablesize() -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")] - pub fn getgrnam_r( - name: *const ::c_char, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - pub fn initgroups(user: *const ::c_char, group: ::gid_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_sigmask$UNIX2003" - )] - pub fn pthread_sigmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; - pub fn getgrnam(name: *const ::c_char) -> *mut ::group; - pub fn pthread_cancel(thread: ::pthread_t) -> ::c_int; - pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; - pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")] - pub fn getpwnam_r( - name: *const ::c_char, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")] - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigwait$UNIX2003" - )] - #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] - pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn getgrgid(gid: ::gid_t) -> *mut ::group; - pub fn getgrouplist( - user: *const ::c_char, - group: ::gid_t, - groups: *mut ::gid_t, - ngroups: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_mutexattr_getpshared( - attr: *const pthread_mutexattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "popen$UNIX2003" - )] - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - pub fn faccessat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn pthread_create( - native: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - pub fn dl_iterate_phdr( - callback: ::Option< - unsafe extern "C" fn( - info: *mut ::dl_phdr_info, - size: ::size_t, - data: *mut ::c_void, - ) -> ::c_int, - >, - data: *mut ::c_void, - ) -> ::c_int; - - pub fn setmntent( - filename: *const ::c_char, - ty: *const ::c_char, - ) -> *mut ::FILE; - pub fn getmntent(stream: *mut ::FILE) -> *mut ::mntent; - pub fn addmntent(stream: *mut ::FILE, mnt: *const ::mntent) -> ::c_int; - pub fn endmntent(streamp: *mut ::FILE) -> ::c_int; - pub fn hasmntopt( - mnt: *const ::mntent, - opt: *const ::c_char, - ) -> *mut ::c_char; - - pub fn posix_spawn( - pid: *mut ::pid_t, - path: *const ::c_char, - file_actions: *const ::posix_spawn_file_actions_t, - attrp: *const ::posix_spawnattr_t, - argv: *const *mut ::c_char, - envp: *const *mut ::c_char, - ) -> ::c_int; - pub fn posix_spawnp( - pid: *mut ::pid_t, - file: *const ::c_char, - file_actions: *const ::posix_spawn_file_actions_t, - attrp: *const ::posix_spawnattr_t, - argv: *const *mut ::c_char, - envp: *const *mut ::c_char, - ) -> ::c_int; - pub fn posix_spawnattr_init(attr: *mut posix_spawnattr_t) -> ::c_int; - pub fn posix_spawnattr_destroy(attr: *mut posix_spawnattr_t) -> ::c_int; - pub fn posix_spawnattr_getsigdefault( - attr: *const posix_spawnattr_t, - default: *mut ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_setsigdefault( - attr: *mut posix_spawnattr_t, - default: *const ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_getsigmask( - attr: *const posix_spawnattr_t, - default: *mut ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_setsigmask( - attr: *mut posix_spawnattr_t, - default: *const ::sigset_t, - ) -> ::c_int; - pub fn posix_spawnattr_getflags( - attr: *const posix_spawnattr_t, - flags: *mut ::c_short, - ) -> ::c_int; - pub fn posix_spawnattr_setflags( - attr: *mut posix_spawnattr_t, - flags: ::c_short, - ) -> ::c_int; - pub fn posix_spawnattr_getpgroup( - attr: *const posix_spawnattr_t, - flags: *mut ::pid_t, - ) -> ::c_int; - pub fn posix_spawnattr_setpgroup( - attr: *mut posix_spawnattr_t, - flags: ::pid_t, - ) -> ::c_int; - pub fn posix_spawnattr_getschedpolicy( - attr: *const posix_spawnattr_t, - flags: *mut ::c_int, - ) -> ::c_int; - pub fn posix_spawnattr_setschedpolicy( - attr: *mut posix_spawnattr_t, - flags: ::c_int, - ) -> ::c_int; - pub fn posix_spawnattr_getschedparam( - attr: *const posix_spawnattr_t, - param: *mut ::sched_param, - ) -> ::c_int; - pub fn posix_spawnattr_setschedparam( - attr: *mut posix_spawnattr_t, - param: *const ::sched_param, - ) -> ::c_int; - - pub fn posix_spawn_file_actions_init( - actions: *mut posix_spawn_file_actions_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_destroy( - actions: *mut posix_spawn_file_actions_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_addopen( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - path: *const ::c_char, - oflag: ::c_int, - mode: ::mode_t, - ) -> ::c_int; - pub fn posix_spawn_file_actions_addclose( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - ) -> ::c_int; - pub fn posix_spawn_file_actions_adddup2( - actions: *mut posix_spawn_file_actions_t, - fd: ::c_int, - newfd: ::c_int, - ) -> ::c_int; - pub fn fread_unlocked( - ptr: *mut ::c_void, - size: ::size_t, - nobj: ::size_t, - stream: *mut ::FILE, - ) -> ::size_t; - pub fn inotify_rm_watch(fd: ::c_int, wd: ::c_int) -> ::c_int; - pub fn inotify_init() -> ::c_int; - pub fn inotify_init1(flags: ::c_int) -> ::c_int; - pub fn inotify_add_watch( - fd: ::c_int, - path: *const ::c_char, - mask: u32, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_env = "musl")] { - mod musl; - pub use self::musl::*; - } else if #[cfg(target_env = "gnu")] { - mod gnu; - pub use self::gnu::*; - } -} - -cfg_if! { - if #[cfg(libc_align)] { - #[macro_use] - mod align; - } else { - #[macro_use] - mod no_align; - } -} -expand_align!(); diff --git a/libc/src/unix/linux_like/linux/musl/b32/arm/align.rs b/libc/src/unix/linux_like/linux/musl/b32/arm/align.rs deleted file mode 100644 index aedbf7a..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/arm/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(8))] - pub struct max_align_t { - priv_: (i64, i64) - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b32/arm/mod.rs b/libc/src/unix/linux_like/linux/musl/b32/arm/mod.rs deleted file mode 100644 index ff23688..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/arm/mod.rs +++ /dev/null @@ -1,845 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - __st_dev_padding: ::c_int, - __st_ino_truncated: ::c_long, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_int, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino_t, - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __st_dev_padding: ::c_int, - __st_ino_truncated: ::c_long, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_int, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino_t, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __unused1: ::c_long, - __unused2: ::c_long - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - __unused1: ::c_int, - pub shm_dtime: ::time_t, - __unused2: ::c_int, - pub shm_ctime: ::time_t, - __unused3: ::c_int, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - __unused1: ::c_int, - pub msg_rtime: ::time_t, - __unused2: ::c_int, - pub msg_ctime: ::time_t, - __unused3: ::c_int, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } -} - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; - -pub const O_DIRECT: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_LARGEFILE: ::c_int = 0o400000; - -pub const FIOCLEX: ::c_int = 0x5451; -pub const FIONCLEX: ::c_int = 0x5450; -pub const FIONBIO: ::c_int = 0x5421; - -pub const RLIMIT_RSS: ::c_int = 5; -pub const RLIMIT_NOFILE: ::c_int = 7; -pub const RLIMIT_AS: ::c_int = 9; -pub const RLIMIT_NPROC: ::c_int = 6; -pub const RLIMIT_MEMLOCK: ::c_int = 8; -pub const RLIMIT_NLIMITS: ::c_int = 15; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::c_int = 0x00000800; -pub const TAB2: ::c_int = 0x00001000; -pub const TAB3: ::c_int = 0x00001800; -pub const CR1: ::c_int = 0x00000200; -pub const CR2: ::c_int = 0x00000400; -pub const CR3: ::c_int = 0x00000600; -pub const FF1: ::c_int = 0x00008000; -pub const BS1: ::c_int = 0x00002000; -pub const VT1: ::c_int = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; - -pub const SOCK_NONBLOCK: ::c_int = 2048; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_SEQPACKET: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EDEADLOCK: ::c_int = EDEADLK; -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const EXTPROC: ::tcflag_t = 0x00010000; - -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const F_GETLK: ::c_int = 12; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETLK: ::c_int = 13; -pub const F_SETLKW: ::c_int = 14; -pub const F_SETOWN: ::c_int = 8; - -pub const VEOF: usize = 4; -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; - -pub const TCGETS: ::c_int = 0x5401; -pub const TCSETS: ::c_int = 0x5402; -pub const TCSETSW: ::c_int = 0x5403; -pub const TCSETSF: ::c_int = 0x5404; -pub const TCGETA: ::c_int = 0x5405; -pub const TCSETA: ::c_int = 0x5406; -pub const TCSETAW: ::c_int = 0x5407; -pub const TCSETAF: ::c_int = 0x5408; -pub const TCSBRK: ::c_int = 0x5409; -pub const TCXONC: ::c_int = 0x540A; -pub const TCFLSH: ::c_int = 0x540B; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x540F; -pub const TIOCSPGRP: ::c_int = 0x5410; -pub const TIOCOUTQ: ::c_int = 0x5411; -pub const TIOCSTI: ::c_int = 0x5412; -pub const TIOCGWINSZ: ::c_int = 0x5413; -pub const TIOCSWINSZ: ::c_int = 0x5414; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x541B; -pub const TIOCCONS: ::c_int = 0x541D; - -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -// Syscall table -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_pause: ::c_long = 29; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_poll: ::c_long = 168; -pub const SYS_nfsservctl: ::c_long = 169; -pub const SYS_setresgid: ::c_long = 170; -pub const SYS_getresgid: ::c_long = 171; -pub const SYS_prctl: ::c_long = 172; -pub const SYS_rt_sigreturn: ::c_long = 173; -pub const SYS_rt_sigaction: ::c_long = 174; -pub const SYS_rt_sigprocmask: ::c_long = 175; -pub const SYS_rt_sigpending: ::c_long = 176; -pub const SYS_rt_sigtimedwait: ::c_long = 177; -pub const SYS_rt_sigqueueinfo: ::c_long = 178; -pub const SYS_rt_sigsuspend: ::c_long = 179; -pub const SYS_pread64: ::c_long = 180; -pub const SYS_pwrite64: ::c_long = 181; -pub const SYS_chown: ::c_long = 182; -pub const SYS_getcwd: ::c_long = 183; -pub const SYS_capget: ::c_long = 184; -pub const SYS_capset: ::c_long = 185; -pub const SYS_sigaltstack: ::c_long = 186; -pub const SYS_sendfile: ::c_long = 187; -pub const SYS_vfork: ::c_long = 190; -pub const SYS_ugetrlimit: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_lchown32: ::c_long = 198; -pub const SYS_getuid32: ::c_long = 199; -pub const SYS_getgid32: ::c_long = 200; -pub const SYS_geteuid32: ::c_long = 201; -pub const SYS_getegid32: ::c_long = 202; -pub const SYS_setreuid32: ::c_long = 203; -pub const SYS_setregid32: ::c_long = 204; -pub const SYS_getgroups32: ::c_long = 205; -pub const SYS_setgroups32: ::c_long = 206; -pub const SYS_fchown32: ::c_long = 207; -pub const SYS_setresuid32: ::c_long = 208; -pub const SYS_getresuid32: ::c_long = 209; -pub const SYS_setresgid32: ::c_long = 210; -pub const SYS_getresgid32: ::c_long = 211; -pub const SYS_chown32: ::c_long = 212; -pub const SYS_setuid32: ::c_long = 213; -pub const SYS_setgid32: ::c_long = 214; -pub const SYS_setfsuid32: ::c_long = 215; -pub const SYS_setfsgid32: ::c_long = 216; -pub const SYS_getdents64: ::c_long = 217; -pub const SYS_pivot_root: ::c_long = 218; -pub const SYS_mincore: ::c_long = 219; -pub const SYS_madvise: ::c_long = 220; -pub const SYS_fcntl64: ::c_long = 221; -pub const SYS_gettid: ::c_long = 224; -pub const SYS_readahead: ::c_long = 225; -pub const SYS_setxattr: ::c_long = 226; -pub const SYS_lsetxattr: ::c_long = 227; -pub const SYS_fsetxattr: ::c_long = 228; -pub const SYS_getxattr: ::c_long = 229; -pub const SYS_lgetxattr: ::c_long = 230; -pub const SYS_fgetxattr: ::c_long = 231; -pub const SYS_listxattr: ::c_long = 232; -pub const SYS_llistxattr: ::c_long = 233; -pub const SYS_flistxattr: ::c_long = 234; -pub const SYS_removexattr: ::c_long = 235; -pub const SYS_lremovexattr: ::c_long = 236; -pub const SYS_fremovexattr: ::c_long = 237; -pub const SYS_tkill: ::c_long = 238; -pub const SYS_sendfile64: ::c_long = 239; -pub const SYS_futex: ::c_long = 240; -pub const SYS_sched_setaffinity: ::c_long = 241; -pub const SYS_sched_getaffinity: ::c_long = 242; -pub const SYS_io_setup: ::c_long = 243; -pub const SYS_io_destroy: ::c_long = 244; -pub const SYS_io_getevents: ::c_long = 245; -pub const SYS_io_submit: ::c_long = 246; -pub const SYS_io_cancel: ::c_long = 247; -pub const SYS_exit_group: ::c_long = 248; -pub const SYS_lookup_dcookie: ::c_long = 249; -pub const SYS_epoll_create: ::c_long = 250; -pub const SYS_epoll_ctl: ::c_long = 251; -pub const SYS_epoll_wait: ::c_long = 252; -pub const SYS_remap_file_pages: ::c_long = 253; -pub const SYS_set_tid_address: ::c_long = 256; -pub const SYS_timer_create: ::c_long = 257; -pub const SYS_timer_settime: ::c_long = 258; -pub const SYS_timer_gettime: ::c_long = 259; -pub const SYS_timer_getoverrun: ::c_long = 260; -pub const SYS_timer_delete: ::c_long = 261; -pub const SYS_clock_settime: ::c_long = 262; -pub const SYS_clock_gettime: ::c_long = 263; -pub const SYS_clock_getres: ::c_long = 264; -pub const SYS_clock_nanosleep: ::c_long = 265; -pub const SYS_statfs64: ::c_long = 266; -pub const SYS_fstatfs64: ::c_long = 267; -pub const SYS_tgkill: ::c_long = 268; -pub const SYS_utimes: ::c_long = 269; -pub const SYS_pciconfig_iobase: ::c_long = 271; -pub const SYS_pciconfig_read: ::c_long = 272; -pub const SYS_pciconfig_write: ::c_long = 273; -pub const SYS_mq_open: ::c_long = 274; -pub const SYS_mq_unlink: ::c_long = 275; -pub const SYS_mq_timedsend: ::c_long = 276; -pub const SYS_mq_timedreceive: ::c_long = 277; -pub const SYS_mq_notify: ::c_long = 278; -pub const SYS_mq_getsetattr: ::c_long = 279; -pub const SYS_waitid: ::c_long = 280; -pub const SYS_socket: ::c_long = 281; -pub const SYS_bind: ::c_long = 282; -pub const SYS_connect: ::c_long = 283; -pub const SYS_listen: ::c_long = 284; -pub const SYS_accept: ::c_long = 285; -pub const SYS_getsockname: ::c_long = 286; -pub const SYS_getpeername: ::c_long = 287; -pub const SYS_socketpair: ::c_long = 288; -pub const SYS_send: ::c_long = 289; -pub const SYS_sendto: ::c_long = 290; -pub const SYS_recv: ::c_long = 291; -pub const SYS_recvfrom: ::c_long = 292; -pub const SYS_shutdown: ::c_long = 293; -pub const SYS_setsockopt: ::c_long = 294; -pub const SYS_getsockopt: ::c_long = 295; -pub const SYS_sendmsg: ::c_long = 296; -pub const SYS_recvmsg: ::c_long = 297; -pub const SYS_semop: ::c_long = 298; -pub const SYS_semget: ::c_long = 299; -pub const SYS_semctl: ::c_long = 300; -pub const SYS_msgsnd: ::c_long = 301; -pub const SYS_msgrcv: ::c_long = 302; -pub const SYS_msgget: ::c_long = 303; -pub const SYS_msgctl: ::c_long = 304; -pub const SYS_shmat: ::c_long = 305; -pub const SYS_shmdt: ::c_long = 306; -pub const SYS_shmget: ::c_long = 307; -pub const SYS_shmctl: ::c_long = 308; -pub const SYS_add_key: ::c_long = 309; -pub const SYS_request_key: ::c_long = 310; -pub const SYS_keyctl: ::c_long = 311; -pub const SYS_semtimedop: ::c_long = 312; -pub const SYS_vserver: ::c_long = 313; -pub const SYS_ioprio_set: ::c_long = 314; -pub const SYS_ioprio_get: ::c_long = 315; -pub const SYS_inotify_init: ::c_long = 316; -pub const SYS_inotify_add_watch: ::c_long = 317; -pub const SYS_inotify_rm_watch: ::c_long = 318; -pub const SYS_mbind: ::c_long = 319; -pub const SYS_get_mempolicy: ::c_long = 320; -pub const SYS_set_mempolicy: ::c_long = 321; -pub const SYS_openat: ::c_long = 322; -pub const SYS_mkdirat: ::c_long = 323; -pub const SYS_mknodat: ::c_long = 324; -pub const SYS_fchownat: ::c_long = 325; -pub const SYS_futimesat: ::c_long = 326; -pub const SYS_fstatat64: ::c_long = 327; -pub const SYS_unlinkat: ::c_long = 328; -pub const SYS_renameat: ::c_long = 329; -pub const SYS_linkat: ::c_long = 330; -pub const SYS_symlinkat: ::c_long = 331; -pub const SYS_readlinkat: ::c_long = 332; -pub const SYS_fchmodat: ::c_long = 333; -pub const SYS_faccessat: ::c_long = 334; -pub const SYS_pselect6: ::c_long = 335; -pub const SYS_ppoll: ::c_long = 336; -pub const SYS_unshare: ::c_long = 337; -pub const SYS_set_robust_list: ::c_long = 338; -pub const SYS_get_robust_list: ::c_long = 339; -pub const SYS_splice: ::c_long = 340; -pub const SYS_tee: ::c_long = 342; -pub const SYS_vmsplice: ::c_long = 343; -pub const SYS_move_pages: ::c_long = 344; -pub const SYS_getcpu: ::c_long = 345; -pub const SYS_epoll_pwait: ::c_long = 346; -pub const SYS_kexec_load: ::c_long = 347; -pub const SYS_utimensat: ::c_long = 348; -pub const SYS_signalfd: ::c_long = 349; -pub const SYS_timerfd_create: ::c_long = 350; -pub const SYS_eventfd: ::c_long = 351; -pub const SYS_fallocate: ::c_long = 352; -pub const SYS_timerfd_settime: ::c_long = 353; -pub const SYS_timerfd_gettime: ::c_long = 354; -pub const SYS_signalfd4: ::c_long = 355; -pub const SYS_eventfd2: ::c_long = 356; -pub const SYS_epoll_create1: ::c_long = 357; -pub const SYS_dup3: ::c_long = 358; -pub const SYS_pipe2: ::c_long = 359; -pub const SYS_inotify_init1: ::c_long = 360; -pub const SYS_preadv: ::c_long = 361; -pub const SYS_pwritev: ::c_long = 362; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 363; -pub const SYS_perf_event_open: ::c_long = 364; -pub const SYS_recvmmsg: ::c_long = 365; -pub const SYS_accept4: ::c_long = 366; -pub const SYS_fanotify_init: ::c_long = 367; -pub const SYS_fanotify_mark: ::c_long = 368; -pub const SYS_prlimit64: ::c_long = 369; -pub const SYS_name_to_handle_at: ::c_long = 370; -pub const SYS_open_by_handle_at: ::c_long = 371; -pub const SYS_clock_adjtime: ::c_long = 372; -pub const SYS_syncfs: ::c_long = 373; -pub const SYS_sendmmsg: ::c_long = 374; -pub const SYS_setns: ::c_long = 375; -pub const SYS_process_vm_readv: ::c_long = 376; -pub const SYS_process_vm_writev: ::c_long = 377; -pub const SYS_kcmp: ::c_long = 378; -pub const SYS_finit_module: ::c_long = 379; -pub const SYS_sched_setattr: ::c_long = 380; -pub const SYS_sched_getattr: ::c_long = 381; -pub const SYS_renameat2: ::c_long = 382; -pub const SYS_seccomp: ::c_long = 383; -pub const SYS_getrandom: ::c_long = 384; -pub const SYS_memfd_create: ::c_long = 385; -pub const SYS_bpf: ::c_long = 386; -pub const SYS_execveat: ::c_long = 387; -pub const SYS_userfaultfd: ::c_long = 388; -pub const SYS_membarrier: ::c_long = 389; -pub const SYS_mlock2: ::c_long = 390; -pub const SYS_copy_file_range: ::c_long = 391; -pub const SYS_preadv2: ::c_long = 392; -pub const SYS_pwritev2: ::c_long = 393; -pub const SYS_pkey_mprotect: ::c_long = 394; -pub const SYS_pkey_alloc: ::c_long = 395; -pub const SYS_pkey_free: ::c_long = 396; -pub const SYS_statx: ::c_long = 397; - -extern "C" { - pub fn getrandom( - buf: *mut ::c_void, - buflen: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b32/hexagon.rs b/libc/src/unix/linux_like/linux/musl/b32/hexagon.rs deleted file mode 100644 index 2340695..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/hexagon.rs +++ /dev/null @@ -1,797 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; -pub type stat64 = ::stat; - -s! { - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::c_ulonglong, - pub st_mode: ::c_uint, - pub st_nlink: ::c_uint, - pub st_uid: ::c_uint, - pub st_gid: ::c_uint, - pub st_rdev: ::c_ulonglong, - __st_rdev_padding: ::c_ulong, - pub st_size: ::c_longlong, - pub st_blksize: ::blksize_t, - __st_blksize_padding: ::c_int, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - - __unused: [::c_int;2], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_ushort, - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - __unused1: ::c_int, - pub shm_dtime: ::time_t, - __unused2: ::c_int, - pub shm_ctime: ::time_t, - __unused3: ::c_int, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - __unused1: ::c_int, - pub msg_rtime: ::time_t, - __unused2: ::c_int, - pub msg_ctime: ::time_t, - __unused3: ::c_int, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct termios2 { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; 19], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } -} - -pub const AF_FILE: ::c_int = 1; -pub const AF_KCM: ::c_int = 41; -pub const AF_MAX: ::c_int = 43; -pub const AF_QIPCRTR: ::c_int = 42; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EALREADY: ::c_int = 114; -pub const EBADE: ::c_int = 52; -pub const EBADMSG: ::c_int = 74; -pub const EBADR: ::c_int = 53; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const ECANCELED: ::c_int = 125; -pub const ECHRNG: ::c_int = 44; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNREFUSED: ::c_int = 111; -pub const ECONNRESET: ::c_int = 104; -pub const EDEADLK: ::c_int = 35; -pub const EDEADLOCK: ::c_int = 35; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EDQUOT: ::c_int = 122; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EHWPOISON: ::c_int = 133; -pub const EIDRM: ::c_int = 43; -pub const EILSEQ: ::c_int = 84; -pub const EINPROGRESS: ::c_int = 115; -pub const EISCONN: ::c_int = 106; -pub const EISNAM: ::c_int = 120; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREJECTED: ::c_int = 129; -pub const EKEYREVOKED: ::c_int = 128; -pub const EL2HLT: ::c_int = 51; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBEXEC: ::c_int = 83; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBSCN: ::c_int = 81; -pub const ELNRNG: ::c_int = 48; -pub const ELOOP: ::c_int = 40; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const EMSGSIZE: ::c_int = 90; -pub const EMULTIHOP: ::c_int = 72; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENAVAIL: ::c_int = 119; -pub const ENETDOWN: ::c_int = 100; -pub const ENETRESET: ::c_int = 102; -pub const ENETUNREACH: ::c_int = 101; -pub const ENOANO: ::c_int = 55; -pub const ENOBUFS: ::c_int = 105; -pub const ENOCSI: ::c_int = 50; -pub const ENOKEY: ::c_int = 126; -pub const ENOLCK: ::c_int = 37; -pub const ENOMEDIUM: ::c_int = 123; -pub const ENOMSG: ::c_int = 42; -pub const ENOPROTOOPT: ::c_int = 92; -pub const ENOSYS: ::c_int = 38; -pub const ENOTCONN: ::c_int = 107; -pub const ENOTEMPTY: ::c_int = 39; -pub const ENOTNAM: ::c_int = 118; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ENOTSOCK: ::c_int = 88; -pub const ENOTSUP: ::c_int = 95; -pub const ENOTUNIQ: ::c_int = 76; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EOVERFLOW: ::c_int = 75; -pub const EOWNERDEAD: ::c_int = 130; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EREMCHG: ::c_int = 78; -pub const ERESTART: ::c_int = 85; -pub const ERFKILL: ::c_int = 132; -pub const ESHUTDOWN: ::c_int = 108; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const ESTALE: ::c_int = 116; -pub const ESTRPIPE: ::c_int = 86; -pub const ETOOMANYREFS: ::c_int = 109; -pub const EUCLEAN: ::c_int = 117; -pub const EUNATCH: ::c_int = 49; -pub const EUSERS: ::c_int = 87; -pub const EXFULL: ::c_int = 54; -pub const EXTPROC: ::c_int = 65536; -pub const F_EXLCK: ::c_int = 4; -pub const F_GETLK: ::c_int = 12; -pub const F_GETOWN: ::c_int = 9; -pub const F_GETOWNER_UIDS: ::c_int = 17; -pub const F_GETOWN_EX: ::c_int = 16; -pub const F_GETSIG: ::c_int = 11; -pub const FIOASYNC: ::c_int = 21586; -pub const FIOCLEX: ::c_int = 21585; -pub const FIONBIO: ::c_int = 21537; -pub const FIONCLEX: ::c_int = 21584; -pub const FIONREAD: ::c_int = 21531; -pub const FIOQSIZE: ::c_int = 21600; -pub const F_LINUX_SPECIFIC_BASE: ::c_int = 1024; -pub const FLUSHO: ::c_int = 4096; -pub const F_OFD_GETLK: ::c_int = 36; -pub const F_OFD_SETLK: ::c_int = 37; -pub const F_OFD_SETLKW: ::c_int = 38; -pub const F_OWNER_PGRP: ::c_int = 2; -pub const F_OWNER_PID: ::c_int = 1; -pub const F_OWNER_TID: ::c_int = 0; -pub const F_SETLK: ::c_int = 13; -pub const F_SETLKW: ::c_int = 14; -pub const F_SETOWN: ::c_int = 8; -pub const F_SETOWN_EX: ::c_int = 15; -pub const F_SETSIG: ::c_int = 10; -pub const F_SHLCK: ::c_int = 8; -pub const IEXTEN: ::c_int = 32768; -pub const MAP_ANON: ::c_int = 32; -pub const MAP_DENYWRITE: ::c_int = 2048; -pub const MAP_EXECUTABLE: ::c_int = 4096; -pub const MAP_GROWSDOWN: ::c_int = 256; -pub const MAP_HUGE_MASK: ::c_int = 63; -pub const MAP_HUGE_SHIFT: ::c_int = 26; -pub const MAP_HUGETLB: ::c_int = 262144; -pub const MAP_LOCKED: ::c_int = 8192; -pub const MAP_NONBLOCK: ::c_int = 65536; -pub const MAP_NORESERVE: ::c_int = 16384; -pub const MAP_POPULATE: ::c_int = 32768; -pub const MAP_STACK: ::c_int = 131072; -pub const MAP_UNINITIALIZED: ::c_int = 0; -pub const O_APPEND: ::c_int = 1024; -pub const O_ASYNC: ::c_int = 8192; -pub const O_CREAT: ::c_int = 64; -pub const O_DIRECT: ::c_int = 16384; -pub const O_DIRECTORY: ::c_int = 65536; -pub const O_DSYNC: ::c_int = 4096; -pub const O_EXCL: ::c_int = 128; -pub const O_LARGEFILE: ::c_int = 32768; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NOFOLLOW: ::c_int = 131072; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const PF_FILE: ::c_int = 1; -pub const PF_KCM: ::c_int = 41; -pub const PF_MAX: ::c_int = 43; -pub const PF_QIPCRTR: ::c_int = 42; -pub const RLIMIT_AS: ::c_int = 9; -pub const RLIMIT_MEMLOCK: ::c_int = 8; -pub const RLIMIT_NOFILE: ::c_int = 7; -pub const RLIMIT_NPROC: ::c_int = 6; -pub const RLIMIT_RSS: ::c_int = 5; -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] -pub const RLIM_NLIMITS: ::c_int = 16; -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; -pub const SIGBUS: ::c_int = 7; -pub const SIGCHLD: ::c_int = 17; -pub const SIGCONT: ::c_int = 18; -pub const SIGIO: ::c_int = 29; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPROF: ::c_int = 27; -pub const SIGPWR: ::c_int = 30; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGSTOP: ::c_int = 19; -pub const SIGSYS: ::c_int = 31; -pub const SIGTSTP: ::c_int = 20; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGURG: ::c_int = 23; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGWINCH: ::c_int = 28; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIG_SETMASK: ::c_int = 2; // FIXME check these -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_ATTACH_BPF: ::c_int = 50; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_ATTACH_REUSEPORT_CBPF: ::c_int = 51; -pub const SO_ATTACH_REUSEPORT_EBPF: ::c_int = 52; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_NONBLOCK: ::c_int = 2048; -pub const SOCK_SEQPACKET: ::c_int = 5; -pub const SOCK_STREAM: ::c_int = 1; -pub const SO_CNX_ADVICE: ::c_int = 53; -pub const SO_DETACH_BPF: ::c_int = 27; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_DOMAIN: ::c_int = 39; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_ERROR: ::c_int = 4; -pub const SO_GET_FILTER: ::c_int = 26; -pub const SO_INCOMING_CPU: ::c_int = 49; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SOL_CAIF: ::c_int = 278; -pub const SO_LINGER: ::c_int = 13; -pub const SOL_IUCV: ::c_int = 277; -pub const SOL_KCM: ::c_int = 281; -pub const SOL_NFC: ::c_int = 280; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SOL_PNPIPE: ::c_int = 275; -pub const SOL_PPPOL2TP: ::c_int = 273; -pub const SOL_RDS: ::c_int = 276; -pub const SOL_RXRPC: ::c_int = 272; -pub const SOL_SOCKET: ::c_int = 1; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_PEERSEC: ::c_int = 31; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_TYPE: ::c_int = 3; -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SYS3264_fadvise64: ::c_int = 223; -pub const SYS3264_fcntl: ::c_int = 25; -pub const SYS3264_fstatat: ::c_int = 79; -pub const SYS3264_fstat: ::c_int = 80; -pub const SYS3264_fstatfs: ::c_int = 44; -pub const SYS3264_ftruncate: ::c_int = 46; -pub const SYS3264_lseek: ::c_int = 62; -pub const SYS3264_lstat: ::c_int = 1039; -pub const SYS3264_mmap: ::c_int = 222; -pub const SYS3264_sendfile: ::c_int = 71; -pub const SYS3264_stat: ::c_int = 1038; -pub const SYS3264_statfs: ::c_int = 43; -pub const SYS3264_truncate: ::c_int = 45; -pub const SYS_accept4: ::c_int = 242; -pub const SYS_accept: ::c_int = 202; -pub const SYS_access: ::c_int = 1033; -pub const SYS_acct: ::c_int = 89; -pub const SYS_add_key: ::c_int = 217; -pub const SYS_adjtimex: ::c_int = 171; -pub const SYS_alarm: ::c_int = 1059; -pub const SYS_arch_specific_syscall: ::c_int = 244; -pub const SYS_bdflush: ::c_int = 1075; -pub const SYS_bind: ::c_int = 200; -pub const SYS_bpf: ::c_int = 280; -pub const SYS_brk: ::c_int = 214; -pub const SYS_capget: ::c_int = 90; -pub const SYS_capset: ::c_int = 91; -pub const SYS_chdir: ::c_int = 49; -pub const SYS_chmod: ::c_int = 1028; -pub const SYS_chown: ::c_int = 1029; -pub const SYS_chroot: ::c_int = 51; -pub const SYS_clock_adjtime: ::c_int = 266; -pub const SYS_clock_getres: ::c_int = 114; -pub const SYS_clock_gettime: ::c_int = 113; -pub const SYS_clock_nanosleep: ::c_int = 115; -pub const SYS_clock_settime: ::c_int = 112; -pub const SYS_clone: ::c_int = 220; -pub const SYS_close: ::c_int = 57; -pub const SYS_connect: ::c_int = 203; -pub const SYS_copy_file_range: ::c_int = -1; // FIXME -pub const SYS_creat: ::c_int = 1064; -pub const SYS_delete_module: ::c_int = 106; -pub const SYS_dup2: ::c_int = 1041; -pub const SYS_dup3: ::c_int = 24; -pub const SYS_dup: ::c_int = 23; -pub const SYS_epoll_create1: ::c_int = 20; -pub const SYS_epoll_create: ::c_int = 1042; -pub const SYS_epoll_ctl: ::c_int = 21; -pub const SYS_epoll_pwait: ::c_int = 22; -pub const SYS_epoll_wait: ::c_int = 1069; -pub const SYS_eventfd2: ::c_int = 19; -pub const SYS_eventfd: ::c_int = 1044; -pub const SYS_execveat: ::c_int = 281; -pub const SYS_execve: ::c_int = 221; -pub const SYS_exit: ::c_int = 93; -pub const SYS_exit_group: ::c_int = 94; -pub const SYS_faccessat: ::c_int = 48; -pub const SYS_fadvise64_64: ::c_int = 223; -pub const SYS_fallocate: ::c_int = 47; -pub const SYS_fanotify_init: ::c_int = 262; -pub const SYS_fanotify_mark: ::c_int = 263; -pub const SYS_fchdir: ::c_int = 50; -pub const SYS_fchmodat: ::c_int = 53; -pub const SYS_fchmod: ::c_int = 52; -pub const SYS_fchownat: ::c_int = 54; -pub const SYS_fchown: ::c_int = 55; -pub const SYS_fcntl64: ::c_int = 25; -pub const SYS_fcntl: ::c_int = 25; -pub const SYS_fdatasync: ::c_int = 83; -pub const SYS_fgetxattr: ::c_int = 10; -pub const SYS_finit_module: ::c_int = 273; -pub const SYS_flistxattr: ::c_int = 13; -pub const SYS_flock: ::c_int = 32; -pub const SYS_fork: ::c_int = 1079; -pub const SYS_fremovexattr: ::c_int = 16; -pub const SYS_fsetxattr: ::c_int = 7; -pub const SYS_fstat64: ::c_int = 80; -pub const SYS_fstatat64: ::c_int = 79; -pub const SYS_fstatfs64: ::c_int = 44; -pub const SYS_fstatfs: ::c_int = 44; -pub const SYS_fsync: ::c_int = 82; -pub const SYS_ftruncate64: ::c_int = 46; -pub const SYS_ftruncate: ::c_int = 46; -pub const SYS_futex: ::c_int = 98; -pub const SYS_futimesat: ::c_int = 1066; -pub const SYS_getcpu: ::c_int = 168; -pub const SYS_getcwd: ::c_int = 17; -pub const SYS_getdents64: ::c_int = 61; -pub const SYS_getdents: ::c_int = 1065; -pub const SYS_getegid: ::c_int = 177; -pub const SYS_geteuid: ::c_int = 175; -pub const SYS_getgid: ::c_int = 176; -pub const SYS_getgroups: ::c_int = 158; -pub const SYS_getitimer: ::c_int = 102; -pub const SYS_get_mempolicy: ::c_int = 236; -pub const SYS_getpeername: ::c_int = 205; -pub const SYS_getpgid: ::c_int = 155; -pub const SYS_getpgrp: ::c_int = 1060; -pub const SYS_getpid: ::c_int = 172; -pub const SYS_getppid: ::c_int = 173; -pub const SYS_getpriority: ::c_int = 141; -pub const SYS_getrandom: ::c_int = 278; -pub const SYS_getresgid: ::c_int = 150; -pub const SYS_getresuid: ::c_int = 148; -pub const SYS_getrlimit: ::c_int = 163; -pub const SYS_get_robust_list: ::c_int = 100; -pub const SYS_getrusage: ::c_int = 165; -pub const SYS_getsid: ::c_int = 156; -pub const SYS_getsockname: ::c_int = 204; -pub const SYS_getsockopt: ::c_int = 209; -pub const SYS_gettid: ::c_int = 178; -pub const SYS_gettimeofday: ::c_int = 169; -pub const SYS_getuid: ::c_int = 174; -pub const SYS_getxattr: ::c_int = 8; -pub const SYS_init_module: ::c_int = 105; -pub const SYS_inotify_add_watch: ::c_int = 27; -pub const SYS_inotify_init1: ::c_int = 26; -pub const SYS_inotify_init: ::c_int = 1043; -pub const SYS_inotify_rm_watch: ::c_int = 28; -pub const SYS_io_cancel: ::c_int = 3; -pub const SYS_ioctl: ::c_int = 29; -pub const SYS_io_destroy: ::c_int = 1; -pub const SYS_io_getevents: ::c_int = 4; -pub const SYS_ioprio_get: ::c_int = 31; -pub const SYS_ioprio_set: ::c_int = 30; -pub const SYS_io_setup: ::c_int = 0; -pub const SYS_io_submit: ::c_int = 2; -pub const SYS_kcmp: ::c_int = 272; -pub const SYS_kexec_load: ::c_int = 104; -pub const SYS_keyctl: ::c_int = 219; -pub const SYS_kill: ::c_int = 129; -pub const SYS_lchown: ::c_int = 1032; -pub const SYS_lgetxattr: ::c_int = 9; -pub const SYS_linkat: ::c_int = 37; -pub const SYS_link: ::c_int = 1025; -pub const SYS_listen: ::c_int = 201; -pub const SYS_listxattr: ::c_int = 11; -pub const SYS_llistxattr: ::c_int = 12; -pub const SYS__llseek: ::c_int = 62; -pub const SYS_lookup_dcookie: ::c_int = 18; -pub const SYS_lremovexattr: ::c_int = 15; -pub const SYS_lseek: ::c_int = 62; -pub const SYS_lsetxattr: ::c_int = 6; -pub const SYS_lstat64: ::c_int = 1039; -pub const SYS_lstat: ::c_int = 1039; -pub const SYS_madvise: ::c_int = 233; -pub const SYS_mbind: ::c_int = 235; -pub const SYS_memfd_create: ::c_int = 279; -pub const SYS_migrate_pages: ::c_int = 238; -pub const SYS_mincore: ::c_int = 232; -pub const SYS_mkdirat: ::c_int = 34; -pub const SYS_mkdir: ::c_int = 1030; -pub const SYS_mknodat: ::c_int = 33; -pub const SYS_mknod: ::c_int = 1027; -pub const SYS_mlockall: ::c_int = 230; -pub const SYS_mlock: ::c_int = 228; -pub const SYS_mmap2: ::c_int = 222; -pub const SYS_mount: ::c_int = 40; -pub const SYS_move_pages: ::c_int = 239; -pub const SYS_mprotect: ::c_int = 226; -pub const SYS_mq_getsetattr: ::c_int = 185; -pub const SYS_mq_notify: ::c_int = 184; -pub const SYS_mq_open: ::c_int = 180; -pub const SYS_mq_timedreceive: ::c_int = 183; -pub const SYS_mq_timedsend: ::c_int = 182; -pub const SYS_mq_unlink: ::c_int = 181; -pub const SYS_mremap: ::c_int = 216; -pub const SYS_msgctl: ::c_int = 187; -pub const SYS_msgget: ::c_int = 186; -pub const SYS_msgrcv: ::c_int = 188; -pub const SYS_msgsnd: ::c_int = 189; -pub const SYS_msync: ::c_int = 227; -pub const SYS_munlockall: ::c_int = 231; -pub const SYS_munlock: ::c_int = 229; -pub const SYS_munmap: ::c_int = 215; -pub const SYS_name_to_handle_at: ::c_int = 264; -pub const SYS_nanosleep: ::c_int = 101; -pub const SYS_newfstatat: ::c_int = 79; -pub const SYS_nfsservctl: ::c_int = 42; -pub const SYS_oldwait4: ::c_int = 1072; -pub const SYS_openat: ::c_int = 56; -pub const SYS_open_by_handle_at: ::c_int = 265; -pub const SYS_open: ::c_int = 1024; -pub const SYS_pause: ::c_int = 1061; -pub const SYS_perf_event_open: ::c_int = 241; -pub const SYS_personality: ::c_int = 92; -pub const SYS_pipe2: ::c_int = 59; -pub const SYS_pipe: ::c_int = 1040; -pub const SYS_pivot_root: ::c_int = 41; -pub const SYS_poll: ::c_int = 1068; -pub const SYS_ppoll: ::c_int = 73; -pub const SYS_prctl: ::c_int = 167; -pub const SYS_pread64: ::c_int = 67; -pub const SYS_preadv: ::c_int = 69; -pub const SYS_prlimit64: ::c_int = 261; -pub const SYS_process_vm_readv: ::c_int = 270; -pub const SYS_process_vm_writev: ::c_int = 271; -pub const SYS_pselect6: ::c_int = 72; -pub const SYS_ptrace: ::c_int = 117; -pub const SYS_pwrite64: ::c_int = 68; -pub const SYS_pwritev: ::c_int = 70; -pub const SYS_quotactl: ::c_int = 60; -pub const SYS_readahead: ::c_int = 213; -pub const SYS_read: ::c_int = 63; -pub const SYS_readlinkat: ::c_int = 78; -pub const SYS_readlink: ::c_int = 1035; -pub const SYS_readv: ::c_int = 65; -pub const SYS_reboot: ::c_int = 142; -pub const SYS_recv: ::c_int = 1073; -pub const SYS_recvfrom: ::c_int = 207; -pub const SYS_recvmmsg: ::c_int = 243; -pub const SYS_recvmsg: ::c_int = 212; -pub const SYS_remap_file_pages: ::c_int = 234; -pub const SYS_removexattr: ::c_int = 14; -pub const SYS_renameat2: ::c_int = 276; -pub const SYS_renameat: ::c_int = 38; -pub const SYS_rename: ::c_int = 1034; -pub const SYS_request_key: ::c_int = 218; -pub const SYS_restart_syscall: ::c_int = 128; -pub const SYS_rmdir: ::c_int = 1031; -pub const SYS_rt_sigaction: ::c_int = 134; -pub const SYS_rt_sigpending: ::c_int = 136; -pub const SYS_rt_sigprocmask: ::c_int = 135; -pub const SYS_rt_sigqueueinfo: ::c_int = 138; -pub const SYS_rt_sigreturn: ::c_int = 139; -pub const SYS_rt_sigsuspend: ::c_int = 133; -pub const SYS_rt_sigtimedwait: ::c_int = 137; -pub const SYS_rt_tgsigqueueinfo: ::c_int = 240; -pub const SYS_sched_getaffinity: ::c_int = 123; -pub const SYS_sched_getattr: ::c_int = 275; -pub const SYS_sched_getparam: ::c_int = 121; -pub const SYS_sched_get_priority_max: ::c_int = 125; -pub const SYS_sched_get_priority_min: ::c_int = 126; -pub const SYS_sched_getscheduler: ::c_int = 120; -pub const SYS_sched_rr_get_interval: ::c_int = 127; -pub const SYS_sched_setaffinity: ::c_int = 122; -pub const SYS_sched_setattr: ::c_int = 274; -pub const SYS_sched_setparam: ::c_int = 118; -pub const SYS_sched_setscheduler: ::c_int = 119; -pub const SYS_sched_yield: ::c_int = 124; -pub const SYS_seccomp: ::c_int = 277; -pub const SYS_select: ::c_int = 1067; -pub const SYS_semctl: ::c_int = 191; -pub const SYS_semget: ::c_int = 190; -pub const SYS_semop: ::c_int = 193; -pub const SYS_semtimedop: ::c_int = 192; -pub const SYS_send: ::c_int = 1074; -pub const SYS_sendfile64: ::c_int = 71; -pub const SYS_sendfile: ::c_int = 71; -pub const SYS_sendmmsg: ::c_int = 269; -pub const SYS_sendmsg: ::c_int = 211; -pub const SYS_sendto: ::c_int = 206; -pub const SYS_setdomainname: ::c_int = 162; -pub const SYS_setfsgid: ::c_int = 152; -pub const SYS_setfsuid: ::c_int = 151; -pub const SYS_setgid: ::c_int = 144; -pub const SYS_setgroups: ::c_int = 159; -pub const SYS_sethostname: ::c_int = 161; -pub const SYS_setitimer: ::c_int = 103; -pub const SYS_set_mempolicy: ::c_int = 237; -pub const SYS_setns: ::c_int = 268; -pub const SYS_setpgid: ::c_int = 154; -pub const SYS_setpriority: ::c_int = 140; -pub const SYS_setregid: ::c_int = 143; -pub const SYS_setresgid: ::c_int = 149; -pub const SYS_setresuid: ::c_int = 147; -pub const SYS_setreuid: ::c_int = 145; -pub const SYS_setrlimit: ::c_int = 164; -pub const SYS_set_robust_list: ::c_int = 99; -pub const SYS_setsid: ::c_int = 157; -pub const SYS_setsockopt: ::c_int = 208; -pub const SYS_set_tid_address: ::c_int = 96; -pub const SYS_settimeofday: ::c_int = 170; -pub const SYS_setuid: ::c_int = 146; -pub const SYS_setxattr: ::c_int = 5; -pub const SYS_shmat: ::c_int = 196; -pub const SYS_shmctl: ::c_int = 195; -pub const SYS_shmdt: ::c_int = 197; -pub const SYS_shmget: ::c_int = 194; -pub const SYS_shutdown: ::c_int = 210; -pub const SYS_sigaltstack: ::c_int = 132; -pub const SYS_signalfd4: ::c_int = 74; -pub const SYS_signalfd: ::c_int = 1045; -pub const SYS_socket: ::c_int = 198; -pub const SYS_socketpair: ::c_int = 199; -pub const SYS_splice: ::c_int = 76; -pub const SYS_stat64: ::c_int = 1038; -pub const SYS_stat: ::c_int = 1038; -pub const SYS_statfs64: ::c_int = 43; -pub const SYS_swapoff: ::c_int = 225; -pub const SYS_swapon: ::c_int = 224; -pub const SYS_symlinkat: ::c_int = 36; -pub const SYS_symlink: ::c_int = 1036; -pub const SYS_sync: ::c_int = 81; -pub const SYS_sync_file_range2: ::c_int = 84; -pub const SYS_sync_file_range: ::c_int = 84; -pub const SYS_syncfs: ::c_int = 267; -pub const SYS_syscalls: ::c_int = 1080; -pub const SYS__sysctl: ::c_int = 1078; -pub const SYS_sysinfo: ::c_int = 179; -pub const SYS_syslog: ::c_int = 116; -pub const SYS_tee: ::c_int = 77; -pub const SYS_tgkill: ::c_int = 131; -pub const SYS_time: ::c_int = 1062; -pub const SYS_timer_create: ::c_int = 107; -pub const SYS_timer_delete: ::c_int = 111; -pub const SYS_timerfd_create: ::c_int = 85; -pub const SYS_timerfd_gettime: ::c_int = 87; -pub const SYS_timerfd_settime: ::c_int = 86; -pub const SYS_timer_getoverrun: ::c_int = 109; -pub const SYS_timer_gettime: ::c_int = 108; -pub const SYS_timer_settime: ::c_int = 110; -pub const SYS_times: ::c_int = 153; -pub const SYS_tkill: ::c_int = 130; -pub const SYS_truncate64: ::c_int = 45; -pub const SYS_truncate: ::c_int = 45; -pub const SYS_umask: ::c_int = 166; -pub const SYS_umount2: ::c_int = 39; -pub const SYS_umount: ::c_int = 1076; -pub const SYS_uname: ::c_int = 160; -pub const SYS_unlinkat: ::c_int = 35; -pub const SYS_unlink: ::c_int = 1026; -pub const SYS_unshare: ::c_int = 97; -pub const SYS_uselib: ::c_int = 1077; -pub const SYS_ustat: ::c_int = 1070; -pub const SYS_utime: ::c_int = 1063; -pub const SYS_utimensat: ::c_int = 88; -pub const SYS_utimes: ::c_int = 1037; -pub const SYS_vfork: ::c_int = 1071; -pub const SYS_vhangup: ::c_int = 58; -pub const SYS_vmsplice: ::c_int = 75; -pub const SYS_wait4: ::c_int = 260; -pub const SYS_waitid: ::c_int = 95; -pub const SYS_write: ::c_int = 64; -pub const SYS_writev: ::c_int = 66; -pub const SYS_statx: ::c_int = 291; -pub const TCFLSH: ::c_int = 21515; -pub const TCGETA: ::c_int = 21509; -pub const TCGETS: ::c_int = 21505; -pub const TCGETX: ::c_int = 21554; -pub const TCSBRK: ::c_int = 21513; -pub const TCSBRKP: ::c_int = 21541; -pub const TCSETA: ::c_int = 21510; -pub const TCSETAF: ::c_int = 21512; -pub const TCSETAW: ::c_int = 21511; -pub const TCSETS: ::c_int = 21506; -pub const TCSETSF: ::c_int = 21508; -pub const TCSETSW: ::c_int = 21507; -pub const TCSETX: ::c_int = 21555; -pub const TCSETXF: ::c_int = 21556; -pub const TCSETXW: ::c_int = 21557; -pub const TCXONC: ::c_int = 21514; -pub const TIOCCBRK: ::c_int = 21544; -pub const TIOCCONS: ::c_int = 21533; -pub const TIOCEXCL: ::c_int = 21516; -pub const TIOCGETD: ::c_int = 21540; -pub const TIOCGICOUNT: ::c_int = 21597; -pub const TIOCGLCKTRMIOS: ::c_int = 21590; -pub const TIOCGPGRP: ::c_int = 21519; -pub const TIOCGRS485: ::c_int = 21550; -pub const TIOCGSERIAL: ::c_int = 21534; -pub const TIOCGSID: ::c_int = 21545; -pub const TIOCGSOFTCAR: ::c_int = 21529; -pub const TIOCGWINSZ: ::c_int = 21523; -pub const TIOCLINUX: ::c_int = 21532; -pub const TIOCMBIC: ::c_int = 21527; -pub const TIOCMBIS: ::c_int = 21526; -pub const TIOCM_CAR: ::c_int = 64; -pub const TIOCM_CD: ::c_int = 64; -pub const TIOCM_CTS: ::c_int = 32; -pub const TIOCM_DSR: ::c_int = 256; -pub const TIOCM_DTR: ::c_int = 2; -pub const TIOCMGET: ::c_int = 21525; -pub const TIOCMIWAIT: ::c_int = 21596; -pub const TIOCM_LE: ::c_int = 1; -pub const TIOCM_LOOP: ::c_int = 32768; -pub const TIOCM_OUT1: ::c_int = 8192; -pub const TIOCM_OUT2: ::c_int = 16384; -pub const TIOCM_RI: ::c_int = 128; -pub const TIOCM_RNG: ::c_int = 128; -pub const TIOCM_RTS: ::c_int = 4; -pub const TIOCMSET: ::c_int = 21528; -pub const TIOCM_SR: ::c_int = 16; -pub const TIOCM_ST: ::c_int = 8; -pub const TIOCNOTTY: ::c_int = 21538; -pub const TIOCNXCL: ::c_int = 21517; -pub const TIOCOUTQ: ::c_int = 21521; -pub const TIOCPKT: ::c_int = 21536; -pub const TIOCPKT_DATA: ::c_int = 0; -pub const TIOCPKT_DOSTOP: ::c_int = 32; -pub const TIOCPKT_FLUSHREAD: ::c_int = 1; -pub const TIOCPKT_FLUSHWRITE: ::c_int = 2; -pub const TIOCPKT_IOCTL: ::c_int = 64; -pub const TIOCPKT_NOSTOP: ::c_int = 16; -pub const TIOCPKT_START: ::c_int = 8; -pub const TIOCPKT_STOP: ::c_int = 4; -pub const TIOCSBRK: ::c_int = 21543; -pub const TIOCSCTTY: ::c_int = 21518; -pub const TIOCSERCONFIG: ::c_int = 21587; -pub const TIOCSERGETLSR: ::c_int = 21593; -pub const TIOCSERGETMULTI: ::c_int = 21594; -pub const TIOCSERGSTRUCT: ::c_int = 21592; -pub const TIOCSERGWILD: ::c_int = 21588; -pub const TIOCSERSETMULTI: ::c_int = 21595; -pub const TIOCSERSWILD: ::c_int = 21589; -pub const TIOCSER_TEMT: ::c_int = 1; -pub const TIOCSETD: ::c_int = 21539; -pub const TIOCSLCKTRMIOS: ::c_int = 21591; -pub const TIOCSPGRP: ::c_int = 21520; -pub const TIOCSRS485: ::c_int = 21551; -pub const TIOCSSERIAL: ::c_int = 21535; -pub const TIOCSSOFTCAR: ::c_int = 21530; -pub const TIOCSTI: ::c_int = 21522; -pub const TIOCSWINSZ: ::c_int = 21524; -pub const TIOCVHANGUP: ::c_int = 21559; -pub const TOSTOP: ::c_int = 256; -pub const VEOF: ::c_int = 4; -pub const VEOL2: ::c_int = 16; -pub const VEOL: ::c_int = 11; -pub const VMIN: ::c_int = 6; diff --git a/libc/src/unix/linux_like/linux/musl/b32/mips/align.rs b/libc/src/unix/linux_like/linux/musl/b32/mips/align.rs deleted file mode 100644 index 8c228eb..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/mips/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(8))] - pub struct max_align_t { - priv_: [f32; 4] - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b32/mips/mod.rs b/libc/src/unix/linux_like/linux/musl/b32/mips/mod.rs deleted file mode 100644 index be11341..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/mips/mod.rs +++ /dev/null @@ -1,849 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = ::c_int; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - __st_padding1: [::c_long; 2], - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_padding2: [::c_long; 2], - pub st_size: ::off_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - __st_padding3: ::c_long, - pub st_blocks: ::blkcnt_t, - __st_padding4: [::c_long; 14], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __st_padding1: [::c_long; 2], - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_padding2: [::c_long; 2], - pub st_size: ::off_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - __st_padding3: ::c_long, - pub st_blocks: ::blkcnt64_t, - __st_padding4: [::c_long; 14], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __unused1: ::c_long, - __unused2: ::c_long - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - #[cfg(target_endian = "big")] - __unused1: ::c_int, - pub msg_stime: ::time_t, - #[cfg(target_endian = "little")] - __unused1: ::c_int, - #[cfg(target_endian = "big")] - __unused2: ::c_int, - pub msg_rtime: ::time_t, - #[cfg(target_endian = "little")] - __unused2: ::c_int, - #[cfg(target_endian = "big")] - __unused3: ::c_int, - pub msg_ctime: ::time_t, - #[cfg(target_endian = "little")] - __unused3: ::c_int, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 5], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 5], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - #[cfg(target_endian = "little")] - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - #[cfg(target_endian = "big")] - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } -} - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; - -pub const O_DIRECT: ::c_int = 0o100000; -pub const O_DIRECTORY: ::c_int = 0o200000; -pub const O_NOFOLLOW: ::c_int = 0o400000; -pub const O_ASYNC: ::c_int = 0o10000; -pub const O_LARGEFILE: ::c_int = 0x2000; - -pub const FIOCLEX: ::c_int = 0x6601; -pub const FIONCLEX: ::c_int = 0x6602; -pub const FIONBIO: ::c_int = 0x667E; - -pub const RLIMIT_RSS: ::c_int = 7; -pub const RLIMIT_NOFILE: ::c_int = 5; -pub const RLIMIT_AS: ::c_int = 6; -pub const RLIMIT_NPROC: ::c_int = 8; -pub const RLIMIT_MEMLOCK: ::c_int = 9; -pub const RLIMIT_NLIMITS: ::c_int = 15; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::c_int = 0x00000800; -pub const TAB2: ::c_int = 0x00001000; -pub const TAB3: ::c_int = 0x00001800; -pub const CR1: ::c_int = 0x00000200; -pub const CR2: ::c_int = 0x00000400; -pub const CR3: ::c_int = 0x00000600; -pub const FF1: ::c_int = 0x00008000; -pub const BS1: ::c_int = 0x00002000; -pub const VT1: ::c_int = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const O_APPEND: ::c_int = 0o010; -pub const O_CREAT: ::c_int = 0o400; -pub const O_EXCL: ::c_int = 0o2000; -pub const O_NOCTTY: ::c_int = 0o4000; -pub const O_NONBLOCK: ::c_int = 0o200; -pub const O_SYNC: ::c_int = 0o40020; -pub const O_RSYNC: ::c_int = 0o40020; -pub const O_DSYNC: ::c_int = 0o020; - -pub const SOCK_NONBLOCK: ::c_int = 0o200; - -pub const MAP_ANON: ::c_int = 0x800; -pub const MAP_GROWSDOWN: ::c_int = 0x1000; -pub const MAP_DENYWRITE: ::c_int = 0x2000; -pub const MAP_EXECUTABLE: ::c_int = 0x4000; -pub const MAP_LOCKED: ::c_int = 0x8000; -pub const MAP_NORESERVE: ::c_int = 0x0400; -pub const MAP_POPULATE: ::c_int = 0x10000; -pub const MAP_NONBLOCK: ::c_int = 0x20000; -pub const MAP_STACK: ::c_int = 0x40000; - -pub const EDEADLK: ::c_int = 45; -pub const ENAMETOOLONG: ::c_int = 78; -pub const ENOLCK: ::c_int = 46; -pub const ENOSYS: ::c_int = 89; -pub const ENOTEMPTY: ::c_int = 93; -pub const ELOOP: ::c_int = 90; -pub const ENOMSG: ::c_int = 35; -pub const EIDRM: ::c_int = 36; -pub const ECHRNG: ::c_int = 37; -pub const EL2NSYNC: ::c_int = 38; -pub const EL3HLT: ::c_int = 39; -pub const EL3RST: ::c_int = 40; -pub const ELNRNG: ::c_int = 41; -pub const EUNATCH: ::c_int = 42; -pub const ENOCSI: ::c_int = 43; -pub const EL2HLT: ::c_int = 44; -pub const EBADE: ::c_int = 50; -pub const EBADR: ::c_int = 51; -pub const EXFULL: ::c_int = 52; -pub const ENOANO: ::c_int = 53; -pub const EBADRQC: ::c_int = 54; -pub const EBADSLT: ::c_int = 55; -pub const EDEADLOCK: ::c_int = 56; -pub const EMULTIHOP: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 79; -pub const ENOTUNIQ: ::c_int = 80; -pub const EBADFD: ::c_int = 81; -pub const EBADMSG: ::c_int = 77; -pub const EREMCHG: ::c_int = 82; -pub const ELIBACC: ::c_int = 83; -pub const ELIBBAD: ::c_int = 84; -pub const ELIBSCN: ::c_int = 85; -pub const ELIBMAX: ::c_int = 86; -pub const ELIBEXEC: ::c_int = 87; -pub const EILSEQ: ::c_int = 88; -pub const ERESTART: ::c_int = 91; -pub const ESTRPIPE: ::c_int = 92; -pub const EUSERS: ::c_int = 94; -pub const ENOTSOCK: ::c_int = 95; -pub const EDESTADDRREQ: ::c_int = 96; -pub const EMSGSIZE: ::c_int = 97; -pub const EPROTOTYPE: ::c_int = 98; -pub const ENOPROTOOPT: ::c_int = 99; -pub const EPROTONOSUPPORT: ::c_int = 120; -pub const ESOCKTNOSUPPORT: ::c_int = 121; -pub const EOPNOTSUPP: ::c_int = 122; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 123; -pub const EAFNOSUPPORT: ::c_int = 124; -pub const EADDRINUSE: ::c_int = 125; -pub const EADDRNOTAVAIL: ::c_int = 126; -pub const ENETDOWN: ::c_int = 127; -pub const ENETUNREACH: ::c_int = 128; -pub const ENETRESET: ::c_int = 129; -pub const ECONNABORTED: ::c_int = 130; -pub const ECONNRESET: ::c_int = 131; -pub const ENOBUFS: ::c_int = 132; -pub const EISCONN: ::c_int = 133; -pub const ENOTCONN: ::c_int = 134; -pub const ESHUTDOWN: ::c_int = 143; -pub const ETOOMANYREFS: ::c_int = 144; -pub const ETIMEDOUT: ::c_int = 145; -pub const ECONNREFUSED: ::c_int = 146; -pub const EHOSTDOWN: ::c_int = 147; -pub const EHOSTUNREACH: ::c_int = 148; -pub const EALREADY: ::c_int = 149; -pub const EINPROGRESS: ::c_int = 150; -pub const ESTALE: ::c_int = 151; -pub const EUCLEAN: ::c_int = 135; -pub const ENOTNAM: ::c_int = 137; -pub const ENAVAIL: ::c_int = 138; -pub const EISNAM: ::c_int = 139; -pub const EREMOTEIO: ::c_int = 140; -pub const EDQUOT: ::c_int = 1133; -pub const ENOMEDIUM: ::c_int = 159; -pub const EMEDIUMTYPE: ::c_int = 160; -pub const ECANCELED: ::c_int = 158; -pub const ENOKEY: ::c_int = 161; -pub const EKEYEXPIRED: ::c_int = 162; -pub const EKEYREVOKED: ::c_int = 163; -pub const EKEYREJECTED: ::c_int = 164; -pub const EOWNERDEAD: ::c_int = 165; -pub const ENOTRECOVERABLE: ::c_int = 166; -pub const EHWPOISON: ::c_int = 168; -pub const ERFKILL: ::c_int = 167; - -pub const SOCK_STREAM: ::c_int = 2; -pub const SOCK_DGRAM: ::c_int = 1; -pub const SOCK_SEQPACKET: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = 65535; - -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_ACCEPTCONN: ::c_int = 0x1009; -pub const SO_PROTOCOL: ::c_int = 0x1028; -pub const SO_DOMAIN: ::c_int = 0x1029; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_PASSCRED: ::c_int = 17; -pub const SO_PEERCRED: ::c_int = 18; -pub const SO_SNDBUFFORCE: ::c_int = 31; -pub const SO_RCVBUFFORCE: ::c_int = 33; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 8; -pub const SA_NOCLDWAIT: ::c_int = 0x10000; - -pub const SIGCHLD: ::c_int = 18; -pub const SIGBUS: ::c_int = 10; -pub const SIGTTIN: ::c_int = 26; -pub const SIGTTOU: ::c_int = 27; -pub const SIGXCPU: ::c_int = 30; -pub const SIGXFSZ: ::c_int = 31; -pub const SIGVTALRM: ::c_int = 28; -pub const SIGPROF: ::c_int = 29; -pub const SIGWINCH: ::c_int = 20; -pub const SIGUSR1: ::c_int = 16; -pub const SIGUSR2: ::c_int = 17; -pub const SIGCONT: ::c_int = 25; -pub const SIGSTOP: ::c_int = 23; -pub const SIGTSTP: ::c_int = 24; -pub const SIGURG: ::c_int = 21; -pub const SIGIO: ::c_int = 22; -pub const SIGSYS: ::c_int = 12; -pub const SIGSTKFLT: ::c_int = 7; -pub const SIGPOLL: ::c_int = ::SIGIO; -pub const SIGPWR: ::c_int = 19; -pub const SIG_SETMASK: ::c_int = 3; -pub const SIG_BLOCK: ::c_int = 1; -pub const SIG_UNBLOCK: ::c_int = 2; - -pub const EXTPROC: ::tcflag_t = 0o200000; - -pub const MAP_HUGETLB: ::c_int = 0x80000; - -pub const F_GETLK: ::c_int = 33; -pub const F_GETOWN: ::c_int = 23; -pub const F_SETLK: ::c_int = 34; -pub const F_SETLKW: ::c_int = 35; -pub const F_SETOWN: ::c_int = 24; - -pub const VEOF: usize = 16; -pub const VEOL: usize = 17; -pub const VEOL2: usize = 6; -pub const VMIN: usize = 4; -pub const IEXTEN: ::tcflag_t = 0o000400; -pub const TOSTOP: ::tcflag_t = 0o100000; -pub const FLUSHO: ::tcflag_t = 0o020000; - -pub const TCGETS: ::c_int = 0x540D; -pub const TCSETS: ::c_int = 0x540E; -pub const TCSETSW: ::c_int = 0x540F; -pub const TCSETSF: ::c_int = 0x5410; -pub const TCGETA: ::c_int = 0x5401; -pub const TCSETA: ::c_int = 0x5402; -pub const TCSETAW: ::c_int = 0x5403; -pub const TCSETAF: ::c_int = 0x5404; -pub const TCSBRK: ::c_int = 0x5405; -pub const TCXONC: ::c_int = 0x5406; -pub const TCFLSH: ::c_int = 0x5407; -pub const TIOCGSOFTCAR: ::c_int = 0x5481; -pub const TIOCSSOFTCAR: ::c_int = 0x5482; -pub const TIOCLINUX: ::c_int = 0x5483; -pub const TIOCGSERIAL: ::c_int = 0x5484; -pub const TIOCEXCL: ::c_int = 0x740D; -pub const TIOCNXCL: ::c_int = 0x740E; -pub const TIOCSCTTY: ::c_int = 0x5480; -pub const TIOCGPGRP: ::c_int = 0x40047477; -pub const TIOCSPGRP: ::c_int = 0x80047476; -pub const TIOCOUTQ: ::c_int = 0x7472; -pub const TIOCSTI: ::c_int = 0x5472; -pub const TIOCGWINSZ: ::c_int = 0x40087468; -pub const TIOCSWINSZ: ::c_int = 0x80087467; -pub const TIOCMGET: ::c_int = 0x741D; -pub const TIOCMBIS: ::c_int = 0x741B; -pub const TIOCMBIC: ::c_int = 0x741C; -pub const TIOCMSET: ::c_int = 0x741A; -pub const FIONREAD: ::c_int = 0x467F; -pub const TIOCCONS: ::c_int = 0x80047478; - -pub const TIOCGRS485: ::c_int = 0x4020542E; -pub const TIOCSRS485: ::c_int = 0xC020542F; - -pub const POLLWRNORM: ::c_short = 0x4; -pub const POLLWRBAND: ::c_short = 0x100; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x010; -pub const TIOCM_SR: ::c_int = 0x020; -pub const TIOCM_CTS: ::c_int = 0x040; -pub const TIOCM_CAR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RNG: ::c_int = 0x200; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; -pub const TIOCM_DSR: ::c_int = 0x400; - -pub const SYS_syscall: ::c_long = 4000 + 0; -pub const SYS_exit: ::c_long = 4000 + 1; -pub const SYS_fork: ::c_long = 4000 + 2; -pub const SYS_read: ::c_long = 4000 + 3; -pub const SYS_write: ::c_long = 4000 + 4; -pub const SYS_open: ::c_long = 4000 + 5; -pub const SYS_close: ::c_long = 4000 + 6; -pub const SYS_waitpid: ::c_long = 4000 + 7; -pub const SYS_creat: ::c_long = 4000 + 8; -pub const SYS_link: ::c_long = 4000 + 9; -pub const SYS_unlink: ::c_long = 4000 + 10; -pub const SYS_execve: ::c_long = 4000 + 11; -pub const SYS_chdir: ::c_long = 4000 + 12; -pub const SYS_time: ::c_long = 4000 + 13; -pub const SYS_mknod: ::c_long = 4000 + 14; -pub const SYS_chmod: ::c_long = 4000 + 15; -pub const SYS_lchown: ::c_long = 4000 + 16; -pub const SYS_break: ::c_long = 4000 + 17; -pub const SYS_lseek: ::c_long = 4000 + 19; -pub const SYS_getpid: ::c_long = 4000 + 20; -pub const SYS_mount: ::c_long = 4000 + 21; -pub const SYS_umount: ::c_long = 4000 + 22; -pub const SYS_setuid: ::c_long = 4000 + 23; -pub const SYS_getuid: ::c_long = 4000 + 24; -pub const SYS_stime: ::c_long = 4000 + 25; -pub const SYS_ptrace: ::c_long = 4000 + 26; -pub const SYS_alarm: ::c_long = 4000 + 27; -pub const SYS_pause: ::c_long = 4000 + 29; -pub const SYS_utime: ::c_long = 4000 + 30; -pub const SYS_stty: ::c_long = 4000 + 31; -pub const SYS_gtty: ::c_long = 4000 + 32; -pub const SYS_access: ::c_long = 4000 + 33; -pub const SYS_nice: ::c_long = 4000 + 34; -pub const SYS_ftime: ::c_long = 4000 + 35; -pub const SYS_sync: ::c_long = 4000 + 36; -pub const SYS_kill: ::c_long = 4000 + 37; -pub const SYS_rename: ::c_long = 4000 + 38; -pub const SYS_mkdir: ::c_long = 4000 + 39; -pub const SYS_rmdir: ::c_long = 4000 + 40; -pub const SYS_dup: ::c_long = 4000 + 41; -pub const SYS_pipe: ::c_long = 4000 + 42; -pub const SYS_times: ::c_long = 4000 + 43; -pub const SYS_prof: ::c_long = 4000 + 44; -pub const SYS_brk: ::c_long = 4000 + 45; -pub const SYS_setgid: ::c_long = 4000 + 46; -pub const SYS_getgid: ::c_long = 4000 + 47; -pub const SYS_signal: ::c_long = 4000 + 48; -pub const SYS_geteuid: ::c_long = 4000 + 49; -pub const SYS_getegid: ::c_long = 4000 + 50; -pub const SYS_acct: ::c_long = 4000 + 51; -pub const SYS_umount2: ::c_long = 4000 + 52; -pub const SYS_lock: ::c_long = 4000 + 53; -pub const SYS_ioctl: ::c_long = 4000 + 54; -pub const SYS_fcntl: ::c_long = 4000 + 55; -pub const SYS_mpx: ::c_long = 4000 + 56; -pub const SYS_setpgid: ::c_long = 4000 + 57; -pub const SYS_ulimit: ::c_long = 4000 + 58; -pub const SYS_umask: ::c_long = 4000 + 60; -pub const SYS_chroot: ::c_long = 4000 + 61; -pub const SYS_ustat: ::c_long = 4000 + 62; -pub const SYS_dup2: ::c_long = 4000 + 63; -pub const SYS_getppid: ::c_long = 4000 + 64; -pub const SYS_getpgrp: ::c_long = 4000 + 65; -pub const SYS_setsid: ::c_long = 4000 + 66; -pub const SYS_sigaction: ::c_long = 4000 + 67; -pub const SYS_sgetmask: ::c_long = 4000 + 68; -pub const SYS_ssetmask: ::c_long = 4000 + 69; -pub const SYS_setreuid: ::c_long = 4000 + 70; -pub const SYS_setregid: ::c_long = 4000 + 71; -pub const SYS_sigsuspend: ::c_long = 4000 + 72; -pub const SYS_sigpending: ::c_long = 4000 + 73; -pub const SYS_sethostname: ::c_long = 4000 + 74; -pub const SYS_setrlimit: ::c_long = 4000 + 75; -pub const SYS_getrlimit: ::c_long = 4000 + 76; -pub const SYS_getrusage: ::c_long = 4000 + 77; -pub const SYS_gettimeofday: ::c_long = 4000 + 78; -pub const SYS_settimeofday: ::c_long = 4000 + 79; -pub const SYS_getgroups: ::c_long = 4000 + 80; -pub const SYS_setgroups: ::c_long = 4000 + 81; -pub const SYS_symlink: ::c_long = 4000 + 83; -pub const SYS_readlink: ::c_long = 4000 + 85; -pub const SYS_uselib: ::c_long = 4000 + 86; -pub const SYS_swapon: ::c_long = 4000 + 87; -pub const SYS_reboot: ::c_long = 4000 + 88; -pub const SYS_readdir: ::c_long = 4000 + 89; -pub const SYS_mmap: ::c_long = 4000 + 90; -pub const SYS_munmap: ::c_long = 4000 + 91; -pub const SYS_truncate: ::c_long = 4000 + 92; -pub const SYS_ftruncate: ::c_long = 4000 + 93; -pub const SYS_fchmod: ::c_long = 4000 + 94; -pub const SYS_fchown: ::c_long = 4000 + 95; -pub const SYS_getpriority: ::c_long = 4000 + 96; -pub const SYS_setpriority: ::c_long = 4000 + 97; -pub const SYS_profil: ::c_long = 4000 + 98; -pub const SYS_statfs: ::c_long = 4000 + 99; -pub const SYS_fstatfs: ::c_long = 4000 + 100; -pub const SYS_ioperm: ::c_long = 4000 + 101; -pub const SYS_socketcall: ::c_long = 4000 + 102; -pub const SYS_syslog: ::c_long = 4000 + 103; -pub const SYS_setitimer: ::c_long = 4000 + 104; -pub const SYS_getitimer: ::c_long = 4000 + 105; -pub const SYS_stat: ::c_long = 4000 + 106; -pub const SYS_lstat: ::c_long = 4000 + 107; -pub const SYS_fstat: ::c_long = 4000 + 108; -pub const SYS_iopl: ::c_long = 4000 + 110; -pub const SYS_vhangup: ::c_long = 4000 + 111; -pub const SYS_idle: ::c_long = 4000 + 112; -pub const SYS_vm86: ::c_long = 4000 + 113; -pub const SYS_wait4: ::c_long = 4000 + 114; -pub const SYS_swapoff: ::c_long = 4000 + 115; -pub const SYS_sysinfo: ::c_long = 4000 + 116; -pub const SYS_ipc: ::c_long = 4000 + 117; -pub const SYS_fsync: ::c_long = 4000 + 118; -pub const SYS_sigreturn: ::c_long = 4000 + 119; -pub const SYS_clone: ::c_long = 4000 + 120; -pub const SYS_setdomainname: ::c_long = 4000 + 121; -pub const SYS_uname: ::c_long = 4000 + 122; -pub const SYS_modify_ldt: ::c_long = 4000 + 123; -pub const SYS_adjtimex: ::c_long = 4000 + 124; -pub const SYS_mprotect: ::c_long = 4000 + 125; -pub const SYS_sigprocmask: ::c_long = 4000 + 126; -pub const SYS_create_module: ::c_long = 4000 + 127; -pub const SYS_init_module: ::c_long = 4000 + 128; -pub const SYS_delete_module: ::c_long = 4000 + 129; -pub const SYS_get_kernel_syms: ::c_long = 4000 + 130; -pub const SYS_quotactl: ::c_long = 4000 + 131; -pub const SYS_getpgid: ::c_long = 4000 + 132; -pub const SYS_fchdir: ::c_long = 4000 + 133; -pub const SYS_bdflush: ::c_long = 4000 + 134; -pub const SYS_sysfs: ::c_long = 4000 + 135; -pub const SYS_personality: ::c_long = 4000 + 136; -pub const SYS_afs_syscall: ::c_long = 4000 + 137; -pub const SYS_setfsuid: ::c_long = 4000 + 138; -pub const SYS_setfsgid: ::c_long = 4000 + 139; -pub const SYS__llseek: ::c_long = 4000 + 140; -pub const SYS_getdents: ::c_long = 4000 + 141; -pub const SYS_flock: ::c_long = 4000 + 143; -pub const SYS_msync: ::c_long = 4000 + 144; -pub const SYS_readv: ::c_long = 4000 + 145; -pub const SYS_writev: ::c_long = 4000 + 146; -pub const SYS_cacheflush: ::c_long = 4000 + 147; -pub const SYS_cachectl: ::c_long = 4000 + 148; -pub const SYS_sysmips: ::c_long = 4000 + 149; -pub const SYS_getsid: ::c_long = 4000 + 151; -pub const SYS_fdatasync: ::c_long = 4000 + 152; -pub const SYS__sysctl: ::c_long = 4000 + 153; -pub const SYS_mlock: ::c_long = 4000 + 154; -pub const SYS_munlock: ::c_long = 4000 + 155; -pub const SYS_mlockall: ::c_long = 4000 + 156; -pub const SYS_munlockall: ::c_long = 4000 + 157; -pub const SYS_sched_setparam: ::c_long = 4000 + 158; -pub const SYS_sched_getparam: ::c_long = 4000 + 159; -pub const SYS_sched_setscheduler: ::c_long = 4000 + 160; -pub const SYS_sched_getscheduler: ::c_long = 4000 + 161; -pub const SYS_sched_yield: ::c_long = 4000 + 162; -pub const SYS_sched_get_priority_max: ::c_long = 4000 + 163; -pub const SYS_sched_get_priority_min: ::c_long = 4000 + 164; -pub const SYS_sched_rr_get_interval: ::c_long = 4000 + 165; -pub const SYS_nanosleep: ::c_long = 4000 + 166; -pub const SYS_mremap: ::c_long = 4000 + 167; -pub const SYS_accept: ::c_long = 4000 + 168; -pub const SYS_bind: ::c_long = 4000 + 169; -pub const SYS_connect: ::c_long = 4000 + 170; -pub const SYS_getpeername: ::c_long = 4000 + 171; -pub const SYS_getsockname: ::c_long = 4000 + 172; -pub const SYS_getsockopt: ::c_long = 4000 + 173; -pub const SYS_listen: ::c_long = 4000 + 174; -pub const SYS_recv: ::c_long = 4000 + 175; -pub const SYS_recvfrom: ::c_long = 4000 + 176; -pub const SYS_recvmsg: ::c_long = 4000 + 177; -pub const SYS_send: ::c_long = 4000 + 178; -pub const SYS_sendmsg: ::c_long = 4000 + 179; -pub const SYS_sendto: ::c_long = 4000 + 180; -pub const SYS_setsockopt: ::c_long = 4000 + 181; -pub const SYS_shutdown: ::c_long = 4000 + 182; -pub const SYS_socket: ::c_long = 4000 + 183; -pub const SYS_socketpair: ::c_long = 4000 + 184; -pub const SYS_setresuid: ::c_long = 4000 + 185; -pub const SYS_getresuid: ::c_long = 4000 + 186; -pub const SYS_query_module: ::c_long = 4000 + 187; -pub const SYS_poll: ::c_long = 4000 + 188; -pub const SYS_nfsservctl: ::c_long = 4000 + 189; -pub const SYS_setresgid: ::c_long = 4000 + 190; -pub const SYS_getresgid: ::c_long = 4000 + 191; -pub const SYS_prctl: ::c_long = 4000 + 192; -pub const SYS_rt_sigreturn: ::c_long = 4000 + 193; -pub const SYS_rt_sigaction: ::c_long = 4000 + 194; -pub const SYS_rt_sigprocmask: ::c_long = 4000 + 195; -pub const SYS_rt_sigpending: ::c_long = 4000 + 196; -pub const SYS_rt_sigtimedwait: ::c_long = 4000 + 197; -pub const SYS_rt_sigqueueinfo: ::c_long = 4000 + 198; -pub const SYS_rt_sigsuspend: ::c_long = 4000 + 199; -pub const SYS_chown: ::c_long = 4000 + 202; -pub const SYS_getcwd: ::c_long = 4000 + 203; -pub const SYS_capget: ::c_long = 4000 + 204; -pub const SYS_capset: ::c_long = 4000 + 205; -pub const SYS_sigaltstack: ::c_long = 4000 + 206; -pub const SYS_sendfile: ::c_long = 4000 + 207; -pub const SYS_getpmsg: ::c_long = 4000 + 208; -pub const SYS_putpmsg: ::c_long = 4000 + 209; -pub const SYS_mmap2: ::c_long = 4000 + 210; -pub const SYS_truncate64: ::c_long = 4000 + 211; -pub const SYS_ftruncate64: ::c_long = 4000 + 212; -pub const SYS_stat64: ::c_long = 4000 + 213; -pub const SYS_lstat64: ::c_long = 4000 + 214; -pub const SYS_fstat64: ::c_long = 4000 + 215; -pub const SYS_pivot_root: ::c_long = 4000 + 216; -pub const SYS_mincore: ::c_long = 4000 + 217; -pub const SYS_madvise: ::c_long = 4000 + 218; -pub const SYS_getdents64: ::c_long = 4000 + 219; -pub const SYS_fcntl64: ::c_long = 4000 + 220; -pub const SYS_gettid: ::c_long = 4000 + 222; -pub const SYS_readahead: ::c_long = 4000 + 223; -pub const SYS_setxattr: ::c_long = 4000 + 224; -pub const SYS_lsetxattr: ::c_long = 4000 + 225; -pub const SYS_fsetxattr: ::c_long = 4000 + 226; -pub const SYS_getxattr: ::c_long = 4000 + 227; -pub const SYS_lgetxattr: ::c_long = 4000 + 228; -pub const SYS_fgetxattr: ::c_long = 4000 + 229; -pub const SYS_listxattr: ::c_long = 4000 + 230; -pub const SYS_llistxattr: ::c_long = 4000 + 231; -pub const SYS_flistxattr: ::c_long = 4000 + 232; -pub const SYS_removexattr: ::c_long = 4000 + 233; -pub const SYS_lremovexattr: ::c_long = 4000 + 234; -pub const SYS_fremovexattr: ::c_long = 4000 + 235; -pub const SYS_tkill: ::c_long = 4000 + 236; -pub const SYS_sendfile64: ::c_long = 4000 + 237; -pub const SYS_futex: ::c_long = 4000 + 238; -pub const SYS_sched_setaffinity: ::c_long = 4000 + 239; -pub const SYS_sched_getaffinity: ::c_long = 4000 + 240; -pub const SYS_io_setup: ::c_long = 4000 + 241; -pub const SYS_io_destroy: ::c_long = 4000 + 242; -pub const SYS_io_getevents: ::c_long = 4000 + 243; -pub const SYS_io_submit: ::c_long = 4000 + 244; -pub const SYS_io_cancel: ::c_long = 4000 + 245; -pub const SYS_exit_group: ::c_long = 4000 + 246; -pub const SYS_lookup_dcookie: ::c_long = 4000 + 247; -pub const SYS_epoll_create: ::c_long = 4000 + 248; -pub const SYS_epoll_ctl: ::c_long = 4000 + 249; -pub const SYS_epoll_wait: ::c_long = 4000 + 250; -pub const SYS_remap_file_pages: ::c_long = 4000 + 251; -pub const SYS_set_tid_address: ::c_long = 4000 + 252; -pub const SYS_restart_syscall: ::c_long = 4000 + 253; -pub const SYS_statfs64: ::c_long = 4000 + 255; -pub const SYS_fstatfs64: ::c_long = 4000 + 256; -pub const SYS_timer_create: ::c_long = 4000 + 257; -pub const SYS_timer_settime: ::c_long = 4000 + 258; -pub const SYS_timer_gettime: ::c_long = 4000 + 259; -pub const SYS_timer_getoverrun: ::c_long = 4000 + 260; -pub const SYS_timer_delete: ::c_long = 4000 + 261; -pub const SYS_clock_settime: ::c_long = 4000 + 262; -pub const SYS_clock_gettime: ::c_long = 4000 + 263; -pub const SYS_clock_getres: ::c_long = 4000 + 264; -pub const SYS_clock_nanosleep: ::c_long = 4000 + 265; -pub const SYS_tgkill: ::c_long = 4000 + 266; -pub const SYS_utimes: ::c_long = 4000 + 267; -pub const SYS_mbind: ::c_long = 4000 + 268; -pub const SYS_get_mempolicy: ::c_long = 4000 + 269; -pub const SYS_set_mempolicy: ::c_long = 4000 + 270; -pub const SYS_mq_open: ::c_long = 4000 + 271; -pub const SYS_mq_unlink: ::c_long = 4000 + 272; -pub const SYS_mq_timedsend: ::c_long = 4000 + 273; -pub const SYS_mq_timedreceive: ::c_long = 4000 + 274; -pub const SYS_mq_notify: ::c_long = 4000 + 275; -pub const SYS_mq_getsetattr: ::c_long = 4000 + 276; -pub const SYS_vserver: ::c_long = 4000 + 277; -pub const SYS_waitid: ::c_long = 4000 + 278; -/* pub const SYS_sys_setaltroot: ::c_long = 4000 + 279; */ -pub const SYS_add_key: ::c_long = 4000 + 280; -pub const SYS_request_key: ::c_long = 4000 + 281; -pub const SYS_keyctl: ::c_long = 4000 + 282; -pub const SYS_set_thread_area: ::c_long = 4000 + 283; -pub const SYS_inotify_init: ::c_long = 4000 + 284; -pub const SYS_inotify_add_watch: ::c_long = 4000 + 285; -pub const SYS_inotify_rm_watch: ::c_long = 4000 + 286; -pub const SYS_migrate_pages: ::c_long = 4000 + 287; -pub const SYS_openat: ::c_long = 4000 + 288; -pub const SYS_mkdirat: ::c_long = 4000 + 289; -pub const SYS_mknodat: ::c_long = 4000 + 290; -pub const SYS_fchownat: ::c_long = 4000 + 291; -pub const SYS_futimesat: ::c_long = 4000 + 292; -pub const SYS_unlinkat: ::c_long = 4000 + 294; -pub const SYS_renameat: ::c_long = 4000 + 295; -pub const SYS_linkat: ::c_long = 4000 + 296; -pub const SYS_symlinkat: ::c_long = 4000 + 297; -pub const SYS_readlinkat: ::c_long = 4000 + 298; -pub const SYS_fchmodat: ::c_long = 4000 + 299; -pub const SYS_faccessat: ::c_long = 4000 + 300; -pub const SYS_pselect6: ::c_long = 4000 + 301; -pub const SYS_ppoll: ::c_long = 4000 + 302; -pub const SYS_unshare: ::c_long = 4000 + 303; -pub const SYS_splice: ::c_long = 4000 + 304; -pub const SYS_sync_file_range: ::c_long = 4000 + 305; -pub const SYS_tee: ::c_long = 4000 + 306; -pub const SYS_vmsplice: ::c_long = 4000 + 307; -pub const SYS_move_pages: ::c_long = 4000 + 308; -pub const SYS_set_robust_list: ::c_long = 4000 + 309; -pub const SYS_get_robust_list: ::c_long = 4000 + 310; -pub const SYS_kexec_load: ::c_long = 4000 + 311; -pub const SYS_getcpu: ::c_long = 4000 + 312; -pub const SYS_epoll_pwait: ::c_long = 4000 + 313; -pub const SYS_ioprio_set: ::c_long = 4000 + 314; -pub const SYS_ioprio_get: ::c_long = 4000 + 315; -pub const SYS_utimensat: ::c_long = 4000 + 316; -pub const SYS_signalfd: ::c_long = 4000 + 317; -pub const SYS_timerfd: ::c_long = 4000 + 318; -pub const SYS_eventfd: ::c_long = 4000 + 319; -pub const SYS_fallocate: ::c_long = 4000 + 320; -pub const SYS_timerfd_create: ::c_long = 4000 + 321; -pub const SYS_timerfd_gettime: ::c_long = 4000 + 322; -pub const SYS_timerfd_settime: ::c_long = 4000 + 323; -pub const SYS_signalfd4: ::c_long = 4000 + 324; -pub const SYS_eventfd2: ::c_long = 4000 + 325; -pub const SYS_epoll_create1: ::c_long = 4000 + 326; -pub const SYS_dup3: ::c_long = 4000 + 327; -pub const SYS_pipe2: ::c_long = 4000 + 328; -pub const SYS_inotify_init1: ::c_long = 4000 + 329; -pub const SYS_preadv: ::c_long = 4000 + 330; -pub const SYS_pwritev: ::c_long = 4000 + 331; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 4000 + 332; -pub const SYS_perf_event_open: ::c_long = 4000 + 333; -pub const SYS_accept4: ::c_long = 4000 + 334; -pub const SYS_recvmmsg: ::c_long = 4000 + 335; -pub const SYS_fanotify_init: ::c_long = 4000 + 336; -pub const SYS_fanotify_mark: ::c_long = 4000 + 337; -pub const SYS_prlimit64: ::c_long = 4000 + 338; -pub const SYS_name_to_handle_at: ::c_long = 4000 + 339; -pub const SYS_open_by_handle_at: ::c_long = 4000 + 340; -pub const SYS_clock_adjtime: ::c_long = 4000 + 341; -pub const SYS_syncfs: ::c_long = 4000 + 342; -pub const SYS_sendmmsg: ::c_long = 4000 + 343; -pub const SYS_setns: ::c_long = 4000 + 344; -pub const SYS_process_vm_readv: ::c_long = 4000 + 345; -pub const SYS_process_vm_writev: ::c_long = 4000 + 346; -pub const SYS_kcmp: ::c_long = 4000 + 347; -pub const SYS_finit_module: ::c_long = 4000 + 348; -pub const SYS_sched_setattr: ::c_long = 4000 + 349; -pub const SYS_sched_getattr: ::c_long = 4000 + 350; -pub const SYS_renameat2: ::c_long = 4000 + 351; -pub const SYS_seccomp: ::c_long = 4000 + 352; -pub const SYS_getrandom: ::c_long = 4000 + 353; -pub const SYS_memfd_create: ::c_long = 4000 + 354; -pub const SYS_bpf: ::c_long = 4000 + 355; -pub const SYS_execveat: ::c_long = 4000 + 356; -pub const SYS_userfaultfd: ::c_long = 4000 + 357; -pub const SYS_membarrier: ::c_long = 4000 + 358; -pub const SYS_mlock2: ::c_long = 4000 + 359; -pub const SYS_copy_file_range: ::c_long = 4000 + 360; -pub const SYS_preadv2: ::c_long = 4000 + 361; -pub const SYS_pwritev2: ::c_long = 4000 + 362; -pub const SYS_pkey_mprotect: ::c_long = 4000 + 363; -pub const SYS_pkey_alloc: ::c_long = 4000 + 364; -pub const SYS_pkey_free: ::c_long = 4000 + 365; -pub const SYS_statx: ::c_long = 4000 + 366; - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b32/mod.rs b/libc/src/unix/linux_like/linux/musl/b32/mod.rs deleted file mode 100644 index 7cf6da9..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/mod.rs +++ /dev/null @@ -1,65 +0,0 @@ -pub type c_long = i32; -pub type c_ulong = u32; -pub type nlink_t = u32; -pub type blksize_t = ::c_long; -pub type __u64 = ::c_ulonglong; - -s! { - pub struct pthread_attr_t { - __size: [u32; 9] - } - - pub struct sigset_t { - __val: [::c_ulong; 32], - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::socklen_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct sem_t { - __val: [::c_int; 4], - } -} - -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24; - -pub const TIOCINQ: ::c_int = ::FIONREAD; - -extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; -} - -cfg_if! { - if #[cfg(any(target_arch = "x86"))] { - mod x86; - pub use self::x86::*; - } else if #[cfg(any(target_arch = "mips"))] { - mod mips; - pub use self::mips::*; - } else if #[cfg(any(target_arch = "arm"))] { - mod arm; - pub use self::arm::*; - } else if #[cfg(any(target_arch = "powerpc"))] { - mod powerpc; - pub use self::powerpc::*; - } else if #[cfg(any(target_arch = "hexagon"))] { - mod hexagon; - pub use self::hexagon::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b32/powerpc.rs b/libc/src/unix/linux_like/linux/musl/b32/powerpc.rs deleted file mode 100644 index 6181b1c..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/powerpc.rs +++ /dev/null @@ -1,863 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = i32; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_short, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 2], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_short, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 2], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __pad1: ::c_int, - __pad2: ::c_longlong, - __pad3: ::c_longlong - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - __unused1: ::c_int, - pub shm_atime: ::time_t, - __unused2: ::c_int, - pub shm_dtime: ::time_t, - __unused3: ::c_int, - pub shm_ctime: ::time_t, - __unused4: ::c_int, - pub shm_segsz: ::size_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - __unused1: ::c_int, - pub msg_stime: ::time_t, - __unused2: ::c_int, - pub msg_rtime: ::time_t, - __unused3: ::c_int, - pub msg_ctime: ::time_t, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - #[cfg(target_endian = "little")] - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - #[cfg(target_endian = "big")] - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } -} - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const SIGSTKSZ: ::size_t = 10240; -pub const MINSIGSTKSZ: ::size_t = 4096; - -pub const O_DIRECT: ::c_int = 0x20000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_LARGEFILE: ::c_int = 0x10000; - -pub const FIOCLEX: ::c_int = 0x20006601; -pub const FIONCLEX: ::c_int = 0x20006602; -pub const FIONBIO: ::c_int = 0x8004667E; - -pub const RLIMIT_RSS: ::c_int = 5; -pub const RLIMIT_NOFILE: ::c_int = 7; -pub const RLIMIT_AS: ::c_int = 9; -pub const RLIMIT_NPROC: ::c_int = 6; -pub const RLIMIT_MEMLOCK: ::c_int = 8; -pub const RLIMIT_NLIMITS: ::c_int = 15; - -pub const MCL_CURRENT: ::c_int = 0x2000; -pub const MCL_FUTURE: ::c_int = 0x4000; -pub const CBAUD: ::tcflag_t = 0o0000377; -pub const TAB1: ::c_int = 0x00000400; -pub const TAB2: ::c_int = 0x00000800; -pub const TAB3: ::c_int = 0x00000C00; -pub const CR1: ::c_int = 0x00001000; -pub const CR2: ::c_int = 0x00002000; -pub const CR3: ::c_int = 0x00003000; -pub const FF1: ::c_int = 0x00004000; -pub const BS1: ::c_int = 0x00008000; -pub const VT1: ::c_int = 0x00010000; -pub const VWERASE: usize = 10; -pub const VREPRINT: usize = 11; -pub const VSUSP: usize = 12; -pub const VSTART: usize = 13; -pub const VSTOP: usize = 14; -pub const VDISCARD: usize = 16; -pub const VTIME: usize = 7; -pub const IXON: ::tcflag_t = 0x00000200; -pub const IXOFF: ::tcflag_t = 0x00000400; -pub const ONLCR: ::tcflag_t = 0x00000002; -pub const CSIZE: ::tcflag_t = 0x00000300; -pub const CS6: ::tcflag_t = 0x00000100; -pub const CS7: ::tcflag_t = 0x00000200; -pub const CS8: ::tcflag_t = 0x00000300; -pub const CSTOPB: ::tcflag_t = 0x00000400; -pub const CREAD: ::tcflag_t = 0x00000800; -pub const PARENB: ::tcflag_t = 0x00001000; -pub const PARODD: ::tcflag_t = 0x00002000; -pub const HUPCL: ::tcflag_t = 0x00004000; -pub const CLOCAL: ::tcflag_t = 0x00008000; -pub const ECHOKE: ::tcflag_t = 0x00000001; -pub const ECHOE: ::tcflag_t = 0x00000002; -pub const ECHOK: ::tcflag_t = 0x00000004; -pub const ECHONL: ::tcflag_t = 0x00000010; -pub const ECHOPRT: ::tcflag_t = 0x00000020; -pub const ECHOCTL: ::tcflag_t = 0x00000040; -pub const ISIG: ::tcflag_t = 0x00000080; -pub const ICANON: ::tcflag_t = 0x00000100; -pub const PENDIN: ::tcflag_t = 0x20000000; -pub const NOFLSH: ::tcflag_t = 0x80000000; -pub const CIBAUD: ::tcflag_t = 0o00077600000; -pub const CBAUDEX: ::tcflag_t = 0o000020; -pub const VSWTC: usize = 9; -pub const OLCUC: ::tcflag_t = 0o000004; -pub const NLDLY: ::tcflag_t = 0o001400; -pub const CRDLY: ::tcflag_t = 0o030000; -pub const TABDLY: ::tcflag_t = 0o006000; -pub const BSDLY: ::tcflag_t = 0o100000; -pub const FFDLY: ::tcflag_t = 0o040000; -pub const VTDLY: ::tcflag_t = 0o200000; -pub const XTABS: ::tcflag_t = 0o006000; -pub const B57600: ::speed_t = 0o000020; -pub const B115200: ::speed_t = 0o000021; -pub const B230400: ::speed_t = 0o000022; -pub const B460800: ::speed_t = 0o000023; -pub const B500000: ::speed_t = 0o000024; -pub const B576000: ::speed_t = 0o000025; -pub const B921600: ::speed_t = 0o000026; -pub const B1000000: ::speed_t = 0o000027; -pub const B1152000: ::speed_t = 0o000030; -pub const B1500000: ::speed_t = 0o000031; -pub const B2000000: ::speed_t = 0o000032; -pub const B2500000: ::speed_t = 0o000033; -pub const B3000000: ::speed_t = 0o000034; -pub const B3500000: ::speed_t = 0o000035; -pub const B4000000: ::speed_t = 0o000036; - -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; - -pub const SOCK_NONBLOCK: ::c_int = 2048; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x00080; -pub const MAP_NORESERVE: ::c_int = 0x00040; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_SEQPACKET: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EDEADLOCK: ::c_int = 58; -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_RCVLOWAT: ::c_int = 16; -pub const SO_SNDLOWAT: ::c_int = 17; -pub const SO_RCVTIMEO: ::c_int = 18; -pub const SO_SNDTIMEO: ::c_int = 19; -pub const SO_PASSCRED: ::c_int = 20; -pub const SO_PEERCRED: ::c_int = 21; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const EXTPROC: ::tcflag_t = 0x10000000; - -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const F_GETLK: ::c_int = 12; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETLK: ::c_int = 13; -pub const F_SETLKW: ::c_int = 14; -pub const F_SETOWN: ::c_int = 8; - -pub const VEOF: usize = 4; -pub const VEOL: usize = 6; -pub const VEOL2: usize = 8; -pub const VMIN: usize = 5; -pub const IEXTEN: ::tcflag_t = 0x00000400; -pub const TOSTOP: ::tcflag_t = 0x00400000; -pub const FLUSHO: ::tcflag_t = 0x00800000; - -pub const TCGETS: ::c_int = 0x402C7413; -pub const TCSETS: ::c_int = 0x802C7414; -pub const TCSETSW: ::c_int = 0x802C7415; -pub const TCSETSF: ::c_int = 0x802C7416; -pub const TCGETA: ::c_int = 0x40147417; -pub const TCSETA: ::c_int = 0x80147418; -pub const TCSETAW: ::c_int = 0x80147419; -pub const TCSETAF: ::c_int = 0x8014741C; -pub const TCSBRK: ::c_int = 0x2000741D; -pub const TCXONC: ::c_int = 0x2000741E; -pub const TCFLSH: ::c_int = 0x2000741F; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x40047477; -pub const TIOCSPGRP: ::c_int = 0x80047476; -pub const TIOCOUTQ: ::c_int = 0x40047473; -pub const TIOCSTI: ::c_int = 0x5412; -pub const TIOCGWINSZ: ::c_int = 0x40087468; -pub const TIOCSWINSZ: ::c_int = 0x80087467; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x4004667F; -pub const TIOCCONS: ::c_int = 0x541D; - -pub const TIOCGRS485: ::c_int = 0x542e; -pub const TIOCSRS485: ::c_int = 0x542f; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -// Syscall table -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_waitpid: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_time: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_break: ::c_long = 17; -pub const SYS_oldstat: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_umount: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_stime: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_oldfstat: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_stty: ::c_long = 31; -pub const SYS_gtty: ::c_long = 32; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_ftime: ::c_long = 35; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_prof: ::c_long = 44; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_lock: ::c_long = 53; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_mpx: ::c_long = 56; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_ulimit: ::c_long = 58; -pub const SYS_oldolduname: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_sgetmask: ::c_long = 68; -pub const SYS_ssetmask: ::c_long = 69; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrlimit: ::c_long = 76; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_select: ::c_long = 82; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_oldlstat: ::c_long = 84; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_readdir: ::c_long = 89; -pub const SYS_mmap: ::c_long = 90; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_profil: ::c_long = 98; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_ioperm: ::c_long = 101; -pub const SYS_socketcall: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_olduname: ::c_long = 109; -pub const SYS_iopl: ::c_long = 110; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_idle: ::c_long = 112; -pub const SYS_vm86: ::c_long = 113; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_ipc: ::c_long = 117; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_modify_ldt: ::c_long = 123; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_create_module: ::c_long = 127; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_get_kernel_syms: ::c_long = 130; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_afs_syscall: ::c_long = 137; -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_query_module: ::c_long = 166; -pub const SYS_poll: ::c_long = 167; -pub const SYS_nfsservctl: ::c_long = 168; -pub const SYS_setresgid: ::c_long = 169; -pub const SYS_getresgid: ::c_long = 170; -pub const SYS_prctl: ::c_long = 171; -pub const SYS_rt_sigreturn: ::c_long = 172; -pub const SYS_rt_sigaction: ::c_long = 173; -pub const SYS_rt_sigprocmask: ::c_long = 174; -pub const SYS_rt_sigpending: ::c_long = 175; -pub const SYS_rt_sigtimedwait: ::c_long = 176; -pub const SYS_rt_sigqueueinfo: ::c_long = 177; -pub const SYS_rt_sigsuspend: ::c_long = 178; -pub const SYS_pread64: ::c_long = 179; -pub const SYS_pwrite64: ::c_long = 180; -pub const SYS_chown: ::c_long = 181; -pub const SYS_getcwd: ::c_long = 182; -pub const SYS_capget: ::c_long = 183; -pub const SYS_capset: ::c_long = 184; -pub const SYS_sigaltstack: ::c_long = 185; -pub const SYS_sendfile: ::c_long = 186; -pub const SYS_getpmsg: ::c_long = 187; -pub const SYS_putpmsg: ::c_long = 188; -pub const SYS_vfork: ::c_long = 189; -pub const SYS_ugetrlimit: ::c_long = 190; -pub const SYS_readahead: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_pciconfig_read: ::c_long = 198; -pub const SYS_pciconfig_write: ::c_long = 199; -pub const SYS_pciconfig_iobase: ::c_long = 200; -pub const SYS_multiplexer: ::c_long = 201; -pub const SYS_getdents64: ::c_long = 202; -pub const SYS_pivot_root: ::c_long = 203; -pub const SYS_fcntl64: ::c_long = 204; -pub const SYS_madvise: ::c_long = 205; -pub const SYS_mincore: ::c_long = 206; -pub const SYS_gettid: ::c_long = 207; -pub const SYS_tkill: ::c_long = 208; -pub const SYS_setxattr: ::c_long = 209; -pub const SYS_lsetxattr: ::c_long = 210; -pub const SYS_fsetxattr: ::c_long = 211; -pub const SYS_getxattr: ::c_long = 212; -pub const SYS_lgetxattr: ::c_long = 213; -pub const SYS_fgetxattr: ::c_long = 214; -pub const SYS_listxattr: ::c_long = 215; -pub const SYS_llistxattr: ::c_long = 216; -pub const SYS_flistxattr: ::c_long = 217; -pub const SYS_removexattr: ::c_long = 218; -pub const SYS_lremovexattr: ::c_long = 219; -pub const SYS_fremovexattr: ::c_long = 220; -pub const SYS_futex: ::c_long = 221; -pub const SYS_sched_setaffinity: ::c_long = 222; -pub const SYS_sched_getaffinity: ::c_long = 223; -pub const SYS_tuxcall: ::c_long = 225; -pub const SYS_sendfile64: ::c_long = 226; -pub const SYS_io_setup: ::c_long = 227; -pub const SYS_io_destroy: ::c_long = 228; -pub const SYS_io_getevents: ::c_long = 229; -pub const SYS_io_submit: ::c_long = 230; -pub const SYS_io_cancel: ::c_long = 231; -pub const SYS_set_tid_address: ::c_long = 232; -pub const SYS_fadvise64: ::c_long = 233; -pub const SYS_exit_group: ::c_long = 234; -pub const SYS_lookup_dcookie: ::c_long = 235; -pub const SYS_epoll_create: ::c_long = 236; -pub const SYS_epoll_ctl: ::c_long = 237; -pub const SYS_epoll_wait: ::c_long = 238; -pub const SYS_remap_file_pages: ::c_long = 239; -pub const SYS_timer_create: ::c_long = 240; -pub const SYS_timer_settime: ::c_long = 241; -pub const SYS_timer_gettime: ::c_long = 242; -pub const SYS_timer_getoverrun: ::c_long = 243; -pub const SYS_timer_delete: ::c_long = 244; -pub const SYS_clock_settime: ::c_long = 245; -pub const SYS_clock_gettime: ::c_long = 246; -pub const SYS_clock_getres: ::c_long = 247; -pub const SYS_clock_nanosleep: ::c_long = 248; -pub const SYS_swapcontext: ::c_long = 249; -pub const SYS_tgkill: ::c_long = 250; -pub const SYS_utimes: ::c_long = 251; -pub const SYS_statfs64: ::c_long = 252; -pub const SYS_fstatfs64: ::c_long = 253; -pub const SYS_fadvise64_64: ::c_long = 254; -pub const SYS_rtas: ::c_long = 255; -pub const SYS_sys_debug_setcontext: ::c_long = 256; -pub const SYS_migrate_pages: ::c_long = 258; -pub const SYS_mbind: ::c_long = 259; -pub const SYS_get_mempolicy: ::c_long = 260; -pub const SYS_set_mempolicy: ::c_long = 261; -pub const SYS_mq_open: ::c_long = 262; -pub const SYS_mq_unlink: ::c_long = 263; -pub const SYS_mq_timedsend: ::c_long = 264; -pub const SYS_mq_timedreceive: ::c_long = 265; -pub const SYS_mq_notify: ::c_long = 266; -pub const SYS_mq_getsetattr: ::c_long = 267; -pub const SYS_kexec_load: ::c_long = 268; -pub const SYS_add_key: ::c_long = 269; -pub const SYS_request_key: ::c_long = 270; -pub const SYS_keyctl: ::c_long = 271; -pub const SYS_waitid: ::c_long = 272; -pub const SYS_ioprio_set: ::c_long = 273; -pub const SYS_ioprio_get: ::c_long = 274; -pub const SYS_inotify_init: ::c_long = 275; -pub const SYS_inotify_add_watch: ::c_long = 276; -pub const SYS_inotify_rm_watch: ::c_long = 277; -pub const SYS_spu_run: ::c_long = 278; -pub const SYS_spu_create: ::c_long = 279; -pub const SYS_pselect6: ::c_long = 280; -pub const SYS_ppoll: ::c_long = 281; -pub const SYS_unshare: ::c_long = 282; -pub const SYS_splice: ::c_long = 283; -pub const SYS_tee: ::c_long = 284; -pub const SYS_vmsplice: ::c_long = 285; -pub const SYS_openat: ::c_long = 286; -pub const SYS_mkdirat: ::c_long = 287; -pub const SYS_mknodat: ::c_long = 288; -pub const SYS_fchownat: ::c_long = 289; -pub const SYS_futimesat: ::c_long = 290; -pub const SYS_fstatat64: ::c_long = 291; -pub const SYS_unlinkat: ::c_long = 292; -pub const SYS_renameat: ::c_long = 293; -pub const SYS_linkat: ::c_long = 294; -pub const SYS_symlinkat: ::c_long = 295; -pub const SYS_readlinkat: ::c_long = 296; -pub const SYS_fchmodat: ::c_long = 297; -pub const SYS_faccessat: ::c_long = 298; -pub const SYS_get_robust_list: ::c_long = 299; -pub const SYS_set_robust_list: ::c_long = 300; -pub const SYS_move_pages: ::c_long = 301; -pub const SYS_getcpu: ::c_long = 302; -pub const SYS_epoll_pwait: ::c_long = 303; -pub const SYS_utimensat: ::c_long = 304; -pub const SYS_signalfd: ::c_long = 305; -pub const SYS_timerfd_create: ::c_long = 306; -pub const SYS_eventfd: ::c_long = 307; -pub const SYS_sync_file_range2: ::c_long = 308; -pub const SYS_fallocate: ::c_long = 309; -pub const SYS_subpage_prot: ::c_long = 310; -pub const SYS_timerfd_settime: ::c_long = 311; -pub const SYS_timerfd_gettime: ::c_long = 312; -pub const SYS_signalfd4: ::c_long = 313; -pub const SYS_eventfd2: ::c_long = 314; -pub const SYS_epoll_create1: ::c_long = 315; -pub const SYS_dup3: ::c_long = 316; -pub const SYS_pipe2: ::c_long = 317; -pub const SYS_inotify_init1: ::c_long = 318; -pub const SYS_perf_event_open: ::c_long = 319; -pub const SYS_preadv: ::c_long = 320; -pub const SYS_pwritev: ::c_long = 321; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 322; -pub const SYS_fanotify_init: ::c_long = 323; -pub const SYS_fanotify_mark: ::c_long = 324; -pub const SYS_prlimit64: ::c_long = 325; -pub const SYS_socket: ::c_long = 326; -pub const SYS_bind: ::c_long = 327; -pub const SYS_connect: ::c_long = 328; -pub const SYS_listen: ::c_long = 329; -pub const SYS_accept: ::c_long = 330; -pub const SYS_getsockname: ::c_long = 331; -pub const SYS_getpeername: ::c_long = 332; -pub const SYS_socketpair: ::c_long = 333; -pub const SYS_send: ::c_long = 334; -pub const SYS_sendto: ::c_long = 335; -pub const SYS_recv: ::c_long = 336; -pub const SYS_recvfrom: ::c_long = 337; -pub const SYS_shutdown: ::c_long = 338; -pub const SYS_setsockopt: ::c_long = 339; -pub const SYS_getsockopt: ::c_long = 340; -pub const SYS_sendmsg: ::c_long = 341; -pub const SYS_recvmsg: ::c_long = 342; -pub const SYS_recvmmsg: ::c_long = 343; -pub const SYS_accept4: ::c_long = 344; -pub const SYS_name_to_handle_at: ::c_long = 345; -pub const SYS_open_by_handle_at: ::c_long = 346; -pub const SYS_clock_adjtime: ::c_long = 347; -pub const SYS_syncfs: ::c_long = 348; -pub const SYS_sendmmsg: ::c_long = 349; -pub const SYS_setns: ::c_long = 350; -pub const SYS_process_vm_readv: ::c_long = 351; -pub const SYS_process_vm_writev: ::c_long = 352; -pub const SYS_finit_module: ::c_long = 353; -pub const SYS_kcmp: ::c_long = 354; -pub const SYS_sched_setattr: ::c_long = 355; -pub const SYS_sched_getattr: ::c_long = 356; -pub const SYS_renameat2: ::c_long = 357; -pub const SYS_seccomp: ::c_long = 358; -pub const SYS_getrandom: ::c_long = 359; -pub const SYS_memfd_create: ::c_long = 360; -pub const SYS_bpf: ::c_long = 361; -pub const SYS_execveat: ::c_long = 362; -pub const SYS_switch_endian: ::c_long = 363; -pub const SYS_userfaultfd: ::c_long = 364; -pub const SYS_membarrier: ::c_long = 365; -pub const SYS_mlock2: ::c_long = 378; -pub const SYS_copy_file_range: ::c_long = 379; -pub const SYS_preadv2: ::c_long = 380; -pub const SYS_pwritev2: ::c_long = 381; -pub const SYS_kexec_file_load: ::c_long = 382; -pub const SYS_statx: ::c_long = 383; -pub const SYS_pkey_alloc: ::c_long = 384; -pub const SYS_pkey_free: ::c_long = 385; -pub const SYS_pkey_mprotect: ::c_long = 386; - -extern "C" { - pub fn getrandom( - buf: *mut ::c_void, - buflen: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; -} diff --git a/libc/src/unix/linux_like/linux/musl/b32/x86/align.rs b/libc/src/unix/linux_like/linux/musl/b32/x86/align.rs deleted file mode 100644 index 7954417..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/x86/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(8))] - pub struct max_align_t { - priv_: [f64; 3] - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b32/x86/mod.rs b/libc/src/unix/linux_like/linux/musl/b32/x86/mod.rs deleted file mode 100644 index fcd8ae4..0000000 --- a/libc/src/unix/linux_like/linux/musl/b32/x86/mod.rs +++ /dev/null @@ -1,954 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - __st_dev_padding: ::c_int, - __st_ino_truncated: ::c_long, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_int, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino_t, - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __st_dev_padding: ::c_int, - __st_ino_truncated: ::c_long, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __st_rdev_padding: ::c_int, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_ino: ::ino_t, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __unused1: ::c_long, - __unused2: ::c_long - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - __unused1: ::c_int, - pub shm_dtime: ::time_t, - __unused2: ::c_int, - pub shm_ctime: ::time_t, - __unused3: ::c_int, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - __unused1: ::c_int, - pub msg_rtime: ::time_t, - __unused2: ::c_int, - pub msg_ctime: ::time_t, - __unused3: ::c_int, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct mcontext_t { - __private: [u32; 22] - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } - - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - __f_unused: ::c_int, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } -} - -s_no_extra_traits! { - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 112], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for ucontext_t { - fn eq(&self, other: &ucontext_t) -> bool { - self.uc_flags == other.uc_flags - && self.uc_link == other.uc_link - && self.uc_stack == other.uc_stack - && self.uc_mcontext == other.uc_mcontext - && self.uc_sigmask == other.uc_sigmask - && self - .__private - .iter() - .zip(other.__private.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for ucontext_t {} - - impl ::fmt::Debug for ucontext_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("ucontext_t") - .field("uc_flags", &self.uc_flags) - .field("uc_link", &self.uc_link) - .field("uc_stack", &self.uc_stack) - .field("uc_mcontext", &self.uc_mcontext) - .field("uc_sigmask", &self.uc_sigmask) - // Ignore __private field - .finish() - } - } - - impl ::hash::Hash for ucontext_t { - fn hash(&self, state: &mut H) { - self.uc_flags.hash(state); - self.uc_link.hash(state); - self.uc_stack.hash(state); - self.uc_mcontext.hash(state); - self.uc_sigmask.hash(state); - self.__private.hash(state); - } - } - } -} - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; - -pub const O_DIRECT: ::c_int = 0x4000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; -pub const O_ASYNC: ::c_int = 0x2000; -pub const O_LARGEFILE: ::c_int = 0o0100000; - -pub const FIOCLEX: ::c_int = 0x5451; -pub const FIONCLEX: ::c_int = 0x5450; -pub const FIONBIO: ::c_int = 0x5421; - -pub const RLIMIT_RSS: ::c_int = 5; -pub const RLIMIT_NOFILE: ::c_int = 7; -pub const RLIMIT_AS: ::c_int = 9; -pub const RLIMIT_NPROC: ::c_int = 6; -pub const RLIMIT_MEMLOCK: ::c_int = 8; -pub const RLIMIT_NLIMITS: ::c_int = 15; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::c_int = 0x00000800; -pub const TAB2: ::c_int = 0x00001000; -pub const TAB3: ::c_int = 0x00001800; -pub const CR1: ::c_int = 0x00000200; -pub const CR2: ::c_int = 0x00000400; -pub const CR3: ::c_int = 0x00000600; -pub const FF1: ::c_int = 0x00008000; -pub const BS1: ::c_int = 0x00002000; -pub const VT1: ::c_int = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const O_APPEND: ::c_int = 1024; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; - -pub const SOCK_NONBLOCK: ::c_int = 2048; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_SEQPACKET: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = 1; - -pub const EDEADLK: ::c_int = 35; -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EDEADLOCK: ::c_int = EDEADLK; -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const EXTPROC: ::tcflag_t = 0x00010000; - -pub const MAP_HUGETLB: ::c_int = 0x040000; -pub const MAP_32BIT: ::c_int = 0x0040; - -pub const F_GETLK: ::c_int = 12; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETLK: ::c_int = 13; -pub const F_SETLKW: ::c_int = 14; -pub const F_SETOWN: ::c_int = 8; - -pub const VEOF: usize = 4; -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; - -pub const TCGETS: ::c_int = 0x5401; -pub const TCSETS: ::c_int = 0x5402; -pub const TCSETSW: ::c_int = 0x5403; -pub const TCSETSF: ::c_int = 0x5404; -pub const TCGETA: ::c_int = 0x5405; -pub const TCSETA: ::c_int = 0x5406; -pub const TCSETAW: ::c_int = 0x5407; -pub const TCSETAF: ::c_int = 0x5408; -pub const TCSBRK: ::c_int = 0x5409; -pub const TCXONC: ::c_int = 0x540A; -pub const TCFLSH: ::c_int = 0x540B; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x540F; -pub const TIOCSPGRP: ::c_int = 0x5410; -pub const TIOCOUTQ: ::c_int = 0x5411; -pub const TIOCSTI: ::c_int = 0x5412; -pub const TIOCGWINSZ: ::c_int = 0x5413; -pub const TIOCSWINSZ: ::c_int = 0x5414; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x541B; -pub const TIOCCONS: ::c_int = 0x541D; - -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -// Syscall table -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_waitpid: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_time: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_break: ::c_long = 17; -pub const SYS_oldstat: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_umount: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_stime: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_oldfstat: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_stty: ::c_long = 31; -pub const SYS_gtty: ::c_long = 32; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_ftime: ::c_long = 35; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_prof: ::c_long = 44; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_lock: ::c_long = 53; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_mpx: ::c_long = 56; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_ulimit: ::c_long = 58; -pub const SYS_oldolduname: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_sgetmask: ::c_long = 68; -pub const SYS_ssetmask: ::c_long = 69; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrlimit: ::c_long = 76; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_select: ::c_long = 82; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_oldlstat: ::c_long = 84; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_readdir: ::c_long = 89; -pub const SYS_mmap: ::c_long = 90; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_profil: ::c_long = 98; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_ioperm: ::c_long = 101; -pub const SYS_socketcall: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_olduname: ::c_long = 109; -pub const SYS_iopl: ::c_long = 110; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_idle: ::c_long = 112; -pub const SYS_vm86old: ::c_long = 113; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_ipc: ::c_long = 117; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_modify_ldt: ::c_long = 123; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_create_module: ::c_long = 127; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_get_kernel_syms: ::c_long = 130; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_afs_syscall: ::c_long = 137; -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_vm86: ::c_long = 166; -pub const SYS_query_module: ::c_long = 167; -pub const SYS_poll: ::c_long = 168; -pub const SYS_nfsservctl: ::c_long = 169; -pub const SYS_setresgid: ::c_long = 170; -pub const SYS_getresgid: ::c_long = 171; -pub const SYS_prctl: ::c_long = 172; -pub const SYS_rt_sigreturn: ::c_long = 173; -pub const SYS_rt_sigaction: ::c_long = 174; -pub const SYS_rt_sigprocmask: ::c_long = 175; -pub const SYS_rt_sigpending: ::c_long = 176; -pub const SYS_rt_sigtimedwait: ::c_long = 177; -pub const SYS_rt_sigqueueinfo: ::c_long = 178; -pub const SYS_rt_sigsuspend: ::c_long = 179; -pub const SYS_pread64: ::c_long = 180; -pub const SYS_pwrite64: ::c_long = 181; -pub const SYS_chown: ::c_long = 182; -pub const SYS_getcwd: ::c_long = 183; -pub const SYS_capget: ::c_long = 184; -pub const SYS_capset: ::c_long = 185; -pub const SYS_sigaltstack: ::c_long = 186; -pub const SYS_sendfile: ::c_long = 187; -pub const SYS_getpmsg: ::c_long = 188; -pub const SYS_putpmsg: ::c_long = 189; -pub const SYS_vfork: ::c_long = 190; -pub const SYS_ugetrlimit: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_lchown32: ::c_long = 198; -pub const SYS_getuid32: ::c_long = 199; -pub const SYS_getgid32: ::c_long = 200; -pub const SYS_geteuid32: ::c_long = 201; -pub const SYS_getegid32: ::c_long = 202; -pub const SYS_setreuid32: ::c_long = 203; -pub const SYS_setregid32: ::c_long = 204; -pub const SYS_getgroups32: ::c_long = 205; -pub const SYS_setgroups32: ::c_long = 206; -pub const SYS_fchown32: ::c_long = 207; -pub const SYS_setresuid32: ::c_long = 208; -pub const SYS_getresuid32: ::c_long = 209; -pub const SYS_setresgid32: ::c_long = 210; -pub const SYS_getresgid32: ::c_long = 211; -pub const SYS_chown32: ::c_long = 212; -pub const SYS_setuid32: ::c_long = 213; -pub const SYS_setgid32: ::c_long = 214; -pub const SYS_setfsuid32: ::c_long = 215; -pub const SYS_setfsgid32: ::c_long = 216; -pub const SYS_pivot_root: ::c_long = 217; -pub const SYS_mincore: ::c_long = 218; -pub const SYS_madvise: ::c_long = 219; -pub const SYS_getdents64: ::c_long = 220; -pub const SYS_fcntl64: ::c_long = 221; -pub const SYS_gettid: ::c_long = 224; -pub const SYS_readahead: ::c_long = 225; -pub const SYS_setxattr: ::c_long = 226; -pub const SYS_lsetxattr: ::c_long = 227; -pub const SYS_fsetxattr: ::c_long = 228; -pub const SYS_getxattr: ::c_long = 229; -pub const SYS_lgetxattr: ::c_long = 230; -pub const SYS_fgetxattr: ::c_long = 231; -pub const SYS_listxattr: ::c_long = 232; -pub const SYS_llistxattr: ::c_long = 233; -pub const SYS_flistxattr: ::c_long = 234; -pub const SYS_removexattr: ::c_long = 235; -pub const SYS_lremovexattr: ::c_long = 236; -pub const SYS_fremovexattr: ::c_long = 237; -pub const SYS_tkill: ::c_long = 238; -pub const SYS_sendfile64: ::c_long = 239; -pub const SYS_futex: ::c_long = 240; -pub const SYS_sched_setaffinity: ::c_long = 241; -pub const SYS_sched_getaffinity: ::c_long = 242; -pub const SYS_set_thread_area: ::c_long = 243; -pub const SYS_get_thread_area: ::c_long = 244; -pub const SYS_io_setup: ::c_long = 245; -pub const SYS_io_destroy: ::c_long = 246; -pub const SYS_io_getevents: ::c_long = 247; -pub const SYS_io_submit: ::c_long = 248; -pub const SYS_io_cancel: ::c_long = 249; -pub const SYS_fadvise64: ::c_long = 250; -pub const SYS_exit_group: ::c_long = 252; -pub const SYS_lookup_dcookie: ::c_long = 253; -pub const SYS_epoll_create: ::c_long = 254; -pub const SYS_epoll_ctl: ::c_long = 255; -pub const SYS_epoll_wait: ::c_long = 256; -pub const SYS_remap_file_pages: ::c_long = 257; -pub const SYS_set_tid_address: ::c_long = 258; -pub const SYS_timer_create: ::c_long = 259; -pub const SYS_timer_settime: ::c_long = 260; -pub const SYS_timer_gettime: ::c_long = 261; -pub const SYS_timer_getoverrun: ::c_long = 262; -pub const SYS_timer_delete: ::c_long = 263; -pub const SYS_clock_settime: ::c_long = 264; -pub const SYS_clock_gettime: ::c_long = 265; -pub const SYS_clock_getres: ::c_long = 266; -pub const SYS_clock_nanosleep: ::c_long = 267; -pub const SYS_statfs64: ::c_long = 268; -pub const SYS_fstatfs64: ::c_long = 269; -pub const SYS_tgkill: ::c_long = 270; -pub const SYS_utimes: ::c_long = 271; -pub const SYS_fadvise64_64: ::c_long = 272; -pub const SYS_vserver: ::c_long = 273; -pub const SYS_mbind: ::c_long = 274; -pub const SYS_get_mempolicy: ::c_long = 275; -pub const SYS_set_mempolicy: ::c_long = 276; -pub const SYS_mq_open: ::c_long = 277; -pub const SYS_mq_unlink: ::c_long = 278; -pub const SYS_mq_timedsend: ::c_long = 279; -pub const SYS_mq_timedreceive: ::c_long = 280; -pub const SYS_mq_notify: ::c_long = 281; -pub const SYS_mq_getsetattr: ::c_long = 282; -pub const SYS_kexec_load: ::c_long = 283; -pub const SYS_waitid: ::c_long = 284; -pub const SYS_add_key: ::c_long = 286; -pub const SYS_request_key: ::c_long = 287; -pub const SYS_keyctl: ::c_long = 288; -pub const SYS_ioprio_set: ::c_long = 289; -pub const SYS_ioprio_get: ::c_long = 290; -pub const SYS_inotify_init: ::c_long = 291; -pub const SYS_inotify_add_watch: ::c_long = 292; -pub const SYS_inotify_rm_watch: ::c_long = 293; -pub const SYS_migrate_pages: ::c_long = 294; -pub const SYS_openat: ::c_long = 295; -pub const SYS_mkdirat: ::c_long = 296; -pub const SYS_mknodat: ::c_long = 297; -pub const SYS_fchownat: ::c_long = 298; -pub const SYS_futimesat: ::c_long = 299; -pub const SYS_fstatat64: ::c_long = 300; -pub const SYS_unlinkat: ::c_long = 301; -pub const SYS_renameat: ::c_long = 302; -pub const SYS_linkat: ::c_long = 303; -pub const SYS_symlinkat: ::c_long = 304; -pub const SYS_readlinkat: ::c_long = 305; -pub const SYS_fchmodat: ::c_long = 306; -pub const SYS_faccessat: ::c_long = 307; -pub const SYS_pselect6: ::c_long = 308; -pub const SYS_ppoll: ::c_long = 309; -pub const SYS_unshare: ::c_long = 310; -pub const SYS_set_robust_list: ::c_long = 311; -pub const SYS_get_robust_list: ::c_long = 312; -pub const SYS_splice: ::c_long = 313; -pub const SYS_sync_file_range: ::c_long = 314; -pub const SYS_tee: ::c_long = 315; -pub const SYS_vmsplice: ::c_long = 316; -pub const SYS_move_pages: ::c_long = 317; -pub const SYS_getcpu: ::c_long = 318; -pub const SYS_epoll_pwait: ::c_long = 319; -pub const SYS_utimensat: ::c_long = 320; -pub const SYS_signalfd: ::c_long = 321; -pub const SYS_timerfd_create: ::c_long = 322; -pub const SYS_eventfd: ::c_long = 323; -pub const SYS_fallocate: ::c_long = 324; -pub const SYS_timerfd_settime: ::c_long = 325; -pub const SYS_timerfd_gettime: ::c_long = 326; -pub const SYS_signalfd4: ::c_long = 327; -pub const SYS_eventfd2: ::c_long = 328; -pub const SYS_epoll_create1: ::c_long = 329; -pub const SYS_dup3: ::c_long = 330; -pub const SYS_pipe2: ::c_long = 331; -pub const SYS_inotify_init1: ::c_long = 332; -pub const SYS_preadv: ::c_long = 333; -pub const SYS_pwritev: ::c_long = 334; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 335; -pub const SYS_perf_event_open: ::c_long = 336; -pub const SYS_recvmmsg: ::c_long = 337; -pub const SYS_fanotify_init: ::c_long = 338; -pub const SYS_fanotify_mark: ::c_long = 339; -pub const SYS_prlimit64: ::c_long = 340; -pub const SYS_name_to_handle_at: ::c_long = 341; -pub const SYS_open_by_handle_at: ::c_long = 342; -pub const SYS_clock_adjtime: ::c_long = 343; -pub const SYS_syncfs: ::c_long = 344; -pub const SYS_sendmmsg: ::c_long = 345; -pub const SYS_setns: ::c_long = 346; -pub const SYS_process_vm_readv: ::c_long = 347; -pub const SYS_process_vm_writev: ::c_long = 348; -pub const SYS_kcmp: ::c_long = 349; -pub const SYS_finit_module: ::c_long = 350; -pub const SYS_sched_setattr: ::c_long = 351; -pub const SYS_sched_getattr: ::c_long = 352; -pub const SYS_renameat2: ::c_long = 353; -pub const SYS_seccomp: ::c_long = 354; -pub const SYS_getrandom: ::c_long = 355; -pub const SYS_memfd_create: ::c_long = 356; -pub const SYS_bpf: ::c_long = 357; -pub const SYS_execveat: ::c_long = 358; -pub const SYS_socket: ::c_long = 359; -pub const SYS_socketpair: ::c_long = 360; -pub const SYS_bind: ::c_long = 361; -pub const SYS_connect: ::c_long = 362; -pub const SYS_listen: ::c_long = 363; -pub const SYS_accept4: ::c_long = 364; -pub const SYS_getsockopt: ::c_long = 365; -pub const SYS_setsockopt: ::c_long = 366; -pub const SYS_getsockname: ::c_long = 367; -pub const SYS_getpeername: ::c_long = 368; -pub const SYS_sendto: ::c_long = 369; -pub const SYS_sendmsg: ::c_long = 370; -pub const SYS_recvfrom: ::c_long = 371; -pub const SYS_recvmsg: ::c_long = 372; -pub const SYS_shutdown: ::c_long = 373; -pub const SYS_userfaultfd: ::c_long = 374; -pub const SYS_membarrier: ::c_long = 375; -pub const SYS_mlock2: ::c_long = 376; -pub const SYS_copy_file_range: ::c_long = 377; -pub const SYS_preadv2: ::c_long = 378; -pub const SYS_pwritev2: ::c_long = 379; -pub const SYS_pkey_mprotect: ::c_long = 380; -pub const SYS_pkey_alloc: ::c_long = 381; -pub const SYS_pkey_free: ::c_long = 382; -pub const SYS_statx: ::c_long = 383; - -// offsets in user_regs_structs, from sys/reg.h -pub const EBX: ::c_int = 0; -pub const ECX: ::c_int = 1; -pub const EDX: ::c_int = 2; -pub const ESI: ::c_int = 3; -pub const EDI: ::c_int = 4; -pub const EBP: ::c_int = 5; -pub const EAX: ::c_int = 6; -pub const DS: ::c_int = 7; -pub const ES: ::c_int = 8; -pub const FS: ::c_int = 9; -pub const GS: ::c_int = 10; -pub const ORIG_EAX: ::c_int = 11; -pub const EIP: ::c_int = 12; -pub const CS: ::c_int = 13; -pub const EFL: ::c_int = 14; -pub const UESP: ::c_int = 15; -pub const SS: ::c_int = 16; - -extern "C" { - pub fn getrandom( - buf: *mut ::c_void, - buflen: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b64/aarch64/align.rs b/libc/src/unix/linux_like/linux/musl/b64/aarch64/align.rs deleted file mode 100644 index 8e94996..0000000 --- a/libc/src/unix/linux_like/linux/musl/b64/aarch64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f32; 8] - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs b/libc/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs deleted file mode 100644 index 876ff3c..0000000 --- a/libc/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs +++ /dev/null @@ -1,655 +0,0 @@ -pub type c_char = u8; -pub type __u64 = ::c_ulonglong; -pub type wchar_t = u32; -pub type nlink_t = u32; -pub type blksize_t = ::c_int; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad0: ::c_ulong, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - __pad1: ::c_int, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_uint; 2], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad0: ::c_ulong, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - __pad1: ::c_int, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_uint; 2], - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong, - } -} - -pub const O_APPEND: ::c_int = 1024; -pub const O_DIRECT: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_LARGEFILE: ::c_int = 0x20000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_ASYNC: ::c_int = 0x2000; - -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOL_SOCKET: ::c_int = 1; -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; -pub const F_SETOWN: ::c_int = 8; - -pub const VEOF: usize = 4; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const MINSIGSTKSZ: ::size_t = 6144; -pub const SIGSTKSZ: ::size_t = 12288; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const SYS_io_setup: ::c_long = 0; -pub const SYS_io_destroy: ::c_long = 1; -pub const SYS_io_submit: ::c_long = 2; -pub const SYS_io_cancel: ::c_long = 3; -pub const SYS_io_getevents: ::c_long = 4; -pub const SYS_setxattr: ::c_long = 5; -pub const SYS_lsetxattr: ::c_long = 6; -pub const SYS_fsetxattr: ::c_long = 7; -pub const SYS_getxattr: ::c_long = 8; -pub const SYS_lgetxattr: ::c_long = 9; -pub const SYS_fgetxattr: ::c_long = 10; -pub const SYS_listxattr: ::c_long = 11; -pub const SYS_llistxattr: ::c_long = 12; -pub const SYS_flistxattr: ::c_long = 13; -pub const SYS_removexattr: ::c_long = 14; -pub const SYS_lremovexattr: ::c_long = 15; -pub const SYS_fremovexattr: ::c_long = 16; -pub const SYS_getcwd: ::c_long = 17; -pub const SYS_lookup_dcookie: ::c_long = 18; -pub const SYS_eventfd2: ::c_long = 19; -pub const SYS_epoll_create1: ::c_long = 20; -pub const SYS_epoll_ctl: ::c_long = 21; -pub const SYS_epoll_pwait: ::c_long = 22; -pub const SYS_dup: ::c_long = 23; -pub const SYS_dup3: ::c_long = 24; -pub const SYS_fcntl: ::c_long = 25; -pub const SYS_inotify_init1: ::c_long = 26; -pub const SYS_inotify_add_watch: ::c_long = 27; -pub const SYS_inotify_rm_watch: ::c_long = 28; -pub const SYS_ioctl: ::c_long = 29; -pub const SYS_ioprio_set: ::c_long = 30; -pub const SYS_ioprio_get: ::c_long = 31; -pub const SYS_flock: ::c_long = 32; -pub const SYS_mknodat: ::c_long = 33; -pub const SYS_mkdirat: ::c_long = 34; -pub const SYS_unlinkat: ::c_long = 35; -pub const SYS_symlinkat: ::c_long = 36; -pub const SYS_linkat: ::c_long = 37; -pub const SYS_renameat: ::c_long = 38; -pub const SYS_umount2: ::c_long = 39; -pub const SYS_mount: ::c_long = 40; -pub const SYS_pivot_root: ::c_long = 41; -pub const SYS_nfsservctl: ::c_long = 42; -pub const SYS_fallocate: ::c_long = 47; -pub const SYS_faccessat: ::c_long = 48; -pub const SYS_chdir: ::c_long = 49; -pub const SYS_fchdir: ::c_long = 50; -pub const SYS_chroot: ::c_long = 51; -pub const SYS_fchmod: ::c_long = 52; -pub const SYS_fchmodat: ::c_long = 53; -pub const SYS_fchownat: ::c_long = 54; -pub const SYS_fchown: ::c_long = 55; -pub const SYS_openat: ::c_long = 56; -pub const SYS_close: ::c_long = 57; -pub const SYS_vhangup: ::c_long = 58; -pub const SYS_pipe2: ::c_long = 59; -pub const SYS_quotactl: ::c_long = 60; -pub const SYS_getdents64: ::c_long = 61; -pub const SYS_lseek: ::c_long = 62; -pub const SYS_read: ::c_long = 63; -pub const SYS_write: ::c_long = 64; -pub const SYS_readv: ::c_long = 65; -pub const SYS_writev: ::c_long = 66; -pub const SYS_pread64: ::c_long = 67; -pub const SYS_pwrite64: ::c_long = 68; -pub const SYS_preadv: ::c_long = 69; -pub const SYS_pwritev: ::c_long = 70; -pub const SYS_pselect6: ::c_long = 72; -pub const SYS_ppoll: ::c_long = 73; -pub const SYS_signalfd4: ::c_long = 74; -pub const SYS_vmsplice: ::c_long = 75; -pub const SYS_splice: ::c_long = 76; -pub const SYS_tee: ::c_long = 77; -pub const SYS_readlinkat: ::c_long = 78; -pub const SYS_newfstatat: ::c_long = 79; -pub const SYS_fstat: ::c_long = 80; -pub const SYS_sync: ::c_long = 81; -pub const SYS_fsync: ::c_long = 82; -pub const SYS_fdatasync: ::c_long = 83; -pub const SYS_sync_file_range: ::c_long = 84; -pub const SYS_timerfd_create: ::c_long = 85; -pub const SYS_timerfd_settime: ::c_long = 86; -pub const SYS_timerfd_gettime: ::c_long = 87; -pub const SYS_utimensat: ::c_long = 88; -pub const SYS_acct: ::c_long = 89; -pub const SYS_capget: ::c_long = 90; -pub const SYS_capset: ::c_long = 91; -pub const SYS_personality: ::c_long = 92; -pub const SYS_exit: ::c_long = 93; -pub const SYS_exit_group: ::c_long = 94; -pub const SYS_waitid: ::c_long = 95; -pub const SYS_set_tid_address: ::c_long = 96; -pub const SYS_unshare: ::c_long = 97; -pub const SYS_futex: ::c_long = 98; -pub const SYS_set_robust_list: ::c_long = 99; -pub const SYS_get_robust_list: ::c_long = 100; -pub const SYS_nanosleep: ::c_long = 101; -pub const SYS_getitimer: ::c_long = 102; -pub const SYS_setitimer: ::c_long = 103; -pub const SYS_kexec_load: ::c_long = 104; -pub const SYS_init_module: ::c_long = 105; -pub const SYS_delete_module: ::c_long = 106; -pub const SYS_timer_create: ::c_long = 107; -pub const SYS_timer_gettime: ::c_long = 108; -pub const SYS_timer_getoverrun: ::c_long = 109; -pub const SYS_timer_settime: ::c_long = 110; -pub const SYS_timer_delete: ::c_long = 111; -pub const SYS_clock_settime: ::c_long = 112; -pub const SYS_clock_gettime: ::c_long = 113; -pub const SYS_clock_getres: ::c_long = 114; -pub const SYS_clock_nanosleep: ::c_long = 115; -pub const SYS_syslog: ::c_long = 116; -pub const SYS_ptrace: ::c_long = 117; -pub const SYS_sched_setparam: ::c_long = 118; -pub const SYS_sched_setscheduler: ::c_long = 119; -pub const SYS_sched_getscheduler: ::c_long = 120; -pub const SYS_sched_getparam: ::c_long = 121; -pub const SYS_sched_setaffinity: ::c_long = 122; -pub const SYS_sched_getaffinity: ::c_long = 123; -pub const SYS_sched_yield: ::c_long = 124; -pub const SYS_sched_get_priority_max: ::c_long = 125; -pub const SYS_sched_get_priority_min: ::c_long = 126; -pub const SYS_sched_rr_get_interval: ::c_long = 127; -pub const SYS_restart_syscall: ::c_long = 128; -pub const SYS_kill: ::c_long = 129; -pub const SYS_tkill: ::c_long = 130; -pub const SYS_tgkill: ::c_long = 131; -pub const SYS_sigaltstack: ::c_long = 132; -pub const SYS_rt_sigsuspend: ::c_long = 133; -pub const SYS_rt_sigaction: ::c_long = 134; -pub const SYS_rt_sigprocmask: ::c_long = 135; -pub const SYS_rt_sigpending: ::c_long = 136; -pub const SYS_rt_sigtimedwait: ::c_long = 137; -pub const SYS_rt_sigqueueinfo: ::c_long = 138; -pub const SYS_rt_sigreturn: ::c_long = 139; -pub const SYS_setpriority: ::c_long = 140; -pub const SYS_getpriority: ::c_long = 141; -pub const SYS_reboot: ::c_long = 142; -pub const SYS_setregid: ::c_long = 143; -pub const SYS_setgid: ::c_long = 144; -pub const SYS_setreuid: ::c_long = 145; -pub const SYS_setuid: ::c_long = 146; -pub const SYS_setresuid: ::c_long = 147; -pub const SYS_getresuid: ::c_long = 148; -pub const SYS_setresgid: ::c_long = 149; -pub const SYS_getresgid: ::c_long = 150; -pub const SYS_setfsuid: ::c_long = 151; -pub const SYS_setfsgid: ::c_long = 152; -pub const SYS_times: ::c_long = 153; -pub const SYS_setpgid: ::c_long = 154; -pub const SYS_getpgid: ::c_long = 155; -pub const SYS_getsid: ::c_long = 156; -pub const SYS_setsid: ::c_long = 157; -pub const SYS_getgroups: ::c_long = 158; -pub const SYS_setgroups: ::c_long = 159; -pub const SYS_uname: ::c_long = 160; -pub const SYS_sethostname: ::c_long = 161; -pub const SYS_setdomainname: ::c_long = 162; -pub const SYS_getrlimit: ::c_long = 163; -pub const SYS_setrlimit: ::c_long = 164; -pub const SYS_getrusage: ::c_long = 165; -pub const SYS_umask: ::c_long = 166; -pub const SYS_prctl: ::c_long = 167; -pub const SYS_getcpu: ::c_long = 168; -pub const SYS_gettimeofday: ::c_long = 169; -pub const SYS_settimeofday: ::c_long = 170; -pub const SYS_adjtimex: ::c_long = 171; -pub const SYS_getpid: ::c_long = 172; -pub const SYS_getppid: ::c_long = 173; -pub const SYS_getuid: ::c_long = 174; -pub const SYS_geteuid: ::c_long = 175; -pub const SYS_getgid: ::c_long = 176; -pub const SYS_getegid: ::c_long = 177; -pub const SYS_gettid: ::c_long = 178; -pub const SYS_sysinfo: ::c_long = 179; -pub const SYS_mq_open: ::c_long = 180; -pub const SYS_mq_unlink: ::c_long = 181; -pub const SYS_mq_timedsend: ::c_long = 182; -pub const SYS_mq_timedreceive: ::c_long = 183; -pub const SYS_mq_notify: ::c_long = 184; -pub const SYS_mq_getsetattr: ::c_long = 185; -pub const SYS_msgget: ::c_long = 186; -pub const SYS_msgctl: ::c_long = 187; -pub const SYS_msgrcv: ::c_long = 188; -pub const SYS_msgsnd: ::c_long = 189; -pub const SYS_semget: ::c_long = 190; -pub const SYS_semctl: ::c_long = 191; -pub const SYS_semtimedop: ::c_long = 192; -pub const SYS_semop: ::c_long = 193; -pub const SYS_shmget: ::c_long = 194; -pub const SYS_shmctl: ::c_long = 195; -pub const SYS_shmat: ::c_long = 196; -pub const SYS_shmdt: ::c_long = 197; -pub const SYS_socket: ::c_long = 198; -pub const SYS_socketpair: ::c_long = 199; -pub const SYS_bind: ::c_long = 200; -pub const SYS_listen: ::c_long = 201; -pub const SYS_accept: ::c_long = 202; -pub const SYS_connect: ::c_long = 203; -pub const SYS_getsockname: ::c_long = 204; -pub const SYS_getpeername: ::c_long = 205; -pub const SYS_sendto: ::c_long = 206; -pub const SYS_recvfrom: ::c_long = 207; -pub const SYS_setsockopt: ::c_long = 208; -pub const SYS_getsockopt: ::c_long = 209; -pub const SYS_shutdown: ::c_long = 210; -pub const SYS_sendmsg: ::c_long = 211; -pub const SYS_recvmsg: ::c_long = 212; -pub const SYS_readahead: ::c_long = 213; -pub const SYS_brk: ::c_long = 214; -pub const SYS_munmap: ::c_long = 215; -pub const SYS_mremap: ::c_long = 216; -pub const SYS_add_key: ::c_long = 217; -pub const SYS_request_key: ::c_long = 218; -pub const SYS_keyctl: ::c_long = 219; -pub const SYS_clone: ::c_long = 220; -pub const SYS_execve: ::c_long = 221; -pub const SYS_mmap: ::c_long = 222; -pub const SYS_swapon: ::c_long = 224; -pub const SYS_swapoff: ::c_long = 225; -pub const SYS_mprotect: ::c_long = 226; -pub const SYS_msync: ::c_long = 227; -pub const SYS_mlock: ::c_long = 228; -pub const SYS_munlock: ::c_long = 229; -pub const SYS_mlockall: ::c_long = 230; -pub const SYS_munlockall: ::c_long = 231; -pub const SYS_mincore: ::c_long = 232; -pub const SYS_madvise: ::c_long = 233; -pub const SYS_remap_file_pages: ::c_long = 234; -pub const SYS_mbind: ::c_long = 235; -pub const SYS_get_mempolicy: ::c_long = 236; -pub const SYS_set_mempolicy: ::c_long = 237; -pub const SYS_migrate_pages: ::c_long = 238; -pub const SYS_move_pages: ::c_long = 239; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 240; -pub const SYS_perf_event_open: ::c_long = 241; -pub const SYS_accept4: ::c_long = 242; -pub const SYS_recvmmsg: ::c_long = 243; -pub const SYS_wait4: ::c_long = 260; -pub const SYS_prlimit64: ::c_long = 261; -pub const SYS_fanotify_init: ::c_long = 262; -pub const SYS_fanotify_mark: ::c_long = 263; -pub const SYS_name_to_handle_at: ::c_long = 264; -pub const SYS_open_by_handle_at: ::c_long = 265; -pub const SYS_clock_adjtime: ::c_long = 266; -pub const SYS_syncfs: ::c_long = 267; -pub const SYS_setns: ::c_long = 268; -pub const SYS_sendmmsg: ::c_long = 269; -pub const SYS_process_vm_readv: ::c_long = 270; -pub const SYS_process_vm_writev: ::c_long = 271; -pub const SYS_kcmp: ::c_long = 272; -pub const SYS_finit_module: ::c_long = 273; -pub const SYS_sched_setattr: ::c_long = 274; -pub const SYS_sched_getattr: ::c_long = 275; -pub const SYS_renameat2: ::c_long = 276; -pub const SYS_seccomp: ::c_long = 277; -pub const SYS_getrandom: ::c_long = 278; -pub const SYS_memfd_create: ::c_long = 279; -pub const SYS_bpf: ::c_long = 280; -pub const SYS_execveat: ::c_long = 281; -pub const SYS_userfaultfd: ::c_long = 282; -pub const SYS_membarrier: ::c_long = 283; -pub const SYS_mlock2: ::c_long = 284; -pub const SYS_copy_file_range: ::c_long = 285; -pub const SYS_preadv2: ::c_long = 286; -pub const SYS_pwritev2: ::c_long = 287; -pub const SYS_pkey_mprotect: ::c_long = 288; -pub const SYS_pkey_alloc: ::c_long = 289; -pub const SYS_pkey_free: ::c_long = 290; -pub const SYS_statx: ::c_long = 291; - -pub const RLIMIT_NLIMITS: ::c_int = 15; -pub const TIOCINQ: ::c_int = ::FIONREAD; -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::c_int = 0x00000800; -pub const TAB2: ::c_int = 0x00001000; -pub const TAB3: ::c_int = 0x00001800; -pub const CR1: ::c_int = 0x00000200; -pub const CR2: ::c_int = 0x00000400; -pub const CR3: ::c_int = 0x00000600; -pub const FF1: ::c_int = 0x00008000; -pub const BS1: ::c_int = 0x00002000; -pub const VT1: ::c_int = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const FIOCLEX: ::c_int = 0x5451; -pub const FIONCLEX: ::c_int = 0x5450; -pub const FIONBIO: ::c_int = 0x5421; -pub const EDEADLK: ::c_int = 35; -pub const EDEADLOCK: ::c_int = EDEADLK; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const EXTPROC: ::tcflag_t = 0x00010000; -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; -pub const TCGETS: ::c_int = 0x5401; -pub const TCSETS: ::c_int = 0x5402; -pub const TCSETSW: ::c_int = 0x5403; -pub const TCSETSF: ::c_int = 0x5404; -pub const TCGETA: ::c_int = 0x5405; -pub const TCSETA: ::c_int = 0x5406; -pub const TCSETAW: ::c_int = 0x5407; -pub const TCSETAF: ::c_int = 0x5408; -pub const TCSBRK: ::c_int = 0x5409; -pub const TCXONC: ::c_int = 0x540A; -pub const TCFLSH: ::c_int = 0x540B; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x540F; -pub const TIOCSPGRP: ::c_int = 0x5410; -pub const TIOCOUTQ: ::c_int = 0x5411; -pub const TIOCSTI: ::c_int = 0x5412; -pub const TIOCGWINSZ: ::c_int = 0x5413; -pub const TIOCSWINSZ: ::c_int = 0x5414; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x541B; -pub const TIOCCONS: ::c_int = 0x541D; - -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b64/mips64.rs b/libc/src/unix/linux_like/linux/musl/b64/mips64.rs deleted file mode 100644 index 2c41050..0000000 --- a/libc/src/unix/linux_like/linux/musl/b64/mips64.rs +++ /dev/null @@ -1,754 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; -pub type __u64 = ::c_ulong; -pub type nlink_t = u64; -pub type blksize_t = i64; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - __pad1: [::c_int; 3], - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: [::c_uint; 2], - pub st_size: ::off_t, - __pad3: ::c_int, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - __pad4: ::c_uint, - pub st_blocks: ::blkcnt_t, - __pad5: [::c_int; 14], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - __pad1: [::c_int; 3], - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - __pad2: [::c_uint; 2], - pub st_size: ::off_t, - __pad3: ::c_int, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - __pad4: ::c_uint, - pub st_blocks: ::blkcnt_t, - __pad5: [::c_int; 14], - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 5], - } - - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 5], - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __pad1: ::c_int, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } -} - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; - -pub const SYS_read: ::c_long = 5000 + 0; -pub const SYS_write: ::c_long = 5000 + 1; -pub const SYS_open: ::c_long = 5000 + 2; -pub const SYS_close: ::c_long = 5000 + 3; -pub const SYS_stat: ::c_long = 5000 + 4; -pub const SYS_fstat: ::c_long = 5000 + 5; -pub const SYS_lstat: ::c_long = 5000 + 6; -pub const SYS_poll: ::c_long = 5000 + 7; -pub const SYS_lseek: ::c_long = 5000 + 8; -pub const SYS_mmap: ::c_long = 5000 + 9; -pub const SYS_mprotect: ::c_long = 5000 + 10; -pub const SYS_munmap: ::c_long = 5000 + 11; -pub const SYS_brk: ::c_long = 5000 + 12; -pub const SYS_rt_sigaction: ::c_long = 5000 + 13; -pub const SYS_rt_sigprocmask: ::c_long = 5000 + 14; -pub const SYS_ioctl: ::c_long = 5000 + 15; -pub const SYS_pread64: ::c_long = 5000 + 16; -pub const SYS_pwrite64: ::c_long = 5000 + 17; -pub const SYS_readv: ::c_long = 5000 + 18; -pub const SYS_writev: ::c_long = 5000 + 19; -pub const SYS_access: ::c_long = 5000 + 20; -pub const SYS_pipe: ::c_long = 5000 + 21; -pub const SYS__newselect: ::c_long = 5000 + 22; -pub const SYS_sched_yield: ::c_long = 5000 + 23; -pub const SYS_mremap: ::c_long = 5000 + 24; -pub const SYS_msync: ::c_long = 5000 + 25; -pub const SYS_mincore: ::c_long = 5000 + 26; -pub const SYS_madvise: ::c_long = 5000 + 27; -pub const SYS_shmget: ::c_long = 5000 + 28; -pub const SYS_shmat: ::c_long = 5000 + 29; -pub const SYS_shmctl: ::c_long = 5000 + 30; -pub const SYS_dup: ::c_long = 5000 + 31; -pub const SYS_dup2: ::c_long = 5000 + 32; -pub const SYS_pause: ::c_long = 5000 + 33; -pub const SYS_nanosleep: ::c_long = 5000 + 34; -pub const SYS_getitimer: ::c_long = 5000 + 35; -pub const SYS_setitimer: ::c_long = 5000 + 36; -pub const SYS_alarm: ::c_long = 5000 + 37; -pub const SYS_getpid: ::c_long = 5000 + 38; -pub const SYS_sendfile: ::c_long = 5000 + 39; -pub const SYS_socket: ::c_long = 5000 + 40; -pub const SYS_connect: ::c_long = 5000 + 41; -pub const SYS_accept: ::c_long = 5000 + 42; -pub const SYS_sendto: ::c_long = 5000 + 43; -pub const SYS_recvfrom: ::c_long = 5000 + 44; -pub const SYS_sendmsg: ::c_long = 5000 + 45; -pub const SYS_recvmsg: ::c_long = 5000 + 46; -pub const SYS_shutdown: ::c_long = 5000 + 47; -pub const SYS_bind: ::c_long = 5000 + 48; -pub const SYS_listen: ::c_long = 5000 + 49; -pub const SYS_getsockname: ::c_long = 5000 + 50; -pub const SYS_getpeername: ::c_long = 5000 + 51; -pub const SYS_socketpair: ::c_long = 5000 + 52; -pub const SYS_setsockopt: ::c_long = 5000 + 53; -pub const SYS_getsockopt: ::c_long = 5000 + 54; -pub const SYS_clone: ::c_long = 5000 + 55; -pub const SYS_fork: ::c_long = 5000 + 56; -pub const SYS_execve: ::c_long = 5000 + 57; -pub const SYS_exit: ::c_long = 5000 + 58; -pub const SYS_wait4: ::c_long = 5000 + 59; -pub const SYS_kill: ::c_long = 5000 + 60; -pub const SYS_uname: ::c_long = 5000 + 61; -pub const SYS_semget: ::c_long = 5000 + 62; -pub const SYS_semop: ::c_long = 5000 + 63; -pub const SYS_semctl: ::c_long = 5000 + 64; -pub const SYS_shmdt: ::c_long = 5000 + 65; -pub const SYS_msgget: ::c_long = 5000 + 66; -pub const SYS_msgsnd: ::c_long = 5000 + 67; -pub const SYS_msgrcv: ::c_long = 5000 + 68; -pub const SYS_msgctl: ::c_long = 5000 + 69; -pub const SYS_fcntl: ::c_long = 5000 + 70; -pub const SYS_flock: ::c_long = 5000 + 71; -pub const SYS_fsync: ::c_long = 5000 + 72; -pub const SYS_fdatasync: ::c_long = 5000 + 73; -pub const SYS_truncate: ::c_long = 5000 + 74; -pub const SYS_ftruncate: ::c_long = 5000 + 75; -pub const SYS_getdents: ::c_long = 5000 + 76; -pub const SYS_getcwd: ::c_long = 5000 + 77; -pub const SYS_chdir: ::c_long = 5000 + 78; -pub const SYS_fchdir: ::c_long = 5000 + 79; -pub const SYS_rename: ::c_long = 5000 + 80; -pub const SYS_mkdir: ::c_long = 5000 + 81; -pub const SYS_rmdir: ::c_long = 5000 + 82; -pub const SYS_creat: ::c_long = 5000 + 83; -pub const SYS_link: ::c_long = 5000 + 84; -pub const SYS_unlink: ::c_long = 5000 + 85; -pub const SYS_symlink: ::c_long = 5000 + 86; -pub const SYS_readlink: ::c_long = 5000 + 87; -pub const SYS_chmod: ::c_long = 5000 + 88; -pub const SYS_fchmod: ::c_long = 5000 + 89; -pub const SYS_chown: ::c_long = 5000 + 90; -pub const SYS_fchown: ::c_long = 5000 + 91; -pub const SYS_lchown: ::c_long = 5000 + 92; -pub const SYS_umask: ::c_long = 5000 + 93; -pub const SYS_gettimeofday: ::c_long = 5000 + 94; -pub const SYS_getrlimit: ::c_long = 5000 + 95; -pub const SYS_getrusage: ::c_long = 5000 + 96; -pub const SYS_sysinfo: ::c_long = 5000 + 97; -pub const SYS_times: ::c_long = 5000 + 98; -pub const SYS_ptrace: ::c_long = 5000 + 99; -pub const SYS_getuid: ::c_long = 5000 + 100; -pub const SYS_syslog: ::c_long = 5000 + 101; -pub const SYS_getgid: ::c_long = 5000 + 102; -pub const SYS_setuid: ::c_long = 5000 + 103; -pub const SYS_setgid: ::c_long = 5000 + 104; -pub const SYS_geteuid: ::c_long = 5000 + 105; -pub const SYS_getegid: ::c_long = 5000 + 106; -pub const SYS_setpgid: ::c_long = 5000 + 107; -pub const SYS_getppid: ::c_long = 5000 + 108; -pub const SYS_getpgrp: ::c_long = 5000 + 109; -pub const SYS_setsid: ::c_long = 5000 + 110; -pub const SYS_setreuid: ::c_long = 5000 + 111; -pub const SYS_setregid: ::c_long = 5000 + 112; -pub const SYS_getgroups: ::c_long = 5000 + 113; -pub const SYS_setgroups: ::c_long = 5000 + 114; -pub const SYS_setresuid: ::c_long = 5000 + 115; -pub const SYS_getresuid: ::c_long = 5000 + 116; -pub const SYS_setresgid: ::c_long = 5000 + 117; -pub const SYS_getresgid: ::c_long = 5000 + 118; -pub const SYS_getpgid: ::c_long = 5000 + 119; -pub const SYS_setfsuid: ::c_long = 5000 + 120; -pub const SYS_setfsgid: ::c_long = 5000 + 121; -pub const SYS_getsid: ::c_long = 5000 + 122; -pub const SYS_capget: ::c_long = 5000 + 123; -pub const SYS_capset: ::c_long = 5000 + 124; -pub const SYS_rt_sigpending: ::c_long = 5000 + 125; -pub const SYS_rt_sigtimedwait: ::c_long = 5000 + 126; -pub const SYS_rt_sigqueueinfo: ::c_long = 5000 + 127; -pub const SYS_rt_sigsuspend: ::c_long = 5000 + 128; -pub const SYS_sigaltstack: ::c_long = 5000 + 129; -pub const SYS_utime: ::c_long = 5000 + 130; -pub const SYS_mknod: ::c_long = 5000 + 131; -pub const SYS_personality: ::c_long = 5000 + 132; -pub const SYS_ustat: ::c_long = 5000 + 133; -pub const SYS_statfs: ::c_long = 5000 + 134; -pub const SYS_fstatfs: ::c_long = 5000 + 135; -pub const SYS_sysfs: ::c_long = 5000 + 136; -pub const SYS_getpriority: ::c_long = 5000 + 137; -pub const SYS_setpriority: ::c_long = 5000 + 138; -pub const SYS_sched_setparam: ::c_long = 5000 + 139; -pub const SYS_sched_getparam: ::c_long = 5000 + 140; -pub const SYS_sched_setscheduler: ::c_long = 5000 + 141; -pub const SYS_sched_getscheduler: ::c_long = 5000 + 142; -pub const SYS_sched_get_priority_max: ::c_long = 5000 + 143; -pub const SYS_sched_get_priority_min: ::c_long = 5000 + 144; -pub const SYS_sched_rr_get_interval: ::c_long = 5000 + 145; -pub const SYS_mlock: ::c_long = 5000 + 146; -pub const SYS_munlock: ::c_long = 5000 + 147; -pub const SYS_mlockall: ::c_long = 5000 + 148; -pub const SYS_munlockall: ::c_long = 5000 + 149; -pub const SYS_vhangup: ::c_long = 5000 + 150; -pub const SYS_pivot_root: ::c_long = 5000 + 151; -pub const SYS__sysctl: ::c_long = 5000 + 152; -pub const SYS_prctl: ::c_long = 5000 + 153; -pub const SYS_adjtimex: ::c_long = 5000 + 154; -pub const SYS_setrlimit: ::c_long = 5000 + 155; -pub const SYS_chroot: ::c_long = 5000 + 156; -pub const SYS_sync: ::c_long = 5000 + 157; -pub const SYS_acct: ::c_long = 5000 + 158; -pub const SYS_settimeofday: ::c_long = 5000 + 159; -pub const SYS_mount: ::c_long = 5000 + 160; -pub const SYS_umount2: ::c_long = 5000 + 161; -pub const SYS_swapon: ::c_long = 5000 + 162; -pub const SYS_swapoff: ::c_long = 5000 + 163; -pub const SYS_reboot: ::c_long = 5000 + 164; -pub const SYS_sethostname: ::c_long = 5000 + 165; -pub const SYS_setdomainname: ::c_long = 5000 + 166; -pub const SYS_create_module: ::c_long = 5000 + 167; -pub const SYS_init_module: ::c_long = 5000 + 168; -pub const SYS_delete_module: ::c_long = 5000 + 169; -pub const SYS_get_kernel_syms: ::c_long = 5000 + 170; -pub const SYS_query_module: ::c_long = 5000 + 171; -pub const SYS_quotactl: ::c_long = 5000 + 172; -pub const SYS_nfsservctl: ::c_long = 5000 + 173; -pub const SYS_getpmsg: ::c_long = 5000 + 174; -pub const SYS_putpmsg: ::c_long = 5000 + 175; -pub const SYS_afs_syscall: ::c_long = 5000 + 176; -pub const SYS_gettid: ::c_long = 5000 + 178; -pub const SYS_readahead: ::c_long = 5000 + 179; -pub const SYS_setxattr: ::c_long = 5000 + 180; -pub const SYS_lsetxattr: ::c_long = 5000 + 181; -pub const SYS_fsetxattr: ::c_long = 5000 + 182; -pub const SYS_getxattr: ::c_long = 5000 + 183; -pub const SYS_lgetxattr: ::c_long = 5000 + 184; -pub const SYS_fgetxattr: ::c_long = 5000 + 185; -pub const SYS_listxattr: ::c_long = 5000 + 186; -pub const SYS_llistxattr: ::c_long = 5000 + 187; -pub const SYS_flistxattr: ::c_long = 5000 + 188; -pub const SYS_removexattr: ::c_long = 5000 + 189; -pub const SYS_lremovexattr: ::c_long = 5000 + 190; -pub const SYS_fremovexattr: ::c_long = 5000 + 191; -pub const SYS_tkill: ::c_long = 5000 + 192; -pub const SYS_futex: ::c_long = 5000 + 194; -pub const SYS_sched_setaffinity: ::c_long = 5000 + 195; -pub const SYS_sched_getaffinity: ::c_long = 5000 + 196; -pub const SYS_cacheflush: ::c_long = 5000 + 197; -pub const SYS_cachectl: ::c_long = 5000 + 198; -pub const SYS_sysmips: ::c_long = 5000 + 199; -pub const SYS_io_setup: ::c_long = 5000 + 200; -pub const SYS_io_destroy: ::c_long = 5000 + 201; -pub const SYS_io_getevents: ::c_long = 5000 + 202; -pub const SYS_io_submit: ::c_long = 5000 + 203; -pub const SYS_io_cancel: ::c_long = 5000 + 204; -pub const SYS_exit_group: ::c_long = 5000 + 205; -pub const SYS_lookup_dcookie: ::c_long = 5000 + 206; -pub const SYS_epoll_create: ::c_long = 5000 + 207; -pub const SYS_epoll_ctl: ::c_long = 5000 + 208; -pub const SYS_epoll_wait: ::c_long = 5000 + 209; -pub const SYS_remap_file_pages: ::c_long = 5000 + 210; -pub const SYS_rt_sigreturn: ::c_long = 5000 + 211; -pub const SYS_set_tid_address: ::c_long = 5000 + 212; -pub const SYS_restart_syscall: ::c_long = 5000 + 213; -pub const SYS_semtimedop: ::c_long = 5000 + 214; -pub const SYS_fadvise64: ::c_long = 5000 + 215; -pub const SYS_timer_create: ::c_long = 5000 + 216; -pub const SYS_timer_settime: ::c_long = 5000 + 217; -pub const SYS_timer_gettime: ::c_long = 5000 + 218; -pub const SYS_timer_getoverrun: ::c_long = 5000 + 219; -pub const SYS_timer_delete: ::c_long = 5000 + 220; -pub const SYS_clock_settime: ::c_long = 5000 + 221; -pub const SYS_clock_gettime: ::c_long = 5000 + 222; -pub const SYS_clock_getres: ::c_long = 5000 + 223; -pub const SYS_clock_nanosleep: ::c_long = 5000 + 224; -pub const SYS_tgkill: ::c_long = 5000 + 225; -pub const SYS_utimes: ::c_long = 5000 + 226; -pub const SYS_mbind: ::c_long = 5000 + 227; -pub const SYS_get_mempolicy: ::c_long = 5000 + 228; -pub const SYS_set_mempolicy: ::c_long = 5000 + 229; -pub const SYS_mq_open: ::c_long = 5000 + 230; -pub const SYS_mq_unlink: ::c_long = 5000 + 231; -pub const SYS_mq_timedsend: ::c_long = 5000 + 232; -pub const SYS_mq_timedreceive: ::c_long = 5000 + 233; -pub const SYS_mq_notify: ::c_long = 5000 + 234; -pub const SYS_mq_getsetattr: ::c_long = 5000 + 235; -pub const SYS_vserver: ::c_long = 5000 + 236; -pub const SYS_waitid: ::c_long = 5000 + 237; -/* pub const SYS_sys_setaltroot: ::c_long = 5000 + 238; */ -pub const SYS_add_key: ::c_long = 5000 + 239; -pub const SYS_request_key: ::c_long = 5000 + 240; -pub const SYS_keyctl: ::c_long = 5000 + 241; -pub const SYS_set_thread_area: ::c_long = 5000 + 242; -pub const SYS_inotify_init: ::c_long = 5000 + 243; -pub const SYS_inotify_add_watch: ::c_long = 5000 + 244; -pub const SYS_inotify_rm_watch: ::c_long = 5000 + 245; -pub const SYS_migrate_pages: ::c_long = 5000 + 246; -pub const SYS_openat: ::c_long = 5000 + 247; -pub const SYS_mkdirat: ::c_long = 5000 + 248; -pub const SYS_mknodat: ::c_long = 5000 + 249; -pub const SYS_fchownat: ::c_long = 5000 + 250; -pub const SYS_futimesat: ::c_long = 5000 + 251; -pub const SYS_newfstatat: ::c_long = 5000 + 252; -pub const SYS_unlinkat: ::c_long = 5000 + 253; -pub const SYS_renameat: ::c_long = 5000 + 254; -pub const SYS_linkat: ::c_long = 5000 + 255; -pub const SYS_symlinkat: ::c_long = 5000 + 256; -pub const SYS_readlinkat: ::c_long = 5000 + 257; -pub const SYS_fchmodat: ::c_long = 5000 + 258; -pub const SYS_faccessat: ::c_long = 5000 + 259; -pub const SYS_pselect6: ::c_long = 5000 + 260; -pub const SYS_ppoll: ::c_long = 5000 + 261; -pub const SYS_unshare: ::c_long = 5000 + 262; -pub const SYS_splice: ::c_long = 5000 + 263; -pub const SYS_sync_file_range: ::c_long = 5000 + 264; -pub const SYS_tee: ::c_long = 5000 + 265; -pub const SYS_vmsplice: ::c_long = 5000 + 266; -pub const SYS_move_pages: ::c_long = 5000 + 267; -pub const SYS_set_robust_list: ::c_long = 5000 + 268; -pub const SYS_get_robust_list: ::c_long = 5000 + 269; -pub const SYS_kexec_load: ::c_long = 5000 + 270; -pub const SYS_getcpu: ::c_long = 5000 + 271; -pub const SYS_epoll_pwait: ::c_long = 5000 + 272; -pub const SYS_ioprio_set: ::c_long = 5000 + 273; -pub const SYS_ioprio_get: ::c_long = 5000 + 274; -pub const SYS_utimensat: ::c_long = 5000 + 275; -pub const SYS_signalfd: ::c_long = 5000 + 276; -pub const SYS_timerfd: ::c_long = 5000 + 277; -pub const SYS_eventfd: ::c_long = 5000 + 278; -pub const SYS_fallocate: ::c_long = 5000 + 279; -pub const SYS_timerfd_create: ::c_long = 5000 + 280; -pub const SYS_timerfd_gettime: ::c_long = 5000 + 281; -pub const SYS_timerfd_settime: ::c_long = 5000 + 282; -pub const SYS_signalfd4: ::c_long = 5000 + 283; -pub const SYS_eventfd2: ::c_long = 5000 + 284; -pub const SYS_epoll_create1: ::c_long = 5000 + 285; -pub const SYS_dup3: ::c_long = 5000 + 286; -pub const SYS_pipe2: ::c_long = 5000 + 287; -pub const SYS_inotify_init1: ::c_long = 5000 + 288; -pub const SYS_preadv: ::c_long = 5000 + 289; -pub const SYS_pwritev: ::c_long = 5000 + 290; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 5000 + 291; -pub const SYS_perf_event_open: ::c_long = 5000 + 292; -pub const SYS_accept4: ::c_long = 5000 + 293; -pub const SYS_recvmmsg: ::c_long = 5000 + 294; -pub const SYS_fanotify_init: ::c_long = 5000 + 295; -pub const SYS_fanotify_mark: ::c_long = 5000 + 296; -pub const SYS_prlimit64: ::c_long = 5000 + 297; -pub const SYS_name_to_handle_at: ::c_long = 5000 + 298; -pub const SYS_open_by_handle_at: ::c_long = 5000 + 299; -pub const SYS_clock_adjtime: ::c_long = 5000 + 300; -pub const SYS_syncfs: ::c_long = 5000 + 301; -pub const SYS_sendmmsg: ::c_long = 5000 + 302; -pub const SYS_setns: ::c_long = 5000 + 303; -pub const SYS_process_vm_readv: ::c_long = 5000 + 304; -pub const SYS_process_vm_writev: ::c_long = 5000 + 305; -pub const SYS_kcmp: ::c_long = 5000 + 306; -pub const SYS_finit_module: ::c_long = 5000 + 307; -pub const SYS_getdents64: ::c_long = 5000 + 308; -pub const SYS_sched_setattr: ::c_long = 5000 + 309; -pub const SYS_sched_getattr: ::c_long = 5000 + 310; -pub const SYS_renameat2: ::c_long = 5000 + 311; -pub const SYS_seccomp: ::c_long = 5000 + 312; -pub const SYS_getrandom: ::c_long = 5000 + 313; -pub const SYS_memfd_create: ::c_long = 5000 + 314; -pub const SYS_bpf: ::c_long = 5000 + 315; -pub const SYS_execveat: ::c_long = 5000 + 316; -pub const SYS_userfaultfd: ::c_long = 5000 + 317; -pub const SYS_membarrier: ::c_long = 5000 + 318; -pub const SYS_mlock2: ::c_long = 5000 + 319; -pub const SYS_copy_file_range: ::c_long = 5000 + 320; -pub const SYS_preadv2: ::c_long = 5000 + 321; -pub const SYS_pwritev2: ::c_long = 5000 + 322; -pub const SYS_pkey_mprotect: ::c_long = 5000 + 323; -pub const SYS_pkey_alloc: ::c_long = 5000 + 324; -pub const SYS_pkey_free: ::c_long = 5000 + 325; -pub const SYS_statx: ::c_long = 5000 + 326; - -pub const O_DIRECT: ::c_int = 0x8000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; - -pub const O_APPEND: ::c_int = 8; -pub const O_CREAT: ::c_int = 256; -pub const O_EXCL: ::c_int = 1024; -pub const O_NOCTTY: ::c_int = 2048; -pub const O_NONBLOCK: ::c_int = 128; -pub const O_SYNC: ::c_int = 0x4010; -pub const O_RSYNC: ::c_int = 0x4010; -pub const O_DSYNC: ::c_int = 0x10; -pub const O_ASYNC: ::c_int = 0x1000; - -pub const EDEADLK: ::c_int = 45; -pub const ENAMETOOLONG: ::c_int = 78; -pub const ENOLCK: ::c_int = 46; -pub const ENOSYS: ::c_int = 89; -pub const ENOTEMPTY: ::c_int = 93; -pub const ELOOP: ::c_int = 90; -pub const ENOMSG: ::c_int = 35; -pub const EIDRM: ::c_int = 36; -pub const ECHRNG: ::c_int = 37; -pub const EL2NSYNC: ::c_int = 38; -pub const EL3HLT: ::c_int = 39; -pub const EL3RST: ::c_int = 40; -pub const ELNRNG: ::c_int = 41; -pub const EUNATCH: ::c_int = 42; -pub const ENOCSI: ::c_int = 43; -pub const EL2HLT: ::c_int = 44; -pub const EBADE: ::c_int = 50; -pub const EBADR: ::c_int = 51; -pub const EXFULL: ::c_int = 52; -pub const ENOANO: ::c_int = 53; -pub const EBADRQC: ::c_int = 54; -pub const EBADSLT: ::c_int = 55; -pub const EDEADLOCK: ::c_int = 56; -pub const EMULTIHOP: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 79; -pub const ENOTUNIQ: ::c_int = 80; -pub const EBADFD: ::c_int = 81; -pub const EBADMSG: ::c_int = 77; -pub const EREMCHG: ::c_int = 82; -pub const ELIBACC: ::c_int = 83; -pub const ELIBBAD: ::c_int = 84; -pub const ELIBSCN: ::c_int = 85; -pub const ELIBMAX: ::c_int = 86; -pub const ELIBEXEC: ::c_int = 87; -pub const EILSEQ: ::c_int = 88; -pub const ERESTART: ::c_int = 91; -pub const ESTRPIPE: ::c_int = 92; -pub const EUSERS: ::c_int = 94; -pub const ENOTSOCK: ::c_int = 95; -pub const EDESTADDRREQ: ::c_int = 96; -pub const EMSGSIZE: ::c_int = 97; -pub const EPROTOTYPE: ::c_int = 98; -pub const ENOPROTOOPT: ::c_int = 99; -pub const EPROTONOSUPPORT: ::c_int = 120; -pub const ESOCKTNOSUPPORT: ::c_int = 121; -pub const EOPNOTSUPP: ::c_int = 122; -pub const EPFNOSUPPORT: ::c_int = 123; -pub const EAFNOSUPPORT: ::c_int = 124; -pub const EADDRINUSE: ::c_int = 125; -pub const EADDRNOTAVAIL: ::c_int = 126; -pub const ENETDOWN: ::c_int = 127; -pub const ENETUNREACH: ::c_int = 128; -pub const ENETRESET: ::c_int = 129; -pub const ECONNABORTED: ::c_int = 130; -pub const ECONNRESET: ::c_int = 131; -pub const ENOBUFS: ::c_int = 132; -pub const EISCONN: ::c_int = 133; -pub const ENOTCONN: ::c_int = 134; -pub const ESHUTDOWN: ::c_int = 143; -pub const ETOOMANYREFS: ::c_int = 144; -pub const ETIMEDOUT: ::c_int = 145; -pub const ECONNREFUSED: ::c_int = 146; -pub const EHOSTDOWN: ::c_int = 147; -pub const EHOSTUNREACH: ::c_int = 148; -pub const EALREADY: ::c_int = 149; -pub const EINPROGRESS: ::c_int = 150; -pub const ESTALE: ::c_int = 151; -pub const EUCLEAN: ::c_int = 135; -pub const ENOTNAM: ::c_int = 137; -pub const ENAVAIL: ::c_int = 138; -pub const EISNAM: ::c_int = 139; -pub const EREMOTEIO: ::c_int = 140; -pub const EDQUOT: ::c_int = 1133; -pub const ENOMEDIUM: ::c_int = 159; -pub const EMEDIUMTYPE: ::c_int = 160; -pub const ECANCELED: ::c_int = 158; -pub const ENOKEY: ::c_int = 161; -pub const EKEYEXPIRED: ::c_int = 162; -pub const EKEYREVOKED: ::c_int = 163; -pub const EKEYREJECTED: ::c_int = 164; -pub const EOWNERDEAD: ::c_int = 165; -pub const ENOTRECOVERABLE: ::c_int = 166; -pub const ERFKILL: ::c_int = 167; - -pub const MAP_ANON: ::c_int = 0x800; -pub const MAP_GROWSDOWN: ::c_int = 0x1000; -pub const MAP_DENYWRITE: ::c_int = 0x2000; -pub const MAP_EXECUTABLE: ::c_int = 0x4000; -pub const MAP_LOCKED: ::c_int = 0x8000; -pub const MAP_NORESERVE: ::c_int = 0x400; -pub const MAP_POPULATE: ::c_int = 0x10000; -pub const MAP_NONBLOCK: ::c_int = 0x20000; -pub const MAP_STACK: ::c_int = 0x40000; -pub const MAP_HUGETLB: ::c_int = 0x080000; - -pub const SOCK_STREAM: ::c_int = 2; -pub const SOCK_DGRAM: ::c_int = 1; - -pub const SOL_SOCKET: ::c_int = 0xffff; - -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ACCEPTCONN: ::c_int = 0x1009; -pub const SO_PROTOCOL: ::c_int = 0x1028; -pub const SO_DOMAIN: ::c_int = 0x1029; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_PASSCRED: ::c_int = 17; -pub const SO_PEERCRED: ::c_int = 18; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_PEERSEC: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 31; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; -pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS; -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; -pub const SO_INCOMING_CPU: ::c_int = 49; -pub const SO_ATTACH_BPF: ::c_int = 50; -pub const SO_DETACH_BPF: ::c_int = SO_DETACH_FILTER; - -pub const FIOCLEX: ::c_int = 0x6601; -pub const FIONCLEX: ::c_int = 0x6602; -pub const FIONBIO: ::c_int = 0x667e; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000008; -pub const SA_NOCLDWAIT: ::c_int = 0x00010000; - -pub const SIGCHLD: ::c_int = 18; -pub const SIGBUS: ::c_int = 10; -pub const SIGTTIN: ::c_int = 26; -pub const SIGTTOU: ::c_int = 27; -pub const SIGXCPU: ::c_int = 30; -pub const SIGXFSZ: ::c_int = 31; -pub const SIGVTALRM: ::c_int = 28; -pub const SIGPROF: ::c_int = 29; -pub const SIGWINCH: ::c_int = 20; -pub const SIGUSR1: ::c_int = 16; -pub const SIGUSR2: ::c_int = 17; -pub const SIGCONT: ::c_int = 25; -pub const SIGSTOP: ::c_int = 23; -pub const SIGTSTP: ::c_int = 24; -pub const SIGURG: ::c_int = 21; -pub const SIGIO: ::c_int = 22; -pub const SIGSYS: ::c_int = 12; -pub const SIGPOLL: ::c_int = 22; -pub const SIGPWR: ::c_int = 19; -pub const SIG_SETMASK: ::c_int = 3; -pub const SIG_BLOCK: ::c_int = 0x1; -pub const SIG_UNBLOCK: ::c_int = 0x2; - -pub const POLLWRNORM: ::c_short = 0x004; -pub const POLLWRBAND: ::c_short = 0x100; - -pub const VEOF: usize = 16; -pub const VEOL: usize = 17; -pub const VEOL2: usize = 6; -pub const VMIN: usize = 4; -pub const IEXTEN: ::tcflag_t = 0x00000100; -pub const TOSTOP: ::tcflag_t = 0x00008000; -pub const FLUSHO: ::tcflag_t = 0x00002000; -pub const EXTPROC: ::tcflag_t = 0o200000; - -pub const F_GETLK: ::c_int = 14; -pub const F_GETOWN: ::c_int = 23; -pub const F_SETOWN: ::c_int = 24; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -pub const TCGETS: ::c_ulong = 0x540d; -pub const TCSETS: ::c_ulong = 0x540e; -pub const TCSETSW: ::c_ulong = 0x540f; -pub const TCSETSF: ::c_ulong = 0x5410; -pub const TCGETA: ::c_ulong = 0x5401; -pub const TCSETA: ::c_ulong = 0x5402; -pub const TCSETAW: ::c_ulong = 0x5403; -pub const TCSETAF: ::c_ulong = 0x5404; -pub const TCSBRK: ::c_ulong = 0x5405; -pub const TCXONC: ::c_ulong = 0x5406; -pub const TCFLSH: ::c_ulong = 0x5407; -pub const TIOCGSOFTCAR: ::c_ulong = 0x5481; -pub const TIOCSSOFTCAR: ::c_ulong = 0x5482; -pub const TIOCINQ: ::c_ulong = 0x467f; -pub const TIOCLINUX: ::c_ulong = 0x5483; -pub const TIOCGSERIAL: ::c_ulong = 0x5484; -pub const TIOCEXCL: ::c_ulong = 0x740d; -pub const TIOCNXCL: ::c_ulong = 0x740e; -pub const TIOCSCTTY: ::c_ulong = 0x5480; -pub const TIOCGPGRP: ::c_ulong = 0x40047477; -pub const TIOCSPGRP: ::c_ulong = 0x80047476; -pub const TIOCOUTQ: ::c_ulong = 0x7472; -pub const TIOCSTI: ::c_ulong = 0x5472; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const TIOCMGET: ::c_ulong = 0x741d; -pub const TIOCMBIS: ::c_ulong = 0x741b; -pub const TIOCMBIC: ::c_ulong = 0x741c; -pub const TIOCMSET: ::c_ulong = 0x741a; -pub const FIONREAD: ::c_ulong = 0x467f; -pub const TIOCCONS: ::c_ulong = 0x80047478; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; - -pub const BOTHER: ::speed_t = 0o010000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const TIOCM_ST: ::c_int = 0x010; -pub const TIOCM_SR: ::c_int = 0x020; -pub const TIOCM_CTS: ::c_int = 0x040; -pub const TIOCM_CAR: ::c_int = 0x100; -pub const TIOCM_RNG: ::c_int = 0x200; -pub const TIOCM_DSR: ::c_int = 0x400; - -pub const EHWPOISON: ::c_int = 168; - -extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; -} diff --git a/libc/src/unix/linux_like/linux/musl/b64/mod.rs b/libc/src/unix/linux_like/linux/musl/b64/mod.rs deleted file mode 100644 index e6a8fc8..0000000 --- a/libc/src/unix/linux_like/linux/musl/b64/mod.rs +++ /dev/null @@ -1,169 +0,0 @@ -pub type c_long = i64; -pub type c_ulong = u64; - -s! { - pub struct statfs64 { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct statvfs64 { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct pthread_attr_t { - __size: [u64; 7] - } - - pub struct sigset_t { - __val: [::c_ulong; 16], - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - pub msg_rtime: ::time_t, - pub msg_ctime: ::time_t, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_ulong, - pub f_bsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_flags: ::c_ulong, - pub f_spare: [::c_ulong; 4], - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - #[cfg(target_endian = "big")] - __pad1: ::c_int, - pub msg_iovlen: ::c_int, - #[cfg(target_endian = "little")] - __pad1: ::c_int, - pub msg_control: *mut ::c_void, - #[cfg(target_endian = "big")] - __pad2: ::c_int, - pub msg_controllen: ::socklen_t, - #[cfg(target_endian = "little")] - __pad2: ::c_int, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - #[cfg(target_endian = "big")] - pub __pad1: ::c_int, - pub cmsg_len: ::socklen_t, - #[cfg(target_endian = "little")] - pub __pad1: ::c_int, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct sem_t { - __val: [::c_int; 8], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - _align: [usize; 0], - } -} - -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; - -pub const RLIMIT_RSS: ::c_int = 5; -pub const RLIMIT_NOFILE: ::c_int = 7; -pub const RLIMIT_AS: ::c_int = 9; -pub const RLIMIT_NPROC: ::c_int = 6; -pub const RLIMIT_MEMLOCK: ::c_int = 8; - -pub const SOCK_NONBLOCK: ::c_int = 2048; - -pub const SOCK_SEQPACKET: ::c_int = 5; - -extern "C" { - pub fn getrandom( - buf: *mut ::c_void, - buflen: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; -} - -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(target_arch = "mips64")] { - mod mips64; - pub use self::mips64::*; - } else if #[cfg(any(target_arch = "powerpc64"))] { - mod powerpc64; - pub use self::powerpc64::*; - } else if #[cfg(any(target_arch = "x86_64"))] { - mod x86_64; - pub use self::x86_64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b64/powerpc64.rs b/libc/src/unix/linux_like/linux/musl/b64/powerpc64.rs deleted file mode 100644 index d27d703..0000000 --- a/libc/src/unix/linux_like/linux/musl/b64/powerpc64.rs +++ /dev/null @@ -1,739 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = i32; -pub type __u64 = ::c_ulong; -pub type nlink_t = u64; -pub type blksize_t = ::c_long; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 3], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __reserved: [::c_long; 3], - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __unused1: ::c_long, - __unused2: ::c_long - } -} - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_32BIT: ::c_int = 0x0040; -pub const O_APPEND: ::c_int = 1024; -pub const O_DIRECT: ::c_int = 0x20000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_LARGEFILE: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_ASYNC: ::c_int = 0x2000; - -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOL_SOCKET: ::c_int = 1; -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; -pub const F_SETOWN: ::c_int = 8; - -pub const VEOF: usize = 4; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const SIGSTKSZ: ::size_t = 10240; -pub const MINSIGSTKSZ: ::size_t = 4096; - -// Syscall table -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_waitpid: ::c_long = 7; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_time: ::c_long = 13; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_break: ::c_long = 17; -pub const SYS_oldstat: ::c_long = 18; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_umount: ::c_long = 22; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_stime: ::c_long = 25; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_alarm: ::c_long = 27; -pub const SYS_oldfstat: ::c_long = 28; -pub const SYS_pause: ::c_long = 29; -pub const SYS_utime: ::c_long = 30; -pub const SYS_stty: ::c_long = 31; -pub const SYS_gtty: ::c_long = 32; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_ftime: ::c_long = 35; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_prof: ::c_long = 44; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_signal: ::c_long = 48; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_lock: ::c_long = 53; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_mpx: ::c_long = 56; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_ulimit: ::c_long = 58; -pub const SYS_oldolduname: ::c_long = 59; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_sgetmask: ::c_long = 68; -pub const SYS_ssetmask: ::c_long = 69; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrlimit: ::c_long = 76; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_select: ::c_long = 82; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_oldlstat: ::c_long = 84; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_readdir: ::c_long = 89; -pub const SYS_mmap: ::c_long = 90; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_profil: ::c_long = 98; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_ioperm: ::c_long = 101; -pub const SYS_socketcall: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_olduname: ::c_long = 109; -pub const SYS_iopl: ::c_long = 110; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_idle: ::c_long = 112; -pub const SYS_vm86: ::c_long = 113; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_ipc: ::c_long = 117; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_modify_ldt: ::c_long = 123; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_create_module: ::c_long = 127; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_get_kernel_syms: ::c_long = 130; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_afs_syscall: ::c_long = 137; /* Syscall for Andrew File System */ -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_query_module: ::c_long = 166; -pub const SYS_poll: ::c_long = 167; -pub const SYS_nfsservctl: ::c_long = 168; -pub const SYS_setresgid: ::c_long = 169; -pub const SYS_getresgid: ::c_long = 170; -pub const SYS_prctl: ::c_long = 171; -pub const SYS_rt_sigreturn: ::c_long = 172; -pub const SYS_rt_sigaction: ::c_long = 173; -pub const SYS_rt_sigprocmask: ::c_long = 174; -pub const SYS_rt_sigpending: ::c_long = 175; -pub const SYS_rt_sigtimedwait: ::c_long = 176; -pub const SYS_rt_sigqueueinfo: ::c_long = 177; -pub const SYS_rt_sigsuspend: ::c_long = 178; -pub const SYS_pread64: ::c_long = 179; -pub const SYS_pwrite64: ::c_long = 180; -pub const SYS_chown: ::c_long = 181; -pub const SYS_getcwd: ::c_long = 182; -pub const SYS_capget: ::c_long = 183; -pub const SYS_capset: ::c_long = 184; -pub const SYS_sigaltstack: ::c_long = 185; -pub const SYS_sendfile: ::c_long = 186; -pub const SYS_getpmsg: ::c_long = 187; /* some people actually want streams */ -pub const SYS_putpmsg: ::c_long = 188; /* some people actually want streams */ -pub const SYS_vfork: ::c_long = 189; -pub const SYS_ugetrlimit: ::c_long = 190; /* SuS compliant getrlimit */ -pub const SYS_readahead: ::c_long = 191; -pub const SYS_pciconfig_read: ::c_long = 198; -pub const SYS_pciconfig_write: ::c_long = 199; -pub const SYS_pciconfig_iobase: ::c_long = 200; -pub const SYS_multiplexer: ::c_long = 201; -pub const SYS_getdents64: ::c_long = 202; -pub const SYS_pivot_root: ::c_long = 203; -pub const SYS_madvise: ::c_long = 205; -pub const SYS_mincore: ::c_long = 206; -pub const SYS_gettid: ::c_long = 207; -pub const SYS_tkill: ::c_long = 208; -pub const SYS_setxattr: ::c_long = 209; -pub const SYS_lsetxattr: ::c_long = 210; -pub const SYS_fsetxattr: ::c_long = 211; -pub const SYS_getxattr: ::c_long = 212; -pub const SYS_lgetxattr: ::c_long = 213; -pub const SYS_fgetxattr: ::c_long = 214; -pub const SYS_listxattr: ::c_long = 215; -pub const SYS_llistxattr: ::c_long = 216; -pub const SYS_flistxattr: ::c_long = 217; -pub const SYS_removexattr: ::c_long = 218; -pub const SYS_lremovexattr: ::c_long = 219; -pub const SYS_fremovexattr: ::c_long = 220; -pub const SYS_futex: ::c_long = 221; -pub const SYS_sched_setaffinity: ::c_long = 222; -pub const SYS_sched_getaffinity: ::c_long = 223; -pub const SYS_tuxcall: ::c_long = 225; -pub const SYS_io_setup: ::c_long = 227; -pub const SYS_io_destroy: ::c_long = 228; -pub const SYS_io_getevents: ::c_long = 229; -pub const SYS_io_submit: ::c_long = 230; -pub const SYS_io_cancel: ::c_long = 231; -pub const SYS_set_tid_address: ::c_long = 232; -pub const SYS_exit_group: ::c_long = 234; -pub const SYS_lookup_dcookie: ::c_long = 235; -pub const SYS_epoll_create: ::c_long = 236; -pub const SYS_epoll_ctl: ::c_long = 237; -pub const SYS_epoll_wait: ::c_long = 238; -pub const SYS_remap_file_pages: ::c_long = 239; -pub const SYS_timer_create: ::c_long = 240; -pub const SYS_timer_settime: ::c_long = 241; -pub const SYS_timer_gettime: ::c_long = 242; -pub const SYS_timer_getoverrun: ::c_long = 243; -pub const SYS_timer_delete: ::c_long = 244; -pub const SYS_clock_settime: ::c_long = 245; -pub const SYS_clock_gettime: ::c_long = 246; -pub const SYS_clock_getres: ::c_long = 247; -pub const SYS_clock_nanosleep: ::c_long = 248; -pub const SYS_swapcontext: ::c_long = 249; -pub const SYS_tgkill: ::c_long = 250; -pub const SYS_utimes: ::c_long = 251; -pub const SYS_statfs64: ::c_long = 252; -pub const SYS_fstatfs64: ::c_long = 253; -pub const SYS_rtas: ::c_long = 255; -pub const SYS_sys_debug_setcontext: ::c_long = 256; -pub const SYS_migrate_pages: ::c_long = 258; -pub const SYS_mbind: ::c_long = 259; -pub const SYS_get_mempolicy: ::c_long = 260; -pub const SYS_set_mempolicy: ::c_long = 261; -pub const SYS_mq_open: ::c_long = 262; -pub const SYS_mq_unlink: ::c_long = 263; -pub const SYS_mq_timedsend: ::c_long = 264; -pub const SYS_mq_timedreceive: ::c_long = 265; -pub const SYS_mq_notify: ::c_long = 266; -pub const SYS_mq_getsetattr: ::c_long = 267; -pub const SYS_kexec_load: ::c_long = 268; -pub const SYS_add_key: ::c_long = 269; -pub const SYS_request_key: ::c_long = 270; -pub const SYS_keyctl: ::c_long = 271; -pub const SYS_waitid: ::c_long = 272; -pub const SYS_ioprio_set: ::c_long = 273; -pub const SYS_ioprio_get: ::c_long = 274; -pub const SYS_inotify_init: ::c_long = 275; -pub const SYS_inotify_add_watch: ::c_long = 276; -pub const SYS_inotify_rm_watch: ::c_long = 277; -pub const SYS_spu_run: ::c_long = 278; -pub const SYS_spu_create: ::c_long = 279; -pub const SYS_pselect6: ::c_long = 280; -pub const SYS_ppoll: ::c_long = 281; -pub const SYS_unshare: ::c_long = 282; -pub const SYS_splice: ::c_long = 283; -pub const SYS_tee: ::c_long = 284; -pub const SYS_vmsplice: ::c_long = 285; -pub const SYS_openat: ::c_long = 286; -pub const SYS_mkdirat: ::c_long = 287; -pub const SYS_mknodat: ::c_long = 288; -pub const SYS_fchownat: ::c_long = 289; -pub const SYS_futimesat: ::c_long = 290; -pub const SYS_newfstatat: ::c_long = 291; -pub const SYS_unlinkat: ::c_long = 292; -pub const SYS_renameat: ::c_long = 293; -pub const SYS_linkat: ::c_long = 294; -pub const SYS_symlinkat: ::c_long = 295; -pub const SYS_readlinkat: ::c_long = 296; -pub const SYS_fchmodat: ::c_long = 297; -pub const SYS_faccessat: ::c_long = 298; -pub const SYS_get_robust_list: ::c_long = 299; -pub const SYS_set_robust_list: ::c_long = 300; -pub const SYS_move_pages: ::c_long = 301; -pub const SYS_getcpu: ::c_long = 302; -pub const SYS_epoll_pwait: ::c_long = 303; -pub const SYS_utimensat: ::c_long = 304; -pub const SYS_signalfd: ::c_long = 305; -pub const SYS_timerfd_create: ::c_long = 306; -pub const SYS_eventfd: ::c_long = 307; -pub const SYS_sync_file_range2: ::c_long = 308; -pub const SYS_fallocate: ::c_long = 309; -pub const SYS_subpage_prot: ::c_long = 310; -pub const SYS_timerfd_settime: ::c_long = 311; -pub const SYS_timerfd_gettime: ::c_long = 312; -pub const SYS_signalfd4: ::c_long = 313; -pub const SYS_eventfd2: ::c_long = 314; -pub const SYS_epoll_create1: ::c_long = 315; -pub const SYS_dup3: ::c_long = 316; -pub const SYS_pipe2: ::c_long = 317; -pub const SYS_inotify_init1: ::c_long = 318; -pub const SYS_perf_event_open: ::c_long = 319; -pub const SYS_preadv: ::c_long = 320; -pub const SYS_pwritev: ::c_long = 321; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 322; -pub const SYS_fanotify_init: ::c_long = 323; -pub const SYS_fanotify_mark: ::c_long = 324; -pub const SYS_prlimit64: ::c_long = 325; -pub const SYS_socket: ::c_long = 326; -pub const SYS_bind: ::c_long = 327; -pub const SYS_connect: ::c_long = 328; -pub const SYS_listen: ::c_long = 329; -pub const SYS_accept: ::c_long = 330; -pub const SYS_getsockname: ::c_long = 331; -pub const SYS_getpeername: ::c_long = 332; -pub const SYS_socketpair: ::c_long = 333; -pub const SYS_send: ::c_long = 334; -pub const SYS_sendto: ::c_long = 335; -pub const SYS_recv: ::c_long = 336; -pub const SYS_recvfrom: ::c_long = 337; -pub const SYS_shutdown: ::c_long = 338; -pub const SYS_setsockopt: ::c_long = 339; -pub const SYS_getsockopt: ::c_long = 340; -pub const SYS_sendmsg: ::c_long = 341; -pub const SYS_recvmsg: ::c_long = 342; -pub const SYS_recvmmsg: ::c_long = 343; -pub const SYS_accept4: ::c_long = 344; -pub const SYS_name_to_handle_at: ::c_long = 345; -pub const SYS_open_by_handle_at: ::c_long = 346; -pub const SYS_clock_adjtime: ::c_long = 347; -pub const SYS_syncfs: ::c_long = 348; -pub const SYS_sendmmsg: ::c_long = 349; -pub const SYS_setns: ::c_long = 350; -pub const SYS_process_vm_readv: ::c_long = 351; -pub const SYS_process_vm_writev: ::c_long = 352; -pub const SYS_finit_module: ::c_long = 353; -pub const SYS_kcmp: ::c_long = 354; -pub const SYS_sched_setattr: ::c_long = 355; -pub const SYS_sched_getattr: ::c_long = 356; -pub const SYS_renameat2: ::c_long = 357; -pub const SYS_seccomp: ::c_long = 358; -pub const SYS_getrandom: ::c_long = 359; -pub const SYS_memfd_create: ::c_long = 360; -pub const SYS_bpf: ::c_long = 361; -pub const SYS_execveat: ::c_long = 362; -pub const SYS_switch_endian: ::c_long = 363; -pub const SYS_userfaultfd: ::c_long = 364; -pub const SYS_membarrier: ::c_long = 365; -pub const SYS_mlock2: ::c_long = 378; -pub const SYS_copy_file_range: ::c_long = 379; -pub const SYS_preadv2: ::c_long = 380; -pub const SYS_pwritev2: ::c_long = 381; -pub const SYS_kexec_file_load: ::c_long = 382; -pub const SYS_statx: ::c_long = 383; - -pub const FIOCLEX: ::c_int = 0x20006601; -pub const FIONCLEX: ::c_int = 0x20006602; -pub const FIONBIO: ::c_int = 0x8004667e; -pub const EDEADLK: ::c_int = 58; -pub const EDEADLOCK: ::c_int = EDEADLK; -pub const SO_PASSCRED: ::c_int = 20; -pub const SO_PEERCRED: ::c_int = 21; -pub const SO_RCVLOWAT: ::c_int = 16; -pub const SO_SNDLOWAT: ::c_int = 17; -pub const SO_RCVTIMEO: ::c_int = 18; -pub const SO_SNDTIMEO: ::c_int = 19; -pub const EXTPROC: ::tcflag_t = 0x10000000; -pub const VEOL: usize = 6; -pub const VEOL2: usize = 8; -pub const VMIN: usize = 5; -pub const IEXTEN: ::tcflag_t = 0x00000400; -pub const TOSTOP: ::tcflag_t = 0x00400000; -pub const FLUSHO: ::tcflag_t = 0x00800000; -pub const TCGETS: ::c_int = 0x403c7413; -pub const TCSETS: ::c_int = 0x803c7414; -pub const TCSETSW: ::c_int = 0x803c7415; -pub const TCSETSF: ::c_int = 0x803c7416; -pub const TCGETA: ::c_int = 0x40147417; -pub const TCSETA: ::c_int = 0x80147418; -pub const TCSETAW: ::c_int = 0x80147419; -pub const TCSETAF: ::c_int = 0x8014741c; -pub const TCSBRK: ::c_int = 0x2000741d; -pub const TCXONC: ::c_int = 0x2000741e; -pub const TCFLSH: ::c_int = 0x2000741f; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x40047477; -pub const TIOCSPGRP: ::c_int = 0x80047476; -pub const TIOCOUTQ: ::c_int = 0x40047473; -pub const TIOCGWINSZ: ::c_int = 0x40087468; -pub const TIOCSWINSZ: ::c_int = 0x80087467; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x4004667f; -pub const TIOCCONS: ::c_int = 0x541D; -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; - -pub const RLIMIT_NLIMITS: ::c_int = 15; -pub const TIOCINQ: ::c_int = ::FIONREAD; -pub const MCL_CURRENT: ::c_int = 0x2000; -pub const MCL_FUTURE: ::c_int = 0x4000; -pub const CBAUD: ::tcflag_t = 0xff; -pub const TAB1: ::c_int = 0x400; -pub const TAB2: ::c_int = 0x800; -pub const TAB3: ::c_int = 0xc00; -pub const CR1: ::c_int = 0x1000; -pub const CR2: ::c_int = 0x2000; -pub const CR3: ::c_int = 0x3000; -pub const FF1: ::c_int = 0x4000; -pub const BS1: ::c_int = 0x8000; -pub const VT1: ::c_int = 0x10000; -pub const VWERASE: usize = 10; -pub const VREPRINT: usize = 11; -pub const VSUSP: usize = 12; -pub const VSTART: usize = 13; -pub const VSTOP: usize = 14; -pub const VDISCARD: usize = 16; -pub const VTIME: usize = 7; -pub const IXON: ::tcflag_t = 0x00000200; -pub const IXOFF: ::tcflag_t = 0x00000400; -pub const ONLCR: ::tcflag_t = 0x2; -pub const CSIZE: ::tcflag_t = 0x00000300; - -pub const CS6: ::tcflag_t = 0x00000100; -pub const CS7: ::tcflag_t = 0x00000200; -pub const CS8: ::tcflag_t = 0x00000300; -pub const CSTOPB: ::tcflag_t = 0x00000400; -pub const CREAD: ::tcflag_t = 0x00000800; -pub const PARENB: ::tcflag_t = 0x00001000; -pub const PARODD: ::tcflag_t = 0x00002000; -pub const HUPCL: ::tcflag_t = 0x00004000; -pub const CLOCAL: ::tcflag_t = 0x00008000; -pub const ECHOKE: ::tcflag_t = 0x00000001; -pub const ECHOE: ::tcflag_t = 0x00000002; -pub const ECHOK: ::tcflag_t = 0x00000004; -pub const ECHONL: ::tcflag_t = 0x00000010; -pub const ECHOPRT: ::tcflag_t = 0x00000020; -pub const ECHOCTL: ::tcflag_t = 0x00000040; -pub const ISIG: ::tcflag_t = 0x00000080; -pub const ICANON: ::tcflag_t = 0x00000100; -pub const PENDIN: ::tcflag_t = 0x20000000; -pub const NOFLSH: ::tcflag_t = 0x80000000; - -pub const CIBAUD: ::tcflag_t = 0o77600000; -pub const CBAUDEX: ::tcflag_t = 0o0000020; -pub const VSWTC: usize = 9; -pub const OLCUC: ::tcflag_t = 0o000004; -pub const NLDLY: ::tcflag_t = 0o0001400; -pub const CRDLY: ::tcflag_t = 0o0030000; -pub const TABDLY: ::tcflag_t = 0o0006000; -pub const BSDLY: ::tcflag_t = 0o0100000; -pub const FFDLY: ::tcflag_t = 0o0040000; -pub const VTDLY: ::tcflag_t = 0o0200000; -pub const XTABS: ::tcflag_t = 0o00006000; - -pub const B57600: ::speed_t = 0o00020; -pub const B115200: ::speed_t = 0o00021; -pub const B230400: ::speed_t = 0o00022; -pub const B460800: ::speed_t = 0o00023; -pub const B500000: ::speed_t = 0o00024; -pub const B576000: ::speed_t = 0o00025; -pub const B921600: ::speed_t = 0o00026; -pub const B1000000: ::speed_t = 0o00027; -pub const B1152000: ::speed_t = 0o00030; -pub const B1500000: ::speed_t = 0o00031; -pub const B2000000: ::speed_t = 0o00032; -pub const B2500000: ::speed_t = 0o00033; -pub const B3000000: ::speed_t = 0o00034; -pub const B3500000: ::speed_t = 0o00035; -pub const B4000000: ::speed_t = 0o00036; - -extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; -} diff --git a/libc/src/unix/linux_like/linux/musl/b64/x86_64/align.rs b/libc/src/unix/linux_like/linux/musl/b64/x86_64/align.rs deleted file mode 100644 index 7ca870f..0000000 --- a/libc/src/unix/linux_like/linux/musl/b64/x86_64/align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 4] - } -} diff --git a/libc/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs b/libc/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs deleted file mode 100644 index ff9300c..0000000 --- a/libc/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs +++ /dev/null @@ -1,961 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; -pub type nlink_t = u64; -pub type blksize_t = ::c_long; -pub type __u64 = ::c_ulonglong; -pub type greg_t = i64; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __unused: [::c_long; 3], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - __reserved: [::c_long; 3], - } - - pub struct user_regs_struct { - pub r15: ::c_ulong, - pub r14: ::c_ulong, - pub r13: ::c_ulong, - pub r12: ::c_ulong, - pub rbp: ::c_ulong, - pub rbx: ::c_ulong, - pub r11: ::c_ulong, - pub r10: ::c_ulong, - pub r9: ::c_ulong, - pub r8: ::c_ulong, - pub rax: ::c_ulong, - pub rcx: ::c_ulong, - pub rdx: ::c_ulong, - pub rsi: ::c_ulong, - pub rdi: ::c_ulong, - pub orig_rax: ::c_ulong, - pub rip: ::c_ulong, - pub cs: ::c_ulong, - pub eflags: ::c_ulong, - pub rsp: ::c_ulong, - pub ss: ::c_ulong, - pub fs_base: ::c_ulong, - pub gs_base: ::c_ulong, - pub ds: ::c_ulong, - pub es: ::c_ulong, - pub fs: ::c_ulong, - pub gs: ::c_ulong, - } - - pub struct user { - pub regs: user_regs_struct, - pub u_fpvalid: ::c_int, - pub i387: user_fpregs_struct, - pub u_tsize: ::c_ulong, - pub u_dsize: ::c_ulong, - pub u_ssize: ::c_ulong, - pub start_code: ::c_ulong, - pub start_stack: ::c_ulong, - pub signal: ::c_long, - __reserved: ::c_int, - #[cfg(target_pointer_width = "32")] - __pad1: u32, - pub u_ar0: *mut user_regs_struct, - #[cfg(target_pointer_width = "32")] - __pad2: u32, - pub u_fpstate: *mut user_fpregs_struct, - pub magic: ::c_ulong, - pub u_comm: [::c_char; 32], - pub u_debugreg: [::c_ulong; 8], - } - - // GitHub repo: ifduyue/musl/ - // commit: b4b1e10364c8737a632be61582e05a8d3acf5690 - // file: arch/x86_64/bits/signal.h#L80-L84 - pub struct mcontext_t { - pub gregs: [greg_t; 23], - __private: [u64; 9], - } - - pub struct ipc_perm { - pub __ipc_perm_key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub __seq: ::c_int, - __unused1: ::c_long, - __unused2: ::c_long - } -} - -s_no_extra_traits! { - pub struct user_fpregs_struct { - pub cwd: ::c_ushort, - pub swd: ::c_ushort, - pub ftw: ::c_ushort, - pub fop: ::c_ushort, - pub rip: ::c_ulong, - pub rdp: ::c_ulong, - pub mxcsr: ::c_uint, - pub mxcr_mask: ::c_uint, - pub st_space: [::c_uint; 32], - pub xmm_space: [::c_uint; 64], - padding: [::c_uint; 24], - } - - pub struct ucontext_t { - pub uc_flags: ::c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: ::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: ::sigset_t, - __private: [u8; 512], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for user_fpregs_struct { - fn eq(&self, other: &user_fpregs_struct) -> bool { - self.cwd == other.cwd - && self.swd == other.swd - && self.ftw == other.ftw - && self.fop == other.fop - && self.rip == other.rip - && self.rdp == other.rdp - && self.mxcsr == other.mxcsr - && self.mxcr_mask == other.mxcr_mask - && self.st_space == other.st_space - && self - .xmm_space - .iter() - .zip(other.xmm_space.iter()) - .all(|(a,b)| a == b) - // Ignore padding field - } - } - - impl Eq for user_fpregs_struct {} - - impl ::fmt::Debug for user_fpregs_struct { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("user_fpregs_struct") - .field("cwd", &self.cwd) - .field("ftw", &self.ftw) - .field("fop", &self.fop) - .field("rip", &self.rip) - .field("rdp", &self.rdp) - .field("mxcsr", &self.mxcsr) - .field("mxcr_mask", &self.mxcr_mask) - .field("st_space", &self.st_space) - // FIXME: .field("xmm_space", &self.xmm_space) - // Ignore padding field - .finish() - } - } - - impl ::hash::Hash for user_fpregs_struct { - fn hash(&self, state: &mut H) { - self.cwd.hash(state); - self.ftw.hash(state); - self.fop.hash(state); - self.rip.hash(state); - self.rdp.hash(state); - self.mxcsr.hash(state); - self.mxcr_mask.hash(state); - self.st_space.hash(state); - self.xmm_space.hash(state); - // Ignore padding field - } - } - - impl PartialEq for ucontext_t { - fn eq(&self, other: &ucontext_t) -> bool { - self.uc_flags == other.uc_flags - && self.uc_link == other.uc_link - && self.uc_stack == other.uc_stack - && self.uc_mcontext == other.uc_mcontext - && self.uc_sigmask == other.uc_sigmask - && self - .__private - .iter() - .zip(other.__private.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for ucontext_t {} - - impl ::fmt::Debug for ucontext_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("ucontext_t") - .field("uc_flags", &self.uc_flags) - .field("uc_link", &self.uc_link) - .field("uc_stack", &self.uc_stack) - .field("uc_mcontext", &self.uc_mcontext) - .field("uc_sigmask", &self.uc_sigmask) - // Ignore __private field - .finish() - } - } - - impl ::hash::Hash for ucontext_t { - fn hash(&self, state: &mut H) { - self.uc_flags.hash(state); - self.uc_link.hash(state); - self.uc_stack.hash(state); - self.uc_mcontext.hash(state); - self.uc_sigmask.hash(state); - self.__private.hash(state); - } - } - } -} - -// Syscall table - -pub const SYS_read: ::c_long = 0; -pub const SYS_write: ::c_long = 1; -pub const SYS_open: ::c_long = 2; -pub const SYS_close: ::c_long = 3; -pub const SYS_stat: ::c_long = 4; -pub const SYS_fstat: ::c_long = 5; -pub const SYS_lstat: ::c_long = 6; -pub const SYS_poll: ::c_long = 7; -pub const SYS_lseek: ::c_long = 8; -pub const SYS_mmap: ::c_long = 9; -pub const SYS_mprotect: ::c_long = 10; -pub const SYS_munmap: ::c_long = 11; -pub const SYS_brk: ::c_long = 12; -pub const SYS_rt_sigaction: ::c_long = 13; -pub const SYS_rt_sigprocmask: ::c_long = 14; -pub const SYS_rt_sigreturn: ::c_long = 15; -pub const SYS_ioctl: ::c_long = 16; -pub const SYS_pread64: ::c_long = 17; -pub const SYS_pwrite64: ::c_long = 18; -pub const SYS_readv: ::c_long = 19; -pub const SYS_writev: ::c_long = 20; -pub const SYS_access: ::c_long = 21; -pub const SYS_pipe: ::c_long = 22; -pub const SYS_select: ::c_long = 23; -pub const SYS_sched_yield: ::c_long = 24; -pub const SYS_mremap: ::c_long = 25; -pub const SYS_msync: ::c_long = 26; -pub const SYS_mincore: ::c_long = 27; -pub const SYS_madvise: ::c_long = 28; -pub const SYS_shmget: ::c_long = 29; -pub const SYS_shmat: ::c_long = 30; -pub const SYS_shmctl: ::c_long = 31; -pub const SYS_dup: ::c_long = 32; -pub const SYS_dup2: ::c_long = 33; -pub const SYS_pause: ::c_long = 34; -pub const SYS_nanosleep: ::c_long = 35; -pub const SYS_getitimer: ::c_long = 36; -pub const SYS_alarm: ::c_long = 37; -pub const SYS_setitimer: ::c_long = 38; -pub const SYS_getpid: ::c_long = 39; -pub const SYS_sendfile: ::c_long = 40; -pub const SYS_socket: ::c_long = 41; -pub const SYS_connect: ::c_long = 42; -pub const SYS_accept: ::c_long = 43; -pub const SYS_sendto: ::c_long = 44; -pub const SYS_recvfrom: ::c_long = 45; -pub const SYS_sendmsg: ::c_long = 46; -pub const SYS_recvmsg: ::c_long = 47; -pub const SYS_shutdown: ::c_long = 48; -pub const SYS_bind: ::c_long = 49; -pub const SYS_listen: ::c_long = 50; -pub const SYS_getsockname: ::c_long = 51; -pub const SYS_getpeername: ::c_long = 52; -pub const SYS_socketpair: ::c_long = 53; -pub const SYS_setsockopt: ::c_long = 54; -pub const SYS_getsockopt: ::c_long = 55; -pub const SYS_clone: ::c_long = 56; -pub const SYS_fork: ::c_long = 57; -pub const SYS_vfork: ::c_long = 58; -pub const SYS_execve: ::c_long = 59; -pub const SYS_exit: ::c_long = 60; -pub const SYS_wait4: ::c_long = 61; -pub const SYS_kill: ::c_long = 62; -pub const SYS_uname: ::c_long = 63; -pub const SYS_semget: ::c_long = 64; -pub const SYS_semop: ::c_long = 65; -pub const SYS_semctl: ::c_long = 66; -pub const SYS_shmdt: ::c_long = 67; -pub const SYS_msgget: ::c_long = 68; -pub const SYS_msgsnd: ::c_long = 69; -pub const SYS_msgrcv: ::c_long = 70; -pub const SYS_msgctl: ::c_long = 71; -pub const SYS_fcntl: ::c_long = 72; -pub const SYS_flock: ::c_long = 73; -pub const SYS_fsync: ::c_long = 74; -pub const SYS_fdatasync: ::c_long = 75; -pub const SYS_truncate: ::c_long = 76; -pub const SYS_ftruncate: ::c_long = 77; -pub const SYS_getdents: ::c_long = 78; -pub const SYS_getcwd: ::c_long = 79; -pub const SYS_chdir: ::c_long = 80; -pub const SYS_fchdir: ::c_long = 81; -pub const SYS_rename: ::c_long = 82; -pub const SYS_mkdir: ::c_long = 83; -pub const SYS_rmdir: ::c_long = 84; -pub const SYS_creat: ::c_long = 85; -pub const SYS_link: ::c_long = 86; -pub const SYS_unlink: ::c_long = 87; -pub const SYS_symlink: ::c_long = 88; -pub const SYS_readlink: ::c_long = 89; -pub const SYS_chmod: ::c_long = 90; -pub const SYS_fchmod: ::c_long = 91; -pub const SYS_chown: ::c_long = 92; -pub const SYS_fchown: ::c_long = 93; -pub const SYS_lchown: ::c_long = 94; -pub const SYS_umask: ::c_long = 95; -pub const SYS_gettimeofday: ::c_long = 96; -pub const SYS_getrlimit: ::c_long = 97; -pub const SYS_getrusage: ::c_long = 98; -pub const SYS_sysinfo: ::c_long = 99; -pub const SYS_times: ::c_long = 100; -pub const SYS_ptrace: ::c_long = 101; -pub const SYS_getuid: ::c_long = 102; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_getgid: ::c_long = 104; -pub const SYS_setuid: ::c_long = 105; -pub const SYS_setgid: ::c_long = 106; -pub const SYS_geteuid: ::c_long = 107; -pub const SYS_getegid: ::c_long = 108; -pub const SYS_setpgid: ::c_long = 109; -pub const SYS_getppid: ::c_long = 110; -pub const SYS_getpgrp: ::c_long = 111; -pub const SYS_setsid: ::c_long = 112; -pub const SYS_setreuid: ::c_long = 113; -pub const SYS_setregid: ::c_long = 114; -pub const SYS_getgroups: ::c_long = 115; -pub const SYS_setgroups: ::c_long = 116; -pub const SYS_setresuid: ::c_long = 117; -pub const SYS_getresuid: ::c_long = 118; -pub const SYS_setresgid: ::c_long = 119; -pub const SYS_getresgid: ::c_long = 120; -pub const SYS_getpgid: ::c_long = 121; -pub const SYS_setfsuid: ::c_long = 122; -pub const SYS_setfsgid: ::c_long = 123; -pub const SYS_getsid: ::c_long = 124; -pub const SYS_capget: ::c_long = 125; -pub const SYS_capset: ::c_long = 126; -pub const SYS_rt_sigpending: ::c_long = 127; -pub const SYS_rt_sigtimedwait: ::c_long = 128; -pub const SYS_rt_sigqueueinfo: ::c_long = 129; -pub const SYS_rt_sigsuspend: ::c_long = 130; -pub const SYS_sigaltstack: ::c_long = 131; -pub const SYS_utime: ::c_long = 132; -pub const SYS_mknod: ::c_long = 133; -pub const SYS_uselib: ::c_long = 134; -pub const SYS_personality: ::c_long = 135; -pub const SYS_ustat: ::c_long = 136; -pub const SYS_statfs: ::c_long = 137; -pub const SYS_fstatfs: ::c_long = 138; -pub const SYS_sysfs: ::c_long = 139; -pub const SYS_getpriority: ::c_long = 140; -pub const SYS_setpriority: ::c_long = 141; -pub const SYS_sched_setparam: ::c_long = 142; -pub const SYS_sched_getparam: ::c_long = 143; -pub const SYS_sched_setscheduler: ::c_long = 144; -pub const SYS_sched_getscheduler: ::c_long = 145; -pub const SYS_sched_get_priority_max: ::c_long = 146; -pub const SYS_sched_get_priority_min: ::c_long = 147; -pub const SYS_sched_rr_get_interval: ::c_long = 148; -pub const SYS_mlock: ::c_long = 149; -pub const SYS_munlock: ::c_long = 150; -pub const SYS_mlockall: ::c_long = 151; -pub const SYS_munlockall: ::c_long = 152; -pub const SYS_vhangup: ::c_long = 153; -pub const SYS_modify_ldt: ::c_long = 154; -pub const SYS_pivot_root: ::c_long = 155; -pub const SYS__sysctl: ::c_long = 156; -pub const SYS_prctl: ::c_long = 157; -pub const SYS_arch_prctl: ::c_long = 158; -pub const SYS_adjtimex: ::c_long = 159; -pub const SYS_setrlimit: ::c_long = 160; -pub const SYS_chroot: ::c_long = 161; -pub const SYS_sync: ::c_long = 162; -pub const SYS_acct: ::c_long = 163; -pub const SYS_settimeofday: ::c_long = 164; -pub const SYS_mount: ::c_long = 165; -pub const SYS_umount2: ::c_long = 166; -pub const SYS_swapon: ::c_long = 167; -pub const SYS_swapoff: ::c_long = 168; -pub const SYS_reboot: ::c_long = 169; -pub const SYS_sethostname: ::c_long = 170; -pub const SYS_setdomainname: ::c_long = 171; -pub const SYS_iopl: ::c_long = 172; -pub const SYS_ioperm: ::c_long = 173; -pub const SYS_create_module: ::c_long = 174; -pub const SYS_init_module: ::c_long = 175; -pub const SYS_delete_module: ::c_long = 176; -pub const SYS_get_kernel_syms: ::c_long = 177; -pub const SYS_query_module: ::c_long = 178; -pub const SYS_quotactl: ::c_long = 179; -pub const SYS_nfsservctl: ::c_long = 180; -pub const SYS_getpmsg: ::c_long = 181; -pub const SYS_putpmsg: ::c_long = 182; -pub const SYS_afs_syscall: ::c_long = 183; -pub const SYS_tuxcall: ::c_long = 184; -pub const SYS_security: ::c_long = 185; -pub const SYS_gettid: ::c_long = 186; -pub const SYS_readahead: ::c_long = 187; -pub const SYS_setxattr: ::c_long = 188; -pub const SYS_lsetxattr: ::c_long = 189; -pub const SYS_fsetxattr: ::c_long = 190; -pub const SYS_getxattr: ::c_long = 191; -pub const SYS_lgetxattr: ::c_long = 192; -pub const SYS_fgetxattr: ::c_long = 193; -pub const SYS_listxattr: ::c_long = 194; -pub const SYS_llistxattr: ::c_long = 195; -pub const SYS_flistxattr: ::c_long = 196; -pub const SYS_removexattr: ::c_long = 197; -pub const SYS_lremovexattr: ::c_long = 198; -pub const SYS_fremovexattr: ::c_long = 199; -pub const SYS_tkill: ::c_long = 200; -pub const SYS_time: ::c_long = 201; -pub const SYS_futex: ::c_long = 202; -pub const SYS_sched_setaffinity: ::c_long = 203; -pub const SYS_sched_getaffinity: ::c_long = 204; -pub const SYS_set_thread_area: ::c_long = 205; -pub const SYS_io_setup: ::c_long = 206; -pub const SYS_io_destroy: ::c_long = 207; -pub const SYS_io_getevents: ::c_long = 208; -pub const SYS_io_submit: ::c_long = 209; -pub const SYS_io_cancel: ::c_long = 210; -pub const SYS_get_thread_area: ::c_long = 211; -pub const SYS_lookup_dcookie: ::c_long = 212; -pub const SYS_epoll_create: ::c_long = 213; -pub const SYS_epoll_ctl_old: ::c_long = 214; -pub const SYS_epoll_wait_old: ::c_long = 215; -pub const SYS_remap_file_pages: ::c_long = 216; -pub const SYS_getdents64: ::c_long = 217; -pub const SYS_set_tid_address: ::c_long = 218; -pub const SYS_restart_syscall: ::c_long = 219; -pub const SYS_semtimedop: ::c_long = 220; -pub const SYS_fadvise64: ::c_long = 221; -pub const SYS_timer_create: ::c_long = 222; -pub const SYS_timer_settime: ::c_long = 223; -pub const SYS_timer_gettime: ::c_long = 224; -pub const SYS_timer_getoverrun: ::c_long = 225; -pub const SYS_timer_delete: ::c_long = 226; -pub const SYS_clock_settime: ::c_long = 227; -pub const SYS_clock_gettime: ::c_long = 228; -pub const SYS_clock_getres: ::c_long = 229; -pub const SYS_clock_nanosleep: ::c_long = 230; -pub const SYS_exit_group: ::c_long = 231; -pub const SYS_epoll_wait: ::c_long = 232; -pub const SYS_epoll_ctl: ::c_long = 233; -pub const SYS_tgkill: ::c_long = 234; -pub const SYS_utimes: ::c_long = 235; -pub const SYS_vserver: ::c_long = 236; -pub const SYS_mbind: ::c_long = 237; -pub const SYS_set_mempolicy: ::c_long = 238; -pub const SYS_get_mempolicy: ::c_long = 239; -pub const SYS_mq_open: ::c_long = 240; -pub const SYS_mq_unlink: ::c_long = 241; -pub const SYS_mq_timedsend: ::c_long = 242; -pub const SYS_mq_timedreceive: ::c_long = 243; -pub const SYS_mq_notify: ::c_long = 244; -pub const SYS_mq_getsetattr: ::c_long = 245; -pub const SYS_kexec_load: ::c_long = 246; -pub const SYS_waitid: ::c_long = 247; -pub const SYS_add_key: ::c_long = 248; -pub const SYS_request_key: ::c_long = 249; -pub const SYS_keyctl: ::c_long = 250; -pub const SYS_ioprio_set: ::c_long = 251; -pub const SYS_ioprio_get: ::c_long = 252; -pub const SYS_inotify_init: ::c_long = 253; -pub const SYS_inotify_add_watch: ::c_long = 254; -pub const SYS_inotify_rm_watch: ::c_long = 255; -pub const SYS_migrate_pages: ::c_long = 256; -pub const SYS_openat: ::c_long = 257; -pub const SYS_mkdirat: ::c_long = 258; -pub const SYS_mknodat: ::c_long = 259; -pub const SYS_fchownat: ::c_long = 260; -pub const SYS_futimesat: ::c_long = 261; -pub const SYS_newfstatat: ::c_long = 262; -pub const SYS_unlinkat: ::c_long = 263; -pub const SYS_renameat: ::c_long = 264; -pub const SYS_linkat: ::c_long = 265; -pub const SYS_symlinkat: ::c_long = 266; -pub const SYS_readlinkat: ::c_long = 267; -pub const SYS_fchmodat: ::c_long = 268; -pub const SYS_faccessat: ::c_long = 269; -pub const SYS_pselect6: ::c_long = 270; -pub const SYS_ppoll: ::c_long = 271; -pub const SYS_unshare: ::c_long = 272; -pub const SYS_set_robust_list: ::c_long = 273; -pub const SYS_get_robust_list: ::c_long = 274; -pub const SYS_splice: ::c_long = 275; -pub const SYS_tee: ::c_long = 276; -pub const SYS_sync_file_range: ::c_long = 277; -pub const SYS_vmsplice: ::c_long = 278; -pub const SYS_move_pages: ::c_long = 279; -pub const SYS_utimensat: ::c_long = 280; -pub const SYS_epoll_pwait: ::c_long = 281; -pub const SYS_signalfd: ::c_long = 282; -pub const SYS_timerfd_create: ::c_long = 283; -pub const SYS_eventfd: ::c_long = 284; -pub const SYS_fallocate: ::c_long = 285; -pub const SYS_timerfd_settime: ::c_long = 286; -pub const SYS_timerfd_gettime: ::c_long = 287; -pub const SYS_accept4: ::c_long = 288; -pub const SYS_signalfd4: ::c_long = 289; -pub const SYS_eventfd2: ::c_long = 290; -pub const SYS_epoll_create1: ::c_long = 291; -pub const SYS_dup3: ::c_long = 292; -pub const SYS_pipe2: ::c_long = 293; -pub const SYS_inotify_init1: ::c_long = 294; -pub const SYS_preadv: ::c_long = 295; -pub const SYS_pwritev: ::c_long = 296; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 297; -pub const SYS_perf_event_open: ::c_long = 298; -pub const SYS_recvmmsg: ::c_long = 299; -pub const SYS_fanotify_init: ::c_long = 300; -pub const SYS_fanotify_mark: ::c_long = 301; -pub const SYS_prlimit64: ::c_long = 302; -pub const SYS_name_to_handle_at: ::c_long = 303; -pub const SYS_open_by_handle_at: ::c_long = 304; -pub const SYS_clock_adjtime: ::c_long = 305; -pub const SYS_syncfs: ::c_long = 306; -pub const SYS_sendmmsg: ::c_long = 307; -pub const SYS_setns: ::c_long = 308; -pub const SYS_getcpu: ::c_long = 309; -pub const SYS_process_vm_readv: ::c_long = 310; -pub const SYS_process_vm_writev: ::c_long = 311; -pub const SYS_kcmp: ::c_long = 312; -pub const SYS_finit_module: ::c_long = 313; -pub const SYS_sched_setattr: ::c_long = 314; -pub const SYS_sched_getattr: ::c_long = 315; -pub const SYS_renameat2: ::c_long = 316; -pub const SYS_seccomp: ::c_long = 317; -pub const SYS_getrandom: ::c_long = 318; -pub const SYS_memfd_create: ::c_long = 319; -pub const SYS_kexec_file_load: ::c_long = 320; -pub const SYS_bpf: ::c_long = 321; -pub const SYS_execveat: ::c_long = 322; -pub const SYS_userfaultfd: ::c_long = 323; -pub const SYS_membarrier: ::c_long = 324; -pub const SYS_mlock2: ::c_long = 325; -pub const SYS_copy_file_range: ::c_long = 326; -pub const SYS_preadv2: ::c_long = 327; -pub const SYS_pwritev2: ::c_long = 328; -pub const SYS_pkey_mprotect: ::c_long = 329; -pub const SYS_pkey_alloc: ::c_long = 330; -pub const SYS_pkey_free: ::c_long = 331; -pub const SYS_statx: ::c_long = 332; - -// offsets in user_regs_structs, from sys/reg.h -pub const R15: ::c_int = 0; -pub const R14: ::c_int = 1; -pub const R13: ::c_int = 2; -pub const R12: ::c_int = 3; -pub const RBP: ::c_int = 4; -pub const RBX: ::c_int = 5; -pub const R11: ::c_int = 6; -pub const R10: ::c_int = 7; -pub const R9: ::c_int = 8; -pub const R8: ::c_int = 9; -pub const RAX: ::c_int = 10; -pub const RCX: ::c_int = 11; -pub const RDX: ::c_int = 12; -pub const RSI: ::c_int = 13; -pub const RDI: ::c_int = 14; -pub const ORIG_RAX: ::c_int = 15; -pub const RIP: ::c_int = 16; -pub const CS: ::c_int = 17; -pub const EFLAGS: ::c_int = 18; -pub const RSP: ::c_int = 19; -pub const SS: ::c_int = 20; -pub const FS_BASE: ::c_int = 21; -pub const GS_BASE: ::c_int = 22; -pub const DS: ::c_int = 23; -pub const ES: ::c_int = 24; -pub const FS: ::c_int = 25; -pub const GS: ::c_int = 26; - -// offsets in mcontext_t.gregs from bits/signal.h -// GitHub repo: ifduyue/musl/ -// commit: b4b1e10364c8737a632be61582e05a8d3acf5690 -// file: arch/x86_64/bits/signal.h#L9-L56 -pub const REG_R8: ::c_int = 0; -pub const REG_R9: ::c_int = 1; -pub const REG_R10: ::c_int = 2; -pub const REG_R11: ::c_int = 3; -pub const REG_R12: ::c_int = 4; -pub const REG_R13: ::c_int = 5; -pub const REG_R14: ::c_int = 6; -pub const REG_R15: ::c_int = 7; -pub const REG_RDI: ::c_int = 8; -pub const REG_RSI: ::c_int = 9; -pub const REG_RBP: ::c_int = 10; -pub const REG_RBX: ::c_int = 11; -pub const REG_RDX: ::c_int = 12; -pub const REG_RAX: ::c_int = 13; -pub const REG_RCX: ::c_int = 14; -pub const REG_RSP: ::c_int = 15; -pub const REG_RIP: ::c_int = 16; -pub const REG_EFL: ::c_int = 17; -pub const REG_CSGSFS: ::c_int = 18; -pub const REG_ERR: ::c_int = 19; -pub const REG_TRAPNO: ::c_int = 20; -pub const REG_OLDMASK: ::c_int = 21; -pub const REG_CR2: ::c_int = 22; - -pub const MADV_SOFT_OFFLINE: ::c_int = 101; -pub const MAP_32BIT: ::c_int = 0x0040; -pub const O_APPEND: ::c_int = 1024; -pub const O_DIRECT: ::c_int = 0x4000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_LARGEFILE: ::c_int = 0; -pub const O_NOFOLLOW: ::c_int = 0x20000; -pub const O_CREAT: ::c_int = 64; -pub const O_EXCL: ::c_int = 128; -pub const O_NOCTTY: ::c_int = 256; -pub const O_NONBLOCK: ::c_int = 2048; -pub const O_SYNC: ::c_int = 1052672; -pub const O_RSYNC: ::c_int = 1052672; -pub const O_DSYNC: ::c_int = 4096; -pub const O_ASYNC: ::c_int = 0x2000; - -pub const TIOCGRS485: ::c_int = 0x542E; -pub const TIOCSRS485: ::c_int = 0x542F; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const MINSIGSTKSZ: ::size_t = 2048; - -pub const ENAMETOOLONG: ::c_int = 36; -pub const ENOLCK: ::c_int = 37; -pub const ENOSYS: ::c_int = 38; -pub const ENOTEMPTY: ::c_int = 39; -pub const ELOOP: ::c_int = 40; -pub const ENOMSG: ::c_int = 42; -pub const EIDRM: ::c_int = 43; -pub const ECHRNG: ::c_int = 44; -pub const EL2NSYNC: ::c_int = 45; -pub const EL3HLT: ::c_int = 46; -pub const EL3RST: ::c_int = 47; -pub const ELNRNG: ::c_int = 48; -pub const EUNATCH: ::c_int = 49; -pub const ENOCSI: ::c_int = 50; -pub const EL2HLT: ::c_int = 51; -pub const EBADE: ::c_int = 52; -pub const EBADR: ::c_int = 53; -pub const EXFULL: ::c_int = 54; -pub const ENOANO: ::c_int = 55; -pub const EBADRQC: ::c_int = 56; -pub const EBADSLT: ::c_int = 57; -pub const EMULTIHOP: ::c_int = 72; -pub const EBADMSG: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 75; -pub const ENOTUNIQ: ::c_int = 76; -pub const EBADFD: ::c_int = 77; -pub const EREMCHG: ::c_int = 78; -pub const ELIBACC: ::c_int = 79; -pub const ELIBBAD: ::c_int = 80; -pub const ELIBSCN: ::c_int = 81; -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; -pub const EILSEQ: ::c_int = 84; -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; -pub const EUSERS: ::c_int = 87; -pub const ENOTSOCK: ::c_int = 88; -pub const EDESTADDRREQ: ::c_int = 89; -pub const EMSGSIZE: ::c_int = 90; -pub const EPROTOTYPE: ::c_int = 91; -pub const ENOPROTOOPT: ::c_int = 92; -pub const EPROTONOSUPPORT: ::c_int = 93; -pub const ESOCKTNOSUPPORT: ::c_int = 94; -pub const EOPNOTSUPP: ::c_int = 95; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; -pub const EADDRNOTAVAIL: ::c_int = 99; -pub const ENETDOWN: ::c_int = 100; -pub const ENETUNREACH: ::c_int = 101; -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EISCONN: ::c_int = 106; -pub const ENOTCONN: ::c_int = 107; -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; -pub const ETIMEDOUT: ::c_int = 110; -pub const ECONNREFUSED: ::c_int = 111; -pub const EHOSTDOWN: ::c_int = 112; -pub const EHOSTUNREACH: ::c_int = 113; -pub const EALREADY: ::c_int = 114; -pub const EINPROGRESS: ::c_int = 115; -pub const ESTALE: ::c_int = 116; -pub const EUCLEAN: ::c_int = 117; -pub const ENOTNAM: ::c_int = 118; -pub const ENAVAIL: ::c_int = 119; -pub const EISNAM: ::c_int = 120; -pub const EREMOTEIO: ::c_int = 121; -pub const EDQUOT: ::c_int = 122; -pub const ENOMEDIUM: ::c_int = 123; -pub const EMEDIUMTYPE: ::c_int = 124; -pub const ECANCELED: ::c_int = 125; -pub const ENOKEY: ::c_int = 126; -pub const EKEYEXPIRED: ::c_int = 127; -pub const EKEYREVOKED: ::c_int = 128; -pub const EKEYREJECTED: ::c_int = 129; -pub const EOWNERDEAD: ::c_int = 130; -pub const ENOTRECOVERABLE: ::c_int = 131; -pub const ERFKILL: ::c_int = 132; -pub const EHWPOISON: ::c_int = 133; - -pub const SA_ONSTACK: ::c_int = 0x08000000; -pub const SA_SIGINFO: ::c_int = 0x00000004; -pub const SA_NOCLDWAIT: ::c_int = 0x00000002; - -pub const SIGCHLD: ::c_int = 17; -pub const SIGBUS: ::c_int = 7; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGUSR1: ::c_int = 10; -pub const SIGUSR2: ::c_int = 12; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGURG: ::c_int = 23; -pub const SIGIO: ::c_int = 29; -pub const SIGSYS: ::c_int = 31; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGPOLL: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIG_BLOCK: ::c_int = 0x000000; -pub const SIG_UNBLOCK: ::c_int = 0x01; - -pub const F_GETLK: ::c_int = 5; -pub const F_GETOWN: ::c_int = 9; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; -pub const F_SETOWN: ::c_int = 8; - -pub const VEOF: usize = 4; - -pub const POLLWRNORM: ::c_short = 0x100; -pub const POLLWRBAND: ::c_short = 0x200; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOL_SOCKET: ::c_int = 1; -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_TYPE: ::c_int = 3; -pub const SO_ERROR: ::c_int = 4; -pub const SO_DONTROUTE: ::c_int = 5; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_OOBINLINE: ::c_int = 10; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_LINGER: ::c_int = 13; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_ACCEPTCONN: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 32; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PROTOCOL: ::c_int = 38; -pub const SO_DOMAIN: ::c_int = 39; - -pub const MAP_ANON: ::c_int = 0x0020; -pub const MAP_GROWSDOWN: ::c_int = 0x0100; -pub const MAP_DENYWRITE: ::c_int = 0x0800; -pub const MAP_EXECUTABLE: ::c_int = 0x01000; -pub const MAP_LOCKED: ::c_int = 0x02000; -pub const MAP_NORESERVE: ::c_int = 0x04000; -pub const MAP_POPULATE: ::c_int = 0x08000; -pub const MAP_NONBLOCK: ::c_int = 0x010000; -pub const MAP_STACK: ::c_int = 0x020000; -pub const MAP_HUGETLB: ::c_int = 0x040000; - -pub const RLIMIT_NLIMITS: ::c_int = 15; -pub const TIOCINQ: ::c_int = ::FIONREAD; -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::c_int = 0x00000800; -pub const TAB2: ::c_int = 0x00001000; -pub const TAB3: ::c_int = 0x00001800; -pub const CR1: ::c_int = 0x00000200; -pub const CR2: ::c_int = 0x00000400; -pub const CR3: ::c_int = 0x00000600; -pub const FF1: ::c_int = 0x00008000; -pub const BS1: ::c_int = 0x00002000; -pub const VT1: ::c_int = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; -pub const CIBAUD: ::tcflag_t = 0o02003600000; -pub const CBAUDEX: ::tcflag_t = 0o010000; -pub const VSWTC: usize = 7; -pub const OLCUC: ::tcflag_t = 0o000002; -pub const NLDLY: ::tcflag_t = 0o000400; -pub const CRDLY: ::tcflag_t = 0o003000; -pub const TABDLY: ::tcflag_t = 0o014000; -pub const BSDLY: ::tcflag_t = 0o020000; -pub const FFDLY: ::tcflag_t = 0o100000; -pub const VTDLY: ::tcflag_t = 0o040000; -pub const XTABS: ::tcflag_t = 0o014000; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -pub const FIOCLEX: ::c_int = 0x5451; -pub const FIONCLEX: ::c_int = 0x5450; -pub const FIONBIO: ::c_int = 0x5421; -pub const EDEADLK: ::c_int = 35; -pub const EDEADLOCK: ::c_int = EDEADLK; -pub const SO_PASSCRED: ::c_int = 16; -pub const SO_PEERCRED: ::c_int = 17; -pub const SO_RCVLOWAT: ::c_int = 18; -pub const SO_SNDLOWAT: ::c_int = 19; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const EXTPROC: ::tcflag_t = 0x00010000; -pub const VEOL: usize = 11; -pub const VEOL2: usize = 16; -pub const VMIN: usize = 6; -pub const IEXTEN: ::tcflag_t = 0x00008000; -pub const TOSTOP: ::tcflag_t = 0x00000100; -pub const FLUSHO: ::tcflag_t = 0x00001000; -pub const TCGETS: ::c_int = 0x5401; -pub const TCSETS: ::c_int = 0x5402; -pub const TCSETSW: ::c_int = 0x5403; -pub const TCSETSF: ::c_int = 0x5404; -pub const TCGETA: ::c_int = 0x5405; -pub const TCSETA: ::c_int = 0x5406; -pub const TCSETAW: ::c_int = 0x5407; -pub const TCSETAF: ::c_int = 0x5408; -pub const TCSBRK: ::c_int = 0x5409; -pub const TCXONC: ::c_int = 0x540A; -pub const TCFLSH: ::c_int = 0x540B; -pub const TIOCGSOFTCAR: ::c_int = 0x5419; -pub const TIOCSSOFTCAR: ::c_int = 0x541A; -pub const TIOCLINUX: ::c_int = 0x541C; -pub const TIOCGSERIAL: ::c_int = 0x541E; -pub const TIOCEXCL: ::c_int = 0x540C; -pub const TIOCNXCL: ::c_int = 0x540D; -pub const TIOCSCTTY: ::c_int = 0x540E; -pub const TIOCGPGRP: ::c_int = 0x540F; -pub const TIOCSPGRP: ::c_int = 0x5410; -pub const TIOCOUTQ: ::c_int = 0x5411; -pub const TIOCSTI: ::c_int = 0x5412; -pub const TIOCGWINSZ: ::c_int = 0x5413; -pub const TIOCSWINSZ: ::c_int = 0x5414; -pub const TIOCMGET: ::c_int = 0x5415; -pub const TIOCMBIS: ::c_int = 0x5416; -pub const TIOCMBIC: ::c_int = 0x5417; -pub const TIOCMSET: ::c_int = 0x5418; -pub const FIONREAD: ::c_int = 0x541B; -pub const TIOCCONS: ::c_int = 0x541D; - -pub const TIOCM_LE: ::c_int = 0x001; -pub const TIOCM_DTR: ::c_int = 0x002; -pub const TIOCM_RTS: ::c_int = 0x004; -pub const TIOCM_ST: ::c_int = 0x008; -pub const TIOCM_SR: ::c_int = 0x010; -pub const TIOCM_CTS: ::c_int = 0x020; -pub const TIOCM_CAR: ::c_int = 0x040; -pub const TIOCM_RNG: ::c_int = 0x080; -pub const TIOCM_DSR: ::c_int = 0x100; -pub const TIOCM_CD: ::c_int = TIOCM_CAR; -pub const TIOCM_RI: ::c_int = TIOCM_RNG; - -extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/unix/linux_like/linux/musl/mod.rs b/libc/src/unix/linux_like/linux/musl/mod.rs deleted file mode 100644 index 2c5d375..0000000 --- a/libc/src/unix/linux_like/linux/musl/mod.rs +++ /dev/null @@ -1,436 +0,0 @@ -pub type pthread_t = *mut ::c_void; -pub type clock_t = c_long; -pub type time_t = c_long; -pub type suseconds_t = c_long; -pub type ino_t = u64; -pub type off_t = i64; -pub type blkcnt_t = i64; - -pub type shmatt_t = ::c_ulong; -pub type msgqnum_t = ::c_ulong; -pub type msglen_t = ::c_ulong; -pub type fsblkcnt_t = ::c_ulonglong; -pub type fsfilcnt_t = ::c_ulonglong; -pub type rlim_t = ::c_ulonglong; - -pub type flock64 = flock; - -impl siginfo_t { - pub unsafe fn si_addr(&self) -> *mut ::c_void { - #[repr(C)] - struct siginfo_sigfault { - _si_signo: ::c_int, - _si_errno: ::c_int, - _si_code: ::c_int, - si_addr: *mut ::c_void, - } - - (*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr - } - - pub unsafe fn si_value(&self) -> ::sigval { - #[repr(C)] - struct siginfo_si_value { - _si_signo: ::c_int, - _si_errno: ::c_int, - _si_code: ::c_int, - _si_timerid: ::c_int, - _si_overrun: ::c_int, - si_value: ::sigval, - } - - (*(self as *const siginfo_t as *const siginfo_si_value)).si_value - } -} - -s! { - pub struct aiocb { - pub aio_fildes: ::c_int, - pub aio_lio_opcode: ::c_int, - pub aio_reqprio: ::c_int, - pub aio_buf: *mut ::c_void, - pub aio_nbytes: ::size_t, - pub aio_sigevent: ::sigevent, - __td: *mut ::c_void, - __lock: [::c_int; 2], - __err: ::c_int, - __ret: ::ssize_t, - pub aio_offset: off_t, - __next: *mut ::c_void, - __prev: *mut ::c_void, - #[cfg(target_pointer_width = "32")] - __dummy4: [::c_char; 24], - #[cfg(target_pointer_width = "64")] - __dummy4: [::c_char; 16], - } - - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - pub sa_mask: ::sigset_t, - pub sa_flags: ::c_int, - pub sa_restorer: ::Option, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - #[cfg(target_endian = "little")] - pub f_fsid: ::c_ulong, - #[cfg(target_pointer_width = "32")] - __f_unused: ::c_int, - #[cfg(target_endian = "big")] - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - pub __c_ispeed: ::speed_t, - pub __c_ospeed: ::speed_t, - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } -} - -s_no_extra_traits! { - pub struct sysinfo { - pub uptime: ::c_ulong, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub __reserved: [::c_char; 256], - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for sysinfo { - fn eq(&self, other: &sysinfo) -> bool { - self.uptime == other.uptime - && self.loads == other.loads - && self.totalram == other.totalram - && self.freeram == other.freeram - && self.sharedram == other.sharedram - && self.bufferram == other.bufferram - && self.totalswap == other.totalswap - && self.freeswap == other.freeswap - && self.procs == other.procs - && self.pad == other.pad - && self.totalhigh == other.totalhigh - && self.freehigh == other.freehigh - && self.mem_unit == other.mem_unit - && self - .__reserved - .iter() - .zip(other.__reserved.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for sysinfo {} - - impl ::fmt::Debug for sysinfo { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sysinfo") - .field("uptime", &self.uptime) - .field("loads", &self.loads) - .field("totalram", &self.totalram) - .field("freeram", &self.freeram) - .field("sharedram", &self.sharedram) - .field("bufferram", &self.bufferram) - .field("totalswap", &self.totalswap) - .field("freeswap", &self.freeswap) - .field("procs", &self.procs) - .field("pad", &self.pad) - .field("totalhigh", &self.totalhigh) - .field("freehigh", &self.freehigh) - .field("mem_unit", &self.mem_unit) - // FIXME: .field("__reserved", &self.__reserved) - .finish() - } - } - - impl ::hash::Hash for sysinfo { - fn hash(&self, state: &mut H) { - self.uptime.hash(state); - self.loads.hash(state); - self.totalram.hash(state); - self.freeram.hash(state); - self.sharedram.hash(state); - self.bufferram.hash(state); - self.totalswap.hash(state); - self.freeswap.hash(state); - self.procs.hash(state); - self.pad.hash(state); - self.totalhigh.hash(state); - self.freehigh.hash(state); - self.mem_unit.hash(state); - self.__reserved.hash(state); - } - } - } -} - -pub const MS_RMT_MASK: ::c_ulong = 0x02800051; - -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; -pub const O_NOATIME: ::c_int = 0o1000000; -pub const O_CLOEXEC: ::c_int = 0x80000; -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const F_RDLCK: ::c_int = 0; -pub const F_WRLCK: ::c_int = 1; -pub const F_UNLCK: ::c_int = 2; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const BUFSIZ: ::c_uint = 1024; -pub const TMP_MAX: ::c_uint = 10000; -pub const FOPEN_MAX: ::c_uint = 1000; -pub const O_PATH: ::c_int = 0o10000000; -pub const O_EXEC: ::c_int = 0o10000000; -pub const O_SEARCH: ::c_int = 0o10000000; -pub const O_ACCMODE: ::c_int = 0o10000003; -pub const O_NDELAY: ::c_int = O_NONBLOCK; -pub const NI_MAXHOST: ::socklen_t = 255; -pub const PTHREAD_STACK_MIN: ::size_t = 2048; -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; - -pub const POSIX_MADV_DONTNEED: ::c_int = 4; - -pub const RLIM_INFINITY: ::rlim_t = !0; -pub const RLIMIT_RTTIME: ::c_int = 15; - -pub const MAP_ANONYMOUS: ::c_int = MAP_ANON; - -pub const SOCK_DCCP: ::c_int = 6; -pub const SOCK_PACKET: ::c_int = 10; - -pub const TCP_COOKIE_TRANSACTIONS: ::c_int = 15; -pub const TCP_THIN_LINEAR_TIMEOUTS: ::c_int = 16; -pub const TCP_THIN_DUPACK: ::c_int = 17; -pub const TCP_USER_TIMEOUT: ::c_int = 18; -pub const TCP_REPAIR: ::c_int = 19; -pub const TCP_REPAIR_QUEUE: ::c_int = 20; -pub const TCP_QUEUE_SEQ: ::c_int = 21; -pub const TCP_REPAIR_OPTIONS: ::c_int = 22; -pub const TCP_FASTOPEN: ::c_int = 23; -pub const TCP_TIMESTAMP: ::c_int = 24; - -#[deprecated(since = "0.2.55", note = "Use SIGSYS instead")] -pub const SIGUNUSED: ::c_int = ::SIGSYS; - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; - -pub const CPU_SETSIZE: ::c_int = 128; - -pub const PTRACE_TRACEME: ::c_int = 0; -pub const PTRACE_PEEKTEXT: ::c_int = 1; -pub const PTRACE_PEEKDATA: ::c_int = 2; -pub const PTRACE_PEEKUSER: ::c_int = 3; -pub const PTRACE_POKETEXT: ::c_int = 4; -pub const PTRACE_POKEDATA: ::c_int = 5; -pub const PTRACE_POKEUSER: ::c_int = 6; -pub const PTRACE_CONT: ::c_int = 7; -pub const PTRACE_KILL: ::c_int = 8; -pub const PTRACE_SINGLESTEP: ::c_int = 9; -pub const PTRACE_GETREGS: ::c_int = 12; -pub const PTRACE_SETREGS: ::c_int = 13; -pub const PTRACE_GETFPREGS: ::c_int = 14; -pub const PTRACE_SETFPREGS: ::c_int = 15; -pub const PTRACE_ATTACH: ::c_int = 16; -pub const PTRACE_DETACH: ::c_int = 17; -pub const PTRACE_GETFPXREGS: ::c_int = 18; -pub const PTRACE_SETFPXREGS: ::c_int = 19; -pub const PTRACE_SYSCALL: ::c_int = 24; -pub const PTRACE_SETOPTIONS: ::c_int = 0x4200; -pub const PTRACE_GETEVENTMSG: ::c_int = 0x4201; -pub const PTRACE_GETSIGINFO: ::c_int = 0x4202; -pub const PTRACE_SETSIGINFO: ::c_int = 0x4203; -pub const PTRACE_GETREGSET: ::c_int = 0x4204; -pub const PTRACE_SETREGSET: ::c_int = 0x4205; -pub const PTRACE_SEIZE: ::c_int = 0x4206; -pub const PTRACE_INTERRUPT: ::c_int = 0x4207; -pub const PTRACE_LISTEN: ::c_int = 0x4208; -pub const PTRACE_PEEKSIGINFO: ::c_int = 0x4209; - -pub const EPOLLWAKEUP: ::c_int = 0x20000000; - -pub const SEEK_DATA: ::c_int = 3; -pub const SEEK_HOLE: ::c_int = 4; - -pub const EFD_NONBLOCK: ::c_int = ::O_NONBLOCK; - -pub const SFD_NONBLOCK: ::c_int = ::O_NONBLOCK; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_NOLOAD: ::c_int = 0x4; - -// TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux -// kernel 3.10). See also linux_like/mod.rs -pub const CLOCK_SGI_CYCLE: ::clockid_t = 10; -pub const CLOCK_TAI: ::clockid_t = 11; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; - -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SO_MARK: ::c_int = 36; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_BUSY_POLL: ::c_int = 46; - -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_LOCKS: ::c_int = 10; -pub const RLIMIT_SIGPENDING: ::c_int = 11; -pub const RLIMIT_MSGQUEUE: ::c_int = 12; -pub const RLIMIT_NICE: ::c_int = 13; -pub const RLIMIT_RTPRIO: ::c_int = 14; - -extern "C" { - pub fn sendmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_uint, - ) -> ::c_int; - pub fn recvmmsg( - sockfd: ::c_int, - msgvec: *mut ::mmsghdr, - vlen: ::c_uint, - flags: ::c_uint, - timeout: *mut ::timespec, - ) -> ::c_int; - - pub fn getrlimit64(resource: ::c_int, rlim: *mut ::rlimit64) -> ::c_int; - pub fn setrlimit64(resource: ::c_int, rlim: *const ::rlimit64) -> ::c_int; - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - pub fn prlimit( - pid: ::pid_t, - resource: ::c_int, - new_limit: *const ::rlimit, - old_limit: *mut ::rlimit, - ) -> ::c_int; - pub fn prlimit64( - pid: ::pid_t, - resource: ::c_int, - new_limit: *const ::rlimit64, - old_limit: *mut ::rlimit64, - ) -> ::c_int; - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn ptrace(request: ::c_int, ...) -> ::c_long; - pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int; - pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int; - pub fn pthread_getaffinity_np( - thread: ::pthread_t, - cpusetsize: ::size_t, - cpuset: *mut ::cpu_set_t, - ) -> ::c_int; - pub fn pthread_setaffinity_np( - thread: ::pthread_t, - cpusetsize: ::size_t, - cpuset: *const ::cpu_set_t, - ) -> ::c_int; - pub fn sched_getcpu() -> ::c_int; -} - -cfg_if! { - if #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "mips64", - target_arch = "powerpc64"))] { - mod b64; - pub use self::b64::*; - } else if #[cfg(any(target_arch = "x86", - target_arch = "mips", - target_arch = "powerpc", - target_arch = "hexagon", - target_arch = "arm"))] { - mod b32; - pub use self::b32::*; - } else { } -} diff --git a/libc/src/unix/linux_like/linux/no_align.rs b/libc/src/unix/linux_like/linux/no_align.rs deleted file mode 100644 index 13c2b71..0000000 --- a/libc/src/unix/linux_like/linux/no_align.rs +++ /dev/null @@ -1,84 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - pub struct pthread_mutexattr_t { - #[cfg(any(target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64", - all(target_arch = "aarch64", - target_env = "musl")))] - __align: [::c_int; 0], - #[cfg(not(any(target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64", - all(target_arch = "aarch64", - target_env = "musl"))))] - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - pub struct pthread_rwlockattr_t { - #[cfg(target_env = "musl")] - __align: [::c_int; 0], - #[cfg(not(target_env = "musl"))] - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T], - } - - pub struct pthread_condattr_t { - __align: [::c_int; 0], - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - - s_no_extra_traits! { - pub struct pthread_cond_t { - #[cfg(target_env = "musl")] - __align: [*const ::c_void; 0], - #[cfg(not(target_env = "musl"))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - pub struct pthread_mutex_t { - #[cfg(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "sparc", - all(target_arch = "x86_64", - target_pointer_width = "32")))] - __align: [::c_long; 0], - #[cfg(not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "sparc", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - pub struct pthread_rwlock_t { - #[cfg(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "sparc", - all(target_arch = "x86_64", - target_pointer_width = "32")))] - __align: [::c_long; 0], - #[cfg(not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc", - target_arch = "sparc", - all(target_arch = "x86_64", - target_pointer_width = "32"))))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - } - }; -} diff --git a/libc/src/unix/linux_like/mod.rs b/libc/src/unix/linux_like/mod.rs deleted file mode 100644 index 792548f..0000000 --- a/libc/src/unix/linux_like/mod.rs +++ /dev/null @@ -1,1569 +0,0 @@ -pub type sa_family_t = u16; -pub type speed_t = ::c_uint; -pub type tcflag_t = ::c_uint; -pub type clockid_t = ::c_int; -pub type key_t = ::c_int; -pub type id_t = ::c_uint; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} - -s! { - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct ip_mreq_source { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - pub imr_sourceaddr: in_addr, - } - - pub struct sockaddr { - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_family: sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [u8; 8], - } - - pub struct sockaddr_in6 { - pub sin6_family: sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: socklen_t, - - #[cfg(any(target_os = "linux", - target_os = "emscripten"))] - pub ai_addr: *mut ::sockaddr, - - pub ai_canonname: *mut c_char, - - #[cfg(target_os = "android")] - pub ai_addr: *mut ::sockaddr, - - pub ai_next: *mut addrinfo, - } - - pub struct sockaddr_ll { - pub sll_family: ::c_ushort, - pub sll_protocol: ::c_ushort, - pub sll_ifindex: ::c_int, - pub sll_hatype: ::c_ushort, - pub sll_pkttype: ::c_uchar, - pub sll_halen: ::c_uchar, - pub sll_addr: [::c_uchar; 8] - } - - pub struct fd_set { - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - pub tm_gmtoff: ::c_long, - pub tm_zone: *const ::c_char, - } - - pub struct sched_param { - pub sched_priority: ::c_int, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] - pub sched_ss_low_priority: ::c_int, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] - pub sched_ss_repl_period: ::timespec, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] - pub sched_ss_init_budget: ::timespec, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] - pub sched_ss_max_repl: ::c_int, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct in_pktinfo { - pub ipi_ifindex: ::c_int, - pub ipi_spec_dst: ::in_addr, - pub ipi_addr: ::in_addr, - } - - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut c_char, - pub ifa_flags: ::c_uint, - pub ifa_addr: *mut ::sockaddr, - pub ifa_netmask: *mut ::sockaddr, - pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union - pub ifa_data: *mut ::c_void - } - - pub struct in6_rtmsg { - rtmsg_dst: ::in6_addr, - rtmsg_src: ::in6_addr, - rtmsg_gateway: ::in6_addr, - rtmsg_type: u32, - rtmsg_dst_len: u16, - rtmsg_src_len: u16, - rtmsg_metric: u32, - rtmsg_info: ::c_ulong, - rtmsg_flags: u32, - rtmsg_ifindex: ::c_int, - } - - pub struct arpreq { - pub arp_pa: ::sockaddr, - pub arp_ha: ::sockaddr, - pub arp_flags: ::c_int, - pub arp_netmask: ::sockaddr, - pub arp_dev: [::c_char; 16], - } - - pub struct arpreq_old { - pub arp_pa: ::sockaddr, - pub arp_ha: ::sockaddr, - pub arp_flags: ::c_int, - pub arp_netmask: ::sockaddr, - } - - pub struct arphdr { - pub ar_hrd: u16, - pub ar_pro: u16, - pub ar_hln: u8, - pub ar_pln: u8, - pub ar_op: u16, - } - - pub struct mmsghdr { - pub msg_hdr: ::msghdr, - pub msg_len: ::c_uint, - } -} - -s_no_extra_traits! { - #[cfg_attr( - any( - all( - target_arch = "x86", - not(target_env = "musl"), - not(target_os = "android")), - target_arch = "x86_64"), - repr(packed))] - pub struct epoll_event { - pub events: u32, - pub u64: u64, - } - - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 108] - } - - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - __ss_align: ::size_t, - #[cfg(target_pointer_width = "32")] - __ss_pad2: [u8; 128 - 2 * 4], - #[cfg(target_pointer_width = "64")] - __ss_pad2: [u8; 128 - 2 * 8], - } - - pub struct utsname { - pub sysname: [::c_char; 65], - pub nodename: [::c_char; 65], - pub release: [::c_char; 65], - pub version: [::c_char; 65], - pub machine: [::c_char; 65], - pub domainname: [::c_char; 65] - } - - pub struct sigevent { - pub sigev_value: ::sigval, - pub sigev_signo: ::c_int, - pub sigev_notify: ::c_int, - // Actually a union. We only expose sigev_notify_thread_id because it's - // the most useful member - pub sigev_notify_thread_id: ::c_int, - #[cfg(target_pointer_width = "64")] - __unused1: [::c_int; 11], - #[cfg(target_pointer_width = "32")] - __unused1: [::c_int; 12] - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for epoll_event { - fn eq(&self, other: &epoll_event) -> bool { - self.events == other.events - && self.u64 == other.u64 - } - } - impl Eq for epoll_event {} - impl ::fmt::Debug for epoll_event { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - let events = self.events; - let u64 = self.u64; - f.debug_struct("epoll_event") - .field("events", &events) - .field("u64", &u64) - .finish() - } - } - impl ::hash::Hash for epoll_event { - fn hash(&self, state: &mut H) { - let events = self.events; - let u64 = self.u64; - events.hash(state); - u64.hash(state); - } - } - - impl PartialEq for sockaddr_un { - fn eq(&self, other: &sockaddr_un) -> bool { - self.sun_family == other.sun_family - && self - .sun_path - .iter() - .zip(other.sun_path.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for sockaddr_un {} - impl ::fmt::Debug for sockaddr_un { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_un") - .field("sun_family", &self.sun_family) - // FIXME: .field("sun_path", &self.sun_path) - .finish() - } - } - impl ::hash::Hash for sockaddr_un { - fn hash(&self, state: &mut H) { - self.sun_family.hash(state); - self.sun_path.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_family == other.ss_family - && self - .__ss_pad2 - .iter() - .zip(other.__ss_pad2.iter()) - .all(|(a, b)| a == b) - } - } - - impl Eq for sockaddr_storage {} - - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_family", &self.ss_family) - .field("__ss_align", &self.__ss_align) - // FIXME: .field("__ss_pad2", &self.__ss_pad2) - .finish() - } - } - - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_family.hash(state); - self.__ss_pad2.hash(state); - } - } - - impl PartialEq for utsname { - fn eq(&self, other: &utsname) -> bool { - self.sysname - .iter() - .zip(other.sysname.iter()) - .all(|(a, b)| a == b) - && self - .nodename - .iter() - .zip(other.nodename.iter()) - .all(|(a, b)| a == b) - && self - .release - .iter() - .zip(other.release.iter()) - .all(|(a, b)| a == b) - && self - .version - .iter() - .zip(other.version.iter()) - .all(|(a, b)| a == b) - && self - .machine - .iter() - .zip(other.machine.iter()) - .all(|(a, b)| a == b) - && self - .domainname - .iter() - .zip(other.domainname.iter()) - .all(|(a, b)| a == b) - } - } - - impl Eq for utsname {} - - impl ::fmt::Debug for utsname { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utsname") - // FIXME: .field("sysname", &self.sysname) - // FIXME: .field("nodename", &self.nodename) - // FIXME: .field("release", &self.release) - // FIXME: .field("version", &self.version) - // FIXME: .field("machine", &self.machine) - // FIXME: .field("domainname", &self.domainname) - .finish() - } - } - - impl ::hash::Hash for utsname { - fn hash(&self, state: &mut H) { - self.sysname.hash(state); - self.nodename.hash(state); - self.release.hash(state); - self.version.hash(state); - self.machine.hash(state); - self.domainname.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_value == other.sigev_value - && self.sigev_signo == other.sigev_signo - && self.sigev_notify == other.sigev_notify - && self.sigev_notify_thread_id - == other.sigev_notify_thread_id - } - } - impl Eq for sigevent {} - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_value", &self.sigev_value) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_notify", &self.sigev_notify) - .field("sigev_notify_thread_id", - &self.sigev_notify_thread_id) - .finish() - } - } - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_value.hash(state); - self.sigev_signo.hash(state); - self.sigev_notify.hash(state); - self.sigev_notify_thread_id.hash(state); - } - } - } -} - -// intentionally not public, only used for fd_set -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - const ULONG_SIZE: usize = 32; - } else if #[cfg(target_pointer_width = "64")] { - const ULONG_SIZE: usize = 64; - } else { - // Unknown target_pointer_width - } -} - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const RAND_MAX: ::c_int = 2147483647; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 2; -pub const _IOLBF: ::c_int = 1; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; - -// Linux-specific fcntls -pub const F_SETLEASE: ::c_int = 1024; -pub const F_GETLEASE: ::c_int = 1025; -pub const F_NOTIFY: ::c_int = 1026; -pub const F_CANCELLK: ::c_int = 1029; -pub const F_DUPFD_CLOEXEC: ::c_int = 1030; -pub const F_SETPIPE_SZ: ::c_int = 1031; -pub const F_GETPIPE_SZ: ::c_int = 1032; -pub const F_ADD_SEALS: ::c_int = 1033; -pub const F_GET_SEALS: ::c_int = 1034; - -pub const F_SEAL_SEAL: ::c_int = 0x0001; -pub const F_SEAL_SHRINK: ::c_int = 0x0002; -pub const F_SEAL_GROW: ::c_int = 0x0004; -pub const F_SEAL_WRITE: ::c_int = 0x0008; - -// TODO(#235): Include file sealing fcntls once we have a way to verify them. - -pub const SIGTRAP: ::c_int = 5; - -pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0; -pub const PTHREAD_CREATE_DETACHED: ::c_int = 1; - -pub const CLOCK_REALTIME: ::clockid_t = 0; -pub const CLOCK_MONOTONIC: ::clockid_t = 1; -pub const CLOCK_PROCESS_CPUTIME_ID: ::clockid_t = 2; -pub const CLOCK_THREAD_CPUTIME_ID: ::clockid_t = 3; -pub const CLOCK_MONOTONIC_RAW: ::clockid_t = 4; -pub const CLOCK_REALTIME_COARSE: ::clockid_t = 5; -pub const CLOCK_MONOTONIC_COARSE: ::clockid_t = 6; -pub const CLOCK_BOOTTIME: ::clockid_t = 7; -pub const CLOCK_REALTIME_ALARM: ::clockid_t = 8; -pub const CLOCK_BOOTTIME_ALARM: ::clockid_t = 9; -// TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep -// 2014.) See also musl/mod.rs -// pub const CLOCK_SGI_CYCLE: ::clockid_t = 10; -// pub const CLOCK_TAI: ::clockid_t = 11; -pub const TIMER_ABSTIME: ::c_int = 1; - -pub const RUSAGE_SELF: ::c_int = 0; - -pub const O_RDONLY: ::c_int = 0; -pub const O_WRONLY: ::c_int = 1; -pub const O_RDWR: ::c_int = 2; - -pub const SOCK_CLOEXEC: ::c_int = O_CLOEXEC; - -pub const S_IFIFO: ::mode_t = 4096; -pub const S_IFCHR: ::mode_t = 8192; -pub const S_IFBLK: ::mode_t = 24576; -pub const S_IFDIR: ::mode_t = 16384; -pub const S_IFREG: ::mode_t = 32768; -pub const S_IFLNK: ::mode_t = 40960; -pub const S_IFSOCK: ::mode_t = 49152; -pub const S_IFMT: ::mode_t = 61440; -pub const S_IRWXU: ::mode_t = 448; -pub const S_IXUSR: ::mode_t = 64; -pub const S_IWUSR: ::mode_t = 128; -pub const S_IRUSR: ::mode_t = 256; -pub const S_IRWXG: ::mode_t = 56; -pub const S_IXGRP: ::mode_t = 8; -pub const S_IWGRP: ::mode_t = 16; -pub const S_IRGRP: ::mode_t = 32; -pub const S_IRWXO: ::mode_t = 7; -pub const S_IXOTH: ::mode_t = 1; -pub const S_IWOTH: ::mode_t = 2; -pub const S_IROTH: ::mode_t = 4; -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGABRT: ::c_int = 6; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSEGV: ::c_int = 11; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_READ: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_EXEC: ::c_int = 4; - -pub const LC_CTYPE: ::c_int = 0; -pub const LC_NUMERIC: ::c_int = 1; -pub const LC_TIME: ::c_int = 2; -pub const LC_COLLATE: ::c_int = 3; -pub const LC_MONETARY: ::c_int = 4; -pub const LC_MESSAGES: ::c_int = 5; -pub const LC_ALL: ::c_int = 6; -pub const LC_CTYPE_MASK: ::c_int = (1 << LC_CTYPE); -pub const LC_NUMERIC_MASK: ::c_int = (1 << LC_NUMERIC); -pub const LC_TIME_MASK: ::c_int = (1 << LC_TIME); -pub const LC_COLLATE_MASK: ::c_int = (1 << LC_COLLATE); -pub const LC_MONETARY_MASK: ::c_int = (1 << LC_MONETARY); -pub const LC_MESSAGES_MASK: ::c_int = (1 << LC_MESSAGES); -// LC_ALL_MASK defined per platform - -pub const MAP_FILE: ::c_int = 0x0000; -pub const MAP_SHARED: ::c_int = 0x0001; -pub const MAP_PRIVATE: ::c_int = 0x0002; -pub const MAP_FIXED: ::c_int = 0x0010; - -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -// MS_ flags for msync(2) -pub const MS_ASYNC: ::c_int = 0x0001; -pub const MS_INVALIDATE: ::c_int = 0x0002; -pub const MS_SYNC: ::c_int = 0x0004; - -// MS_ flags for mount(2) -pub const MS_RDONLY: ::c_ulong = 0x01; -pub const MS_NOSUID: ::c_ulong = 0x02; -pub const MS_NODEV: ::c_ulong = 0x04; -pub const MS_NOEXEC: ::c_ulong = 0x08; -pub const MS_SYNCHRONOUS: ::c_ulong = 0x10; -pub const MS_REMOUNT: ::c_ulong = 0x20; -pub const MS_MANDLOCK: ::c_ulong = 0x40; -pub const MS_DIRSYNC: ::c_ulong = 0x80; -pub const MS_NOATIME: ::c_ulong = 0x0400; -pub const MS_NODIRATIME: ::c_ulong = 0x0800; -pub const MS_BIND: ::c_ulong = 0x1000; -pub const MS_MOVE: ::c_ulong = 0x2000; -pub const MS_REC: ::c_ulong = 0x4000; -pub const MS_SILENT: ::c_ulong = 0x8000; -pub const MS_POSIXACL: ::c_ulong = 0x010000; -pub const MS_UNBINDABLE: ::c_ulong = 0x020000; -pub const MS_PRIVATE: ::c_ulong = 0x040000; -pub const MS_SLAVE: ::c_ulong = 0x080000; -pub const MS_SHARED: ::c_ulong = 0x100000; -pub const MS_RELATIME: ::c_ulong = 0x200000; -pub const MS_KERNMOUNT: ::c_ulong = 0x400000; -pub const MS_I_VERSION: ::c_ulong = 0x800000; -pub const MS_STRICTATIME: ::c_ulong = 0x1000000; -pub const MS_ACTIVE: ::c_ulong = 0x40000000; -pub const MS_MGC_VAL: ::c_ulong = 0xc0ed0000; -pub const MS_MGC_MSK: ::c_ulong = 0xffff0000; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EAGAIN: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const ENOTBLK: ::c_int = 15; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const EWOULDBLOCK: ::c_int = EAGAIN; - -pub const SCM_RIGHTS: ::c_int = 0x01; -pub const SCM_CREDENTIALS: ::c_int = 0x02; - -pub const PROT_GROWSDOWN: ::c_int = 0x1000000; -pub const PROT_GROWSUP: ::c_int = 0x2000000; - -pub const MAP_TYPE: ::c_int = 0x000f; - -pub const MADV_NORMAL: ::c_int = 0; -pub const MADV_RANDOM: ::c_int = 1; -pub const MADV_SEQUENTIAL: ::c_int = 2; -pub const MADV_WILLNEED: ::c_int = 3; -pub const MADV_DONTNEED: ::c_int = 4; -pub const MADV_FREE: ::c_int = 8; -pub const MADV_REMOVE: ::c_int = 9; -pub const MADV_DONTFORK: ::c_int = 10; -pub const MADV_DOFORK: ::c_int = 11; -pub const MADV_MERGEABLE: ::c_int = 12; -pub const MADV_UNMERGEABLE: ::c_int = 13; -pub const MADV_HUGEPAGE: ::c_int = 14; -pub const MADV_NOHUGEPAGE: ::c_int = 15; -pub const MADV_DONTDUMP: ::c_int = 16; -pub const MADV_DODUMP: ::c_int = 17; -pub const MADV_HWPOISON: ::c_int = 100; - -pub const IFF_UP: ::c_int = 0x1; -pub const IFF_BROADCAST: ::c_int = 0x2; -pub const IFF_DEBUG: ::c_int = 0x4; -pub const IFF_LOOPBACK: ::c_int = 0x8; -pub const IFF_POINTOPOINT: ::c_int = 0x10; -pub const IFF_NOTRAILERS: ::c_int = 0x20; -pub const IFF_RUNNING: ::c_int = 0x40; -pub const IFF_NOARP: ::c_int = 0x80; -pub const IFF_PROMISC: ::c_int = 0x100; -pub const IFF_ALLMULTI: ::c_int = 0x200; -pub const IFF_MASTER: ::c_int = 0x400; -pub const IFF_SLAVE: ::c_int = 0x800; -pub const IFF_MULTICAST: ::c_int = 0x1000; -pub const IFF_PORTSEL: ::c_int = 0x2000; -pub const IFF_AUTOMEDIA: ::c_int = 0x4000; -pub const IFF_DYNAMIC: ::c_int = 0x8000; - -pub const SOL_IP: ::c_int = 0; -pub const SOL_TCP: ::c_int = 6; -pub const SOL_UDP: ::c_int = 17; -pub const SOL_IPV6: ::c_int = 41; -pub const SOL_ICMPV6: ::c_int = 58; -pub const SOL_RAW: ::c_int = 255; -pub const SOL_DECNET: ::c_int = 261; -pub const SOL_X25: ::c_int = 262; -pub const SOL_PACKET: ::c_int = 263; -pub const SOL_ATM: ::c_int = 264; -pub const SOL_AAL: ::c_int = 265; -pub const SOL_IRDA: ::c_int = 266; -pub const SOL_NETBEUI: ::c_int = 267; -pub const SOL_LLC: ::c_int = 268; -pub const SOL_DCCP: ::c_int = 269; -pub const SOL_NETLINK: ::c_int = 270; -pub const SOL_TIPC: ::c_int = 271; -pub const SOL_BLUETOOTH: ::c_int = 274; -pub const SOL_ALG: ::c_int = 279; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_UNIX: ::c_int = 1; -pub const AF_LOCAL: ::c_int = 1; -pub const AF_INET: ::c_int = 2; -pub const AF_AX25: ::c_int = 3; -pub const AF_IPX: ::c_int = 4; -pub const AF_APPLETALK: ::c_int = 5; -pub const AF_NETROM: ::c_int = 6; -pub const AF_BRIDGE: ::c_int = 7; -pub const AF_ATMPVC: ::c_int = 8; -pub const AF_X25: ::c_int = 9; -pub const AF_INET6: ::c_int = 10; -pub const AF_ROSE: ::c_int = 11; -pub const AF_DECnet: ::c_int = 12; -pub const AF_NETBEUI: ::c_int = 13; -pub const AF_SECURITY: ::c_int = 14; -pub const AF_KEY: ::c_int = 15; -pub const AF_NETLINK: ::c_int = 16; -pub const AF_ROUTE: ::c_int = AF_NETLINK; -pub const AF_PACKET: ::c_int = 17; -pub const AF_ASH: ::c_int = 18; -pub const AF_ECONET: ::c_int = 19; -pub const AF_ATMSVC: ::c_int = 20; -pub const AF_RDS: ::c_int = 21; -pub const AF_SNA: ::c_int = 22; -pub const AF_IRDA: ::c_int = 23; -pub const AF_PPPOX: ::c_int = 24; -pub const AF_WANPIPE: ::c_int = 25; -pub const AF_LLC: ::c_int = 26; -pub const AF_CAN: ::c_int = 29; -pub const AF_TIPC: ::c_int = 30; -pub const AF_BLUETOOTH: ::c_int = 31; -pub const AF_IUCV: ::c_int = 32; -pub const AF_RXRPC: ::c_int = 33; -pub const AF_ISDN: ::c_int = 34; -pub const AF_PHONET: ::c_int = 35; -pub const AF_IEEE802154: ::c_int = 36; -pub const AF_CAIF: ::c_int = 37; -pub const AF_ALG: ::c_int = 38; - -pub const PF_UNSPEC: ::c_int = AF_UNSPEC; -pub const PF_UNIX: ::c_int = AF_UNIX; -pub const PF_LOCAL: ::c_int = AF_LOCAL; -pub const PF_INET: ::c_int = AF_INET; -pub const PF_AX25: ::c_int = AF_AX25; -pub const PF_IPX: ::c_int = AF_IPX; -pub const PF_APPLETALK: ::c_int = AF_APPLETALK; -pub const PF_NETROM: ::c_int = AF_NETROM; -pub const PF_BRIDGE: ::c_int = AF_BRIDGE; -pub const PF_ATMPVC: ::c_int = AF_ATMPVC; -pub const PF_X25: ::c_int = AF_X25; -pub const PF_INET6: ::c_int = AF_INET6; -pub const PF_ROSE: ::c_int = AF_ROSE; -pub const PF_DECnet: ::c_int = AF_DECnet; -pub const PF_NETBEUI: ::c_int = AF_NETBEUI; -pub const PF_SECURITY: ::c_int = AF_SECURITY; -pub const PF_KEY: ::c_int = AF_KEY; -pub const PF_NETLINK: ::c_int = AF_NETLINK; -pub const PF_ROUTE: ::c_int = AF_ROUTE; -pub const PF_PACKET: ::c_int = AF_PACKET; -pub const PF_ASH: ::c_int = AF_ASH; -pub const PF_ECONET: ::c_int = AF_ECONET; -pub const PF_ATMSVC: ::c_int = AF_ATMSVC; -pub const PF_RDS: ::c_int = AF_RDS; -pub const PF_SNA: ::c_int = AF_SNA; -pub const PF_IRDA: ::c_int = AF_IRDA; -pub const PF_PPPOX: ::c_int = AF_PPPOX; -pub const PF_WANPIPE: ::c_int = AF_WANPIPE; -pub const PF_LLC: ::c_int = AF_LLC; -pub const PF_CAN: ::c_int = AF_CAN; -pub const PF_TIPC: ::c_int = AF_TIPC; -pub const PF_BLUETOOTH: ::c_int = AF_BLUETOOTH; -pub const PF_IUCV: ::c_int = AF_IUCV; -pub const PF_RXRPC: ::c_int = AF_RXRPC; -pub const PF_ISDN: ::c_int = AF_ISDN; -pub const PF_PHONET: ::c_int = AF_PHONET; -pub const PF_IEEE802154: ::c_int = AF_IEEE802154; -pub const PF_CAIF: ::c_int = AF_CAIF; -pub const PF_ALG: ::c_int = AF_ALG; - -pub const SOMAXCONN: ::c_int = 128; - -pub const MSG_OOB: ::c_int = 1; -pub const MSG_PEEK: ::c_int = 2; -pub const MSG_DONTROUTE: ::c_int = 4; -pub const MSG_CTRUNC: ::c_int = 8; -pub const MSG_TRUNC: ::c_int = 0x20; -pub const MSG_DONTWAIT: ::c_int = 0x40; -pub const MSG_EOR: ::c_int = 0x80; -pub const MSG_WAITALL: ::c_int = 0x100; -pub const MSG_FIN: ::c_int = 0x200; -pub const MSG_SYN: ::c_int = 0x400; -pub const MSG_CONFIRM: ::c_int = 0x800; -pub const MSG_RST: ::c_int = 0x1000; -pub const MSG_ERRQUEUE: ::c_int = 0x2000; -pub const MSG_NOSIGNAL: ::c_int = 0x4000; -pub const MSG_MORE: ::c_int = 0x8000; -pub const MSG_WAITFORONE: ::c_int = 0x10000; -pub const MSG_FASTOPEN: ::c_int = 0x20000000; -pub const MSG_CMSG_CLOEXEC: ::c_int = 0x40000000; - -pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP; - -pub const SOCK_RAW: ::c_int = 3; -pub const SOCK_RDM: ::c_int = 4; -pub const IP_MULTICAST_IF: ::c_int = 32; -pub const IP_MULTICAST_TTL: ::c_int = 33; -pub const IP_MULTICAST_LOOP: ::c_int = 34; -pub const IP_TOS: ::c_int = 1; -pub const IP_TTL: ::c_int = 2; -pub const IP_HDRINCL: ::c_int = 3; -pub const IP_PKTINFO: ::c_int = 8; -pub const IP_RECVTOS: ::c_int = 13; -pub const IP_RECVERR: ::c_int = 11; -pub const IP_ADD_MEMBERSHIP: ::c_int = 35; -pub const IP_DROP_MEMBERSHIP: ::c_int = 36; -pub const IP_ADD_SOURCE_MEMBERSHIP: ::c_int = 39; -pub const IP_DROP_SOURCE_MEMBERSHIP: ::c_int = 40; -pub const IP_TRANSPARENT: ::c_int = 19; -pub const IPV6_ADDRFORM: ::c_int = 1; -pub const IPV6_2292PKTINFO: ::c_int = 2; -pub const IPV6_2292HOPOPTS: ::c_int = 3; -pub const IPV6_2292DSTOPTS: ::c_int = 4; -pub const IPV6_2292RTHDR: ::c_int = 5; -pub const IPV6_2292PKTOPTIONS: ::c_int = 6; -pub const IPV6_CHECKSUM: ::c_int = 7; -pub const IPV6_2292HOPLIMIT: ::c_int = 8; -pub const IPV6_NEXTHOP: ::c_int = 9; -pub const IPV6_FLOWINFO: ::c_int = 11; -pub const IPV6_UNICAST_HOPS: ::c_int = 16; -pub const IPV6_MULTICAST_IF: ::c_int = 17; -pub const IPV6_MULTICAST_HOPS: ::c_int = 18; -pub const IPV6_MULTICAST_LOOP: ::c_int = 19; -pub const IPV6_ADD_MEMBERSHIP: ::c_int = 20; -pub const IPV6_DROP_MEMBERSHIP: ::c_int = 21; -pub const IPV6_ROUTER_ALERT: ::c_int = 22; -pub const IPV6_MTU_DISCOVER: ::c_int = 23; -pub const IPV6_MTU: ::c_int = 24; -pub const IPV6_RECVERR: ::c_int = 25; -pub const IPV6_V6ONLY: ::c_int = 26; -pub const IPV6_JOIN_ANYCAST: ::c_int = 27; -pub const IPV6_LEAVE_ANYCAST: ::c_int = 28; -pub const IPV6_RECVPKTINFO: ::c_int = 49; -pub const IPV6_PKTINFO: ::c_int = 50; -pub const IPV6_RECVTCLASS: ::c_int = 66; -pub const IPV6_TCLASS: ::c_int = 67; - -pub const TCP_NODELAY: ::c_int = 1; -pub const TCP_MAXSEG: ::c_int = 2; -pub const TCP_CORK: ::c_int = 3; -pub const TCP_KEEPIDLE: ::c_int = 4; -pub const TCP_KEEPINTVL: ::c_int = 5; -pub const TCP_KEEPCNT: ::c_int = 6; -pub const TCP_SYNCNT: ::c_int = 7; -pub const TCP_LINGER2: ::c_int = 8; -pub const TCP_DEFER_ACCEPT: ::c_int = 9; -pub const TCP_WINDOW_CLAMP: ::c_int = 10; -pub const TCP_INFO: ::c_int = 11; -pub const TCP_QUICKACK: ::c_int = 12; -pub const TCP_CONGESTION: ::c_int = 13; - -pub const SO_DEBUG: ::c_int = 1; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const LOCK_SH: ::c_int = 1; -pub const LOCK_EX: ::c_int = 2; -pub const LOCK_NB: ::c_int = 4; -pub const LOCK_UN: ::c_int = 8; - -pub const SS_ONSTACK: ::c_int = 1; -pub const SS_DISABLE: ::c_int = 2; - -pub const PATH_MAX: ::c_int = 4096; - -pub const FD_SETSIZE: usize = 1024; - -pub const EPOLLIN: ::c_int = 0x1; -pub const EPOLLPRI: ::c_int = 0x2; -pub const EPOLLOUT: ::c_int = 0x4; -pub const EPOLLRDNORM: ::c_int = 0x40; -pub const EPOLLRDBAND: ::c_int = 0x80; -pub const EPOLLWRNORM: ::c_int = 0x100; -pub const EPOLLWRBAND: ::c_int = 0x200; -pub const EPOLLMSG: ::c_int = 0x400; -pub const EPOLLERR: ::c_int = 0x8; -pub const EPOLLHUP: ::c_int = 0x10; -pub const EPOLLET: ::c_int = 0x80000000; - -pub const EPOLL_CTL_ADD: ::c_int = 1; -pub const EPOLL_CTL_MOD: ::c_int = 3; -pub const EPOLL_CTL_DEL: ::c_int = 2; - -pub const MNT_DETACH: ::c_int = 0x2; -pub const MNT_EXPIRE: ::c_int = 0x4; - -pub const Q_GETFMT: ::c_int = 0x800004; -pub const Q_GETINFO: ::c_int = 0x800005; -pub const Q_SETINFO: ::c_int = 0x800006; -pub const QIF_BLIMITS: u32 = 1; -pub const QIF_SPACE: u32 = 2; -pub const QIF_ILIMITS: u32 = 4; -pub const QIF_INODES: u32 = 8; -pub const QIF_BTIME: u32 = 16; -pub const QIF_ITIME: u32 = 32; -pub const QIF_LIMITS: u32 = 5; -pub const QIF_USAGE: u32 = 10; -pub const QIF_TIMES: u32 = 48; -pub const QIF_ALL: u32 = 63; - -pub const MNT_FORCE: ::c_int = 0x1; - -pub const Q_SYNC: ::c_int = 0x800001; -pub const Q_QUOTAON: ::c_int = 0x800002; -pub const Q_QUOTAOFF: ::c_int = 0x800003; -pub const Q_GETQUOTA: ::c_int = 0x800007; -pub const Q_SETQUOTA: ::c_int = 0x800008; - -pub const TCIOFF: ::c_int = 2; -pub const TCION: ::c_int = 3; -pub const TCOOFF: ::c_int = 0; -pub const TCOON: ::c_int = 1; -pub const TCIFLUSH: ::c_int = 0; -pub const TCOFLUSH: ::c_int = 1; -pub const TCIOFLUSH: ::c_int = 2; -pub const NL0: ::tcflag_t = 0x00000000; -pub const NL1: ::tcflag_t = 0x00000100; -pub const TAB0: ::tcflag_t = 0x00000000; -pub const CR0: ::tcflag_t = 0x00000000; -pub const FF0: ::tcflag_t = 0x00000000; -pub const BS0: ::tcflag_t = 0x00000000; -pub const VT0: ::tcflag_t = 0x00000000; -pub const VERASE: usize = 2; -pub const VKILL: usize = 3; -pub const VINTR: usize = 0; -pub const VQUIT: usize = 1; -pub const VLNEXT: usize = 15; -pub const IGNBRK: ::tcflag_t = 0x00000001; -pub const BRKINT: ::tcflag_t = 0x00000002; -pub const IGNPAR: ::tcflag_t = 0x00000004; -pub const PARMRK: ::tcflag_t = 0x00000008; -pub const INPCK: ::tcflag_t = 0x00000010; -pub const ISTRIP: ::tcflag_t = 0x00000020; -pub const INLCR: ::tcflag_t = 0x00000040; -pub const IGNCR: ::tcflag_t = 0x00000080; -pub const ICRNL: ::tcflag_t = 0x00000100; -pub const IXANY: ::tcflag_t = 0x00000800; -pub const IMAXBEL: ::tcflag_t = 0x00002000; -pub const OPOST: ::tcflag_t = 0x1; -pub const CS5: ::tcflag_t = 0x00000000; -pub const CRTSCTS: ::tcflag_t = 0x80000000; -pub const ECHO: ::tcflag_t = 0x00000008; -pub const OCRNL: ::tcflag_t = 0o000010; -pub const ONOCR: ::tcflag_t = 0o000020; -pub const ONLRET: ::tcflag_t = 0o000040; -pub const OFILL: ::tcflag_t = 0o000100; -pub const OFDEL: ::tcflag_t = 0o000200; - -pub const CLONE_VM: ::c_int = 0x100; -pub const CLONE_FS: ::c_int = 0x200; -pub const CLONE_FILES: ::c_int = 0x400; -pub const CLONE_SIGHAND: ::c_int = 0x800; -pub const CLONE_PTRACE: ::c_int = 0x2000; -pub const CLONE_VFORK: ::c_int = 0x4000; -pub const CLONE_PARENT: ::c_int = 0x8000; -pub const CLONE_THREAD: ::c_int = 0x10000; -pub const CLONE_NEWNS: ::c_int = 0x20000; -pub const CLONE_SYSVSEM: ::c_int = 0x40000; -pub const CLONE_SETTLS: ::c_int = 0x80000; -pub const CLONE_PARENT_SETTID: ::c_int = 0x100000; -pub const CLONE_CHILD_CLEARTID: ::c_int = 0x200000; -pub const CLONE_DETACHED: ::c_int = 0x400000; -pub const CLONE_UNTRACED: ::c_int = 0x800000; -pub const CLONE_CHILD_SETTID: ::c_int = 0x01000000; -pub const CLONE_NEWUTS: ::c_int = 0x04000000; -pub const CLONE_NEWIPC: ::c_int = 0x08000000; -pub const CLONE_NEWUSER: ::c_int = 0x10000000; -pub const CLONE_NEWPID: ::c_int = 0x20000000; -pub const CLONE_NEWNET: ::c_int = 0x40000000; -pub const CLONE_IO: ::c_int = 0x80000000; -pub const CLONE_NEWCGROUP: ::c_int = 0x02000000; - -pub const WNOHANG: ::c_int = 0x00000001; -pub const WUNTRACED: ::c_int = 0x00000002; -pub const WSTOPPED: ::c_int = WUNTRACED; -pub const WEXITED: ::c_int = 0x00000004; -pub const WCONTINUED: ::c_int = 0x00000008; -pub const WNOWAIT: ::c_int = 0x01000000; - -// Options set using PTRACE_SETOPTIONS. -pub const PTRACE_O_TRACESYSGOOD: ::c_int = 0x00000001; -pub const PTRACE_O_TRACEFORK: ::c_int = 0x00000002; -pub const PTRACE_O_TRACEVFORK: ::c_int = 0x00000004; -pub const PTRACE_O_TRACECLONE: ::c_int = 0x00000008; -pub const PTRACE_O_TRACEEXEC: ::c_int = 0x00000010; -pub const PTRACE_O_TRACEVFORKDONE: ::c_int = 0x00000020; -pub const PTRACE_O_TRACEEXIT: ::c_int = 0x00000040; -pub const PTRACE_O_TRACESECCOMP: ::c_int = 0x00000080; -pub const PTRACE_O_EXITKILL: ::c_int = 0x00100000; -pub const PTRACE_O_SUSPEND_SECCOMP: ::c_int = 0x00200000; -pub const PTRACE_O_MASK: ::c_int = 0x003000ff; - -// Wait extended result codes for the above trace options. -pub const PTRACE_EVENT_FORK: ::c_int = 1; -pub const PTRACE_EVENT_VFORK: ::c_int = 2; -pub const PTRACE_EVENT_CLONE: ::c_int = 3; -pub const PTRACE_EVENT_EXEC: ::c_int = 4; -pub const PTRACE_EVENT_VFORK_DONE: ::c_int = 5; -pub const PTRACE_EVENT_EXIT: ::c_int = 6; -pub const PTRACE_EVENT_SECCOMP: ::c_int = 7; -// PTRACE_EVENT_STOP was added to glibc in 2.26 -// pub const PTRACE_EVENT_STOP: ::c_int = 128; - -pub const __WNOTHREAD: ::c_int = 0x20000000; -pub const __WALL: ::c_int = 0x40000000; -pub const __WCLONE: ::c_int = 0x80000000; - -pub const SPLICE_F_MOVE: ::c_uint = 0x01; -pub const SPLICE_F_NONBLOCK: ::c_uint = 0x02; -pub const SPLICE_F_MORE: ::c_uint = 0x04; -pub const SPLICE_F_GIFT: ::c_uint = 0x08; - -pub const RTLD_LOCAL: ::c_int = 0; -pub const RTLD_LAZY: ::c_int = 1; - -pub const POSIX_FADV_NORMAL: ::c_int = 0; -pub const POSIX_FADV_RANDOM: ::c_int = 1; -pub const POSIX_FADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_FADV_WILLNEED: ::c_int = 3; - -pub const AT_FDCWD: ::c_int = -100; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100; -pub const AT_REMOVEDIR: ::c_int = 0x200; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; -pub const AT_NO_AUTOMOUNT: ::c_int = 0x800; -pub const AT_EMPTY_PATH: ::c_int = 0x1000; - -pub const LOG_CRON: ::c_int = 9 << 3; -pub const LOG_AUTHPRIV: ::c_int = 10 << 3; -pub const LOG_FTP: ::c_int = 11 << 3; -pub const LOG_PERROR: ::c_int = 0x20; - -pub const PIPE_BUF: usize = 4096; - -pub const SI_LOAD_SHIFT: ::c_uint = 16; - -pub const SIGEV_SIGNAL: ::c_int = 0; -pub const SIGEV_NONE: ::c_int = 1; -pub const SIGEV_THREAD: ::c_int = 2; - -pub const P_ALL: idtype_t = 0; -pub const P_PID: idtype_t = 1; -pub const P_PGID: idtype_t = 2; - -pub const UTIME_OMIT: c_long = 1073741822; -pub const UTIME_NOW: c_long = 1073741823; - -pub const POLLIN: ::c_short = 0x1; -pub const POLLPRI: ::c_short = 0x2; -pub const POLLOUT: ::c_short = 0x4; -pub const POLLERR: ::c_short = 0x8; -pub const POLLHUP: ::c_short = 0x10; -pub const POLLNVAL: ::c_short = 0x20; -pub const POLLRDNORM: ::c_short = 0x040; -pub const POLLRDBAND: ::c_short = 0x080; - -pub const IPTOS_LOWDELAY: u8 = 0x10; -pub const IPTOS_THROUGHPUT: u8 = 0x08; -pub const IPTOS_RELIABILITY: u8 = 0x04; -pub const IPTOS_MINCOST: u8 = 0x02; - -pub const IPTOS_PREC_NETCONTROL: u8 = 0xe0; -pub const IPTOS_PREC_INTERNETCONTROL: u8 = 0xc0; -pub const IPTOS_PREC_CRITIC_ECP: u8 = 0xa0; -pub const IPTOS_PREC_FLASHOVERRIDE: u8 = 0x80; -pub const IPTOS_PREC_FLASH: u8 = 0x60; -pub const IPTOS_PREC_IMMEDIATE: u8 = 0x40; -pub const IPTOS_PREC_PRIORITY: u8 = 0x20; -pub const IPTOS_PREC_ROUTINE: u8 = 0x00; - -pub const IPTOS_ECN_MASK: u8 = 0x03; -pub const IPTOS_ECN_ECT1: u8 = 0x01; -pub const IPTOS_ECN_ECT0: u8 = 0x02; -pub const IPTOS_ECN_CE: u8 = 0x03; - -pub const IPOPT_COPY: u8 = 0x80; -pub const IPOPT_CLASS_MASK: u8 = 0x60; -pub const IPOPT_NUMBER_MASK: u8 = 0x1f; - -pub const IPOPT_CONTROL: u8 = 0x00; -pub const IPOPT_RESERVED1: u8 = 0x20; -pub const IPOPT_MEASUREMENT: u8 = 0x40; -pub const IPOPT_RESERVED2: u8 = 0x60; -pub const IPOPT_END: u8 = (0 | IPOPT_CONTROL); -pub const IPOPT_NOOP: u8 = (1 | IPOPT_CONTROL); -pub const IPOPT_SEC: u8 = (2 | IPOPT_CONTROL | IPOPT_COPY); -pub const IPOPT_LSRR: u8 = (3 | IPOPT_CONTROL | IPOPT_COPY); -pub const IPOPT_TIMESTAMP: u8 = (4 | IPOPT_MEASUREMENT); -pub const IPOPT_RR: u8 = (7 | IPOPT_CONTROL); -pub const IPOPT_SID: u8 = (8 | IPOPT_CONTROL | IPOPT_COPY); -pub const IPOPT_SSRR: u8 = (9 | IPOPT_CONTROL | IPOPT_COPY); -pub const IPOPT_RA: u8 = (20 | IPOPT_CONTROL | IPOPT_COPY); -pub const IPVERSION: u8 = 4; -pub const MAXTTL: u8 = 255; -pub const IPDEFTTL: u8 = 64; -pub const IPOPT_OPTVAL: u8 = 0; -pub const IPOPT_OLEN: u8 = 1; -pub const IPOPT_OFFSET: u8 = 2; -pub const IPOPT_MINOFF: u8 = 4; -pub const MAX_IPOPTLEN: u8 = 40; -pub const IPOPT_NOP: u8 = IPOPT_NOOP; -pub const IPOPT_EOL: u8 = IPOPT_END; -pub const IPOPT_TS: u8 = IPOPT_TIMESTAMP; -pub const IPOPT_TS_TSONLY: u8 = 0; -pub const IPOPT_TS_TSANDADDR: u8 = 1; -pub const IPOPT_TS_PRESPEC: u8 = 3; - -pub const ARPOP_RREQUEST: u16 = 3; -pub const ARPOP_RREPLY: u16 = 4; -pub const ARPOP_InREQUEST: u16 = 8; -pub const ARPOP_InREPLY: u16 = 9; -pub const ARPOP_NAK: u16 = 10; - -pub const ATF_NETMASK: ::c_int = 0x20; -pub const ATF_DONTPUB: ::c_int = 0x40; - -pub const ARPHRD_NETROM: u16 = 0; -pub const ARPHRD_ETHER: u16 = 1; -pub const ARPHRD_EETHER: u16 = 2; -pub const ARPHRD_AX25: u16 = 3; -pub const ARPHRD_PRONET: u16 = 4; -pub const ARPHRD_CHAOS: u16 = 5; -pub const ARPHRD_IEEE802: u16 = 6; -pub const ARPHRD_ARCNET: u16 = 7; -pub const ARPHRD_APPLETLK: u16 = 8; -pub const ARPHRD_DLCI: u16 = 15; -pub const ARPHRD_ATM: u16 = 19; -pub const ARPHRD_METRICOM: u16 = 23; -pub const ARPHRD_IEEE1394: u16 = 24; -pub const ARPHRD_EUI64: u16 = 27; -pub const ARPHRD_INFINIBAND: u16 = 32; - -pub const ARPHRD_SLIP: u16 = 256; -pub const ARPHRD_CSLIP: u16 = 257; -pub const ARPHRD_SLIP6: u16 = 258; -pub const ARPHRD_CSLIP6: u16 = 259; -pub const ARPHRD_RSRVD: u16 = 260; -pub const ARPHRD_ADAPT: u16 = 264; -pub const ARPHRD_ROSE: u16 = 270; -pub const ARPHRD_X25: u16 = 271; -pub const ARPHRD_HWX25: u16 = 272; -pub const ARPHRD_PPP: u16 = 512; -pub const ARPHRD_CISCO: u16 = 513; -pub const ARPHRD_HDLC: u16 = ARPHRD_CISCO; -pub const ARPHRD_LAPB: u16 = 516; -pub const ARPHRD_DDCMP: u16 = 517; -pub const ARPHRD_RAWHDLC: u16 = 518; - -pub const ARPHRD_TUNNEL: u16 = 768; -pub const ARPHRD_TUNNEL6: u16 = 769; -pub const ARPHRD_FRAD: u16 = 770; -pub const ARPHRD_SKIP: u16 = 771; -pub const ARPHRD_LOOPBACK: u16 = 772; -pub const ARPHRD_LOCALTLK: u16 = 773; -pub const ARPHRD_FDDI: u16 = 774; -pub const ARPHRD_BIF: u16 = 775; -pub const ARPHRD_SIT: u16 = 776; -pub const ARPHRD_IPDDP: u16 = 777; -pub const ARPHRD_IPGRE: u16 = 778; -pub const ARPHRD_PIMREG: u16 = 779; -pub const ARPHRD_HIPPI: u16 = 780; -pub const ARPHRD_ASH: u16 = 781; -pub const ARPHRD_ECONET: u16 = 782; -pub const ARPHRD_IRDA: u16 = 783; -pub const ARPHRD_FCPP: u16 = 784; -pub const ARPHRD_FCAL: u16 = 785; -pub const ARPHRD_FCPL: u16 = 786; -pub const ARPHRD_FCFABRIC: u16 = 787; -pub const ARPHRD_IEEE802_TR: u16 = 800; -pub const ARPHRD_IEEE80211: u16 = 801; -pub const ARPHRD_IEEE80211_PRISM: u16 = 802; -pub const ARPHRD_IEEE80211_RADIOTAP: u16 = 803; -pub const ARPHRD_IEEE802154: u16 = 804; - -pub const ARPHRD_VOID: u16 = 0xFFFF; -pub const ARPHRD_NONE: u16 = 0xFFFE; - -const_fn! { - {const} fn CMSG_ALIGN(len: usize) -> usize { - len + ::mem::size_of::() - 1 & !(::mem::size_of::() - 1) - } -} - -f! { - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= ::mem::size_of::() { - (*mhdr).msg_control as *mut cmsghdr - } else { - 0 as *mut cmsghdr - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut ::c_uchar { - cmsg.offset(1) as *mut ::c_uchar - } - - pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (CMSG_ALIGN(length as usize) + CMSG_ALIGN(::mem::size_of::())) - as ::c_uint - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - CMSG_ALIGN(::mem::size_of::()) as ::c_uint + length - } - - pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return - } - - pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 - } - - pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return - } - - pub fn FD_ZERO(set: *mut fd_set) -> () { - for slot in (*set).fds_bits.iter_mut() { - *slot = 0; - } - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0xff) == 0x7f - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WIFCONTINUED(status: ::c_int) -> bool { - status == 0xffff - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - ((status & 0x7f) + 1) as i8 >= 2 - } - - pub fn WTERMSIG(status: ::c_int) -> ::c_int { - status & 0x7f - } - - pub fn WIFEXITED(status: ::c_int) -> bool { - (status & 0x7f) == 0 - } - - pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WCOREDUMP(status: ::c_int) -> bool { - (status & 0x80) != 0 - } - - pub fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { - (cmd << 8) | (type_ & 0x00ff) - } - - pub fn IPOPT_COPIED(o: u8) -> u8 { - o & IPOPT_COPY - } - - pub fn IPOPT_CLASS(o: u8) -> u8 { - o & IPOPT_CLASS_MASK - } - - pub fn IPOPT_NUMBER(o: u8) -> u8 { - o & IPOPT_NUMBER_MASK - } - - pub fn IPTOS_ECN(x: u8) -> u8 { - x & ::IPTOS_ECN_MASK - } -} - -extern "C" { - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - pub fn fdatasync(fd: ::c_int) -> ::c_int; - pub fn mincore( - addr: *mut ::c_void, - len: ::size_t, - vec: *mut ::c_uchar, - ) -> ::c_int; - pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_settime( - clk_id: ::clockid_t, - tp: *const ::timespec, - ) -> ::c_int; - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - - pub fn pthread_getattr_np( - native: ::pthread_t, - attr: *mut ::pthread_attr_t, - ) -> ::c_int; - pub fn pthread_attr_getstack( - attr: *const ::pthread_attr_t, - stackaddr: *mut *mut ::c_void, - stacksize: *mut ::size_t, - ) -> ::c_int; - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; - pub fn setgroups(ngroups: ::size_t, ptr: *const ::gid_t) -> ::c_int; - pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int; - pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; - pub fn statfs64(path: *const ::c_char, buf: *mut statfs64) -> ::c_int; - pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; - pub fn fstatfs64(fd: ::c_int, buf: *mut statfs64) -> ::c_int; - pub fn statvfs64(path: *const ::c_char, buf: *mut statvfs64) -> ::c_int; - pub fn fstatvfs64(fd: ::c_int, buf: *mut statvfs64) -> ::c_int; - pub fn memrchr( - cx: *const ::c_void, - c: ::c_int, - n: ::size_t, - ) -> *mut ::c_void; - - pub fn posix_fadvise( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - advise: ::c_int, - ) -> ::c_int; - pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; - pub fn utimensat( - dirfd: ::c_int, - path: *const ::c_char, - times: *const ::timespec, - flag: ::c_int, - ) -> ::c_int; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn freelocale(loc: ::locale_t); - pub fn newlocale( - mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t, - ) -> ::locale_t; - pub fn uselocale(loc: ::locale_t) -> ::locale_t; - pub fn creat64(path: *const c_char, mode: mode_t) -> ::c_int; - pub fn fstat64(fildes: ::c_int, buf: *mut stat64) -> ::c_int; - pub fn fstatat64( - dirfd: ::c_int, - pathname: *const c_char, - buf: *mut stat64, - flags: ::c_int, - ) -> ::c_int; - pub fn ftruncate64(fd: ::c_int, length: off64_t) -> ::c_int; - pub fn lseek64(fd: ::c_int, offset: off64_t, whence: ::c_int) -> off64_t; - pub fn lstat64(path: *const c_char, buf: *mut stat64) -> ::c_int; - pub fn mmap64( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - flags: ::c_int, - fd: ::c_int, - offset: off64_t, - ) -> *mut ::c_void; - pub fn open64(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; - pub fn openat64( - fd: ::c_int, - path: *const c_char, - oflag: ::c_int, - ... - ) -> ::c_int; - pub fn pread64( - fd: ::c_int, - buf: *mut ::c_void, - count: ::size_t, - offset: off64_t, - ) -> ::ssize_t; - pub fn preadv64( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off64_t, - ) -> ::ssize_t; - pub fn pwrite64( - fd: ::c_int, - buf: *const ::c_void, - count: ::size_t, - offset: off64_t, - ) -> ::ssize_t; - pub fn pwritev64( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off64_t, - ) -> ::ssize_t; - pub fn readdir64(dirp: *mut ::DIR) -> *mut ::dirent64; - pub fn readdir64_r( - dirp: *mut ::DIR, - entry: *mut ::dirent64, - result: *mut *mut ::dirent64, - ) -> ::c_int; - pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int; - pub fn truncate64(path: *const c_char, length: off64_t) -> ::c_int; - - pub fn mknodat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - dev: dev_t, - ) -> ::c_int; - pub fn pthread_condattr_getclock( - attr: *const pthread_condattr_t, - clock_id: *mut clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_setclock( - attr: *mut pthread_condattr_t, - clock_id: ::clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_setpshared( - attr: *mut pthread_condattr_t, - pshared: ::c_int, - ) -> ::c_int; - pub fn accept4( - fd: ::c_int, - addr: *mut ::sockaddr, - len: *mut ::socklen_t, - flg: ::c_int, - ) -> ::c_int; - pub fn pthread_mutexattr_setpshared( - attr: *mut pthread_mutexattr_t, - pshared: ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_getpshared( - attr: *const pthread_rwlockattr_t, - val: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_setpshared( - attr: *mut pthread_rwlockattr_t, - val: ::c_int, - ) -> ::c_int; - pub fn ptsname_r( - fd: ::c_int, - buf: *mut ::c_char, - buflen: ::size_t, - ) -> ::c_int; - pub fn clearenv() -> ::c_int; - pub fn waitid( - idtype: idtype_t, - id: id_t, - infop: *mut ::siginfo_t, - options: ::c_int, - ) -> ::c_int; - pub fn setreuid(ruid: ::uid_t, euid: ::uid_t) -> ::c_int; - pub fn setregid(rgid: ::gid_t, egid: ::gid_t) -> ::c_int; - pub fn getresuid( - ruid: *mut ::uid_t, - euid: *mut ::uid_t, - suid: *mut ::uid_t, - ) -> ::c_int; - pub fn getresgid( - rgid: *mut ::gid_t, - egid: *mut ::gid_t, - sgid: *mut ::gid_t, - ) -> ::c_int; - pub fn acct(filename: *const ::c_char) -> ::c_int; - pub fn brk(addr: *mut ::c_void) -> ::c_int; - pub fn sbrk(increment: ::intptr_t) -> *mut ::c_void; - #[deprecated( - since = "0.2.66", - note = "causes memory corruption, see rust-lang/libc#1596" - )] - pub fn vfork() -> ::pid_t; - pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int; - pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int; - pub fn wait4( - pid: ::pid_t, - status: *mut ::c_int, - options: ::c_int, - rusage: *mut ::rusage, - ) -> ::pid_t; - pub fn openpty( - amaster: *mut ::c_int, - aslave: *mut ::c_int, - name: *mut ::c_char, - termp: *const termios, - winp: *const ::winsize, - ) -> ::c_int; - pub fn forkpty( - amaster: *mut ::c_int, - name: *mut ::c_char, - termp: *const termios, - winp: *const ::winsize, - ) -> ::pid_t; - pub fn login_tty(fd: ::c_int) -> ::c_int; - pub fn execvpe( - file: *const ::c_char, - argv: *const *const ::c_char, - envp: *const *const ::c_char, - ) -> ::c_int; - pub fn fexecve( - fd: ::c_int, - argv: *const *const ::c_char, - envp: *const *const ::c_char, - ) -> ::c_int; - pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; - pub fn freeifaddrs(ifa: *mut ::ifaddrs); - pub fn bind( - socket: ::c_int, - address: *const ::sockaddr, - address_len: ::socklen_t, - ) -> ::c_int; - - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - - pub fn sendmsg( - fd: ::c_int, - msg: *const ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - pub fn recvmsg( - fd: ::c_int, - msg: *mut ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - pub fn uname(buf: *mut ::utsname) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_os = "emscripten")] { - mod emscripten; - pub use self::emscripten::*; - } else if #[cfg(target_os = "linux")] { - mod linux; - pub use self::linux::*; - } else if #[cfg(target_os = "android")] { - mod android; - pub use self::android::*; - } else { - // Unknown target_os - } -} diff --git a/libc/src/unix/mod.rs b/libc/src/unix/mod.rs deleted file mode 100644 index 238da24..0000000 --- a/libc/src/unix/mod.rs +++ /dev/null @@ -1,1552 +0,0 @@ -//! Definitions found commonly among almost all Unix derivatives -//! -//! More functions and definitions can be found in the more specific modules -//! according to the platform in question. - -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type size_t = usize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type ssize_t = isize; - -pub type pid_t = i32; -pub type uid_t = u32; -pub type gid_t = u32; -pub type in_addr_t = u32; -pub type in_port_t = u16; -pub type sighandler_t = ::size_t; -pub type cc_t = ::c_uchar; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum DIR {} -impl ::Copy for DIR {} -impl ::Clone for DIR { - fn clone(&self) -> DIR { - *self - } -} -pub type locale_t = *mut ::c_void; - -s! { - pub struct group { - pub gr_name: *mut ::c_char, - pub gr_passwd: *mut ::c_char, - pub gr_gid: ::gid_t, - pub gr_mem: *mut *mut ::c_char, - } - - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - // linux x32 compatibility - // See https://sourceware.org/bugzilla/show_bug.cgi?id=16437 - pub struct timespec { - pub tv_sec: time_t, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - pub tv_nsec: i64, - #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))] - pub tv_nsec: ::c_long, - } - - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad1: u32, - pub ru_ixrss: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad2: u32, - pub ru_idrss: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad3: u32, - pub ru_isrss: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad4: u32, - pub ru_minflt: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad5: u32, - pub ru_majflt: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad6: u32, - pub ru_nswap: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad7: u32, - pub ru_inblock: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad8: u32, - pub ru_oublock: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad9: u32, - pub ru_msgsnd: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad10: u32, - pub ru_msgrcv: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad11: u32, - pub ru_nsignals: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad12: u32, - pub ru_nvcsw: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad13: u32, - pub ru_nivcsw: c_long, - #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] - __pad14: u32, - - #[cfg(any(target_env = "musl", target_os = "emscripten"))] - __reserved: [c_long; 16], - } - - pub struct ipv6_mreq { - pub ipv6mr_multiaddr: in6_addr, - #[cfg(target_os = "android")] - pub ipv6mr_interface: ::c_int, - #[cfg(not(target_os = "android"))] - pub ipv6mr_interface: ::c_uint, - } - - pub struct hostent { - pub h_name: *mut ::c_char, - pub h_aliases: *mut *mut ::c_char, - pub h_addrtype: ::c_int, - pub h_length: ::c_int, - pub h_addr_list: *mut *mut ::c_char, - } - - pub struct iovec { - pub iov_base: *mut ::c_void, - pub iov_len: ::size_t, - } - - pub struct pollfd { - pub fd: ::c_int, - pub events: ::c_short, - pub revents: ::c_short, - } - - pub struct winsize { - pub ws_row: ::c_ushort, - pub ws_col: ::c_ushort, - pub ws_xpixel: ::c_ushort, - pub ws_ypixel: ::c_ushort, - } - - pub struct linger { - pub l_onoff: ::c_int, - pub l_linger: ::c_int, - } - - pub struct sigval { - // Actually a union of an int and a void* - pub sival_ptr: *mut ::c_void - } - - // - pub struct itimerval { - pub it_interval: ::timeval, - pub it_value: ::timeval, - } - - // - pub struct tms { - pub tms_utime: ::clock_t, - pub tms_stime: ::clock_t, - pub tms_cutime: ::clock_t, - pub tms_cstime: ::clock_t, - } - - pub struct servent { - pub s_name: *mut ::c_char, - pub s_aliases: *mut *mut ::c_char, - pub s_port: ::c_int, - pub s_proto: *mut ::c_char, - } - - pub struct protoent { - pub p_name: *mut ::c_char, - pub p_aliases: *mut *mut ::c_char, - pub p_proto: ::c_int, - } -} - -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; - -pub const SIG_DFL: sighandler_t = 0 as sighandler_t; -pub const SIG_IGN: sighandler_t = 1 as sighandler_t; -pub const SIG_ERR: sighandler_t = !0 as sighandler_t; - -pub const DT_UNKNOWN: u8 = 0; -pub const DT_FIFO: u8 = 1; -pub const DT_CHR: u8 = 2; -pub const DT_DIR: u8 = 4; -pub const DT_BLK: u8 = 6; -pub const DT_REG: u8 = 8; -pub const DT_LNK: u8 = 10; -pub const DT_SOCK: u8 = 12; - -cfg_if! { - if #[cfg(not(target_os = "redox"))] { - pub const FD_CLOEXEC: ::c_int = 0x1; - } -} - -pub const USRQUOTA: ::c_int = 0; -pub const GRPQUOTA: ::c_int = 1; - -pub const SIGIOT: ::c_int = 6; - -pub const S_ISUID: ::mode_t = 0x800; -pub const S_ISGID: ::mode_t = 0x400; -pub const S_ISVTX: ::mode_t = 0x200; - -pub const IF_NAMESIZE: ::size_t = 16; -pub const IFNAMSIZ: ::size_t = IF_NAMESIZE; - -pub const LOG_EMERG: ::c_int = 0; -pub const LOG_ALERT: ::c_int = 1; -pub const LOG_CRIT: ::c_int = 2; -pub const LOG_ERR: ::c_int = 3; -pub const LOG_WARNING: ::c_int = 4; -pub const LOG_NOTICE: ::c_int = 5; -pub const LOG_INFO: ::c_int = 6; -pub const LOG_DEBUG: ::c_int = 7; - -pub const LOG_KERN: ::c_int = 0; -pub const LOG_USER: ::c_int = 1 << 3; -pub const LOG_MAIL: ::c_int = 2 << 3; -pub const LOG_DAEMON: ::c_int = 3 << 3; -pub const LOG_AUTH: ::c_int = 4 << 3; -pub const LOG_SYSLOG: ::c_int = 5 << 3; -pub const LOG_LPR: ::c_int = 6 << 3; -pub const LOG_NEWS: ::c_int = 7 << 3; -pub const LOG_UUCP: ::c_int = 8 << 3; -pub const LOG_LOCAL0: ::c_int = 16 << 3; -pub const LOG_LOCAL1: ::c_int = 17 << 3; -pub const LOG_LOCAL2: ::c_int = 18 << 3; -pub const LOG_LOCAL3: ::c_int = 19 << 3; -pub const LOG_LOCAL4: ::c_int = 20 << 3; -pub const LOG_LOCAL5: ::c_int = 21 << 3; -pub const LOG_LOCAL6: ::c_int = 22 << 3; -pub const LOG_LOCAL7: ::c_int = 23 << 3; - -pub const LOG_PID: ::c_int = 0x01; -pub const LOG_CONS: ::c_int = 0x02; -pub const LOG_ODELAY: ::c_int = 0x04; -pub const LOG_NDELAY: ::c_int = 0x08; -pub const LOG_NOWAIT: ::c_int = 0x10; - -pub const LOG_PRIMASK: ::c_int = 7; -pub const LOG_FACMASK: ::c_int = 0x3f8; - -pub const PRIO_PROCESS: ::c_int = 0; -pub const PRIO_PGRP: ::c_int = 1; -pub const PRIO_USER: ::c_int = 2; - -pub const PRIO_MIN: ::c_int = -20; -pub const PRIO_MAX: ::c_int = 20; - -pub const IPPROTO_ICMP: ::c_int = 1; -pub const IPPROTO_ICMPV6: ::c_int = 58; -pub const IPPROTO_TCP: ::c_int = 6; -pub const IPPROTO_UDP: ::c_int = 17; -pub const IPPROTO_IP: ::c_int = 0; -pub const IPPROTO_IPV6: ::c_int = 41; - -pub const INADDR_LOOPBACK: in_addr_t = 2130706433; -pub const INADDR_ANY: in_addr_t = 0; -pub const INADDR_BROADCAST: in_addr_t = 4294967295; -pub const INADDR_NONE: in_addr_t = 4294967295; - -pub const ARPOP_REQUEST: u16 = 1; -pub const ARPOP_REPLY: u16 = 2; - -pub const ATF_COM: ::c_int = 0x02; -pub const ATF_PERM: ::c_int = 0x04; -pub const ATF_PUBL: ::c_int = 0x08; -pub const ATF_USETRAILERS: ::c_int = 0x10; - -cfg_if! { - if #[cfg(target_os = "l4re")] { - // required libraries for L4Re are linked externally, ATM - } else if #[cfg(feature = "std")] { - // cargo build, don't pull in anything extra as the libstd dep - // already pulls in all libs. - } else if #[cfg(target_env = "musl")] { - #[cfg_attr(feature = "rustc-dep-of-std", - link(name = "c", kind = "static", - cfg(target_feature = "crt-static")))] - #[cfg_attr(feature = "rustc-dep-of-std", - link(name = "c", cfg(not(target_feature = "crt-static"))))] - extern {} - } else if #[cfg(target_os = "emscripten")] { - #[link(name = "c")] - extern {} - } else if #[cfg(all(target_os = "netbsd", - feature = "rustc-dep-of-std", - target_vendor = "rumprun"))] { - // Since we don't use -nodefaultlibs on Rumprun, libc is always pulled - // in automatically by the linker. We avoid passing it explicitly, as it - // causes some versions of binutils to crash with an assertion failure. - #[link(name = "m")] - extern {} - } else if #[cfg(any(target_os = "macos", - target_os = "ios", - target_os = "android", - target_os = "openbsd"))] { - #[link(name = "c")] - #[link(name = "m")] - extern {} - } else if #[cfg(target_os = "haiku")] { - #[link(name = "root")] - #[link(name = "network")] - extern {} - } else if #[cfg(target_env = "newlib")] { - #[link(name = "c")] - #[link(name = "m")] - extern {} - } else if #[cfg(target_os = "hermit")] { - // no_default_libraries is set to false for HermitCore, so only a link - // to "pthread" needs to be added. - #[link(name = "pthread")] - extern {} - } else if #[cfg(target_env = "illumos")] { - #[link(name = "c")] - #[link(name = "m")] - extern {} - } else if #[cfg(target_os = "redox")] { - #[cfg_attr(feature = "rustc-dep-of-std", - link(name = "c", kind = "static-nobundle", - cfg(target_feature = "crt-static")))] - #[cfg_attr(feature = "rustc-dep-of-std", - link(name = "c", cfg(not(target_feature = "crt-static"))))] - extern {} - } else { - #[link(name = "c")] - #[link(name = "m")] - #[link(name = "rt")] - #[link(name = "pthread")] - extern {} - } -} - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum FILE {} -impl ::Copy for FILE {} -impl ::Clone for FILE { - fn clone(&self) -> FILE { - *self - } -} -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos_t {} // TODO: fill this out with a struct -impl ::Copy for fpos_t {} -impl ::Clone for fpos_t { - fn clone(&self) -> fpos_t { - *self - } -} - -extern "C" { - pub fn isalnum(c: c_int) -> c_int; - pub fn isalpha(c: c_int) -> c_int; - pub fn iscntrl(c: c_int) -> c_int; - pub fn isdigit(c: c_int) -> c_int; - pub fn isgraph(c: c_int) -> c_int; - pub fn islower(c: c_int) -> c_int; - pub fn isprint(c: c_int) -> c_int; - pub fn ispunct(c: c_int) -> c_int; - pub fn isspace(c: c_int) -> c_int; - pub fn isupper(c: c_int) -> c_int; - pub fn isxdigit(c: c_int) -> c_int; - pub fn isblank(c: c_int) -> c_int; - pub fn tolower(c: c_int) -> c_int; - pub fn toupper(c: c_int) -> c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fopen$UNIX2003" - )] - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "freopen$UNIX2003" - )] - pub fn freopen( - filename: *const c_char, - mode: *const c_char, - file: *mut FILE, - ) -> *mut FILE; - pub fn fflush(file: *mut FILE) -> c_int; - pub fn fclose(file: *mut FILE) -> c_int; - pub fn remove(filename: *const c_char) -> c_int; - pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; - pub fn tmpfile() -> *mut FILE; - pub fn setvbuf( - stream: *mut FILE, - buffer: *mut c_char, - mode: c_int, - size: size_t, - ) -> c_int; - pub fn setbuf(stream: *mut FILE, buf: *mut c_char); - pub fn getchar() -> c_int; - pub fn putchar(c: c_int) -> c_int; - pub fn fgetc(stream: *mut FILE) -> c_int; - pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) - -> *mut c_char; - pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fputs$UNIX2003" - )] - pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; - pub fn puts(s: *const c_char) -> c_int; - pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fread( - ptr: *mut c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fwrite$UNIX2003" - )] - pub fn fwrite( - ptr: *const c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; - pub fn ftell(stream: *mut FILE) -> c_long; - pub fn rewind(stream: *mut FILE); - #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")] - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")] - pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; - pub fn feof(stream: *mut FILE) -> c_int; - pub fn ferror(stream: *mut FILE) -> c_int; - pub fn perror(s: *const c_char); - pub fn atoi(s: *const c_char) -> c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "strtod$UNIX2003" - )] - pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; - pub fn strtol( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_long; - pub fn strtoul( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_ulong; - pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; - pub fn malloc(size: size_t) -> *mut c_void; - pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; - pub fn free(p: *mut c_void); - pub fn abort() -> !; - pub fn exit(status: c_int) -> !; - pub fn _exit(status: c_int) -> !; - pub fn atexit(cb: extern "C" fn()) -> c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "system$UNIX2003" - )] - pub fn system(s: *const c_char) -> c_int; - pub fn getenv(s: *const c_char) -> *mut c_char; - - pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; - pub fn strncpy( - dst: *mut c_char, - src: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; - pub fn strncat( - s: *mut c_char, - ct: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; - pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strdup(cs: *const c_char) -> *mut c_char; - pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; - pub fn strncasecmp( - s1: *const c_char, - s2: *const c_char, - n: size_t, - ) -> c_int; - pub fn strlen(cs: *const c_char) -> size_t; - pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "strerror$UNIX2003" - )] - pub fn strerror(n: c_int) -> *mut c_char; - pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; - pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; - pub fn wcslen(buf: *const wchar_t) -> size_t; - pub fn wcstombs( - dest: *mut c_char, - src: *const wchar_t, - n: size_t, - ) -> ::size_t; - - pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memcpy( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memmove( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; -} - -extern "C" { - #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam50")] - pub fn getpwnam(name: *const ::c_char) -> *mut passwd; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid50")] - pub fn getpwuid(uid: ::uid_t) -> *mut passwd; - - pub fn fprintf( - stream: *mut ::FILE, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn printf(format: *const ::c_char, ...) -> ::c_int; - pub fn snprintf( - s: *mut ::c_char, - n: ::size_t, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int; - #[cfg_attr(target_os = "linux", link_name = "__isoc99_fscanf")] - pub fn fscanf( - stream: *mut ::FILE, - format: *const ::c_char, - ... - ) -> ::c_int; - #[cfg_attr(target_os = "linux", link_name = "__isoc99_scanf")] - pub fn scanf(format: *const ::c_char, ...) -> ::c_int; - #[cfg_attr(target_os = "linux", link_name = "__isoc99_sscanf")] - pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) - -> ::c_int; - pub fn getchar_unlocked() -> ::c_int; - pub fn putchar_unlocked(c: ::c_int) -> ::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__socket30")] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")] - pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "connect$UNIX2003" - )] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_connect")] - pub fn connect( - socket: ::c_int, - address: *const sockaddr, - len: socklen_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "listen$UNIX2003" - )] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_listen")] - pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "accept$UNIX2003" - )] - pub fn accept( - socket: ::c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "getpeername$UNIX2003" - )] - pub fn getpeername( - socket: ::c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "getsockname$UNIX2003" - )] - pub fn getsockname( - socket: ::c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ::c_int; - pub fn setsockopt( - socket: ::c_int, - level: ::c_int, - name: ::c_int, - value: *const ::c_void, - option_len: socklen_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "socketpair$UNIX2003" - )] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")] - pub fn socketpair( - domain: ::c_int, - type_: ::c_int, - protocol: ::c_int, - socket_vector: *mut ::c_int, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sendto$UNIX2003" - )] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_sendto")] - pub fn sendto( - socket: ::c_int, - buf: *const ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *const sockaddr, - addrlen: socklen_t, - ) -> ::ssize_t; - pub fn shutdown(socket: ::c_int, how: ::c_int) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "chmod$UNIX2003" - )] - pub fn chmod(path: *const c_char, mode: mode_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fchmod$UNIX2003" - )] - pub fn fchmod(fd: ::c_int, mode: mode_t) -> ::c_int; - - #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")] - #[cfg_attr(target_os = "netbsd", link_name = "__fstat50")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "fstat@FBSD_1.0" - )] - pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; - - pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int; - - #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")] - #[cfg_attr(target_os = "netbsd", link_name = "__stat50")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "stat@FBSD_1.0" - )] - pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; - - pub fn pclose(stream: *mut ::FILE) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fdopen$UNIX2003" - )] - pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; - pub fn fileno(stream: *mut ::FILE) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "open$UNIX2003" - )] - pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "creat$UNIX2003" - )] - pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fcntl$UNIX2003" - )] - pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86_64"), - link_name = "opendir$INODE64" - )] - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "opendir$INODE64$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__opendir30")] - pub fn opendir(dirname: *const c_char) -> *mut ::DIR; - - #[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")] - #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "readdir@FBSD_1.0" - )] - pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "closedir$UNIX2003" - )] - pub fn closedir(dirp: *mut ::DIR) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86_64"), - link_name = "rewinddir$INODE64" - )] - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "rewinddir$INODE64$UNIX2003" - )] - pub fn rewinddir(dirp: *mut ::DIR); - - pub fn fchmodat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - flags: ::c_int, - ) -> ::c_int; - pub fn fchown(fd: ::c_int, owner: ::uid_t, group: ::gid_t) -> ::c_int; - pub fn fchownat( - dirfd: ::c_int, - pathname: *const ::c_char, - owner: ::uid_t, - group: ::gid_t, - flags: ::c_int, - ) -> ::c_int; - #[cfg_attr(target_os = "macos", link_name = "fstatat$INODE64")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "fstatat@FBSD_1.1" - )] - pub fn fstatat( - dirfd: ::c_int, - pathname: *const ::c_char, - buf: *mut stat, - flags: ::c_int, - ) -> ::c_int; - pub fn linkat( - olddirfd: ::c_int, - oldpath: *const ::c_char, - newdirfd: ::c_int, - newpath: *const ::c_char, - flags: ::c_int, - ) -> ::c_int; - pub fn renameat( - olddirfd: ::c_int, - oldpath: *const ::c_char, - newdirfd: ::c_int, - newpath: *const ::c_char, - ) -> ::c_int; - pub fn symlinkat( - target: *const ::c_char, - newdirfd: ::c_int, - linkpath: *const ::c_char, - ) -> ::c_int; - pub fn unlinkat( - dirfd: ::c_int, - pathname: *const ::c_char, - flags: ::c_int, - ) -> ::c_int; - - pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; - pub fn alarm(seconds: ::c_uint) -> ::c_uint; - pub fn chdir(dir: *const c_char) -> ::c_int; - pub fn fchdir(dirfd: ::c_int) -> ::c_int; - pub fn chown(path: *const c_char, uid: uid_t, gid: gid_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "lchown$UNIX2003" - )] - pub fn lchown(path: *const c_char, uid: uid_t, gid: gid_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "close$NOCANCEL$UNIX2003" - )] - #[cfg_attr( - all(target_os = "macos", target_arch = "x86_64"), - link_name = "close$NOCANCEL" - )] - pub fn close(fd: ::c_int) -> ::c_int; - pub fn dup(fd: ::c_int) -> ::c_int; - pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; - pub fn execl(path: *const c_char, arg0: *const c_char, ...) -> ::c_int; - pub fn execle( - path: *const ::c_char, - arg0: *const ::c_char, - ... - ) -> ::c_int; - pub fn execlp( - file: *const ::c_char, - arg0: *const ::c_char, - ... - ) -> ::c_int; - pub fn execv(prog: *const c_char, argv: *const *const c_char) -> ::c_int; - pub fn execve( - prog: *const c_char, - argv: *const *const c_char, - envp: *const *const c_char, - ) -> ::c_int; - pub fn execvp(c: *const c_char, argv: *const *const c_char) -> ::c_int; - pub fn fork() -> pid_t; - pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> c_long; - pub fn getcwd(buf: *mut c_char, size: ::size_t) -> *mut c_char; - pub fn getegid() -> gid_t; - pub fn geteuid() -> uid_t; - pub fn getgid() -> gid_t; - pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t) -> ::c_int; - pub fn getlogin() -> *mut c_char; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "getopt$UNIX2003" - )] - pub fn getopt( - argc: ::c_int, - argv: *const *mut c_char, - optstr: *const c_char, - ) -> ::c_int; - pub fn getpgid(pid: pid_t) -> pid_t; - pub fn getpgrp() -> pid_t; - pub fn getpid() -> pid_t; - pub fn getppid() -> pid_t; - pub fn getuid() -> uid_t; - pub fn isatty(fd: ::c_int) -> ::c_int; - pub fn link(src: *const c_char, dst: *const c_char) -> ::c_int; - pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t; - pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long; - pub fn pipe(fds: *mut ::c_int) -> ::c_int; - pub fn posix_memalign( - memptr: *mut *mut ::c_void, - align: ::size_t, - size: ::size_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "read$UNIX2003" - )] - pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) - -> ::ssize_t; - pub fn rmdir(path: *const c_char) -> ::c_int; - pub fn seteuid(uid: uid_t) -> ::c_int; - pub fn setegid(gid: gid_t) -> ::c_int; - pub fn setgid(gid: gid_t) -> ::c_int; - pub fn setpgid(pid: pid_t, pgid: pid_t) -> ::c_int; - pub fn setsid() -> pid_t; - pub fn setuid(uid: uid_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sleep$UNIX2003" - )] - pub fn sleep(secs: ::c_uint) -> ::c_uint; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "nanosleep$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__nanosleep50")] - pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> ::c_int; - pub fn tcgetpgrp(fd: ::c_int) -> pid_t; - pub fn tcsetpgrp(fd: ::c_int, pgrp: ::pid_t) -> ::c_int; - pub fn ttyname(fd: ::c_int) -> *mut c_char; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "ttyname_r$UNIX2003" - )] - pub fn ttyname_r( - fd: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - pub fn unlink(c: *const c_char) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "wait$UNIX2003" - )] - pub fn wait(status: *mut ::c_int) -> pid_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "waitpid$UNIX2003" - )] - pub fn waitpid( - pid: pid_t, - status: *mut ::c_int, - options: ::c_int, - ) -> pid_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "write$UNIX2003" - )] - pub fn write( - fd: ::c_int, - buf: *const ::c_void, - count: ::size_t, - ) -> ::ssize_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pread$UNIX2003" - )] - pub fn pread( - fd: ::c_int, - buf: *mut ::c_void, - count: ::size_t, - offset: off_t, - ) -> ::ssize_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pwrite$UNIX2003" - )] - pub fn pwrite( - fd: ::c_int, - buf: *const ::c_void, - count: ::size_t, - offset: off_t, - ) -> ::ssize_t; - pub fn umask(mask: mode_t) -> mode_t; - - #[cfg_attr(target_os = "netbsd", link_name = "__utime50")] - pub fn utime(file: *const c_char, buf: *const utimbuf) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "kill$UNIX2003" - )] - pub fn kill(pid: pid_t, sig: ::c_int) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "killpg$UNIX2003" - )] - pub fn killpg(pgrp: pid_t, sig: ::c_int) -> ::c_int; - - pub fn mlock(addr: *const ::c_void, len: ::size_t) -> ::c_int; - pub fn munlock(addr: *const ::c_void, len: ::size_t) -> ::c_int; - pub fn mlockall(flags: ::c_int) -> ::c_int; - pub fn munlockall() -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "mmap$UNIX2003" - )] - pub fn mmap( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - flags: ::c_int, - fd: ::c_int, - offset: off_t, - ) -> *mut ::c_void; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "munmap$UNIX2003" - )] - pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int; - - pub fn if_nametoindex(ifname: *const c_char) -> ::c_uint; - pub fn if_indextoname( - ifindex: ::c_uint, - ifname: *mut ::c_char, - ) -> *mut ::c_char; - - #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")] - #[cfg_attr(target_os = "netbsd", link_name = "__lstat50")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "lstat@FBSD_1.0" - )] - pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fsync$UNIX2003" - )] - pub fn fsync(fd: ::c_int) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "setenv$UNIX2003" - )] - pub fn setenv( - name: *const c_char, - val: *const c_char, - overwrite: ::c_int, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "unsetenv$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__unsetenv13")] - pub fn unsetenv(name: *const c_char) -> ::c_int; - - pub fn symlink(path1: *const c_char, path2: *const c_char) -> ::c_int; - - pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int; - - pub fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t; - - #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")] - pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int; - - #[cfg_attr( - any(target_os = "macos", target_os = "ios"), - link_name = "realpath$DARWIN_EXTSN" - )] - pub fn realpath( - pathname: *const ::c_char, - resolved: *mut ::c_char, - ) -> *mut ::c_char; - - pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__times13")] - pub fn times(buf: *mut ::tms) -> ::clock_t; - - pub fn pthread_self() -> ::pthread_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_join$UNIX2003" - )] - pub fn pthread_join( - native: ::pthread_t, - value: *mut *mut ::c_void, - ) -> ::c_int; - pub fn pthread_exit(value: *mut ::c_void) -> !; - pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int; - pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int; - pub fn pthread_attr_setstacksize( - attr: *mut ::pthread_attr_t, - stack_size: ::size_t, - ) -> ::c_int; - pub fn pthread_attr_setdetachstate( - attr: *mut ::pthread_attr_t, - state: ::c_int, - ) -> ::c_int; - pub fn pthread_detach(thread: ::pthread_t) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__libc_thr_yield")] - pub fn sched_yield() -> ::c_int; - pub fn pthread_key_create( - key: *mut pthread_key_t, - dtor: ::Option, - ) -> ::c_int; - pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int; - pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void; - pub fn pthread_setspecific( - key: pthread_key_t, - value: *const ::c_void, - ) -> ::c_int; - pub fn pthread_mutex_init( - lock: *mut pthread_mutex_t, - attr: *const pthread_mutexattr_t, - ) -> ::c_int; - pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> ::c_int; - pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> ::c_int; - pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> ::c_int; - pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> ::c_int; - - pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_mutexattr_destroy$UNIX2003" - )] - pub fn pthread_mutexattr_destroy( - attr: *mut pthread_mutexattr_t, - ) -> ::c_int; - pub fn pthread_mutexattr_settype( - attr: *mut pthread_mutexattr_t, - _type: ::c_int, - ) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_cond_init$UNIX2003" - )] - pub fn pthread_cond_init( - cond: *mut pthread_cond_t, - attr: *const pthread_condattr_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_cond_wait$UNIX2003" - )] - pub fn pthread_cond_wait( - cond: *mut pthread_cond_t, - lock: *mut pthread_mutex_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_cond_timedwait$UNIX2003" - )] - pub fn pthread_cond_timedwait( - cond: *mut pthread_cond_t, - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int; - pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int; - pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int; - pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> ::c_int; - pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_rwlock_init$UNIX2003" - )] - pub fn pthread_rwlock_init( - lock: *mut pthread_rwlock_t, - attr: *const pthread_rwlockattr_t, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_rwlock_destroy$UNIX2003" - )] - pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_rwlock_rdlock$UNIX2003" - )] - pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_rwlock_tryrdlock$UNIX2003" - )] - pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_rwlock_wrlock$UNIX2003" - )] - pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_rwlock_trywrlock$UNIX2003" - )] - pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_rwlock_unlock$UNIX2003" - )] - pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int; - pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) - -> ::c_int; - pub fn pthread_rwlockattr_destroy( - attr: *mut pthread_rwlockattr_t, - ) -> ::c_int; - - #[cfg_attr(target_os = "illumos", link_name = "__xnet_getsockopt")] - pub fn getsockopt( - sockfd: ::c_int, - level: ::c_int, - optname: ::c_int, - optval: *mut ::c_void, - optlen: *mut ::socklen_t, - ) -> ::c_int; - pub fn raise(signum: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__sigaction14")] - pub fn sigaction( - signum: ::c_int, - act: *const sigaction, - oldact: *mut sigaction, - ) -> ::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")] - pub fn utimes( - filename: *const ::c_char, - times: *const ::timeval, - ) -> ::c_int; - pub fn dlopen(filename: *const ::c_char, flag: ::c_int) -> *mut ::c_void; - pub fn dlerror() -> *mut ::c_char; - pub fn dlsym( - handle: *mut ::c_void, - symbol: *const ::c_char, - ) -> *mut ::c_void; - pub fn dlclose(handle: *mut ::c_void) -> ::c_int; - pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int; - - pub fn getaddrinfo( - node: *const c_char, - service: *const c_char, - hints: *const addrinfo, - res: *mut *mut addrinfo, - ) -> ::c_int; - pub fn freeaddrinfo(res: *mut addrinfo); - pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char; - #[cfg_attr( - any( - all(target_os = "linux", not(target_env = "musl")), - target_os = "freebsd", - target_os = "dragonfly", - target_os = "haiku" - ), - link_name = "__res_init" - )] - #[cfg_attr( - any(target_os = "macos", target_os = "ios"), - link_name = "res_9_init" - )] - pub fn res_init() -> ::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")] - pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; - #[cfg_attr(target_os = "netbsd", link_name = "__localtime_r50")] - pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "mktime$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__mktime50")] - pub fn mktime(tm: *mut tm) -> time_t; - #[cfg_attr(target_os = "netbsd", link_name = "__time50")] - pub fn time(time: *mut time_t) -> time_t; - #[cfg_attr(target_os = "netbsd", link_name = "__gmtime50")] - pub fn gmtime(time_p: *const time_t) -> *mut tm; - #[cfg_attr(target_os = "netbsd", link_name = "__locatime50")] - pub fn localtime(time_p: *const time_t) -> *mut tm; - #[cfg_attr(target_os = "netbsd", link_name = "__difftime50")] - pub fn difftime(time1: time_t, time0: time_t) -> ::c_double; - - #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "mknod@FBSD_1.0" - )] - pub fn mknod( - pathname: *const ::c_char, - mode: ::mode_t, - dev: ::dev_t, - ) -> ::c_int; - pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int; - pub fn getservbyname( - name: *const ::c_char, - proto: *const ::c_char, - ) -> *mut servent; - pub fn getprotobyname(name: *const ::c_char) -> *mut protoent; - pub fn getprotobynumber(proto: ::c_int) -> *mut protoent; - pub fn chroot(name: *const ::c_char) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "usleep$UNIX2003" - )] - pub fn usleep(secs: ::c_uint) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "send$UNIX2003" - )] - pub fn send( - socket: ::c_int, - buf: *const ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "recv$UNIX2003" - )] - pub fn recv( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "putenv$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__putenv50")] - pub fn putenv(string: *mut c_char) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "poll$UNIX2003" - )] - pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86_64"), - link_name = "select$1050" - )] - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "select$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__select50")] - pub fn select( - nfds: ::c_int, - readfs: *mut fd_set, - writefds: *mut fd_set, - errorfds: *mut fd_set, - timeout: *mut timeval, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__setlocale50")] - pub fn setlocale( - category: ::c_int, - locale: *const ::c_char, - ) -> *mut ::c_char; - pub fn localeconv() -> *mut lconv; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sem_wait$UNIX2003" - )] - pub fn sem_wait(sem: *mut sem_t) -> ::c_int; - pub fn sem_trywait(sem: *mut sem_t) -> ::c_int; - pub fn sem_post(sem: *mut sem_t) -> ::c_int; - pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int; - pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int; - - pub fn readlink( - path: *const c_char, - buf: *mut c_char, - bufsz: ::size_t, - ) -> ::ssize_t; - - #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")] - pub fn sigemptyset(set: *mut sigset_t) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")] - pub fn sigaddset(set: *mut sigset_t, signum: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__sigfillset14")] - pub fn sigfillset(set: *mut sigset_t) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__sigdelset14")] - pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__sigismember14")] - pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__sigprocmask14")] - pub fn sigprocmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__sigpending14")] - pub fn sigpending(set: *mut sigset_t) -> ::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")] - pub fn timegm(tm: *mut ::tm) -> time_t; - - pub fn sysconf(name: ::c_int) -> ::c_long; - - pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86_64"), - link_name = "pselect$1050" - )] - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pselect$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__pselect50")] - pub fn pselect( - nfds: ::c_int, - readfs: *mut fd_set, - writefds: *mut fd_set, - errorfds: *mut fd_set, - timeout: *const timespec, - sigmask: *const sigset_t, - ) -> ::c_int; - pub fn fseeko( - stream: *mut ::FILE, - offset: ::off_t, - whence: ::c_int, - ) -> ::c_int; - pub fn ftello(stream: *mut ::FILE) -> ::off_t; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "tcdrain$UNIX2003" - )] - pub fn tcdrain(fd: ::c_int) -> ::c_int; - pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t; - pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t; - pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; - pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int; - pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int; - pub fn tcsetattr( - fd: ::c_int, - optional_actions: ::c_int, - termios: *const ::termios, - ) -> ::c_int; - pub fn tcflow(fd: ::c_int, action: ::c_int) -> ::c_int; - pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int; - pub fn tcgetsid(fd: ::c_int) -> ::pid_t; - pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int; - pub fn mkstemp(template: *mut ::c_char) -> ::c_int; - pub fn mkdtemp(template: *mut ::c_char) -> *mut ::c_char; - - pub fn tmpnam(ptr: *mut ::c_char) -> *mut ::c_char; - - pub fn openlog(ident: *const ::c_char, logopt: ::c_int, facility: ::c_int); - pub fn closelog(); - pub fn setlogmask(maskpri: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "macos", link_name = "syslog$DARWIN_EXTSN")] - pub fn syslog(priority: ::c_int, message: *const ::c_char, ...); - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "nice$UNIX2003" - )] - pub fn nice(incr: ::c_int) -> ::c_int; - - pub fn grantpt(fd: ::c_int) -> ::c_int; - pub fn posix_openpt(flags: ::c_int) -> ::c_int; - pub fn ptsname(fd: ::c_int) -> *mut ::c_char; - pub fn unlockpt(fd: ::c_int) -> ::c_int; - - pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn getline( - lineptr: *mut *mut c_char, - n: *mut size_t, - stream: *mut FILE, - ) -> ssize_t; -} - -cfg_if! { - if #[cfg(not(target_os = "redox"))] { - extern { - pub fn getsid(pid: pid_t) -> pid_t; - pub fn truncate(path: *const c_char, length: off_t) -> ::c_int; - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "pause$UNIX2003")] - pub fn pause() -> ::c_int; - - pub fn readlinkat(dirfd: ::c_int, - pathname: *const ::c_char, - buf: *mut ::c_char, - bufsiz: ::size_t) -> ::ssize_t; - pub fn mkdirat(dirfd: ::c_int, pathname: *const ::c_char, - mode: ::mode_t) -> ::c_int; - pub fn openat(dirfd: ::c_int, pathname: *const ::c_char, - flags: ::c_int, ...) -> ::c_int; - - #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"), - link_name = "fdopendir$INODE64")] - #[cfg_attr(all(target_os = "macos", target_arch = "x86"), - link_name = "fdopendir$INODE64$UNIX2003")] - pub fn fdopendir(fd: ::c_int) -> *mut ::DIR; - - #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] - #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")] - #[cfg_attr( - all(target_os = "freebsd", any(freebsd11, freebsd10)), - link_name = "readdir_r@FBSD_1.0" - )] - /// The 64-bit libc on Solaris and illumos only has readdir_r. If a - /// 32-bit Solaris or illumos target is ever created, it should use - /// __posix_readdir_r. See libc(3LIB) on Solaris or illumos: - /// https://illumos.org/man/3lib/libc - /// https://docs.oracle.com/cd/E36784_01/html/E36873/libc-3lib.html - /// https://www.unix.com/man-page/opensolaris/3LIB/libc/ - pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent, - result: *mut *mut ::dirent) -> ::c_int; - } - } -} - -cfg_if! { - if #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] { - extern { - pub fn cfmakeraw(termios: *mut ::termios); - pub fn cfsetspeed(termios: *mut ::termios, - speed: ::speed_t) -> ::c_int; - } - } -} - -cfg_if! { - if #[cfg(target_env = "uclibc")] { - mod uclibc; - pub use self::uclibc::*; - } else if #[cfg(target_env = "newlib")] { - mod newlib; - pub use self::newlib::*; - } else if #[cfg(any(target_os = "linux", - target_os = "android", - target_os = "emscripten"))] { - mod linux_like; - pub use self::linux_like::*; - } else if #[cfg(any(target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "openbsd", - target_os = "netbsd"))] { - mod bsd; - pub use self::bsd::*; - } else if #[cfg(any(target_os = "solaris", - target_os = "illumos"))] { - mod solarish; - pub use self::solarish::*; - } else if #[cfg(target_os = "haiku")] { - mod haiku; - pub use self::haiku::*; - } else if #[cfg(target_os = "hermit")] { - mod hermit; - pub use self::hermit::*; - } else if #[cfg(target_os = "redox")] { - mod redox; - pub use self::redox::*; - } else { - // Unknown target_os - } -} - -cfg_if! { - if #[cfg(libc_core_cvoid)] { - pub use ::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - #[allow(missing_copy_implementations)] - #[allow(missing_debug_implementations)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } else { - mod no_align; - pub use self::no_align::*; - } -} diff --git a/libc/src/unix/newlib/aarch64/mod.rs b/libc/src/unix/newlib/aarch64/mod.rs deleted file mode 100644 index 7e1b2bb..0000000 --- a/libc/src/unix/newlib/aarch64/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; - -pub type c_long = i64; -pub type c_ulong = u64; - -s! { - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: ::sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: ::sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [::c_char; 8], - } -} - -pub const POLLOUT: ::c_short = 0x4; -pub const POLLHUP: ::c_short = 0x10; diff --git a/libc/src/unix/newlib/align.rs b/libc/src/unix/newlib/align.rs deleted file mode 100644 index db9beb8..0000000 --- a/libc/src/unix/newlib/align.rs +++ /dev/null @@ -1,61 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))), - repr(align(8)))] - pub struct pthread_mutex_t { // Unverified - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))), - repr(align(8)))] - pub struct pthread_rwlock_t { // Unverified - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - - #[cfg_attr(any(target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64"), - repr(align(4)))] - #[cfg_attr(not(any(target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64")), - repr(align(8)))] - pub struct pthread_mutexattr_t { // Unverified - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[repr(align(8))] - pub struct pthread_cond_t { // Unverified - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - #[repr(align(4))] - pub struct pthread_condattr_t { // Unverified - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - }; -} diff --git a/libc/src/unix/newlib/arm/mod.rs b/libc/src/unix/newlib/arm/mod.rs deleted file mode 100644 index 39cb425..0000000 --- a/libc/src/unix/newlib/arm/mod.rs +++ /dev/null @@ -1,35 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; - -pub type c_long = i32; -pub type c_ulong = u32; - -s! { - pub struct sockaddr { - pub sa_family: ::sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in6 { - pub sin6_family: ::sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct sockaddr_in { - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [u8; 8], - } - - pub struct sockaddr_storage { - pub ss_family: ::sa_family_t, - pub __ss_padding: [u8; 26], - } -} - -pub const POLLOUT: ::c_short = 0x10; -pub const POLLHUP: ::c_short = 0x4; diff --git a/libc/src/unix/newlib/mod.rs b/libc/src/unix/newlib/mod.rs deleted file mode 100644 index bd9a107..0000000 --- a/libc/src/unix/newlib/mod.rs +++ /dev/null @@ -1,725 +0,0 @@ -pub type blkcnt_t = i32; -pub type blksize_t = i32; -pub type clock_t = i32; -pub type clockid_t = ::c_ulong; -pub type dev_t = u32; -pub type fsblkcnt_t = u64; -pub type fsfilcnt_t = u32; -pub type id_t = u32; -pub type ino_t = u32; -pub type key_t = ::c_int; -pub type loff_t = ::c_longlong; -pub type mode_t = ::c_uint; -pub type nfds_t = u32; -pub type nlink_t = ::c_ushort; -pub type off_t = i64; -pub type pthread_t = ::c_ulong; -pub type pthread_key_t = ::c_uint; -pub type rlim_t = u32; -pub type sa_family_t = u8; -pub type socklen_t = u32; -pub type speed_t = u32; -pub type suseconds_t = i32; -pub type tcflag_t = ::c_uint; -pub type time_t = i32; -pub type useconds_t = u32; - -s! { - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: socklen_t, - pub ai_canonname: *mut ::c_char, - pub ai_addr: *mut sockaddr, - pub ai_next: *mut addrinfo, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct linger { - pub l_onoff: ::c_int, - pub l_linger: ::c_int, - } - - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct hostent { - pub h_name: *mut ::c_char, - pub h_aliases: *mut *mut ::c_char, - pub h_addrtype: ::c_int, - pub h_length: ::c_int, - pub h_addr_list: *mut *mut ::c_char, - pub h_addr: *mut ::c_char, - } - - pub struct pollfd { - pub fd: ::c_int, - pub events: ::c_int, - pub revents: ::c_int, - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: dev_t, - pub st_size: off_t, - pub st_atime: time_t, - pub st_spare1: ::c_long, - pub st_mtime: time_t, - pub st_spare2: ::c_long, - pub st_ctime: time_t, - pub st_spare3: ::c_long, - pub st_blksize: blksize_t, - pub st_blocks: blkcnt_t, - pub st_spare4: [::c_long; 2usize], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: fsblkcnt_t, - pub f_bfree: fsblkcnt_t, - pub f_bavail: fsblkcnt_t, - pub f_files: fsfilcnt_t, - pub f_ffree: fsfilcnt_t, - pub f_favail: fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - } - - pub struct sigset_t { - __val: [::c_ulong; 16], - } - - pub struct sigaction { - pub sa_handler: extern fn(arg1: ::c_int), - pub sa_mask: sigset_t, - pub sa_flags: ::c_int, - } - - pub struct dirent { - pub d_ino: ino_t, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256usize], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: usize, - } - - pub struct fd_set { // Unverified - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], - } - - pub struct passwd { // Unverified - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct termios { // Unverified - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - } - - pub struct sem_t { // Unverified - __size: [::c_char; 16], - } - - pub struct Dl_info { // Unverified - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct utsname { // Unverified - pub sysname: [::c_char; 65], - pub nodename: [::c_char; 65], - pub release: [::c_char; 65], - pub version: [::c_char; 65], - pub machine: [::c_char; 65], - pub domainname: [::c_char; 65] - } - - pub struct cpu_set_t { // Unverified - bits: [u32; 32], - } - - pub struct pthread_attr_t { // Unverified - __size: [u64; 7] - } - - pub struct pthread_rwlockattr_t { // Unverified - __lockkind: ::c_int, - __pshared: ::c_int, - } -} - -// unverified constants -align_const! { - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - size: [0; __SIZEOF_PTHREAD_MUTEX_T], - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - size: [0; __SIZEOF_PTHREAD_COND_T], - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - size: [0; __SIZEOF_PTHREAD_RWLOCK_T], - }; -} -pub const NCCS: usize = 32; -pub const __SIZEOF_PTHREAD_ATTR_T: usize = 56; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_COND_T: usize = 48; -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; -pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32; -pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4; -pub const __PTHREAD_MUTEX_HAVE_PREV: usize = 1; -pub const __PTHREAD_RWLOCK_INT_FLAGS_SHARED: usize = 1; -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const FD_SETSIZE: usize = 1024; -// intentionally not public, only used for fd_set -const ULONG_SIZE: usize = 32; - -// Other constants -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EAGAIN: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const ENOMSG: ::c_int = 35; -pub const EIDRM: ::c_int = 36; -pub const EDEADLK: ::c_int = 45; -pub const ENOLCK: ::c_int = 46; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENOLINK: ::c_int = 67; -pub const EPROTO: ::c_int = 71; -pub const EMULTIHOP: ::c_int = 74; -pub const EBADMSG: ::c_int = 77; -pub const EFTYPE: ::c_int = 79; -pub const ENOSYS: ::c_int = 88; -pub const ENOTEMPTY: ::c_int = 90; -pub const ENAMETOOLONG: ::c_int = 91; -pub const ELOOP: ::c_int = 92; -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; -pub const ECONNRESET: ::c_int = 104; -pub const ENOBUFS: ::c_int = 105; -pub const EAFNOSUPPORT: ::c_int = 106; -pub const EPROTOTYPE: ::c_int = 107; -pub const ENOTSOCK: ::c_int = 108; -pub const ENOPROTOOPT: ::c_int = 109; -pub const ECONNREFUSED: ::c_int = 111; -pub const EADDRINUSE: ::c_int = 112; -pub const ECONNABORTED: ::c_int = 113; -pub const ENETUNREACH: ::c_int = 114; -pub const ENETDOWN: ::c_int = 115; -pub const ETIMEDOUT: ::c_int = 116; -pub const EHOSTDOWN: ::c_int = 117; -pub const EHOSTUNREACH: ::c_int = 118; -pub const EINPROGRESS: ::c_int = 119; -pub const EALREADY: ::c_int = 120; -pub const EDESTADDRREQ: ::c_int = 121; -pub const EMSGSIZE: ::c_int = 122; -pub const EPROTONOSUPPORT: ::c_int = 123; -pub const EADDRNOTAVAIL: ::c_int = 125; -pub const ENETRESET: ::c_int = 126; -pub const EISCONN: ::c_int = 127; -pub const ENOTCONN: ::c_int = 128; -pub const ETOOMANYREFS: ::c_int = 129; -pub const EDQUOT: ::c_int = 132; -pub const ESTALE: ::c_int = 133; -pub const ENOTSUP: ::c_int = 134; -pub const EILSEQ: ::c_int = 138; -pub const EOVERFLOW: ::c_int = 139; -pub const ECANCELED: ::c_int = 140; -pub const ENOTRECOVERABLE: ::c_int = 141; -pub const EOWNERDEAD: ::c_int = 142; -pub const EWOULDBLOCK: ::c_int = 11; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; -pub const F_GETOWN: ::c_int = 5; -pub const F_SETOWN: ::c_int = 6; -pub const F_GETLK: ::c_int = 7; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; -pub const F_RGETLK: ::c_int = 10; -pub const F_RSETLK: ::c_int = 11; -pub const F_CNVT: ::c_int = 12; -pub const F_RSETLKW: ::c_int = 13; -pub const F_DUPFD_CLOEXEC: ::c_int = 14; - -pub const O_RDONLY: ::c_int = 0; -pub const O_WRONLY: ::c_int = 1; -pub const O_RDWR: ::c_int = 2; -pub const O_APPEND: ::c_int = 8; -pub const O_CREAT: ::c_int = 512; -pub const O_TRUNC: ::c_int = 1024; -pub const O_EXCL: ::c_int = 2048; -pub const O_SYNC: ::c_int = 8192; -pub const O_NONBLOCK: ::c_int = 16384; - -pub const O_ACCMODE: ::c_int = 3; -pub const O_CLOEXEC: ::c_int = 0x80000; - -pub const POLLIN: ::c_short = 0x1; -pub const POLLPRI: ::c_short = 0x2; -pub const POLLERR: ::c_short = 0x8; -pub const POLLNVAL: ::c_short = 0x20; - -pub const RTLD_LAZY: ::c_int = 0x1; - -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; - -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; - -pub const FIONBIO: ::c_ulong = 1; -pub const FIOCLEX: ::c_ulong = 0x20006601; -pub const FIONCLEX: ::c_ulong = 0x20006602; - -pub const S_BLKSIZE: ::mode_t = 1024; -pub const S_IREAD: ::mode_t = 256; -pub const S_IWRITE: ::mode_t = 128; -pub const S_IEXEC: ::mode_t = 64; -pub const S_ENFMT: ::mode_t = 1024; -pub const S_IFMT: ::mode_t = 61440; -pub const S_IFDIR: ::mode_t = 16384; -pub const S_IFCHR: ::mode_t = 8192; -pub const S_IFBLK: ::mode_t = 24576; -pub const S_IFREG: ::mode_t = 32768; -pub const S_IFLNK: ::mode_t = 40960; -pub const S_IFSOCK: ::mode_t = 49152; -pub const S_IFIFO: ::mode_t = 4096; -pub const S_IRUSR: ::mode_t = 256; -pub const S_IWUSR: ::mode_t = 128; -pub const S_IXUSR: ::mode_t = 64; -pub const S_IRGRP: ::mode_t = 32; -pub const S_IWGRP: ::mode_t = 16; -pub const S_IXGRP: ::mode_t = 8; -pub const S_IROTH: ::mode_t = 4; -pub const S_IWOTH: ::mode_t = 2; -pub const S_IXOTH: ::mode_t = 1; - -pub const SOL_SOCKET: ::c_int = 65535; -pub const SOL_TCP: ::c_int = 6; - -pub const PF_UNSPEC: ::c_int = 0; -pub const PF_INET: ::c_int = 2; -pub const PF_INET6: ::c_int = 23; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_INET: ::c_int = 2; -pub const AF_INET6: ::c_int = 23; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; - -pub const MSG_OOB: ::c_int = 1; -pub const MSG_PEEK: ::c_int = 2; -pub const MSG_DONTWAIT: ::c_int = 4; -pub const MSG_DONTROUTE: ::c_int = 0; -pub const MSG_WAITALL: ::c_int = 0; -pub const MSG_MORE: ::c_int = 0; -pub const MSG_NOSIGNAL: ::c_int = 0; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const SO_BINTIME: ::c_int = 0x2000; -pub const SO_NO_OFFLOAD: ::c_int = 0x4000; -pub const SO_NO_DDP: ::c_int = 0x8000; -pub const SO_REUSEPORT_LB: ::c_int = 0x10000; -pub const SO_LABEL: ::c_int = 0x1009; -pub const SO_PEERLABEL: ::c_int = 0x1010; -pub const SO_LISTENQLIMIT: ::c_int = 0x1011; -pub const SO_LISTENQLEN: ::c_int = 0x1012; -pub const SO_LISTENINCQLEN: ::c_int = 0x1013; -pub const SO_SETFIB: ::c_int = 0x1014; -pub const SO_USER_COOKIE: ::c_int = 0x1015; -pub const SO_PROTOCOL: ::c_int = 0x1016; -pub const SO_PROTOTYPE: ::c_int = SO_PROTOCOL; -pub const SO_VENDOR: ::c_int = 0x80000000; -pub const SO_DEBUG: ::c_int = 0x01; -pub const SO_ACCEPTCONN: ::c_int = 0x0002; -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_USELOOPBACK: ::c_int = 0x0040; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_TIMESTAMP: ::c_int = 0x0400; -pub const SO_NOSIGPIPE: ::c_int = 0x0800; -pub const SO_ACCEPTFILTER: ::c_int = 0x1000; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_TYPE: ::c_int = 0x1008; - -pub const SOCK_CLOEXEC: ::c_int = O_CLOEXEC; - -pub const INET_ADDRSTRLEN: ::c_int = 16; - -// https://github. -// com/bminor/newlib/blob/master/newlib/libc/sys/linux/include/net/if.h#L121 -pub const IFF_UP: ::c_int = 0x1; // interface is up -pub const IFF_BROADCAST: ::c_int = 0x2; // broadcast address valid -pub const IFF_DEBUG: ::c_int = 0x4; // turn on debugging -pub const IFF_LOOPBACK: ::c_int = 0x8; // is a loopback net -pub const IFF_POINTOPOINT: ::c_int = 0x10; // interface is point-to-point link -pub const IFF_NOTRAILERS: ::c_int = 0x20; // avoid use of trailers -pub const IFF_RUNNING: ::c_int = 0x40; // resources allocated -pub const IFF_NOARP: ::c_int = 0x80; // no address resolution protocol -pub const IFF_PROMISC: ::c_int = 0x100; // receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x200; // receive all multicast packets -pub const IFF_OACTIVE: ::c_int = 0x400; // transmission in progress -pub const IFF_SIMPLEX: ::c_int = 0x800; // can't hear own transmissions -pub const IFF_LINK0: ::c_int = 0x1000; // per link layer defined bit -pub const IFF_LINK1: ::c_int = 0x2000; // per link layer defined bit -pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit -pub const IFF_ALTPHYS: ::c_int = IFF_LINK2; // use alternate physical connection -pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast - -pub const TCP_NODELAY: ::c_int = 8193; -pub const TCP_MAXSEG: ::c_int = 8194; -pub const TCP_NOPUSH: ::c_int = 4; -pub const TCP_NOOPT: ::c_int = 8; -pub const TCP_KEEPIDLE: ::c_int = 256; -pub const TCP_KEEPINTVL: ::c_int = 512; -pub const TCP_KEEPCNT: ::c_int = 1024; - -pub const IP_TOS: ::c_int = 3; -pub const IP_TTL: ::c_int = 8; -pub const IP_MULTICAST_IF: ::c_int = 9; -pub const IP_MULTICAST_TTL: ::c_int = 10; -pub const IP_MULTICAST_LOOP: ::c_int = 11; -pub const IP_ADD_MEMBERSHIP: ::c_int = 11; -pub const IP_DROP_MEMBERSHIP: ::c_int = 12; - -pub const IPV6_UNICAST_HOPS: ::c_int = 4; -pub const IPV6_MULTICAST_IF: ::c_int = 9; -pub const IPV6_MULTICAST_HOPS: ::c_int = 10; -pub const IPV6_MULTICAST_LOOP: ::c_int = 11; -pub const IPV6_V6ONLY: ::c_int = 27; -pub const IPV6_JOIN_GROUP: ::c_int = 12; -pub const IPV6_LEAVE_GROUP: ::c_int = 13; -pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12; -pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13; - -pub const HOST_NOT_FOUND: ::c_int = 1; -pub const NO_DATA: ::c_int = 2; -pub const NO_ADDRESS: ::c_int = 2; -pub const NO_RECOVERY: ::c_int = 3; -pub const TRY_AGAIN: ::c_int = 4; - -pub const AI_PASSIVE: ::c_int = 1; -pub const AI_CANONNAME: ::c_int = 2; -pub const AI_NUMERICHOST: ::c_int = 4; -pub const AI_NUMERICSERV: ::c_int = 0; -pub const AI_ADDRCONFIG: ::c_int = 0; - -pub const NI_MAXHOST: ::c_int = 1025; -pub const NI_MAXSERV: ::c_int = 32; -pub const NI_NOFQDN: ::c_int = 1; -pub const NI_NUMERICHOST: ::c_int = 2; -pub const NI_NAMEREQD: ::c_int = 4; -pub const NI_NUMERICSERV: ::c_int = 0; -pub const NI_DGRAM: ::c_int = 0; - -pub const EAI_FAMILY: ::c_int = -303; -pub const EAI_MEMORY: ::c_int = -304; -pub const EAI_NONAME: ::c_int = -305; -pub const EAI_SOCKTYPE: ::c_int = -307; - -f! { - pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); - return - } - - pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 - } - - pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - (*set).fds_bits[fd / bits] |= 1 << (fd % bits); - return - } - - pub fn FD_ZERO(set: *mut fd_set) -> () { - for slot in (*set).fds_bits.iter_mut() { - *slot = 0; - } - } -} - -extern "C" { - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - - #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")] - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; - pub fn rand() -> ::c_int; - pub fn srand(seed: ::c_uint); - - pub fn bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t) - -> ::c_int; - pub fn closesocket(sockfd: ::c_int) -> ::c_int; - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; - pub fn recvfrom( - fd: ::c_int, - buf: *mut ::c_void, - n: usize, - flags: ::c_int, - addr: *mut sockaddr, - addr_len: *mut socklen_t, - ) -> isize; - pub fn getnameinfo( - sa: *const sockaddr, - salen: socklen_t, - host: *mut ::c_char, - hostlen: socklen_t, - serv: *mut ::c_char, - servlen: socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; - pub fn fexecve( - fd: ::c_int, - argv: *const *const ::c_char, - envp: *const *const ::c_char, - ) -> ::c_int; - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r( - gid: ::gid_t, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigaltstack$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] - pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; - pub fn sem_close(sem: *mut sem_t) -> ::c_int; - pub fn getdtablesize() -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")] - pub fn getgrnam_r( - name: *const ::c_char, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_sigmask$UNIX2003" - )] - pub fn pthread_sigmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; - pub fn getgrnam(name: *const ::c_char) -> *mut ::group; - pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; - pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")] - pub fn getpwnam_r( - name: *const ::c_char, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")] - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigwait$UNIX2003" - )] - #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] - pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn getgrgid(gid: ::gid_t) -> *mut ::group; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "popen$UNIX2003" - )] - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - pub fn uname(buf: *mut ::utsname) -> ::c_int; -} - -cfg_if! { - if #[cfg(target_arch = "arm")] { - mod arm; - pub use self::arm::*; - } else if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else { - // Only tested on ARM so far. Other platforms might have different - // definitions for types and constants. - pub use target_arch_not_implemented; - } -} - -cfg_if! { - if #[cfg(libc_align)] { - #[macro_use] - mod align; - } else { - #[macro_use] - mod no_align; - } -} -expand_align!(); diff --git a/libc/src/unix/newlib/no_align.rs b/libc/src/unix/newlib/no_align.rs deleted file mode 100644 index 316c464..0000000 --- a/libc/src/unix/newlib/no_align.rs +++ /dev/null @@ -1,51 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - pub struct pthread_mutex_t { // Unverified - #[cfg(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))] - __align: [::c_long; 0], - #[cfg(not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - pub struct pthread_rwlock_t { // Unverified - #[cfg(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))] - __align: [::c_long; 0], - #[cfg(not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - - pub struct pthread_mutexattr_t { // Unverified - #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))] - __align: [::c_int; 0], - #[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")))] - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - pub struct pthread_cond_t { // Unverified - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - pub struct pthread_condattr_t { // Unverified - __align: [::c_int; 0], - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - } -} diff --git a/libc/src/unix/no_align.rs b/libc/src/unix/no_align.rs deleted file mode 100644 index f6b9f4c..0000000 --- a/libc/src/unix/no_align.rs +++ /dev/null @@ -1,6 +0,0 @@ -s! { - pub struct in6_addr { - pub s6_addr: [u8; 16], - __align: [u32; 0], - } -} diff --git a/libc/src/unix/redox/mod.rs b/libc/src/unix/redox/mod.rs deleted file mode 100644 index b00a191..0000000 --- a/libc/src/unix/redox/mod.rs +++ /dev/null @@ -1,1114 +0,0 @@ -pub type c_char = i8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type wchar_t = i32; - -pub type blkcnt_t = ::c_ulong; -pub type blksize_t = ::c_long; -pub type clock_t = ::c_long; -pub type clockid_t = ::c_int; -pub type dev_t = ::c_long; -pub type fsblkcnt_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; -pub type ino_t = ::c_ulong; -pub type mode_t = ::c_int; -pub type nfds_t = ::c_ulong; -pub type nlink_t = ::c_ulong; -pub type off_t = ::c_long; -pub type pthread_t = *mut ::c_void; -pub type pthread_attr_t = *mut ::c_void; -pub type pthread_cond_t = *mut ::c_void; -pub type pthread_condattr_t = *mut ::c_void; -// Must be usize due to libstd/sys_common/thread_local.rs, -// should technically be *mut ::c_void -pub type pthread_key_t = usize; -pub type pthread_mutex_t = *mut ::c_void; -pub type pthread_mutexattr_t = *mut ::c_void; -pub type pthread_rwlock_t = *mut ::c_void; -pub type pthread_rwlockattr_t = *mut ::c_void; -pub type rlim_t = ::c_ulonglong; -pub type sa_family_t = u16; -pub type sem_t = *mut ::c_void; -pub type sigset_t = ::c_ulong; -pub type socklen_t = u32; -pub type speed_t = u32; -pub type suseconds_t = ::c_int; -pub type tcflag_t = u32; -pub type time_t = ::c_long; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} - -s_no_extra_traits! { - #[repr(C)] - pub struct utsname { - pub sysname: [::c_char; UTSLENGTH], - pub nodename: [::c_char; UTSLENGTH], - pub release: [::c_char; UTSLENGTH], - pub version: [::c_char; UTSLENGTH], - pub machine: [::c_char; UTSLENGTH], - pub domainname: [::c_char; UTSLENGTH], - } - - pub struct dirent { - pub d_ino: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct sockaddr_un { - pub sun_family: ::sa_family_t, - pub sun_path: [::c_char; 108] - } - - pub struct sockaddr_storage { - pub ss_family: ::sa_family_t, - __ss_padding: [ - u8; - 128 - - ::core::mem::size_of::() - - ::core::mem::size_of::() - ], - __ss_align: ::c_ulong, - } -} - -s! { - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: ::size_t, - pub ai_canonname: *mut ::c_char, - pub ai_addr: *mut ::sockaddr, - pub ai_next: *mut ::addrinfo, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct epoll_event { - pub events: u32, - pub u64: u64, - pub _pad: u64, - } - - pub struct fd_set { - fds_bits: [::c_ulong; ::FD_SETSIZE / ULONG_SIZE], - } - - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct ip_mreq { - pub imr_multiaddr: ::in_addr, - pub imr_interface: ::in_addr, - } - - pub struct lconv { - pub currency_symbol: *const ::c_char, - pub decimal_point: *const ::c_char, - pub frac_digits: ::c_char, - pub grouping: *const ::c_char, - pub int_curr_symbol: *const ::c_char, - pub int_frac_digits: ::c_char, - pub mon_decimal_point: *const ::c_char, - pub mon_grouping: *const ::c_char, - pub mon_thousands_sep: *const ::c_char, - pub negative_sign: *const ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub n_sign_posn: ::c_char, - pub positive_sign: *const ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub thousands_sep: *const ::c_char, - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct sigaction { - pub sa_handler: ::sighandler_t, - pub sa_flags: ::c_ulong, - pub sa_restorer: ::Option, - pub sa_mask: ::sigset_t, - } - - pub struct sockaddr { - pub sa_family: ::sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [::c_char; 8], - } - - pub struct sockaddr_in6 { - pub sin6_family: ::sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - _pad: [::c_char; 24], - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - pub tm_gmtoff: ::c_long, - pub tm_zone: *const ::c_char, - } -} - -pub const UTSLENGTH: usize = 65; - -// intentionally not public, only used for fd_set -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - const ULONG_SIZE: usize = 32; - } else if #[cfg(target_pointer_width = "64")] { - const ULONG_SIZE: usize = 64; - } else { - // Unknown target_pointer_width - } -} - -// limits.h -pub const PATH_MAX: ::c_int = 4096; - -// fcntl.h -pub const F_GETLK: ::c_int = 5; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -// TODO: relibc { -pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; -// } - -// dlfcn.h -pub const RTLD_LAZY: ::c_int = 0x0001; -pub const RTLD_NOW: ::c_int = 0x0002; -pub const RTLD_GLOBAL: ::c_int = 0x0100; -pub const RTLD_LOCAL: ::c_int = 0x0000; - -// errno.h -pub const EPERM: ::c_int = 1; /* Operation not permitted */ -pub const ENOENT: ::c_int = 2; /* No such file or directory */ -pub const ESRCH: ::c_int = 3; /* No such process */ -pub const EINTR: ::c_int = 4; /* Interrupted system call */ -pub const EIO: ::c_int = 5; /* I/O error */ -pub const ENXIO: ::c_int = 6; /* No such device or address */ -pub const E2BIG: ::c_int = 7; /* Argument list too long */ -pub const ENOEXEC: ::c_int = 8; /* Exec format error */ -pub const EBADF: ::c_int = 9; /* Bad file number */ -pub const ECHILD: ::c_int = 10; /* No child processes */ -pub const EAGAIN: ::c_int = 11; /* Try again */ -pub const ENOMEM: ::c_int = 12; /* Out of memory */ -pub const EACCES: ::c_int = 13; /* Permission denied */ -pub const EFAULT: ::c_int = 14; /* Bad address */ -pub const ENOTBLK: ::c_int = 15; /* Block device required */ -pub const EBUSY: ::c_int = 16; /* Device or resource busy */ -pub const EEXIST: ::c_int = 17; /* File exists */ -pub const EXDEV: ::c_int = 18; /* Cross-device link */ -pub const ENODEV: ::c_int = 19; /* No such device */ -pub const ENOTDIR: ::c_int = 20; /* Not a directory */ -pub const EISDIR: ::c_int = 21; /* Is a directory */ -pub const EINVAL: ::c_int = 22; /* Invalid argument */ -pub const ENFILE: ::c_int = 23; /* File table overflow */ -pub const EMFILE: ::c_int = 24; /* Too many open files */ -pub const ENOTTY: ::c_int = 25; /* Not a typewriter */ -pub const ETXTBSY: ::c_int = 26; /* Text file busy */ -pub const EFBIG: ::c_int = 27; /* File too large */ -pub const ENOSPC: ::c_int = 28; /* No space left on device */ -pub const ESPIPE: ::c_int = 29; /* Illegal seek */ -pub const EROFS: ::c_int = 30; /* Read-only file system */ -pub const EMLINK: ::c_int = 31; /* Too many links */ -pub const EPIPE: ::c_int = 32; /* Broken pipe */ -pub const EDOM: ::c_int = 33; /* Math argument out of domain of func */ -pub const ERANGE: ::c_int = 34; /* Math result not representable */ -pub const EDEADLK: ::c_int = 35; /* Resource deadlock would occur */ -pub const ENAMETOOLONG: ::c_int = 36; /* File name too long */ -pub const ENOLCK: ::c_int = 37; /* No record locks available */ -pub const ENOSYS: ::c_int = 38; /* Function not implemented */ -pub const ENOTEMPTY: ::c_int = 39; /* Directory not empty */ -pub const ELOOP: ::c_int = 40; /* Too many symbolic links encountered */ -pub const EWOULDBLOCK: ::c_int = 41; /* Operation would block */ -pub const ENOMSG: ::c_int = 42; /* No message of desired type */ -pub const EIDRM: ::c_int = 43; /* Identifier removed */ -pub const ECHRNG: ::c_int = 44; /* Channel number out of range */ -pub const EL2NSYNC: ::c_int = 45; /* Level 2 not synchronized */ -pub const EL3HLT: ::c_int = 46; /* Level 3 halted */ -pub const EL3RST: ::c_int = 47; /* Level 3 reset */ -pub const ELNRNG: ::c_int = 48; /* Link number out of range */ -pub const EUNATCH: ::c_int = 49; /* Protocol driver not attached */ -pub const ENOCSI: ::c_int = 50; /* No CSI structure available */ -pub const EL2HLT: ::c_int = 51; /* Level 2 halted */ -pub const EBADE: ::c_int = 52; /* Invalid exchange */ -pub const EBADR: ::c_int = 53; /* Invalid request descriptor */ -pub const EXFULL: ::c_int = 54; /* Exchange full */ -pub const ENOANO: ::c_int = 55; /* No anode */ -pub const EBADRQC: ::c_int = 56; /* Invalid request code */ -pub const EBADSLT: ::c_int = 57; /* Invalid slot */ -pub const EDEADLOCK: ::c_int = 58; /* Resource deadlock would occur */ -pub const EBFONT: ::c_int = 59; /* Bad font file format */ -pub const ENOSTR: ::c_int = 60; /* Device not a stream */ -pub const ENODATA: ::c_int = 61; /* No data available */ -pub const ETIME: ::c_int = 62; /* Timer expired */ -pub const ENOSR: ::c_int = 63; /* Out of streams resources */ -pub const ENONET: ::c_int = 64; /* Machine is not on the network */ -pub const ENOPKG: ::c_int = 65; /* Package not installed */ -pub const EREMOTE: ::c_int = 66; /* Object is remote */ -pub const ENOLINK: ::c_int = 67; /* Link has been severed */ -pub const EADV: ::c_int = 68; /* Advertise error */ -pub const ESRMNT: ::c_int = 69; /* Srmount error */ -pub const ECOMM: ::c_int = 70; /* Communication error on send */ -pub const EPROTO: ::c_int = 71; /* Protocol error */ -pub const EMULTIHOP: ::c_int = 72; /* Multihop attempted */ -pub const EDOTDOT: ::c_int = 73; /* RFS specific error */ -pub const EBADMSG: ::c_int = 74; /* Not a data message */ -pub const EOVERFLOW: ::c_int = 75; /* Value too large for defined data type */ -pub const ENOTUNIQ: ::c_int = 76; /* Name not unique on network */ -pub const EBADFD: ::c_int = 77; /* File descriptor in bad state */ -pub const EREMCHG: ::c_int = 78; /* Remote address changed */ -pub const ELIBACC: ::c_int = 79; /* Can not access a needed shared library */ -pub const ELIBBAD: ::c_int = 80; /* Accessing a corrupted shared library */ -pub const ELIBSCN: ::c_int = 81; /* .lib section in a.out corrupted */ -/* Attempting to link in too many shared libraries */ -pub const ELIBMAX: ::c_int = 82; -pub const ELIBEXEC: ::c_int = 83; /* Cannot exec a shared library directly */ -pub const EILSEQ: ::c_int = 84; /* Illegal byte sequence */ -/* Interrupted system call should be restarted */ -pub const ERESTART: ::c_int = 85; -pub const ESTRPIPE: ::c_int = 86; /* Streams pipe error */ -pub const EUSERS: ::c_int = 87; /* Too many users */ -pub const ENOTSOCK: ::c_int = 88; /* Socket operation on non-socket */ -pub const EDESTADDRREQ: ::c_int = 89; /* Destination address required */ -pub const EMSGSIZE: ::c_int = 90; /* Message too long */ -pub const EPROTOTYPE: ::c_int = 91; /* Protocol wrong type for socket */ -pub const ENOPROTOOPT: ::c_int = 92; /* Protocol not available */ -pub const EPROTONOSUPPORT: ::c_int = 93; /* Protocol not supported */ -pub const ESOCKTNOSUPPORT: ::c_int = 94; /* Socket type not supported */ -/* Operation not supported on transport endpoint */ -pub const EOPNOTSUPP: ::c_int = 95; -pub const EPFNOSUPPORT: ::c_int = 96; /* Protocol family not supported */ -/* Address family not supported by protocol */ -pub const EAFNOSUPPORT: ::c_int = 97; -pub const EADDRINUSE: ::c_int = 98; /* Address already in use */ -pub const EADDRNOTAVAIL: ::c_int = 99; /* Cannot assign requested address */ -pub const ENETDOWN: ::c_int = 100; /* Network is down */ -pub const ENETUNREACH: ::c_int = 101; /* Network is unreachable */ -/* Network dropped connection because of reset */ -pub const ENETRESET: ::c_int = 102; -pub const ECONNABORTED: ::c_int = 103; /* Software caused connection abort */ -pub const ECONNRESET: ::c_int = 104; /* Connection reset by peer */ -pub const ENOBUFS: ::c_int = 105; /* No buffer space available */ -pub const EISCONN: ::c_int = 106; /* Transport endpoint is already connected */ -pub const ENOTCONN: ::c_int = 107; /* Transport endpoint is not connected */ -/* Cannot send after transport endpoint shutdown */ -pub const ESHUTDOWN: ::c_int = 108; -pub const ETOOMANYREFS: ::c_int = 109; /* Too many references: cannot splice */ -pub const ETIMEDOUT: ::c_int = 110; /* Connection timed out */ -pub const ECONNREFUSED: ::c_int = 111; /* Connection refused */ -pub const EHOSTDOWN: ::c_int = 112; /* Host is down */ -pub const EHOSTUNREACH: ::c_int = 113; /* No route to host */ -pub const EALREADY: ::c_int = 114; /* Operation already in progress */ -pub const EINPROGRESS: ::c_int = 115; /* Operation now in progress */ -pub const ESTALE: ::c_int = 116; /* Stale NFS file handle */ -pub const EUCLEAN: ::c_int = 117; /* Structure needs cleaning */ -pub const ENOTNAM: ::c_int = 118; /* Not a XENIX named type file */ -pub const ENAVAIL: ::c_int = 119; /* No XENIX semaphores available */ -pub const EISNAM: ::c_int = 120; /* Is a named type file */ -pub const EREMOTEIO: ::c_int = 121; /* Remote I/O error */ -pub const EDQUOT: ::c_int = 122; /* Quota exceeded */ -pub const ENOMEDIUM: ::c_int = 123; /* No medium found */ -pub const EMEDIUMTYPE: ::c_int = 124; /* Wrong medium type */ -pub const ECANCELED: ::c_int = 125; /* Operation Canceled */ -pub const ENOKEY: ::c_int = 126; /* Required key not available */ -pub const EKEYEXPIRED: ::c_int = 127; /* Key has expired */ -pub const EKEYREVOKED: ::c_int = 128; /* Key has been revoked */ -pub const EKEYREJECTED: ::c_int = 129; /* Key was rejected by service */ -pub const EOWNERDEAD: ::c_int = 130; /* Owner died */ -pub const ENOTRECOVERABLE: ::c_int = 131; /* State not recoverable */ - -// fcntl.h -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; -// TODO: relibc { -pub const F_DUPFD_CLOEXEC: ::c_int = ::F_DUPFD; -// } -pub const FD_CLOEXEC: ::c_int = 0x0100_0000; -pub const O_RDONLY: ::c_int = 0x0001_0000; -pub const O_WRONLY: ::c_int = 0x0002_0000; -pub const O_RDWR: ::c_int = 0x0003_0000; -pub const O_ACCMODE: ::c_int = 0x0003_0000; -pub const O_NONBLOCK: ::c_int = 0x0004_0000; -pub const O_APPEND: ::c_int = 0x0008_0000; -pub const O_SHLOCK: ::c_int = 0x0010_0000; -pub const O_EXLOCK: ::c_int = 0x0020_0000; -pub const O_ASYNC: ::c_int = 0x0040_0000; -pub const O_FSYNC: ::c_int = 0x0080_0000; -pub const O_CLOEXEC: ::c_int = 0x0100_0000; -pub const O_CREAT: ::c_int = 0x0200_0000; -pub const O_TRUNC: ::c_int = 0x0400_0000; -pub const O_EXCL: ::c_int = 0x0800_0000; -pub const O_DIRECTORY: ::c_int = 0x1000_0000; -pub const O_PATH: ::c_int = 0x2000_0000; -pub const O_SYMLINK: ::c_int = 0x4000_0000; -// Negative to allow it to be used as int -// TODO: Fix negative values missing from includes -pub const O_NOFOLLOW: ::c_int = -0x8000_0000; - -// netdb.h -pub const EAI_SYSTEM: ::c_int = -11; - -// netinet/in.h -// TODO: relibc { -pub const IP_TTL: ::c_int = 2; -pub const IPV6_UNICAST_HOPS: ::c_int = 16; -pub const IPV6_MULTICAST_IF: ::c_int = 17; -pub const IPV6_MULTICAST_HOPS: ::c_int = 18; -pub const IPV6_MULTICAST_LOOP: ::c_int = 19; -pub const IPV6_ADD_MEMBERSHIP: ::c_int = 20; -pub const IPV6_DROP_MEMBERSHIP: ::c_int = 21; -pub const IPV6_V6ONLY: ::c_int = 26; -pub const IP_MULTICAST_IF: ::c_int = 32; -pub const IP_MULTICAST_TTL: ::c_int = 33; -pub const IP_MULTICAST_LOOP: ::c_int = 34; -pub const IP_ADD_MEMBERSHIP: ::c_int = 35; -pub const IP_DROP_MEMBERSHIP: ::c_int = 36; -// } - -// netinet/tcp.h -pub const TCP_NODELAY: ::c_int = 1; -// TODO: relibc { -pub const TCP_KEEPIDLE: ::c_int = 1; -// } - -// poll.h -pub const POLLIN: ::c_short = 0x001; -pub const POLLPRI: ::c_short = 0x002; -pub const POLLOUT: ::c_short = 0x004; -pub const POLLERR: ::c_short = 0x008; -pub const POLLHUP: ::c_short = 0x010; -pub const POLLNVAL: ::c_short = 0x020; - -// pthread.h -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_MUTEX_INITIALIZER: ::pthread_mutex_t = -1isize as *mut _; -pub const PTHREAD_COND_INITIALIZER: ::pthread_cond_t = -1isize as *mut _; -pub const PTHREAD_RWLOCK_INITIALIZER: ::pthread_rwlock_t = -1isize as *mut _; -pub const PTHREAD_STACK_MIN: ::size_t = 4096; - -// signal.h -pub const SIG_BLOCK: ::c_int = 0; -pub const SIG_UNBLOCK: ::c_int = 1; -pub const SIG_SETMASK: ::c_int = 2; -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGTRAP: ::c_int = 5; -pub const SIGABRT: ::c_int = 6; -pub const SIGBUS: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGUSR1: ::c_int = 10; -pub const SIGSEGV: ::c_int = 11; -pub const SIGUSR2: ::c_int = 12; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; -pub const SIGSTKFLT: ::c_int = 16; -pub const SIGCHLD: ::c_int = 17; -pub const SIGCONT: ::c_int = 18; -pub const SIGSTOP: ::c_int = 19; -pub const SIGTSTP: ::c_int = 20; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; -pub const SIGURG: ::c_int = 23; -pub const SIGXCPU: ::c_int = 24; -pub const SIGXFSZ: ::c_int = 25; -pub const SIGVTALRM: ::c_int = 26; -pub const SIGPROF: ::c_int = 27; -pub const SIGWINCH: ::c_int = 28; -pub const SIGIO: ::c_int = 29; -pub const SIGPWR: ::c_int = 30; -pub const SIGSYS: ::c_int = 31; -pub const NSIG: ::c_int = 32; - -pub const SA_NOCLDSTOP: ::c_ulong = 0x00000001; -pub const SA_NOCLDWAIT: ::c_ulong = 0x00000002; -pub const SA_SIGINFO: ::c_ulong = 0x00000004; -pub const SA_RESTORER: ::c_ulong = 0x04000000; -pub const SA_ONSTACK: ::c_ulong = 0x08000000; -pub const SA_RESTART: ::c_ulong = 0x10000000; -pub const SA_NODEFER: ::c_ulong = 0x40000000; -pub const SA_RESETHAND: ::c_ulong = 0x80000000; - -// sys/epoll.h -pub const EPOLL_CLOEXEC: ::c_int = 0x0100_0000; -pub const EPOLL_CTL_ADD: ::c_int = 1; -pub const EPOLL_CTL_DEL: ::c_int = 2; -pub const EPOLL_CTL_MOD: ::c_int = 3; -pub const EPOLLIN: ::c_int = 1; -pub const EPOLLPRI: ::c_int = 0; -pub const EPOLLOUT: ::c_int = 2; -pub const EPOLLRDNORM: ::c_int = 0; -pub const EPOLLNVAL: ::c_int = 0; -pub const EPOLLRDBAND: ::c_int = 0; -pub const EPOLLWRNORM: ::c_int = 0; -pub const EPOLLWRBAND: ::c_int = 0; -pub const EPOLLMSG: ::c_int = 0; -pub const EPOLLERR: ::c_int = 0; -pub const EPOLLHUP: ::c_int = 0; -pub const EPOLLRDHUP: ::c_int = 0; -pub const EPOLLEXCLUSIVE: ::c_int = 0; -pub const EPOLLWAKEUP: ::c_int = 0; -pub const EPOLLONESHOT: ::c_int = 0; -pub const EPOLLET: ::c_int = 0; - -// sys/stat.h -pub const S_IFMT: ::c_int = 0o0_170_000; -pub const S_IFDIR: ::c_int = 0o040_000; -pub const S_IFCHR: ::c_int = 0o020_000; -pub const S_IFBLK: ::c_int = 0o060_000; -pub const S_IFREG: ::c_int = 0o100_000; -pub const S_IFIFO: ::c_int = 0o010_000; -pub const S_IFLNK: ::c_int = 0o120_000; -pub const S_IFSOCK: ::c_int = 0o140_000; -pub const S_IRWXU: ::c_int = 0o0_700; -pub const S_IRUSR: ::c_int = 0o0_400; -pub const S_IWUSR: ::c_int = 0o0_200; -pub const S_IXUSR: ::c_int = 0o0_100; -pub const S_IRWXG: ::c_int = 0o0_070; -pub const S_IRGRP: ::c_int = 0o0_040; -pub const S_IWGRP: ::c_int = 0o0_020; -pub const S_IXGRP: ::c_int = 0o0_010; -pub const S_IRWXO: ::c_int = 0o0_007; -pub const S_IROTH: ::c_int = 0o0_004; -pub const S_IWOTH: ::c_int = 0o0_002; -pub const S_IXOTH: ::c_int = 0o0_001; - -// stdlib.h -pub const EXIT_SUCCESS: ::c_int = 0; -pub const EXIT_FAILURE: ::c_int = 1; - -// sys/ioctl.h -// TODO: relibc { -pub const FIONBIO: ::c_ulong = 0x5421; -pub const FIOCLEX: ::c_ulong = 0x5451; -// } -pub const TCGETS: ::c_ulong = 0x5401; -pub const TCSETS: ::c_ulong = 0x5402; -pub const TCFLSH: ::c_ulong = 0x540B; -pub const TIOCGPGRP: ::c_ulong = 0x540F; -pub const TIOCSPGRP: ::c_ulong = 0x5410; -pub const TIOCGWINSZ: ::c_ulong = 0x5413; -pub const TIOCSWINSZ: ::c_ulong = 0x5414; - -// sys/select.h -pub const FD_SETSIZE: usize = 1024; - -// sys/socket.h -pub const AF_UNIX: ::c_int = 1; -pub const AF_INET: ::c_int = 2; -pub const AF_INET6: ::c_int = 10; -pub const MSG_PEEK: ::c_int = 2; -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_ERROR: ::c_int = 4; -pub const SO_BROADCAST: ::c_int = 6; -pub const SO_SNDBUF: ::c_int = 7; -pub const SO_RCVBUF: ::c_int = 8; -pub const SO_KEEPALIVE: ::c_int = 9; -pub const SO_LINGER: ::c_int = 13; -pub const SO_REUSEPORT: ::c_int = 15; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOL_SOCKET: ::c_int = 1; - -// sys/termios.h -pub const NCCS: usize = 32; - -pub const VINTR: usize = 0; -pub const VQUIT: usize = 1; -pub const VERASE: usize = 2; -pub const VKILL: usize = 3; -pub const VEOF: usize = 4; -pub const VTIME: usize = 5; -pub const VMIN: usize = 6; -pub const VSWTC: usize = 7; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VSUSP: usize = 10; -pub const VEOL: usize = 11; -pub const VREPRINT: usize = 12; -pub const VDISCARD: usize = 13; -pub const VWERASE: usize = 14; -pub const VLNEXT: usize = 15; -pub const VEOL2: usize = 16; - -pub const IGNBRK: ::tcflag_t = 0o000_001; -pub const BRKINT: ::tcflag_t = 0o000_002; -pub const IGNPAR: ::tcflag_t = 0o000_004; -pub const PARMRK: ::tcflag_t = 0o000_010; -pub const INPCK: ::tcflag_t = 0o000_020; -pub const ISTRIP: ::tcflag_t = 0o000_040; -pub const INLCR: ::tcflag_t = 0o000_100; -pub const IGNCR: ::tcflag_t = 0o000_200; -pub const ICRNL: ::tcflag_t = 0o000_400; -pub const IUCLC: ::tcflag_t = 0o001_000; -pub const IXON: ::tcflag_t = 0o002_000; -pub const IXANY: ::tcflag_t = 0o004_000; -pub const IXOFF: ::tcflag_t = 0o010_000; -pub const IMAXBEL: ::tcflag_t = 0o020_000; -pub const IUTF8: ::tcflag_t = 0o040_000; - -pub const OPOST: ::tcflag_t = 0o000_001; -pub const OLCUC: ::tcflag_t = 0o000_002; -pub const ONLCR: ::tcflag_t = 0o000_004; -pub const OCRNL: ::tcflag_t = 0o000_010; -pub const ONOCR: ::tcflag_t = 0o000_020; -pub const ONLRET: ::tcflag_t = 0o00_0040; -pub const OFILL: ::tcflag_t = 0o000_100; -pub const OFDEL: ::tcflag_t = 0o000_200; - -pub const VTDLY: usize = 0o040_000; -pub const VT0: usize = 0o000_000; -pub const VT1: usize = 0o040_000; - -pub const B0: speed_t = 0o000_000; -pub const B50: speed_t = 0o000_001; -pub const B75: speed_t = 0o000_002; -pub const B110: speed_t = 0o000_003; -pub const B134: speed_t = 0o000_004; -pub const B150: speed_t = 0o000_005; -pub const B200: speed_t = 0o000_006; -pub const B300: speed_t = 0o000_007; -pub const B600: speed_t = 0o000_010; -pub const B1200: speed_t = 0o000_011; -pub const B1800: speed_t = 0o000_012; -pub const B2400: speed_t = 0o000_013; -pub const B4800: speed_t = 0o000_014; -pub const B9600: speed_t = 0o000_015; -pub const B19200: speed_t = 0o000_016; -pub const B38400: speed_t = 0o000_017; - -pub const B57600: speed_t = 0o010_001; -pub const B115200: speed_t = 0o010_002; -pub const B230400: speed_t = 0o010_003; -pub const B460800: speed_t = 0o010_004; -pub const B500000: speed_t = 0o010_005; -pub const B576000: speed_t = 0o010_006; -pub const B921600: speed_t = 0o010_007; -pub const B1000000: speed_t = 0o010_010; -pub const B1152000: speed_t = 0o010_011; -pub const B1500000: speed_t = 0o010_012; -pub const B2000000: speed_t = 0o010_013; -pub const B2500000: speed_t = 0o010_014; -pub const B3000000: speed_t = 0o010_015; -pub const B3500000: speed_t = 0o010_016; -pub const B4000000: speed_t = 0o010_017; - -pub const CSIZE: ::tcflag_t = 0o000_060; -pub const CS5: ::tcflag_t = 0o000_000; -pub const CS6: ::tcflag_t = 0o000_020; -pub const CS7: ::tcflag_t = 0o000_040; -pub const CS8: ::tcflag_t = 0o000_060; -pub const CSTOPB: ::tcflag_t = 0o000_100; -pub const CREAD: ::tcflag_t = 0o000_200; -pub const PARENB: ::tcflag_t = 0o000_400; -pub const PARODD: ::tcflag_t = 0o001_000; -pub const HUPCL: ::tcflag_t = 0o002_000; -pub const CLOCAL: ::tcflag_t = 0o004_000; - -pub const ISIG: ::tcflag_t = 0o000_001; -pub const ICANON: ::tcflag_t = 0o000_002; -pub const ECHO: ::tcflag_t = 0o000_010; -pub const ECHOE: ::tcflag_t = 0o000_020; -pub const ECHOK: ::tcflag_t = 0o000_040; -pub const ECHONL: ::tcflag_t = 0o000_100; -pub const NOFLSH: ::tcflag_t = 0o000_200; -pub const TOSTOP: ::tcflag_t = 0o000_400; -pub const IEXTEN: ::tcflag_t = 0o100_000; - -pub const TCOOFF: ::c_int = 0; -pub const TCOON: ::c_int = 1; -pub const TCIOFF: ::c_int = 2; -pub const TCION: ::c_int = 3; - -pub const TCIFLUSH: ::c_int = 0; -pub const TCOFLUSH: ::c_int = 1; -pub const TCIOFLUSH: ::c_int = 2; - -pub const TCSANOW: ::c_int = 0; -pub const TCSADRAIN: ::c_int = 1; -pub const TCSAFLUSH: ::c_int = 2; - -// sys/wait.h -pub const WNOHANG: ::c_int = 1; -pub const WUNTRACED: ::c_int = 2; - -pub const WSTOPPED: ::c_int = 2; -pub const WEXITED: ::c_int = 4; -pub const WCONTINUED: ::c_int = 8; -pub const WNOWAIT: ::c_int = 0x0100_0000; - -pub const __WNOTHREAD: ::c_int = 0x2000_0000; -pub const __WALL: ::c_int = 0x4000_0000; -#[allow(overflowing_literals)] -pub const __WCLONE: ::c_int = 0x8000_0000; - -// time.h -pub const CLOCK_REALTIME: ::c_int = 1; -pub const CLOCK_MONOTONIC: ::c_int = 4; - -// unistd.h -// POSIX.1 { -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_CHILD_MAX: ::c_int = 1; -pub const _SC_CLK_TCK: ::c_int = 2; -pub const _SC_NGROUPS_MAX: ::c_int = 3; -pub const _SC_OPEN_MAX: ::c_int = 4; -pub const _SC_STREAM_MAX: ::c_int = 5; -pub const _SC_TZNAME_MAX: ::c_int = 6; -// ... -pub const _SC_VERSION: ::c_int = 29; -pub const _SC_PAGESIZE: ::c_int = 30; -pub const _SC_PAGE_SIZE: ::c_int = 30; -// ... -pub const _SC_RE_DUP_MAX: ::c_int = 44; -// ... -pub const _SC_LOGIN_NAME_MAX: ::c_int = 71; -pub const _SC_TTY_NAME_MAX: ::c_int = 72; -// ... -pub const _SC_SYMLOOP_MAX: ::c_int = 173; -// ... -pub const _SC_HOST_NAME_MAX: ::c_int = 180; -// } POSIX.1 - -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; - -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; - -pub const _PC_LINK_MAX: ::c_int = 0; -pub const _PC_MAX_CANON: ::c_int = 1; -pub const _PC_MAX_INPUT: ::c_int = 2; -pub const _PC_NAME_MAX: ::c_int = 3; -pub const _PC_PATH_MAX: ::c_int = 4; -pub const _PC_PIPE_BUF: ::c_int = 5; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 6; -pub const _PC_NO_TRUNC: ::c_int = 7; -pub const _PC_VDISABLE: ::c_int = 8; -pub const _PC_SYNC_IO: ::c_int = 9; -pub const _PC_ASYNC_IO: ::c_int = 10; -pub const _PC_PRIO_IO: ::c_int = 11; -pub const _PC_SOCK_MAXBUF: ::c_int = 12; -pub const _PC_FILESIZEBITS: ::c_int = 13; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 14; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 15; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 16; -pub const _PC_REC_XFER_ALIGN: ::c_int = 17; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 18; -pub const _PC_SYMLINK_MAX: ::c_int = 19; -pub const _PC_2_SYMLINKS: ::c_int = 20; - -// wait.h -f! { - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0xff) == 0x7f - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WIFCONTINUED(status: ::c_int) -> bool { - status == 0xffff - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - ((status & 0x7f) + 1) as i8 >= 2 - } - - pub fn WTERMSIG(status: ::c_int) -> ::c_int { - status & 0x7f - } - - pub fn WIFEXITED(status: ::c_int) -> bool { - (status & 0x7f) == 0 - } - - pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WCOREDUMP(status: ::c_int) -> bool { - (status & 0x80) != 0 - } -} - -extern "C" { - // errno.h - pub fn __errno_location() -> *mut ::c_int; - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - // unistd.h - pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int; - - // malloc.h - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; - - // pthread.h - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn pthread_create( - tid: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - start: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - arg: *mut ::c_void, - ) -> ::c_int; - pub fn pthread_condattr_setclock( - attr: *mut pthread_condattr_t, - clock_id: ::clockid_t, - ) -> ::c_int; - - // pwd.h - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - - // signal.h - pub fn pthread_sigmask( - how: ::c_int, - set: *const ::sigset_t, - oldset: *mut ::sigset_t, - ) -> ::c_int; - - // sys/epoll.h - pub fn epoll_create(size: ::c_int) -> ::c_int; - pub fn epoll_create1(flags: ::c_int) -> ::c_int; - pub fn epoll_wait( - epfd: ::c_int, - events: *mut ::epoll_event, - maxevents: ::c_int, - timeout: ::c_int, - ) -> ::c_int; - pub fn epoll_ctl( - epfd: ::c_int, - op: ::c_int, - fd: ::c_int, - event: *mut ::epoll_event, - ) -> ::c_int; - - // sys/ioctl.h - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; - - // sys/resource.h - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - - // sys/socket.h - pub fn bind( - socket: ::c_int, - address: *const ::sockaddr, - address_len: ::socklen_t, - ) -> ::c_int; - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - - // sys/stat.h - pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; - - // sys/uio.h - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - - // sys/utsname.h - pub fn uname(utsname: *mut utsname) -> ::c_int; - - // time.h - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for dirent { - fn eq(&self, other: &dirent) -> bool { - self.d_ino == other.d_ino - && self.d_off == other.d_off - && self.d_reclen == other.d_reclen - && self.d_type == other.d_type - && self - .d_name - .iter() - .zip(other.d_name.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for dirent {} - - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_ino", &self.d_ino) - .field("d_off", &self.d_off) - .field("d_reclen", &self.d_reclen) - .field("d_type", &self.d_type) - // FIXME: .field("d_name", &self.d_name) - .finish() - } - } - - impl ::hash::Hash for dirent { - fn hash(&self, state: &mut H) { - self.d_ino.hash(state); - self.d_off.hash(state); - self.d_reclen.hash(state); - self.d_type.hash(state); - self.d_name.hash(state); - } - } - - impl PartialEq for sockaddr_un { - fn eq(&self, other: &sockaddr_un) -> bool { - self.sun_family == other.sun_family - && self - .sun_path - .iter() - .zip(other.sun_path.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for sockaddr_un {} - - impl ::fmt::Debug for sockaddr_un { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_un") - .field("sun_family", &self.sun_family) - // FIXME: .field("sun_path", &self.sun_path) - .finish() - } - } - - impl ::hash::Hash for sockaddr_un { - fn hash(&self, state: &mut H) { - self.sun_family.hash(state); - self.sun_path.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_family == other.ss_family - && self.__ss_align == self.__ss_align - && self - .__ss_padding - .iter() - .zip(other.__ss_padding.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for sockaddr_storage {} - - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_family", &self.ss_family) - .field("__ss_align", &self.__ss_align) - // FIXME: .field("__ss_padding", &self.__ss_padding) - .finish() - } - } - - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_family.hash(state); - self.__ss_padding.hash(state); - self.__ss_align.hash(state); - } - } - - impl PartialEq for utsname { - fn eq(&self, other: &utsname) -> bool { - self.sysname - .iter() - .zip(other.sysname.iter()) - .all(|(a, b)| a == b) - && self - .nodename - .iter() - .zip(other.nodename.iter()) - .all(|(a, b)| a == b) - && self - .release - .iter() - .zip(other.release.iter()) - .all(|(a, b)| a == b) - && self - .version - .iter() - .zip(other.version.iter()) - .all(|(a, b)| a == b) - && self - .machine - .iter() - .zip(other.machine.iter()) - .all(|(a, b)| a == b) - && self - .domainname - .iter() - .zip(other.domainname.iter()) - .all(|(a, b)| a == b) - } - } - - impl Eq for utsname {} - - impl ::fmt::Debug for utsname { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utsname") - // FIXME: .field("sysname", &self.sysname) - // FIXME: .field("nodename", &self.nodename) - // FIXME: .field("release", &self.release) - // FIXME: .field("version", &self.version) - // FIXME: .field("machine", &self.machine) - // FIXME: .field("domainname", &self.domainname) - .finish() - } - } - - impl ::hash::Hash for utsname { - fn hash(&self, state: &mut H) { - self.sysname.hash(state); - self.nodename.hash(state); - self.release.hash(state); - self.version.hash(state); - self.machine.hash(state); - self.domainname.hash(state); - } - } - } -} diff --git a/libc/src/unix/solarish/compat.rs b/libc/src/unix/solarish/compat.rs deleted file mode 100644 index a336452..0000000 --- a/libc/src/unix/solarish/compat.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Common functions that are unfortunately missing on illumos and -// Solaris, but often needed by other crates. - -use unix::solarish::*; - -pub unsafe fn cfmakeraw(termios: *mut ::termios) { - let mut t = *termios as ::termios; - t.c_iflag &= !(IMAXBEL - | IGNBRK - | BRKINT - | PARMRK - | ISTRIP - | INLCR - | IGNCR - | ICRNL - | IXON); - t.c_oflag &= !OPOST; - t.c_lflag &= !(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - t.c_cflag &= !(CSIZE | PARENB); - t.c_cflag |= CS8; -} - -pub unsafe fn cfsetspeed( - termios: *mut ::termios, - speed: ::speed_t, -) -> ::c_int { - // Neither of these functions on illumos or Solaris actually ever - // return an error - ::cfsetispeed(termios, speed); - ::cfsetospeed(termios, speed); - 0 -} diff --git a/libc/src/unix/solarish/mod.rs b/libc/src/unix/solarish/mod.rs deleted file mode 100644 index 06c1a20..0000000 --- a/libc/src/unix/solarish/mod.rs +++ /dev/null @@ -1,2499 +0,0 @@ -pub type c_char = i8; -pub type c_long = i64; -pub type c_ulong = u64; - -pub type clockid_t = ::c_int; -pub type blkcnt_t = ::c_long; -pub type clock_t = ::c_long; -pub type daddr_t = ::c_long; -pub type dev_t = ::c_ulong; -pub type fsblkcnt_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; -pub type ino_t = ::c_ulong; -pub type key_t = ::c_int; -pub type major_t = ::c_uint; -pub type minor_t = ::c_uint; -pub type mode_t = ::c_uint; -pub type nlink_t = ::c_uint; -pub type rlim_t = ::c_ulong; -pub type speed_t = ::c_uint; -pub type tcflag_t = ::c_uint; -pub type time_t = ::c_long; -pub type wchar_t = ::c_int; -pub type nfds_t = ::c_ulong; - -pub type suseconds_t = ::c_long; -pub type off_t = ::c_long; -pub type useconds_t = ::c_uint; -pub type socklen_t = ::c_uint; -pub type sa_family_t = u16; -pub type pthread_t = ::c_uint; -pub type pthread_key_t = ::c_uint; -pub type blksize_t = ::c_int; -pub type nl_item = ::c_int; -pub type mqd_t = *mut ::c_void; -pub type id_t = ::c_int; -pub type idtype_t = ::c_uint; -pub type shmatt_t = ::c_ulong; - -pub type door_attr_t = ::c_uint; -pub type door_id_t = ::c_ulonglong; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} - -s! { - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct ipc_perm { - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::mode_t, - pub seq: ::c_uint, - pub key: ::key_t, - } - - pub struct sockaddr { - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_family: sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [::c_char; 8] - } - - pub struct sockaddr_in6 { - pub sin6_family: sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - pub __sin6_src_id: u32 - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_age: *mut ::c_char, - pub pw_comment: *mut ::c_char, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char - } - - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut ::c_char, - pub ifa_flags: ::c_ulong, - pub ifa_addr: *mut ::sockaddr, - pub ifa_netmask: *mut ::sockaddr, - pub ifa_dstaddr: *mut ::sockaddr, - pub ifa_data: *mut ::c_void - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::socklen_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct pthread_attr_t { - __pthread_attrp: *mut ::c_void - } - - pub struct pthread_mutex_t { - __pthread_mutex_flag1: u16, - __pthread_mutex_flag2: u8, - __pthread_mutex_ceiling: u8, - __pthread_mutex_type: u16, - __pthread_mutex_magic: u16, - __pthread_mutex_lock: u64, - __pthread_mutex_data: u64 - } - - pub struct pthread_mutexattr_t { - __pthread_mutexattrp: *mut ::c_void - } - - pub struct pthread_cond_t { - __pthread_cond_flag: [u8; 4], - __pthread_cond_type: u16, - __pthread_cond_magic: u16, - __pthread_cond_data: u64 - } - - pub struct pthread_condattr_t { - __pthread_condattrp: *mut ::c_void, - } - - pub struct pthread_rwlock_t { - __pthread_rwlock_readers: i32, - __pthread_rwlock_type: u16, - __pthread_rwlock_magic: u16, - __pthread_rwlock_mutex: ::pthread_mutex_t, - __pthread_rwlock_readercv: ::pthread_cond_t, - __pthread_rwlock_writercv: ::pthread_cond_t - } - - pub struct pthread_rwlockattr_t { - __pthread_rwlockattrp: *mut ::c_void, - } - - pub struct dirent { - pub d_ino: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: u16, - pub d_name: [::c_char; 3] - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut ::c_char, - pub gl_offs: ::size_t, - __unused1: *mut ::c_void, - __unused2: ::c_int, - __unused3: ::c_int, - __unused4: ::c_int, - __unused5: *mut ::c_void, - __unused6: *mut ::c_void, - __unused7: *mut ::c_void, - __unused8: *mut ::c_void, - __unused9: *mut ::c_void, - __unused10: *mut ::c_void, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - #[cfg(target_arch = "sparc64")] - __sparcv9_pad: ::c_int, - pub ai_addrlen: ::socklen_t, - pub ai_canonname: *mut ::c_char, - pub ai_addr: *mut ::sockaddr, - pub ai_next: *mut addrinfo, - } - - pub struct shmid_ds { - pub shm_perm: ipc_perm, - pub shm_segsz: ::size_t, - #[cfg(target_os = "illumos")] - pub shm_amp: *mut ::c_void, - #[cfg(target_os = "solaris")] - pub shm_flags: ::uintptr_t, - pub shm_lkcnt: ::c_ushort, - pub shm_lpid: ::pid_t, - pub shm_cpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - pub shm_cnattch: ::c_ulong, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - #[cfg(target_os = "illumos")] - pub shm_pad4: [i64; 4], - #[cfg(target_os = "solaris")] - pub shm_amp: *mut ::c_void, - #[cfg(target_os = "solaris")] - pub shm_gransize: u64, - #[cfg(target_os = "solaris")] - pub shm_allocated: u64, - #[cfg(target_os = "solaris")] - pub shm_pad4: [i64; 1], - } - - pub struct sigset_t { - bits: [u32; 4], - } - - pub struct sigaction { - pub sa_flags: ::c_int, - pub sa_sigaction: ::sighandler_t, - pub sa_mask: sigset_t, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - pub f_fsid: ::c_ulong, - pub f_basetype: [::c_char; 16], - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - pub f_fstr: [::c_char; 32] - } - - pub struct sched_param { - pub sched_priority: ::c_int, - sched_pad: [::c_int; 8] - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - __unused: [::c_char; 16] - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_cc: [::cc_t; ::NCCS] - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct sem_t { - pub sem_count: u32, - pub sem_type: u16, - pub sem_magic: u16, - pub sem_pad1: [u64; 3], - pub sem_pad2: [u64; 2] - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_sysid: ::c_int, - pub l_pid: ::pid_t, - pub l_pad: [::c_long; 4] - } - - pub struct if_nameindex { - pub if_index: ::c_uint, - pub if_name: *mut ::c_char, - } - - pub struct mq_attr { - pub mq_flags: ::c_long, - pub mq_maxmsg: ::c_long, - pub mq_msgsize: ::c_long, - pub mq_curmsgs: ::c_long, - _pad: [::c_int; 4] - } - - pub struct port_event { - pub portev_events: ::c_int, - pub portev_source: ::c_ushort, - pub portev_pad: ::c_ushort, - pub portev_object: ::uintptr_t, - pub portev_user: *mut ::c_void, - } - - pub struct door_desc_t__d_data__d_desc { - pub d_descriptor: ::c_int, - pub d_id: ::door_id_t - } - - pub struct exit_status { - e_termination: ::c_short, - e_exit: ::c_short, - } - - pub struct utmp { - pub ut_user: [::c_char; 8], - pub ut_id: [::c_char; 4], - pub ut_line: [::c_char; 12], - pub ut_pid: ::c_short, - pub ut_type: ::c_short, - pub ut_exit: exit_status, - pub ut_time: ::time_t, - } -} - -s_no_extra_traits! { - #[cfg_attr(any(target_arch = "x86", target_arch = "x86_64"), repr(packed))] - pub struct epoll_event { - pub events: u32, - pub u64: u64, - } - - pub struct utmpx { - pub ut_user: [::c_char; _UTX_USERSIZE], - pub ut_id: [::c_char; _UTX_IDSIZE], - pub ut_line: [::c_char; _UTX_LINESIZE], - pub ut_pid: ::pid_t, - pub ut_type: ::c_short, - pub ut_exit: exit_status, - pub ut_tv: ::timeval, - pub ut_session: ::c_int, - pub ut_pad: [::c_int; _UTX_PADSIZE], - pub ut_syslen: ::c_short, - pub ut_host: [::c_char; _UTX_HOSTSIZE], - } - - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [c_char; 108] - } - - pub struct utsname { - pub sysname: [::c_char; 257], - pub nodename: [::c_char; 257], - pub release: [::c_char; 257], - pub version: [::c_char; 257], - pub machine: [::c_char; 257], - } - - pub struct fd_set { - #[cfg(target_pointer_width = "64")] - fds_bits: [i64; FD_SETSIZE / 64], - #[cfg(target_pointer_width = "32")] - fds_bits: [i32; FD_SETSIZE / 32], - } - - pub struct sockaddr_storage { - pub ss_family: ::sa_family_t, - __ss_pad1: [u8; 6], - __ss_align: i64, - __ss_pad2: [u8; 240], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub si_pad: ::c_int, - pub si_addr: *mut ::c_void, - __pad: [u8; 232], - } - - pub struct sockaddr_dl { - pub sdl_family: ::c_ushort, - pub sdl_index: ::c_ushort, - pub sdl_type: ::c_uchar, - pub sdl_nlen: ::c_uchar, - pub sdl_alen: ::c_uchar, - pub sdl_slen: ::c_uchar, - pub sdl_data: [::c_char; 244], - } - - pub struct sigevent { - pub sigev_notify: ::c_int, - pub sigev_signo: ::c_int, - pub sigev_value: ::sigval, - pub ss_sp: *mut ::c_void, - pub sigev_notify_attributes: *const ::pthread_attr_t, - __sigev_pad2: ::c_int, - } - - pub union door_desc_t__d_data { - pub d_desc: door_desc_t__d_data__d_desc, - d_resv: [::c_int; 5], /* Check out /usr/include/sys/door.h */ - } - - pub struct door_desc_t { - pub d_attributes: door_attr_t, - pub d_data: door_desc_t__d_data, - } - - pub struct door_arg_t { - pub data_ptr: *const ::c_char, - pub data_size: ::size_t, - pub desc_ptr: *const door_desc_t, - pub dec_num: ::c_uint, - pub rbuf: *const ::c_char, - pub rsize: ::size_t, - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for utmpx { - fn eq(&self, other: &utmpx) -> bool { - self.ut_type == other.ut_type - && self.ut_pid == other.ut_pid - && self.ut_user == other.ut_user - && self.ut_line == other.ut_line - && self.ut_id == other.ut_id - && self.ut_exit == other.ut_exit - && self.ut_session == other.ut_session - && self.ut_tv == other.ut_tv - && self.ut_syslen == other.ut_syslen - && self.ut_pad == other.ut_pad - && self - .ut_host - .iter() - .zip(other.ut_host.iter()) - .all(|(a,b)| a == b) - } - } - - impl Eq for utmpx {} - - impl ::fmt::Debug for utmpx { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utmpx") - .field("ut_user", &self.ut_user) - .field("ut_id", &self.ut_id) - .field("ut_line", &self.ut_line) - .field("ut_pid", &self.ut_pid) - .field("ut_type", &self.ut_type) - .field("ut_exit", &self.ut_exit) - .field("ut_tv", &self.ut_tv) - .field("ut_session", &self.ut_session) - .field("ut_pad", &self.ut_pad) - .field("ut_syslen", &self.ut_syslen) - .field("ut_host", &self.ut_host) - .finish() - } - } - - impl ::hash::Hash for utmpx { - fn hash(&self, state: &mut H) { - self.ut_user.hash(state); - self.ut_type.hash(state); - self.ut_pid.hash(state); - self.ut_line.hash(state); - self.ut_id.hash(state); - self.ut_host.hash(state); - self.ut_exit.hash(state); - self.ut_session.hash(state); - self.ut_tv.hash(state); - self.ut_syslen.hash(state); - self.ut_pad.hash(state); - } - } - - impl PartialEq for epoll_event { - fn eq(&self, other: &epoll_event) -> bool { - self.events == other.events - && self.u64 == other.u64 - } - } - impl Eq for epoll_event {} - impl ::fmt::Debug for epoll_event { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - let events = self.events; - let u64 = self.u64; - f.debug_struct("epoll_event") - .field("events", &events) - .field("u64", &u64) - .finish() - } - } - impl ::hash::Hash for epoll_event { - fn hash(&self, state: &mut H) { - let events = self.events; - let u64 = self.u64; - events.hash(state); - u64.hash(state); - } - } - - impl PartialEq for sockaddr_un { - fn eq(&self, other: &sockaddr_un) -> bool { - self.sun_family == other.sun_family - && self - .sun_path - .iter() - .zip(other.sun_path.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for sockaddr_un {} - impl ::fmt::Debug for sockaddr_un { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_un") - .field("sun_family", &self.sun_family) - // FIXME: .field("sun_path", &self.sun_path) - .finish() - } - } - impl ::hash::Hash for sockaddr_un { - fn hash(&self, state: &mut H) { - self.sun_family.hash(state); - self.sun_path.hash(state); - } - } - - impl PartialEq for utsname { - fn eq(&self, other: &utsname) -> bool { - self.sysname - .iter() - .zip(other.sysname.iter()) - .all(|(a, b)| a == b) - && self - .nodename - .iter() - .zip(other.nodename.iter()) - .all(|(a, b)| a == b) - && self - .release - .iter() - .zip(other.release.iter()) - .all(|(a, b)| a == b) - && self - .version - .iter() - .zip(other.version.iter()) - .all(|(a, b)| a == b) - && self - .machine - .iter() - .zip(other.machine.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for utsname {} - impl ::fmt::Debug for utsname { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("utsname") - // FIXME: .field("sysname", &self.sysname) - // FIXME: .field("nodename", &self.nodename) - // FIXME: .field("release", &self.release) - // FIXME: .field("version", &self.version) - // FIXME: .field("machine", &self.machine) - .finish() - } - } - impl ::hash::Hash for utsname { - fn hash(&self, state: &mut H) { - self.sysname.hash(state); - self.nodename.hash(state); - self.release.hash(state); - self.version.hash(state); - self.machine.hash(state); - } - } - - impl PartialEq for fd_set { - fn eq(&self, other: &fd_set) -> bool { - self.fds_bits - .iter() - .zip(other.fds_bits.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for fd_set {} - impl ::fmt::Debug for fd_set { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("fd_set") - // FIXME: .field("fds_bits", &self.fds_bits) - .finish() - } - } - impl ::hash::Hash for fd_set { - fn hash(&self, state: &mut H) { - self.fds_bits.hash(state); - } - } - - impl PartialEq for sockaddr_storage { - fn eq(&self, other: &sockaddr_storage) -> bool { - self.ss_family == other.ss_family - && self.__ss_pad1 == other.__ss_pad1 - && self.__ss_align == other.__ss_align - && self - .__ss_pad2 - .iter() - .zip(other.__ss_pad2.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for sockaddr_storage {} - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_family", &self.ss_family) - .field("__ss_pad1", &self.__ss_pad1) - .field("__ss_align", &self.__ss_align) - // FIXME: .field("__ss_pad2", &self.__ss_pad2) - .finish() - } - } - impl ::hash::Hash for sockaddr_storage { - fn hash(&self, state: &mut H) { - self.ss_family.hash(state); - self.__ss_pad1.hash(state); - self.__ss_align.hash(state); - self.__ss_pad2.hash(state); - } - } - - impl PartialEq for siginfo_t { - fn eq(&self, other: &siginfo_t) -> bool { - self.si_signo == other.si_signo - && self.si_code == other.si_code - && self.si_errno == other.si_errno - && self.si_addr == other.si_addr - && self - .__pad - .iter() - .zip(other.__pad.iter()) - .all(|(a, b)| a == b) - } - } - impl Eq for siginfo_t {} - impl ::fmt::Debug for siginfo_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("siginfo_t") - .field("si_signo", &self.si_signo) - .field("si_code", &self.si_code) - .field("si_errno", &self.si_errno) - .field("si_addr", &self.si_addr) - // FIXME: .field("__pad", &self.__pad) - .finish() - } - } - impl ::hash::Hash for siginfo_t { - fn hash(&self, state: &mut H) { - self.si_signo.hash(state); - self.si_code.hash(state); - self.si_errno.hash(state); - self.si_addr.hash(state); - self.__pad.hash(state); - } - } - - impl PartialEq for sockaddr_dl { - fn eq(&self, other: &sockaddr_dl) -> bool { - self.sdl_family == other.sdl_family - && self.sdl_index == other.sdl_index - && self.sdl_type == other.sdl_type - && self.sdl_nlen == other.sdl_nlen - && self.sdl_alen == other.sdl_alen - && self.sdl_slen == other.sdl_slen - && self - .sdl_data - .iter() - .zip(other.sdl_data.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for sockaddr_dl {} - impl ::fmt::Debug for sockaddr_dl { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_dl") - .field("sdl_family", &self.sdl_family) - .field("sdl_index", &self.sdl_index) - .field("sdl_type", &self.sdl_type) - .field("sdl_nlen", &self.sdl_nlen) - .field("sdl_alen", &self.sdl_alen) - .field("sdl_slen", &self.sdl_slen) - // FIXME: .field("sdl_data", &self.sdl_data) - .finish() - } - } - impl ::hash::Hash for sockaddr_dl { - fn hash(&self, state: &mut H) { - self.sdl_family.hash(state); - self.sdl_index.hash(state); - self.sdl_type.hash(state); - self.sdl_nlen.hash(state); - self.sdl_alen.hash(state); - self.sdl_slen.hash(state); - self.sdl_data.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_notify == other.sigev_notify - && self.sigev_signo == other.sigev_signo - && self.sigev_value == other.sigev_value - && self.ss_sp == other.ss_sp - && self.sigev_notify_attributes - == other.sigev_notify_attributes - } - } - impl Eq for sigevent {} - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_notify", &self.sigev_notify) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_value", &self.sigev_value) - .field("ss_sp", &self.ss_sp) - .field("sigev_notify_attributes", - &self.sigev_notify_attributes) - .finish() - } - } - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_notify.hash(state); - self.sigev_signo.hash(state); - self.sigev_value.hash(state); - self.ss_sp.hash(state); - self.sigev_notify_attributes.hash(state); - } - } - - } -} - -pub const LC_CTYPE: ::c_int = 0; -pub const LC_NUMERIC: ::c_int = 1; -pub const LC_TIME: ::c_int = 2; -pub const LC_COLLATE: ::c_int = 3; -pub const LC_MONETARY: ::c_int = 4; -pub const LC_MESSAGES: ::c_int = 5; -pub const LC_ALL: ::c_int = 6; -pub const LC_CTYPE_MASK: ::c_int = (1 << LC_CTYPE); -pub const LC_NUMERIC_MASK: ::c_int = (1 << LC_NUMERIC); -pub const LC_TIME_MASK: ::c_int = (1 << LC_TIME); -pub const LC_COLLATE_MASK: ::c_int = (1 << LC_COLLATE); -pub const LC_MONETARY_MASK: ::c_int = (1 << LC_MONETARY); -pub const LC_MESSAGES_MASK: ::c_int = (1 << LC_MESSAGES); -pub const LC_ALL_MASK: ::c_int = LC_CTYPE_MASK - | LC_NUMERIC_MASK - | LC_TIME_MASK - | LC_COLLATE_MASK - | LC_MONETARY_MASK - | LC_MESSAGES_MASK; - -pub const DAY_1: ::nl_item = 1; -pub const DAY_2: ::nl_item = 2; -pub const DAY_3: ::nl_item = 3; -pub const DAY_4: ::nl_item = 4; -pub const DAY_5: ::nl_item = 5; -pub const DAY_6: ::nl_item = 6; -pub const DAY_7: ::nl_item = 7; - -pub const ABDAY_1: ::nl_item = 8; -pub const ABDAY_2: ::nl_item = 9; -pub const ABDAY_3: ::nl_item = 10; -pub const ABDAY_4: ::nl_item = 11; -pub const ABDAY_5: ::nl_item = 12; -pub const ABDAY_6: ::nl_item = 13; -pub const ABDAY_7: ::nl_item = 14; - -pub const MON_1: ::nl_item = 15; -pub const MON_2: ::nl_item = 16; -pub const MON_3: ::nl_item = 17; -pub const MON_4: ::nl_item = 18; -pub const MON_5: ::nl_item = 19; -pub const MON_6: ::nl_item = 20; -pub const MON_7: ::nl_item = 21; -pub const MON_8: ::nl_item = 22; -pub const MON_9: ::nl_item = 23; -pub const MON_10: ::nl_item = 24; -pub const MON_11: ::nl_item = 25; -pub const MON_12: ::nl_item = 26; - -pub const ABMON_1: ::nl_item = 27; -pub const ABMON_2: ::nl_item = 28; -pub const ABMON_3: ::nl_item = 29; -pub const ABMON_4: ::nl_item = 30; -pub const ABMON_5: ::nl_item = 31; -pub const ABMON_6: ::nl_item = 32; -pub const ABMON_7: ::nl_item = 33; -pub const ABMON_8: ::nl_item = 34; -pub const ABMON_9: ::nl_item = 35; -pub const ABMON_10: ::nl_item = 36; -pub const ABMON_11: ::nl_item = 37; -pub const ABMON_12: ::nl_item = 38; - -pub const RADIXCHAR: ::nl_item = 39; -pub const THOUSEP: ::nl_item = 40; -pub const YESSTR: ::nl_item = 41; -pub const NOSTR: ::nl_item = 42; -pub const CRNCYSTR: ::nl_item = 43; - -pub const D_T_FMT: ::nl_item = 44; -pub const D_FMT: ::nl_item = 45; -pub const T_FMT: ::nl_item = 46; -pub const AM_STR: ::nl_item = 47; -pub const PM_STR: ::nl_item = 48; - -pub const CODESET: ::nl_item = 49; -pub const T_FMT_AMPM: ::nl_item = 50; -pub const ERA: ::nl_item = 51; -pub const ERA_D_FMT: ::nl_item = 52; -pub const ERA_D_T_FMT: ::nl_item = 53; -pub const ERA_T_FMT: ::nl_item = 54; -pub const ALT_DIGITS: ::nl_item = 55; -pub const YESEXPR: ::nl_item = 56; -pub const NOEXPR: ::nl_item = 57; -pub const _DATE_FMT: ::nl_item = 58; -pub const MAXSTRMSG: ::nl_item = 58; - -pub const PATH_MAX: ::c_int = 1024; - -pub const SA_ONSTACK: ::c_int = 0x00000001; -pub const SA_RESETHAND: ::c_int = 0x00000002; -pub const SA_RESTART: ::c_int = 0x00000004; -pub const SA_SIGINFO: ::c_int = 0x00000008; -pub const SA_NODEFER: ::c_int = 0x00000010; -pub const SA_NOCLDWAIT: ::c_int = 0x00010000; -pub const SA_NOCLDSTOP: ::c_int = 0x00020000; - -pub const SS_ONSTACK: ::c_int = 1; -pub const SS_DISABLE: ::c_int = 2; - -pub const FIOCLEX: ::c_int = 0x20006601; -pub const FIONCLEX: ::c_int = 0x20006602; -pub const FIONREAD: ::c_int = 0x4004667f; -pub const FIONBIO: ::c_int = 0x8004667e; -pub const FIOASYNC: ::c_int = 0x8004667d; -pub const FIOSETOWN: ::c_int = 0x8004667c; -pub const FIOGETOWN: ::c_int = 0x4004667b; - -pub const SIGCHLD: ::c_int = 18; -pub const SIGBUS: ::c_int = 10; -pub const SIGINFO: ::c_int = 41; -pub const SIG_BLOCK: ::c_int = 1; -pub const SIG_UNBLOCK: ::c_int = 2; -pub const SIG_SETMASK: ::c_int = 3; - -pub const SIGEV_NONE: ::c_int = 1; -pub const SIGEV_SIGNAL: ::c_int = 2; -pub const SIGEV_THREAD: ::c_int = 3; - -pub const IPV6_UNICAST_HOPS: ::c_int = 0x5; -pub const IPV6_MULTICAST_IF: ::c_int = 0x6; -pub const IPV6_MULTICAST_HOPS: ::c_int = 0x7; -pub const IPV6_MULTICAST_LOOP: ::c_int = 0x8; -pub const IPV6_V6ONLY: ::c_int = 0x27; - -cfg_if! { - if #[cfg(target_pointer_width = "64")] { - pub const FD_SETSIZE: usize = 65536; - } else { - pub const FD_SETSIZE: usize = 1024; - } -} - -pub const ST_RDONLY: ::c_ulong = 1; -pub const ST_NOSUID: ::c_ulong = 2; - -pub const NI_MAXHOST: ::socklen_t = 1025; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const RAND_MAX: ::c_int = 32767; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 4; -pub const _IOLBF: ::c_int = 64; -pub const BUFSIZ: ::c_uint = 1024; -pub const FOPEN_MAX: ::c_uint = 20; -pub const FILENAME_MAX: ::c_uint = 1024; -pub const L_tmpnam: ::c_uint = 25; -pub const TMP_MAX: ::c_uint = 17576; - -pub const O_RDONLY: ::c_int = 0; -pub const O_WRONLY: ::c_int = 1; -pub const O_RDWR: ::c_int = 2; -pub const O_NDELAY: ::c_int = 0x04; -pub const O_APPEND: ::c_int = 8; -pub const O_DSYNC: ::c_int = 0x40; -pub const O_CREAT: ::c_int = 256; -pub const O_EXCL: ::c_int = 1024; -pub const O_NOCTTY: ::c_int = 2048; -pub const O_TRUNC: ::c_int = 512; -pub const O_NOFOLLOW: ::c_int = 0x200000; -pub const O_SEARCH: ::c_int = 0x200000; -pub const O_EXEC: ::c_int = 0x400000; -pub const O_CLOEXEC: ::c_int = 0x800000; -pub const O_ACCMODE: ::c_int = 0x600003; -pub const S_IFIFO: mode_t = 4096; -pub const S_IFCHR: mode_t = 8192; -pub const S_IFBLK: mode_t = 24576; -pub const S_IFDIR: mode_t = 16384; -pub const S_IFREG: mode_t = 32768; -pub const S_IFLNK: mode_t = 40960; -pub const S_IFSOCK: mode_t = 49152; -pub const S_IFMT: mode_t = 61440; -pub const S_IEXEC: mode_t = 64; -pub const S_IWRITE: mode_t = 128; -pub const S_IREAD: mode_t = 256; -pub const S_IRWXU: mode_t = 448; -pub const S_IXUSR: mode_t = 64; -pub const S_IWUSR: mode_t = 128; -pub const S_IRUSR: mode_t = 256; -pub const S_IRWXG: mode_t = 56; -pub const S_IXGRP: mode_t = 8; -pub const S_IWGRP: mode_t = 16; -pub const S_IRGRP: mode_t = 32; -pub const S_IRWXO: mode_t = 7; -pub const S_IXOTH: mode_t = 1; -pub const S_IWOTH: mode_t = 2; -pub const S_IROTH: mode_t = 4; -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; -pub const F_DUPFD_CLOEXEC: ::c_int = 37; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; -pub const F_GETLK: ::c_int = 14; -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGABRT: ::c_int = 6; -pub const SIGEMT: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSEGV: ::c_int = 11; -pub const SIGSYS: ::c_int = 12; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; -pub const SIGUSR1: ::c_int = 16; -pub const SIGUSR2: ::c_int = 17; -pub const SIGPWR: ::c_int = 19; -pub const SIGWINCH: ::c_int = 20; -pub const SIGURG: ::c_int = 21; -pub const SIGPOLL: ::c_int = 22; -pub const SIGIO: ::c_int = SIGPOLL; -pub const SIGSTOP: ::c_int = 23; -pub const SIGTSTP: ::c_int = 24; -pub const SIGCONT: ::c_int = 25; -pub const SIGTTIN: ::c_int = 26; -pub const SIGTTOU: ::c_int = 27; -pub const SIGVTALRM: ::c_int = 28; -pub const SIGPROF: ::c_int = 29; -pub const SIGXCPU: ::c_int = 30; -pub const SIGXFSZ: ::c_int = 31; - -pub const WNOHANG: ::c_int = 0x40; -pub const WUNTRACED: ::c_int = 0x04; - -pub const WEXITED: ::c_int = 0x01; -pub const WTRAPPED: ::c_int = 0x02; -pub const WSTOPPED: ::c_int = WUNTRACED; -pub const WCONTINUED: ::c_int = 0x08; -pub const WNOWAIT: ::c_int = 0x80; - -pub const AT_FDCWD: ::c_int = 0xffd19553; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x1000; - -pub const P_PID: idtype_t = 0; -pub const P_PPID: idtype_t = 1; -pub const P_PGID: idtype_t = 2; -pub const P_SID: idtype_t = 3; -pub const P_CID: idtype_t = 4; -pub const P_UID: idtype_t = 5; -pub const P_GID: idtype_t = 6; -pub const P_ALL: idtype_t = 7; -pub const P_LWPID: idtype_t = 8; -pub const P_TASKID: idtype_t = 9; -pub const P_PROJID: idtype_t = 10; -pub const P_POOLID: idtype_t = 11; -pub const P_ZONEID: idtype_t = 12; -pub const P_CTID: idtype_t = 13; -pub const P_CPUID: idtype_t = 14; -pub const P_PSETID: idtype_t = 15; - -pub const UTIME_OMIT: c_long = -2; -pub const UTIME_NOW: c_long = -1; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_READ: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_EXEC: ::c_int = 4; - -pub const MAP_FILE: ::c_int = 0; -pub const MAP_SHARED: ::c_int = 0x0001; -pub const MAP_PRIVATE: ::c_int = 0x0002; -pub const MAP_FIXED: ::c_int = 0x0010; -pub const MAP_NORESERVE: ::c_int = 0x40; -pub const MAP_ANON: ::c_int = 0x0100; -pub const MAP_ANONYMOUS: ::c_int = 0x0100; -pub const MAP_RENAME: ::c_int = 0x20; -pub const MAP_ALIGN: ::c_int = 0x200; -pub const MAP_TEXT: ::c_int = 0x400; -pub const MAP_INITDATA: ::c_int = 0x800; -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const MS_SYNC: ::c_int = 0x0004; -pub const MS_ASYNC: ::c_int = 0x0001; -pub const MS_INVALIDATE: ::c_int = 0x0002; -pub const MS_INVALCURPROC: ::c_int = 0x0008; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EAGAIN: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const ENOTBLK: ::c_int = 15; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const ENOMSG: ::c_int = 35; -pub const EIDRM: ::c_int = 36; -pub const ECHRNG: ::c_int = 37; -pub const EL2NSYNC: ::c_int = 38; -pub const EL3HLT: ::c_int = 39; -pub const EL3RST: ::c_int = 40; -pub const ELNRNG: ::c_int = 41; -pub const EUNATCH: ::c_int = 42; -pub const ENOCSI: ::c_int = 43; -pub const EL2HLT: ::c_int = 44; -pub const EDEADLK: ::c_int = 45; -pub const ENOLCK: ::c_int = 46; -pub const ECANCELED: ::c_int = 47; -pub const ENOTSUP: ::c_int = 48; -pub const EDQUOT: ::c_int = 49; -pub const EBADE: ::c_int = 50; -pub const EBADR: ::c_int = 51; -pub const EXFULL: ::c_int = 52; -pub const ENOANO: ::c_int = 53; -pub const EBADRQC: ::c_int = 54; -pub const EBADSLT: ::c_int = 55; -pub const EDEADLOCK: ::c_int = 56; -pub const EBFONT: ::c_int = 57; -pub const EOWNERDEAD: ::c_int = 58; -pub const ENOTRECOVERABLE: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const ELOCKUNMAPPED: ::c_int = 72; -pub const ENOTACTIVE: ::c_int = 73; -pub const EMULTIHOP: ::c_int = 74; -pub const EADI: ::c_int = 75; -pub const EBADMSG: ::c_int = 77; -pub const ENAMETOOLONG: ::c_int = 78; -pub const EOVERFLOW: ::c_int = 79; -pub const ENOTUNIQ: ::c_int = 80; -pub const EBADFD: ::c_int = 81; -pub const EREMCHG: ::c_int = 82; -pub const ELIBACC: ::c_int = 83; -pub const ELIBBAD: ::c_int = 84; -pub const ELIBSCN: ::c_int = 85; -pub const ELIBMAX: ::c_int = 86; -pub const ELIBEXEC: ::c_int = 87; -pub const EILSEQ: ::c_int = 88; -pub const ENOSYS: ::c_int = 89; -pub const ELOOP: ::c_int = 90; -pub const ERESTART: ::c_int = 91; -pub const ESTRPIPE: ::c_int = 92; -pub const ENOTEMPTY: ::c_int = 93; -pub const EUSERS: ::c_int = 94; -pub const ENOTSOCK: ::c_int = 95; -pub const EDESTADDRREQ: ::c_int = 96; -pub const EMSGSIZE: ::c_int = 97; -pub const EPROTOTYPE: ::c_int = 98; -pub const ENOPROTOOPT: ::c_int = 99; -pub const EPROTONOSUPPORT: ::c_int = 120; -pub const ESOCKTNOSUPPORT: ::c_int = 121; -pub const EOPNOTSUPP: ::c_int = 122; -pub const EPFNOSUPPORT: ::c_int = 123; -pub const EAFNOSUPPORT: ::c_int = 124; -pub const EADDRINUSE: ::c_int = 125; -pub const EADDRNOTAVAIL: ::c_int = 126; -pub const ENETDOWN: ::c_int = 127; -pub const ENETUNREACH: ::c_int = 128; -pub const ENETRESET: ::c_int = 129; -pub const ECONNABORTED: ::c_int = 130; -pub const ECONNRESET: ::c_int = 131; -pub const ENOBUFS: ::c_int = 132; -pub const EISCONN: ::c_int = 133; -pub const ENOTCONN: ::c_int = 134; -pub const ESHUTDOWN: ::c_int = 143; -pub const ETOOMANYREFS: ::c_int = 144; -pub const ETIMEDOUT: ::c_int = 145; -pub const ECONNREFUSED: ::c_int = 146; -pub const EHOSTDOWN: ::c_int = 147; -pub const EHOSTUNREACH: ::c_int = 148; -pub const EWOULDBLOCK: ::c_int = EAGAIN; -pub const EALREADY: ::c_int = 149; -pub const EINPROGRESS: ::c_int = 150; -pub const ESTALE: ::c_int = 151; - -pub const EAI_AGAIN: ::c_int = 2; -pub const EAI_BADFLAGS: ::c_int = 3; -pub const EAI_FAIL: ::c_int = 4; -pub const EAI_FAMILY: ::c_int = 5; -pub const EAI_MEMORY: ::c_int = 6; -pub const EAI_NODATA: ::c_int = 7; -pub const EAI_NONAME: ::c_int = 8; -pub const EAI_SERVICE: ::c_int = 9; -pub const EAI_SOCKTYPE: ::c_int = 10; -pub const EAI_SYSTEM: ::c_int = 11; -pub const EAI_OVERFLOW: ::c_int = 12; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; - -pub const SIGTRAP: ::c_int = 5; - -pub const GLOB_APPEND: ::c_int = 32; -pub const GLOB_DOOFFS: ::c_int = 16; -pub const GLOB_ERR: ::c_int = 1; -pub const GLOB_MARK: ::c_int = 2; -pub const GLOB_NOCHECK: ::c_int = 8; -pub const GLOB_NOSORT: ::c_int = 4; -pub const GLOB_NOESCAPE: ::c_int = 64; - -pub const GLOB_NOSPACE: ::c_int = -2; -pub const GLOB_ABORTED: ::c_int = -1; -pub const GLOB_NOMATCH: ::c_int = -3; - -pub const POLLIN: ::c_short = 0x1; -pub const POLLPRI: ::c_short = 0x2; -pub const POLLOUT: ::c_short = 0x4; -pub const POLLERR: ::c_short = 0x8; -pub const POLLHUP: ::c_short = 0x10; -pub const POLLNVAL: ::c_short = 0x20; -pub const POLLNORM: ::c_short = 0x0040; -pub const POLLRDNORM: ::c_short = 0x0040; -pub const POLLWRNORM: ::c_short = 0x4; /* POLLOUT */ -pub const POLLRDBAND: ::c_short = 0x0080; -pub const POLLWRBAND: ::c_short = 0x0100; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; -pub const POSIX_MADV_DONTNEED: ::c_int = 4; - -pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0; -pub const PTHREAD_CREATE_DETACHED: ::c_int = 0x40; -pub const PTHREAD_PROCESS_SHARED: ::c_int = 1; -pub const PTHREAD_PROCESS_PRIVATE: ::c_ushort = 0; -pub const PTHREAD_STACK_MIN: ::size_t = 4096; - -pub const SIGSTKSZ: ::size_t = 8192; - -// https://illumos.org/man/3c/clock_gettime -// https://github.com/illumos/illumos-gate/ -// blob/HEAD/usr/src/lib/libc/amd64/sys/__clock_gettime.s -// clock_gettime(3c) doesn't seem to accept anything other than CLOCK_REALTIME -// or __CLOCK_REALTIME0 -// -// https://github.com/illumos/illumos-gate/ -// blob/HEAD/usr/src/uts/common/sys/time_impl.h -// Confusing! CLOCK_HIGHRES==CLOCK_MONOTONIC==4 -// __CLOCK_REALTIME0==0 is an obsoleted version of CLOCK_REALTIME==3 -pub const CLOCK_REALTIME: ::clockid_t = 3; -pub const CLOCK_MONOTONIC: ::clockid_t = 4; -pub const TIMER_RELTIME: ::c_int = 0; -pub const TIMER_ABSTIME: ::c_int = 1; - -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_NOFILE: ::c_int = 5; -pub const RLIMIT_VMEM: ::c_int = 6; -pub const RLIMIT_AS: ::c_int = RLIMIT_VMEM; - -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] -pub const RLIM_NLIMITS: rlim_t = 7; -pub const RLIM_INFINITY: rlim_t = 0x7fffffff; - -pub const RUSAGE_SELF: ::c_int = 0; -pub const RUSAGE_CHILDREN: ::c_int = -1; - -pub const MADV_NORMAL: ::c_int = 0; -pub const MADV_RANDOM: ::c_int = 1; -pub const MADV_SEQUENTIAL: ::c_int = 2; -pub const MADV_WILLNEED: ::c_int = 3; -pub const MADV_DONTNEED: ::c_int = 4; -pub const MADV_FREE: ::c_int = 5; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_UNIX: ::c_int = 1; -pub const AF_LOCAL: ::c_int = 0; -pub const AF_FILE: ::c_int = 0; -pub const AF_INET: ::c_int = 2; -pub const AF_IMPLINK: ::c_int = 3; -pub const AF_PUP: ::c_int = 4; -pub const AF_CHAOS: ::c_int = 5; -pub const AF_NS: ::c_int = 6; -pub const AF_NBS: ::c_int = 7; -pub const AF_ECMA: ::c_int = 8; -pub const AF_DATAKIT: ::c_int = 9; -pub const AF_CCITT: ::c_int = 10; -pub const AF_SNA: ::c_int = 11; -pub const AF_DECnet: ::c_int = 12; -pub const AF_DLI: ::c_int = 13; -pub const AF_LAT: ::c_int = 14; -pub const AF_HYLINK: ::c_int = 15; -pub const AF_APPLETALK: ::c_int = 16; -pub const AF_NIT: ::c_int = 17; -pub const AF_802: ::c_int = 18; -pub const AF_OSI: ::c_int = 19; -pub const AF_X25: ::c_int = 20; -pub const AF_OSINET: ::c_int = 21; -pub const AF_GOSIP: ::c_int = 22; -pub const AF_IPX: ::c_int = 23; -pub const AF_ROUTE: ::c_int = 24; -pub const AF_LINK: ::c_int = 25; -pub const AF_INET6: ::c_int = 26; -pub const AF_KEY: ::c_int = 27; -pub const AF_NCA: ::c_int = 28; -pub const AF_POLICY: ::c_int = 29; -pub const AF_INET_OFFLOAD: ::c_int = 30; -pub const AF_TRILL: ::c_int = 31; -pub const AF_PACKET: ::c_int = 32; -pub const AF_LX_NETLINK: ::c_int = 33; - -pub const SOCK_DGRAM: ::c_int = 1; -pub const SOCK_STREAM: ::c_int = 2; -pub const SOCK_RAW: ::c_int = 4; -pub const SOCK_RDM: ::c_int = 5; -pub const SOCK_SEQPACKET: ::c_int = 6; -pub const IP_MULTICAST_IF: ::c_int = 16; -pub const IP_MULTICAST_TTL: ::c_int = 17; -pub const IP_MULTICAST_LOOP: ::c_int = 18; -pub const IP_TTL: ::c_int = 4; -pub const IP_HDRINCL: ::c_int = 2; -pub const IP_ADD_MEMBERSHIP: ::c_int = 19; -pub const IP_DROP_MEMBERSHIP: ::c_int = 20; -pub const IPV6_JOIN_GROUP: ::c_int = 9; -pub const IPV6_LEAVE_GROUP: ::c_int = 10; - -pub const TCP_NODELAY: ::c_int = 1; -pub const TCP_KEEPIDLE: ::c_int = 34; -pub const SOL_SOCKET: ::c_int = 0xffff; -pub const SO_DEBUG: ::c_int = 0x01; -pub const SO_ACCEPTCONN: ::c_int = 0x0002; -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_USELOOPBACK: ::c_int = 0x0040; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_TIMESTAMP: ::c_int = 0x1013; - -pub const SCM_RIGHTS: ::c_int = 0x1010; -pub const SCM_UCRED: ::c_int = 0x1012; -pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP; - -pub const MSG_OOB: ::c_int = 0x1; -pub const MSG_PEEK: ::c_int = 0x2; -pub const MSG_DONTROUTE: ::c_int = 0x4; -pub const MSG_EOR: ::c_int = 0x8; -pub const MSG_CTRUNC: ::c_int = 0x10; -pub const MSG_TRUNC: ::c_int = 0x20; -pub const MSG_WAITALL: ::c_int = 0x40; -pub const MSG_DONTWAIT: ::c_int = 0x80; -pub const MSG_NOTIFICATION: ::c_int = 0x100; -pub const MSG_NOSIGNAL: ::c_int = 0x200; -pub const MSG_DUPCTRL: ::c_int = 0x800; -pub const MSG_XPG4_2: ::c_int = 0x8000; -pub const MSG_MAXIOVLEN: ::c_int = 16; - -// https://docs.oracle.com/cd/E23824_01/html/821-1475/if-7p.html -pub const IFF_UP: ::c_int = 0x0000000001; // Address is up -pub const IFF_BROADCAST: ::c_int = 0x0000000002; // Broadcast address valid -pub const IFF_DEBUG: ::c_int = 0x0000000004; // Turn on debugging -pub const IFF_LOOPBACK: ::c_int = 0x0000000008; // Loopback net -pub const IFF_POINTOPOINT: ::c_int = 0x0000000010; // Interface is p-to-p -pub const IFF_NOTRAILERS: ::c_int = 0x0000000020; // Avoid use of trailers -pub const IFF_RUNNING: ::c_int = 0x0000000040; // Resources allocated -pub const IFF_NOARP: ::c_int = 0x0000000080; // No address res. protocol -pub const IFF_PROMISC: ::c_int = 0x0000000100; // Receive all packets -pub const IFF_ALLMULTI: ::c_int = 0x0000000200; // Receive all multicast pkts -pub const IFF_INTELLIGENT: ::c_int = 0x0000000400; // Protocol code on board -pub const IFF_MULTICAST: ::c_int = 0x0000000800; // Supports multicast - -// Multicast using broadcst. add. -pub const IFF_MULTI_BCAST: ::c_int = 0x0000001000; -pub const IFF_UNNUMBERED: ::c_int = 0x0000002000; // Non-unique address -pub const IFF_DHCPRUNNING: ::c_int = 0x0000004000; // DHCP controls interface -pub const IFF_PRIVATE: ::c_int = 0x0000008000; // Do not advertise -pub const IFF_NOXMIT: ::c_int = 0x0000010000; // Do not transmit pkts - -// No address - just on-link subnet -pub const IFF_NOLOCAL: ::c_int = 0x0000020000; -pub const IFF_DEPRECATED: ::c_int = 0x0000040000; // Address is deprecated -pub const IFF_ADDRCONF: ::c_int = 0x0000080000; // Addr. from stateless addrconf -pub const IFF_ROUTER: ::c_int = 0x0000100000; // Router on interface -pub const IFF_NONUD: ::c_int = 0x0000200000; // No NUD on interface -pub const IFF_ANYCAST: ::c_int = 0x0000400000; // Anycast address -pub const IFF_NORTEXCH: ::c_int = 0x0000800000; // Don't xchange rout. info -pub const IFF_IPV4: ::c_int = 0x0001000000; // IPv4 interface -pub const IFF_IPV6: ::c_int = 0x0002000000; // IPv6 interface -pub const IFF_NOFAILOVER: ::c_int = 0x0008000000; // in.mpathd test address -pub const IFF_FAILED: ::c_int = 0x0010000000; // Interface has failed -pub const IFF_STANDBY: ::c_int = 0x0020000000; // Interface is a hot-spare -pub const IFF_INACTIVE: ::c_int = 0x0040000000; // Functioning but not used -pub const IFF_OFFLINE: ::c_int = 0x0080000000; // Interface is offline - // If CoS marking is supported -pub const IFF_COS_ENABLED: ::c_longlong = 0x0200000000; -pub const IFF_PREFERRED: ::c_longlong = 0x0400000000; // Prefer as source addr. -pub const IFF_TEMPORARY: ::c_longlong = 0x0800000000; // RFC3041 -pub const IFF_FIXEDMTU: ::c_longlong = 0x1000000000; // MTU set with SIOCSLIFMTU -pub const IFF_VIRTUAL: ::c_longlong = 0x2000000000; // Cannot send/receive pkts -pub const IFF_DUPLICATE: ::c_longlong = 0x4000000000; // Local address in use -pub const IFF_IPMP: ::c_longlong = 0x8000000000; // IPMP IP interface - -// sys/ipc.h: -pub const IPC_ALLOC: ::c_int = 0x8000; -pub const IPC_CREAT: ::c_int = 0x200; -pub const IPC_EXCL: ::c_int = 0x400; -pub const IPC_NOWAIT: ::c_int = 0x800; -pub const IPC_PRIVATE: key_t = 0; -pub const IPC_RMID: ::c_int = 10; -pub const IPC_SET: ::c_int = 11; -pub const IPC_SEAT: ::c_int = 12; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const LOCK_SH: ::c_int = 1; -pub const LOCK_EX: ::c_int = 2; -pub const LOCK_NB: ::c_int = 4; -pub const LOCK_UN: ::c_int = 8; - -pub const F_RDLCK: ::c_short = 1; -pub const F_WRLCK: ::c_short = 2; -pub const F_UNLCK: ::c_short = 3; - -pub const O_SYNC: ::c_int = 16; -pub const O_NONBLOCK: ::c_int = 128; - -pub const IPPROTO_RAW: ::c_int = 255; - -pub const _PC_LINK_MAX: ::c_int = 1; -pub const _PC_MAX_CANON: ::c_int = 2; -pub const _PC_MAX_INPUT: ::c_int = 3; -pub const _PC_NAME_MAX: ::c_int = 4; -pub const _PC_PATH_MAX: ::c_int = 5; -pub const _PC_PIPE_BUF: ::c_int = 6; -pub const _PC_NO_TRUNC: ::c_int = 7; -pub const _PC_VDISABLE: ::c_int = 8; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 9; -pub const _PC_ASYNC_IO: ::c_int = 10; -pub const _PC_PRIO_IO: ::c_int = 11; -pub const _PC_SYNC_IO: ::c_int = 12; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 13; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 14; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 15; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 16; -pub const _PC_REC_XFER_ALIGN: ::c_int = 17; -pub const _PC_SYMLINK_MAX: ::c_int = 18; -pub const _PC_2_SYMLINKS: ::c_int = 19; -pub const _PC_ACL_ENABLED: ::c_int = 20; -pub const _PC_MIN_HOLE_SIZE: ::c_int = 21; -pub const _PC_CASE_BEHAVIOR: ::c_int = 22; -pub const _PC_SATTR_ENABLED: ::c_int = 23; -pub const _PC_SATTR_EXISTS: ::c_int = 24; -pub const _PC_ACCESS_FILTERING: ::c_int = 25; -pub const _PC_TIMESTAMP_RESOLUTION: ::c_int = 26; -pub const _PC_FILESIZEBITS: ::c_int = 67; -pub const _PC_XATTR_ENABLED: ::c_int = 100; -pub const _PC_LAST: ::c_int = 101; -pub const _PC_XATTR_EXISTS: ::c_int = 101; - -pub const _SC_ARG_MAX: ::c_int = 1; -pub const _SC_CHILD_MAX: ::c_int = 2; -pub const _SC_CLK_TCK: ::c_int = 3; -pub const _SC_NGROUPS_MAX: ::c_int = 4; -pub const _SC_OPEN_MAX: ::c_int = 5; -pub const _SC_JOB_CONTROL: ::c_int = 6; -pub const _SC_SAVED_IDS: ::c_int = 7; -pub const _SC_VERSION: ::c_int = 8; -pub const _SC_PASS_MAX: ::c_int = 9; -pub const _SC_LOGNAME_MAX: ::c_int = 10; -pub const _SC_PAGESIZE: ::c_int = 11; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_XOPEN_VERSION: ::c_int = 12; -pub const _SC_NPROCESSORS_CONF: ::c_int = 14; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 15; -pub const _SC_STREAM_MAX: ::c_int = 16; -pub const _SC_TZNAME_MAX: ::c_int = 17; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 18; -pub const _SC_AIO_MAX: ::c_int = 19; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 20; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 21; -pub const _SC_DELAYTIMER_MAX: ::c_int = 22; -pub const _SC_FSYNC: ::c_int = 23; -pub const _SC_MAPPED_FILES: ::c_int = 24; -pub const _SC_MEMLOCK: ::c_int = 25; -pub const _SC_MEMLOCK_RANGE: ::c_int = 26; -pub const _SC_MEMORY_PROTECTION: ::c_int = 27; -pub const _SC_MESSAGE_PASSING: ::c_int = 28; -pub const _SC_MQ_OPEN_MAX: ::c_int = 29; -pub const _SC_MQ_PRIO_MAX: ::c_int = 30; -pub const _SC_PRIORITIZED_IO: ::c_int = 31; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 32; -pub const _SC_REALTIME_SIGNALS: ::c_int = 33; -pub const _SC_RTSIG_MAX: ::c_int = 34; -pub const _SC_SEMAPHORES: ::c_int = 35; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 36; -pub const _SC_SEM_VALUE_MAX: ::c_int = 37; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 38; -pub const _SC_SIGQUEUE_MAX: ::c_int = 39; -pub const _SC_SIGRT_MIN: ::c_int = 40; -pub const _SC_SIGRT_MAX: ::c_int = 41; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 42; -pub const _SC_TIMERS: ::c_int = 43; -pub const _SC_TIMER_MAX: ::c_int = 44; -pub const _SC_2_C_BIND: ::c_int = 45; -pub const _SC_2_C_DEV: ::c_int = 46; -pub const _SC_2_C_VERSION: ::c_int = 47; -pub const _SC_2_FORT_DEV: ::c_int = 48; -pub const _SC_2_FORT_RUN: ::c_int = 49; -pub const _SC_2_LOCALEDEF: ::c_int = 50; -pub const _SC_2_SW_DEV: ::c_int = 51; -pub const _SC_2_UPE: ::c_int = 52; -pub const _SC_2_VERSION: ::c_int = 53; -pub const _SC_BC_BASE_MAX: ::c_int = 54; -pub const _SC_BC_DIM_MAX: ::c_int = 55; -pub const _SC_BC_SCALE_MAX: ::c_int = 56; -pub const _SC_BC_STRING_MAX: ::c_int = 57; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 58; -pub const _SC_EXPR_NEST_MAX: ::c_int = 59; -pub const _SC_LINE_MAX: ::c_int = 60; -pub const _SC_RE_DUP_MAX: ::c_int = 61; -pub const _SC_XOPEN_CRYPT: ::c_int = 62; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 63; -pub const _SC_XOPEN_SHM: ::c_int = 64; -pub const _SC_2_CHAR_TERM: ::c_int = 66; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 67; -pub const _SC_ATEXIT_MAX: ::c_int = 76; -pub const _SC_IOV_MAX: ::c_int = 77; -pub const _SC_XOPEN_UNIX: ::c_int = 78; -pub const _SC_T_IOV_MAX: ::c_int = 79; -pub const _SC_PHYS_PAGES: ::c_int = 500; -pub const _SC_AVPHYS_PAGES: ::c_int = 501; -pub const _SC_COHER_BLKSZ: ::c_int = 503; -pub const _SC_SPLIT_CACHE: ::c_int = 504; -pub const _SC_ICACHE_SZ: ::c_int = 505; -pub const _SC_DCACHE_SZ: ::c_int = 506; -pub const _SC_ICACHE_LINESZ: ::c_int = 507; -pub const _SC_DCACHE_LINESZ: ::c_int = 508; -pub const _SC_ICACHE_BLKSZ: ::c_int = 509; -pub const _SC_DCACHE_BLKSZ: ::c_int = 510; -pub const _SC_DCACHE_TBLKSZ: ::c_int = 511; -pub const _SC_ICACHE_ASSOC: ::c_int = 512; -pub const _SC_DCACHE_ASSOC: ::c_int = 513; -pub const _SC_MAXPID: ::c_int = 514; -pub const _SC_STACK_PROT: ::c_int = 515; -pub const _SC_NPROCESSORS_MAX: ::c_int = 516; -pub const _SC_CPUID_MAX: ::c_int = 517; -pub const _SC_EPHID_MAX: ::c_int = 518; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 568; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 569; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 570; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 571; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 572; -pub const _SC_THREAD_STACK_MIN: ::c_int = 573; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 574; -pub const _SC_TTY_NAME_MAX: ::c_int = 575; -pub const _SC_THREADS: ::c_int = 576; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 577; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 578; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 579; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 580; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 581; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 582; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 583; -pub const _SC_XOPEN_LEGACY: ::c_int = 717; -pub const _SC_XOPEN_REALTIME: ::c_int = 718; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 719; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = 720; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = 721; -pub const _SC_XBS5_LP64_OFF64: ::c_int = 722; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = 723; -pub const _SC_2_PBS: ::c_int = 724; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 725; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 726; -pub const _SC_2_PBS_LOCATE: ::c_int = 728; -pub const _SC_2_PBS_MESSAGE: ::c_int = 729; -pub const _SC_2_PBS_TRACK: ::c_int = 730; -pub const _SC_ADVISORY_INFO: ::c_int = 731; -pub const _SC_BARRIERS: ::c_int = 732; -pub const _SC_CLOCK_SELECTION: ::c_int = 733; -pub const _SC_CPUTIME: ::c_int = 734; -pub const _SC_HOST_NAME_MAX: ::c_int = 735; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 736; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 737; -pub const _SC_REGEXP: ::c_int = 738; -pub const _SC_SHELL: ::c_int = 739; -pub const _SC_SPAWN: ::c_int = 740; -pub const _SC_SPIN_LOCKS: ::c_int = 741; -pub const _SC_SPORADIC_SERVER: ::c_int = 742; -pub const _SC_SS_REPL_MAX: ::c_int = 743; -pub const _SC_SYMLOOP_MAX: ::c_int = 744; -pub const _SC_THREAD_CPUTIME: ::c_int = 745; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 746; -pub const _SC_TIMEOUTS: ::c_int = 747; -pub const _SC_TRACE: ::c_int = 748; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 749; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 750; -pub const _SC_TRACE_INHERIT: ::c_int = 751; -pub const _SC_TRACE_LOG: ::c_int = 752; -pub const _SC_TRACE_NAME_MAX: ::c_int = 753; -pub const _SC_TRACE_SYS_MAX: ::c_int = 754; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 755; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 756; -pub const _SC_V6_ILP32_OFF32: ::c_int = 757; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 758; -pub const _SC_V6_LP64_OFF64: ::c_int = 759; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 760; -pub const _SC_XOPEN_STREAMS: ::c_int = 761; -pub const _SC_IPV6: ::c_int = 762; -pub const _SC_RAW_SOCKETS: ::c_int = 763; - -pub const _MUTEX_MAGIC: u16 = 0x4d58; // MX -pub const _COND_MAGIC: u16 = 0x4356; // CV -pub const _RWL_MAGIC: u16 = 0x5257; // RW - -pub const NCCS: usize = 19; - -pub const LOG_CRON: ::c_int = 15 << 3; - -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - __pthread_mutex_flag1: 0, - __pthread_mutex_flag2: 0, - __pthread_mutex_ceiling: 0, - __pthread_mutex_type: PTHREAD_PROCESS_PRIVATE, - __pthread_mutex_magic: _MUTEX_MAGIC, - __pthread_mutex_lock: 0, - __pthread_mutex_data: 0, -}; -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - __pthread_cond_flag: [0; 4], - __pthread_cond_type: PTHREAD_PROCESS_PRIVATE, - __pthread_cond_magic: _COND_MAGIC, - __pthread_cond_data: 0, -}; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - __pthread_rwlock_readers: 0, - __pthread_rwlock_type: PTHREAD_PROCESS_PRIVATE, - __pthread_rwlock_magic: _RWL_MAGIC, - __pthread_rwlock_mutex: PTHREAD_MUTEX_INITIALIZER, - __pthread_rwlock_readercv: PTHREAD_COND_INITIALIZER, - __pthread_rwlock_writercv: PTHREAD_COND_INITIALIZER, -}; -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 4; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; - -pub const RTLD_NEXT: *mut ::c_void = -1isize as *mut ::c_void; -pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void; -pub const RTLD_SELF: *mut ::c_void = -3isize as *mut ::c_void; -pub const RTLD_PROBE: *mut ::c_void = -4isize as *mut ::c_void; - -pub const RTLD_LAZY: ::c_int = 0x1; -pub const RTLD_NOW: ::c_int = 0x2; -pub const RTLD_NOLOAD: ::c_int = 0x4; -pub const RTLD_GLOBAL: ::c_int = 0x100; -pub const RTLD_LOCAL: ::c_int = 0x0; -pub const RTLD_PARENT: ::c_int = 0x200; -pub const RTLD_GROUP: ::c_int = 0x400; -pub const RTLD_WORLD: ::c_int = 0x800; -pub const RTLD_NODELETE: ::c_int = 0x1000; -pub const RTLD_FIRST: ::c_int = 0x2000; -pub const RTLD_CONFGEN: ::c_int = 0x10000; - -pub const PORT_SOURCE_AIO: ::c_int = 1; -pub const PORT_SOURCE_TIMER: ::c_int = 2; -pub const PORT_SOURCE_USER: ::c_int = 3; -pub const PORT_SOURCE_FD: ::c_int = 4; -pub const PORT_SOURCE_ALERT: ::c_int = 5; -pub const PORT_SOURCE_MQ: ::c_int = 6; -pub const PORT_SOURCE_FILE: ::c_int = 7; -pub const PORT_SOURCE_POSTWAIT: ::c_int = 8; -pub const PORT_SOURCE_SIGNAL: ::c_int = 9; - -pub const NONROOT_USR: ::c_short = 2; -pub const _UTX_USERSIZE: usize = 32; -pub const _UTX_LINESIZE: usize = 32; -pub const _UTX_PADSIZE: usize = 5; -pub const _UTX_IDSIZE: usize = 4; -pub const _UTX_HOSTSIZE: usize = 257; -pub const EMPTY: ::c_short = 0; -pub const RUN_LVL: ::c_short = 1; -pub const BOOT_TIME: ::c_short = 2; -pub const OLD_TIME: ::c_short = 3; -pub const NEW_TIME: ::c_short = 4; -pub const INIT_PROCESS: ::c_short = 5; -pub const LOGIN_PROCESS: ::c_short = 6; -pub const USER_PROCESS: ::c_short = 7; -pub const DEAD_PROCESS: ::c_short = 8; -pub const ACCOUNTING: ::c_short = 9; -pub const DOWN_TIME: ::c_short = 10; - -const _TIOC: ::c_int = ('T' as i32) << 8; -const tIOC: ::c_int = ('t' as i32) << 8; -pub const TCGETA: ::c_int = (_TIOC | 1); -pub const TCSETA: ::c_int = (_TIOC | 2); -pub const TCSETAW: ::c_int = (_TIOC | 3); -pub const TCSETAF: ::c_int = (_TIOC | 4); -pub const TCSBRK: ::c_int = (_TIOC | 5); -pub const TCXONC: ::c_int = (_TIOC | 6); -pub const TCFLSH: ::c_int = (_TIOC | 7); -pub const TCDSET: ::c_int = (_TIOC | 32); -pub const TCGETS: ::c_int = (_TIOC | 13); -pub const TCSETS: ::c_int = (_TIOC | 14); -pub const TCSANOW: ::c_int = (_TIOC | 14); -pub const TCSETSW: ::c_int = (_TIOC | 15); -pub const TCSADRAIN: ::c_int = (_TIOC | 15); -pub const TCSETSF: ::c_int = (_TIOC | 16); -pub const TCSAFLUSH: ::c_int = (_TIOC | 16); -pub const TCIFLUSH: ::c_int = 0; -pub const TCOFLUSH: ::c_int = 1; -pub const TCIOFLUSH: ::c_int = 2; -pub const TCOOFF: ::c_int = 0; -pub const TCOON: ::c_int = 1; -pub const TCIOFF: ::c_int = 2; -pub const TCION: ::c_int = 3; -pub const TIOC: ::c_int = _TIOC; -pub const TIOCKBON: ::c_int = (_TIOC | 8); -pub const TIOCKBOF: ::c_int = (_TIOC | 9); -pub const TIOCGWINSZ: ::c_int = (_TIOC | 104); -pub const TIOCSWINSZ: ::c_int = (_TIOC | 103); -pub const TIOCGSOFTCAR: ::c_int = (_TIOC | 105); -pub const TIOCSSOFTCAR: ::c_int = (_TIOC | 106); -pub const TIOCSETLD: ::c_int = (_TIOC | 123); -pub const TIOCGETLD: ::c_int = (_TIOC | 124); -pub const TIOCGPPS: ::c_int = (_TIOC | 125); -pub const TIOCSPPS: ::c_int = (_TIOC | 126); -pub const TIOCGPPSEV: ::c_int = (_TIOC | 127); -pub const TIOCGETD: ::c_int = (tIOC | 0); -pub const TIOCSETD: ::c_int = (tIOC | 1); -pub const TIOCHPCL: ::c_int = (tIOC | 2); -pub const TIOCGETP: ::c_int = (tIOC | 8); -pub const TIOCSETP: ::c_int = (tIOC | 9); -pub const TIOCSETN: ::c_int = (tIOC | 10); -pub const TIOCEXCL: ::c_int = (tIOC | 13); -pub const TIOCNXCL: ::c_int = (tIOC | 14); -pub const TIOCFLUSH: ::c_int = (tIOC | 16); -pub const TIOCSETC: ::c_int = (tIOC | 17); -pub const TIOCGETC: ::c_int = (tIOC | 18); -pub const TIOCLBIS: ::c_int = (tIOC | 127); -pub const TIOCLBIC: ::c_int = (tIOC | 126); -pub const TIOCLSET: ::c_int = (tIOC | 125); -pub const TIOCLGET: ::c_int = (tIOC | 124); -pub const TIOCSBRK: ::c_int = (tIOC | 123); -pub const TIOCCBRK: ::c_int = (tIOC | 122); -pub const TIOCSDTR: ::c_int = (tIOC | 121); -pub const TIOCCDTR: ::c_int = (tIOC | 120); -pub const TIOCSLTC: ::c_int = (tIOC | 117); -pub const TIOCGLTC: ::c_int = (tIOC | 116); -pub const TIOCOUTQ: ::c_int = (tIOC | 115); -pub const TIOCNOTTY: ::c_int = (tIOC | 113); -pub const TIOCSCTTY: ::c_int = (tIOC | 132); -pub const TIOCSTOP: ::c_int = (tIOC | 111); -pub const TIOCSTART: ::c_int = (tIOC | 110); -pub const TIOCSILOOP: ::c_int = (tIOC | 109); -pub const TIOCCILOOP: ::c_int = (tIOC | 108); -pub const TIOCGPGRP: ::c_int = (tIOC | 20); -pub const TIOCSPGRP: ::c_int = (tIOC | 21); -pub const TIOCGSID: ::c_int = (tIOC | 22); -pub const TIOCSTI: ::c_int = (tIOC | 23); -pub const TIOCMSET: ::c_int = (tIOC | 26); -pub const TIOCMBIS: ::c_int = (tIOC | 27); -pub const TIOCMBIC: ::c_int = (tIOC | 28); -pub const TIOCMGET: ::c_int = (tIOC | 29); -pub const TIOCREMOTE: ::c_int = (tIOC | 30); -pub const TIOCSIGNAL: ::c_int = (tIOC | 31); - -pub const EPOLLIN: ::c_int = 0x1; -pub const EPOLLPRI: ::c_int = 0x2; -pub const EPOLLOUT: ::c_int = 0x4; -pub const EPOLLRDNORM: ::c_int = 0x40; -pub const EPOLLRDBAND: ::c_int = 0x80; -pub const EPOLLWRNORM: ::c_int = 0x100; -pub const EPOLLWRBAND: ::c_int = 0x200; -pub const EPOLLMSG: ::c_int = 0x400; -pub const EPOLLERR: ::c_int = 0x8; -pub const EPOLLHUP: ::c_int = 0x10; -pub const EPOLLET: ::c_int = 0x80000000; -pub const EPOLLRDHUP: ::c_int = 0x2000; -pub const EPOLLEXCLUSIVE: ::c_int = 0x10000000; -pub const EPOLLONESHOT: ::c_int = 0x40000000; -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; -pub const EPOLL_CTL_ADD: ::c_int = 1; -pub const EPOLL_CTL_MOD: ::c_int = 3; -pub const EPOLL_CTL_DEL: ::c_int = 2; - -/* termios */ -pub const B0: speed_t = 0; -pub const B50: speed_t = 1; -pub const B75: speed_t = 2; -pub const B110: speed_t = 3; -pub const B134: speed_t = 4; -pub const B150: speed_t = 5; -pub const B200: speed_t = 6; -pub const B300: speed_t = 7; -pub const B600: speed_t = 8; -pub const B1200: speed_t = 9; -pub const B1800: speed_t = 10; -pub const B2400: speed_t = 11; -pub const B4800: speed_t = 12; -pub const B9600: speed_t = 13; -pub const B19200: speed_t = 14; -pub const B38400: speed_t = 15; -pub const B57600: speed_t = 16; -pub const B76800: speed_t = 17; -pub const B115200: speed_t = 18; -pub const B153600: speed_t = 19; -pub const B230400: speed_t = 20; -pub const B307200: speed_t = 21; -pub const B460800: speed_t = 22; -pub const B921600: speed_t = 23; -pub const CSTART: ::tcflag_t = 021; -pub const CSTOP: ::tcflag_t = 023; -pub const CSWTCH: ::tcflag_t = 032; -pub const CSIZE: ::tcflag_t = 0o000060; -pub const CS5: ::tcflag_t = 0; -pub const CS6: ::tcflag_t = 0o000020; -pub const CS7: ::tcflag_t = 0o000040; -pub const CS8: ::tcflag_t = 0o000060; -pub const CSTOPB: ::tcflag_t = 0o000100; -pub const ECHO: ::tcflag_t = 0o000010; -pub const ECHOE: ::tcflag_t = 0o000020; -pub const ECHOK: ::tcflag_t = 0o000040; -pub const ECHONL: ::tcflag_t = 0o000100; -pub const ECHOCTL: ::tcflag_t = 0o001000; -pub const ECHOPRT: ::tcflag_t = 0o002000; -pub const ECHOKE: ::tcflag_t = 0o004000; -pub const EXTPROC: ::tcflag_t = 0o200000; -pub const IGNBRK: ::tcflag_t = 0o000001; -pub const BRKINT: ::tcflag_t = 0o000002; -pub const IGNPAR: ::tcflag_t = 0o000004; -pub const PARMRK: ::tcflag_t = 0o000010; -pub const INPCK: ::tcflag_t = 0o000020; -pub const ISTRIP: ::tcflag_t = 0o000040; -pub const INLCR: ::tcflag_t = 0o000100; -pub const IGNCR: ::tcflag_t = 0o000200; -pub const ICRNL: ::tcflag_t = 0o000400; -pub const IXON: ::tcflag_t = 0o002000; -pub const IXOFF: ::tcflag_t = 0o010000; -pub const IXANY: ::tcflag_t = 0o004000; -pub const IMAXBEL: ::tcflag_t = 0o020000; -pub const OPOST: ::tcflag_t = 0o000001; -pub const ONLCR: ::tcflag_t = 0o000004; -pub const OCRNL: ::tcflag_t = 0o000010; -pub const ONOCR: ::tcflag_t = 0o000020; -pub const ONLRET: ::tcflag_t = 0o000040; -pub const CREAD: ::tcflag_t = 0o000200; -pub const PARENB: ::tcflag_t = 0o000400; -pub const PARODD: ::tcflag_t = 0o001000; -pub const HUPCL: ::tcflag_t = 0o002000; -pub const CLOCAL: ::tcflag_t = 0o004000; -pub const CRTSCTS: ::tcflag_t = 0o20000000000; -pub const ISIG: ::tcflag_t = 0o000001; -pub const ICANON: ::tcflag_t = 0o000002; -pub const IEXTEN: ::tcflag_t = 0o100000; -pub const TOSTOP: ::tcflag_t = 0o000400; -pub const FLUSHO: ::tcflag_t = 0o020000; -pub const PENDIN: ::tcflag_t = 0o040000; -pub const NOFLSH: ::tcflag_t = 0o000200; -pub const VINTR: usize = 0; -pub const VQUIT: usize = 1; -pub const VERASE: usize = 2; -pub const VKILL: usize = 3; -pub const VEOF: usize = 4; -pub const VEOL: usize = 5; -pub const VEOL2: usize = 6; -pub const VMIN: usize = 4; -pub const VTIME: usize = 5; -pub const VSWTCH: usize = 7; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VSUSP: usize = 10; -pub const VDSUSP: usize = 11; -pub const VREPRINT: usize = 12; -pub const VDISCARD: usize = 13; -pub const VWERASE: usize = 14; -pub const VLNEXT: usize = 15; -pub const VSTATUS: usize = 16; -pub const VERASE2: usize = 17; - -// 3SOCKET flags -pub const SOCK_CLOEXEC: ::c_int = 0x080000; -pub const SOCK_NONBLOCK: ::c_int = 0x100000; -pub const SOCK_NDELAY: ::c_int = 0x200000; - -f! { - pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); - return - } - - pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 - } - - pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - let fd = fd as usize; - (*set).fds_bits[fd / bits] |= 1 << (fd % bits); - return - } - - pub fn FD_ZERO(set: *mut fd_set) -> () { - for slot in (*set).fds_bits.iter_mut() { - *slot = 0; - } - } - - pub fn WIFEXITED(status: ::c_int) -> bool { - (status & 0xFF) == 0 - } - - pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - (status >> 8) & 0xFF - } - - pub fn WTERMSIG(status: ::c_int) -> ::c_int { - status & 0x7F - } - - pub fn WIFCONTINUED(status: ::c_int) -> bool { - (status & 0xffff) == 0xffff - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - (status & 0xff00) >> 8 - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - ((status & 0xff) > 0) && (status & 0xff00 == 0) - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - ((status & 0xff) == 0x7f) && ((status & 0xff00) != 0) - } - - pub fn WCOREDUMP(status: ::c_int) -> bool { - (status & 0x80) != 0 - } -} - -extern "C" { - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - - pub fn abs(i: ::c_int) -> ::c_int; - pub fn acct(filename: *const ::c_char) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - pub fn labs(i: ::c_long) -> ::c_long; - pub fn rand() -> ::c_int; - pub fn srand(seed: ::c_uint); - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn settimeofday(tp: *const ::timeval, tz: *const ::c_void) -> ::c_int; - pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; - pub fn freeifaddrs(ifa: *mut ::ifaddrs); - - pub fn stack_getbounds(sp: *mut ::stack_t) -> ::c_int; - pub fn mincore( - addr: *const ::c_void, - len: ::size_t, - vec: *mut c_char, - ) -> ::c_int; - pub fn initgroups(name: *const ::c_char, basegid: ::gid_t) -> ::c_int; - pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int; - pub fn ioctl(fildes: ::c_int, request: ::c_int, ...) -> ::c_int; - pub fn mprotect( - addr: *const ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn ___errno() -> *mut ::c_int; - pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_nanosleep( - clk_id: ::clockid_t, - flags: ::c_int, - rqtp: *const ::timespec, - rmtp: *mut ::timespec, - ) -> ::c_int; - pub fn clock_settime( - clk_id: ::clockid_t, - tp: *const ::timespec, - ) -> ::c_int; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::socklen_t, - serv: *mut ::c_char, - sevlen: ::socklen_t, - flags: ::c_int, - ) -> ::c_int; - pub fn setpwent(); - pub fn endpwent(); - pub fn getpwent() -> *mut passwd; - pub fn fdatasync(fd: ::c_int) -> ::c_int; - pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) - -> *mut ::c_char; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn freelocale(loc: ::locale_t); - pub fn newlocale( - mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t, - ) -> ::locale_t; - pub fn uselocale(loc: ::locale_t) -> ::locale_t; - pub fn getprogname() -> *const ::c_char; - pub fn setprogname(name: *const ::c_char); - pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int; - pub fn getpriority(which: ::c_int, who: ::c_int) -> ::c_int; - pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) - -> ::c_int; - - pub fn mknodat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - dev: dev_t, - ) -> ::c_int; - pub fn mkfifoat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - pub fn sethostname(name: *const ::c_char, len: ::c_int) -> ::c_int; - pub fn if_nameindex() -> *mut if_nameindex; - pub fn if_freenameindex(ptr: *mut if_nameindex); - pub fn pthread_create( - native: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - pub fn pthread_condattr_getclock( - attr: *const pthread_condattr_t, - clock_id: *mut clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_setclock( - attr: *mut pthread_condattr_t, - clock_id: ::clockid_t, - ) -> ::c_int; - pub fn sem_timedwait( - sem: *mut sem_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn waitid( - idtype: idtype_t, - id: id_t, - infop: *mut ::siginfo_t, - options: ::c_int, - ) -> ::c_int; - - pub fn glob( - pattern: *const ::c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut ::glob_t, - ) -> ::c_int; - - pub fn globfree(pglob: *mut ::glob_t); - - pub fn posix_madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn shmat( - shmid: ::c_int, - shmaddr: *const ::c_void, - shmflg: ::c_int, - ) -> *mut ::c_void; - - pub fn shmctl( - shmid: ::c_int, - cmd: ::c_int, - buf: *mut ::shmid_ds, - ) -> ::c_int; - - pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int; - - pub fn shmget(key: key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int; - - pub fn shm_open( - name: *const ::c_char, - oflag: ::c_int, - mode: ::mode_t, - ) -> ::c_int; - pub fn shm_unlink(name: *const ::c_char) -> ::c_int; - - pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); - - pub fn telldir(dirp: *mut ::DIR) -> ::c_long; - pub fn madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn msync( - addr: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::c_int; - - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; - - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int; - pub fn futimesat( - fd: ::c_int, - path: *const ::c_char, - times: *const ::timeval, - ) -> ::c_int; - pub fn futimens(dirfd: ::c_int, times: *const ::timespec) -> ::c_int; - pub fn utimensat( - dirfd: ::c_int, - path: *const ::c_char, - times: *const ::timespec, - flag: ::c_int, - ) -> ::c_int; - pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; - - #[cfg_attr(target_os = "illumos", link_name = "__xnet_bind")] - pub fn bind( - socket: ::c_int, - address: *const ::sockaddr, - address_len: ::socklen_t, - ) -> ::c_int; - - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - - #[cfg_attr(target_os = "illumos", link_name = "__xnet_sendmsg")] - pub fn sendmsg( - fd: ::c_int, - msg: *const ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - #[cfg_attr(target_os = "illumos", link_name = "__xnet_recvmsg")] - pub fn recvmsg( - fd: ::c_int, - msg: *mut ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - - pub fn mq_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::mqd_t; - pub fn mq_close(mqd: ::mqd_t) -> ::c_int; - pub fn mq_unlink(name: *const ::c_char) -> ::c_int; - pub fn mq_receive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - ) -> ::ssize_t; - pub fn mq_timedreceive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - abs_timeout: *const ::timespec, - ) -> ::ssize_t; - pub fn mq_send( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - ) -> ::c_int; - pub fn mq_timedsend( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - abs_timeout: *const ::timespec, - ) -> ::c_int; - pub fn mq_getattr(mqd: ::mqd_t, attr: *mut ::mq_attr) -> ::c_int; - pub fn mq_setattr( - mqd: ::mqd_t, - newattr: *const ::mq_attr, - oldattr: *mut ::mq_attr, - ) -> ::c_int; - pub fn port_create() -> ::c_int; - pub fn port_associate( - port: ::c_int, - source: ::c_int, - object: ::uintptr_t, - events: ::c_int, - user: *mut ::c_void, - ) -> ::c_int; - pub fn port_dissociate( - port: ::c_int, - source: ::c_int, - object: ::uintptr_t, - ) -> ::c_int; - pub fn port_get( - port: ::c_int, - pe: *mut port_event, - timeout: *mut ::timespec, - ) -> ::c_int; - pub fn port_getn( - port: ::c_int, - pe_list: *mut port_event, - max: ::c_uint, - nget: *mut ::c_uint, - timeout: *mut ::timespec, - ) -> ::c_int; - pub fn fexecve( - fd: ::c_int, - argv: *const *const ::c_char, - envp: *const *const ::c_char, - ) -> ::c_int; - #[cfg_attr( - any(target_os = "solaris", target_os = "illumos"), - link_name = "__posix_getgrgid_r" - )] - pub fn getgrgid_r( - gid: ::gid_t, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; - pub fn sem_close(sem: *mut sem_t) -> ::c_int; - pub fn getdtablesize() -> ::c_int; - - // The epoll functions are actually only present on illumos. However, - // there are things using epoll on illumos (built using the - // x86_64-sun-solaris target) which would break until the illumos target is - // present in rustc. - pub fn epoll_pwait( - epfd: ::c_int, - events: *mut ::epoll_event, - maxevents: ::c_int, - timeout: ::c_int, - sigmask: *const ::sigset_t, - ) -> ::c_int; - - pub fn epoll_create(size: ::c_int) -> ::c_int; - pub fn epoll_create1(flags: ::c_int) -> ::c_int; - pub fn epoll_wait( - epfd: ::c_int, - events: *mut ::epoll_event, - maxevents: ::c_int, - timeout: ::c_int, - ) -> ::c_int; - pub fn epoll_ctl( - epfd: ::c_int, - op: ::c_int, - fd: ::c_int, - event: *mut ::epoll_event, - ) -> ::c_int; - - #[cfg_attr( - any(target_os = "solaris", target_os = "illumos"), - link_name = "__posix_getgrnam_r" - )] - pub fn getgrnam_r( - name: *const ::c_char, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - pub fn pthread_sigmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; - pub fn getgrnam(name: *const ::c_char) -> *mut ::group; - pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; - pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - #[cfg_attr( - any(target_os = "solaris", target_os = "illumos"), - link_name = "__posix_getpwnam_r" - )] - pub fn getpwnam_r( - name: *const ::c_char, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - any(target_os = "solaris", target_os = "illumos"), - link_name = "__posix_getpwuid_r" - )] - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - any(target_os = "solaris", target_os = "illumos"), - link_name = "__posix_getpwent_r" - )] - pub fn getpwent_r( - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - any(target_os = "solaris", target_os = "illumos"), - link_name = "__posix_getgrent_r" - )] - pub fn getgrent_r( - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - any(target_os = "solaris", target_os = "illumos"), - link_name = "__posix_sigwait" - )] - pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn getgrgid(gid: ::gid_t) -> *mut ::group; - pub fn setgrent(); - pub fn endgrent(); - pub fn getgrent() -> *mut ::group; - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - - pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int; - pub fn uname(buf: *mut ::utsname) -> ::c_int; - pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int; - pub fn door_call(d: ::c_int, params: *const door_arg_t) -> ::c_int; - pub fn door_return( - data_ptr: *const ::c_char, - data_size: ::size_t, - desc_ptr: *const door_desc_t, - num_desc: ::c_uint, - ); - pub fn door_create( - server_procedure: extern "C" fn( - cookie: *const ::c_void, - argp: *const ::c_char, - arg_size: ::size_t, - dp: *const door_desc_t, - n_desc: ::c_uint, - ), - cookie: *const ::c_void, - attributes: door_attr_t, - ) -> ::c_int; - pub fn fattach(fildes: ::c_int, path: *const ::c_char) -> ::c_int; - - pub fn makeutx(ux: *const utmpx) -> *mut utmpx; - pub fn modutx(ux: *const utmpx) -> *mut utmpx; - pub fn updwtmpx(file: *const ::c_char, ut: *const utmpx) -> ::c_int; - pub fn utmpxname(file: *const ::c_char) -> ::c_int; - pub fn getutxent() -> *mut utmpx; - pub fn getutxid(ut: *const utmpx) -> *mut utmpx; - pub fn getutxline(ut: *const utmpx) -> *mut utmpx; - pub fn pututxline(ut: *const utmpx) -> *mut utmpx; - pub fn setutxent(); - pub fn endutxent(); - - pub fn endutent(); - pub fn getutent() -> *mut utmp; - pub fn getutid(u: *const utmp) -> *mut utmp; - pub fn getutline(u: *const utmp) -> *mut utmp; - pub fn pututline(u: *const utmp) -> *mut utmp; - pub fn setutent(); - pub fn utmpname(file: *const ::c_char) -> ::c_int; - - pub fn getutmp(ux: *const utmpx, u: *mut utmp); - pub fn getutmpx(u: *const utmp, ux: *mut utmpx); - pub fn updwtmp(file: *const ::c_char, u: *mut utmp); -} - -mod compat; -pub use self::compat::*; diff --git a/libc/src/unix/uclibc/align.rs b/libc/src/unix/uclibc/align.rs deleted file mode 100644 index 76b524d..0000000 --- a/libc/src/unix/uclibc/align.rs +++ /dev/null @@ -1,66 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - #[cfg_attr(any(target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64"), - repr(align(4)))] - #[cfg_attr(not(any(target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64")), - repr(align(8)))] - pub struct pthread_mutexattr_t { - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[repr(align(4))] - pub struct pthread_condattr_t { - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - - s_no_extra_traits! { - #[repr(align(8))] - #[allow(missing_debug_implementations)] - pub struct pthread_cond_t { - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))), - repr(align(8)))] - #[allow(missing_debug_implementations)] - pub struct pthread_mutex_t { - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))), - repr(align(8)))] - #[allow(missing_debug_implementations)] - pub struct pthread_rwlock_t { - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - } - }; -} diff --git a/libc/src/unix/uclibc/arm/align.rs b/libc/src/unix/uclibc/arm/align.rs deleted file mode 100644 index 4a0e074..0000000 --- a/libc/src/unix/uclibc/arm/align.rs +++ /dev/null @@ -1,13 +0,0 @@ -s! { - // FIXME this is actually a union - #[cfg_attr(target_pointer_width = "32", - repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", - repr(align(8)))] - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - } -} diff --git a/libc/src/unix/uclibc/arm/mod.rs b/libc/src/unix/uclibc/arm/mod.rs deleted file mode 100644 index 613a11f..0000000 --- a/libc/src/unix/uclibc/arm/mod.rs +++ /dev/null @@ -1,1049 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = ::c_uint; -pub type c_long = i32; -pub type c_ulong = u32; -pub type time_t = ::c_long; - -pub type clock_t = ::c_long; -pub type fsblkcnt_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; -pub type ino_t = ::c_ulong; -pub type off_t = ::c_long; -pub type pthread_t = ::c_ulong; -pub type rlim_t = ::c_ulong; -pub type suseconds_t = ::c_long; - -pub type nlink_t = ::c_uint; -pub type blksize_t = ::c_long; -pub type blkcnt_t = ::c_long; - -s! { - pub struct cmsghdr { - pub cmsg_len: ::size_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - pub msg_flags: ::c_int, - } - - pub struct pthread_attr_t { - __size: [::c_long; 9], - } - - pub struct stat { - pub st_dev: ::c_ulonglong, - pub __pad1: ::c_ushort, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulonglong, - pub __pad2: ::c_ushort, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_ulong, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_ulong, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_ulong, - pub __unused4: ::c_ulong, - pub __unused5: ::c_ulong, - } - - pub struct stat64 - { - pub st_dev: ::c_ulonglong, - pub __pad1: ::c_uint, - pub __st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulonglong, - pub __pad2: ::c_uint, - pub st_size: ::off64_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_ulong, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_ulong, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_ulong, - pub st_ino: ::ino64_t, - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - } - - pub struct statfs { - pub f_type: ::c_int, - pub f_bsize: ::c_int, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - - pub f_fsid: ::fsid_t, - pub f_namelen: ::c_int, - pub f_frsize: ::c_int, - pub f_spare: [::c_int; 5], - } - - pub struct sigset_t { - __val: [::c_ulong; 2], - } - - pub struct sigaction { - pub sa_sigaction: ::sighandler_t, - // uClibc defines sa_flags as `unsigned long int`, - // but nix crate expects `int` - pub sa_flags: ::c_int, - pub sa_restorer: *mut ::c_void, - pub sa_mask: sigset_t, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - pub c_ispeed: ::speed_t, - pub c_ospeed: ::speed_t, - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_errno: ::c_int, - pub si_code: ::c_int, - pub _pad: [::c_int; 29], - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t, - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_ushort, - pub __pad1: ::c_ushort, - pub __seq: ::c_ushort, - pub __pad2: ::c_ushort, - pub __unused1: ::c_ulong, - pub __unused2: ::c_ulong, - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - pub __unused1: ::c_ulong, - pub msg_rtime: ::time_t, - pub __unused2: ::c_ulong, - pub msg_ctime: ::time_t, - pub __unused3: ::c_ulong, - pub __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - pub __unused4: ::c_ulong, - pub __unused5: ::c_ulong, - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub __unused1: ::c_ulong, - pub shm_dtime: ::time_t, - pub __unused2: ::c_ulong, - pub shm_ctime: ::time_t, - pub __unused3: ::c_ulong, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - pub __unused4: ::c_ulong, - pub __unused5: ::c_ulong, - } - - pub struct ucred { - pub pid: ::pid_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - } - -} - -pub const O_CLOEXEC: ::c_int = 0o2000000; -pub const RLIM_INFINITY: rlim_t = !0; -pub const __SIZEOF_PTHREAD_ATTR_T: usize = 36; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_COND_COMPAT_T: usize = 12; -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; -pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20; -pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4; -pub const NCCS: usize = 32; - -// I wasn't able to find those constants -// in uclibc build environment for armv7 -pub const AIO_ALLDONE: ::c_int = 2; // from linux/mod.rs -pub const AIO_CANCELED: ::c_int = 0; // from linux/mod.rs -pub const AIO_NOTCANCELED: ::c_int = 1; // from linux/mod.rs -pub const CLONE_NEWCGROUP: ::c_int = 0x02000000; // from linux/mod.rs -pub const EPOLLEXCLUSIVE: ::c_int = 0x10000000; // from linux/mod.rs -pub const EPOLLWAKEUP: ::c_int = 0x20000000; // from linux/other/mod.rs -pub const EXTPROC: ::tcflag_t = 0o200000; // from asm-generic/termbits.h -pub const F_GETPIPE_SZ: ::c_int = 1032; // from linux_like/mod.rs -pub const F_SETPIPE_SZ: ::c_int = 1031; // from linux_like/mod.rs -pub const LIO_NOP: ::c_int = 2; // from linux/mod.rs -pub const LIO_NOWAIT: ::c_int = 1; // from linux/mod.rs -pub const LIO_READ: ::c_int = 0; // from linux/mod.rs -pub const LIO_WAIT: ::c_int = 0; // from linux/mod.rs -pub const LIO_WRITE: ::c_int = 1; // from linux/mod.rs -pub const MAP_HUGETLB: ::c_int = 0x040000; // from linux/other/mod.rs -pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY; -pub const RB_KEXEC: ::c_int = 0x45584543u32 as i32; // from linux/mod.rs -pub const RB_SW_SUSPEND: ::c_int = 0xd000fce2u32 as i32; // from linux/mod.rs -pub const SO_BUSY_POLL: ::c_int = 46; // from src/unix/linux_like/mod.rs -pub const SO_PEEK_OFF: ::c_int = 42; // from src/unix/linux_like/mod.rs -pub const SO_REUSEPORT: ::c_int = 15; // from src/unix/linux_like/mod.rs -pub const SOL_NETLINK: ::c_int = 270; // from src/unix/linux_like/mod.rs -pub const _POSIX_VDISABLE: ::cc_t = 0; // from linux/mod.rs -pub const AT_EMPTY_PATH: ::c_int = 0x1000; // from linux_like/mod.rs - -// autogenerated constants with hand tuned types -pub const AT_NO_AUTOMOUNT: ::c_int = 0x800; -pub const B0: ::speed_t = 0; -pub const B1000000: ::speed_t = 0x1008; -pub const B110: ::speed_t = 0x3; -pub const B115200: ::speed_t = 0x1002; -pub const B1152000: ::speed_t = 0x1009; -pub const B1200: ::speed_t = 0x9; -pub const B134: ::speed_t = 0x4; -pub const B150: ::speed_t = 0x5; -pub const B1500000: ::speed_t = 0x100a; -pub const B1800: ::speed_t = 0xa; -pub const B19200: ::speed_t = 0xe; -pub const B200: ::speed_t = 0x6; -pub const B2000000: ::speed_t = 0x100b; -pub const B230400: ::speed_t = 0x1003; -pub const B2400: ::speed_t = 0xb; -pub const B2500000: ::speed_t = 0x100c; -pub const B300: ::speed_t = 0x7; -pub const B3000000: ::speed_t = 0x100d; -pub const B3500000: ::speed_t = 0x100e; -pub const B38400: ::speed_t = 0xf; -pub const B4000000: ::speed_t = 0x100f; -pub const B460800: ::speed_t = 0x1004; -pub const B4800: ::speed_t = 0xc; -pub const B50: ::speed_t = 0x1; -pub const B500000: ::speed_t = 0x1005; -pub const B57600: ::speed_t = 0x1001; -pub const B576000: ::speed_t = 0x1006; -pub const B600: ::speed_t = 0x8; -pub const B75: ::speed_t = 0x2; -pub const B921600: ::speed_t = 0x1007; -pub const B9600: ::speed_t = 0xd; -pub const BS1: ::c_int = 0x2000; -pub const BSDLY: ::c_int = 0x2000; -pub const CBAUD: ::tcflag_t = 0x100f; -pub const CBAUDEX: ::tcflag_t = 0x1000; -pub const CIBAUD: ::tcflag_t = 0x100f0000; -pub const CLOCAL: ::tcflag_t = 0x800; -pub const CMSPAR: ::tcflag_t = 0x40000000; -pub const CPU_SETSIZE: ::c_int = 0x400; -pub const CR1: ::c_int = 0x200; -pub const CR2: ::c_int = 0x400; -pub const CR3: ::c_int = 0x600; -pub const CRDLY: ::c_int = 0x600; -pub const CREAD: ::tcflag_t = 0x80; -pub const CS6: ::tcflag_t = 0x10; -pub const CS7: ::tcflag_t = 0x20; -pub const CS8: ::tcflag_t = 0x30; -pub const CSIZE: ::tcflag_t = 0x30; -pub const CSTOPB: ::tcflag_t = 0x40; -pub const EADDRINUSE: ::c_int = 0x62; -pub const EADDRNOTAVAIL: ::c_int = 0x63; -pub const EADV: ::c_int = 0x44; -pub const EAFNOSUPPORT: ::c_int = 0x61; -pub const EALREADY: ::c_int = 0x72; -pub const EBADE: ::c_int = 0x34; -pub const EBADFD: ::c_int = 0x4d; -pub const EBADMSG: ::c_int = 0x4a; -pub const EBADR: ::c_int = 0x35; -pub const EBADRQC: ::c_int = 0x38; -pub const EBADSLT: ::c_int = 0x39; -pub const EBFONT: ::c_int = 0x3b; -pub const ECANCELED: ::c_int = 0x7d; -pub const ECHOCTL: ::tcflag_t = 0x200; -pub const ECHOE: ::tcflag_t = 0x10; -pub const ECHOK: ::tcflag_t = 0x20; -pub const ECHOKE: ::tcflag_t = 0x800; -pub const ECHONL: ::tcflag_t = 0x40; -pub const ECHOPRT: ::tcflag_t = 0x400; -pub const ECHRNG: ::c_int = 0x2c; -pub const ECOMM: ::c_int = 0x46; -pub const ECONNABORTED: ::c_int = 0x67; -pub const ECONNREFUSED: ::c_int = 0x6f; -pub const ECONNRESET: ::c_int = 0x68; -pub const EDEADLK: ::c_int = 0x23; -pub const EDESTADDRREQ: ::c_int = 0x59; -pub const EDOTDOT: ::c_int = 0x49; -pub const EDQUOT: ::c_int = 0x7a; -pub const EFD_CLOEXEC: ::c_int = 0x80000; -pub const EFD_NONBLOCK: ::c_int = 0x800; -pub const EHOSTDOWN: ::c_int = 0x70; -pub const EHOSTUNREACH: ::c_int = 0x71; -pub const EHWPOISON: ::c_int = 0x85; -pub const EIDRM: ::c_int = 0x2b; -pub const EILSEQ: ::c_int = 0x54; -pub const EINPROGRESS: ::c_int = 0x73; -pub const EISCONN: ::c_int = 0x6a; -pub const EISNAM: ::c_int = 0x78; -pub const EKEYEXPIRED: ::c_int = 0x7f; -pub const EKEYREJECTED: ::c_int = 0x81; -pub const EKEYREVOKED: ::c_int = 0x80; -pub const EL2HLT: ::c_int = 0x33; -pub const EL2NSYNC: ::c_int = 0x2d; -pub const EL3HLT: ::c_int = 0x2e; -pub const EL3RST: ::c_int = 0x2f; -pub const ELIBACC: ::c_int = 0x4f; -pub const ELIBBAD: ::c_int = 0x50; -pub const ELIBEXEC: ::c_int = 0x53; -pub const ELIBMAX: ::c_int = 0x52; -pub const ELIBSCN: ::c_int = 0x51; -pub const ELNRNG: ::c_int = 0x30; -pub const ELOOP: ::c_int = 0x28; -pub const EMEDIUMTYPE: ::c_int = 0x7c; -pub const EMSGSIZE: ::c_int = 0x5a; -pub const EMULTIHOP: ::c_int = 0x48; -pub const ENAMETOOLONG: ::c_int = 0x24; -pub const ENAVAIL: ::c_int = 0x77; -pub const ENETDOWN: ::c_int = 0x64; -pub const ENETRESET: ::c_int = 0x66; -pub const ENETUNREACH: ::c_int = 0x65; -pub const ENOANO: ::c_int = 0x37; -pub const ENOBUFS: ::c_int = 0x69; -pub const ENOCSI: ::c_int = 0x32; -pub const ENODATA: ::c_int = 0x3d; -pub const ENOKEY: ::c_int = 0x7e; -pub const ENOLCK: ::c_int = 0x25; -pub const ENOLINK: ::c_int = 0x43; -pub const ENOMEDIUM: ::c_int = 0x7b; -pub const ENOMSG: ::c_int = 0x2a; -pub const ENONET: ::c_int = 0x40; -pub const ENOPKG: ::c_int = 0x41; -pub const ENOPROTOOPT: ::c_int = 0x5c; -pub const ENOSR: ::c_int = 0x3f; -pub const ENOSTR: ::c_int = 0x3c; -pub const ENOSYS: ::c_int = 0x26; -pub const ENOTCONN: ::c_int = 0x6b; -pub const ENOTEMPTY: ::c_int = 0x27; -pub const ENOTNAM: ::c_int = 0x76; -pub const ENOTRECOVERABLE: ::c_int = 0x83; -pub const ENOTSOCK: ::c_int = 0x58; -pub const ENOTUNIQ: ::c_int = 0x4c; -pub const EOPNOTSUPP: ::c_int = 0x5f; -pub const EOVERFLOW: ::c_int = 0x4b; -pub const EOWNERDEAD: ::c_int = 0x82; -pub const EPFNOSUPPORT: ::c_int = 0x60; -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; -pub const EPROTO: ::c_int = 0x47; -pub const EPROTONOSUPPORT: ::c_int = 0x5d; -pub const EPROTOTYPE: ::c_int = 0x5b; -pub const EREMCHG: ::c_int = 0x4e; -pub const EREMOTE: ::c_int = 0x42; -pub const EREMOTEIO: ::c_int = 0x79; -pub const ERESTART: ::c_int = 0x55; -pub const ERFKILL: ::c_int = 0x84; -pub const ESHUTDOWN: ::c_int = 0x6c; -pub const ESOCKTNOSUPPORT: ::c_int = 0x5e; -pub const ESRMNT: ::c_int = 0x45; -pub const ESTALE: ::c_int = 0x74; -pub const ESTRPIPE: ::c_int = 0x56; -pub const ETIME: ::c_int = 0x3e; -pub const ETIMEDOUT: ::c_int = 0x6e; -pub const ETOOMANYREFS: ::c_int = 0x6d; -pub const EUCLEAN: ::c_int = 0x75; -pub const EUNATCH: ::c_int = 0x31; -pub const EUSERS: ::c_int = 0x57; -pub const EXFULL: ::c_int = 0x36; -pub const FF1: ::c_int = 0x8000; -pub const FFDLY: ::c_int = 0x8000; -pub const FIONBIO: ::c_ulong = 0x5421; -pub const FIOCLEX: ::c_ulong = 0x5451; -pub const FIONCLEX: ::c_ulong = 0x5450; -pub const FLUSHO: ::tcflag_t = 0x1000; -pub const F_GETLK: ::c_int = 0x5; -pub const F_SETLK: ::c_int = 0x6; -pub const F_SETLKW: ::c_int = 0x7; -pub const HUPCL: ::tcflag_t = 0x400; -pub const ICANON: ::tcflag_t = 0x2; -pub const IEXTEN: ::tcflag_t = 0x8000; -pub const ISIG: ::tcflag_t = 0x1; -pub const IUTF8: ::tcflag_t = 0x4000; -pub const IXOFF: ::tcflag_t = 0x1000; -pub const IXON: ::tcflag_t = 0x400; -pub const MAP_ANON: ::c_int = 0x20; -pub const MAP_ANONYMOUS: ::c_int = 0x20; -pub const MAP_DENYWRITE: ::c_int = 0x800; -pub const MAP_EXECUTABLE: ::c_int = 0x1000; -pub const MAP_GROWSDOWN: ::c_int = 0x100; -pub const MAP_LOCKED: ::c_int = 0x2000; -pub const MAP_NONBLOCK: ::c_int = 0x10000; -pub const MAP_NORESERVE: ::c_int = 0x4000; -pub const MAP_POPULATE: ::c_int = 0x8000; -pub const MAP_STACK: ::c_int = 0x20000; -pub const MS_ACTIVE: u32 = 0x40000000; -pub const MS_DIRSYNC: u32 = 0x80; -pub const MS_I_VERSION: u32 = 0x800000; -pub const MS_KERNMOUNT: u32 = 0x400000; -pub const MS_MOVE: u32 = 0x2000; -pub const MS_POSIXACL: u32 = 0x10000; -pub const MS_PRIVATE: u32 = 0x40000; -pub const MS_REC: u32 = 0x4000; -pub const MS_RELATIME: u32 = 0x200000; -pub const MS_SHARED: u32 = 0x100000; -pub const MS_SILENT: u32 = 0x8000; -pub const MS_SLAVE: u32 = 0x80000; -pub const MS_STRICTATIME: u32 = 0x1000000; -pub const MS_UNBINDABLE: u32 = 0x20000; -pub const NLDLY: ::tcflag_t = 0x100; -pub const NOFLSH: ::tcflag_t = 0x80; -pub const OCRNL: ::c_int = 0x8; -pub const OFDEL: ::c_int = 0x80; -pub const OFILL: ::c_int = 0x40; -pub const OLCUC: ::tcflag_t = 0x2; -pub const ONLCR: ::tcflag_t = 0x4; -pub const ONLRET: ::tcflag_t = 0x20; -pub const ONOCR: ::tcflag_t = 0x10; -pub const O_ACCMODE: ::c_int = 0x3; -pub const O_APPEND: ::c_int = 0x400; -pub const O_CREAT: ::c_int = 0x40; -pub const O_DIRECT: ::c_int = 0x10000; -pub const O_DIRECTORY: ::c_int = 0x4000; -pub const O_DSYNC: ::c_int = 0x1000; -pub const O_EXCL: ::c_int = 0x80; -pub const O_NDELAY: ::c_int = 0x800; -pub const O_NOCTTY: ::c_int = 0x100; -pub const O_NOFOLLOW: ::c_int = 0x8000; -pub const O_NONBLOCK: ::c_int = 0x800; -pub const O_SYNC: ::c_int = 0o10000; -pub const O_TRUNC: ::c_int = 0x200; -pub const PARENB: ::tcflag_t = 0x100; -pub const PARODD: ::tcflag_t = 0x200; -pub const PENDIN: ::tcflag_t = 0x4000; -pub const POLLRDBAND: ::c_short = 0x80; -pub const POLLRDNORM: ::c_short = 0x40; -pub const POLLWRBAND: ::c_short = 0x200; -pub const POLLWRNORM: ::c_short = 0x100; -pub const PTHREAD_STACK_MIN: ::size_t = 16384; -pub const QIF_ALL: u32 = 0x3f; -pub const QIF_BLIMITS: u32 = 0x1; -pub const QIF_BTIME: u32 = 0x10; -pub const QIF_ILIMITS: u32 = 0x4; -pub const QIF_INODES: u32 = 0x8; -pub const QIF_ITIME: u32 = 0x20; -pub const QIF_LIMITS: u32 = 0x5; -pub const QIF_SPACE: u32 = 0x2; -pub const QIF_TIMES: u32 = 0x30; -pub const QIF_USAGE: u32 = 0xa; -pub const SA_NOCLDSTOP: ::c_int = 0x1; -pub const SA_NOCLDWAIT: ::c_int = 0x2; -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_ONSTACK: ::c_int = 0x8000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_SIGINFO: ::c_int = 0x4; -pub const SFD_CLOEXEC: ::c_int = 0x80000; -pub const SFD_NONBLOCK: ::c_int = 0x800; -pub const SIGBUS: ::c_int = 0x7; -pub const SIGCHLD: ::c_int = 0x11; -pub const SIGCONT: ::c_int = 0x12; -pub const SIGIO: ::c_int = 0x1d; -pub const SIGPROF: ::c_int = 0x1b; -pub const SIGPWR: ::c_int = 0x1e; -pub const SIGSTKFLT: ::c_int = 0x10; -pub const SIGSTKSZ: ::size_t = 8192; -pub const SIGSTOP: ::c_int = 0x13; -pub const SIGSYS: ::c_int = 0x1f; -pub const SIGTSTP: ::c_int = 0x14; -pub const SIGTTIN: ::c_int = 0x15; -pub const SIGTTOU: ::c_int = 0x16; -pub const SIGURG: ::c_int = 0x17; -pub const SIGUSR1: ::c_int = 0xa; -pub const SIGUSR2: ::c_int = 0xc; -pub const SIGVTALRM: ::c_int = 0x1a; -pub const SIGWINCH: ::c_int = 0x1c; -pub const SIGXCPU: ::c_int = 0x18; -pub const SIGXFSZ: ::c_int = 0x19; -pub const SIG_BLOCK: ::c_int = 0; -pub const SIG_SETMASK: ::c_int = 0x2; -pub const SIG_UNBLOCK: ::c_int = 0x1; -pub const SOCK_DGRAM: ::c_int = 0x2; -pub const SOCK_NONBLOCK: ::c_int = 0o0004000; -pub const SOCK_SEQPACKET: ::c_int = 0x5; -pub const SOCK_STREAM: ::c_int = 0x1; -pub const SOL_SOCKET: ::c_int = 0x1; -pub const SO_ACCEPTCONN: ::c_int = 0x1e; -pub const SO_BINDTODEVICE: ::c_int = 0x19; -pub const SO_BROADCAST: ::c_int = 0x6; -pub const SO_BSDCOMPAT: ::c_int = 0xe; -pub const SO_DOMAIN: ::c_int = 0x27; -pub const SO_DONTROUTE: ::c_int = 0x5; -pub const SO_ERROR: ::c_int = 0x4; -pub const SO_KEEPALIVE: ::c_int = 0x9; -pub const SO_LINGER: ::c_int = 0xd; -pub const SO_MARK: ::c_int = 0x24; -pub const SO_OOBINLINE: ::c_int = 0xa; -pub const SO_PASSCRED: ::c_int = 0x10; -pub const SO_PEERCRED: ::c_int = 0x11; -pub const SO_PRIORITY: ::c_int = 0xc; -pub const SO_PROTOCOL: ::c_int = 0x26; -pub const SO_RCVBUF: ::c_int = 0x8; -pub const SO_RCVLOWAT: ::c_int = 0x12; -pub const SO_RCVTIMEO: ::c_int = 0x14; -pub const SO_REUSEADDR: ::c_int = 0x2; -pub const SO_RXQ_OVFL: ::c_int = 0x28; -pub const SO_SNDBUF: ::c_int = 0x7; -pub const SO_SNDBUFFORCE: ::c_int = 0x20; -pub const SO_SNDLOWAT: ::c_int = 0x13; -pub const SO_SNDTIMEO: ::c_int = 0x15; -pub const SO_TIMESTAMP: ::c_int = 0x1d; -pub const SO_TYPE: ::c_int = 0x3; -pub const TAB1: ::c_int = 0x800; -pub const TAB2: ::c_int = 0x1000; -pub const TAB3: ::c_int = 0x1800; -pub const TABDLY: ::c_int = 0x1800; -pub const TCSADRAIN: ::c_int = 0x1; -pub const TCSAFLUSH: ::c_int = 0x2; -pub const TCSANOW: ::c_int = 0; -pub const TOSTOP: ::tcflag_t = 0x100; -pub const VDISCARD: usize = 0xd; -pub const VEOF: usize = 0x4; -pub const VEOL: usize = 0xb; -pub const VEOL2: usize = 0x10; -pub const VMIN: usize = 0x6; -pub const VREPRINT: usize = 0xc; -pub const VSTART: usize = 0x8; -pub const VSTOP: usize = 0x9; -pub const VSUSP: usize = 0xa; -pub const VSWTC: usize = 0x7; -pub const VT1: ::c_int = 0x4000; -pub const VTDLY: ::c_int = 0x4000; -pub const VTIME: usize = 0x5; -pub const VWERASE: usize = 0xe; -pub const XTABS: ::tcflag_t = 0x1800; -pub const _PC_2_SYMLINKS: ::c_int = 0x14; -pub const _PC_ALLOC_SIZE_MIN: ::c_int = 0x12; -pub const _PC_ASYNC_IO: ::c_int = 0xa; -pub const _PC_FILESIZEBITS: ::c_int = 0xd; -pub const _PC_PRIO_IO: ::c_int = 0xb; -pub const _PC_REC_INCR_XFER_SIZE: ::c_int = 0xe; -pub const _PC_REC_MAX_XFER_SIZE: ::c_int = 0xf; -pub const _PC_REC_MIN_XFER_SIZE: ::c_int = 0x10; -pub const _PC_REC_XFER_ALIGN: ::c_int = 0x11; -pub const _PC_SYMLINK_MAX: ::c_int = 0x13; -pub const _PC_SYNC_IO: ::c_int = 0x9; -pub const _SC_2_PBS: ::c_int = 0xa8; -pub const _SC_2_PBS_ACCOUNTING: ::c_int = 0xa9; -pub const _SC_2_PBS_CHECKPOINT: ::c_int = 0xaf; -pub const _SC_2_PBS_LOCATE: ::c_int = 0xaa; -pub const _SC_2_PBS_MESSAGE: ::c_int = 0xab; -pub const _SC_2_PBS_TRACK: ::c_int = 0xac; -pub const _SC_ADVISORY_INFO: ::c_int = 0x84; -pub const _SC_BARRIERS: ::c_int = 0x85; -pub const _SC_CLOCK_SELECTION: ::c_int = 0x89; -pub const _SC_CPUTIME: ::c_int = 0x8a; -pub const _SC_IPV6: ::c_int = 0xeb; -pub const _SC_MONOTONIC_CLOCK: ::c_int = 0x95; -pub const _SC_RAW_SOCKETS: ::c_int = 0xec; -pub const _SC_READER_WRITER_LOCKS: ::c_int = 0x99; -pub const _SC_REGEXP: ::c_int = 0x9b; -pub const _SC_SHELL: ::c_int = 0x9d; -pub const _SC_SPAWN: ::c_int = 0x9f; -pub const _SC_SPIN_LOCKS: ::c_int = 0x9a; -pub const _SC_SPORADIC_SERVER: ::c_int = 0xa0; -pub const _SC_SS_REPL_MAX: ::c_int = 0xf1; -pub const _SC_SYMLOOP_MAX: ::c_int = 0xad; -pub const _SC_THREAD_CPUTIME: ::c_int = 0x8b; -pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 0x52; -pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 0xf7; -pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 0xf8; -pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 0xa1; -pub const _SC_TIMEOUTS: ::c_int = 0xa4; -pub const _SC_TRACE: ::c_int = 0xb5; -pub const _SC_TRACE_EVENT_FILTER: ::c_int = 0xb6; -pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 0xf2; -pub const _SC_TRACE_INHERIT: ::c_int = 0xb7; -pub const _SC_TRACE_LOG: ::c_int = 0xb8; -pub const _SC_TRACE_NAME_MAX: ::c_int = 0xf3; -pub const _SC_TRACE_SYS_MAX: ::c_int = 0xf4; -pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 0xf5; -pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 0xa5; -pub const _SC_V6_ILP32_OFF32: ::c_int = 0xb0; -pub const _SC_V6_ILP32_OFFBIG: ::c_int = 0xb1; -pub const _SC_V6_LP64_OFF64: ::c_int = 0xb2; -pub const _SC_V6_LPBIG_OFFBIG: ::c_int = 0xb3; -pub const _SC_XOPEN_STREAMS: ::c_int = 0xf6; - -// Syscall table is copied from src/unix/notbsd/linux/musl/b32/arm.rs -pub const SYS_restart_syscall: ::c_long = 0; -pub const SYS_exit: ::c_long = 1; -pub const SYS_fork: ::c_long = 2; -pub const SYS_read: ::c_long = 3; -pub const SYS_write: ::c_long = 4; -pub const SYS_open: ::c_long = 5; -pub const SYS_close: ::c_long = 6; -pub const SYS_creat: ::c_long = 8; -pub const SYS_link: ::c_long = 9; -pub const SYS_unlink: ::c_long = 10; -pub const SYS_execve: ::c_long = 11; -pub const SYS_chdir: ::c_long = 12; -pub const SYS_mknod: ::c_long = 14; -pub const SYS_chmod: ::c_long = 15; -pub const SYS_lchown: ::c_long = 16; -pub const SYS_lseek: ::c_long = 19; -pub const SYS_getpid: ::c_long = 20; -pub const SYS_mount: ::c_long = 21; -pub const SYS_setuid: ::c_long = 23; -pub const SYS_getuid: ::c_long = 24; -pub const SYS_ptrace: ::c_long = 26; -pub const SYS_pause: ::c_long = 29; -pub const SYS_access: ::c_long = 33; -pub const SYS_nice: ::c_long = 34; -pub const SYS_sync: ::c_long = 36; -pub const SYS_kill: ::c_long = 37; -pub const SYS_rename: ::c_long = 38; -pub const SYS_mkdir: ::c_long = 39; -pub const SYS_rmdir: ::c_long = 40; -pub const SYS_dup: ::c_long = 41; -pub const SYS_pipe: ::c_long = 42; -pub const SYS_times: ::c_long = 43; -pub const SYS_brk: ::c_long = 45; -pub const SYS_setgid: ::c_long = 46; -pub const SYS_getgid: ::c_long = 47; -pub const SYS_geteuid: ::c_long = 49; -pub const SYS_getegid: ::c_long = 50; -pub const SYS_acct: ::c_long = 51; -pub const SYS_umount2: ::c_long = 52; -pub const SYS_ioctl: ::c_long = 54; -pub const SYS_fcntl: ::c_long = 55; -pub const SYS_setpgid: ::c_long = 57; -pub const SYS_umask: ::c_long = 60; -pub const SYS_chroot: ::c_long = 61; -pub const SYS_ustat: ::c_long = 62; -pub const SYS_dup2: ::c_long = 63; -pub const SYS_getppid: ::c_long = 64; -pub const SYS_getpgrp: ::c_long = 65; -pub const SYS_setsid: ::c_long = 66; -pub const SYS_sigaction: ::c_long = 67; -pub const SYS_setreuid: ::c_long = 70; -pub const SYS_setregid: ::c_long = 71; -pub const SYS_sigsuspend: ::c_long = 72; -pub const SYS_sigpending: ::c_long = 73; -pub const SYS_sethostname: ::c_long = 74; -pub const SYS_setrlimit: ::c_long = 75; -pub const SYS_getrusage: ::c_long = 77; -pub const SYS_gettimeofday: ::c_long = 78; -pub const SYS_settimeofday: ::c_long = 79; -pub const SYS_getgroups: ::c_long = 80; -pub const SYS_setgroups: ::c_long = 81; -pub const SYS_symlink: ::c_long = 83; -pub const SYS_readlink: ::c_long = 85; -pub const SYS_uselib: ::c_long = 86; -pub const SYS_swapon: ::c_long = 87; -pub const SYS_reboot: ::c_long = 88; -pub const SYS_munmap: ::c_long = 91; -pub const SYS_truncate: ::c_long = 92; -pub const SYS_ftruncate: ::c_long = 93; -pub const SYS_fchmod: ::c_long = 94; -pub const SYS_fchown: ::c_long = 95; -pub const SYS_getpriority: ::c_long = 96; -pub const SYS_setpriority: ::c_long = 97; -pub const SYS_statfs: ::c_long = 99; -pub const SYS_fstatfs: ::c_long = 100; -pub const SYS_syslog: ::c_long = 103; -pub const SYS_setitimer: ::c_long = 104; -pub const SYS_getitimer: ::c_long = 105; -pub const SYS_stat: ::c_long = 106; -pub const SYS_lstat: ::c_long = 107; -pub const SYS_fstat: ::c_long = 108; -pub const SYS_vhangup: ::c_long = 111; -pub const SYS_wait4: ::c_long = 114; -pub const SYS_swapoff: ::c_long = 115; -pub const SYS_sysinfo: ::c_long = 116; -pub const SYS_fsync: ::c_long = 118; -pub const SYS_sigreturn: ::c_long = 119; -pub const SYS_clone: ::c_long = 120; -pub const SYS_setdomainname: ::c_long = 121; -pub const SYS_uname: ::c_long = 122; -pub const SYS_adjtimex: ::c_long = 124; -pub const SYS_mprotect: ::c_long = 125; -pub const SYS_sigprocmask: ::c_long = 126; -pub const SYS_init_module: ::c_long = 128; -pub const SYS_delete_module: ::c_long = 129; -pub const SYS_quotactl: ::c_long = 131; -pub const SYS_getpgid: ::c_long = 132; -pub const SYS_fchdir: ::c_long = 133; -pub const SYS_bdflush: ::c_long = 134; -pub const SYS_sysfs: ::c_long = 135; -pub const SYS_personality: ::c_long = 136; -pub const SYS_setfsuid: ::c_long = 138; -pub const SYS_setfsgid: ::c_long = 139; -pub const SYS__llseek: ::c_long = 140; -pub const SYS_getdents: ::c_long = 141; -pub const SYS__newselect: ::c_long = 142; -pub const SYS_flock: ::c_long = 143; -pub const SYS_msync: ::c_long = 144; -pub const SYS_readv: ::c_long = 145; -pub const SYS_writev: ::c_long = 146; -pub const SYS_getsid: ::c_long = 147; -pub const SYS_fdatasync: ::c_long = 148; -pub const SYS__sysctl: ::c_long = 149; -pub const SYS_mlock: ::c_long = 150; -pub const SYS_munlock: ::c_long = 151; -pub const SYS_mlockall: ::c_long = 152; -pub const SYS_munlockall: ::c_long = 153; -pub const SYS_sched_setparam: ::c_long = 154; -pub const SYS_sched_getparam: ::c_long = 155; -pub const SYS_sched_setscheduler: ::c_long = 156; -pub const SYS_sched_getscheduler: ::c_long = 157; -pub const SYS_sched_yield: ::c_long = 158; -pub const SYS_sched_get_priority_max: ::c_long = 159; -pub const SYS_sched_get_priority_min: ::c_long = 160; -pub const SYS_sched_rr_get_interval: ::c_long = 161; -pub const SYS_nanosleep: ::c_long = 162; -pub const SYS_mremap: ::c_long = 163; -pub const SYS_setresuid: ::c_long = 164; -pub const SYS_getresuid: ::c_long = 165; -pub const SYS_poll: ::c_long = 168; -pub const SYS_nfsservctl: ::c_long = 169; -pub const SYS_setresgid: ::c_long = 170; -pub const SYS_getresgid: ::c_long = 171; -pub const SYS_prctl: ::c_long = 172; -pub const SYS_rt_sigreturn: ::c_long = 173; -pub const SYS_rt_sigaction: ::c_long = 174; -pub const SYS_rt_sigprocmask: ::c_long = 175; -pub const SYS_rt_sigpending: ::c_long = 176; -pub const SYS_rt_sigtimedwait: ::c_long = 177; -pub const SYS_rt_sigqueueinfo: ::c_long = 178; -pub const SYS_rt_sigsuspend: ::c_long = 179; -pub const SYS_pread64: ::c_long = 180; -pub const SYS_pwrite64: ::c_long = 181; -pub const SYS_chown: ::c_long = 182; -pub const SYS_getcwd: ::c_long = 183; -pub const SYS_capget: ::c_long = 184; -pub const SYS_capset: ::c_long = 185; -pub const SYS_sigaltstack: ::c_long = 186; -pub const SYS_sendfile: ::c_long = 187; -pub const SYS_vfork: ::c_long = 190; -pub const SYS_ugetrlimit: ::c_long = 191; -pub const SYS_mmap2: ::c_long = 192; -pub const SYS_truncate64: ::c_long = 193; -pub const SYS_ftruncate64: ::c_long = 194; -pub const SYS_stat64: ::c_long = 195; -pub const SYS_lstat64: ::c_long = 196; -pub const SYS_fstat64: ::c_long = 197; -pub const SYS_lchown32: ::c_long = 198; -pub const SYS_getuid32: ::c_long = 199; -pub const SYS_getgid32: ::c_long = 200; -pub const SYS_geteuid32: ::c_long = 201; -pub const SYS_getegid32: ::c_long = 202; -pub const SYS_setreuid32: ::c_long = 203; -pub const SYS_setregid32: ::c_long = 204; -pub const SYS_getgroups32: ::c_long = 205; -pub const SYS_setgroups32: ::c_long = 206; -pub const SYS_fchown32: ::c_long = 207; -pub const SYS_setresuid32: ::c_long = 208; -pub const SYS_getresuid32: ::c_long = 209; -pub const SYS_setresgid32: ::c_long = 210; -pub const SYS_getresgid32: ::c_long = 211; -pub const SYS_chown32: ::c_long = 212; -pub const SYS_setuid32: ::c_long = 213; -pub const SYS_setgid32: ::c_long = 214; -pub const SYS_setfsuid32: ::c_long = 215; -pub const SYS_setfsgid32: ::c_long = 216; -pub const SYS_getdents64: ::c_long = 217; -pub const SYS_pivot_root: ::c_long = 218; -pub const SYS_mincore: ::c_long = 219; -pub const SYS_madvise: ::c_long = 220; -pub const SYS_fcntl64: ::c_long = 221; -pub const SYS_gettid: ::c_long = 224; -pub const SYS_readahead: ::c_long = 225; -pub const SYS_setxattr: ::c_long = 226; -pub const SYS_lsetxattr: ::c_long = 227; -pub const SYS_fsetxattr: ::c_long = 228; -pub const SYS_getxattr: ::c_long = 229; -pub const SYS_lgetxattr: ::c_long = 230; -pub const SYS_fgetxattr: ::c_long = 231; -pub const SYS_listxattr: ::c_long = 232; -pub const SYS_llistxattr: ::c_long = 233; -pub const SYS_flistxattr: ::c_long = 234; -pub const SYS_removexattr: ::c_long = 235; -pub const SYS_lremovexattr: ::c_long = 236; -pub const SYS_fremovexattr: ::c_long = 237; -pub const SYS_tkill: ::c_long = 238; -pub const SYS_sendfile64: ::c_long = 239; -pub const SYS_futex: ::c_long = 240; -pub const SYS_sched_setaffinity: ::c_long = 241; -pub const SYS_sched_getaffinity: ::c_long = 242; -pub const SYS_io_setup: ::c_long = 243; -pub const SYS_io_destroy: ::c_long = 244; -pub const SYS_io_getevents: ::c_long = 245; -pub const SYS_io_submit: ::c_long = 246; -pub const SYS_io_cancel: ::c_long = 247; -pub const SYS_exit_group: ::c_long = 248; -pub const SYS_lookup_dcookie: ::c_long = 249; -pub const SYS_epoll_create: ::c_long = 250; -pub const SYS_epoll_ctl: ::c_long = 251; -pub const SYS_epoll_wait: ::c_long = 252; -pub const SYS_remap_file_pages: ::c_long = 253; -pub const SYS_set_tid_address: ::c_long = 256; -pub const SYS_timer_create: ::c_long = 257; -pub const SYS_timer_settime: ::c_long = 258; -pub const SYS_timer_gettime: ::c_long = 259; -pub const SYS_timer_getoverrun: ::c_long = 260; -pub const SYS_timer_delete: ::c_long = 261; -pub const SYS_clock_settime: ::c_long = 262; -pub const SYS_clock_gettime: ::c_long = 263; -pub const SYS_clock_getres: ::c_long = 264; -pub const SYS_clock_nanosleep: ::c_long = 265; -pub const SYS_statfs64: ::c_long = 266; -pub const SYS_fstatfs64: ::c_long = 267; -pub const SYS_tgkill: ::c_long = 268; -pub const SYS_utimes: ::c_long = 269; -pub const SYS_pciconfig_iobase: ::c_long = 271; -pub const SYS_pciconfig_read: ::c_long = 272; -pub const SYS_pciconfig_write: ::c_long = 273; -pub const SYS_mq_open: ::c_long = 274; -pub const SYS_mq_unlink: ::c_long = 275; -pub const SYS_mq_timedsend: ::c_long = 276; -pub const SYS_mq_timedreceive: ::c_long = 277; -pub const SYS_mq_notify: ::c_long = 278; -pub const SYS_mq_getsetattr: ::c_long = 279; -pub const SYS_waitid: ::c_long = 280; -pub const SYS_socket: ::c_long = 281; -pub const SYS_bind: ::c_long = 282; -pub const SYS_connect: ::c_long = 283; -pub const SYS_listen: ::c_long = 284; -pub const SYS_accept: ::c_long = 285; -pub const SYS_getsockname: ::c_long = 286; -pub const SYS_getpeername: ::c_long = 287; -pub const SYS_socketpair: ::c_long = 288; -pub const SYS_send: ::c_long = 289; -pub const SYS_sendto: ::c_long = 290; -pub const SYS_recv: ::c_long = 291; -pub const SYS_recvfrom: ::c_long = 292; -pub const SYS_shutdown: ::c_long = 293; -pub const SYS_setsockopt: ::c_long = 294; -pub const SYS_getsockopt: ::c_long = 295; -pub const SYS_sendmsg: ::c_long = 296; -pub const SYS_recvmsg: ::c_long = 297; -pub const SYS_semop: ::c_long = 298; -pub const SYS_semget: ::c_long = 299; -pub const SYS_semctl: ::c_long = 300; -pub const SYS_msgsnd: ::c_long = 301; -pub const SYS_msgrcv: ::c_long = 302; -pub const SYS_msgget: ::c_long = 303; -pub const SYS_msgctl: ::c_long = 304; -pub const SYS_shmat: ::c_long = 305; -pub const SYS_shmdt: ::c_long = 306; -pub const SYS_shmget: ::c_long = 307; -pub const SYS_shmctl: ::c_long = 308; -pub const SYS_add_key: ::c_long = 309; -pub const SYS_request_key: ::c_long = 310; -pub const SYS_keyctl: ::c_long = 311; -pub const SYS_semtimedop: ::c_long = 312; -pub const SYS_vserver: ::c_long = 313; -pub const SYS_ioprio_set: ::c_long = 314; -pub const SYS_ioprio_get: ::c_long = 315; -pub const SYS_inotify_init: ::c_long = 316; -pub const SYS_inotify_add_watch: ::c_long = 317; -pub const SYS_inotify_rm_watch: ::c_long = 318; -pub const SYS_mbind: ::c_long = 319; -pub const SYS_get_mempolicy: ::c_long = 320; -pub const SYS_set_mempolicy: ::c_long = 321; -pub const SYS_openat: ::c_long = 322; -pub const SYS_mkdirat: ::c_long = 323; -pub const SYS_mknodat: ::c_long = 324; -pub const SYS_fchownat: ::c_long = 325; -pub const SYS_futimesat: ::c_long = 326; -pub const SYS_fstatat64: ::c_long = 327; -pub const SYS_unlinkat: ::c_long = 328; -pub const SYS_renameat: ::c_long = 329; -pub const SYS_linkat: ::c_long = 330; -pub const SYS_symlinkat: ::c_long = 331; -pub const SYS_readlinkat: ::c_long = 332; -pub const SYS_fchmodat: ::c_long = 333; -pub const SYS_faccessat: ::c_long = 334; -pub const SYS_pselect6: ::c_long = 335; -pub const SYS_ppoll: ::c_long = 336; -pub const SYS_unshare: ::c_long = 337; -pub const SYS_set_robust_list: ::c_long = 338; -pub const SYS_get_robust_list: ::c_long = 339; -pub const SYS_splice: ::c_long = 340; -pub const SYS_tee: ::c_long = 342; -pub const SYS_vmsplice: ::c_long = 343; -pub const SYS_move_pages: ::c_long = 344; -pub const SYS_getcpu: ::c_long = 345; -pub const SYS_epoll_pwait: ::c_long = 346; -pub const SYS_kexec_load: ::c_long = 347; -pub const SYS_utimensat: ::c_long = 348; -pub const SYS_signalfd: ::c_long = 349; -pub const SYS_timerfd_create: ::c_long = 350; -pub const SYS_eventfd: ::c_long = 351; -pub const SYS_fallocate: ::c_long = 352; -pub const SYS_timerfd_settime: ::c_long = 353; -pub const SYS_timerfd_gettime: ::c_long = 354; -pub const SYS_signalfd4: ::c_long = 355; -pub const SYS_eventfd2: ::c_long = 356; -pub const SYS_epoll_create1: ::c_long = 357; -pub const SYS_dup3: ::c_long = 358; -pub const SYS_pipe2: ::c_long = 359; -pub const SYS_inotify_init1: ::c_long = 360; -pub const SYS_preadv: ::c_long = 361; -pub const SYS_pwritev: ::c_long = 362; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 363; -pub const SYS_perf_event_open: ::c_long = 364; -pub const SYS_recvmmsg: ::c_long = 365; -pub const SYS_accept4: ::c_long = 366; -pub const SYS_fanotify_init: ::c_long = 367; -pub const SYS_fanotify_mark: ::c_long = 368; -pub const SYS_prlimit64: ::c_long = 369; -pub const SYS_name_to_handle_at: ::c_long = 370; -pub const SYS_open_by_handle_at: ::c_long = 371; -pub const SYS_clock_adjtime: ::c_long = 372; -pub const SYS_syncfs: ::c_long = 373; -pub const SYS_sendmmsg: ::c_long = 374; -pub const SYS_setns: ::c_long = 375; -pub const SYS_process_vm_readv: ::c_long = 376; -pub const SYS_process_vm_writev: ::c_long = 377; -pub const SYS_kcmp: ::c_long = 378; -pub const SYS_finit_module: ::c_long = 379; -pub const SYS_sched_setattr: ::c_long = 380; -pub const SYS_sched_getattr: ::c_long = 381; -pub const SYS_renameat2: ::c_long = 382; -pub const SYS_seccomp: ::c_long = 383; -pub const SYS_getrandom: ::c_long = 384; -pub const SYS_memfd_create: ::c_long = 385; -pub const SYS_bpf: ::c_long = 386; -pub const SYS_execveat: ::c_long = 387; -pub const SYS_userfaultfd: ::c_long = 388; -pub const SYS_membarrier: ::c_long = 389; -pub const SYS_mlock2: ::c_long = 390; -pub const SYS_copy_file_range: ::c_long = 391; -pub const SYS_preadv2: ::c_long = 392; -pub const SYS_pwritev2: ::c_long = 393; -pub const SYS_pkey_mprotect: ::c_long = 394; -pub const SYS_pkey_alloc: ::c_long = 395; -pub const SYS_pkey_free: ::c_long = 396; - -fn CMSG_ALIGN(len: usize) -> usize { - len + ::mem::size_of::() - 1 & !(::mem::size_of::() - 1) -} - -f! { - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize >= ::mem::size_of::() { - (*mhdr).msg_control as *mut cmsghdr - } else { - 0 as *mut cmsghdr - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut ::c_uchar { - cmsg.offset(1) as *mut ::c_uchar - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (CMSG_ALIGN(length as usize) + CMSG_ALIGN(::mem::size_of::())) - as ::c_uint - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - CMSG_ALIGN(::mem::size_of::()) as ::c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, - cmsg: *const cmsghdr) -> *mut cmsghdr { - if ((*cmsg).cmsg_len as usize) < ::mem::size_of::() { - return 0 as *mut cmsghdr; - }; - let next = (cmsg as usize + - CMSG_ALIGN((*cmsg).cmsg_len as usize)) - as *mut cmsghdr; - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if (next.offset(1)) as usize > max || - next as usize + CMSG_ALIGN((*next).cmsg_len as usize) > max - { - 0 as *mut cmsghdr - } else { - next as *mut cmsghdr - } - } - -} - -extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; - pub fn openpty( - amaster: *mut ::c_int, - aslave: *mut ::c_int, - name: *mut ::c_char, - termp: *mut termios, - winp: *mut ::winsize, - ) -> ::c_int; - pub fn setns(fd: ::c_int, nstype: ::c_int) -> ::c_int; - pub fn pwritev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn preadv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } else { - mod no_align; - pub use self::no_align::*; - } -} diff --git a/libc/src/unix/uclibc/arm/no_align.rs b/libc/src/unix/uclibc/arm/no_align.rs deleted file mode 100644 index e32bf67..0000000 --- a/libc/src/unix/uclibc/arm/no_align.rs +++ /dev/null @@ -1,10 +0,0 @@ -s! { - // FIXME this is actually a union - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - __align: [::c_long; 0], - } -} diff --git a/libc/src/unix/uclibc/mips/mips32/align.rs b/libc/src/unix/uclibc/mips/mips32/align.rs deleted file mode 100644 index 4a0e074..0000000 --- a/libc/src/unix/uclibc/mips/mips32/align.rs +++ /dev/null @@ -1,13 +0,0 @@ -s! { - // FIXME this is actually a union - #[cfg_attr(target_pointer_width = "32", - repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", - repr(align(8)))] - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - } -} diff --git a/libc/src/unix/uclibc/mips/mips32/mod.rs b/libc/src/unix/uclibc/mips/mips32/mod.rs deleted file mode 100644 index 31bca58..0000000 --- a/libc/src/unix/uclibc/mips/mips32/mod.rs +++ /dev/null @@ -1,633 +0,0 @@ -pub type c_char = i8; -pub type c_long = i32; -pub type c_ulong = u32; -pub type clock_t = i32; -pub type time_t = i32; -pub type suseconds_t = i32; -pub type wchar_t = i32; -pub type off_t = i32; -pub type ino_t = u32; -pub type blkcnt_t = i32; -pub type blksize_t = i32; -pub type nlink_t = u32; -pub type fsblkcnt_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; -pub type rlim_t = c_ulong; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - st_pad1: [::c_long; 2], - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_pad2: [::c_long; 1], - pub st_size: ::off_t, - st_pad3: ::c_long, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - st_pad5: [::c_long; 14], - } - - pub struct stat64 { - pub st_dev: ::dev_t, - st_pad1: [::c_long; 2], - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - st_pad2: [::c_long; 2], - pub st_size: ::off64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - st_pad3: ::c_long, - pub st_blocks: ::blkcnt64_t, - st_pad5: [::c_long; 14], - } - - pub struct pthread_attr_t { - __size: [u32; 9] - } - - pub struct sigaction { - pub sa_flags: ::c_uint, - pub sa_sigaction: ::sighandler_t, - pub sa_mask: sigset_t, - _restorer: *mut ::c_void, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct sigset_t { - __val: [::c_ulong; 4], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - pub _pad: [::c_int; 29], - } - - pub struct glob64_t { - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut ::c_char, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_uint, - pub __seq: ::c_ushort, - __pad1: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - #[cfg(target_endian = "big")] - __glibc_reserved1: ::c_ulong, - pub msg_stime: ::time_t, - #[cfg(target_endian = "little")] - __glibc_reserved1: ::c_ulong, - #[cfg(target_endian = "big")] - __glibc_reserved2: ::c_ulong, - pub msg_rtime: ::time_t, - #[cfg(target_endian = "little")] - __glibc_reserved2: ::c_ulong, - #[cfg(target_endian = "big")] - __glibc_reserved3: ::c_ulong, - pub msg_ctime: ::time_t, - #[cfg(target_endian = "little")] - __glibc_reserved3: ::c_ulong, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __glibc_reserved4: ::c_ulong, - __glibc_reserved5: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_frsize: ::c_long, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_files: ::fsblkcnt_t, - pub f_ffree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::c_long, - f_spare: [::c_long; 6], - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::size_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::size_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - } - - pub struct flock { - pub l_type: ::c_short, - pub l_whence: ::c_short, - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_sysid: ::c_long, - pub l_pid: ::pid_t, - pad: [::c_long; 4], - } - - pub struct sysinfo { - pub uptime: ::c_long, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub _f: [::c_char; 8], - } -} - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; - -pub const RLIM_INFINITY: ::rlim_t = 0x7fffffff; - -pub const SYS_syscall: ::c_long = 4000 + 0; -pub const SYS_exit: ::c_long = 4000 + 1; -pub const SYS_fork: ::c_long = 4000 + 2; -pub const SYS_read: ::c_long = 4000 + 3; -pub const SYS_write: ::c_long = 4000 + 4; -pub const SYS_open: ::c_long = 4000 + 5; -pub const SYS_close: ::c_long = 4000 + 6; -pub const SYS_waitpid: ::c_long = 4000 + 7; -pub const SYS_creat: ::c_long = 4000 + 8; -pub const SYS_link: ::c_long = 4000 + 9; -pub const SYS_unlink: ::c_long = 4000 + 10; -pub const SYS_execve: ::c_long = 4000 + 11; -pub const SYS_chdir: ::c_long = 4000 + 12; -pub const SYS_time: ::c_long = 4000 + 13; -pub const SYS_mknod: ::c_long = 4000 + 14; -pub const SYS_chmod: ::c_long = 4000 + 15; -pub const SYS_lchown: ::c_long = 4000 + 16; -pub const SYS_break: ::c_long = 4000 + 17; -pub const SYS_lseek: ::c_long = 4000 + 19; -pub const SYS_getpid: ::c_long = 4000 + 20; -pub const SYS_mount: ::c_long = 4000 + 21; -pub const SYS_umount: ::c_long = 4000 + 22; -pub const SYS_setuid: ::c_long = 4000 + 23; -pub const SYS_getuid: ::c_long = 4000 + 24; -pub const SYS_stime: ::c_long = 4000 + 25; -pub const SYS_ptrace: ::c_long = 4000 + 26; -pub const SYS_alarm: ::c_long = 4000 + 27; -pub const SYS_pause: ::c_long = 4000 + 29; -pub const SYS_utime: ::c_long = 4000 + 30; -pub const SYS_stty: ::c_long = 4000 + 31; -pub const SYS_gtty: ::c_long = 4000 + 32; -pub const SYS_access: ::c_long = 4000 + 33; -pub const SYS_nice: ::c_long = 4000 + 34; -pub const SYS_ftime: ::c_long = 4000 + 35; -pub const SYS_sync: ::c_long = 4000 + 36; -pub const SYS_kill: ::c_long = 4000 + 37; -pub const SYS_rename: ::c_long = 4000 + 38; -pub const SYS_mkdir: ::c_long = 4000 + 39; -pub const SYS_rmdir: ::c_long = 4000 + 40; -pub const SYS_dup: ::c_long = 4000 + 41; -pub const SYS_pipe: ::c_long = 4000 + 42; -pub const SYS_times: ::c_long = 4000 + 43; -pub const SYS_prof: ::c_long = 4000 + 44; -pub const SYS_brk: ::c_long = 4000 + 45; -pub const SYS_setgid: ::c_long = 4000 + 46; -pub const SYS_getgid: ::c_long = 4000 + 47; -pub const SYS_signal: ::c_long = 4000 + 48; -pub const SYS_geteuid: ::c_long = 4000 + 49; -pub const SYS_getegid: ::c_long = 4000 + 50; -pub const SYS_acct: ::c_long = 4000 + 51; -pub const SYS_umount2: ::c_long = 4000 + 52; -pub const SYS_lock: ::c_long = 4000 + 53; -pub const SYS_ioctl: ::c_long = 4000 + 54; -pub const SYS_fcntl: ::c_long = 4000 + 55; -pub const SYS_mpx: ::c_long = 4000 + 56; -pub const SYS_setpgid: ::c_long = 4000 + 57; -pub const SYS_ulimit: ::c_long = 4000 + 58; -pub const SYS_umask: ::c_long = 4000 + 60; -pub const SYS_chroot: ::c_long = 4000 + 61; -pub const SYS_ustat: ::c_long = 4000 + 62; -pub const SYS_dup2: ::c_long = 4000 + 63; -pub const SYS_getppid: ::c_long = 4000 + 64; -pub const SYS_getpgrp: ::c_long = 4000 + 65; -pub const SYS_setsid: ::c_long = 4000 + 66; -pub const SYS_sigaction: ::c_long = 4000 + 67; -pub const SYS_sgetmask: ::c_long = 4000 + 68; -pub const SYS_ssetmask: ::c_long = 4000 + 69; -pub const SYS_setreuid: ::c_long = 4000 + 70; -pub const SYS_setregid: ::c_long = 4000 + 71; -pub const SYS_sigsuspend: ::c_long = 4000 + 72; -pub const SYS_sigpending: ::c_long = 4000 + 73; -pub const SYS_sethostname: ::c_long = 4000 + 74; -pub const SYS_setrlimit: ::c_long = 4000 + 75; -pub const SYS_getrlimit: ::c_long = 4000 + 76; -pub const SYS_getrusage: ::c_long = 4000 + 77; -pub const SYS_gettimeofday: ::c_long = 4000 + 78; -pub const SYS_settimeofday: ::c_long = 4000 + 79; -pub const SYS_getgroups: ::c_long = 4000 + 80; -pub const SYS_setgroups: ::c_long = 4000 + 81; -pub const SYS_symlink: ::c_long = 4000 + 83; -pub const SYS_readlink: ::c_long = 4000 + 85; -pub const SYS_uselib: ::c_long = 4000 + 86; -pub const SYS_swapon: ::c_long = 4000 + 87; -pub const SYS_reboot: ::c_long = 4000 + 88; -pub const SYS_readdir: ::c_long = 4000 + 89; -pub const SYS_mmap: ::c_long = 4000 + 90; -pub const SYS_munmap: ::c_long = 4000 + 91; -pub const SYS_truncate: ::c_long = 4000 + 92; -pub const SYS_ftruncate: ::c_long = 4000 + 93; -pub const SYS_fchmod: ::c_long = 4000 + 94; -pub const SYS_fchown: ::c_long = 4000 + 95; -pub const SYS_getpriority: ::c_long = 4000 + 96; -pub const SYS_setpriority: ::c_long = 4000 + 97; -pub const SYS_profil: ::c_long = 4000 + 98; -pub const SYS_statfs: ::c_long = 4000 + 99; -pub const SYS_fstatfs: ::c_long = 4000 + 100; -pub const SYS_ioperm: ::c_long = 4000 + 101; -pub const SYS_socketcall: ::c_long = 4000 + 102; -pub const SYS_syslog: ::c_long = 4000 + 103; -pub const SYS_setitimer: ::c_long = 4000 + 104; -pub const SYS_getitimer: ::c_long = 4000 + 105; -pub const SYS_stat: ::c_long = 4000 + 106; -pub const SYS_lstat: ::c_long = 4000 + 107; -pub const SYS_fstat: ::c_long = 4000 + 108; -pub const SYS_iopl: ::c_long = 4000 + 110; -pub const SYS_vhangup: ::c_long = 4000 + 111; -pub const SYS_idle: ::c_long = 4000 + 112; -pub const SYS_vm86: ::c_long = 4000 + 113; -pub const SYS_wait4: ::c_long = 4000 + 114; -pub const SYS_swapoff: ::c_long = 4000 + 115; -pub const SYS_sysinfo: ::c_long = 4000 + 116; -pub const SYS_ipc: ::c_long = 4000 + 117; -pub const SYS_fsync: ::c_long = 4000 + 118; -pub const SYS_sigreturn: ::c_long = 4000 + 119; -pub const SYS_clone: ::c_long = 4000 + 120; -pub const SYS_setdomainname: ::c_long = 4000 + 121; -pub const SYS_uname: ::c_long = 4000 + 122; -pub const SYS_modify_ldt: ::c_long = 4000 + 123; -pub const SYS_adjtimex: ::c_long = 4000 + 124; -pub const SYS_mprotect: ::c_long = 4000 + 125; -pub const SYS_sigprocmask: ::c_long = 4000 + 126; -pub const SYS_create_module: ::c_long = 4000 + 127; -pub const SYS_init_module: ::c_long = 4000 + 128; -pub const SYS_delete_module: ::c_long = 4000 + 129; -pub const SYS_get_kernel_syms: ::c_long = 4000 + 130; -pub const SYS_quotactl: ::c_long = 4000 + 131; -pub const SYS_getpgid: ::c_long = 4000 + 132; -pub const SYS_fchdir: ::c_long = 4000 + 133; -pub const SYS_bdflush: ::c_long = 4000 + 134; -pub const SYS_sysfs: ::c_long = 4000 + 135; -pub const SYS_personality: ::c_long = 4000 + 136; -pub const SYS_afs_syscall: ::c_long = 4000 + 137; -pub const SYS_setfsuid: ::c_long = 4000 + 138; -pub const SYS_setfsgid: ::c_long = 4000 + 139; -pub const SYS__llseek: ::c_long = 4000 + 140; -pub const SYS_getdents: ::c_long = 4000 + 141; -pub const SYS__newselect: ::c_long = 4000 + 142; -pub const SYS_flock: ::c_long = 4000 + 143; -pub const SYS_msync: ::c_long = 4000 + 144; -pub const SYS_readv: ::c_long = 4000 + 145; -pub const SYS_writev: ::c_long = 4000 + 146; -pub const SYS_cacheflush: ::c_long = 4000 + 147; -pub const SYS_cachectl: ::c_long = 4000 + 148; -pub const SYS_sysmips: ::c_long = 4000 + 149; -pub const SYS_getsid: ::c_long = 4000 + 151; -pub const SYS_fdatasync: ::c_long = 4000 + 152; -pub const SYS__sysctl: ::c_long = 4000 + 153; -pub const SYS_mlock: ::c_long = 4000 + 154; -pub const SYS_munlock: ::c_long = 4000 + 155; -pub const SYS_mlockall: ::c_long = 4000 + 156; -pub const SYS_munlockall: ::c_long = 4000 + 157; -pub const SYS_sched_setparam: ::c_long = 4000 + 158; -pub const SYS_sched_getparam: ::c_long = 4000 + 159; -pub const SYS_sched_setscheduler: ::c_long = 4000 + 160; -pub const SYS_sched_getscheduler: ::c_long = 4000 + 161; -pub const SYS_sched_yield: ::c_long = 4000 + 162; -pub const SYS_sched_get_priority_max: ::c_long = 4000 + 163; -pub const SYS_sched_get_priority_min: ::c_long = 4000 + 164; -pub const SYS_sched_rr_get_interval: ::c_long = 4000 + 165; -pub const SYS_nanosleep: ::c_long = 4000 + 166; -pub const SYS_mremap: ::c_long = 4000 + 167; -pub const SYS_accept: ::c_long = 4000 + 168; -pub const SYS_bind: ::c_long = 4000 + 169; -pub const SYS_connect: ::c_long = 4000 + 170; -pub const SYS_getpeername: ::c_long = 4000 + 171; -pub const SYS_getsockname: ::c_long = 4000 + 172; -pub const SYS_getsockopt: ::c_long = 4000 + 173; -pub const SYS_listen: ::c_long = 4000 + 174; -pub const SYS_recv: ::c_long = 4000 + 175; -pub const SYS_recvfrom: ::c_long = 4000 + 176; -pub const SYS_recvmsg: ::c_long = 4000 + 177; -pub const SYS_send: ::c_long = 4000 + 178; -pub const SYS_sendmsg: ::c_long = 4000 + 179; -pub const SYS_sendto: ::c_long = 4000 + 180; -pub const SYS_setsockopt: ::c_long = 4000 + 181; -pub const SYS_shutdown: ::c_long = 4000 + 182; -pub const SYS_socket: ::c_long = 4000 + 183; -pub const SYS_socketpair: ::c_long = 4000 + 184; -pub const SYS_setresuid: ::c_long = 4000 + 185; -pub const SYS_getresuid: ::c_long = 4000 + 186; -pub const SYS_query_module: ::c_long = 4000 + 187; -pub const SYS_poll: ::c_long = 4000 + 188; -pub const SYS_nfsservctl: ::c_long = 4000 + 189; -pub const SYS_setresgid: ::c_long = 4000 + 190; -pub const SYS_getresgid: ::c_long = 4000 + 191; -pub const SYS_prctl: ::c_long = 4000 + 192; -pub const SYS_rt_sigreturn: ::c_long = 4000 + 193; -pub const SYS_rt_sigaction: ::c_long = 4000 + 194; -pub const SYS_rt_sigprocmask: ::c_long = 4000 + 195; -pub const SYS_rt_sigpending: ::c_long = 4000 + 196; -pub const SYS_rt_sigtimedwait: ::c_long = 4000 + 197; -pub const SYS_rt_sigqueueinfo: ::c_long = 4000 + 198; -pub const SYS_rt_sigsuspend: ::c_long = 4000 + 199; -pub const SYS_pread64: ::c_long = 4000 + 200; -pub const SYS_pwrite64: ::c_long = 4000 + 201; -pub const SYS_chown: ::c_long = 4000 + 202; -pub const SYS_getcwd: ::c_long = 4000 + 203; -pub const SYS_capget: ::c_long = 4000 + 204; -pub const SYS_capset: ::c_long = 4000 + 205; -pub const SYS_sigaltstack: ::c_long = 4000 + 206; -pub const SYS_sendfile: ::c_long = 4000 + 207; -pub const SYS_getpmsg: ::c_long = 4000 + 208; -pub const SYS_putpmsg: ::c_long = 4000 + 209; -pub const SYS_mmap2: ::c_long = 4000 + 210; -pub const SYS_truncate64: ::c_long = 4000 + 211; -pub const SYS_ftruncate64: ::c_long = 4000 + 212; -pub const SYS_stat64: ::c_long = 4000 + 213; -pub const SYS_lstat64: ::c_long = 4000 + 214; -pub const SYS_fstat64: ::c_long = 4000 + 215; -pub const SYS_pivot_root: ::c_long = 4000 + 216; -pub const SYS_mincore: ::c_long = 4000 + 217; -pub const SYS_madvise: ::c_long = 4000 + 218; -pub const SYS_getdents64: ::c_long = 4000 + 219; -pub const SYS_fcntl64: ::c_long = 4000 + 220; -pub const SYS_gettid: ::c_long = 4000 + 222; -pub const SYS_readahead: ::c_long = 4000 + 223; -pub const SYS_setxattr: ::c_long = 4000 + 224; -pub const SYS_lsetxattr: ::c_long = 4000 + 225; -pub const SYS_fsetxattr: ::c_long = 4000 + 226; -pub const SYS_getxattr: ::c_long = 4000 + 227; -pub const SYS_lgetxattr: ::c_long = 4000 + 228; -pub const SYS_fgetxattr: ::c_long = 4000 + 229; -pub const SYS_listxattr: ::c_long = 4000 + 230; -pub const SYS_llistxattr: ::c_long = 4000 + 231; -pub const SYS_flistxattr: ::c_long = 4000 + 232; -pub const SYS_removexattr: ::c_long = 4000 + 233; -pub const SYS_lremovexattr: ::c_long = 4000 + 234; -pub const SYS_fremovexattr: ::c_long = 4000 + 235; -pub const SYS_tkill: ::c_long = 4000 + 236; -pub const SYS_sendfile64: ::c_long = 4000 + 237; -pub const SYS_futex: ::c_long = 4000 + 238; -pub const SYS_sched_setaffinity: ::c_long = 4000 + 239; -pub const SYS_sched_getaffinity: ::c_long = 4000 + 240; -pub const SYS_io_setup: ::c_long = 4000 + 241; -pub const SYS_io_destroy: ::c_long = 4000 + 242; -pub const SYS_io_getevents: ::c_long = 4000 + 243; -pub const SYS_io_submit: ::c_long = 4000 + 244; -pub const SYS_io_cancel: ::c_long = 4000 + 245; -pub const SYS_exit_group: ::c_long = 4000 + 246; -pub const SYS_lookup_dcookie: ::c_long = 4000 + 247; -pub const SYS_epoll_create: ::c_long = 4000 + 248; -pub const SYS_epoll_ctl: ::c_long = 4000 + 249; -pub const SYS_epoll_wait: ::c_long = 4000 + 250; -pub const SYS_remap_file_pages: ::c_long = 4000 + 251; -pub const SYS_set_tid_address: ::c_long = 4000 + 252; -pub const SYS_restart_syscall: ::c_long = 4000 + 253; -pub const SYS_fadvise64: ::c_long = 4000 + 254; -pub const SYS_statfs64: ::c_long = 4000 + 255; -pub const SYS_fstatfs64: ::c_long = 4000 + 256; -pub const SYS_timer_create: ::c_long = 4000 + 257; -pub const SYS_timer_settime: ::c_long = 4000 + 258; -pub const SYS_timer_gettime: ::c_long = 4000 + 259; -pub const SYS_timer_getoverrun: ::c_long = 4000 + 260; -pub const SYS_timer_delete: ::c_long = 4000 + 261; -pub const SYS_clock_settime: ::c_long = 4000 + 262; -pub const SYS_clock_gettime: ::c_long = 4000 + 263; -pub const SYS_clock_getres: ::c_long = 4000 + 264; -pub const SYS_clock_nanosleep: ::c_long = 4000 + 265; -pub const SYS_tgkill: ::c_long = 4000 + 266; -pub const SYS_utimes: ::c_long = 4000 + 267; -pub const SYS_mbind: ::c_long = 4000 + 268; -pub const SYS_get_mempolicy: ::c_long = 4000 + 269; -pub const SYS_set_mempolicy: ::c_long = 4000 + 270; -pub const SYS_mq_open: ::c_long = 4000 + 271; -pub const SYS_mq_unlink: ::c_long = 4000 + 272; -pub const SYS_mq_timedsend: ::c_long = 4000 + 273; -pub const SYS_mq_timedreceive: ::c_long = 4000 + 274; -pub const SYS_mq_notify: ::c_long = 4000 + 275; -pub const SYS_mq_getsetattr: ::c_long = 4000 + 276; -pub const SYS_vserver: ::c_long = 4000 + 277; -pub const SYS_waitid: ::c_long = 4000 + 278; -/* pub const SYS_sys_setaltroot: ::c_long = 4000 + 279; */ -pub const SYS_add_key: ::c_long = 4000 + 280; -pub const SYS_request_key: ::c_long = 4000 + 281; -pub const SYS_keyctl: ::c_long = 4000 + 282; -pub const SYS_set_thread_area: ::c_long = 4000 + 283; -pub const SYS_inotify_init: ::c_long = 4000 + 284; -pub const SYS_inotify_add_watch: ::c_long = 4000 + 285; -pub const SYS_inotify_rm_watch: ::c_long = 4000 + 286; -pub const SYS_migrate_pages: ::c_long = 4000 + 287; -pub const SYS_openat: ::c_long = 4000 + 288; -pub const SYS_mkdirat: ::c_long = 4000 + 289; -pub const SYS_mknodat: ::c_long = 4000 + 290; -pub const SYS_fchownat: ::c_long = 4000 + 291; -pub const SYS_futimesat: ::c_long = 4000 + 292; -pub const SYS_fstatat64: ::c_long = 4000 + 293; -pub const SYS_unlinkat: ::c_long = 4000 + 294; -pub const SYS_renameat: ::c_long = 4000 + 295; -pub const SYS_linkat: ::c_long = 4000 + 296; -pub const SYS_symlinkat: ::c_long = 4000 + 297; -pub const SYS_readlinkat: ::c_long = 4000 + 298; -pub const SYS_fchmodat: ::c_long = 4000 + 299; -pub const SYS_faccessat: ::c_long = 4000 + 300; -pub const SYS_pselect6: ::c_long = 4000 + 301; -pub const SYS_ppoll: ::c_long = 4000 + 302; -pub const SYS_unshare: ::c_long = 4000 + 303; -pub const SYS_splice: ::c_long = 4000 + 304; -pub const SYS_sync_file_range: ::c_long = 4000 + 305; -pub const SYS_tee: ::c_long = 4000 + 306; -pub const SYS_vmsplice: ::c_long = 4000 + 307; -pub const SYS_move_pages: ::c_long = 4000 + 308; -pub const SYS_set_robust_list: ::c_long = 4000 + 309; -pub const SYS_get_robust_list: ::c_long = 4000 + 310; -pub const SYS_kexec_load: ::c_long = 4000 + 311; -pub const SYS_getcpu: ::c_long = 4000 + 312; -pub const SYS_epoll_pwait: ::c_long = 4000 + 313; -pub const SYS_ioprio_set: ::c_long = 4000 + 314; -pub const SYS_ioprio_get: ::c_long = 4000 + 315; -pub const SYS_utimensat: ::c_long = 4000 + 316; -pub const SYS_signalfd: ::c_long = 4000 + 317; -pub const SYS_timerfd: ::c_long = 4000 + 318; -pub const SYS_eventfd: ::c_long = 4000 + 319; -pub const SYS_fallocate: ::c_long = 4000 + 320; -pub const SYS_timerfd_create: ::c_long = 4000 + 321; -pub const SYS_timerfd_gettime: ::c_long = 4000 + 322; -pub const SYS_timerfd_settime: ::c_long = 4000 + 323; -pub const SYS_signalfd4: ::c_long = 4000 + 324; -pub const SYS_eventfd2: ::c_long = 4000 + 325; -pub const SYS_epoll_create1: ::c_long = 4000 + 326; -pub const SYS_dup3: ::c_long = 4000 + 327; -pub const SYS_pipe2: ::c_long = 4000 + 328; -pub const SYS_inotify_init1: ::c_long = 4000 + 329; -pub const SYS_preadv: ::c_long = 4000 + 330; -pub const SYS_pwritev: ::c_long = 4000 + 331; -pub const SYS_rt_tgsigqueueinfo: ::c_long = 4000 + 332; -pub const SYS_perf_event_open: ::c_long = 4000 + 333; -pub const SYS_accept4: ::c_long = 4000 + 334; -pub const SYS_recvmmsg: ::c_long = 4000 + 335; -pub const SYS_fanotify_init: ::c_long = 4000 + 336; -pub const SYS_fanotify_mark: ::c_long = 4000 + 337; -pub const SYS_prlimit64: ::c_long = 4000 + 338; -pub const SYS_name_to_handle_at: ::c_long = 4000 + 339; -pub const SYS_open_by_handle_at: ::c_long = 4000 + 340; -pub const SYS_clock_adjtime: ::c_long = 4000 + 341; -pub const SYS_syncfs: ::c_long = 4000 + 342; -pub const SYS_sendmmsg: ::c_long = 4000 + 343; -pub const SYS_setns: ::c_long = 4000 + 344; -pub const SYS_process_vm_readv: ::c_long = 4000 + 345; -pub const SYS_process_vm_writev: ::c_long = 4000 + 346; -pub const SYS_kcmp: ::c_long = 4000 + 347; -pub const SYS_finit_module: ::c_long = 4000 + 348; -pub const SYS_sched_setattr: ::c_long = 4000 + 349; -pub const SYS_sched_getattr: ::c_long = 4000 + 350; -pub const SYS_renameat2: ::c_long = 4000 + 351; -pub const SYS_seccomp: ::c_long = 4000 + 352; -pub const SYS_getrandom: ::c_long = 4000 + 353; -pub const SYS_memfd_create: ::c_long = 4000 + 354; -pub const SYS_bpf: ::c_long = 4000 + 355; -pub const SYS_execveat: ::c_long = 4000 + 356; -pub const SYS_userfaultfd: ::c_long = 4000 + 357; -pub const SYS_membarrier: ::c_long = 4000 + 358; -pub const SYS_mlock2: ::c_long = 4000 + 359; -pub const SYS_copy_file_range: ::c_long = 4000 + 360; -pub const SYS_preadv2: ::c_long = 4000 + 361; -pub const SYS_pwritev2: ::c_long = 4000 + 362; -pub const SYS_pkey_mprotect: ::c_long = 4000 + 363; -pub const SYS_pkey_alloc: ::c_long = 4000 + 364; -pub const SYS_pkey_free: ::c_long = 4000 + 365; - -#[link(name = "util")] -extern "C" { - pub fn sysctl( - name: *mut ::c_int, - namelen: ::c_int, - oldp: *mut ::c_void, - oldlenp: *mut ::size_t, - newp: *mut ::c_void, - newlen: ::size_t, - ) -> ::c_int; - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; - pub fn backtrace(buf: *mut *mut ::c_void, sz: ::c_int) -> ::c_int; - pub fn glob64( - pattern: *const ::c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut glob64_t, - ) -> ::c_int; - pub fn globfree64(pglob: *mut glob64_t); - pub fn ptrace(request: ::c_uint, ...) -> ::c_long; - pub fn pthread_attr_getaffinity_np( - attr: *const ::pthread_attr_t, - cpusetsize: ::size_t, - cpuset: *mut ::cpu_set_t, - ) -> ::c_int; - pub fn pthread_attr_setaffinity_np( - attr: *mut ::pthread_attr_t, - cpusetsize: ::size_t, - cpuset: *const ::cpu_set_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } else { - mod no_align; - pub use self::no_align::*; - } -} diff --git a/libc/src/unix/uclibc/mips/mips32/no_align.rs b/libc/src/unix/uclibc/mips/mips32/no_align.rs deleted file mode 100644 index e32bf67..0000000 --- a/libc/src/unix/uclibc/mips/mips32/no_align.rs +++ /dev/null @@ -1,10 +0,0 @@ -s! { - // FIXME this is actually a union - pub struct sem_t { - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - __align: [::c_long; 0], - } -} diff --git a/libc/src/unix/uclibc/mips/mips64/align.rs b/libc/src/unix/uclibc/mips/mips64/align.rs deleted file mode 100644 index 21e2190..0000000 --- a/libc/src/unix/uclibc/mips/mips64/align.rs +++ /dev/null @@ -1,10 +0,0 @@ -s! { - // FIXME this is actually a union - #[cfg_attr(target_pointer_width = "32", - repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", - repr(align(8)))] - pub struct sem_t { - __size: [::c_char; 32], - } -} diff --git a/libc/src/unix/uclibc/mips/mips64/mod.rs b/libc/src/unix/uclibc/mips/mips64/mod.rs deleted file mode 100644 index 735eb85..0000000 --- a/libc/src/unix/uclibc/mips/mips64/mod.rs +++ /dev/null @@ -1,213 +0,0 @@ -pub type blkcnt_t = i64; -pub type blksize_t = i64; -pub type c_char = i8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type fsblkcnt_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; -pub type ino_t = u64; -pub type nlink_t = u64; -pub type off_t = i64; -pub type rlim_t = ::c_ulong; -pub type suseconds_t = i64; -pub type time_t = i64; -pub type wchar_t = i32; - -s! { - pub struct stat { - pub st_dev: ::c_ulong, - st_pad1: [::c_long; 2], - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulong, - st_pad2: [::c_ulong; 1], - pub st_size: ::off_t, - st_pad3: ::c_long, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - st_pad4: ::c_long, - pub st_blocks: ::blkcnt_t, - st_pad5: [::c_long; 7], - } - - pub struct stat64 { - pub st_dev: ::c_ulong, - st_pad1: [::c_long; 2], - pub st_ino: ::ino64_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulong, - st_pad2: [::c_long; 2], - pub st_size: ::off64_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - st_pad3: ::c_long, - pub st_blocks: ::blkcnt64_t, - st_pad5: [::c_long; 7], - } - - pub struct pthread_attr_t { - __size: [::c_ulong; 7] - } - - pub struct sigaction { - pub sa_flags: ::c_int, - pub sa_sigaction: ::sighandler_t, - pub sa_mask: sigset_t, - _restorer: *mut ::c_void, - } - - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - - pub struct sigset_t { - __size: [::c_ulong; 16], - } - - pub struct siginfo_t { - pub si_signo: ::c_int, - pub si_code: ::c_int, - pub si_errno: ::c_int, - _pad: ::c_int, - _pad2: [::c_long; 14], - } - - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_uint, - pub __seq: ::c_ushort, - __pad1: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused4: ::c_ulong, - __unused5: ::c_ulong - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - pub msg_rtime: ::time_t, - pub msg_ctime: ::time_t, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __glibc_reserved4: ::c_ulong, - __glibc_reserved5: ::c_ulong, - } - - pub struct statfs { - pub f_type: ::c_long, - pub f_bsize: ::c_long, - pub f_frsize: ::c_long, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_files: ::fsblkcnt_t, - pub f_ffree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_fsid: ::fsid_t, - - pub f_namelen: ::c_long, - f_spare: [::c_long; 6], - } - - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::size_t, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::size_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: ::size_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - pub struct termios { - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - } - - pub struct sysinfo { - pub uptime: ::c_long, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub _f: [::c_char; 0], - } -} - -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; - -pub const RLIM_INFINITY: ::rlim_t = 0xffff_ffff_ffff_ffff; - -pub const SYS_gettid: ::c_long = 5178; // Valid for n64 - -#[link(name = "util")] -extern "C" { - pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } else { - mod no_align; - pub use self::no_align::*; - } -} diff --git a/libc/src/unix/uclibc/mips/mips64/no_align.rs b/libc/src/unix/uclibc/mips/mips64/no_align.rs deleted file mode 100644 index 8909114..0000000 --- a/libc/src/unix/uclibc/mips/mips64/no_align.rs +++ /dev/null @@ -1,7 +0,0 @@ -s! { - // FIXME this is actually a union - pub struct sem_t { - __size: [::c_char; 32], - __align: [::c_long; 0], - } -} diff --git a/libc/src/unix/uclibc/mips/mod.rs b/libc/src/unix/uclibc/mips/mod.rs deleted file mode 100644 index 6a9b41c..0000000 --- a/libc/src/unix/uclibc/mips/mod.rs +++ /dev/null @@ -1,479 +0,0 @@ -pub type pthread_t = ::c_ulong; - -pub const SFD_CLOEXEC: ::c_int = 0x080000; - -pub const NCCS: usize = 32; - -pub const O_TRUNC: ::c_int = 512; - -pub const O_CLOEXEC: ::c_int = 0x80000; - -pub const EBFONT: ::c_int = 59; -pub const ENOSTR: ::c_int = 60; -pub const ENODATA: ::c_int = 61; -pub const ETIME: ::c_int = 62; -pub const ENOSR: ::c_int = 63; -pub const ENONET: ::c_int = 64; -pub const ENOPKG: ::c_int = 65; -pub const EREMOTE: ::c_int = 66; -pub const ENOLINK: ::c_int = 67; -pub const EADV: ::c_int = 68; -pub const ESRMNT: ::c_int = 69; -pub const ECOMM: ::c_int = 70; -pub const EPROTO: ::c_int = 71; -pub const EDOTDOT: ::c_int = 73; - -pub const SA_NODEFER: ::c_int = 0x40000000; -pub const SA_RESETHAND: ::c_int = 0x80000000; -pub const SA_RESTART: ::c_int = 0x10000000; -pub const SA_NOCLDSTOP: ::c_int = 0x00000001; - -pub const EPOLL_CLOEXEC: ::c_int = 0x80000; - -pub const EFD_CLOEXEC: ::c_int = 0x80000; - -pub const BUFSIZ: ::c_uint = 4096; -pub const TMP_MAX: ::c_uint = 238328; -pub const FOPEN_MAX: ::c_uint = 16; -pub const POSIX_FADV_DONTNEED: ::c_int = 4; -pub const POSIX_FADV_NOREUSE: ::c_int = 5; -pub const POSIX_MADV_DONTNEED: ::c_int = 4; -pub const _SC_2_C_VERSION: ::c_int = 96; -pub const O_ACCMODE: ::c_int = 3; -pub const O_DIRECT: ::c_int = 0x8000; -pub const O_DIRECTORY: ::c_int = 0x10000; -pub const O_NOFOLLOW: ::c_int = 0x20000; -pub const ST_RELATIME: ::c_ulong = 4096; -pub const NI_MAXHOST: ::socklen_t = 1025; - -pub const RLIMIT_NOFILE: ::c_int = 5; -pub const RLIMIT_AS: ::c_int = 6; -pub const RLIMIT_RSS: ::c_int = 7; -pub const RLIMIT_NPROC: ::c_int = 8; -pub const RLIMIT_MEMLOCK: ::c_int = 9; -pub const RLIMIT_NLIMITS: ::c_int = 15; - -pub const O_APPEND: ::c_int = 8; -pub const O_CREAT: ::c_int = 256; -pub const O_EXCL: ::c_int = 1024; -pub const O_NOCTTY: ::c_int = 2048; -pub const O_NONBLOCK: ::c_int = 128; -pub const O_SYNC: ::c_int = 0x10; -pub const O_RSYNC: ::c_int = 0x10; -pub const O_DSYNC: ::c_int = 0x10; -pub const O_FSYNC: ::c_int = 0x10; -pub const O_ASYNC: ::c_int = 0x1000; -pub const O_NDELAY: ::c_int = 0x80; - -pub const SOCK_NONBLOCK: ::c_int = 128; - -pub const EDEADLK: ::c_int = 45; -pub const ENAMETOOLONG: ::c_int = 78; -pub const ENOLCK: ::c_int = 46; -pub const ENOSYS: ::c_int = 89; -pub const ENOTEMPTY: ::c_int = 93; -pub const ELOOP: ::c_int = 90; -pub const ENOMSG: ::c_int = 35; -pub const EIDRM: ::c_int = 36; -pub const ECHRNG: ::c_int = 37; -pub const EL2NSYNC: ::c_int = 38; -pub const EL3HLT: ::c_int = 39; -pub const EL3RST: ::c_int = 40; -pub const ELNRNG: ::c_int = 41; -pub const EUNATCH: ::c_int = 42; -pub const ENOCSI: ::c_int = 43; -pub const EL2HLT: ::c_int = 44; -pub const EBADE: ::c_int = 50; -pub const EBADR: ::c_int = 51; -pub const EXFULL: ::c_int = 52; -pub const ENOANO: ::c_int = 53; -pub const EBADRQC: ::c_int = 54; -pub const EBADSLT: ::c_int = 55; -pub const EDEADLOCK: ::c_int = 56; -pub const EMULTIHOP: ::c_int = 74; -pub const EOVERFLOW: ::c_int = 79; -pub const ENOTUNIQ: ::c_int = 80; -pub const EBADFD: ::c_int = 81; -pub const EBADMSG: ::c_int = 77; -pub const EREMCHG: ::c_int = 82; -pub const ELIBACC: ::c_int = 83; -pub const ELIBBAD: ::c_int = 84; -pub const ELIBSCN: ::c_int = 85; -pub const ELIBMAX: ::c_int = 86; -pub const ELIBEXEC: ::c_int = 87; -pub const EILSEQ: ::c_int = 88; -pub const ERESTART: ::c_int = 91; -pub const ESTRPIPE: ::c_int = 92; -pub const EUSERS: ::c_int = 94; -pub const ENOTSOCK: ::c_int = 95; -pub const EDESTADDRREQ: ::c_int = 96; -pub const EMSGSIZE: ::c_int = 97; -pub const EPROTOTYPE: ::c_int = 98; -pub const ENOPROTOOPT: ::c_int = 99; -pub const EPROTONOSUPPORT: ::c_int = 120; -pub const ESOCKTNOSUPPORT: ::c_int = 121; -pub const EOPNOTSUPP: ::c_int = 122; -pub const ENOTSUP: ::c_int = EOPNOTSUPP; -pub const EPFNOSUPPORT: ::c_int = 123; -pub const EAFNOSUPPORT: ::c_int = 124; -pub const EADDRINUSE: ::c_int = 125; -pub const EADDRNOTAVAIL: ::c_int = 126; -pub const ENETDOWN: ::c_int = 127; -pub const ENETUNREACH: ::c_int = 128; -pub const ENETRESET: ::c_int = 129; -pub const ECONNABORTED: ::c_int = 130; -pub const ECONNRESET: ::c_int = 131; -pub const ENOBUFS: ::c_int = 132; -pub const EISCONN: ::c_int = 133; -pub const ENOTCONN: ::c_int = 134; -pub const ESHUTDOWN: ::c_int = 143; -pub const ETOOMANYREFS: ::c_int = 144; -pub const ETIMEDOUT: ::c_int = 145; -pub const ECONNREFUSED: ::c_int = 146; -pub const EHOSTDOWN: ::c_int = 147; -pub const EHOSTUNREACH: ::c_int = 148; -pub const EALREADY: ::c_int = 149; -pub const EINPROGRESS: ::c_int = 150; -pub const ESTALE: ::c_int = 151; -pub const EUCLEAN: ::c_int = 135; -pub const ENOTNAM: ::c_int = 137; -pub const ENAVAIL: ::c_int = 138; -pub const EISNAM: ::c_int = 139; -pub const EREMOTEIO: ::c_int = 140; -pub const EDQUOT: ::c_int = 1133; -pub const ENOMEDIUM: ::c_int = 159; -pub const EMEDIUMTYPE: ::c_int = 160; -pub const ECANCELED: ::c_int = 158; -pub const ENOKEY: ::c_int = 161; -pub const EKEYEXPIRED: ::c_int = 162; -pub const EKEYREVOKED: ::c_int = 163; -pub const EKEYREJECTED: ::c_int = 164; -pub const EOWNERDEAD: ::c_int = 165; -pub const ENOTRECOVERABLE: ::c_int = 166; -pub const ERFKILL: ::c_int = 167; - -pub const MAP_NORESERVE: ::c_int = 0x400; -pub const MAP_ANON: ::c_int = 0x800; -pub const MAP_ANONYMOUS: ::c_int = 0x800; -pub const MAP_GROWSDOWN: ::c_int = 0x1000; -pub const MAP_DENYWRITE: ::c_int = 0x2000; -pub const MAP_EXECUTABLE: ::c_int = 0x4000; -pub const MAP_LOCKED: ::c_int = 0x8000; -pub const MAP_POPULATE: ::c_int = 0x10000; -pub const MAP_NONBLOCK: ::c_int = 0x20000; -pub const MAP_STACK: ::c_int = 0x40000; - -pub const SOCK_STREAM: ::c_int = 2; -pub const SOCK_DGRAM: ::c_int = 1; -pub const SOCK_SEQPACKET: ::c_int = 5; - -pub const SOL_SOCKET: ::c_int = 0xffff; - -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_OOBINLINE: ::c_int = 0x0100; -pub const SO_REUSEPORT: ::c_int = 0x0200; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_STYLE: ::c_int = SO_TYPE; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_SNDLOWAT: ::c_int = 0x1003; -pub const SO_RCVLOWAT: ::c_int = 0x1004; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ACCEPTCONN: ::c_int = 0x1009; -pub const SO_PROTOCOL: ::c_int = 0x1028; -pub const SO_DOMAIN: ::c_int = 0x1029; -pub const SO_NO_CHECK: ::c_int = 11; -pub const SO_PRIORITY: ::c_int = 12; -pub const SO_BSDCOMPAT: ::c_int = 14; -pub const SO_PASSCRED: ::c_int = 17; -pub const SO_PEERCRED: ::c_int = 18; -pub const SO_SECURITY_AUTHENTICATION: ::c_int = 22; -pub const SO_SECURITY_ENCRYPTION_TRANSPORT: ::c_int = 23; -pub const SO_SECURITY_ENCRYPTION_NETWORK: ::c_int = 24; -pub const SO_BINDTODEVICE: ::c_int = 25; -pub const SO_ATTACH_FILTER: ::c_int = 26; -pub const SO_DETACH_FILTER: ::c_int = 27; -pub const SO_GET_FILTER: ::c_int = SO_ATTACH_FILTER; -pub const SO_PEERNAME: ::c_int = 28; -pub const SO_TIMESTAMP: ::c_int = 29; -pub const SCM_TIMESTAMP: ::c_int = SO_TIMESTAMP; -pub const SO_PEERSEC: ::c_int = 30; -pub const SO_SNDBUFFORCE: ::c_int = 31; -pub const SO_RCVBUFFORCE: ::c_int = 33; -pub const SO_PASSSEC: ::c_int = 34; -pub const SO_TIMESTAMPNS: ::c_int = 35; -pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS; -pub const SO_MARK: ::c_int = 36; -pub const SO_TIMESTAMPING: ::c_int = 37; -pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING; -pub const SO_RXQ_OVFL: ::c_int = 40; -pub const SO_WIFI_STATUS: ::c_int = 41; -pub const SCM_WIFI_STATUS: ::c_int = SO_WIFI_STATUS; -pub const SO_PEEK_OFF: ::c_int = 42; -pub const SO_NOFCS: ::c_int = 43; -pub const SO_LOCK_FILTER: ::c_int = 44; -pub const SO_SELECT_ERR_QUEUE: ::c_int = 45; -pub const SO_BUSY_POLL: ::c_int = 46; -pub const SO_MAX_PACING_RATE: ::c_int = 47; -pub const SO_BPF_EXTENSIONS: ::c_int = 48; - -pub const FIOCLEX: ::c_ulong = 0x6601; -pub const FIONCLEX: ::c_ulong = 0x6602; -pub const FIONBIO: ::c_ulong = 0x667e; - -pub const SA_ONSTACK: ::c_uint = 0x08000000; -pub const SA_SIGINFO: ::c_uint = 0x00000008; -pub const SA_NOCLDWAIT: ::c_int = 0x00010000; - -pub const SIGCHLD: ::c_int = 18; -pub const SIGBUS: ::c_int = 10; -pub const SIGTTIN: ::c_int = 26; -pub const SIGTTOU: ::c_int = 27; -pub const SIGXCPU: ::c_int = 30; -pub const SIGXFSZ: ::c_int = 31; -pub const SIGVTALRM: ::c_int = 28; -pub const SIGPROF: ::c_int = 29; -pub const SIGWINCH: ::c_int = 20; -pub const SIGUSR1: ::c_int = 16; -pub const SIGUSR2: ::c_int = 17; -pub const SIGCONT: ::c_int = 25; -pub const SIGSTOP: ::c_int = 23; -pub const SIGTSTP: ::c_int = 24; -pub const SIGURG: ::c_int = 21; -pub const SIGIO: ::c_int = 22; -pub const SIGSYS: ::c_int = 12; -pub const SIGPOLL: ::c_int = 22; -pub const SIGPWR: ::c_int = 19; -pub const SIG_SETMASK: ::c_int = 3; -pub const SIG_BLOCK: ::c_int = 0x1; -pub const SIG_UNBLOCK: ::c_int = 0x2; - -pub const POLLRDNORM: ::c_short = 0x040; -pub const POLLWRNORM: ::c_short = 0x004; -pub const POLLRDBAND: ::c_short = 0x080; -pub const POLLWRBAND: ::c_short = 0x100; - -pub const PTHREAD_STACK_MIN: ::size_t = 16384; - -pub const ADFS_SUPER_MAGIC: ::c_long = 0x0000adf5; -pub const AFFS_SUPER_MAGIC: ::c_long = 0x0000adff; -pub const CODA_SUPER_MAGIC: ::c_long = 0x73757245; -pub const CRAMFS_MAGIC: ::c_long = 0x28cd3d45; -pub const EFS_SUPER_MAGIC: ::c_long = 0x00414a53; -pub const EXT2_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const EXT3_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const EXT4_SUPER_MAGIC: ::c_long = 0x0000ef53; -pub const HPFS_SUPER_MAGIC: ::c_long = 0xf995e849; -pub const HUGETLBFS_MAGIC: ::c_long = 0x958458f6; -pub const ISOFS_SUPER_MAGIC: ::c_long = 0x00009660; -pub const JFFS2_SUPER_MAGIC: ::c_long = 0x000072b6; -pub const MINIX_SUPER_MAGIC: ::c_long = 0x0000137f; -pub const MINIX_SUPER_MAGIC2: ::c_long = 0x0000138f; -pub const MINIX2_SUPER_MAGIC: ::c_long = 0x00002468; -pub const MINIX2_SUPER_MAGIC2: ::c_long = 0x00002478; -pub const MSDOS_SUPER_MAGIC: ::c_long = 0x00004d44; -pub const NCP_SUPER_MAGIC: ::c_long = 0x0000564c; -pub const NFS_SUPER_MAGIC: ::c_long = 0x00006969; -pub const OPENPROM_SUPER_MAGIC: ::c_long = 0x00009fa1; -pub const PROC_SUPER_MAGIC: ::c_long = 0x00009fa0; -pub const QNX4_SUPER_MAGIC: ::c_long = 0x0000002f; -pub const REISERFS_SUPER_MAGIC: ::c_long = 0x52654973; -pub const SMB_SUPER_MAGIC: ::c_long = 0x0000517b; -pub const TMPFS_MAGIC: ::c_long = 0x01021994; -pub const USBDEVICE_SUPER_MAGIC: ::c_long = 0x00009fa2; - -pub const VEOF: usize = 16; -pub const VEOL: usize = 17; -pub const VEOL2: usize = 6; -pub const VMIN: usize = 4; -pub const IEXTEN: ::tcflag_t = 0x00000100; -pub const TOSTOP: ::tcflag_t = 0x00008000; -pub const FLUSHO: ::tcflag_t = 0x00002000; -pub const IUTF8: ::tcflag_t = 0x00004000; -pub const TCSANOW: ::c_int = 0x540e; -pub const TCSADRAIN: ::c_int = 0x540f; -pub const TCSAFLUSH: ::c_int = 0x5410; - -pub const CPU_SETSIZE: ::c_int = 0x400; - -pub const PTRACE_TRACEME: ::c_uint = 0; -pub const PTRACE_PEEKTEXT: ::c_uint = 1; -pub const PTRACE_PEEKDATA: ::c_uint = 2; -pub const PTRACE_PEEKUSER: ::c_uint = 3; -pub const PTRACE_POKETEXT: ::c_uint = 4; -pub const PTRACE_POKEDATA: ::c_uint = 5; -pub const PTRACE_POKEUSER: ::c_uint = 6; -pub const PTRACE_CONT: ::c_uint = 7; -pub const PTRACE_KILL: ::c_uint = 8; -pub const PTRACE_SINGLESTEP: ::c_uint = 9; -pub const PTRACE_ATTACH: ::c_uint = 16; -pub const PTRACE_DETACH: ::c_uint = 17; -pub const PTRACE_SYSCALL: ::c_uint = 24; -pub const PTRACE_SETOPTIONS: ::c_uint = 0x4200; -pub const PTRACE_GETEVENTMSG: ::c_uint = 0x4201; -pub const PTRACE_GETSIGINFO: ::c_uint = 0x4202; -pub const PTRACE_SETSIGINFO: ::c_uint = 0x4203; -pub const PTRACE_GETFPREGS: ::c_uint = 14; -pub const PTRACE_SETFPREGS: ::c_uint = 15; -pub const PTRACE_GETFPXREGS: ::c_uint = 18; -pub const PTRACE_SETFPXREGS: ::c_uint = 19; -pub const PTRACE_GETREGS: ::c_uint = 12; -pub const PTRACE_SETREGS: ::c_uint = 13; - -pub const EFD_NONBLOCK: ::c_int = 0x80; - -pub const F_GETLK: ::c_int = 14; -pub const F_GETOWN: ::c_int = 23; -pub const F_SETOWN: ::c_int = 24; -pub const F_SETLK: ::c_int = 6; -pub const F_SETLKW: ::c_int = 7; - -pub const SFD_NONBLOCK: ::c_int = 0x80; - -pub const TCGETS: ::c_ulong = 0x540d; -pub const TCSETS: ::c_ulong = 0x540e; -pub const TCSETSW: ::c_ulong = 0x540f; -pub const TCSETSF: ::c_ulong = 0x5410; -pub const TCGETA: ::c_ulong = 0x5401; -pub const TCSETA: ::c_ulong = 0x5402; -pub const TCSETAW: ::c_ulong = 0x5403; -pub const TCSETAF: ::c_ulong = 0x5404; -pub const TCSBRK: ::c_ulong = 0x5405; -pub const TCXONC: ::c_ulong = 0x5406; -pub const TCFLSH: ::c_ulong = 0x5407; -pub const TIOCGSOFTCAR: ::c_ulong = 0x5481; -pub const TIOCSSOFTCAR: ::c_ulong = 0x5482; -pub const TIOCINQ: ::c_ulong = 0x467f; -pub const TIOCLINUX: ::c_ulong = 0x5483; -pub const TIOCGSERIAL: ::c_ulong = 0x5484; -pub const TIOCEXCL: ::c_ulong = 0x740d; -pub const TIOCNXCL: ::c_ulong = 0x740e; -pub const TIOCSCTTY: ::c_ulong = 0x5480; -pub const TIOCGPGRP: ::c_ulong = 0x40047477; -pub const TIOCSPGRP: ::c_ulong = 0x80047476; -pub const TIOCOUTQ: ::c_ulong = 0x7472; -pub const TIOCSTI: ::c_ulong = 0x5472; -pub const TIOCGWINSZ: ::c_ulong = 0x40087468; -pub const TIOCSWINSZ: ::c_ulong = 0x80087467; -pub const TIOCMGET: ::c_ulong = 0x741d; -pub const TIOCMBIS: ::c_ulong = 0x741b; -pub const TIOCMBIC: ::c_ulong = 0x741c; -pub const TIOCMSET: ::c_ulong = 0x741a; -pub const FIONREAD: ::c_ulong = 0x467f; -pub const TIOCCONS: ::c_ulong = 0x80047478; - -pub const RTLD_DEEPBIND: ::c_int = 0x10; -pub const RTLD_GLOBAL: ::c_int = 0x4; -pub const RTLD_NOLOAD: ::c_int = 0x8; - -pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead; -pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793; -pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278; -pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448; -pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216; - -pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567; -pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123; -pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF; -pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000; -pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC; -pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4; -pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2; -pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543; - -pub const MCL_CURRENT: ::c_int = 0x0001; -pub const MCL_FUTURE: ::c_int = 0x0002; - -pub const SIGSTKSZ: ::size_t = 8192; -pub const CBAUD: ::tcflag_t = 0o0010017; -pub const TAB1: ::tcflag_t = 0x00000800; -pub const TAB2: ::tcflag_t = 0x00001000; -pub const TAB3: ::tcflag_t = 0x00001800; -pub const CR1: ::tcflag_t = 0x00000200; -pub const CR2: ::tcflag_t = 0x00000400; -pub const CR3: ::tcflag_t = 0x00000600; -pub const FF1: ::tcflag_t = 0x00008000; -pub const BS1: ::tcflag_t = 0x00002000; -pub const VT1: ::tcflag_t = 0x00004000; -pub const VWERASE: usize = 14; -pub const VREPRINT: usize = 12; -pub const VSUSP: usize = 10; -pub const VSTART: usize = 8; -pub const VSTOP: usize = 9; -pub const VDISCARD: usize = 13; -pub const VTIME: usize = 5; -pub const IXON: ::tcflag_t = 0x00000400; -pub const IXOFF: ::tcflag_t = 0x00001000; -pub const ONLCR: ::tcflag_t = 0x4; -pub const CSIZE: ::tcflag_t = 0x00000030; -pub const CS6: ::tcflag_t = 0x00000010; -pub const CS7: ::tcflag_t = 0x00000020; -pub const CS8: ::tcflag_t = 0x00000030; -pub const CSTOPB: ::tcflag_t = 0x00000040; -pub const CREAD: ::tcflag_t = 0x00000080; -pub const PARENB: ::tcflag_t = 0x00000100; -pub const PARODD: ::tcflag_t = 0x00000200; -pub const HUPCL: ::tcflag_t = 0x00000400; -pub const CLOCAL: ::tcflag_t = 0x00000800; -pub const ECHOKE: ::tcflag_t = 0x00000800; -pub const ECHOE: ::tcflag_t = 0x00000010; -pub const ECHOK: ::tcflag_t = 0x00000020; -pub const ECHONL: ::tcflag_t = 0x00000040; -pub const ECHOPRT: ::tcflag_t = 0x00000400; -pub const ECHOCTL: ::tcflag_t = 0x00000200; -pub const ISIG: ::tcflag_t = 0x00000001; -pub const ICANON: ::tcflag_t = 0x00000002; -pub const PENDIN: ::tcflag_t = 0x00004000; -pub const NOFLSH: ::tcflag_t = 0x00000080; - -pub const B0: ::speed_t = 0o000000; -pub const B50: ::speed_t = 0o000001; -pub const B75: ::speed_t = 0o000002; -pub const B110: ::speed_t = 0o000003; -pub const B134: ::speed_t = 0o000004; -pub const B150: ::speed_t = 0o000005; -pub const B200: ::speed_t = 0o000006; -pub const B300: ::speed_t = 0o000007; -pub const B600: ::speed_t = 0o000010; -pub const B1200: ::speed_t = 0o000011; -pub const B1800: ::speed_t = 0o000012; -pub const B2400: ::speed_t = 0o000013; -pub const B4800: ::speed_t = 0o000014; -pub const B9600: ::speed_t = 0o000015; -pub const B19200: ::speed_t = 0o000016; -pub const B38400: ::speed_t = 0o000017; -pub const EXTA: ::speed_t = B19200; -pub const EXTB: ::speed_t = B38400; -pub const B57600: ::speed_t = 0o010001; -pub const B115200: ::speed_t = 0o010002; -pub const B230400: ::speed_t = 0o010003; -pub const B460800: ::speed_t = 0o010004; -pub const B500000: ::speed_t = 0o010005; -pub const B576000: ::speed_t = 0o010006; -pub const B921600: ::speed_t = 0o010007; -pub const B1000000: ::speed_t = 0o010010; -pub const B1152000: ::speed_t = 0o010011; -pub const B1500000: ::speed_t = 0o010012; -pub const B2000000: ::speed_t = 0o010013; -pub const B2500000: ::speed_t = 0o010014; -pub const B3000000: ::speed_t = 0o010015; -pub const B3500000: ::speed_t = 0o010016; -pub const B4000000: ::speed_t = 0o010017; - -cfg_if! { - if #[cfg(target_arch = "mips")] { - mod mips32; - pub use self::mips32::*; - } else if #[cfg(target_arch = "mips64")] { - mod mips64; - pub use self::mips64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/unix/uclibc/mod.rs b/libc/src/unix/uclibc/mod.rs deleted file mode 100644 index b4fe036..0000000 --- a/libc/src/unix/uclibc/mod.rs +++ /dev/null @@ -1,2295 +0,0 @@ -pub type sa_family_t = u16; -pub type pthread_key_t = ::c_uint; -pub type speed_t = ::c_uint; -pub type tcflag_t = ::c_uint; -pub type loff_t = ::c_longlong; -pub type clockid_t = ::c_int; -pub type key_t = ::c_int; -pub type id_t = ::c_uint; -pub type useconds_t = u32; -pub type dev_t = u64; -pub type socklen_t = u32; -pub type mode_t = u32; -pub type ino64_t = u64; -pub type off64_t = i64; -pub type blkcnt64_t = i64; -pub type rlim64_t = u64; -pub type shmatt_t = ::c_ulong; -pub type mqd_t = ::c_int; -pub type msgqnum_t = ::c_ulong; -pub type msglen_t = ::c_ulong; -pub type nfds_t = ::c_ulong; -pub type nl_item = ::c_int; -pub type idtype_t = ::c_uint; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos64_t {} // TODO: fill this out with a struct -impl ::Copy for fpos64_t {} -impl ::Clone for fpos64_t { - fn clone(&self) -> fpos64_t { - *self - } -} - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} - -s! { - pub struct in_addr { - pub s_addr: ::in_addr_t, - } - - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - pub struct sockaddr { - pub sa_family: sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_family: sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [u8; 8], - } - - pub struct sockaddr_in6 { - pub sin6_family: sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct addrinfo { - pub ai_flags: ::c_int, - pub ai_family: ::c_int, - pub ai_socktype: ::c_int, - pub ai_protocol: ::c_int, - pub ai_addrlen: socklen_t, - - pub ai_addr: *mut ::sockaddr, - - pub ai_canonname: *mut c_char, - - pub ai_next: *mut addrinfo, - } - - pub struct sockaddr_ll { - pub sll_family: ::c_ushort, - pub sll_protocol: ::c_ushort, - pub sll_ifindex: ::c_int, - pub sll_hatype: ::c_ushort, - pub sll_pkttype: ::c_uchar, - pub sll_halen: ::c_uchar, - pub sll_addr: [::c_uchar; 8] - } - - pub struct fd_set { - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - pub tm_gmtoff: ::c_long, - pub tm_zone: *const ::c_char, - } - - pub struct sched_param { - pub sched_priority: ::c_int, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } - - pub struct lconv { - pub decimal_point: *mut ::c_char, - pub thousands_sep: *mut ::c_char, - pub grouping: *mut ::c_char, - pub int_curr_symbol: *mut ::c_char, - pub currency_symbol: *mut ::c_char, - pub mon_decimal_point: *mut ::c_char, - pub mon_thousands_sep: *mut ::c_char, - pub mon_grouping: *mut ::c_char, - pub positive_sign: *mut ::c_char, - pub negative_sign: *mut ::c_char, - pub int_frac_digits: ::c_char, - pub frac_digits: ::c_char, - pub p_cs_precedes: ::c_char, - pub p_sep_by_space: ::c_char, - pub n_cs_precedes: ::c_char, - pub n_sep_by_space: ::c_char, - pub p_sign_posn: ::c_char, - pub n_sign_posn: ::c_char, - pub int_p_cs_precedes: ::c_char, - pub int_p_sep_by_space: ::c_char, - pub int_n_cs_precedes: ::c_char, - pub int_n_sep_by_space: ::c_char, - pub int_p_sign_posn: ::c_char, - pub int_n_sign_posn: ::c_char, - } - - pub struct rlimit64 { - pub rlim_cur: rlim64_t, - pub rlim_max: rlim64_t, - } - - pub struct glob_t { - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut c_char, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - } - - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut c_char, - pub ifa_flags: ::c_uint, - pub ifa_addr: *mut ::sockaddr, - pub ifa_netmask: *mut ::sockaddr, - pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union - pub ifa_data: *mut ::c_void - } - - pub struct pthread_rwlockattr_t { - __lockkind: ::c_int, - __pshared: ::c_int, - } - - pub struct passwd { - pub pw_name: *mut ::c_char, - pub pw_passwd: *mut ::c_char, - pub pw_uid: ::uid_t, - pub pw_gid: ::gid_t, - pub pw_gecos: *mut ::c_char, - pub pw_dir: *mut ::c_char, - pub pw_shell: *mut ::c_char, - } - - pub struct spwd { - pub sp_namp: *mut ::c_char, - pub sp_pwdp: *mut ::c_char, - pub sp_lstchg: ::c_long, - pub sp_min: ::c_long, - pub sp_max: ::c_long, - pub sp_warn: ::c_long, - pub sp_inact: ::c_long, - pub sp_expire: ::c_long, - pub sp_flag: ::c_ulong, - } - - pub struct statvfs { - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - #[cfg(target_endian = "little")] - pub f_fsid: ::c_ulong, - #[cfg(target_pointer_width = "32")] - __f_unused: ::c_int, - #[cfg(target_endian = "big")] - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct dqblk { - pub dqb_bhardlimit: u32, - pub dqb_bsoftlimit: u32, - pub dqb_curblocks: u32, - pub dqb_ihardlimit: u32, - pub dqb_isoftlimit: u32, - pub dqb_curinodes: u32, - pub dqb_btime: ::time_t, - pub dqb_itime: ::time_t, - } - - pub struct signalfd_siginfo { - pub ssi_signo: u32, - pub ssi_errno: i32, - pub ssi_code: i32, - pub ssi_pid: u32, - pub ssi_uid: u32, - pub ssi_fd: i32, - pub ssi_tid: u32, - pub ssi_band: u32, - pub ssi_overrun: u32, - pub ssi_trapno: u32, - pub ssi_status: i32, - pub ssi_int: i32, - pub ssi_ptr: u64, - pub ssi_utime: u64, - pub ssi_stime: u64, - pub ssi_addr: u64, - pub ssi_addr_lsb: u16, - _pad2: u16, - pub ssi_syscall: i32, - pub ssi_call_addr: u64, - pub ssi_arch: u32, - _pad: [u8; 28], - } - - pub struct fsid_t { - __val: [::c_int; 2], - } - - pub struct cpu_set_t { - #[cfg(target_pointer_width = "32")] - bits: [u32; 32], - #[cfg(target_pointer_width = "64")] - bits: [u64; 16], - } - - pub struct if_nameindex { - pub if_index: ::c_uint, - pub if_name: *mut ::c_char, - } - - // System V IPC - pub struct msginfo { - pub msgpool: ::c_int, - pub msgmap: ::c_int, - pub msgmax: ::c_int, - pub msgmnb: ::c_int, - pub msgmni: ::c_int, - pub msgssz: ::c_int, - pub msgtql: ::c_int, - pub msgseg: ::c_ushort, - } - - pub struct ucred { - pub pid: ::pid_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - } -} - -s_no_extra_traits! { - #[cfg_attr( - any(target_arch = "x86", target_arch = "x86_64"), - repr(packed) - )] - #[allow(missing_debug_implementations)] - pub struct epoll_event { - pub events: u32, - pub u64: u64, - } - - #[allow(missing_debug_implementations)] - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 108] - } - - #[allow(missing_debug_implementations)] - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - __ss_align: ::size_t, - #[cfg(target_pointer_width = "32")] - __ss_pad2: [u8; 128 - 2 * 4], - #[cfg(target_pointer_width = "64")] - __ss_pad2: [u8; 128 - 2 * 8], - } - - #[allow(missing_debug_implementations)] - pub struct utsname { - pub sysname: [::c_char; 65], - pub nodename: [::c_char; 65], - pub release: [::c_char; 65], - pub version: [::c_char; 65], - pub machine: [::c_char; 65], - pub domainname: [::c_char; 65] - } - - #[allow(missing_debug_implementations)] - pub struct dirent { - pub d_ino: ::ino_t, - pub d_off: ::off_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - #[allow(missing_debug_implementations)] - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: ::c_ushort, - pub d_type: ::c_uchar, - pub d_name: [::c_char; 256], - } - - pub struct mq_attr { - pub mq_flags: ::c_long, - pub mq_maxmsg: ::c_long, - pub mq_msgsize: ::c_long, - pub mq_curmsgs: ::c_long, - pad: [::c_long; 4] - } - - pub struct sockaddr_nl { - pub nl_family: ::sa_family_t, - nl_pad: ::c_ushort, - pub nl_pid: u32, - pub nl_groups: u32 - } - - pub struct sigevent { - pub sigev_value: ::sigval, - pub sigev_signo: ::c_int, - pub sigev_notify: ::c_int, - // Actually a union. We only expose sigev_notify_thread_id because it's - // the most useful member - pub sigev_notify_thread_id: ::c_int, - #[cfg(target_pointer_width = "64")] - __unused1: [::c_int; 11], - #[cfg(target_pointer_width = "32")] - __unused1: [::c_int; 12] - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl PartialEq for mq_attr { - fn eq(&self, other: &mq_attr) -> bool { - self.mq_flags == other.mq_flags && - self.mq_maxmsg == other.mq_maxmsg && - self.mq_msgsize == other.mq_msgsize && - self.mq_curmsgs == other.mq_curmsgs - } - } - impl Eq for mq_attr {} - impl ::fmt::Debug for mq_attr { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("mq_attr") - .field("mq_flags", &self.mq_flags) - .field("mq_maxmsg", &self.mq_maxmsg) - .field("mq_msgsize", &self.mq_msgsize) - .field("mq_curmsgs", &self.mq_curmsgs) - .finish() - } - } - impl ::hash::Hash for mq_attr { - fn hash(&self, state: &mut H) { - self.mq_flags.hash(state); - self.mq_maxmsg.hash(state); - self.mq_msgsize.hash(state); - self.mq_curmsgs.hash(state); - } - } - - impl PartialEq for sockaddr_nl { - fn eq(&self, other: &sockaddr_nl) -> bool { - self.nl_family == other.nl_family && - self.nl_pid == other.nl_pid && - self.nl_groups == other.nl_groups - } - } - impl Eq for sockaddr_nl {} - impl ::fmt::Debug for sockaddr_nl { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_nl") - .field("nl_family", &self.nl_family) - .field("nl_pid", &self.nl_pid) - .field("nl_groups", &self.nl_groups) - .finish() - } - } - impl ::hash::Hash for sockaddr_nl { - fn hash(&self, state: &mut H) { - self.nl_family.hash(state); - self.nl_pid.hash(state); - self.nl_groups.hash(state); - } - } - - impl PartialEq for sigevent { - fn eq(&self, other: &sigevent) -> bool { - self.sigev_value == other.sigev_value - && self.sigev_signo == other.sigev_signo - && self.sigev_notify == other.sigev_notify - && self.sigev_notify_thread_id - == other.sigev_notify_thread_id - } - } - impl Eq for sigevent {} - impl ::fmt::Debug for sigevent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigevent") - .field("sigev_value", &self.sigev_value) - .field("sigev_signo", &self.sigev_signo) - .field("sigev_notify", &self.sigev_notify) - .field("sigev_notify_thread_id", - &self.sigev_notify_thread_id) - .finish() - } - } - impl ::hash::Hash for sigevent { - fn hash(&self, state: &mut H) { - self.sigev_value.hash(state); - self.sigev_signo.hash(state); - self.sigev_notify.hash(state); - self.sigev_notify_thread_id.hash(state); - } - } - } -} - -// intentionally not public, only used for fd_set -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - const ULONG_SIZE: usize = 32; - } else if #[cfg(target_pointer_width = "64")] { - const ULONG_SIZE: usize = 64; - } else { - // Unknown target_pointer_width - } -} - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const RAND_MAX: ::c_int = 2147483647; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 2; -pub const _IOLBF: ::c_int = 1; - -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; - -// Linux-specific fcntls -pub const F_SETLEASE: ::c_int = 1024; -pub const F_GETLEASE: ::c_int = 1025; -pub const F_NOTIFY: ::c_int = 1026; -pub const F_DUPFD_CLOEXEC: ::c_int = 1030; - -// TODO(#235): Include file sealing fcntls once we have a way to verify them. - -pub const SIGTRAP: ::c_int = 5; - -pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0; -pub const PTHREAD_CREATE_DETACHED: ::c_int = 1; - -pub const CLOCK_REALTIME: ::clockid_t = 0; -pub const CLOCK_MONOTONIC: ::clockid_t = 1; -pub const CLOCK_PROCESS_CPUTIME_ID: ::clockid_t = 2; -pub const CLOCK_THREAD_CPUTIME_ID: ::clockid_t = 3; -// TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep -// 2014.) See also musl/mod.rs -// pub const CLOCK_SGI_CYCLE: ::clockid_t = 10; -// pub const CLOCK_TAI: ::clockid_t = 11; -pub const TIMER_ABSTIME: ::c_int = 1; - -pub const RLIMIT_CPU: ::c_int = 0; -pub const RLIMIT_FSIZE: ::c_int = 1; -pub const RLIMIT_DATA: ::c_int = 2; -pub const RLIMIT_STACK: ::c_int = 3; -pub const RLIMIT_CORE: ::c_int = 4; -pub const RLIMIT_LOCKS: ::c_int = 10; -pub const RLIMIT_SIGPENDING: ::c_int = 11; -pub const RLIMIT_MSGQUEUE: ::c_int = 12; -pub const RLIMIT_NICE: ::c_int = 13; -pub const RLIMIT_RTPRIO: ::c_int = 14; - -pub const RUSAGE_SELF: ::c_int = 0; - -pub const O_RDONLY: ::c_int = 0; -pub const O_WRONLY: ::c_int = 1; -pub const O_RDWR: ::c_int = 2; - -pub const SOCK_CLOEXEC: ::c_int = O_CLOEXEC; - -pub const S_IFIFO: ::mode_t = 4096; -pub const S_IFCHR: ::mode_t = 8192; -pub const S_IFBLK: ::mode_t = 24576; -pub const S_IFDIR: ::mode_t = 16384; -pub const S_IFREG: ::mode_t = 32768; -pub const S_IFLNK: ::mode_t = 40960; -pub const S_IFSOCK: ::mode_t = 49152; -pub const S_IFMT: ::mode_t = 61440; -pub const S_IRWXU: ::mode_t = 448; -pub const S_IXUSR: ::mode_t = 64; -pub const S_IWUSR: ::mode_t = 128; -pub const S_IRUSR: ::mode_t = 256; -pub const S_IRWXG: ::mode_t = 56; -pub const S_IXGRP: ::mode_t = 8; -pub const S_IWGRP: ::mode_t = 16; -pub const S_IRGRP: ::mode_t = 32; -pub const S_IRWXO: ::mode_t = 7; -pub const S_IXOTH: ::mode_t = 1; -pub const S_IWOTH: ::mode_t = 2; -pub const S_IROTH: ::mode_t = 4; -pub const F_OK: ::c_int = 0; -pub const R_OK: ::c_int = 4; -pub const W_OK: ::c_int = 2; -pub const X_OK: ::c_int = 1; -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGABRT: ::c_int = 6; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGSEGV: ::c_int = 11; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; - -pub const PROT_NONE: ::c_int = 0; -pub const PROT_READ: ::c_int = 1; -pub const PROT_WRITE: ::c_int = 2; -pub const PROT_EXEC: ::c_int = 4; - -pub const LC_CTYPE: ::c_int = 0; -pub const LC_NUMERIC: ::c_int = 1; -pub const LC_MONETARY: ::c_int = 2; -pub const LC_TIME: ::c_int = 3; -pub const LC_COLLATE: ::c_int = 4; -pub const LC_MESSAGES: ::c_int = 5; -pub const LC_ALL: ::c_int = 6; -pub const LC_CTYPE_MASK: ::c_int = (1 << LC_CTYPE); -pub const LC_NUMERIC_MASK: ::c_int = (1 << LC_NUMERIC); -pub const LC_TIME_MASK: ::c_int = (1 << LC_TIME); -pub const LC_COLLATE_MASK: ::c_int = (1 << LC_COLLATE); -pub const LC_MONETARY_MASK: ::c_int = (1 << LC_MONETARY); -pub const LC_MESSAGES_MASK: ::c_int = (1 << LC_MESSAGES); -// LC_ALL_MASK defined per platform - -pub const MAP_FILE: ::c_int = 0x0000; -pub const MAP_SHARED: ::c_int = 0x0001; -pub const MAP_PRIVATE: ::c_int = 0x0002; -pub const MAP_FIXED: ::c_int = 0x0010; - -pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void; - -// MS_ flags for msync(2) -pub const MS_ASYNC: ::c_int = 0x0001; -pub const MS_INVALIDATE: ::c_int = 0x0002; -pub const MS_SYNC: ::c_int = 0x0004; - -// MS_ flags for mount(2) -pub const MS_RDONLY: ::c_ulong = 0x01; -pub const MS_NOSUID: ::c_ulong = 0x02; -pub const MS_NODEV: ::c_ulong = 0x04; -pub const MS_NOEXEC: ::c_ulong = 0x08; -pub const MS_SYNCHRONOUS: ::c_ulong = 0x10; -pub const MS_REMOUNT: ::c_ulong = 0x20; -pub const MS_MANDLOCK: ::c_ulong = 0x40; -pub const MS_NOATIME: ::c_ulong = 0x0400; -pub const MS_NODIRATIME: ::c_ulong = 0x0800; -pub const MS_BIND: ::c_ulong = 0x1000; -pub const MS_NOUSER: ::c_ulong = 0x80000000; -pub const MS_MGC_VAL: ::c_ulong = 0xc0ed0000; -pub const MS_MGC_MSK: ::c_ulong = 0xffff0000; -pub const MS_RMT_MASK: ::c_ulong = 0x800051; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EAGAIN: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const ENOTBLK: ::c_int = 15; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const ETXTBSY: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const EWOULDBLOCK: ::c_int = EAGAIN; - -pub const SCM_RIGHTS: ::c_int = 0x01; -pub const SCM_CREDENTIALS: ::c_int = 0x02; - -// netinet/in.h -// NOTE: These are in addition to the constants defined in src/unix/mod.rs - -// IPPROTO_IP defined in src/unix/mod.rs -/// Hop-by-hop option header -pub const IPPROTO_HOPOPTS: ::c_int = 0; -// IPPROTO_ICMP defined in src/unix/mod.rs -/// group mgmt protocol -pub const IPPROTO_IGMP: ::c_int = 2; -/// for compatibility -pub const IPPROTO_IPIP: ::c_int = 4; -// IPPROTO_TCP defined in src/unix/mod.rs -/// exterior gateway protocol -pub const IPPROTO_EGP: ::c_int = 8; -/// pup -pub const IPPROTO_PUP: ::c_int = 12; -// IPPROTO_UDP defined in src/unix/mod.rs -/// xns idp -pub const IPPROTO_IDP: ::c_int = 22; -/// tp-4 w/ class negotiation -pub const IPPROTO_TP: ::c_int = 29; -/// DCCP -pub const IPPROTO_DCCP: ::c_int = 33; -// IPPROTO_IPV6 defined in src/unix/mod.rs -/// IP6 routing header -pub const IPPROTO_ROUTING: ::c_int = 43; -/// IP6 fragmentation header -pub const IPPROTO_FRAGMENT: ::c_int = 44; -/// resource reservation -pub const IPPROTO_RSVP: ::c_int = 46; -/// General Routing Encap. -pub const IPPROTO_GRE: ::c_int = 47; -/// IP6 Encap Sec. Payload -pub const IPPROTO_ESP: ::c_int = 50; -/// IP6 Auth Header -pub const IPPROTO_AH: ::c_int = 51; -// IPPROTO_ICMPV6 defined in src/unix/mod.rs -/// IP6 no next header -pub const IPPROTO_NONE: ::c_int = 59; -/// IP6 destination option -pub const IPPROTO_DSTOPTS: ::c_int = 60; -pub const IPPROTO_MTP: ::c_int = 92; -pub const IPPROTO_BEETPH: ::c_int = 94; -/// encapsulation header -pub const IPPROTO_ENCAP: ::c_int = 98; -/// Protocol indep. multicast -pub const IPPROTO_PIM: ::c_int = 103; -/// IP Payload Comp. Protocol -pub const IPPROTO_COMP: ::c_int = 108; -/// SCTP -pub const IPPROTO_SCTP: ::c_int = 132; -pub const IPPROTO_MH: ::c_int = 135; -pub const IPPROTO_UDPLITE: ::c_int = 136; -pub const IPPROTO_MPLS: ::c_int = 137; -/// raw IP packet -pub const IPPROTO_RAW: ::c_int = 255; -pub const IPPROTO_MAX: ::c_int = 256; - -pub const PROT_GROWSDOWN: ::c_int = 0x1000000; -pub const PROT_GROWSUP: ::c_int = 0x2000000; - -pub const MAP_TYPE: ::c_int = 0x000f; - -pub const MADV_NORMAL: ::c_int = 0; -pub const MADV_RANDOM: ::c_int = 1; -pub const MADV_SEQUENTIAL: ::c_int = 2; -pub const MADV_WILLNEED: ::c_int = 3; -pub const MADV_DONTNEED: ::c_int = 4; -pub const MADV_REMOVE: ::c_int = 9; -pub const MADV_DONTFORK: ::c_int = 10; -pub const MADV_DOFORK: ::c_int = 11; -pub const MADV_MERGEABLE: ::c_int = 12; -pub const MADV_UNMERGEABLE: ::c_int = 13; -pub const MADV_HWPOISON: ::c_int = 100; - -// https://github.com/kraj/uClibc/blob/master/include/net/if.h#L44 -pub const IFF_UP: ::c_int = 0x1; // Interface is up. -pub const IFF_BROADCAST: ::c_int = 0x2; // Broadcast address valid. -pub const IFF_DEBUG: ::c_int = 0x4; // Turn on debugging. -pub const IFF_LOOPBACK: ::c_int = 0x8; // Is a loopback net. -pub const IFF_POINTOPOINT: ::c_int = 0x10; // Interface is point-to-point link. -pub const IFF_NOTRAILERS: ::c_int = 0x20; // Avoid use of trailers. -pub const IFF_RUNNING: ::c_int = 0x40; // Resources allocated. -pub const IFF_NOARP: ::c_int = 0x80; // No address resolution protocol. -pub const IFF_PROMISC: ::c_int = 0x100; // Receive all packets. - -// Not supported -pub const IFF_ALLMULTI: ::c_int = 0x200; // Receive all multicast packets. -pub const IFF_MASTER: ::c_int = 0x400; // Master of a load balancer. -pub const IFF_SLAVE: ::c_int = 0x800; // Slave of a load balancer. -pub const IFF_MULTICAST: ::c_int = 0x1000; // Supports multicast. -pub const IFF_PORTSEL: ::c_int = 0x2000; // Can set media type. -pub const IFF_AUTOMEDIA: ::c_int = 0x4000; // Auto media select active. - -// Dialup device with changing addresses. -pub const IFF_DYNAMIC: ::c_int = 0x8000; - -pub const SOL_IP: ::c_int = 0; -pub const SOL_TCP: ::c_int = 6; -pub const SOL_IPV6: ::c_int = 41; -pub const SOL_ICMPV6: ::c_int = 58; -pub const SOL_RAW: ::c_int = 255; -pub const SOL_DECNET: ::c_int = 261; -pub const SOL_X25: ::c_int = 262; -pub const SOL_PACKET: ::c_int = 263; -pub const SOL_ATM: ::c_int = 264; -pub const SOL_AAL: ::c_int = 265; -pub const SOL_IRDA: ::c_int = 266; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_UNIX: ::c_int = 1; -pub const AF_LOCAL: ::c_int = 1; -pub const AF_INET: ::c_int = 2; -pub const AF_AX25: ::c_int = 3; -pub const AF_IPX: ::c_int = 4; -pub const AF_APPLETALK: ::c_int = 5; -pub const AF_NETROM: ::c_int = 6; -pub const AF_BRIDGE: ::c_int = 7; -pub const AF_ATMPVC: ::c_int = 8; -pub const AF_X25: ::c_int = 9; -pub const AF_INET6: ::c_int = 10; -pub const AF_ROSE: ::c_int = 11; -pub const AF_DECnet: ::c_int = 12; -pub const AF_NETBEUI: ::c_int = 13; -pub const AF_SECURITY: ::c_int = 14; -pub const AF_KEY: ::c_int = 15; -pub const AF_NETLINK: ::c_int = 16; -pub const AF_ROUTE: ::c_int = AF_NETLINK; -pub const AF_PACKET: ::c_int = 17; -pub const AF_ASH: ::c_int = 18; -pub const AF_ECONET: ::c_int = 19; -pub const AF_ATMSVC: ::c_int = 20; -pub const AF_SNA: ::c_int = 22; -pub const AF_IRDA: ::c_int = 23; -pub const AF_PPPOX: ::c_int = 24; -pub const AF_WANPIPE: ::c_int = 25; -pub const AF_LLC: ::c_int = 26; -pub const AF_CAN: ::c_int = 29; -pub const AF_TIPC: ::c_int = 30; -pub const AF_BLUETOOTH: ::c_int = 31; -pub const AF_IUCV: ::c_int = 32; -pub const AF_RXRPC: ::c_int = 33; -pub const AF_ISDN: ::c_int = 34; -pub const AF_PHONET: ::c_int = 35; -pub const AF_IEEE802154: ::c_int = 36; -pub const AF_CAIF: ::c_int = 37; -pub const AF_ALG: ::c_int = 38; - -pub const PF_UNSPEC: ::c_int = AF_UNSPEC; -pub const PF_UNIX: ::c_int = AF_UNIX; -pub const PF_LOCAL: ::c_int = AF_LOCAL; -pub const PF_INET: ::c_int = AF_INET; -pub const PF_AX25: ::c_int = AF_AX25; -pub const PF_IPX: ::c_int = AF_IPX; -pub const PF_APPLETALK: ::c_int = AF_APPLETALK; -pub const PF_NETROM: ::c_int = AF_NETROM; -pub const PF_BRIDGE: ::c_int = AF_BRIDGE; -pub const PF_ATMPVC: ::c_int = AF_ATMPVC; -pub const PF_X25: ::c_int = AF_X25; -pub const PF_INET6: ::c_int = AF_INET6; -pub const PF_ROSE: ::c_int = AF_ROSE; -pub const PF_DECnet: ::c_int = AF_DECnet; -pub const PF_NETBEUI: ::c_int = AF_NETBEUI; -pub const PF_SECURITY: ::c_int = AF_SECURITY; -pub const PF_KEY: ::c_int = AF_KEY; -pub const PF_NETLINK: ::c_int = AF_NETLINK; -pub const PF_ROUTE: ::c_int = AF_ROUTE; -pub const PF_PACKET: ::c_int = AF_PACKET; -pub const PF_ASH: ::c_int = AF_ASH; -pub const PF_ECONET: ::c_int = AF_ECONET; -pub const PF_ATMSVC: ::c_int = AF_ATMSVC; -pub const PF_SNA: ::c_int = AF_SNA; -pub const PF_IRDA: ::c_int = AF_IRDA; -pub const PF_PPPOX: ::c_int = AF_PPPOX; -pub const PF_WANPIPE: ::c_int = AF_WANPIPE; -pub const PF_LLC: ::c_int = AF_LLC; -pub const PF_CAN: ::c_int = AF_CAN; -pub const PF_TIPC: ::c_int = AF_TIPC; -pub const PF_BLUETOOTH: ::c_int = AF_BLUETOOTH; -pub const PF_IUCV: ::c_int = AF_IUCV; -pub const PF_RXRPC: ::c_int = AF_RXRPC; -pub const PF_ISDN: ::c_int = AF_ISDN; -pub const PF_PHONET: ::c_int = AF_PHONET; -pub const PF_IEEE802154: ::c_int = AF_IEEE802154; -pub const PF_CAIF: ::c_int = AF_CAIF; -pub const PF_ALG: ::c_int = AF_ALG; - -pub const SOMAXCONN: ::c_int = 128; - -pub const MSG_OOB: ::c_int = 1; -pub const MSG_PEEK: ::c_int = 2; -pub const MSG_DONTROUTE: ::c_int = 4; -pub const MSG_CTRUNC: ::c_int = 8; -pub const MSG_TRUNC: ::c_int = 0x20; -pub const MSG_DONTWAIT: ::c_int = 0x40; -pub const MSG_EOR: ::c_int = 0x80; -pub const MSG_WAITALL: ::c_int = 0x100; -pub const MSG_FIN: ::c_int = 0x200; -pub const MSG_SYN: ::c_int = 0x400; -pub const MSG_CONFIRM: ::c_int = 0x800; -pub const MSG_RST: ::c_int = 0x1000; -pub const MSG_ERRQUEUE: ::c_int = 0x2000; -pub const MSG_NOSIGNAL: ::c_int = 0x4000; -pub const MSG_MORE: ::c_int = 0x8000; -pub const MSG_WAITFORONE: ::c_int = 0x10000; -pub const MSG_CMSG_CLOEXEC: ::c_int = 0x40000000; - -pub const SOCK_RAW: ::c_int = 3; -pub const IP_MULTICAST_TTL: ::c_int = 33; -pub const IP_MULTICAST_LOOP: ::c_int = 34; -pub const IP_TTL: ::c_int = 2; -pub const IP_HDRINCL: ::c_int = 3; -pub const IP_ADD_MEMBERSHIP: ::c_int = 35; -pub const IP_DROP_MEMBERSHIP: ::c_int = 36; -pub const IPV6_ADD_MEMBERSHIP: ::c_int = 20; -pub const IPV6_DROP_MEMBERSHIP: ::c_int = 21; - -pub const IPV6_JOIN_GROUP: ::c_int = 20; -pub const IPV6_LEAVE_GROUP: ::c_int = 21; - -pub const TCP_NODELAY: ::c_int = 1; -pub const TCP_MAXSEG: ::c_int = 2; -pub const TCP_CORK: ::c_int = 3; -pub const TCP_KEEPIDLE: ::c_int = 4; -pub const TCP_KEEPINTVL: ::c_int = 5; -pub const TCP_KEEPCNT: ::c_int = 6; -pub const TCP_SYNCNT: ::c_int = 7; -pub const TCP_LINGER2: ::c_int = 8; -pub const TCP_DEFER_ACCEPT: ::c_int = 9; -pub const TCP_WINDOW_CLAMP: ::c_int = 10; -pub const TCP_INFO: ::c_int = 11; -pub const TCP_QUICKACK: ::c_int = 12; -pub const TCP_CONGESTION: ::c_int = 13; - -// Source: -// https://github.com/kraj/uClibc/blob/ca1c74d67dd115d059a875150e10b8560a9c35a8 -// /libc/sysdeps/linux/common/bits/in.h -// Same for all architectures -pub const IPV6_MULTICAST_HOPS: ::c_int = 18; -pub const IP_MULTICAST_IF: ::c_int = 32; -pub const IPV6_MULTICAST_IF: ::c_int = 17; -pub const IPV6_UNICAST_HOPS: ::c_int = 16; - -// Source: -// https://github.com/kraj/uClibc/tree/ca1c74d67dd115d059a875150e10b8560a9c35a8 -// Same for all architectures -pub const FUTEX_WAIT: ::c_int = 0; -pub const FUTEX_PRIVATE_FLAG: ::c_int = 128; -pub const FUTEX_WAKE: ::c_int = 1; - -pub const IPV6_MULTICAST_LOOP: ::c_int = 19; -pub const IPV6_V6ONLY: ::c_int = 26; - -pub const SO_DEBUG: ::c_int = 1; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const LOCK_SH: ::c_int = 1; -pub const LOCK_EX: ::c_int = 2; -pub const LOCK_NB: ::c_int = 4; -pub const LOCK_UN: ::c_int = 8; - -pub const SS_ONSTACK: ::c_int = 1; -pub const SS_DISABLE: ::c_int = 2; - -pub const PATH_MAX: ::c_int = 4096; - -pub const FD_SETSIZE: usize = 1024; - -pub const EPOLLIN: ::c_int = 0x1; -pub const EPOLLPRI: ::c_int = 0x2; -pub const EPOLLOUT: ::c_int = 0x4; -pub const EPOLLRDNORM: ::c_int = 0x40; -pub const EPOLLRDBAND: ::c_int = 0x80; -pub const EPOLLWRNORM: ::c_int = 0x100; -pub const EPOLLWRBAND: ::c_int = 0x200; -pub const EPOLLMSG: ::c_int = 0x400; -pub const EPOLLERR: ::c_int = 0x8; -pub const EPOLLHUP: ::c_int = 0x10; -pub const EPOLLET: ::c_int = 0x80000000; - -pub const EPOLL_CTL_ADD: ::c_int = 1; -pub const EPOLL_CTL_MOD: ::c_int = 3; -pub const EPOLL_CTL_DEL: ::c_int = 2; - -pub const MNT_DETACH: ::c_int = 0x2; -pub const MNT_EXPIRE: ::c_int = 0x4; - -pub const MNT_FORCE: ::c_int = 0x1; - -pub const Q_SYNC: ::c_int = 0x600; -pub const Q_QUOTAON: ::c_int = 0x100; -pub const Q_QUOTAOFF: ::c_int = 0x200; -pub const Q_GETQUOTA: ::c_int = 0x300; -pub const Q_SETQUOTA: ::c_int = 0x400; - -pub const TCIOFF: ::c_int = 2; -pub const TCION: ::c_int = 3; -pub const TCOOFF: ::c_int = 0; -pub const TCOON: ::c_int = 1; -pub const TCIFLUSH: ::c_int = 0; -pub const TCOFLUSH: ::c_int = 1; -pub const TCIOFLUSH: ::c_int = 2; -pub const NL0: ::tcflag_t = 0x00000000; -pub const NL1: ::tcflag_t = 0x00000100; -pub const TAB0: ::tcflag_t = 0x00000000; -pub const CR0: ::tcflag_t = 0x00000000; -pub const FF0: ::tcflag_t = 0x00000000; -pub const BS0: ::tcflag_t = 0x00000000; -pub const VT0: ::tcflag_t = 0x00000000; -pub const VERASE: usize = 2; -pub const VKILL: usize = 3; -pub const VINTR: usize = 0; -pub const VQUIT: usize = 1; -pub const VLNEXT: usize = 15; -pub const IGNBRK: ::tcflag_t = 0x00000001; -pub const BRKINT: ::tcflag_t = 0x00000002; -pub const IGNPAR: ::tcflag_t = 0x00000004; -pub const PARMRK: ::tcflag_t = 0x00000008; -pub const INPCK: ::tcflag_t = 0x00000010; -pub const ISTRIP: ::tcflag_t = 0x00000020; -pub const INLCR: ::tcflag_t = 0x00000040; -pub const IGNCR: ::tcflag_t = 0x00000080; -pub const ICRNL: ::tcflag_t = 0x00000100; -pub const IXANY: ::tcflag_t = 0x00000800; -pub const IMAXBEL: ::tcflag_t = 0x00002000; -pub const OPOST: ::tcflag_t = 0x1; -pub const CS5: ::tcflag_t = 0x00000000; -pub const CRTSCTS: ::tcflag_t = 0x80000000; -pub const ECHO: ::tcflag_t = 0x00000008; - -pub const CLONE_VM: ::c_int = 0x100; -pub const CLONE_FS: ::c_int = 0x200; -pub const CLONE_FILES: ::c_int = 0x400; -pub const CLONE_SIGHAND: ::c_int = 0x800; -pub const CLONE_PTRACE: ::c_int = 0x2000; -pub const CLONE_VFORK: ::c_int = 0x4000; -pub const CLONE_PARENT: ::c_int = 0x8000; -pub const CLONE_THREAD: ::c_int = 0x10000; -pub const CLONE_NEWNS: ::c_int = 0x20000; -pub const CLONE_SYSVSEM: ::c_int = 0x40000; -pub const CLONE_SETTLS: ::c_int = 0x80000; -pub const CLONE_PARENT_SETTID: ::c_int = 0x100000; -pub const CLONE_CHILD_CLEARTID: ::c_int = 0x200000; -pub const CLONE_DETACHED: ::c_int = 0x400000; -pub const CLONE_UNTRACED: ::c_int = 0x800000; -pub const CLONE_CHILD_SETTID: ::c_int = 0x01000000; -pub const CLONE_NEWUTS: ::c_int = 0x04000000; -pub const CLONE_NEWIPC: ::c_int = 0x08000000; -pub const CLONE_NEWUSER: ::c_int = 0x10000000; -pub const CLONE_NEWPID: ::c_int = 0x20000000; -pub const CLONE_NEWNET: ::c_int = 0x40000000; -pub const CLONE_IO: ::c_int = 0x80000000; - -pub const WNOHANG: ::c_int = 0x00000001; -pub const WUNTRACED: ::c_int = 0x00000002; -pub const WSTOPPED: ::c_int = WUNTRACED; -pub const WEXITED: ::c_int = 0x00000004; -pub const WCONTINUED: ::c_int = 0x00000008; -pub const WNOWAIT: ::c_int = 0x01000000; - -pub const __WNOTHREAD: ::c_int = 0x20000000; -pub const __WALL: ::c_int = 0x40000000; -pub const __WCLONE: ::c_int = 0x80000000; - -pub const SPLICE_F_MOVE: ::c_uint = 0x01; -pub const SPLICE_F_NONBLOCK: ::c_uint = 0x02; -pub const SPLICE_F_MORE: ::c_uint = 0x04; -pub const SPLICE_F_GIFT: ::c_uint = 0x08; - -pub const RTLD_LOCAL: ::c_int = 0; -pub const RTLD_LAZY: ::c_int = 1; - -pub const POSIX_FADV_NORMAL: ::c_int = 0; -pub const POSIX_FADV_RANDOM: ::c_int = 1; -pub const POSIX_FADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_FADV_WILLNEED: ::c_int = 3; - -pub const AT_FDCWD: ::c_int = -100; -pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100; -pub const AT_REMOVEDIR: ::c_int = 0x200; -pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; - -pub const LOG_CRON: ::c_int = 9 << 3; -pub const LOG_AUTHPRIV: ::c_int = 10 << 3; -pub const LOG_FTP: ::c_int = 11 << 3; -pub const LOG_PERROR: ::c_int = 0x20; - -pub const POLLIN: ::c_short = 0x1; -pub const POLLPRI: ::c_short = 0x2; -pub const POLLOUT: ::c_short = 0x4; -pub const POLLERR: ::c_short = 0x8; -pub const POLLHUP: ::c_short = 0x10; -pub const POLLNVAL: ::c_short = 0x20; - -pub const PIPE_BUF: usize = 4096; - -pub const SI_LOAD_SHIFT: ::c_uint = 16; - -pub const SIGEV_SIGNAL: ::c_int = 0; -pub const SIGEV_NONE: ::c_int = 1; -pub const SIGEV_THREAD: ::c_int = 2; - -pub const P_ALL: idtype_t = 0; -pub const P_PID: idtype_t = 1; -pub const P_PGID: idtype_t = 2; - -pub const UTIME_OMIT: c_long = 1073741822; -pub const UTIME_NOW: c_long = 1073741823; - -pub const L_tmpnam: ::c_uint = 20; -pub const _PC_LINK_MAX: ::c_int = 0; -pub const _PC_MAX_CANON: ::c_int = 1; -pub const _PC_MAX_INPUT: ::c_int = 2; -pub const _PC_NAME_MAX: ::c_int = 3; -pub const _PC_PATH_MAX: ::c_int = 4; -pub const _PC_PIPE_BUF: ::c_int = 5; -pub const _PC_CHOWN_RESTRICTED: ::c_int = 6; -pub const _PC_NO_TRUNC: ::c_int = 7; -pub const _PC_VDISABLE: ::c_int = 8; - -pub const _SC_ARG_MAX: ::c_int = 0; -pub const _SC_CHILD_MAX: ::c_int = 1; -pub const _SC_CLK_TCK: ::c_int = 2; -pub const _SC_NGROUPS_MAX: ::c_int = 3; -pub const _SC_OPEN_MAX: ::c_int = 4; -pub const _SC_STREAM_MAX: ::c_int = 5; -pub const _SC_TZNAME_MAX: ::c_int = 6; -pub const _SC_JOB_CONTROL: ::c_int = 7; -pub const _SC_SAVED_IDS: ::c_int = 8; -pub const _SC_REALTIME_SIGNALS: ::c_int = 9; -pub const _SC_PRIORITY_SCHEDULING: ::c_int = 10; -pub const _SC_TIMERS: ::c_int = 11; -pub const _SC_ASYNCHRONOUS_IO: ::c_int = 12; -pub const _SC_PRIORITIZED_IO: ::c_int = 13; -pub const _SC_SYNCHRONIZED_IO: ::c_int = 14; -pub const _SC_FSYNC: ::c_int = 15; -pub const _SC_MAPPED_FILES: ::c_int = 16; -pub const _SC_MEMLOCK: ::c_int = 17; -pub const _SC_MEMLOCK_RANGE: ::c_int = 18; -pub const _SC_MEMORY_PROTECTION: ::c_int = 19; -pub const _SC_MESSAGE_PASSING: ::c_int = 20; -pub const _SC_SEMAPHORES: ::c_int = 21; -pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 22; -pub const _SC_AIO_LISTIO_MAX: ::c_int = 23; -pub const _SC_AIO_MAX: ::c_int = 24; -pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 25; -pub const _SC_DELAYTIMER_MAX: ::c_int = 26; -pub const _SC_MQ_OPEN_MAX: ::c_int = 27; -pub const _SC_MQ_PRIO_MAX: ::c_int = 28; -pub const _SC_VERSION: ::c_int = 29; -pub const _SC_PAGESIZE: ::c_int = 30; -pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; -pub const _SC_RTSIG_MAX: ::c_int = 31; -pub const _SC_SEM_NSEMS_MAX: ::c_int = 32; -pub const _SC_SEM_VALUE_MAX: ::c_int = 33; -pub const _SC_SIGQUEUE_MAX: ::c_int = 34; -pub const _SC_TIMER_MAX: ::c_int = 35; -pub const _SC_BC_BASE_MAX: ::c_int = 36; -pub const _SC_BC_DIM_MAX: ::c_int = 37; -pub const _SC_BC_SCALE_MAX: ::c_int = 38; -pub const _SC_BC_STRING_MAX: ::c_int = 39; -pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 40; -pub const _SC_EXPR_NEST_MAX: ::c_int = 42; -pub const _SC_LINE_MAX: ::c_int = 43; -pub const _SC_RE_DUP_MAX: ::c_int = 44; -pub const _SC_2_VERSION: ::c_int = 46; -pub const _SC_2_C_BIND: ::c_int = 47; -pub const _SC_2_C_DEV: ::c_int = 48; -pub const _SC_2_FORT_DEV: ::c_int = 49; -pub const _SC_2_FORT_RUN: ::c_int = 50; -pub const _SC_2_SW_DEV: ::c_int = 51; -pub const _SC_2_LOCALEDEF: ::c_int = 52; -pub const _SC_IOV_MAX: ::c_int = 60; -pub const _SC_THREADS: ::c_int = 67; -pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 68; -pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 69; -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 70; -pub const _SC_LOGIN_NAME_MAX: ::c_int = 71; -pub const _SC_TTY_NAME_MAX: ::c_int = 72; -pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 73; -pub const _SC_THREAD_KEYS_MAX: ::c_int = 74; -pub const _SC_THREAD_STACK_MIN: ::c_int = 75; -pub const _SC_THREAD_THREADS_MAX: ::c_int = 76; -pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 77; -pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 78; -pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 79; -pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 80; -pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 81; -pub const _SC_NPROCESSORS_ONLN: ::c_int = 84; -pub const _SC_ATEXIT_MAX: ::c_int = 87; -pub const _SC_XOPEN_VERSION: ::c_int = 89; -pub const _SC_XOPEN_XCU_VERSION: ::c_int = 90; -pub const _SC_XOPEN_UNIX: ::c_int = 91; -pub const _SC_XOPEN_CRYPT: ::c_int = 92; -pub const _SC_XOPEN_ENH_I18N: ::c_int = 93; -pub const _SC_XOPEN_SHM: ::c_int = 94; -pub const _SC_2_CHAR_TERM: ::c_int = 95; -pub const _SC_2_UPE: ::c_int = 97; -pub const _SC_XBS5_ILP32_OFF32: ::c_int = 125; -pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = 126; -pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = 128; -pub const _SC_XOPEN_LEGACY: ::c_int = 129; -pub const _SC_XOPEN_REALTIME: ::c_int = 130; -pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 131; -pub const _SC_HOST_NAME_MAX: ::c_int = 180; - -pub const RLIM_SAVED_MAX: ::rlim_t = RLIM_INFINITY; -pub const RLIM_SAVED_CUR: ::rlim_t = RLIM_INFINITY; - -pub const GLOB_ERR: ::c_int = 1 << 0; -pub const GLOB_MARK: ::c_int = 1 << 1; -pub const GLOB_NOSORT: ::c_int = 1 << 2; -pub const GLOB_DOOFFS: ::c_int = 1 << 3; -pub const GLOB_NOCHECK: ::c_int = 1 << 4; -pub const GLOB_APPEND: ::c_int = 1 << 5; -pub const GLOB_NOESCAPE: ::c_int = 1 << 6; - -pub const GLOB_NOSPACE: ::c_int = 1; -pub const GLOB_ABORTED: ::c_int = 2; -pub const GLOB_NOMATCH: ::c_int = 3; - -pub const POSIX_MADV_NORMAL: ::c_int = 0; -pub const POSIX_MADV_RANDOM: ::c_int = 1; -pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; -pub const POSIX_MADV_WILLNEED: ::c_int = 3; - -pub const S_IEXEC: mode_t = 64; -pub const S_IWRITE: mode_t = 128; -pub const S_IREAD: mode_t = 256; - -pub const F_LOCK: ::c_int = 1; -pub const F_TEST: ::c_int = 3; -pub const F_TLOCK: ::c_int = 2; -pub const F_ULOCK: ::c_int = 0; - -pub const ST_RDONLY: ::c_ulong = 1; -pub const ST_NOSUID: ::c_ulong = 2; -pub const ST_NODEV: ::c_ulong = 4; -pub const ST_NOEXEC: ::c_ulong = 8; -pub const ST_SYNCHRONOUS: ::c_ulong = 16; -pub const ST_MANDLOCK: ::c_ulong = 64; -pub const ST_WRITE: ::c_ulong = 128; -pub const ST_APPEND: ::c_ulong = 256; -pub const ST_IMMUTABLE: ::c_ulong = 512; -pub const ST_NOATIME: ::c_ulong = 1024; -pub const ST_NODIRATIME: ::c_ulong = 2048; - -pub const RTLD_NEXT: *mut ::c_void = -1i64 as *mut ::c_void; -pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; -pub const RTLD_NODELETE: ::c_int = 0x1000; -pub const RTLD_NOW: ::c_int = 0x2; - -pub const TCP_MD5SIG: ::c_int = 14; - -align_const! { - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - size: [0; __SIZEOF_PTHREAD_MUTEX_T], - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - size: [0; __SIZEOF_PTHREAD_COND_T], - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - size: [0; __SIZEOF_PTHREAD_RWLOCK_T], - }; -} -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; -pub const __SIZEOF_PTHREAD_COND_T: usize = 48; - -pub const SCHED_OTHER: ::c_int = 0; -pub const SCHED_FIFO: ::c_int = 1; -pub const SCHED_RR: ::c_int = 2; -pub const SCHED_BATCH: ::c_int = 3; -pub const SCHED_IDLE: ::c_int = 5; - -// System V IPC -pub const IPC_PRIVATE: ::key_t = 0; - -pub const IPC_CREAT: ::c_int = 0o1000; -pub const IPC_EXCL: ::c_int = 0o2000; -pub const IPC_NOWAIT: ::c_int = 0o4000; - -pub const IPC_RMID: ::c_int = 0; -pub const IPC_SET: ::c_int = 1; -pub const IPC_STAT: ::c_int = 2; -pub const IPC_INFO: ::c_int = 3; -pub const MSG_STAT: ::c_int = 11; -pub const MSG_INFO: ::c_int = 12; - -pub const MSG_NOERROR: ::c_int = 0o10000; -pub const MSG_EXCEPT: ::c_int = 0o20000; - -pub const SHM_R: ::c_int = 0o400; -pub const SHM_W: ::c_int = 0o200; - -pub const SHM_RDONLY: ::c_int = 0o10000; -pub const SHM_RND: ::c_int = 0o20000; -pub const SHM_REMAP: ::c_int = 0o40000; - -pub const SHM_LOCK: ::c_int = 11; -pub const SHM_UNLOCK: ::c_int = 12; - -pub const SHM_HUGETLB: ::c_int = 0o4000; -pub const SHM_NORESERVE: ::c_int = 0o10000; - -pub const EPOLLRDHUP: ::c_int = 0x2000; -pub const EPOLLONESHOT: ::c_int = 0x40000000; - -pub const QFMT_VFS_OLD: ::c_int = 1; -pub const QFMT_VFS_V0: ::c_int = 2; - -pub const EFD_SEMAPHORE: ::c_int = 0x1; - -pub const LOG_NFACILITIES: ::c_int = 24; - -pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t; - -pub const RB_AUTOBOOT: ::c_int = 0x01234567u32 as i32; -pub const RB_HALT_SYSTEM: ::c_int = 0xcdef0123u32 as i32; -pub const RB_ENABLE_CAD: ::c_int = 0x89abcdefu32 as i32; -pub const RB_DISABLE_CAD: ::c_int = 0x00000000u32 as i32; -pub const RB_POWER_OFF: ::c_int = 0x4321fedcu32 as i32; - -pub const AI_PASSIVE: ::c_int = 0x0001; -pub const AI_CANONNAME: ::c_int = 0x0002; -pub const AI_NUMERICHOST: ::c_int = 0x0004; -pub const AI_V4MAPPED: ::c_int = 0x0008; -pub const AI_ALL: ::c_int = 0x0010; -pub const AI_ADDRCONFIG: ::c_int = 0x0020; - -pub const AI_NUMERICSERV: ::c_int = 0x0400; - -pub const EAI_BADFLAGS: ::c_int = -1; -pub const EAI_NONAME: ::c_int = -2; -pub const EAI_AGAIN: ::c_int = -3; -pub const EAI_FAIL: ::c_int = -4; -pub const EAI_FAMILY: ::c_int = -6; -pub const EAI_SOCKTYPE: ::c_int = -7; -pub const EAI_SERVICE: ::c_int = -8; -pub const EAI_MEMORY: ::c_int = -10; -pub const EAI_OVERFLOW: ::c_int = -12; - -pub const NI_NUMERICHOST: ::c_int = 1; -pub const NI_NUMERICSERV: ::c_int = 2; -pub const NI_NOFQDN: ::c_int = 4; -pub const NI_NAMEREQD: ::c_int = 8; -pub const NI_DGRAM: ::c_int = 16; - -pub const SYNC_FILE_RANGE_WAIT_BEFORE: ::c_uint = 1; -pub const SYNC_FILE_RANGE_WRITE: ::c_uint = 2; -pub const SYNC_FILE_RANGE_WAIT_AFTER: ::c_uint = 4; - -pub const EAI_SYSTEM: ::c_int = -11; - -pub const MREMAP_MAYMOVE: ::c_int = 1; -pub const MREMAP_FIXED: ::c_int = 2; - -pub const PR_SET_PDEATHSIG: ::c_int = 1; -pub const PR_GET_PDEATHSIG: ::c_int = 2; - -pub const PR_GET_DUMPABLE: ::c_int = 3; -pub const PR_SET_DUMPABLE: ::c_int = 4; - -pub const PR_GET_UNALIGN: ::c_int = 5; -pub const PR_SET_UNALIGN: ::c_int = 6; -pub const PR_UNALIGN_NOPRINT: ::c_int = 1; -pub const PR_UNALIGN_SIGBUS: ::c_int = 2; - -pub const PR_GET_KEEPCAPS: ::c_int = 7; -pub const PR_SET_KEEPCAPS: ::c_int = 8; - -pub const PR_GET_FPEMU: ::c_int = 9; -pub const PR_SET_FPEMU: ::c_int = 10; -pub const PR_FPEMU_NOPRINT: ::c_int = 1; -pub const PR_FPEMU_SIGFPE: ::c_int = 2; - -pub const PR_GET_FPEXC: ::c_int = 11; -pub const PR_SET_FPEXC: ::c_int = 12; -pub const PR_FP_EXC_SW_ENABLE: ::c_int = 0x80; -pub const PR_FP_EXC_DIV: ::c_int = 0x010000; -pub const PR_FP_EXC_OVF: ::c_int = 0x020000; -pub const PR_FP_EXC_UND: ::c_int = 0x040000; -pub const PR_FP_EXC_RES: ::c_int = 0x080000; -pub const PR_FP_EXC_INV: ::c_int = 0x100000; -pub const PR_FP_EXC_DISABLED: ::c_int = 0; -pub const PR_FP_EXC_NONRECOV: ::c_int = 1; -pub const PR_FP_EXC_ASYNC: ::c_int = 2; -pub const PR_FP_EXC_PRECISE: ::c_int = 3; - -pub const PR_GET_TIMING: ::c_int = 13; -pub const PR_SET_TIMING: ::c_int = 14; -pub const PR_TIMING_STATISTICAL: ::c_int = 0; -pub const PR_TIMING_TIMESTAMP: ::c_int = 1; - -pub const PR_SET_NAME: ::c_int = 15; -pub const PR_GET_NAME: ::c_int = 16; - -pub const PR_GET_ENDIAN: ::c_int = 19; -pub const PR_SET_ENDIAN: ::c_int = 20; -pub const PR_ENDIAN_BIG: ::c_int = 0; -pub const PR_ENDIAN_LITTLE: ::c_int = 1; -pub const PR_ENDIAN_PPC_LITTLE: ::c_int = 2; - -pub const PR_GET_SECCOMP: ::c_int = 21; -pub const PR_SET_SECCOMP: ::c_int = 22; - -pub const PR_CAPBSET_READ: ::c_int = 23; -pub const PR_CAPBSET_DROP: ::c_int = 24; - -pub const PR_GET_TSC: ::c_int = 25; -pub const PR_SET_TSC: ::c_int = 26; -pub const PR_TSC_ENABLE: ::c_int = 1; -pub const PR_TSC_SIGSEGV: ::c_int = 2; - -pub const PR_GET_SECUREBITS: ::c_int = 27; -pub const PR_SET_SECUREBITS: ::c_int = 28; - -pub const PR_SET_TIMERSLACK: ::c_int = 29; -pub const PR_GET_TIMERSLACK: ::c_int = 30; - -pub const PR_TASK_PERF_EVENTS_DISABLE: ::c_int = 31; -pub const PR_TASK_PERF_EVENTS_ENABLE: ::c_int = 32; - -pub const PR_MCE_KILL: ::c_int = 33; -pub const PR_MCE_KILL_CLEAR: ::c_int = 0; -pub const PR_MCE_KILL_SET: ::c_int = 1; - -pub const PR_MCE_KILL_LATE: ::c_int = 0; -pub const PR_MCE_KILL_EARLY: ::c_int = 1; -pub const PR_MCE_KILL_DEFAULT: ::c_int = 2; - -pub const PR_MCE_KILL_GET: ::c_int = 34; - -pub const PR_SET_MM: ::c_int = 35; -pub const PR_SET_MM_START_CODE: ::c_int = 1; -pub const PR_SET_MM_END_CODE: ::c_int = 2; -pub const PR_SET_MM_START_DATA: ::c_int = 3; -pub const PR_SET_MM_END_DATA: ::c_int = 4; -pub const PR_SET_MM_START_STACK: ::c_int = 5; -pub const PR_SET_MM_START_BRK: ::c_int = 6; -pub const PR_SET_MM_BRK: ::c_int = 7; -pub const PR_SET_MM_ARG_START: ::c_int = 8; -pub const PR_SET_MM_ARG_END: ::c_int = 9; -pub const PR_SET_MM_ENV_START: ::c_int = 10; -pub const PR_SET_MM_ENV_END: ::c_int = 11; -pub const PR_SET_MM_AUXV: ::c_int = 12; -pub const PR_SET_MM_EXE_FILE: ::c_int = 13; -pub const PR_SET_MM_MAP: ::c_int = 14; -pub const PR_SET_MM_MAP_SIZE: ::c_int = 15; - -pub const PR_SET_PTRACER: ::c_int = 0x59616d61; - -pub const PR_SET_CHILD_SUBREAPER: ::c_int = 36; -pub const PR_GET_CHILD_SUBREAPER: ::c_int = 37; - -pub const PR_SET_NO_NEW_PRIVS: ::c_int = 38; -pub const PR_GET_NO_NEW_PRIVS: ::c_int = 39; - -pub const PR_GET_TID_ADDRESS: ::c_int = 40; - -pub const PR_SET_THP_DISABLE: ::c_int = 41; -pub const PR_GET_THP_DISABLE: ::c_int = 42; - -pub const GRND_NONBLOCK: ::c_uint = 0x0001; -pub const GRND_RANDOM: ::c_uint = 0x0002; - -pub const ABDAY_1: ::nl_item = 0x300; -pub const ABDAY_2: ::nl_item = 0x301; -pub const ABDAY_3: ::nl_item = 0x302; -pub const ABDAY_4: ::nl_item = 0x303; -pub const ABDAY_5: ::nl_item = 0x304; -pub const ABDAY_6: ::nl_item = 0x305; -pub const ABDAY_7: ::nl_item = 0x306; - -pub const DAY_1: ::nl_item = 0x307; -pub const DAY_2: ::nl_item = 0x308; -pub const DAY_3: ::nl_item = 0x309; -pub const DAY_4: ::nl_item = 0x30A; -pub const DAY_5: ::nl_item = 0x30B; -pub const DAY_6: ::nl_item = 0x30C; -pub const DAY_7: ::nl_item = 0x30D; - -pub const ABMON_1: ::nl_item = 0x30E; -pub const ABMON_2: ::nl_item = 0x30F; -pub const ABMON_3: ::nl_item = 0x310; -pub const ABMON_4: ::nl_item = 0x311; -pub const ABMON_5: ::nl_item = 0x312; -pub const ABMON_6: ::nl_item = 0x313; -pub const ABMON_7: ::nl_item = 0x314; -pub const ABMON_8: ::nl_item = 0x315; -pub const ABMON_9: ::nl_item = 0x316; -pub const ABMON_10: ::nl_item = 0x317; -pub const ABMON_11: ::nl_item = 0x318; -pub const ABMON_12: ::nl_item = 0x319; - -pub const MON_1: ::nl_item = 0x31A; -pub const MON_2: ::nl_item = 0x31B; -pub const MON_3: ::nl_item = 0x31C; -pub const MON_4: ::nl_item = 0x31D; -pub const MON_5: ::nl_item = 0x31E; -pub const MON_6: ::nl_item = 0x31F; -pub const MON_7: ::nl_item = 0x320; -pub const MON_8: ::nl_item = 0x321; -pub const MON_9: ::nl_item = 0x322; -pub const MON_10: ::nl_item = 0x323; -pub const MON_11: ::nl_item = 0x324; -pub const MON_12: ::nl_item = 0x325; - -pub const AM_STR: ::nl_item = 0x326; -pub const PM_STR: ::nl_item = 0x327; - -pub const D_T_FMT: ::nl_item = 0x328; -pub const D_FMT: ::nl_item = 0x329; -pub const T_FMT: ::nl_item = 0x32A; -pub const T_FMT_AMPM: ::nl_item = 0x32B; - -pub const ERA: ::nl_item = 0x32C; -pub const ERA_D_FMT: ::nl_item = 0x32E; -pub const ALT_DIGITS: ::nl_item = 0x32F; -pub const ERA_D_T_FMT: ::nl_item = 0x330; -pub const ERA_T_FMT: ::nl_item = 0x331; - -pub const CODESET: ::nl_item = 10; - -pub const CRNCYSTR: ::nl_item = 0x215; - -pub const RADIXCHAR: ::nl_item = 0x100; -pub const THOUSEP: ::nl_item = 0x101; - -pub const NOEXPR: ::nl_item = 0x501; -pub const YESSTR: ::nl_item = 0x502; -pub const NOSTR: ::nl_item = 0x503; - -pub const FILENAME_MAX: ::c_uint = 4095; - -f! { - pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] &= !(1 << (fd % size)); - return - } - - pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0 - } - - pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { - let fd = fd as usize; - let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8; - (*set).fds_bits[fd / size] |= 1 << (fd % size); - return - } - - pub fn FD_ZERO(set: *mut fd_set) -> () { - for slot in (*set).fds_bits.iter_mut() { - *slot = 0; - } - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0xff) == 0x7f - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WIFCONTINUED(status: ::c_int) -> bool { - status == 0xffff - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - ((status & 0x7f) + 1) as i8 >= 2 - } - - pub fn WTERMSIG(status: ::c_int) -> ::c_int { - status & 0x7f - } - - pub fn WIFEXITED(status: ::c_int) -> bool { - (status & 0x7f) == 0 - } - - pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - (status >> 8) & 0xff - } - - pub fn WCOREDUMP(status: ::c_int) -> bool { - (status & 0x80) != 0 - } - - pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { - for slot in cpuset.bits.iter_mut() { - *slot = 0; - } - } - - pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits - = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] |= 1 << offset; - () - } - - pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits - = 8 * ::mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] &= !(1 << offset); - () - } - - pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * ::mem::size_of_val(&cpuset.bits[0]); - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - 0 != (cpuset.bits[idx] & (1 << offset)) - } - - pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool { - set1.bits == set2.bits - } - - pub fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int { - (cmd << 8) | (type_ & 0x00ff) - } -} - -extern "C" { - #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")] - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; - pub fn sem_init( - sem: *mut sem_t, - pshared: ::c_int, - value: ::c_uint, - ) -> ::c_int; - - pub fn abs(i: ::c_int) -> ::c_int; - pub fn atof(s: *const ::c_char) -> ::c_double; - pub fn labs(i: ::c_long) -> ::c_long; - pub fn rand() -> ::c_int; - pub fn srand(seed: ::c_uint); - - pub fn fdatasync(fd: ::c_int) -> ::c_int; - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int; - pub fn mincore( - addr: *mut ::c_void, - len: ::size_t, - vec: *mut ::c_uchar, - ) -> ::c_int; - pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int; - pub fn clock_nanosleep( - clk_id: ::clockid_t, - flags: ::c_int, - rqtp: *const ::timespec, - rmtp: *mut ::timespec, - ) -> ::c_int; - pub fn clock_settime( - clk_id: ::clockid_t, - tp: *const ::timespec, - ) -> ::c_int; - pub fn prctl(option: ::c_int, ...) -> ::c_int; - pub fn pthread_getattr_np( - native: ::pthread_t, - attr: *mut ::pthread_attr_t, - ) -> ::c_int; - pub fn pthread_attr_getguardsize( - attr: *const ::pthread_attr_t, - guardsize: *mut ::size_t, - ) -> ::c_int; - pub fn pthread_attr_getstack( - attr: *const ::pthread_attr_t, - stackaddr: *mut *mut ::c_void, - stacksize: *mut ::size_t, - ) -> ::c_int; - pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; - pub fn setgroups(ngroups: ::size_t, ptr: *const ::gid_t) -> ::c_int; - pub fn initgroups(user: *const ::c_char, group: ::gid_t) -> ::c_int; - pub fn sched_setscheduler( - pid: ::pid_t, - policy: ::c_int, - param: *const ::sched_param, - ) -> ::c_int; - pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int; - pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int; - pub fn sched_get_priority_min(policy: ::c_int) -> ::c_int; - pub fn epoll_create(size: ::c_int) -> ::c_int; - pub fn epoll_create1(flags: ::c_int) -> ::c_int; - pub fn epoll_ctl( - epfd: ::c_int, - op: ::c_int, - fd: ::c_int, - event: *mut ::epoll_event, - ) -> ::c_int; - pub fn epoll_wait( - epfd: ::c_int, - events: *mut ::epoll_event, - maxevents: ::c_int, - timeout: ::c_int, - ) -> ::c_int; - pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int; - pub fn mount( - src: *const ::c_char, - target: *const ::c_char, - fstype: *const ::c_char, - flags: ::c_ulong, - data: *const ::c_void, - ) -> ::c_int; - pub fn umount(target: *const ::c_char) -> ::c_int; - pub fn umount2(target: *const ::c_char, flags: ::c_int) -> ::c_int; - pub fn clone( - cb: extern "C" fn(*mut ::c_void) -> ::c_int, - child_stack: *mut ::c_void, - flags: ::c_int, - arg: *mut ::c_void, - ... - ) -> ::c_int; - pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int; - pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int; - pub fn memrchr( - cx: *const ::c_void, - c: ::c_int, - n: ::size_t, - ) -> *mut ::c_void; - pub fn syscall(num: ::c_long, ...) -> ::c_long; - pub fn sendfile( - out_fd: ::c_int, - in_fd: ::c_int, - offset: *mut off_t, - count: ::size_t, - ) -> ::ssize_t; - pub fn splice( - fd_in: ::c_int, - off_in: *mut ::loff_t, - fd_out: ::c_int, - off_out: *mut ::loff_t, - len: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn tee( - fd_in: ::c_int, - fd_out: ::c_int, - len: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - pub fn vmsplice( - fd: ::c_int, - iov: *const ::iovec, - nr_segs: ::size_t, - flags: ::c_uint, - ) -> ::ssize_t; - - pub fn posix_fadvise( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - advise: ::c_int, - ) -> ::c_int; - pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int; - pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int; - pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; - pub fn utimensat( - dirfd: ::c_int, - path: *const ::c_char, - times: *const ::timespec, - flag: ::c_int, - ) -> ::c_int; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn freelocale(loc: ::locale_t); - pub fn newlocale( - mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t, - ) -> ::locale_t; - pub fn uselocale(loc: ::locale_t) -> ::locale_t; - pub fn creat64(path: *const c_char, mode: mode_t) -> ::c_int; - pub fn fstat64(fildes: ::c_int, buf: *mut stat64) -> ::c_int; - pub fn fstatat64( - fildes: ::c_int, - path: *const ::c_char, - buf: *mut stat64, - flag: ::c_int, - ) -> ::c_int; - pub fn ftruncate64(fd: ::c_int, length: off64_t) -> ::c_int; - pub fn getrlimit64(resource: ::c_int, rlim: *mut rlimit64) -> ::c_int; - pub fn lseek64(fd: ::c_int, offset: off64_t, whence: ::c_int) -> off64_t; - pub fn lstat64(path: *const c_char, buf: *mut stat64) -> ::c_int; - pub fn mmap64( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - flags: ::c_int, - fd: ::c_int, - offset: off64_t, - ) -> *mut ::c_void; - pub fn open64(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; - pub fn openat64( - fd: ::c_int, - path: *const c_char, - oflag: ::c_int, - ... - ) -> ::c_int; - pub fn pread64( - fd: ::c_int, - buf: *mut ::c_void, - count: ::size_t, - offset: off64_t, - ) -> ::ssize_t; - pub fn pwrite64( - fd: ::c_int, - buf: *const ::c_void, - count: ::size_t, - offset: off64_t, - ) -> ::ssize_t; - pub fn readdir64(dirp: *mut ::DIR) -> *mut ::dirent64; - pub fn readdir64_r( - dirp: *mut ::DIR, - entry: *mut ::dirent64, - result: *mut *mut ::dirent64, - ) -> ::c_int; - pub fn setrlimit64(resource: ::c_int, rlim: *const rlimit64) -> ::c_int; - pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int; - pub fn truncate64(path: *const c_char, length: off64_t) -> ::c_int; - pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int; - - pub fn mknodat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - dev: dev_t, - ) -> ::c_int; - pub fn ppoll( - fds: *mut ::pollfd, - nfds: nfds_t, - timeout: *const ::timespec, - sigmask: *const sigset_t, - ) -> ::c_int; - pub fn pthread_condattr_getclock( - attr: *const pthread_condattr_t, - clock_id: *mut clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_setclock( - attr: *mut pthread_condattr_t, - clock_id: ::clockid_t, - ) -> ::c_int; - pub fn pthread_condattr_setpshared( - attr: *mut pthread_condattr_t, - pshared: ::c_int, - ) -> ::c_int; - pub fn pthread_condattr_getpshared( - attr: *const pthread_condattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - pub fn sched_getaffinity( - pid: ::pid_t, - cpusetsize: ::size_t, - cpuset: *mut cpu_set_t, - ) -> ::c_int; - pub fn sched_setaffinity( - pid: ::pid_t, - cpusetsize: ::size_t, - cpuset: *const cpu_set_t, - ) -> ::c_int; - pub fn unshare(flags: ::c_int) -> ::c_int; - pub fn sem_timedwait( - sem: *mut sem_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; - pub fn accept4( - fd: ::c_int, - addr: *mut ::sockaddr, - len: *mut ::socklen_t, - flg: ::c_int, - ) -> ::c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - pub fn pthread_mutexattr_setpshared( - attr: *mut pthread_mutexattr_t, - pshared: ::c_int, - ) -> ::c_int; - pub fn pthread_mutexattr_getpshared( - attr: *const pthread_mutexattr_t, - pshared: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_getkind_np( - attr: *const pthread_rwlockattr_t, - val: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_setkind_np( - attr: *mut pthread_rwlockattr_t, - val: ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_getpshared( - attr: *const pthread_rwlockattr_t, - val: *mut ::c_int, - ) -> ::c_int; - pub fn pthread_rwlockattr_setpshared( - attr: *mut pthread_rwlockattr_t, - val: ::c_int, - ) -> ::c_int; - pub fn ptsname_r( - fd: ::c_int, - buf: *mut ::c_char, - buflen: ::size_t, - ) -> ::c_int; - pub fn clearenv() -> ::c_int; - pub fn waitid( - idtype: idtype_t, - id: id_t, - infop: *mut ::siginfo_t, - options: ::c_int, - ) -> ::c_int; - - pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; - - pub fn setpwent(); - pub fn endpwent(); - pub fn getpwent() -> *mut passwd; - pub fn setspent(); - pub fn endspent(); - pub fn getspent() -> *mut spwd; - pub fn getspnam(__name: *const ::c_char) -> *mut spwd; - - pub fn shm_open( - name: *const c_char, - oflag: ::c_int, - mode: mode_t, - ) -> ::c_int; - - // System V IPC - pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int; - pub fn shmat( - shmid: ::c_int, - shmaddr: *const ::c_void, - shmflg: ::c_int, - ) -> *mut ::c_void; - pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int; - pub fn shmctl( - shmid: ::c_int, - cmd: ::c_int, - buf: *mut ::shmid_ds, - ) -> ::c_int; - pub fn ftok(pathname: *const ::c_char, proj_id: ::c_int) -> ::key_t; - pub fn msgctl(msqid: ::c_int, cmd: ::c_int, buf: *mut msqid_ds) - -> ::c_int; - pub fn msgget(key: ::key_t, msgflg: ::c_int) -> ::c_int; - pub fn msgrcv( - msqid: ::c_int, - msgp: *mut ::c_void, - msgsz: ::size_t, - msgtyp: ::c_long, - msgflg: ::c_int, - ) -> ::ssize_t; - pub fn msgsnd( - msqid: ::c_int, - msgp: *const ::c_void, - msgsz: ::size_t, - msgflg: ::c_int, - ) -> ::c_int; - - pub fn mprotect( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - ) -> ::c_int; - pub fn __errno_location() -> *mut ::c_int; - - pub fn fopen64( - filename: *const c_char, - mode: *const c_char, - ) -> *mut ::FILE; - pub fn freopen64( - filename: *const c_char, - mode: *const c_char, - file: *mut ::FILE, - ) -> *mut ::FILE; - pub fn tmpfile64() -> *mut ::FILE; - pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int; - pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int; - pub fn fseeko64( - stream: *mut ::FILE, - offset: ::off64_t, - whence: ::c_int, - ) -> ::c_int; - pub fn ftello64(stream: *mut ::FILE) -> ::off64_t; - pub fn readahead( - fd: ::c_int, - offset: ::off64_t, - count: ::size_t, - ) -> ::ssize_t; - pub fn getxattr( - path: *const c_char, - name: *const c_char, - value: *mut ::c_void, - size: ::size_t, - ) -> ::ssize_t; - pub fn lgetxattr( - path: *const c_char, - name: *const c_char, - value: *mut ::c_void, - size: ::size_t, - ) -> ::ssize_t; - pub fn fgetxattr( - filedes: ::c_int, - name: *const c_char, - value: *mut ::c_void, - size: ::size_t, - ) -> ::ssize_t; - pub fn setxattr( - path: *const c_char, - name: *const c_char, - value: *const ::c_void, - size: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn lsetxattr( - path: *const c_char, - name: *const c_char, - value: *const ::c_void, - size: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn fsetxattr( - filedes: ::c_int, - name: *const c_char, - value: *const ::c_void, - size: ::size_t, - flags: ::c_int, - ) -> ::c_int; - pub fn listxattr( - path: *const c_char, - list: *mut c_char, - size: ::size_t, - ) -> ::ssize_t; - pub fn llistxattr( - path: *const c_char, - list: *mut c_char, - size: ::size_t, - ) -> ::ssize_t; - pub fn flistxattr( - filedes: ::c_int, - list: *mut c_char, - size: ::size_t, - ) -> ::ssize_t; - pub fn removexattr(path: *const c_char, name: *const c_char) -> ::c_int; - pub fn lremovexattr(path: *const c_char, name: *const c_char) -> ::c_int; - pub fn fremovexattr(filedes: ::c_int, name: *const c_char) -> ::c_int; - pub fn signalfd( - fd: ::c_int, - mask: *const ::sigset_t, - flags: ::c_int, - ) -> ::c_int; - pub fn quotactl( - cmd: ::c_int, - special: *const ::c_char, - id: ::c_int, - data: *mut ::c_char, - ) -> ::c_int; - pub fn mq_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::mqd_t; - pub fn mq_close(mqd: ::mqd_t) -> ::c_int; - pub fn mq_unlink(name: *const ::c_char) -> ::c_int; - pub fn mq_receive( - mqd: ::mqd_t, - msg_ptr: *mut ::c_char, - msg_len: ::size_t, - msg_prio: *mut ::c_uint, - ) -> ::ssize_t; - pub fn mq_send( - mqd: ::mqd_t, - msg_ptr: *const ::c_char, - msg_len: ::size_t, - msg_prio: ::c_uint, - ) -> ::c_int; - pub fn mq_getattr(mqd: ::mqd_t, attr: *mut ::mq_attr) -> ::c_int; - pub fn mq_setattr( - mqd: ::mqd_t, - newattr: *const ::mq_attr, - oldattr: *mut ::mq_attr, - ) -> ::c_int; - pub fn epoll_pwait( - epfd: ::c_int, - events: *mut ::epoll_event, - maxevents: ::c_int, - timeout: ::c_int, - sigmask: *const ::sigset_t, - ) -> ::c_int; - pub fn sethostname(name: *const ::c_char, len: ::size_t) -> ::c_int; - pub fn sigtimedwait( - set: *const sigset_t, - info: *mut siginfo_t, - timeout: *const ::timespec, - ) -> ::c_int; - pub fn sigwaitinfo(set: *const sigset_t, info: *mut siginfo_t) -> ::c_int; - pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) - -> *mut ::c_char; - pub fn prlimit( - pid: ::pid_t, - resource: ::c_int, - new_limit: *const ::rlimit, - old_limit: *mut ::rlimit, - ) -> ::c_int; - pub fn prlimit64( - pid: ::pid_t, - resource: ::c_int, - new_limit: *const ::rlimit64, - old_limit: *mut ::rlimit64, - ) -> ::c_int; - pub fn reboot(how_to: ::c_int) -> ::c_int; - pub fn setfsgid(gid: ::gid_t) -> ::c_int; - pub fn setfsuid(uid: ::uid_t) -> ::c_int; - pub fn setresgid(rgid: ::gid_t, egid: ::gid_t, sgid: ::gid_t) -> ::c_int; - pub fn setresuid(ruid: ::uid_t, euid: ::uid_t, suid: ::uid_t) -> ::c_int; - - // Not available now on Android - pub fn mkfifoat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - pub fn if_nameindex() -> *mut if_nameindex; - pub fn if_freenameindex(ptr: *mut if_nameindex); - pub fn sync_file_range( - fd: ::c_int, - offset: ::off64_t, - nbytes: ::off64_t, - flags: ::c_uint, - ) -> ::c_int; - pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; - pub fn freeifaddrs(ifa: *mut ::ifaddrs); - - pub fn mremap( - addr: *mut ::c_void, - len: ::size_t, - new_len: ::size_t, - flags: ::c_int, - ... - ) -> *mut ::c_void; - - pub fn glob( - pattern: *const c_char, - flags: ::c_int, - errfunc: ::Option< - extern "C" fn(epath: *const c_char, errno: ::c_int) -> ::c_int, - >, - pglob: *mut ::glob_t, - ) -> ::c_int; - pub fn globfree(pglob: *mut ::glob_t); - - pub fn shm_unlink(name: *const ::c_char) -> ::c_int; - - pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long); - - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - - pub fn telldir(dirp: *mut ::DIR) -> ::c_long; - pub fn madvise( - addr: *mut ::c_void, - len: ::size_t, - advice: ::c_int, - ) -> ::c_int; - - pub fn msync( - addr: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::c_int; - - pub fn recvfrom( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::ssize_t; - pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; - - pub fn bind( - socket: ::c_int, - address: *const ::sockaddr, - address_len: ::socklen_t, - ) -> ::c_int; - - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - - pub fn sendmsg( - fd: ::c_int, - msg: *const ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - pub fn recvmsg( - fd: ::c_int, - msg: *mut ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")] - pub fn getgrgid_r( - gid: ::gid_t, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigaltstack$UNIX2003" - )] - #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] - pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int; - pub fn sem_close(sem: *mut sem_t) -> ::c_int; - pub fn getdtablesize() -> ::c_int; - #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")] - pub fn getgrnam_r( - name: *const ::c_char, - grp: *mut ::group, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut ::group, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "pthread_sigmask$UNIX2003" - )] - pub fn pthread_sigmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t; - pub fn getgrnam(name: *const ::c_char) -> *mut ::group; - pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int; - pub fn sem_unlink(name: *const ::c_char) -> ::c_int; - pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")] - pub fn getpwnam_r( - name: *const ::c_char, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] - #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")] - pub fn getpwuid_r( - uid: ::uid_t, - pwd: *mut passwd, - buf: *mut ::c_char, - buflen: ::size_t, - result: *mut *mut passwd, - ) -> ::c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "sigwait$UNIX2003" - )] - #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")] - pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int; - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - pub fn pthread_create( - native: *mut ::pthread_t, - attr: *const ::pthread_attr_t, - f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - pub fn getgrgid(gid: ::gid_t) -> *mut ::group; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "popen$UNIX2003" - )] - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - pub fn uname(buf: *mut ::utsname) -> ::c_int; -} - -cfg_if! { - if #[cfg(any(target_arch = "mips", target_arch = "mips64"))] { - mod mips; - pub use self::mips::*; - } else if #[cfg(target_arch = "x86_64")] { - mod x86_64; - pub use self::x86_64::*; - } else if #[cfg(target_arch = "arm")] { - mod arm; - pub use self::arm::*; - } else { - pub use unsupported_target; - } -} - -cfg_if! { - if #[cfg(libc_align)] { - #[macro_use] - mod align; - } else { - #[macro_use] - mod no_align; - } -} - -expand_align!(); diff --git a/libc/src/unix/uclibc/no_align.rs b/libc/src/unix/uclibc/no_align.rs deleted file mode 100644 index a73dbde..0000000 --- a/libc/src/unix/uclibc/no_align.rs +++ /dev/null @@ -1,53 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - pub struct pthread_mutex_t { - #[cfg(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))] - __align: [::c_long; 0], - #[cfg(any(libc_align, - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - pub struct pthread_rwlock_t { - #[cfg(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))] - __align: [::c_long; 0], - #[cfg(not(any( - target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - - pub struct pthread_mutexattr_t { - #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))] - __align: [::c_int; 0], - #[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")))] - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - pub struct pthread_cond_t { - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - pub struct pthread_condattr_t { - __align: [::c_int; 0], - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - } -} diff --git a/libc/src/unix/uclibc/x86_64/align.rs b/libc/src/unix/uclibc/x86_64/align.rs deleted file mode 100644 index 583a278..0000000 --- a/libc/src/unix/uclibc/x86_64/align.rs +++ /dev/null @@ -1,77 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - #[cfg_attr(target_pointer_width = "32", - repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", - repr(align(8)))] - pub struct sem_t { // ToDo - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - } - - #[cfg_attr(any(target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64"), - repr(align(4)))] - #[cfg_attr(not(any(target_pointer_width = "32", - target_arch = "x86_64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64")), - repr(align(8)))] - pub struct pthread_mutexattr_t { // ToDo - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - #[repr(align(4))] - pub struct pthread_condattr_t { // ToDo - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - } - - s_no_extra_traits! { - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(all(any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))), - repr(align(8)))] - #[allow(missing_debug_implementations)] - pub struct pthread_mutex_t { // ToDo - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - #[repr(align(8))] - #[allow(missing_debug_implementations)] - pub struct pthread_cond_t { // ToDo - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - #[cfg_attr(all(target_pointer_width = "32", - any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")), - repr(align(4)))] - #[cfg_attr(any(target_pointer_width = "64", - not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))), - repr(align(8)))] - #[allow(missing_debug_implementations)] - pub struct pthread_rwlock_t { // ToDo - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - } - }; -} diff --git a/libc/src/unix/uclibc/x86_64/l4re.rs b/libc/src/unix/uclibc/x86_64/l4re.rs deleted file mode 100644 index 16ec0ef..0000000 --- a/libc/src/unix/uclibc/x86_64/l4re.rs +++ /dev/null @@ -1,48 +0,0 @@ -/// L4Re specifics -/// This module contains definitions required by various L4Re libc backends. -/// Some of them are formally not part of the libc, but are a dependency of the -/// libc and hence we should provide them here. - -pub type l4_umword_t = ::c_ulong; // Unsigned machine word. -pub type pthread_t = *mut ::c_void; - -s! { - /// CPU sets. - pub struct l4_sched_cpu_set_t { - // from the L4Re docs - /// Combination of granularity and offset. - /// - /// The granularity defines how many CPUs each bit in map describes. - /// The offset is the numer of the first CPU described by the first - /// bit in the bitmap. - /// offset must be a multiple of 2^graularity. - /// - /// | MSB | LSB | - /// | ---------------- | ------------------- | - /// | 8bit granularity | 24bit offset .. | - gran_offset: l4_umword_t , - /// Bitmap of CPUs. - map: l4_umword_t , - } -} - -#[cfg(target_os = "l4re")] -#[allow(missing_debug_implementations)] -pub struct pthread_attr_t { - pub __detachstate: ::c_int, - pub __schedpolicy: ::c_int, - pub __schedparam: super::__sched_param, - pub __inheritsched: ::c_int, - pub __scope: ::c_int, - pub __guardsize: ::size_t, - pub __stackaddr_set: ::c_int, - pub __stackaddr: *mut ::c_void, // better don't use it - pub __stacksize: ::size_t, - // L4Re specifics - pub affinity: l4_sched_cpu_set_t, - pub create_flags: ::c_uint, -} - -// L4Re requires a min stack size of 64k; that isn't defined in uClibc, but -// somewhere in the core libraries. uClibc wants 16k, but that's not enough. -pub const PTHREAD_STACK_MIN: usize = 65536; diff --git a/libc/src/unix/uclibc/x86_64/mod.rs b/libc/src/unix/uclibc/x86_64/mod.rs deleted file mode 100644 index a8bb079..0000000 --- a/libc/src/unix/uclibc/x86_64/mod.rs +++ /dev/null @@ -1,312 +0,0 @@ -//! Definitions for uclibc on 64bit systems -pub type blkcnt_t = i64; -pub type blksize_t = i64; -pub type clock_t = i64; -pub type c_char = u8; -pub type c_long = i64; -pub type c_ulong = u64; -pub type fsblkcnt_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; -pub type fsword_t = ::c_long; -pub type ino_t = ::c_ulong; -pub type nlink_t = ::c_uint; -pub type off_t = ::c_long; -pub type rlim_t = c_ulong; -pub type rlim64_t = u64; -// [uClibc docs] Note stat64 has the same shape as stat for x86-64. -pub type stat64 = stat; -pub type suseconds_t = ::c_long; -pub type time_t = ::c_int; -pub type wchar_t = ::c_int; - -s! { - pub struct ipc_perm { - pub __key: ::key_t, - pub uid: ::uid_t, - pub gid: ::gid_t, - pub cuid: ::uid_t, - pub cgid: ::gid_t, - pub mode: ::c_ushort, // read / write - __pad1: ::c_ushort, - pub __seq: ::c_ushort, - __pad2: ::c_ushort, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - #[cfg(not(target_os = "l4re"))] - pub struct pthread_attr_t { - __detachstate: ::c_int, - __schedpolicy: ::c_int, - __schedparam: __sched_param, - __inheritsched: ::c_int, - __scope: ::c_int, - __guardsize: ::size_t, - __stackaddr_set: ::c_int, - __stackaddr: *mut ::c_void, // better don't use it - __stacksize: ::size_t, - } - - pub struct __sched_param { - __sched_priority: ::c_int, - } - - pub struct siginfo_t { - si_signo: ::c_int, // signal number - si_errno: ::c_int, // if not zero: error value of signal, see errno.h - si_code: ::c_int, // signal code - pub _pad: [::c_int; 28], // unported union - _align: [usize; 0], - } - - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, // segment size in bytes - pub shm_atime: ::time_t, // time of last shmat() - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::shmatt_t, - __unused1: ::c_ulong, - __unused2: ::c_ulong - } - - pub struct msqid_ds { - pub msg_perm: ::ipc_perm, - pub msg_stime: ::time_t, - pub msg_rtime: ::time_t, - pub msg_ctime: ::time_t, - __msg_cbytes: ::c_ulong, - pub msg_qnum: ::msgqnum_t, - pub msg_qbytes: ::msglen_t, - pub msg_lspid: ::pid_t, - pub msg_lrpid: ::pid_t, - __ignored1: ::c_ulong, - __ignored2: ::c_ulong, - } - - pub struct sockaddr { - pub sa_family: ::sa_family_t, - pub sa_data: [::c_char; 14], - } - - pub struct sockaddr_in { - pub sin_family: ::sa_family_t, - pub sin_port: ::in_port_t, - pub sin_addr: ::in_addr, - pub sin_zero: [u8; 8], - } - - pub struct sockaddr_in6 { - pub sin6_family: ::sa_family_t, - pub sin6_port: ::in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: ::in6_addr, - pub sin6_scope_id: u32, - } - - // ------------------------------------------------------------ - // definitions below are *unverified* and might **break** the software -// pub struct in_addr { -// pub s_addr: in_addr_t, -// } -// -// pub struct in6_addr { -// pub s6_addr: [u8; 16], -// #[cfg(not(libc_align))] -// __align: [u32; 0], -// } - - pub struct stat { - pub st_dev: ::c_ulong, - pub st_ino: ::ino_t, - // According to uclibc/libc/sysdeps/linux/x86_64/bits/stat.h, order of - // nlink and mode are swapped on 64 bit systems. - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::c_ulong, // dev_t - pub st_size: off_t, // file size - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_ulong, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_ulong, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_ulong, - st_pad4: [::c_long; 3] - } - - pub struct sigaction { - pub sa_handler: ::sighandler_t, - pub sa_flags: ::c_ulong, - pub sa_restorer: *mut ::c_void, - pub sa_mask: ::sigset_t, - } - - pub struct stack_t { // ToDo - pub ss_sp: *mut ::c_void, - pub ss_flags: ::c_int, - pub ss_size: ::size_t - } - - pub struct statfs { // ToDo - pub f_type: fsword_t, - pub f_bsize: fsword_t, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_fsid: ::fsid_t, - pub f_namelen: fsword_t, - pub f_frsize: fsword_t, - f_spare: [fsword_t; 5], - } - - pub struct msghdr { // ToDo - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::size_t, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::size_t, - pub msg_flags: ::c_int, - } - - pub struct termios { // ToDo - pub c_iflag: ::tcflag_t, - pub c_oflag: ::tcflag_t, - pub c_cflag: ::tcflag_t, - pub c_lflag: ::tcflag_t, - pub c_line: ::cc_t, - pub c_cc: [::cc_t; ::NCCS], - } - - pub struct sigset_t { // ToDo - __val: [::c_ulong; 16], - } - - pub struct sysinfo { // ToDo - pub uptime: ::c_long, - pub loads: [::c_ulong; 3], - pub totalram: ::c_ulong, - pub freeram: ::c_ulong, - pub sharedram: ::c_ulong, - pub bufferram: ::c_ulong, - pub totalswap: ::c_ulong, - pub freeswap: ::c_ulong, - pub procs: ::c_ushort, - pub pad: ::c_ushort, - pub totalhigh: ::c_ulong, - pub freehigh: ::c_ulong, - pub mem_unit: ::c_uint, - pub _f: [::c_char; 0], - } - - pub struct glob_t { // ToDo - pub gl_pathc: ::size_t, - pub gl_pathv: *mut *mut c_char, - pub gl_offs: ::size_t, - pub gl_flags: ::c_int, - __unused1: *mut ::c_void, - __unused2: *mut ::c_void, - __unused3: *mut ::c_void, - __unused4: *mut ::c_void, - __unused5: *mut ::c_void, - } - - pub struct rlimit64 { // ToDo - pub rlim_cur: rlim64_t, - pub rlim_max: rlim64_t, - } - - pub struct cpu_set_t { // ToDo - #[cfg(target_pointer_width = "32")] - bits: [u32; 32], - #[cfg(target_pointer_width = "64")] - bits: [u64; 16], - } - - pub struct fsid_t { // ToDo - __val: [::c_int; 2], - } -} - -s_no_extra_traits! { - #[allow(missing_debug_implementations)] - pub struct dirent { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: u16, - pub d_type: u8, - pub d_name: [::c_char; 256], - } - #[allow(missing_debug_implementations)] - pub struct dirent64 { - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: u16, - pub d_type: u8, - pub d_name: [::c_char; 256], - } -} - -// constants -pub const EADDRINUSE: ::c_int = 98; // Address already in use -pub const EADDRNOTAVAIL: ::c_int = 99; // Cannot assign requested address -pub const ECONNABORTED: ::c_int = 103; // Software caused connection abort -pub const ECONNREFUSED: ::c_int = 111; // Connection refused -pub const ECONNRESET: ::c_int = 104; // Connection reset by peer -pub const EDEADLK: ::c_int = 35; // Resource deadlock would occur -pub const ENOSYS: ::c_int = 38; // Function not implemented -pub const ENOTCONN: ::c_int = 107; // Transport endpoint is not connected -pub const ETIMEDOUT: ::c_int = 110; // connection timed out -pub const O_APPEND: ::c_int = 02000; -pub const O_ACCMODE: ::c_int = 0003; -pub const O_CLOEXEC: ::c_int = 0x80000; -pub const O_CREAT: ::c_int = 0100; -pub const O_DIRECTORY: ::c_int = 0200000; -pub const O_EXCL: ::c_int = 0200; -pub const O_NONBLOCK: ::c_int = 04000; -pub const O_TRUNC: ::c_int = 01000; -pub const NCCS: usize = 32; -pub const SIG_SETMASK: ::c_int = 2; // Set the set of blocked signals -pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; -pub const SO_BROADCAST: ::c_int = 6; -pub const SOCK_DGRAM: ::c_int = 2; // connectionless, unreliable datagrams -pub const SOCK_STREAM: ::c_int = 1; // …/common/bits/socket_type.h -pub const SO_ERROR: ::c_int = 4; -pub const SOL_SOCKET: ::c_int = 1; -pub const SO_RCVTIMEO: ::c_int = 20; -pub const SO_REUSEADDR: ::c_int = 2; -pub const SO_SNDTIMEO: ::c_int = 21; -pub const RLIM_INFINITY: u64 = 0xffffffffffffffff; -pub const __SIZEOF_PTHREAD_COND_T: usize = 48; -pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; -pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; - -cfg_if! { - if #[cfg(target_os = "l4re")] { - mod l4re; - pub use self::l4re::*; - } else { - mod other; - pub use other::*; - } -} - -cfg_if! { - if #[cfg(libc_align)] { - #[macro_use] - mod align; - } else { - #[macro_use] - mod no_align; - } -} -expand_align!(); diff --git a/libc/src/unix/uclibc/x86_64/no_align.rs b/libc/src/unix/uclibc/x86_64/no_align.rs deleted file mode 100644 index 422d78f..0000000 --- a/libc/src/unix/uclibc/x86_64/no_align.rs +++ /dev/null @@ -1,59 +0,0 @@ -macro_rules! expand_align { - () => { - s! { - pub struct sem_t { // ToDo - #[cfg(target_pointer_width = "32")] - __size: [::c_char; 16], - #[cfg(target_pointer_width = "64")] - __size: [::c_char; 32], - __align: [::c_long; 0], - } - - pub struct pthread_mutex_t { // ToDo - #[cfg(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))] - __align: [::c_long; 0], - #[cfg(not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T], - } - - pub struct pthread_mutexattr_t { // ToDo - #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64"))] - __align: [::c_int; 0], - #[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64", - target_arch = "mips64", target_arch = "s390x", - target_arch = "sparc64")))] - __align: [::c_long; 0], - size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T], - } - - pub struct pthread_cond_t { // ToDo - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_COND_T], - } - - pub struct pthread_condattr_t { // ToDo - __align: [::c_int; 0], - size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T], - } - - pub struct pthread_rwlock_t { // ToDo - #[cfg(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc"))] - __align: [::c_long; 0], - #[cfg(not(any(target_arch = "mips", - target_arch = "arm", - target_arch = "powerpc")))] - __align: [::c_longlong; 0], - size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T], - } - } - } -} diff --git a/libc/src/unix/uclibc/x86_64/other.rs b/libc/src/unix/uclibc/x86_64/other.rs deleted file mode 100644 index 481577c..0000000 --- a/libc/src/unix/uclibc/x86_64/other.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Thestyle checker discourages the use of #[cfg], so this has to go into a -// separate module -pub type pthread_t = ::c_ulong; - -pub const PTHREAD_STACK_MIN: usize = 16384; diff --git a/libc/src/vxworks/aarch64.rs b/libc/src/vxworks/aarch64.rs deleted file mode 100644 index 4032488..0000000 --- a/libc/src/vxworks/aarch64.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; -pub type c_long = i64; -pub type c_ulong = u64; diff --git a/libc/src/vxworks/arm.rs b/libc/src/vxworks/arm.rs deleted file mode 100644 index 5524006..0000000 --- a/libc/src/vxworks/arm.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/libc/src/vxworks/mod.rs b/libc/src/vxworks/mod.rs deleted file mode 100755 index a086ded..0000000 --- a/libc/src/vxworks/mod.rs +++ /dev/null @@ -1,2086 +0,0 @@ -//! Interface to VxWorks C library - -use core::mem::size_of; -use core::ptr::null_mut; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum DIR {} -impl ::Copy for DIR {} -impl ::Clone for DIR { - fn clone(&self) -> DIR { - *self - } -} - -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type uintptr_t = usize; -pub type intptr_t = isize; -pub type ptrdiff_t = isize; -pub type size_t = ::uintptr_t; -pub type ssize_t = ::intptr_t; - -pub type pid_t = ::c_int; -pub type in_addr_t = u32; -pub type sighandler_t = ::size_t; -pub type cpuset_t = u32; - -pub type blkcnt_t = ::c_long; -pub type blksize_t = ::c_long; -pub type ino_t = ::c_ulong; - -pub type rlim_t = ::c_ulong; -pub type suseconds_t = ::c_long; -pub type time_t = ::c_long; - -pub type errno_t = ::c_int; - -pub type useconds_t = ::c_ulong; - -pub type socklen_t = ::c_uint; - -pub type pthread_t = ::c_ulong; - -pub type clockid_t = ::c_int; - -//defined for the structs -pub type dev_t = ::c_ulong; -pub type mode_t = ::c_int; -pub type nlink_t = ::c_ulong; -pub type uid_t = ::c_ushort; -pub type gid_t = ::c_ushort; -pub type sigset_t = ::c_ulonglong; -pub type key_t = ::c_long; - -pub type nfds_t = ::c_uint; -pub type stat64 = ::stat; - -pub type pthread_key_t = ::c_ulong; - -// From b_off_t.h -pub type off_t = ::c_longlong; -pub type off64_t = off_t; - -// From b_BOOL.h -pub type BOOL = ::c_int; - -// From vxWind.h .. -pub type _Vx_OBJ_HANDLE = ::c_int; -pub type _Vx_TASK_ID = ::_Vx_OBJ_HANDLE; -pub type _Vx_MSG_Q_ID = ::_Vx_OBJ_HANDLE; -pub type _Vx_SEM_ID_KERNEL = ::_Vx_OBJ_HANDLE; -pub type _Vx_RTP_ID = ::_Vx_OBJ_HANDLE; -pub type _Vx_SD_ID = ::_Vx_OBJ_HANDLE; -pub type _Vx_CONDVAR_ID = ::_Vx_OBJ_HANDLE; -pub type _Vx_SEM_ID = *mut ::_Vx_semaphore; -pub type OBJ_HANDLE = ::_Vx_OBJ_HANDLE; -pub type TASK_ID = ::OBJ_HANDLE; -pub type MSG_Q_ID = ::OBJ_HANDLE; -pub type SEM_ID_KERNEL = ::OBJ_HANDLE; -pub type RTP_ID = ::OBJ_HANDLE; -pub type SD_ID = ::OBJ_HANDLE; -pub type CONDVAR_ID = ::OBJ_HANDLE; - -// From vxTypes.h -pub type _Vx_usr_arg_t = isize; -pub type _Vx_exit_code_t = isize; -pub type _Vx_ticks_t = ::c_uint; -pub type _Vx_ticks64_t = ::c_ulonglong; - -pub type sa_family_t = ::c_uchar; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum _Vx_semaphore {} -impl ::Copy for _Vx_semaphore {} -impl ::Clone for _Vx_semaphore { - fn clone(&self) -> _Vx_semaphore { - *self - } -} - -s! { - // b_pthread_condattr_t.h - pub struct pthread_condattr_t { - pub condAttrStatus: ::c_int, - pub condAttrPshared: ::c_int, - pub condAttrClockId: ::clockid_t, - } - - // b_pthread_cond_t.h - pub struct pthread_cond_t{ - pub condSemId: ::_Vx_SEM_ID, - pub condValid: ::c_int, - pub condInitted: ::c_int, - pub condRefCount: ::c_int, - pub condMutex: *mut ::pthread_mutex_t, - pub condAttr: ::pthread_condattr_t, - pub condSemName: [::c_char; _PTHREAD_SHARED_SEM_NAME_MAX] - } - - // b_pthread_rwlockattr_t.h - pub struct pthread_rwlockattr_t { - pub rwlockAttrStatus: ::c_int, - pub rwlockAttrPshared: ::c_int, - pub rwlockAttrMaxReaders: ::c_uint, - pub rwlockAttrConformOpt: ::c_uint, - } - - // b_pthread_rwlock_t.h - pub struct pthread_rwlock_t { - pub rwlockSemId: :: _Vx_SEM_ID, - pub rwlockReadersRefCount: ::c_uint, - pub rwlockValid: ::c_int, - pub rwlockInitted: ::c_int, - pub rwlockAttr: ::pthread_rwlockattr_t, - pub rwlockSemName: [::c_char; _PTHREAD_SHARED_SEM_NAME_MAX] - } - - // b_struct_timeval.h - pub struct timeval { - pub tv_sec: ::time_t, - pub tv_usec: ::suseconds_t, - } - - // socket.h - pub struct linger { - pub l_onoff: ::c_int, - pub l_linger: ::c_int, - } - - pub struct sockaddr { - pub sa_len : ::c_uchar, - pub sa_family : sa_family_t, - pub sa_data : [::c_char; 14], - } - - pub struct iovec { - pub iov_base: *mut ::c_void, - pub iov_len: ::size_t, - } - - pub struct msghdr { - pub msg_name: *mut c_void, - pub msg_namelen: socklen_t, - pub msg_iov: *mut iovec, - pub msg_iovlen: ::c_int, - pub msg_control: *mut c_void, - pub msg_controllen: socklen_t, - pub msg_flags: ::c_int, - } - - pub struct cmsghdr { - pub cmsg_len: socklen_t, - pub cmsg_level: ::c_int, - pub cmsg_type: ::c_int, - } - - // poll.h - pub struct pollfd { - pub fd : ::c_int, - pub events : ::c_short, - pub revents : ::c_short, - } - - // resource.h - pub struct rlimit { - pub rlim_cur : ::rlim_t, - pub rlim_max : ::rlim_t, - } - - // stat.h - pub struct stat { - pub st_dev : ::dev_t, - pub st_ino : ::ino_t, - pub st_mode : ::mode_t, - pub st_nlink : ::nlink_t, - pub st_uid : ::uid_t, - pub st_gid : ::gid_t, - pub st_rdev : ::dev_t, - pub st_size : ::off_t, - pub st_atime : ::time_t, - pub st_mtime : ::time_t, - pub st_ctime : ::time_t, - pub st_blksize : ::blksize_t, - pub st_blocks : ::blkcnt_t, - pub st_attrib : ::c_uchar, - pub st_reserved1 : ::c_int, - pub st_reserved2 : ::c_int, - pub st_reserved3 : ::c_int, - pub st_reserved4 : ::c_int, - } - - //b_struct__Timespec.h - pub struct _Timespec { - pub tv_sec : ::time_t, - pub tv_nsec : ::c_long, - } - - // b_struct__Sched_param.h - pub struct _Sched_param { - pub sched_priority: ::c_int, /* scheduling priority */ - pub sched_ss_low_priority: ::c_int, /* low scheduling priority */ - pub sched_ss_repl_period: ::_Timespec, /* replenishment period */ - pub sched_ss_init_budget: ::_Timespec, /* initial budget */ - pub sched_ss_max_repl: ::c_int, /* max pending replenishment */ - - } - - // b_pthread_attr_t.h - pub struct pthread_attr_t { - pub threadAttrStatus : ::c_int, - pub threadAttrStacksize : ::size_t, - pub threadAttrStackaddr : *mut ::c_void, - pub threadAttrGuardsize : ::size_t, - pub threadAttrDetachstate : ::c_int, - pub threadAttrContentionscope : ::c_int, - pub threadAttrInheritsched : ::c_int, - pub threadAttrSchedpolicy : ::c_int, - pub threadAttrName : *mut ::c_char, - pub threadAttrOptions : ::c_int, - pub threadAttrSchedparam : ::_Sched_param, - } - - // signal.h - - pub struct sigaction { - pub sa_u : ::sa_u_t, - pub sa_mask : ::sigset_t, - pub sa_flags : ::c_int, - } - - // b_stack_t.h - pub struct stack_t { - pub ss_sp : *mut ::c_void, - pub ss_size : ::size_t, - pub ss_flags : ::c_int, - } - - // signal.h - pub struct siginfo_t { - pub si_signo : ::c_int, - pub si_code : ::c_int, - pub si_value : ::sigval, - pub si_errno : ::c_int, - pub si_status: ::c_int, - pub si_addr: *mut ::c_void, - pub si_uid: ::uid_t, - pub si_pid: ::pid_t, - } - - // pthread.h (krnl) - // b_pthread_mutexattr_t.h (usr) - pub struct pthread_mutexattr_t { - mutexAttrStatus : ::c_int, - mutexAttrPshared : ::c_int, - mutexAttrProtocol : ::c_int, - mutexAttrPrioceiling : ::c_int, - mutexAttrType : ::c_int, - } - - // pthread.h (krnl) - // b_pthread_mutex_t.h (usr) - pub struct pthread_mutex_t { - pub mutexSemId: ::_Vx_SEM_ID, /*_Vx_SEM_ID ..*/ - pub mutexValid: ::c_int, - pub mutexInitted: ::c_int, - pub mutexCondRefCount: ::c_int, - pub mutexSavPriority: ::c_int, - pub mutexAttr: ::pthread_mutexattr_t, - pub mutexSemName: [::c_char; _PTHREAD_SHARED_SEM_NAME_MAX], - } - - // b_struct_timespec.h - pub struct timespec { - pub tv_sec: ::time_t, - pub tv_nsec: ::c_long, - } - - // time.h - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - } - - // in.h - pub struct in_addr { - pub s_addr: in_addr_t, - } - - // in.h - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - // in6.h - #[repr(align(4))] - pub struct in6_addr { - pub s6_addr: [u8; 16], - } - - // in6.h - pub struct ipv6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: ::c_uint, - } - - // netdb.h - pub struct addrinfo { - pub ai_flags : ::c_int, - pub ai_family : ::c_int, - pub ai_socktype : ::c_int, - pub ai_protocol : ::c_int, - pub ai_addrlen : ::size_t, - pub ai_canonname: *mut ::c_char, - pub ai_addr : *mut ::sockaddr, - pub ai_next : *mut ::addrinfo, - } - - // in.h - pub struct sockaddr_in { - pub sin_len : u8, - pub sin_family: u8, - pub sin_port : u16, - pub sin_addr : ::in_addr, - pub sin_zero : [::c_char; 8], - } - - // in6.h - pub struct sockaddr_in6 { - pub sin6_len : u8, - pub sin6_family : u8, - pub sin6_port : u16, - pub sin6_flowinfo: u32, - pub sin6_addr : ::in6_addr, - pub sin6_scope_id: u32, - } - - pub struct Dl_info { - pub dli_fname: *const ::c_char, - pub dli_fbase: *mut ::c_void, - pub dli_sname: *const ::c_char, - pub dli_saddr: *mut ::c_void, - } -} - -s_no_extra_traits! { - // dirent.h - pub struct dirent { - pub d_ino : ::ino_t, - pub d_name : [::c_char; _PARM_NAME_MAX as usize + 1], - } - - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 104] - } - - // rtpLibCommon.h - pub struct RTP_DESC { - pub status : ::c_int, - pub options : u32, - pub entrAddr : *mut ::c_void, - pub initTaskId: ::TASK_ID, - pub parentId : ::RTP_ID, - pub pathName : [::c_char; VX_RTP_NAME_LENGTH as usize + 1], - pub taskCnt : ::c_int, - pub textStart : *mut ::c_void, - pub textEnd : *mut ::c_void, - } - // socket.h - pub struct sockaddr_storage { - pub ss_len : ::c_uchar, - pub ss_family : ::sa_family_t, - pub __ss_pad1 : [::c_char; _SS_PAD1SIZE], - pub __ss_align : i32, - pub __ss_pad2 : [::c_char; _SS_PAD2SIZE], - } - - pub union sa_u_t { - pub sa_handler : ::Option !>, - pub sa_sigaction: ::Option !>, - } - - pub union sigval { - pub sival_int : ::c_int, - pub sival_ptr : *mut ::c_void, - } -} - -cfg_if! { - if #[cfg(feature = "extra_traits")] { - impl ::fmt::Debug for dirent { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("dirent") - .field("d_ino", &self.d_ino) - .field("d_name", &&self.d_name[..]) - .finish() - } - } - - impl ::fmt::Debug for sockaddr_un { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_un") - .field("sun_len", &self.sun_len) - .field("sun_family", &self.sun_family) - .field("sun_path", &&self.sun_path[..]) - .finish() - } - } - - impl ::fmt::Debug for RTP_DESC { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("RTP_DESC") - .field("status", &self.status) - .field("options", &self.options) - .field("entrAddr", &self.entrAddr) - .field("initTaskId", &self.initTaskId) - .field("parentId", &self.parentId) - .field("pathName", &&self.pathName[..]) - .field("taskCnt", &self.taskCnt) - .field("textStart", &self.textStart) - .field("textEnd", &self.textEnd) - .finish() - } - } - impl ::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sockaddr_storage") - .field("ss_len", &self.ss_len) - .field("ss_family", &self.ss_family) - .field("__ss_pad1", &&self.__ss_pad1[..]) - .field("__ss_align", &self.__ss_align) - .field("__ss_pad2", &&self.__ss_pad2[..]) - .finish() - } - } - - impl PartialEq for sa_u_t { - fn eq(&self, other: &sa_u_t) -> bool { - unsafe { - let h1 = match self.sa_handler { - Some(handler) => handler as usize, - None => 0 as usize, - }; - let h2 = match other.sa_handler { - Some(handler) => handler as usize, - None => 0 as usize, - }; - h1 == h2 - } - } - } - impl Eq for sa_u_t {} - impl ::fmt::Debug for sa_u_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - unsafe { - let h = match self.sa_handler { - Some(handler) => handler as usize, - None => 0 as usize, - }; - - f.debug_struct("sa_u_t") - .field("sa_handler", &h) - .finish() - } - } - } - impl ::hash::Hash for sa_u_t { - fn hash(&self, state: &mut H) { - unsafe { - let h = match self.sa_handler { - Some(handler) => handler as usize, - None => 0 as usize, - }; - h.hash(state) - } - } - } - - impl PartialEq for sigval { - fn eq(&self, other: &sigval) -> bool { - unsafe { self.sival_ptr as usize == other.sival_ptr as usize } - } - } - impl Eq for sigval {} - impl ::fmt::Debug for sigval { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("sigval") - .field("sival_ptr", unsafe { &(self.sival_ptr as usize) }) - .finish() - } - } - impl ::hash::Hash for sigval { - fn hash(&self, state: &mut H) { - unsafe { (self.sival_ptr as usize).hash(state) }; - } - } - } -} - -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; - -pub const EXIT_SUCCESS: ::c_int = 0; -pub const EXIT_FAILURE: ::c_int = 1; - -pub const EAI_SERVICE: ::c_int = 9; -pub const EAI_SOCKTYPE: ::c_int = 10; -pub const EAI_SYSTEM: ::c_int = 11; - -// This is not defined in vxWorks, but we have to define it here -// to make the building pass for getrandom and libstd, FIXME -pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; - -//Clock Lib Stuff -pub const CLOCK_REALTIME: ::c_int = 0x0; -pub const CLOCK_MONOTONIC: ::c_int = 0x1; -pub const CLOCK_PROCESS_CPUTIME_ID: ::c_int = 0x2; -pub const CLOCK_THREAD_CPUTIME_ID: ::c_int = 0x3; -pub const TIMER_ABSTIME: ::c_int = 0x1; -pub const TIMER_RELTIME: ::c_int = 0x0; - -// PTHREAD STUFF -pub const PTHREAD_INITIALIZED_OBJ: ::c_int = 0xF70990EF; -pub const PTHREAD_DESTROYED_OBJ: ::c_int = -1; -pub const PTHREAD_VALID_OBJ: ::c_int = 0xEC542A37; -pub const PTHREAD_INVALID_OBJ: ::c_int = -1; -pub const PTHREAD_UNUSED_YET_OBJ: ::c_int = -1; - -pub const PTHREAD_PRIO_NONE: ::c_int = 0; -pub const PTHREAD_PRIO_INHERIT: ::c_int = 1; -pub const PTHREAD_PRIO_PROTECT: ::c_int = 2; - -pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; -pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 1; -pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2; -pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; -pub const PTHREAD_STACK_MIN: usize = 4096; -pub const _PTHREAD_SHARED_SEM_NAME_MAX: usize = 30; - -// ERRNO STUFF -pub const OK: ::c_int = 0; -pub const EPERM: ::c_int = 1; /* Not owner */ -pub const ENOENT: ::c_int = 2; /* No such file or directory */ -pub const ESRCH: ::c_int = 3; /* No such process */ -pub const EINTR: ::c_int = 4; /* Interrupted system call */ -pub const EIO: ::c_int = 5; /* I/O error */ -pub const ENXIO: ::c_int = 6; /* No such device or address */ -pub const E2BIG: ::c_int = 7; /* Arg list too long */ -pub const ENOEXEC: ::c_int = 8; /* Exec format error */ -pub const EBADF: ::c_int = 9; /* Bad file number */ -pub const ECHILD: ::c_int = 10; /* No children */ -pub const EAGAIN: ::c_int = 11; /* No more processes */ -pub const ENOMEM: ::c_int = 12; /* Not enough core */ -pub const EACCES: ::c_int = 13; /* Permission denied */ -pub const EFAULT: ::c_int = 14; -pub const ENOTEMPTY: ::c_int = 15; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENAMETOOLONG: ::c_int = 26; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const EROFS: ::c_int = 30; -pub const EPIPE: ::c_int = 32; -pub const EDEADLK: ::c_int = 33; -pub const ERANGE: ::c_int = 38; -pub const EDESTADDRREQ: ::c_int = 40; -pub const EPROTOTYPE: ::c_int = 41; -pub const ENOPROTOOPT: ::c_int = 42; -pub const EPROTONOSUPPORT: ::c_int = 43; -pub const ESOCKTNOSUPPORT: ::c_int = 44; -pub const EOPNOTSUPP: ::c_int = 45; -pub const EPFNOSUPPORT: ::c_int = 46; -pub const EAFNOSUPPORT: ::c_int = 47; -pub const EADDRINUSE: ::c_int = 48; -pub const EADDRNOTAVAIL: ::c_int = 49; -pub const ENOTSOCK: ::c_int = 50; -pub const ENETUNREACH: ::c_int = 51; -pub const ENETRESET: ::c_int = 52; -pub const ECONNABORTED: ::c_int = 53; -pub const ECONNRESET: ::c_int = 54; -pub const ENOBUFS: ::c_int = 55; -pub const EISCONN: ::c_int = 56; -pub const ENOTCONN: ::c_int = 57; -pub const ESHUTDOWN: ::c_int = 58; -pub const ETOOMANYREFS: ::c_int = 59; -pub const ETIMEDOUT: ::c_int = 60; -pub const ECONNREFUSED: ::c_int = 61; -pub const EINPROGRESS: ::c_int = 68; -pub const EALREADY: ::c_int = 69; -pub const EWOULDBLOCK: ::c_int = 70; -pub const ENOSYS: ::c_int = 71; -pub const EDQUOT: ::c_int = 83; -pub const ESTALE: ::c_int = 88; - -// NFS errnos: Refer to pkgs_v2/storage/fs/nfs/h/nfs/nfsCommon.h -const M_nfsStat: ::c_int = 48 << 16; -enum nfsstat { - NFSERR_REMOTE = 71, - NFSERR_WFLUSH = 99, - NFSERR_BADHANDLE = 10001, - NFSERR_NOT_SYNC = 10002, - NFSERR_BAD_COOKIE = 10003, - NFSERR_TOOSMALL = 10005, - NFSERR_BADTYPE = 10007, - NFSERR_JUKEBOX = 10008, -} - -pub const S_nfsLib_NFS_OK: ::c_int = OK; -pub const S_nfsLib_NFSERR_PERM: ::c_int = EPERM; -pub const S_nfsLib_NFSERR_NOENT: ::c_int = ENOENT; -pub const S_nfsLib_NFSERR_IO: ::c_int = EIO; -pub const S_nfsLib_NFSERR_NXIO: ::c_int = ENXIO; -pub const S_nfsLib_NFSERR_ACCESS: ::c_int = EACCES; -pub const S_nfsLib_NFSERR_EXIST: ::c_int = EEXIST; -pub const S_nfsLib_NFSERR_ENODEV: ::c_int = ENODEV; -pub const S_nfsLib_NFSERR_NOTDIR: ::c_int = ENOTDIR; -pub const S_nfsLib_NFSERR_ISDIR: ::c_int = EISDIR; -pub const S_nfsLib_NFSERR_INVAL: ::c_int = EINVAL; -pub const S_nfsLib_NFSERR_FBIG: ::c_int = EFBIG; -pub const S_nfsLib_NFSERR_NOSPC: ::c_int = ENOSPC; -pub const S_nfsLib_NFSERR_ROFS: ::c_int = EROFS; -pub const S_nfsLib_NFSERR_NAMETOOLONG: ::c_int = ENAMETOOLONG; -pub const S_nfsLib_NFSERR_NOTEMPTY: ::c_int = ENOTEMPTY; -pub const S_nfsLib_NFSERR_DQUOT: ::c_int = EDQUOT; -pub const S_nfsLib_NFSERR_STALE: ::c_int = ESTALE; -pub const S_nfsLib_NFSERR_WFLUSH: ::c_int = - M_nfsStat | nfsstat::NFSERR_WFLUSH as ::c_int; -pub const S_nfsLib_NFSERR_REMOTE: ::c_int = - M_nfsStat | nfsstat::NFSERR_REMOTE as ::c_int; -pub const S_nfsLib_NFSERR_BADHANDLE: ::c_int = - M_nfsStat | nfsstat::NFSERR_BADHANDLE as ::c_int; -pub const S_nfsLib_NFSERR_NOT_SYNC: ::c_int = - M_nfsStat | nfsstat::NFSERR_NOT_SYNC as ::c_int; -pub const S_nfsLib_NFSERR_BAD_COOKIE: ::c_int = - M_nfsStat | nfsstat::NFSERR_BAD_COOKIE as ::c_int; -pub const S_nfsLib_NFSERR_NOTSUPP: ::c_int = EOPNOTSUPP; -pub const S_nfsLib_NFSERR_TOOSMALL: ::c_int = - M_nfsStat | nfsstat::NFSERR_TOOSMALL as ::c_int; -pub const S_nfsLib_NFSERR_SERVERFAULT: ::c_int = EIO; -pub const S_nfsLib_NFSERR_BADTYPE: ::c_int = - M_nfsStat | nfsstat::NFSERR_BADTYPE as ::c_int; -pub const S_nfsLib_NFSERR_JUKEBOX: ::c_int = - M_nfsStat | nfsstat::NFSERR_JUKEBOX as ::c_int; - -// in.h -pub const IPPROTO_IP: ::c_int = 0; -pub const IPPROTO_IPV6: ::c_int = 41; - -pub const IP_TTL: ::c_int = 4; -pub const IP_MULTICAST_IF: ::c_int = 9; -pub const IP_MULTICAST_TTL: ::c_int = 10; -pub const IP_MULTICAST_LOOP: ::c_int = 11; -pub const IP_ADD_MEMBERSHIP: ::c_int = 12; -pub const IP_DROP_MEMBERSHIP: ::c_int = 13; - -// in6.h -pub const IPV6_V6ONLY: ::c_int = 1; -pub const IPV6_UNICAST_HOPS: ::c_int = 4; -pub const IPV6_MULTICAST_IF: ::c_int = 9; -pub const IPV6_MULTICAST_HOPS: ::c_int = 10; -pub const IPV6_MULTICAST_LOOP: ::c_int = 11; -pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12; -pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13; - -// STAT Stuff -pub const S_IFMT: ::c_int = 0xf000; -pub const S_IFIFO: ::c_int = 0x1000; -pub const S_IFCHR: ::c_int = 0x2000; -pub const S_IFDIR: ::c_int = 0x4000; -pub const S_IFBLK: ::c_int = 0x6000; -pub const S_IFREG: ::c_int = 0x8000; -pub const S_IFLNK: ::c_int = 0xa000; -pub const S_IFSHM: ::c_int = 0xb000; -pub const S_IFSOCK: ::c_int = 0xc000; -pub const S_ISUID: ::c_int = 0x0800; -pub const S_ISGID: ::c_int = 0x0400; -pub const S_ISTXT: ::c_int = 0x0200; -pub const S_IRUSR: ::c_int = 0x0100; -pub const S_IWUSR: ::c_int = 0x0080; -pub const S_IXUSR: ::c_int = 0x0040; -pub const S_IRWXU: ::c_int = 0x01c0; -pub const S_IRGRP: ::c_int = 0x0020; -pub const S_IWGRP: ::c_int = 0x0010; -pub const S_IXGRP: ::c_int = 0x0008; -pub const S_IRWXG: ::c_int = 0x0038; -pub const S_IROTH: ::c_int = 0x0004; -pub const S_IWOTH: ::c_int = 0x0002; -pub const S_IXOTH: ::c_int = 0x0001; -pub const S_IRWXO: ::c_int = 0x0007; - -// socket.h -pub const SOL_SOCKET: ::c_int = 0xffff; - -pub const SO_DEBUG: ::c_int = 0x0001; -pub const SO_REUSEADDR: ::c_int = 0x0004; -pub const SO_KEEPALIVE: ::c_int = 0x0008; -pub const SO_DONTROUTE: ::c_int = 0x0010; -pub const SO_RCVLOWAT: ::c_int = 0x0012; -pub const SO_SNDLOWAT: ::c_int = 0x0013; -pub const SO_SNDTIMEO: ::c_int = 0x1005; -pub const SO_ACCEPTCONN: ::c_int = 0x001e; -pub const SO_BROADCAST: ::c_int = 0x0020; -pub const SO_USELOOPBACK: ::c_int = 0x0040; -pub const SO_LINGER: ::c_int = 0x0080; -pub const SO_REUSEPORT: ::c_int = 0x0200; - -pub const SO_VLAN: ::c_int = 0x8000; - -pub const SO_SNDBUF: ::c_int = 0x1001; -pub const SO_RCVBUF: ::c_int = 0x1002; -pub const SO_RCVTIMEO: ::c_int = 0x1006; -pub const SO_ERROR: ::c_int = 0x1007; -pub const SO_TYPE: ::c_int = 0x1008; -pub const SO_BINDTODEVICE: ::c_int = 0x1010; -pub const SO_OOBINLINE: ::c_int = 0x1011; -pub const SO_CONNTIMEO: ::c_int = 0x100a; - -pub const SOCK_STREAM: ::c_int = 1; -pub const SOCK_DGRAM: ::c_int = 2; -pub const SOCK_RAW: ::c_int = 3; -pub const SOCK_RDM: ::c_int = 4; -pub const SOCK_SEQPACKET: ::c_int = 5; -pub const SOCK_PACKET: ::c_int = 10; - -pub const _SS_MAXSIZE: usize = 128; -pub const _SS_ALIGNSIZE: usize = size_of::(); -pub const _SS_PAD1SIZE: usize = - (_SS_ALIGNSIZE - size_of::<::c_uchar>() - size_of::<::sa_family_t>()); -pub const _SS_PAD2SIZE: usize = (_SS_MAXSIZE - - size_of::<::c_uchar>() - - size_of::<::sa_family_t>() - - _SS_PAD1SIZE - - _SS_ALIGNSIZE); - -pub const MSG_OOB: ::c_int = 0x0001; -pub const MSG_PEEK: ::c_int = 0x0002; -pub const MSG_DONTROUTE: ::c_int = 0x0004; -pub const MSG_EOR: ::c_int = 0x0008; -pub const MSG_TRUNC: ::c_int = 0x0010; -pub const MSG_CTRUNC: ::c_int = 0x0020; -pub const MSG_WAITALL: ::c_int = 0x0040; -pub const MSG_DONTWAIT: ::c_int = 0x0080; -pub const MSG_EOF: ::c_int = 0x0100; -pub const MSG_EXP: ::c_int = 0x0200; -pub const MSG_MBUF: ::c_int = 0x0400; -pub const MSG_NOTIFICATION: ::c_int = 0x0800; -pub const MSG_COMPAT: ::c_int = 0x8000; - -pub const AF_UNSPEC: ::c_int = 0; -pub const AF_LOCAL: ::c_int = 1; -pub const AF_UNIX: ::c_int = AF_LOCAL; -pub const AF_INET: ::c_int = 2; -pub const AF_NETLINK: ::c_int = 16; -pub const AF_ROUTE: ::c_int = 17; -pub const AF_LINK: ::c_int = 18; -pub const AF_PACKET: ::c_int = 19; -pub const pseudo_AF_KEY: ::c_int = 27; -pub const AF_KEY: ::c_int = pseudo_AF_KEY; -pub const AF_INET6: ::c_int = 28; -pub const AF_SOCKDEV: ::c_int = 31; -pub const AF_TIPC: ::c_int = 33; -pub const AF_MIPC: ::c_int = 34; -pub const AF_MIPC_SAFE: ::c_int = 35; -pub const AF_MAX: ::c_int = 37; - -pub const SHUT_RD: ::c_int = 0; -pub const SHUT_WR: ::c_int = 1; -pub const SHUT_RDWR: ::c_int = 2; - -pub const IPPROTO_TCP: ::c_int = 6; -pub const TCP_NODELAY: ::c_int = 1; -pub const TCP_MAXSEG: ::c_int = 2; -pub const TCP_NOPUSH: ::c_int = 3; -pub const TCP_KEEPIDLE: ::c_int = 4; -pub const TCP_KEEPINTVL: ::c_int = 5; -pub const TCP_KEEPCNT: ::c_int = 6; - -// ioLib.h -pub const FIONREAD: ::c_int = 0x40040001; -pub const FIOFLUSH: ::c_int = 2; -pub const FIOOPTIONS: ::c_int = 3; -pub const FIOBAUDRATE: ::c_int = 4; -pub const FIODISKFORMAT: ::c_int = 5; -pub const FIODISKINIT: ::c_int = 6; -pub const FIOSEEK: ::c_int = 7; -pub const FIOWHERE: ::c_int = 8; -pub const FIODIRENTRY: ::c_int = 9; -pub const FIORENAME: ::c_int = 10; -pub const FIOREADYCHANGE: ::c_int = 11; -pub const FIODISKCHANGE: ::c_int = 13; -pub const FIOCANCEL: ::c_int = 14; -pub const FIOSQUEEZE: ::c_int = 15; -pub const FIOGETNAME: ::c_int = 18; -pub const FIONBIO: ::c_int = 0x90040010; - -// limits.h -pub const PATH_MAX: ::c_int = _PARM_PATH_MAX; -pub const _POSIX_PATH_MAX: ::c_int = 256; - -// Some poll stuff -pub const POLLIN: ::c_short = 0x0001; -pub const POLLPRI: ::c_short = 0x0002; -pub const POLLOUT: ::c_short = 0x0004; -pub const POLLRDNORM: ::c_short = 0x0040; -pub const POLLWRNORM: ::c_short = POLLOUT; -pub const POLLRDBAND: ::c_short = 0x0080; -pub const POLLWRBAND: ::c_short = 0x0100; -pub const POLLERR: ::c_short = 0x0008; -pub const POLLHUP: ::c_short = 0x0010; -pub const POLLNVAL: ::c_short = 0x0020; - -// fnctlcom.h -pub const FD_CLOEXEC: ::c_int = 1; -pub const F_DUPFD: ::c_int = 0; -pub const F_GETFD: ::c_int = 1; -pub const F_SETFD: ::c_int = 2; -pub const F_GETFL: ::c_int = 3; -pub const F_SETFL: ::c_int = 4; -pub const F_GETOWN: ::c_int = 5; -pub const F_SETOWN: ::c_int = 6; -pub const F_GETLK: ::c_int = 7; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; -pub const F_DUPFD_CLOEXEC: ::c_int = 14; - -// signal.h -pub const SIG_DFL: sighandler_t = 0 as sighandler_t; -pub const SIG_IGN: sighandler_t = 1 as sighandler_t; -pub const SIG_ERR: sighandler_t = -1 as isize as sighandler_t; - -pub const SIGHUP: ::c_int = 1; -pub const SIGINT: ::c_int = 2; -pub const SIGQUIT: ::c_int = 3; -pub const SIGILL: ::c_int = 4; -pub const SIGTRAP: ::c_int = 5; -pub const SIGABRT: ::c_int = 6; -pub const SIGEMT: ::c_int = 7; -pub const SIGFPE: ::c_int = 8; -pub const SIGKILL: ::c_int = 9; -pub const SIGBUS: ::c_int = 10; -pub const SIGSEGV: ::c_int = 11; -pub const SIGFMT: ::c_int = 12; -pub const SIGPIPE: ::c_int = 13; -pub const SIGALRM: ::c_int = 14; -pub const SIGTERM: ::c_int = 15; -pub const SIGCNCL: ::c_int = 16; -pub const SIGSTOP: ::c_int = 17; -pub const SIGTSTP: ::c_int = 18; -pub const SIGCONT: ::c_int = 19; -pub const SIGCHLD: ::c_int = 20; -pub const SIGTTIN: ::c_int = 21; -pub const SIGTTOU: ::c_int = 22; - -pub const SIG_BLOCK: ::c_int = 1; -pub const SIG_UNBLOCK: ::c_int = 2; -pub const SIG_SETMASK: ::c_int = 3; - -pub const SI_SYNC: ::c_int = 0; -pub const SI_USER: ::c_int = -1; -pub const SI_QUEUE: ::c_int = -2; -pub const SI_TIMER: ::c_int = -3; -pub const SI_ASYNCIO: ::c_int = -4; -pub const SI_MESGQ: ::c_int = -5; -pub const SI_CHILD: ::c_int = -6; -pub const SI_KILL: ::c_int = SI_USER; - -// vxParams.h definitions -pub const _PARM_NAME_MAX: ::c_int = 255; -pub const _PARM_PATH_MAX: ::c_int = 1024; - -// WAIT STUFF -pub const WNOHANG: ::c_int = 0x01; -pub const WUNTRACED: ::c_int = 0x02; - -const PTHREAD_MUTEXATTR_INITIALIZER: pthread_mutexattr_t = - pthread_mutexattr_t { - mutexAttrStatus: PTHREAD_INITIALIZED_OBJ, - mutexAttrProtocol: PTHREAD_PRIO_NONE, - mutexAttrPrioceiling: 0, - mutexAttrType: PTHREAD_MUTEX_DEFAULT, - mutexAttrPshared: 1, - }; -pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - mutexSemId: null_mut(), - mutexValid: PTHREAD_VALID_OBJ, - mutexInitted: PTHREAD_UNUSED_YET_OBJ, - mutexCondRefCount: 0, - mutexSavPriority: -1, - mutexAttr: PTHREAD_MUTEXATTR_INITIALIZER, - mutexSemName: [0; _PTHREAD_SHARED_SEM_NAME_MAX], -}; - -const PTHREAD_CONDATTR_INITIALIZER: pthread_condattr_t = pthread_condattr_t { - condAttrStatus: 0xf70990ef, - condAttrPshared: 1, - condAttrClockId: CLOCK_REALTIME, -}; -pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - condSemId: null_mut(), - condValid: PTHREAD_VALID_OBJ, - condInitted: PTHREAD_UNUSED_YET_OBJ, - condRefCount: 0, - condMutex: null_mut(), - condAttr: PTHREAD_CONDATTR_INITIALIZER, - condSemName: [0; _PTHREAD_SHARED_SEM_NAME_MAX], -}; - -const PTHREAD_RWLOCKATTR_INITIALIZER: pthread_rwlockattr_t = - pthread_rwlockattr_t { - rwlockAttrStatus: PTHREAD_INITIALIZED_OBJ, - rwlockAttrPshared: 1, - rwlockAttrMaxReaders: 0, - rwlockAttrConformOpt: 1, - }; -pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - rwlockSemId: null_mut(), - rwlockReadersRefCount: 0, - rwlockValid: PTHREAD_VALID_OBJ, - rwlockInitted: PTHREAD_UNUSED_YET_OBJ, - rwlockAttr: PTHREAD_RWLOCKATTR_INITIALIZER, - rwlockSemName: [0; _PTHREAD_SHARED_SEM_NAME_MAX], -}; - -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; - -// rtpLibCommon.h -pub const VX_RTP_NAME_LENGTH: ::c_int = 255; -pub const RTP_ID_ERROR: ::RTP_ID = -1; - -// h/public/unistd.h -pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 21; // Via unistd.h -pub const _SC_PAGESIZE: ::c_int = 39; -pub const O_ACCMODE: ::c_int = 3; -pub const O_CLOEXEC: ::c_int = 0x100000; // fcntlcom -pub const O_EXCL: ::c_int = 0x0800; -pub const O_CREAT: ::c_int = 0x0200; -pub const O_TRUNC: ::c_int = 0x0400; -pub const O_APPEND: ::c_int = 0x0008; -pub const O_RDWR: ::c_int = 0x0002; -pub const O_WRONLY: ::c_int = 0x0001; -pub const O_RDONLY: ::c_int = 0; -pub const O_NONBLOCK: ::c_int = 0x4000; - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum FILE {} -impl ::Copy for FILE {} -impl ::Clone for FILE { - fn clone(&self) -> FILE { - *self - } -} -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos_t {} // TODO: fill this out with a struct -impl ::Copy for fpos_t {} -impl ::Clone for fpos_t { - fn clone(&self) -> fpos_t { - *self - } -} - -f! { - pub fn CMSG_ALIGN(len: usize) -> usize { - len + ::mem::size_of::() - 1 & !(::mem::size_of::() - 1) - } - - pub fn CMSG_NXTHDR(mhdr: *const msghdr, - cmsg: *const cmsghdr) -> *mut cmsghdr { - let next = cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize) - + CMSG_ALIGN(::mem::size_of::<::cmsghdr>()); - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next <= max { - (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) - as *mut ::cmsghdr - } else { - 0 as *mut ::cmsghdr - } - } - - pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { - if (*mhdr).msg_controllen as usize > 0 { - (*mhdr).msg_control as *mut cmsghdr - } else { - 0 as *mut cmsghdr - } - } - - pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut ::c_uchar { - (cmsg as *mut ::c_uchar) - .offset(CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (CMSG_ALIGN(length as usize) + CMSG_ALIGN(::mem::size_of::())) - as ::c_uint - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - CMSG_ALIGN(::mem::size_of::()) as ::c_uint + length - } -} - -extern "C" { - pub fn isalnum(c: c_int) -> c_int; - pub fn isalpha(c: c_int) -> c_int; - pub fn iscntrl(c: c_int) -> c_int; - pub fn isdigit(c: c_int) -> c_int; - pub fn isgraph(c: c_int) -> c_int; - pub fn islower(c: c_int) -> c_int; - pub fn isprint(c: c_int) -> c_int; - pub fn ispunct(c: c_int) -> c_int; - pub fn isspace(c: c_int) -> c_int; - pub fn isupper(c: c_int) -> c_int; - pub fn isxdigit(c: c_int) -> c_int; - pub fn isblank(c: c_int) -> c_int; - pub fn tolower(c: c_int) -> c_int; - pub fn toupper(c: c_int) -> c_int; - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - pub fn freopen( - filename: *const c_char, - mode: *const c_char, - file: *mut FILE, - ) -> *mut FILE; - pub fn fflush(file: *mut FILE) -> c_int; - pub fn fclose(file: *mut FILE) -> c_int; - pub fn remove(filename: *const c_char) -> c_int; - pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; - pub fn tmpfile() -> *mut FILE; - pub fn setvbuf( - stream: *mut FILE, - buffer: *mut c_char, - mode: c_int, - size: size_t, - ) -> c_int; - pub fn setbuf(stream: *mut FILE, buf: *mut c_char); - pub fn getchar() -> c_int; - pub fn putchar(c: c_int) -> c_int; - pub fn fgetc(stream: *mut FILE) -> c_int; - pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) - -> *mut c_char; - pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; - pub fn puts(s: *const c_char) -> c_int; - pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fread( - ptr: *mut c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fwrite( - ptr: *const c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; - pub fn ftell(stream: *mut FILE) -> c_long; - pub fn rewind(stream: *mut FILE); - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; - pub fn feof(stream: *mut FILE) -> c_int; - pub fn ferror(stream: *mut FILE) -> c_int; - pub fn perror(s: *const c_char); - pub fn atoi(s: *const c_char) -> c_int; - pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; - pub fn strtol( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_long; - pub fn strtoul( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_ulong; - pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; - pub fn malloc(size: size_t) -> *mut c_void; - pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; - pub fn free(p: *mut c_void); - pub fn abort() -> !; - pub fn exit(status: c_int) -> !; - pub fn atexit(cb: extern "C" fn()) -> c_int; - pub fn system(s: *const c_char) -> c_int; - pub fn getenv(s: *const c_char) -> *mut c_char; - - pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; - pub fn strncpy( - dst: *mut c_char, - src: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; - pub fn strncat( - s: *mut c_char, - ct: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; - pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strdup(cs: *const c_char) -> *mut c_char; - pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; - pub fn strncasecmp( - s1: *const c_char, - s2: *const c_char, - n: size_t, - ) -> c_int; - pub fn strlen(cs: *const c_char) -> size_t; - pub fn strerror(n: c_int) -> *mut c_char; - pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; - pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; - pub fn wcslen(buf: *const wchar_t) -> size_t; - pub fn wcstombs( - dest: *mut c_char, - src: *const wchar_t, - n: size_t, - ) -> ::size_t; - - pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memcpy( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memmove( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; -} - -extern "C" { - pub fn fprintf( - stream: *mut ::FILE, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn printf(format: *const ::c_char, ...) -> ::c_int; - pub fn snprintf( - s: *mut ::c_char, - n: ::size_t, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int; - pub fn fscanf( - stream: *mut ::FILE, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn scanf(format: *const ::c_char, ...) -> ::c_int; - pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) - -> ::c_int; - pub fn getchar_unlocked() -> ::c_int; - pub fn putchar_unlocked(c: ::c_int) -> ::c_int; - pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; - pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; - pub fn fileno(stream: *mut ::FILE) -> ::c_int; - pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int; - pub fn rewinddir(dirp: *mut ::DIR); - pub fn fchown(fd: ::c_int, owner: ::uid_t, group: ::gid_t) -> ::c_int; - pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; - pub fn alarm(seconds: ::c_uint) -> ::c_uint; - pub fn fchdir(dirfd: ::c_int) -> ::c_int; - pub fn chown(path: *const c_char, uid: uid_t, gid: gid_t) -> ::c_int; - pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> c_long; - pub fn getegid() -> gid_t; - pub fn geteuid() -> uid_t; - pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t) -> ::c_int; - pub fn getlogin() -> *mut c_char; - pub fn getopt( - argc: ::c_int, - argv: *const *mut c_char, - optstr: *const c_char, - ) -> ::c_int; - pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long; - pub fn pause() -> ::c_int; - pub fn seteuid(uid: uid_t) -> ::c_int; - pub fn setegid(gid: gid_t) -> ::c_int; - pub fn sleep(secs: ::c_uint) -> ::c_uint; - pub fn ttyname(fd: ::c_int) -> *mut c_char; - pub fn wait(status: *mut ::c_int) -> pid_t; - pub fn umask(mask: mode_t) -> mode_t; - pub fn mlock(addr: *const ::c_void, len: ::size_t) -> ::c_int; - pub fn mlockall(flags: ::c_int) -> ::c_int; - pub fn munlockall() -> ::c_int; - - pub fn mmap( - addr: *mut ::c_void, - len: ::size_t, - prot: ::c_int, - flags: ::c_int, - fd: ::c_int, - offset: off_t, - ) -> *mut ::c_void; - pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int; - pub fn truncate(path: *const c_char, length: off_t) -> ::c_int; - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn pthread_exit(value: *mut ::c_void) -> !; - pub fn pthread_attr_setdetachstate( - attr: *mut ::pthread_attr_t, - state: ::c_int, - ) -> ::c_int; - - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn sigaction( - signum: ::c_int, - act: *const sigaction, - oldact: *mut sigaction, - ) -> ::c_int; - - pub fn utimes( - filename: *const ::c_char, - times: *const ::timeval, - ) -> ::c_int; - - #[link_name = "_rtld_dlopen"] - pub fn dlopen(filename: *const ::c_char, flag: ::c_int) -> *mut ::c_void; - - #[link_name = "_rtld_dlerror"] - pub fn dlerror() -> *mut ::c_char; - - #[link_name = "_rtld_dlsym"] - pub fn dlsym( - handle: *mut ::c_void, - symbol: *const ::c_char, - ) -> *mut ::c_void; - - #[link_name = "_rtld_dlclose"] - pub fn dlclose(handle: *mut ::c_void) -> ::c_int; - - #[link_name = "_rtld_dladdr"] - pub fn dladdr(addr: *mut ::c_void, info: *mut Dl_info) -> ::c_int; - - // time.h - pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; - pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm; - pub fn mktime(tm: *mut tm) -> time_t; - pub fn time(time: *mut time_t) -> time_t; - pub fn gmtime(time_p: *const time_t) -> *mut tm; - pub fn localtime(time_p: *const time_t) -> *mut tm; - pub fn timegm(tm: *mut tm) -> time_t; - pub fn difftime(time1: time_t, time0: time_t) -> ::c_double; - pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int; - pub fn usleep(secs: ::useconds_t) -> ::c_int; - pub fn putenv(string: *mut c_char) -> ::c_int; - pub fn setlocale( - category: ::c_int, - locale: *const ::c_char, - ) -> *mut ::c_char; - - pub fn sigprocmask( - how: ::c_int, - set: *const sigset_t, - oldset: *mut sigset_t, - ) -> ::c_int; - pub fn sigpending(set: *mut sigset_t) -> ::c_int; - - pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int; - - pub fn fseeko( - stream: *mut ::FILE, - offset: ::off_t, - whence: ::c_int, - ) -> ::c_int; - pub fn ftello(stream: *mut ::FILE) -> ::off_t; - pub fn mkstemp(template: *mut ::c_char) -> ::c_int; - - pub fn tmpnam(ptr: *mut ::c_char) -> *mut ::c_char; - - pub fn openlog(ident: *const ::c_char, logopt: ::c_int, facility: ::c_int); - pub fn closelog(); - pub fn setlogmask(maskpri: ::c_int) -> ::c_int; - pub fn syslog(priority: ::c_int, message: *const ::c_char, ...); - pub fn getline( - lineptr: *mut *mut c_char, - n: *mut size_t, - stream: *mut FILE, - ) -> ssize_t; - -} - -extern "C" { - // stdlib.h - pub fn memalign(block_size: ::size_t, size_arg: ::size_t) - -> *mut ::c_void; - - // ioLib.h - pub fn getcwd(buf: *mut ::c_char, size: ::size_t) -> *mut ::c_char; - - // ioLib.h - pub fn chdir(attr: *const ::c_char) -> ::c_int; - - // pthread.h - pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int; - - // pthread.h - pub fn pthread_mutexattr_destroy( - attr: *mut pthread_mutexattr_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_mutexattr_settype( - pAttr: *mut ::pthread_mutexattr_t, - pType: ::c_int, - ) -> ::c_int; - - // pthread.h - pub fn pthread_mutex_init( - mutex: *mut pthread_mutex_t, - attr: *const pthread_mutexattr_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_mutex_destroy(mutex: *mut pthread_mutex_t) -> ::c_int; - - // pthread.h - pub fn pthread_mutex_lock(mutex: *mut pthread_mutex_t) -> ::c_int; - - // pthread.h - pub fn pthread_mutex_trylock(mutex: *mut pthread_mutex_t) -> ::c_int; - - // pthread.h - pub fn pthread_mutex_timedlock( - attr: *mut pthread_mutex_t, - spec: *const timespec, - ) -> ::c_int; - - // pthread.h - pub fn pthread_mutex_unlock(mutex: *mut pthread_mutex_t) -> ::c_int; - - // pthread.h - pub fn pthread_attr_setname( - pAttr: *mut ::pthread_attr_t, - name: *mut ::c_char, - ) -> ::c_int; - - // pthread.h - pub fn pthread_attr_setstacksize( - attr: *mut ::pthread_attr_t, - stacksize: ::size_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_attr_getstacksize( - attr: *const ::pthread_attr_t, - size: *mut ::size_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int; - - // pthread.h - pub fn pthread_create( - pThread: *mut ::pthread_t, - pAttr: *const ::pthread_attr_t, - start_routine: extern "C" fn(*mut ::c_void) -> *mut ::c_void, - value: *mut ::c_void, - ) -> ::c_int; - - // pthread.h - pub fn pthread_attr_destroy(thread: *mut ::pthread_attr_t) -> ::c_int; - - // pthread.h - pub fn pthread_detach(thread: ::pthread_t) -> ::c_int; - - // int pthread_atfork (void (*)(void), void (*)(void), void (*)(void)); - pub fn pthread_atfork( - prepare: ::Option, - parent: ::Option, - child: ::Option, - ) -> ::c_int; - // stat.h - pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; - - // stat.h - pub fn lstat(path: *const ::c_char, buf: *mut stat) -> ::c_int; - - // unistd.h - pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int; - - // dirent.h - pub fn readdir_r( - pDir: *mut ::DIR, - entry: *mut ::dirent, - result: *mut *mut ::dirent, - ) -> ::c_int; - - // dirent.h - pub fn readdir(pDir: *mut ::DIR) -> *mut ::dirent; - - // fcntl.h or - // ioLib.h - pub fn open(path: *const ::c_char, oflag: ::c_int, ...) -> ::c_int; - - // poll.h - pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int; - - // pthread.h - pub fn pthread_condattr_init(attr: *mut ::pthread_condattr_t) -> ::c_int; - - // pthread.h - pub fn pthread_condattr_destroy( - attr: *mut ::pthread_condattr_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_condattr_getclock( - pAttr: *const ::pthread_condattr_t, - pClockId: *mut ::clockid_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_condattr_setclock( - pAttr: *mut ::pthread_condattr_t, - clockId: ::clockid_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_cond_init( - cond: *mut ::pthread_cond_t, - attr: *const ::pthread_condattr_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int; - - // pthread.h - pub fn pthread_cond_signal(cond: *mut ::pthread_cond_t) -> ::c_int; - - // pthread.h - pub fn pthread_cond_broadcast(cond: *mut ::pthread_cond_t) -> ::c_int; - - // pthread.h - pub fn pthread_cond_wait( - cond: *mut ::pthread_cond_t, - mutex: *mut ::pthread_mutex_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_rwlockattr_init( - attr: *mut ::pthread_rwlockattr_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_rwlockattr_destroy( - attr: *mut ::pthread_rwlockattr_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_rwlockattr_setmaxreaders( - attr: *mut ::pthread_rwlockattr_t, - attr2: ::c_uint, - ) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_init( - attr: *mut ::pthread_rwlock_t, - host: *const ::pthread_rwlockattr_t, - ) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_destroy(attr: *mut ::pthread_rwlock_t) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_rdlock(attr: *mut ::pthread_rwlock_t) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_tryrdlock(attr: *mut ::pthread_rwlock_t) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_timedrdlock( - attr: *mut ::pthread_rwlock_t, - host: *const ::timespec, - ) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_wrlock(attr: *mut ::pthread_rwlock_t) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_trywrlock(attr: *mut ::pthread_rwlock_t) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_timedwrlock( - attr: *mut ::pthread_rwlock_t, - host: *const ::timespec, - ) -> ::c_int; - - // pthread.h - pub fn pthread_rwlock_unlock(attr: *mut ::pthread_rwlock_t) -> ::c_int; - - // pthread.h - pub fn pthread_key_create( - key: *mut ::pthread_key_t, - dtor: ::Option, - ) -> ::c_int; - - // pthread.h - pub fn pthread_key_delete(key: ::pthread_key_t) -> ::c_int; - - // pthread.h - pub fn pthread_setspecific( - key: ::pthread_key_t, - value: *const ::c_void, - ) -> ::c_int; - - // pthread.h - pub fn pthread_getspecific(key: ::pthread_key_t) -> *mut ::c_void; - - // pthread.h - pub fn pthread_cond_timedwait( - cond: *mut ::pthread_cond_t, - mutex: *mut ::pthread_mutex_t, - abstime: *const ::timespec, - ) -> ::c_int; - - // pthread.h - pub fn pthread_attr_getname( - attr: *mut ::pthread_attr_t, - name: *mut *mut ::c_char, - ) -> ::c_int; - - // pthread.h - pub fn pthread_join( - thread: ::pthread_t, - status: *mut *mut ::c_void, - ) -> ::c_int; - - // pthread.h - pub fn pthread_self() -> ::pthread_t; - - // clockLib.h - pub fn clock_gettime( - clock_id: ::clockid_t, - tp: *mut ::timespec, - ) -> ::c_int; - - // clockLib.h - pub fn clock_settime( - clock_id: ::clockid_t, - tp: *const ::timespec, - ) -> ::c_int; - - // clockLib.h - pub fn clock_getres( - clock_id: ::clockid_t, - res: *mut ::timespec, - ) -> ::c_int; - - // clockLib.h - pub fn clock_nanosleep( - clock_id: ::clockid_t, - flags: ::c_int, - rqtp: *const ::timespec, - rmtp: *mut ::timespec, - ) -> ::c_int; - - // timerLib.h - pub fn nanosleep( - rqtp: *const ::timespec, - rmtp: *mut ::timespec, - ) -> ::c_int; - - // socket.h - pub fn accept( - s: ::c_int, - addr: *mut ::sockaddr, - addrlen: *mut ::socklen_t, - ) -> ::c_int; - - // socket.h - pub fn bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t) - -> ::c_int; - - // socket.h - pub fn connect( - s: ::c_int, - name: *const ::sockaddr, - namelen: ::socklen_t, - ) -> ::c_int; - - // socket.h - pub fn getpeername( - s: ::c_int, - name: *mut ::sockaddr, - namelen: *mut ::socklen_t, - ) -> ::c_int; - - // socket.h - pub fn getsockname( - socket: ::c_int, - address: *mut sockaddr, - address_len: *mut socklen_t, - ) -> ::c_int; - - // socket.h - pub fn getsockopt( - sockfd: ::c_int, - level: ::c_int, - optname: ::c_int, - optval: *mut ::c_void, - optlen: *mut ::socklen_t, - ) -> ::c_int; - - // socket.h - pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; - - // socket.h - pub fn recv( - s: ::c_int, - buf: *mut ::c_void, - bufLen: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - - // socket.h - pub fn recvfrom( - s: ::c_int, - buf: *mut ::c_void, - bufLen: ::size_t, - flags: ::c_int, - from: *mut ::sockaddr, - pFromLen: *mut ::socklen_t, - ) -> ::ssize_t; - - pub fn recvmsg( - socket: ::c_int, - mp: *mut ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - - // socket.h - pub fn send( - socket: ::c_int, - buf: *const ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - - pub fn sendmsg( - socket: ::c_int, - mp: *const ::msghdr, - flags: ::c_int, - ) -> ::ssize_t; - - // socket.h - pub fn sendto( - socket: ::c_int, - buf: *const ::c_void, - len: ::size_t, - flags: ::c_int, - addr: *const sockaddr, - addrlen: socklen_t, - ) -> ::ssize_t; - - // socket.h - pub fn setsockopt( - socket: ::c_int, - level: ::c_int, - name: ::c_int, - value: *const ::c_void, - option_len: socklen_t, - ) -> ::c_int; - - // socket.h - pub fn shutdown(s: ::c_int, how: ::c_int) -> ::c_int; - - // socket.h - pub fn socket( - domain: ::c_int, - _type: ::c_int, - protocol: ::c_int, - ) -> ::c_int; - - // icotl.h - pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int; - - // fcntl.h - pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int; - - // ntp_rfc2553.h for kernel - // netdb.h for user - pub fn gai_strerror(errcode: ::c_int) -> *mut ::c_char; - - // ioLib.h or - // unistd.h - pub fn close(fd: ::c_int) -> ::c_int; - - // ioLib.h or - // unistd.h - pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t) - -> ::ssize_t; - - // ioLib.h or - // unistd.h - pub fn write( - fd: ::c_int, - buf: *const ::c_void, - count: ::size_t, - ) -> ::ssize_t; - - // ioLib.h or - // unistd.h - pub fn isatty(fd: ::c_int) -> ::c_int; - - // ioLib.h or - // unistd.h - pub fn dup(src: ::c_int) -> ::c_int; - - // ioLib.h or - // unistd.h - pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; - - // ioLib.h or - // unistd.h - pub fn pipe(fds: *mut ::c_int) -> ::c_int; - - // ioLib.h or - // unistd.h - pub fn unlink(pathname: *const ::c_char) -> ::c_int; - - // unistd.h and - // ioLib.h - pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t; - - // netdb.h - pub fn getaddrinfo( - node: *const ::c_char, - service: *const ::c_char, - hints: *const addrinfo, - res: *mut *mut addrinfo, - ) -> ::c_int; - - // netdb.h - pub fn freeaddrinfo(res: *mut addrinfo); - - // signal.h - pub fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t; - - // unistd.h - pub fn getpid() -> pid_t; - - // unistd.h - pub fn getppid() -> pid_t; - - // wait.h - pub fn waitpid(pid: pid_t, status: *mut ::c_int, optons: ::c_int) - -> pid_t; - - // unistd.h - pub fn sysconf(attr: ::c_int) -> ::c_long; - - // stdlib.h - pub fn setenv( - // setenv.c - envVarName: *const ::c_char, - envVarValue: *const ::c_char, - overwrite: ::c_int, - ) -> ::c_int; - - // stdlib.h - pub fn unsetenv( - // setenv.c - envVarName: *const ::c_char, - ) -> ::c_int; - - // stdlib.h - pub fn realpath( - fileName: *const ::c_char, - resolvedName: *mut ::c_char, - ) -> *mut ::c_char; - - // unistd.h - pub fn link(src: *const ::c_char, dst: *const ::c_char) -> ::c_int; - - // unistd.h - pub fn readlink( - path: *const ::c_char, - buf: *mut ::c_char, - bufsize: ::size_t, - ) -> ::ssize_t; - - // unistd.h - pub fn symlink(path1: *const ::c_char, path2: *const ::c_char) -> ::c_int; - - // dirent.h - pub fn opendir(name: *const ::c_char) -> *mut ::DIR; - - // unistd.h - pub fn rmdir(path: *const ::c_char) -> ::c_int; - - // stat.h - pub fn mkdir(dirName: *const ::c_char, mode: ::mode_t) -> ::c_int; - - // stat.h - pub fn chmod(path: *const ::c_char, mode: ::mode_t) -> ::c_int; - - // stat.h - pub fn fchmod(attr1: ::c_int, attr2: ::mode_t) -> ::c_int; - - // unistd.h - pub fn fsync(fd: ::c_int) -> ::c_int; - - // dirent.h - pub fn closedir(ptr: *mut ::DIR) -> ::c_int; - - // sched.h - pub fn sched_yield() -> ::c_int; - - // errnoLib.h - pub fn errnoSet(err: ::c_int) -> ::c_int; - - // errnoLib.h - pub fn errnoGet() -> ::c_int; - - // unistd.h - pub fn _exit(status: ::c_int) -> !; - - // unistd.h - pub fn setgid(gid: ::gid_t) -> ::c_int; - - // unistd.h - pub fn getgid() -> ::gid_t; - - // unistd.h - pub fn setuid(uid: ::uid_t) -> ::c_int; - - // unistd.h - pub fn getuid() -> ::uid_t; - - // signal.h - pub fn sigemptyset(__set: *mut sigset_t) -> ::c_int; - - // pthread.h for kernel - // signal.h for user - pub fn pthread_sigmask( - __how: ::c_int, - __set: *const sigset_t, - __oset: *mut sigset_t, - ) -> ::c_int; - - // signal.h for user - pub fn kill(__pid: pid_t, __signo: ::c_int) -> ::c_int; - - // signal.h for user - pub fn sigqueue( - __pid: pid_t, - __signo: ::c_int, - __value: ::sigval, - ) -> ::c_int; - - // signal.h for user - pub fn _sigqueue( - rtpId: ::RTP_ID, - signo: ::c_int, - pValue: *const ::sigval, - sigCode: ::c_int, - ) -> ::c_int; - - // signal.h - pub fn taskKill(taskId: ::TASK_ID, signo: ::c_int) -> ::c_int; - - // signal.h - pub fn raise(__signo: ::c_int) -> ::c_int; - - // taskLibCommon.h - pub fn taskIdSelf() -> ::TASK_ID; - pub fn taskDelay(ticks: ::_Vx_ticks_t) -> ::c_int; - - // rtpLibCommon.h - pub fn rtpInfoGet(rtpId: ::RTP_ID, rtpStruct: *mut ::RTP_DESC) -> ::c_int; - pub fn rtpSpawn( - pubrtpFileName: *const ::c_char, - argv: *mut *const ::c_char, - envp: *mut *const ::c_char, - priority: ::c_int, - uStackSize: ::size_t, - options: ::c_int, - taskOptions: ::c_int, - ) -> RTP_ID; - - // ioLib.h - pub fn _realpath( - fileName: *const ::c_char, - resolvedName: *mut ::c_char, - ) -> *mut ::c_char; - - // pathLib.h - pub fn _pathIsAbsolute( - filepath: *const ::c_char, - pNameTail: *mut *const ::c_char, - ) -> BOOL; - - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - - // randomNumGen.h - pub fn randBytes(buf: *mut c_uchar, length: c_int) -> c_int; - pub fn randABytes(buf: *mut c_uchar, length: c_int) -> c_int; - pub fn randUBytes(buf: *mut c_uchar, length: c_int) -> c_int; - pub fn randSecure() -> c_int; -} - -//Dummy functions, these don't really exist in VxWorks. - -// wait.h macros -pub fn WIFEXITED(status: ::c_int) -> bool { - (status & 0xFF00) == 0 -} -pub fn WIFSIGNALED(status: ::c_int) -> bool { - (status & 0xFF00) != 0 -} -pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0xFF0000) != 0 -} -pub fn WEXITSTATUS(status: ::c_int) -> ::c_int { - status & 0xFF -} -pub fn WTERMSIG(status: ::c_int) -> ::c_int { - (status >> 8) & 0xFF -} -pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - (status >> 16) & 0xFF -} - -pub fn pread( - _fd: ::c_int, - _buf: *mut ::c_void, - _count: ::size_t, - _offset: off64_t, -) -> ::ssize_t { - -1 -} - -pub fn pwrite( - _fd: ::c_int, - _buf: *const ::c_void, - _count: ::size_t, - _offset: off64_t, -) -> ::ssize_t { - -1 -} -pub fn posix_memalign( - memptr: *mut *mut ::c_void, - align: ::size_t, - size: ::size_t, -) -> ::c_int { - // check to see if align is a power of 2 and if align is a multiple - // of sizeof(void *) - if (align & align - 1 != 0) - || (align as usize % size_of::<::size_t>() != 0) - { - return ::EINVAL; - } - - unsafe { - // posix_memalign should not set errno - let e = ::errnoGet(); - - let temp = memalign(align, size); - ::errnoSet(e as ::c_int); - - if temp.is_null() { - ::ENOMEM - } else { - *memptr = temp; - 0 - } - } -} - -cfg_if! { - if #[cfg(libc_core_cvoid)] { - pub use ::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - #[allow(missing_copy_implementations)] - #[allow(missing_debug_implementations)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} - -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } else if #[cfg(any(target_arch = "arm"))] { - mod arm; - pub use self::arm::*; - } else if #[cfg(any(target_arch = "x86"))] { - mod x86; - pub use self::x86::*; - } else if #[cfg(any(target_arch = "x86_64"))] { - mod x86_64; - pub use self::x86_64::*; - } else if #[cfg(any(target_arch = "powerpc"))] { - mod powerpc; - pub use self::powerpc::*; - } else if #[cfg(any(target_arch = "powerpc64"))] { - mod powerpc64; - pub use self::powerpc64::*; - } else { - // Unknown target_arch - } -} diff --git a/libc/src/vxworks/powerpc.rs b/libc/src/vxworks/powerpc.rs deleted file mode 100644 index 5524006..0000000 --- a/libc/src/vxworks/powerpc.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/libc/src/vxworks/powerpc64.rs b/libc/src/vxworks/powerpc64.rs deleted file mode 100644 index 4032488..0000000 --- a/libc/src/vxworks/powerpc64.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = u8; -pub type wchar_t = u32; -pub type c_long = i64; -pub type c_ulong = u64; diff --git a/libc/src/vxworks/x86.rs b/libc/src/vxworks/x86.rs deleted file mode 100644 index e617bb8..0000000 --- a/libc/src/vxworks/x86.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; -pub type c_long = i32; -pub type c_ulong = u32; diff --git a/libc/src/vxworks/x86_64.rs b/libc/src/vxworks/x86_64.rs deleted file mode 100644 index 5e95ea2..0000000 --- a/libc/src/vxworks/x86_64.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub type c_char = i8; -pub type wchar_t = i32; -pub type c_long = i64; -pub type c_ulong = u64; diff --git a/libc/src/wasi.rs b/libc/src/wasi.rs deleted file mode 100644 index 2e0914d..0000000 --- a/libc/src/wasi.rs +++ /dev/null @@ -1,743 +0,0 @@ -pub use ffi::c_void; - -pub type c_char = i8; -pub type c_uchar = u8; -pub type c_schar = i8; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_long = i32; -pub type c_ulong = u32; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; -pub type size_t = usize; -pub type ssize_t = isize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type off_t = i64; -pub type pid_t = i32; -pub type clock_t = c_longlong; -pub type time_t = c_longlong; -pub type c_double = f64; -pub type c_float = f32; -pub type ino_t = u64; -pub type sigset_t = c_uchar; -pub type suseconds_t = c_longlong; -pub type mode_t = u32; -pub type dev_t = u64; -pub type uid_t = u32; -pub type gid_t = u32; -pub type nlink_t = u64; -pub type blksize_t = c_long; -pub type blkcnt_t = i64; -pub type nfds_t = c_ulong; - -pub type __wasi_rights_t = u64; - -#[allow(missing_copy_implementations)] -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum FILE {} -#[allow(missing_copy_implementations)] -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum DIR {} -#[allow(missing_copy_implementations)] -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum __locale_struct {} - -pub type locale_t = *mut __locale_struct; - -s! { - #[repr(align(8))] - pub struct fpos_t { - data: [u8; 16], - } - - pub struct tm { - pub tm_sec: c_int, - pub tm_min: c_int, - pub tm_hour: c_int, - pub tm_mday: c_int, - pub tm_mon: c_int, - pub tm_year: c_int, - pub tm_wday: c_int, - pub tm_yday: c_int, - pub tm_isdst: c_int, - pub __tm_gmtoff: c_int, - pub __tm_zone: *const c_char, - pub __tm_nsec: c_int, - } - - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub struct tms { - pub tms_utime: clock_t, - pub tms_stime: clock_t, - pub tms_cutime: clock_t, - pub tms_cstime: clock_t, - } - - pub struct itimerspec { - pub it_interval: timespec, - pub it_value: timespec, - } - - pub struct iovec { - pub iov_base: *mut c_void, - pub iov_len: size_t, - } - - pub struct lconv { - pub decimal_point: *mut c_char, - pub thousands_sep: *mut c_char, - pub grouping: *mut c_char, - pub int_curr_symbol: *mut c_char, - pub currency_symbol: *mut c_char, - pub mon_decimal_point: *mut c_char, - pub mon_thousands_sep: *mut c_char, - pub mon_grouping: *mut c_char, - pub positive_sign: *mut c_char, - pub negative_sign: *mut c_char, - pub int_frac_digits: c_char, - pub frac_digits: c_char, - pub p_cs_precedes: c_char, - pub p_sep_by_space: c_char, - pub n_cs_precedes: c_char, - pub n_sep_by_space: c_char, - pub p_sign_posn: c_char, - pub n_sign_posn: c_char, - pub int_p_cs_precedes: c_char, - pub int_p_sep_by_space: c_char, - pub int_n_cs_precedes: c_char, - pub int_n_sep_by_space: c_char, - pub int_p_sign_posn: c_char, - pub int_n_sign_posn: c_char, - } - - pub struct pollfd { - pub fd: c_int, - pub events: c_short, - pub revents: c_short, - } - - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - } - - pub struct stat { - pub st_dev: dev_t, - pub st_ino: ino_t, - pub st_nlink: nlink_t, - pub st_mode: mode_t, - pub st_uid: uid_t, - pub st_gid: gid_t, - __pad0: c_uint, - pub st_rdev: dev_t, - pub st_size: off_t, - pub st_blksize: blksize_t, - pub st_blocks: blkcnt_t, - pub st_atim: timespec, - pub st_mtim: timespec, - pub st_ctim: timespec, - __reserved: [c_longlong; 3], - } -} - -// Declare dirent outside of s! so that it doesn't implement Copy, Eq, Hash, -// etc., since it contains a flexible array member with a dynamic size. -#[repr(C)] -#[allow(missing_copy_implementations)] -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub struct dirent { - pub d_ino: ino_t, - pub d_type: c_uchar, - /// d_name is declared in WASI libc as a flexible array member, which - /// can't be directly expressed in Rust. As an imperfect workaround, - /// declare it as a zero-length array instead. - pub d_name: [c_char; 0], -} - -pub const EXIT_SUCCESS: c_int = 0; -pub const EXIT_FAILURE: c_int = 1; -pub const STDIN_FILENO: c_int = 0; -pub const STDOUT_FILENO: c_int = 1; -pub const STDERR_FILENO: c_int = 2; -pub const SEEK_SET: c_int = 2; -pub const SEEK_CUR: c_int = 0; -pub const SEEK_END: c_int = 1; -pub const _IOFBF: c_int = 0; -pub const _IONBF: c_int = 2; -pub const _IOLBF: c_int = 1; -pub const FD_SETSIZE: size_t = 1024; -pub const O_APPEND: c_int = 0x0001; -pub const O_DSYNC: c_int = 0x0002; -pub const O_NONBLOCK: c_int = 0x0004; -pub const O_RSYNC: c_int = 0x0008; -pub const O_SYNC: c_int = 0x0010; -pub const O_CREAT: c_int = 0x0001 << 12; -pub const O_DIRECTORY: c_int = 0x0002 << 12; -pub const O_EXCL: c_int = 0x0004 << 12; -pub const O_TRUNC: c_int = 0x0008 << 12; -pub const O_NOFOLLOW: c_int = 0x01000000; -pub const O_EXEC: c_int = 0x02000000; -pub const O_RDONLY: c_int = 0x04000000; -pub const O_SEARCH: c_int = 0x08000000; -pub const O_WRONLY: c_int = 0x10000000; -pub const O_RDWR: c_int = O_WRONLY | O_RDONLY; -pub const O_ACCMODE: c_int = O_EXEC | O_RDWR | O_SEARCH; -pub const POSIX_FADV_DONTNEED: c_int = 4; -pub const POSIX_FADV_NOREUSE: c_int = 5; -pub const POSIX_FADV_NORMAL: c_int = 0; -pub const POSIX_FADV_RANDOM: c_int = 2; -pub const POSIX_FADV_SEQUENTIAL: c_int = 1; -pub const POSIX_FADV_WILLNEED: c_int = 3; -pub const AT_EACCESS: c_int = 0x0; -pub const AT_SYMLINK_NOFOLLOW: c_int = 0x1; -pub const AT_SYMLINK_FOLLOW: c_int = 0x2; -pub const AT_REMOVEDIR: c_int = 0x4; -pub const UTIME_OMIT: c_long = 1073741822; -pub const UTIME_NOW: c_long = 1073741823; - -pub const E2BIG: c_int = 1; -pub const EACCES: c_int = 2; -pub const EADDRINUSE: c_int = 3; -pub const EADDRNOTAVAIL: c_int = 4; -pub const EAFNOSUPPORT: c_int = 5; -pub const EAGAIN: c_int = 6; -pub const EALREADY: c_int = 7; -pub const EBADF: c_int = 8; -pub const EBADMSG: c_int = 9; -pub const EBUSY: c_int = 10; -pub const ECANCELED: c_int = 11; -pub const ECHILD: c_int = 12; -pub const ECONNABORTED: c_int = 13; -pub const ECONNREFUSED: c_int = 14; -pub const ECONNRESET: c_int = 15; -pub const EDEADLK: c_int = 16; -pub const EDESTADDRREQ: c_int = 17; -pub const EDOM: c_int = 18; -pub const EDQUOT: c_int = 19; -pub const EEXIST: c_int = 20; -pub const EFAULT: c_int = 21; -pub const EFBIG: c_int = 22; -pub const EHOSTUNREACH: c_int = 23; -pub const EIDRM: c_int = 24; -pub const EILSEQ: c_int = 25; -pub const EINPROGRESS: c_int = 26; -pub const EINTR: c_int = 27; -pub const EINVAL: c_int = 28; -pub const EIO: c_int = 29; -pub const EISCONN: c_int = 30; -pub const EISDIR: c_int = 31; -pub const ELOOP: c_int = 32; -pub const EMFILE: c_int = 33; -pub const EMLINK: c_int = 34; -pub const EMSGSIZE: c_int = 35; -pub const EMULTIHOP: c_int = 36; -pub const ENAMETOOLONG: c_int = 37; -pub const ENETDOWN: c_int = 38; -pub const ENETRESET: c_int = 39; -pub const ENETUNREACH: c_int = 40; -pub const ENFILE: c_int = 41; -pub const ENOBUFS: c_int = 42; -pub const ENODEV: c_int = 43; -pub const ENOENT: c_int = 44; -pub const ENOEXEC: c_int = 45; -pub const ENOLCK: c_int = 46; -pub const ENOLINK: c_int = 47; -pub const ENOMEM: c_int = 48; -pub const ENOMSG: c_int = 49; -pub const ENOPROTOOPT: c_int = 50; -pub const ENOSPC: c_int = 51; -pub const ENOSYS: c_int = 52; -pub const ENOTCONN: c_int = 53; -pub const ENOTDIR: c_int = 54; -pub const ENOTEMPTY: c_int = 55; -pub const ENOTRECOVERABLE: c_int = 56; -pub const ENOTSOCK: c_int = 57; -pub const ENOTSUP: c_int = 58; -pub const ENOTTY: c_int = 59; -pub const ENXIO: c_int = 60; -pub const EOVERFLOW: c_int = 61; -pub const EOWNERDEAD: c_int = 62; -pub const EPERM: c_int = 63; -pub const EPIPE: c_int = 64; -pub const EPROTO: c_int = 65; -pub const EPROTONOSUPPORT: c_int = 66; -pub const EPROTOTYPE: c_int = 67; -pub const ERANGE: c_int = 68; -pub const EROFS: c_int = 69; -pub const ESPIPE: c_int = 70; -pub const ESRCH: c_int = 71; -pub const ESTALE: c_int = 72; -pub const ETIMEDOUT: c_int = 73; -pub const ETXTBSY: c_int = 74; -pub const EXDEV: c_int = 75; -pub const ENOTCAPABLE: c_int = 76; -pub const EOPNOTSUPP: c_int = ENOTSUP; -pub const EWOULDBLOCK: c_int = EAGAIN; - -#[cfg_attr( - feature = "rustc-dep-of-std", - link(name = "c", kind = "static", cfg(target_feature = "crt-static")) -)] -#[cfg_attr( - feature = "rustc-dep-of-std", - link(name = "c", cfg(not(target_feature = "crt-static"))) -)] -extern "C" { - pub fn _Exit(code: c_int) -> !; - pub fn _exit(code: c_int) -> !; - pub fn abort() -> !; - pub fn aligned_alloc(a: size_t, b: size_t) -> *mut c_void; - pub fn calloc(amt: size_t, amt2: size_t) -> *mut c_void; - pub fn exit(code: c_int) -> !; - pub fn free(ptr: *mut c_void); - pub fn getenv(s: *const c_char) -> *mut c_char; - pub fn malloc(amt: size_t) -> *mut c_void; - pub fn malloc_usable_size(ptr: *mut c_void) -> size_t; - pub fn sbrk(increment: ::intptr_t) -> *mut ::c_void; - pub fn rand() -> c_int; - pub fn read(fd: c_int, ptr: *mut c_void, size: size_t) -> ssize_t; - pub fn realloc(ptr: *mut c_void, amt: size_t) -> *mut c_void; - pub fn setenv(k: *const c_char, v: *const c_char, a: c_int) -> c_int; - pub fn unsetenv(k: *const c_char) -> c_int; - pub fn clearenv() -> ::c_int; - pub fn write(fd: c_int, ptr: *const c_void, size: size_t) -> ssize_t; - pub static mut environ: *mut *mut c_char; - pub fn fopen(a: *const c_char, b: *const c_char) -> *mut FILE; - pub fn freopen( - a: *const c_char, - b: *const c_char, - f: *mut FILE, - ) -> *mut FILE; - pub fn fclose(f: *mut FILE) -> c_int; - pub fn remove(a: *const c_char) -> c_int; - pub fn rename(a: *const c_char, b: *const c_char) -> c_int; - pub fn feof(f: *mut FILE) -> c_int; - pub fn ferror(f: *mut FILE) -> c_int; - pub fn fflush(f: *mut FILE) -> c_int; - pub fn clearerr(f: *mut FILE); - pub fn fseek(f: *mut FILE, b: c_long, c: c_int) -> c_int; - pub fn ftell(f: *mut FILE) -> c_long; - pub fn rewind(f: *mut FILE); - pub fn fgetpos(f: *mut FILE, pos: *mut fpos_t) -> c_int; - pub fn fsetpos(f: *mut FILE, pos: *const fpos_t) -> c_int; - pub fn fread( - buf: *mut c_void, - a: size_t, - b: size_t, - f: *mut FILE, - ) -> size_t; - pub fn fwrite( - buf: *const c_void, - a: size_t, - b: size_t, - f: *mut FILE, - ) -> size_t; - pub fn fgetc(f: *mut FILE) -> c_int; - pub fn getc(f: *mut FILE) -> c_int; - pub fn getchar() -> c_int; - pub fn ungetc(a: c_int, f: *mut FILE) -> c_int; - pub fn fputc(a: c_int, f: *mut FILE) -> c_int; - pub fn putc(a: c_int, f: *mut FILE) -> c_int; - pub fn putchar(a: c_int) -> c_int; - pub fn fputs(a: *const c_char, f: *mut FILE) -> c_int; - pub fn puts(a: *const c_char) -> c_int; - pub fn perror(a: *const c_char); - pub fn srand(a: c_uint); - pub fn atexit(a: extern "C" fn()) -> c_int; - pub fn at_quick_exit(a: extern "C" fn()) -> c_int; - pub fn quick_exit(a: c_int) -> !; - pub fn posix_memalign(a: *mut *mut c_void, b: size_t, c: size_t) -> c_int; - pub fn rand_r(a: *mut c_uint) -> c_int; - pub fn random() -> c_long; - pub fn srandom(a: c_uint); - pub fn putenv(a: *mut c_char) -> c_int; - pub fn clock() -> clock_t; - pub fn time(a: *mut time_t) -> time_t; - pub fn difftime(a: time_t, b: time_t) -> c_double; - pub fn mktime(a: *mut tm) -> time_t; - pub fn strftime( - a: *mut c_char, - b: size_t, - c: *const c_char, - d: *const tm, - ) -> size_t; - pub fn gmtime(a: *const time_t) -> *mut tm; - pub fn gmtime_r(a: *const time_t, b: *mut tm) -> *mut tm; - pub fn localtime_r(a: *const time_t, b: *mut tm) -> *mut tm; - pub fn asctime_r(a: *const tm, b: *mut c_char) -> *mut c_char; - pub fn ctime_r(a: *const time_t, b: *mut c_char) -> *mut c_char; - - pub fn nanosleep(a: *const timespec, b: *mut timespec) -> c_int; - // pub fn clock_getres(a: clockid_t, b: *mut timespec) -> c_int; - // pub fn clock_gettime(a: clockid_t, b: *mut timespec) -> c_int; - // pub fn clock_nanosleep( - // a: clockid_t, - // a2: c_int, - // b: *const timespec, - // c: *mut timespec, - // ) -> c_int; - - pub fn isalnum(c: c_int) -> c_int; - pub fn isalpha(c: c_int) -> c_int; - pub fn iscntrl(c: c_int) -> c_int; - pub fn isdigit(c: c_int) -> c_int; - pub fn isgraph(c: c_int) -> c_int; - pub fn islower(c: c_int) -> c_int; - pub fn isprint(c: c_int) -> c_int; - pub fn ispunct(c: c_int) -> c_int; - pub fn isspace(c: c_int) -> c_int; - pub fn isupper(c: c_int) -> c_int; - pub fn isxdigit(c: c_int) -> c_int; - pub fn tolower(c: c_int) -> c_int; - pub fn toupper(c: c_int) -> c_int; - pub fn setvbuf( - stream: *mut FILE, - buffer: *mut c_char, - mode: c_int, - size: size_t, - ) -> c_int; - pub fn setbuf(stream: *mut FILE, buf: *mut c_char); - pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) - -> *mut c_char; - pub fn atoi(s: *const c_char) -> c_int; - pub fn atof(s: *const c_char) -> c_double; - pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; - pub fn strtol( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_long; - pub fn strtoul( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_ulong; - - pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; - pub fn strncpy( - dst: *mut c_char, - src: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; - pub fn strncat( - s: *mut c_char, - ct: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; - pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strdup(cs: *const c_char) -> *mut c_char; - pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int; - pub fn strncasecmp( - s1: *const c_char, - s2: *const c_char, - n: size_t, - ) -> c_int; - pub fn strlen(cs: *const c_char) -> size_t; - pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; - pub fn strerror(n: c_int) -> *mut c_char; - pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; - pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; - - pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memcpy( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memmove( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; - - pub fn fprintf( - stream: *mut ::FILE, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn printf(format: *const ::c_char, ...) -> ::c_int; - pub fn snprintf( - s: *mut ::c_char, - n: ::size_t, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int; - pub fn fscanf( - stream: *mut ::FILE, - format: *const ::c_char, - ... - ) -> ::c_int; - pub fn scanf(format: *const ::c_char, ...) -> ::c_int; - pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) - -> ::c_int; - pub fn getchar_unlocked() -> ::c_int; - pub fn putchar_unlocked(c: ::c_int) -> ::c_int; - - pub fn shutdown(socket: ::c_int, how: ::c_int) -> ::c_int; - pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; - pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int; - pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; - pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; - pub fn fileno(stream: *mut ::FILE) -> ::c_int; - pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; - pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int; - pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int; - pub fn opendir(dirname: *const c_char) -> *mut ::DIR; - pub fn fdopendir(fd: ::c_int) -> *mut ::DIR; - pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; - pub fn closedir(dirp: *mut ::DIR) -> ::c_int; - pub fn rewinddir(dirp: *mut ::DIR); - pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - - pub fn openat( - dirfd: ::c_int, - pathname: *const ::c_char, - flags: ::c_int, - ... - ) -> ::c_int; - pub fn fstatat( - dirfd: ::c_int, - pathname: *const ::c_char, - buf: *mut stat, - flags: ::c_int, - ) -> ::c_int; - pub fn linkat( - olddirfd: ::c_int, - oldpath: *const ::c_char, - newdirfd: ::c_int, - newpath: *const ::c_char, - flags: ::c_int, - ) -> ::c_int; - pub fn mkdirat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::mode_t, - ) -> ::c_int; - pub fn readlinkat( - dirfd: ::c_int, - pathname: *const ::c_char, - buf: *mut ::c_char, - bufsiz: ::size_t, - ) -> ::ssize_t; - pub fn renameat( - olddirfd: ::c_int, - oldpath: *const ::c_char, - newdirfd: ::c_int, - newpath: *const ::c_char, - ) -> ::c_int; - pub fn symlinkat( - target: *const ::c_char, - newdirfd: ::c_int, - linkpath: *const ::c_char, - ) -> ::c_int; - pub fn unlinkat( - dirfd: ::c_int, - pathname: *const ::c_char, - flags: ::c_int, - ) -> ::c_int; - - pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; - pub fn close(fd: ::c_int) -> ::c_int; - pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> c_long; - pub fn getopt( - argc: ::c_int, - argv: *const *mut c_char, - optstr: *const c_char, - ) -> ::c_int; - pub fn isatty(fd: ::c_int) -> ::c_int; - pub fn link(src: *const c_char, dst: *const c_char) -> ::c_int; - pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t; - pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long; - pub fn pause() -> ::c_int; - pub fn rmdir(path: *const c_char) -> ::c_int; - pub fn sleep(secs: ::c_uint) -> ::c_uint; - pub fn unlink(c: *const c_char) -> ::c_int; - pub fn pread( - fd: ::c_int, - buf: *mut ::c_void, - count: ::size_t, - offset: off_t, - ) -> ::ssize_t; - pub fn pwrite( - fd: ::c_int, - buf: *const ::c_void, - count: ::size_t, - offset: off_t, - ) -> ::ssize_t; - - pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int; - - pub fn fsync(fd: ::c_int) -> ::c_int; - pub fn fdatasync(fd: ::c_int) -> ::c_int; - - pub fn symlink(path1: *const c_char, path2: *const c_char) -> ::c_int; - - pub fn truncate(path: *const c_char, length: off_t) -> ::c_int; - pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int; - - pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int; - - pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn times(buf: *mut ::tms) -> ::clock_t; - - pub fn strerror_r( - errnum: ::c_int, - buf: *mut c_char, - buflen: ::size_t, - ) -> ::c_int; - - pub fn usleep(secs: ::c_uint) -> ::c_int; - pub fn send( - socket: ::c_int, - buf: *const ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - pub fn recv( - socket: ::c_int, - buf: *mut ::c_void, - len: ::size_t, - flags: ::c_int, - ) -> ::ssize_t; - pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int; - pub fn setlocale( - category: ::c_int, - locale: *const ::c_char, - ) -> *mut ::c_char; - pub fn localeconv() -> *mut lconv; - - pub fn readlink( - path: *const c_char, - buf: *mut c_char, - bufsz: ::size_t, - ) -> ::ssize_t; - - pub fn timegm(tm: *mut ::tm) -> time_t; - - pub fn sysconf(name: ::c_int) -> ::c_long; - - pub fn fseeko( - stream: *mut ::FILE, - offset: ::off_t, - whence: ::c_int, - ) -> ::c_int; - pub fn ftello(stream: *mut ::FILE) -> ::off_t; - pub fn posix_fallocate( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - ) -> ::c_int; - - pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn getline( - lineptr: *mut *mut c_char, - n: *mut size_t, - stream: *mut FILE, - ) -> ssize_t; - - pub fn faccessat( - dirfd: ::c_int, - pathname: *const ::c_char, - mode: ::c_int, - flags: ::c_int, - ) -> ::c_int; - pub fn writev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn readv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - ) -> ::ssize_t; - pub fn pwritev( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn preadv( - fd: ::c_int, - iov: *const ::iovec, - iovcnt: ::c_int, - offset: ::off_t, - ) -> ::ssize_t; - pub fn posix_fadvise( - fd: ::c_int, - offset: ::off_t, - len: ::off_t, - advise: ::c_int, - ) -> ::c_int; - pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; - pub fn utimensat( - dirfd: ::c_int, - path: *const ::c_char, - times: *const ::timespec, - flag: ::c_int, - ) -> ::c_int; - pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int; - pub fn memrchr( - cx: *const ::c_void, - c: ::c_int, - n: ::size_t, - ) -> *mut ::c_void; - pub fn abs(i: c_int) -> c_int; - pub fn labs(i: c_long) -> c_long; - pub fn duplocale(base: ::locale_t) -> ::locale_t; - pub fn freelocale(loc: ::locale_t); - pub fn newlocale( - mask: ::c_int, - locale: *const ::c_char, - base: ::locale_t, - ) -> ::locale_t; - pub fn uselocale(loc: ::locale_t) -> ::locale_t; - pub fn sched_yield() -> ::c_int; - - pub fn __wasilibc_register_preopened_fd( - fd: c_int, - path: *const c_char, - ) -> c_int; - pub fn __wasilibc_fd_renumber(fd: c_int, newfd: c_int) -> c_int; - pub fn __wasilibc_unlinkat(fd: c_int, path: *const c_char) -> c_int; - pub fn __wasilibc_rmdirat(fd: c_int, path: *const c_char) -> c_int; - pub fn __wasilibc_init_preopen(); - pub fn __wasilibc_find_relpath( - path: *const c_char, - rights_base: __wasi_rights_t, - rights_inheriting: __wasi_rights_t, - relative_path: *mut *const c_char, - ) -> c_int; - pub fn __wasilibc_tell(fd: c_int) -> ::off_t; - - pub fn arc4random() -> u32; - pub fn arc4random_buf(a: *mut c_void, b: size_t); - pub fn arc4random_uniform(a: u32) -> u32; -} diff --git a/libc/src/windows/gnu/align.rs b/libc/src/windows/gnu/align.rs deleted file mode 100644 index 3af99e3..0000000 --- a/libc/src/windows/gnu/align.rs +++ /dev/null @@ -1,19 +0,0 @@ -cfg_if! { - if #[cfg(target_pointer_width = "64")] { - s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [f64; 4] - } - } - } else if #[cfg(target_pointer_width = "32")] { - s_no_extra_traits! { - #[allow(missing_debug_implementations)] - #[repr(align(16))] - pub struct max_align_t { - priv_: [i64; 6] - } - } - } -} diff --git a/libc/src/windows/gnu/mod.rs b/libc/src/windows/gnu/mod.rs deleted file mode 100644 index e74628b..0000000 --- a/libc/src/windows/gnu/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -pub const L_tmpnam: ::c_uint = 14; -pub const TMP_MAX: ::c_uint = 0x7fff; - -// stdio file descriptor numbers -pub const STDIN_FILENO: ::c_int = 0; -pub const STDOUT_FILENO: ::c_int = 1; -pub const STDERR_FILENO: ::c_int = 2; - -extern "C" { - pub fn strcasecmp(s1: *const ::c_char, s2: *const ::c_char) -> ::c_int; - pub fn strncasecmp( - s1: *const ::c_char, - s2: *const ::c_char, - n: ::size_t, - ) -> ::c_int; -} - -cfg_if! { - if #[cfg(libc_align)] { - mod align; - pub use self::align::*; - } -} diff --git a/libc/src/windows/mod.rs b/libc/src/windows/mod.rs deleted file mode 100644 index a83baba..0000000 --- a/libc/src/windows/mod.rs +++ /dev/null @@ -1,604 +0,0 @@ -//! Windows CRT definitions - -pub type c_schar = i8; -pub type c_uchar = u8; -pub type c_short = i16; -pub type c_ushort = u16; -pub type c_int = i32; -pub type c_uint = u32; -pub type c_float = f32; -pub type c_double = f64; -pub type c_longlong = i64; -pub type c_ulonglong = u64; -pub type intmax_t = i64; -pub type uintmax_t = u64; - -pub type size_t = usize; -pub type ptrdiff_t = isize; -pub type intptr_t = isize; -pub type uintptr_t = usize; -pub type ssize_t = isize; -pub type sighandler_t = usize; - -pub type c_char = i8; -pub type c_long = i32; -pub type c_ulong = u32; -pub type wchar_t = u16; - -pub type clock_t = i32; - -cfg_if! { - if #[cfg(all(target_arch = "x86", target_env = "gnu"))] { - pub type time_t = i32; - } else { - pub type time_t = i64; - } -} - -pub type off_t = i32; -pub type dev_t = u32; -pub type ino_t = u16; -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum timezone {} -impl ::Copy for timezone {} -impl ::Clone for timezone { - fn clone(&self) -> timezone { - *self - } -} -pub type time64_t = i64; - -pub type SOCKET = ::uintptr_t; - -s! { - // note this is the struct called stat64 in Windows. Not stat, nor stati64. - pub struct stat { - pub st_dev: dev_t, - pub st_ino: ino_t, - pub st_mode: u16, - pub st_nlink: ::c_short, - pub st_uid: ::c_short, - pub st_gid: ::c_short, - pub st_rdev: dev_t, - pub st_size: i64, - pub st_atime: time64_t, - pub st_mtime: time64_t, - pub st_ctime: time64_t, - } - - // note that this is called utimbuf64 in Windows - pub struct utimbuf { - pub actime: time64_t, - pub modtime: time64_t, - } - - pub struct tm { - pub tm_sec: ::c_int, - pub tm_min: ::c_int, - pub tm_hour: ::c_int, - pub tm_mday: ::c_int, - pub tm_mon: ::c_int, - pub tm_year: ::c_int, - pub tm_wday: ::c_int, - pub tm_yday: ::c_int, - pub tm_isdst: ::c_int, - } - - pub struct timeval { - pub tv_sec: c_long, - pub tv_usec: c_long, - } - - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub struct sockaddr { - pub sa_family: c_ushort, - pub sa_data: [c_char; 14], - } -} - -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; - -pub const EXIT_FAILURE: ::c_int = 1; -pub const EXIT_SUCCESS: ::c_int = 0; -pub const RAND_MAX: ::c_int = 32767; -pub const EOF: ::c_int = -1; -pub const SEEK_SET: ::c_int = 0; -pub const SEEK_CUR: ::c_int = 1; -pub const SEEK_END: ::c_int = 2; -pub const _IOFBF: ::c_int = 0; -pub const _IONBF: ::c_int = 4; -pub const _IOLBF: ::c_int = 64; -pub const BUFSIZ: ::c_uint = 512; -pub const FOPEN_MAX: ::c_uint = 20; -pub const FILENAME_MAX: ::c_uint = 260; - -pub const O_RDONLY: ::c_int = 0; -pub const O_WRONLY: ::c_int = 1; -pub const O_RDWR: ::c_int = 2; -pub const O_APPEND: ::c_int = 8; -pub const O_CREAT: ::c_int = 256; -pub const O_EXCL: ::c_int = 1024; -pub const O_TEXT: ::c_int = 16384; -pub const O_BINARY: ::c_int = 32768; -pub const O_NOINHERIT: ::c_int = 128; -pub const O_TRUNC: ::c_int = 512; -pub const S_IFCHR: ::c_int = 8192; -pub const S_IFDIR: ::c_int = 16384; -pub const S_IFREG: ::c_int = 32768; -pub const S_IFMT: ::c_int = 61440; -pub const S_IEXEC: ::c_int = 64; -pub const S_IWRITE: ::c_int = 128; -pub const S_IREAD: ::c_int = 256; - -pub const LC_ALL: ::c_int = 0; -pub const LC_COLLATE: ::c_int = 1; -pub const LC_CTYPE: ::c_int = 2; -pub const LC_MONETARY: ::c_int = 3; -pub const LC_NUMERIC: ::c_int = 4; -pub const LC_TIME: ::c_int = 5; - -pub const EPERM: ::c_int = 1; -pub const ENOENT: ::c_int = 2; -pub const ESRCH: ::c_int = 3; -pub const EINTR: ::c_int = 4; -pub const EIO: ::c_int = 5; -pub const ENXIO: ::c_int = 6; -pub const E2BIG: ::c_int = 7; -pub const ENOEXEC: ::c_int = 8; -pub const EBADF: ::c_int = 9; -pub const ECHILD: ::c_int = 10; -pub const EAGAIN: ::c_int = 11; -pub const ENOMEM: ::c_int = 12; -pub const EACCES: ::c_int = 13; -pub const EFAULT: ::c_int = 14; -pub const EBUSY: ::c_int = 16; -pub const EEXIST: ::c_int = 17; -pub const EXDEV: ::c_int = 18; -pub const ENODEV: ::c_int = 19; -pub const ENOTDIR: ::c_int = 20; -pub const EISDIR: ::c_int = 21; -pub const EINVAL: ::c_int = 22; -pub const ENFILE: ::c_int = 23; -pub const EMFILE: ::c_int = 24; -pub const ENOTTY: ::c_int = 25; -pub const EFBIG: ::c_int = 27; -pub const ENOSPC: ::c_int = 28; -pub const ESPIPE: ::c_int = 29; -pub const EROFS: ::c_int = 30; -pub const EMLINK: ::c_int = 31; -pub const EPIPE: ::c_int = 32; -pub const EDOM: ::c_int = 33; -pub const ERANGE: ::c_int = 34; -pub const EDEADLK: ::c_int = 36; -pub const EDEADLOCK: ::c_int = 36; -pub const ENAMETOOLONG: ::c_int = 38; -pub const ENOLCK: ::c_int = 39; -pub const ENOSYS: ::c_int = 40; -pub const ENOTEMPTY: ::c_int = 41; -pub const EILSEQ: ::c_int = 42; -pub const STRUNCATE: ::c_int = 80; - -// POSIX Supplement (from errno.h) -pub const EADDRINUSE: ::c_int = 100; -pub const EADDRNOTAVAIL: ::c_int = 101; -pub const EAFNOSUPPORT: ::c_int = 102; -pub const EALREADY: ::c_int = 103; -pub const EBADMSG: ::c_int = 104; -pub const ECANCELED: ::c_int = 105; -pub const ECONNABORTED: ::c_int = 106; -pub const ECONNREFUSED: ::c_int = 107; -pub const ECONNRESET: ::c_int = 108; -pub const EDESTADDRREQ: ::c_int = 109; -pub const EHOSTUNREACH: ::c_int = 110; -pub const EIDRM: ::c_int = 111; -pub const EINPROGRESS: ::c_int = 112; -pub const EISCONN: ::c_int = 113; -pub const ELOOP: ::c_int = 114; -pub const EMSGSIZE: ::c_int = 115; -pub const ENETDOWN: ::c_int = 116; -pub const ENETRESET: ::c_int = 117; -pub const ENETUNREACH: ::c_int = 118; -pub const ENOBUFS: ::c_int = 119; -pub const ENODATA: ::c_int = 120; -pub const ENOLINK: ::c_int = 121; -pub const ENOMSG: ::c_int = 122; -pub const ENOPROTOOPT: ::c_int = 123; -pub const ENOSR: ::c_int = 124; -pub const ENOSTR: ::c_int = 125; -pub const ENOTCONN: ::c_int = 126; -pub const ENOTRECOVERABLE: ::c_int = 127; -pub const ENOTSOCK: ::c_int = 128; -pub const ENOTSUP: ::c_int = 129; -pub const EOPNOTSUPP: ::c_int = 130; -pub const EOVERFLOW: ::c_int = 132; -pub const EOWNERDEAD: ::c_int = 133; -pub const EPROTO: ::c_int = 134; -pub const EPROTONOSUPPORT: ::c_int = 135; -pub const EPROTOTYPE: ::c_int = 136; -pub const ETIME: ::c_int = 137; -pub const ETIMEDOUT: ::c_int = 138; -pub const ETXTBSY: ::c_int = 139; -pub const EWOULDBLOCK: ::c_int = 140; - -// signal codes -pub const SIGINT: ::c_int = 2; -pub const SIGILL: ::c_int = 4; -pub const SIGFPE: ::c_int = 8; -pub const SIGSEGV: ::c_int = 11; -pub const SIGTERM: ::c_int = 15; -pub const SIGABRT: ::c_int = 22; -pub const NSIG: ::c_int = 23; -pub const SIG_ERR: ::c_int = -1; - -// inline comment below appeases style checker -#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if " -#[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))] -#[link(name = "libcmt", cfg(target_feature = "crt-static"))] -extern "C" {} - -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum FILE {} -impl ::Copy for FILE {} -impl ::Clone for FILE { - fn clone(&self) -> FILE { - *self - } -} -#[cfg_attr(feature = "extra_traits", derive(Debug))] -pub enum fpos_t {} // TODO: fill this out with a struct -impl ::Copy for fpos_t {} -impl ::Clone for fpos_t { - fn clone(&self) -> fpos_t { - *self - } -} - -extern "C" { - pub fn isalnum(c: c_int) -> c_int; - pub fn isalpha(c: c_int) -> c_int; - pub fn iscntrl(c: c_int) -> c_int; - pub fn isdigit(c: c_int) -> c_int; - pub fn isgraph(c: c_int) -> c_int; - pub fn islower(c: c_int) -> c_int; - pub fn isprint(c: c_int) -> c_int; - pub fn ispunct(c: c_int) -> c_int; - pub fn isspace(c: c_int) -> c_int; - pub fn isupper(c: c_int) -> c_int; - pub fn isxdigit(c: c_int) -> c_int; - pub fn isblank(c: c_int) -> c_int; - pub fn tolower(c: c_int) -> c_int; - pub fn toupper(c: c_int) -> c_int; - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - pub fn freopen( - filename: *const c_char, - mode: *const c_char, - file: *mut FILE, - ) -> *mut FILE; - pub fn fflush(file: *mut FILE) -> c_int; - pub fn fclose(file: *mut FILE) -> c_int; - pub fn remove(filename: *const c_char) -> c_int; - pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; - pub fn tmpfile() -> *mut FILE; - pub fn setvbuf( - stream: *mut FILE, - buffer: *mut c_char, - mode: c_int, - size: size_t, - ) -> c_int; - pub fn setbuf(stream: *mut FILE, buf: *mut c_char); - pub fn getchar() -> c_int; - pub fn putchar(c: c_int) -> c_int; - pub fn fgetc(stream: *mut FILE) -> c_int; - pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) - -> *mut c_char; - pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; - pub fn puts(s: *const c_char) -> c_int; - pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fread( - ptr: *mut c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fwrite( - ptr: *const c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE, - ) -> size_t; - pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; - pub fn ftell(stream: *mut FILE) -> c_long; - pub fn rewind(stream: *mut FILE); - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; - pub fn feof(stream: *mut FILE) -> c_int; - pub fn ferror(stream: *mut FILE) -> c_int; - pub fn perror(s: *const c_char); - pub fn atoi(s: *const c_char) -> c_int; - pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; - pub fn strtol( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_long; - pub fn strtoul( - s: *const c_char, - endp: *mut *mut c_char, - base: c_int, - ) -> c_ulong; - pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; - pub fn malloc(size: size_t) -> *mut c_void; - pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; - pub fn free(p: *mut c_void); - pub fn abort() -> !; - pub fn exit(status: c_int) -> !; - pub fn _exit(status: c_int) -> !; - pub fn atexit(cb: extern "C" fn()) -> c_int; - pub fn system(s: *const c_char) -> c_int; - pub fn getenv(s: *const c_char) -> *mut c_char; - - pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; - pub fn strncpy( - dst: *mut c_char, - src: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; - pub fn strncat( - s: *mut c_char, - ct: *const c_char, - n: size_t, - ) -> *mut c_char; - pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; - pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strdup(cs: *const c_char) -> *mut c_char; - pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strlen(cs: *const c_char) -> size_t; - pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; - pub fn strerror(n: c_int) -> *mut c_char; - pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; - pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; - pub fn wcslen(buf: *const wchar_t) -> size_t; - pub fn wcstombs( - dest: *mut c_char, - src: *const wchar_t, - n: size_t, - ) -> ::size_t; - - pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; - pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memcpy( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memmove( - dest: *mut c_void, - src: *const c_void, - n: size_t, - ) -> *mut c_void; - pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; - - pub fn abs(i: c_int) -> c_int; - pub fn atof(s: *const c_char) -> c_double; - pub fn labs(i: c_long) -> c_long; - pub fn rand() -> c_int; - pub fn srand(seed: c_uint); - - pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; - pub fn raise(signum: c_int) -> c_int; - - #[link_name = "_time64"] - pub fn time(destTime: *mut time_t) -> time_t; - #[link_name = "_chmod"] - pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int; - #[link_name = "_wchmod"] - pub fn wchmod(path: *const wchar_t, mode: ::c_int) -> ::c_int; - #[link_name = "_mkdir"] - pub fn mkdir(path: *const c_char) -> ::c_int; - #[link_name = "_wrmdir"] - pub fn wrmdir(path: *const wchar_t) -> ::c_int; - #[link_name = "_fstat64"] - pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; - #[link_name = "_stat64"] - pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; - #[link_name = "_wstat64"] - pub fn wstat(path: *const wchar_t, buf: *mut stat) -> ::c_int; - #[link_name = "_wutime64"] - pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> ::c_int; - #[link_name = "_popen"] - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; - #[link_name = "_pclose"] - pub fn pclose(stream: *mut ::FILE) -> ::c_int; - #[link_name = "_fdopen"] - pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; - #[link_name = "_fileno"] - pub fn fileno(stream: *mut ::FILE) -> ::c_int; - #[link_name = "_open"] - pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; - #[link_name = "_wopen"] - pub fn wopen(path: *const wchar_t, oflag: ::c_int, ...) -> ::c_int; - #[link_name = "_creat"] - pub fn creat(path: *const c_char, mode: ::c_int) -> ::c_int; - #[link_name = "_access"] - pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; - #[link_name = "_chdir"] - pub fn chdir(dir: *const c_char) -> ::c_int; - #[link_name = "_close"] - pub fn close(fd: ::c_int) -> ::c_int; - #[link_name = "_dup"] - pub fn dup(fd: ::c_int) -> ::c_int; - #[link_name = "_dup2"] - pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; - #[link_name = "_execv"] - pub fn execv( - prog: *const c_char, - argv: *const *const c_char, - ) -> ::intptr_t; - #[link_name = "_execve"] - pub fn execve( - prog: *const c_char, - argv: *const *const c_char, - envp: *const *const c_char, - ) -> ::c_int; - #[link_name = "_execvp"] - pub fn execvp(c: *const c_char, argv: *const *const c_char) -> ::c_int; - #[link_name = "_execvpe"] - pub fn execvpe( - c: *const c_char, - argv: *const *const c_char, - envp: *const *const c_char, - ) -> ::c_int; - #[link_name = "_getcwd"] - pub fn getcwd(buf: *mut c_char, size: ::c_int) -> *mut c_char; - #[link_name = "_getpid"] - pub fn getpid() -> ::c_int; - #[link_name = "_isatty"] - pub fn isatty(fd: ::c_int) -> ::c_int; - #[link_name = "_lseek"] - pub fn lseek(fd: ::c_int, offset: c_long, origin: ::c_int) -> c_long; - #[link_name = "_lseeki64"] - pub fn lseek64( - fd: ::c_int, - offset: c_longlong, - origin: ::c_int, - ) -> c_longlong; - #[link_name = "_pipe"] - pub fn pipe( - fds: *mut ::c_int, - psize: ::c_uint, - textmode: ::c_int, - ) -> ::c_int; - #[link_name = "_read"] - pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::c_uint) -> ::c_int; - #[link_name = "_rmdir"] - pub fn rmdir(path: *const c_char) -> ::c_int; - #[link_name = "_unlink"] - pub fn unlink(c: *const c_char) -> ::c_int; - #[link_name = "_write"] - pub fn write( - fd: ::c_int, - buf: *const ::c_void, - count: ::c_uint, - ) -> ::c_int; - #[link_name = "_commit"] - pub fn commit(fd: ::c_int) -> ::c_int; - #[link_name = "_get_osfhandle"] - pub fn get_osfhandle(fd: ::c_int) -> ::intptr_t; - #[link_name = "_open_osfhandle"] - pub fn open_osfhandle(osfhandle: ::intptr_t, flags: ::c_int) -> ::c_int; - pub fn setlocale(category: ::c_int, locale: *const c_char) -> *mut c_char; - #[link_name = "_wsetlocale"] - pub fn wsetlocale( - category: ::c_int, - locale: *const wchar_t, - ) -> *mut wchar_t; -} - -extern "system" { - pub fn listen(s: SOCKET, backlog: ::c_int) -> ::c_int; - pub fn accept( - s: SOCKET, - addr: *mut ::sockaddr, - addrlen: *mut ::c_int, - ) -> SOCKET; - pub fn bind( - s: SOCKET, - name: *const ::sockaddr, - namelen: ::c_int, - ) -> ::c_int; - pub fn connect( - s: SOCKET, - name: *const ::sockaddr, - namelen: ::c_int, - ) -> ::c_int; - pub fn getpeername( - s: SOCKET, - name: *mut ::sockaddr, - nameln: *mut ::c_int, - ) -> ::c_int; - pub fn getsockname( - s: SOCKET, - name: *mut ::sockaddr, - nameln: *mut ::c_int, - ) -> ::c_int; - pub fn getsockopt( - s: SOCKET, - level: ::c_int, - optname: ::c_int, - optval: *mut ::c_char, - optlen: *mut ::c_int, - ) -> ::c_int; - pub fn recvfrom( - s: SOCKET, - buf: *mut ::c_char, - len: ::c_int, - flags: ::c_int, - from: *mut ::sockaddr, - fromlen: *mut ::c_int, - ) -> ::c_int; - pub fn sendto( - s: SOCKET, - buf: *const ::c_char, - len: ::c_int, - flags: ::c_int, - to: *const ::sockaddr, - tolen: ::c_int, - ) -> ::c_int; - pub fn setsockopt( - s: SOCKET, - level: ::c_int, - optname: ::c_int, - optval: *const ::c_char, - optlen: ::c_int, - ) -> ::c_int; - pub fn socket( - af: ::c_int, - socket_type: ::c_int, - protocol: ::c_int, - ) -> SOCKET; -} - -cfg_if! { - if #[cfg(libc_core_cvoid)] { - pub use ::ffi::c_void; - } else { - // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help - // enable more optimization opportunities around it recognizing things - // like malloc/free. - #[repr(u8)] - #[allow(missing_copy_implementations)] - #[allow(missing_debug_implementations)] - pub enum c_void { - // Two dummy variants so the #[repr] attribute can be used. - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - } -} - -cfg_if! { - if #[cfg(all(target_env = "gnu"))] { - mod gnu; - pub use self::gnu::*; - } else if #[cfg(all(target_env = "msvc"))] { - mod msvc; - pub use self::msvc::*; - } else { - // Unknown target_env - } -} diff --git a/libc/src/windows/msvc.rs b/libc/src/windows/msvc.rs deleted file mode 100644 index 8f20deb..0000000 --- a/libc/src/windows/msvc.rs +++ /dev/null @@ -1,17 +0,0 @@ -pub const L_tmpnam: ::c_uint = 260; -pub const TMP_MAX: ::c_uint = 0x7fff_ffff; - -// POSIX Supplement (from errno.h) -// This particular error code is only currently available in msvc toolchain -pub const EOTHER: ::c_int = 131; - -extern "C" { - #[link_name = "_stricmp"] - pub fn stricmp(s1: *const ::c_char, s2: *const ::c_char) -> ::c_int; - #[link_name = "_strnicmp"] - pub fn strnicmp( - s1: *const ::c_char, - s2: *const ::c_char, - n: ::size_t, - ) -> ::c_int; -} diff --git a/libc/tests/const_fn.rs b/libc/tests/const_fn.rs deleted file mode 100644 index 0e7e186..0000000 --- a/libc/tests/const_fn.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![cfg(libc_const_extern_fn)] // If this does not hold, the file is empty - -#[cfg(target_os = "linux")] -const _FOO: libc::c_uint = unsafe { libc::CMSG_SPACE(1) }; -//^ if CMSG_SPACE is not const, this will fail to compile diff --git a/nitrocli/CHANGELOG.md b/nitrocli/CHANGELOG.md index e331f2f..9147ec5 100644 --- a/nitrocli/CHANGELOG.md +++ b/nitrocli/CHANGELOG.md @@ -1,3 +1,8 @@ +Unreleased +---------- +- Removed vendored dependencies + + 0.3.1 ----- - Added note about interaction with GnuPG to `README` file diff --git a/nitrocli/Cargo.lock b/nitrocli/Cargo.lock index 5f2a127..3e914a4 100644 --- a/nitrocli/Cargo.lock +++ b/nitrocli/Cargo.lock @@ -11,35 +11,42 @@ dependencies = [ [[package]] name = "argparse" version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "base32" version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "getrandom" version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10", - "libc 0.2.66", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "lazy_static" version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" version = "0.2.66" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memchr" @@ -50,10 +57,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "nitrocli" version = "0.3.1" dependencies = [ - "argparse 0.2.2", - "base32 0.4.0", - "libc 0.2.66", - "nitrokey 0.4.0", + "argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "base32 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "nitrokey 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "nitrokey-test 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "nitrokey-test-state 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -62,18 +69,20 @@ dependencies = [ [[package]] name = "nitrokey" version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.4.0", - "libc 0.2.66", - "nitrokey-sys 3.5.0", - "rand_core 0.5.1", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "nitrokey-sys 3.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "nitrokey-sys" version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.48", + "cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -110,8 +119,9 @@ dependencies = [ [[package]] name = "rand_core" version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "getrandom 0.1.13", + "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -145,7 +155,7 @@ name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.4.0", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -160,11 +170,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" +"checksum argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3f8ebf5827e4ac4fd5946560e6a99776ea73b596d80898f357007317a7141e47" +"checksum base32 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" +"checksum cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" +"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" +"checksum nitrokey 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5f19c16e1530850b171e98ad1c95fe0af897916eb308e19fbfd3ee2dcda0abe" +"checksum nitrokey-sys 3.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71c6052aeb37309317d25c8fec2801f271b96c5a15656f2573d8e78ba4124c49" "checksum nitrokey-test 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f3da0c2cedaa512f79fbc3ed45143a52c76c5edcca88d0823b967ff11d05fe37" "checksum nitrokey-test-state 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a59b732ed6d5212424ed31ec9649f05652bcbc38f45f2292b27a6044e7098803" "checksum proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" "checksum syn 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc157159e2a7df58cd67b1cace10b8ed256a404fb0070593f137d8ba6bef4de" diff --git a/nitrocli/Cargo.toml b/nitrocli/Cargo.toml index a18cae9..63e6409 100644 --- a/nitrocli/Cargo.toml +++ b/nitrocli/Cargo.toml @@ -47,7 +47,6 @@ version = "0.2.2" [dependencies.base32] version = "0.4.0" -path = "../base32" [dependencies.libc] version = "0.2" @@ -63,15 +62,3 @@ version = "0.1" [dev-dependencies.regex] version = "1" - -[patch.crates-io] -argparse = { path = "../argparse" } -base32 = { path = "../base32" } -cc = { path = "../cc" } -cfg-if = { path = "../cfg-if" } -getrandom = { path = "../getrandom" } -libc = { path = "../libc" } -nitrokey = { path = "../nitrokey" } -nitrokey-sys = { path = "../nitrokey-sys" } -lazy_static = { path = "../lazy-static" } -rand_core = { path = "../rand/rand_core" } diff --git a/nitrokey-sys/.gitignore b/nitrokey-sys/.gitignore deleted file mode 100644 index a821aa9..0000000 --- a/nitrokey-sys/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ - -/target -**/*.rs.bk -Cargo.lock diff --git a/nitrokey-sys/CHANGELOG.md b/nitrokey-sys/CHANGELOG.md deleted file mode 100644 index a440ca1..0000000 --- a/nitrokey-sys/CHANGELOG.md +++ /dev/null @@ -1,76 +0,0 @@ -# v3.5.0 (2019-07-04) -- Mark deprecated functions using the `deprecated` attribute. -- Update to libnitrokey 3.5, causing all following changes. -- New constant `NK_PWS_SLOT_COUNT`. -- New structures: - - `NK_device_info` - - `NK_status` - - `NK_SD_usage_data` - - `ReadSlot_t` -- New functions: - - `NK_get_SD_usage_data` - - `NK_get_status` - - `NK_get_status_as_string` - - `NK_list_devices` - - `NK_free_device_info` - - `NK_connect_with_path` - - `NK_enable_firmware_update_pro` - - `NK_change_firmware_password_pro` - - `NK_read_HOTP_slot` -- Deprecated functions: - - `NK_status` -- Changed the return type for `NK_get_major_firmware_version` and - `NK_get_minor_firmware_version` to `u8`. -- Changed `NK_get_progress_bar_value` to return -2 instead of 0 if an error - occurs. - -# v3.4.3 (2019-10-12) -- Link directly against `libnitrokey` if the `USE_SYSTEM_LIBNITROKEY` - environment variable is set. - -# v3.4.2 (2019-01-01) -- Use the -std=c++14 compiler flag. -- Change the build script to link to `-lhidapi` on non-Linux operating systems - (while still using `-lhidapi-libusb` on Linux). -- Decouple the libnitrokey and nitrokey-sys-rs versions. - -# v3.4.1 (2018-12-10) - -- Update to libnitrokey 3.4.1. There are no changes affecting this crate. - -# v3.4.0 (2018-12-10) - -- Update to libnitrokey 3.4, causing all following changes. -- New constant `NK_device_model_NK_DISCONNECTED` in the `NK_device_model` - enumeration. -- New structures: - - `NK_storage_ProductionTest` - - `NK_storage_status` -- New functions: - - `NK_get_device_model` - - `NK_get_library_version` - - `NK_get_major_library_version` - - `NK_get_minor_libray_version` - - `NK_get_status_storage` - - `NK_get_storage_production_info` - - `NK_totp_set_time_soft` - - `NK_wink` -- The function `NK_totp_get_time` is now deprecated. If applicable, - `NK_totp_set_time_soft` should be used instead. See the [upstream pull - request #114][] for details. -- Strings are now returned as mutable instead of constant pointers. - -# v3.3.0 (2018-05-21) - -- Change the crate license to LGPL 3.0. -- Adapt the crate version number according to the bundled `libnitrokey` - version. -- Include a copy of `libnitrokey`. -- Compile `libnitrokey` from source. -- Generate the `bindgen` bindings statically and add them to the repository. - -# v0.1.0 (2018-05-19) - -- Initial release. - -[upstream pull request #114]: https://github.com/Nitrokey/libnitrokey/pull/114 diff --git a/nitrokey-sys/Cargo.toml b/nitrokey-sys/Cargo.toml deleted file mode 100644 index 068670b..0000000 --- a/nitrokey-sys/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "nitrokey-sys" -version = "3.5.0" -authors = ["Robin Krahl "] -edition = "2018" -homepage = "https://code.ireas.org/nitrokey-rs/" -repository = "https://git.ireas.org/nitrokey-sys-rs/" -description = "Low-level bindings to libnitrokey for communication with Nitrokey devices" -categories = ["external-ffi-bindings"] -license = "LGPL-3.0" -links = "nitrokey" -build = "build.rs" -readme = "README.md" - -[build-dependencies] -cc = "1.0" diff --git a/nitrokey-sys/LICENSE b/nitrokey-sys/LICENSE deleted file mode 100644 index 341c30b..0000000 --- a/nitrokey-sys/LICENSE +++ /dev/null @@ -1,166 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. - diff --git a/nitrokey-sys/README.md b/nitrokey-sys/README.md deleted file mode 100644 index 343b7b5..0000000 --- a/nitrokey-sys/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# nitrokey-sys-rs - -Low-level Rust bindings for `libnitrokey`, providing access to Nitrokey -devices. - -This crate contains a copy of the [`libnitrokey`][] library, builds it from -source and links it statically. The host system must provide its dependencies -in the library search path: - -- `libhidapi-libusb0` (on Linux) -- `libhidapi` (on non-Linux systems) - -If you set the `USE_SYSTEM_LIBNITROKEY` environment variable when building this -crate, it links directly against `libnitrokey` instead of building it from -source. In this case, `libnitrokey` must be available in the library search -path. - -## Versioning - -The major and minor version of the `nitrokey-sys` crate map to the major and -minor version of `libnitrokey`. The `nitrokey-sys` patch version may be -increased independently. - -## Contact - -For bug reports, patches, feature requests or other messages, please send a -mail to [nitrokey-rs-dev@ireas.org][]. - -## License - -This project as well as `libnitrokey` are licensed under the [LGPL-3.0][]. - -[`libnitrokey`]: https://github.com/nitrokey/libnitrokey -[nitrokey-rs-dev@ireas.org]: mailto:nitrokey-rs-dev@ireas.org -[LGPL-3.0]: https://opensource.org/licenses/lgpl-3.0.html diff --git a/nitrokey-sys/build.rs b/nitrokey-sys/build.rs deleted file mode 100644 index a9d0778..0000000 --- a/nitrokey-sys/build.rs +++ /dev/null @@ -1,94 +0,0 @@ -use std::env; -use std::fs; -use std::io; -use std::io::{Read, Write}; -use std::path; -use std::string; - -use cc; - -#[derive(Clone, Copy, Debug, PartialEq)] -struct Version { - major: u32, - minor: u32, - patch: Option, -} - -impl string::ToString for Version { - fn to_string(&self) -> String { - match self.patch { - Some(patch) => format!("v{}.{}.{}", self.major, self.minor, patch), - None => format!("v{}.{}", self.major, self.minor), - } - } -} - -const LIBNITROKEY_VERSION: Version = Version { - major: 3, - minor: 5, - patch: None, -}; - -fn prepare_version_source( - version: Version, - out_path: &path::Path, - library_path: &path::Path, -) -> io::Result { - let out = out_path.join("version.cc"); - let template = library_path.join("version.cc.in"); - - let mut file = fs::File::open(template)?; - let mut data = String::new(); - file.read_to_string(&mut data)?; - drop(file); - - let data = data - .replace("@PROJECT_VERSION_MAJOR@", &version.major.to_string()) - .replace("@PROJECT_VERSION_MINOR@", &version.minor.to_string()) - .replace("@PROJECT_VERSION_GIT@", &version.to_string()); - - let mut file = fs::File::create(&out)?; - file.write_all(data.as_bytes())?; - - Ok(out) -} - -fn main() { - if env::var("USE_SYSTEM_LIBNITROKEY").is_ok() { - println!("cargo:rustc-link-lib=nitrokey"); - return; - } - - let out_dir = env::var("OUT_DIR").expect("Environment variable OUT_DIR is not set"); - let out_path = path::PathBuf::from(out_dir); - - let sources = [ - "DeviceCommunicationExceptions.cpp", - "NK_C_API.cc", - "NitrokeyManager.cc", - "command_id.cc", - "device.cc", - "log.cc", - "misc.cc", - ]; - let library_dir = format!("libnitrokey-{}", LIBNITROKEY_VERSION.to_string()); - let library_path = path::Path::new(&library_dir); - - let version_source = prepare_version_source(LIBNITROKEY_VERSION, &out_path, &library_path) - .expect("Could not prepare the version source file"); - - cc::Build::new() - .cpp(true) - .flag("-std=c++14") - .include(library_path.join("libnitrokey")) - .files(sources.iter().map(|s| library_path.join(s))) - .file(version_source) - .compile("libnitrokey.a"); - - let hidapi_library_name = if cfg!(target_os = "linux") { - "hidapi-libusb" - } else { - "hidapi" - }; - println!("cargo:rustc-link-lib={}", hidapi_library_name); -} diff --git a/nitrokey-sys/libnitrokey-v3.5/DeviceCommunicationExceptions.cpp b/nitrokey-sys/libnitrokey-v3.5/DeviceCommunicationExceptions.cpp deleted file mode 100644 index 4d62aad..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/DeviceCommunicationExceptions.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include "DeviceCommunicationExceptions.h" - -std::atomic_int DeviceCommunicationException::occurred {0}; diff --git a/nitrokey-sys/libnitrokey-v3.5/LICENSE b/nitrokey-sys/libnitrokey-v3.5/LICENSE deleted file mode 100644 index 341c30b..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/LICENSE +++ /dev/null @@ -1,166 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. - diff --git a/nitrokey-sys/libnitrokey-v3.5/NK_C_API.cc b/nitrokey-sys/libnitrokey-v3.5/NK_C_API.cc deleted file mode 100644 index 1d3fa3a..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/NK_C_API.cc +++ /dev/null @@ -1,910 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include "NK_C_API.h" -#include -#include -#include "libnitrokey/NitrokeyManager.h" -#include -#include "libnitrokey/LibraryException.h" -#include "libnitrokey/cxx_semantics.h" -#include "libnitrokey/stick20_commands.h" -#include "libnitrokey/device_proto.h" -#include "libnitrokey/version.h" - -#ifdef _MSC_VER -#ifdef _WIN32 -#pragma message "Using own strndup" -char * strndup(const char* str, size_t maxlen) { - size_t len = strnlen(str, maxlen); - char* dup = (char *)malloc(len + 1); - memcpy(dup, str, len); - dup[len] = 0; - return dup; -} -#endif -#endif - -using namespace nitrokey; - -const uint8_t NK_PWS_SLOT_COUNT = PWS_SLOT_COUNT; -static uint8_t NK_last_command_status = 0; -static const int max_string_field_length = 100; - -template -T* duplicate_vector_and_clear(std::vector &v){ - auto d = new T[v.size()]; - std::copy(v.begin(), v.end(), d); - std::fill(v.begin(), v.end(), 0); - return d; -} - -template -std::tuple get_with_status(T func, R fallback) { - NK_last_command_status = 0; - try { - return std::make_tuple(0, func()); - } - catch (CommandFailedException & commandFailedException){ - NK_last_command_status = commandFailedException.last_command_status; - } - catch (LibraryException & libraryException){ - NK_last_command_status = libraryException.exception_id(); - } - catch (const DeviceCommunicationException &deviceException){ - NK_last_command_status = 256-deviceException.getType(); - } - return std::make_tuple(NK_last_command_status, fallback); -} - -template -uint8_t * get_with_array_result(T func){ - return std::get<1>(get_with_status(func, nullptr)); -} - -template -char* get_with_string_result(T func){ - auto result = std::get<1>(get_with_status(func, nullptr)); - if (result == nullptr) { - return strndup("", MAXIMUM_STR_REPLY_LENGTH); - } - return result; -} - -template -auto get_with_result(T func){ - return std::get<1>(get_with_status(func, static_cast(0))); -} - -template -uint8_t get_without_result(T func){ - NK_last_command_status = 0; - try { - func(); - return 0; - } - catch (CommandFailedException & commandFailedException){ - NK_last_command_status = commandFailedException.last_command_status; - } - catch (LibraryException & libraryException){ - NK_last_command_status = libraryException.exception_id(); - } - catch (const InvalidCRCReceived &invalidCRCException){ - ; - } - catch (const DeviceCommunicationException &deviceException){ - NK_last_command_status = 256-deviceException.getType(); - } - return NK_last_command_status; -} - - -#ifdef __cplusplus -extern "C" { -#endif - - NK_C_API uint8_t NK_get_last_command_status() { - auto _copy = NK_last_command_status; - NK_last_command_status = 0; - return _copy; - } - - NK_C_API int NK_login(const char *device_model) { - auto m = NitrokeyManager::instance(); - try { - NK_last_command_status = 0; - return m->connect(device_model); - } - catch (CommandFailedException & commandFailedException) { - NK_last_command_status = commandFailedException.last_command_status; - return commandFailedException.last_command_status; - } - catch (const DeviceCommunicationException &deviceException){ - NK_last_command_status = 256-deviceException.getType(); - cerr << deviceException.what() << endl; - return 0; - } - catch (std::runtime_error &e) { - cerr << e.what() << endl; - return 0; - } - return 0; - } - - NK_C_API int NK_login_enum(NK_device_model device_model) { - const char *model_string; - switch (device_model) { - case NK_PRO: - model_string = "P"; - break; - case NK_STORAGE: - model_string = "S"; - break; - case NK_DISCONNECTED: - default: - /* no such enum value -- return error code */ - return 0; - } - return NK_login(model_string); - } - - NK_C_API int NK_logout() { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->disconnect(); - }); - } - - NK_C_API int NK_first_authenticate(const char* admin_password, const char* admin_temporary_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - return m->first_authenticate(admin_password, admin_temporary_password); - }); - } - - - NK_C_API int NK_user_authenticate(const char* user_password, const char* user_temporary_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->user_authenticate(user_password, user_temporary_password); - }); - } - - NK_C_API int NK_factory_reset(const char* admin_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->factory_reset(admin_password); - }); - } - NK_C_API int NK_build_aes_key(const char* admin_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->build_aes_key(admin_password); - }); - } - - NK_C_API int NK_unlock_user_password(const char *admin_password, const char *new_user_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->unlock_user_password(admin_password, new_user_password); - }); - } - - NK_C_API int NK_write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password, - bool delete_user_password, - const char *admin_temporary_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - return m->write_config(numlock, capslock, scrolllock, enable_user_password, delete_user_password, admin_temporary_password); - }); - } - - - NK_C_API uint8_t* NK_read_config() { - auto m = NitrokeyManager::instance(); - return get_with_array_result([&]() { - auto v = m->read_config(); - return duplicate_vector_and_clear(v); - }); - } - - - NK_C_API enum NK_device_model NK_get_device_model() { - auto m = NitrokeyManager::instance(); - try { - auto model = m->get_connected_device_model(); - switch (model) { - case DeviceModel::PRO: - return NK_PRO; - case DeviceModel::STORAGE: - return NK_STORAGE; - default: - /* unknown or not connected device */ - return NK_device_model::NK_DISCONNECTED; - } - } catch (const DeviceNotConnected& e) { - return NK_device_model::NK_DISCONNECTED; - } -} - - - void clear_string(std::string &s) { - std::fill(s.begin(), s.end(), ' '); - } - - - NK_C_API char * NK_status() { - return NK_get_status_as_string(); - } - - NK_C_API char * NK_get_status_as_string() { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - string && s = m->get_status_as_string(); - char * rs = strndup(s.c_str(), MAXIMUM_STR_REPLY_LENGTH); - clear_string(s); - return rs; - }); - } - - NK_C_API int NK_get_status(struct NK_status* out) { - if (out == nullptr) { - return -1; - } - auto m = NitrokeyManager::instance(); - auto result = get_with_status([&]() { - return m->get_status(); - }, proto::stick10::GetStatus::ResponsePayload()); - auto error_code = std::get<0>(result); - if (error_code != 0) { - return error_code; - } - - auto status = std::get<1>(result); - out->firmware_version_major = status.firmware_version_st.major; - out->firmware_version_minor = status.firmware_version_st.minor; - out->serial_number_smart_card = status.card_serial_u32; - out->config_numlock = status.numlock; - out->config_capslock = status.capslock; - out->config_scrolllock = status.scrolllock; - out->otp_user_password = status.enable_user_password != 0; - return 0; - } - - NK_C_API char * NK_device_serial_number() { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - string && s = m->get_serial_number(); - char * rs = strndup(s.c_str(), max_string_field_length); - clear_string(s); - return rs; - }); - } - - NK_C_API char * NK_get_hotp_code(uint8_t slot_number) { - return NK_get_hotp_code_PIN(slot_number, ""); - } - - NK_C_API char * NK_get_hotp_code_PIN(uint8_t slot_number, const char *user_temporary_password) { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - string && s = m->get_HOTP_code(slot_number, user_temporary_password); - char * rs = strndup(s.c_str(), max_string_field_length); - clear_string(s); - return rs; - }); - } - - NK_C_API char * NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, - uint8_t last_interval) { - return NK_get_totp_code_PIN(slot_number, challenge, last_totp_time, last_interval, ""); - } - - NK_C_API char * NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, - uint8_t last_interval, const char *user_temporary_password) { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - string && s = m->get_TOTP_code(slot_number, challenge, last_totp_time, last_interval, user_temporary_password); - char * rs = strndup(s.c_str(), max_string_field_length); - clear_string(s); - return rs; - }); - } - - NK_C_API int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&] { - m->erase_hotp_slot(slot_number, temporary_password); - }); - } - - NK_C_API int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&] { - m->erase_totp_slot(slot_number, temporary_password); - }); - } - - NK_C_API int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&] { - m->write_HOTP_slot(slot_number, slot_name, secret, hotp_counter, use_8_digits, use_enter, use_tokenID, token_ID, - temporary_password); - }); - } - - NK_C_API int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&] { - m->write_TOTP_slot(slot_number, slot_name, secret, time_window, use_8_digits, use_enter, use_tokenID, token_ID, - temporary_password); - }); - } - - NK_C_API char* NK_get_totp_slot_name(uint8_t slot_number) { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - const auto slot_name = m->get_totp_slot_name(slot_number); - return slot_name; - }); - } - NK_C_API char* NK_get_hotp_slot_name(uint8_t slot_number) { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - const auto slot_name = m->get_hotp_slot_name(slot_number); - return slot_name; - }); - } - - NK_C_API void NK_set_debug(bool state) { - auto m = NitrokeyManager::instance(); - m->set_debug(state); - } - - - NK_C_API void NK_set_debug_level(const int level) { - auto m = NitrokeyManager::instance(); - m->set_loglevel(level); - } - - NK_C_API unsigned int NK_get_major_library_version() { - return get_major_library_version(); - } - - NK_C_API unsigned int NK_get_minor_library_version() { - return get_minor_library_version(); - } - - NK_C_API const char* NK_get_library_version() { - return get_library_version(); - } - - NK_C_API int NK_totp_set_time(uint64_t time) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->set_time(time); - }); - } - - NK_C_API int NK_totp_set_time_soft(uint64_t time) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->set_time_soft(time); - }); - } - - NK_C_API int NK_totp_get_time() { - return 0; - } - - NK_C_API int NK_change_admin_PIN(const char *current_PIN, const char *new_PIN) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->change_admin_PIN(current_PIN, new_PIN); - }); - } - - NK_C_API int NK_change_user_PIN(const char *current_PIN, const char *new_PIN) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->change_user_PIN(current_PIN, new_PIN); - }); - } - - NK_C_API int NK_enable_password_safe(const char *user_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->enable_password_safe(user_pin); - }); - } - NK_C_API uint8_t * NK_get_password_safe_slot_status() { - auto m = NitrokeyManager::instance(); - return get_with_array_result([&]() { - auto slot_status = m->get_password_safe_slot_status(); - return duplicate_vector_and_clear(slot_status); - }); - - } - - NK_C_API uint8_t NK_get_user_retry_count() { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return m->get_user_retry_count(); - }); - } - - NK_C_API uint8_t NK_get_admin_retry_count() { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return m->get_admin_retry_count(); - }); - } - - NK_C_API int NK_lock_device() { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->lock_device(); - }); - } - - NK_C_API char *NK_get_password_safe_slot_name(uint8_t slot_number) { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - return m->get_password_safe_slot_name(slot_number); - }); - } - - NK_C_API char *NK_get_password_safe_slot_login(uint8_t slot_number) { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - return m->get_password_safe_slot_login(slot_number); - }); - } - NK_C_API char *NK_get_password_safe_slot_password(uint8_t slot_number) { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - return m->get_password_safe_slot_password(slot_number); - }); - } - NK_C_API int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, - const char *slot_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->write_password_safe_slot(slot_number, slot_name, slot_login, slot_password); - }); - } - - NK_C_API int NK_erase_password_safe_slot(uint8_t slot_number) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->erase_password_safe_slot(slot_number); - }); - } - - NK_C_API int NK_is_AES_supported(const char *user_password) { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return (uint8_t)m->is_AES_supported(user_password); - }); - } - - NK_C_API int NK_login_auto() { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return (uint8_t)m->connect(); - }); - } - - // storage commands - - NK_C_API int NK_send_startup(uint64_t seconds_from_epoch) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->send_startup(seconds_from_epoch); - }); - } - - NK_C_API int NK_unlock_encrypted_volume(const char* user_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->unlock_encrypted_volume(user_pin); - }); - } - - NK_C_API int NK_lock_encrypted_volume() { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->lock_encrypted_volume(); - }); - } - - NK_C_API int NK_unlock_hidden_volume(const char* hidden_volume_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->unlock_hidden_volume(hidden_volume_password); - }); - } - - NK_C_API int NK_lock_hidden_volume() { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->lock_hidden_volume(); - }); - } - - NK_C_API int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, - const char *hidden_volume_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->create_hidden_volume(slot_nr, start_percent, end_percent, - hidden_volume_password); - }); - } - - NK_C_API int NK_set_unencrypted_read_only(const char *user_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->set_unencrypted_read_only(user_pin); - }); - } - - NK_C_API int NK_set_unencrypted_read_write(const char *user_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->set_unencrypted_read_write(user_pin); - }); - } - - NK_C_API int NK_set_unencrypted_read_only_admin(const char *admin_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->set_unencrypted_read_only_admin(admin_pin); - }); - } - - NK_C_API int NK_set_unencrypted_read_write_admin(const char *admin_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->set_unencrypted_read_write_admin(admin_pin); - }); - } - - NK_C_API int NK_set_encrypted_read_only(const char* admin_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->set_encrypted_volume_read_only(admin_pin); - }); - } - - NK_C_API int NK_set_encrypted_read_write(const char* admin_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->set_encrypted_volume_read_write(admin_pin); - }); - } - - NK_C_API int NK_export_firmware(const char* admin_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->export_firmware(admin_pin); - }); - } - - NK_C_API int NK_clear_new_sd_card_warning(const char* admin_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->clear_new_sd_card_warning(admin_pin); - }); - } - - NK_C_API int NK_fill_SD_card_with_random_data(const char* admin_pin) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->fill_SD_card_with_random_data(admin_pin); - }); - } - - NK_C_API int NK_change_update_password(const char* current_update_password, - const char* new_update_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->change_update_password(current_update_password, new_update_password); - }); - } - - NK_C_API int NK_enable_firmware_update(const char* update_password){ - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->enable_firmware_update(update_password); - }); - } - - NK_C_API char* NK_get_status_storage_as_string() { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - return m->get_status_storage_as_string(); - }); - } - - NK_C_API int NK_get_status_storage(NK_storage_status* out) { - if (out == nullptr) { - return -1; - } - auto m = NitrokeyManager::instance(); - auto result = get_with_status([&]() { - return m->get_status_storage(); - }, proto::stick20::DeviceConfigurationResponsePacket::ResponsePayload()); - auto error_code = std::get<0>(result); - if (error_code != 0) { - return error_code; - } - - auto status = std::get<1>(result); - out->unencrypted_volume_read_only = status.ReadWriteFlagUncryptedVolume_u8 != 0; - out->unencrypted_volume_active = status.VolumeActiceFlag_st.unencrypted; - out->encrypted_volume_read_only = status.ReadWriteFlagCryptedVolume_u8 != 0; - out->encrypted_volume_active = status.VolumeActiceFlag_st.encrypted; - out->hidden_volume_read_only = status.ReadWriteFlagHiddenVolume_u8 != 0; - out->hidden_volume_active = status.VolumeActiceFlag_st.hidden; - out->firmware_version_major = status.versionInfo.major; - out->firmware_version_minor = status.versionInfo.minor; - out->firmware_locked = status.FirmwareLocked_u8 != 0; - out->serial_number_sd_card = status.ActiveSD_CardID_u32; - out->serial_number_smart_card = status.ActiveSmartCardID_u32; - out->user_retry_count = status.UserPwRetryCount; - out->admin_retry_count = status.AdminPwRetryCount; - out->new_sd_card_found = status.NewSDCardFound_st.NewCard; - out->filled_with_random = (status.SDFillWithRandomChars_u8 & 0x01) != 0; - out->stick_initialized = status.StickKeysNotInitiated == 0; - return 0; - } - - NK_C_API int NK_get_storage_production_info(NK_storage_ProductionTest * out){ - if (out == nullptr) { - return -1; - } - auto m = NitrokeyManager::instance(); - auto result = get_with_status([&]() { - return m->production_info(); - }, proto::stick20::ProductionTest::ResponsePayload()); - - auto error_code = std::get<0>(result); - if (error_code != 0) { - return error_code; - } - - stick20::ProductionTest::ResponsePayload status = std::get<1>(result); - // Cannot use memcpy without declaring C API struct packed - // (which is not parsed by Python's CFFI apparently), hence the manual way. -#define a(x) out->x = status.x; - a(FirmwareVersion_au8[0]); - a(FirmwareVersion_au8[1]); - a(FirmwareVersionInternal_u8); - a(SD_Card_Size_u8); - a(CPU_CardID_u32); - a(SmartCardID_u32); - a(SD_CardID_u32); - a(SC_UserPwRetryCount); - a(SC_AdminPwRetryCount); - a(SD_Card_ManufacturingYear_u8); - a(SD_Card_ManufacturingMonth_u8); - a(SD_Card_OEM_u16); - a(SD_WriteSpeed_u16); - a(SD_Card_Manufacturer_u8); -#undef a - return 0; - } - - NK_C_API int NK_get_SD_usage_data(struct NK_SD_usage_data* out) { - if (out == nullptr) - return -1; - auto m = NitrokeyManager::instance(); - auto result = get_with_status([&]() { - return m->get_SD_usage_data(); - }, std::make_pair(0, 0)); - auto error_code = std::get<0>(result); - if (error_code != 0) - return error_code; - - auto data = std::get<1>(result); - out->write_level_min = std::get<0>(data); - out->write_level_max = std::get<1>(data); - - return 0; - } - -NK_C_API char* NK_get_SD_usage_data_as_string() { - auto m = NitrokeyManager::instance(); - return get_with_string_result([&]() { - return m->get_SD_usage_data_as_string(); - }); - } - - NK_C_API int NK_get_progress_bar_value() { - auto m = NitrokeyManager::instance(); - return std::get<1>(get_with_status([&]() { - return m->get_progress_bar_value(); - }, -2)); - } - - NK_C_API uint8_t NK_get_major_firmware_version() { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return m->get_major_firmware_version(); - }); - } - - NK_C_API uint8_t NK_get_minor_firmware_version() { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return m->get_minor_firmware_version(); - }); - } - - NK_C_API int NK_set_unencrypted_volume_rorw_pin_type_user() { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return m->set_unencrypted_volume_rorw_pin_type_user() ? 1 : 0; - }); - } - - NK_C_API char* NK_list_devices_by_cpuID() { - auto nm = NitrokeyManager::instance(); - return get_with_string_result([&]() { - auto v = nm->list_devices_by_cpuID(); - std::string res; - for (const auto a : v){ - res += a+";"; - } - if (res.size()>0) res.pop_back(); // remove last delimiter char - return strndup(res.c_str(), MAXIMUM_STR_REPLY_LENGTH); - }); - } - - bool copy_device_info(const DeviceInfo& source, NK_device_info* target) { - switch (source.m_deviceModel) { - case DeviceModel::PRO: - target->model = NK_PRO; - break; - case DeviceModel::STORAGE: - target->model = NK_STORAGE; - break; - default: - return false; - } - - target->path = strndup(source.m_path.c_str(), MAXIMUM_STR_REPLY_LENGTH); - target->serial_number = strndup(source.m_serialNumber.c_str(), MAXIMUM_STR_REPLY_LENGTH); - target->next = nullptr; - - return target->path && target->serial_number; - } - - NK_C_API struct NK_device_info* NK_list_devices() { - auto nm = NitrokeyManager::instance(); - return get_with_result([&]() -> NK_device_info* { - auto v = nm->list_devices(); - if (v.empty()) - return nullptr; - - auto result = new NK_device_info(); - auto ptr = result; - auto first = v.begin(); - if (!copy_device_info(*first, ptr)) { - NK_free_device_info(result); - return nullptr; - } - v.erase(first); - - for (auto& info : v) { - ptr->next = new NK_device_info(); - ptr = ptr->next; - - if (!copy_device_info(info, ptr)) { - NK_free_device_info(result); - return nullptr; - } - } - return result; - }); - } - - NK_C_API void NK_free_device_info(struct NK_device_info* device_info) { - if (!device_info) - return; - - if (device_info->next) - NK_free_device_info(device_info->next); - - free(device_info->path); - free(device_info->serial_number); - delete device_info; - } - - NK_C_API int NK_connect_with_ID(const char* id) { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return m->connect_with_ID(id) ? 1 : 0; - }); - } - - NK_C_API int NK_connect_with_path(const char* path) { - auto m = NitrokeyManager::instance(); - return get_with_result([&]() { - return m->connect_with_path(path) ? 1 : 0; - }); - } - - - NK_C_API int NK_wink() { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - return m->wink(); - }); - } - - NK_C_API int NK_enable_firmware_update_pro(const char* update_password){ - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->enable_firmware_update_pro(update_password); - }); -} - - NK_C_API int NK_change_firmware_password_pro(const char *current_firmware_password, const char *new_firmware_password) { - auto m = NitrokeyManager::instance(); - return get_without_result([&]() { - m->change_firmware_update_password_pro(current_firmware_password, - new_firmware_password); - }); - } - - - NK_C_API int NK_read_HOTP_slot(const uint8_t slot_num, struct ReadSlot_t* out){ - if (out == nullptr) - return -1; - auto m = NitrokeyManager::instance(); - auto result = get_with_status([&]() { - return m->get_HOTP_slot_data(slot_num); - }, stick10::ReadSlot::ResponsePayload() ); - auto error_code = std::get<0>(result); - if (error_code != 0) { - return error_code; - } -#define a(x) out->x = read_slot.x - stick10::ReadSlot::ResponsePayload read_slot = std::get<1>(result); - a(_slot_config); - a(slot_counter); -#undef a -#define m(x) memmove(out->x, read_slot.x, sizeof(read_slot.x)) - m(slot_name); - m(slot_token_id); -#undef m - return 0; -} - - -#ifdef __cplusplus -} -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/NK_C_API.h b/nitrokey-sys/libnitrokey-v3.5/NK_C_API.h deleted file mode 100644 index d5c54a3..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/NK_C_API.h +++ /dev/null @@ -1,1014 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef LIBNITROKEY_NK_C_API_H -#define LIBNITROKEY_NK_C_API_H - -#include -#include - -#include "deprecated.h" - -#ifdef _MSC_VER -#define NK_C_API __declspec(dllexport) -#else -#define NK_C_API -#endif - -/** - * \file - * - * C API for libnitrokey - * - * \mainpage - * - * **libnitrokey** provides access to Nitrokey Pro and Nitrokey Storage devices. - * This documentation describes libnitrokey’s C API. For a list of the - * available functions, see the NK_C_API.h file. - * - * \section getting_started Example - * - * \code{.c} - * #include - * #include - * #include - * - * int main(void) - * { - * if (NK_login_auto() != 1) { - * fprintf(stderr, "No Nitrokey found.\n"); - * return 1; - * } - * - * NK_device_model model = NK_get_device_model(); - * printf("Connected to "); - * switch (model) { - * case NK_PRO: - * printf("a Nitrokey Pro"); - * break; - * case NK_STORAGE: - * printf("a Nitrokey Storage"); - * break; - * default: - * printf("an unsupported Nitrokey"); - * break; - * } - * - * char* serial_number = NK_device_serial_number(); - * if (serial_number) - * printf(" with serial number %s\n", serial_number); - * else - * printf(" -- could not query serial number!\n"); - * free(serial_number); - * - * NK_logout(); - * return 0; - * } - * \endcode - */ - -#ifdef __cplusplus -extern "C" { -#endif - - /** - * The number of slots in the password safe. - */ - extern const uint8_t NK_PWS_SLOT_COUNT; - - static const int MAXIMUM_STR_REPLY_LENGTH = 8192; - - /** - * The Nitrokey device models supported by the API. - */ - enum NK_device_model { - /** - * Use, if no supported device is connected - */ - NK_DISCONNECTED = 0, - /** - * Nitrokey Pro. - */ - NK_PRO = 1, - /** - * Nitrokey Storage. - */ - NK_STORAGE = 2 - }; - - /** - * The connection info for a Nitrokey device as a linked list. - */ - struct NK_device_info { - /** - * The model of the Nitrokey device. - */ - enum NK_device_model model; - /** - * The USB device path for NK_connect_with_path. - */ - char* path; - /** - * The serial number. - */ - char* serial_number; - /** - * The pointer to the next element of the linked list or null - * if this is the last element in the list. - */ - struct NK_device_info* next; - }; - - /** - * Stores the common device status for all Nitrokey devices. - */ - struct NK_status { - /** - * The major firmware version, e. g. 0 in v0.40. - */ - uint8_t firmware_version_major; - /** - * The minor firmware version, e. g. 40 in v0.40. - */ - uint8_t firmware_version_minor; - /** - * The serial number of the smart card. - */ - uint32_t serial_number_smart_card; - /** - * The HOTP slot to generate a password from if the numlock - * key is pressed twice (slot 0-1, or any other value to - * disable the function). - */ - uint8_t config_numlock; - /** - * The HOTP slot to generate a password from if the capslock - * key is pressed twice (slot 0-1, or any other value to - * disable the function). - */ - uint8_t config_capslock; - /** - * The HOTP slot to generate a password from if the scrolllock - * key is pressed twice (slot 0-1, or any other value to - * disable the function). - */ - uint8_t config_scrolllock; - /** - * Indicates whether the user password is required to generate - * an OTP value. - */ - bool otp_user_password; - }; - - /** - * Stores the status of a Storage device. - */ - struct NK_storage_status { - /** - * Indicates whether the unencrypted volume is read-only. - */ - bool unencrypted_volume_read_only; - /** - * Indicates whether the unencrypted volume is active. - */ - bool unencrypted_volume_active; - /** - * Indicates whether the encrypted volume is read-only. - */ - bool encrypted_volume_read_only; - /** - * Indicates whether the encrypted volume is active. - */ - bool encrypted_volume_active; - /** - * Indicates whether the hidden volume is read-only. - */ - bool hidden_volume_read_only; - /** - * Indicates whether the hidden volume is active. - */ - bool hidden_volume_active; - /** - * The major firmware version, e. g. 0 in v0.40. - */ - uint8_t firmware_version_major; - /** - * The minor firmware version, e. g. 40 in v0.40. - */ - uint8_t firmware_version_minor; - /** - * Indicates whether the firmware is locked. - */ - bool firmware_locked; - /** - * The serial number of the SD card in the Storage stick. - */ - uint32_t serial_number_sd_card; - /** - * The serial number of the smart card in the Storage stick. - */ - uint32_t serial_number_smart_card; - /** - * The number of remaining login attempts for the user PIN. - */ - uint8_t user_retry_count; - /** - * The number of remaining login attempts for the admin PIN. - */ - uint8_t admin_retry_count; - /** - * Indicates whether a new SD card was found. - */ - bool new_sd_card_found; - /** - * Indicates whether the SD card is filled with random characters. - */ - bool filled_with_random; - /** - * Indicates whether the stick has been initialized by generating - * the AES keys. - */ - bool stick_initialized; - }; - - /** - * Data about the usage of the SD card. - */ - struct NK_SD_usage_data { - /** - * The minimum write level, as a percentage of the total card - * size. - */ - uint8_t write_level_min; - /** - * The maximum write level, as a percentage of the total card - * size. - */ - uint8_t write_level_max; - }; - - - struct NK_storage_ProductionTest{ - uint8_t FirmwareVersion_au8[2]; - uint8_t FirmwareVersionInternal_u8; - uint8_t SD_Card_Size_u8; - uint32_t CPU_CardID_u32; - uint32_t SmartCardID_u32; - uint32_t SD_CardID_u32; - uint8_t SC_UserPwRetryCount; - uint8_t SC_AdminPwRetryCount; - uint8_t SD_Card_ManufacturingYear_u8; - uint8_t SD_Card_ManufacturingMonth_u8; - uint16_t SD_Card_OEM_u16; - uint16_t SD_WriteSpeed_u16; - uint8_t SD_Card_Manufacturer_u8; - }; - - NK_C_API int NK_get_storage_production_info(struct NK_storage_ProductionTest * out); - - -/** - * Set debug level of messages written on stderr - * @param state state=True - most messages, state=False - only errors level - */ - NK_C_API void NK_set_debug(bool state); - - /** - * Set debug level of messages written on stderr - * @param level (int) 0-lowest verbosity, 5-highest verbosity - */ - NK_C_API void NK_set_debug_level(const int level); - - /** - * Get the major library version, e. g. the 3 in v3.2. - * @return the major library version - */ - NK_C_API unsigned int NK_get_major_library_version(); - - /** - * Get the minor library version, e. g. the 2 in v3.2. - * @return the minor library version - */ - NK_C_API unsigned int NK_get_minor_library_version(); - - /** - * Get the library version as a string. This is the output of - * `git describe --always` at compile time, for example "v3.3" or - * "v3.3-19-gaee920b". - * The return value is a string literal and must not be freed. - * @return the library version as a string - */ - NK_C_API const char* NK_get_library_version(); - - /** - * Connect to device of given model. Currently library can be connected only to one device at once. - * @param device_model char 'S': Nitrokey Storage, 'P': Nitrokey Pro - * @return 1 if connected, 0 if wrong model or cannot connect - */ - NK_C_API int NK_login(const char *device_model); - - /** - * Connect to device of given model. Currently library can be connected only to one device at once. - * @param device_model NK_device_model: NK_PRO: Nitrokey Pro, NK_STORAGE: Nitrokey Storage - * @return 1 if connected, 0 if wrong model or cannot connect - */ - NK_C_API int NK_login_enum(enum NK_device_model device_model); - - /** - * Connect to first available device, starting checking from Pro 1st to Storage 2nd. - * @return 1 if connected, 0 if wrong model or cannot connect - */ - NK_C_API int NK_login_auto(); - - /** - * Disconnect from the device. - * @return command processing error code - */ - NK_C_API int NK_logout(); - - /** - * Query the model of the connected device. - * Returns the model of the connected device or NK_DISCONNECTED. - * - * @return true if a device is connected and the out argument has been set - */ - NK_C_API enum NK_device_model NK_get_device_model(); - - /** - * Return the debug status string. Debug purposes. This function is - * deprecated in favor of NK_get_status_as_string. - * @return string representation of the status or an empty string - * if the command failed - */ - DEPRECATED - NK_C_API char * NK_status(); - - /** - * Return the debug status string. Debug purposes. - * @return string representation of the status or an empty string - * if the command failed - */ - NK_C_API char * NK_get_status_as_string(); - - /** - * Get the stick status common to all Nitrokey devices and return the - * command processing error code. If the code is zero, i. e. the - * command was successful, the storage status is written to the output - * pointer's target. The output pointer must not be null. - * - * @param out the output pointer for the status - * @return command processing error code - */ - NK_C_API int NK_get_status(struct NK_status* out); - - /** - * Return the device's serial number string in hex. - * @return string device's serial number in hex - */ - NK_C_API char * NK_device_serial_number(); - - /** - * Get last command processing status. Useful for commands which returns the results of their own and could not return - * an error code. - * @return previous command processing error code - */ - NK_C_API uint8_t NK_get_last_command_status(); - - /** - * Lock device - cancel any user device unlocking. - * @return command processing error code - */ - NK_C_API int NK_lock_device(); - - /** - * Authenticates the user on USER privilages with user_password and sets user's temporary password on device to user_temporary_password. - * @param user_password char[25] current user password - * @param user_temporary_password char[25] user temporary password to be set on device for further communication (authentication command) - * @return command processing error code - */ - NK_C_API int NK_user_authenticate(const char* user_password, const char* user_temporary_password); - - /** - * Authenticates the user on ADMIN privilages with admin_password and sets user's temporary password on device to admin_temporary_password. - * @param admin_password char[25] current administrator PIN - * @param admin_temporary_password char[25] admin temporary password to be set on device for further communication (authentication command) - * @return command processing error code - */ - NK_C_API int NK_first_authenticate(const char* admin_password, const char* admin_temporary_password); - - /** - * Execute a factory reset. - * @param admin_password char[20] current administrator PIN - * @return command processing error code - */ - NK_C_API int NK_factory_reset(const char* admin_password); - - /** - * Generates AES key on the device - * @param admin_password char[20] current administrator PIN - * @return command processing error code - */ - NK_C_API int NK_build_aes_key(const char* admin_password); - - /** - * Unlock user PIN locked after 3 incorrect codes tries. - * @param admin_password char[20] current administrator PIN - * @return command processing error code - */ - NK_C_API int NK_unlock_user_password(const char *admin_password, const char *new_user_password); - - /** - * Write general config to the device - * @param numlock set value in range [0-1] to send HOTP code from slot 'numlock' after double pressing numlock - * or outside the range to disable this function - * @param capslock similar to numlock but with capslock - * @param scrolllock similar to numlock but with scrolllock - * @param enable_user_password set True to enable OTP PIN protection (require PIN each OTP code request) - * @param delete_user_password (unused) - * @param admin_temporary_password current admin temporary password - * @return command processing error code - */ - NK_C_API int NK_write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, - bool enable_user_password, bool delete_user_password, const char *admin_temporary_password); - - /** - * Get currently set config - status of function Numlock/Capslock/Scrollock OTP sending and is enabled PIN protected OTP - * @see NK_write_config - * @return uint8_t general_config[5]: - * uint8_t numlock; - uint8_t capslock; - uint8_t scrolllock; - uint8_t enable_user_password; - uint8_t delete_user_password; - - */ - NK_C_API uint8_t* NK_read_config(); - - //OTP - - /** - * Get name of given TOTP slot - * @param slot_number TOTP slot number, slot_number<15 - * @return char[20] the name of the slot - */ - NK_C_API char * NK_get_totp_slot_name(uint8_t slot_number); - - /** - * - * @param slot_number HOTP slot number, slot_number<3 - * @return char[20] the name of the slot - */ - NK_C_API char * NK_get_hotp_slot_name(uint8_t slot_number); - - /** - * Erase HOTP slot data from the device - * @param slot_number HOTP slot number, slot_number<3 - * @param temporary_password admin temporary password - * @return command processing error code - */ - NK_C_API int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_password); - - /** - * Erase TOTP slot data from the device - * @param slot_number TOTP slot number, slot_number<15 - * @param temporary_password admin temporary password - * @return command processing error code - */ - NK_C_API int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_password); - - /** - * Write HOTP slot data to the device - * @param slot_number HOTP slot number, slot_number<3, 0-numbered - * @param slot_name char[15] desired slot name. C string (requires ending '\0'; 16 bytes). - * @param secret char[40] 160-bit or 320-bit (currently Pro v0.8 only) secret as a hex string. C string (requires ending '\0'; 41 bytes). - * See NitrokeyManager::is_320_OTP_secret_supported. - * @param hotp_counter uint32_t starting value of HOTP counter - * @param use_8_digits should returned codes be 6 (false) or 8 digits (true) - * @param use_enter press ENTER key after sending OTP code using double-pressed scroll/num/capslock - * @param use_tokenID @see token_ID - * @param token_ID @see https://openauthentication.org/token-specs/, 'Class A' section - * @param temporary_password char[25] admin temporary password - * @return command processing error code - */ - NK_C_API int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password); - - /** - * Write TOTP slot data to the device - * @param slot_number TOTP slot number, slot_number<15, 0-numbered - * @param slot_name char[15] desired slot name. C string (requires ending '\0'; 16 bytes). - * @param secret char[40] 160-bit or 320-bit (currently Pro v0.8 only) secret as a hex string. C string (requires ending '\0'; 41 bytes). - * See NitrokeyManager::is_320_OTP_secret_supported. - * @param time_window uint16_t time window for this TOTP - * @param use_8_digits should returned codes be 6 (false) or 8 digits (true) - * @param use_enter press ENTER key after sending OTP code using double-pressed scroll/num/capslock - * @param use_tokenID @see token_ID - * @param token_ID @see https://openauthentication.org/token-specs/, 'Class A' section - * @param temporary_password char[20] admin temporary password - * @return command processing error code - */ - NK_C_API int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password); - - /** - * Get HOTP code from the device - * @param slot_number HOTP slot number, slot_number<3 - * @return HOTP code - */ - NK_C_API char * NK_get_hotp_code(uint8_t slot_number); - - /** - * Get HOTP code from the device (PIN protected) - * @param slot_number HOTP slot number, slot_number<3 - * @param user_temporary_password char[25] user temporary password if PIN protected OTP codes are enabled, - * otherwise should be set to empty string - '' - * @return HOTP code - */ - NK_C_API char * NK_get_hotp_code_PIN(uint8_t slot_number, const char *user_temporary_password); - - /** - * Get TOTP code from the device - * @param slot_number TOTP slot number, slot_number<15 - * @param challenge TOTP challenge -- unused - * @param last_totp_time last time -- unused - * @param last_interval last interval --unused - * @return TOTP code - */ - NK_C_API char * NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, - uint8_t last_interval); - - /** - * Get TOTP code from the device (PIN protected) - * @param slot_number TOTP slot number, slot_number<15 - * @param challenge TOTP challenge -- unused - * @param last_totp_time last time -- unused - * @param last_interval last interval -- unused - * @param user_temporary_password char[25] user temporary password if PIN protected OTP codes are enabled, - * otherwise should be set to empty string - '' - * @return TOTP code - */ - NK_C_API char * NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, - uint64_t last_totp_time, uint8_t last_interval, - const char *user_temporary_password); - - /** - * Set time on the device (for TOTP requests) - * @param time seconds in unix epoch (from 01.01.1970) - * @return command processing error code - */ - NK_C_API int NK_totp_set_time(uint64_t time); - - /** - * Set the device time used for TOTP to the given time. Contrary to - * {@code set_time(uint64_t)}, this command fails if {@code old_time} - * > {@code time} or if {@code old_time} is zero (where {@code - * old_time} is the current time on the device). - * - * @param time new device time as Unix timestamp (seconds since - * 1970-01-01) - * @return command processing error code - */ - NK_C_API int NK_totp_set_time_soft(uint64_t time); - - // NK_totp_get_time is deprecated -- use NK_totp_set_time_soft instead - DEPRECATED - NK_C_API int NK_totp_get_time(); - - //passwords - /** - * Change administrator PIN - * @param current_PIN char[25] current PIN - * @param new_PIN char[25] new PIN - * @return command processing error code - */ - NK_C_API int NK_change_admin_PIN(const char *current_PIN, const char *new_PIN); - - /** - * Change user PIN - * @param current_PIN char[25] current PIN - * @param new_PIN char[25] new PIN - * @return command processing error code - */ - NK_C_API int NK_change_user_PIN(const char *current_PIN, const char *new_PIN); - - - /** - * Get retry count of user PIN - * @return user PIN retry count - */ - NK_C_API uint8_t NK_get_user_retry_count(); - - /** - * Get retry count of admin PIN - * @return admin PIN retry count - */ - NK_C_API uint8_t NK_get_admin_retry_count(); - //password safe - - /** - * Enable password safe access - * @param user_pin char[30] current user PIN - * @return command processing error code - */ - NK_C_API int NK_enable_password_safe(const char *user_pin); - - /** - * Get password safe slots' status - * @return uint8_t[16] slot statuses - each byte represents one slot with 0 (not programmed) and 1 (programmed) - */ - NK_C_API uint8_t * NK_get_password_safe_slot_status(); - - /** - * Get password safe slot name - * @param slot_number password safe slot number, slot_number<16 - * @return slot name - */ - NK_C_API char *NK_get_password_safe_slot_name(uint8_t slot_number); - - /** - * Get password safe slot login - * @param slot_number password safe slot number, slot_number<16 - * @return login from the PWS slot - */ - NK_C_API char *NK_get_password_safe_slot_login(uint8_t slot_number); - - /** - * Get the password safe slot password - * @param slot_number password safe slot number, slot_number<16 - * @return password from the PWS slot - */ - NK_C_API char *NK_get_password_safe_slot_password(uint8_t slot_number); - - /** - * Write password safe data to the slot - * @param slot_number password safe slot number, slot_number<16 - * @param slot_name char[11] name of the slot - * @param slot_login char[32] login string - * @param slot_password char[20] password string - * @return command processing error code - */ - NK_C_API int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, - const char *slot_login, const char *slot_password); - - /** - * Erase the password safe slot from the device - * @param slot_number password safe slot number, slot_number<16 - * @return command processing error code - */ - NK_C_API int NK_erase_password_safe_slot(uint8_t slot_number); - - /** - * Check whether AES is supported by the device - * @return 0 for no and 1 for yes - */ - NK_C_API int NK_is_AES_supported(const char *user_password); - - /** - * Get device's major firmware version - * @return major part of the version number (e.g. 0 from 0.48, 0 from 0.7 etc.) - */ - NK_C_API uint8_t NK_get_major_firmware_version(); - - /** - * Get device's minor firmware version - * @return minor part of the version number (e.g. 7 from 0.7, 48 from 0.48 etc.) - */ - NK_C_API uint8_t NK_get_minor_firmware_version(); - - /** - * Function to determine unencrypted volume PIN type - * @param minor_firmware_version - * @return Returns 1, if set unencrypted volume ro/rw pin type is User, 0 otherwise. - */ - NK_C_API int NK_set_unencrypted_volume_rorw_pin_type_user(); - - - /** - * This command is typically run to initiate - * communication with the device (altough not required). - * It sets time on device and returns its current status - * - a combination of set_time and get_status_storage commands - * Storage only - * @param seconds_from_epoch date and time expressed in seconds - */ - NK_C_API int NK_send_startup(uint64_t seconds_from_epoch); - - /** - * Unlock encrypted volume. - * Storage only - * @param user_pin user pin 20 characters - * @return command processing error code - */ - NK_C_API int NK_unlock_encrypted_volume(const char* user_pin); - - /** - * Locks encrypted volume - * @return command processing error code - */ - NK_C_API int NK_lock_encrypted_volume(); - - /** - * Unlock hidden volume and lock encrypted volume. - * Requires encrypted volume to be unlocked. - * Storage only - * @param hidden_volume_password 20 characters - * @return command processing error code - */ - NK_C_API int NK_unlock_hidden_volume(const char* hidden_volume_password); - - /** - * Locks hidden volume - * @return command processing error code - */ - NK_C_API int NK_lock_hidden_volume(); - - /** - * Create hidden volume. - * Requires encrypted volume to be unlocked. - * Storage only - * @param slot_nr slot number in range 0-3 - * @param start_percent volume begin expressed in percent of total available storage, int in range 0-99 - * @param end_percent volume end expressed in percent of total available storage, int in range 1-100 - * @param hidden_volume_password 20 characters - * @return command processing error code - */ - NK_C_API int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, - const char *hidden_volume_password); - - /** - * Make unencrypted volume read-only. - * Device hides unencrypted volume for a second therefore make sure - * buffers are flushed before running. - * Does nothing if firmware version is not matched - * Firmware range: Storage v0.50, v0.48 and below - * Storage only - * @param user_pin 20 characters User PIN - * @return command processing error code - */ - NK_C_API int NK_set_unencrypted_read_only(const char *user_pin); - - /** - * Make unencrypted volume read-write. - * Device hides unencrypted volume for a second therefore make sure - * buffers are flushed before running. - * Does nothing if firmware version is not matched - * Firmware range: Storage v0.50, v0.48 and below - * Storage only - * @param user_pin 20 characters User PIN - * @return command processing error code - */ - NK_C_API int NK_set_unencrypted_read_write(const char *user_pin); - - /** - * Make unencrypted volume read-only. - * Device hides unencrypted volume for a second therefore make sure - * buffers are flushed before running. - * Does nothing if firmware version is not matched - * Firmware range: Storage v0.49, v0.51+ - * Storage only - * @param admin_pin 20 characters Admin PIN - * @return command processing error code - */ - NK_C_API int NK_set_unencrypted_read_only_admin(const char* admin_pin); - - /** - * Make unencrypted volume read-write. - * Device hides unencrypted volume for a second therefore make sure - * buffers are flushed before running. - * Does nothing if firmware version is not matched - * Firmware range: Storage v0.49, v0.51+ - * Storage only - * @param admin_pin 20 characters Admin PIN - * @return command processing error code - */ - NK_C_API int NK_set_unencrypted_read_write_admin(const char* admin_pin); - - /** - * Make encrypted volume read-only. - * Device hides encrypted volume for a second therefore make sure - * buffers are flushed before running. - * Firmware range: v0.49 only, future (see firmware release notes) - * Storage only - * @param admin_pin 20 characters - * @return command processing error code - */ - NK_C_API int NK_set_encrypted_read_only(const char* admin_pin); - - /** - * Make encrypted volume read-write. - * Device hides encrypted volume for a second therefore make sure - * buffers are flushed before running. - * Firmware range: v0.49 only, future (see firmware release notes) - * Storage only - * @param admin_pin 20 characters - * @return command processing error code - */ - NK_C_API int NK_set_encrypted_read_write(const char* admin_pin); - - /** - * Exports device's firmware to unencrypted volume. - * Storage only - * @param admin_pin 20 characters - * @return command processing error code - */ - NK_C_API int NK_export_firmware(const char* admin_pin); - - /** - * Clear new SD card notification. It is set after factory reset. - * Storage only - * @param admin_pin 20 characters - * @return command processing error code - */ - NK_C_API int NK_clear_new_sd_card_warning(const char* admin_pin); - - /** - * Fill SD card with random data. - * Should be done on first stick initialization after creating keys. - * Storage only - * @param admin_pin 20 characters - * @return command processing error code - */ - NK_C_API int NK_fill_SD_card_with_random_data(const char* admin_pin); - - /** - * Change update password. - * Update password is used for entering update mode, where firmware - * could be uploaded using dfu-programmer or other means. - * Storage only - * @param current_update_password 20 characters - * @param new_update_password 20 characters - * @return command processing error code - */ - NK_C_API int NK_change_update_password(const char* current_update_password, - const char* new_update_password); - - /** - * Enter update mode. Needs update password. - * When device is in update mode it no longer accepts any HID commands until - * firmware is launched (regardless of being updated or not). - * Smartcard (through CCID interface) and its all volumes are not visible as well. - * Its VID and PID are changed to factory-default (03eb:2ff1 Atmel Corp.) - * to be detected by flashing software. Result of this command can be reversed - * by using 'launch' command. - * For dfu-programmer it would be: 'dfu-programmer at32uc3a3256s launch'. - * Storage only - * @param update_password 20 characters - * @return command processing error code - */ - NK_C_API int NK_enable_firmware_update(const char* update_password); - - /** - * Get Storage stick status as string. - * Storage only - * @return string with devices attributes - */ - NK_C_API char* NK_get_status_storage_as_string(); - - /** - * Get the Storage stick status and return the command processing - * error code. If the code is zero, i. e. the command was successful, - * the storage status is written to the output pointer's target. - * The output pointer must not be null. - * - * @param out the output pointer for the storage status - * @return command processing error code - */ - NK_C_API int NK_get_status_storage(struct NK_storage_status* out); - - /** - * Get SD card usage attributes. Usable during hidden volumes creation. - * If the command was successful (return value 0), the usage data is - * written to the output pointer’s target. The output pointer must - * not be null. - * Storage only - * @param out the output pointer for the usage data - * @return command processing error code - */ - NK_C_API int NK_get_SD_usage_data(struct NK_SD_usage_data* out); - - /** - * Get SD card usage attributes as string. - * Usable during hidden volumes creation. - * Storage only - * @return string with SD card usage attributes - */ - NK_C_API char* NK_get_SD_usage_data_as_string(); - - /** - * Get progress value of current long operation. - * Storage only - * @return int in range 0-100 or -1 if device is not busy or -2 if an - * error occured - */ - NK_C_API int NK_get_progress_bar_value(); - -/** - * Returns a list of connected devices' id's, delimited by ';' character. Empty string is returned on no device found. - * Each ID could consist of: - * 1. SC_id:SD_id_p_path (about 40 bytes) - * 2. path (about 10 bytes) - * where 'path' is USB path (bus:num), 'SC_id' is smartcard ID, 'SD_id' is storage card ID and - * '_p_' and ':' are field delimiters. - * Case 2 (USB path only) is used, when the device cannot be asked about its status data (e.g. during a long operation, - * like clearing SD card. - * Internally connects to all available devices and creates a map between ids and connection objects. - * Side effects: changes active device to last detected Storage device. - * Storage only - * @example Example of returned data: '00005d19:dacc2cb4_p_0001:0010:02;000037c7:4cf12445_p_0001:000f:02;0001:000c:02' - * @return string delimited id's of connected devices - */ - NK_C_API char* NK_list_devices_by_cpuID(); - - /** - * Returns a linked list of all connected devices, or null if no devices - * are connected or an error occured. The linked list must be freed by - * calling NK_free_device_info. - * @return a linked list of all connected devices - */ - NK_C_API struct NK_device_info* NK_list_devices(); - - /** - * Free a linked list returned by NK_list_devices. - * @param the linked list to free or null - */ - NK_C_API void NK_free_device_info(struct NK_device_info* device_info); - -/** - * Connects to the device with given ID. ID's list could be created with NK_list_devices_by_cpuID. - * Requires calling to NK_list_devices_by_cpuID first. Connecting to arbitrary ID/USB path is not handled. - * On connection requests status from device and disconnects it / removes from map on connection failure. - * Storage only - * @param id Target device ID (example: '00005d19:dacc2cb4_p_0001:0010:02') - * @return 1 on successful connection, 0 otherwise - */ - NK_C_API int NK_connect_with_ID(const char* id); - - /** - * Connects to a device with the given path. The path is a USB device - * path as returned by hidapi. - * @param path the device path - * @return 1 on successful connection, 0 otherwise - */ - NK_C_API int NK_connect_with_path(const char* path); - - /** - * Blink red and green LED alternatively and infinitely (until device is reconnected). - * @return command processing error code - */ - NK_C_API int NK_wink(); - - - /** - * Enable update mode on Nitrokey Pro. - * Supported from v0.11. - * @param update_password 20 bytes update password - * @return command processing error code - */ - NK_C_API int NK_enable_firmware_update_pro(const char* update_password); - - /** - * Change update-mode password on Nitrokey Pro. - * Supported from v0.11. - * @param current_firmware_password 20 bytes update password - * @param new_firmware_password 20 bytes update password - * @return command processing error code - */ - NK_C_API int NK_change_firmware_password_pro(const char *current_firmware_password, const char *new_firmware_password); - - -// as in ReadSlot::ResponsePayload -struct ReadSlot_t { - uint8_t slot_name[15]; - uint8_t _slot_config; - uint8_t slot_token_id[13]; - uint64_t slot_counter; -}; - - -NK_C_API int NK_read_HOTP_slot(const uint8_t slot_num, struct ReadSlot_t* out); - -#ifdef __cplusplus -} -#endif - -#endif //LIBNITROKEY_NK_C_API_H diff --git a/nitrokey-sys/libnitrokey-v3.5/NitrokeyManager.cc b/nitrokey-sys/libnitrokey-v3.5/NitrokeyManager.cc deleted file mode 100644 index 6c26a43..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/NitrokeyManager.cc +++ /dev/null @@ -1,1199 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include -#include -#include "libnitrokey/NitrokeyManager.h" -#include "libnitrokey/LibraryException.h" -#include -#include -#include -#include "libnitrokey/misc.h" -#include -#include "libnitrokey/cxx_semantics.h" -#include "libnitrokey/misc.h" -#include -#include - -std::mutex nitrokey::proto::send_receive_mtx; - -namespace nitrokey{ - - std::mutex mex_dev_com_manager; - -#ifndef strndup -#ifdef _WIN32 -#pragma message "Using own strndup" -char * strndup(const char* str, size_t maxlen){ - size_t len = strnlen(str, maxlen); - char* dup = (char *) malloc(len + 1); - memcpy(dup, str, len); - dup[len] = 0; - return dup; -} -#endif -#endif - -using nitrokey::misc::strcpyT; - - template - typename T::CommandPayload get_payload(){ - //Create, initialize and return by value command payload - typename T::CommandPayload st; - bzero(&st, sizeof(st)); - return st; - } - - - // package type to auth, auth type [Authorize,UserAuthorize] - template - void NitrokeyManager::authorize_packet(T &package, const char *admin_temporary_password, shared_ptr device){ - if (!is_authorization_command_supported()){ - LOG("Authorization command not supported, skipping", Loglevel::WARNING); - } - auto auth = get_payload(); - strcpyT(auth.temporary_password, admin_temporary_password); - auth.crc_to_authorize = S::CommandTransaction::getCRC(package); - A::CommandTransaction::run(device, auth); - } - - shared_ptr NitrokeyManager::_instance = nullptr; - - NitrokeyManager::NitrokeyManager() : device(nullptr) - { - set_debug(false); - } - NitrokeyManager::~NitrokeyManager() { - std::lock_guard lock(mex_dev_com_manager); - - for (auto d : connected_devices){ - if (d.second == nullptr) continue; - d.second->disconnect(); - connected_devices[d.first] = nullptr; - } - } - - bool NitrokeyManager::set_current_device_speed(int retry_delay, int send_receive_delay){ - if (retry_delay < 20 || send_receive_delay < 20){ - LOG("Delay set too low: " + to_string(retry_delay) +" "+ to_string(send_receive_delay), Loglevel::WARNING); - return false; - } - - std::lock_guard lock(mex_dev_com_manager); - if(device == nullptr) { - return false; - } - device->set_receiving_delay(std::chrono::duration(send_receive_delay)); - device->set_retry_delay(std::chrono::duration(retry_delay)); - return true; - } - - std::vector NitrokeyManager::list_devices(){ - std::lock_guard lock(mex_dev_com_manager); - - return Device::enumerate(); - } - - std::vector NitrokeyManager::list_devices_by_cpuID(){ - using misc::toHex; - //disconnect default device - disconnect(); - - std::lock_guard lock(mex_dev_com_manager); - LOGD1("Disconnecting registered devices"); - for (auto & kv : connected_devices_byID){ - if (kv.second != nullptr) - kv.second->disconnect(); - } - connected_devices_byID.clear(); - - LOGD1("Enumerating devices"); - std::vector res; - const auto v = Device::enumerate(); - LOGD1("Discovering IDs"); - for (auto & i: v){ - if (i.m_deviceModel != DeviceModel::STORAGE) - continue; - auto p = i.m_path; - auto d = make_shared(); - LOGD1( std::string("Found: ") + p ); - d->set_path(p); - try{ - if (d->connect()){ - device = d; - std::string id; - try { - const auto status = get_status_storage(); - const auto sc_id = toHex(status.ActiveSmartCardID_u32); - const auto sd_id = toHex(status.ActiveSD_CardID_u32); - id += sc_id + ":" + sd_id; - id += "_p_" + p; - } - catch (const LongOperationInProgressException &e) { - LOGD1(std::string("Long operation in progress, setting ID to: ") + p); - id = p; - } - - connected_devices_byID[id] = d; - res.push_back(id); - LOGD1( std::string("Found: ") + p + " => " + id); - } else{ - LOGD1( std::string("Could not connect to: ") + p); - } - } - catch (const DeviceCommunicationException &e){ - LOGD1( std::string("Exception encountered: ") + p); - } - } - return res; - } - - bool NitrokeyManager::connect_with_ID(const std::string id) { - std::lock_guard lock(mex_dev_com_manager); - - auto position = connected_devices_byID.find(id); - if (position == connected_devices_byID.end()) { - LOGD1(std::string("Could not find device ")+id + ". Refresh devices list with list_devices_by_cpuID()."); - return false; - } - - auto d = connected_devices_byID[id]; - device = d; - current_device_id = id; - - //validate connection - try{ - get_status(); - } - catch (const LongOperationInProgressException &){ - //ignore - } - catch (const DeviceCommunicationException &){ - d->disconnect(); - current_device_id = ""; - connected_devices_byID[id] = nullptr; - connected_devices_byID.erase(position); - return false; - } - nitrokey::log::Log::setPrefix(id); - LOGD1("Device successfully changed"); - return true; - } - - /** - * Connects device to path. - * Assumes devices are not being disconnected and caches connections (param cache_connections). - * @param path os-dependent device path - * @return false, when could not connect, true otherwise - */ - bool NitrokeyManager::connect_with_path(std::string path) { - const bool cache_connections = false; - - std::lock_guard lock(mex_dev_com_manager); - - if (cache_connections){ - if(connected_devices.find(path) != connected_devices.end() - && connected_devices[path] != nullptr) { - device = connected_devices[path]; - return true; - } - } - - auto info_ptr = hid_enumerate(NITROKEY_VID, 0); - auto first_info_ptr = info_ptr; - if (!info_ptr) - return false; - - misc::Option model; - while (info_ptr && !model.has_value()) { - if (path == std::string(info_ptr->path)) { - model = product_id_to_model(info_ptr->product_id); - } - info_ptr = info_ptr->next; - } - hid_free_enumeration(first_info_ptr); - - if (!model.has_value()) - return false; - - auto p = Device::create(model.value()); - if (!p) - return false; - p->set_path(path); - - if(!p->connect()) return false; - - if(cache_connections){ - connected_devices [path] = p; - } - - device = p; //previous device will be disconnected automatically - current_device_id = path; - nitrokey::log::Log::setPrefix(path); - LOGD1("Device successfully changed"); - return true; - } - - bool NitrokeyManager::connect() { - std::lock_guard lock(mex_dev_com_manager); - vector< shared_ptr > devices = { make_shared(), make_shared() }; - bool connected = false; - for( auto & d : devices ){ - if (d->connect()){ - device = std::shared_ptr(d); - connected = true; - } - } - return connected; - } - - - void NitrokeyManager::set_log_function(std::function log_function){ - static nitrokey::log::FunctionalLogHandler handler(log_function); - nitrokey::log::Log::instance().set_handler(&handler); - } - - bool NitrokeyManager::set_default_commands_delay(int delay){ - if (delay < 20){ - LOG("Delay set too low: " + to_string(delay), Loglevel::WARNING); - return false; - } - Device::set_default_device_speed(delay); - return true; - } - - bool NitrokeyManager::connect(const char *device_model) { - std::lock_guard lock(mex_dev_com_manager); - LOG(__FUNCTION__, nitrokey::log::Loglevel::DEBUG_L2); - switch (device_model[0]){ - case 'P': - device = make_shared(); - break; - case 'S': - device = make_shared(); - break; - default: - throw std::runtime_error("Unknown model"); - } - return device->connect(); - } - - bool NitrokeyManager::connect(device::DeviceModel device_model) { - const char *model_string; - switch (device_model) { - case device::DeviceModel::PRO: - model_string = "P"; - break; - case device::DeviceModel::STORAGE: - model_string = "S"; - break; - default: - throw std::runtime_error("Unknown model"); - } - return connect(model_string); - } - - shared_ptr NitrokeyManager::instance() { - static std::mutex mutex; - std::lock_guard lock(mutex); - if (_instance == nullptr){ - _instance = make_shared(); - } - return _instance; - } - - - - bool NitrokeyManager::disconnect() { - std::lock_guard lock(mex_dev_com_manager); - return _disconnect_no_lock(); - } - - bool NitrokeyManager::_disconnect_no_lock() { - //do not use directly without locked mutex, - //used by could_be_enumerated, disconnect - if (device == nullptr){ - return false; - } - const auto res = device->disconnect(); - device = nullptr; - return res; - } - - bool NitrokeyManager::is_connected() throw(){ - std::lock_guard lock(mex_dev_com_manager); - if(device != nullptr){ - auto connected = device->could_be_enumerated(); - if(connected){ - return true; - } else { - _disconnect_no_lock(); - return false; - } - } - return false; - } - - bool NitrokeyManager::could_current_device_be_enumerated() { - std::lock_guard lock(mex_dev_com_manager); - if (device != nullptr) { - return device->could_be_enumerated(); - } - return false; - } - - void NitrokeyManager::set_loglevel(int loglevel) { - loglevel = max(loglevel, static_cast(Loglevel::ERROR)); - loglevel = min(loglevel, static_cast(Loglevel::DEBUG_L2)); - Log::instance().set_loglevel(static_cast(loglevel)); - } - - void NitrokeyManager::set_loglevel(Loglevel loglevel) { - Log::instance().set_loglevel(loglevel); - } - - void NitrokeyManager::set_debug(bool state) { - if (state){ - Log::instance().set_loglevel(Loglevel::DEBUG); - } else { - Log::instance().set_loglevel(Loglevel::ERROR); - } - } - - - string NitrokeyManager::get_serial_number() { - if (device == nullptr) { return ""; }; - switch (device->get_device_model()) { - case DeviceModel::PRO: { - auto response = GetStatus::CommandTransaction::run(device); - return nitrokey::misc::toHex(response.data().card_serial_u32); - } - break; - - case DeviceModel::STORAGE: - { - auto response = stick20::GetDeviceStatus::CommandTransaction::run(device); - return nitrokey::misc::toHex(response.data().ActiveSmartCardID_u32); - } - break; - } - return "NA"; - } - - stick10::GetStatus::ResponsePayload NitrokeyManager::get_status(){ - try{ - auto response = GetStatus::CommandTransaction::run(device); - return response.data(); - } - catch (DeviceSendingFailure &e){ -// disconnect(); - throw; - } - } - - string NitrokeyManager::get_status_as_string() { - auto response = GetStatus::CommandTransaction::run(device); - return response.data().dissect(); - } - - string getFilledOTPCode(uint32_t code, bool use_8_digits){ - stringstream s; - s << std::right << std::setw(use_8_digits ? 8 : 6) << std::setfill('0') << code; - return s.str(); - } - - string NitrokeyManager::get_HOTP_code(uint8_t slot_number, const char *user_temporary_password) { - if (!is_valid_hotp_slot_number(slot_number)) throw InvalidSlotException(slot_number); - - if (is_authorization_command_supported()){ - auto gh = get_payload(); - gh.slot_number = get_internal_slot_number_for_hotp(slot_number); - if(user_temporary_password != nullptr && strlen(user_temporary_password)!=0){ //FIXME use string instead of strlen - authorize_packet(gh, user_temporary_password, device); - } - auto resp = GetHOTP::CommandTransaction::run(device, gh); - return getFilledOTPCode(resp.data().code, resp.data().use_8_digits); - } else { - auto gh = get_payload(); - gh.slot_number = get_internal_slot_number_for_hotp(slot_number); - if(user_temporary_password != nullptr && strlen(user_temporary_password)!=0) { - strcpyT(gh.temporary_user_password, user_temporary_password); - } - auto resp = stick10_08::GetHOTP::CommandTransaction::run(device, gh); - return getFilledOTPCode(resp.data().code, resp.data().use_8_digits); - } - return ""; - } - - bool NitrokeyManager::is_internal_hotp_slot_number(uint8_t slot_number) const { return slot_number < 0x20; } - bool NitrokeyManager::is_valid_hotp_slot_number(uint8_t slot_number) const { return slot_number < 3; } - bool NitrokeyManager::is_valid_totp_slot_number(uint8_t slot_number) const { return slot_number < 0x10-1; } //15 - uint8_t NitrokeyManager::get_internal_slot_number_for_totp(uint8_t slot_number) const { return (uint8_t) (0x20 + slot_number); } - uint8_t NitrokeyManager::get_internal_slot_number_for_hotp(uint8_t slot_number) const { return (uint8_t) (0x10 + slot_number); } - - - - string NitrokeyManager::get_TOTP_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, - uint8_t last_interval, - const char *user_temporary_password) { - if(!is_valid_totp_slot_number(slot_number)) throw InvalidSlotException(slot_number); - slot_number = get_internal_slot_number_for_totp(slot_number); - - if (is_authorization_command_supported()){ - auto gt = get_payload(); - gt.slot_number = slot_number; - gt.challenge = challenge; - gt.last_interval = last_interval; - gt.last_totp_time = last_totp_time; - - if(user_temporary_password != nullptr && strlen(user_temporary_password)!=0){ //FIXME use string instead of strlen - authorize_packet(gt, user_temporary_password, device); - } - auto resp = GetTOTP::CommandTransaction::run(device, gt); - return getFilledOTPCode(resp.data().code, resp.data().use_8_digits); - } else { - auto gt = get_payload(); - strcpyT(gt.temporary_user_password, user_temporary_password); - gt.slot_number = slot_number; - auto resp = stick10_08::GetTOTP::CommandTransaction::run(device, gt); - return getFilledOTPCode(resp.data().code, resp.data().use_8_digits); - } - return ""; - } - - bool NitrokeyManager::erase_slot(uint8_t slot_number, const char *temporary_password) { - if (is_authorization_command_supported()){ - auto p = get_payload(); - p.slot_number = slot_number; - authorize_packet(p, temporary_password, device); - auto resp = EraseSlot::CommandTransaction::run(device,p); - } else { - auto p = get_payload(); - p.slot_number = slot_number; - strcpyT(p.temporary_admin_password, temporary_password); - auto resp = stick10_08::EraseSlot::CommandTransaction::run(device,p); - } - return true; - } - - bool NitrokeyManager::erase_hotp_slot(uint8_t slot_number, const char *temporary_password) { - if (!is_valid_hotp_slot_number(slot_number)) throw InvalidSlotException(slot_number); - slot_number = get_internal_slot_number_for_hotp(slot_number); - return erase_slot(slot_number, temporary_password); - } - - bool NitrokeyManager::erase_totp_slot(uint8_t slot_number, const char *temporary_password) { - if (!is_valid_totp_slot_number(slot_number)) throw InvalidSlotException(slot_number); - slot_number = get_internal_slot_number_for_totp(slot_number); - return erase_slot(slot_number, temporary_password); - } - - template - void vector_copy_ranged(T& dest, std::vector &vec, size_t begin, size_t elements_to_copy){ - const size_t d_size = sizeof(dest); - if(d_size < elements_to_copy){ - throw TargetBufferSmallerThanSource(elements_to_copy, d_size); - } - std::fill(dest, dest+d_size, 0); - std::copy(vec.begin() + begin, vec.begin() +begin + elements_to_copy, dest); - } - - template - void vector_copy(T& dest, std::vector &vec){ - const size_t d_size = sizeof(dest); - if(d_size < vec.size()){ - throw TargetBufferSmallerThanSource(vec.size(), d_size); - } - std::fill(dest, dest+d_size, 0); - std::copy(vec.begin(), vec.end(), dest); - } - - bool NitrokeyManager::write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password) { - if (!is_valid_hotp_slot_number(slot_number)) throw InvalidSlotException(slot_number); - - int internal_slot_number = get_internal_slot_number_for_hotp(slot_number); - if (is_authorization_command_supported()){ - write_HOTP_slot_authorize(internal_slot_number, slot_name, secret, hotp_counter, use_8_digits, use_enter, use_tokenID, - token_ID, temporary_password); - } else { - write_OTP_slot_no_authorize(internal_slot_number, slot_name, secret, hotp_counter, use_8_digits, use_enter, use_tokenID, - token_ID, temporary_password); - } - return true; - } - - void NitrokeyManager::write_HOTP_slot_authorize(uint8_t slot_number, const char *slot_name, const char *secret, - uint64_t hotp_counter, bool use_8_digits, bool use_enter, - bool use_tokenID, const char *token_ID, const char *temporary_password) { - auto payload = get_payload(); - payload.slot_number = slot_number; - auto secret_bin = misc::hex_string_to_byte(secret); - vector_copy(payload.slot_secret, secret_bin); - strcpyT(payload.slot_name, slot_name); - strcpyT(payload.slot_token_id, token_ID); - switch (device->get_device_model() ){ - case DeviceModel::PRO: { - payload.slot_counter = hotp_counter; - break; - } - case DeviceModel::STORAGE: { - string counter = to_string(hotp_counter); - strcpyT(payload.slot_counter_s, counter.c_str()); - break; - } - default: - LOG(string(__FILE__) + to_string(__LINE__) + - string(__FUNCTION__) + string(" Unhandled device model for HOTP") - , Loglevel::DEBUG); - break; - } - payload.use_8_digits = use_8_digits; - payload.use_enter = use_enter; - payload.use_tokenID = use_tokenID; - - authorize_packet(payload, temporary_password, device); - - auto resp = WriteToHOTPSlot::CommandTransaction::run(device, payload); - } - - bool NitrokeyManager::write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password) { - if (!is_valid_totp_slot_number(slot_number)) throw InvalidSlotException(slot_number); - int internal_slot_number = get_internal_slot_number_for_totp(slot_number); - - if (is_authorization_command_supported()){ - write_TOTP_slot_authorize(internal_slot_number, slot_name, secret, time_window, use_8_digits, use_enter, use_tokenID, - token_ID, temporary_password); - } else { - write_OTP_slot_no_authorize(internal_slot_number, slot_name, secret, time_window, use_8_digits, use_enter, use_tokenID, - token_ID, temporary_password); - } - - return true; - } - - void NitrokeyManager::write_OTP_slot_no_authorize(uint8_t internal_slot_number, const char *slot_name, - const char *secret, - uint64_t counter_or_interval, bool use_8_digits, bool use_enter, - bool use_tokenID, const char *token_ID, - const char *temporary_password) const { - - auto payload2 = get_payload(); - strcpyT(payload2.temporary_admin_password, temporary_password); - strcpyT(payload2.data, slot_name); - payload2.setTypeName(); - stick10_08::SendOTPData::CommandTransaction::run(device, payload2); - - payload2.setTypeSecret(); - payload2.id = 0; - auto secret_bin = misc::hex_string_to_byte(secret); - auto remaining_secret_length = secret_bin.size(); - const auto maximum_OTP_secret_size = 40; - if(remaining_secret_length > maximum_OTP_secret_size){ - throw TargetBufferSmallerThanSource(remaining_secret_length, maximum_OTP_secret_size); - } - - while (remaining_secret_length>0){ - const auto bytesToCopy = std::min(sizeof(payload2.data), remaining_secret_length); - const auto start = secret_bin.size() - remaining_secret_length; - memset(payload2.data, 0, sizeof(payload2.data)); - vector_copy_ranged(payload2.data, secret_bin, start, bytesToCopy); - stick10_08::SendOTPData::CommandTransaction::run(device, payload2); - remaining_secret_length -= bytesToCopy; - payload2.id++; - } - - auto payload = get_payload(); - strcpyT(payload.temporary_admin_password, temporary_password); - strcpyT(payload.slot_token_id, token_ID); - payload.use_8_digits = use_8_digits; - payload.use_enter = use_enter; - payload.use_tokenID = use_tokenID; - payload.slot_counter_or_interval = counter_or_interval; - payload.slot_number = internal_slot_number; - stick10_08::WriteToOTPSlot::CommandTransaction::run(device, payload); - } - - void NitrokeyManager::write_TOTP_slot_authorize(uint8_t slot_number, const char *slot_name, const char *secret, - uint16_t time_window, bool use_8_digits, bool use_enter, - bool use_tokenID, const char *token_ID, const char *temporary_password) { - auto payload = get_payload(); - payload.slot_number = slot_number; - auto secret_bin = misc::hex_string_to_byte(secret); - vector_copy(payload.slot_secret, secret_bin); - strcpyT(payload.slot_name, slot_name); - strcpyT(payload.slot_token_id, token_ID); - payload.slot_interval = time_window; //FIXME naming - payload.use_8_digits = use_8_digits; - payload.use_enter = use_enter; - payload.use_tokenID = use_tokenID; - - authorize_packet(payload, temporary_password, device); - - auto resp = WriteToTOTPSlot::CommandTransaction::run(device, payload); - } - - char * NitrokeyManager::get_totp_slot_name(uint8_t slot_number) { - if (!is_valid_totp_slot_number(slot_number)) throw InvalidSlotException(slot_number); - slot_number = get_internal_slot_number_for_totp(slot_number); - return get_slot_name(slot_number); - } - char * NitrokeyManager::get_hotp_slot_name(uint8_t slot_number) { - if (!is_valid_hotp_slot_number(slot_number)) throw InvalidSlotException(slot_number); - slot_number = get_internal_slot_number_for_hotp(slot_number); - return get_slot_name(slot_number); - } - - static const int max_string_field_length = 2*1024; //storage's status string is ~1k - - char * NitrokeyManager::get_slot_name(uint8_t slot_number) { - auto payload = get_payload(); - payload.slot_number = slot_number; - auto resp = GetSlotName::CommandTransaction::run(device, payload); - return strndup((const char *) resp.data().slot_name, max_string_field_length); - } - - bool NitrokeyManager::first_authenticate(const char *pin, const char *temporary_password) { - auto authreq = get_payload(); - strcpyT(authreq.card_password, pin); - strcpyT(authreq.temporary_password, temporary_password); - FirstAuthenticate::CommandTransaction::run(device, authreq); - return true; - } - - bool NitrokeyManager::set_time(uint64_t time) { - auto p = get_payload(); - p.reset = 1; - p.time = time; - SetTime::CommandTransaction::run(device, p); - return false; - } - - void NitrokeyManager::set_time_soft(uint64_t time) { - auto p = get_payload(); - p.reset = 0; - p.time = time; - SetTime::CommandTransaction::run(device, p); - } - - bool NitrokeyManager::get_time(uint64_t time) { - set_time_soft(time); - return true; - } - - void NitrokeyManager::change_user_PIN(const char *current_PIN, const char *new_PIN) { - change_PIN_general(current_PIN, new_PIN); - } - - void NitrokeyManager::change_admin_PIN(const char *current_PIN, const char *new_PIN) { - change_PIN_general(current_PIN, new_PIN); - } - - template - void NitrokeyManager::change_PIN_general(const char *current_PIN, const char *new_PIN) { - switch (device->get_device_model()){ - case DeviceModel::PRO: - { - auto p = get_payload(); - strcpyT(p.old_pin, current_PIN); - strcpyT(p.new_pin, new_PIN); - ProCommand::CommandTransaction::run(device, p); - } - break; - //in Storage change admin/user pin is divided to two commands with 20 chars field len - case DeviceModel::STORAGE: - { - auto p = get_payload(); - strcpyT(p.password, current_PIN); - p.set_kind(StoKind); - auto p2 = get_payload(); - strcpyT(p2.password, new_PIN); - p2.set_kind(StoKind); - ChangeAdminUserPin20Current::CommandTransaction::run(device, p); - ChangeAdminUserPin20New::CommandTransaction::run(device, p2); - } - break; - } - - } - - void NitrokeyManager::enable_password_safe(const char *user_pin) { - //The following command will cancel enabling PWS if it is not supported - auto a = get_payload(); - strcpyT(a.user_password, user_pin); - IsAESSupported::CommandTransaction::run(device, a); - - auto p = get_payload(); - strcpyT(p.user_password, user_pin); - EnablePasswordSafe::CommandTransaction::run(device, p); - } - - vector NitrokeyManager::get_password_safe_slot_status() { - auto responsePayload = GetPasswordSafeSlotStatus::CommandTransaction::run(device); - vector v = vector(responsePayload.data().password_safe_status, - responsePayload.data().password_safe_status - + sizeof(responsePayload.data().password_safe_status)); - return v; - } - - uint8_t NitrokeyManager::get_user_retry_count() { - if(device->get_device_model() == DeviceModel::STORAGE){ - stick20::GetDeviceStatus::CommandTransaction::run(device); - } - auto response = GetUserPasswordRetryCount::CommandTransaction::run(device); - return response.data().password_retry_count; - } - - uint8_t NitrokeyManager::get_admin_retry_count() { - if(device->get_device_model() == DeviceModel::STORAGE){ - stick20::GetDeviceStatus::CommandTransaction::run(device); - } - auto response = GetPasswordRetryCount::CommandTransaction::run(device); - return response.data().password_retry_count; - } - - void NitrokeyManager::lock_device() { - LockDevice::CommandTransaction::run(device); - } - - char * NitrokeyManager::get_password_safe_slot_name(uint8_t slot_number) { - if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number); - auto p = get_payload(); - p.slot_number = slot_number; - auto response = GetPasswordSafeSlotName::CommandTransaction::run(device, p); - return strndup((const char *) response.data().slot_name, max_string_field_length); - } - - bool NitrokeyManager::is_valid_password_safe_slot_number(uint8_t slot_number) const { return slot_number < 16; } - - char * NitrokeyManager::get_password_safe_slot_login(uint8_t slot_number) { - if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number); - auto p = get_payload(); - p.slot_number = slot_number; - auto response = GetPasswordSafeSlotLogin::CommandTransaction::run(device, p); - return strndup((const char *) response.data().slot_login, max_string_field_length); - } - - char * NitrokeyManager::get_password_safe_slot_password(uint8_t slot_number) { - if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number); - auto p = get_payload(); - p.slot_number = slot_number; - auto response = GetPasswordSafeSlotPassword::CommandTransaction::run(device, p); - return strndup((const char *) response.data().slot_password, max_string_field_length); //FIXME use secure way - } - - void NitrokeyManager::write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, - const char *slot_password) { - if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number); - auto p = get_payload(); - p.slot_number = slot_number; - strcpyT(p.slot_name, slot_name); - strcpyT(p.slot_password, slot_password); - SetPasswordSafeSlotData::CommandTransaction::run(device, p); - - auto p2 = get_payload(); - p2.slot_number = slot_number; - strcpyT(p2.slot_login_name, slot_login); - SetPasswordSafeSlotData2::CommandTransaction::run(device, p2); - } - - void NitrokeyManager::erase_password_safe_slot(uint8_t slot_number) { - if (!is_valid_password_safe_slot_number(slot_number)) throw InvalidSlotException(slot_number); - auto p = get_payload(); - p.slot_number = slot_number; - ErasePasswordSafeSlot::CommandTransaction::run(device, p); - } - - void NitrokeyManager::user_authenticate(const char *user_password, const char *temporary_password) { - auto p = get_payload(); - strcpyT(p.card_password, user_password); - strcpyT(p.temporary_password, temporary_password); - UserAuthenticate::CommandTransaction::run(device, p); - } - - void NitrokeyManager::build_aes_key(const char *admin_password) { - switch (device->get_device_model()) { - case DeviceModel::PRO: { - auto p = get_payload(); - strcpyT(p.admin_password, admin_password); - BuildAESKey::CommandTransaction::run(device, p); - break; - } - case DeviceModel::STORAGE : { - auto p = get_payload(); - strcpyT(p.password, admin_password); - p.set_defaults(); - stick20::CreateNewKeys::CommandTransaction::run(device, p); - break; - } - } - } - - void NitrokeyManager::factory_reset(const char *admin_password) { - auto p = get_payload(); - strcpyT(p.admin_password, admin_password); - FactoryReset::CommandTransaction::run(device, p); - } - - void NitrokeyManager::unlock_user_password(const char *admin_password, const char *new_user_password) { - switch (device->get_device_model()){ - case DeviceModel::PRO: { - auto p = get_payload(); - strcpyT(p.admin_password, admin_password); - strcpyT(p.user_new_password, new_user_password); - stick10::UnlockUserPassword::CommandTransaction::run(device, p); - break; - } - case DeviceModel::STORAGE : { - auto p2 = get_payload(); - p2.set_defaults(); - strcpyT(p2.password, admin_password); - ChangeAdminUserPin20Current::CommandTransaction::run(device, p2); - auto p3 = get_payload(); - p3.set_defaults(); - strcpyT(p3.password, new_user_password); - stick20::UnlockUserPin::CommandTransaction::run(device, p3); - break; - } - } - } - - - void NitrokeyManager::write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password, - bool delete_user_password, const char *admin_temporary_password) { - auto p = get_payload(); - p.numlock = numlock; - p.capslock = capslock; - p.scrolllock = scrolllock; - p.enable_user_password = static_cast(enable_user_password ? 1 : 0); - p.delete_user_password = static_cast(delete_user_password ? 1 : 0); - if (is_authorization_command_supported()){ - authorize_packet(p, admin_temporary_password, device); - } else { - strcpyT(p.temporary_admin_password, admin_temporary_password); - } - stick10_08::WriteGeneralConfig::CommandTransaction::run(device, p); - } - - vector NitrokeyManager::read_config() { - auto responsePayload = GetStatus::CommandTransaction::run(device); - vector v = vector(responsePayload.data().general_config, - responsePayload.data().general_config+sizeof(responsePayload.data().general_config)); - return v; - } - - bool NitrokeyManager::is_authorization_command_supported(){ - //authorization command is supported for versions equal or below: - auto m = std::unordered_map({ - {DeviceModel::PRO, 7}, - {DeviceModel::STORAGE, 53}, - }); - return get_minor_firmware_version() <= m[device->get_device_model()]; - } - - bool NitrokeyManager::is_320_OTP_secret_supported(){ - // 320 bit OTP secret is supported by version bigger or equal to: - auto m = std::unordered_map({ - {DeviceModel::PRO, 8}, - {DeviceModel::STORAGE, 54}, - }); - return get_minor_firmware_version() >= m[device->get_device_model()]; - } - - DeviceModel NitrokeyManager::get_connected_device_model() const{ - if (device == nullptr){ - throw DeviceNotConnected("device not connected"); - } - return device->get_device_model(); - } - - bool NitrokeyManager::is_smartcard_in_use(){ - try{ - stick20::CheckSmartcardUsage::CommandTransaction::run(device); - } - catch(const CommandFailedException & e){ - return e.reason_smartcard_busy(); - } - return false; - } - - uint8_t NitrokeyManager::get_minor_firmware_version(){ - switch(device->get_device_model()){ - case DeviceModel::PRO:{ - auto status_p = GetStatus::CommandTransaction::run(device); - return status_p.data().firmware_version_st.minor; //7 or 8 - } - case DeviceModel::STORAGE:{ - auto status = stick20::GetDeviceStatus::CommandTransaction::run(device); - auto test_firmware = status.data().versionInfo.build_iteration != 0; - if (test_firmware) - LOG("Development firmware detected. Increasing minor version number.", nitrokey::log::Loglevel::WARNING); - return status.data().versionInfo.minor + (test_firmware? 1 : 0); - } - } - return 0; - } - uint8_t NitrokeyManager::get_major_firmware_version(){ - switch(device->get_device_model()){ - case DeviceModel::PRO:{ - auto status_p = GetStatus::CommandTransaction::run(device); - return status_p.data().firmware_version_st.major; //0 - } - case DeviceModel::STORAGE:{ - auto status = stick20::GetDeviceStatus::CommandTransaction::run(device); - return status.data().versionInfo.major; - } - } - return 0; - } - - bool NitrokeyManager::is_AES_supported(const char *user_password) { - auto a = get_payload(); - strcpyT(a.user_password, user_password); - IsAESSupported::CommandTransaction::run(device, a); - return true; - } - - //storage commands - - void NitrokeyManager::send_startup(uint64_t seconds_from_epoch){ - auto p = get_payload(); -// p.set_defaults(); //set current time - p.localtime = seconds_from_epoch; - stick20::SendStartup::CommandTransaction::run(device, p); - } - - void NitrokeyManager::unlock_encrypted_volume(const char* user_pin){ - misc::execute_password_command(device, user_pin); - } - - void NitrokeyManager::unlock_hidden_volume(const char* hidden_volume_password) { - misc::execute_password_command(device, hidden_volume_password); - } - - void NitrokeyManager::set_encrypted_volume_read_only(const char* admin_pin) { - misc::execute_password_command(device, admin_pin); - } - - void NitrokeyManager::set_encrypted_volume_read_write(const char* admin_pin) { - misc::execute_password_command(device, admin_pin); - } - - //TODO check is encrypted volume unlocked before execution - //if not return library exception - void NitrokeyManager::create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, - const char *hidden_volume_password) { - auto p = get_payload(); - p.SlotNr_u8 = slot_nr; - p.StartBlockPercent_u8 = start_percent; - p.EndBlockPercent_u8 = end_percent; - strcpyT(p.HiddenVolumePassword_au8, hidden_volume_password); - stick20::SetupHiddenVolume::CommandTransaction::run(device, p); - } - - void NitrokeyManager::set_unencrypted_read_only_admin(const char* admin_pin) { - //from v0.49, v0.52+ it needs Admin PIN - if (set_unencrypted_volume_rorw_pin_type_user()){ - LOG("set_unencrypted_read_only_admin is not supported for this version of Storage device. " - "Please update firmware to v0.52+. Doing nothing.", nitrokey::log::Loglevel::WARNING); - return; - } - misc::execute_password_command(device, admin_pin); - } - - void NitrokeyManager::set_unencrypted_read_only(const char *user_pin) { - //until v0.48 (incl. v0.50 and v0.51) User PIN was sufficient - LOG("set_unencrypted_read_only is deprecated. Use set_unencrypted_read_only_admin instead.", - nitrokey::log::Loglevel::WARNING); - if (!set_unencrypted_volume_rorw_pin_type_user()){ - LOG("set_unencrypted_read_only is not supported for this version of Storage device. Doing nothing.", - nitrokey::log::Loglevel::WARNING); - return; - } - misc::execute_password_command(device, user_pin); - } - - void NitrokeyManager::set_unencrypted_read_write_admin(const char* admin_pin) { - //from v0.49, v0.52+ it needs Admin PIN - if (set_unencrypted_volume_rorw_pin_type_user()){ - LOG("set_unencrypted_read_write_admin is not supported for this version of Storage device. " - "Please update firmware to v0.52+. Doing nothing.", nitrokey::log::Loglevel::WARNING); - return; - } - misc::execute_password_command(device, admin_pin); - } - - void NitrokeyManager::set_unencrypted_read_write(const char *user_pin) { - //until v0.48 (incl. v0.50 and v0.51) User PIN was sufficient - LOG("set_unencrypted_read_write is deprecated. Use set_unencrypted_read_write_admin instead.", - nitrokey::log::Loglevel::WARNING); - if (!set_unencrypted_volume_rorw_pin_type_user()){ - LOG("set_unencrypted_read_write is not supported for this version of Storage device. Doing nothing.", - nitrokey::log::Loglevel::WARNING); - return; - } - misc::execute_password_command(device, user_pin); - } - - bool NitrokeyManager::set_unencrypted_volume_rorw_pin_type_user(){ - auto minor_firmware_version = get_minor_firmware_version(); - return minor_firmware_version <= 48 || minor_firmware_version == 50 || minor_firmware_version == 51; - } - - void NitrokeyManager::export_firmware(const char* admin_pin) { - misc::execute_password_command(device, admin_pin); - } - - void NitrokeyManager::enable_firmware_update(const char* firmware_pin) { - misc::execute_password_command(device, firmware_pin); - } - - void NitrokeyManager::clear_new_sd_card_warning(const char* admin_pin) { - misc::execute_password_command(device, admin_pin); - } - - void NitrokeyManager::fill_SD_card_with_random_data(const char* admin_pin) { - auto p = get_payload(); - p.set_defaults(); - strcpyT(p.admin_pin, admin_pin); - stick20::FillSDCardWithRandomChars::CommandTransaction::run(device, p); - } - - void NitrokeyManager::change_update_password(const char* current_update_password, const char* new_update_password) { - auto p = get_payload(); - strcpyT(p.current_update_password, current_update_password); - strcpyT(p.new_update_password, new_update_password); - stick20::ChangeUpdatePassword::CommandTransaction::run(device, p); - } - - char * NitrokeyManager::get_status_storage_as_string(){ - auto p = stick20::GetDeviceStatus::CommandTransaction::run(device); - return strndup(p.data().dissect().c_str(), max_string_field_length); - } - - stick20::DeviceConfigurationResponsePacket::ResponsePayload NitrokeyManager::get_status_storage(){ - auto p = stick20::GetDeviceStatus::CommandTransaction::run(device); - return p.data(); - } - - char * NitrokeyManager::get_SD_usage_data_as_string(){ - auto p = stick20::GetSDCardOccupancy::CommandTransaction::run(device); - return strndup(p.data().dissect().c_str(), max_string_field_length); - } - - std::pair NitrokeyManager::get_SD_usage_data(){ - auto p = stick20::GetSDCardOccupancy::CommandTransaction::run(device); - return std::make_pair(p.data().WriteLevelMin, p.data().WriteLevelMax); - } - - int NitrokeyManager::get_progress_bar_value(){ - try{ - stick20::GetDeviceStatus::CommandTransaction::run(device); - return -1; - } - catch (LongOperationInProgressException &e){ - return e.progress_bar_value; - } - } - - string NitrokeyManager::get_TOTP_code(uint8_t slot_number, const char *user_temporary_password) { - return get_TOTP_code(slot_number, 0, 0, 0, user_temporary_password); - } - - /** - * Returns ReadSlot structure, describing OTP slot configuration. Always return binary counter - - * does the necessary conversion, if needed, to unify the behavior across Pro and Storage. - * @private For internal use only - * @param slot_number which OTP slot to use (usual format) - * @return ReadSlot structure - */ - stick10::ReadSlot::ResponsePayload NitrokeyManager::get_OTP_slot_data(const uint8_t slot_number) { - auto p = get_payload(); - p.slot_number = slot_number; - p.data_format = stick10::ReadSlot::CounterFormat::BINARY; // ignored for devices other than Storage v0.54+ - auto data = stick10::ReadSlot::CommandTransaction::run(device, p); - - auto &payload = data.data(); - - // if fw <=v0.53 and asked binary - do the conversion from ASCII - if (device->get_device_model() == DeviceModel::STORAGE && get_minor_firmware_version() <= 53 - && is_internal_hotp_slot_number(slot_number)) - { - //convert counter from string to ull - auto counter_s = std::string(payload.slot_counter_s, payload.slot_counter_s + sizeof(payload.slot_counter_s)); - payload.slot_counter = std::stoull(counter_s); - } - - return payload; - } - - stick10::ReadSlot::ResponsePayload NitrokeyManager::get_TOTP_slot_data(const uint8_t slot_number) { - return get_OTP_slot_data(get_internal_slot_number_for_totp(slot_number)); - } - - stick10::ReadSlot::ResponsePayload NitrokeyManager::get_HOTP_slot_data(const uint8_t slot_number) { - return get_OTP_slot_data(get_internal_slot_number_for_hotp(slot_number)); - } - - void NitrokeyManager::lock_encrypted_volume() { - misc::execute_password_command(device, ""); - } - - void NitrokeyManager::lock_hidden_volume() { - misc::execute_password_command(device, ""); - } - - uint8_t NitrokeyManager::get_SD_card_size() { - auto data = stick20::ProductionTest::CommandTransaction::run(device); - return data.data().SD_Card_Size_u8; - } - - const string NitrokeyManager::get_current_device_id() const { - return current_device_id; - } - - void NitrokeyManager::wink(){ - stick20::Wink::CommandTransaction::run(device); - }; - - stick20::ProductionTest::ResponsePayload NitrokeyManager::production_info(){ - auto data = stick20::ProductionTest::CommandTransaction::run(device); - return data.data(); - }; - - void NitrokeyManager::enable_firmware_update_pro(const char *firmware_pin) { - auto p = get_payload(); - strcpyT(p.firmware_password, firmware_pin); - FirmwareUpdate::CommandTransaction::run(device, p); - } - - void - NitrokeyManager::change_firmware_update_password_pro(const char *firmware_pin_current, const char *firmware_pin_new) { - auto p = get_payload(); - strcpyT(p.firmware_password_current, firmware_pin_current); - strcpyT(p.firmware_password_new, firmware_pin_new); - FirmwarePasswordChange::CommandTransaction::run(device, p); - } - -} diff --git a/nitrokey-sys/libnitrokey-v3.5/README.md b/nitrokey-sys/libnitrokey-v3.5/README.md deleted file mode 100644 index a3683c0..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/README.md +++ /dev/null @@ -1,291 +0,0 @@ -[![Build Status](https://travis-ci.org/Nitrokey/libnitrokey.svg?branch=master)](https://travis-ci.org/Nitrokey/libnitrokey) -[![Waffle.io - Columns and their card count](https://badge.waffle.io/Nitrokey/libnitrokey.svg?columns=ready,in%20progress,test,waiting%20for%20feedback)](https://waffle.io/Nitrokey/libnitrokey) - -# libnitrokey -libnitrokey is a project to communicate with Nitrokey Pro and Storage devices in a clean and easy manner. Written in C++14, testable with `py.test` and `Catch` frameworks, with C API, Python access (through CFFI and C API, in future with Pybind11). - -The development of this project is aimed to make it itself a living documentation of communication protocol between host and the Nitrokey stick devices. The command packets' format is described here: [Pro v0.7](libnitrokey/stick10_commands.h), [Pro v0.8](libnitrokey/stick10_commands_0.8.h), [Storage](libnitrokey/stick20_commands.h). Handling and additional operations are described here: [NitrokeyManager.cc](NitrokeyManager.cc). - -A C++14 complying compiler is required due to heavy use of variable templates. For feature support tables please check [table 1](https://gcc.gnu.org/projects/cxx-status.html#cxx14) or [table 2](http://en.cppreference.com/w/cpp/compiler_support). - -libnitrokey is developed and tested with the latest compilers: g++ 6.2, clang 3.8. We use Travis CI to test builds also on g++ 5.4 and under OSX compilers starting up from xcode 8.2 environment. - -## Getting sources -This repository uses `git submodules`. -To clone please use git's `--recursive` option like in: -```bash -git clone --recursive https://github.com/Nitrokey/libnitrokey.git -``` -or for already cloned repository: -```bash -git clone https://github.com/Nitrokey/libnitrokey.git -cd libnitrokey -git submodule update --init --recursive -``` - -## Dependencies -Following libraries are needed to use libnitrokey on Linux (names of the packages on Ubuntu): -- libhidapi-dev [(HID API)](http://www.signal11.us/oss/hidapi/) -- libusb-1.0-0-dev - - -## Compilation -libnitrokey uses CMake as its main build system. As a secondary option it offers building through Qt's qMake. -### Qt -A Qt's .pro project file is provided for direct compilation and for inclusion to other projects. -Using it directly is not recommended due to lack of dependencies check and not implemented library versioning. -Compilation is tested with Qt 5.6 and greater. - -Quick start example: -```bash -mkdir -p build -cd build -qmake .. -make -j2 -``` - -### Windows and Visual Studio 2017 -Lately Visual Studio has started handling CMake files directly. After opening the project's directory it should recognize it and initialize build system. Afterwards please run: -1. `CMake -> Cache -> View Cache CMakeLists.txt -> CMakeLists.txt` to edit settings -2. `CMake -> Build All` to build - -It is possible too to use CMake GUI directly with its settings editor. - -### CMake -To compile please run following sequence of commands: -```bash -# assuming current dir is ./libnitrokey/ -mkdir -p build -cd build -cmake .. -make -j2 -``` - -By default (with empty `` string) this will create in `build/` directory a shared library (.so, .dll or .dynlib). If you wish to build static version you can use as `` string `-DBUILD_SHARED_LIBS=OFF`. - -All options could be listed with `cmake .. -L` or instead `cmake` a `ccmake ..` tool could be used for configuration (where `..` is the path to directory with `CMakeLists.txt` file). `ccmake` shows also description of the build parameters. - -If you have trouble compiling or running the library you can check [.travis.yml](.travis.yml) file for configuration details. This file is used by Travis CI service to make test builds on OSX and Ubuntu 14.04. - -Other build options (all take either `ON` or `OFF`): -* ADD_ASAN - add tests for memory leaks and out-of-bounds access -* ADD_TSAN - add tests for threads race, needs USE_CLANG -* COMPILE_TESTS - compile C++ tests -* COMPILE_OFFLINE_TESTS - compile C++ tests, that do not require any device to be connected -* LOG_VOLATILE_DATA (default: OFF) - include secrets in log (PWS passwords, PINs etc) -* NO_LOG (default: OFF) - do not compile LOG statements - will make library smaller, but without any diagnostic messages - - -### Meson -It is possible to use Meson and Ninja to build the project as well (currently available only `master` branch). -Please run: -``` -meson builddir -meson configure builddir # to show available build flags -ninja -C builddir -``` - -# Using libnitrokey with Python -To use libnitrokey with Python a [CFFI](http://cffi.readthedocs.io/en/latest/overview.html) library is required (either 2.7+ or 3.0+). It can be installed with: -```bash -pip install --user cffi # for python 2.x -pip3 install cffi # for python 3.x -``` -Just import it, read the C API header and it is done! You have access to the library. Here is an example (in Python 2) printing HOTP code for Pro or Storage device, assuming it is run in root directory [(full example)](python_bindings_example.py): -```python -#!/usr/bin/env python2 -import cffi - -ffi = cffi.FFI() -get_string = ffi.string - -def get_library(): - fp = 'NK_C_API.h' # path to C API header - - declarations = [] - with open(fp, 'r') as f: - declarations = f.readlines() - - cnt = 0 - a = iter(declarations) - for declaration in a: - if declaration.strip().startswith('NK_C_API'): - declaration = declaration.replace('NK_C_API', '').strip() - while ';' not in declaration: - declaration += (next(a)).strip() - # print(declaration) - ffi.cdef(declaration, override=True) - cnt +=1 - print('Imported {} declarations'.format(cnt)) - - - C = None - import os, sys - path_build = os.path.join(".", "build") - paths = [ - os.environ.get('LIBNK_PATH', None), - os.path.join(path_build,"libnitrokey.so"), - os.path.join(path_build,"libnitrokey.dylib"), - os.path.join(path_build,"libnitrokey.dll"), - os.path.join(path_build,"nitrokey.dll"), - ] - for p in paths: - if not p: continue - print("Trying " +p) - p = os.path.abspath(p) - if os.path.exists(p): - print("Found: "+p) - C = ffi.dlopen(p) - break - else: - print("File does not exist: " + p) - if not C: - print("No library file found") - sys.exit(1) - - return C - - -def get_hotp_code(lib, i): - return lib.NK_get_hotp_code(i) - - -libnitrokey = get_library() -libnitrokey.NK_set_debug(False) # do not show debug messages (log library only) - -hotp_slot_code = get_hotp_code(libnitrokey, 1) -print('Getting HOTP code from Nitrokey device: ') -print(hotp_slot_code) -libnitrokey.NK_logout() # disconnect device -``` - -In case no devices are connected, a friendly message will be printed. -All available functions for C and Python are listed in [NK_C_API.h](NK_C_API.h). Please check `Documentation` section below. - -## Documentation -The documentation of C API is included in the sources (can be generated with `make doc` if Doxygen is installed). -Please check [NK_C_API.h](NK_C_API.h) (C API) for high level commands and [libnitrokey/NitrokeyManager.h](libnitrokey/NitrokeyManager.h) (C++ API). All devices' commands are listed along with packet format in [libnitrokey/stick10_commands.h](libnitrokey/stick10_commands.h) and [libnitrokey/stick20_commands.h](libnitrokey/stick20_commands.h) respectively for Nitrokey Pro and Nitrokey Storage products. - -# Tests -**Warning!** Most of the tests will overwrite user data. The only user-data safe tests are specified in `unittest/test_safe.cpp` (see *C++ tests* chapter). - -**Warning!** Before you run unittests please change both your Admin and User PINs on your Nitrostick to defaults (`12345678` and `123456` respectively), or change the values in tests source code. If you do not change them, the tests might lock your device temporarily. If it's too late already, you can reset your Nitrokey using instructions from [homepage](https://www.nitrokey.com/de/documentation/how-reset-nitrokey). - -## Python tests -libnitrokey has a great suite of tests written in Python 3 under the path: [unittest/test_*.py](https://github.com/Nitrokey/libnitrokey/tree/master/unittest): -* `test_pro.py` - contains tests of OTP, Password Safe and PIN control functionality. Could be run on both Pro and Storage devices. -* `test_storage.py` - contains tests of Encrypted Volumes functionality. Could be run only on Storage. - -The tests themselves show how to handle common requests to device. -Before running please install all required libraries with: -```bash -cd unittest -pip install --user -r requirements.txt -``` -or use Python's environment managing tool like [pipenv](https://pipenv.readthedocs.io/en/latest/) or `virtualenv`. - - -To run them please execute: -```bash -# substitute with either 'pro' or 'storage' -py.test -v test_.py -# more specific use - run tests containing in name 5 times: -py.test -v test_.py -k --count 5 - -``` -For additional documentation please check the following for [py.test installation](http://doc.pytest.org/en/latest/getting-started.html). For better coverage [randomly plugin](https://pypi.python.org/pypi/pytest-randomly) is installed - it randomizes the test order allowing to detect unseen dependencies between the tests. - -## C++ tests -There are also some unit tests implemented in C++, placed in unittest directory. The only user-data safe online test set here is [test_safe.cpp](https://github.com/Nitrokey/libnitrokey/blob/master/unittest/test_safe.cpp), which tries to connect to the device, and collect its status data. Example run for Storage: -```text -# Storage device inserted, firmware version v0.53 -$ ./test_safe -[Wed Jan 2 13:31:17 2019][DEBUG_L1] => GET_DEVICE_STATUS -.. -[Wed Jan 2 13:31:17 2019][DEBUG_L1] <= GET_DEVICE_STATUS 0 1 -[Wed Jan 2 13:31:17 2019][DEBUG_L1] => GET_PASSWORD_RETRY_COUNT -[Wed Jan 2 13:31:17 2019][DEBUG_L1] <= GET_PASSWORD_RETRY_COUNT 0 0 -[Wed Jan 2 13:31:17 2019][DEBUG_L1] => GET_DEVICE_STATUS -.. -[Wed Jan 2 13:31:17 2019][DEBUG_L1] <= GET_DEVICE_STATUS 0 1 -[Wed Jan 2 13:31:17 2019][DEBUG_L1] => GET_USER_PASSWORD_RETRY_COUNT -[Wed Jan 2 13:31:17 2019][DEBUG_L1] <= GET_USER_PASSWORD_RETRY_COUNT 0 0 -[Wed Jan 2 13:31:17 2019][DEBUG_L1] => GET_DEVICE_STATUS -... -[Wed Jan 2 13:31:17 2019][DEBUG_L1] <= GET_DEVICE_STATUS 0 1 - transmission_data.dissect(): _padding: -0000 00 00 00 00 00 00 00 00 00 00 00 00 00 05 2e 01 ................ -0010 00 00 -- -- -- -- -- -- -- -- -- -- -- -- -- -- .. - (int) SendCounter_u8: 0 - (int) SendDataType_u8: 3 - (int) FollowBytesFlag_u8: 0 - (int) SendSize_u8: 28 - - MagicNumber_StickConfig_u16: 13080 - (int) ReadWriteFlagUncryptedVolume_u8: 1 - (int) ReadWriteFlagCryptedVolume_u8: 0 - (int) ReadWriteFlagHiddenVolume_u8: 0 - (int) versionInfo.major: 0 - (int) versionInfo.minor: 53 - (int) versionInfo.build_iteration: 0 - (int) FirmwareLocked_u8: 0 - (int) NewSDCardFound_u8: 1 - (int) NewSDCardFound_st.NewCard: 1 - (int) NewSDCardFound_st.Counter: 0 - (int) SDFillWithRandomChars_u8: 1 - ActiveSD_CardID_u32: 3670817656 - (int) VolumeActiceFlag_u8: 1 - (int) VolumeActiceFlag_st.unencrypted: 1 - (int) VolumeActiceFlag_st.encrypted: 0 - (int) VolumeActiceFlag_st.hidden: 0 - (int) NewSmartCardFound_u8: 0 - (int) UserPwRetryCount: 3 - (int) AdminPwRetryCount: 3 - ActiveSmartCardID_u32: 24122 - (int) StickKeysNotInitiated: 0 - -[Wed Jan 2 13:31:17 2019][DEBUG_L1] => GET_DEVICE_STATUS -.. -[Wed Jan 2 13:31:17 2019][DEBUG_L1] <= GET_DEVICE_STATUS 0 1 -00005e3a -[Wed Jan 2 13:31:17 2019][DEBUG_L1] => GET_DEVICE_STATUS -.... -[Wed Jan 2 13:31:18 2019][DEBUG_L1] <= GET_DEVICE_STATUS 0 1 -[Wed Jan 2 13:31:18 2019][DEBUG_L1] => GET_DEVICE_STATUS -... -[Wed Jan 2 13:31:18 2019][DEBUG_L1] <= GET_DEVICE_STATUS 0 1 -=============================================================================== -All tests passed (18 assertions in 6 test cases) -``` -Test's execution configuration and verbosity could be manipulated - please see `./test_safe --help` for details. - -The other tests sets are not written as extensively as Python tests and are rather more a C++ low level interface check used during the library development, using either low-level components, C API from `NK_C_API.cc`, or C++ API from `NitrokeyManager.cc`. Some of them are: [test_HOTP.cc](https://github.com/Nitrokey/libnitrokey/blob/master/unittest/test_HOTP.cc), -[test1.cc](https://github.com/Nitrokey/libnitrokey/blob/master/unittest/test1.cc). See more in [unittest](https://github.com/Nitrokey/libnitrokey/tree/master/unittest) directory. - -**Note: these are not device model agnostic, and will most probably destroy your data on the device.** - - -Unit tests were checked on Ubuntu 16.04/16.10/17.04. To run them just execute binaries built in `./libnitrokey/build` dir, after enabling them by passing `-DCOMPILE_TESTS=ON` option to `cmake` - e.g.: `cmake .. -DCOMPILE_TESTS=ON && make`. - - -The documentation of how it works could be found in nitrokey-app project's README on Github: -[Nitrokey-app - internals](https://github.com/Nitrokey/nitrokey-app/blob/master/README.md#internals). - -To peek/debug communication with device running nitrokey-app (0.x branch) in debug mode (`-d` switch) and checking the logs -(right click on tray icon and then 'Debug') might be helpful. Latest Nitrokey App (1.x branch) uses libnitrokey to communicate with device. Once run with `--dl 3` (3 or higher; range 0-5) it will print all communication to the console. Additionally crosschecking with -firmware code should show how things works: -[report_protocol.c](https://github.com/Nitrokey/nitrokey-pro-firmware/blob/master/src/keyboard/report_protocol.c) -(for Nitrokey Pro, for Storage similarly). - -# Known issues / tasks -* Currently only one device can be connected at a time (experimental work could be found in `wip-multiple_devices` branch), -* C++ API needs some reorganization to C++ objects (instead of pointers to byte arrays). This will be also preparing for integration with Pybind11, -* Fix compilation warnings. - -Other tasks might be listed either in [TODO](TODO) file or on project's issues page. - -# License -This project is licensed under LGPL version 3. License text could be found under [LICENSE](LICENSE) file. - -# Roadmap -To check what issues will be fixed and when please check [milestones](https://github.com/Nitrokey/libnitrokey/milestones) page. diff --git a/nitrokey-sys/libnitrokey-v3.5/command_id.cc b/nitrokey-sys/libnitrokey-v3.5/command_id.cc deleted file mode 100644 index 9a329bc..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/command_id.cc +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include -#include "command_id.h" - -namespace nitrokey { -namespace proto { - -const char *commandid_to_string(CommandID id) { - switch (id) { - case CommandID::GET_STATUS: - return "GET_STATUS"; - case CommandID::WRITE_TO_SLOT: - return "WRITE_TO_SLOT"; - case CommandID::READ_SLOT_NAME: - return "READ_SLOT_NAME"; - case CommandID::READ_SLOT: - return "READ_SLOT"; - case CommandID::GET_CODE: - return "GET_CODE"; - case CommandID::WRITE_CONFIG: - return "WRITE_CONFIG"; - case CommandID::ERASE_SLOT: - return "ERASE_SLOT"; - case CommandID::FIRST_AUTHENTICATE: - return "FIRST_AUTHENTICATE"; - case CommandID::AUTHORIZE: - return "AUTHORIZE"; - case CommandID::GET_PASSWORD_RETRY_COUNT: - return "GET_PASSWORD_RETRY_COUNT"; - case CommandID::CLEAR_WARNING: - return "CLEAR_WARNING"; - case CommandID::SET_TIME: - return "SET_TIME"; - case CommandID::TEST_COUNTER: - return "TEST_COUNTER"; - case CommandID::TEST_TIME: - return "TEST_TIME"; - case CommandID::USER_AUTHENTICATE: - return "USER_AUTHENTICATE"; - case CommandID::GET_USER_PASSWORD_RETRY_COUNT: - return "GET_USER_PASSWORD_RETRY_COUNT"; - case CommandID::USER_AUTHORIZE: - return "USER_AUTHORIZE"; - case CommandID::UNLOCK_USER_PASSWORD: - return "UNLOCK_USER_PASSWORD"; - case CommandID::LOCK_DEVICE: - return "LOCK_DEVICE"; - case CommandID::FACTORY_RESET: - return "FACTORY_RESET"; - case CommandID::CHANGE_USER_PIN: - return "CHANGE_USER_PIN"; - case CommandID::CHANGE_ADMIN_PIN: - return "CHANGE_ADMIN_PIN"; - case CommandID::FIRMWARE_UPDATE: - return "FIRMWARE_UPDATE"; - case CommandID::FIRMWARE_PASSWORD_CHANGE: - return "FIRMWARE_PASSWORD_CHANGE"; - - case CommandID::ENABLE_CRYPTED_PARI: - return "ENABLE_CRYPTED_PARI"; - case CommandID::DISABLE_CRYPTED_PARI: - return "DISABLE_CRYPTED_PARI"; - case CommandID::ENABLE_HIDDEN_CRYPTED_PARI: - return "ENABLE_HIDDEN_CRYPTED_PARI"; - case CommandID::DISABLE_HIDDEN_CRYPTED_PARI: - return "DISABLE_HIDDEN_CRYPTED_PARI"; - case CommandID::ENABLE_FIRMWARE_UPDATE: - return "ENABLE_FIRMWARE_UPDATE"; - case CommandID::EXPORT_FIRMWARE_TO_FILE: - return "EXPORT_FIRMWARE_TO_FILE"; - case CommandID::GENERATE_NEW_KEYS: - return "GENERATE_NEW_KEYS"; - case CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS: - return "FILL_SD_CARD_WITH_RANDOM_CHARS"; - - case CommandID::WRITE_STATUS_DATA: - return "WRITE_STATUS_DATA"; - case CommandID::ENABLE_READONLY_UNCRYPTED_LUN: - return "ENABLE_READONLY_UNCRYPTED_LUN"; - case CommandID::ENABLE_READWRITE_UNCRYPTED_LUN: - return "ENABLE_READWRITE_UNCRYPTED_LUN"; - - case CommandID::SEND_PASSWORD_MATRIX: - return "SEND_PASSWORD_MATRIX"; - case CommandID::SEND_PASSWORD_MATRIX_PINDATA: - return "SEND_PASSWORD_MATRIX_PINDATA"; - case CommandID::SEND_PASSWORD_MATRIX_SETUP: - return "SEND_PASSWORD_MATRIX_SETUP"; - - case CommandID::GET_DEVICE_STATUS: - return "GET_DEVICE_STATUS"; - case CommandID::SEND_DEVICE_STATUS: - return "SEND_DEVICE_STATUS"; - - case CommandID::SEND_HIDDEN_VOLUME_PASSWORD: - return "SEND_HIDDEN_VOLUME_PASSWORD"; - case CommandID::SEND_HIDDEN_VOLUME_SETUP: - return "SEND_HIDDEN_VOLUME_SETUP"; - case CommandID::SEND_PASSWORD: - return "SEND_PASSWORD"; - case CommandID::SEND_NEW_PASSWORD: - return "SEND_NEW_PASSWORD"; - case CommandID::CLEAR_NEW_SD_CARD_FOUND: - return "CLEAR_NEW_SD_CARD_FOUND"; - - case CommandID::SEND_STARTUP: - return "SEND_STARTUP"; - case CommandID::SEND_CLEAR_STICK_KEYS_NOT_INITIATED: - return "SEND_CLEAR_STICK_KEYS_NOT_INITIATED"; - case CommandID::SEND_LOCK_STICK_HARDWARE: - return "SEND_LOCK_STICK_HARDWARE"; - - case CommandID::PRODUCTION_TEST: - return "PRODUCTION_TEST"; - case CommandID::SEND_DEBUG_DATA: - return "SEND_DEBUG_DATA"; - - case CommandID::CHANGE_UPDATE_PIN: - return "CHANGE_UPDATE_PIN"; - - case CommandID::ENABLE_ADMIN_READONLY_UNCRYPTED_LUN: - return "ENABLE_ADMIN_READONLY_UNCRYPTED_LUN"; - case CommandID::ENABLE_ADMIN_READWRITE_UNCRYPTED_LUN: - return "ENABLE_ADMIN_READWRITE_UNCRYPTED_LUN"; - case CommandID::ENABLE_ADMIN_READONLY_ENCRYPTED_LUN: - return "ENABLE_ADMIN_READONLY_ENCRYPTED_LUN"; - case CommandID::ENABLE_ADMIN_READWRITE_ENCRYPTED_LUN: - return "ENABLE_ADMIN_READWRITE_ENCRYPTED_LUN"; - case CommandID::CHECK_SMARTCARD_USAGE: - return "CHECK_SMARTCARD_USAGE"; - - case CommandID::GET_PW_SAFE_SLOT_STATUS: - return "GET_PW_SAFE_SLOT_STATUS"; - case CommandID::GET_PW_SAFE_SLOT_NAME: - return "GET_PW_SAFE_SLOT_NAME"; - case CommandID::GET_PW_SAFE_SLOT_PASSWORD: - return "GET_PW_SAFE_SLOT_PASSWORD"; - case CommandID::GET_PW_SAFE_SLOT_LOGINNAME: - return "GET_PW_SAFE_SLOT_LOGINNAME"; - case CommandID::SET_PW_SAFE_SLOT_DATA_1: - return "SET_PW_SAFE_SLOT_DATA_1"; - case CommandID::SET_PW_SAFE_SLOT_DATA_2: - return "SET_PW_SAFE_SLOT_DATA_2"; - case CommandID::PW_SAFE_ERASE_SLOT: - return "PW_SAFE_ERASE_SLOT"; - case CommandID::PW_SAFE_ENABLE: - return "PW_SAFE_ENABLE"; - case CommandID::PW_SAFE_INIT_KEY: - return "PW_SAFE_INIT_KEY"; - case CommandID::PW_SAFE_SEND_DATA: - return "PW_SAFE_SEND_DATA"; - case CommandID::SD_CARD_HIGH_WATERMARK: - return "SD_CARD_HIGH_WATERMARK"; - case CommandID::DETECT_SC_AES: - return "DETECT_SC_AES"; - case CommandID::NEW_AES_KEY: - return "NEW_AES_KEY"; - case CommandID::WRITE_TO_SLOT_2: - return "WRITE_TO_SLOT_2"; - case CommandID::SEND_OTP_DATA: - return "SEND_OTP_DATA"; - case CommandID::WINK: - return "WINK"; - } - return "UNKNOWN"; -} -} -} diff --git a/nitrokey-sys/libnitrokey-v3.5/device.cc b/nitrokey-sys/libnitrokey-v3.5/device.cc deleted file mode 100644 index bc42965..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/device.cc +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include -#include -#include -#include -#include -#include -#include -#include "hidapi/hidapi.h" -#include "libnitrokey/misc.h" -#include "libnitrokey/device.h" -#include "libnitrokey/log.h" -#include -#include "DeviceCommunicationExceptions.h" -#include "device.h" - -std::mutex mex_dev_com; - -using namespace nitrokey::device; -using namespace nitrokey::log; -using namespace nitrokey::misc; -using namespace std::chrono; - -const uint16_t nitrokey::device::NITROKEY_VID = 0x20a0; -const uint16_t nitrokey::device::NITROKEY_PRO_PID = 0x4108; -const uint16_t nitrokey::device::NITROKEY_STORAGE_PID = 0x4109; - -Option nitrokey::device::product_id_to_model(uint16_t product_id) { - switch (product_id) { - case NITROKEY_PRO_PID: - return DeviceModel::PRO; - case NITROKEY_STORAGE_PID: - return DeviceModel::STORAGE; - default: - return {}; - } -} - -std::atomic_int Device::instances_count{0}; -std::chrono::milliseconds Device::default_delay {0} ; - -std::ostream& nitrokey::device::operator<<(std::ostream& stream, DeviceModel model) { - switch (model) { - case DeviceModel::PRO: - stream << "Pro"; - break; - case DeviceModel::STORAGE: - stream << "Storage"; - break; - default: - stream << "Unknown"; - break; - } - return stream; -} - -Device::Device(const uint16_t vid, const uint16_t pid, const DeviceModel model, - const milliseconds send_receive_delay, const int retry_receiving_count, - const milliseconds retry_timeout) - : - last_command_status(0), - m_vid(vid), - m_pid(pid), - m_model(model), - m_retry_sending_count(1), - m_retry_receiving_count(retry_receiving_count), - m_retry_timeout(retry_timeout), - m_send_receive_delay(send_receive_delay), - mp_devhandle(nullptr) -{ - instances_count++; -} - -bool Device::disconnect() { - //called in object's destructor - LOG(__FUNCTION__, Loglevel::DEBUG_L2); - std::lock_guard lock(mex_dev_com); - return _disconnect(); -} - -bool Device::_disconnect() { - LOG(std::string(__FUNCTION__) + std::string(m_model == DeviceModel::PRO ? "PRO" : "STORAGE"), Loglevel::DEBUG_L2); - LOG(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); - - if(mp_devhandle == nullptr) { - LOG(std::string("Disconnection: handle already freed: ") + std::to_string(mp_devhandle == nullptr) + " ("+m_path+")", Loglevel::DEBUG_L1); - return false; - } - - hid_close(mp_devhandle); - mp_devhandle = nullptr; -#ifndef __APPLE__ - if (instances_count == 1){ - LOG(std::string("Calling hid_exit"), Loglevel::DEBUG_L2); - hid_exit(); - } -#endif - return true; -} - -bool Device::connect() { - LOG(__FUNCTION__, Loglevel::DEBUG_L2); - std::lock_guard lock(mex_dev_com); - return _connect(); -} - -bool Device::_connect() { - LOG(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); - -// hid_init(); // done automatically on hid_open - if (m_path.empty()){ - mp_devhandle = hid_open(m_vid, m_pid, nullptr); - } else { - mp_devhandle = hid_open_path(m_path.c_str()); - } - const bool success = mp_devhandle != nullptr; - LOG(std::string("Connection success: ") + std::to_string(success) + " ("+m_path+")", Loglevel::DEBUG_L1); - return success; -} - -void Device::set_path(const std::string path){ - m_path = path; -} - -int Device::send(const void *packet) { - LOG(__FUNCTION__, Loglevel::DEBUG_L2); - std::lock_guard lock(mex_dev_com); - LOG(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); - - int send_feature_report = -1; - - for (int i = 0; i < 3 && send_feature_report < 0; ++i) { - if (mp_devhandle == nullptr) { - LOG(std::string("Connection fail") , Loglevel::DEBUG_L2); - throw DeviceNotConnected("Attempted HID send on an invalid descriptor."); - } - send_feature_report = hid_send_feature_report( - mp_devhandle, (const unsigned char *)(packet), HID_REPORT_SIZE); - if (send_feature_report < 0) _reconnect(); - //add thread sleep? - LOG(std::string("Sending attempt: ")+std::to_string(i+1) + " / 3" , Loglevel::DEBUG_L2); - } - return send_feature_report; -} - -int Device::recv(void *packet) { - LOG(__FUNCTION__, Loglevel::DEBUG_L2); - std::lock_guard lock(mex_dev_com); - LOG(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); - int status; - int retry_count = 0; - - for (;;) { - if (mp_devhandle == nullptr){ - LOG(std::string("Connection fail") , Loglevel::DEBUG_L2); - throw DeviceNotConnected("Attempted HID receive on an invalid descriptor."); - } - - status = (hid_get_feature_report(mp_devhandle, (unsigned char *)(packet), - HID_REPORT_SIZE)); - - auto pwherr = hid_error(mp_devhandle); - std::wstring wherr = (pwherr != nullptr) ? pwherr : L"No error message"; - std::string herr(wherr.begin(), wherr.end()); - LOG(std::string("libhid error message: ") + herr, - Loglevel::DEBUG_L2); - - if (status > 0) break; // success - if (retry_count++ >= m_retry_receiving_count) { - LOG( - "Maximum retry count reached: " + std::to_string(retry_count), - Loglevel::WARNING); - LOG( - std::string("Counter stats: ") + m_counters.get_as_string(), - Loglevel::DEBUG); - break; - } - _reconnect(); - LOG("Retrying... " + std::to_string(retry_count), - Loglevel::DEBUG); - std::this_thread::sleep_for(m_retry_timeout); - } - - return status; -} - -std::vector Device::enumerate(){ - auto pInfo = hid_enumerate(NITROKEY_VID, 0); - auto pInfo_ = pInfo; - std::vector res; - while (pInfo != nullptr){ - auto deviceModel = product_id_to_model(pInfo->product_id); - if (deviceModel.has_value()) { - std::string path(pInfo->path); - std::wstring serialNumberW(pInfo->serial_number); - std::wstring_convert> converter; - std::string serialNumber = converter.to_bytes(serialNumberW); - DeviceInfo info = { deviceModel.value(), path, serialNumber }; - res.push_back(info); - } - pInfo = pInfo->next; - } - - if (pInfo_ != nullptr){ - hid_free_enumeration(pInfo_); - } - - return res; -} - -std::shared_ptr Device::create(DeviceModel model) { - switch (model) { - case DeviceModel::PRO: - return std::make_shared(); - case DeviceModel::STORAGE: - return std::make_shared(); - default: - return {}; - } -} - -bool Device::could_be_enumerated() { - LOG(__FUNCTION__, Loglevel::DEBUG_L2); - std::lock_guard lock(mex_dev_com); - if (mp_devhandle==nullptr){ - return false; - } -#ifndef __APPLE__ - auto pInfo = hid_enumerate(m_vid, m_pid); - if (pInfo != nullptr){ - hid_free_enumeration(pInfo); - return true; - } - return false; -#else -// alternative for OSX - unsigned char buf[1]; - return hid_read_timeout(mp_devhandle, buf, sizeof(buf), 20) != -1; -#endif -} - -void Device::show_stats() { - auto s = m_counters.get_as_string(); - LOG(s, Loglevel::DEBUG_L2); -} - -void Device::_reconnect() { - LOG(__FUNCTION__, Loglevel::DEBUG_L2); - ++m_counters.low_level_reconnect; - _disconnect(); - _connect(); -} - -Device::~Device() { - show_stats(); - disconnect(); - instances_count--; -} - -void Device::set_default_device_speed(int delay) { - default_delay = std::chrono::duration(delay); -} - - -void Device::set_receiving_delay(const std::chrono::milliseconds delay){ - std::lock_guard lock(mex_dev_com); - m_send_receive_delay = delay; -} - -void Device::set_retry_delay(const std::chrono::milliseconds delay){ - std::lock_guard lock(mex_dev_com); - m_retry_timeout = delay; -} - -Stick10::Stick10(): - Device(NITROKEY_VID, NITROKEY_PRO_PID, DeviceModel::PRO, 100ms, 5, 100ms) - { - setDefaultDelay(); - } - - -Stick20::Stick20(): - Device(NITROKEY_VID, NITROKEY_STORAGE_PID, DeviceModel::STORAGE, 40ms, 55, 40ms) - { - setDefaultDelay(); - } - -#include -#define p(x) ss << #x << " " << x << ", "; -std::string Device::ErrorCounters::get_as_string() { - std::stringstream ss; - p(total_comm_runs); - p(communication_successful); - ss << "("; - p(command_successful_recv); - p(command_result_not_equal_0_recv); - ss << "), "; - p(sends_executed); - p(recv_executed); - p(successful_storage_commands); - p(total_retries); - ss << "("; - p(busy); - p(busy_progressbar); - p(CRC_other_than_awaited); - p(wrong_CRC); - ss << "), "; - p(low_level_reconnect); - p(sending_error); - p(receiving_error); - return ss.str(); -} - -void Device::setDefaultDelay() { - LOG(__FUNCTION__, Loglevel::DEBUG_L2); - - auto count = default_delay.count(); - if (count != 0){ - LOG("Setting default delay to " + std::to_string(count), Loglevel::DEBUG_L2); - m_retry_timeout = default_delay; - m_send_receive_delay = default_delay; - } -} - -#undef p diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/CommandFailedException.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/CommandFailedException.h deleted file mode 100644 index 32bd6b7..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/CommandFailedException.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef LIBNITROKEY_COMMANDFAILEDEXCEPTION_H -#define LIBNITROKEY_COMMANDFAILEDEXCEPTION_H - -#include -#include -#include "log.h" -#include "command_id.h" - -using cs = nitrokey::proto::stick10::command_status; -using cs2 = nitrokey::proto::stick20::device_status; - -class CommandFailedException : public std::exception { -public: - const uint8_t last_command_id; - const uint8_t last_command_status; - - CommandFailedException(uint8_t last_command_id, uint8_t last_command_status) : - last_command_id(last_command_id), - last_command_status(last_command_status){ - LOG(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); - } - - virtual const char *what() const throw() { - return "Command execution has failed on device"; - } - - - bool reason_timestamp_warning() const throw(){ - return last_command_status == static_cast(cs::timestamp_warning); - } - - bool reason_AES_not_initialized() const throw(){ - return last_command_status == static_cast(cs::AES_dec_failed); - } - - bool reason_not_authorized() const throw(){ - return last_command_status == static_cast(cs::not_authorized); - } - - bool reason_slot_not_programmed() const throw(){ - return last_command_status == static_cast(cs::slot_not_programmed); - } - - bool reason_wrong_password() const throw(){ - return last_command_status == static_cast(cs::wrong_password); - } - - bool reason_smartcard_busy() const throw(){ - return last_command_status == static_cast(cs2::smartcard_error); - } - -}; - - -#endif //LIBNITROKEY_COMMANDFAILEDEXCEPTION_H diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/DeviceCommunicationExceptions.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/DeviceCommunicationExceptions.h deleted file mode 100644 index f710d0b..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/DeviceCommunicationExceptions.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - - -#ifndef LIBNITROKEY_DEVICECOMMUNICATIONEXCEPTIONS_H -#define LIBNITROKEY_DEVICECOMMUNICATIONEXCEPTIONS_H - -#include -#include -#include -#include - - -class DeviceCommunicationException: public std::runtime_error -{ - std::string message; - static std::atomic_int occurred; -public: - DeviceCommunicationException(std::string _msg): std::runtime_error(_msg), message(_msg){ - ++occurred; - } - uint8_t getType() const {return 1;}; -// virtual const char* what() const throw() override { -// return message.c_str(); -// } - static bool has_occurred(){ return occurred > 0; }; - static void reset_occurred_flag(){ occurred = 0; }; -}; - -class DeviceNotConnected: public DeviceCommunicationException { -public: - DeviceNotConnected(std::string msg) : DeviceCommunicationException(msg){} - uint8_t getType() const {return 2;}; -}; - -class DeviceSendingFailure: public DeviceCommunicationException { -public: - DeviceSendingFailure(std::string msg) : DeviceCommunicationException(msg){} - uint8_t getType() const {return 3;}; -}; - -class DeviceReceivingFailure: public DeviceCommunicationException { -public: - DeviceReceivingFailure(std::string msg) : DeviceCommunicationException(msg){} - uint8_t getType() const {return 4;}; -}; - -class InvalidCRCReceived: public DeviceReceivingFailure { -public: - InvalidCRCReceived(std::string msg) : DeviceReceivingFailure(msg){} - uint8_t getType() const {return 5;}; -}; - - -#endif //LIBNITROKEY_DEVICECOMMUNICATIONEXCEPTIONS_H diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/LibraryException.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/LibraryException.h deleted file mode 100644 index 3b9d177..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/LibraryException.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef LIBNITROKEY_LIBRARYEXCEPTION_H -#define LIBNITROKEY_LIBRARYEXCEPTION_H - -#include -#include -#include -#include "log.h" - -class LibraryException: std::exception { -public: - virtual uint8_t exception_id()= 0; -}; - -class TargetBufferSmallerThanSource: public LibraryException { -public: - virtual uint8_t exception_id() override { - return 203; - } - -public: - size_t source_size; - size_t target_size; - - TargetBufferSmallerThanSource( - size_t source_size, size_t target_size - ) : source_size(source_size), target_size(target_size) {} - - virtual const char *what() const throw() override { - std::string s = " "; - auto ts = [](size_t x){ return std::to_string(x); }; - std::string msg = std::string("Target buffer size is smaller than source: [source size, buffer size]") - +s+ ts(source_size) +s+ ts(target_size); - return msg.c_str(); - } - -}; - -class InvalidHexString : public LibraryException { -public: - virtual uint8_t exception_id() override { - return 202; - } - -public: - uint8_t invalid_char; - - InvalidHexString (uint8_t invalid_char) : invalid_char( invalid_char) {} - - virtual const char *what() const throw() override { - return "Invalid character in hex string"; - } - -}; - -class InvalidSlotException : public LibraryException { -public: - virtual uint8_t exception_id() override { - return 201; - } - -public: - uint8_t slot_selected; - - InvalidSlotException(uint8_t slot_selected) : slot_selected(slot_selected) {} - - virtual const char *what() const throw() override { - return "Wrong slot selected"; - } - -}; - - - -class TooLongStringException : public LibraryException { -public: - virtual uint8_t exception_id() override { - return 200; - } - - std::size_t size_source; - std::size_t size_destination; - std::string message; - - TooLongStringException(size_t size_source, size_t size_destination, const std::string &message = "") : size_source( - size_source), size_destination(size_destination), message(message) { - LOG(std::string("TooLongStringException, size diff: ")+ std::to_string(size_source-size_destination), nitrokey::log::Loglevel::DEBUG); - - } - - virtual const char *what() const throw() override { - //TODO add sizes and message data to final message - return "Too long string has been supplied as an argument"; - } - -}; - -#endif //LIBNITROKEY_LIBRARYEXCEPTION_H diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/LongOperationInProgressException.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/LongOperationInProgressException.h deleted file mode 100644 index 865d6b5..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/LongOperationInProgressException.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef LIBNITROKEY_LONGOPERATIONINPROGRESSEXCEPTION_H -#define LIBNITROKEY_LONGOPERATIONINPROGRESSEXCEPTION_H - -#include "CommandFailedException.h" - -class LongOperationInProgressException : public CommandFailedException { - -public: - unsigned char progress_bar_value; - - LongOperationInProgressException( - unsigned char _command_id, uint8_t last_command_status, unsigned char _progress_bar_value) - : CommandFailedException(_command_id, last_command_status), progress_bar_value(_progress_bar_value){ - LOG( - std::string("LongOperationInProgressException, progress bar status: ")+ - std::to_string(progress_bar_value), nitrokey::log::Loglevel::DEBUG); - } - virtual const char *what() const throw() { - return "Device returned busy status with long operation in progress"; - } -}; - - -#endif //LIBNITROKEY_LONGOPERATIONINPROGRESSEXCEPTION_H diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/NitrokeyManager.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/NitrokeyManager.h deleted file mode 100644 index 33ede1b..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/NitrokeyManager.h +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef LIBNITROKEY_NITROKEYMANAGER_H -#define LIBNITROKEY_NITROKEYMANAGER_H - -#include "device.h" -#include "log.h" -#include "device_proto.h" -#include "stick10_commands.h" -#include "stick10_commands_0.8.h" -#include "stick20_commands.h" -#include -#include -#include - -namespace nitrokey { - using namespace nitrokey::device; - using namespace std; - using namespace nitrokey::proto::stick10; - using namespace nitrokey::proto::stick20; - using namespace nitrokey::proto; - using namespace nitrokey::log; - - -#ifdef __WIN32 -char * strndup(const char* str, size_t maxlen); -#endif - - class NitrokeyManager { - public: - static shared_ptr instance(); - - bool first_authenticate(const char *pin, const char *temporary_password); - bool write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password); - bool write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password); - string get_HOTP_code(uint8_t slot_number, const char *user_temporary_password); - string get_TOTP_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, - uint8_t last_interval, - const char *user_temporary_password); - string get_TOTP_code(uint8_t slot_number, const char *user_temporary_password); - stick10::ReadSlot::ResponsePayload get_TOTP_slot_data(const uint8_t slot_number); - stick10::ReadSlot::ResponsePayload get_HOTP_slot_data(const uint8_t slot_number); - - bool set_time(uint64_t time); - /** - * Set the device time used for TOTP to the given time. Contrary to - * {@code set_time(uint64_t)}, this command fails if {@code old_time} - * > {@code time} or if {@code old_time} is zero (where {@code - * old_time} is the current time on the device). - * - * @param time new device time as Unix timestamp (seconds since - * 1970-01-01) - */ - void set_time_soft(uint64_t time); - - [[deprecated("get_time is deprecated -- use set_time_soft instead")]] - bool get_time(uint64_t time = 0); - bool erase_totp_slot(uint8_t slot_number, const char *temporary_password); - bool erase_hotp_slot(uint8_t slot_number, const char *temporary_password); - std::vector list_devices(); - std::vector list_devices_by_cpuID(); - - /** - * Connect to the device using unique smartcard:datacard id. - * Needs list_device_by_cpuID() run first - * @param id Current ID of the target device - * @return true on success, false on failure - */ - bool connect_with_ID(const std::string id); - bool connect_with_path (std::string path); - bool connect(const char *device_model); - bool connect(device::DeviceModel device_model); - bool connect(); - bool disconnect(); - bool is_connected() throw() ; - bool could_current_device_be_enumerated(); - bool set_default_commands_delay(int delay); - - DeviceModel get_connected_device_model() const; - void set_debug(bool state); - stick10::GetStatus::ResponsePayload get_status(); - string get_status_as_string(); - string get_serial_number(); - - char * get_totp_slot_name(uint8_t slot_number); - char * get_hotp_slot_name(uint8_t slot_number); - - void change_user_PIN(const char *current_PIN, const char *new_PIN); - void change_admin_PIN(const char *current_PIN, const char *new_PIN); - - void enable_password_safe(const char *user_pin); - - vector get_password_safe_slot_status(); - - uint8_t get_admin_retry_count(); - uint8_t get_user_retry_count(); - - void lock_device(); - - char * get_password_safe_slot_name(uint8_t slot_number); - char * get_password_safe_slot_password(uint8_t slot_number); - char * get_password_safe_slot_login(uint8_t slot_number); - - void - write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, - const char *slot_password); - - void erase_password_safe_slot(uint8_t slot_number); - - void user_authenticate(const char *user_password, const char *temporary_password); - - void factory_reset(const char *admin_password); - - void build_aes_key(const char *admin_password); - - void unlock_user_password(const char *admin_password, const char *new_user_password); - - void write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password, - bool delete_user_password, const char *admin_temporary_password); - - vector read_config(); - - bool is_AES_supported(const char *user_password); - - void unlock_encrypted_volume(const char *user_password); - void lock_encrypted_volume(); - - void unlock_hidden_volume(const char *hidden_volume_password); - void lock_hidden_volume(); - - /** - * Sets unencrypted volume read-only. - * Works until v0.48 (incl. v0.50), where User PIN was sufficient - * Does nothing otherwise. - * @param user_pin User PIN - */ - void set_unencrypted_read_only(const char *user_pin); - - /** - * Sets unencrypted volume read-only. - * Works from v0.49 (except v0.50) accepts Admin PIN - * Does nothing otherwise. - * @param admin_pin Admin PIN - */ - void set_unencrypted_read_only_admin(const char *admin_pin); - - /** - * Sets unencrypted volume read-write. - * Works until v0.48 (incl. v0.50), where User PIN was sufficient - * Does nothing otherwise. - * @param user_pin User PIN - */ - void set_unencrypted_read_write(const char *user_pin); - - /** - * Sets unencrypted volume read-write. - * Works from v0.49 (except v0.50) accepts Admin PIN - * Does nothing otherwise. - * @param admin_pin Admin PIN - */ - void set_unencrypted_read_write_admin(const char *admin_pin); - - void export_firmware(const char *admin_pin); - void enable_firmware_update(const char *firmware_pin); - - void clear_new_sd_card_warning(const char *admin_pin); - - void fill_SD_card_with_random_data(const char *admin_pin); - - uint8_t get_SD_card_size(); - - void change_update_password(const char *current_update_password, const char *new_update_password); - - void create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, - const char *hidden_volume_password); - - void send_startup(uint64_t seconds_from_epoch); - - char * get_status_storage_as_string(); - stick20::DeviceConfigurationResponsePacket::ResponsePayload get_status_storage(); - - char * get_SD_usage_data_as_string(); - std::pair get_SD_usage_data(); - - - int get_progress_bar_value(); - - ~NitrokeyManager(); - bool is_authorization_command_supported(); - bool is_320_OTP_secret_supported(); - - - template - void authorize_packet(T &package, const char *admin_temporary_password, shared_ptr device); - uint8_t get_minor_firmware_version(); - - explicit NitrokeyManager(); - void set_log_function(std::function log_function); - private: - - static shared_ptr _instance; - std::shared_ptr device; - std::string current_device_id; - public: - const string get_current_device_id() const; - - private: - std::unordered_map > connected_devices; - std::unordered_map > connected_devices_byID; - - - stick10::ReadSlot::ResponsePayload get_OTP_slot_data(const uint8_t slot_number); - bool is_valid_hotp_slot_number(uint8_t slot_number) const; - bool is_valid_totp_slot_number(uint8_t slot_number) const; - bool is_valid_password_safe_slot_number(uint8_t slot_number) const; - uint8_t get_internal_slot_number_for_hotp(uint8_t slot_number) const; - uint8_t get_internal_slot_number_for_totp(uint8_t slot_number) const; - bool erase_slot(uint8_t slot_number, const char *temporary_password); - char * get_slot_name(uint8_t slot_number); - - template - void change_PIN_general(const char *current_PIN, const char *new_PIN); - - void write_HOTP_slot_authorize(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password); - - void write_TOTP_slot_authorize(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password); - - void write_OTP_slot_no_authorize(uint8_t internal_slot_number, const char *slot_name, const char *secret, - uint64_t counter_or_interval, - bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, - const char *temporary_password) const; - bool _disconnect_no_lock(); - - public: - bool set_current_device_speed(int retry_delay, int send_receive_delay); - void set_loglevel(Loglevel loglevel); - - void set_loglevel(int loglevel); - - /** - * Sets encrypted volume read-only. - * Supported from future versions of Storage. - * @param admin_pin Admin PIN - */ - void set_encrypted_volume_read_only(const char *admin_pin); - - /** - * Sets encrypted volume read-write. - * Supported from future versions of Storage. - * @param admin_pin Admin PIN - */ - void set_encrypted_volume_read_write(const char *admin_pin); - - uint8_t get_major_firmware_version(); - - bool is_smartcard_in_use(); - - /** - * Function to determine unencrypted volume PIN type - * @param minor_firmware_version - * @return Returns true, if set unencrypted volume ro/rw pin type is User, false otherwise. - */ - bool set_unencrypted_volume_rorw_pin_type_user(); - - /** - * Blink red and green LED alternatively and infinitely (until device is reconnected). - */ - void wink(); - - stick20::ProductionTest::ResponsePayload production_info(); - - void enable_firmware_update_pro(const char *firmware_pin); - - void change_firmware_update_password_pro(const char *firmware_pin_current, const char *firmware_pin_new); - bool is_internal_hotp_slot_number(uint8_t slot_number) const; - }; -} - - - -#endif //LIBNITROKEY_NITROKEYMANAGER_H diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/command.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/command.h deleted file mode 100644 index 6852bf0..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/command.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef COMMAND_H -#define COMMAND_H -#include -#include "command_id.h" -#include "cxx_semantics.h" - -#define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); -#ifdef LOG_VOLATILE_DATA -#define print_to_ss_volatile(x) print_to_ss(x); -#else -#define print_to_ss_volatile(x) ( ss << " " << (#x) <<":\t" << "***********" << std::endl ); -#endif -#define hexdump_to_ss(x) (ss << #x":\n"\ - << ::nitrokey::misc::hexdump((const uint8_t *) (&x), sizeof x, false)); - -namespace nitrokey { - namespace proto { - - template - class Command : semantics::non_constructible { - public: - constexpr static CommandID command_id() { return cmd_id; } - - template - std::string dissect(const T &) { - return std::string("Payload dissection is unavailable"); - } - }; - -namespace stick20{ - enum class PasswordKind : uint8_t { - User = 'P', - Admin = 'A', - AdminPrefixed - }; - - template - class PasswordCommand : public Command { - constexpr static CommandID _command_id() { return cmd_id; } - public: - struct CommandPayload { - uint8_t kind; - uint8_t password[password_length]; - - std::string dissect() const { - std::stringstream ss; - print_to_ss( kind ); - print_to_ss_volatile(password); - return ss.str(); - } - void set_kind_admin() { - kind = (uint8_t) 'A'; - } - void set_kind_admin_prefixed() { - kind = (uint8_t) 'P'; - } - void set_kind_user() { - kind = (uint8_t) 'P'; - } - - void set_defaults(){ - set_kind(Tpassword_kind); - } - - void set_kind(PasswordKind password_kind){ - switch (password_kind){ - case PasswordKind::Admin: - set_kind_admin(); - break; - case PasswordKind::User: - set_kind_user(); - break; - case PasswordKind::AdminPrefixed: - set_kind_admin_prefixed(); - break; - } - }; - - } __packed; - - //typedef Transaction::command_id(), struct CommandPayload, struct EmptyPayload> - // CommandTransaction; - using CommandTransaction = Transaction; - //using CommandTransaction = Transaction<_command_id(), CommandPayload, EmptyPayload>; - - }; - } - } -} - -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/command_id.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/command_id.h deleted file mode 100644 index ee6726c..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/command_id.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef COMMAND_ID_H -#define COMMAND_ID_H -#include - -namespace nitrokey { -namespace proto { - namespace stick20 { - enum class device_status : uint8_t { - idle = 0, - ok, - busy, - wrong_password, - busy_progressbar, - password_matrix_ready, - no_user_password_unlock, // FIXME: translate on receive to command status error (fix in firmware?) - smartcard_error, - security_bit_active - }; - const int CMD_START_VALUE = 0x20; - const int CMD_END_VALUE = 0x60; - } - namespace stick10 { - enum class command_status : uint8_t { - ok = 0, - wrong_CRC, - wrong_slot, - slot_not_programmed, - wrong_password = 4, - not_authorized, - timestamp_warning, - no_name_error, - not_supported, - unknown_command, - AES_dec_failed - }; - enum class device_status : uint8_t { - ok = 0, - busy = 1, - error, - received_report, - }; - } - - -enum class CommandID : uint8_t { - GET_STATUS = 0x00, - WRITE_TO_SLOT = 0x01, - READ_SLOT_NAME = 0x02, - READ_SLOT = 0x03, - GET_CODE = 0x04, - WRITE_CONFIG = 0x05, - ERASE_SLOT = 0x06, - FIRST_AUTHENTICATE = 0x07, - AUTHORIZE = 0x08, - GET_PASSWORD_RETRY_COUNT = 0x09, - CLEAR_WARNING = 0x0A, - SET_TIME = 0x0B, - TEST_COUNTER = 0x0C, - TEST_TIME = 0x0D, - USER_AUTHENTICATE = 0x0E, - GET_USER_PASSWORD_RETRY_COUNT = 0x0F, - USER_AUTHORIZE = 0x10, - UNLOCK_USER_PASSWORD = 0x11, - LOCK_DEVICE = 0x12, - FACTORY_RESET = 0x13, - CHANGE_USER_PIN = 0x14, - CHANGE_ADMIN_PIN = 0x15, - WRITE_TO_SLOT_2 = 0x16, - SEND_OTP_DATA = 0x17, - FIRMWARE_UPDATE = 0x19, - FIRMWARE_PASSWORD_CHANGE = 0x1A, - - ENABLE_CRYPTED_PARI = 0x20, - DISABLE_CRYPTED_PARI = 0x20 + 1, - ENABLE_HIDDEN_CRYPTED_PARI = 0x20 + 2, - DISABLE_HIDDEN_CRYPTED_PARI = 0x20 + 3, - ENABLE_FIRMWARE_UPDATE = 0x20 + 4, //enables update mode - EXPORT_FIRMWARE_TO_FILE = 0x20 + 5, - GENERATE_NEW_KEYS = 0x20 + 6, - FILL_SD_CARD_WITH_RANDOM_CHARS = 0x20 + 7, - - WRITE_STATUS_DATA = 0x20 + 8, //@unused - ENABLE_READONLY_UNCRYPTED_LUN = 0x20 + 9, - ENABLE_READWRITE_UNCRYPTED_LUN = 0x20 + 10, - - SEND_PASSWORD_MATRIX = 0x20 + 11, //@unused - SEND_PASSWORD_MATRIX_PINDATA = 0x20 + 12, //@unused - SEND_PASSWORD_MATRIX_SETUP = 0x20 + 13, //@unused - - GET_DEVICE_STATUS = 0x20 + 14, - SEND_DEVICE_STATUS = 0x20 + 15, - - SEND_HIDDEN_VOLUME_PASSWORD = 0x20 + 16, //@unused - SEND_HIDDEN_VOLUME_SETUP = 0x20 + 17, - SEND_PASSWORD = 0x20 + 18, - SEND_NEW_PASSWORD = 0x20 + 19, - CLEAR_NEW_SD_CARD_FOUND = 0x20 + 20, - - SEND_STARTUP = 0x20 + 21, - SEND_CLEAR_STICK_KEYS_NOT_INITIATED = 0x20 + 22, - SEND_LOCK_STICK_HARDWARE = 0x20 + 23, //locks firmware upgrade - - PRODUCTION_TEST = 0x20 + 24, - SEND_DEBUG_DATA = 0x20 + 25, //@unused - - CHANGE_UPDATE_PIN = 0x20 + 26, - - //added in v0.48.5 - ENABLE_ADMIN_READONLY_UNCRYPTED_LUN = 0x20 + 28, - ENABLE_ADMIN_READWRITE_UNCRYPTED_LUN = 0x20 + 29, - ENABLE_ADMIN_READONLY_ENCRYPTED_LUN = 0x20 + 30, - ENABLE_ADMIN_READWRITE_ENCRYPTED_LUN = 0x20 + 31, - CHECK_SMARTCARD_USAGE = 0x20 + 32, - //v0.52+ - WINK = 0x20 + 33, - - GET_PW_SAFE_SLOT_STATUS = 0x60, - GET_PW_SAFE_SLOT_NAME = 0x61, - GET_PW_SAFE_SLOT_PASSWORD = 0x62, - GET_PW_SAFE_SLOT_LOGINNAME = 0x63, - SET_PW_SAFE_SLOT_DATA_1 = 0x64, - SET_PW_SAFE_SLOT_DATA_2 = 0x65, - PW_SAFE_ERASE_SLOT = 0x66, - PW_SAFE_ENABLE = 0x67, - PW_SAFE_INIT_KEY = 0x68, //@unused - PW_SAFE_SEND_DATA = 0x69, //@unused - SD_CARD_HIGH_WATERMARK = 0x70, - DETECT_SC_AES = 0x6a, - NEW_AES_KEY = 0x6b -}; - -const char *commandid_to_string(CommandID id); -} -} -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/cxx_semantics.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/cxx_semantics.h deleted file mode 100644 index 36ed142..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/cxx_semantics.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef CXX_SEMANTICS_H -#define CXX_SEMANTICS_H - -#ifndef _MSC_VER -#define __packed __attribute__((__packed__)) -#else -#define __packed -#endif - -#ifdef _MSC_VER -#define strdup _strdup -#endif - -/* - * There's no need to include Boost for a simple subset this project needs. - */ -namespace semantics { -class non_constructible { - non_constructible() {} -}; -} - -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/deprecated.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/deprecated.h deleted file mode 100644 index 5a83288..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/deprecated.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - - -#ifndef LIBNITROKEY_DEPRECATED_H -#define LIBNITROKEY_DEPRECATED_H - -#if defined(__GNUC__) || defined(__clang__) -#define DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) -#define DEPRECATED __declspec(deprecated) -#else -#pragma message("WARNING: DEPRECATED macro is not defined for this compiler") -#define DEPRECATED -#endif - -#endif //LIBNITROKEY_DEPRECATED_H diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/device.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/device.h deleted file mode 100644 index d50080d..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/device.h +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef DEVICE_H -#define DEVICE_H -#include -#include "hidapi/hidapi.h" -#include -#include -#include -#include -#include -#include "misc.h" - -#define HID_REPORT_SIZE 65 - -#include - -namespace nitrokey { -namespace device { - using namespace std::chrono_literals; - using std::chrono::milliseconds; - - struct EnumClassHash - { - template - std::size_t operator()(T t) const - { - return static_cast(t); - } - }; - -enum class DeviceModel{ - PRO, - STORAGE -}; - -std::ostream& operator<<(std::ostream& stream, DeviceModel model); - -/** - * The USB vendor ID for Nitrokey devices. - */ -extern const uint16_t NITROKEY_VID; -/** - * The USB product ID for the Nitrokey Pro. - */ -extern const uint16_t NITROKEY_PRO_PID; -/** - * The USB product ID for the Nitrokey Storage. - */ -extern const uint16_t NITROKEY_STORAGE_PID; - -/** - * Convert the given USB product ID to a Nitrokey model. If there is no model - * with that ID, return an absent value. - */ -misc::Option product_id_to_model(uint16_t product_id); - -/** - * Information about a connected device. - * - * This struct contains the information about a connected device returned by - * hidapi when enumerating the connected devices. - */ -struct DeviceInfo { - /** - * The model of the connected device. - */ - DeviceModel m_deviceModel; - /** - * The USB connection path for the device. - */ - std::string m_path; - /** - * The serial number of the device. - */ - std::string m_serialNumber; -}; - -#include - -class Device { - -public: - - struct ErrorCounters{ - using cnt = std::atomic_int; - cnt wrong_CRC; - cnt CRC_other_than_awaited; - cnt busy; - cnt total_retries; - cnt sending_error; - cnt receiving_error; - cnt total_comm_runs; - cnt successful_storage_commands; - cnt command_successful_recv; - cnt recv_executed; - cnt sends_executed; - cnt busy_progressbar; - cnt command_result_not_equal_0_recv; - cnt communication_successful; - cnt low_level_reconnect; - std::string get_as_string(); - - } m_counters = {}; - - - Device(const uint16_t vid, const uint16_t pid, const DeviceModel model, - const milliseconds send_receive_delay, const int retry_receiving_count, - const milliseconds retry_timeout); - - virtual ~Device(); - - // lack of device is not actually an error, - // so it doesn't throw - virtual bool connect(); - virtual bool disconnect(); - - /* - * Sends packet of HID_REPORT_SIZE. - */ - virtual int send(const void *packet); - - /* - * Gets packet of HID_REPORT_SIZE. - * Can sleep. See below. - */ - virtual int recv(void *packet); - - /*** - * Returns true if some device is visible by OS with given VID and PID - * whether the device is connected through HID API or not. - * @return true if visible by OS - */ - bool could_be_enumerated(); - /** - * Returns a vector with all connected Nitrokey devices. - * - * @return information about all connected devices - */ - static std::vector enumerate(); - - /** - * Create a Device of the given model. - */ - static std::shared_ptr create(DeviceModel model); - - - void show_stats(); -// ErrorCounters get_stats(){ return m_counters; } - int get_retry_receiving_count() const { return m_retry_receiving_count; }; - int get_retry_sending_count() const { return m_retry_sending_count; }; - std::chrono::milliseconds get_retry_timeout() const { return m_retry_timeout; }; - std::chrono::milliseconds get_send_receive_delay() const {return m_send_receive_delay;} - - int get_last_command_status() {int a = std::atomic_exchange(&last_command_status, static_cast(0)); return a;}; - void set_last_command_status(uint8_t _err) { last_command_status = _err;} ; - bool last_command_sucessfull() const {return last_command_status == 0;}; - DeviceModel get_device_model() const {return m_model;} - void set_receiving_delay(std::chrono::milliseconds delay); - void set_retry_delay(std::chrono::milliseconds delay); - static void set_default_device_speed(int delay); - void setDefaultDelay(); - void set_path(const std::string path); - - - private: - std::atomic last_command_status; - void _reconnect(); - bool _connect(); - bool _disconnect(); - -protected: - const uint16_t m_vid; - const uint16_t m_pid; - const DeviceModel m_model; - - /* - * While the project uses Signal11 portable HIDAPI - * library, there's no way of doing it asynchronously, - * hence polling. - */ - const int m_retry_sending_count; - const int m_retry_receiving_count; - std::chrono::milliseconds m_retry_timeout; - std::chrono::milliseconds m_send_receive_delay; - std::atomicmp_devhandle; - std::string m_path; - - static std::atomic_int instances_count; - static std::chrono::milliseconds default_delay ; -}; - -class Stick10 : public Device { - public: - Stick10(); - -}; - -class Stick20 : public Device { - public: - Stick20(); -}; -} -} -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/device_proto.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/device_proto.h deleted file mode 100644 index 45a6c16..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/device_proto.h +++ /dev/null @@ -1,491 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef DEVICE_PROTO_H -#define DEVICE_PROTO_H - -#include -#include -#include -#include -#include -// a local version for compatibility with Windows -#include -#include "cxx_semantics.h" -#include "device.h" -#include "misc.h" -#include "log.h" -#include "command_id.h" -#include "dissect.h" -#include "CommandFailedException.h" -#include "LongOperationInProgressException.h" - -#define STICK20_UPDATE_MODE_VID 0x03EB -#define STICK20_UPDATE_MODE_PID 0x2FF1 - -#define PAYLOAD_SIZE 53 -#define PWS_SLOT_COUNT 16 -#define PWS_SLOTNAME_LENGTH 11 -#define PWS_PASSWORD_LENGTH 20 -#define PWS_LOGINNAME_LENGTH 32 - -#define PWS_SEND_PASSWORD 0 -#define PWS_SEND_LOGINNAME 1 -#define PWS_SEND_TAB 2 -#define PWS_SEND_CR 3 - -#include -#include "DeviceCommunicationExceptions.h" -#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) - -namespace nitrokey { - namespace proto { - extern std::mutex send_receive_mtx; - - -/* - * POD types for HID proto commands - * Instances are meant to be __packed. - * - * TODO (future) support for Big Endian - */ -#pragma pack (push,1) -/* - * Every packet is a USB HID report (check USB spec) - */ - template - struct HIDReport { - uint8_t _zero; - CommandID command_id; // uint8_t - union { - uint8_t _padding[HID_REPORT_SIZE - 6]; - Payload payload; - } __packed; - uint32_t crc; - - // POD types can't have non-default constructors - // used in Transaction<>::run() - void initialize() { - bzero(this, sizeof *this); - command_id = cmd_id; - } - - uint32_t calculate_CRC() const { - // w/o leading zero, a part of each HID packet - // w/o 4-byte crc - return misc::stm_crc32((const uint8_t *) (this) + 1, - (size_t) (HID_REPORT_SIZE - 5)); - } - - void update_CRC() { crc = calculate_CRC(); } - - bool isCRCcorrect() const { return crc == calculate_CRC(); } - - bool isValid() const { - return true; - // return !_zero && payload.isValid() && isCRCcorrect(); - } - - operator std::string() const { - // Packet type is known upfront in normal operation. - // Can't be used to dissect random packets. - return QueryDissector::dissect(*this); - } - } __packed; - -/* - * Response payload (the parametrized type inside struct HIDReport) - * - * command_id member in incoming HIDReport structure carries the command - * type last used. - */ - namespace DeviceResponseConstants{ - //magic numbers from firmware - static constexpr auto storage_status_absolute_address = 21; - static constexpr auto storage_data_absolute_address = storage_status_absolute_address + 5; - static constexpr auto header_size = 8; //from _zero to last_command_status inclusive - static constexpr auto footer_size = 4; //crc - static constexpr auto wrapping_size = header_size + footer_size; - } - - template - struct DeviceResponse { - static constexpr auto storage_status_padding_size = - DeviceResponseConstants::storage_status_absolute_address - DeviceResponseConstants::header_size; - - uint8_t _zero; - uint8_t device_status; - uint8_t command_id; // originally last_command_type - uint32_t last_command_crc; - uint8_t last_command_status; - - union { - uint8_t _padding[HID_REPORT_SIZE - DeviceResponseConstants::wrapping_size]; - ResponsePayload payload; - struct { - uint8_t _storage_status_padding[storage_status_padding_size]; - uint8_t command_counter; - uint8_t command_id; - uint8_t device_status; //@see stick20::device_status - uint8_t progress_bar_value; - } __packed storage_status; - } __packed; - - uint32_t crc; - - void initialize() { bzero(this, sizeof *this); } - - uint32_t calculate_CRC() const { - // w/o leading zero, a part of each HID packet - // w/o 4-byte crc - return misc::stm_crc32((const uint8_t *) (this) + 1, - (size_t) (HID_REPORT_SIZE - 5)); - } - - void update_CRC() { crc = calculate_CRC(); } - bool isCRCcorrect() const { return crc == calculate_CRC(); } - bool isValid() const { - // return !_zero && payload.isValid() && isCRCcorrect() && - // command_id == (uint8_t)(cmd_id); - return crc != 0; - } - - operator std::string() const { - return ResponseDissector::dissect(*this); - } - } __packed; - - struct EmptyPayload { - bool isValid() const { return true; } - - std::string dissect() const { return std::string("Empty Payload."); } - } __packed; - - template - class ClearingProxy { - public: - ClearingProxy(command_packet &p) { - packet = p; - bzero(&p, sizeof(p)); - } - - ~ClearingProxy() { - bzero(&packet, sizeof(packet)); - } - - response_payload &data() { - return packet.payload; - } - - command_packet packet; - }; - - template - class Transaction : semantics::non_constructible { - public: - // Types declared in command class scope can't be reached from there. - typedef command_payload CommandPayload; - typedef response_payload ResponsePayload; - - - typedef struct HIDReport OutgoingPacket; - typedef struct DeviceResponse ResponsePacket; -#pragma pack (pop) - - static_assert(std::is_pod::value, - "outgoingpacket must be a pod type"); - static_assert(std::is_pod::value, - "ResponsePacket must be a POD type"); - static_assert(sizeof(OutgoingPacket) == HID_REPORT_SIZE, - "OutgoingPacket type is not the right size"); - static_assert(sizeof(ResponsePacket) == HID_REPORT_SIZE, - "ResponsePacket type is not the right size"); - - static uint32_t getCRC( - const command_payload &payload) { - OutgoingPacket outp; - outp.initialize(); - outp.payload = payload; - outp.update_CRC(); - return outp.crc; - } - - template - static void clear_packet(T &st) { - bzero(&st, sizeof(st)); - } - - static ClearingProxy run(std::shared_ptr dev, - const command_payload &payload) { - using namespace ::nitrokey::device; - using namespace ::nitrokey::log; - using namespace std::chrono_literals; - - std::lock_guard guard(send_receive_mtx); - - LOG(__FUNCTION__, Loglevel::DEBUG_L2); - - if (dev == nullptr){ - LOG(std::string("Throw: Device not initialized"), Loglevel::DEBUG_L1); - throw DeviceNotConnected("Device not initialized"); - } - dev->m_counters.total_comm_runs++; - - int status; - OutgoingPacket outp; - ResponsePacket resp; - - // POD types can't have non-default constructors - outp.initialize(); - resp.initialize(); - - outp.payload = payload; - outp.update_CRC(); - - LOG("-------------------", Loglevel::DEBUG); - LOG("Outgoing HID packet:", Loglevel::DEBUG); - LOG(static_cast(outp), Loglevel::DEBUG); - LOG(std::string("=> ") + std::string(commandid_to_string(static_cast(outp.command_id))), Loglevel::DEBUG_L1); - - - if (!outp.isValid()) { - LOG(std::string("Throw: Invalid outgoing packet"), Loglevel::DEBUG_L1); - throw DeviceSendingFailure("Invalid outgoing packet"); - } - - bool successful_communication = false; - int receiving_retry_counter = 0; - int sending_retry_counter = dev->get_retry_sending_count(); - while (sending_retry_counter-- > 0) { - dev->m_counters.sends_executed++; - status = dev->send(&outp); - if (status <= 0){ - //FIXME early disconnection not yet working properly -// LOG("Encountered communication error, disconnecting device", Loglevel::DEBUG_L2); -// dev->disconnect(); - dev->m_counters.sending_error++; - LOG(std::string("Throw: Device error while sending command "), Loglevel::DEBUG_L1); - throw DeviceSendingFailure( - std::string("Device error while sending command ") + - std::to_string(status)); - } - - std::this_thread::sleep_for(dev->get_send_receive_delay()); - - // FIXME make checks done in device:recv here - receiving_retry_counter = dev->get_retry_receiving_count(); - int busy_counter = 0; - auto retry_timeout = dev->get_retry_timeout(); - while (receiving_retry_counter-- > 0) { - dev->m_counters.recv_executed++; - status = dev->recv(&resp); - - if (dev->get_device_model() == DeviceModel::STORAGE && - resp.command_id >= stick20::CMD_START_VALUE && - resp.command_id < stick20::CMD_END_VALUE ) { - LOG(std::string("Detected storage device cmd, status: ") + - std::to_string(resp.storage_status.device_status), Loglevel::DEBUG_L2); - - resp.last_command_status = static_cast(stick10::command_status::ok); - switch (static_cast(resp.storage_status.device_status)) { - case stick20::device_status::idle : - case stick20::device_status::ok: - resp.device_status = static_cast(stick10::device_status::ok); - break; - case stick20::device_status::busy: - case stick20::device_status::busy_progressbar: //TODO this will be modified later for getting progressbar status - resp.device_status = static_cast(stick10::device_status::busy); - break; - case stick20::device_status::wrong_password: - resp.last_command_status = static_cast(stick10::command_status::wrong_password); - resp.device_status = static_cast(stick10::device_status::ok); - break; - case stick20::device_status::no_user_password_unlock: - resp.last_command_status = static_cast(stick10::command_status::AES_dec_failed); - resp.device_status = static_cast(stick10::device_status::ok); - break; - default: - LOG(std::string("Unknown storage device status, cannot translate: ") + - std::to_string(resp.storage_status.device_status), Loglevel::DEBUG); - resp.device_status = resp.storage_status.device_status; - break; - }; - } - - //Some of the commands return wrong CRC, for now skip checking it (TODO list and report) - //if (resp.device_status == 0 && resp.last_command_crc == outp.crc && resp.isCRCcorrect()) break; - auto CRC_equal_awaited = true; // resp.last_command_crc == outp.crc; - if (resp.device_status == static_cast(stick10::device_status::ok) && - CRC_equal_awaited && resp.isValid()){ - successful_communication = true; - break; - } - if (resp.device_status == static_cast(stick10::device_status::busy)) { - dev->m_counters.busy++; - - if (busy_counter++<10) { - receiving_retry_counter++; - LOG("Status busy, not decreasing receiving_retry_counter counter: " + - std::to_string(receiving_retry_counter), Loglevel::DEBUG_L2); - } else { - retry_timeout *= 2; - retry_timeout = std::min(retry_timeout, 300ms); - busy_counter = 0; - LOG("Status busy, decreasing receiving_retry_counter counter: " + - std::to_string(receiving_retry_counter) + ", current delay:" - + std::to_string(retry_timeout.count()), Loglevel::DEBUG); - LOG(std::string("Busy retry: status ") - + std::to_string(resp.storage_status.device_status) - + ", " - + std::to_string(retry_timeout.count()) - + "ms, counter " - + std::to_string(receiving_retry_counter) - + ", progress: " - + std::to_string(resp.storage_status.progress_bar_value) - , Loglevel::DEBUG_L1); - } - } - if (resp.device_status == static_cast(stick10::device_status::busy) && - static_cast(resp.storage_status.device_status) - == stick20::device_status::busy_progressbar){ - successful_communication = true; - break; - } - LOG(std::string("Retry status - dev status, awaited cmd crc, correct packet CRC: ") - + std::to_string(resp.device_status) + - " " + std::to_string(CRC_equal_awaited) + - " " + std::to_string(resp.isCRCcorrect()), Loglevel::DEBUG_L2); - - if (!resp.isCRCcorrect()) dev->m_counters.wrong_CRC++; - if (!CRC_equal_awaited) dev->m_counters.CRC_other_than_awaited++; - - - LOG( - "Device is not ready or received packet's last CRC is not equal to sent CRC packet, retrying...", - Loglevel::DEBUG_L2); - LOG("Invalid incoming HID packet:", Loglevel::DEBUG_L2); - LOG(static_cast(resp), Loglevel::DEBUG_L2); - dev->m_counters.total_retries++; - LOG(".", Loglevel::DEBUG_L1); - std::this_thread::sleep_for(retry_timeout); - continue; - } - if (successful_communication) break; - LOG(std::string("Resending (outer loop) "), Loglevel::DEBUG_L2); - LOG(std::string("sending_retry_counter count: ") + std::to_string(sending_retry_counter), - Loglevel::DEBUG); - } - - if(resp.last_command_crc != outp.crc){ - LOG(std::string("Accepting response with CRC other than expected ") - + "Command ID: " + std::to_string(resp.command_id) + " " + - commandid_to_string(static_cast(resp.command_id)) + " " - + "Reported by response and expected: " + std::to_string(resp.last_command_crc) + "!=" + std::to_string(outp.crc), - Loglevel::WARNING - ); - } - - dev->set_last_command_status(resp.last_command_status); // FIXME should be handled on device.recv - - clear_packet(outp); - - - if (status <= 0) { - dev->m_counters.receiving_error++; - LOG(std::string("Throw: Device error while executing command "), Loglevel::DEBUG_L1); - throw DeviceReceivingFailure( //FIXME replace with CriticalErrorException - std::string("Device error while executing command ") + - std::to_string(status)); - } - - LOG(std::string("<= ") + - std::string( - commandid_to_string(static_cast(resp.command_id)) - + std::string(" ") - + std::to_string(resp.device_status) - + std::string(" ") - + std::to_string(resp.storage_status.device_status) -// + std::to_string( status_translate_command(resp.storage_status.device_status)) - ), Loglevel::DEBUG_L1); - - LOG("Incoming HID packet:", Loglevel::DEBUG); - LOG(static_cast(resp), Loglevel::DEBUG); - if (dev->get_retry_receiving_count() - receiving_retry_counter > 2) { - LOG(std::string("Packet received with receiving_retry_counter count: ") + - std::to_string(receiving_retry_counter), - Loglevel::DEBUG_L1); - } - - if (resp.device_status == static_cast(stick10::device_status::busy) && - static_cast(resp.storage_status.device_status) - == stick20::device_status::busy_progressbar){ - dev->m_counters.busy_progressbar++; - LOG(std::string("Throw: Long operation in progress exception"), Loglevel::DEBUG_L1); - throw LongOperationInProgressException( - resp.command_id, resp.device_status, resp.storage_status.progress_bar_value); - } - - if (!resp.isValid()) { - LOG(std::string("Throw: Invalid incoming packet"), Loglevel::DEBUG_L1); - throw InvalidCRCReceived("Invalid incoming packet"); - } - if (receiving_retry_counter <= 0){ - LOG(std::string("Throw: \"Maximum receiving_retry_counter count reached for receiving response from the device!\"" - + std::to_string(receiving_retry_counter)), Loglevel::DEBUG_L1); - throw DeviceReceivingFailure( - "Maximum receiving_retry_counter count reached for receiving response from the device!"); - } - dev->m_counters.communication_successful++; - - if (resp.last_command_status != static_cast(stick10::command_status::ok)){ - dev->m_counters.command_result_not_equal_0_recv++; - LOG(std::string("Throw: CommandFailedException ") + std::to_string(resp.last_command_status), Loglevel::DEBUG_L1); - throw CommandFailedException(resp.command_id, resp.last_command_status); - } - - dev->m_counters.command_successful_recv++; - - if (dev->get_device_model() == DeviceModel::STORAGE && - resp.command_id >= stick20::CMD_START_VALUE && - resp.command_id < stick20::CMD_END_VALUE ) { - dev->m_counters.successful_storage_commands++; - } - - if (!resp.isCRCcorrect()) - LOG(std::string("Accepting response from device with invalid CRC. ") - + "Command ID: " + std::to_string(resp.command_id) + " " + - commandid_to_string(static_cast(resp.command_id)) + " " - + "Reported and calculated: " + std::to_string(resp.crc) + "!=" + std::to_string(resp.calculate_CRC()), - Loglevel::WARNING - ); - - // See: DeviceResponse - return resp; - } - - static ClearingProxy run(std::shared_ptr dev) { - command_payload empty_payload; - return run(dev, empty_payload); - } - }; - } -} -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/dissect.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/dissect.h deleted file mode 100644 index 690b5b7..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/dissect.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -/* - * Protocol packet dissection - */ -#ifndef DISSECT_H -#define DISSECT_H -#include -#include -#include -#include "misc.h" -#include "cxx_semantics.h" -#include "command_id.h" -#include "device_proto.h" - -namespace nitrokey { -namespace proto { - -template -class QueryDissector : semantics::non_constructible { - public: - static std::string dissect(const HIDPacket &pod) { - std::stringstream out; - -#ifdef LOG_VOLATILE_DATA - out << "Raw HID packet:" << std::endl; - out << ::nitrokey::misc::hexdump((const uint8_t *)(&pod), sizeof pod); -#endif - - out << "Contents:" << std::endl; - out << "Command ID:\t" << commandid_to_string((CommandID)(pod.command_id)) - << std::endl; - out << "CRC:\t" - << std::hex << std::setw(2) << std::setfill('0') - << pod.crc << std::endl; - - out << "Payload:" << std::endl; - out << pod.payload.dissect(); - return out.str(); - } -}; - - - - -template -class ResponseDissector : semantics::non_constructible { - public: - static std::string status_translate_device(int status){ - auto enum_status = static_cast(status); - switch (enum_status){ - case stick10::device_status::ok: return "OK"; - case stick10::device_status::busy: return "BUSY"; - case stick10::device_status::error: return "ERROR"; - case stick10::device_status::received_report: return "RECEIVED_REPORT"; - } - return std::string("UNKNOWN: ") + std::to_string(status); - } - - static std::string to_upper(std::string str){ - for (auto & c: str) c = toupper(c); - return str; - } - static std::string status_translate_command(int status){ - auto enum_status = static_cast(status); - switch (enum_status) { -#define p(X) case X: return to_upper(std::string(#X)); - p(stick10::command_status::ok) - p(stick10::command_status::wrong_CRC) - p(stick10::command_status::wrong_slot) - p(stick10::command_status::slot_not_programmed) - p(stick10::command_status::wrong_password) - p(stick10::command_status::not_authorized) - p(stick10::command_status::timestamp_warning) - p(stick10::command_status::no_name_error) - p(stick10::command_status::not_supported) - p(stick10::command_status::unknown_command) - p(stick10::command_status::AES_dec_failed) -#undef p - } - return std::string("UNKNOWN: ") + std::to_string(status); - } - - static std::string dissect(const HIDPacket &pod) { - std::stringstream out; - - // FIXME use values from firmware (possibly generate separate - // header automatically) - -#ifdef LOG_VOLATILE_DATA - out << "Raw HID packet:" << std::endl; - out << ::nitrokey::misc::hexdump((const uint8_t *)(&pod), sizeof pod); -#endif - - out << "Device status:\t" << pod.device_status + 0 << " " - << status_translate_device(pod.device_status) << std::endl; - out << "Command ID:\t" << commandid_to_string((CommandID)(pod.command_id)) << " hex: " << std::hex << (int)pod.command_id - << std::endl; - out << "Last command CRC:\t" - << std::hex << std::setw(2) << std::setfill('0') - << pod.last_command_crc << std::endl; - out << "Last command status:\t" << pod.last_command_status + 0 << " " - << status_translate_command(pod.last_command_status) << std::endl; - out << "CRC:\t" - << std::hex << std::setw(2) << std::setfill('0') - << pod.crc << std::endl; - if((int)pod.command_id == pod.storage_status.command_id){ - out << "Storage stick status (where applicable):" << std::endl; -#define d(x) out << " "#x": \t"<< std::hex << std::setw(2) \ - << std::setfill('0')<< static_cast(x) << std::endl; - d(pod.storage_status.command_counter); - d(pod.storage_status.command_id); - d(pod.storage_status.device_status); - d(pod.storage_status.progress_bar_value); -#undef d - } - - out << "Payload:" << std::endl; - out << pod.payload.dissect(); - return out.str(); - } -}; -} -} - -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/hidapi/hidapi.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/hidapi/hidapi.h deleted file mode 100644 index e5bc2dc..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/hidapi/hidapi.h +++ /dev/null @@ -1,391 +0,0 @@ -/******************************************************* - HIDAPI - Multi-Platform library for - communication with HID devices. - - Alan Ott - Signal 11 Software - - 8/22/2009 - - Copyright 2009, All Rights Reserved. - - At the discretion of the user of this library, - this software may be licensed under the terms of the - GNU General Public License v3, a BSD-Style license, or the - original HIDAPI license as outlined in the LICENSE.txt, - LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt - files located at the root of the source distribution. - These files may also be found in the public source - code repository located at: - http://github.com/signal11/hidapi . -********************************************************/ - -/** @file - * @defgroup API hidapi API - */ - -#ifndef HIDAPI_H__ -#define HIDAPI_H__ - -#include - -#ifdef _WIN32 - #define HID_API_EXPORT __declspec(dllexport) - #define HID_API_CALL -#else - #define HID_API_EXPORT /**< API export macro */ - #define HID_API_CALL /**< API call macro */ -#endif - -#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/ - -#ifdef __cplusplus -extern "C" { -#endif - struct hid_device_; - typedef struct hid_device_ hid_device; /**< opaque hidapi structure */ - - /** hidapi info structure */ - struct hid_device_info { - /** Platform-specific device path */ - char *path; - /** Device Vendor ID */ - unsigned short vendor_id; - /** Device Product ID */ - unsigned short product_id; - /** Serial Number */ - wchar_t *serial_number; - /** Device Release Number in binary-coded decimal, - also known as Device Version Number */ - unsigned short release_number; - /** Manufacturer String */ - wchar_t *manufacturer_string; - /** Product string */ - wchar_t *product_string; - /** Usage Page for this Device/Interface - (Windows/Mac only). */ - unsigned short usage_page; - /** Usage for this Device/Interface - (Windows/Mac only).*/ - unsigned short usage; - /** The USB interface which this logical device - represents. Valid on both Linux implementations - in all cases, and valid on the Windows implementation - only if the device contains more than one interface. */ - int interface_number; - - /** Pointer to the next device */ - struct hid_device_info *next; - }; - - - /** @brief Initialize the HIDAPI library. - - This function initializes the HIDAPI library. Calling it is not - strictly necessary, as it will be called automatically by - hid_enumerate() and any of the hid_open_*() functions if it is - needed. This function should be called at the beginning of - execution however, if there is a chance of HIDAPI handles - being opened by different threads simultaneously. - - @ingroup API - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_init(void); - - /** @brief Finalize the HIDAPI library. - - This function frees all of the static data associated with - HIDAPI. It should be called at the end of execution to avoid - memory leaks. - - @ingroup API - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_exit(void); - - /** @brief Enumerate the HID Devices. - - This function returns a linked list of all the HID devices - attached to the system which match vendor_id and product_id. - If @p vendor_id is set to 0 then any vendor matches. - If @p product_id is set to 0 then any product matches. - If @p vendor_id and @p product_id are both set to 0, then - all HID devices will be returned. - - @ingroup API - @param vendor_id The Vendor ID (VID) of the types of device - to open. - @param product_id The Product ID (PID) of the types of - device to open. - - @returns - This function returns a pointer to a linked list of type - struct #hid_device, containing information about the HID devices - attached to the system, or NULL in the case of failure. Free - this linked list by calling hid_free_enumeration(). - */ - struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id); - - /** @brief Free an enumeration Linked List - - This function frees a linked list created by hid_enumerate(). - - @ingroup API - @param devs Pointer to a list of struct_device returned from - hid_enumerate(). - */ - void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs); - - /** @brief Open a HID device using a Vendor ID (VID), Product ID - (PID) and optionally a serial number. - - If @p serial_number is NULL, the first device with the - specified VID and PID is opened. - - @ingroup API - @param vendor_id The Vendor ID (VID) of the device to open. - @param product_id The Product ID (PID) of the device to open. - @param serial_number The Serial Number of the device to open - (Optionally NULL). - - @returns - This function returns a pointer to a #hid_device object on - success or NULL on failure. - */ - HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number); - - /** @brief Open a HID device by its path name. - - The path name be determined by calling hid_enumerate(), or a - platform-specific path name can be used (eg: /dev/hidraw0 on - Linux). - - @ingroup API - @param path The path name of the device to open - - @returns - This function returns a pointer to a #hid_device object on - success or NULL on failure. - */ - HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path); - - /** @brief Write an Output report to a HID device. - - The first byte of @p data[] must contain the Report ID. For - devices which only support a single report, this must be set - to 0x0. The remaining bytes contain the report data. Since - the Report ID is mandatory, calls to hid_write() will always - contain one more byte than the report contains. For example, - if a hid report is 16 bytes long, 17 bytes must be passed to - hid_write(), the Report ID (or 0x0, for devices with a - single report), followed by the report data (16 bytes). In - this example, the length passed in would be 17. - - hid_write() will send the data on the first OUT endpoint, if - one exists. If it does not, it will send the data through - the Control Endpoint (Endpoint 0). - - @ingroup API - @param device A device handle returned from hid_open(). - @param data The data to send, including the report number as - the first byte. - @param length The length in bytes of the data to send. - - @returns - This function returns the actual number of bytes written and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length); - - /** @brief Read an Input report from a HID device with timeout. - - Input reports are returned - to the host through the INTERRUPT IN endpoint. The first byte will - contain the Report number if the device uses numbered reports. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into. - @param length The number of bytes to read. For devices with - multiple reports, make sure to read an extra byte for - the report number. - @param milliseconds timeout in milliseconds or -1 for blocking wait. - - @returns - This function returns the actual number of bytes read and - -1 on error. If no packet was available to be read within - the timeout period, this function returns 0. - */ - int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds); - - /** @brief Read an Input report from a HID device. - - Input reports are returned - to the host through the INTERRUPT IN endpoint. The first byte will - contain the Report number if the device uses numbered reports. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into. - @param length The number of bytes to read. For devices with - multiple reports, make sure to read an extra byte for - the report number. - - @returns - This function returns the actual number of bytes read and - -1 on error. If no packet was available to be read and - the handle is in non-blocking mode, this function returns 0. - */ - int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length); - - /** @brief Set the device handle to be non-blocking. - - In non-blocking mode calls to hid_read() will return - immediately with a value of 0 if there is no data to be - read. In blocking mode, hid_read() will wait (block) until - there is data to read before returning. - - Nonblocking can be turned on and off at any time. - - @ingroup API - @param device A device handle returned from hid_open(). - @param nonblock enable or not the nonblocking reads - - 1 to enable nonblocking - - 0 to disable nonblocking. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock); - - /** @brief Send a Feature report to the device. - - Feature reports are sent over the Control endpoint as a - Set_Report transfer. The first byte of @p data[] must - contain the Report ID. For devices which only support a - single report, this must be set to 0x0. The remaining bytes - contain the report data. Since the Report ID is mandatory, - calls to hid_send_feature_report() will always contain one - more byte than the report contains. For example, if a hid - report is 16 bytes long, 17 bytes must be passed to - hid_send_feature_report(): the Report ID (or 0x0, for - devices which do not use numbered reports), followed by the - report data (16 bytes). In this example, the length passed - in would be 17. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data The data to send, including the report number as - the first byte. - @param length The length in bytes of the data to send, including - the report number. - - @returns - This function returns the actual number of bytes written and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length); - - /** @brief Get a feature report from a HID device. - - Set the first byte of @p data[] to the Report ID of the - report to be read. Make sure to allow space for this - extra byte in @p data[]. Upon return, the first byte will - still contain the Report ID, and the report data will - start in data[1]. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into, including - the Report ID. Set the first byte of @p data[] to the - Report ID of the report to be read, or set it to zero - if your device does not use numbered reports. - @param length The number of bytes to read, including an - extra byte for the report ID. The buffer can be longer - than the actual report. - - @returns - This function returns the number of bytes read plus - one for the report ID (which is still in the first - byte), or -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length); - - /** @brief Close a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - */ - void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device); - - /** @brief Get The Manufacturer String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get The Product String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get The Serial Number String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get a string from a HID device, based on its string index. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string_index The index of the string to get. - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen); - - /** @brief Get a string describing the last error which occurred. - - @ingroup API - @param device A device handle returned from hid_open(). - - @returns - This function returns a string containing the last error - which occurred or NULL if none has occurred. - */ - HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/log.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/log.h deleted file mode 100644 index 278b49c..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/log.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef LOG_H -#define LOG_H - -#include -#include - -namespace nitrokey { - namespace log { - -//for MSVC -#ifdef ERROR -#undef ERROR -#endif - - - enum class Loglevel : int { - ERROR, - WARNING, - INFO, - DEBUG_L1, - DEBUG, - DEBUG_L2 - }; - - class LogHandler { - public: - virtual void print(const std::string &, Loglevel lvl) = 0; - virtual ~LogHandler() = default; - protected: - std::string loglevel_to_str(Loglevel); - std::string format_message_to_string(const std::string &str, const Loglevel &lvl); - - }; - - class StdlogHandler : public LogHandler { - public: - virtual void print(const std::string &, Loglevel lvl); - }; - - class FunctionalLogHandler : public LogHandler { - using log_function_type = std::function; - log_function_type log_function; - public: - FunctionalLogHandler(log_function_type _log_function); - virtual void print(const std::string &, Loglevel lvl); - - }; - - extern StdlogHandler stdlog_handler; - - class Log { - public: - Log() : mp_loghandler(&stdlog_handler), m_loglevel(Loglevel::WARNING) {} - - static Log &instance() { - if (mp_instance == nullptr) mp_instance = new Log; - return *mp_instance; - } - - void operator()(const std::string &, Loglevel); - void set_loglevel(Loglevel lvl) { m_loglevel = lvl; } - void set_handler(LogHandler *handler) { mp_loghandler = handler; } - - private: - LogHandler *mp_loghandler; - Loglevel m_loglevel; - static std::string prefix; - public: - static void setPrefix(std::string prefix = std::string()); - - private: - - static Log *mp_instance; - }; - } -} - - -#ifdef NO_LOG -#define LOG(string, level) while(false){} -#define LOGD(string) while(false){} -#else -#define LOG(string, level) nitrokey::log::Log::instance()((string), (level)) -#define LOGD1(string) nitrokey::log::Log::instance()((string), (nitrokey::log::Loglevel::DEBUG_L1)) -#define LOGD(string) nitrokey::log::Log::instance()((string), (nitrokey::log::Loglevel::DEBUG_L2)) -#endif - -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/misc.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/misc.h deleted file mode 100644 index a9c4672..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/misc.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - - -#ifndef MISC_H -#define MISC_H -#include -#include -#include -#include -#include "log.h" -#include "LibraryException.h" -#include -#include -#include - - -namespace nitrokey { -namespace misc { - -/** - * Simple replacement for std::optional (C++17). - */ -template -class Option { -public: - Option() : m_hasValue(false), m_value() {} - Option(T value) : m_hasValue(true), m_value(value) {} - - bool has_value() const { - return m_hasValue; - } - T value() const { - if (!m_hasValue) { - throw std::logic_error("Called Option::value without value"); - } - return m_value; - } - -private: - bool m_hasValue; - T m_value; -}; - - template - std::string toHex(T value){ - using namespace std; - std::ostringstream oss; - oss << std::hex << std::setw(sizeof(value)*2) << std::setfill('0') << value; - return oss.str(); - } - -#define FIELD_WIDTH_MAX (100) - /** - * Copies string from pointer to fixed size C-style array. Src needs to be a valid C-string - eg. ended with '\0'. - * Throws when source is bigger than destination. - * @tparam T type of destination array - * @param dest fixed size destination array - * @param src pointer to source c-style valid string - */ - template - void strcpyT(T& dest, const char* src){ - - if (src == nullptr) -// throw EmptySourceStringException(slot_number); - return; - const size_t s_dest = sizeof dest; - const size_t src_strlen = strnlen(src, FIELD_WIDTH_MAX); - LOG(std::string("strcpyT sizes dest src ") - + std::to_string(s_dest) + " " - + std::to_string(src_strlen) + " " - , nitrokey::log::Loglevel::DEBUG_L2); - if (src_strlen > s_dest){ - throw TooLongStringException(src_strlen, s_dest, src); - } - strncpy((char*) &dest, src, s_dest); - } - -#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) - template -typename T::CommandPayload get_payload(){ - //Create, initialize and return by value command payload - typename T::CommandPayload st; - bzero(&st, sizeof(st)); - return st; -} - - template - void execute_password_command(Tdev &stick, const char *password) { - auto p = get_payload(); - p.set_defaults(); - strcpyT(p.password, password); - CMDTYPE::CommandTransaction::run(stick, p); - } - - std::string hexdump(const uint8_t *p, size_t size, bool print_header=true, bool print_ascii=true, - bool print_empty=true); - uint32_t stm_crc32(const uint8_t *data, size_t size); - std::vector hex_string_to_byte(const char* hexString); -} -} - -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick10_commands.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick10_commands.h deleted file mode 100644 index 5e8a5aa..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick10_commands.h +++ /dev/null @@ -1,929 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef STICK10_COMMANDS_H -#define STICK10_COMMANDS_H - -#include -#include -#include -#include -#include -#include "device_proto.h" -#include "command.h" - -#pragma pack (push,1) - -namespace nitrokey { -namespace proto { - - - -/* - * Stick10 protocol definition - */ -namespace stick10 { -class GetSlotName : public Command { - public: - // reachable as a typedef in Transaction - struct CommandPayload { - uint8_t slot_number; - - bool isValid() const { return slot_number<0x10+3; } - std::string dissect() const { - std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - uint8_t slot_name[15]; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(slot_name); - return ss.str(); - } - } __packed; - - typedef Transaction CommandTransaction; -}; - -class EraseSlot : Command { - public: - struct CommandPayload { - uint8_t slot_number; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class SetTime : Command { - public: - struct CommandPayload { - uint8_t reset; // 0 - get time, 1 - set time - uint64_t time; // posix time - - bool isValid() const { return reset && reset != 1; } - std::string dissect() const { - std::stringstream ss; - ss << "reset:\t" << (int)(reset) << std::endl; - ss << "time:\t" << (time) << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - - -class WriteToHOTPSlot : Command { - public: - struct CommandPayload { - uint8_t slot_number; - uint8_t slot_name[15]; - uint8_t slot_secret[20]; - union{ - uint8_t _slot_config; - struct{ - bool use_8_digits : 1; - bool use_enter : 1; - bool use_tokenID : 1; - }; - }; - union{ - uint8_t slot_token_id[13]; /** OATH Token Identifier */ - struct{ /** @see https://openauthentication.org/token-specs/ */ - uint8_t omp[2]; - uint8_t tt[2]; - uint8_t mui[8]; - uint8_t keyboard_layout; //disabled feature in nitroapp as of 20160805 - } slot_token_fields; - }; - union{ - uint64_t slot_counter; - uint8_t slot_counter_s[8]; - } __packed; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - print_to_ss_volatile(slot_name); - print_to_ss_volatile(slot_secret); - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; - ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; - ss << "\tuse_enter(1):\t" << use_enter << std::endl; - ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; - - ss << "slot_token_id:\t"; - for (auto i : slot_token_id) - ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; - ss << std::endl; - ss << "slot_counter:\t[" << (int)slot_counter << "]\t" - << ::nitrokey::misc::hexdump((const uint8_t *)(&slot_counter), sizeof slot_counter, false); - - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class WriteToTOTPSlot : Command { - public: - struct CommandPayload { - uint8_t slot_number; - uint8_t slot_name[15]; - uint8_t slot_secret[20]; - union{ - uint8_t _slot_config; - struct{ - bool use_8_digits : 1; - bool use_enter : 1; - bool use_tokenID : 1; - }; - }; - union{ - uint8_t slot_token_id[13]; /** OATH Token Identifier */ - struct{ /** @see https://openauthentication.org/token-specs/ */ - uint8_t omp[2]; - uint8_t tt[2]; - uint8_t mui[8]; - uint8_t keyboard_layout; //disabled feature in nitroapp as of 20160805 - } slot_token_fields; - }; - uint16_t slot_interval; - - bool isValid() const { return !(slot_number & 0xF0); } //TODO check - std::string dissect() const { - std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - print_to_ss_volatile(slot_name); - print_to_ss_volatile(slot_secret); - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; - ss << "slot_token_id:\t"; - for (auto i : slot_token_id) - ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; - ss << std::endl; - ss << "slot_interval:\t" << (int)slot_interval << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class GetTOTP : Command { - public: - struct CommandPayload { - uint8_t slot_number; - uint64_t challenge; - uint64_t last_totp_time; - uint8_t last_interval; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - ss << "challenge:\t" << (challenge) << std::endl; - ss << "last_totp_time:\t" << (last_totp_time) << std::endl; - ss << "last_interval:\t" << (int)(last_interval) << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - union { - uint8_t whole_response[18]; //14 bytes reserved for config, but used only 1 - struct { - uint32_t code; - union{ - uint8_t _slot_config; - struct{ - bool use_8_digits : 1; - bool use_enter : 1; - bool use_tokenID : 1; - }; - }; - } __packed ; - } __packed ; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - ss << "code:\t" << (code) << std::endl; - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; - ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; - ss << "\tuse_enter(1):\t" << use_enter << std::endl; - ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class GetHOTP : Command { - public: - struct CommandPayload { - uint8_t slot_number; - - bool isValid() const { return (slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - union { - uint8_t whole_response[18]; //14 bytes reserved for config, but used only 1 - struct { - uint32_t code; - union{ - uint8_t _slot_config; - struct{ - bool use_8_digits : 1; - bool use_enter : 1; - bool use_tokenID : 1; - }; - }; - } __packed; - } __packed; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - ss << "code:\t" << (code) << std::endl; - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; - ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; - ss << "\tuse_enter(1):\t" << use_enter << std::endl; - ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class ReadSlot : Command { - public: - enum class CounterFormat { - ASCII = 0, - BINARY = 1, - }; - struct CommandPayload { - uint8_t slot_number; - CounterFormat data_format; //Storage v0.54+ only: slot_counter value format: 0 - in ascii, 1 - binary - - bool isValid() const { return !(slot_number & 0xF0); } - - std::string dissect() const { - std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - uint8_t slot_name[15]; - union{ - uint8_t _slot_config; - struct{ - bool use_8_digits : 1; - bool use_enter : 1; - bool use_tokenID : 1; - }; - }; - union{ - uint8_t slot_token_id[13]; /** OATH Token Identifier */ - struct{ /** @see https://openauthentication.org/token-specs/ */ - uint8_t omp[2]; - uint8_t tt[2]; - uint8_t mui[8]; - uint8_t keyboard_layout; //disabled feature in nitroapp as of 20160805 - } slot_token_fields; - }; - union{ - uint64_t slot_counter; - uint8_t slot_counter_s[8]; - } __packed; - - bool isValid() const { return true; } - - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(slot_name); - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; - ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; - ss << "\tuse_enter(1):\t" << use_enter << std::endl; - ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; - - ss << "slot_token_id:\t"; - for (auto i : slot_token_id) - ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; - ss << std::endl; - ss << "slot_counter:\t[" << (int)slot_counter << "]\t" - << ::nitrokey::misc::hexdump((const uint8_t *)(&slot_counter), sizeof slot_counter, false); - return ss.str(); - } - } __packed; - - typedef Transaction CommandTransaction; -}; - -class GetStatus : Command { - public: - struct ResponsePayload { - union { - uint16_t firmware_version; - struct { - uint8_t minor; - uint8_t major; - } firmware_version_st; - }; - union{ - uint8_t card_serial[4]; - uint32_t card_serial_u32; - } __packed; - union { - uint8_t general_config[5]; - struct{ - uint8_t numlock; /** 0-1: HOTP slot number from which the code will be get on double press, other value - function disabled */ - uint8_t capslock; /** same as numlock */ - uint8_t scrolllock; /** same as numlock */ - uint8_t enable_user_password; - uint8_t delete_user_password; /* unused */ - } __packed; - } __packed; - - static constexpr uint8_t special_HOTP_slots = 2; - bool isValid() const { return numlock < special_HOTP_slots && capslock < special_HOTP_slots - && scrolllock < special_HOTP_slots && enable_user_password < 2; } - - std::string get_card_serial_hex() const { - return nitrokey::misc::toHex(card_serial_u32); - } - - std::string dissect() const { - std::stringstream ss; - ss << "firmware_version:\t" - << "[" << firmware_version << "]" << "\t" - << ::nitrokey::misc::hexdump( - (const uint8_t *)(&firmware_version), sizeof firmware_version, false); - ss << "card_serial_u32:\t" << std::hex << card_serial_u32 << std::endl; - ss << "card_serial:\t" - << ::nitrokey::misc::hexdump((const uint8_t *)(card_serial), - sizeof card_serial, false); - ss << "general_config:\t" - << ::nitrokey::misc::hexdump((const uint8_t *)(general_config), - sizeof general_config, false); - ss << "numlock:\t" << (int)numlock << std::endl; - ss << "capslock:\t" << (int)capslock << std::endl; - ss << "scrolllock:\t" << (int)scrolllock << std::endl; - ss << "enable_user_password:\t" << (bool) enable_user_password << std::endl; - ss << "delete_user_password:\t" << (bool) delete_user_password << std::endl; - - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class GetPasswordRetryCount : Command { - public: - struct ResponsePayload { - uint8_t password_retry_count; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - ss << " password_retry_count\t" << (int)password_retry_count << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class GetUserPasswordRetryCount - : Command { - public: - struct ResponsePayload { - uint8_t password_retry_count; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - ss << " password_retry_count\t" << (int)password_retry_count << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - - template - void write_array(T &ss, Q (&arr)[N]){ - for (int i=0; i { - public: - struct ResponsePayload { - uint8_t password_safe_status[PWS_SLOT_COUNT]; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - ss << "password_safe_status\t"; - write_array(ss, password_safe_status); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class GetPasswordSafeSlotName : Command { - public: - struct CommandPayload { - uint8_t slot_number; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << "slot_number\t" << (int)slot_number << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - uint8_t slot_name[PWS_SLOTNAME_LENGTH]; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(slot_name); - return ss.str(); - } - } __packed; - - typedef Transaction CommandTransaction; -}; - -class GetPasswordSafeSlotPassword - : Command { - public: - struct CommandPayload { - uint8_t slot_number; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - uint8_t slot_password[PWS_PASSWORD_LENGTH]; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(slot_password); - return ss.str(); - } - } __packed; - - typedef Transaction CommandTransaction; -}; - -class GetPasswordSafeSlotLogin - : Command { - public: - struct CommandPayload { - uint8_t slot_number; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - uint8_t slot_login[PWS_LOGINNAME_LENGTH]; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(slot_login); - return ss.str(); - } - } __packed; - - typedef Transaction CommandTransaction; -}; - -class SetPasswordSafeSlotData : Command { - public: - struct CommandPayload { - uint8_t slot_number; - uint8_t slot_name[PWS_SLOTNAME_LENGTH]; - uint8_t slot_password[PWS_PASSWORD_LENGTH]; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; - print_to_ss_volatile(slot_name); - print_to_ss_volatile(slot_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class SetPasswordSafeSlotData2 : Command { - public: - struct CommandPayload { - uint8_t slot_number; - uint8_t slot_login_name[PWS_LOGINNAME_LENGTH]; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; - print_to_ss_volatile(slot_login_name); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class ErasePasswordSafeSlot : Command { - public: - struct CommandPayload { - uint8_t slot_number; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << " slot_number\t" << (int)slot_number << std::endl; - return ss.str(); - } - - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class EnablePasswordSafe : Command { - public: - struct CommandPayload { - uint8_t user_password[30]; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(user_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class PasswordSafeInitKey : Command { - /** - * never used in Nitrokey App - */ - public: - typedef Transaction - CommandTransaction; -}; - -class PasswordSafeSendSlotViaHID : Command { - /** - * never used in Nitrokey App - */ - public: - struct CommandPayload { - uint8_t slot_number; - uint8_t slot_kind; - - bool isValid() const { return !(slot_number & 0xF0); } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -// TODO "Device::passwordSafeSendSlotDataViaHID" - -class WriteGeneralConfig : Command { - public: - struct CommandPayload { - union{ - uint8_t config[5]; - struct{ - uint8_t numlock; /** 0-1: HOTP slot number from which the code will be get on double press, other value - function disabled */ - uint8_t capslock; /** same as numlock */ - uint8_t scrolllock; /** same as numlock */ - uint8_t enable_user_password; - uint8_t delete_user_password; - }; - }; - bool isValid() const { return numlock < 2 && capslock < 2 && scrolllock < 2 && enable_user_password < 2; } - - std::string dissect() const { - std::stringstream ss; - ss << "numlock:\t" << (int)numlock << std::endl; - ss << "capslock:\t" << (int)capslock << std::endl; - ss << "scrolllock:\t" << (int)scrolllock << std::endl; - ss << "enable_user_password:\t" << (bool) enable_user_password << std::endl; - ss << "delete_user_password:\t" << (bool) delete_user_password << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class FirstAuthenticate : Command { - public: - struct CommandPayload { - uint8_t card_password[25]; - uint8_t temporary_password[25]; - - bool isValid() const { return true; } - - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(card_password); - hexdump_to_ss(temporary_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class UserAuthenticate : Command { - public: - struct CommandPayload { - uint8_t card_password[25]; - uint8_t temporary_password[25]; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(card_password); - hexdump_to_ss(temporary_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class Authorize : Command { - public: - struct CommandPayload { - uint32_t crc_to_authorize; - uint8_t temporary_password[25]; - - std::string dissect() const { - std::stringstream ss; - ss << " crc_to_authorize:\t" << std::hex << std::setw(2) << std::setfill('0') << crc_to_authorize<< std::endl; - hexdump_to_ss(temporary_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class UserAuthorize : Command { - public: - struct CommandPayload { - uint32_t crc_to_authorize; - uint8_t temporary_password[25]; - std::string dissect() const { - std::stringstream ss; - ss << " crc_to_authorize:\t" << crc_to_authorize<< std::endl; - hexdump_to_ss(temporary_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class UnlockUserPassword : Command { - public: - struct CommandPayload { - uint8_t admin_password[25]; - uint8_t user_new_password[25]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(admin_password); - print_to_ss_volatile(user_new_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class ChangeUserPin : Command { - public: - struct CommandPayload { - uint8_t old_pin[25]; - uint8_t new_pin[25]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(old_pin); - print_to_ss_volatile(new_pin); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class IsAESSupported : Command { - public: - struct CommandPayload { - uint8_t user_password[20]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(user_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - - -class ChangeAdminPin : Command { - public: - struct CommandPayload { - uint8_t old_pin[25]; - uint8_t new_pin[25]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(old_pin); - print_to_ss_volatile(new_pin); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class LockDevice : Command { - public: - typedef Transaction - CommandTransaction; -}; - -class FactoryReset : Command { - public: - struct CommandPayload { - uint8_t admin_password[20]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(admin_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; -}; - -class BuildAESKey : Command { - public: - struct CommandPayload { - uint8_t admin_password[20]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(admin_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - -}; - -class FirmwareUpdate : Command { -public: - struct CommandPayload { - uint8_t firmware_password[20]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(firmware_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - -}; - -class FirmwarePasswordChange : Command { -public: - struct CommandPayload { - uint8_t firmware_password_current[20]; - uint8_t firmware_password_new[20]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile(firmware_password_current); - print_to_ss_volatile(firmware_password_new); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - -}; - - -} -} -} -#pragma pack (pop) -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick10_commands_0.8.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick10_commands_0.8.h deleted file mode 100644 index 9477890..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick10_commands_0.8.h +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - - -#ifndef LIBNITROKEY_STICK10_COMMANDS_0_8_H -#define LIBNITROKEY_STICK10_COMMANDS_0_8_H - -#include -#include -#include -#include -#include -#include "command.h" -#include "device_proto.h" -#include "stick10_commands.h" - -#pragma pack (push,1) - - -namespace nitrokey { - namespace proto { - -/* - * Stick10 protocol definition - */ - namespace stick10_08 { - using stick10::FirstAuthenticate; - using stick10::UserAuthenticate; - using stick10::SetTime; - using stick10::GetStatus; - using stick10::BuildAESKey; - using stick10::ChangeAdminPin; - using stick10::ChangeUserPin; - using stick10::EnablePasswordSafe; - using stick10::ErasePasswordSafeSlot; - using stick10::FactoryReset; - using stick10::GetPasswordRetryCount; - using stick10::GetUserPasswordRetryCount; - using stick10::GetPasswordSafeSlotLogin; - using stick10::GetPasswordSafeSlotName; - using stick10::GetPasswordSafeSlotPassword; - using stick10::GetPasswordSafeSlotStatus; - using stick10::GetSlotName; - using stick10::IsAESSupported; - using stick10::LockDevice; - using stick10::PasswordSafeInitKey; - using stick10::PasswordSafeSendSlotViaHID; - using stick10::SetPasswordSafeSlotData; - using stick10::SetPasswordSafeSlotData2; - using stick10::UnlockUserPassword; - using stick10::ReadSlot; - - class EraseSlot : Command { - public: - struct CommandPayload { - uint8_t slot_number; - uint8_t temporary_admin_password[25]; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - hexdump_to_ss(temporary_admin_password); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - class SendOTPData : Command { - //admin auth - public: - struct CommandPayload { - uint8_t temporary_admin_password[25]; - uint8_t type; //S-secret, N-name - uint8_t id; //multiple reports for values longer than 30 bytes - uint8_t data[30]; //data, does not need null termination - - bool isValid() const { return true; } - - void setTypeName(){ - type = 'N'; - } - void setTypeSecret(){ - type = 'S'; - } - - std::string dissect() const { - std::stringstream ss; - hexdump_to_ss(temporary_admin_password); - ss << "type:\t" << type << std::endl; - ss << "id:\t" << (int)id << std::endl; -#ifdef LOG_VOLATILE_DATA - ss << "data:" << std::endl - << ::nitrokey::misc::hexdump((const uint8_t *) (&data), sizeof data); -#else - ss << " Volatile data not logged" << std::endl; -#endif - return ss.str(); - } - } __packed; - - - struct ResponsePayload { - union { - uint8_t data[40]; - } __packed; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; -#ifdef LOG_VOLATILE_DATA - ss << "data:" << std::endl - << ::nitrokey::misc::hexdump((const uint8_t *) (&data), sizeof data); -#else - ss << " Volatile data not logged" << std::endl; -#endif - return ss.str(); - } - } __packed; - - - typedef Transaction - CommandTransaction; - }; - - class WriteToOTPSlot : Command { - //admin auth - public: - struct CommandPayload { - uint8_t temporary_admin_password[25]; - uint8_t slot_number; - union { - uint64_t slot_counter_or_interval; - uint8_t slot_counter_s[8]; - } __packed; - union { - uint8_t _slot_config; - struct { - bool use_8_digits : 1; - bool use_enter : 1; - bool use_tokenID : 1; - }; - }; - union { - uint8_t slot_token_id[13]; /** OATH Token Identifier */ - struct { /** @see https://openauthentication.org/token-specs/ */ - uint8_t omp[2]; - uint8_t tt[2]; - uint8_t mui[8]; - uint8_t keyboard_layout; //disabled feature in nitroapp as of 20160805 - } slot_token_fields; - }; - - bool isValid() const { return true; } - - std::string dissect() const { - std::stringstream ss; - hexdump_to_ss(temporary_admin_password); - ss << "slot_config:\t" << std::bitset<8>((int) _slot_config) << std::endl; - ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; - ss << "\tuse_enter(1):\t" << use_enter << std::endl; - ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; - ss << "slot_number:\t" << (int) (slot_number) << std::endl; - ss << "slot_counter_or_interval:\t[" << (int) slot_counter_or_interval << "]\t" - << ::nitrokey::misc::hexdump((const uint8_t *) (&slot_counter_or_interval), sizeof slot_counter_or_interval, false); - - ss << "slot_token_id:\t"; - for (auto i : slot_token_id) - ss << std::hex << std::setw(2) << std::setfill('0') << (int) i << " "; - ss << std::endl; - - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - class GetHOTP : Command { - public: - struct CommandPayload { - uint8_t slot_number; - struct { - uint64_t challenge; //@unused - uint64_t last_totp_time; //@unused - uint8_t last_interval; //@unused - } __packed _unused; - uint8_t temporary_user_password[25]; - - bool isValid() const { return (slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - hexdump_to_ss(temporary_user_password); - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - union { - uint8_t whole_response[18]; //14 bytes reserved for config, but used only 1 - struct { - uint32_t code; - union{ - uint8_t _slot_config; - struct{ - bool use_8_digits : 1; - bool use_enter : 1; - bool use_tokenID : 1; - }; - }; - } __packed; - } __packed; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - ss << "code:\t" << (code) << std::endl; - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; - ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; - ss << "\tuse_enter(1):\t" << use_enter << std::endl; - ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - - class GetTOTP : Command { - //user auth - public: - struct CommandPayload { - uint8_t slot_number; - uint64_t challenge; //@unused - uint64_t last_totp_time; //@unused - uint8_t last_interval; //@unused - uint8_t temporary_user_password[25]; - - bool isValid() const { return !(slot_number & 0xF0); } - std::string dissect() const { - std::stringstream ss; - hexdump_to_ss(temporary_user_password); - ss << "slot_number:\t" << (int)(slot_number) << std::endl; - ss << "challenge:\t" << (challenge) << std::endl; - ss << "last_totp_time:\t" << (last_totp_time) << std::endl; - ss << "last_interval:\t" << (int)(last_interval) << std::endl; - return ss.str(); - } - } __packed; - - struct ResponsePayload { - union { - uint8_t whole_response[18]; //14 bytes reserved for config, but used only 1 - struct { - uint32_t code; - union{ - uint8_t _slot_config; - struct{ - bool use_8_digits : 1; - bool use_enter : 1; - bool use_tokenID : 1; - }; - }; - } __packed ; - } __packed ; - - bool isValid() const { return true; } - std::string dissect() const { - std::stringstream ss; - ss << "code:\t" << (code) << std::endl; - ss << "slot_config:\t" << std::bitset<8>((int)_slot_config) << std::endl; - ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl; - ss << "\tuse_enter(1):\t" << use_enter << std::endl; - ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - - class WriteGeneralConfig : Command { - //admin auth - public: - struct CommandPayload { - union{ - uint8_t config[5]; - struct{ - uint8_t numlock; /** 0-1: HOTP slot number from which the code will be get on double press, other value - function disabled */ - uint8_t capslock; /** same as numlock */ - uint8_t scrolllock; /** same as numlock */ - uint8_t enable_user_password; - uint8_t delete_user_password; - }; - }; - uint8_t temporary_admin_password[25]; - - static constexpr uint8_t special_HOTP_slots = 3; - bool isValid() const { return numlock < special_HOTP_slots && capslock < special_HOTP_slots - && scrolllock < special_HOTP_slots && enable_user_password < 2; } - - std::string dissect() const { - std::stringstream ss; - ss << "numlock:\t" << (int)numlock << std::endl; - ss << "capslock:\t" << (int)capslock << std::endl; - ss << "scrolllock:\t" << (int)scrolllock << std::endl; - ss << "enable_user_password:\t" << (bool) enable_user_password << std::endl; - ss << "delete_user_password:\t" << (bool) delete_user_password << std::endl; - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - } - } -} -#pragma pack (pop) - -#endif //LIBNITROKEY_STICK10_COMMANDS_0_8_H diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick20_commands.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick20_commands.h deleted file mode 100644 index 7efa1b6..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/stick20_commands.h +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef STICK20_COMMANDS_H -#define STICK20_COMMANDS_H - - - -#include -#include "command.h" -#include -#include -#include "device_proto.h" - -#pragma pack (push,1) - -namespace nitrokey { - namespace proto { - -/* -* STICK20 protocol command ids -* a superset (almost) of STICK10 -*/ - - namespace stick20 { - - class ChangeAdminUserPin20Current : - public PasswordCommand {}; - class ChangeAdminUserPin20New : - public PasswordCommand {}; - class UnlockUserPin : - public PasswordCommand {}; - - class EnableEncryptedPartition : public PasswordCommand {}; - class EnableHiddenEncryptedPartition : public PasswordCommand {}; - - class SetUnencryptedVolumeReadOnlyAdmin : - public PasswordCommand {}; - class SetUnencryptedVolumeReadWriteAdmin : - public PasswordCommand {}; - class SetEncryptedVolumeReadOnly : - public PasswordCommand {}; - class SetEncryptedVolumeReadWrite : - public PasswordCommand {}; - - //FIXME the volume disabling commands do not need password - class DisableEncryptedPartition : public PasswordCommand {}; - class DisableHiddenEncryptedPartition : public PasswordCommand {}; - - class EnableFirmwareUpdate : public PasswordCommand {}; - - class ChangeUpdatePassword : Command { - public: - struct CommandPayload { - uint8_t __gap; - uint8_t current_update_password[20]; - uint8_t __gap2; - uint8_t new_update_password[20]; - std::string dissect() const { - std::stringstream ss; - print_to_ss_volatile( current_update_password ); - print_to_ss_volatile( new_update_password ); - return ss.str(); - } - }; - - typedef Transaction - CommandTransaction; - }; - - class ExportFirmware : public PasswordCommand {}; - - class CreateNewKeys : - public PasswordCommand {}; - - - class FillSDCardWithRandomChars : Command { - public: - enum class ChosenVolumes : uint8_t { - all_volumes = 0, - encrypted_volume = 1 - }; - - struct CommandPayload { - uint8_t volume_flag; - uint8_t kind; - uint8_t admin_pin[20]; - - std::string dissect() const { - std::stringstream ss; - print_to_ss( (int) volume_flag ); - print_to_ss( kind ); - print_to_ss_volatile(admin_pin); - return ss.str(); - } - void set_kind_user() { - kind = (uint8_t) 'P'; - } - void set_defaults(){ - set_kind_user(); - volume_flag = static_cast(ChosenVolumes::encrypted_volume); - } - - } __packed; - - typedef Transaction::command_id(), - struct CommandPayload, struct EmptyPayload> - CommandTransaction; - }; - - namespace StorageCommandResponsePayload{ - using namespace DeviceResponseConstants; - static constexpr auto padding_size = - storage_data_absolute_address - header_size; - struct TransmissionData{ - uint8_t _padding[padding_size]; - - uint8_t SendCounter_u8; - uint8_t SendDataType_u8; - uint8_t FollowBytesFlag_u8; - uint8_t SendSize_u8; - - std::string dissect() const { - std::stringstream ss; - ss << "_padding:" << std::endl - << ::nitrokey::misc::hexdump((const uint8_t *) (_padding), - sizeof _padding); - print_to_ss((int) SendCounter_u8); - print_to_ss((int) SendDataType_u8); - print_to_ss((int) FollowBytesFlag_u8); - print_to_ss((int) SendSize_u8); - return ss.str(); - } - - } __packed; - } - - namespace DeviceConfigurationResponsePacket{ - - struct ResponsePayload { - StorageCommandResponsePayload::TransmissionData transmission_data; - - uint16_t MagicNumber_StickConfig_u16; - /** - * READ_WRITE_ACTIVE = ReadWriteFlagUncryptedVolume_u8 == 0; - */ - uint8_t ReadWriteFlagUncryptedVolume_u8; - uint8_t ReadWriteFlagCryptedVolume_u8; - - union{ - uint8_t VersionInfo_au8[4]; - struct { - uint8_t major; - uint8_t minor; - uint8_t _reserved2; - uint8_t build_iteration; - } __packed versionInfo; - } __packed; - - uint8_t ReadWriteFlagHiddenVolume_u8; - uint8_t FirmwareLocked_u8; - - union{ - uint8_t NewSDCardFound_u8; - struct { - bool NewCard :1; - uint8_t Counter :7; - } __packed NewSDCardFound_st; - } __packed; - - /** - * SD card FILLED with random chars - */ - uint8_t SDFillWithRandomChars_u8; - uint32_t ActiveSD_CardID_u32; - union{ - uint8_t VolumeActiceFlag_u8; - struct { - bool unencrypted :1; - bool encrypted :1; - bool hidden :1; - } __packed VolumeActiceFlag_st; - } __packed; - uint8_t NewSmartCardFound_u8; - uint8_t UserPwRetryCount; - uint8_t AdminPwRetryCount; - uint32_t ActiveSmartCardID_u32; - uint8_t StickKeysNotInitiated; - - bool isValid() const { return true; } - - std::string dissect() const { - std::stringstream ss; - - print_to_ss(transmission_data.dissect()); - print_to_ss( MagicNumber_StickConfig_u16 ); - print_to_ss((int) ReadWriteFlagUncryptedVolume_u8 ); - print_to_ss((int) ReadWriteFlagCryptedVolume_u8 ); - print_to_ss((int) ReadWriteFlagHiddenVolume_u8 ); - print_to_ss((int) versionInfo.major ); - print_to_ss((int) versionInfo.minor ); - print_to_ss((int) versionInfo.build_iteration ); - print_to_ss((int) FirmwareLocked_u8 ); - print_to_ss((int) NewSDCardFound_u8 ); - print_to_ss((int) NewSDCardFound_st.NewCard ); - print_to_ss((int) NewSDCardFound_st.Counter ); - print_to_ss((int) SDFillWithRandomChars_u8 ); - print_to_ss( ActiveSD_CardID_u32 ); - print_to_ss((int) VolumeActiceFlag_u8 ); - print_to_ss((int) VolumeActiceFlag_st.unencrypted ); - print_to_ss((int) VolumeActiceFlag_st.encrypted ); - print_to_ss((int) VolumeActiceFlag_st.hidden); - print_to_ss((int) NewSmartCardFound_u8 ); - print_to_ss((int) UserPwRetryCount ); - print_to_ss((int) AdminPwRetryCount ); - print_to_ss( ActiveSmartCardID_u32 ); - print_to_ss((int) StickKeysNotInitiated ); - - return ss.str(); - } - } __packed; - } - - class SendStartup : Command { - public: - struct CommandPayload { - uint64_t localtime; // POSIX seconds from epoch start, supports until year 2106 - std::string dissect() const { - std::stringstream ss; - print_to_ss( localtime ); - return ss.str(); - } - void set_defaults(){ - localtime = - std::chrono::duration_cast ( - std::chrono::system_clock::now().time_since_epoch()).count(); - } - }__packed; - - using ResponsePayload = DeviceConfigurationResponsePacket::ResponsePayload; - - typedef Transaction - CommandTransaction; - }; - - -// TODO fix original nomenclature - class SendSetReadonlyToUncryptedVolume : public PasswordCommand {}; - class SendSetReadwriteToUncryptedVolume : public PasswordCommand {}; - class SendClearNewSdCardFound : public PasswordCommand {}; - - class GetDeviceStatus : Command { - public: - using ResponsePayload = DeviceConfigurationResponsePacket::ResponsePayload; - - typedef Transaction - CommandTransaction; - }; - - class Wink : Command { - public: - typedef Transaction - CommandTransaction; - }; - - class CheckSmartcardUsage : Command { - public: - typedef Transaction - CommandTransaction; - }; - - class GetSDCardOccupancy : Command { - public: - struct ResponsePayload { - uint8_t WriteLevelMin; - uint8_t WriteLevelMax; - uint8_t ReadLevelMin; - uint8_t ReadLevelMax; - std::string dissect() const { - std::stringstream ss; - print_to_ss((int) WriteLevelMin); - print_to_ss((int) WriteLevelMax); - print_to_ss((int) ReadLevelMin); - print_to_ss((int) ReadLevelMax); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - - class SetupHiddenVolume : Command { - public: - constexpr static int MAX_HIDDEN_VOLUME_PASSWORD_SIZE = 20; - struct CommandPayload { - uint8_t SlotNr_u8; - uint8_t StartBlockPercent_u8; - uint8_t EndBlockPercent_u8; - uint8_t HiddenVolumePassword_au8[MAX_HIDDEN_VOLUME_PASSWORD_SIZE]; - std::string dissect() const { - std::stringstream ss; - print_to_ss((int) SlotNr_u8); - print_to_ss((int) StartBlockPercent_u8); - print_to_ss((int) EndBlockPercent_u8); - print_to_ss_volatile(HiddenVolumePassword_au8); - return ss.str(); - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - -//disable this command for now -// class LockFirmware : public PasswordCommand {}; - - class ProductionTest : Command { - public: - struct ResponsePayload { - - StorageCommandResponsePayload::TransmissionData transmission_data; - - uint8_t FirmwareVersion_au8[2]; // 2 byte // 2 - uint8_t FirmwareVersionInternal_u8; // 1 byte // 3 - uint8_t SD_Card_Size_u8; // 1 byte // 4 - uint32_t CPU_CardID_u32; // 4 byte // 8 - uint32_t SmartCardID_u32; // 4 byte // 12 - uint32_t SD_CardID_u32; // 4 byte // 16 - uint8_t SC_UserPwRetryCount; // User PIN retry count 1 byte // 17 - uint8_t SC_AdminPwRetryCount; // Admin PIN retry count 1 byte // 18 - uint8_t SD_Card_ManufacturingYear_u8; // 1 byte // 19 - uint8_t SD_Card_ManufacturingMonth_u8; // 1 byte // 20 - uint16_t SD_Card_OEM_u16; // 2 byte // 22 - uint16_t SD_WriteSpeed_u16; // in kbyte / sec 2 byte // 24 - uint8_t SD_Card_Manufacturer_u8; // 1 byte // 25 - - bool isValid() const { return true; } - - std::string dissect() const { - std::stringstream ss; - - print_to_ss(transmission_data.dissect()); - print_to_ss((int) FirmwareVersion_au8[0]); - print_to_ss((int) FirmwareVersion_au8[1]); - print_to_ss((int) FirmwareVersionInternal_u8); - print_to_ss((int) SD_Card_Size_u8); - print_to_ss( CPU_CardID_u32); - print_to_ss( SmartCardID_u32); - print_to_ss( SD_CardID_u32); - print_to_ss((int) SC_UserPwRetryCount); - print_to_ss((int) SC_AdminPwRetryCount); - print_to_ss((int) SD_Card_ManufacturingYear_u8); - print_to_ss((int) SD_Card_ManufacturingMonth_u8); - print_to_ss( SD_Card_OEM_u16); - print_to_ss( SD_WriteSpeed_u16); - print_to_ss((int) SD_Card_Manufacturer_u8); - return ss.str(); - } - - } __packed; - - typedef Transaction - CommandTransaction; - }; - - } - } -} - -#undef print_to_ss -#pragma pack (pop) - -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/version.h b/nitrokey-sys/libnitrokey-v3.5/libnitrokey/version.h deleted file mode 100644 index 6547af0..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/libnitrokey/version.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#ifndef LIBNITROKEY_VERSION_H -#define LIBNITROKEY_VERSION_H - -namespace nitrokey { - unsigned int get_major_library_version(); - - unsigned int get_minor_library_version(); - - const char* get_library_version(); -} - -#endif diff --git a/nitrokey-sys/libnitrokey-v3.5/log.cc b/nitrokey-sys/libnitrokey-v3.5/log.cc deleted file mode 100644 index 06acee7..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/log.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include "log.h" -#include -#include -#include - -#include - -namespace nitrokey { - namespace log { - - Log *Log::mp_instance = nullptr; - StdlogHandler stdlog_handler; - - std::string Log::prefix = ""; - - - std::string LogHandler::loglevel_to_str(Loglevel lvl) { - switch (lvl) { - case Loglevel::DEBUG_L1: - return std::string("DEBUG_L1"); - case Loglevel::DEBUG_L2: - return std::string("DEBUG_L2"); - case Loglevel::DEBUG: - return std::string("DEBUG"); - case Loglevel::INFO: - return std::string("INFO"); - case Loglevel::WARNING: - return std::string("WARNING"); - case Loglevel::ERROR: - return std::string("ERROR"); - } - return std::string(""); - } - - void Log::operator()(const std::string &logstr, Loglevel lvl) { - if (mp_loghandler != nullptr){ - if ((int) lvl <= (int) m_loglevel) mp_loghandler->print(prefix+logstr, lvl); - } - } - - void Log::setPrefix(const std::string prefix) { - if (!prefix.empty()){ - Log::prefix = "["+prefix+"]"; - } else { - Log::prefix = ""; - } - } - - void StdlogHandler::print(const std::string &str, Loglevel lvl) { - std::string s = format_message_to_string(str, lvl); - std::clog << s; - } - - void FunctionalLogHandler::print(const std::string &str, Loglevel lvl) { - std::string s = format_message_to_string(str, lvl); - log_function(s); - } - - std::string LogHandler::format_message_to_string(const std::string &str, const Loglevel &lvl) { - static bool last_short = false; - if (str.length() == 1){ - last_short = true; - return str; - } - time_t t = time(nullptr); - tm tm = *localtime(&t); - - std::stringstream s; - s - << (last_short? "\n" : "") - << "[" << std::put_time(&tm, "%c") << "]" - << "[" << loglevel_to_str(lvl) << "]\t" - << str << std::endl; - last_short = false; - return s.str(); - } - - FunctionalLogHandler::FunctionalLogHandler(log_function_type _log_function) { - log_function = _log_function; - } - } -} diff --git a/nitrokey-sys/libnitrokey-v3.5/misc.cc b/nitrokey-sys/libnitrokey-v3.5/misc.cc deleted file mode 100644 index 59185f3..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/misc.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2015-2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include -#include -#include "misc.h" -#include "inttypes.h" -#include -#include -#include "LibraryException.h" -#include - -namespace nitrokey { -namespace misc { - - - -::std::vector hex_string_to_byte(const char* hexString){ - const size_t big_string_size = 257; //arbitrary 'big' number - const size_t s_size = strnlen(hexString, big_string_size); - const size_t d_size = s_size/2; - if (s_size%2!=0 || s_size>=big_string_size){ - throw InvalidHexString(0); - } - auto data = ::std::vector(); - data.reserve(d_size); - - char buf[3]; - buf[2] = '\0'; - for(size_t i=0; i -::std::string hexdump(const uint8_t *p, size_t size, bool print_header, - bool print_ascii, bool print_empty) { - ::std::stringstream out; - char formatbuf[128]; - const uint8_t *pstart = p; - - for (const uint8_t *pend = p + size; p < pend;) { - if (print_header){ - snprintf(formatbuf, 128, "%04x\t", static_cast (p - pstart)); - out << formatbuf; - } - - const uint8_t* pp = p; - for (const uint8_t *le = p + 16; p < le; p++) { - if (p < pend){ - snprintf(formatbuf, 128, "%02x ", uint8_t(*p)); - out << formatbuf; - } else { - if(print_empty) - out << "-- "; - } - - } - if(print_ascii){ - out << " "; - for (const uint8_t *le = pp + 16; pp < le && pp < pend; pp++) { - if (std::isgraph(*pp)) - out << uint8_t(*pp); - else - out << '.'; - } - } - out << ::std::endl; - } - return out.str(); -} - -static uint32_t _crc32(uint32_t crc, uint32_t data) { - int i; - crc = crc ^ data; - - for (i = 0; i < 32; i++) { - if (crc & 0x80000000) - crc = (crc << 1) ^ 0x04C11DB7; // polynomial used in STM32 - else - crc = (crc << 1); - } - - return crc; -} - -uint32_t stm_crc32(const uint8_t *data, size_t size) { - uint32_t crc = 0xffffffff; - const uint32_t *pend = (const uint32_t *)(data + size); - for (const uint32_t *p = (const uint32_t *)(data); p < pend; p++) - crc = _crc32(crc, *p); - return crc; -} -} -} diff --git a/nitrokey-sys/libnitrokey-v3.5/version.cc b/nitrokey-sys/libnitrokey-v3.5/version.cc deleted file mode 100644 index dfdc802..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/version.cc +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include "version.h" - -namespace nitrokey { - unsigned int get_major_library_version() { - return 3; - } - - unsigned int get_minor_library_version() { - return 0; - } - - const char* get_library_version() { - return "unknown"; - } -} - diff --git a/nitrokey-sys/libnitrokey-v3.5/version.cc.in b/nitrokey-sys/libnitrokey-v3.5/version.cc.in deleted file mode 100644 index 0eae647..0000000 --- a/nitrokey-sys/libnitrokey-v3.5/version.cc.in +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2018 Nitrokey UG - * - * This file is part of libnitrokey. - * - * libnitrokey is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * libnitrokey is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libnitrokey. If not, see . - * - * SPDX-License-Identifier: LGPL-3.0 - */ - -#include "version.h" - -namespace nitrokey { - unsigned int get_major_library_version() { - return @PROJECT_VERSION_MAJOR@; - } - - unsigned int get_minor_library_version() { - return @PROJECT_VERSION_MINOR@; - } - - const char* get_library_version() { - return "@PROJECT_VERSION_GIT@"; - } -} - diff --git a/nitrokey-sys/src/ffi.rs b/nitrokey-sys/src/ffi.rs deleted file mode 100644 index a01eae8..0000000 --- a/nitrokey-sys/src/ffi.rs +++ /dev/null @@ -1,1481 +0,0 @@ -/* automatically generated by rust-bindgen, manually modified */ - -extern "C" { - #[link_name = "\u{1}NK_PWS_SLOT_COUNT"] - pub static mut NK_PWS_SLOT_COUNT: u8; -} -pub const MAXIMUM_STR_REPLY_LENGTH: ::std::os::raw::c_int = 8192; -/// Use, if no supported device is connected -pub const NK_device_model_NK_DISCONNECTED: NK_device_model = 0; -/// Nitrokey Pro. -pub const NK_device_model_NK_PRO: NK_device_model = 1; -/// Nitrokey Storage. -pub const NK_device_model_NK_STORAGE: NK_device_model = 2; -/// The Nitrokey device models supported by the API. -pub type NK_device_model = u32; -/// The connection info for a Nitrokey device as a linked list. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct NK_device_info { - /// The model of the Nitrokey device. - pub model: NK_device_model, - /// The USB device path for NK_connect_with_path. - pub path: *mut ::std::os::raw::c_char, - /// The serial number. - pub serial_number: *mut ::std::os::raw::c_char, - /// The pointer to the next element of the linked list or null - /// if this is the last element in the list. - pub next: *mut NK_device_info, -} -#[test] -fn bindgen_test_layout_NK_device_info() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(NK_device_info)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(NK_device_info)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).model as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(model) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).path as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(path) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).serial_number as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(serial_number) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).next as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_device_info), - "::", - stringify!(next) - ) - ); -} -/// Stores the common device status for all Nitrokey devices. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct NK_status { - /// The major firmware version, e. g. 0 in v0.40. - pub firmware_version_major: u8, - /// The minor firmware version, e. g. 40 in v0.40. - pub firmware_version_minor: u8, - /// The serial number of the smart card. - pub serial_number_smart_card: u32, - /// The HOTP slot to generate a password from if the numlock - /// key is pressed twice (slot 0-1, or any other value to - /// disable the function). - pub config_numlock: u8, - /// The HOTP slot to generate a password from if the capslock - /// key is pressed twice (slot 0-1, or any other value to - /// disable the function). - pub config_capslock: u8, - /// The HOTP slot to generate a password from if the scrolllock - /// key is pressed twice (slot 0-1, or any other value to - /// disable the function). - pub config_scrolllock: u8, - /// Indicates whether the user password is required to generate - /// an OTP value. - pub otp_user_password: bool, -} -#[test] -fn bindgen_test_layout_NK_status() { - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(NK_status)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NK_status)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_version_major as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(firmware_version_major) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_version_minor as *const _ as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(firmware_version_minor) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).serial_number_smart_card as *const _ as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(serial_number_smart_card) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).config_numlock as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_numlock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).config_capslock as *const _ as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_capslock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).config_scrolllock as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(config_scrolllock) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).otp_user_password as *const _ as usize }, - 11usize, - concat!( - "Offset of field: ", - stringify!(NK_status), - "::", - stringify!(otp_user_password) - ) - ); -} -/// Stores the status of a Storage device. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct NK_storage_status { - /// Indicates whether the unencrypted volume is read-only. - pub unencrypted_volume_read_only: bool, - /// Indicates whether the unencrypted volume is active. - pub unencrypted_volume_active: bool, - /// Indicates whether the encrypted volume is read-only. - pub encrypted_volume_read_only: bool, - /// Indicates whether the encrypted volume is active. - pub encrypted_volume_active: bool, - /// Indicates whether the hidden volume is read-only. - pub hidden_volume_read_only: bool, - /// Indicates whether the hidden volume is active. - pub hidden_volume_active: bool, - /// The major firmware version, e. g. 0 in v0.40. - pub firmware_version_major: u8, - /// The minor firmware version, e. g. 40 in v0.40. - pub firmware_version_minor: u8, - /// Indicates whether the firmware is locked. - pub firmware_locked: bool, - /// The serial number of the SD card in the Storage stick. - pub serial_number_sd_card: u32, - /// The serial number of the smart card in the Storage stick. - pub serial_number_smart_card: u32, - /// The number of remaining login attempts for the user PIN. - pub user_retry_count: u8, - /// The number of remaining login attempts for the admin PIN. - pub admin_retry_count: u8, - /// Indicates whether a new SD card was found. - pub new_sd_card_found: bool, - /// Indicates whether the SD card is filled with random characters. - pub filled_with_random: bool, - /// Indicates whether the stick has been initialized by generating - /// the AES keys. - pub stick_initialized: bool, -} -#[test] -fn bindgen_test_layout_NK_storage_status() { - assert_eq!( - ::std::mem::size_of::(), - 28usize, - concat!("Size of: ", stringify!(NK_storage_status)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NK_storage_status)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).unencrypted_volume_read_only as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(unencrypted_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).unencrypted_volume_active as *const _ - as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(unencrypted_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).encrypted_volume_read_only as *const _ - as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(encrypted_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).encrypted_volume_active as *const _ - as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(encrypted_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hidden_volume_read_only as *const _ - as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(hidden_volume_read_only) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hidden_volume_active as *const _ as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(hidden_volume_active) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_version_major as *const _ - as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_version_major) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_version_minor as *const _ - as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_version_minor) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).firmware_locked as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(firmware_locked) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).serial_number_sd_card as *const _ as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(serial_number_sd_card) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).serial_number_smart_card as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(serial_number_smart_card) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).user_retry_count as *const _ as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(user_retry_count) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).admin_retry_count as *const _ as usize - }, - 21usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(admin_retry_count) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).new_sd_card_found as *const _ as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(new_sd_card_found) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).filled_with_random as *const _ as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(filled_with_random) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).stick_initialized as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_status), - "::", - stringify!(stick_initialized) - ) - ); -} -/// Data about the usage of the SD card. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct NK_SD_usage_data { - /// The minimum write level, as a percentage of the total card - /// size. - pub write_level_min: u8, - /// The maximum write level, as a percentage of the total card - /// size. - pub write_level_max: u8, -} -#[test] -fn bindgen_test_layout_NK_SD_usage_data() { - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(NK_SD_usage_data)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NK_SD_usage_data)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).write_level_min as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_SD_usage_data), - "::", - stringify!(write_level_min) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).write_level_max as *const _ as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(NK_SD_usage_data), - "::", - stringify!(write_level_max) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct NK_storage_ProductionTest { - pub FirmwareVersion_au8: [u8; 2usize], - pub FirmwareVersionInternal_u8: u8, - pub SD_Card_Size_u8: u8, - pub CPU_CardID_u32: u32, - pub SmartCardID_u32: u32, - pub SD_CardID_u32: u32, - pub SC_UserPwRetryCount: u8, - pub SC_AdminPwRetryCount: u8, - pub SD_Card_ManufacturingYear_u8: u8, - pub SD_Card_ManufacturingMonth_u8: u8, - pub SD_Card_OEM_u16: u16, - pub SD_WriteSpeed_u16: u16, - pub SD_Card_Manufacturer_u8: u8, -} -#[test] -fn bindgen_test_layout_NK_storage_ProductionTest() { - assert_eq!( - ::std::mem::size_of::(), - 28usize, - concat!("Size of: ", stringify!(NK_storage_ProductionTest)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NK_storage_ProductionTest)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).FirmwareVersion_au8 as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(FirmwareVersion_au8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).FirmwareVersionInternal_u8 - as *const _ as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(FirmwareVersionInternal_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_Size_u8 as *const _ - as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_Size_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).CPU_CardID_u32 as *const _ - as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(CPU_CardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SmartCardID_u32 as *const _ - as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SmartCardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_CardID_u32 as *const _ as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_CardID_u32) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SC_UserPwRetryCount as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SC_UserPwRetryCount) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SC_AdminPwRetryCount as *const _ - as usize - }, - 17usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SC_AdminPwRetryCount) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_ManufacturingYear_u8 - as *const _ as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_ManufacturingYear_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_ManufacturingMonth_u8 - as *const _ as usize - }, - 19usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_ManufacturingMonth_u8) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_OEM_u16 as *const _ - as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_OEM_u16) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_WriteSpeed_u16 as *const _ - as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_WriteSpeed_u16) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).SD_Card_Manufacturer_u8 - as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(NK_storage_ProductionTest), - "::", - stringify!(SD_Card_Manufacturer_u8) - ) - ); -} -extern "C" { - pub fn NK_get_storage_production_info( - out: *mut NK_storage_ProductionTest, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Set debug level of messages written on stderr - /// @param state state=True - most messages, state=False - only errors level - pub fn NK_set_debug(state: bool); -} -extern "C" { - /// Set debug level of messages written on stderr - /// @param level (int) 0-lowest verbosity, 5-highest verbosity - pub fn NK_set_debug_level(level: ::std::os::raw::c_int); -} -extern "C" { - /// Get the major library version, e. g. the 3 in v3.2. - /// @return the major library version - pub fn NK_get_major_library_version() -> ::std::os::raw::c_uint; -} -extern "C" { - /// Get the minor library version, e. g. the 2 in v3.2. - /// @return the minor library version - pub fn NK_get_minor_library_version() -> ::std::os::raw::c_uint; -} -extern "C" { - /// Get the library version as a string. This is the output of - /// `git describe --always` at compile time, for example "v3.3" or - /// "v3.3-19-gaee920b". - /// The return value is a string literal and must not be freed. - /// @return the library version as a string - pub fn NK_get_library_version() -> *const ::std::os::raw::c_char; -} -extern "C" { - /// Connect to device of given model. Currently library can be connected only to one device at once. - /// @param device_model char 'S': Nitrokey Storage, 'P': Nitrokey Pro - /// @return 1 if connected, 0 if wrong model or cannot connect - pub fn NK_login(device_model: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; -} -extern "C" { - /// Connect to device of given model. Currently library can be connected only to one device at once. - /// @param device_model NK_device_model: NK_PRO: Nitrokey Pro, NK_STORAGE: Nitrokey Storage - /// @return 1 if connected, 0 if wrong model or cannot connect - pub fn NK_login_enum(device_model: NK_device_model) -> ::std::os::raw::c_int; -} -extern "C" { - /// Connect to first available device, starting checking from Pro 1st to Storage 2nd. - /// @return 1 if connected, 0 if wrong model or cannot connect - pub fn NK_login_auto() -> ::std::os::raw::c_int; -} -extern "C" { - /// Disconnect from the device. - /// @return command processing error code - pub fn NK_logout() -> ::std::os::raw::c_int; -} -extern "C" { - /// Query the model of the connected device. - /// Returns the model of the connected device or NK_DISCONNECTED. - /// - /// @return true if a device is connected and the out argument has been set - pub fn NK_get_device_model() -> NK_device_model; -} -extern "C" { - /// Return the debug status string. Debug purposes. This function is - /// deprecated in favor of NK_get_status_as_string. - /// @return string representation of the status or an empty string - /// if the command failed - #[deprecated(since = "3.5.0", note="use `NK_get_status_as_string` instead")] - pub fn NK_status() -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Return the debug status string. Debug purposes. - /// @return string representation of the status or an empty string - /// if the command failed - pub fn NK_get_status_as_string() -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get the stick status common to all Nitrokey devices and return the - /// command processing error code. If the code is zero, i. e. the - /// command was successful, the storage status is written to the output - /// pointer's target. The output pointer must not be null. - /// - /// @param out the output pointer for the status - /// @return command processing error code - pub fn NK_get_status(out: *mut NK_status) -> ::std::os::raw::c_int; -} -extern "C" { - /// Return the device's serial number string in hex. - /// @return string device's serial number in hex - pub fn NK_device_serial_number() -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get last command processing status. Useful for commands which returns the results of their own and could not return - /// an error code. - /// @return previous command processing error code - pub fn NK_get_last_command_status() -> u8; -} -extern "C" { - /// Lock device - cancel any user device unlocking. - /// @return command processing error code - pub fn NK_lock_device() -> ::std::os::raw::c_int; -} -extern "C" { - /// Authenticates the user on USER privilages with user_password and sets user's temporary password on device to user_temporary_password. - /// @param user_password char[25] current user password - /// @param user_temporary_password char[25] user temporary password to be set on device for further communication (authentication command) - /// @return command processing error code - pub fn NK_user_authenticate( - user_password: *const ::std::os::raw::c_char, - user_temporary_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Authenticates the user on ADMIN privilages with admin_password and sets user's temporary password on device to admin_temporary_password. - /// @param admin_password char[25] current administrator PIN - /// @param admin_temporary_password char[25] admin temporary password to be set on device for further communication (authentication command) - /// @return command processing error code - pub fn NK_first_authenticate( - admin_password: *const ::std::os::raw::c_char, - admin_temporary_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Execute a factory reset. - /// @param admin_password char[20] current administrator PIN - /// @return command processing error code - pub fn NK_factory_reset(admin_password: *const ::std::os::raw::c_char) - -> ::std::os::raw::c_int; -} -extern "C" { - /// Generates AES key on the device - /// @param admin_password char[20] current administrator PIN - /// @return command processing error code - pub fn NK_build_aes_key(admin_password: *const ::std::os::raw::c_char) - -> ::std::os::raw::c_int; -} -extern "C" { - /// Unlock user PIN locked after 3 incorrect codes tries. - /// @param admin_password char[20] current administrator PIN - /// @return command processing error code - pub fn NK_unlock_user_password( - admin_password: *const ::std::os::raw::c_char, - new_user_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Write general config to the device - /// @param numlock set value in range [0-1] to send HOTP code from slot 'numlock' after double pressing numlock - /// or outside the range to disable this function - /// @param capslock similar to numlock but with capslock - /// @param scrolllock similar to numlock but with scrolllock - /// @param enable_user_password set True to enable OTP PIN protection (require PIN each OTP code request) - /// @param delete_user_password (unused) - /// @param admin_temporary_password current admin temporary password - /// @return command processing error code - pub fn NK_write_config( - numlock: u8, - capslock: u8, - scrolllock: u8, - enable_user_password: bool, - delete_user_password: bool, - admin_temporary_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Get currently set config - status of function Numlock/Capslock/Scrollock OTP sending and is enabled PIN protected OTP - /// @see NK_write_config - /// @return uint8_t general_config[5]: - /// uint8_t numlock; - /// uint8_t capslock; - /// uint8_t scrolllock; - /// uint8_t enable_user_password; - /// uint8_t delete_user_password; - pub fn NK_read_config() -> *mut u8; -} -extern "C" { - /// Get name of given TOTP slot - /// @param slot_number TOTP slot number, slot_number<15 - /// @return char[20] the name of the slot - pub fn NK_get_totp_slot_name(slot_number: u8) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// @param slot_number HOTP slot number, slot_number<3 - /// @return char[20] the name of the slot - pub fn NK_get_hotp_slot_name(slot_number: u8) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Erase HOTP slot data from the device - /// @param slot_number HOTP slot number, slot_number<3 - /// @param temporary_password admin temporary password - /// @return command processing error code - pub fn NK_erase_hotp_slot( - slot_number: u8, - temporary_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Erase TOTP slot data from the device - /// @param slot_number TOTP slot number, slot_number<15 - /// @param temporary_password admin temporary password - /// @return command processing error code - pub fn NK_erase_totp_slot( - slot_number: u8, - temporary_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Write HOTP slot data to the device - /// @param slot_number HOTP slot number, slot_number<3, 0-numbered - /// @param slot_name char[15] desired slot name. C string (requires ending '\0'; 16 bytes). - /// @param secret char[40] 160-bit or 320-bit (currently Pro v0.8 only) secret as a hex string. C string (requires ending '\0'; 41 bytes). - /// See NitrokeyManager::is_320_OTP_secret_supported. - /// @param hotp_counter uint32_t starting value of HOTP counter - /// @param use_8_digits should returned codes be 6 (false) or 8 digits (true) - /// @param use_enter press ENTER key after sending OTP code using double-pressed scroll/num/capslock - /// @param use_tokenID @see token_ID - /// @param token_ID @see https://openauthentication.org/token-specs/, 'Class A' section - /// @param temporary_password char[25] admin temporary password - /// @return command processing error code - pub fn NK_write_hotp_slot( - slot_number: u8, - slot_name: *const ::std::os::raw::c_char, - secret: *const ::std::os::raw::c_char, - hotp_counter: u64, - use_8_digits: bool, - use_enter: bool, - use_tokenID: bool, - token_ID: *const ::std::os::raw::c_char, - temporary_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Write TOTP slot data to the device - /// @param slot_number TOTP slot number, slot_number<15, 0-numbered - /// @param slot_name char[15] desired slot name. C string (requires ending '\0'; 16 bytes). - /// @param secret char[40] 160-bit or 320-bit (currently Pro v0.8 only) secret as a hex string. C string (requires ending '\0'; 41 bytes). - /// See NitrokeyManager::is_320_OTP_secret_supported. - /// @param time_window uint16_t time window for this TOTP - /// @param use_8_digits should returned codes be 6 (false) or 8 digits (true) - /// @param use_enter press ENTER key after sending OTP code using double-pressed scroll/num/capslock - /// @param use_tokenID @see token_ID - /// @param token_ID @see https://openauthentication.org/token-specs/, 'Class A' section - /// @param temporary_password char[20] admin temporary password - /// @return command processing error code - pub fn NK_write_totp_slot( - slot_number: u8, - slot_name: *const ::std::os::raw::c_char, - secret: *const ::std::os::raw::c_char, - time_window: u16, - use_8_digits: bool, - use_enter: bool, - use_tokenID: bool, - token_ID: *const ::std::os::raw::c_char, - temporary_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Get HOTP code from the device - /// @param slot_number HOTP slot number, slot_number<3 - /// @return HOTP code - pub fn NK_get_hotp_code(slot_number: u8) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get HOTP code from the device (PIN protected) - /// @param slot_number HOTP slot number, slot_number<3 - /// @param user_temporary_password char[25] user temporary password if PIN protected OTP codes are enabled, - /// otherwise should be set to empty string - '' - /// @return HOTP code - pub fn NK_get_hotp_code_PIN( - slot_number: u8, - user_temporary_password: *const ::std::os::raw::c_char, - ) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get TOTP code from the device - /// @param slot_number TOTP slot number, slot_number<15 - /// @param challenge TOTP challenge -- unused - /// @param last_totp_time last time -- unused - /// @param last_interval last interval --unused - /// @return TOTP code - pub fn NK_get_totp_code( - slot_number: u8, - challenge: u64, - last_totp_time: u64, - last_interval: u8, - ) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get TOTP code from the device (PIN protected) - /// @param slot_number TOTP slot number, slot_number<15 - /// @param challenge TOTP challenge -- unused - /// @param last_totp_time last time -- unused - /// @param last_interval last interval -- unused - /// @param user_temporary_password char[25] user temporary password if PIN protected OTP codes are enabled, - /// otherwise should be set to empty string - '' - /// @return TOTP code - pub fn NK_get_totp_code_PIN( - slot_number: u8, - challenge: u64, - last_totp_time: u64, - last_interval: u8, - user_temporary_password: *const ::std::os::raw::c_char, - ) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Set time on the device (for TOTP requests) - /// @param time seconds in unix epoch (from 01.01.1970) - /// @return command processing error code - pub fn NK_totp_set_time(time: u64) -> ::std::os::raw::c_int; -} -extern "C" { - /// Set the device time used for TOTP to the given time. Contrary to - /// {@code set_time(uint64_t)}, this command fails if {@code old_time} - /// > {@code time} or if {@code old_time} is zero (where {@code - /// old_time} is the current time on the device). - /// - /// @param time new device time as Unix timestamp (seconds since - /// 1970-01-01) - /// @return command processing error code - pub fn NK_totp_set_time_soft(time: u64) -> ::std::os::raw::c_int; -} -extern "C" { - #[deprecated(since = "3.4.0", note="use `NK_totp_set_time_soft` instead")] - pub fn NK_totp_get_time() -> ::std::os::raw::c_int; -} -extern "C" { - /// Change administrator PIN - /// @param current_PIN char[25] current PIN - /// @param new_PIN char[25] new PIN - /// @return command processing error code - pub fn NK_change_admin_PIN( - current_PIN: *const ::std::os::raw::c_char, - new_PIN: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Change user PIN - /// @param current_PIN char[25] current PIN - /// @param new_PIN char[25] new PIN - /// @return command processing error code - pub fn NK_change_user_PIN( - current_PIN: *const ::std::os::raw::c_char, - new_PIN: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Get retry count of user PIN - /// @return user PIN retry count - pub fn NK_get_user_retry_count() -> u8; -} -extern "C" { - /// Get retry count of admin PIN - /// @return admin PIN retry count - pub fn NK_get_admin_retry_count() -> u8; -} -extern "C" { - /// Enable password safe access - /// @param user_pin char[30] current user PIN - /// @return command processing error code - pub fn NK_enable_password_safe( - user_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Get password safe slots' status - /// @return uint8_t[16] slot statuses - each byte represents one slot with 0 (not programmed) and 1 (programmed) - pub fn NK_get_password_safe_slot_status() -> *mut u8; -} -extern "C" { - /// Get password safe slot name - /// @param slot_number password safe slot number, slot_number<16 - /// @return slot name - pub fn NK_get_password_safe_slot_name(slot_number: u8) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get password safe slot login - /// @param slot_number password safe slot number, slot_number<16 - /// @return login from the PWS slot - pub fn NK_get_password_safe_slot_login(slot_number: u8) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get the password safe slot password - /// @param slot_number password safe slot number, slot_number<16 - /// @return password from the PWS slot - pub fn NK_get_password_safe_slot_password(slot_number: u8) -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Write password safe data to the slot - /// @param slot_number password safe slot number, slot_number<16 - /// @param slot_name char[11] name of the slot - /// @param slot_login char[32] login string - /// @param slot_password char[20] password string - /// @return command processing error code - pub fn NK_write_password_safe_slot( - slot_number: u8, - slot_name: *const ::std::os::raw::c_char, - slot_login: *const ::std::os::raw::c_char, - slot_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Erase the password safe slot from the device - /// @param slot_number password safe slot number, slot_number<16 - /// @return command processing error code - pub fn NK_erase_password_safe_slot(slot_number: u8) -> ::std::os::raw::c_int; -} -extern "C" { - /// Check whether AES is supported by the device - /// @return 0 for no and 1 for yes - pub fn NK_is_AES_supported( - user_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Get device's major firmware version - /// @return major part of the version number (e.g. 0 from 0.48, 0 from 0.7 etc.) - pub fn NK_get_major_firmware_version() -> u8; -} -extern "C" { - /// Get device's minor firmware version - /// @return minor part of the version number (e.g. 7 from 0.7, 48 from 0.48 etc.) - pub fn NK_get_minor_firmware_version() -> u8; -} -extern "C" { - /// Function to determine unencrypted volume PIN type - /// @param minor_firmware_version - /// @return Returns 1, if set unencrypted volume ro/rw pin type is User, 0 otherwise. - pub fn NK_set_unencrypted_volume_rorw_pin_type_user() -> ::std::os::raw::c_int; -} -extern "C" { - /// This command is typically run to initiate - /// communication with the device (altough not required). - /// It sets time on device and returns its current status - /// - a combination of set_time and get_status_storage commands - /// Storage only - /// @param seconds_from_epoch date and time expressed in seconds - pub fn NK_send_startup(seconds_from_epoch: u64) -> ::std::os::raw::c_int; -} -extern "C" { - /// Unlock encrypted volume. - /// Storage only - /// @param user_pin user pin 20 characters - /// @return command processing error code - pub fn NK_unlock_encrypted_volume( - user_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Locks encrypted volume - /// @return command processing error code - pub fn NK_lock_encrypted_volume() -> ::std::os::raw::c_int; -} -extern "C" { - /// Unlock hidden volume and lock encrypted volume. - /// Requires encrypted volume to be unlocked. - /// Storage only - /// @param hidden_volume_password 20 characters - /// @return command processing error code - pub fn NK_unlock_hidden_volume( - hidden_volume_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Locks hidden volume - /// @return command processing error code - pub fn NK_lock_hidden_volume() -> ::std::os::raw::c_int; -} -extern "C" { - /// Create hidden volume. - /// Requires encrypted volume to be unlocked. - /// Storage only - /// @param slot_nr slot number in range 0-3 - /// @param start_percent volume begin expressed in percent of total available storage, int in range 0-99 - /// @param end_percent volume end expressed in percent of total available storage, int in range 1-100 - /// @param hidden_volume_password 20 characters - /// @return command processing error code - pub fn NK_create_hidden_volume( - slot_nr: u8, - start_percent: u8, - end_percent: u8, - hidden_volume_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Make unencrypted volume read-only. - /// Device hides unencrypted volume for a second therefore make sure - /// buffers are flushed before running. - /// Does nothing if firmware version is not matched - /// Firmware range: Storage v0.50, v0.48 and below - /// Storage only - /// @param user_pin 20 characters User PIN - /// @return command processing error code - pub fn NK_set_unencrypted_read_only( - user_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Make unencrypted volume read-write. - /// Device hides unencrypted volume for a second therefore make sure - /// buffers are flushed before running. - /// Does nothing if firmware version is not matched - /// Firmware range: Storage v0.50, v0.48 and below - /// Storage only - /// @param user_pin 20 characters User PIN - /// @return command processing error code - pub fn NK_set_unencrypted_read_write( - user_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Make unencrypted volume read-only. - /// Device hides unencrypted volume for a second therefore make sure - /// buffers are flushed before running. - /// Does nothing if firmware version is not matched - /// Firmware range: Storage v0.49, v0.51+ - /// Storage only - /// @param admin_pin 20 characters Admin PIN - /// @return command processing error code - pub fn NK_set_unencrypted_read_only_admin( - admin_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Make unencrypted volume read-write. - /// Device hides unencrypted volume for a second therefore make sure - /// buffers are flushed before running. - /// Does nothing if firmware version is not matched - /// Firmware range: Storage v0.49, v0.51+ - /// Storage only - /// @param admin_pin 20 characters Admin PIN - /// @return command processing error code - pub fn NK_set_unencrypted_read_write_admin( - admin_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Make encrypted volume read-only. - /// Device hides encrypted volume for a second therefore make sure - /// buffers are flushed before running. - /// Firmware range: v0.49 only, future (see firmware release notes) - /// Storage only - /// @param admin_pin 20 characters - /// @return command processing error code - pub fn NK_set_encrypted_read_only( - admin_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Make encrypted volume read-write. - /// Device hides encrypted volume for a second therefore make sure - /// buffers are flushed before running. - /// Firmware range: v0.49 only, future (see firmware release notes) - /// Storage only - /// @param admin_pin 20 characters - /// @return command processing error code - pub fn NK_set_encrypted_read_write( - admin_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Exports device's firmware to unencrypted volume. - /// Storage only - /// @param admin_pin 20 characters - /// @return command processing error code - pub fn NK_export_firmware(admin_pin: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; -} -extern "C" { - /// Clear new SD card notification. It is set after factory reset. - /// Storage only - /// @param admin_pin 20 characters - /// @return command processing error code - pub fn NK_clear_new_sd_card_warning( - admin_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Fill SD card with random data. - /// Should be done on first stick initialization after creating keys. - /// Storage only - /// @param admin_pin 20 characters - /// @return command processing error code - pub fn NK_fill_SD_card_with_random_data( - admin_pin: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Change update password. - /// Update password is used for entering update mode, where firmware - /// could be uploaded using dfu-programmer or other means. - /// Storage only - /// @param current_update_password 20 characters - /// @param new_update_password 20 characters - /// @return command processing error code - pub fn NK_change_update_password( - current_update_password: *const ::std::os::raw::c_char, - new_update_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Enter update mode. Needs update password. - /// When device is in update mode it no longer accepts any HID commands until - /// firmware is launched (regardless of being updated or not). - /// Smartcard (through CCID interface) and its all volumes are not visible as well. - /// Its VID and PID are changed to factory-default (03eb:2ff1 Atmel Corp.) - /// to be detected by flashing software. Result of this command can be reversed - /// by using 'launch' command. - /// For dfu-programmer it would be: 'dfu-programmer at32uc3a3256s launch'. - /// Storage only - /// @param update_password 20 characters - /// @return command processing error code - pub fn NK_enable_firmware_update( - update_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Get Storage stick status as string. - /// Storage only - /// @return string with devices attributes - pub fn NK_get_status_storage_as_string() -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get the Storage stick status and return the command processing - /// error code. If the code is zero, i. e. the command was successful, - /// the storage status is written to the output pointer's target. - /// The output pointer must not be null. - /// - /// @param out the output pointer for the storage status - /// @return command processing error code - pub fn NK_get_status_storage(out: *mut NK_storage_status) -> ::std::os::raw::c_int; -} -extern "C" { - /// Get SD card usage attributes. Usable during hidden volumes creation. - /// If the command was successful (return value 0), the usage data is - /// written to the output pointer’s target. The output pointer must - /// not be null. - /// Storage only - /// @param out the output pointer for the usage data - /// @return command processing error code - pub fn NK_get_SD_usage_data(out: *mut NK_SD_usage_data) -> ::std::os::raw::c_int; -} -extern "C" { - /// Get SD card usage attributes as string. - /// Usable during hidden volumes creation. - /// Storage only - /// @return string with SD card usage attributes - pub fn NK_get_SD_usage_data_as_string() -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Get progress value of current long operation. - /// Storage only - /// @return int in range 0-100 or -1 if device is not busy or -2 if an - /// error occured - pub fn NK_get_progress_bar_value() -> ::std::os::raw::c_int; -} -extern "C" { - /// Returns a list of connected devices' id's, delimited by ';' character. Empty string is returned on no device found. - /// Each ID could consist of: - /// 1. SC_id:SD_id_p_path (about 40 bytes) - /// 2. path (about 10 bytes) - /// where 'path' is USB path (bus:num), 'SC_id' is smartcard ID, 'SD_id' is storage card ID and - /// '_p_' and ':' are field delimiters. - /// Case 2 (USB path only) is used, when the device cannot be asked about its status data (e.g. during a long operation, - /// like clearing SD card. - /// Internally connects to all available devices and creates a map between ids and connection objects. - /// Side effects: changes active device to last detected Storage device. - /// Storage only - /// @example Example of returned data: '00005d19:dacc2cb4_p_0001:0010:02;000037c7:4cf12445_p_0001:000f:02;0001:000c:02' - /// @return string delimited id's of connected devices - pub fn NK_list_devices_by_cpuID() -> *mut ::std::os::raw::c_char; -} -extern "C" { - /// Returns a linked list of all connected devices, or null if no devices - /// are connected or an error occured. The linked list must be freed by - /// calling NK_free_device_info. - /// @return a linked list of all connected devices - pub fn NK_list_devices() -> *mut NK_device_info; -} -extern "C" { - /// Free a linked list returned by NK_list_devices. - /// @param the linked list to free or null - pub fn NK_free_device_info(device_info: *mut NK_device_info); -} -extern "C" { - /// Connects to the device with given ID. ID's list could be created with NK_list_devices_by_cpuID. - /// Requires calling to NK_list_devices_by_cpuID first. Connecting to arbitrary ID/USB path is not handled. - /// On connection requests status from device and disconnects it / removes from map on connection failure. - /// Storage only - /// @param id Target device ID (example: '00005d19:dacc2cb4_p_0001:0010:02') - /// @return 1 on successful connection, 0 otherwise - pub fn NK_connect_with_ID(id: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; -} -extern "C" { - /// Connects to a device with the given path. The path is a USB device - /// path as returned by hidapi. - /// @param path the device path - /// @return 1 on successful connection, 0 otherwise - pub fn NK_connect_with_path(path: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; -} -extern "C" { - /// Blink red and green LED alternatively and infinitely (until device is reconnected). - /// @return command processing error code - pub fn NK_wink() -> ::std::os::raw::c_int; -} -extern "C" { - /// Enable update mode on Nitrokey Pro. - /// Supported from v0.11. - /// @param update_password 20 bytes update password - /// @return command processing error code - pub fn NK_enable_firmware_update_pro( - update_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// Change update-mode password on Nitrokey Pro. - /// Supported from v0.11. - /// @param current_firmware_password 20 bytes update password - /// @param new_firmware_password 20 bytes update password - /// @return command processing error code - pub fn NK_change_firmware_password_pro( - current_firmware_password: *const ::std::os::raw::c_char, - new_firmware_password: *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ReadSlot_t { - pub slot_name: [u8; 15usize], - pub _slot_config: u8, - pub slot_token_id: [u8; 13usize], - pub slot_counter: u64, -} -#[test] -fn bindgen_test_layout_ReadSlot_t() { - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(ReadSlot_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ReadSlot_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).slot_name as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_name) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::()))._slot_config as *const _ as usize }, - 15usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(_slot_config) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).slot_token_id as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_token_id) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).slot_counter as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ReadSlot_t), - "::", - stringify!(slot_counter) - ) - ); -} -extern "C" { - pub fn NK_read_HOTP_slot(slot_num: u8, out: *mut ReadSlot_t) -> ::std::os::raw::c_int; -} diff --git a/nitrokey-sys/src/lib.rs b/nitrokey-sys/src/lib.rs deleted file mode 100644 index a179da8..0000000 --- a/nitrokey-sys/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] - -mod ffi; - -pub use crate::ffi::*; - -#[cfg(test)] -mod tests { - use super::*; - use std::ffi::CString; - - #[test] - fn login_auto() { - unsafe { - assert_eq!(0, NK_login_auto()); - } - } - - #[test] - fn login() { - unsafe { - // Unconnected - assert_eq!(0, NK_login(CString::new("S").unwrap().as_ptr())); - assert_eq!(0, NK_login(CString::new("P").unwrap().as_ptr())); - // Unsupported model - assert_eq!(0, NK_login(CString::new("T").unwrap().as_ptr())); - } - } -} diff --git a/nitrokey/.builds/archlinux-msrv.yml b/nitrokey/.builds/archlinux-msrv.yml deleted file mode 100644 index 66c0390..0000000 --- a/nitrokey/.builds/archlinux-msrv.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) 2019 Robin Krahl -# SPDX-License-Identifier: CC0-1.0 -image: archlinux -packages: - - rustup - - libnitrokey -environment: - USE_SYSTEM_LIBNITROKEY: "1" -sources: - - https://git.ireas.org/nitrokey-rs -tasks: - - setup: | - rustup set profile minimal - rustup default 1.34.2 - - version: | - rustc -V - - build: | - cd nitrokey-rs - cargo build --release - - test: | - cd nitrokey-rs - cargo test diff --git a/nitrokey/.builds/archlinux-use-system-lib.yml b/nitrokey/.builds/archlinux-use-system-lib.yml deleted file mode 100644 index 29bda19..0000000 --- a/nitrokey/.builds/archlinux-use-system-lib.yml +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2019 Robin Krahl -# SPDX-License-Identifier: CC0-1.0 -image: archlinux -packages: - - rust - - libnitrokey -environment: - USE_SYSTEM_LIBNITROKEY: "1" -sources: - - https://git.ireas.org/nitrokey-rs -tasks: - - version: | - rustc -V - - build: | - cd nitrokey-rs - cargo build --release - - test: | - cd nitrokey-rs - cargo test - - format: | - cd nitrokey-rs - cargo fmt -- --check - - clippy: | - cd nitrokey-rs - cargo clippy -- -D warnings diff --git a/nitrokey/.builds/archlinux.yml b/nitrokey/.builds/archlinux.yml deleted file mode 100644 index 151eb66..0000000 --- a/nitrokey/.builds/archlinux.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2019 Robin Krahl -# SPDX-License-Identifier: CC0-1.0 -image: archlinux -packages: - - rust - - hidapi - - gcc -sources: - - https://git.ireas.org/nitrokey-rs -tasks: - - build: | - cd nitrokey-rs - cargo build --release - - test: | - cd nitrokey-rs - cargo test diff --git a/nitrokey/.builds/lint.yml b/nitrokey/.builds/lint.yml deleted file mode 100644 index 678cde8..0000000 --- a/nitrokey/.builds/lint.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2019 Robin Krahl -# SPDX-License-Identifier: CC0-1.0 -image: archlinux -packages: - - gnupg - - reuse -sources: - - https://git.ireas.org/nitrokey-rs -tasks: - - verify: | - cd nitrokey-rs - curl -s "https://pgp.ireas.org/0x6D533958F070C57C.txt" | gpg --import - git verify-commit HEAD - - reuse: | - cd nitrokey-rs - reuse lint diff --git a/nitrokey/.gitignore b/nitrokey/.gitignore deleted file mode 100644 index 7ea18df..0000000 --- a/nitrokey/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (C) 2019 Robin Krahl -# SPDX-License-Identifier: CC0-1.0 -/target -/nitrokey-sys/target -**/*.rs.bk -Cargo.lock -*.swp diff --git a/nitrokey/CHANGELOG.md b/nitrokey/CHANGELOG.md deleted file mode 100644 index d4451bc..0000000 --- a/nitrokey/CHANGELOG.md +++ /dev/null @@ -1,135 +0,0 @@ - - -# v0.4.0 (2020-01-02) -- Remove the `test-pro` and `test-storage` features. -- Implement `Display` for `Version`. -- Introduce `DEFAULT_ADMIN_PIN` and `DEFAULT_USER_PIN` constants. -- Refactor the error handling code: - - Implement `std::error::Error` for `CommandError`. - - Add the `Error` enum. - - Add the `LibraryError` enum and move the library error variants from - `CommandError` to `LibraryError`. - - Add the `CommunicationError` enum and move the communication error variants - from `CommandError` to `CommunicationError`. - - Return `Error` instead of `CommandError` in all public functions. - - Move the `CommandError::RngError` variant to `Error::RandError` and the - `CommandError::Unknown` variant to `Error::UnknownError`. - - Return `CommunicationError::NotConnected` instead of - `CommandError::Undefined` from the connect functions. - - Remove the `CommandError::Undefined` variant. -- Add a private `PhantomData` field to `Pro` and `Storage` to make direct - instantiation impossible. -- Refactor and clean up internal code: - - Prefer using the `Into` trait over numeric casting. - - Add `Pro::new` and `Storage::new` functions. -- Implement `From` and `From` for `DeviceWrapper`. -- Add `Error::Utf8Error` variant. - - Return `Result` instead of `Version` from `get_library_version`. - - Return `Error::Utf8Error` if libnitrokey returns an invalid UTF-8 string. -- Implement `From<(T: Device, Error)>` for `Error`. -- Fix timing issues with the `totp_no_pin` and `totp_pin` test cases. -- Always return a `Result` in functions that communicate with a device. -- Combine `get_{major,minor}_firmware_version` into `get_firmware_version`. -- Add `set_encrypted_volume_mode` to `Storage`. -- Use mutability to represent changes to the device status: - - Implement `DerefMut` for `User` and `Admin`. - - Add `device_mut` method to `DeviceWrapper`. - - Require a mutable `Device` reference if a method changes the device state. -- Update dependencies: - - `nitrokey-sys` to 3.5 - - `nitrokey-test` to 0.3 - - `rand_core` to 0.5 - - `rand_os` to 0.2 -- Add `nitrokey-test-state` dependency in version 0.1. -- Refactor connection management: - - Add `ConcurrentAccessError` and `PoisonError` `Error` variants. - - Add the `Manager` struct that manages connections to Nitrokey devices. - - Remove `connect`, `connect_model`, `Pro::connect` and `Storage::connect`. - - Add the `into_manager` function to the `Device` trait. - - Add the `force_take` function that ignores a `PoisonError` when accessing - the manager instance. -- Internally refactor the `device` module into submodules. - -# v0.3.5 (2019-12-16) -- Update the nitrokey-sys dependency version specification to ~3.4. - -# v0.3.4 (2019-01-20) -- Fix authentication methods that assumed that `char` is signed. - -# v0.3.3 (2019-01-16) -- Add the `get_production_info` and `clear_new_sd_card_warning` methods to the - `Storage` struct. -- Use `rand_os` instead of `rand` for random data creation. - - (Re-)add `CommandError::RngError` variant. -- Account for the possibility that an empty string returned by libnitrokey can - not only indicate an error but also be a valid return value. -- Make test cases more robust and avoid side effects on other test cases. - -# v0.3.2 (2019-01-12) -- Make three additional error codes known: `CommandError::StringTooLong`, - `CommandError::InvalidHexString` and `CommandError::TargetBufferTooSmall`. -- Add the `get_library_version` function to query the libnitrokey version. -- Add the `wink` method to the `Storage` struct. -- Add the `set_unencrypted_volume_mode` to set the access mode of the - unencrypted volume. -- Add the `export_firmware` method to the `Storage` struct. - -# v0.3.1 (2019-01-07) -- Use `nitrokey-test` to select and execute the unit tests. -- Add support for the hidden volumes on a Nitrokey Storage - (`enable_hidden_volume`, `disable_hidden_volume` and `create_hidden_volume` - methods for the `Storage` struct). -- Add the `connect_model` function to connect to a specific model using an enum - variant. - -# v0.3.0 (2019-01-04) -- Add a `force` argument to `ConfigureOtp::set_time`. -- Remove the obsolete `CommandError::RngError`. -- Add `CommandError::Undefined` to represent errors without further - information (e. g. a method returned `NULL` unexpectedly). -- Add error code to `CommandError::Unknown`. -- Add the `Storage::change_update_pin` method that changes the firmware update - PIN. -- Add the `Device::factory_reset` method that performs a factory reset. -- Add the `Device::build_aes_key` method that builds a new AES key on the Nitrokey. -- Add the `Storage::enable_firmware_update` method that puts the Nitrokey - Storage in update mode so that the firmware can be updated. - -# v0.2.3 (2018-12-31) - -- Dummy release to fix an issue with the crates.io tarball. - -# v0.2.2 (2018-12-30) - -- Update to Rust edition 2018. -- Remove the `test-no-device` feature. -- Update the rand dependency to version 0.6. -- Add function `Device::get_model` that returns the connected model. -- Derive the `Copy` and `Clone` traits for the enums `CommandError`, `LogLevel` - and `OtpMode` - -# v0.2.1 (2018-12-10) - -- Re-export `device::{StorageStatus, VolumeStatus}` in `lib.rs`. - -# v0.2.0 (2018-12-10) - -- Update to libnitrokey v3.4.1. -- Major refactoring of the existing code structure. -- Add support for most of the Nitrokey Pro features and some of the Nitrokey - Storage features. See the `TODO.md` file for more details about the missing - functionality. - -# v0.1.1 (2018-05-21) - -- Update the `nitrokey-sys` dependency to version 3.3.0. Now `libnitrokey` - is built from source and `bindgen` is no longer a build dependency. -- Add `get_minor_firmware_version` to `Device`. -- Use `NK_login_enum` instead of `NK_login` in `Device::connect`. - -# v0.1.0 (2018-05-19) - -- Initial release diff --git a/nitrokey/Cargo.toml b/nitrokey/Cargo.toml deleted file mode 100644 index b57591b..0000000 --- a/nitrokey/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (C) 2019-2020 Robin Krahl -# SPDX-License-Identifier: CC0-1.0 - -[package] -name = "nitrokey" -version = "0.4.0" -authors = ["Robin Krahl "] -edition = "2018" -homepage = "https://code.ireas.org/nitrokey-rs/" -repository = "https://git.ireas.org/nitrokey-rs/" -documentation = "https://docs.rs/nitrokey" -description = "Bindings to libnitrokey for communication with Nitrokey devices" -keywords = ["nitrokey", "otp"] -categories = ["api-bindings"] -readme = "README.md" -license = "MIT" -exclude = [".builds/*"] - -[dependencies] -lazy_static = "1.2" -libc = "0.2" -nitrokey-sys = "3.5" -rand_core = {version = "0.5.1", features = ["getrandom"] } - -[dev-dependencies] -nitrokey-test = "0.3" -nitrokey-test-state = "0.1" diff --git a/nitrokey/LICENSES/CC0-1.0.txt b/nitrokey/LICENSES/CC0-1.0.txt deleted file mode 100644 index 0e259d4..0000000 --- a/nitrokey/LICENSES/CC0-1.0.txt +++ /dev/null @@ -1,121 +0,0 @@ -Creative Commons Legal Code - -CC0 1.0 Universal - - CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE - LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN - ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS - INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES - REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS - PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM - THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED - HEREUNDER. - -Statement of Purpose - -The laws of most jurisdictions throughout the world automatically confer -exclusive Copyright and Related Rights (defined below) upon the creator -and subsequent owner(s) (each and all, an "owner") of an original work of -authorship and/or a database (each, a "Work"). - -Certain owners wish to permanently relinquish those rights to a Work for -the purpose of contributing to a commons of creative, cultural and -scientific works ("Commons") that the public can reliably and without fear -of later claims of infringement build upon, modify, incorporate in other -works, reuse and redistribute as freely as possible in any form whatsoever -and for any purposes, including without limitation commercial purposes. -These owners may contribute to the Commons to promote the ideal of a free -culture and the further production of creative, cultural and scientific -works, or to gain reputation or greater distribution for their Work in -part through the use and efforts of others. - -For these and/or other purposes and motivations, and without any -expectation of additional consideration or compensation, the person -associating CC0 with a Work (the "Affirmer"), to the extent that he or she -is an owner of Copyright and Related Rights in the Work, voluntarily -elects to apply CC0 to the Work and publicly distribute the Work under its -terms, with knowledge of his or her Copyright and Related Rights in the -Work and the meaning and intended legal effect of CC0 on those rights. - -1. Copyright and Related Rights. A Work made available under CC0 may be -protected by copyright and related or neighboring rights ("Copyright and -Related Rights"). Copyright and Related Rights include, but are not -limited to, the following: - - i. the right to reproduce, adapt, distribute, perform, display, - communicate, and translate a Work; - ii. moral rights retained by the original author(s) and/or performer(s); -iii. publicity and privacy rights pertaining to a person's image or - likeness depicted in a Work; - iv. rights protecting against unfair competition in regards to a Work, - subject to the limitations in paragraph 4(a), below; - v. rights protecting the extraction, dissemination, use and reuse of data - in a Work; - vi. database rights (such as those arising under Directive 96/9/EC of the - European Parliament and of the Council of 11 March 1996 on the legal - protection of databases, and under any national implementation - thereof, including any amended or successor version of such - directive); and -vii. other similar, equivalent or corresponding rights throughout the - world based on applicable law or treaty, and any national - implementations thereof. - -2. Waiver. To the greatest extent permitted by, but not in contravention -of, applicable law, Affirmer hereby overtly, fully, permanently, -irrevocably and unconditionally waives, abandons, and surrenders all of -Affirmer's Copyright and Related Rights and associated claims and causes -of action, whether now known or unknown (including existing as well as -future claims and causes of action), in the Work (i) in all territories -worldwide, (ii) for the maximum duration provided by applicable law or -treaty (including future time extensions), (iii) in any current or future -medium and for any number of copies, and (iv) for any purpose whatsoever, -including without limitation commercial, advertising or promotional -purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each -member of the public at large and to the detriment of Affirmer's heirs and -successors, fully intending that such Waiver shall not be subject to -revocation, rescission, cancellation, termination, or any other legal or -equitable action to disrupt the quiet enjoyment of the Work by the public -as contemplated by Affirmer's express Statement of Purpose. - -3. Public License Fallback. Should any part of the Waiver for any reason -be judged legally invalid or ineffective under applicable law, then the -Waiver shall be preserved to the maximum extent permitted taking into -account Affirmer's express Statement of Purpose. In addition, to the -extent the Waiver is so judged Affirmer hereby grants to each affected -person a royalty-free, non transferable, non sublicensable, non exclusive, -irrevocable and unconditional license to exercise Affirmer's Copyright and -Related Rights in the Work (i) in all territories worldwide, (ii) for the -maximum duration provided by applicable law or treaty (including future -time extensions), (iii) in any current or future medium and for any number -of copies, and (iv) for any purpose whatsoever, including without -limitation commercial, advertising or promotional purposes (the -"License"). The License shall be deemed effective as of the date CC0 was -applied by Affirmer to the Work. Should any part of the License for any -reason be judged legally invalid or ineffective under applicable law, such -partial invalidity or ineffectiveness shall not invalidate the remainder -of the License, and in such case Affirmer hereby affirms that he or she -will not (i) exercise any of his or her remaining Copyright and Related -Rights in the Work or (ii) assert any associated claims and causes of -action with respect to the Work, in either case contrary to Affirmer's -express Statement of Purpose. - -4. Limitations and Disclaimers. - - a. No trademark or patent rights held by Affirmer are waived, abandoned, - surrendered, licensed or otherwise affected by this document. - b. Affirmer offers the Work as-is and makes no representations or - warranties of any kind concerning the Work, express, implied, - statutory or otherwise, including without limitation warranties of - title, merchantability, fitness for a particular purpose, non - infringement, or the absence of latent or other defects, accuracy, or - the present or absence of errors, whether or not discoverable, all to - the greatest extent permissible under applicable law. - c. Affirmer disclaims responsibility for clearing rights of other persons - that may apply to the Work or any use thereof, including without - limitation any person's Copyright and Related Rights in the Work. - Further, Affirmer disclaims responsibility for obtaining any necessary - consents, permissions or other rights required for any use of the - Work. - d. Affirmer understands and acknowledges that Creative Commons is not a - party to this document and has no duty or obligation with respect to - this CC0 or use of the Work. diff --git a/nitrokey/LICENSES/MIT.txt b/nitrokey/LICENSES/MIT.txt deleted file mode 100644 index 6c67cd5..0000000 --- a/nitrokey/LICENSES/MIT.txt +++ /dev/null @@ -1,24 +0,0 @@ -Valid-License-Identifier: MIT -License-Text: - -The MIT License (MIT) - -Copyright (c) 2018 Robin Krahl - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/nitrokey/README.md b/nitrokey/README.md deleted file mode 100644 index 12a9f6d..0000000 --- a/nitrokey/README.md +++ /dev/null @@ -1,92 +0,0 @@ - - -# nitrokey-rs - -A libnitrokey wrapper for Rust providing access to Nitrokey devices. - -[Documentation][] - -## Compatibility - -The required [`libnitrokey`][] version is built from source. The host system -must provide `libhidapi-libusb0` (Linux) or `libhidapi` (non-Linux) in the -default library search path. Depending on your system, you might also have to -install the [Nitrokey udev rules][]. - -Currently, this crate provides access to the common features of the Nitrokey -Pro and the Nitrokey Storage: general configuration, OTP generation and the -password safe. Basic support for the secure storage on the Nitrokey Storage is -available but still under development. - -### Unsupported Functions - -The following functions provided by `libnitrokey` are deliberately not -supported by `nitrokey-rs`: - -- `NK_get_device_model`. We know which model we connected to, so we can - provide this information without calling `libnitrokey`. -- `NK_is_AES_supported`. This method is no longer needed for Nitrokey devices - with a recent firmware version. -- `NK_set_unencrypted_volume_rorw_pin_type_user`, - `NK_set_unencrypted_read_only`, `NK_set_unencrypted_read_write`. These - methods are only relevant for older firmware versions (pre-v0.51). As the - Nitrokey Storage firmware can be updated easily, we do not support these - outdated versions. -- `NK_totp_get_time`, `NK_status`. These functions are deprecated. -- `NK_read_HOTP_slot`. This function is only available for HOTP slots, not for - TOTP. We will support it once both types are supported by `libnitrokey`. -- All `*_as_string` functions that return string representations of data - returned by other functions. - -## Tests - -This crate has tests for different scenarios: Some tests require that no -Nitrokey device is connected, others require a Nitrokey Storage or a Nitrokey -Pro. We use the [`nitrokey-test`][] crate to select the test cases. You can -just run `cargo test` to auto-detect connected Nitrokey devices and to run the -appropriate tests. If you want to manually select the tests, set the -`NITROKEY_TEST_GROUP` environment variable to `nodev` (no device connected), -`pro` (Nitrokey Pro connected) or `storage` (Nitrokey Storage connected). - -Note that the tests assume that the device’s passwords are the factory defaults -(admin PIN `12345678`, user PIN `123456`, update password `12345678`) and that -an AES key has been built. Some tests will overwrite the data stored on the -Nitrokey device or perform a factory reset. Never execute the tests if you -don’t want to destroy all data on any connected Nitrokey device! - -## Acknowledgments - -Thanks to Nitrokey UG for providing two Nitrokey devices to support the -development of this crate. Thanks to Daniel Mueller for contributions to -`nitrokey-rs` and for the `nitrokey-test` crate. - -## Minimum Supported Rust Version - -This crate supports Rust 1.34.2 or later. - -## Contact - -For bug reports, patches, feature requests or other messages, please send a -mail to [nitrokey-rs-dev@ireas.org][]. - -## License - -This project is licensed under the [MIT][] license. The documentation and -configuration files contained in this repository are licensed under the -[Creative Commons Zero][CC0] license. You can find a copy of the license texts -in the `LICENSES` directory. `libnitrokey` is licensed under the [LGPL-3.0][]. - -`nitrokey-rs` complies with [version 3.0 of the REUSE specification][reuse]. - -[Documentation]: https://docs.rs/nitrokey -[Nitrokey udev rules]: https://www.nitrokey.com/documentation/frequently-asked-questions-faq#openpgp-card-not-available -[`libnitrokey`]: https://github.com/nitrokey/libnitrokey -[`nitrokey-test`]: https://github.com/d-e-s-o/nitrokey-test -[nitrokey-rs-dev@ireas.org]: mailto:nitrokey-rs-dev@ireas.org -[MIT]: https://opensource.org/licenses/MIT -[CC0]: https://creativecommons.org/publicdomain/zero/1.0/ -[LGPL-3.0]: https://opensource.org/licenses/lgpl-3.0.html -[reuse]: https://reuse.software/practices/3.0/ diff --git a/nitrokey/TODO.md b/nitrokey/TODO.md deleted file mode 100644 index 54525ef..0000000 --- a/nitrokey/TODO.md +++ /dev/null @@ -1,26 +0,0 @@ - - -- Add support for the currently unsupported commands: - - `NK_send_startup` - - `NK_fill_SD_card_with_random_data` - - `NK_get_SD_usage_data` - - `NK_get_progress_bar_value` - - `NK_list_devices_by_cpuID` - - `NK_connect_with_ID` - - `NK_get_status` - - `NK_list_devices` - - `NK_free_device_info` - - `NK_connect_with_path` - - `NK_enable_firmware_update_pro` - - `NK_change_firmware_password_pro` -- Clear passwords from memory. -- Lock password safe in `PasswordSafe::drop()` (see [nitrokey-storage-firmware - issue 65][]). -- Disable creation of multiple password safes at the same time. -- Check timing in Storage tests. -- Consider restructuring `device::StorageStatus`. - -[nitrokey-storage-firmware issue 65]: https://github.com/Nitrokey/nitrokey-storage-firmware/issues/65 diff --git a/nitrokey/src/auth.rs b/nitrokey/src/auth.rs deleted file mode 100644 index cab1021..0000000 --- a/nitrokey/src/auth.rs +++ /dev/null @@ -1,437 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use std::convert::TryFrom as _; -use std::marker; -use std::ops; -use std::os::raw::c_char; -use std::os::raw::c_int; - -use nitrokey_sys; - -use crate::config::{Config, RawConfig}; -use crate::device::{Device, DeviceWrapper, Pro, Storage}; -use crate::error::Error; -use crate::otp::{ConfigureOtp, GenerateOtp, OtpMode, OtpSlotData, RawOtpSlotData}; -use crate::util::{generate_password, get_command_result, get_cstring, result_from_string}; - -static TEMPORARY_PASSWORD_LENGTH: usize = 25; - -/// Provides methods to authenticate as a user or as an admin using a PIN. The authenticated -/// methods will consume the current device instance. On success, they return the authenticated -/// device. Otherwise, they return the current unauthenticated device and the error code. -pub trait Authenticate<'a> { - /// Performs user authentication. This method consumes the device. If successful, an - /// authenticated device is returned. Otherwise, the current unauthenticated device and the - /// error are returned. - /// - /// This method generates a random temporary password that is used for all operations that - /// require user access. - /// - /// # Errors - /// - /// - [`InvalidString`][] if the provided user password contains a null byte - /// - [`RngError`][] if the generation of the temporary password failed - /// - [`WrongPassword`][] if the provided user password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, DeviceWrapper, User}; - /// # use nitrokey::Error; - /// - /// fn perform_user_task<'a>(device: &User<'a, DeviceWrapper<'a>>) {} - /// fn perform_other_task(device: &DeviceWrapper) {} - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// let device = match device.authenticate_user("123456") { - /// Ok(user) => { - /// perform_user_task(&user); - /// user.device() - /// }, - /// Err((device, err)) => { - /// eprintln!("Could not authenticate as user: {}", err); - /// device - /// }, - /// }; - /// perform_other_task(&device); - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`RngError`]: enum.CommandError.html#variant.RngError - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - fn authenticate_user(self, password: &str) -> Result, (Self, Error)> - where - Self: Device<'a> + Sized; - - /// Performs admin authentication. This method consumes the device. If successful, an - /// authenticated device is returned. Otherwise, the current unauthenticated device and the - /// error are returned. - /// - /// This method generates a random temporary password that is used for all operations that - /// require admin access. - /// - /// # Errors - /// - /// - [`InvalidString`][] if the provided admin password contains a null byte - /// - [`RngError`][] if the generation of the temporary password failed - /// - [`WrongPassword`][] if the provided admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, Admin, DeviceWrapper}; - /// # use nitrokey::Error; - /// - /// fn perform_admin_task<'a>(device: &Admin<'a, DeviceWrapper<'a>>) {} - /// fn perform_other_task(device: &DeviceWrapper) {} - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// let device = match device.authenticate_admin("123456") { - /// Ok(admin) => { - /// perform_admin_task(&admin); - /// admin.device() - /// }, - /// Err((device, err)) => { - /// eprintln!("Could not authenticate as admin: {}", err); - /// device - /// }, - /// }; - /// perform_other_task(&device); - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`RngError`]: enum.CommandError.html#variant.RngError - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - fn authenticate_admin(self, password: &str) -> Result, (Self, Error)> - where - Self: Device<'a> + Sized; -} - -trait AuthenticatedDevice { - fn new(device: T, temp_password: Vec) -> Self; - - fn temp_password_ptr(&self) -> *const c_char; -} - -/// A Nitrokey device with user authentication. -/// -/// To obtain an instance of this struct, use the [`authenticate_user`][] method from the -/// [`Authenticate`][] trait. To get back to an unauthenticated device, use the [`device`][] -/// method. -/// -/// [`Authenticate`]: trait.Authenticate.html -/// [`authenticate_admin`]: trait.Authenticate.html#method.authenticate_admin -/// [`device`]: #method.device -#[derive(Debug)] -pub struct User<'a, T: Device<'a>> { - device: T, - temp_password: Vec, - marker: marker::PhantomData<&'a T>, -} - -/// A Nitrokey device with admin authentication. -/// -/// To obtain an instance of this struct, use the [`authenticate_admin`][] method from the -/// [`Authenticate`][] trait. To get back to an unauthenticated device, use the [`device`][] -/// method. -/// -/// [`Authenticate`]: trait.Authenticate.html -/// [`authenticate_admin`]: trait.Authenticate.html#method.authenticate_admin -/// [`device`]: #method.device -#[derive(Debug)] -pub struct Admin<'a, T: Device<'a>> { - device: T, - temp_password: Vec, - marker: marker::PhantomData<&'a T>, -} - -fn authenticate<'a, D, A, T>(device: D, password: &str, callback: T) -> Result -where - D: Device<'a>, - A: AuthenticatedDevice, - T: Fn(*const c_char, *const c_char) -> c_int, -{ - let temp_password = match generate_password(TEMPORARY_PASSWORD_LENGTH) { - Ok(temp_password) => temp_password, - Err(err) => return Err((device, err)), - }; - let password = match get_cstring(password) { - Ok(password) => password, - Err(err) => return Err((device, err)), - }; - let password_ptr = password.as_ptr(); - let temp_password_ptr = temp_password.as_ptr() as *const c_char; - match callback(password_ptr, temp_password_ptr) { - 0 => Ok(A::new(device, temp_password)), - rv => Err((device, Error::from(rv))), - } -} - -fn authenticate_user_wrapper<'a, T, C>( - device: T, - constructor: C, - password: &str, -) -> Result>, (DeviceWrapper<'a>, Error)> -where - T: Device<'a> + 'a, - C: Fn(T) -> DeviceWrapper<'a>, -{ - let result = device.authenticate_user(password); - match result { - Ok(user) => Ok(User::new(constructor(user.device), user.temp_password)), - Err((device, err)) => Err((constructor(device), err)), - } -} - -fn authenticate_admin_wrapper<'a, T, C>( - device: T, - constructor: C, - password: &str, -) -> Result>, (DeviceWrapper<'a>, Error)> -where - T: Device<'a> + 'a, - C: Fn(T) -> DeviceWrapper<'a>, -{ - let result = device.authenticate_admin(password); - match result { - Ok(user) => Ok(Admin::new(constructor(user.device), user.temp_password)), - Err((device, err)) => Err((constructor(device), err)), - } -} - -impl<'a, T: Device<'a>> User<'a, T> { - /// Forgets the user authentication and returns an unauthenticated device. This method - /// consumes the authenticated device. It does not perform any actual commands on the - /// Nitrokey. - pub fn device(self) -> T { - self.device - } -} - -impl<'a, T: Device<'a>> ops::Deref for User<'a, T> { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.device - } -} - -impl<'a, T: Device<'a>> ops::DerefMut for User<'a, T> { - fn deref_mut(&mut self) -> &mut T { - &mut self.device - } -} - -impl<'a, T: Device<'a>> GenerateOtp for User<'a, T> { - fn get_hotp_code(&mut self, slot: u8) -> Result { - result_from_string(unsafe { - nitrokey_sys::NK_get_hotp_code_PIN(slot, self.temp_password_ptr()) - }) - } - - fn get_totp_code(&self, slot: u8) -> Result { - result_from_string(unsafe { - nitrokey_sys::NK_get_totp_code_PIN(slot, 0, 0, 0, self.temp_password_ptr()) - }) - } -} - -impl<'a, T: Device<'a>> AuthenticatedDevice for User<'a, T> { - fn new(device: T, temp_password: Vec) -> Self { - User { - device, - temp_password, - marker: marker::PhantomData, - } - } - - fn temp_password_ptr(&self) -> *const c_char { - self.temp_password.as_ptr() as *const c_char - } -} - -impl<'a, T: Device<'a>> ops::Deref for Admin<'a, T> { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.device - } -} - -impl<'a, T: Device<'a>> ops::DerefMut for Admin<'a, T> { - fn deref_mut(&mut self) -> &mut T { - &mut self.device - } -} - -impl<'a, T: Device<'a>> Admin<'a, T> { - /// Forgets the user authentication and returns an unauthenticated device. This method - /// consumes the authenticated device. It does not perform any actual commands on the - /// Nitrokey. - pub fn device(self) -> T { - self.device - } - - /// Writes the given configuration to the Nitrokey device. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if the provided numlock, capslock or scrolllock slot is larger than two - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, Config}; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// let config = Config::new(None, None, None, false); - /// match device.authenticate_admin("12345678") { - /// Ok(mut admin) => { - /// admin.write_config(config); - /// () - /// }, - /// Err((_, err)) => eprintln!("Could not authenticate as admin: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - pub fn write_config(&mut self, config: Config) -> Result<(), Error> { - let raw_config = RawConfig::try_from(config)?; - get_command_result(unsafe { - nitrokey_sys::NK_write_config( - raw_config.numlock, - raw_config.capslock, - raw_config.scrollock, - raw_config.user_password, - false, - self.temp_password_ptr(), - ) - }) - } -} - -impl<'a, T: Device<'a>> ConfigureOtp for Admin<'a, T> { - fn write_hotp_slot(&mut self, data: OtpSlotData, counter: u64) -> Result<(), Error> { - let raw_data = RawOtpSlotData::new(data)?; - get_command_result(unsafe { - nitrokey_sys::NK_write_hotp_slot( - raw_data.number, - raw_data.name.as_ptr(), - raw_data.secret.as_ptr(), - counter, - raw_data.mode == OtpMode::EightDigits, - raw_data.use_enter, - raw_data.use_token_id, - raw_data.token_id.as_ptr(), - self.temp_password_ptr(), - ) - }) - } - - fn write_totp_slot(&mut self, data: OtpSlotData, time_window: u16) -> Result<(), Error> { - let raw_data = RawOtpSlotData::new(data)?; - get_command_result(unsafe { - nitrokey_sys::NK_write_totp_slot( - raw_data.number, - raw_data.name.as_ptr(), - raw_data.secret.as_ptr(), - time_window, - raw_data.mode == OtpMode::EightDigits, - raw_data.use_enter, - raw_data.use_token_id, - raw_data.token_id.as_ptr(), - self.temp_password_ptr(), - ) - }) - } - - fn erase_hotp_slot(&mut self, slot: u8) -> Result<(), Error> { - get_command_result(unsafe { - nitrokey_sys::NK_erase_hotp_slot(slot, self.temp_password_ptr()) - }) - } - - fn erase_totp_slot(&mut self, slot: u8) -> Result<(), Error> { - get_command_result(unsafe { - nitrokey_sys::NK_erase_totp_slot(slot, self.temp_password_ptr()) - }) - } -} - -impl<'a, T: Device<'a>> AuthenticatedDevice for Admin<'a, T> { - fn new(device: T, temp_password: Vec) -> Self { - Admin { - device, - temp_password, - marker: marker::PhantomData, - } - } - - fn temp_password_ptr(&self) -> *const c_char { - self.temp_password.as_ptr() as *const c_char - } -} - -impl<'a> Authenticate<'a> for DeviceWrapper<'a> { - fn authenticate_user(self, password: &str) -> Result, (Self, Error)> { - match self { - DeviceWrapper::Storage(storage) => { - authenticate_user_wrapper(storage, DeviceWrapper::Storage, password) - } - DeviceWrapper::Pro(pro) => authenticate_user_wrapper(pro, DeviceWrapper::Pro, password), - } - } - - fn authenticate_admin(self, password: &str) -> Result, (Self, Error)> { - match self { - DeviceWrapper::Storage(storage) => { - authenticate_admin_wrapper(storage, DeviceWrapper::Storage, password) - } - DeviceWrapper::Pro(pro) => { - authenticate_admin_wrapper(pro, DeviceWrapper::Pro, password) - } - } - } -} - -impl<'a> Authenticate<'a> for Pro<'a> { - fn authenticate_user(self, password: &str) -> Result, (Self, Error)> { - authenticate(self, password, |password_ptr, temp_password_ptr| unsafe { - nitrokey_sys::NK_user_authenticate(password_ptr, temp_password_ptr) - }) - } - - fn authenticate_admin(self, password: &str) -> Result, (Self, Error)> { - authenticate(self, password, |password_ptr, temp_password_ptr| unsafe { - nitrokey_sys::NK_first_authenticate(password_ptr, temp_password_ptr) - }) - } -} - -impl<'a> Authenticate<'a> for Storage<'a> { - fn authenticate_user(self, password: &str) -> Result, (Self, Error)> { - authenticate(self, password, |password_ptr, temp_password_ptr| unsafe { - nitrokey_sys::NK_user_authenticate(password_ptr, temp_password_ptr) - }) - } - - fn authenticate_admin(self, password: &str) -> Result, (Self, Error)> { - authenticate(self, password, |password_ptr, temp_password_ptr| unsafe { - nitrokey_sys::NK_first_authenticate(password_ptr, temp_password_ptr) - }) - } -} diff --git a/nitrokey/src/config.rs b/nitrokey/src/config.rs deleted file mode 100644 index cb678d7..0000000 --- a/nitrokey/src/config.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use std::convert; - -use crate::error::{Error, LibraryError}; - -/// The configuration for a Nitrokey. -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct Config { - /// If set, the stick will generate a code from the HOTP slot with the given number if numlock - /// is pressed. The slot number must be 0, 1 or 2. - pub numlock: Option, - /// If set, the stick will generate a code from the HOTP slot with the given number if capslock - /// is pressed. The slot number must be 0, 1 or 2. - pub capslock: Option, - /// If set, the stick will generate a code from the HOTP slot with the given number if - /// scrollock is pressed. The slot number must be 0, 1 or 2. - pub scrollock: Option, - /// If set, OTP generation using [`get_hotp_code`][] or [`get_totp_code`][] requires user - /// authentication. Otherwise, OTPs can be generated without authentication. - /// - /// [`get_hotp_code`]: trait.ProvideOtp.html#method.get_hotp_code - /// [`get_totp_code`]: trait.ProvideOtp.html#method.get_totp_code - pub user_password: bool, -} - -#[derive(Debug)] -pub struct RawConfig { - pub numlock: u8, - pub capslock: u8, - pub scrollock: u8, - pub user_password: bool, -} - -fn config_otp_slot_to_option(value: u8) -> Option { - if value < 3 { - Some(value) - } else { - None - } -} - -fn option_to_config_otp_slot(value: Option) -> Result { - if let Some(value) = value { - if value < 3 { - Ok(value) - } else { - Err(LibraryError::InvalidSlot.into()) - } - } else { - Ok(255) - } -} - -impl Config { - /// Constructs a new instance of this struct. - pub fn new( - numlock: Option, - capslock: Option, - scrollock: Option, - user_password: bool, - ) -> Config { - Config { - numlock, - capslock, - scrollock, - user_password, - } - } -} - -impl convert::TryFrom for RawConfig { - type Error = Error; - - fn try_from(config: Config) -> Result { - Ok(RawConfig { - numlock: option_to_config_otp_slot(config.numlock)?, - capslock: option_to_config_otp_slot(config.capslock)?, - scrollock: option_to_config_otp_slot(config.scrollock)?, - user_password: config.user_password, - }) - } -} - -impl From<[u8; 5]> for RawConfig { - fn from(data: [u8; 5]) -> Self { - RawConfig { - numlock: data[0], - capslock: data[1], - scrollock: data[2], - user_password: data[3] != 0, - } - } -} - -impl Into for RawConfig { - fn into(self) -> Config { - Config { - numlock: config_otp_slot_to_option(self.numlock), - capslock: config_otp_slot_to_option(self.capslock), - scrollock: config_otp_slot_to_option(self.scrollock), - user_password: self.user_password, - } - } -} diff --git a/nitrokey/src/device/mod.rs b/nitrokey/src/device/mod.rs deleted file mode 100644 index 5e15f08..0000000 --- a/nitrokey/src/device/mod.rs +++ /dev/null @@ -1,464 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -mod pro; -mod storage; -mod wrapper; - -use std::fmt; - -use libc; -use nitrokey_sys; - -use crate::auth::Authenticate; -use crate::config::{Config, RawConfig}; -use crate::error::{CommunicationError, Error}; -use crate::otp::GenerateOtp; -use crate::pws::GetPasswordSafe; -use crate::util::{ - get_command_result, get_cstring, get_last_error, result_from_string, result_or_error, -}; - -pub use pro::Pro; -pub use storage::{ - SdCardData, Storage, StorageProductionInfo, StorageStatus, VolumeMode, VolumeStatus, -}; -pub use wrapper::DeviceWrapper; - -/// Available Nitrokey models. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum Model { - /// The Nitrokey Storage. - Storage, - /// The Nitrokey Pro. - Pro, -} - -impl fmt::Display for Model { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match *self { - Model::Pro => "Pro", - Model::Storage => "Storage", - }) - } -} - -/// A firmware version for a Nitrokey device. -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct FirmwareVersion { - /// The major firmware version, e. g. 0 in v0.40. - pub major: u8, - /// The minor firmware version, e. g. 40 in v0.40. - pub minor: u8, -} - -impl fmt::Display for FirmwareVersion { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "v{}.{}", self.major, self.minor) - } -} - -/// A Nitrokey device. -/// -/// This trait provides the commands that can be executed without authentication and that are -/// present on all supported Nitrokey devices. -pub trait Device<'a>: Authenticate<'a> + GetPasswordSafe<'a> + GenerateOtp + fmt::Debug { - /// Returns the [`Manager`][] instance that has been used to connect to this device. - /// - /// # Example - /// - /// ``` - /// use nitrokey::{Device, DeviceWrapper}; - /// - /// fn do_something(device: DeviceWrapper) { - /// // reconnect to any device - /// let manager = device.into_manager(); - /// let device = manager.connect(); - /// // do something with the device - /// // ... - /// } - /// - /// match nitrokey::take()?.connect() { - /// Ok(device) => do_something(device), - /// Err(err) => println!("Could not connect to a Nitrokey: {}", err), - /// } - /// # Ok::<(), nitrokey::Error>(()) - /// ``` - fn into_manager(self) -> &'a mut crate::Manager; - - /// Returns the model of the connected Nitrokey device. - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// println!("Connected to a Nitrokey {}", device.get_model()); - /// # Ok(()) - /// # } - fn get_model(&self) -> Model; - - /// Returns the serial number of the Nitrokey device. The serial number is the string - /// representation of a hex number. - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// match device.get_serial_number() { - /// Ok(number) => println!("serial no: {}", number), - /// Err(err) => eprintln!("Could not get serial number: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - fn get_serial_number(&self) -> Result { - result_from_string(unsafe { nitrokey_sys::NK_device_serial_number() }) - } - - /// Returns the number of remaining authentication attempts for the user. The total number of - /// available attempts is three. - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// let count = device.get_user_retry_count(); - /// match device.get_user_retry_count() { - /// Ok(count) => println!("{} remaining authentication attempts (user)", count), - /// Err(err) => eprintln!("Could not get user retry count: {}", err), - /// } - /// # Ok(()) - /// # } - /// ``` - fn get_user_retry_count(&self) -> Result { - result_or_error(unsafe { nitrokey_sys::NK_get_user_retry_count() }) - } - - /// Returns the number of remaining authentication attempts for the admin. The total number of - /// available attempts is three. - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// let count = device.get_admin_retry_count(); - /// match device.get_admin_retry_count() { - /// Ok(count) => println!("{} remaining authentication attempts (admin)", count), - /// Err(err) => eprintln!("Could not get admin retry count: {}", err), - /// } - /// # Ok(()) - /// # } - /// ``` - fn get_admin_retry_count(&self) -> Result { - result_or_error(unsafe { nitrokey_sys::NK_get_admin_retry_count() }) - } - - /// Returns the firmware version. - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// match device.get_firmware_version() { - /// Ok(version) => println!("Firmware version: {}", version), - /// Err(err) => eprintln!("Could not access firmware version: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - fn get_firmware_version(&self) -> Result { - let major = result_or_error(unsafe { nitrokey_sys::NK_get_major_firmware_version() })?; - let minor = result_or_error(unsafe { nitrokey_sys::NK_get_minor_firmware_version() })?; - Ok(FirmwareVersion { major, minor }) - } - - /// Returns the current configuration of the Nitrokey device. - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// let config = device.get_config()?; - /// println!("numlock binding: {:?}", config.numlock); - /// println!("capslock binding: {:?}", config.capslock); - /// println!("scrollock binding: {:?}", config.scrollock); - /// println!("require password for OTP: {:?}", config.user_password); - /// # Ok(()) - /// # } - /// ``` - fn get_config(&self) -> Result { - let config_ptr = unsafe { nitrokey_sys::NK_read_config() }; - if config_ptr.is_null() { - return Err(get_last_error()); - } - let config_array_ptr = config_ptr as *const [u8; 5]; - let raw_config = unsafe { RawConfig::from(*config_array_ptr) }; - unsafe { libc::free(config_ptr as *mut libc::c_void) }; - Ok(raw_config.into()) - } - - /// Changes the administrator PIN. - /// - /// # Errors - /// - /// - [`InvalidString`][] if one of the provided passwords contains a null byte - /// - [`WrongPassword`][] if the current admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// match device.change_admin_pin("12345678", "12345679") { - /// Ok(()) => println!("Updated admin PIN."), - /// Err(err) => eprintln!("Failed to update admin PIN: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - fn change_admin_pin(&mut self, current: &str, new: &str) -> Result<(), Error> { - let current_string = get_cstring(current)?; - let new_string = get_cstring(new)?; - get_command_result(unsafe { - nitrokey_sys::NK_change_admin_PIN(current_string.as_ptr(), new_string.as_ptr()) - }) - } - - /// Changes the user PIN. - /// - /// # Errors - /// - /// - [`InvalidString`][] if one of the provided passwords contains a null byte - /// - [`WrongPassword`][] if the current user password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// match device.change_user_pin("123456", "123457") { - /// Ok(()) => println!("Updated admin PIN."), - /// Err(err) => eprintln!("Failed to update admin PIN: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - fn change_user_pin(&mut self, current: &str, new: &str) -> Result<(), Error> { - let current_string = get_cstring(current)?; - let new_string = get_cstring(new)?; - get_command_result(unsafe { - nitrokey_sys::NK_change_user_PIN(current_string.as_ptr(), new_string.as_ptr()) - }) - } - - /// Unlocks the user PIN after three failed login attempts and sets it to the given value. - /// - /// # Errors - /// - /// - [`InvalidString`][] if one of the provided passwords contains a null byte - /// - [`WrongPassword`][] if the admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// match device.unlock_user_pin("12345678", "123456") { - /// Ok(()) => println!("Unlocked user PIN."), - /// Err(err) => eprintln!("Failed to unlock user PIN: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - fn unlock_user_pin(&mut self, admin_pin: &str, user_pin: &str) -> Result<(), Error> { - let admin_pin_string = get_cstring(admin_pin)?; - let user_pin_string = get_cstring(user_pin)?; - get_command_result(unsafe { - nitrokey_sys::NK_unlock_user_password( - admin_pin_string.as_ptr(), - user_pin_string.as_ptr(), - ) - }) - } - - /// Locks the Nitrokey device. - /// - /// This disables the password store if it has been unlocked. On the Nitrokey Storage, this - /// also disables the volumes if they have been enabled. - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// match device.lock() { - /// Ok(()) => println!("Locked the Nitrokey device."), - /// Err(err) => eprintln!("Could not lock the Nitrokey device: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - fn lock(&mut self) -> Result<(), Error> { - get_command_result(unsafe { nitrokey_sys::NK_lock_device() }) - } - - /// Performs a factory reset on the Nitrokey device. - /// - /// This commands performs a factory reset on the smart card (like the factory reset via `gpg - /// --card-edit`) and then clears the flash memory (password safe, one-time passwords etc.). - /// After a factory reset, [`build_aes_key`][] has to be called before the password safe or the - /// encrypted volume can be used. - /// - /// # Errors - /// - /// - [`InvalidString`][] if the provided password contains a null byte - /// - [`WrongPassword`][] if the admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// match device.factory_reset("12345678") { - /// Ok(()) => println!("Performed a factory reset."), - /// Err(err) => eprintln!("Could not perform a factory reset: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`build_aes_key`]: #method.build_aes_key - fn factory_reset(&mut self, admin_pin: &str) -> Result<(), Error> { - let admin_pin_string = get_cstring(admin_pin)?; - get_command_result(unsafe { nitrokey_sys::NK_factory_reset(admin_pin_string.as_ptr()) }) - } - - /// Builds a new AES key on the Nitrokey. - /// - /// The AES key is used to encrypt the password safe and the encrypted volume. You may need - /// to call this method after a factory reset, either using [`factory_reset`][] or using `gpg - /// --card-edit`. You can also use it to destroy the data stored in the password safe or on - /// the encrypted volume. - /// - /// # Errors - /// - /// - [`InvalidString`][] if the provided password contains a null byte - /// - [`WrongPassword`][] if the admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::Device; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// match device.build_aes_key("12345678") { - /// Ok(()) => println!("New AES keys have been built."), - /// Err(err) => eprintln!("Could not build new AES keys: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`factory_reset`]: #method.factory_reset - fn build_aes_key(&mut self, admin_pin: &str) -> Result<(), Error> { - let admin_pin_string = get_cstring(admin_pin)?; - get_command_result(unsafe { nitrokey_sys::NK_build_aes_key(admin_pin_string.as_ptr()) }) - } -} - -fn get_connected_model() -> Option { - match unsafe { nitrokey_sys::NK_get_device_model() } { - nitrokey_sys::NK_device_model_NK_PRO => Some(Model::Pro), - nitrokey_sys::NK_device_model_NK_STORAGE => Some(Model::Storage), - _ => None, - } -} - -pub(crate) fn create_device_wrapper( - manager: &mut crate::Manager, - model: Model, -) -> DeviceWrapper<'_> { - match model { - Model::Pro => Pro::new(manager).into(), - Model::Storage => Storage::new(manager).into(), - } -} - -pub(crate) fn get_connected_device( - manager: &mut crate::Manager, -) -> Result, Error> { - match get_connected_model() { - Some(model) => Ok(create_device_wrapper(manager, model)), - None => Err(CommunicationError::NotConnected.into()), - } -} - -pub(crate) fn connect_enum(model: Model) -> bool { - let model = match model { - Model::Storage => nitrokey_sys::NK_device_model_NK_STORAGE, - Model::Pro => nitrokey_sys::NK_device_model_NK_PRO, - }; - unsafe { nitrokey_sys::NK_login_enum(model) == 1 } -} diff --git a/nitrokey/src/device/pro.rs b/nitrokey/src/device/pro.rs deleted file mode 100644 index a65345e..0000000 --- a/nitrokey/src/device/pro.rs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use nitrokey_sys; - -use crate::device::{Device, Model}; -use crate::otp::GenerateOtp; - -/// A Nitrokey Pro device without user or admin authentication. -/// -/// Use the [`connect`][] method to obtain an instance wrapper or the [`connect_pro`] method to -/// directly obtain an instance. If you want to execute a command that requires user or admin -/// authentication, use [`authenticate_admin`][] or [`authenticate_user`][]. -/// -/// # Examples -/// -/// Authentication with error handling: -/// -/// ```no_run -/// use nitrokey::{Authenticate, User, Pro}; -/// # use nitrokey::Error; -/// -/// fn perform_user_task<'a>(device: &User<'a, Pro<'a>>) {} -/// fn perform_other_task(device: &Pro) {} -/// -/// # fn try_main() -> Result<(), Error> { -/// let mut manager = nitrokey::take()?; -/// let device = manager.connect_pro()?; -/// let device = match device.authenticate_user("123456") { -/// Ok(user) => { -/// perform_user_task(&user); -/// user.device() -/// }, -/// Err((device, err)) => { -/// eprintln!("Could not authenticate as user: {}", err); -/// device -/// }, -/// }; -/// perform_other_task(&device); -/// # Ok(()) -/// # } -/// ``` -/// -/// [`authenticate_admin`]: trait.Authenticate.html#method.authenticate_admin -/// [`authenticate_user`]: trait.Authenticate.html#method.authenticate_user -/// [`connect`]: struct.Manager.html#method.connect -/// [`connect_pro`]: struct.Manager.html#method.connect_pro -#[derive(Debug)] -pub struct Pro<'a> { - manager: Option<&'a mut crate::Manager>, -} - -impl<'a> Pro<'a> { - pub(crate) fn new(manager: &'a mut crate::Manager) -> Pro<'a> { - Pro { - manager: Some(manager), - } - } -} - -impl<'a> Drop for Pro<'a> { - fn drop(&mut self) { - unsafe { - nitrokey_sys::NK_logout(); - } - } -} - -impl<'a> Device<'a> for Pro<'a> { - fn into_manager(mut self) -> &'a mut crate::Manager { - self.manager.take().unwrap() - } - - fn get_model(&self) -> Model { - Model::Pro - } -} - -impl<'a> GenerateOtp for Pro<'a> {} diff --git a/nitrokey/src/device/storage.rs b/nitrokey/src/device/storage.rs deleted file mode 100644 index 370ce36..0000000 --- a/nitrokey/src/device/storage.rs +++ /dev/null @@ -1,735 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use std::fmt; - -use nitrokey_sys; - -use crate::device::{Device, FirmwareVersion, Model}; -use crate::error::Error; -use crate::otp::GenerateOtp; -use crate::util::{get_command_result, get_cstring}; - -/// A Nitrokey Storage device without user or admin authentication. -/// -/// Use the [`connect`][] method to obtain an instance wrapper or the [`connect_storage`] method to -/// directly obtain an instance. If you want to execute a command that requires user or admin -/// authentication, use [`authenticate_admin`][] or [`authenticate_user`][]. -/// -/// # Examples -/// -/// Authentication with error handling: -/// -/// ```no_run -/// use nitrokey::{Authenticate, User, Storage}; -/// # use nitrokey::Error; -/// -/// fn perform_user_task<'a>(device: &User<'a, Storage<'a>>) {} -/// fn perform_other_task(device: &Storage) {} -/// -/// # fn try_main() -> Result<(), Error> { -/// let mut manager = nitrokey::take()?; -/// let device = manager.connect_storage()?; -/// let device = match device.authenticate_user("123456") { -/// Ok(user) => { -/// perform_user_task(&user); -/// user.device() -/// }, -/// Err((device, err)) => { -/// eprintln!("Could not authenticate as user: {}", err); -/// device -/// }, -/// }; -/// perform_other_task(&device); -/// # Ok(()) -/// # } -/// ``` -/// -/// [`authenticate_admin`]: trait.Authenticate.html#method.authenticate_admin -/// [`authenticate_user`]: trait.Authenticate.html#method.authenticate_user -/// [`connect`]: struct.Manager.html#method.connect -/// [`connect_storage`]: struct.Manager.html#method.connect_storage -#[derive(Debug)] -pub struct Storage<'a> { - manager: Option<&'a mut crate::Manager>, -} - -/// The access mode of a volume on the Nitrokey Storage. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum VolumeMode { - /// A read-only volume. - ReadOnly, - /// A read-write volume. - ReadWrite, -} - -impl fmt::Display for VolumeMode { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match *self { - VolumeMode::ReadOnly => "read-only", - VolumeMode::ReadWrite => "read-write", - }) - } -} - -/// The status of a volume on a Nitrokey Storage device. -#[derive(Debug)] -pub struct VolumeStatus { - /// Indicates whether the volume is read-only. - pub read_only: bool, - /// Indicates whether the volume is active. - pub active: bool, -} - -/// Information about the SD card in a Storage device. -#[derive(Debug)] -pub struct SdCardData { - /// The serial number of the SD card. - pub serial_number: u32, - /// The size of the SD card in GB. - pub size: u8, - /// The year the card was manufactured, e. g. 17 for 2017. - pub manufacturing_year: u8, - /// The month the card was manufactured. - pub manufacturing_month: u8, - /// The OEM ID. - pub oem: u16, - /// The manufacturer ID. - pub manufacturer: u8, -} - -/// Production information for a Storage device. -#[derive(Debug)] -pub struct StorageProductionInfo { - /// The firmware version. - pub firmware_version: FirmwareVersion, - /// The internal firmware version. - pub firmware_version_internal: u8, - /// The serial number of the CPU. - pub serial_number_cpu: u32, - /// Information about the SD card. - pub sd_card: SdCardData, -} - -/// The status of a Nitrokey Storage device. -#[derive(Debug)] -pub struct StorageStatus { - /// The status of the unencrypted volume. - pub unencrypted_volume: VolumeStatus, - /// The status of the encrypted volume. - pub encrypted_volume: VolumeStatus, - /// The status of the hidden volume. - pub hidden_volume: VolumeStatus, - /// The firmware version. - pub firmware_version: FirmwareVersion, - /// Indicates whether the firmware is locked. - pub firmware_locked: bool, - /// The serial number of the SD card in the Storage stick. - pub serial_number_sd_card: u32, - /// The serial number of the smart card in the Storage stick. - pub serial_number_smart_card: u32, - /// The number of remaining login attempts for the user PIN. - pub user_retry_count: u8, - /// The number of remaining login attempts for the admin PIN. - pub admin_retry_count: u8, - /// Indicates whether a new SD card was found. - pub new_sd_card_found: bool, - /// Indicates whether the SD card is filled with random characters. - pub filled_with_random: bool, - /// Indicates whether the stick has been initialized by generating - /// the AES keys. - pub stick_initialized: bool, -} - -impl<'a> Storage<'a> { - pub(crate) fn new(manager: &'a mut crate::Manager) -> Storage<'a> { - Storage { - manager: Some(manager), - } - } - - /// Changes the update PIN. - /// - /// The update PIN is used to enable firmware updates. Unlike the user and the admin PIN, the - /// update PIN is not managed by the OpenPGP smart card but by the Nitrokey firmware. There is - /// no retry counter as with the other PIN types. - /// - /// # Errors - /// - /// - [`InvalidString`][] if one of the provided passwords contains a null byte - /// - [`WrongPassword`][] if the current update password is wrong - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// match device.change_update_pin("12345678", "87654321") { - /// Ok(()) => println!("Updated update PIN."), - /// Err(err) => eprintln!("Failed to update update PIN: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - pub fn change_update_pin(&mut self, current: &str, new: &str) -> Result<(), Error> { - let current_string = get_cstring(current)?; - let new_string = get_cstring(new)?; - get_command_result(unsafe { - nitrokey_sys::NK_change_update_password(current_string.as_ptr(), new_string.as_ptr()) - }) - } - - /// Enables the firmware update mode. - /// - /// During firmware update mode, the Nitrokey can no longer be accessed using HID commands. - /// To resume normal operation, run `dfu-programmer at32uc3a3256s launch`. In order to enter - /// the firmware update mode, you need the update password that can be changed using the - /// [`change_update_pin`][] method. - /// - /// # Errors - /// - /// - [`InvalidString`][] if one of the provided passwords contains a null byte - /// - [`WrongPassword`][] if the current update password is wrong - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// match device.enable_firmware_update("12345678") { - /// Ok(()) => println!("Nitrokey entered update mode."), - /// Err(err) => eprintln!("Could not enter update mode: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - pub fn enable_firmware_update(&mut self, update_pin: &str) -> Result<(), Error> { - let update_pin_string = get_cstring(update_pin)?; - get_command_result(unsafe { - nitrokey_sys::NK_enable_firmware_update(update_pin_string.as_ptr()) - }) - } - - /// Enables the encrypted storage volume. - /// - /// Once the encrypted volume is enabled, it is presented to the operating system as a block - /// device. The API does not provide any information on the name or path of this block device. - /// - /// # Errors - /// - /// - [`InvalidString`][] if the provided password contains a null byte - /// - [`WrongPassword`][] if the provided user password is wrong - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// match device.enable_encrypted_volume("123456") { - /// Ok(()) => println!("Enabled the encrypted volume."), - /// Err(err) => eprintln!("Could not enable the encrypted volume: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - pub fn enable_encrypted_volume(&mut self, user_pin: &str) -> Result<(), Error> { - let user_pin = get_cstring(user_pin)?; - get_command_result(unsafe { nitrokey_sys::NK_unlock_encrypted_volume(user_pin.as_ptr()) }) - } - - /// Disables the encrypted storage volume. - /// - /// Once the volume is disabled, it can be no longer accessed as a block device. If the - /// encrypted volume has not been enabled, this method still returns a success. - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// fn use_volume() {} - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// match device.enable_encrypted_volume("123456") { - /// Ok(()) => { - /// println!("Enabled the encrypted volume."); - /// use_volume(); - /// match device.disable_encrypted_volume() { - /// Ok(()) => println!("Disabled the encrypted volume."), - /// Err(err) => { - /// eprintln!("Could not disable the encrypted volume: {}", err); - /// }, - /// }; - /// }, - /// Err(err) => eprintln!("Could not enable the encrypted volume: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - pub fn disable_encrypted_volume(&mut self) -> Result<(), Error> { - get_command_result(unsafe { nitrokey_sys::NK_lock_encrypted_volume() }) - } - - /// Enables a hidden storage volume. - /// - /// This function will only succeed if the encrypted storage ([`enable_encrypted_volume`][]) or - /// another hidden volume has been enabled previously. Once the hidden volume is enabled, it - /// is presented to the operating system as a block device and any previously opened encrypted - /// or hidden volumes are closed. The API does not provide any information on the name or path - /// of this block device. - /// - /// Note that the encrypted and the hidden volumes operate on the same storage area, so using - /// both at the same time might lead to data loss. - /// - /// The hidden volume to unlock is selected based on the provided password. - /// - /// # Errors - /// - /// - [`AesDecryptionFailed`][] if the encrypted storage has not been opened before calling - /// this method or the AES key has not been built - /// - [`InvalidString`][] if the provided password contains a null byte - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// device.enable_encrypted_volume("123445")?; - /// match device.enable_hidden_volume("hidden-pw") { - /// Ok(()) => println!("Enabled a hidden volume."), - /// Err(err) => eprintln!("Could not enable the hidden volume: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`enable_encrypted_volume`]: #method.enable_encrypted_volume - /// [`AesDecryptionFailed`]: enum.CommandError.html#variant.AesDecryptionFailed - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - pub fn enable_hidden_volume(&mut self, volume_password: &str) -> Result<(), Error> { - let volume_password = get_cstring(volume_password)?; - get_command_result(unsafe { - nitrokey_sys::NK_unlock_hidden_volume(volume_password.as_ptr()) - }) - } - - /// Disables a hidden storage volume. - /// - /// Once the volume is disabled, it can be no longer accessed as a block device. If no hidden - /// volume has been enabled, this method still returns a success. - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// fn use_volume() {} - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// device.enable_encrypted_volume("123445")?; - /// match device.enable_hidden_volume("hidden-pw") { - /// Ok(()) => { - /// println!("Enabled the hidden volume."); - /// use_volume(); - /// match device.disable_hidden_volume() { - /// Ok(()) => println!("Disabled the hidden volume."), - /// Err(err) => { - /// eprintln!("Could not disable the hidden volume: {}", err); - /// }, - /// }; - /// }, - /// Err(err) => eprintln!("Could not enable the hidden volume: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - pub fn disable_hidden_volume(&mut self) -> Result<(), Error> { - get_command_result(unsafe { nitrokey_sys::NK_lock_hidden_volume() }) - } - - /// Creates a hidden volume. - /// - /// The volume is crated in the given slot and in the given range of the available memory, - /// where `start` is the start position as a percentage of the available memory, and `end` is - /// the end position as a percentage of the available memory. The volume will be protected by - /// the given password. - /// - /// Note that the encrypted and the hidden volumes operate on the same storage area, so using - /// both at the same time might lead to data loss. - /// - /// According to the libnitrokey documentation, this function only works if the encrypted - /// storage has been opened. - /// - /// # Errors - /// - /// - [`AesDecryptionFailed`][] if the encrypted storage has not been opened before calling - /// this method or the AES key has not been built - /// - [`InvalidString`][] if the provided password contains a null byte - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// device.enable_encrypted_volume("123445")?; - /// device.create_hidden_volume(0, 0, 100, "hidden-pw")?; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`AesDecryptionFailed`]: enum.CommandError.html#variant.AesDecryptionFailed - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - pub fn create_hidden_volume( - &mut self, - slot: u8, - start: u8, - end: u8, - password: &str, - ) -> Result<(), Error> { - let password = get_cstring(password)?; - get_command_result(unsafe { - nitrokey_sys::NK_create_hidden_volume(slot, start, end, password.as_ptr()) - }) - } - - /// Sets the access mode of the unencrypted volume. - /// - /// This command will reconnect the unencrypted volume so buffers should be flushed before - /// calling it. Since firmware version v0.51, this command requires the admin PIN. Older - /// firmware versions are not supported. - /// - /// # Errors - /// - /// - [`InvalidString`][] if the provided password contains a null byte - /// - [`WrongPassword`][] if the provided admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// use nitrokey::VolumeMode; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// match device.set_unencrypted_volume_mode("12345678", VolumeMode::ReadWrite) { - /// Ok(()) => println!("Set the unencrypted volume to read-write mode."), - /// Err(err) => eprintln!("Could not set the unencrypted volume to read-write mode: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - pub fn set_unencrypted_volume_mode( - &mut self, - admin_pin: &str, - mode: VolumeMode, - ) -> Result<(), Error> { - let admin_pin = get_cstring(admin_pin)?; - let result = match mode { - VolumeMode::ReadOnly => unsafe { - nitrokey_sys::NK_set_unencrypted_read_only_admin(admin_pin.as_ptr()) - }, - VolumeMode::ReadWrite => unsafe { - nitrokey_sys::NK_set_unencrypted_read_write_admin(admin_pin.as_ptr()) - }, - }; - get_command_result(result) - } - - /// Sets the access mode of the encrypted volume. - /// - /// This command will reconnect the encrypted volume so buffers should be flushed before - /// calling it. It is only available in firmware version 0.49. - /// - /// # Errors - /// - /// - [`InvalidString`][] if the provided password contains a null byte - /// - [`WrongPassword`][] if the provided admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// use nitrokey::VolumeMode; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// match device.set_encrypted_volume_mode("12345678", VolumeMode::ReadWrite) { - /// Ok(()) => println!("Set the encrypted volume to read-write mode."), - /// Err(err) => eprintln!("Could not set the encrypted volume to read-write mode: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - pub fn set_encrypted_volume_mode( - &mut self, - admin_pin: &str, - mode: VolumeMode, - ) -> Result<(), Error> { - let admin_pin = get_cstring(admin_pin)?; - let result = match mode { - VolumeMode::ReadOnly => unsafe { - nitrokey_sys::NK_set_encrypted_read_only(admin_pin.as_ptr()) - }, - VolumeMode::ReadWrite => unsafe { - nitrokey_sys::NK_set_encrypted_read_write(admin_pin.as_ptr()) - }, - }; - get_command_result(result) - } - - /// Returns the status of the connected storage device. - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// fn use_volume() {} - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect_storage()?; - /// match device.get_status() { - /// Ok(status) => { - /// println!("SD card ID: {:#x}", status.serial_number_sd_card); - /// }, - /// Err(err) => eprintln!("Could not get Storage status: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - pub fn get_status(&self) -> Result { - let mut raw_status = nitrokey_sys::NK_storage_status { - unencrypted_volume_read_only: false, - unencrypted_volume_active: false, - encrypted_volume_read_only: false, - encrypted_volume_active: false, - hidden_volume_read_only: false, - hidden_volume_active: false, - firmware_version_major: 0, - firmware_version_minor: 0, - firmware_locked: false, - serial_number_sd_card: 0, - serial_number_smart_card: 0, - user_retry_count: 0, - admin_retry_count: 0, - new_sd_card_found: false, - filled_with_random: false, - stick_initialized: false, - }; - let raw_result = unsafe { nitrokey_sys::NK_get_status_storage(&mut raw_status) }; - get_command_result(raw_result).map(|_| StorageStatus::from(raw_status)) - } - - /// Returns the production information for the connected storage device. - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// fn use_volume() {} - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect_storage()?; - /// match device.get_production_info() { - /// Ok(data) => { - /// println!("SD card ID: {:#x}", data.sd_card.serial_number); - /// println!("SD card size: {} GB", data.sd_card.size); - /// }, - /// Err(err) => eprintln!("Could not get Storage production info: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - pub fn get_production_info(&self) -> Result { - let mut raw_data = nitrokey_sys::NK_storage_ProductionTest { - FirmwareVersion_au8: [0, 2], - FirmwareVersionInternal_u8: 0, - SD_Card_Size_u8: 0, - CPU_CardID_u32: 0, - SmartCardID_u32: 0, - SD_CardID_u32: 0, - SC_UserPwRetryCount: 0, - SC_AdminPwRetryCount: 0, - SD_Card_ManufacturingYear_u8: 0, - SD_Card_ManufacturingMonth_u8: 0, - SD_Card_OEM_u16: 0, - SD_WriteSpeed_u16: 0, - SD_Card_Manufacturer_u8: 0, - }; - let raw_result = unsafe { nitrokey_sys::NK_get_storage_production_info(&mut raw_data) }; - get_command_result(raw_result).map(|_| StorageProductionInfo::from(raw_data)) - } - - /// Clears the warning for a new SD card. - /// - /// The Storage status contains a field for a new SD card warning. After a factory reset, the - /// field is set to true. After filling the SD card with random data, it is set to false. - /// This method can be used to set it to false without filling the SD card with random data. - /// - /// # Errors - /// - /// - [`InvalidString`][] if the provided password contains a null byte - /// - [`WrongPassword`][] if the provided admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect_storage()?; - /// match device.clear_new_sd_card_warning("12345678") { - /// Ok(()) => println!("Cleared the new SD card warning."), - /// Err(err) => eprintln!("Could not set the clear the new SD card warning: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - pub fn clear_new_sd_card_warning(&mut self, admin_pin: &str) -> Result<(), Error> { - let admin_pin = get_cstring(admin_pin)?; - get_command_result(unsafe { - nitrokey_sys::NK_clear_new_sd_card_warning(admin_pin.as_ptr()) - }) - } - - /// Blinks the red and green LED alternatively and infinitely until the device is reconnected. - pub fn wink(&mut self) -> Result<(), Error> { - get_command_result(unsafe { nitrokey_sys::NK_wink() }) - } - - /// Exports the firmware to the unencrypted volume. - /// - /// This command requires the admin PIN. The unencrypted volume must be in read-write mode - /// when this command is executed. Otherwise, it will still return `Ok` but not write the - /// firmware. - /// - /// This command unmounts the unencrypted volume if it has been mounted, so all buffers should - /// be flushed. The firmware is written to the `firmware.bin` file on the unencrypted volume. - /// - /// # Errors - /// - /// - [`InvalidString`][] if one of the provided passwords contains a null byte - /// - [`WrongPassword`][] if the admin password is wrong - /// - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - pub fn export_firmware(&mut self, admin_pin: &str) -> Result<(), Error> { - let admin_pin_string = get_cstring(admin_pin)?; - get_command_result(unsafe { nitrokey_sys::NK_export_firmware(admin_pin_string.as_ptr()) }) - } -} - -impl<'a> Drop for Storage<'a> { - fn drop(&mut self) { - unsafe { - nitrokey_sys::NK_logout(); - } - } -} - -impl<'a> Device<'a> for Storage<'a> { - fn into_manager(mut self) -> &'a mut crate::Manager { - self.manager.take().unwrap() - } - - fn get_model(&self) -> Model { - Model::Storage - } -} - -impl<'a> GenerateOtp for Storage<'a> {} - -impl From for StorageProductionInfo { - fn from(data: nitrokey_sys::NK_storage_ProductionTest) -> Self { - Self { - firmware_version: FirmwareVersion { - major: data.FirmwareVersion_au8[0], - minor: data.FirmwareVersion_au8[1], - }, - firmware_version_internal: data.FirmwareVersionInternal_u8, - serial_number_cpu: data.CPU_CardID_u32, - sd_card: SdCardData { - serial_number: data.SD_CardID_u32, - size: data.SD_Card_Size_u8, - manufacturing_year: data.SD_Card_ManufacturingYear_u8, - manufacturing_month: data.SD_Card_ManufacturingMonth_u8, - oem: data.SD_Card_OEM_u16, - manufacturer: data.SD_Card_Manufacturer_u8, - }, - } - } -} - -impl From for StorageStatus { - fn from(status: nitrokey_sys::NK_storage_status) -> Self { - StorageStatus { - unencrypted_volume: VolumeStatus { - read_only: status.unencrypted_volume_read_only, - active: status.unencrypted_volume_active, - }, - encrypted_volume: VolumeStatus { - read_only: status.encrypted_volume_read_only, - active: status.encrypted_volume_active, - }, - hidden_volume: VolumeStatus { - read_only: status.hidden_volume_read_only, - active: status.hidden_volume_active, - }, - firmware_version: FirmwareVersion { - major: status.firmware_version_major, - minor: status.firmware_version_minor, - }, - firmware_locked: status.firmware_locked, - serial_number_sd_card: status.serial_number_sd_card, - serial_number_smart_card: status.serial_number_smart_card, - user_retry_count: status.user_retry_count, - admin_retry_count: status.admin_retry_count, - new_sd_card_found: status.new_sd_card_found, - filled_with_random: status.filled_with_random, - stick_initialized: status.stick_initialized, - } - } -} diff --git a/nitrokey/src/device/wrapper.rs b/nitrokey/src/device/wrapper.rs deleted file mode 100644 index a3a18f9..0000000 --- a/nitrokey/src/device/wrapper.rs +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use crate::device::{Device, Model, Pro, Storage}; -use crate::error::Error; -use crate::otp::GenerateOtp; - -/// A wrapper for a Nitrokey device of unknown type. -/// -/// Use the [`connect`][] method to obtain a wrapped instance. The wrapper implements all traits -/// that are shared between all Nitrokey devices so that the shared functionality can be used -/// without knowing the type of the underlying device. If you want to use functionality that is -/// not available for all devices, you have to extract the device. -/// -/// # Examples -/// -/// Authentication with error handling: -/// -/// ```no_run -/// use nitrokey::{Authenticate, DeviceWrapper, User}; -/// # use nitrokey::Error; -/// -/// fn perform_user_task<'a>(device: &User<'a, DeviceWrapper<'a>>) {} -/// fn perform_other_task(device: &DeviceWrapper) {} -/// -/// # fn try_main() -> Result<(), Error> { -/// let mut manager = nitrokey::take()?; -/// let device = manager.connect()?; -/// let device = match device.authenticate_user("123456") { -/// Ok(user) => { -/// perform_user_task(&user); -/// user.device() -/// }, -/// Err((device, err)) => { -/// eprintln!("Could not authenticate as user: {}", err); -/// device -/// }, -/// }; -/// perform_other_task(&device); -/// # Ok(()) -/// # } -/// ``` -/// -/// Device-specific commands: -/// -/// ```no_run -/// use nitrokey::{DeviceWrapper, Storage}; -/// # use nitrokey::Error; -/// -/// fn perform_common_task(device: &DeviceWrapper) {} -/// fn perform_storage_task(device: &Storage) {} -/// -/// # fn try_main() -> Result<(), Error> { -/// let mut manager = nitrokey::take()?; -/// let device = manager.connect()?; -/// perform_common_task(&device); -/// match device { -/// DeviceWrapper::Storage(storage) => perform_storage_task(&storage), -/// _ => (), -/// }; -/// # Ok(()) -/// # } -/// ``` -/// -/// [`connect`]: struct.Manager.html#method.connect -#[derive(Debug)] -pub enum DeviceWrapper<'a> { - /// A Nitrokey Storage device. - Storage(Storage<'a>), - /// A Nitrokey Pro device. - Pro(Pro<'a>), -} - -impl<'a> DeviceWrapper<'a> { - fn device(&self) -> &dyn Device<'a> { - match *self { - DeviceWrapper::Storage(ref storage) => storage, - DeviceWrapper::Pro(ref pro) => pro, - } - } - - fn device_mut(&mut self) -> &mut dyn Device<'a> { - match *self { - DeviceWrapper::Storage(ref mut storage) => storage, - DeviceWrapper::Pro(ref mut pro) => pro, - } - } -} - -impl<'a> From> for DeviceWrapper<'a> { - fn from(device: Pro<'a>) -> Self { - DeviceWrapper::Pro(device) - } -} - -impl<'a> From> for DeviceWrapper<'a> { - fn from(device: Storage<'a>) -> Self { - DeviceWrapper::Storage(device) - } -} - -impl<'a> GenerateOtp for DeviceWrapper<'a> { - fn get_hotp_slot_name(&self, slot: u8) -> Result { - self.device().get_hotp_slot_name(slot) - } - - fn get_totp_slot_name(&self, slot: u8) -> Result { - self.device().get_totp_slot_name(slot) - } - - fn get_hotp_code(&mut self, slot: u8) -> Result { - self.device_mut().get_hotp_code(slot) - } - - fn get_totp_code(&self, slot: u8) -> Result { - self.device().get_totp_code(slot) - } -} - -impl<'a> Device<'a> for DeviceWrapper<'a> { - fn into_manager(self) -> &'a mut crate::Manager { - match self { - DeviceWrapper::Pro(dev) => dev.into_manager(), - DeviceWrapper::Storage(dev) => dev.into_manager(), - } - } - - fn get_model(&self) -> Model { - match *self { - DeviceWrapper::Pro(_) => Model::Pro, - DeviceWrapper::Storage(_) => Model::Storage, - } - } -} diff --git a/nitrokey/src/error.rs b/nitrokey/src/error.rs deleted file mode 100644 index 9e6adc0..0000000 --- a/nitrokey/src/error.rs +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright (C) 2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use std::error; -use std::fmt; -use std::os::raw; -use std::str; -use std::sync; - -use crate::device; - -/// An error returned by the nitrokey crate. -#[derive(Debug)] -pub enum Error { - /// An error reported by the Nitrokey device in the response packet. - CommandError(CommandError), - /// A device communication error. - CommunicationError(CommunicationError), - /// An error occurred due to concurrent access to the Nitrokey device. - ConcurrentAccessError, - /// A library usage error. - LibraryError(LibraryError), - /// An error that occurred due to a poisoned lock. - PoisonError(sync::PoisonError>), - /// An error that occurred during random number generation. - RandError(Box), - /// An error that is caused by an unexpected value returned by libnitrokey. - UnexpectedError, - /// An unknown error returned by libnitrokey. - UnknownError(i64), - /// An error occurred when interpreting a UTF-8 string. - Utf8Error(str::Utf8Error), -} - -impl From for Error { - fn from(code: raw::c_int) -> Self { - if let Some(err) = CommandError::try_from(code) { - Error::CommandError(err) - } else if let Some(err) = CommunicationError::try_from(256 - code) { - Error::CommunicationError(err) - } else if let Some(err) = LibraryError::try_from(code) { - Error::LibraryError(err) - } else { - Error::UnknownError(code.into()) - } - } -} - -impl From for Error { - fn from(err: CommandError) -> Self { - Error::CommandError(err) - } -} - -impl From for Error { - fn from(err: CommunicationError) -> Self { - Error::CommunicationError(err) - } -} - -impl From for Error { - fn from(err: LibraryError) -> Self { - Error::LibraryError(err) - } -} - -impl From for Error { - fn from(error: str::Utf8Error) -> Self { - Error::Utf8Error(error) - } -} - -impl From>> for Error { - fn from(error: sync::PoisonError>) -> Self { - Error::PoisonError(error) - } -} - -impl From>> for Error { - fn from(error: sync::TryLockError>) -> Self { - match error { - sync::TryLockError::Poisoned(err) => err.into(), - sync::TryLockError::WouldBlock => Error::ConcurrentAccessError, - } - } -} - -impl<'a, T: device::Device<'a>> From<(T, Error)> for Error { - fn from((_, err): (T, Error)) -> Self { - err - } -} - -impl error::Error for Error { - fn source(&self) -> Option<&(dyn error::Error + 'static)> { - match *self { - Error::CommandError(ref err) => Some(err), - Error::CommunicationError(ref err) => Some(err), - Error::ConcurrentAccessError => None, - Error::LibraryError(ref err) => Some(err), - Error::PoisonError(ref err) => Some(err), - Error::RandError(ref err) => Some(err.as_ref()), - Error::UnexpectedError => None, - Error::UnknownError(_) => None, - Error::Utf8Error(ref err) => Some(err), - } - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self { - Error::CommandError(ref err) => write!(f, "Command error: {}", err), - Error::CommunicationError(ref err) => write!(f, "Communication error: {}", err), - Error::ConcurrentAccessError => write!(f, "Internal error: concurrent access"), - Error::LibraryError(ref err) => write!(f, "Library error: {}", err), - Error::PoisonError(_) => write!(f, "Internal error: poisoned lock"), - Error::RandError(ref err) => write!(f, "RNG error: {}", err), - Error::UnexpectedError => write!(f, "An unexpected error occurred"), - Error::UnknownError(ref err) => write!(f, "Unknown error: {}", err), - Error::Utf8Error(ref err) => write!(f, "UTF-8 error: {}", err), - } - } -} - -/// An error reported by the Nitrokey device in the response packet. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum CommandError { - /// A packet with a wrong checksum has been sent or received. - WrongCrc, - /// A command tried to access an OTP slot that does not exist. - WrongSlot, - /// A command tried to generate an OTP on a slot that is not configured. - SlotNotProgrammed, - /// The provided password is wrong. - WrongPassword, - /// You are not authorized for this command or provided a wrong temporary - /// password. - NotAuthorized, - /// An error occurred when getting or setting the time. - Timestamp, - /// You did not provide a name for the OTP slot. - NoName, - /// This command is not supported by this device. - NotSupported, - /// This command is unknown. - UnknownCommand, - /// AES decryption failed. - AesDecryptionFailed, -} - -impl CommandError { - fn try_from(value: raw::c_int) -> Option { - match value { - 1 => Some(CommandError::WrongCrc), - 2 => Some(CommandError::WrongSlot), - 3 => Some(CommandError::SlotNotProgrammed), - 4 => Some(CommandError::WrongPassword), - 5 => Some(CommandError::NotAuthorized), - 6 => Some(CommandError::Timestamp), - 7 => Some(CommandError::NoName), - 8 => Some(CommandError::NotSupported), - 9 => Some(CommandError::UnknownCommand), - 10 => Some(CommandError::AesDecryptionFailed), - _ => None, - } - } -} - -impl error::Error for CommandError {} - -impl fmt::Display for CommandError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match *self { - CommandError::WrongCrc => "A packet with a wrong checksum has been sent or received", - CommandError::WrongSlot => "The given slot does not exist", - CommandError::SlotNotProgrammed => "The given slot is not programmed", - CommandError::WrongPassword => "The given password is wrong", - CommandError::NotAuthorized => { - "You are not authorized for this command or provided a wrong temporary \ - password" - } - CommandError::Timestamp => "An error occurred when getting or setting the time", - CommandError::NoName => "You did not provide a name for the slot", - CommandError::NotSupported => "This command is not supported by this device", - CommandError::UnknownCommand => "This command is unknown", - CommandError::AesDecryptionFailed => "AES decryption failed", - }) - } -} - -/// A device communication error. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum CommunicationError { - /// Could not connect to a Nitrokey device. - NotConnected, - /// Sending a packet failed. - SendingFailure, - /// Receiving a packet failed. - ReceivingFailure, - /// A packet with a wrong checksum was received. - InvalidCrc, -} - -impl CommunicationError { - fn try_from(value: raw::c_int) -> Option { - match value { - 2 => Some(CommunicationError::NotConnected), - 3 => Some(CommunicationError::SendingFailure), - 4 => Some(CommunicationError::ReceivingFailure), - 5 => Some(CommunicationError::InvalidCrc), - _ => None, - } - } -} - -impl error::Error for CommunicationError {} - -impl fmt::Display for CommunicationError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match *self { - CommunicationError::NotConnected => "Could not connect to a Nitrokey device", - CommunicationError::SendingFailure => "Sending a packet failed", - CommunicationError::ReceivingFailure => "Receiving a packet failed", - CommunicationError::InvalidCrc => "A packet with a wrong checksum was received", - }) - } -} - -/// A library usage error. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum LibraryError { - /// A supplied string exceeded a length limit. - StringTooLong, - /// You passed an invalid slot. - InvalidSlot, - /// The supplied string was not in hexadecimal format. - InvalidHexString, - /// The target buffer was smaller than the source. - TargetBufferTooSmall, - /// You passed a string containing a null byte. - InvalidString, -} - -impl LibraryError { - fn try_from(value: raw::c_int) -> Option { - match value { - 200 => Some(LibraryError::StringTooLong), - 201 => Some(LibraryError::InvalidSlot), - 202 => Some(LibraryError::InvalidHexString), - 203 => Some(LibraryError::TargetBufferTooSmall), - _ => None, - } - } -} - -impl error::Error for LibraryError {} - -impl fmt::Display for LibraryError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match *self { - LibraryError::StringTooLong => "The supplied string is too long", - LibraryError::InvalidSlot => "The given slot is invalid", - LibraryError::InvalidHexString => "The supplied string is not in hexadecimal format", - LibraryError::TargetBufferTooSmall => "The target buffer is too small", - LibraryError::InvalidString => "You passed a string containing a null byte", - }) - } -} diff --git a/nitrokey/src/lib.rs b/nitrokey/src/lib.rs deleted file mode 100644 index 059792d..0000000 --- a/nitrokey/src/lib.rs +++ /dev/null @@ -1,465 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -//! Provides access to a Nitrokey device using the native libnitrokey API. -//! -//! # Usage -//! -//! Operations on the Nitrokey require different authentication levels. Some operations can be -//! performed without authentication, some require user access, and some require admin access. -//! This is modelled using the types [`User`][] and [`Admin`][]. -//! -//! You can only connect to one Nitrokey at a time. Use the global [`take`][] function to obtain -//! an reference to the [`Manager`][] singleton that keeps track of the connections. Then use the -//! [`connect`][] method to connect to any Nitrokey device. The method will return a -//! [`DeviceWrapper`][] that abstracts over the supported Nitrokey devices. You can also use -//! [`connect_model`][], [`connect_pro`][] or [`connect_storage`][] to connect to a specific -//! device. -//! -//! You can call [`authenticate_user`][] or [`authenticate_admin`][] to get an authenticated device -//! that can perform operations that require authentication. You can use [`device`][] to go back -//! to the unauthenticated device. -//! -//! This makes sure that you can only execute a command if you have the required access rights. -//! Otherwise, your code will not compile. The only exception are the methods to generate one-time -//! passwords – [`get_hotp_code`][] and [`get_totp_code`][]. Depending on the stick configuration, -//! these operations are available without authentication or with user authentication. -//! -//! # Examples -//! -//! Connect to any Nitrokey and print its serial number: -//! -//! ```no_run -//! use nitrokey::Device; -//! # use nitrokey::Error; -//! -//! # fn try_main() -> Result<(), Error> { -//! let mut manager = nitrokey::take()?; -//! let device = manager.connect()?; -//! println!("{}", device.get_serial_number()?); -//! # Ok(()) -//! # } -//! ``` -//! -//! Configure an HOTP slot: -//! -//! ```no_run -//! use nitrokey::{Authenticate, ConfigureOtp, OtpMode, OtpSlotData}; -//! # use nitrokey::Error; -//! -//! # fn try_main() -> Result<(), Error> { -//! let mut manager = nitrokey::take()?; -//! let device = manager.connect()?; -//! let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::SixDigits); -//! match device.authenticate_admin("12345678") { -//! Ok(mut admin) => { -//! match admin.write_hotp_slot(slot_data, 0) { -//! Ok(()) => println!("Successfully wrote slot."), -//! Err(err) => eprintln!("Could not write slot: {}", err), -//! } -//! }, -//! Err((_, err)) => eprintln!("Could not authenticate as admin: {}", err), -//! } -//! # Ok(()) -//! # } -//! ``` -//! -//! Generate an HOTP one-time password: -//! -//! ```no_run -//! use nitrokey::{Device, GenerateOtp}; -//! # use nitrokey::Error; -//! -//! # fn try_main() -> Result<(), Error> { -//! let mut manager = nitrokey::take()?; -//! let mut device = manager.connect()?; -//! match device.get_hotp_code(1) { -//! Ok(code) => println!("Generated HOTP code: {}", code), -//! Err(err) => eprintln!("Could not generate HOTP code: {}", err), -//! } -//! # Ok(()) -//! # } -//! ``` -//! -//! [`authenticate_admin`]: trait.Authenticate.html#method.authenticate_admin -//! [`authenticate_user`]: trait.Authenticate.html#method.authenticate_user -//! [`take`]: fn.take.html -//! [`connect`]: struct.Manager.html#method.connect -//! [`connect_model`]: struct.Manager.html#method.connect_model -//! [`connect_pro`]: struct.Manager.html#method.connect_pro -//! [`connect_storage`]: struct.Manager.html#method.connect_storage -//! [`manager`]: trait.Device.html#method.manager -//! [`device`]: struct.User.html#method.device -//! [`get_hotp_code`]: trait.GenerateOtp.html#method.get_hotp_code -//! [`get_totp_code`]: trait.GenerateOtp.html#method.get_totp_code -//! [`Admin`]: struct.Admin.html -//! [`DeviceWrapper`]: enum.DeviceWrapper.html -//! [`User`]: struct.User.html - -#![warn(missing_docs, rust_2018_compatibility, rust_2018_idioms, unused)] - -#[macro_use(lazy_static)] -extern crate lazy_static; - -mod auth; -mod config; -mod device; -mod error; -mod otp; -mod pws; -mod util; - -use std::fmt; -use std::marker; -use std::sync; - -use nitrokey_sys; - -pub use crate::auth::{Admin, Authenticate, User}; -pub use crate::config::Config; -pub use crate::device::{ - Device, DeviceWrapper, Model, Pro, SdCardData, Storage, StorageProductionInfo, StorageStatus, - VolumeMode, VolumeStatus, -}; -pub use crate::error::{CommandError, CommunicationError, Error, LibraryError}; -pub use crate::otp::{ConfigureOtp, GenerateOtp, OtpMode, OtpSlotData}; -pub use crate::pws::{GetPasswordSafe, PasswordSafe, SLOT_COUNT}; -pub use crate::util::LogLevel; - -/// The default admin PIN for all Nitrokey devices. -pub const DEFAULT_ADMIN_PIN: &str = "12345678"; -/// The default user PIN for all Nitrokey devices. -pub const DEFAULT_USER_PIN: &str = "123456"; - -lazy_static! { - static ref MANAGER: sync::Mutex = sync::Mutex::new(Manager::new()); -} - -/// A version of the libnitrokey library. -/// -/// Use the [`get_library_version`](fn.get_library_version.html) function to query the library -/// version. -#[derive(Clone, Debug, PartialEq)] -pub struct Version { - /// The Git library version as a string. - /// - /// The library version is the output of `git describe --always` at compile time, for example - /// `v3.3` or `v3.4.1`. If the library has not been built from a release, the version string - /// contains the number of commits since the last release and the hash of the current commit, for - /// example `v3.3-19-gaee920b`. If the library has not been built from a Git checkout, this - /// string may be empty. - pub git: String, - /// The major library version. - pub major: u32, - /// The minor library version. - pub minor: u32, -} - -impl fmt::Display for Version { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if self.git.is_empty() { - write!(f, "v{}.{}", self.major, self.minor) - } else { - f.write_str(&self.git) - } - } -} - -/// A manager for connections to Nitrokey devices. -/// -/// Currently, libnitrokey only provides access to one Nitrokey device at the same time. This -/// manager struct makes sure that `nitrokey-rs` does not try to connect to two devices at the same -/// time. -/// -/// To obtain a reference to an instance of this manager, use the [`take`][] function. Use one of -/// the connect methods – [`connect`][], [`connect_model`][], [`connect_pro`][] or -/// [`connect_storage`][] – to retrieve a [`Device`][] instance. -/// -/// # Examples -/// -/// Connect to a single device: -/// -/// ```no_run -/// use nitrokey::Device; -/// # use nitrokey::Error; -/// -/// # fn try_main() -> Result<(), Error> { -/// let mut manager = nitrokey::take()?; -/// let device = manager.connect()?; -/// println!("{}", device.get_serial_number()?); -/// # Ok(()) -/// # } -/// ``` -/// -/// Connect to a Pro and a Storage device: -/// -/// ```no_run -/// use nitrokey::{Device, Model}; -/// # use nitrokey::Error; -/// -/// # fn try_main() -> Result<(), Error> { -/// let mut manager = nitrokey::take()?; -/// let device = manager.connect_model(Model::Pro)?; -/// println!("Pro: {}", device.get_serial_number()?); -/// drop(device); -/// let device = manager.connect_model(Model::Storage)?; -/// println!("Storage: {}", device.get_serial_number()?); -/// # Ok(()) -/// # } -/// ``` -/// -/// [`connect`]: #method.connect -/// [`connect_model`]: #method.connect_model -/// [`connect_pro`]: #method.connect_pro -/// [`connect_storage`]: #method.connect_storage -/// [`manager`]: trait.Device.html#method.manager -/// [`take`]: fn.take.html -/// [`Device`]: trait.Device.html -#[derive(Debug)] -pub struct Manager { - marker: marker::PhantomData<()>, -} - -impl Manager { - fn new() -> Self { - Manager { - marker: marker::PhantomData, - } - } - - /// Connects to a Nitrokey device. - /// - /// This method can be used to connect to any connected device, both a Nitrokey Pro and a - /// Nitrokey Storage. - /// - /// # Errors - /// - /// - [`NotConnected`][] if no Nitrokey device is connected - /// - /// # Example - /// - /// ``` - /// use nitrokey::DeviceWrapper; - /// - /// fn do_something(device: DeviceWrapper) {} - /// - /// let mut manager = nitrokey::take()?; - /// match manager.connect() { - /// Ok(device) => do_something(device), - /// Err(err) => println!("Could not connect to a Nitrokey: {}", err), - /// } - /// # Ok::<(), nitrokey::Error>(()) - /// ``` - /// - /// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected - pub fn connect(&mut self) -> Result, Error> { - if unsafe { nitrokey_sys::NK_login_auto() } == 1 { - device::get_connected_device(self) - } else { - Err(CommunicationError::NotConnected.into()) - } - } - - /// Connects to a Nitrokey device of the given model. - /// - /// # Errors - /// - /// - [`NotConnected`][] if no Nitrokey device of the given model is connected - /// - /// # Example - /// - /// ``` - /// use nitrokey::DeviceWrapper; - /// use nitrokey::Model; - /// - /// fn do_something(device: DeviceWrapper) {} - /// - /// match nitrokey::take()?.connect_model(Model::Pro) { - /// Ok(device) => do_something(device), - /// Err(err) => println!("Could not connect to a Nitrokey Pro: {}", err), - /// } - /// # Ok::<(), nitrokey::Error>(()) - /// ``` - /// - /// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected - pub fn connect_model(&mut self, model: Model) -> Result, Error> { - if device::connect_enum(model) { - Ok(device::create_device_wrapper(self, model)) - } else { - Err(CommunicationError::NotConnected.into()) - } - } - - /// Connects to a Nitrokey Pro. - /// - /// # Errors - /// - /// - [`NotConnected`][] if no Nitrokey device of the given model is connected - /// - /// # Example - /// - /// ``` - /// use nitrokey::Pro; - /// - /// fn use_pro(device: Pro) {} - /// - /// match nitrokey::take()?.connect_pro() { - /// Ok(device) => use_pro(device), - /// Err(err) => println!("Could not connect to the Nitrokey Pro: {}", err), - /// } - /// # Ok::<(), nitrokey::Error>(()) - /// ``` - /// - /// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected - pub fn connect_pro(&mut self) -> Result, Error> { - if device::connect_enum(device::Model::Pro) { - Ok(device::Pro::new(self)) - } else { - Err(CommunicationError::NotConnected.into()) - } - } - - /// Connects to a Nitrokey Storage. - /// - /// # Errors - /// - /// - [`NotConnected`][] if no Nitrokey device of the given model is connected - /// - /// # Example - /// - /// ``` - /// use nitrokey::Storage; - /// - /// fn use_storage(device: Storage) {} - /// - /// match nitrokey::take()?.connect_storage() { - /// Ok(device) => use_storage(device), - /// Err(err) => println!("Could not connect to the Nitrokey Storage: {}", err), - /// } - /// # Ok::<(), nitrokey::Error>(()) - /// ``` - /// - /// [`NotConnected`]: enum.CommunicationError.html#variant.NotConnected - pub fn connect_storage(&mut self) -> Result, Error> { - if device::connect_enum(Model::Storage) { - Ok(Storage::new(self)) - } else { - Err(CommunicationError::NotConnected.into()) - } - } -} - -/// Take an instance of the connection manager, blocking until an instance is available. -/// -/// There may only be one [`Manager`][] instance at the same time. If there already is an -/// instance, this method blocks. If you want a non-blocking version, use [`take`][]. -/// -/// # Errors -/// -/// - [`PoisonError`][] if the lock is poisoned -/// -/// [`take`]: fn.take.html -/// [`PoisonError`]: struct.Error.html#variant.PoisonError -/// [`Manager`]: struct.Manager.html -pub fn take_blocking() -> Result, Error> { - MANAGER.lock().map_err(Into::into) -} - -/// Try to take an instance of the connection manager. -/// -/// There may only be one [`Manager`][] instance at the same time. If there already is an -/// instance, a [`ConcurrentAccessError`][] is returned. If you want a blocking version, use -/// [`take_blocking`][]. If you want to access the manager instance even if the cache is poisoned, -/// use [`force_take`][]. -/// -/// # Errors -/// -/// - [`ConcurrentAccessError`][] if the token for the `Manager` instance cannot be locked -/// - [`PoisonError`][] if the lock is poisoned -/// -/// [`take_blocking`]: fn.take_blocking.html -/// [`force_take`]: fn.force_take.html -/// [`ConcurrentAccessError`]: struct.Error.html#variant.ConcurrentAccessError -/// [`PoisonError`]: struct.Error.html#variant.PoisonError -/// [`Manager`]: struct.Manager.html -pub fn take() -> Result, Error> { - MANAGER.try_lock().map_err(Into::into) -} - -/// Try to take an instance of the connection manager, ignoring a poisoned cache. -/// -/// There may only be one [`Manager`][] instance at the same time. If there already is an -/// instance, a [`ConcurrentAccessError`][] is returned. If you want a blocking version, use -/// [`take_blocking`][]. -/// -/// If a thread has previously panicked while accessing the manager instance, the cache is -/// poisoned. The default implementation, [`take`][], returns a [`PoisonError`][] on subsequent -/// calls. This implementation ignores the poisoned cache and returns the manager instance. -/// -/// # Errors -/// -/// - [`ConcurrentAccessError`][] if the token for the `Manager` instance cannot be locked -/// -/// [`take`]: fn.take.html -/// [`take_blocking`]: fn.take_blocking.html -/// [`ConcurrentAccessError`]: struct.Error.html#variant.ConcurrentAccessError -/// [`Manager`]: struct.Manager.html -pub fn force_take() -> Result, Error> { - match take() { - Ok(guard) => Ok(guard), - Err(err) => match err { - Error::PoisonError(err) => Ok(err.into_inner()), - err => Err(err), - }, - } -} - -/// Enables or disables debug output. Calling this method with `true` is equivalent to setting the -/// log level to `Debug`; calling it with `false` is equivalent to the log level `Error` (see -/// [`set_log_level`][]). -/// -/// If debug output is enabled, detailed information about the communication with the Nitrokey -/// device is printed to the standard output. -/// -/// [`set_log_level`]: fn.set_log_level.html -pub fn set_debug(state: bool) { - unsafe { - nitrokey_sys::NK_set_debug(state); - } -} - -/// Sets the log level for libnitrokey. All log messages are written to the standard error stream. -/// Setting the log level enables all log messages on the same or on a higher log level. -pub fn set_log_level(level: LogLevel) { - unsafe { - nitrokey_sys::NK_set_debug_level(level.into()); - } -} - -/// Returns the libnitrokey library version. -/// -/// # Errors -/// -/// - [`Utf8Error`][] if libnitrokey returned an invalid UTF-8 string -/// -/// # Example -/// -/// ``` -/// let version = nitrokey::get_library_version()?; -/// println!("Using libnitrokey {}", version.git); -/// # Ok::<(), nitrokey::Error>(()) -/// ``` -/// -/// [`Utf8Error`]: enum.Error.html#variant.Utf8Error -pub fn get_library_version() -> Result { - // NK_get_library_version returns a static string, so we don’t have to free the pointer. - let git = unsafe { nitrokey_sys::NK_get_library_version() }; - let git = if git.is_null() { - String::new() - } else { - util::owned_str_from_ptr(git)? - }; - let major = unsafe { nitrokey_sys::NK_get_major_library_version() }; - let minor = unsafe { nitrokey_sys::NK_get_minor_library_version() }; - Ok(Version { git, major, minor }) -} diff --git a/nitrokey/src/otp.rs b/nitrokey/src/otp.rs deleted file mode 100644 index 4667aff..0000000 --- a/nitrokey/src/otp.rs +++ /dev/null @@ -1,423 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use std::ffi::CString; - -use nitrokey_sys; - -use crate::error::Error; -use crate::util::{get_command_result, get_cstring, result_from_string}; - -/// Modes for one-time password generation. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum OtpMode { - /// Generate one-time passwords with six digits. - SixDigits, - /// Generate one-time passwords with eight digits. - EightDigits, -} - -/// Provides methods to configure and erase OTP slots on a Nitrokey device. -pub trait ConfigureOtp { - /// Configure an HOTP slot with the given data and set the HOTP counter to the given value - /// (default 0). - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if there is no slot with the given number - /// - [`InvalidString`][] if the provided token ID contains a null byte - /// - [`NoName`][] if the provided name is empty - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, ConfigureOtp, OtpMode, OtpSlotData}; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::SixDigits); - /// match device.authenticate_admin("12345678") { - /// Ok(mut admin) => { - /// match admin.write_hotp_slot(slot_data, 0) { - /// Ok(()) => println!("Successfully wrote slot."), - /// Err(err) => eprintln!("Could not write slot: {}", err), - /// } - /// }, - /// Err((_, err)) => eprintln!("Could not authenticate as admin: {}", err), - /// } - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`NoName`]: enum.CommandError.html#variant.NoName - fn write_hotp_slot(&mut self, data: OtpSlotData, counter: u64) -> Result<(), Error>; - - /// Configure a TOTP slot with the given data and set the TOTP time window to the given value - /// (default 30). - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if there is no slot with the given number - /// - [`InvalidString`][] if the provided token ID contains a null byte - /// - [`NoName`][] if the provided name is empty - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, ConfigureOtp, OtpMode, OtpSlotData}; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::EightDigits); - /// match device.authenticate_admin("12345678") { - /// Ok(mut admin) => { - /// match admin.write_totp_slot(slot_data, 30) { - /// Ok(()) => println!("Successfully wrote slot."), - /// Err(err) => eprintln!("Could not write slot: {}", err), - /// } - /// }, - /// Err((_, err)) => eprintln!("Could not authenticate as admin: {}", err), - /// } - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`NoName`]: enum.CommandError.html#variant.NoName - fn write_totp_slot(&mut self, data: OtpSlotData, time_window: u16) -> Result<(), Error>; - - /// Erases an HOTP slot. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if there is no slot with the given number - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, ConfigureOtp}; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// match device.authenticate_admin("12345678") { - /// Ok(mut admin) => { - /// match admin.erase_hotp_slot(1) { - /// Ok(()) => println!("Successfully erased slot."), - /// Err(err) => eprintln!("Could not erase slot: {}", err), - /// } - /// }, - /// Err((_, err)) => eprintln!("Could not authenticate as admin: {}", err), - /// } - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - fn erase_hotp_slot(&mut self, slot: u8) -> Result<(), Error>; - - /// Erases a TOTP slot. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if there is no slot with the given number - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, ConfigureOtp}; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// match device.authenticate_admin("12345678") { - /// Ok(mut admin) => { - /// match admin.erase_totp_slot(1) { - /// Ok(()) => println!("Successfully erased slot."), - /// Err(err) => eprintln!("Could not erase slot: {}", err), - /// } - /// }, - /// Err((_, err)) => eprintln!("Could not authenticate as admin: {}", err), - /// } - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - fn erase_totp_slot(&mut self, slot: u8) -> Result<(), Error>; -} - -/// Provides methods to generate OTP codes and to query OTP slots on a Nitrokey -/// device. -pub trait GenerateOtp { - /// Sets the time on the Nitrokey. - /// - /// `time` is the number of seconds since January 1st, 1970 (Unix timestamp). Unless `force` - /// is set to `true`, this command fails if the timestamp on the device is larger than the - /// given timestamp or if it is zero. - /// - /// The time is used for TOTP generation (see [`get_totp_code`][]). - /// - /// # Example - /// - /// ```no_run - /// use std::time; - /// use nitrokey::GenerateOtp; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// let time = time::SystemTime::now().duration_since(time::UNIX_EPOCH); - /// match time { - /// Ok(time) => device.set_time(time.as_secs(), false)?, - /// Err(_) => eprintln!("The system time is before the Unix epoch!"), - /// } - /// # Ok(()) - /// # } - /// ``` - /// - /// # Errors - /// - /// - [`Timestamp`][] if the time could not be set - /// - /// [`get_totp_code`]: #method.get_totp_code - /// [`Timestamp`]: enum.CommandError.html#variant.Timestamp - fn set_time(&mut self, time: u64, force: bool) -> Result<(), Error> { - let result = if force { - unsafe { nitrokey_sys::NK_totp_set_time(time) } - } else { - unsafe { nitrokey_sys::NK_totp_set_time_soft(time) } - }; - get_command_result(result) - } - - /// Returns the name of the given HOTP slot. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if there is no slot with the given number - /// - [`SlotNotProgrammed`][] if the given slot is not configured - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{CommandError, Error, GenerateOtp}; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// match device.get_hotp_slot_name(1) { - /// Ok(name) => println!("HOTP slot 1: {}", name), - /// Err(Error::CommandError(CommandError::SlotNotProgrammed)) => eprintln!("HOTP slot 1 not programmed"), - /// Err(err) => eprintln!("Could not get slot name: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed - fn get_hotp_slot_name(&self, slot: u8) -> Result { - result_from_string(unsafe { nitrokey_sys::NK_get_hotp_slot_name(slot) }) - } - - /// Returns the name of the given TOTP slot. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if there is no slot with the given number - /// - [`SlotNotProgrammed`][] if the given slot is not configured - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{CommandError, Error, GenerateOtp}; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let device = manager.connect()?; - /// match device.get_totp_slot_name(1) { - /// Ok(name) => println!("TOTP slot 1: {}", name), - /// Err(Error::CommandError(CommandError::SlotNotProgrammed)) => eprintln!("TOTP slot 1 not programmed"), - /// Err(err) => eprintln!("Could not get slot name: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed - fn get_totp_slot_name(&self, slot: u8) -> Result { - result_from_string(unsafe { nitrokey_sys::NK_get_totp_slot_name(slot) }) - } - - /// Generates an HOTP code on the given slot. This operation may require user authorization, - /// depending on the device configuration (see [`get_config`][]). - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if there is no slot with the given number - /// - [`NotAuthorized`][] if OTP generation requires user authentication - /// - [`SlotNotProgrammed`][] if the given slot is not configured - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::GenerateOtp; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// let code = device.get_hotp_code(1)?; - /// println!("Generated HOTP code on slot 1: {}", code); - /// # Ok(()) - /// # } - /// ``` - /// - /// [`get_config`]: trait.Device.html#method.get_config - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`NotAuthorized`]: enum.CommandError.html#variant.NotAuthorized - /// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed - fn get_hotp_code(&mut self, slot: u8) -> Result { - result_from_string(unsafe { nitrokey_sys::NK_get_hotp_code(slot) }) - } - - /// Generates a TOTP code on the given slot. This operation may require user authorization, - /// depending on the device configuration (see [`get_config`][]). - /// - /// To make sure that the Nitrokey’s time is in sync, consider calling [`set_time`][] before - /// calling this method. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if there is no slot with the given number - /// - [`NotAuthorized`][] if OTP generation requires user authentication - /// - [`SlotNotProgrammed`][] if the given slot is not configured - /// - /// # Example - /// - /// ```no_run - /// use std::time; - /// use nitrokey::GenerateOtp; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// let time = time::SystemTime::now().duration_since(time::UNIX_EPOCH); - /// match time { - /// Ok(time) => { - /// device.set_time(time.as_secs(), false)?; - /// let code = device.get_totp_code(1)?; - /// println!("Generated TOTP code on slot 1: {}", code); - /// }, - /// Err(_) => eprintln!("Timestamps before 1970-01-01 are not supported!"), - /// } - /// # Ok(()) - /// # } - /// ``` - /// - /// [`set_time`]: #method.set_time - /// [`get_config`]: trait.Device.html#method.get_config - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`NotAuthorized`]: enum.CommandError.html#variant.NotAuthorized - /// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed - fn get_totp_code(&self, slot: u8) -> Result { - result_from_string(unsafe { nitrokey_sys::NK_get_totp_code(slot, 0, 0, 0) }) - } -} - -/// The configuration for an OTP slot. -#[derive(Debug)] -pub struct OtpSlotData { - /// The number of the slot – must be less than three for HOTP and less than 15 for TOTP. - pub number: u8, - /// The name of the slot – must not be empty. - pub name: String, - /// The secret for the slot. - pub secret: String, - /// The OTP generation mode. - pub mode: OtpMode, - /// If true, press the enter key after sending an OTP code using double-pressed - /// numlock, capslock or scrolllock. - pub use_enter: bool, - /// Set the token ID, see [OATH Token Identifier Specification][tokspec], section “Class A”. - /// - /// [tokspec]: https://openauthentication.org/token-specs/ - pub token_id: Option, -} - -#[derive(Debug)] -pub struct RawOtpSlotData { - pub number: u8, - pub name: CString, - pub secret: CString, - pub mode: OtpMode, - pub use_enter: bool, - pub use_token_id: bool, - pub token_id: CString, -} - -impl OtpSlotData { - /// Constructs a new instance of this struct. - pub fn new, T: Into>( - number: u8, - name: S, - secret: T, - mode: OtpMode, - ) -> OtpSlotData { - OtpSlotData { - number, - name: name.into(), - secret: secret.into(), - mode, - use_enter: false, - token_id: None, - } - } - - /// Enables pressing the enter key after sending an OTP code using double-pressed numlock, - /// capslock or scrollock. - pub fn use_enter(mut self) -> OtpSlotData { - self.use_enter = true; - self - } - - /// Sets the token ID, see [OATH Token Identifier Specification][tokspec], section “Class A”. - /// - /// [tokspec]: https://openauthentication.org/token-specs/ - pub fn token_id>(mut self, id: S) -> OtpSlotData { - self.token_id = Some(id.into()); - self - } -} - -impl RawOtpSlotData { - pub fn new(data: OtpSlotData) -> Result { - let name = get_cstring(data.name)?; - let secret = get_cstring(data.secret)?; - let use_token_id = data.token_id.is_some(); - let token_id = get_cstring(data.token_id.unwrap_or_else(String::new))?; - - Ok(RawOtpSlotData { - number: data.number, - name, - secret, - mode: data.mode, - use_enter: data.use_enter, - use_token_id, - token_id, - }) - } -} diff --git a/nitrokey/src/pws.rs b/nitrokey/src/pws.rs deleted file mode 100644 index 3398deb..0000000 --- a/nitrokey/src/pws.rs +++ /dev/null @@ -1,391 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use libc; -use nitrokey_sys; - -use crate::device::{Device, DeviceWrapper, Pro, Storage}; -use crate::error::{CommandError, Error}; -use crate::util::{get_command_result, get_cstring, get_last_error, result_from_string}; - -/// The number of slots in a [`PasswordSafe`][]. -/// -/// [`PasswordSafe`]: struct.PasswordSafe.html -pub const SLOT_COUNT: u8 = 16; - -/// A password safe on a Nitrokey device. -/// -/// The password safe stores a tuple consisting of a name, a login and a password on a slot. The -/// number of available slots is [`SLOT_COUNT`][]. The slots are addressed starting with zero. To -/// retrieve a password safe from a Nitrokey device, use the [`get_password_safe`][] method from -/// the [`GetPasswordSafe`][] trait. Note that the device must live at least as long as the -/// password safe. -/// -/// Once the password safe has been unlocked, it can be accessed without a password. Therefore it -/// is mandatory to call [`lock`][] on the corresponding device after the password store is used. -/// As this command may have side effects on the Nitrokey Storage, it cannot be called -/// automatically once the password safe is destroyed. -/// -/// # Examples -/// -/// Open a password safe and access a password: -/// -/// ```no_run -/// use nitrokey::{Device, GetPasswordSafe, PasswordSafe}; -/// # use nitrokey::Error; -/// -/// fn use_password_safe(pws: &PasswordSafe) -> Result<(), Error> { -/// let name = pws.get_slot_name(0)?; -/// let login = pws.get_slot_login(0)?; -/// let password = pws.get_slot_login(0)?; -/// println!("Credentials for {}: login {}, password {}", name, login, password); -/// Ok(()) -/// } -/// -/// # fn try_main() -> Result<(), Error> { -/// let mut manager = nitrokey::take()?; -/// let mut device = manager.connect()?; -/// let pws = device.get_password_safe("123456")?; -/// use_password_safe(&pws); -/// drop(pws); -/// device.lock()?; -/// # Ok(()) -/// # } -/// ``` -/// -/// [`SLOT_COUNT`]: constant.SLOT_COUNT.html -/// [`get_password_safe`]: trait.GetPasswordSafe.html#method.get_password_safe -/// [`lock`]: trait.Device.html#method.lock -/// [`GetPasswordSafe`]: trait.GetPasswordSafe.html -#[derive(Debug)] -pub struct PasswordSafe<'a, 'b> { - _device: &'a dyn Device<'b>, -} - -/// Provides access to a [`PasswordSafe`][]. -/// -/// The device that implements this trait must always live at least as long as a password safe -/// retrieved from it. -/// -/// [`PasswordSafe`]: struct.PasswordSafe.html -pub trait GetPasswordSafe<'a> { - /// Enables and returns the password safe. - /// - /// The underlying device must always live at least as long as a password safe retrieved from - /// it. It is mandatory to lock the underlying device using [`lock`][] after the password safe - /// has been used. Otherwise, other applications can access the password store without - /// authentication. - /// - /// If this method returns an `AesDecryptionFailed` (Nitrokey Pro) or `Unknown` (Nitrokey - /// Storage) error, the AES data object on the smart card could not be accessed. This problem - /// occurs after a factory reset using `gpg --card-edit` and can be fixed using the - /// [`Device::build_aes_key`][] command. - /// - /// # Errors - /// - /// - [`AesDecryptionFailed`][] if the secret for the password safe could not be decrypted - /// (Nitrokey Pro only) - /// - [`InvalidString`][] if one of the provided passwords contains a null byte - /// - [`Unknown`][] if the secret for the password safe could not be decrypted (Nitrokey - /// Storage only) - /// - [`WrongPassword`][] if the current user password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Device, GetPasswordSafe, PasswordSafe}; - /// # use nitrokey::Error; - /// - /// fn use_password_safe(pws: &PasswordSafe) {} - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// match device.get_password_safe("123456") { - /// Ok(pws) => { - /// use_password_safe(&pws); - /// }, - /// Err(err) => eprintln!("Could not open the password safe: {}", err), - /// }; - /// device.lock()?; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`device`]: struct.PasswordSafe.html#method.device - /// [`lock`]: trait.Device.html#method.lock - /// [`AesDecryptionFailed`]: enum.CommandError.html#variant.AesDecryptionFailed - /// [`Device::build_aes_key`]: trait.Device.html#method.build_aes_key - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - /// [`Unknown`]: enum.CommandError.html#variant.Unknown - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - fn get_password_safe(&mut self, user_pin: &str) -> Result, Error>; -} - -fn get_password_safe<'a, 'b>( - device: &'a dyn Device<'b>, - user_pin: &str, -) -> Result, Error> { - let user_pin_string = get_cstring(user_pin)?; - get_command_result(unsafe { nitrokey_sys::NK_enable_password_safe(user_pin_string.as_ptr()) }) - .map(|_| PasswordSafe { _device: device }) -} - -fn get_pws_result(s: String) -> Result { - if s.is_empty() { - Err(CommandError::SlotNotProgrammed.into()) - } else { - Ok(s) - } -} - -impl<'a, 'b> PasswordSafe<'a, 'b> { - /// Returns the status of all password slots. - /// - /// The status indicates whether a slot is programmed or not. - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{GetPasswordSafe, SLOT_COUNT}; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// let pws = device.get_password_safe("123456")?; - /// pws.get_slot_status()?.iter().enumerate().for_each(|(slot, programmed)| { - /// let status = match *programmed { - /// true => "programmed", - /// false => "not programmed", - /// }; - /// println!("Slot {}: {}", slot, status); - /// }); - /// # Ok(()) - /// # } - /// ``` - pub fn get_slot_status(&self) -> Result<[bool; SLOT_COUNT as usize], Error> { - let status_ptr = unsafe { nitrokey_sys::NK_get_password_safe_slot_status() }; - if status_ptr.is_null() { - return Err(get_last_error()); - } - let status_array_ptr = status_ptr as *const [u8; SLOT_COUNT as usize]; - let status_array = unsafe { *status_array_ptr }; - let mut result = [false; SLOT_COUNT as usize]; - for i in 0..SLOT_COUNT { - result[i as usize] = status_array[i as usize] == 1; - } - unsafe { - libc::free(status_ptr as *mut libc::c_void); - } - Ok(result) - } - - /// Returns the name of the given slot (if it is programmed). - /// - /// This method also returns a `SlotNotProgrammed` error if the name is empty. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if the given slot is out of range - /// - [`SlotNotProgrammed`][] if the slot is not programmed - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::GetPasswordSafe; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// match device.get_password_safe("123456") { - /// Ok(pws) => { - /// let name = pws.get_slot_name(0)?; - /// let login = pws.get_slot_login(0)?; - /// let password = pws.get_slot_login(0)?; - /// println!("Credentials for {}: login {}, password {}", name, login, password); - /// }, - /// Err(err) => eprintln!("Could not open the password safe: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed - pub fn get_slot_name(&self, slot: u8) -> Result { - result_from_string(unsafe { nitrokey_sys::NK_get_password_safe_slot_name(slot) }) - .and_then(get_pws_result) - } - - /// Returns the login for the given slot (if it is programmed). - /// - /// This method also returns a `SlotNotProgrammed` error if the login is empty. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if the given slot is out of range - /// - [`SlotNotProgrammed`][] if the slot is not programmed - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::GetPasswordSafe; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// let pws = device.get_password_safe("123456")?; - /// let name = pws.get_slot_name(0)?; - /// let login = pws.get_slot_login(0)?; - /// let password = pws.get_slot_login(0)?; - /// println!("Credentials for {}: login {}, password {}", name, login, password); - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed - pub fn get_slot_login(&self, slot: u8) -> Result { - result_from_string(unsafe { nitrokey_sys::NK_get_password_safe_slot_login(slot) }) - .and_then(get_pws_result) - } - - /// Returns the password for the given slot (if it is programmed). - /// - /// This method also returns a `SlotNotProgrammed` error if the password is empty. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if the given slot is out of range - /// - [`SlotNotProgrammed`][] if the slot is not programmed - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::GetPasswordSafe; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// let pws = device.get_password_safe("123456")?; - /// let name = pws.get_slot_name(0)?; - /// let login = pws.get_slot_login(0)?; - /// let password = pws.get_slot_login(0)?; - /// println!("Credentials for {}: login {}, password {}", name, login, password); - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`SlotNotProgrammed`]: enum.CommandError.html#variant.SlotNotProgrammed - pub fn get_slot_password(&self, slot: u8) -> Result { - result_from_string(unsafe { nitrokey_sys::NK_get_password_safe_slot_password(slot) }) - .and_then(get_pws_result) - } - - /// Writes the given slot with the given name, login and password. - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if the given slot is out of range - /// - [`InvalidString`][] if the provided token ID contains a null byte - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::GetPasswordSafe; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// let pws = device.get_password_safe("123456")?; - /// let name = pws.get_slot_name(0)?; - /// let login = pws.get_slot_login(0)?; - /// let password = pws.get_slot_login(0)?; - /// println!("Credentials for {}: login {}, password {}", name, login, password); - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - /// [`InvalidString`]: enum.LibraryError.html#variant.InvalidString - pub fn write_slot( - &mut self, - slot: u8, - name: &str, - login: &str, - password: &str, - ) -> Result<(), Error> { - let name_string = get_cstring(name)?; - let login_string = get_cstring(login)?; - let password_string = get_cstring(password)?; - get_command_result(unsafe { - nitrokey_sys::NK_write_password_safe_slot( - slot, - name_string.as_ptr(), - login_string.as_ptr(), - password_string.as_ptr(), - ) - }) - } - - /// Erases the given slot. Erasing clears the stored name, login and password (if the slot was - /// programmed). - /// - /// # Errors - /// - /// - [`InvalidSlot`][] if the given slot is out of range - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::GetPasswordSafe; - /// # use nitrokey::Error; - /// - /// # fn try_main() -> Result<(), Error> { - /// let mut manager = nitrokey::take()?; - /// let mut device = manager.connect()?; - /// let mut pws = device.get_password_safe("123456")?; - /// match pws.erase_slot(0) { - /// Ok(()) => println!("Erased slot 0."), - /// Err(err) => eprintln!("Could not erase slot 0: {}", err), - /// }; - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidSlot`]: enum.LibraryError.html#variant.InvalidSlot - pub fn erase_slot(&mut self, slot: u8) -> Result<(), Error> { - get_command_result(unsafe { nitrokey_sys::NK_erase_password_safe_slot(slot) }) - } -} - -impl<'a, 'b> Drop for PasswordSafe<'a, 'b> { - fn drop(&mut self) { - // TODO: disable the password safe -- NK_lock_device has side effects on the Nitrokey - // Storage, see https://github.com/Nitrokey/nitrokey-storage-firmware/issues/65 - } -} - -impl<'a> GetPasswordSafe<'a> for Pro<'a> { - fn get_password_safe(&mut self, user_pin: &str) -> Result, Error> { - get_password_safe(self, user_pin) - } -} - -impl<'a> GetPasswordSafe<'a> for Storage<'a> { - fn get_password_safe(&mut self, user_pin: &str) -> Result, Error> { - get_password_safe(self, user_pin) - } -} - -impl<'a> GetPasswordSafe<'a> for DeviceWrapper<'a> { - fn get_password_safe(&mut self, user_pin: &str) -> Result, Error> { - get_password_safe(self, user_pin) - } -} diff --git a/nitrokey/src/util.rs b/nitrokey/src/util.rs deleted file mode 100644 index 5a56c55..0000000 --- a/nitrokey/src/util.rs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use std::ffi::{CStr, CString}; -use std::os::raw::{c_char, c_int}; - -use libc::{c_void, free}; -use rand_core::{OsRng, RngCore}; - -use crate::error::{Error, LibraryError}; - -/// Log level for libnitrokey. -/// -/// Setting the log level to a lower level enables all output from higher levels too. Currently, -/// only the log levels `Warning`, `DebugL1`, `Debug` and `DebugL2` are actually used. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum LogLevel { - /// Error messages. Currently not used. - Error, - /// Warning messages. - Warning, - /// Informational messages. Currently not used. - Info, - /// Basic debug messages, especially basic information on the sent and received packets. - DebugL1, - /// Detailed debug messages, especially detailed information on the sent and received packets. - Debug, - /// Very detailed debug messages, especially detailed information about the control flow for - /// device communication (for example function entries and exits). - DebugL2, -} - -pub fn owned_str_from_ptr(ptr: *const c_char) -> Result { - unsafe { CStr::from_ptr(ptr) } - .to_str() - .map(String::from) - .map_err(Error::from) -} - -pub fn result_from_string(ptr: *const c_char) -> Result { - if ptr.is_null() { - return Err(Error::UnexpectedError); - } - let s = owned_str_from_ptr(ptr)?; - unsafe { free(ptr as *mut c_void) }; - // An empty string can both indicate an error or be a valid return value. In this case, we - // have to check the last command status to decide what to return. - if s.is_empty() { - get_last_result().map(|_| s) - } else { - Ok(s) - } -} - -pub fn result_or_error(value: T) -> Result { - get_last_result().and(Ok(value)) -} - -pub fn get_command_result(value: c_int) -> Result<(), Error> { - if value == 0 { - Ok(()) - } else { - Err(Error::from(value)) - } -} - -pub fn get_last_result() -> Result<(), Error> { - get_command_result(unsafe { nitrokey_sys::NK_get_last_command_status() }.into()) -} - -pub fn get_last_error() -> Error { - match get_last_result() { - Ok(()) => Error::UnexpectedError, - Err(err) => err, - } -} - -pub fn generate_password(length: usize) -> Result, Error> { - let mut data = vec![0u8; length]; - OsRng.fill_bytes(&mut data[..]); - Ok(data) -} - -pub fn get_cstring>>(s: T) -> Result { - CString::new(s).or_else(|_| Err(LibraryError::InvalidString.into())) -} - -impl Into for LogLevel { - fn into(self) -> i32 { - match self { - LogLevel::Error => 0, - LogLevel::Warning => 1, - LogLevel::Info => 2, - LogLevel::DebugL1 => 3, - LogLevel::Debug => 4, - LogLevel::DebugL2 => 5, - } - } -} diff --git a/nitrokey/tests/device.rs b/nitrokey/tests/device.rs deleted file mode 100644 index e367558..0000000 --- a/nitrokey/tests/device.rs +++ /dev/null @@ -1,575 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -mod util; - -use std::ffi::CStr; -use std::process::Command; -use std::{thread, time}; - -use nitrokey::{ - Authenticate, CommandError, CommunicationError, Config, ConfigureOtp, Device, Error, - GenerateOtp, GetPasswordSafe, LibraryError, OtpMode, OtpSlotData, Storage, VolumeMode, - DEFAULT_ADMIN_PIN, DEFAULT_USER_PIN, -}; -use nitrokey_test::test as test_device; - -static ADMIN_NEW_PASSWORD: &str = "1234567890"; -static UPDATE_PIN: &str = "12345678"; -static UPDATE_NEW_PIN: &str = "87654321"; -static USER_NEW_PASSWORD: &str = "abcdefghij"; - -fn count_nitrokey_block_devices() -> usize { - thread::sleep(time::Duration::from_secs(2)); - let output = Command::new("lsblk") - .args(&["-o", "MODEL"]) - .output() - .expect("Could not list block devices"); - String::from_utf8_lossy(&output.stdout) - .split("\n") - .filter(|&s| s.replace("_", " ") == "Nitrokey Storage") - .count() -} - -#[test_device] -fn connect_no_device() { - let mut manager = unwrap_ok!(nitrokey::take()); - - assert_cmu_err!(CommunicationError::NotConnected, manager.connect()); - assert_cmu_err!( - CommunicationError::NotConnected, - manager.connect_model(nitrokey::Model::Pro) - ); - assert_cmu_err!( - CommunicationError::NotConnected, - manager.connect_model(nitrokey::Model::Storage) - ); - assert_cmu_err!(CommunicationError::NotConnected, manager.connect_pro()); - assert_cmu_err!(CommunicationError::NotConnected, manager.connect_storage()); -} - -#[test_device] -fn connect_pro(device: Pro) { - assert_eq!(device.get_model(), nitrokey::Model::Pro); - - let manager = device.into_manager(); - assert_any_ok!(manager.connect()); - assert_any_ok!(manager.connect_model(nitrokey::Model::Pro)); - assert_any_ok!(manager.connect_pro()); -} - -#[test_device] -fn connect_storage(device: Storage) { - assert_eq!(device.get_model(), nitrokey::Model::Storage); - - let manager = device.into_manager(); - assert_any_ok!(manager.connect()); - assert_any_ok!(manager.connect_model(nitrokey::Model::Storage)); - assert_any_ok!(manager.connect_storage()); -} - -fn assert_empty_serial_number() { - unsafe { - let ptr = nitrokey_sys::NK_device_serial_number(); - assert!(!ptr.is_null()); - let cstr = CStr::from_ptr(ptr); - assert_eq!(cstr.to_string_lossy(), ""); - } -} - -#[test_device] -fn disconnect(device: DeviceWrapper) { - drop(device); - assert_empty_serial_number(); -} - -#[test_device] -fn get_serial_number(device: DeviceWrapper) { - let serial_number = unwrap_ok!(device.get_serial_number()); - assert!(serial_number.is_ascii()); - assert!(serial_number.chars().all(|c| c.is_ascii_hexdigit())); -} -#[test_device] -fn get_firmware_version(device: Pro) { - let version = unwrap_ok!(device.get_firmware_version()); - assert_eq!(0, version.major); - assert!(version.minor > 0); -} - -fn admin_retry<'a, T>(device: T, suffix: &str, count: u8) -> T -where - T: Authenticate<'a> + Device<'a> + 'a, -{ - let result = device.authenticate_admin(&(DEFAULT_ADMIN_PIN.to_owned() + suffix)); - let device = match result { - Ok(admin) => admin.device(), - Err((device, _)) => device, - }; - assert_ok!(count, device.get_admin_retry_count()); - return device; -} - -fn user_retry<'a, T>(device: T, suffix: &str, count: u8) -> T -where - T: Authenticate<'a> + Device<'a> + 'a, -{ - let result = device.authenticate_user(&(DEFAULT_USER_PIN.to_owned() + suffix)); - let device = match result { - Ok(admin) => admin.device(), - Err((device, _)) => device, - }; - assert_ok!(count, device.get_user_retry_count()); - return device; -} - -#[test_device] -fn get_retry_count(device: DeviceWrapper) { - let device = admin_retry(device, "", 3); - let device = admin_retry(device, "123", 2); - let device = admin_retry(device, "456", 1); - let device = admin_retry(device, "", 3); - - let device = user_retry(device, "", 3); - let device = user_retry(device, "123", 2); - let device = user_retry(device, "456", 1); - user_retry(device, "", 3); -} - -#[test_device] -fn config(device: DeviceWrapper) { - let mut admin = unwrap_ok!(device.authenticate_admin(DEFAULT_ADMIN_PIN)); - - let config = Config::new(None, None, None, true); - assert_ok!((), admin.write_config(config)); - assert_ok!(config, admin.get_config()); - - let config = Config::new(None, Some(9), None, true); - assert_lib_err!(LibraryError::InvalidSlot, admin.write_config(config)); - - let config = Config::new(Some(1), None, Some(0), false); - assert_ok!((), admin.write_config(config)); - assert_ok!(config, admin.get_config()); - - let config = Config::new(None, None, None, false); - assert_ok!((), admin.write_config(config)); - assert_ok!(config, admin.get_config()); -} - -#[test_device] -fn change_user_pin(device: DeviceWrapper) { - let device = device.authenticate_user(DEFAULT_USER_PIN).unwrap().device(); - let device = device.authenticate_user(USER_NEW_PASSWORD).unwrap_err().0; - - let mut device = device; - assert_ok!( - (), - device.change_user_pin(DEFAULT_USER_PIN, USER_NEW_PASSWORD) - ); - - let device = device.authenticate_user(DEFAULT_USER_PIN).unwrap_err().0; - let device = device - .authenticate_user(USER_NEW_PASSWORD) - .unwrap() - .device(); - - let mut device = device; - let result = device.change_user_pin(DEFAULT_USER_PIN, DEFAULT_USER_PIN); - assert_cmd_err!(CommandError::WrongPassword, result); - - assert_ok!( - (), - device.change_user_pin(USER_NEW_PASSWORD, DEFAULT_USER_PIN) - ); - - let device = device.authenticate_user(DEFAULT_USER_PIN).unwrap().device(); - assert!(device.authenticate_user(USER_NEW_PASSWORD).is_err()); -} - -#[test_device] -fn change_admin_pin(device: DeviceWrapper) { - let device = device - .authenticate_admin(DEFAULT_ADMIN_PIN) - .unwrap() - .device(); - let mut device = device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap_err().0; - - assert_ok!( - (), - device.change_admin_pin(DEFAULT_ADMIN_PIN, ADMIN_NEW_PASSWORD) - ); - - let device = device.authenticate_admin(DEFAULT_ADMIN_PIN).unwrap_err().0; - let mut device = device - .authenticate_admin(ADMIN_NEW_PASSWORD) - .unwrap() - .device(); - - assert_cmd_err!( - CommandError::WrongPassword, - device.change_admin_pin(DEFAULT_ADMIN_PIN, DEFAULT_ADMIN_PIN) - ); - - assert_ok!( - (), - device.change_admin_pin(ADMIN_NEW_PASSWORD, DEFAULT_ADMIN_PIN) - ); - - let device = device - .authenticate_admin(DEFAULT_ADMIN_PIN) - .unwrap() - .device(); - device.authenticate_admin(ADMIN_NEW_PASSWORD).unwrap_err(); -} - -fn require_failed_user_login<'a, D>(device: D, password: &str, error: CommandError) -> D -where - D: Device<'a> + Authenticate<'a> + 'a, - nitrokey::User<'a, D>: std::fmt::Debug, -{ - let result = device.authenticate_user(password); - assert!(result.is_err()); - let err = result.unwrap_err(); - match err.1 { - Error::CommandError(err) => assert_eq!(error, err), - _ => assert!(false), - }; - err.0 -} - -#[test_device] -fn unlock_user_pin(device: DeviceWrapper) { - let mut device = device.authenticate_user(DEFAULT_USER_PIN).unwrap().device(); - assert_ok!( - (), - device.unlock_user_pin(DEFAULT_ADMIN_PIN, DEFAULT_USER_PIN) - ); - assert_cmd_err!( - CommandError::WrongPassword, - device.unlock_user_pin(DEFAULT_USER_PIN, DEFAULT_USER_PIN) - ); - - // block user PIN - let wrong_password = DEFAULT_USER_PIN.to_owned() + "foo"; - let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); - let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); - let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); - let mut device = - require_failed_user_login(device, DEFAULT_USER_PIN, CommandError::WrongPassword); - - // unblock with current PIN - assert_cmd_err!( - CommandError::WrongPassword, - device.unlock_user_pin(DEFAULT_USER_PIN, DEFAULT_USER_PIN) - ); - assert_ok!( - (), - device.unlock_user_pin(DEFAULT_ADMIN_PIN, DEFAULT_USER_PIN) - ); - let device = device.authenticate_user(DEFAULT_USER_PIN).unwrap().device(); - - // block user PIN - let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); - let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); - let device = require_failed_user_login(device, &wrong_password, CommandError::WrongPassword); - let mut device = - require_failed_user_login(device, DEFAULT_USER_PIN, CommandError::WrongPassword); - - // unblock with new PIN - assert_cmd_err!( - CommandError::WrongPassword, - device.unlock_user_pin(DEFAULT_USER_PIN, DEFAULT_USER_PIN) - ); - assert_ok!( - (), - device.unlock_user_pin(DEFAULT_ADMIN_PIN, USER_NEW_PASSWORD) - ); - - // reset user PIN - assert_ok!( - (), - device.change_user_pin(USER_NEW_PASSWORD, DEFAULT_USER_PIN) - ); -} - -fn assert_utf8_err_or_ne(left: &str, right: Result) { - match right { - Ok(s) => assert_ne!(left.to_string(), s), - Err(Error::Utf8Error(_)) => {} - Err(err) => panic!("Expected Utf8Error, got {}!", err), - } -} - -#[test_device] -fn factory_reset(device: DeviceWrapper) { - let mut admin = unwrap_ok!(device.authenticate_admin(DEFAULT_ADMIN_PIN)); - let otp_data = OtpSlotData::new(1, "test", "0123468790", OtpMode::SixDigits); - assert_ok!((), admin.write_totp_slot(otp_data, 30)); - - let mut device = admin.device(); - let mut pws = unwrap_ok!(device.get_password_safe(DEFAULT_USER_PIN)); - assert_ok!((), pws.write_slot(0, "test", "testlogin", "testpw")); - drop(pws); - - assert_ok!( - (), - device.change_user_pin(DEFAULT_USER_PIN, USER_NEW_PASSWORD) - ); - assert_ok!( - (), - device.change_admin_pin(DEFAULT_ADMIN_PIN, ADMIN_NEW_PASSWORD) - ); - - assert_cmd_err!( - CommandError::WrongPassword, - device.factory_reset(USER_NEW_PASSWORD) - ); - assert_cmd_err!( - CommandError::WrongPassword, - device.factory_reset(DEFAULT_ADMIN_PIN) - ); - assert_ok!((), device.factory_reset(ADMIN_NEW_PASSWORD)); - - let device = device - .authenticate_admin(DEFAULT_ADMIN_PIN) - .unwrap() - .device(); - - let user = unwrap_ok!(device.authenticate_user(DEFAULT_USER_PIN)); - assert_cmd_err!(CommandError::SlotNotProgrammed, user.get_totp_slot_name(1)); - - let mut device = user.device(); - let pws = unwrap_ok!(device.get_password_safe(DEFAULT_USER_PIN)); - assert_utf8_err_or_ne("test", pws.get_slot_name(0)); - assert_utf8_err_or_ne("testlogin", pws.get_slot_login(0)); - assert_utf8_err_or_ne("testpw", pws.get_slot_password(0)); - drop(pws); - - assert_ok!(3, device.get_user_retry_count()); - assert_ok!((), device.build_aes_key(DEFAULT_ADMIN_PIN)); -} - -#[test_device] -fn build_aes_key(device: DeviceWrapper) { - let mut device = device; - let mut pws = unwrap_ok!(device.get_password_safe(DEFAULT_USER_PIN)); - assert_ok!((), pws.write_slot(0, "test", "testlogin", "testpw")); - drop(pws); - - assert_cmd_err!( - CommandError::WrongPassword, - device.build_aes_key(DEFAULT_USER_PIN) - ); - assert_ok!((), device.build_aes_key(DEFAULT_ADMIN_PIN)); - - let mut device = device - .authenticate_admin(DEFAULT_ADMIN_PIN) - .unwrap() - .device(); - - let pws = unwrap_ok!(device.get_password_safe(DEFAULT_USER_PIN)); - assert_utf8_err_or_ne("test", pws.get_slot_name(0)); - assert_utf8_err_or_ne("testlogin", pws.get_slot_login(0)); - assert_utf8_err_or_ne("testpw", pws.get_slot_password(0)); -} - -#[test_device] -fn change_update_pin(device: Storage) { - let mut device = device; - assert_cmd_err!( - CommandError::WrongPassword, - device.change_update_pin(UPDATE_NEW_PIN, UPDATE_PIN) - ); - assert_ok!((), device.change_update_pin(UPDATE_PIN, UPDATE_NEW_PIN)); - assert_ok!((), device.change_update_pin(UPDATE_NEW_PIN, UPDATE_PIN)); -} - -#[test_device] -fn encrypted_volume(device: Storage) { - let mut device = device; - assert_ok!((), device.lock()); - - assert_eq!(1, count_nitrokey_block_devices()); - assert_ok!((), device.disable_encrypted_volume()); - assert_eq!(1, count_nitrokey_block_devices()); - assert_cmd_err!( - CommandError::WrongPassword, - device.enable_encrypted_volume("123") - ); - assert_eq!(1, count_nitrokey_block_devices()); - assert_ok!((), device.enable_encrypted_volume(DEFAULT_USER_PIN)); - assert_eq!(2, count_nitrokey_block_devices()); - assert_ok!((), device.disable_encrypted_volume()); - assert_eq!(1, count_nitrokey_block_devices()); -} - -#[test_device] -fn hidden_volume(device: Storage) { - let mut device = device; - assert_ok!((), device.lock()); - - assert_eq!(1, count_nitrokey_block_devices()); - assert_ok!((), device.disable_hidden_volume()); - assert_eq!(1, count_nitrokey_block_devices()); - - assert_ok!((), device.enable_encrypted_volume(DEFAULT_USER_PIN)); - assert_eq!(2, count_nitrokey_block_devices()); - - // TODO: why this error code? - assert_cmd_err!( - CommandError::WrongPassword, - device.create_hidden_volume(5, 0, 100, "hiddenpw") - ); - assert_ok!((), device.create_hidden_volume(0, 20, 21, "hidden-pw")); - assert_ok!((), device.create_hidden_volume(0, 20, 21, "hiddenpassword")); - assert_ok!((), device.create_hidden_volume(1, 0, 1, "otherpw")); - // TODO: test invalid range (not handled by libnitrokey) - assert_eq!(2, count_nitrokey_block_devices()); - - assert_cmd_err!( - CommandError::WrongPassword, - device.enable_hidden_volume("blubb") - ); - assert_ok!((), device.enable_hidden_volume("hiddenpassword")); - assert_eq!(2, count_nitrokey_block_devices()); - assert_ok!((), device.enable_hidden_volume("otherpw")); - assert_eq!(2, count_nitrokey_block_devices()); - - assert_ok!((), device.disable_hidden_volume()); - assert_eq!(1, count_nitrokey_block_devices()); -} - -#[test_device] -fn lock(device: Storage) { - let mut device = device; - assert_ok!((), device.enable_encrypted_volume(DEFAULT_USER_PIN)); - assert_ok!((), device.lock()); - assert_eq!(1, count_nitrokey_block_devices()); -} - -#[test_device] -fn set_encrypted_volume_mode(device: Storage) { - // This test case does not check the device status as the command only works with firmware - // version 0.49. For later versions, it does not do anything and always returns Ok(()). - let mut device = device; - - assert_ok!( - (), - device.set_encrypted_volume_mode(DEFAULT_ADMIN_PIN, VolumeMode::ReadOnly) - ); - - // TODO: re-enable once the password is checked in the firmware - // assert_cmd_err!( - // CommandError::WrongPassword, - // device.set_encrypted_volume_mode(DEFAULT_USER_PIN, VolumeMode::ReadOnly) - // ); - - assert_ok!( - (), - device.set_encrypted_volume_mode(DEFAULT_ADMIN_PIN, VolumeMode::ReadOnly) - ); - assert_ok!( - (), - device.set_encrypted_volume_mode(DEFAULT_ADMIN_PIN, VolumeMode::ReadWrite) - ); - assert_ok!( - (), - device.set_encrypted_volume_mode(DEFAULT_ADMIN_PIN, VolumeMode::ReadOnly) - ); -} - -#[test_device] -fn set_unencrypted_volume_mode(device: Storage) { - fn assert_mode(device: &Storage, mode: VolumeMode) { - let status = unwrap_ok!(device.get_status()); - assert_eq!( - status.unencrypted_volume.read_only, - mode == VolumeMode::ReadOnly - ); - } - - fn assert_success(device: &mut Storage, mode: VolumeMode) { - assert_ok!( - (), - device.set_unencrypted_volume_mode(DEFAULT_ADMIN_PIN, mode) - ); - assert_mode(&device, mode); - } - - let mut device = device; - assert_success(&mut device, VolumeMode::ReadOnly); - - assert_cmd_err!( - CommandError::WrongPassword, - device.set_unencrypted_volume_mode(DEFAULT_USER_PIN, VolumeMode::ReadOnly) - ); - assert_mode(&device, VolumeMode::ReadOnly); - - assert_success(&mut device, VolumeMode::ReadWrite); - assert_success(&mut device, VolumeMode::ReadWrite); - assert_success(&mut device, VolumeMode::ReadOnly); -} - -#[test_device] -fn get_storage_status(device: Storage) { - let status = unwrap_ok!(device.get_status()); - assert!(status.serial_number_sd_card > 0); - assert!(status.serial_number_smart_card > 0); -} - -#[test_device] -fn get_production_info(device: Storage) { - let info = unwrap_ok!(device.get_production_info()); - assert_eq!(0, info.firmware_version.major); - assert!(info.firmware_version.minor != 0); - assert!(info.serial_number_cpu != 0); - assert!(info.sd_card.serial_number != 0); - assert!(info.sd_card.size > 0); - assert!(info.sd_card.manufacturing_year > 10); - assert!(info.sd_card.manufacturing_year < 100); - // TODO: month value is not valid atm - // assert!(info.sd_card.manufacturing_month < 12); - assert!(info.sd_card.oem != 0); - assert!(info.sd_card.manufacturer != 0); - - let status = unwrap_ok!(device.get_status()); - assert_eq!(status.firmware_version, info.firmware_version); - assert_eq!(status.serial_number_sd_card, info.sd_card.serial_number); -} - -#[test_device] -fn clear_new_sd_card_warning(device: Storage) { - let mut device = device; - assert_ok!((), device.factory_reset(DEFAULT_ADMIN_PIN)); - thread::sleep(time::Duration::from_secs(3)); - assert_ok!((), device.build_aes_key(DEFAULT_ADMIN_PIN)); - - // We have to perform an SD card operation to reset the new_sd_card_found field - assert_ok!((), device.lock()); - - let status = unwrap_ok!(device.get_status()); - assert!(status.new_sd_card_found); - - assert_ok!((), device.clear_new_sd_card_warning(DEFAULT_ADMIN_PIN)); - - let status = unwrap_ok!(device.get_status()); - assert!(!status.new_sd_card_found); -} - -#[test_device] -fn export_firmware(device: Storage) { - let mut device = device; - assert_cmd_err!( - CommandError::WrongPassword, - device.export_firmware("someadminpn") - ); - assert_ok!((), device.export_firmware(DEFAULT_ADMIN_PIN)); - assert_ok!( - (), - device.set_unencrypted_volume_mode(DEFAULT_ADMIN_PIN, VolumeMode::ReadWrite) - ); - assert_ok!((), device.export_firmware(DEFAULT_ADMIN_PIN)); - assert_ok!( - (), - device.set_unencrypted_volume_mode(DEFAULT_ADMIN_PIN, VolumeMode::ReadOnly) - ); -} diff --git a/nitrokey/tests/lib.rs b/nitrokey/tests/lib.rs deleted file mode 100644 index 25aae0f..0000000 --- a/nitrokey/tests/lib.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2019 Robin Krahl -// SPDX-License-Identifier: MIT - -mod util; - -#[test] -fn get_library_version() { - let version = unwrap_ok!(nitrokey::get_library_version()); - - assert!(version.git.is_empty() || version.git.starts_with("v")); - assert!(version.major > 0); -} - -#[test] -fn take_manager() { - assert!(nitrokey::take().is_ok()); - - let result = nitrokey::take(); - assert!(result.is_ok()); - let result2 = nitrokey::take(); - match result2 { - Ok(_) => panic!("Expected error, got Ok(_)!"), - Err(nitrokey::Error::ConcurrentAccessError) => {} - Err(err) => panic!("Expected ConcurrentAccessError, got {}", err), - } - drop(result); - assert!(nitrokey::take().is_ok()); -} diff --git a/nitrokey/tests/otp.rs b/nitrokey/tests/otp.rs deleted file mode 100644 index 38cd8a9..0000000 --- a/nitrokey/tests/otp.rs +++ /dev/null @@ -1,287 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -mod util; - -use std::fmt::Debug; -use std::ops::DerefMut; - -use nitrokey::{ - Admin, Authenticate, CommandError, Config, ConfigureOtp, Device, GenerateOtp, LibraryError, - OtpMode, OtpSlotData, DEFAULT_ADMIN_PIN, DEFAULT_USER_PIN, -}; -use nitrokey_test::test as test_device; - -// test suite according to RFC 4226, Appendix D -static HOTP_SECRET: &str = "3132333435363738393031323334353637383930"; -static HOTP_CODES: &[&str] = &[ - "755224", "287082", "359152", "969429", "338314", "254676", "287922", "162583", "399871", - "520489", -]; - -// test suite according to RFC 6238, Appendix B -static TOTP_SECRET: &str = "3132333435363738393031323334353637383930"; -static TOTP_CODES: &[(u64, &[&str])] = &[ - (59, &["94287082", "37359152"]), - (1111111109, &["07081804"]), - (1111111111, &["14050471"]), - (1234567890, &["89005924"]), - (2000000000, &["69279037"]), - (20000000000, &["65353130"]), -]; - -#[derive(PartialEq)] -enum TotpTimestampSize { - U32, - U64, -} - -fn make_admin_test_device<'a, T>(device: T) -> Admin<'a, T> -where - T: Device<'a>, - (T, nitrokey::Error): Debug, -{ - unwrap_ok!(device.authenticate_admin(DEFAULT_ADMIN_PIN)) -} - -fn configure_hotp(admin: &mut dyn ConfigureOtp, counter: u8) { - let slot_data = OtpSlotData::new(1, "test-hotp", HOTP_SECRET, OtpMode::SixDigits); - assert_ok!((), admin.write_hotp_slot(slot_data, counter.into())); -} - -fn check_hotp_codes(device: &mut dyn GenerateOtp, offset: u8) { - HOTP_CODES.iter().enumerate().for_each(|(i, code)| { - if i >= offset as usize { - assert_ok!(code.to_string(), device.get_hotp_code(1)); - } - }); -} - -#[test_device] -fn set_time(device: DeviceWrapper) { - let mut device = device; - assert_ok!((), device.set_time(1546385382, true)); - assert_ok!((), device.set_time(1546385392, false)); - assert_cmd_err!(CommandError::Timestamp, device.set_time(1546385292, false)); - assert_ok!((), device.set_time(1546385382, true)); -} - -#[test_device] -fn hotp_no_pin(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let config = Config::new(None, None, None, false); - assert_ok!((), admin.write_config(config)); - - configure_hotp(&mut admin, 0); - check_hotp_codes(admin.deref_mut(), 0); - - configure_hotp(&mut admin, 5); - check_hotp_codes(admin.deref_mut(), 5); - - configure_hotp(&mut admin, 0); - check_hotp_codes(&mut admin.device(), 0); -} - -#[test_device] -fn hotp_pin(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let config = Config::new(None, None, None, true); - assert_ok!((), admin.write_config(config)); - - configure_hotp(&mut admin, 0); - let mut user = unwrap_ok!(admin.device().authenticate_user(DEFAULT_USER_PIN)); - check_hotp_codes(&mut user, 0); - - assert_cmd_err!(CommandError::NotAuthorized, user.device().get_hotp_code(1)); -} - -#[test_device] -fn hotp_slot_name(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let slot_data = OtpSlotData::new(1, "test-hotp", HOTP_SECRET, OtpMode::SixDigits); - assert_ok!((), admin.write_hotp_slot(slot_data, 0)); - - let device = admin.device(); - assert_ok!("test-hotp".to_string(), device.get_hotp_slot_name(1)); - assert_lib_err!(LibraryError::InvalidSlot, device.get_hotp_slot_name(4)); -} - -#[test_device] -fn hotp_error(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let slot_data = OtpSlotData::new(1, "", HOTP_SECRET, OtpMode::SixDigits); - assert_cmd_err!(CommandError::NoName, admin.write_hotp_slot(slot_data, 0)); - let slot_data = OtpSlotData::new(4, "test", HOTP_SECRET, OtpMode::SixDigits); - assert_lib_err!( - LibraryError::InvalidSlot, - admin.write_hotp_slot(slot_data, 0) - ); - let slot_data = OtpSlotData::new(1, "test", "foobar", OtpMode::SixDigits); - assert_lib_err!( - LibraryError::InvalidHexString, - admin.write_hotp_slot(slot_data, 0) - ); - let code = admin.get_hotp_code(4); - assert_lib_err!(LibraryError::InvalidSlot, code); -} - -#[test_device] -fn hotp_erase(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let config = Config::new(None, None, None, false); - assert_ok!((), admin.write_config(config)); - let slot_data = OtpSlotData::new(1, "test1", HOTP_SECRET, OtpMode::SixDigits); - assert_ok!((), admin.write_hotp_slot(slot_data, 0)); - let slot_data = OtpSlotData::new(2, "test2", HOTP_SECRET, OtpMode::SixDigits); - assert_ok!((), admin.write_hotp_slot(slot_data, 0)); - - assert_ok!((), admin.erase_hotp_slot(1)); - - let mut device = admin.device(); - let result = device.get_hotp_slot_name(1); - assert_cmd_err!(CommandError::SlotNotProgrammed, result); - let result = device.get_hotp_code(1); - assert_cmd_err!(CommandError::SlotNotProgrammed, result); - - assert_ok!("test2".to_string(), device.get_hotp_slot_name(2)); -} - -fn configure_totp(admin: &mut dyn ConfigureOtp, factor: u64) { - let slot_data = OtpSlotData::new(1, "test-totp", TOTP_SECRET, OtpMode::EightDigits); - let time_window = 30u64.checked_mul(factor).unwrap(); - assert_ok!((), admin.write_totp_slot(slot_data, time_window as u16)); -} - -fn check_totp_codes(device: &mut dyn GenerateOtp, factor: u64, timestamp_size: TotpTimestampSize) { - for (base_time, codes) in TOTP_CODES { - let time = base_time.checked_mul(factor).unwrap(); - let is_u64 = time > u32::max_value() as u64; - if is_u64 != (timestamp_size == TotpTimestampSize::U64) { - continue; - } - - assert_ok!((), device.set_time(time, true)); - let code = unwrap_ok!(device.get_totp_code(1)); - assert!( - code.contains(&code), - "Generated TOTP code {} for {}, but expected one of {}", - code, - base_time, - codes.join(", ") - ); - } -} - -#[test_device] -fn totp_no_pin(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let config = Config::new(None, None, None, false); - assert_ok!((), admin.write_config(config)); - - configure_totp(&mut admin, 1); - check_totp_codes(admin.deref_mut(), 1, TotpTimestampSize::U32); - - configure_totp(&mut admin, 2); - check_totp_codes(admin.deref_mut(), 2, TotpTimestampSize::U32); - - configure_totp(&mut admin, 1); - check_totp_codes(&mut admin.device(), 1, TotpTimestampSize::U32); -} - -#[test_device] -// Nitrokey Storage does only support timestamps that fit in a 32-bit -// unsigned integer, so don't test with it. -fn totp_no_pin_64(device: Pro) { - let mut admin = make_admin_test_device(device); - let config = Config::new(None, None, None, false); - assert_ok!((), admin.write_config(config)); - - configure_totp(&mut admin, 1); - check_totp_codes(admin.deref_mut(), 1, TotpTimestampSize::U64); - - configure_totp(&mut admin, 2); - check_totp_codes(admin.deref_mut(), 2, TotpTimestampSize::U64); - - configure_totp(&mut admin, 1); - check_totp_codes(&mut admin.device(), 1, TotpTimestampSize::U64); -} - -#[test_device] -fn totp_pin(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let config = Config::new(None, None, None, true); - assert_ok!((), admin.write_config(config)); - - configure_totp(&mut admin, 1); - let mut user = unwrap_ok!(admin.device().authenticate_user(DEFAULT_USER_PIN)); - check_totp_codes(&mut user, 1, TotpTimestampSize::U32); - - assert_cmd_err!(CommandError::NotAuthorized, user.device().get_totp_code(1)); -} - -#[test_device] -// See comment for totp_no_pin_64. -fn totp_pin_64(device: Pro) { - let mut admin = make_admin_test_device(device); - let config = Config::new(None, None, None, true); - assert_ok!((), admin.write_config(config)); - - configure_totp(&mut admin, 1); - let mut user = unwrap_ok!(admin.device().authenticate_user(DEFAULT_USER_PIN)); - check_totp_codes(&mut user, 1, TotpTimestampSize::U64); - - assert_cmd_err!(CommandError::NotAuthorized, user.device().get_totp_code(1)); -} - -#[test_device] -fn totp_slot_name(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let slot_data = OtpSlotData::new(1, "test-totp", TOTP_SECRET, OtpMode::EightDigits); - assert_ok!((), admin.write_totp_slot(slot_data, 0)); - - let device = admin.device(); - let result = device.get_totp_slot_name(1); - assert_ok!("test-totp", result); - let result = device.get_totp_slot_name(16); - assert_lib_err!(LibraryError::InvalidSlot, result); -} - -#[test_device] -fn totp_error(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let slot_data = OtpSlotData::new(1, "", TOTP_SECRET, OtpMode::SixDigits); - assert_cmd_err!(CommandError::NoName, admin.write_totp_slot(slot_data, 0)); - let slot_data = OtpSlotData::new(20, "test", TOTP_SECRET, OtpMode::SixDigits); - assert_lib_err!( - LibraryError::InvalidSlot, - admin.write_totp_slot(slot_data, 0) - ); - let slot_data = OtpSlotData::new(4, "test", "foobar", OtpMode::SixDigits); - assert_lib_err!( - LibraryError::InvalidHexString, - admin.write_totp_slot(slot_data, 0) - ); - let code = admin.get_totp_code(20); - assert_lib_err!(LibraryError::InvalidSlot, code); -} - -#[test_device] -fn totp_erase(device: DeviceWrapper) { - let mut admin = make_admin_test_device(device); - let config = Config::new(None, None, None, false); - assert_ok!((), admin.write_config(config)); - let slot_data = OtpSlotData::new(1, "test1", TOTP_SECRET, OtpMode::SixDigits); - assert_ok!((), admin.write_totp_slot(slot_data, 0)); - let slot_data = OtpSlotData::new(2, "test2", TOTP_SECRET, OtpMode::SixDigits); - assert_ok!((), admin.write_totp_slot(slot_data, 0)); - - assert_ok!((), admin.erase_totp_slot(1)); - - let device = admin.device(); - let result = device.get_totp_slot_name(1); - assert_cmd_err!(CommandError::SlotNotProgrammed, result); - let result = device.get_totp_code(1); - assert_cmd_err!(CommandError::SlotNotProgrammed, result); - - assert_ok!("test2".to_string(), device.get_totp_slot_name(2)); -} diff --git a/nitrokey/tests/pws.rs b/nitrokey/tests/pws.rs deleted file mode 100644 index 7169695..0000000 --- a/nitrokey/tests/pws.rs +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -mod util; - -use std::ffi::CStr; - -use libc::{c_int, c_void, free}; -use nitrokey::{ - CommandError, Device, Error, GetPasswordSafe, LibraryError, PasswordSafe, DEFAULT_ADMIN_PIN, - DEFAULT_USER_PIN, SLOT_COUNT, -}; -use nitrokey_sys; -use nitrokey_test::test as test_device; - -fn get_slot_name_direct(slot: u8) -> Result { - let ptr = unsafe { nitrokey_sys::NK_get_password_safe_slot_name(slot) }; - if ptr.is_null() { - return Err(Error::UnexpectedError); - } - let s = unsafe { CStr::from_ptr(ptr).to_string_lossy().into_owned() }; - unsafe { free(ptr as *mut c_void) }; - match s.is_empty() { - true => { - let error = unsafe { nitrokey_sys::NK_get_last_command_status() } as c_int; - match error { - 0 => Ok(s), - other => Err(Error::from(other)), - } - } - false => Ok(s), - } -} - -fn get_pws<'a, T>(device: &mut T) -> PasswordSafe<'_, 'a> -where - T: Device<'a>, -{ - unwrap_ok!(device.get_password_safe(DEFAULT_USER_PIN)) -} - -#[test_device] -fn enable(device: DeviceWrapper) { - let mut device = device; - assert_cmd_err!( - CommandError::WrongPassword, - device.get_password_safe(&(DEFAULT_USER_PIN.to_owned() + "123")) - ); - assert_any_ok!(device.get_password_safe(DEFAULT_USER_PIN)); - assert_cmd_err!( - CommandError::WrongPassword, - device.get_password_safe(DEFAULT_ADMIN_PIN) - ); - assert_any_ok!(device.get_password_safe(DEFAULT_USER_PIN)); -} - -#[test_device] -fn drop(device: DeviceWrapper) { - let mut device = device; - { - let mut pws = get_pws(&mut device); - assert_ok!((), pws.write_slot(1, "name", "login", "password")); - assert_ok!("name".to_string(), pws.get_slot_name(1)); - let result = get_slot_name_direct(1); - assert_ok!(String::from("name"), result); - } - let result = get_slot_name_direct(1); - assert_ok!(String::from("name"), result); - assert_ok!((), device.lock()); - let result = get_slot_name_direct(1); - assert_cmd_err!(CommandError::NotAuthorized, result); -} - -#[test_device] -fn get_status(device: DeviceWrapper) { - let mut device = device; - let mut pws = get_pws(&mut device); - for i in 0..SLOT_COUNT { - assert_ok!((), pws.erase_slot(i)); - } - let status = unwrap_ok!(pws.get_slot_status()); - assert_eq!(status, [false; SLOT_COUNT as usize]); - - assert_ok!((), pws.write_slot(1, "name", "login", "password")); - let status = unwrap_ok!(pws.get_slot_status()); - for i in 0..SLOT_COUNT { - assert_eq!(i == 1, status[i as usize]); - } - - for i in 0..SLOT_COUNT { - assert_ok!((), pws.write_slot(i, "name", "login", "password")); - } - assert_ok!([true; SLOT_COUNT as usize], pws.get_slot_status()); -} - -#[test_device] -fn get_data(device: DeviceWrapper) { - let mut device = device; - let mut pws = get_pws(&mut device); - assert_ok!((), pws.write_slot(1, "name", "login", "password")); - assert_ok!("name".to_string(), pws.get_slot_name(1)); - assert_ok!("login".to_string(), pws.get_slot_login(1)); - assert_ok!("password".to_string(), pws.get_slot_password(1)); - - assert_ok!((), pws.erase_slot(1)); - assert_cmd_err!(CommandError::SlotNotProgrammed, pws.get_slot_name(1)); - assert_cmd_err!(CommandError::SlotNotProgrammed, pws.get_slot_login(1)); - assert_cmd_err!(CommandError::SlotNotProgrammed, pws.get_slot_password(1)); - - let name = "with å"; - let login = "pär@test.com"; - let password = "'i3lJc[09?I:,[u7dWz9"; - assert_ok!((), pws.write_slot(1, name, login, password)); - assert_ok!(name.to_string(), pws.get_slot_name(1)); - assert_ok!(login.to_string(), pws.get_slot_login(1)); - assert_ok!(password.to_string(), pws.get_slot_password(1)); - - assert_lib_err!(LibraryError::InvalidSlot, pws.get_slot_name(SLOT_COUNT)); - assert_lib_err!(LibraryError::InvalidSlot, pws.get_slot_login(SLOT_COUNT)); - assert_lib_err!(LibraryError::InvalidSlot, pws.get_slot_password(SLOT_COUNT)); -} - -#[test_device] -fn write(device: DeviceWrapper) { - let mut device = device; - let mut pws = get_pws(&mut device); - - assert_lib_err!( - LibraryError::InvalidSlot, - pws.write_slot(SLOT_COUNT, "name", "login", "password") - ); - - assert_ok!((), pws.write_slot(0, "", "login", "password")); - assert_cmd_err!(CommandError::SlotNotProgrammed, pws.get_slot_name(0)); - assert_ok!(String::from("login"), pws.get_slot_login(0)); - assert_ok!(String::from("password"), pws.get_slot_password(0)); - - assert_ok!((), pws.write_slot(0, "name", "", "password")); - assert_ok!(String::from("name"), pws.get_slot_name(0)); - assert_cmd_err!(CommandError::SlotNotProgrammed, pws.get_slot_login(0)); - assert_ok!(String::from("password"), pws.get_slot_password(0)); - - assert_ok!((), pws.write_slot(0, "name", "login", "")); - assert_ok!(String::from("name"), pws.get_slot_name(0)); - assert_ok!(String::from("login"), pws.get_slot_login(0)); - assert_cmd_err!(CommandError::SlotNotProgrammed, pws.get_slot_password(0)); -} - -#[test_device] -fn erase(device: DeviceWrapper) { - let mut device = device; - let mut pws = get_pws(&mut device); - assert_lib_err!(LibraryError::InvalidSlot, pws.erase_slot(SLOT_COUNT)); - - assert_ok!((), pws.write_slot(0, "name", "login", "password")); - assert_ok!((), pws.erase_slot(0)); - assert_ok!((), pws.erase_slot(0)); - assert_cmd_err!(CommandError::SlotNotProgrammed, pws.get_slot_name(0)); -} diff --git a/nitrokey/tests/util/mod.rs b/nitrokey/tests/util/mod.rs deleted file mode 100644 index f2b20ec..0000000 --- a/nitrokey/tests/util/mod.rs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -#[macro_export] -macro_rules! unwrap_ok { - ($val:expr) => {{ - match $val { - Ok(val) => val, - Err(err) => panic!( - r#"assertion failed: `(left == right)` - left: `Ok(_)`, - right: `Err({:?})`"#, - err - ), - } - }}; -} - -#[macro_export] -macro_rules! assert_any_ok { - ($val:expr) => {{ - match &$val { - Ok(_) => {} - Err(err) => panic!( - r#"assertion failed: `(left == right)` - left: `Ok(_)`, - right: `Err({:?})`"#, - err - ), - } - }}; -} - -#[macro_export] -macro_rules! assert_ok { - ($left:expr, $right:expr) => {{ - match &$right { - Ok(right) => match &$left { - left => { - if !(*left == *right) { - panic!( - r#"assertion failed: `(left == right)` - left: `{:?}`, - right: `{:?}`"#, - left, right - ) - } - } - }, - Err(right_err) => panic!( - r#"assertion failed: `(left == right)` - left: `Ok({:?})`, - right: `Err({:?})`"#, - $left, right_err - ), - } - }}; -} - -#[macro_export] -macro_rules! assert_err { - ($err:path, $left:expr, $right:expr) => { - match &$right { - Err($err(ref right_err)) => match &$left { - left_err => { - if !(*left_err == *right_err) { - panic!( - r#"assertion failed: `(left == right)` - left: `{:?}`, - right: `{:?}`"#, - left_err, right_err - ) - } - } - }, - Err(ref right_err) => panic!( - r#"assertion failed: `(left == right)` - left: `{:?}`, - right: `{:?}`"#, - $err($left), - right_err - ), - Ok(right_ok) => panic!( - r#"assertion failed: `(left == right)` - left: `Err({:?})`, - right: `Ok({:?})`"#, - $err($left), - right_ok - ), - } - }; -} - -#[macro_export] -macro_rules! assert_cmd_err { - ($left:expr, $right:expr) => { - assert_err!(::nitrokey::Error::CommandError, $left, $right); - }; -} - -#[macro_export] -macro_rules! assert_cmu_err { - ($left:expr, $right:expr) => { - assert_err!(::nitrokey::Error::CommunicationError, $left, $right); - }; -} - -#[macro_export] -macro_rules! assert_lib_err { - ($left:expr, $right:expr) => { - assert_err!(::nitrokey::Error::LibraryError, $left, $right); - }; -} diff --git a/rand/.github/ISSUE_TEMPLATE/compile-issue.md b/rand/.github/ISSUE_TEMPLATE/compile-issue.md deleted file mode 100644 index 8a8354b..0000000 --- a/rand/.github/ISSUE_TEMPLATE/compile-issue.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: Compile issue -about: Report / ask about a compilation issue -title: '' -labels: '' -assignees: '' - ---- - -# Common issues - -**Problem**: `rand_hc::Hc128Rng: rand_core::SeedableRng` (or other RNG) - -**Quick solution**: `cargo update` - -**Details**: This happens when multiple versions of the `rand_core` crate are in use. Check your `Cargo.lock` file for all versions of `rand_core`. Note that some versions (0.2.2 and 0.3.1) are compatibility shims and are not a problem by themselves. diff --git a/rand/.github/ISSUE_TEMPLATE/feature_request.md b/rand/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 90c57c8..0000000 --- a/rand/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - ---- - -## Background - -**What is your motivation?** - -**What type of application is this?** (E.g. cryptography, game, numerical simulation) - -## Feature request - -
diff --git a/rand/.github/ISSUE_TEMPLATE/other.md b/rand/.github/ISSUE_TEMPLATE/other.md deleted file mode 100644 index a3e76ca..0000000 --- a/rand/.github/ISSUE_TEMPLATE/other.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: Other -about: empty template -title: '' -labels: '' -assignees: '' - ---- - - diff --git a/rand/.gitignore b/rand/.gitignore deleted file mode 100644 index ac38e81..0000000 --- a/rand/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -Cargo.lock -rand_wasm_bindgen_test*.[tj]s -rand_wasm_bindgen_test*.wasm diff --git a/rand/.travis.yml b/rand/.travis.yml deleted file mode 100644 index f3790dc..0000000 --- a/rand/.travis.yml +++ /dev/null @@ -1,315 +0,0 @@ -language: rust -sudo: false - -# We support too many combinations of Rust releases, crate features, operating -# systems, and architectures to even remotely test all combinations. -# Yet it turns out we can test most of these independent of each other, because -# they serve different goals or test different pieces of code. -# -# RUST RELEASES -# Goal: make sure we don't use language features unavailable on a certain -# version, and build without warnings. -# We have different builders use 4 Rust releases, a pinned stable release, -# the latest stable, beta and nightly. -# -# ARCHITECTURES -# Goal: test against issues caused by differences in endianness, pointer sizes, -# etc. -# We run tests on 4 different architectures. -# - x64_84, default on Travis (Linux) and AppVeyor (Windows) -# - i686, second AppVeyor (Windows) configuration -# - MIPS, big-endian Linux emulated with QEMU (thanks to Trust) -# - ARMv7, Android emulated with QEMU (thanks to Trust) -# -# OPERATING SYSTEMS -# Goal: test on many operating systems, to verify the OsRng code, which is -# mostly architecture-independent. -# We run tests on Linux, OS X, Windows, Android (emulated), and Node.js (using -# cargo-web). -# One builder cross-compiles for many of the remaining OSes, which ensures we -# keep building, but doesn't run tests. -# OSes supported by Rand but which we can't cross-compile because there -# is no pre-built standard library available: Dragonfly BSD, Haiku, OpenBSD. -# -# CRATE FEATURES, TESTS, AND SUB-CRATES -# Goal: Run unit tests, doctests, examples, and test benchmarks for all crates, -# in configurations that cover all interesting combinations of features. -# Tests run on rand: -# - test no_std support, but only the unit tests: -# `cargo test --tests --no-default-features` -# - test no_std support, including the alloc feature: -# cargo test --tests --no-default-features --features=alloc -# - run unit tests and doctests with all features which are available on stable: -# `cargo test --features=serde1,log` -# - test examples: -# `cargo test --examples` -# Additional tests on nightly: -# - run unit tests and doctests with all features which are available on nightly: -# `cargo test --all-features` -# - run benchmarks as tests: -# `cargo test --benches --features=nightly` -# Tests on subcrates: -# - select crates via --manifest-path (more reliable than --package) -# - test appropriate feature matrix -# -# TODO: SIMD support on stable releases -# NOTE: SIMD support is unreliable on nightly; we track the latest release -# NOTE: Test for alloc feature in no_std is not included here because it depends -# on the alloc crate stabilized in Rust 1.36. -matrix: - include: - - rust: 1.32.0 - env: DESCRIPTION="Linux, 1.32.0" - os: linux - script: - # Differs from standard script: rand_pcg features - - cargo test --tests --no-default-features - # TODO: add simd_support feature: - - cargo test --features=serde1,log - - cargo test --examples - - cargo test --manifest-path rand_core/Cargo.toml - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features - - cargo test --manifest-path rand_distr/Cargo.toml - - cargo test --manifest-path rand_isaac/Cargo.toml --features=serde1 - # TODO: cannot test rand_pcg due to explicit dependency on i128 - - cargo test --manifest-path rand_xorshift/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xoshiro/Cargo.toml - - cargo test --manifest-path rand_chacha/Cargo.toml - - cargo test --manifest-path rand_hc/Cargo.toml - - cargo test --manifest-path rand_jitter/Cargo.toml - - cargo test --manifest-path rand_os/Cargo.toml - - - rust: 1.32.0 - env: DESCRIPTION="OSX, 1.32.0" - os: osx - script: - # Differs from standard script: rand_pcg features - - cargo test --tests --no-default-features - # TODO: add simd_support feature: - - cargo test --features=serde1,log - - cargo test --examples - - cargo test --manifest-path rand_core/Cargo.toml - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features - - cargo test --manifest-path rand_distr/Cargo.toml - - cargo test --manifest-path rand_isaac/Cargo.toml --features=serde1 - # TODO: cannot test rand_pcg due to explicit dependency on i128 - - cargo test --manifest-path rand_xorshift/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xoshiro/Cargo.toml - - cargo test --manifest-path rand_chacha/Cargo.toml - - cargo test --manifest-path rand_hc/Cargo.toml - - cargo test --manifest-path rand_jitter/Cargo.toml - - cargo test --manifest-path rand_os/Cargo.toml - - - rust: stable - env: DESCRIPTION="Linux, stable" - - - rust: stable - env: DESCRIPTION="OSX+iOS, stable" - os: osx - install: - - rustup target add aarch64-apple-ios - script: - # Differs from standard script: includes aarch64-apple-ios cross-build - - cargo test --tests --no-default-features - # TODO: add simd_support feature: - - cargo test --features=serde1,log - - cargo test --examples - - cargo test --manifest-path rand_core/Cargo.toml - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features - - cargo test --manifest-path rand_distr/Cargo.toml - - cargo test --manifest-path rand_isaac/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_pcg/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xorshift/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xoshiro/Cargo.toml - - cargo test --manifest-path rand_chacha/Cargo.toml - - cargo test --manifest-path rand_hc/Cargo.toml - - cargo test --manifest-path rand_jitter/Cargo.toml - - cargo test --manifest-path rand_os/Cargo.toml - - cargo build --target=aarch64-apple-ios - - - rust: beta - env: DESCRIPTION="Linux, beta" - - - rust: nightly - os: linux - env: DESCRIPTION="Linux, nightly, docs" - install: - - cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks - - cargo deadlinks -V - before_script: - - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH - script: - # Differs from standard script: all features, doc build - - cargo test --tests --no-default-features --features=alloc - - cargo test --all-features - - cargo test --benches --features=nightly - - cargo test --examples - - cargo test --manifest-path rand_core/Cargo.toml - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc - - cargo test --manifest-path rand_distr/Cargo.toml - - cargo test --manifest-path rand_isaac/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_pcg/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xorshift/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xoshiro/Cargo.toml - - cargo test --manifest-path rand_chacha/Cargo.toml - - cargo test --manifest-path rand_hc/Cargo.toml - - cargo test --manifest-path rand_jitter/Cargo.toml - - cargo test --manifest-path rand_os/Cargo.toml - # remove cached documentation, otherwise files from previous PRs can get included - - rm -rf target/doc - - cargo doc --no-deps --all --all-features - - cargo deadlinks --dir target/doc - after_success: - - travis-cargo --only nightly doc-upload - - - rust: nightly - os: osx - env: DESCRIPTION="OSX, nightly, docs" - install: - - cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks - - cargo deadlinks -V - script: - # Differs from standard script: all features, doc build - - cargo test --tests --no-default-features --features=alloc - - cargo test --all-features - - cargo test --benches --features=nightly - - cargo test --examples - - cargo test --manifest-path rand_core/Cargo.toml - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc - - cargo test --manifest-path rand_distr/Cargo.toml - - cargo test --manifest-path rand_isaac/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_pcg/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xorshift/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xoshiro/Cargo.toml - - cargo test --manifest-path rand_chacha/Cargo.toml - - cargo test --manifest-path rand_hc/Cargo.toml - - cargo test --manifest-path rand_jitter/Cargo.toml - - cargo test --manifest-path rand_os/Cargo.toml - # remove cached documentation, otherwise files from previous PRs can get included - - rm -rf target/doc - - cargo doc --no-deps --all --all-features - - cargo deadlinks --dir target/doc - - - rust: nightly - env: DESCRIPTION="WASM via emscripten, stdweb and wasm-bindgen" - install: - - rustup target add wasm32-unknown-unknown - - rustup target add wasm32-unknown-emscripten - - nvm install 9 - - ./utils/ci/install_cargo_web.sh - - cargo web prepare-emscripten - - cargo web -V - - cargo list | grep install-update || cargo install -f cargo-update - - cargo install-update -i cargo-update wasm-bindgen-cli wasm-pack - addons: - chrome: stable - script: - # Testing wasm32-unknown-emscripten fails because of rust-lang/rust#49877 - # However, we can still build and link all tests to make sure that works. - # This is actually useful as it finds stuff such as rust-random/rand#669 - - EMCC_CFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" cargo web test --target wasm32-unknown-emscripten --no-run - #- cargo web test --target wasm32-unknown-emscripten - #- cargo web test --nodejs --target wasm32-unknown-emscripten - #- cargo build --target wasm32-unknown-unknown # without any features - - cargo build --target wasm32-unknown-unknown --features=wasm-bindgen - - cargo web test --target wasm32-unknown-unknown --features=stdweb - - cargo build --manifest-path tests/wasm_bindgen/Cargo.toml --target wasm32-unknown-unknown - - wasm-bindgen --nodejs target/wasm32-unknown-unknown/debug/rand_wasm_bindgen_test.wasm --out-dir tests/wasm_bindgen/js - - node tests/wasm_bindgen/js/index.js - - wasm-pack test --node tests/wasm_bindgen - - - rust: nightly - env: DESCRIPTION="cross-platform builder (doesn't run tests)" - install: - - rustup target add x86_64-sun-solaris - - rustup target add x86_64-unknown-cloudabi - - rustup target add x86_64-unknown-freebsd - #- rustup target add x86_64-unknown-fuchsia - - rustup target add x86_64-unknown-netbsd - - rustup target add x86_64-unknown-redox - script: - # Test the top-level crate with all features: - - cargo build --target=x86_64-sun-solaris --all-features - - cargo build --target=x86_64-unknown-cloudabi --all-features - - cargo build --target=x86_64-unknown-freebsd --all-features - #- cargo build --target=x86_64-unknown-fuchsia --all-features - - cargo build --target=x86_64-unknown-netbsd --all-features - - cargo build --target=x86_64-unknown-redox --all-features - - # Trust cross-built/emulated targets. We must repeat all non-default values. - - rust: stable - sudo: required - dist: trusty - services: docker - env: DESCRIPTION="Linux (MIPS, big-endian)" TARGET=mips-unknown-linux-gnu - install: - - sh utils/ci/install.sh - - source ~/.cargo/env || true - script: - - bash utils/ci/script.sh - - rust: stable - sudo: required - dist: trusty - services: docker - env: DESCRIPTION="Android (ARMv7)" TARGET=armv7-linux-androideabi - install: - - sh utils/ci/install.sh - - source ~/.cargo/env || true - script: - - bash utils/ci/script.sh - - rust: nightly - env: DESCRIPTION="no_std platform test" - install: - - rustup target add thumbv6m-none-eabi - script: - # Test the top-level crate with all features: - - cargo build --target=thumbv6m-none-eabi --no-default-features - - - rust: nightly - os: linux - env: DESCRIPTION="Miri, nightly" - script: - - sh utils/ci/miri.sh - -before_install: - - set -e - - rustup self update - -script: - - cargo test --tests --no-default-features - - cargo test --tests --no-default-features --features getrandom - - cargo test --tests --no-default-features --features=alloc - # TODO: add simd_support feature: - - cargo test --features=serde1,log - - cargo test --examples - - cargo test --manifest-path rand_core/Cargo.toml - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc - - cargo test --manifest-path rand_distr/Cargo.toml - - cargo test --manifest-path rand_isaac/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_pcg/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xorshift/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xoshiro/Cargo.toml - - cargo test --manifest-path rand_chacha/Cargo.toml - - cargo test --manifest-path rand_hc/Cargo.toml - - cargo test --manifest-path rand_jitter/Cargo.toml - - cargo test --manifest-path rand_os/Cargo.toml - -after_script: set +e - -cache: - cargo: true - directories: - - .local/share/cargo-web - -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -env: - global: - secure: "BdDntVHSompN+Qxz5Rz45VI4ZqhD72r6aPl166FADlnkIwS6N6FLWdqs51O7G5CpoMXEDvyYrjmRMZe/GYLIG9cmqmn/wUrWPO+PauGiIuG/D2dmfuUNvSTRcIe7UQLXrfP3yyfZPgqsH6pSnNEVopquQKy3KjzqepgriOJtbyY=" - -notifications: - email: - on_success: never diff --git a/rand/CHANGELOG.md b/rand/CHANGELOG.md deleted file mode 100644 index a2ae496..0000000 --- a/rand/CHANGELOG.md +++ /dev/null @@ -1,568 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md). - -You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful. - -## [Unreleased] -- Fix `no_std` behaviour, appropriately enable c2-chacha's `std` feature (#844) -- Add a `no_std` target to CI to continously evaluate `no_std` status (#844) -- `alloc` feature in `no_std` is available since Rust 1.36 (#856) - -## [0.7.0] - 2019-06-28 - -### Fixes -- Fix incorrect pointer usages revealed by Miri testing (#780, #781) -- Fix (tiny!) bias in `Uniform` for 8- and 16-bit ints (#809) - -### Crate -- Bumped MSRV (min supported Rust version) to 1.32.0 -- Updated to Rust Edition 2018 (#823, #824) -- Removed dependence on `rand_xorshift`, `rand_isaac`, `rand_jitter` crates (#759, #765) -- Remove dependency on `winapi` (#724) -- Removed all `build.rs` files (#824) -- Removed code already deprecated in version 0.6 (#757) -- Removed the serde1 feature (It's still available for backwards compatibility, but it does not do anything. #830) -- Many documentation changes - -### rand_core -- Updated to `rand_core` 0.5.0 -- `Error` type redesigned with new API (#800) -- Move `from_entropy` method to `SeedableRng` and remove `FromEntropy` (#800) -- `SeedableRng::from_rng` is now expected to be value-stable (#815) - -### Standard RNGs -- OS interface moved from `rand_os` to new `getrandom` crate (#765, [getrandom](https://github.com/rust-random/getrandom)) -- Use ChaCha for `StdRng` and `ThreadRng` (#792) -- Feature-gate `SmallRng` (#792) -- `ThreadRng` now supports `Copy` (#758) -- Deprecated `EntropyRng` (#765) -- Enable fork protection of ReseedingRng without `std` (#724) - -### Distributions -- Many distributions have been moved to `rand_distr` (#761) -- `Bernoulli::new` constructor now returns a `Result` (#803) -- `Distribution::sample_iter` adjusted for more flexibility (#758) -- Added `distributions::weighted::alias_method::WeightedIndex` for `O(1)` sampling (#692) -- Support sampling `NonZeroU*` types with the `Standard` distribution (#728) -- Optimised `Binomial` distribution sampling (#735, #740, #752) -- Optimised SIMD float sampling (#739) - -### Sequences -- Make results portable across 32- and 64-bit by using `u32` samples for `usize` where possible (#809) - -## [0.6.5] - 2019-01-28 -### Crates -- Update `rand_core` to 0.4 (#703) -- Move `JitterRng` to its own crate (#685) -- Add a wasm-bindgen test crate (#696) - -### Platforms -- Fuchsia: Replaced fuchsia-zircon with fuchsia-cprng - -### Doc -- Use RFC 1946 for doc links (#691) -- Fix some doc links and notes (#711) - -## [0.6.4] - 2019-01-08 -### Fixes -- Move wasm-bindgen shims to correct crate (#686) -- Make `wasm32-unknown-unknown` compile but fail at run-time if missing bindingsg (#686) - -## [0.6.3] - 2019-01-04 -### Fixes -- Make the `std` feature require the optional `rand_os` dependency (#675) -- Re-export the optional WASM dependencies of `rand_os` from `rand` to avoid breakage (#674) - -## [0.6.2] - 2019-01-04 -### Additions -- Add `Default` for `ThreadRng` (#657) -- Move `rngs::OsRng` to `rand_os` sub-crate; clean up code; use as dependency (#643) ##BLOCKER## -- Add `rand_xoshiro` sub-crate, plus benchmarks (#642, #668) - -### Fixes -- Fix bias in `UniformInt::sample_single` (#662) -- Use `autocfg` instead of `rustc_version` for rustc version detection (#664) -- Disable `i128` and `u128` if the `target_os` is `emscripten` (#671: work-around Emscripten limitation) -- CI fixes (#660, #671) - -### Optimisations -- Optimise memory usage of `UnitCircle` and `UnitSphereSurface` distributions (no PR) - -## [0.6.1] - 2018-11-22 -- Support sampling `Duration` also for `no_std` (only since Rust 1.25) (#649) -- Disable default features of `libc` (#647) - -## [0.6.0] - 2018-11-14 - -### Project organisation -- Rand has moved from [rust-lang-nursery](https://github.com/rust-lang-nursery/rand) - to [rust-random](https://github.com/rust-random/rand)! (#578) -- Created [The Rust Random Book](https://rust-random.github.io/book/) - ([source](https://github.com/rust-random/book)) -- Update copyright and licence notices (#591, #611) -- Migrate policy documentation from the wiki (#544) - -### Platforms -- Add fork protection on Unix (#466) -- Added support for wasm-bindgen. (#541, #559, #562, #600) -- Enable `OsRng` for powerpc64, sparc and sparc64 (#609) -- Use `syscall` from `libc` on Linux instead of redefining it (#629) - -### RNGs -- Switch `SmallRng` to use PCG (#623) -- Implement `Pcg32` and `Pcg64Mcg` generators (#632) -- Move ISAAC RNGs to a dedicated crate (#551) -- Move Xorshift RNG to its own crate (#557) -- Move ChaCha and HC128 RNGs to dedicated crates (#607, #636) -- Remove usage of `Rc` from `ThreadRng` (#615) - -### Sampling and distributions -- Implement `Rng.gen_ratio()` and `Bernoulli::new_ratio()` (#491) -- Make `Uniform` strictly respect `f32` / `f64` high/low bounds (#477) -- Allow `gen_range` and `Uniform` to work on non-`Copy` types (#506) -- `Uniform` supports inclusive ranges: `Uniform::from(a..=b)`. This is - automatically enabled for Rust >= 1.27. (#566) -- Implement `TrustedLen` and `FusedIterator` for `DistIter` (#620) - -#### New distributions -- Add the `Dirichlet` distribution (#485) -- Added sampling from the unit sphere and circle. (#567) -- Implement the triangular distribution (#575) -- Implement the Weibull distribution (#576) -- Implement the Beta distribution (#574) - -#### Optimisations - -- Optimise `Bernoulli::new` (#500) -- Optimise `char` sampling (#519) -- Optimise sampling of `std::time::Duration` (#583) - -### Sequences -- Redesign the `seq` module (#483, #515) -- Add `WeightedIndex` and `choose_weighted` (#518, #547) -- Optimised and changed return type of the `sample_indices` function. (#479) -- Use `Iterator::size_hint()` to speed up `IteratorRandom::choose` (#593) - -### SIMD -- Support for generating SIMD types (#523, #542, #561, #630) - -### Other -- Revise CI scripts (#632, #635) -- Remove functionality already deprecated in 0.5 (#499) -- Support for `i128` and `u128` is automatically enabled for Rust >= 1.26. This - renders the `i128_support` feature obsolete. It still exists for backwards - compatibility but does not have any effect. This breaks programs using Rand - with `i128_support` on nightlies older than Rust 1.26. (#571) - - -## [0.5.5] - 2018-08-07 -### Documentation -- Fix links in documentation (#582) - - -## [0.5.4] - 2018-07-11 -### Platform support -- Make `OsRng` work via WASM/stdweb for WebWorkers - - -## [0.5.3] - 2018-06-26 -### Platform support -- OpenBSD, Bitrig: fix compilation (broken in 0.5.1) (#530) - - -## [0.5.2] - 2018-06-18 -### Platform support -- Hide `OsRng` and `JitterRng` on unsupported platforms (#512; fixes #503). - - -## [0.5.1] - 2018-06-08 - -### New distributions -- Added Cauchy distribution. (#474, #486) -- Added Pareto distribution. (#495) - -### Platform support and `OsRng` -- Remove blanket Unix implementation. (#484) -- Remove Wasm unimplemented stub. (#484) -- Dragonfly BSD: read from `/dev/random`. (#484) -- Bitrig: use `getentropy` like OpenBSD. (#484) -- Solaris: (untested) use `getrandom` if available, otherwise `/dev/random`. (#484) -- Emscripten, `stdweb`: split the read up in chunks. (#484) -- Emscripten, Haiku: don't do an extra blocking read from `/dev/random`. (#484) -- Linux, NetBSD, Solaris: read in blocking mode on first use in `fill_bytes`. (#484) -- Fuchsia, CloudABI: fix compilation (broken in Rand 0.5). (#484) - - -## [0.5.0] - 2018-05-21 - -### Crate features and organisation -- Minimum Rust version update: 1.22.0. (#239) -- Create a separate `rand_core` crate. (#288) -- Deprecate `rand_derive`. (#256) -- Add `prelude` (and module reorganisation). (#435) -- Add `log` feature. Logging is now available in `JitterRng`, `OsRng`, `EntropyRng` and `ReseedingRng`. (#246) -- Add `serde1` feature for some PRNGs. (#189) -- `stdweb` feature for `OsRng` support on WASM via stdweb. (#272, #336) - -### `Rng` trait -- Split `Rng` in `RngCore` and `Rng` extension trait. - `next_u32`, `next_u64` and `fill_bytes` are now part of `RngCore`. (#265) -- Add `Rng::sample`. (#256) -- Deprecate `Rng::gen_weighted_bool`. (#308) -- Add `Rng::gen_bool`. (#308) -- Remove `Rng::next_f32` and `Rng::next_f64`. (#273) -- Add optimized `Rng::fill` and `Rng::try_fill` methods. (#247) -- Deprecate `Rng::gen_iter`. (#286) -- Deprecate `Rng::gen_ascii_chars`. (#279) - -### `rand_core` crate -- `rand` now depends on new `rand_core` crate (#288) -- `RngCore` and `SeedableRng` are now part of `rand_core`. (#288) -- Add modules to help implementing RNGs `impl` and `le`. (#209, #228) -- Add `Error` and `ErrorKind`. (#225) -- Add `CryptoRng` marker trait. (#273) -- Add `BlockRngCore` trait. (#281) -- Add `BlockRng` and `BlockRng64` wrappers to help implementations. (#281, #325) -- Revise the `SeedableRng` trait. (#233) -- Remove default implementations for `RngCore::next_u64` and `RngCore::fill_bytes`. (#288) -- Add `RngCore::try_fill_bytes`. (#225) - -### Other traits and types -- Add `FromEntropy` trait. (#233, #375) -- Add `SmallRng` wrapper. (#296) -- Rewrite `ReseedingRng` to only work with `BlockRngCore` (substantial performance improvement). (#281) -- Deprecate `weak_rng`. Use `SmallRng` instead. (#296) -- Deprecate `AsciiGenerator`. (#279) - -### Random number generators -- Switch `StdRng` and `thread_rng` to HC-128. (#277) -- `StdRng` must now be created with `from_entropy` instead of `new` -- Change `thread_rng` reseeding threshold to 32 MiB. (#277) -- PRNGs no longer implement `Copy`. (#209) -- `Debug` implementations no longer show internals. (#209) -- Implement `Clone` for `ReseedingRng`, `JitterRng`, OsRng`. (#383, #384) -- Implement serialization for `XorShiftRng`, `IsaacRng` and `Isaac64Rng` under the `serde1` feature. (#189) -- Implement `BlockRngCore` for `ChaChaCore` and `Hc128Core`. (#281) -- All PRNGs are now portable across big- and little-endian architectures. (#209) -- `Isaac64Rng::next_u32` no longer throws away half the results. (#209) -- Add `IsaacRng::new_from_u64` and `Isaac64Rng::new_from_u64`. (#209) -- Add the HC-128 CSPRNG `Hc128Rng`. (#210) -- Change ChaCha20 to have 64-bit counter and 64-bit stream. (#349) -- Changes to `JitterRng` to get its size down from 2112 to 24 bytes. (#251) -- Various performance improvements to all PRNGs. - -### Platform support and `OsRng` -- Add support for CloudABI. (#224) -- Remove support for NaCl. (#225) -- WASM support for `OsRng` via stdweb, behind the `stdweb` feature. (#272, #336) -- Use `getrandom` on more platforms for Linux, and on Android. (#338) -- Use the `SecRandomCopyBytes` interface on macOS. (#322) -- On systems that do not have a syscall interface, only keep a single file descriptor open for `OsRng`. (#239) -- On Unix, first try a single read from `/dev/random`, then `/dev/urandom`. (#338) -- Better error handling and reporting in `OsRng` (using new error type). (#225) -- `OsRng` now uses non-blocking when available. (#225) -- Add `EntropyRng`, which provides `OsRng`, but has `JitterRng` as a fallback. (#235) - -### Distributions -- New `Distribution` trait. (#256) -- Add `Distribution::sample_iter` and `Rng::::sample_iter`. (#361) -- Deprecate `Rand`, `Sample` and `IndependentSample` traits. (#256) -- Add a `Standard` distribution (replaces most `Rand` implementations). (#256) -- Add `Binomial` and `Poisson` distributions. (#96) -- Add `Bernoulli` dsitribution. (#411) -- Add `Alphanumeric` distribution. (#279) -- Remove `Closed01` distribution, add `OpenClosed01`. (#274, #420) -- Rework `Range` type, making it possible to implement it for user types. (#274) -- Rename `Range` to `Uniform`. (#395) -- Add `Uniform::new_inclusive` for inclusive ranges. (#274) -- Use widening multiply method for much faster integer range reduction. (#274) -- `Standard` distribution for `char` uses `Uniform` internally. (#274) -- `Standard` distribution for `bool` uses sign test. (#274) -- Implement `Standard` distribution for `Wrapping`. (#436) -- Implement `Uniform` distribution for `Duration`. (#427) - - -## [0.4.3] - 2018-08-16 -### Fixed -- Use correct syscall number for PowerPC (#589) - - -## [0.4.2] - 2018-01-06 -### Changed -- Use `winapi` on Windows -- Update for Fuchsia OS -- Remove dev-dependency on `log` - - -## [0.4.1] - 2017-12-17 -### Added -- `no_std` support - - -## [0.4.0-pre.0] - 2017-12-11 -### Added -- `JitterRng` added as a high-quality alternative entropy source using the - system timer -- new `seq` module with `sample_iter`, `sample_slice`, etc. -- WASM support via dummy implementations (fail at run-time) -- Additional benchmarks, covering generators and new seq code - -### Changed -- `thread_rng` uses `JitterRng` if seeding from system time fails - (slower but more secure than previous method) - -### Deprecated - - `sample` function deprecated (replaced by `sample_iter`) - - -## [0.3.20] - 2018-01-06 -### Changed -- Remove dev-dependency on `log` -- Update `fuchsia-zircon` dependency to 0.3.2 - - -## [0.3.19] - 2017-12-27 -### Changed -- Require `log <= 0.3.8` for dev builds -- Update `fuchsia-zircon` dependency to 0.3 -- Fix broken links in docs (to unblock compiler docs testing CI) - - -## [0.3.18] - 2017-11-06 -### Changed -- `thread_rng` is seeded from the system time if `OsRng` fails -- `weak_rng` now uses `thread_rng` internally - - -## [0.3.17] - 2017-10-07 -### Changed - - Fuchsia: Magenta was renamed Zircon - -## [0.3.16] - 2017-07-27 -### Added -- Implement Debug for mote non-public types -- implement `Rand` for (i|u)i128 -- Support for Fuchsia - -### Changed -- Add inline attribute to SampleRange::construct_range. - This improves the benchmark for sample in 11% and for shuffle in 16%. -- Use `RtlGenRandom` instead of `CryptGenRandom` - - -## [0.3.15] - 2016-11-26 -### Added -- Add `Rng` trait method `choose_mut` -- Redox support - -### Changed -- Use `arc4rand` for `OsRng` on FreeBSD. -- Use `arc4random(3)` for `OsRng` on OpenBSD. - -### Fixed -- Fix filling buffers 4 GiB or larger with `OsRng::fill_bytes` on Windows - - -## [0.3.14] - 2016-02-13 -### Fixed -- Inline definitions from winapi/advapi32, wich decreases build times - - -## [0.3.13] - 2016-01-09 -### Fixed -- Compatible with Rust 1.7.0-nightly (needed some extra type annotations) - - -## [0.3.12] - 2015-11-09 -### Changed -- Replaced the methods in `next_f32` and `next_f64` with the technique described - Saito & Matsumoto at MCQMC'08. The new method should exhibit a slightly more - uniform distribution. -- Depend on libc 0.2 - -### Fixed -- Fix iterator protocol issue in `rand::sample` - - -## [0.3.11] - 2015-08-31 -### Added -- Implement `Rand` for arrays with n <= 32 - - -## [0.3.10] - 2015-08-17 -### Added -- Support for NaCl platforms - -### Changed -- Allow `Rng` to be `?Sized`, impl for `&mut R` and `Box` where `R: ?Sized + Rng` - - -## [0.3.9] - 2015-06-18 -### Changed -- Use `winapi` for Windows API things - -### Fixed -- Fixed test on stable/nightly -- Fix `getrandom` syscall number for aarch64-unknown-linux-gnu - - -## [0.3.8] - 2015-04-23 -### Changed -- `log` is a dev dependency - -### Fixed -- Fix race condition of atomics in `is_getrandom_available` - - -## [0.3.7] - 2015-04-03 -### Fixed -- Derive Copy/Clone changes - - -## [0.3.6] - 2015-04-02 -### Changed -- Move to stable Rust! - - -## [0.3.5] - 2015-04-01 -### Fixed -- Compatible with Rust master - - -## [0.3.4] - 2015-03-31 -### Added -- Implement Clone for `Weighted` - -### Fixed -- Compatible with Rust master - - -## [0.3.3] - 2015-03-26 -### Fixed -- Fix compile on Windows - - -## [0.3.2] - 2015-03-26 - - -## [0.3.1] - 2015-03-26 -### Fixed -- Fix compile on Windows - - -## [0.3.0] - 2015-03-25 -### Changed -- Update to use log version 0.3.x - - -## [0.2.1] - 2015-03-22 -### Fixed -- Compatible with Rust master -- Fixed iOS compilation - - -## [0.2.0] - 2015-03-06 -### Fixed -- Compatible with Rust master (move from `old_io` to `std::io`) - - -## [0.1.4] - 2015-03-04 -### Fixed -- Compatible with Rust master (use wrapping ops) - - -## [0.1.3] - 2015-02-20 -### Fixed -- Compatible with Rust master - -### Removed -- Removed Copy implementations from RNGs - - -## [0.1.2] - 2015-02-03 -### Added -- Imported functionality from `std::rand`, including: - - `StdRng`, `SeedableRng`, `TreadRng`, `weak_rng()` - - `ReaderRng`: A wrapper around any Reader to treat it as an RNG. -- Imported documentation from `std::rand` -- Imported tests from `std::rand` - - -## [0.1.1] - 2015-02-03 -### Added -- Migrate to a cargo-compatible directory structure. - -### Fixed -- Do not use entropy during `gen_weighted_bool(1)` - - -## [Rust 0.12.0] - 2014-10-09 -### Added -- Impl Rand for tuples of arity 11 and 12 -- Include ChaCha pseudorandom generator -- Add `next_f64` and `next_f32` to Rng -- Implement Clone for PRNGs - -### Changed -- Rename `TaskRng` to `ThreadRng` and `task_rng` to `thread_rng` (since a - runtime is removed from Rust). - -### Fixed -- Improved performance of ISAAC and ISAAC64 by 30% and 12 % respectively, by - informing the optimiser that indexing is never out-of-bounds. - -### Removed -- Removed the Deprecated `choose_option` - - -## [Rust 0.11.0] - 2014-07-02 -### Added -- document when to use `OSRng` in cryptographic context, and explain why we use `/dev/urandom` instead of `/dev/random` -- `Rng::gen_iter()` which will return an infinite stream of random values -- `Rng::gen_ascii_chars()` which will return an infinite stream of random ascii characters - -### Changed -- Now only depends on libcore! -- Remove `Rng.choose()`, rename `Rng.choose_option()` to `.choose()` -- Rename OSRng to OsRng -- The WeightedChoice structure is no longer built with a `Vec>`, - but rather a `&mut [Weighted]`. This means that the WeightedChoice - structure now has a lifetime associated with it. -- The `sample` method on `Rng` has been moved to a top-level function in the - `rand` module due to its dependence on `Vec`. - -### Removed -- `Rng::gen_vec()` was removed. Previous behavior can be regained with - `rng.gen_iter().take(n).collect()` -- `Rng::gen_ascii_str()` was removed. Previous behavior can be regained with - `rng.gen_ascii_chars().take(n).collect()` -- {IsaacRng, Isaac64Rng, XorShiftRng}::new() have all been removed. These all - relied on being able to use an OSRng for seeding, but this is no longer - available in librand (where these types are defined). To retain the same - functionality, these types now implement the `Rand` trait so they can be - generated with a random seed from another random number generator. This allows - the stdlib to use an OSRng to create seeded instances of these RNGs. -- Rand implementations for `Box` and `@T` were removed. These seemed to be - pretty rare in the codebase, and it allows for librand to not depend on - liballoc. Additionally, other pointer types like Rc and Arc were not - supported. -- Remove a slew of old deprecated functions - - -## [Rust 0.10] - 2014-04-03 -### Changed -- replace `Rng.shuffle's` functionality with `.shuffle_mut` -- bubble up IO errors when creating an OSRng - -### Fixed -- Use `fill()` instead of `read()` -- Rewrite OsRng in Rust for windows - -## [0.10-pre] - 2014-03-02 -### Added -- Seperate `rand` out of the standard library diff --git a/rand/COPYRIGHT b/rand/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/Cargo.toml b/rand/Cargo.toml deleted file mode 100644 index ef344a6..0000000 --- a/rand/Cargo.toml +++ /dev/null @@ -1,90 +0,0 @@ -[package] -name = "rand" -version = "0.7.0" -authors = ["The Rand Project Developers", "The Rust Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/" -homepage = "https://crates.io/crates/rand" -description = """ -Random number generators and other randomness functionality. -""" -keywords = ["random", "rng"] -categories = ["algorithms", "no-std"] -exclude = ["/utils/*", "/.travis.yml", "/appveyor.yml", ".gitignore"] -autobenches = true -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[features] -# Meta-features: -default = ["std"] # without "std" rand uses libcore -nightly = ["simd_support"] # enables all features requiring nightly rust -serde1 = [] # does nothing, deprecated - -# Optional dependencies: -std = ["rand_core/std", "rand_chacha/std", "alloc", "getrandom"] -alloc = ["rand_core/alloc"] # enables Vec and Box support (without std) -# re-export optional WASM dependencies to avoid breakage: -wasm-bindgen = ["getrandom_package/wasm-bindgen"] -stdweb = ["getrandom_package/stdweb"] -getrandom = ["getrandom_package", "rand_core/getrandom"] - -# Configuration: -simd_support = ["packed_simd"] # enables SIMD support -small_rng = ["rand_pcg"] # enables SmallRng - -[workspace] -members = [ - "rand_core", - "rand_distr", - "rand_jitter", - "rand_os", - "rand_isaac", - "rand_chacha", - "rand_hc", - "rand_pcg", - "rand_xorshift", - "rand_xoshiro", - "tests/wasm_bindgen", -] - -[dependencies] -rand_core = { path = "rand_core", version = "0.5" } -rand_pcg = { path = "rand_pcg", version = "0.2", optional = true } -# Do not depend on 'getrandom_package' directly; use the 'getrandom' feature! -getrandom_package = { version = "0.1.1", package = "getrandom", optional = true } -log = { version = "0.4", optional = true } - -[dependencies.packed_simd] -# NOTE: so far no version works reliably due to dependence on unstable features -version = "0.3" -# git = "https://github.com/rust-lang-nursery/packed_simd" -optional = true -features = ["into_bits"] - -[target.'cfg(unix)'.dependencies] -# Used for fork protection (reseeding.rs) -libc = { version = "0.2.22", default-features = false } - -# Emscripten does not support 128-bit integers, which are used by ChaCha code. -# We work around this by using a different RNG. -[target.'cfg(not(target_os = "emscripten"))'.dependencies] -rand_chacha = { path = "rand_chacha", version = "0.2.1", default-features = false } -[target.'cfg(target_os = "emscripten")'.dependencies] -rand_hc = { path = "rand_hc", version = "0.2" } - -[dev-dependencies] -rand_pcg = { path = "rand_pcg", version = "0.2" } -# Only for benches: -rand_hc = { path = "rand_hc", version = "0.2" } -rand_xoshiro = { path = "rand_xoshiro", version = "0.3" } -rand_isaac = { path = "rand_isaac", version = "0.2" } -rand_xorshift = { path = "rand_xorshift", version = "0.2" } - -[package.metadata.docs.rs] -all-features = true diff --git a/rand/LICENSE-APACHE b/rand/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/LICENSE-MIT b/rand/LICENSE-MIT deleted file mode 100644 index d93b5ba..0000000 --- a/rand/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2018 Developers of the Rand project -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/README.md b/rand/README.md deleted file mode 100644 index 5acbadb..0000000 --- a/rand/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# Rand - -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Crate](https://img.shields.io/crates/v/rand.svg)](https://crates.io/crates/rand) -[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand) -[![API](https://docs.rs/rand/badge.svg)](https://docs.rs/rand) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -A Rust library for random number generation. - -Rand provides utilities to generate random numbers, to convert them to useful -types and distributions, and some randomness-related algorithms. - -The core random number generation traits of Rand live in the [rand_core]( -https://crates.io/crates/rand_core) crate but are also exposed here; RNG -implementations should prefer to use `rand_core` while most other users should -depend on `rand`. - -Documentation: -- [The Rust Rand Book](https://rust-random.github.io/book) -- [API reference (master)](https://rust-random.github.io/rand) -- [API reference (docs.rs)](https://docs.rs/rand) - - -## Usage - -Add this to your `Cargo.toml`: - -```toml -[dependencies] -rand = "0.7" -``` - -To get started using Rand, see [The Book](https://rust-random.github.io/book). - - -## Versions - -Rand libs have inter-dependencies and make use of the -[semver trick](https://github.com/dtolnay/semver-trick/) in order to make traits -compatible across crate versions. (This is especially important for `RngCore` -and `SeedableRng`.) A few crate releases are thus compatibility shims, -depending on the *next* lib version (e.g. `rand_core` versions `0.2.2` and -`0.3.1`). This means, for example, that `rand_core_0_4_0::SeedableRng` and -`rand_core_0_3_0::SeedableRng` are distinct, incompatible traits, which can -cause build errors. Usually, running `cargo update` is enough to fix any issues. - -The Rand lib is not yet stable, however we are careful to limit breaking changes -and warn via deprecation wherever possible. Patch versions never introduce -breaking changes. The following minor versions are supported: - -- Version 0.7 was released in June 2019, moving most non-uniform distributions - to an external crate, moving `from_entropy` to `SeedableRng`, and many small - changes and fixes. -- Version 0.6 was released in November 2018, redesigning the `seq` module, - moving most PRNGs to external crates, and many small changes. -- Version 0.5 was released in May 2018, as a major reorganisation - (introducing `RngCore` and `rand_core`, and deprecating `Rand` and the - previous distribution traits). -- Version 0.4 was released in December 2017, but contained almost no breaking - changes from the 0.3 series. - -A detailed [changelog](CHANGELOG.md) is available. - -When upgrading to the next minor series (especially 0.4 → 0.5), we recommend -reading the [Upgrade Guide](https://rust-random.github.io/book/update.html). - -### Rust version requirements - -Since version 0.7, Rand requires **Rustc version 1.32 or greater**. -Rand 0.5 requires Rustc 1.22 or greater while versions -0.4 and 0.3 (since approx. June 2017) require Rustc version 1.15 or -greater. Subsets of the Rand code may work with older Rust versions, but this -is not supported. - -Travis CI always has a build with a pinned version of Rustc matching the oldest -supported Rust release. The current policy is that this can be updated in any -Rand release if required, but the change must be noted in the changelog. - -## Crate Features - -Rand is built with these features enabled by default: - -- `std` enables functionality dependent on the `std` lib -- `alloc` (implied by `std`) enables functionality requiring an allocator (when using this feature in `no_std`, Rand requires Rustc version 1.36 or greater) -- `getrandom` (implied by `std`) is an optional dependency providing the code - behind `rngs::OsRng` - -Optionally, the following dependencies can be enabled: - -- `log` enables logging via the `log` crate -- `stdweb` implies `getrandom/stdweb` to enable - `getrandom` support on `wasm32-unknown-unknown` -- `wasm-bindgen` implies `getrandom/wasm-bindgen` to enable - `getrandom` support on `wasm32-unknown-unknown` - -Additionally, these features configure Rand: - -- `small_rng` enables inclusion of the `SmallRng` PRNG -- `nightly` enables all experimental features -- `simd_support` (experimental) enables sampling of SIMD values - (uniformly random SIMD integers and floats) - -Rand supports limited functionality in `no_std` mode (enabled via -`default-features = false`). In this case, `OsRng` and `from_entropy` are -unavailable (unless `getrandom` is enabled), large parts of `seq` are -unavailable (unless `alloc` is enabled), and `thread_rng` and `random` are -unavailable. - -# License - -Rand is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/appveyor.yml b/rand/appveyor.yml deleted file mode 100644 index ef0b4bf..0000000 --- a/rand/appveyor.yml +++ /dev/null @@ -1,49 +0,0 @@ -environment: - - # At the time this was added AppVeyor was having troubles with checking - # revocation of SSL certificates of sites like static.rust-lang.org and what - # we think is crates.io. The libcurl HTTP client by default checks for - # revocation on Windows and according to a mailing list [1] this can be - # disabled. - # - # The `CARGO_HTTP_CHECK_REVOKE` env var here tells cargo to disable SSL - # revocation checking on Windows in libcurl. Note, though, that rustup, which - # we're using to download Rust here, also uses libcurl as the default backend. - # Unlike Cargo, however, rustup doesn't have a mechanism to disable revocation - # checking. To get rustup working we set `RUSTUP_USE_HYPER` which forces it to - # use the Hyper instead of libcurl backend. Both Hyper and libcurl use - # schannel on Windows but it appears that Hyper configures it slightly - # differently such that revocation checking isn't turned on by default. - # - # [1]: https://curl.haxx.se/mail/lib-2016-03/0202.html - RUSTUP_USE_HYPER: 1 - CARGO_HTTP_CHECK_REVOKE: false - - matrix: - - TARGET: x86_64-pc-windows-msvc - - TARGET: i686-pc-windows-msvc -install: - - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - - rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - rustc -V - - cargo -V - -build: false - -test_script: - - cargo test --tests --no-default-features --features alloc - # TODO: use --all-features once simd_support is sufficiently stable: - - cargo test --features=serde1,log - - cargo test --benches --features=nightly - - cargo test --examples - - cargo test --manifest-path rand_core/Cargo.toml - - cargo test --manifest-path rand_core/Cargo.toml --no-default-features --features=alloc - - cargo test --manifest-path rand_distr/Cargo.toml - - cargo test --manifest-path rand_isaac/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_pcg/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xorshift/Cargo.toml --features=serde1 - - cargo test --manifest-path rand_xoshiro/Cargo.toml - - cargo test --manifest-path rand_chacha/Cargo.toml - - cargo test --manifest-path rand_hc/Cargo.toml - - cargo test --manifest-path rand_os/Cargo.toml diff --git a/rand/benches/generators.rs b/rand/benches/generators.rs deleted file mode 100644 index 808bb67..0000000 --- a/rand/benches/generators.rs +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(test)] -#![allow(non_snake_case)] - -extern crate test; - -const RAND_BENCH_N: u64 = 1000; -const BYTES_LEN: usize = 1024; - -use std::mem::size_of; -use test::{black_box, Bencher}; - -use rand::prelude::*; -use rand::rngs::adapter::ReseedingRng; -use rand::rngs::{OsRng, mock::StepRng}; -use rand_isaac::{IsaacRng, Isaac64Rng}; -use rand_chacha::{ChaCha20Core, ChaCha8Rng, ChaCha12Rng, ChaCha20Rng}; -use rand_hc::{Hc128Rng}; -use rand_pcg::{Pcg32, Pcg64, Pcg64Mcg}; -use rand_xorshift::XorShiftRng; -use rand_xoshiro::{Xoshiro256StarStar, Xoshiro256Plus, Xoshiro128StarStar, - Xoshiro128Plus, Xoroshiro128StarStar, Xoroshiro128Plus, SplitMix64, - Xoroshiro64StarStar, Xoroshiro64Star}; - -macro_rules! gen_bytes { - ($fnn:ident, $gen:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = $gen; - let mut buf = [0u8; BYTES_LEN]; - b.iter(|| { - for _ in 0..RAND_BENCH_N { - rng.fill_bytes(&mut buf); - black_box(buf); - } - }); - b.bytes = BYTES_LEN as u64 * RAND_BENCH_N; - } - } -} - -gen_bytes!(gen_bytes_step, StepRng::new(0, 1)); -gen_bytes!(gen_bytes_xorshift, XorShiftRng::from_entropy()); -gen_bytes!(gen_bytes_xoshiro256starstar, Xoshiro256StarStar::from_entropy()); -gen_bytes!(gen_bytes_xoshiro256plus, Xoshiro256Plus::from_entropy()); -gen_bytes!(gen_bytes_xoshiro128starstar, Xoshiro128StarStar::from_entropy()); -gen_bytes!(gen_bytes_xoshiro128plus, Xoshiro128Plus::from_entropy()); -gen_bytes!(gen_bytes_xoroshiro128starstar, Xoroshiro128StarStar::from_entropy()); -gen_bytes!(gen_bytes_xoroshiro128plus, Xoroshiro128Plus::from_entropy()); -gen_bytes!(gen_bytes_xoroshiro64starstar, Xoroshiro64StarStar::from_entropy()); -gen_bytes!(gen_bytes_xoroshiro64star, Xoroshiro64Star::from_entropy()); -gen_bytes!(gen_bytes_splitmix64, SplitMix64::from_entropy()); -gen_bytes!(gen_bytes_pcg32, Pcg32::from_entropy()); -gen_bytes!(gen_bytes_pcg64, Pcg64::from_entropy()); -gen_bytes!(gen_bytes_pcg64mcg, Pcg64Mcg::from_entropy()); -gen_bytes!(gen_bytes_chacha8, ChaCha8Rng::from_entropy()); -gen_bytes!(gen_bytes_chacha12, ChaCha12Rng::from_entropy()); -gen_bytes!(gen_bytes_chacha20, ChaCha20Rng::from_entropy()); -gen_bytes!(gen_bytes_hc128, Hc128Rng::from_entropy()); -gen_bytes!(gen_bytes_isaac, IsaacRng::from_entropy()); -gen_bytes!(gen_bytes_isaac64, Isaac64Rng::from_entropy()); -gen_bytes!(gen_bytes_std, StdRng::from_entropy()); -#[cfg(feature="small_rng")] -gen_bytes!(gen_bytes_small, SmallRng::from_entropy()); -gen_bytes!(gen_bytes_os, OsRng); - -macro_rules! gen_uint { - ($fnn:ident, $ty:ty, $gen:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = $gen; - b.iter(|| { - let mut accum: $ty = 0; - for _ in 0..RAND_BENCH_N { - accum = accum.wrapping_add(rng.gen::<$ty>()); - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -gen_uint!(gen_u32_step, u32, StepRng::new(0, 1)); -gen_uint!(gen_u32_xorshift, u32, XorShiftRng::from_entropy()); -gen_uint!(gen_u32_xoshiro256starstar, u32, Xoshiro256StarStar::from_entropy()); -gen_uint!(gen_u32_xoshiro256plus, u32, Xoshiro256Plus::from_entropy()); -gen_uint!(gen_u32_xoshiro128starstar, u32, Xoshiro128StarStar::from_entropy()); -gen_uint!(gen_u32_xoshiro128plus, u32, Xoshiro128Plus::from_entropy()); -gen_uint!(gen_u32_xoroshiro128starstar, u32, Xoroshiro128StarStar::from_entropy()); -gen_uint!(gen_u32_xoroshiro128plus, u32, Xoroshiro128Plus::from_entropy()); -gen_uint!(gen_u32_xoroshiro64starstar, u32, Xoroshiro64StarStar::from_entropy()); -gen_uint!(gen_u32_xoroshiro64star, u32, Xoroshiro64Star::from_entropy()); -gen_uint!(gen_u32_splitmix64, u32, SplitMix64::from_entropy()); -gen_uint!(gen_u32_pcg32, u32, Pcg32::from_entropy()); -gen_uint!(gen_u32_pcg64, u32, Pcg64::from_entropy()); -gen_uint!(gen_u32_pcg64mcg, u32, Pcg64Mcg::from_entropy()); -gen_uint!(gen_u32_chacha8, u32, ChaCha8Rng::from_entropy()); -gen_uint!(gen_u32_chacha12, u32, ChaCha12Rng::from_entropy()); -gen_uint!(gen_u32_chacha20, u32, ChaCha20Rng::from_entropy()); -gen_uint!(gen_u32_hc128, u32, Hc128Rng::from_entropy()); -gen_uint!(gen_u32_isaac, u32, IsaacRng::from_entropy()); -gen_uint!(gen_u32_isaac64, u32, Isaac64Rng::from_entropy()); -gen_uint!(gen_u32_std, u32, StdRng::from_entropy()); -#[cfg(feature="small_rng")] -gen_uint!(gen_u32_small, u32, SmallRng::from_entropy()); -gen_uint!(gen_u32_os, u32, OsRng); - -gen_uint!(gen_u64_step, u64, StepRng::new(0, 1)); -gen_uint!(gen_u64_xorshift, u64, XorShiftRng::from_entropy()); -gen_uint!(gen_u64_xoshiro256starstar, u64, Xoshiro256StarStar::from_entropy()); -gen_uint!(gen_u64_xoshiro256plus, u64, Xoshiro256Plus::from_entropy()); -gen_uint!(gen_u64_xoshiro128starstar, u64, Xoshiro128StarStar::from_entropy()); -gen_uint!(gen_u64_xoshiro128plus, u64, Xoshiro128Plus::from_entropy()); -gen_uint!(gen_u64_xoroshiro128starstar, u64, Xoroshiro128StarStar::from_entropy()); -gen_uint!(gen_u64_xoroshiro128plus, u64, Xoroshiro128Plus::from_entropy()); -gen_uint!(gen_u64_xoroshiro64starstar, u64, Xoroshiro64StarStar::from_entropy()); -gen_uint!(gen_u64_xoroshiro64star, u64, Xoroshiro64Star::from_entropy()); -gen_uint!(gen_u64_splitmix64, u64, SplitMix64::from_entropy()); -gen_uint!(gen_u64_pcg32, u64, Pcg32::from_entropy()); -gen_uint!(gen_u64_pcg64, u64, Pcg64::from_entropy()); -gen_uint!(gen_u64_pcg64mcg, u64, Pcg64Mcg::from_entropy()); -gen_uint!(gen_u64_chacha8, u64, ChaCha8Rng::from_entropy()); -gen_uint!(gen_u64_chacha12, u64, ChaCha12Rng::from_entropy()); -gen_uint!(gen_u64_chacha20, u64, ChaCha20Rng::from_entropy()); -gen_uint!(gen_u64_hc128, u64, Hc128Rng::from_entropy()); -gen_uint!(gen_u64_isaac, u64, IsaacRng::from_entropy()); -gen_uint!(gen_u64_isaac64, u64, Isaac64Rng::from_entropy()); -gen_uint!(gen_u64_std, u64, StdRng::from_entropy()); -#[cfg(feature="small_rng")] -gen_uint!(gen_u64_small, u64, SmallRng::from_entropy()); -gen_uint!(gen_u64_os, u64, OsRng); - -macro_rules! init_gen { - ($fnn:ident, $gen:ident) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = XorShiftRng::from_entropy(); - b.iter(|| { - let r2 = $gen::from_rng(&mut rng).unwrap(); - r2 - }); - } - } -} - -init_gen!(init_xorshift, XorShiftRng); -init_gen!(init_xoshiro256starstar, Xoshiro256StarStar); -init_gen!(init_xoshiro256plus, Xoshiro256Plus); -init_gen!(init_xoshiro128starstar, Xoshiro128StarStar); -init_gen!(init_xoshiro128plus, Xoshiro128Plus); -init_gen!(init_xoroshiro128starstar, Xoroshiro128StarStar); -init_gen!(init_xoroshiro128plus, Xoroshiro128Plus); -init_gen!(init_xoroshiro64starstar, Xoroshiro64StarStar); -init_gen!(init_xoroshiro64star, Xoroshiro64Star); -init_gen!(init_splitmix64, SplitMix64); -init_gen!(init_pcg32, Pcg32); -init_gen!(init_pcg64, Pcg64); -init_gen!(init_pcg64mcg, Pcg64Mcg); -init_gen!(init_hc128, Hc128Rng); -init_gen!(init_isaac, IsaacRng); -init_gen!(init_isaac64, Isaac64Rng); -init_gen!(init_chacha, ChaCha20Rng); - -const RESEEDING_BYTES_LEN: usize = 1024 * 1024; -const RESEEDING_BENCH_N: u64 = 16; - -macro_rules! reseeding_bytes { - ($fnn:ident, $thresh:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = ReseedingRng::new(ChaCha20Core::from_entropy(), - $thresh * 1024, - OsRng); - let mut buf = [0u8; RESEEDING_BYTES_LEN]; - b.iter(|| { - for _ in 0..RESEEDING_BENCH_N { - rng.fill_bytes(&mut buf); - black_box(&buf); - } - }); - b.bytes = RESEEDING_BYTES_LEN as u64 * RESEEDING_BENCH_N; - } - } -} - -reseeding_bytes!(reseeding_chacha20_4k, 4); -reseeding_bytes!(reseeding_chacha20_16k, 16); -reseeding_bytes!(reseeding_chacha20_32k, 32); -reseeding_bytes!(reseeding_chacha20_64k, 64); -reseeding_bytes!(reseeding_chacha20_256k, 256); -reseeding_bytes!(reseeding_chacha20_1M, 1024); - - -macro_rules! threadrng_uint { - ($fnn:ident, $ty:ty) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = thread_rng(); - b.iter(|| { - let mut accum: $ty = 0; - for _ in 0..RAND_BENCH_N { - accum = accum.wrapping_add(rng.gen::<$ty>()); - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -threadrng_uint!(thread_rng_u32, u32); -threadrng_uint!(thread_rng_u64, u64); diff --git a/rand/benches/misc.rs b/rand/benches/misc.rs deleted file mode 100644 index 4098686..0000000 --- a/rand/benches/misc.rs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(test)] - -extern crate test; - -const RAND_BENCH_N: u64 = 1000; - -use test::Bencher; - -use rand::prelude::*; -use rand::distributions::{Distribution, Standard, Bernoulli}; -use rand_pcg::{Pcg32, Pcg64Mcg}; - -#[bench] -fn misc_gen_bool_const(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let mut accum = true; - for _ in 0..crate::RAND_BENCH_N { - accum ^= rng.gen_bool(0.18); - } - accum - }) -} - -#[bench] -fn misc_gen_bool_var(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let mut accum = true; - let mut p = 0.18; - for _ in 0..crate::RAND_BENCH_N { - accum ^= rng.gen_bool(p); - p += 0.0001; - } - accum - }) -} - -#[bench] -fn misc_gen_ratio_const(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let mut accum = true; - for _ in 0..crate::RAND_BENCH_N { - accum ^= rng.gen_ratio(2, 3); - } - accum - }) -} - -#[bench] -fn misc_gen_ratio_var(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let mut accum = true; - for i in 2..(crate::RAND_BENCH_N as u32 + 2) { - accum ^= rng.gen_ratio(i, i + 1); - } - accum - }) -} - -#[bench] -fn misc_bernoulli_const(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let d = rand::distributions::Bernoulli::new(0.18).unwrap(); - let mut accum = true; - for _ in 0..crate::RAND_BENCH_N { - accum ^= rng.sample(d); - } - accum - }) -} - -#[bench] -fn misc_bernoulli_var(b: &mut Bencher) { - let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let mut accum = true; - let mut p = 0.18; - for _ in 0..crate::RAND_BENCH_N { - let d = Bernoulli::new(p).unwrap(); - accum ^= rng.sample(d); - p += 0.0001; - } - accum - }) -} - -#[bench] -fn gen_1k_iter_repeat(b: &mut Bencher) { - use std::iter; - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let v: Vec = iter::repeat(()).map(|()| rng.gen()).take(128).collect(); - v - }); - b.bytes = 1024; -} - -#[bench] -fn gen_1k_sample_iter(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - let v: Vec = Standard.sample_iter(&mut rng).take(128).collect(); - v - }); - b.bytes = 1024; -} - -#[bench] -fn gen_1k_gen_array(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); - b.iter(|| { - // max supported array length is 32! - let v: [[u64; 32]; 4] = rng.gen(); - v - }); - b.bytes = 1024; -} - -#[bench] -fn gen_1k_fill(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); - let mut buf = [0u64; 128]; - b.iter(|| { - rng.fill(&mut buf[..]); - buf - }); - b.bytes = 1024; -} diff --git a/rand/benches/seq.rs b/rand/benches/seq.rs deleted file mode 100644 index 4c671b8..0000000 --- a/rand/benches/seq.rs +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(test)] -#![allow(non_snake_case)] - -extern crate test; - -use test::Bencher; - -use rand::prelude::*; -use rand::seq::*; -use std::mem::size_of; - -// We force use of 32-bit RNG since seq code is optimised for use with 32-bit -// generators on all platforms. -use rand_pcg::Pcg32 as SmallRng; - -const RAND_BENCH_N: u64 = 1000; - -#[bench] -fn seq_shuffle_100(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - let x : &mut [usize] = &mut [1; 100]; - b.iter(|| { - x.shuffle(&mut rng); - x[0] - }) -} - -#[bench] -fn seq_slice_choose_1_of_1000(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - let x : &mut [usize] = &mut [1; 1000]; - for i in 0..1000 { - x[i] = i; - } - b.iter(|| { - let mut s = 0; - for _ in 0..RAND_BENCH_N { - s += x.choose(&mut rng).unwrap(); - } - s - }); - b.bytes = size_of::() as u64 * crate::RAND_BENCH_N; -} - -macro_rules! seq_slice_choose_multiple { - ($name:ident, $amount:expr, $length:expr) => { - #[bench] - fn $name(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - let x : &[i32] = &[$amount; $length]; - let mut result = [0i32; $amount]; - b.iter(|| { - // Collect full result to prevent unwanted shortcuts getting - // first element (in case sample_indices returns an iterator). - for (slot, sample) in result.iter_mut().zip( - x.choose_multiple(&mut rng, $amount)) { - *slot = *sample; - } - result[$amount-1] - }) - } - } -} - -seq_slice_choose_multiple!(seq_slice_choose_multiple_1_of_1000, 1, 1000); -seq_slice_choose_multiple!(seq_slice_choose_multiple_950_of_1000, 950, 1000); -seq_slice_choose_multiple!(seq_slice_choose_multiple_10_of_100, 10, 100); -seq_slice_choose_multiple!(seq_slice_choose_multiple_90_of_100, 90, 100); - -#[bench] -fn seq_iter_choose_from_1000(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - let x : &mut [usize] = &mut [1; 1000]; - for i in 0..1000 { - x[i] = i; - } - b.iter(|| { - let mut s = 0; - for _ in 0..RAND_BENCH_N { - s += x.iter().choose(&mut rng).unwrap(); - } - s - }); - b.bytes = size_of::() as u64 * crate::RAND_BENCH_N; -} - -#[derive(Clone)] -struct UnhintedIterator { - iter: I, -} -impl Iterator for UnhintedIterator { - type Item = I::Item; - fn next(&mut self) -> Option { - self.iter.next() - } -} - -#[derive(Clone)] -struct WindowHintedIterator { - iter: I, - window_size: usize, -} -impl Iterator for WindowHintedIterator { - type Item = I::Item; - fn next(&mut self) -> Option { - self.iter.next() - } - fn size_hint(&self) -> (usize, Option) { - (std::cmp::min(self.iter.len(), self.window_size), None) - } -} - -#[bench] -fn seq_iter_unhinted_choose_from_1000(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - let x : &[usize] = &[1; 1000]; - b.iter(|| { - UnhintedIterator { iter: x.iter() }.choose(&mut rng).unwrap() - }) -} - -#[bench] -fn seq_iter_window_hinted_choose_from_1000(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - let x : &[usize] = &[1; 1000]; - b.iter(|| { - WindowHintedIterator { iter: x.iter(), window_size: 7 }.choose(&mut rng) - }) -} - -#[bench] -fn seq_iter_choose_multiple_10_of_100(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - let x : &[usize] = &[1; 100]; - b.iter(|| { - x.iter().cloned().choose_multiple(&mut rng, 10) - }) -} - -#[bench] -fn seq_iter_choose_multiple_fill_10_of_100(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - let x : &[usize] = &[1; 100]; - let mut buf = [0; 10]; - b.iter(|| { - x.iter().cloned().choose_multiple_fill(&mut rng, &mut buf) - }) -} - -macro_rules! sample_indices { - ($name:ident, $fn:ident, $amount:expr, $length:expr) => { - #[bench] - fn $name(b: &mut Bencher) { - let mut rng = SmallRng::from_rng(thread_rng()).unwrap(); - b.iter(|| { - index::$fn(&mut rng, $length, $amount) - }) - } - } -} - -sample_indices!(misc_sample_indices_1_of_1k, sample, 1, 1000); -sample_indices!(misc_sample_indices_10_of_1k, sample, 10, 1000); -sample_indices!(misc_sample_indices_100_of_1k, sample, 100, 1000); -sample_indices!(misc_sample_indices_100_of_1M, sample, 100, 1000_000); -sample_indices!(misc_sample_indices_100_of_1G, sample, 100, 1000_000_000); -sample_indices!(misc_sample_indices_200_of_1G, sample, 200, 1000_000_000); -sample_indices!(misc_sample_indices_400_of_1G, sample, 400, 1000_000_000); -sample_indices!(misc_sample_indices_600_of_1G, sample, 600, 1000_000_000); diff --git a/rand/benches/weighted.rs b/rand/benches/weighted.rs deleted file mode 100644 index 5ddca3f..0000000 --- a/rand/benches/weighted.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(test)] - -extern crate test; - -use test::Bencher; -use rand::Rng; -use rand::distributions::WeightedIndex; - -#[bench] -fn weighted_index_creation(b: &mut Bencher) { - let mut rng = rand::thread_rng(); - let weights = [1u32, 2, 4, 0, 5, 1, 7, 1, 2, 3, 4, 5, 6, 7]; - b.iter(|| { - let distr = WeightedIndex::new(weights.to_vec()).unwrap(); - rng.sample(distr) - }) -} - -#[bench] -fn weighted_index_modification(b: &mut Bencher) { - let mut rng = rand::thread_rng(); - let weights = [1u32, 2, 3, 0, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7]; - let mut distr = WeightedIndex::new(weights.to_vec()).unwrap(); - b.iter(|| { - distr.update_weights(&[(2, &4), (5, &1)]).unwrap(); - rng.sample(&distr) - }) -} diff --git a/rand/examples/monte-carlo.rs b/rand/examples/monte-carlo.rs deleted file mode 100644 index 39c779f..0000000 --- a/rand/examples/monte-carlo.rs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2018 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! # Monte Carlo estimation of π -//! -//! Imagine that we have a square with sides of length 2 and a unit circle -//! (radius = 1), both centered at the origin. The areas are: -//! -//! ```text -//! area of circle = πr² = π * r * r = π -//! area of square = 2² = 4 -//! ``` -//! -//! The circle is entirely within the square, so if we sample many points -//! randomly from the square, roughly π / 4 of them should be inside the circle. -//! -//! We can use the above fact to estimate the value of π: pick many points in -//! the square at random, calculate the fraction that fall within the circle, -//! and multiply this fraction by 4. - -#![cfg(feature = "std")] - -use rand::distributions::{Distribution, Uniform}; - -fn main() { - let range = Uniform::new(-1.0f64, 1.0); - let mut rng = rand::thread_rng(); - - let total = 1_000_000; - let mut in_circle = 0; - - for _ in 0..total { - let a = range.sample(&mut rng); - let b = range.sample(&mut rng); - if a*a + b*b <= 1.0 { - in_circle += 1; - } - } - - // prints something close to 3.14159... - println!("π is approximately {}", 4. * (in_circle as f64) / (total as f64)); -} diff --git a/rand/examples/monty-hall.rs b/rand/examples/monty-hall.rs deleted file mode 100644 index 9fe5839..0000000 --- a/rand/examples/monty-hall.rs +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2018 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! ## Monty Hall Problem -//! -//! This is a simulation of the [Monty Hall Problem][]: -//! -//! > Suppose you're on a game show, and you're given the choice of three doors: -//! > Behind one door is a car; behind the others, goats. You pick a door, say -//! > No. 1, and the host, who knows what's behind the doors, opens another -//! > door, say No. 3, which has a goat. He then says to you, "Do you want to -//! > pick door No. 2?" Is it to your advantage to switch your choice? -//! -//! The rather unintuitive answer is that you will have a 2/3 chance of winning -//! if you switch and a 1/3 chance of winning if you don't, so it's better to -//! switch. -//! -//! This program will simulate the game show and with large enough simulation -//! steps it will indeed confirm that it is better to switch. -//! -//! [Monty Hall Problem]: https://en.wikipedia.org/wiki/Monty_Hall_problem - -#![cfg(feature = "std")] - -use rand::distributions::{Distribution, Uniform}; -use rand::Rng; - -struct SimulationResult { - win: bool, - switch: bool, -} - -// Run a single simulation of the Monty Hall problem. -fn simulate(random_door: &Uniform, rng: &mut R) -> SimulationResult { - let car = random_door.sample(rng); - - // This is our initial choice - let mut choice = random_door.sample(rng); - - // The game host opens a door - let open = game_host_open(car, choice, rng); - - // Shall we switch? - let switch = rng.gen(); - if switch { - choice = switch_door(choice, open); - } - - SimulationResult { win: choice == car, switch } -} - -// Returns the door the game host opens given our choice and knowledge of -// where the car is. The game host will never open the door with the car. -fn game_host_open(car: u32, choice: u32, rng: &mut R) -> u32 { - use rand::seq::SliceRandom; - *free_doors(&[car, choice]).choose(rng).unwrap() -} - -// Returns the door we switch to, given our current choice and -// the open door. There will only be one valid door. -fn switch_door(choice: u32, open: u32) -> u32 { - free_doors(&[choice, open])[0] -} - -fn free_doors(blocked: &[u32]) -> Vec { - (0..3).filter(|x| !blocked.contains(x)).collect() -} - -fn main() { - // The estimation will be more accurate with more simulations - let num_simulations = 10000; - - let mut rng = rand::thread_rng(); - let random_door = Uniform::new(0u32, 3); - - let (mut switch_wins, mut switch_losses) = (0, 0); - let (mut keep_wins, mut keep_losses) = (0, 0); - - println!("Running {} simulations...", num_simulations); - for _ in 0..num_simulations { - let result = simulate(&random_door, &mut rng); - - match (result.win, result.switch) { - (true, true) => switch_wins += 1, - (true, false) => keep_wins += 1, - (false, true) => switch_losses += 1, - (false, false) => keep_losses += 1, - } - } - - let total_switches = switch_wins + switch_losses; - let total_keeps = keep_wins + keep_losses; - - println!("Switched door {} times with {} wins and {} losses", - total_switches, switch_wins, switch_losses); - - println!("Kept our choice {} times with {} wins and {} losses", - total_keeps, keep_wins, keep_losses); - - // With a large number of simulations, the values should converge to - // 0.667 and 0.333 respectively. - println!("Estimated chance to win if we switch: {}", - switch_wins as f32 / total_switches as f32); - println!("Estimated chance to win if we don't: {}", - keep_wins as f32 / total_keeps as f32); -} diff --git a/rand/rand_chacha/CHANGELOG.md b/rand/rand_chacha/CHANGELOG.md deleted file mode 100644 index d242f97..0000000 --- a/rand/rand_chacha/CHANGELOG.md +++ /dev/null @@ -1,18 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.2.1] - 2019-07-22 -- Force enable the `simd` feature of `c2-chacha` (#845) - -## [0.2.0] - 2019-06-06 -- Rewrite based on the much faster `c2-chacha` crate (#789) - -## [0.1.1] - 2019-01-04 -- Disable `i128` and `u128` if the `target_os` is `emscripten` (#671: work-around Emscripten limitation) -- Update readme and doc links - -## [0.1.0] - 2018-10-17 -- Pulled out of the Rand crate diff --git a/rand/rand_chacha/COPYRIGHT b/rand/rand_chacha/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_chacha/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_chacha/Cargo.toml b/rand/rand_chacha/Cargo.toml deleted file mode 100644 index 6a47b86..0000000 --- a/rand/rand_chacha/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "rand_chacha" -version = "0.2.1" -authors = ["The Rand Project Developers", "The Rust Project Developers", "The CryptoCorrosion Contributors"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_chacha/" -homepage = "https://crates.io/crates/rand_chacha" -description = """ -ChaCha random number generator -""" -keywords = ["random", "rng", "chacha"] -categories = ["algorithms", "no-std"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[dependencies] -rand_core = { path = "../rand_core", version = "0.5" } -c2-chacha = { version = "0.2.2", default-features = false, features = ["simd"] } - -[features] -default = ["std", "simd"] -std = ["c2-chacha/std"] -simd = [] # deprecated diff --git a/rand/rand_chacha/LICENSE-APACHE b/rand/rand_chacha/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_chacha/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_chacha/LICENSE-MIT b/rand/rand_chacha/LICENSE-MIT deleted file mode 100644 index d93b5ba..0000000 --- a/rand/rand_chacha/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2018 Developers of the Rand project -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_chacha/README.md b/rand/rand_chacha/README.md deleted file mode 100644 index 69a0ce7..0000000 --- a/rand/rand_chacha/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# rand_chacha - -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_chacha.svg)](https://crates.io/crates/rand_chacha) -[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_chacha) -[![API](https://docs.rs/rand_chacha/badge.svg)](https://docs.rs/rand_chacha) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -A cryptographically secure random number generator that uses the ChaCha -algorithm. - -ChaCha is a stream cipher designed by Daniel J. Bernstein[^1], that we use -as an RNG. It is an improved variant of the Salsa20 cipher family, which was -selected as one of the "stream ciphers suitable for widespread adoption" by -eSTREAM[^2]. - -The RNGs provided by this crate are implemented via the fast stream ciphers of -the [`c2-chacha`](https://crates.io/crates/c2-chacha) crate. - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_chacha) -- [API documentation (docs.rs)](https://docs.rs/rand_chacha) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_chacha/CHANGELOG.md) - -[rand]: https://crates.io/crates/rand -[^1]: D. J. Bernstein, [*ChaCha, a variant of Salsa20*]( - https://cr.yp.to/chacha.html) - -[^2]: [eSTREAM: the ECRYPT Stream Cipher Project]( - http://www.ecrypt.eu.org/stream/) - - -## Crate Features - -`rand_chacha` is `no_std` compatible when disabling default features; the `std` -feature can be explicitly required to re-enable `std` support. Using `std` -allows detection of CPU features and thus better optimisation. - - -# License - -`rand_chacha` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_chacha/src/chacha.rs b/rand/rand_chacha/src/chacha.rs deleted file mode 100644 index b1b89e0..0000000 --- a/rand/rand_chacha/src/chacha.rs +++ /dev/null @@ -1,452 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The ChaCha random number generator. - -#[cfg(feature = "std")] -use std as core; -#[cfg(not(feature = "std"))] -use core; - -use c2_chacha::guts::ChaCha; -use self::core::fmt; -use rand_core::block::{BlockRng, BlockRngCore}; -use rand_core::{CryptoRng, Error, RngCore, SeedableRng}; - -const STREAM_PARAM_NONCE: u32 = 1; -const STREAM_PARAM_BLOCK: u32 = 0; - -pub struct Array64([T; 64]); -impl Default for Array64 where T: Default { - fn default() -> Self { - Self([T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), - T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), - T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), - T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), - T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), - T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), - T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), - T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default()]) - } -} -impl AsRef<[T]> for Array64 { - fn as_ref(&self) -> &[T] { - &self.0 - } -} -impl AsMut<[T]> for Array64 { - fn as_mut(&mut self) -> &mut [T] { - &mut self.0 - } -} -impl Clone for Array64 where T: Copy + Default { - fn clone(&self) -> Self { - let mut new = Self::default(); - new.0.copy_from_slice(&self.0); - new - } -} -impl fmt::Debug for Array64 { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Array64 {{}}") - } -} - -macro_rules! chacha_impl { - ($ChaChaXCore:ident, $ChaChaXRng:ident, $rounds:expr, $doc:expr) => { - #[doc=$doc] - #[derive(Clone)] - pub struct $ChaChaXCore { - state: ChaCha, - } - - // Custom Debug implementation that does not expose the internal state - impl fmt::Debug for $ChaChaXCore { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "ChaChaXCore {{}}") - } - } - - impl BlockRngCore for $ChaChaXCore { - type Item = u32; - type Results = Array64; - #[inline] - fn generate(&mut self, r: &mut Self::Results) { - // Fill slice of words by writing to equivalent slice of bytes, then fixing endianness. - self.state.refill4($rounds, unsafe { - &mut *(&mut *r as *mut Array64 as *mut [u8; 256]) - }); - for x in r.as_mut() { - *x = x.to_le(); - } - } - } - - impl SeedableRng for $ChaChaXCore { - type Seed = [u8; 32]; - #[inline] - fn from_seed(seed: Self::Seed) -> Self { - $ChaChaXCore { state: ChaCha::new(&seed, &[0u8; 8]) } - } - } - - /// A cryptographically secure random number generator that uses the ChaCha algorithm. - /// - /// ChaCha is a stream cipher designed by Daniel J. Bernstein[^1], that we use as an RNG. It is - /// an improved variant of the Salsa20 cipher family, which was selected as one of the "stream - /// ciphers suitable for widespread adoption" by eSTREAM[^2]. - /// - /// ChaCha uses add-rotate-xor (ARX) operations as its basis. These are safe against timing - /// attacks, although that is mostly a concern for ciphers and not for RNGs. We provide a SIMD - /// implementation to support high throughput on a variety of common hardware platforms. - /// - /// With the ChaCha algorithm it is possible to choose the number of rounds the core algorithm - /// should run. The number of rounds is a tradeoff between performance and security, where 8 - /// rounds is the minimum potentially secure configuration, and 20 rounds is widely used as a - /// conservative choice. - /// - /// We use a 64-bit counter and 64-bit stream identifier as in Bernstein's implementation[^1] - /// except that we use a stream identifier in place of a nonce. A 64-bit counter over 64-byte - /// (16 word) blocks allows 1 ZiB of output before cycling, and the stream identifier allows - /// 264 unique streams of output per seed. Both counter and stream are initialized - /// to zero but may be set via the `set_word_pos` and `set_stream` methods. - /// - /// The word layout is: - /// - /// ```text - /// constant constant constant constant - /// seed seed seed seed - /// seed seed seed seed - /// counter counter stream_id stream_id - /// ``` - /// - /// This implementation uses an output buffer of sixteen `u32` words, and uses - /// [`BlockRng`] to implement the [`RngCore`] methods. - /// - /// [^1]: D. J. Bernstein, [*ChaCha, a variant of Salsa20*]( - /// https://cr.yp.to/chacha.html) - /// - /// [^2]: [eSTREAM: the ECRYPT Stream Cipher Project]( - /// http://www.ecrypt.eu.org/stream/) - #[derive(Clone, Debug)] - pub struct $ChaChaXRng { - rng: BlockRng<$ChaChaXCore>, - } - - impl SeedableRng for $ChaChaXRng { - type Seed = [u8; 32]; - #[inline] - fn from_seed(seed: Self::Seed) -> Self { - let core = $ChaChaXCore::from_seed(seed); - Self { - rng: BlockRng::new(core), - } - } - } - - impl RngCore for $ChaChaXRng { - #[inline] - fn next_u32(&mut self) -> u32 { - self.rng.next_u32() - } - #[inline] - fn next_u64(&mut self) -> u64 { - self.rng.next_u64() - } - #[inline] - fn fill_bytes(&mut self, bytes: &mut [u8]) { - self.rng.fill_bytes(bytes) - } - #[inline] - fn try_fill_bytes(&mut self, bytes: &mut [u8]) -> Result<(), Error> { - self.rng.try_fill_bytes(bytes) - } - } - - impl $ChaChaXRng { - // The buffer is a 4-block window, i.e. it is always at a block-aligned position in the - // stream but if the stream has been seeked it may not be self-aligned. - - /// Get the offset from the start of the stream, in 32-bit words. - /// - /// Since the generated blocks are 16 words (24) long and the - /// counter is 64-bits, the offset is a 68-bit number. Sub-word offsets are - /// not supported, hence the result can simply be multiplied by 4 to get a - /// byte-offset. - #[inline] - pub fn get_word_pos(&self) -> u128 { - let mut block = u128::from(self.rng.core.state.get_stream_param(STREAM_PARAM_BLOCK)); - // counter is incremented *after* filling buffer - block -= 4; - (block << 4) + self.rng.index() as u128 - } - - /// Set the offset from the start of the stream, in 32-bit words. - /// - /// As with `get_word_pos`, we use a 68-bit number. Since the generator - /// simply cycles at the end of its period (1 ZiB), we ignore the upper - /// 60 bits. - #[inline] - pub fn set_word_pos(&mut self, word_offset: u128) { - let block = (word_offset >> 4) as u64; - self.rng - .core - .state - .set_stream_param(STREAM_PARAM_BLOCK, block); - self.rng.generate_and_set((word_offset & 15) as usize); - } - - /// Set the stream number. - /// - /// This is initialized to zero; 264 unique streams of output - /// are available per seed/key. - /// - /// Note that in order to reproduce ChaCha output with a specific 64-bit - /// nonce, one can convert that nonce to a `u64` in little-endian fashion - /// and pass to this function. In theory a 96-bit nonce can be used by - /// passing the last 64-bits to this function and using the first 32-bits as - /// the most significant half of the 64-bit counter (which may be set - /// indirectly via `set_word_pos`), but this is not directly supported. - #[inline] - pub fn set_stream(&mut self, stream: u64) { - self.rng - .core - .state - .set_stream_param(STREAM_PARAM_NONCE, stream); - if self.rng.index() != 64 { - let wp = self.get_word_pos(); - self.set_word_pos(wp); - } - } - } - - impl CryptoRng for $ChaChaXRng {} - - impl From<$ChaChaXCore> for $ChaChaXRng { - fn from(core: $ChaChaXCore) -> Self { - $ChaChaXRng { - rng: BlockRng::new(core), - } - } - } - } -} - -chacha_impl!(ChaCha20Core, ChaCha20Rng, 10, "ChaCha with 20 rounds"); -chacha_impl!(ChaCha12Core, ChaCha12Rng, 6, "ChaCha with 12 rounds"); -chacha_impl!(ChaCha8Core, ChaCha8Rng, 4, "ChaCha with 8 rounds"); - -#[cfg(test)] -mod test { - use rand_core::{RngCore, SeedableRng}; - - type ChaChaRng = super::ChaCha20Rng; - - #[test] - fn test_chacha_construction() { - let seed = [ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, - ]; - let mut rng1 = ChaChaRng::from_seed(seed); - assert_eq!(rng1.next_u32(), 137206642); - - let mut rng2 = ChaChaRng::from_rng(rng1).unwrap(); - assert_eq!(rng2.next_u32(), 1325750369); - } - - #[test] - fn test_chacha_true_values_a() { - // Test vectors 1 and 2 from - // https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04 - let seed = [0u8; 32]; - let mut rng = ChaChaRng::from_seed(seed); - - let mut results = [0u32; 16]; - for i in results.iter_mut() { - *i = rng.next_u32(); - } - let expected = [ - 0xade0b876, 0x903df1a0, 0xe56a5d40, 0x28bd8653, 0xb819d2bd, 0x1aed8da0, 0xccef36a8, - 0xc70d778b, 0x7c5941da, 0x8d485751, 0x3fe02477, 0x374ad8b8, 0xf4b8436a, 0x1ca11815, - 0x69b687c3, 0x8665eeb2, - ]; - assert_eq!(results, expected); - - for i in results.iter_mut() { - *i = rng.next_u32(); - } - let expected = [ - 0xbee7079f, 0x7a385155, 0x7c97ba98, 0x0d082d73, 0xa0290fcb, 0x6965e348, 0x3e53c612, - 0xed7aee32, 0x7621b729, 0x434ee69c, 0xb03371d5, 0xd539d874, 0x281fed31, 0x45fb0a51, - 0x1f0ae1ac, 0x6f4d794b, - ]; - assert_eq!(results, expected); - } - - #[test] - fn test_chacha_true_values_b() { - // Test vector 3 from - // https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04 - let seed = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, - ]; - let mut rng = ChaChaRng::from_seed(seed); - - // Skip block 0 - for _ in 0..16 { - rng.next_u32(); - } - - let mut results = [0u32; 16]; - for i in results.iter_mut() { - *i = rng.next_u32(); - } - let expected = [ - 0x2452eb3a, 0x9249f8ec, 0x8d829d9b, 0xddd4ceb1, 0xe8252083, 0x60818b01, 0xf38422b8, - 0x5aaa49c9, 0xbb00ca8e, 0xda3ba7b4, 0xc4b592d1, 0xfdf2732f, 0x4436274e, 0x2561b3c8, - 0xebdd4aa6, 0xa0136c00, - ]; - assert_eq!(results, expected); - } - - #[test] - fn test_chacha_true_values_c() { - // Test vector 4 from - // https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04 - let seed = [ - 0, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, - ]; - let expected = [ - 0xfb4dd572, 0x4bc42ef1, 0xdf922636, 0x327f1394, 0xa78dea8f, 0x5e269039, 0xa1bebbc1, - 0xcaf09aae, 0xa25ab213, 0x48a6b46c, 0x1b9d9bcb, 0x092c5be6, 0x546ca624, 0x1bec45d5, - 0x87f47473, 0x96f0992e, - ]; - let expected_end = 3 * 16; - let mut results = [0u32; 16]; - - // Test block 2 by skipping block 0 and 1 - let mut rng1 = ChaChaRng::from_seed(seed); - for _ in 0..32 { - rng1.next_u32(); - } - for i in results.iter_mut() { - *i = rng1.next_u32(); - } - assert_eq!(results, expected); - assert_eq!(rng1.get_word_pos(), expected_end); - - // Test block 2 by using `set_word_pos` - let mut rng2 = ChaChaRng::from_seed(seed); - rng2.set_word_pos(2 * 16); - for i in results.iter_mut() { - *i = rng2.next_u32(); - } - assert_eq!(results, expected); - assert_eq!(rng2.get_word_pos(), expected_end); - - // Test skipping behaviour with other types - let mut buf = [0u8; 32]; - rng2.fill_bytes(&mut buf[..]); - assert_eq!(rng2.get_word_pos(), expected_end + 8); - rng2.fill_bytes(&mut buf[0..25]); - assert_eq!(rng2.get_word_pos(), expected_end + 15); - rng2.next_u64(); - assert_eq!(rng2.get_word_pos(), expected_end + 17); - rng2.next_u32(); - rng2.next_u64(); - assert_eq!(rng2.get_word_pos(), expected_end + 20); - rng2.fill_bytes(&mut buf[0..1]); - assert_eq!(rng2.get_word_pos(), expected_end + 21); - } - - #[test] - fn test_chacha_multiple_blocks() { - let seed = [ - 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7, - 0, 0, 0, - ]; - let mut rng = ChaChaRng::from_seed(seed); - - // Store the 17*i-th 32-bit word, - // i.e., the i-th word of the i-th 16-word block - let mut results = [0u32; 16]; - for i in results.iter_mut() { - *i = rng.next_u32(); - for _ in 0..16 { - rng.next_u32(); - } - } - let expected = [ - 0xf225c81a, 0x6ab1be57, 0x04d42951, 0x70858036, 0x49884684, 0x64efec72, 0x4be2d186, - 0x3615b384, 0x11cfa18e, 0xd3c50049, 0x75c775f6, 0x434c6530, 0x2c5bad8f, 0x898881dc, - 0x5f1c86d9, 0xc1f8e7f4, - ]; - assert_eq!(results, expected); - } - - #[test] - fn test_chacha_true_bytes() { - let seed = [0u8; 32]; - let mut rng = ChaChaRng::from_seed(seed); - let mut results = [0u8; 32]; - rng.fill_bytes(&mut results); - let expected = [ - 118, 184, 224, 173, 160, 241, 61, 144, 64, 93, 106, 229, 83, 134, 189, 40, 189, 210, - 25, 184, 160, 141, 237, 26, 168, 54, 239, 204, 139, 119, 13, 199, - ]; - assert_eq!(results, expected); - } - - #[test] - fn test_chacha_nonce() { - // Test vector 5 from - // https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04 - // Although we do not support setting a nonce, we try it here anyway so - // we can use this test vector. - let seed = [0u8; 32]; - let mut rng = ChaChaRng::from_seed(seed); - // 96-bit nonce in LE order is: 0,0,0,0, 0,0,0,0, 0,0,0,2 - rng.set_stream(2u64 << (24 + 32)); - - let mut results = [0u32; 16]; - for i in results.iter_mut() { - *i = rng.next_u32(); - } - let expected = [ - 0x374dc6c2, 0x3736d58c, 0xb904e24a, 0xcd3f93ef, 0x88228b1a, 0x96a4dfb3, 0x5b76ab72, - 0xc727ee54, 0x0e0e978a, 0xf3145c95, 0x1b748ea8, 0xf786c297, 0x99c28f5f, 0x628314e8, - 0x398a19fa, 0x6ded1b53, - ]; - assert_eq!(results, expected); - } - - #[test] - fn test_chacha_clone_streams() { - let seed = [ - 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7, - 0, 0, 0, - ]; - let mut rng = ChaChaRng::from_seed(seed); - let mut clone = rng.clone(); - for _ in 0..16 { - assert_eq!(rng.next_u64(), clone.next_u64()); - } - - rng.set_stream(51); - for _ in 0..7 { - assert!(rng.next_u32() != clone.next_u32()); - } - clone.set_stream(51); // switch part way through block - for _ in 7..16 { - assert_eq!(rng.next_u32(), clone.next_u32()); - } - } -} diff --git a/rand/rand_chacha/src/lib.rs b/rand/rand_chacha/src/lib.rs deleted file mode 100644 index e374bdd..0000000 --- a/rand/rand_chacha/src/lib.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The ChaCha random number generator. - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] -#![doc(test(attr(allow(unused_variables), deny(warnings))))] - -#![cfg_attr(not(feature = "std"), no_std)] - -pub use rand_core; - -mod chacha; - -pub use crate::chacha::{ChaCha12Core, ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Core, ChaCha8Rng}; - -/// ChaCha with 20 rounds -pub type ChaChaRng = ChaCha20Rng; -/// ChaCha with 20 rounds, low-level interface -pub type ChaChaCore = ChaCha20Core; diff --git a/rand/rand_core/CHANGELOG.md b/rand/rand_core/CHANGELOG.md deleted file mode 100644 index dfdd692..0000000 --- a/rand/rand_core/CHANGELOG.md +++ /dev/null @@ -1,58 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.5.1] - 2019-08-28 -- `OsRng` added to `rand_core` (#863) -- `Error::INTERNAL_START` and `Error::CUSTOM_START` constants (#864) -- `Error::raw_os_error` method (#864) -- `Debug` and `Display` formatting for `getrandom` error codes without `std` (#864) -### Changed -- `alloc` feature in `no_std` is available since Rust 1.36 (#856) -- Added `#[inline]` to `Error` conversion methods (#864) - -## [0.5.0] - 2019-06-06 -### Changed -- Enable testing with Miri and fix incorrect pointer usages (#779, #780, #781, #783, #784) -- Rewrite `Error` type and adjust API (#800) -- Adjust usage of `#[inline]` for `BlockRng` and `BlockRng64` - -## [0.4.0] - 2019-01-24 -### Changed -- Disable the `std` feature by default (#702) - -## [0.3.0] - 2018-09-24 -### Added -- Add `SeedableRng::seed_from_u64` for convenient seeding. (#537) - -## [0.2.1] - 2018-06-08 -### Added -- References to a `CryptoRng` now also implement `CryptoRng`. (#470) - -## [0.2.0] - 2018-05-21 -### Changed -- Enable the `std` feature by default. (#409) -- Remove `BlockRng{64}::inner` and `BlockRng::inner_mut`; instead making `core` public -- Change `BlockRngCore::Results` bound to also require `AsMut<[Self::Item]>`. (#419) -### Added -- Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419) -- Implement `std::io::Read` for RngCore. (#434) - -## [0.1.0] - 2018-04-17 -(Split out of the Rand crate, changes here are relative to rand 0.4.2.) -### Added -- `RngCore` and `SeedableRng` are now part of `rand_core`. (#288) -- Add modules to help implementing RNGs `impl` and `le`. (#209, #228) -- Add `Error` and `ErrorKind`. (#225) -- Add `CryptoRng` marker trait. (#273) -- Add `BlockRngCore` trait. (#281) -- Add `BlockRng` and `BlockRng64` wrappers to help implementations. (#281, #325) -- Add `RngCore::try_fill_bytes`. (#225) -### Changed -- Revise the `SeedableRng` trait. (#233) -- Remove default implementations for `RngCore::next_u64` and `RngCore::fill_bytes`. (#288) - -## [0.0.1] - 2017-09-14 (yanked) -Experimental version as part of the rand crate refactor. diff --git a/rand/rand_core/COPYRIGHT b/rand/rand_core/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_core/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_core/Cargo.toml b/rand/rand_core/Cargo.toml deleted file mode 100644 index e52af5f..0000000 --- a/rand/rand_core/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "rand_core" -version = "0.5.1" -authors = ["The Rand Project Developers", "The Rust Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_core/" -homepage = "https://crates.io/crates/rand_core" -description = """ -Core random number generator traits and tools for implementation. -""" -keywords = ["random", "rng"] -categories = ["algorithms", "no-std"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[features] -std = ["alloc", "getrandom", "getrandom/std"] # use std library; should be default but for above bug -alloc = [] # enables Vec and Box support without std -serde1 = ["serde"] # enables serde for BlockRng wrapper - -[dependencies] -serde = { version = "1", features = ["derive"], optional = true } -getrandom = { version = "0.1", optional = true } diff --git a/rand/rand_core/LICENSE-APACHE b/rand/rand_core/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_core/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_core/LICENSE-MIT b/rand/rand_core/LICENSE-MIT deleted file mode 100644 index d93b5ba..0000000 --- a/rand/rand_core/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2018 Developers of the Rand project -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_core/README.md b/rand/rand_core/README.md deleted file mode 100644 index 467e66f..0000000 --- a/rand/rand_core/README.md +++ /dev/null @@ -1,82 +0,0 @@ -# rand_core - -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_core.svg)](https://crates.io/crates/rand_core) -[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_core) -[![API](https://docs.rs/rand_core/badge.svg)](https://docs.rs/rand_core) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -Core traits and error types of the [rand] library, plus tools for implementing -RNGs. - -This crate is intended for use when implementing the core trait, `RngCore`; it -defines the core traits to be implemented as well as several small functions to -aid in their implementation and types required for error handling. - -The main [rand] crate re-exports most items defined in this crate, along with -tools to convert the integer samples generated by `RngCore` to many different -applications (including sampling from restricted ranges, conversion to floating -point, list permutations and secure initialisation of RNGs). Most users should -prefer to use the main [rand] crate. - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_core) -- [API documentation (docs.rs)](https://docs.rs/rand_core) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_core/CHANGELOG.md) - -[rand]: https://crates.io/crates/rand - - -## Functionality - -The `rand_core` crate provides: - -- base random number generator traits -- error-reporting types -- functionality to aid implementation of RNGs - -The traits and error types are also available via `rand`. - -## Versions - -The current version is: -``` -rand_core = "0.5.0" -``` - -Rand libs have inter-dependencies and make use of the -[semver trick](https://github.com/dtolnay/semver-trick/) in order to make traits -compatible across crate versions. (This is especially important for `RngCore` -and `SeedableRng`.) A few crate releases are thus compatibility shims, -depending on the *next* lib version (e.g. `rand_core` versions `0.2.2` and -`0.3.1`). This means, for example, that `rand_core_0_4_0::SeedableRng` and -`rand_core_0_3_0::SeedableRng` are distinct, incompatible traits, which can -cause build errors. Usually, running `cargo update` is enough to fix any issues. - -## Crate Features - -`rand_core` supports `no_std` and `alloc`-only configurations, as well as full -`std` functionality. The differences between `no_std` and full `std` are small, -comprising `RngCore` support for `Box` types where `R: RngCore`, -`std::io::Read` support for types supporting `RngCore`, and -extensions to the `Error` type's functionality. - -The `std` feature is *not enabled by default*. This is primarily to avoid build -problems where one crate implicitly requires `rand_core` with `std` support and -another crate requires `rand` *without* `std` support. However, the `rand` crate -continues to enable `std` support by default, both for itself and `rand_core`. - -The `serde1` feature can be used to derive `Serialize` and `Deserialize` for RNG -implementations that use the `BlockRng` or `BlockRng64` wrappers. - - -# License - -`rand_core` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_core/src/block.rs b/rand/rand_core/src/block.rs deleted file mode 100644 index 0ab7458..0000000 --- a/rand/rand_core/src/block.rs +++ /dev/null @@ -1,437 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The `BlockRngCore` trait and implementation helpers -//! -//! The [`BlockRngCore`] trait exists to assist in the implementation of RNGs -//! which generate a block of data in a cache instead of returning generated -//! values directly. -//! -//! Usage of this trait is optional, but provides two advantages: -//! implementations only need to concern themselves with generation of the -//! block, not the various [`RngCore`] methods (especially [`fill_bytes`], where -//! the optimal implementations are not trivial), and this allows -//! `ReseedingRng` (see [`rand`](https://docs.rs/rand) crate) perform periodic -//! reseeding with very low overhead. -//! -//! # Example -//! -//! ```norun -//! use rand_core::block::{BlockRngCore, BlockRng}; -//! -//! struct MyRngCore; -//! -//! impl BlockRngCore for MyRngCore { -//! type Results = [u32; 16]; -//! -//! fn generate(&mut self, results: &mut Self::Results) { -//! unimplemented!() -//! } -//! } -//! -//! impl SeedableRng for MyRngCore { -//! type Seed = unimplemented!(); -//! fn from_seed(seed: Self::Seed) -> Self { -//! unimplemented!() -//! } -//! } -//! -//! // optionally, also implement CryptoRng for MyRngCore -//! -//! // Final RNG. -//! type MyRng = BlockRng; -//! ``` -//! -//! [`BlockRngCore`]: crate::block::BlockRngCore -//! [`fill_bytes`]: RngCore::fill_bytes - -use core::convert::AsRef; -use core::{fmt, ptr}; -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use crate::{RngCore, CryptoRng, SeedableRng, Error}; -use crate::impls::{fill_via_u32_chunks, fill_via_u64_chunks}; - -/// A trait for RNGs which do not generate random numbers individually, but in -/// blocks (typically `[u32; N]`). This technique is commonly used by -/// cryptographic RNGs to improve performance. -/// -/// See the [module][crate::block] documentation for details. -pub trait BlockRngCore { - /// Results element type, e.g. `u32`. - type Item; - - /// Results type. This is the 'block' an RNG implementing `BlockRngCore` - /// generates, which will usually be an array like `[u32; 16]`. - type Results: AsRef<[Self::Item]> + AsMut<[Self::Item]> + Default; - - /// Generate a new block of results. - fn generate(&mut self, results: &mut Self::Results); -} - - -/// A wrapper type implementing [`RngCore`] for some type implementing -/// [`BlockRngCore`] with `u32` array buffer; i.e. this can be used to implement -/// a full RNG from just a `generate` function. -/// -/// The `core` field may be accessed directly but the results buffer may not. -/// PRNG implementations can simply use a type alias -/// (`pub type MyRng = BlockRng;`) but might prefer to use a -/// wrapper type (`pub struct MyRng(BlockRng);`); the latter must -/// re-implement `RngCore` but hides the implementation details and allows -/// extra functionality to be defined on the RNG -/// (e.g. `impl MyRng { fn set_stream(...){...} }`). -/// -/// `BlockRng` has heavily optimized implementations of the [`RngCore`] methods -/// reading values from the results buffer, as well as -/// calling [`BlockRngCore::generate`] directly on the output array when -/// [`fill_bytes`] / [`try_fill_bytes`] is called on a large array. These methods -/// also handle the bookkeeping of when to generate a new batch of values. -/// -/// No whole generated `u32` values are thown away and all values are consumed -/// in-order. [`next_u32`] simply takes the next available `u32` value. -/// [`next_u64`] is implemented by combining two `u32` values, least -/// significant first. [`fill_bytes`] and [`try_fill_bytes`] consume a whole -/// number of `u32` values, converting each `u32` to a byte slice in -/// little-endian order. If the requested byte length is not a multiple of 4, -/// some bytes will be discarded. -/// -/// See also [`BlockRng64`] which uses `u64` array buffers. Currently there is -/// no direct support for other buffer types. -/// -/// For easy initialization `BlockRng` also implements [`SeedableRng`]. -/// -/// [`next_u32`]: RngCore::next_u32 -/// [`next_u64`]: RngCore::next_u64 -/// [`fill_bytes`]: RngCore::fill_bytes -/// [`try_fill_bytes`]: RngCore::try_fill_bytes -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct BlockRng { - results: R::Results, - index: usize, - /// The *core* part of the RNG, implementing the `generate` function. - pub core: R, -} - -// Custom Debug implementation that does not expose the contents of `results`. -impl fmt::Debug for BlockRng { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("BlockRng") - .field("core", &self.core) - .field("result_len", &self.results.as_ref().len()) - .field("index", &self.index) - .finish() - } -} - -impl BlockRng { - /// Create a new `BlockRng` from an existing RNG implementing - /// `BlockRngCore`. Results will be generated on first use. - #[inline] - pub fn new(core: R) -> BlockRng{ - let results_empty = R::Results::default(); - BlockRng { - core, - index: results_empty.as_ref().len(), - results: results_empty, - } - } - - /// Get the index into the result buffer. - /// - /// If this is equal to or larger than the size of the result buffer then - /// the buffer is "empty" and `generate()` must be called to produce new - /// results. - #[inline(always)] - pub fn index(&self) -> usize { - self.index - } - - /// Reset the number of available results. - /// This will force a new set of results to be generated on next use. - #[inline] - pub fn reset(&mut self) { - self.index = self.results.as_ref().len(); - } - - /// Generate a new set of results immediately, setting the index to the - /// given value. - #[inline] - pub fn generate_and_set(&mut self, index: usize) { - assert!(index < self.results.as_ref().len()); - self.core.generate(&mut self.results); - self.index = index; - } -} - -impl> RngCore for BlockRng -where ::Results: AsRef<[u32]> + AsMut<[u32]> -{ - #[inline] - fn next_u32(&mut self) -> u32 { - if self.index >= self.results.as_ref().len() { - self.generate_and_set(0); - } - - let value = self.results.as_ref()[self.index]; - self.index += 1; - value - } - - #[inline] - fn next_u64(&mut self) -> u64 { - let read_u64 = |results: &[u32], index| { - if cfg!(any(target_endian = "little")) { - // requires little-endian CPU - #[allow(clippy::cast_ptr_alignment)] // false positive - let ptr: *const u64 = results[index..=index+1].as_ptr() as *const u64; - unsafe { ptr::read_unaligned(ptr) } - } else { - let x = u64::from(results[index]); - let y = u64::from(results[index + 1]); - (y << 32) | x - } - }; - - let len = self.results.as_ref().len(); - - let index = self.index; - if index < len-1 { - self.index += 2; - // Read an u64 from the current index - read_u64(self.results.as_ref(), index) - } else if index >= len { - self.generate_and_set(2); - read_u64(self.results.as_ref(), 0) - } else { - let x = u64::from(self.results.as_ref()[len-1]); - self.generate_and_set(1); - let y = u64::from(self.results.as_ref()[0]); - (y << 32) | x - } - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - let mut read_len = 0; - while read_len < dest.len() { - if self.index >= self.results.as_ref().len() { - self.generate_and_set(0); - } - let (consumed_u32, filled_u8) = - fill_via_u32_chunks(&self.results.as_ref()[self.index..], - &mut dest[read_len..]); - - self.index += consumed_u32; - read_len += filled_u8; - } - } - - #[inline(always)] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for BlockRng { - type Seed = R::Seed; - - #[inline(always)] - fn from_seed(seed: Self::Seed) -> Self { - Self::new(R::from_seed(seed)) - } - - #[inline(always)] - fn seed_from_u64(seed: u64) -> Self { - Self::new(R::seed_from_u64(seed)) - } - - #[inline(always)] - fn from_rng(rng: S) -> Result { - Ok(Self::new(R::from_rng(rng)?)) - } -} - - - -/// A wrapper type implementing [`RngCore`] for some type implementing -/// [`BlockRngCore`] with `u64` array buffer; i.e. this can be used to implement -/// a full RNG from just a `generate` function. -/// -/// This is similar to [`BlockRng`], but specialized for algorithms that operate -/// on `u64` values. -/// -/// No whole generated `u64` values are thrown away and all values are consumed -/// in-order. [`next_u64`] simply takes the next available `u64` value. -/// [`next_u32`] is however a bit special: half of a `u64` is consumed, leaving -/// the other half in the buffer. If the next function called is [`next_u32`] -/// then the other half is then consumed, however both [`next_u64`] and -/// [`fill_bytes`] discard the rest of any half-consumed `u64`s when called. -/// -/// [`fill_bytes`] and [`try_fill_bytes`] consume a whole number of `u64` -/// values. If the requested length is not a multiple of 8, some bytes will be -/// discarded. -/// -/// [`next_u32`]: RngCore::next_u32 -/// [`next_u64`]: RngCore::next_u64 -/// [`fill_bytes`]: RngCore::fill_bytes -/// [`try_fill_bytes`]: RngCore::try_fill_bytes -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct BlockRng64 { - results: R::Results, - index: usize, - half_used: bool, // true if only half of the previous result is used - /// The *core* part of the RNG, implementing the `generate` function. - pub core: R, -} - -// Custom Debug implementation that does not expose the contents of `results`. -impl fmt::Debug for BlockRng64 { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("BlockRng64") - .field("core", &self.core) - .field("result_len", &self.results.as_ref().len()) - .field("index", &self.index) - .field("half_used", &self.half_used) - .finish() - } -} - -impl BlockRng64 { - /// Create a new `BlockRng` from an existing RNG implementing - /// `BlockRngCore`. Results will be generated on first use. - #[inline] - pub fn new(core: R) -> BlockRng64{ - let results_empty = R::Results::default(); - BlockRng64 { - core, - index: results_empty.as_ref().len(), - half_used: false, - results: results_empty, - } - } - - /// Get the index into the result buffer. - /// - /// If this is equal to or larger than the size of the result buffer then - /// the buffer is "empty" and `generate()` must be called to produce new - /// results. - #[inline(always)] - pub fn index(&self) -> usize { - self.index - } - - /// Reset the number of available results. - /// This will force a new set of results to be generated on next use. - #[inline] - pub fn reset(&mut self) { - self.index = self.results.as_ref().len(); - self.half_used = false; - } - - /// Generate a new set of results immediately, setting the index to the - /// given value. - #[inline] - pub fn generate_and_set(&mut self, index: usize) { - assert!(index < self.results.as_ref().len()); - self.core.generate(&mut self.results); - self.index = index; - self.half_used = false; - } -} - -impl> RngCore for BlockRng64 -where ::Results: AsRef<[u64]> + AsMut<[u64]> -{ - #[inline] - fn next_u32(&mut self) -> u32 { - let mut index = self.index * 2 - self.half_used as usize; - if index >= self.results.as_ref().len() * 2 { - self.core.generate(&mut self.results); - self.index = 0; - // `self.half_used` is by definition `false` - self.half_used = false; - index = 0; - } - - self.half_used = !self.half_used; - self.index += self.half_used as usize; - - // Index as if this is a u32 slice. - unsafe { - let results = - &*(self.results.as_ref() as *const [u64] as *const [u32]); - if cfg!(target_endian = "little") { - *results.get_unchecked(index) - } else { - *results.get_unchecked(index ^ 1) - } - } - } - - #[inline] - fn next_u64(&mut self) -> u64 { - if self.index >= self.results.as_ref().len() { - self.core.generate(&mut self.results); - self.index = 0; - } - - let value = self.results.as_ref()[self.index]; - self.index += 1; - self.half_used = false; - value - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - let mut read_len = 0; - self.half_used = false; - while read_len < dest.len() { - if self.index as usize >= self.results.as_ref().len() { - self.core.generate(&mut self.results); - self.index = 0; - } - - let (consumed_u64, filled_u8) = - fill_via_u64_chunks(&self.results.as_ref()[self.index as usize..], - &mut dest[read_len..]); - - self.index += consumed_u64; - read_len += filled_u8; - } - } - - #[inline(always)] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for BlockRng64 { - type Seed = R::Seed; - - #[inline(always)] - fn from_seed(seed: Self::Seed) -> Self { - Self::new(R::from_seed(seed)) - } - - #[inline(always)] - fn seed_from_u64(seed: u64) -> Self { - Self::new(R::seed_from_u64(seed)) - } - - #[inline(always)] - fn from_rng(rng: S) -> Result { - Ok(Self::new(R::from_rng(rng)?)) - } -} - -impl CryptoRng for BlockRng {} diff --git a/rand/rand_core/src/error.rs b/rand/rand_core/src/error.rs deleted file mode 100644 index 30b095c..0000000 --- a/rand/rand_core/src/error.rs +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Error types - -use core::fmt; -use core::num::NonZeroU32; - - -/// Error type of random number generators -/// -/// In order to be compatible with `std` and `no_std`, this type has two -/// possible implementations: with `std` a boxed `Error` trait object is stored, -/// while with `no_std` we merely store an error code. -pub struct Error { - #[cfg(feature="std")] - inner: Box, - #[cfg(not(feature="std"))] - code: NonZeroU32, -} - -impl Error { - /// Construct from any type supporting `std::error::Error` - /// - /// Available only when configured with `std`. - /// - /// See also `From`, which is available with and without `std`. - #[cfg(feature="std")] - #[inline] - pub fn new(err: E) -> Self - where E: Into> - { - Error { inner: err.into() } - } - - /// Reference the inner error (`std` only) - /// - /// When configured with `std`, this is a trivial operation and never - /// panics. Without `std`, this method is simply unavailable. - #[cfg(feature="std")] - #[inline] - pub fn inner(&self) -> &(dyn std::error::Error + Send + Sync + 'static) { - &*self.inner - } - - /// Unwrap the inner error (`std` only) - /// - /// When configured with `std`, this is a trivial operation and never - /// panics. Without `std`, this method is simply unavailable. - #[cfg(feature="std")] - #[inline] - pub fn take_inner(self) -> Box { - self.inner - } - - /// Codes below this point represent OS Errors (i.e. positive i32 values). - /// Codes at or above this point, but below [`Error::CUSTOM_START`] are - /// reserved for use by the `rand` and `getrandom` crates. - pub const INTERNAL_START: u32 = 1 << 31; - - /// Codes at or above this point can be used by users to define their own - /// custom errors. - pub const CUSTOM_START: u32 = (1 << 31) + (1 << 30); - - /// Extract the raw OS error code (if this error came from the OS) - /// - /// This method is identical to `std::io::Error::raw_os_error()`, except - /// that it works in `no_std` contexts. If this method returns `None`, the - /// error value can still be formatted via the `Diplay` implementation. - #[inline] - pub fn raw_os_error(&self) -> Option { - #[cfg(feature="std")] { - if let Some(e) = self.inner.downcast_ref::() { - return e.raw_os_error(); - } - } - match self.code() { - Some(code) if u32::from(code) < Self::INTERNAL_START => - Some(u32::from(code) as i32), - _ => None, - } - } - - /// Retrieve the error code, if any. - /// - /// If this `Error` was constructed via `From`, then this method - /// will return this `NonZeroU32` code (for `no_std` this is always the - /// case). Otherwise, this method will return `None`. - #[inline] - pub fn code(&self) -> Option { - #[cfg(feature="std")] { - self.inner.downcast_ref::().map(|c| c.0) - } - #[cfg(not(feature="std"))] { - Some(self.code) - } - } -} - -impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - #[cfg(feature="std")] { - write!(f, "Error {{ inner: {:?} }}", self.inner) - } - #[cfg(all(feature="getrandom", not(feature="std")))] { - getrandom::Error::from(self.code).fmt(f) - } - #[cfg(not(feature="getrandom"))] { - write!(f, "Error {{ code: {} }}", self.code) - } - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - #[cfg(feature="std")] { - write!(f, "{}", self.inner) - } - #[cfg(all(feature="getrandom", not(feature="std")))] { - getrandom::Error::from(self.code).fmt(f) - } - #[cfg(not(feature="getrandom"))] { - write!(f, "error code {}", self.code) - } - } -} - -impl From for Error { - #[inline] - fn from(code: NonZeroU32) -> Self { - #[cfg(feature="std")] { - Error { inner: Box::new(ErrorCode(code)) } - } - #[cfg(not(feature="std"))] { - Error { code } - } - } -} - -#[cfg(feature="getrandom")] -impl From for Error { - #[inline] - fn from(error: getrandom::Error) -> Self { - #[cfg(feature="std")] { - Error { inner: Box::new(error) } - } - #[cfg(not(feature="std"))] { - Error { code: error.code() } - } - } -} - -#[cfg(feature="std")] -impl std::error::Error for Error { - #[inline] - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - self.inner.source() - } -} - -#[cfg(feature="std")] -impl From for std::io::Error { - #[inline] - fn from(error: Error) -> Self { - if let Some(code) = error.raw_os_error() { - std::io::Error::from_raw_os_error(code) - } else { - std::io::Error::new(std::io::ErrorKind::Other, error) - } - } -} - -#[cfg(feature="std")] -#[derive(Debug, Copy, Clone)] -struct ErrorCode(NonZeroU32); - -#[cfg(feature="std")] -impl fmt::Display for ErrorCode { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "error code {}", self.0) - } -} - -#[cfg(feature="std")] -impl std::error::Error for ErrorCode {} diff --git a/rand/rand_core/src/impls.rs b/rand/rand_core/src/impls.rs deleted file mode 100644 index dee4ed1..0000000 --- a/rand/rand_core/src/impls.rs +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Helper functions for implementing `RngCore` functions. -//! -//! For cross-platform reproducibility, these functions all use Little Endian: -//! least-significant part first. For example, `next_u64_via_u32` takes `u32` -//! values `x, y`, then outputs `(y << 32) | x`. To implement `next_u32` -//! from `next_u64` in little-endian order, one should use `next_u64() as u32`. -//! -//! Byte-swapping (like the std `to_le` functions) is only needed to convert -//! to/from byte sequences, and since its purpose is reproducibility, -//! non-reproducible sources (e.g. `OsRng`) need not bother with it. - -use core::ptr::copy_nonoverlapping; -use core::slice; -use core::cmp::min; -use core::mem::size_of; -use crate::RngCore; - - -/// Implement `next_u64` via `next_u32`, little-endian order. -pub fn next_u64_via_u32(rng: &mut R) -> u64 { - // Use LE; we explicitly generate one value before the next. - let x = u64::from(rng.next_u32()); - let y = u64::from(rng.next_u32()); - (y << 32) | x -} - -/// Implement `fill_bytes` via `next_u64` and `next_u32`, little-endian order. -/// -/// The fastest way to fill a slice is usually to work as long as possible with -/// integers. That is why this method mostly uses `next_u64`, and only when -/// there are 4 or less bytes remaining at the end of the slice it uses -/// `next_u32` once. -pub fn fill_bytes_via_next(rng: &mut R, dest: &mut [u8]) { - let mut left = dest; - while left.len() >= 8 { - let (l, r) = {left}.split_at_mut(8); - left = r; - let chunk: [u8; 8] = rng.next_u64().to_le_bytes(); - l.copy_from_slice(&chunk); - } - let n = left.len(); - if n > 4 { - let chunk: [u8; 8] = rng.next_u64().to_le_bytes(); - left.copy_from_slice(&chunk[..n]); - } else if n > 0 { - let chunk: [u8; 4] = rng.next_u32().to_le_bytes(); - left.copy_from_slice(&chunk[..n]); - } -} - -macro_rules! impl_uint_from_fill { - ($rng:expr, $ty:ty, $N:expr) => ({ - debug_assert!($N == size_of::<$ty>()); - - let mut int: $ty = 0; - unsafe { - let ptr = &mut int as *mut $ty as *mut u8; - let slice = slice::from_raw_parts_mut(ptr, $N); - $rng.fill_bytes(slice); - } - int - }); -} - -macro_rules! fill_via_chunks { - ($src:expr, $dst:expr, $ty:ty, $size:expr) => ({ - let chunk_size_u8 = min($src.len() * $size, $dst.len()); - let chunk_size = (chunk_size_u8 + $size - 1) / $size; - if cfg!(target_endian="little") { - unsafe { - copy_nonoverlapping( - $src.as_ptr() as *const u8, - $dst.as_mut_ptr(), - chunk_size_u8); - } - } else { - for (&n, chunk) in $src.iter().zip($dst.chunks_mut($size)) { - let tmp = n.to_le(); - let src_ptr = &tmp as *const $ty as *const u8; - unsafe { - copy_nonoverlapping(src_ptr, - chunk.as_mut_ptr(), - chunk.len()); - } - } - } - - (chunk_size, chunk_size_u8) - }); -} - -/// Implement `fill_bytes` by reading chunks from the output buffer of a block -/// based RNG. -/// -/// The return values are `(consumed_u32, filled_u8)`. -/// -/// `filled_u8` is the number of filled bytes in `dest`, which may be less than -/// the length of `dest`. -/// `consumed_u32` is the number of words consumed from `src`, which is the same -/// as `filled_u8 / 4` rounded up. -/// -/// # Example -/// (from `IsaacRng`) -/// -/// ```ignore -/// fn fill_bytes(&mut self, dest: &mut [u8]) { -/// let mut read_len = 0; -/// while read_len < dest.len() { -/// if self.index >= self.rsl.len() { -/// self.isaac(); -/// } -/// -/// let (consumed_u32, filled_u8) = -/// impls::fill_via_u32_chunks(&mut self.rsl[self.index..], -/// &mut dest[read_len..]); -/// -/// self.index += consumed_u32; -/// read_len += filled_u8; -/// } -/// } -/// ``` -pub fn fill_via_u32_chunks(src: &[u32], dest: &mut [u8]) -> (usize, usize) { - fill_via_chunks!(src, dest, u32, 4) -} - -/// Implement `fill_bytes` by reading chunks from the output buffer of a block -/// based RNG. -/// -/// The return values are `(consumed_u64, filled_u8)`. -/// `filled_u8` is the number of filled bytes in `dest`, which may be less than -/// the length of `dest`. -/// `consumed_u64` is the number of words consumed from `src`, which is the same -/// as `filled_u8 / 8` rounded up. -/// -/// See `fill_via_u32_chunks` for an example. -pub fn fill_via_u64_chunks(src: &[u64], dest: &mut [u8]) -> (usize, usize) { - fill_via_chunks!(src, dest, u64, 8) -} - -/// Implement `next_u32` via `fill_bytes`, little-endian order. -pub fn next_u32_via_fill(rng: &mut R) -> u32 { - impl_uint_from_fill!(rng, u32, 4) -} - -/// Implement `next_u64` via `fill_bytes`, little-endian order. -pub fn next_u64_via_fill(rng: &mut R) -> u64 { - impl_uint_from_fill!(rng, u64, 8) -} - -// TODO: implement tests for the above diff --git a/rand/rand_core/src/le.rs b/rand/rand_core/src/le.rs deleted file mode 100644 index 266651f..0000000 --- a/rand/rand_core/src/le.rs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Little-Endian utilities -//! -//! Little-Endian order has been chosen for internal usage; this makes some -//! useful functions available. - -use core::ptr; - -macro_rules! read_slice { - ($src:expr, $dst:expr, $size:expr, $which:ident) => {{ - assert_eq!($src.len(), $size * $dst.len()); - - unsafe { - ptr::copy_nonoverlapping( - $src.as_ptr(), - $dst.as_mut_ptr() as *mut u8, - $src.len()); - } - for v in $dst.iter_mut() { - *v = v.$which(); - } - }}; -} - -/// Reads unsigned 32 bit integers from `src` into `dst`. -/// Borrowed from the `byteorder` crate. -#[inline] -pub fn read_u32_into(src: &[u8], dst: &mut [u32]) { - read_slice!(src, dst, 4, to_le); -} - -/// Reads unsigned 64 bit integers from `src` into `dst`. -/// Borrowed from the `byteorder` crate. -#[inline] -pub fn read_u64_into(src: &[u8], dst: &mut [u64]) { - read_slice!(src, dst, 8, to_le); -} - -#[test] -fn test_read() { - let bytes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - - let mut buf = [0u32; 4]; - read_u32_into(&bytes, &mut buf); - assert_eq!(buf[0], 0x04030201); - assert_eq!(buf[3], 0x100F0E0D); - - let mut buf = [0u32; 3]; - read_u32_into(&bytes[1..13], &mut buf); // unaligned - assert_eq!(buf[0], 0x05040302); - assert_eq!(buf[2], 0x0D0C0B0A); - - let mut buf = [0u64; 2]; - read_u64_into(&bytes, &mut buf); - assert_eq!(buf[0], 0x0807060504030201); - assert_eq!(buf[1], 0x100F0E0D0C0B0A09); - - let mut buf = [0u64; 1]; - read_u64_into(&bytes[7..15], &mut buf); // unaligned - assert_eq!(buf[0], 0x0F0E0D0C0B0A0908); -} diff --git a/rand/rand_core/src/lib.rs b/rand/rand_core/src/lib.rs deleted file mode 100644 index d8e0189..0000000 --- a/rand/rand_core/src/lib.rs +++ /dev/null @@ -1,492 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2017-2018 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Random number generation traits -//! -//! This crate is mainly of interest to crates publishing implementations of -//! [`RngCore`]. Other users are encouraged to use the [`rand`] crate instead -//! which re-exports the main traits and error types. -//! -//! [`RngCore`] is the core trait implemented by algorithmic pseudo-random number -//! generators and external random-number sources. -//! -//! [`SeedableRng`] is an extension trait for construction from fixed seeds and -//! other random number generators. -//! -//! [`Error`] is provided for error-handling. It is safe to use in `no_std` -//! environments. -//! -//! The [`impls`] and [`le`] sub-modules include a few small functions to assist -//! implementation of [`RngCore`]. -//! -//! [`rand`]: https://docs.rs/rand - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] -#![doc(test(attr(allow(unused_variables), deny(warnings))))] - -#![allow(clippy::unreadable_literal)] - -#![cfg_attr(not(feature="std"), no_std)] - - -use core::default::Default; -use core::convert::AsMut; -use core::ptr::copy_nonoverlapping; - -#[cfg(all(feature="alloc", not(feature="std")))] extern crate alloc; -#[cfg(all(feature="alloc", not(feature="std")))] use alloc::boxed::Box; - -pub use error::Error; -#[cfg(feature="getrandom")] pub use os::OsRng; - - -mod error; -pub mod block; -pub mod impls; -pub mod le; -#[cfg(feature="getrandom")] mod os; - - -/// The core of a random number generator. -/// -/// This trait encapsulates the low-level functionality common to all -/// generators, and is the "back end", to be implemented by generators. -/// End users should normally use the `Rng` trait from the [`rand`] crate, -/// which is automatically implemented for every type implementing `RngCore`. -/// -/// Three different methods for generating random data are provided since the -/// optimal implementation of each is dependent on the type of generator. There -/// is no required relationship between the output of each; e.g. many -/// implementations of [`fill_bytes`] consume a whole number of `u32` or `u64` -/// values and drop any remaining unused bytes. -/// -/// The [`try_fill_bytes`] method is a variant of [`fill_bytes`] allowing error -/// handling; it is not deemed sufficiently useful to add equivalents for -/// [`next_u32`] or [`next_u64`] since the latter methods are almost always used -/// with algorithmic generators (PRNGs), which are normally infallible. -/// -/// Algorithmic generators implementing [`SeedableRng`] should normally have -/// *portable, reproducible* output, i.e. fix Endianness when converting values -/// to avoid platform differences, and avoid making any changes which affect -/// output (except by communicating that the release has breaking changes). -/// -/// Typically implementators will implement only one of the methods available -/// in this trait directly, then use the helper functions from the -/// [`impls`] module to implement the other methods. -/// -/// It is recommended that implementations also implement: -/// -/// - `Debug` with a custom implementation which *does not* print any internal -/// state (at least, [`CryptoRng`]s should not risk leaking state through -/// `Debug`). -/// - `Serialize` and `Deserialize` (from Serde), preferably making Serde -/// support optional at the crate level in PRNG libs. -/// - `Clone`, if possible. -/// - *never* implement `Copy` (accidental copies may cause repeated values). -/// - *do not* implement `Default` for pseudorandom generators, but instead -/// implement [`SeedableRng`], to guide users towards proper seeding. -/// External / hardware RNGs can choose to implement `Default`. -/// - `Eq` and `PartialEq` could be implemented, but are probably not useful. -/// -/// # Example -/// -/// A simple example, obviously not generating very *random* output: -/// -/// ``` -/// #![allow(dead_code)] -/// use rand_core::{RngCore, Error, impls}; -/// -/// struct CountingRng(u64); -/// -/// impl RngCore for CountingRng { -/// fn next_u32(&mut self) -> u32 { -/// self.next_u64() as u32 -/// } -/// -/// fn next_u64(&mut self) -> u64 { -/// self.0 += 1; -/// self.0 -/// } -/// -/// fn fill_bytes(&mut self, dest: &mut [u8]) { -/// impls::fill_bytes_via_next(self, dest) -/// } -/// -/// fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { -/// Ok(self.fill_bytes(dest)) -/// } -/// } -/// ``` -/// -/// [`rand`]: https://docs.rs/rand -/// [`try_fill_bytes`]: RngCore::try_fill_bytes -/// [`fill_bytes`]: RngCore::fill_bytes -/// [`next_u32`]: RngCore::next_u32 -/// [`next_u64`]: RngCore::next_u64 -pub trait RngCore { - /// Return the next random `u32`. - /// - /// RNGs must implement at least one method from this trait directly. In - /// the case this method is not implemented directly, it can be implemented - /// using `self.next_u64() as u32` or via - /// [`fill_bytes`](impls::next_u32_via_fill). - fn next_u32(&mut self) -> u32; - - /// Return the next random `u64`. - /// - /// RNGs must implement at least one method from this trait directly. In - /// the case this method is not implemented directly, it can be implemented - /// via [`next_u32`](impls::next_u64_via_u32) or via - /// [`fill_bytes`](impls::next_u64_via_fill). - fn next_u64(&mut self) -> u64; - - /// Fill `dest` with random data. - /// - /// RNGs must implement at least one method from this trait directly. In - /// the case this method is not implemented directly, it can be implemented - /// via [`next_u*`](impls::fill_bytes_via_next) or - /// via [`try_fill_bytes`](RngCore::try_fill_bytes); if this generator can - /// fail the implementation must choose how best to handle errors here - /// (e.g. panic with a descriptive message or log a warning and retry a few - /// times). - /// - /// This method should guarantee that `dest` is entirely filled - /// with new data, and may panic if this is impossible - /// (e.g. reading past the end of a file that is being used as the - /// source of randomness). - fn fill_bytes(&mut self, dest: &mut [u8]); - - /// Fill `dest` entirely with random data. - /// - /// This is the only method which allows an RNG to report errors while - /// generating random data thus making this the primary method implemented - /// by external (true) RNGs (e.g. `OsRng`) which can fail. It may be used - /// directly to generate keys and to seed (infallible) PRNGs. - /// - /// Other than error handling, this method is identical to [`fill_bytes`]; - /// thus this may be implemented using `Ok(self.fill_bytes(dest))` or - /// `fill_bytes` may be implemented with - /// `self.try_fill_bytes(dest).unwrap()` or more specific error handling. - /// - /// [`fill_bytes`]: RngCore::fill_bytes - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>; -} - -/// A marker trait used to indicate that an [`RngCore`] or [`BlockRngCore`] -/// implementation is supposed to be cryptographically secure. -/// -/// *Cryptographically secure generators*, also known as *CSPRNGs*, should -/// satisfy an additional properties over other generators: given the first -/// *k* bits of an algorithm's output -/// sequence, it should not be possible using polynomial-time algorithms to -/// predict the next bit with probability significantly greater than 50%. -/// -/// Some generators may satisfy an additional property, however this is not -/// required by this trait: if the CSPRNG's state is revealed, it should not be -/// computationally-feasible to reconstruct output prior to this. Some other -/// generators allow backwards-computation and are consided *reversible*. -/// -/// Note that this trait is provided for guidance only and cannot guarantee -/// suitability for cryptographic applications. In general it should only be -/// implemented for well-reviewed code implementing well-regarded algorithms. -/// -/// Note also that use of a `CryptoRng` does not protect against other -/// weaknesses such as seeding from a weak entropy source or leaking state. -/// -/// [`BlockRngCore`]: block::BlockRngCore -pub trait CryptoRng {} - -/// A random number generator that can be explicitly seeded. -/// -/// This trait encapsulates the low-level functionality common to all -/// pseudo-random number generators (PRNGs, or algorithmic generators). -/// -/// [`rand`]: https://docs.rs/rand -pub trait SeedableRng: Sized { - /// Seed type, which is restricted to types mutably-dereferencable as `u8` - /// arrays (we recommend `[u8; N]` for some `N`). - /// - /// It is recommended to seed PRNGs with a seed of at least circa 100 bits, - /// which means an array of `[u8; 12]` or greater to avoid picking RNGs with - /// partially overlapping periods. - /// - /// For cryptographic RNG's a seed of 256 bits is recommended, `[u8; 32]`. - /// - /// - /// # Implementing `SeedableRng` for RNGs with large seeds - /// - /// Note that the required traits `core::default::Default` and - /// `core::convert::AsMut` are not implemented for large arrays - /// `[u8; N]` with `N` > 32. To be able to implement the traits required by - /// `SeedableRng` for RNGs with such large seeds, the newtype pattern can be - /// used: - /// - /// ``` - /// use rand_core::SeedableRng; - /// - /// const N: usize = 64; - /// pub struct MyRngSeed(pub [u8; N]); - /// pub struct MyRng(MyRngSeed); - /// - /// impl Default for MyRngSeed { - /// fn default() -> MyRngSeed { - /// MyRngSeed([0; N]) - /// } - /// } - /// - /// impl AsMut<[u8]> for MyRngSeed { - /// fn as_mut(&mut self) -> &mut [u8] { - /// &mut self.0 - /// } - /// } - /// - /// impl SeedableRng for MyRng { - /// type Seed = MyRngSeed; - /// - /// fn from_seed(seed: MyRngSeed) -> MyRng { - /// MyRng(seed) - /// } - /// } - /// ``` - type Seed: Sized + Default + AsMut<[u8]>; - - /// Create a new PRNG using the given seed. - /// - /// PRNG implementations are allowed to assume that bits in the seed are - /// well distributed. That means usually that the number of one and zero - /// bits are roughly equal, and values like 0, 1 and (size - 1) are unlikely. - /// Note that many non-cryptographic PRNGs will show poor quality output - /// if this is not adhered to. If you wish to seed from simple numbers, use - /// `seed_from_u64` instead. - /// - /// All PRNG implementations should be reproducible unless otherwise noted: - /// given a fixed `seed`, the same sequence of output should be produced - /// on all runs, library versions and architectures (e.g. check endianness). - /// Any "value-breaking" changes to the generator should require bumping at - /// least the minor version and documentation of the change. - /// - /// It is not required that this function yield the same state as a - /// reference implementation of the PRNG given equivalent seed; if necessary - /// another constructor replicating behaviour from a reference - /// implementation can be added. - /// - /// PRNG implementations should make sure `from_seed` never panics. In the - /// case that some special values (like an all zero seed) are not viable - /// seeds it is preferable to map these to alternative constant value(s), - /// for example `0xBAD5EEDu32` or `0x0DDB1A5E5BAD5EEDu64` ("odd biases? bad - /// seed"). This is assuming only a small number of values must be rejected. - fn from_seed(seed: Self::Seed) -> Self; - - /// Create a new PRNG using a `u64` seed. - /// - /// This is a convenience-wrapper around `from_seed` to allow construction - /// of any `SeedableRng` from a simple `u64` value. It is designed such that - /// low Hamming Weight numbers like 0 and 1 can be used and should still - /// result in good, independent seeds to the PRNG which is returned. - /// - /// This **is not suitable for cryptography**, as should be clear given that - /// the input size is only 64 bits. - /// - /// Implementations for PRNGs *may* provide their own implementations of - /// this function, but the default implementation should be good enough for - /// all purposes. *Changing* the implementation of this function should be - /// considered a value-breaking change. - fn seed_from_u64(mut state: u64) -> Self { - // We use PCG32 to generate a u32 sequence, and copy to the seed - const MUL: u64 = 6364136223846793005; - const INC: u64 = 11634580027462260723; - - let mut seed = Self::Seed::default(); - for chunk in seed.as_mut().chunks_mut(4) { - // We advance the state first (to get away from the input value, - // in case it has low Hamming Weight). - state = state.wrapping_mul(MUL).wrapping_add(INC); - - // Use PCG output function with to_le to generate x: - let xorshifted = (((state >> 18) ^ state) >> 27) as u32; - let rot = (state >> 59) as u32; - let x = xorshifted.rotate_right(rot).to_le(); - - unsafe { - let p = &x as *const u32 as *const u8; - copy_nonoverlapping(p, chunk.as_mut_ptr(), chunk.len()); - } - } - - Self::from_seed(seed) - } - - /// Create a new PRNG seeded from another `Rng`. - /// - /// This may be useful when needing to rapidly seed many PRNGs from a master - /// PRNG, and to allow forking of PRNGs. It may be considered deterministic. - /// - /// The master PRNG should be at least as high quality as the child PRNGs. - /// When seeding non-cryptographic child PRNGs, we recommend using a - /// different algorithm for the master PRNG (ideally a CSPRNG) to avoid - /// correlations between the child PRNGs. If this is not possible (e.g. - /// forking using small non-crypto PRNGs) ensure that your PRNG has a good - /// mixing function on the output or consider use of a hash function with - /// `from_seed`. - /// - /// Note that seeding `XorShiftRng` from another `XorShiftRng` provides an - /// extreme example of what can go wrong: the new PRNG will be a clone - /// of the parent. - /// - /// PRNG implementations are allowed to assume that a good RNG is provided - /// for seeding, and that it is cryptographically secure when appropriate. - /// As of `rand` 0.7 / `rand_core` 0.5, implementations overriding this - /// method should ensure the implementation satisfies reproducibility - /// (in prior versions this was not required). - /// - /// [`rand`]: https://docs.rs/rand - /// [`rand_os`]: https://docs.rs/rand_os - fn from_rng(mut rng: R) -> Result { - let mut seed = Self::Seed::default(); - rng.try_fill_bytes(seed.as_mut())?; - Ok(Self::from_seed(seed)) - } - - /// Creates a new instance of the RNG seeded via [`getrandom`]. - /// - /// This method is the recommended way to construct non-deterministic PRNGs - /// since it is convenient and secure. - /// - /// In case the overhead of using [`getrandom`] to seed *many* PRNGs is an - /// issue, one may prefer to seed from a local PRNG, e.g. - /// `from_rng(thread_rng()).unwrap()`. - /// - /// # Panics - /// - /// If [`getrandom`] is unable to provide secure entropy this method will panic. - /// - /// [`getrandom`]: https://docs.rs/getrandom - #[cfg(feature="getrandom")] - fn from_entropy() -> Self { - let mut seed = Self::Seed::default(); - if let Err(err) = getrandom::getrandom(seed.as_mut()) { - panic!("from_entropy failed: {}", err); - } - Self::from_seed(seed) - } -} - -// Implement `RngCore` for references to an `RngCore`. -// Force inlining all functions, so that it is up to the `RngCore` -// implementation and the optimizer to decide on inlining. -impl<'a, R: RngCore + ?Sized> RngCore for &'a mut R { - #[inline(always)] - fn next_u32(&mut self) -> u32 { - (**self).next_u32() - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - (**self).next_u64() - } - - #[inline(always)] - fn fill_bytes(&mut self, dest: &mut [u8]) { - (**self).fill_bytes(dest) - } - - #[inline(always)] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - (**self).try_fill_bytes(dest) - } -} - -// Implement `RngCore` for boxed references to an `RngCore`. -// Force inlining all functions, so that it is up to the `RngCore` -// implementation and the optimizer to decide on inlining. -#[cfg(feature="alloc")] -impl RngCore for Box { - #[inline(always)] - fn next_u32(&mut self) -> u32 { - (**self).next_u32() - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - (**self).next_u64() - } - - #[inline(always)] - fn fill_bytes(&mut self, dest: &mut [u8]) { - (**self).fill_bytes(dest) - } - - #[inline(always)] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - (**self).try_fill_bytes(dest) - } -} - -#[cfg(feature="std")] -impl std::io::Read for dyn RngCore { - fn read(&mut self, buf: &mut [u8]) -> Result { - self.try_fill_bytes(buf)?; - Ok(buf.len()) - } -} - -// Implement `CryptoRng` for references to an `CryptoRng`. -impl<'a, R: CryptoRng + ?Sized> CryptoRng for &'a mut R {} - -// Implement `CryptoRng` for boxed references to an `CryptoRng`. -#[cfg(feature="alloc")] -impl CryptoRng for Box {} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_seed_from_u64() { - struct SeedableNum(u64); - impl SeedableRng for SeedableNum { - type Seed = [u8; 8]; - fn from_seed(seed: Self::Seed) -> Self { - let mut x = [0u64; 1]; - le::read_u64_into(&seed, &mut x); - SeedableNum(x[0]) - } - } - - const N: usize = 8; - const SEEDS: [u64; N] = [0u64, 1, 2, 3, 4, 8, 16, -1i64 as u64]; - let mut results = [0u64; N]; - for (i, seed) in SEEDS.iter().enumerate() { - let SeedableNum(x) = SeedableNum::seed_from_u64(*seed); - results[i] = x; - } - - for (i1, r1) in results.iter().enumerate() { - let weight = r1.count_ones(); - // This is the binomial distribution B(64, 0.5), so chance of - // weight < 20 is binocdf(19, 64, 0.5) = 7.8e-4, and same for - // weight > 44. - assert!(weight >= 20 && weight <= 44); - - for (i2, r2) in results.iter().enumerate() { - if i1 == i2 { continue; } - let diff_weight = (r1 ^ r2).count_ones(); - assert!(diff_weight >= 20); - } - } - - // value-breakage test: - assert_eq!(results[0], 5029875928683246316); - } -} diff --git a/rand/rand_core/src/os.rs b/rand/rand_core/src/os.rs deleted file mode 100644 index fc23a57..0000000 --- a/rand/rand_core/src/os.rs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Interface to the random number generator of the operating system. -// Note: keep this code in sync with the rand_os crate! - -use getrandom::getrandom; -use crate::{CryptoRng, RngCore, Error, impls}; - -/// A random number generator that retrieves randomness from from the -/// operating system. -/// -/// This is a zero-sized struct. It can be freely constructed with `OsRng`. -/// -/// The implementation is provided by the [getrandom] crate. Refer to -/// [getrandom] documentation for details. -/// -/// This struct is only available when specifying the crate feature `getrandom` -/// or `std`. When using the `rand` lib, it is also available as `rand::rngs::OsRng`. -/// -/// # Blocking and error handling -/// -/// It is possible that when used during early boot the first call to `OsRng` -/// will block until the system's RNG is initialised. It is also possible -/// (though highly unlikely) for `OsRng` to fail on some platforms, most -/// likely due to system mis-configuration. -/// -/// After the first successful call, it is highly unlikely that failures or -/// significant delays will occur (although performance should be expected to -/// be much slower than a user-space PRNG). -/// -/// # Usage example -/// ``` -/// use rand_core::{RngCore, OsRng}; -/// -/// let mut key = [0u8; 16]; -/// OsRng.fill_bytes(&mut key); -/// let random_u64 = OsRng.next_u64(); -/// ``` -/// -/// [getrandom]: https://crates.io/crates/getrandom -#[derive(Clone, Copy, Debug, Default)] -pub struct OsRng; - -impl CryptoRng for OsRng {} - -impl RngCore for OsRng { - fn next_u32(&mut self) -> u32 { - impls::next_u32_via_fill(self) - } - - fn next_u64(&mut self) -> u64 { - impls::next_u64_via_fill(self) - } - - fn fill_bytes(&mut self, dest: &mut [u8]) { - if let Err(e) = self.try_fill_bytes(dest) { - panic!("Error: {}", e); - } - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - getrandom(dest)?; - Ok(()) - } -} - -#[test] -fn test_os_rng() { - let x = OsRng.next_u64(); - let y = OsRng.next_u64(); - assert!(x != 0); - assert!(x != y); -} - -#[test] -fn test_construction() { - let mut rng = OsRng::default(); - assert!(rng.next_u64() != 0); -} diff --git a/rand/rand_distr/CHANGELOG.md b/rand/rand_distr/CHANGELOG.md deleted file mode 100644 index 376bb95..0000000 --- a/rand/rand_distr/CHANGELOG.md +++ /dev/null @@ -1,21 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.2.1] - 2019-06-29 -- Update dependency to support Rand 0.7 -- Doc link fixes - -## [0.2.0] - 2019-06-06 -- Remove `new` constructors for zero-sized types -- Add Pert distribution -- Fix undefined behavior in `Poisson` -- Make all distributions return `Result`s instead of panicking -- Implement `f32` support for most distributions -- Rename `UnitSphereSurface` to `UnitSphere` -- Implement `UnitBall` and `UnitDisc` - -## [0.1.0] - 2019-06-06 -Initial release. This is equivalent to the code in `rand` 0.6.5. diff --git a/rand/rand_distr/COPYRIGHT b/rand/rand_distr/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_distr/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_distr/Cargo.toml b/rand/rand_distr/Cargo.toml deleted file mode 100644 index 315a5b0..0000000 --- a/rand/rand_distr/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "rand_distr" -version = "0.2.1" -authors = ["The Rand Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_distr/" -homepage = "https://crates.io/crates/rand_distr" -description = """ -Sampling from random number distributions -""" -keywords = ["random", "rng", "distribution", "probability"] -categories = ["algorithms"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[dependencies] -rand = { path = "..", version = "0.7" } - -[dev-dependencies] -rand_pcg = { version = "0.2", path = "../rand_pcg" } -# Histogram implementation for testing uniformity -average = "0.9.2" diff --git a/rand/rand_distr/LICENSE-APACHE b/rand/rand_distr/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_distr/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_distr/LICENSE-MIT b/rand/rand_distr/LICENSE-MIT deleted file mode 100644 index cf65607..0000000 --- a/rand/rand_distr/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright 2018 Developers of the Rand project - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_distr/README.md b/rand/rand_distr/README.md deleted file mode 100644 index 68acd2f..0000000 --- a/rand/rand_distr/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# rand_distr - -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_distr.svg)](https://crates.io/crates/rand_distr) -[[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_distr) -[![API](https://docs.rs/rand_distr/badge.svg)](https://docs.rs/rand_distr) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -Implements a full suite of random number distributions sampling routines. - -This crate is a super-set of the [rand::distributions] module, including support -for sampling from Beta, Binomial, Cauchy, ChiSquared, Dirichlet, exponential, -Fisher F, Gamma, Log-normal, Normal, Pareto, Poisson, StudentT, Triangular and -Weibull distributions, as well as sampling points from the unit circle and unit -sphere surface. - -It is worth mentioning the [statrs] crate which provides similar functionality -along with various support functions, including PDF and CDF computation. In -contrast, this `rand_distr` crate focusses on sampling from distributions. - -Unlike most Rand crates, `rand_distr` does not currently support `no_std`. - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_distr) -- [API documentation (docs.rs)](https://docs.rs/rand_distr) -- [Changelog](CHANGELOG.md) -- [The Rand project](https://github.com/rust-random/rand) - - -[statrs]: https://github.com/boxtown/statrs -[rand::distributions]: https://rust-random.github.io/rand/rand/distributions/index.html - -## License - -`rand_distr` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_distr/benches/distributions.rs b/rand/rand_distr/benches/distributions.rs deleted file mode 100644 index 63bde36..0000000 --- a/rand/rand_distr/benches/distributions.rs +++ /dev/null @@ -1,316 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(test)] - -const RAND_BENCH_N: u64 = 1000; - -use std::mem::size_of; -use std::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128}; -use test::Bencher; -use std::time::Duration; - -use rand::prelude::*; -use rand_distr::{*, weighted::WeightedIndex}; - -// At this time, distributions are optimised for 64-bit platforms. -use rand_pcg::Pcg64Mcg; - -macro_rules! distr_int { - ($fnn:ident, $ty:ty, $distr:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - let distr = $distr; - - b.iter(|| { - let mut accum = 0 as $ty; - for _ in 0..RAND_BENCH_N { - let x: $ty = distr.sample(&mut rng); - accum = accum.wrapping_add(x); - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -macro_rules! distr_nz_int { - ($fnn:ident, $tynz:ty, $ty:ty, $distr:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - let distr = $distr; - - b.iter(|| { - let mut accum = 0 as $ty; - for _ in 0..RAND_BENCH_N { - let x: $tynz = distr.sample(&mut rng); - accum = accum.wrapping_add(x.get()); - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -macro_rules! distr_float { - ($fnn:ident, $ty:ty, $distr:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - let distr = $distr; - - b.iter(|| { - let mut accum = 0.0; - for _ in 0..RAND_BENCH_N { - let x: $ty = distr.sample(&mut rng); - accum += x; - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -macro_rules! distr_duration { - ($fnn:ident, $distr:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - let distr = $distr; - - b.iter(|| { - let mut accum = Duration::new(0, 0); - for _ in 0..RAND_BENCH_N { - let x: Duration = distr.sample(&mut rng); - accum = accum.checked_add(x).unwrap_or(Duration::new(u64::max_value(), 999_999_999)); - } - accum - }); - b.bytes = size_of::() as u64 * RAND_BENCH_N; - } - } -} - -macro_rules! distr { - ($fnn:ident, $ty:ty, $distr:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - let distr = $distr; - - b.iter(|| { - let mut accum = 0u32; - for _ in 0..RAND_BENCH_N { - let x: $ty = distr.sample(&mut rng); - accum = accum.wrapping_add(x as u32); - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -macro_rules! distr_arr { - ($fnn:ident, $ty:ty, $distr:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - let distr = $distr; - - b.iter(|| { - let mut accum = 0u32; - for _ in 0..RAND_BENCH_N { - let x: $ty = distr.sample(&mut rng); - accum = accum.wrapping_add(x[0] as u32); - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -// uniform -distr_int!(distr_uniform_i8, i8, Uniform::new(20i8, 100)); -distr_int!(distr_uniform_i16, i16, Uniform::new(-500i16, 2000)); -distr_int!(distr_uniform_i32, i32, Uniform::new(-200_000_000i32, 800_000_000)); -distr_int!(distr_uniform_i64, i64, Uniform::new(3i64, 123_456_789_123)); -distr_int!(distr_uniform_i128, i128, Uniform::new(-123_456_789_123i128, 123_456_789_123_456_789)); -distr_int!(distr_uniform_usize16, usize, Uniform::new(0usize, 0xb9d7)); -distr_int!(distr_uniform_usize32, usize, Uniform::new(0usize, 0x548c0f43)); -#[cfg(target_pointer_width = "64")] -distr_int!(distr_uniform_usize64, usize, Uniform::new(0usize, 0x3a42714f2bf927a8)); -distr_int!(distr_uniform_isize, isize, Uniform::new(-1060478432isize, 1858574057)); - -distr_float!(distr_uniform_f32, f32, Uniform::new(2.26f32, 2.319)); -distr_float!(distr_uniform_f64, f64, Uniform::new(2.26f64, 2.319)); - -const LARGE_SEC: u64 = u64::max_value() / 1000; - -distr_duration!(distr_uniform_duration_largest, - Uniform::new_inclusive(Duration::new(0, 0), Duration::new(u64::max_value(), 999_999_999)) -); -distr_duration!(distr_uniform_duration_large, - Uniform::new(Duration::new(0, 0), Duration::new(LARGE_SEC, 1_000_000_000 / 2)) -); -distr_duration!(distr_uniform_duration_one, - Uniform::new(Duration::new(0, 0), Duration::new(1, 0)) -); -distr_duration!(distr_uniform_duration_variety, - Uniform::new(Duration::new(10000, 423423), Duration::new(200000, 6969954)) -); -distr_duration!(distr_uniform_duration_edge, - Uniform::new_inclusive(Duration::new(LARGE_SEC, 999_999_999), Duration::new(LARGE_SEC + 1, 1)) -); - - -// standard -distr_int!(distr_standard_i8, i8, Standard); -distr_int!(distr_standard_i16, i16, Standard); -distr_int!(distr_standard_i32, i32, Standard); -distr_int!(distr_standard_i64, i64, Standard); -distr_int!(distr_standard_i128, i128, Standard); -distr_nz_int!(distr_standard_nz8, NonZeroU8, u8, Standard); -distr_nz_int!(distr_standard_nz16, NonZeroU16, u16, Standard); -distr_nz_int!(distr_standard_nz32, NonZeroU32, u32, Standard); -distr_nz_int!(distr_standard_nz64, NonZeroU64, u64, Standard); -distr_nz_int!(distr_standard_nz128, NonZeroU128, u128, Standard); - -distr!(distr_standard_bool, bool, Standard); -distr!(distr_standard_alphanumeric, char, Alphanumeric); -distr!(distr_standard_codepoint, char, Standard); - -distr_float!(distr_standard_f32, f32, Standard); -distr_float!(distr_standard_f64, f64, Standard); -distr_float!(distr_open01_f32, f32, Open01); -distr_float!(distr_open01_f64, f64, Open01); -distr_float!(distr_openclosed01_f32, f32, OpenClosed01); -distr_float!(distr_openclosed01_f64, f64, OpenClosed01); - -// distributions -distr_float!(distr_exp, f64, Exp::new(1.23 * 4.56).unwrap()); -distr_float!(distr_normal, f64, Normal::new(-1.23, 4.56).unwrap()); -distr_float!(distr_log_normal, f64, LogNormal::new(-1.23, 4.56).unwrap()); -distr_float!(distr_gamma_large_shape, f64, Gamma::new(10., 1.0).unwrap()); -distr_float!(distr_gamma_small_shape, f64, Gamma::new(0.1, 1.0).unwrap()); -distr_float!(distr_cauchy, f64, Cauchy::new(4.2, 6.9).unwrap()); -distr_float!(distr_triangular, f64, Triangular::new(0., 1., 0.9).unwrap()); -distr_int!(distr_binomial, u64, Binomial::new(20, 0.7).unwrap()); -distr_int!(distr_binomial_small, u64, Binomial::new(1000000, 1e-30).unwrap()); -distr_int!(distr_poisson, u64, Poisson::new(4.0).unwrap()); -distr!(distr_bernoulli, bool, Bernoulli::new(0.18).unwrap()); -distr_arr!(distr_circle, [f64; 2], UnitCircle); -distr_arr!(distr_sphere, [f64; 3], UnitSphere); - -// Weighted -distr_int!(distr_weighted_i8, usize, WeightedIndex::new(&[1i8, 2, 3, 4, 12, 0, 2, 1]).unwrap()); -distr_int!(distr_weighted_u32, usize, WeightedIndex::new(&[1u32, 2, 3, 4, 12, 0, 2, 1]).unwrap()); -distr_int!(distr_weighted_f64, usize, WeightedIndex::new(&[1.0f64, 0.001, 1.0/3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap()); -distr_int!(distr_weighted_large_set, usize, WeightedIndex::new((0..10000).rev().chain(1..10001)).unwrap()); - -distr_int!(distr_weighted_alias_method_i8, usize, weighted::alias_method::WeightedIndex::new(vec![1i8, 2, 3, 4, 12, 0, 2, 1]).unwrap()); -distr_int!(distr_weighted_alias_method_u32, usize, weighted::alias_method::WeightedIndex::new(vec![1u32, 2, 3, 4, 12, 0, 2, 1]).unwrap()); -distr_int!(distr_weighted_alias_method_f64, usize, weighted::alias_method::WeightedIndex::new(vec![1.0f64, 0.001, 1.0/3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap()); -distr_int!(distr_weighted_alias_method_large_set, usize, weighted::alias_method::WeightedIndex::new((0..10000).rev().chain(1..10001).collect()).unwrap()); - -// construct and sample from a range -macro_rules! gen_range_int { - ($fnn:ident, $ty:ident, $low:expr, $high:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - - b.iter(|| { - let mut high = $high; - let mut accum: $ty = 0; - for _ in 0..RAND_BENCH_N { - accum = accum.wrapping_add(rng.gen_range($low, high)); - // force recalculation of range each time - high = high.wrapping_add(1) & std::$ty::MAX; - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -gen_range_int!(gen_range_i8, i8, -20i8, 100); -gen_range_int!(gen_range_i16, i16, -500i16, 2000); -gen_range_int!(gen_range_i32, i32, -200_000_000i32, 800_000_000); -gen_range_int!(gen_range_i64, i64, 3i64, 123_456_789_123); -gen_range_int!(gen_range_i128, i128, -12345678901234i128, 123_456_789_123_456_789); - -// construct and sample from a floating-point range -macro_rules! gen_range_float { - ($fnn:ident, $ty:ident, $low:expr, $high:expr) => { - #[bench] - fn $fnn(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - - b.iter(|| { - let mut high = $high; - let mut low = $low; - let mut accum: $ty = 0.0; - for _ in 0..RAND_BENCH_N { - accum += rng.gen_range(low, high); - // force recalculation of range each time - low += 0.9; - high += 1.1; - } - accum - }); - b.bytes = size_of::<$ty>() as u64 * RAND_BENCH_N; - } - } -} - -gen_range_float!(gen_range_f32, f32, -20000.0f32, 100000.0); -gen_range_float!(gen_range_f64, f64, 123.456f64, 7890.12); - -#[bench] -fn dist_iter(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_entropy(); - let distr = Normal::new(-2.71828, 3.14159).unwrap(); - let mut iter = distr.sample_iter(&mut rng); - - b.iter(|| { - let mut accum = 0.0; - for _ in 0..RAND_BENCH_N { - accum += iter.next().unwrap(); - } - accum - }); - b.bytes = size_of::() as u64 * RAND_BENCH_N; -} - -macro_rules! sample_binomial { - ($name:ident, $n:expr, $p:expr) => { - #[bench] - fn $name(b: &mut Bencher) { - let mut rng = Pcg64Mcg::from_rng(&mut thread_rng()).unwrap(); - let (n, p) = ($n, $p); - b.iter(|| { - let d = Binomial::new(n, p).unwrap(); - rng.sample(d) - }) - } - } -} - -sample_binomial!(misc_binomial_1, 1, 0.9); -sample_binomial!(misc_binomial_10, 10, 0.9); -sample_binomial!(misc_binomial_100, 100, 0.99); -sample_binomial!(misc_binomial_1000, 1000, 0.01); -sample_binomial!(misc_binomial_1e12, 1000_000_000_000, 0.2); diff --git a/rand/rand_distr/src/binomial.rs b/rand/rand_distr/src/binomial.rs deleted file mode 100644 index 0e6bf9a..0000000 --- a/rand/rand_distr/src/binomial.rs +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2016-2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The binomial distribution. - -use rand::Rng; -use crate::{Distribution, Uniform}; - -/// The binomial distribution `Binomial(n, p)`. -/// -/// This distribution has density function: -/// `f(k) = n!/(k! (n-k)!) p^k (1-p)^(n-k)` for `k >= 0`. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{Binomial, Distribution}; -/// -/// let bin = Binomial::new(20, 0.3).unwrap(); -/// let v = bin.sample(&mut rand::thread_rng()); -/// println!("{} is from a binomial distribution", v); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct Binomial { - /// Number of trials. - n: u64, - /// Probability of success. - p: f64, -} - -/// Error type returned from `Binomial::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `p < 0` or `nan`. - ProbabilityTooSmall, - /// `p > 1`. - ProbabilityTooLarge, -} - -impl Binomial { - /// Construct a new `Binomial` with the given shape parameters `n` (number - /// of trials) and `p` (probability of success). - pub fn new(n: u64, p: f64) -> Result { - if !(p >= 0.0) { - return Err(Error::ProbabilityTooSmall); - } - if !(p <= 1.0) { - return Err(Error::ProbabilityTooLarge); - } - Ok(Binomial { n, p }) - } -} - -/// Convert a `f64` to an `i64`, panicing on overflow. -// In the future (Rust 1.34), this might be replaced with `TryFrom`. -fn f64_to_i64(x: f64) -> i64 { - assert!(x < (::std::i64::MAX as f64)); - x as i64 -} - -impl Distribution for Binomial { - #[allow(clippy::many_single_char_names)] // Same names as in the reference. - fn sample(&self, rng: &mut R) -> u64 { - // Handle these values directly. - if self.p == 0.0 { - return 0; - } else if self.p == 1.0 { - return self.n; - } - - // The binomial distribution is symmetrical with respect to p -> 1-p, - // k -> n-k switch p so that it is less than 0.5 - this allows for lower - // expected values we will just invert the result at the end - let p = if self.p <= 0.5 { - self.p - } else { - 1.0 - self.p - }; - - let result; - let q = 1. - p; - - // For small n * min(p, 1 - p), the BINV algorithm based on the inverse - // transformation of the binomial distribution is efficient. Otherwise, - // the BTPE algorithm is used. - // - // Voratas Kachitvichyanukul and Bruce W. Schmeiser. 1988. Binomial - // random variate generation. Commun. ACM 31, 2 (February 1988), - // 216-222. http://dx.doi.org/10.1145/42372.42381 - - // Threshold for prefering the BINV algorithm. The paper suggests 10, - // Ranlib uses 30, and GSL uses 14. - const BINV_THRESHOLD: f64 = 10.; - - if (self.n as f64) * p < BINV_THRESHOLD && - self.n <= (::std::i32::MAX as u64) { - // Use the BINV algorithm. - let s = p / q; - let a = ((self.n + 1) as f64) * s; - let mut r = q.powi(self.n as i32); - let mut u: f64 = rng.gen(); - let mut x = 0; - while u > r as f64 { - u -= r; - x += 1; - r *= a / (x as f64) - s; - } - result = x; - } else { - // Use the BTPE algorithm. - - // Threshold for using the squeeze algorithm. This can be freely - // chosen based on performance. Ranlib and GSL use 20. - const SQUEEZE_THRESHOLD: i64 = 20; - - // Step 0: Calculate constants as functions of `n` and `p`. - let n = self.n as f64; - let np = n * p; - let npq = np * q; - let f_m = np + p; - let m = f64_to_i64(f_m); - // radius of triangle region, since height=1 also area of region - let p1 = (2.195 * npq.sqrt() - 4.6 * q).floor() + 0.5; - // tip of triangle - let x_m = (m as f64) + 0.5; - // left edge of triangle - let x_l = x_m - p1; - // right edge of triangle - let x_r = x_m + p1; - let c = 0.134 + 20.5 / (15.3 + (m as f64)); - // p1 + area of parallelogram region - let p2 = p1 * (1. + 2. * c); - - fn lambda(a: f64) -> f64 { - a * (1. + 0.5 * a) - } - - let lambda_l = lambda((f_m - x_l) / (f_m - x_l * p)); - let lambda_r = lambda((x_r - f_m) / (x_r * q)); - // p1 + area of left tail - let p3 = p2 + c / lambda_l; - // p1 + area of right tail - let p4 = p3 + c / lambda_r; - - // return value - let mut y: i64; - - let gen_u = Uniform::new(0., p4); - let gen_v = Uniform::new(0., 1.); - - loop { - // Step 1: Generate `u` for selecting the region. If region 1 is - // selected, generate a triangularly distributed variate. - let u = gen_u.sample(rng); - let mut v = gen_v.sample(rng); - if !(u > p1) { - y = f64_to_i64(x_m - p1 * v + u); - break; - } - - if !(u > p2) { - // Step 2: Region 2, parallelograms. Check if region 2 is - // used. If so, generate `y`. - let x = x_l + (u - p1) / c; - v = v * c + 1.0 - (x - x_m).abs() / p1; - if v > 1. { - continue; - } else { - y = f64_to_i64(x); - } - } else if !(u > p3) { - // Step 3: Region 3, left exponential tail. - y = f64_to_i64(x_l + v.ln() / lambda_l); - if y < 0 { - continue; - } else { - v *= (u - p2) * lambda_l; - } - } else { - // Step 4: Region 4, right exponential tail. - y = f64_to_i64(x_r - v.ln() / lambda_r); - if y > 0 && (y as u64) > self.n { - continue; - } else { - v *= (u - p3) * lambda_r; - } - } - - // Step 5: Acceptance/rejection comparison. - - // Step 5.0: Test for appropriate method of evaluating f(y). - let k = (y - m).abs(); - if !(k > SQUEEZE_THRESHOLD && (k as f64) < 0.5 * npq - 1.) { - // Step 5.1: Evaluate f(y) via the recursive relationship. Start the - // search from the mode. - let s = p / q; - let a = s * (n + 1.); - let mut f = 1.0; - if m < y { - let mut i = m; - loop { - i += 1; - f *= a / (i as f64) - s; - if i == y { - break; - } - } - } else if m > y { - let mut i = y; - loop { - i += 1; - f /= a / (i as f64) - s; - if i == m { - break; - } - } - } - if v > f { - continue; - } else { - break; - } - } - - // Step 5.2: Squeezing. Check the value of ln(v) againts upper and - // lower bound of ln(f(y)). - let k = k as f64; - let rho = (k / npq) * ((k * (k / 3. + 0.625) + 1./6.) / npq + 0.5); - let t = -0.5 * k*k / npq; - let alpha = v.ln(); - if alpha < t - rho { - break; - } - if alpha > t + rho { - continue; - } - - // Step 5.3: Final acceptance/rejection test. - let x1 = (y + 1) as f64; - let f1 = (m + 1) as f64; - let z = (f64_to_i64(n) + 1 - m) as f64; - let w = (f64_to_i64(n) - y + 1) as f64; - - fn stirling(a: f64) -> f64 { - let a2 = a * a; - (13860. - (462. - (132. - (99. - 140. / a2) / a2) / a2) / a2) / a / 166320. - } - - if alpha > x_m * (f1 / x1).ln() - + (n - (m as f64) + 0.5) * (z / w).ln() - + ((y - m) as f64) * (w * p / (x1 * q)).ln() - // We use the signs from the GSL implementation, which are - // different than the ones in the reference. According to - // the GSL authors, the new signs were verified to be - // correct by one of the original designers of the - // algorithm. - + stirling(f1) + stirling(z) - stirling(x1) - stirling(w) - { - continue; - } - - break; - } - assert!(y >= 0); - result = y as u64; - } - - // Invert the result for p < 0.5. - if p != self.p { - self.n - result - } else { - result - } - } -} - -#[cfg(test)] -mod test { - use rand::Rng; - use crate::Distribution; - use super::Binomial; - - fn test_binomial_mean_and_variance(n: u64, p: f64, rng: &mut R) { - let binomial = Binomial::new(n, p).unwrap(); - - let expected_mean = n as f64 * p; - let expected_variance = n as f64 * p * (1.0 - p); - - let mut results = [0.0; 1000]; - for i in results.iter_mut() { *i = binomial.sample(rng) as f64; } - - let mean = results.iter().sum::() / results.len() as f64; - assert!((mean as f64 - expected_mean).abs() < expected_mean / 50.0); - - let variance = - results.iter().map(|x| (x - mean) * (x - mean)).sum::() - / results.len() as f64; - assert!((variance - expected_variance).abs() < expected_variance / 10.0); - } - - #[test] - fn test_binomial() { - let mut rng = crate::test::rng(351); - test_binomial_mean_and_variance(150, 0.1, &mut rng); - test_binomial_mean_and_variance(70, 0.6, &mut rng); - test_binomial_mean_and_variance(40, 0.5, &mut rng); - test_binomial_mean_and_variance(20, 0.7, &mut rng); - test_binomial_mean_and_variance(20, 0.5, &mut rng); - } - - #[test] - fn test_binomial_end_points() { - let mut rng = crate::test::rng(352); - assert_eq!(rng.sample(Binomial::new(20, 0.0).unwrap()), 0); - assert_eq!(rng.sample(Binomial::new(20, 1.0).unwrap()), 20); - } - - #[test] - #[should_panic] - fn test_binomial_invalid_lambda_neg() { - Binomial::new(20, -10.0).unwrap(); - } -} diff --git a/rand/rand_distr/src/cauchy.rs b/rand/rand_distr/src/cauchy.rs deleted file mode 100644 index 6b0e7c6..0000000 --- a/rand/rand_distr/src/cauchy.rs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2016-2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Cauchy distribution. - -use rand::Rng; -use crate::{Distribution, Standard}; -use crate::utils::Float; - -/// The Cauchy distribution `Cauchy(median, scale)`. -/// -/// This distribution has a density function: -/// `f(x) = 1 / (pi * scale * (1 + ((x - median) / scale)^2))` -/// -/// # Example -/// -/// ``` -/// use rand_distr::{Cauchy, Distribution}; -/// -/// let cau = Cauchy::new(2.0, 5.0).unwrap(); -/// let v = cau.sample(&mut rand::thread_rng()); -/// println!("{} is from a Cauchy(2, 5) distribution", v); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct Cauchy { - median: N, - scale: N, -} - -/// Error type returned from `Cauchy::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `scale <= 0` or `nan`. - ScaleTooSmall, -} - -impl Cauchy -where Standard: Distribution -{ - /// Construct a new `Cauchy` with the given shape parameters - /// `median` the peak location and `scale` the scale factor. - pub fn new(median: N, scale: N) -> Result, Error> { - if !(scale > N::from(0.0)) { - return Err(Error::ScaleTooSmall); - } - Ok(Cauchy { - median, - scale - }) - } -} - -impl Distribution for Cauchy -where Standard: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - // sample from [0, 1) - let x = Standard.sample(rng); - // get standard cauchy random number - // note that π/2 is not exactly representable, even if x=0.5 the result is finite - let comp_dev = (N::pi() * x).tan(); - // shift and scale according to parameters - self.median + self.scale * comp_dev - } -} - -#[cfg(test)] -mod test { - use crate::Distribution; - use super::Cauchy; - - fn median(mut numbers: &mut [f64]) -> f64 { - sort(&mut numbers); - let mid = numbers.len() / 2; - numbers[mid] - } - - fn sort(numbers: &mut [f64]) { - numbers.sort_by(|a, b| a.partial_cmp(b).unwrap()); - } - - #[test] - fn test_cauchy_averages() { - // NOTE: given that the variance and mean are undefined, - // this test does not have any rigorous statistical meaning. - let cauchy = Cauchy::new(10.0, 5.0).unwrap(); - let mut rng = crate::test::rng(123); - let mut numbers: [f64; 1000] = [0.0; 1000]; - let mut sum = 0.0; - for i in 0..1000 { - numbers[i] = cauchy.sample(&mut rng); - sum += numbers[i]; - } - let median = median(&mut numbers); - println!("Cauchy median: {}", median); - assert!((median - 10.0).abs() < 0.4); // not 100% certain, but probable enough - let mean = sum / 1000.0; - println!("Cauchy mean: {}", mean); - // for a Cauchy distribution the mean should not converge - assert!((mean - 10.0).abs() > 0.4); // not 100% certain, but probable enough - } - - #[test] - #[should_panic] - fn test_cauchy_invalid_scale_zero() { - Cauchy::new(0.0, 0.0).unwrap(); - } - - #[test] - #[should_panic] - fn test_cauchy_invalid_scale_neg() { - Cauchy::new(0.0, -10.0).unwrap(); - } -} diff --git a/rand/rand_distr/src/dirichlet.rs b/rand/rand_distr/src/dirichlet.rs deleted file mode 100644 index 71cf73c..0000000 --- a/rand/rand_distr/src/dirichlet.rs +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The dirichlet distribution. - -use rand::Rng; -use crate::{Distribution, Gamma, StandardNormal, Exp1, Open01}; -use crate::utils::Float; - -/// The dirichelet distribution `Dirichlet(alpha)`. -/// -/// The Dirichlet distribution is a family of continuous multivariate -/// probability distributions parameterized by a vector alpha of positive reals. -/// It is a multivariate generalization of the beta distribution. -/// -/// # Example -/// -/// ``` -/// use rand::prelude::*; -/// use rand_distr::Dirichlet; -/// -/// let dirichlet = Dirichlet::new(vec![1.0, 2.0, 3.0]).unwrap(); -/// let samples = dirichlet.sample(&mut rand::thread_rng()); -/// println!("{:?} is from a Dirichlet([1.0, 2.0, 3.0]) distribution", samples); -/// ``` -#[derive(Clone, Debug)] -pub struct Dirichlet { - /// Concentration parameters (alpha) - alpha: Vec, -} - -/// Error type returned from `Dirchlet::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `alpha.len() < 2`. - AlphaTooShort, - /// `alpha <= 0.0` or `nan`. - AlphaTooSmall, - /// `size < 2`. - SizeTooSmall, -} - -impl Dirichlet -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - /// Construct a new `Dirichlet` with the given alpha parameter `alpha`. - /// - /// Requires `alpha.len() >= 2`. - #[inline] - pub fn new>>(alpha: V) -> Result, Error> { - let a = alpha.into(); - if a.len() < 2 { - return Err(Error::AlphaTooShort); - } - for &ai in &a { - if !(ai > N::from(0.0)) { - return Err(Error::AlphaTooSmall); - } - } - - Ok(Dirichlet { alpha: a }) - } - - /// Construct a new `Dirichlet` with the given shape parameter `alpha` and `size`. - /// - /// Requires `size >= 2`. - #[inline] - pub fn new_with_size(alpha: N, size: usize) -> Result, Error> { - if !(alpha > N::from(0.0)) { - return Err(Error::AlphaTooSmall); - } - if size < 2 { - return Err(Error::SizeTooSmall); - } - Ok(Dirichlet { - alpha: vec![alpha; size], - }) - } -} - -impl Distribution> for Dirichlet -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - fn sample(&self, rng: &mut R) -> Vec { - let n = self.alpha.len(); - let mut samples = vec![N::from(0.0); n]; - let mut sum = N::from(0.0); - - for (s, &a) in samples.iter_mut().zip(self.alpha.iter()) { - let g = Gamma::new(a, N::from(1.0)).unwrap(); - *s = g.sample(rng); - sum += *s; - } - let invacc = N::from(1.0) / sum; - for s in samples.iter_mut() { - *s *= invacc; - } - samples - } -} - -#[cfg(test)] -mod test { - use super::Dirichlet; - use crate::Distribution; - - #[test] - fn test_dirichlet() { - let d = Dirichlet::new(vec![1.0, 2.0, 3.0]).unwrap(); - let mut rng = crate::test::rng(221); - let samples = d.sample(&mut rng); - let _: Vec = samples - .into_iter() - .map(|x| { - assert!(x > 0.0); - x - }) - .collect(); - } - - #[test] - fn test_dirichlet_with_param() { - let alpha = 0.5f64; - let size = 2; - let d = Dirichlet::new_with_size(alpha, size).unwrap(); - let mut rng = crate::test::rng(221); - let samples = d.sample(&mut rng); - let _: Vec = samples - .into_iter() - .map(|x| { - assert!(x > 0.0); - x - }) - .collect(); - } - - #[test] - #[should_panic] - fn test_dirichlet_invalid_length() { - Dirichlet::new_with_size(0.5f64, 1).unwrap(); - } - - #[test] - #[should_panic] - fn test_dirichlet_invalid_alpha() { - Dirichlet::new_with_size(0.0f64, 2).unwrap(); - } -} diff --git a/rand/rand_distr/src/exponential.rs b/rand/rand_distr/src/exponential.rs deleted file mode 100644 index 8322489..0000000 --- a/rand/rand_distr/src/exponential.rs +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The exponential distribution. - -use rand::Rng; -use crate::{ziggurat_tables, Distribution}; -use crate::utils::{ziggurat, Float}; - -/// Samples floating-point numbers according to the exponential distribution, -/// with rate parameter `λ = 1`. This is equivalent to `Exp::new(1.0)` or -/// sampling with `-rng.gen::().ln()`, but faster. -/// -/// See `Exp` for the general exponential distribution. -/// -/// Implemented via the ZIGNOR variant[^1] of the Ziggurat method. The exact -/// description in the paper was adjusted to use tables for the exponential -/// distribution rather than normal. -/// -/// [^1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to -/// Generate Normal Random Samples*]( -/// https://www.doornik.com/research/ziggurat.pdf). -/// Nuffield College, Oxford -/// -/// # Example -/// ``` -/// use rand::prelude::*; -/// use rand_distr::Exp1; -/// -/// let val: f64 = thread_rng().sample(Exp1); -/// println!("{}", val); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct Exp1; - -impl Distribution for Exp1 { - #[inline] - fn sample(&self, rng: &mut R) -> f32 { - // TODO: use optimal 32-bit implementation - let x: f64 = self.sample(rng); - x as f32 - } -} - -// This could be done via `-rng.gen::().ln()` but that is slower. -impl Distribution for Exp1 { - #[inline] - fn sample(&self, rng: &mut R) -> f64 { - #[inline] - fn pdf(x: f64) -> f64 { - (-x).exp() - } - #[inline] - fn zero_case(rng: &mut R, _u: f64) -> f64 { - ziggurat_tables::ZIG_EXP_R - rng.gen::().ln() - } - - ziggurat(rng, false, - &ziggurat_tables::ZIG_EXP_X, - &ziggurat_tables::ZIG_EXP_F, - pdf, zero_case) - } -} - -/// The exponential distribution `Exp(lambda)`. -/// -/// This distribution has density function: `f(x) = lambda * exp(-lambda * x)` -/// for `x > 0`. -/// -/// Note that [`Exp1`](crate::Exp1) is an optimised implementation for `lambda = 1`. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{Exp, Distribution}; -/// -/// let exp = Exp::new(2.0).unwrap(); -/// let v = exp.sample(&mut rand::thread_rng()); -/// println!("{} is from a Exp(2) distribution", v); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct Exp { - /// `lambda` stored as `1/lambda`, since this is what we scale by. - lambda_inverse: N -} - -/// Error type returned from `Exp::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `lambda <= 0` or `nan`. - LambdaTooSmall, -} - -impl Exp -where Exp1: Distribution -{ - /// Construct a new `Exp` with the given shape parameter - /// `lambda`. - #[inline] - pub fn new(lambda: N) -> Result, Error> { - if !(lambda > N::from(0.0)) { - return Err(Error::LambdaTooSmall); - } - Ok(Exp { lambda_inverse: N::from(1.0) / lambda }) - } -} - -impl Distribution for Exp -where Exp1: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - rng.sample(Exp1) * self.lambda_inverse - } -} - -#[cfg(test)] -mod test { - use crate::Distribution; - use super::Exp; - - #[test] - fn test_exp() { - let exp = Exp::new(10.0).unwrap(); - let mut rng = crate::test::rng(221); - for _ in 0..1000 { - assert!(exp.sample(&mut rng) >= 0.0); - } - } - #[test] - #[should_panic] - fn test_exp_invalid_lambda_zero() { - Exp::new(0.0).unwrap(); - } - #[test] - #[should_panic] - fn test_exp_invalid_lambda_neg() { - Exp::new(-10.0).unwrap(); - } -} diff --git a/rand/rand_distr/src/gamma.rs b/rand/rand_distr/src/gamma.rs deleted file mode 100644 index 4018361..0000000 --- a/rand/rand_distr/src/gamma.rs +++ /dev/null @@ -1,485 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Gamma and derived distributions. - -use self::GammaRepr::*; -use self::ChiSquaredRepr::*; - -use rand::Rng; -use crate::normal::StandardNormal; -use crate::{Distribution, Exp1, Exp, Open01}; -use crate::utils::Float; - -/// The Gamma distribution `Gamma(shape, scale)` distribution. -/// -/// The density function of this distribution is -/// -/// ```text -/// f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k) -/// ``` -/// -/// where `Γ` is the Gamma function, `k` is the shape and `θ` is the -/// scale and both `k` and `θ` are strictly positive. -/// -/// The algorithm used is that described by Marsaglia & Tsang 2000[^1], -/// falling back to directly sampling from an Exponential for `shape -/// == 1`, and using the boosting technique described in that paper for -/// `shape < 1`. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{Distribution, Gamma}; -/// -/// let gamma = Gamma::new(2.0, 5.0).unwrap(); -/// let v = gamma.sample(&mut rand::thread_rng()); -/// println!("{} is from a Gamma(2, 5) distribution", v); -/// ``` -/// -/// [^1]: George Marsaglia and Wai Wan Tsang. 2000. "A Simple Method for -/// Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3 -/// (September 2000), 363-372. -/// DOI:[10.1145/358407.358414](https://doi.acm.org/10.1145/358407.358414) -#[derive(Clone, Copy, Debug)] -pub struct Gamma { - repr: GammaRepr, -} - -/// Error type returned from `Gamma::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `shape <= 0` or `nan`. - ShapeTooSmall, - /// `scale <= 0` or `nan`. - ScaleTooSmall, - /// `1 / scale == 0`. - ScaleTooLarge, -} - -#[derive(Clone, Copy, Debug)] -enum GammaRepr { - Large(GammaLargeShape), - One(Exp), - Small(GammaSmallShape) -} - -// These two helpers could be made public, but saving the -// match-on-Gamma-enum branch from using them directly (e.g. if one -// knows that the shape is always > 1) doesn't appear to be much -// faster. - -/// Gamma distribution where the shape parameter is less than 1. -/// -/// Note, samples from this require a compulsory floating-point `pow` -/// call, which makes it significantly slower than sampling from a -/// gamma distribution where the shape parameter is greater than or -/// equal to 1. -/// -/// See `Gamma` for sampling from a Gamma distribution with general -/// shape parameters. -#[derive(Clone, Copy, Debug)] -struct GammaSmallShape { - inv_shape: N, - large_shape: GammaLargeShape -} - -/// Gamma distribution where the shape parameter is larger than 1. -/// -/// See `Gamma` for sampling from a Gamma distribution with general -/// shape parameters. -#[derive(Clone, Copy, Debug)] -struct GammaLargeShape { - scale: N, - c: N, - d: N -} - -impl Gamma -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - /// Construct an object representing the `Gamma(shape, scale)` - /// distribution. - #[inline] - pub fn new(shape: N, scale: N) -> Result, Error> { - if !(shape > N::from(0.0)) { - return Err(Error::ShapeTooSmall); - } - if !(scale > N::from(0.0)) { - return Err(Error::ScaleTooSmall); - } - - let repr = if shape == N::from(1.0) { - One(Exp::new(N::from(1.0) / scale).map_err(|_| Error::ScaleTooLarge)?) - } else if shape < N::from(1.0) { - Small(GammaSmallShape::new_raw(shape, scale)) - } else { - Large(GammaLargeShape::new_raw(shape, scale)) - }; - Ok(Gamma { repr }) - } -} - -impl GammaSmallShape -where StandardNormal: Distribution, Open01: Distribution -{ - fn new_raw(shape: N, scale: N) -> GammaSmallShape { - GammaSmallShape { - inv_shape: N::from(1.0) / shape, - large_shape: GammaLargeShape::new_raw(shape + N::from(1.0), scale) - } - } -} - -impl GammaLargeShape -where StandardNormal: Distribution, Open01: Distribution -{ - fn new_raw(shape: N, scale: N) -> GammaLargeShape { - let d = shape - N::from(1. / 3.); - GammaLargeShape { - scale, - c: N::from(1.0) / (N::from(9.) * d).sqrt(), - d - } - } -} - -impl Distribution for Gamma -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - match self.repr { - Small(ref g) => g.sample(rng), - One(ref g) => g.sample(rng), - Large(ref g) => g.sample(rng), - } - } -} -impl Distribution for GammaSmallShape -where StandardNormal: Distribution, Open01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - let u: N = rng.sample(Open01); - - self.large_shape.sample(rng) * u.powf(self.inv_shape) - } -} -impl Distribution for GammaLargeShape -where StandardNormal: Distribution, Open01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - // Marsaglia & Tsang method, 2000 - loop { - let x: N = rng.sample(StandardNormal); - let v_cbrt = N::from(1.0) + self.c * x; - if v_cbrt <= N::from(0.0) { // a^3 <= 0 iff a <= 0 - continue - } - - let v = v_cbrt * v_cbrt * v_cbrt; - let u: N = rng.sample(Open01); - - let x_sqr = x * x; - if u < N::from(1.0) - N::from(0.0331) * x_sqr * x_sqr || - u.ln() < N::from(0.5) * x_sqr + self.d * (N::from(1.0) - v + v.ln()) - { - return self.d * v * self.scale - } - } - } -} - -/// The chi-squared distribution `χ²(k)`, where `k` is the degrees of -/// freedom. -/// -/// For `k > 0` integral, this distribution is the sum of the squares -/// of `k` independent standard normal random variables. For other -/// `k`, this uses the equivalent characterisation -/// `χ²(k) = Gamma(k/2, 2)`. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{ChiSquared, Distribution}; -/// -/// let chi = ChiSquared::new(11.0).unwrap(); -/// let v = chi.sample(&mut rand::thread_rng()); -/// println!("{} is from a χ²(11) distribution", v) -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct ChiSquared { - repr: ChiSquaredRepr, -} - -/// Error type returned from `ChiSquared::new` and `StudentT::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum ChiSquaredError { - /// `0.5 * k <= 0` or `nan`. - DoFTooSmall, -} - -#[derive(Clone, Copy, Debug)] -enum ChiSquaredRepr { - // k == 1, Gamma(alpha, ..) is particularly slow for alpha < 1, - // e.g. when alpha = 1/2 as it would be for this case, so special- - // casing and using the definition of N(0,1)^2 is faster. - DoFExactlyOne, - DoFAnythingElse(Gamma), -} - -impl ChiSquared -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - /// Create a new chi-squared distribution with degrees-of-freedom - /// `k`. - pub fn new(k: N) -> Result, ChiSquaredError> { - let repr = if k == N::from(1.0) { - DoFExactlyOne - } else { - if !(N::from(0.5) * k > N::from(0.0)) { - return Err(ChiSquaredError::DoFTooSmall); - } - DoFAnythingElse(Gamma::new(N::from(0.5) * k, N::from(2.0)).unwrap()) - }; - Ok(ChiSquared { repr }) - } -} -impl Distribution for ChiSquared -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - match self.repr { - DoFExactlyOne => { - // k == 1 => N(0,1)^2 - let norm: N = rng.sample(StandardNormal); - norm * norm - } - DoFAnythingElse(ref g) => g.sample(rng) - } - } -} - -/// The Fisher F distribution `F(m, n)`. -/// -/// This distribution is equivalent to the ratio of two normalised -/// chi-squared distributions, that is, `F(m,n) = (χ²(m)/m) / -/// (χ²(n)/n)`. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{FisherF, Distribution}; -/// -/// let f = FisherF::new(2.0, 32.0).unwrap(); -/// let v = f.sample(&mut rand::thread_rng()); -/// println!("{} is from an F(2, 32) distribution", v) -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct FisherF { - numer: ChiSquared, - denom: ChiSquared, - // denom_dof / numer_dof so that this can just be a straight - // multiplication, rather than a division. - dof_ratio: N, -} - -/// Error type returned from `FisherF::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FisherFError { - /// `m <= 0` or `nan`. - MTooSmall, - /// `n <= 0` or `nan`. - NTooSmall, -} - -impl FisherF -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - /// Create a new `FisherF` distribution, with the given parameter. - pub fn new(m: N, n: N) -> Result, FisherFError> { - if !(m > N::from(0.0)) { - return Err(FisherFError::MTooSmall); - } - if !(n > N::from(0.0)) { - return Err(FisherFError::NTooSmall); - } - - Ok(FisherF { - numer: ChiSquared::new(m).unwrap(), - denom: ChiSquared::new(n).unwrap(), - dof_ratio: n / m - }) - } -} -impl Distribution for FisherF -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - self.numer.sample(rng) / self.denom.sample(rng) * self.dof_ratio - } -} - -/// The Student t distribution, `t(nu)`, where `nu` is the degrees of -/// freedom. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{StudentT, Distribution}; -/// -/// let t = StudentT::new(11.0).unwrap(); -/// let v = t.sample(&mut rand::thread_rng()); -/// println!("{} is from a t(11) distribution", v) -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct StudentT { - chi: ChiSquared, - dof: N -} - -impl StudentT -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - /// Create a new Student t distribution with `n` degrees of - /// freedom. - pub fn new(n: N) -> Result, ChiSquaredError> { - Ok(StudentT { - chi: ChiSquared::new(n)?, - dof: n - }) - } -} -impl Distribution for StudentT -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - let norm: N = rng.sample(StandardNormal); - norm * (self.dof / self.chi.sample(rng)).sqrt() - } -} - -/// The Beta distribution with shape parameters `alpha` and `beta`. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{Distribution, Beta}; -/// -/// let beta = Beta::new(2.0, 5.0).unwrap(); -/// let v = beta.sample(&mut rand::thread_rng()); -/// println!("{} is from a Beta(2, 5) distribution", v); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct Beta { - gamma_a: Gamma, - gamma_b: Gamma, -} - -/// Error type returned from `Beta::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum BetaError { - /// `alpha <= 0` or `nan`. - AlphaTooSmall, - /// `beta <= 0` or `nan`. - BetaTooSmall, -} - -impl Beta -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - /// Construct an object representing the `Beta(alpha, beta)` - /// distribution. - pub fn new(alpha: N, beta: N) -> Result, BetaError> { - Ok(Beta { - gamma_a: Gamma::new(alpha, N::from(1.)) - .map_err(|_| BetaError::AlphaTooSmall)?, - gamma_b: Gamma::new(beta, N::from(1.)) - .map_err(|_| BetaError::BetaTooSmall)?, - }) - } -} - -impl Distribution for Beta -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - let x = self.gamma_a.sample(rng); - let y = self.gamma_b.sample(rng); - x / (x + y) - } -} - -#[cfg(test)] -mod test { - use crate::Distribution; - use super::{Beta, ChiSquared, StudentT, FisherF}; - - #[test] - fn test_chi_squared_one() { - let chi = ChiSquared::new(1.0).unwrap(); - let mut rng = crate::test::rng(201); - for _ in 0..1000 { - chi.sample(&mut rng); - } - } - #[test] - fn test_chi_squared_small() { - let chi = ChiSquared::new(0.5).unwrap(); - let mut rng = crate::test::rng(202); - for _ in 0..1000 { - chi.sample(&mut rng); - } - } - #[test] - fn test_chi_squared_large() { - let chi = ChiSquared::new(30.0).unwrap(); - let mut rng = crate::test::rng(203); - for _ in 0..1000 { - chi.sample(&mut rng); - } - } - #[test] - #[should_panic] - fn test_chi_squared_invalid_dof() { - ChiSquared::new(-1.0).unwrap(); - } - - #[test] - fn test_f() { - let f = FisherF::new(2.0, 32.0).unwrap(); - let mut rng = crate::test::rng(204); - for _ in 0..1000 { - f.sample(&mut rng); - } - } - - #[test] - fn test_t() { - let t = StudentT::new(11.0).unwrap(); - let mut rng = crate::test::rng(205); - for _ in 0..1000 { - t.sample(&mut rng); - } - } - - #[test] - fn test_beta() { - let beta = Beta::new(1.0, 2.0).unwrap(); - let mut rng = crate::test::rng(201); - for _ in 0..1000 { - beta.sample(&mut rng); - } - } - - #[test] - #[should_panic] - fn test_beta_invalid_dof() { - Beta::new(0., 0.).unwrap(); - } -} diff --git a/rand/rand_distr/src/lib.rs b/rand/rand_distr/src/lib.rs deleted file mode 100644 index baf65ed..0000000 --- a/rand/rand_distr/src/lib.rs +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] - -#![allow(clippy::excessive_precision, clippy::float_cmp, clippy::unreadable_literal)] -#![allow(clippy::neg_cmp_op_on_partial_ord)] // suggested fix too verbose - -//! Generating random samples from probability distributions. -//! -//! ## Re-exports -//! -//! This crate is a super-set of the [`rand::distributions`] module. See the -//! [`rand::distributions`] module documentation for an overview of the core -//! [`Distribution`] trait and implementations. -//! -//! The following are re-exported: -//! -//! - The [`Distribution`] trait and [`DistIter`] helper type -//! - The [`Standard`], [`Alphanumeric`], [`Uniform`], [`OpenClosed01`], [`Open01`] and [`Bernoulli`] distributions -//! - The [`weighted`] sub-module -//! -//! ## Distributions -//! -//! This crate provides the following probability distributions: -//! -//! - Related to real-valued quantities that grow linearly -//! (e.g. errors, offsets): -//! - [`Normal`] distribution, and [`StandardNormal`] as a primitive -//! - [`Cauchy`] distribution -//! - Related to Bernoulli trials (yes/no events, with a given probability): -//! - [`Binomial`] distribution -//! - Related to positive real-valued quantities that grow exponentially -//! (e.g. prices, incomes, populations): -//! - [`LogNormal`] distribution -//! - Related to the occurrence of independent events at a given rate: -//! - [`Pareto`] distribution -//! - [`Poisson`] distribution -//! - [`Exp`]onential distribution, and [`Exp1`] as a primitive -//! - [`Weibull`] distribution -//! - Gamma and derived distributions: -//! - [`Gamma`] distribution -//! - [`ChiSquared`] distribution -//! - [`StudentT`] distribution -//! - [`FisherF`] distribution -//! - Triangular distribution: -//! - [`Beta`] distribution -//! - [`Triangular`] distribution -//! - Multivariate probability distributions -//! - [`Dirichlet`] distribution -//! - [`UnitSphere`] distribution -//! - [`UnitBall`] distribution -//! - [`UnitCircle`] distribution -//! - [`UnitDisc`] distribution - -pub use rand::distributions::{Distribution, DistIter, Standard, - Alphanumeric, Uniform, OpenClosed01, Open01, Bernoulli, uniform, weighted}; - -pub use self::unit_sphere::UnitSphere; -pub use self::unit_ball::UnitBall; -pub use self::unit_circle::UnitCircle; -pub use self::unit_disc::UnitDisc; -pub use self::gamma::{Gamma, Error as GammaError, ChiSquared, ChiSquaredError, - FisherF, FisherFError, StudentT, Beta, BetaError}; -pub use self::normal::{Normal, Error as NormalError, LogNormal, StandardNormal}; -pub use self::exponential::{Exp, Error as ExpError, Exp1}; -pub use self::pareto::{Pareto, Error as ParetoError}; -pub use self::pert::{Pert, PertError}; -pub use self::poisson::{Poisson, Error as PoissonError}; -pub use self::binomial::{Binomial, Error as BinomialError}; -pub use self::cauchy::{Cauchy, Error as CauchyError}; -pub use self::dirichlet::{Dirichlet, Error as DirichletError}; -pub use self::triangular::{Triangular, TriangularError}; -pub use self::weibull::{Weibull, Error as WeibullError}; -pub use self::utils::Float; - -mod unit_sphere; -mod unit_ball; -mod unit_circle; -mod unit_disc; -mod gamma; -mod normal; -mod exponential; -mod pareto; -mod pert; -mod poisson; -mod binomial; -mod cauchy; -mod dirichlet; -mod triangular; -mod weibull; -mod utils; -mod ziggurat_tables; - -#[cfg(test)] -mod test { - // Notes on testing - // - // Testing random number distributions correctly is hard. The following - // testing is desired: - // - // - Construction: test initialisation with a few valid parameter sets. - // - Erroneous usage: test that incorrect usage generates an error. - // - Vector: test that usage with fixed inputs (including RNG) generates a - // fixed output sequence on all platforms. - // - Correctness at fixed points (optional): using a specific mock RNG, - // check that specific values are sampled (e.g. end-points and median of - // distribution). - // - Correctness of PDF (extra): generate a histogram of samples within a - // certain range, and check this approximates the PDF. These tests are - // expected to be expensive, and should be behind a feature-gate. - // - // TODO: Vector and correctness tests are largely absent so far. - // NOTE: Some distributions have tests checking only that samples can be - // generated. This is redundant with vector and correctness tests. - - /// Construct a deterministic RNG with the given seed - pub fn rng(seed: u64) -> impl rand::RngCore { - // For tests, we want a statistically good, fast, reproducible RNG. - // PCG32 will do fine, and will be easy to embed if we ever need to. - const INC: u64 = 11634580027462260723; - rand_pcg::Pcg32::new(seed, INC) - } -} diff --git a/rand/rand_distr/src/normal.rs b/rand/rand_distr/src/normal.rs deleted file mode 100644 index 882754f..0000000 --- a/rand/rand_distr/src/normal.rs +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The normal and derived distributions. - -use rand::Rng; -use crate::{ziggurat_tables, Distribution, Open01}; -use crate::utils::{ziggurat, Float}; - -/// Samples floating-point numbers according to the normal distribution -/// `N(0, 1)` (a.k.a. a standard normal, or Gaussian). This is equivalent to -/// `Normal::new(0.0, 1.0)` but faster. -/// -/// See `Normal` for the general normal distribution. -/// -/// Implemented via the ZIGNOR variant[^1] of the Ziggurat method. -/// -/// [^1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to -/// Generate Normal Random Samples*]( -/// https://www.doornik.com/research/ziggurat.pdf). -/// Nuffield College, Oxford -/// -/// # Example -/// ``` -/// use rand::prelude::*; -/// use rand_distr::StandardNormal; -/// -/// let val: f64 = thread_rng().sample(StandardNormal); -/// println!("{}", val); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct StandardNormal; - -impl Distribution for StandardNormal { - #[inline] - fn sample(&self, rng: &mut R) -> f32 { - // TODO: use optimal 32-bit implementation - let x: f64 = self.sample(rng); - x as f32 - } -} - -impl Distribution for StandardNormal { - fn sample(&self, rng: &mut R) -> f64 { - #[inline] - fn pdf(x: f64) -> f64 { - (-x*x/2.0).exp() - } - #[inline] - fn zero_case(rng: &mut R, u: f64) -> f64 { - // compute a random number in the tail by hand - - // strange initial conditions, because the loop is not - // do-while, so the condition should be true on the first - // run, they get overwritten anyway (0 < 1, so these are - // good). - let mut x = 1.0f64; - let mut y = 0.0f64; - - while -2.0 * y < x * x { - let x_: f64 = rng.sample(Open01); - let y_: f64 = rng.sample(Open01); - - x = x_.ln() / ziggurat_tables::ZIG_NORM_R; - y = y_.ln(); - } - - if u < 0.0 { x - ziggurat_tables::ZIG_NORM_R } else { ziggurat_tables::ZIG_NORM_R - x } - } - - ziggurat(rng, true, // this is symmetric - &ziggurat_tables::ZIG_NORM_X, - &ziggurat_tables::ZIG_NORM_F, - pdf, zero_case) - } -} - -/// The normal distribution `N(mean, std_dev**2)`. -/// -/// This uses the ZIGNOR variant of the Ziggurat method, see [`StandardNormal`] -/// for more details. -/// -/// Note that [`StandardNormal`] is an optimised implementation for mean 0, and -/// standard deviation 1. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{Normal, Distribution}; -/// -/// // mean 2, standard deviation 3 -/// let normal = Normal::new(2.0, 3.0).unwrap(); -/// let v = normal.sample(&mut rand::thread_rng()); -/// println!("{} is from a N(2, 9) distribution", v) -/// ``` -/// -/// [`StandardNormal`]: crate::StandardNormal -#[derive(Clone, Copy, Debug)] -pub struct Normal { - mean: N, - std_dev: N, -} - -/// Error type returned from `Normal::new` and `LogNormal::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `std_dev < 0` or `nan`. - StdDevTooSmall, -} - -impl Normal -where StandardNormal: Distribution -{ - /// Construct a new `Normal` distribution with the given mean and - /// standard deviation. - #[inline] - pub fn new(mean: N, std_dev: N) -> Result, Error> { - if !(std_dev >= N::from(0.0)) { - return Err(Error::StdDevTooSmall); - } - Ok(Normal { - mean, - std_dev - }) - } -} - -impl Distribution for Normal -where StandardNormal: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - let n: N = rng.sample(StandardNormal); - self.mean + self.std_dev * n - } -} - - -/// The log-normal distribution `ln N(mean, std_dev**2)`. -/// -/// If `X` is log-normal distributed, then `ln(X)` is `N(mean, std_dev**2)` -/// distributed. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{LogNormal, Distribution}; -/// -/// // mean 2, standard deviation 3 -/// let log_normal = LogNormal::new(2.0, 3.0).unwrap(); -/// let v = log_normal.sample(&mut rand::thread_rng()); -/// println!("{} is from an ln N(2, 9) distribution", v) -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct LogNormal { - norm: Normal -} - -impl LogNormal -where StandardNormal: Distribution -{ - /// Construct a new `LogNormal` distribution with the given mean - /// and standard deviation of the logarithm of the distribution. - #[inline] - pub fn new(mean: N, std_dev: N) -> Result, Error> { - if !(std_dev >= N::from(0.0)) { - return Err(Error::StdDevTooSmall); - } - Ok(LogNormal { norm: Normal::new(mean, std_dev).unwrap() }) - } -} - -impl Distribution for LogNormal -where StandardNormal: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - self.norm.sample(rng).exp() - } -} - -#[cfg(test)] -mod tests { - use crate::Distribution; - use super::{Normal, LogNormal}; - - #[test] - fn test_normal() { - let norm = Normal::new(10.0, 10.0).unwrap(); - let mut rng = crate::test::rng(210); - for _ in 0..1000 { - norm.sample(&mut rng); - } - } - #[test] - #[should_panic] - fn test_normal_invalid_sd() { - Normal::new(10.0, -1.0).unwrap(); - } - - - #[test] - fn test_log_normal() { - let lnorm = LogNormal::new(10.0, 10.0).unwrap(); - let mut rng = crate::test::rng(211); - for _ in 0..1000 { - lnorm.sample(&mut rng); - } - } - #[test] - #[should_panic] - fn test_log_normal_invalid_sd() { - LogNormal::new(10.0, -1.0).unwrap(); - } -} diff --git a/rand/rand_distr/src/pareto.rs b/rand/rand_distr/src/pareto.rs deleted file mode 100644 index 33ea382..0000000 --- a/rand/rand_distr/src/pareto.rs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Pareto distribution. - -use rand::Rng; -use crate::{Distribution, OpenClosed01}; -use crate::utils::Float; - -/// Samples floating-point numbers according to the Pareto distribution -/// -/// # Example -/// ``` -/// use rand::prelude::*; -/// use rand_distr::Pareto; -/// -/// let val: f64 = thread_rng().sample(Pareto::new(1., 2.).unwrap()); -/// println!("{}", val); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct Pareto { - scale: N, - inv_neg_shape: N, -} - -/// Error type returned from `Pareto::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `scale <= 0` or `nan`. - ScaleTooSmall, - /// `shape <= 0` or `nan`. - ShapeTooSmall, -} - -impl Pareto -where OpenClosed01: Distribution -{ - /// Construct a new Pareto distribution with given `scale` and `shape`. - /// - /// In the literature, `scale` is commonly written as xm or k and - /// `shape` is often written as α. - pub fn new(scale: N, shape: N) -> Result, Error> { - if !(scale > N::from(0.0)) { - return Err(Error::ScaleTooSmall); - } - if !(shape > N::from(0.0)) { - return Err(Error::ShapeTooSmall); - } - Ok(Pareto { scale, inv_neg_shape: N::from(-1.0) / shape }) - } -} - -impl Distribution for Pareto -where OpenClosed01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - let u: N = OpenClosed01.sample(rng); - self.scale * u.powf(self.inv_neg_shape) - } -} - -#[cfg(test)] -mod tests { - use crate::Distribution; - use super::Pareto; - - #[test] - #[should_panic] - fn invalid() { - Pareto::new(0., 0.).unwrap(); - } - - #[test] - fn sample() { - let scale = 1.0; - let shape = 2.0; - let d = Pareto::new(scale, shape).unwrap(); - let mut rng = crate::test::rng(1); - for _ in 0..1000 { - let r = d.sample(&mut rng); - assert!(r >= scale); - } - } -} diff --git a/rand/rand_distr/src/pert.rs b/rand/rand_distr/src/pert.rs deleted file mode 100644 index 040cd05..0000000 --- a/rand/rand_distr/src/pert.rs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -//! The PERT distribution. - -use rand::Rng; -use crate::{Distribution, Beta, StandardNormal, Exp1, Open01}; -use crate::utils::Float; - -/// The PERT distribution. -/// -/// Similar to the [`Triangular`] distribution, the PERT distribution is -/// parameterised by a range and a mode within that range. Unlike the -/// [`Triangular`] distribution, the probability density function of the PERT -/// distribution is smooth, with a configurable weighting around the mode. -/// -/// # Example -/// -/// ```rust -/// use rand_distr::{Pert, Distribution}; -/// -/// let d = Pert::new(0., 5., 2.5).unwrap(); -/// let v = d.sample(&mut rand::thread_rng()); -/// println!("{} is from a PERT distribution", v); -/// ``` -/// -/// [`Triangular`]: crate::Triangular -#[derive(Clone, Copy, Debug)] -pub struct Pert { - min: N, - range: N, - beta: Beta, -} - -/// Error type returned from [`Pert`] constructors. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum PertError { - /// `max < min` or `min` or `max` is NaN. - RangeTooSmall, - /// `mode < min` or `mode > max` or `mode` is NaN. - ModeRange, - /// `shape < 0` or `shape` is NaN - ShapeTooSmall, -} - -impl Pert -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - /// Set up the PERT distribution with defined `min`, `max` and `mode`. - /// - /// This is equivalent to calling `Pert::new_shape` with `shape == 4.0`. - #[inline] - pub fn new(min: N, max: N, mode: N) -> Result, PertError> { - Pert::new_with_shape(min, max, mode, N::from(4.)) - } - - /// Set up the PERT distribution with defined `min`, `max`, `mode` and - /// `shape`. - pub fn new_with_shape(min: N, max: N, mode: N, shape: N) -> Result, PertError> { - if !(max > min) { - return Err(PertError::RangeTooSmall); - } - if !(mode >= min && max >= mode) { - return Err(PertError::ModeRange); - } - if !(shape >= N::from(0.)) { - return Err(PertError::ShapeTooSmall); - } - - let range = max - min; - let mu = (min + max + shape * mode) / (shape + N::from(2.)); - let v = if mu == mode { - shape * N::from(0.5) + N::from(1.) - } else { - (mu - min) * (N::from(2.) * mode - min - max) - / ((mode - mu) * (max - min)) - }; - let w = v * (max - mu) / (mu - min); - let beta = Beta::new(v, w).map_err(|_| PertError::RangeTooSmall)?; - Ok(Pert{ min, range, beta }) - } -} - -impl Distribution for Pert -where StandardNormal: Distribution, Exp1: Distribution, Open01: Distribution -{ - #[inline] - fn sample(&self, rng: &mut R) -> N { - self.beta.sample(rng) * self.range + self.min - } -} - -#[cfg(test)] -mod test { - use std::f64; - use super::*; - - #[test] - fn test_pert() { - for &(min, max, mode) in &[ - (-1., 1., 0.), - (1., 2., 1.), - (5., 25., 25.), - ] { - let _distr = Pert::new(min, max, mode).unwrap(); - // TODO: test correctness - } - - for &(min, max, mode) in &[ - (-1., 1., 2.), - (-1., 1., -2.), - (2., 1., 1.), - ] { - assert!(Pert::new(min, max, mode).is_err()); - } - } - - #[test] - fn value_stability() { - let rng = crate::test::rng(860); - let distr = Pert::new(2., 10., 3.).unwrap(); // mean = 4, var = 12/7 - let seq = distr.sample_iter(rng).take(5).collect::>(); - println!("seq: {:?}", seq); - let expected = vec![4.631484136029422, 3.307201472321789, - 3.29995019556348, 3.66835483991721, 3.514246139933899]; - assert!(seq == expected); - } -} diff --git a/rand/rand_distr/src/poisson.rs b/rand/rand_distr/src/poisson.rs deleted file mode 100644 index 4f4a0b7..0000000 --- a/rand/rand_distr/src/poisson.rs +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2016-2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Poisson distribution. - -use rand::Rng; -use crate::{Distribution, Cauchy, Standard}; -use crate::utils::Float; - -/// The Poisson distribution `Poisson(lambda)`. -/// -/// This distribution has a density function: -/// `f(k) = lambda^k * exp(-lambda) / k!` for `k >= 0`. -/// -/// # Example -/// -/// ``` -/// use rand_distr::{Poisson, Distribution}; -/// -/// let poi = Poisson::new(2.0).unwrap(); -/// let v: u64 = poi.sample(&mut rand::thread_rng()); -/// println!("{} is from a Poisson(2) distribution", v); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct Poisson { - lambda: N, - // precalculated values - exp_lambda: N, - log_lambda: N, - sqrt_2lambda: N, - magic_val: N, -} - -/// Error type returned from `Poisson::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `lambda <= 0` or `nan`. - ShapeTooSmall, -} - -impl Poisson -where Standard: Distribution -{ - /// Construct a new `Poisson` with the given shape parameter - /// `lambda`. - pub fn new(lambda: N) -> Result, Error> { - if !(lambda > N::from(0.0)) { - return Err(Error::ShapeTooSmall); - } - let log_lambda = lambda.ln(); - Ok(Poisson { - lambda, - exp_lambda: (-lambda).exp(), - log_lambda, - sqrt_2lambda: (N::from(2.0) * lambda).sqrt(), - magic_val: lambda * log_lambda - (N::from(1.0) + lambda).log_gamma(), - }) - } -} - -impl Distribution for Poisson -where Standard: Distribution -{ - #[inline] - fn sample(&self, rng: &mut R) -> N { - // using the algorithm from Numerical Recipes in C - - // for low expected values use the Knuth method - if self.lambda < N::from(12.0) { - let mut result = N::from(0.); - let mut p = N::from(1.0); - while p > self.exp_lambda { - p *= rng.gen::(); - result += N::from(1.); - } - result - N::from(1.) - } - // high expected values - rejection method - else { - // we use the Cauchy distribution as the comparison distribution - // f(x) ~ 1/(1+x^2) - let cauchy = Cauchy::new(N::from(0.0), N::from(1.0)).unwrap(); - let mut result; - - loop { - let mut comp_dev; - - loop { - // draw from the Cauchy distribution - comp_dev = rng.sample(cauchy); - // shift the peak of the comparison ditribution - result = self.sqrt_2lambda * comp_dev + self.lambda; - // repeat the drawing until we are in the range of possible values - if result >= N::from(0.0) { - break; - } - } - // now the result is a random variable greater than 0 with Cauchy distribution - // the result should be an integer value - result = result.floor(); - - // this is the ratio of the Poisson distribution to the comparison distribution - // the magic value scales the distribution function to a range of approximately 0-1 - // since it is not exact, we multiply the ratio by 0.9 to avoid ratios greater than 1 - // this doesn't change the resulting distribution, only increases the rate of failed drawings - let check = N::from(0.9) * (N::from(1.0) + comp_dev * comp_dev) - * (result * self.log_lambda - (N::from(1.0) + result).log_gamma() - self.magic_val).exp(); - - // check with uniform random value - if below the threshold, we are within the target distribution - if rng.gen::() <= check { - break; - } - } - result - } - } -} - -impl Distribution for Poisson -where Standard: Distribution -{ - #[inline] - fn sample(&self, rng: &mut R) -> u64 { - let result: N = self.sample(rng); - result.to_u64().unwrap() - } -} - -#[cfg(test)] -mod test { - use crate::Distribution; - use super::Poisson; - - #[test] - fn test_poisson_10() { - let poisson = Poisson::new(10.0).unwrap(); - let mut rng = crate::test::rng(123); - let mut sum_u64 = 0; - let mut sum_f64 = 0.; - for _ in 0..1000 { - let s_u64: u64 = poisson.sample(&mut rng); - let s_f64: f64 = poisson.sample(&mut rng); - sum_u64 += s_u64; - sum_f64 += s_f64; - } - let avg_u64 = (sum_u64 as f64) / 1000.0; - let avg_f64 = sum_f64 / 1000.0; - println!("Poisson averages: {} (u64) {} (f64)", avg_u64, avg_f64); - for &avg in &[avg_u64, avg_f64] { - assert!((avg - 10.0).abs() < 0.5); // not 100% certain, but probable enough - } - } - - #[test] - fn test_poisson_15() { - // Take the 'high expected values' path - let poisson = Poisson::new(15.0).unwrap(); - let mut rng = crate::test::rng(123); - let mut sum_u64 = 0; - let mut sum_f64 = 0.; - for _ in 0..1000 { - let s_u64: u64 = poisson.sample(&mut rng); - let s_f64: f64 = poisson.sample(&mut rng); - sum_u64 += s_u64; - sum_f64 += s_f64; - } - let avg_u64 = (sum_u64 as f64) / 1000.0; - let avg_f64 = sum_f64 / 1000.0; - println!("Poisson average: {} (u64) {} (f64)", avg_u64, avg_f64); - for &avg in &[avg_u64, avg_f64] { - assert!((avg - 15.0).abs() < 0.5); // not 100% certain, but probable enough - } - } - - #[test] - fn test_poisson_10_f32() { - let poisson = Poisson::new(10.0f32).unwrap(); - let mut rng = crate::test::rng(123); - let mut sum_u64 = 0; - let mut sum_f32 = 0.; - for _ in 0..1000 { - let s_u64: u64 = poisson.sample(&mut rng); - let s_f32: f32 = poisson.sample(&mut rng); - sum_u64 += s_u64; - sum_f32 += s_f32; - } - let avg_u64 = (sum_u64 as f32) / 1000.0; - let avg_f32 = sum_f32 / 1000.0; - println!("Poisson averages: {} (u64) {} (f32)", avg_u64, avg_f32); - for &avg in &[avg_u64, avg_f32] { - assert!((avg - 10.0).abs() < 0.5); // not 100% certain, but probable enough - } - } - - #[test] - fn test_poisson_15_f32() { - // Take the 'high expected values' path - let poisson = Poisson::new(15.0f32).unwrap(); - let mut rng = crate::test::rng(123); - let mut sum_u64 = 0; - let mut sum_f32 = 0.; - for _ in 0..1000 { - let s_u64: u64 = poisson.sample(&mut rng); - let s_f32: f32 = poisson.sample(&mut rng); - sum_u64 += s_u64; - sum_f32 += s_f32; - } - let avg_u64 = (sum_u64 as f32) / 1000.0; - let avg_f32 = sum_f32 / 1000.0; - println!("Poisson average: {} (u64) {} (f32)", avg_u64, avg_f32); - for &avg in &[avg_u64, avg_f32] { - assert!((avg - 15.0).abs() < 0.5); // not 100% certain, but probable enough - } - } - - #[test] - #[should_panic] - fn test_poisson_invalid_lambda_zero() { - Poisson::new(0.0).unwrap(); - } - - #[test] - #[should_panic] - fn test_poisson_invalid_lambda_neg() { - Poisson::new(-10.0).unwrap(); - } -} diff --git a/rand/rand_distr/src/triangular.rs b/rand/rand_distr/src/triangular.rs deleted file mode 100644 index dd0bbfb..0000000 --- a/rand/rand_distr/src/triangular.rs +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -//! The triangular distribution. - -use rand::Rng; -use crate::{Distribution, Standard}; -use crate::utils::Float; - -/// The triangular distribution. -/// -/// A continuous probability distribution parameterised by a range, and a mode -/// (most likely value) within that range. -/// -/// The probability density function is triangular. For a similar distribution -/// with a smooth PDF, see the [`Pert`] distribution. -/// -/// # Example -/// -/// ```rust -/// use rand_distr::{Triangular, Distribution}; -/// -/// let d = Triangular::new(0., 5., 2.5).unwrap(); -/// let v = d.sample(&mut rand::thread_rng()); -/// println!("{} is from a triangular distribution", v); -/// ``` -/// -/// [`Pert`]: crate::Pert -#[derive(Clone, Copy, Debug)] -pub struct Triangular { - min: N, - max: N, - mode: N, -} - -/// Error type returned from [`Triangular::new`]. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum TriangularError { - /// `max < min` or `min` or `max` is NaN. - RangeTooSmall, - /// `mode < min` or `mode > max` or `mode` is NaN. - ModeRange, -} - -impl Triangular -where Standard: Distribution -{ - /// Set up the Triangular distribution with defined `min`, `max` and `mode`. - #[inline] - pub fn new(min: N, max: N, mode: N) -> Result, TriangularError> { - if !(max >= min) { - return Err(TriangularError::RangeTooSmall); - } - if !(mode >= min && max >= mode) { - return Err(TriangularError::ModeRange); - } - Ok(Triangular { min, max, mode }) - } -} - -impl Distribution for Triangular -where Standard: Distribution -{ - #[inline] - fn sample(&self, rng: &mut R) -> N { - let f: N = rng.sample(Standard); - let diff_mode_min = self.mode - self.min; - let range = self.max - self.min; - let f_range = f * range; - if f_range < diff_mode_min { - self.min + (f_range * diff_mode_min).sqrt() - } else { - self.max - ((range - f_range) * (self.max - self.mode)).sqrt() - } - } -} - -#[cfg(test)] -mod test { - use std::f64; - use rand::{Rng, rngs::mock}; - use super::*; - - #[test] - fn test_triangular() { - let mut half_rng = mock::StepRng::new(0x8000_0000_0000_0000, 0); - assert_eq!(half_rng.gen::(), 0.5); - for &(min, max, mode, median) in &[ - (-1., 1., 0., 0.), - (1., 2., 1., 2. - 0.5f64.sqrt()), - (5., 25., 25., 5. + 200f64.sqrt()), - (1e-5, 1e5, 1e-3, 1e5 - 4999999949.5f64.sqrt()), - (0., 1., 0.9, 0.45f64.sqrt()), - (-4., -0.5, -2., -4.0 + 3.5f64.sqrt()), - ] { - println!("{} {} {} {}", min, max, mode, median); - let distr = Triangular::new(min, max, mode).unwrap(); - // Test correct value at median: - assert_eq!(distr.sample(&mut half_rng), median); - } - - for &(min, max, mode) in &[ - (-1., 1., 2.), - (-1., 1., -2.), - (2., 1., 1.), - ] { - assert!(Triangular::new(min, max, mode).is_err()); - } - } - - #[test] - fn value_stability() { - let rng = crate::test::rng(860); - let distr = Triangular::new(2., 10., 3.).unwrap(); - let seq = distr.sample_iter(rng).take(5).collect::>(); - println!("seq: {:?}", seq); - let expected = vec![5.74373257511361, 7.890059162791258, - 4.7256280652553455, 2.9474808121184077, 3.058301946314053]; - assert!(seq == expected); - } -} diff --git a/rand/rand_distr/src/unit_ball.rs b/rand/rand_distr/src/unit_ball.rs deleted file mode 100644 index 9d61627..0000000 --- a/rand/rand_distr/src/unit_ball.rs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rand::Rng; -use crate::{Distribution, Uniform, uniform::SampleUniform}; -use crate::utils::Float; - -/// Samples uniformly from the unit ball (surface and interior) in three -/// dimensions. -/// -/// Implemented via rejection sampling. -/// -/// -/// # Example -/// -/// ``` -/// use rand_distr::{UnitBall, Distribution}; -/// -/// let v: [f64; 3] = UnitBall.sample(&mut rand::thread_rng()); -/// println!("{:?} is from the unit ball.", v) -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct UnitBall; - -impl Distribution<[N; 3]> for UnitBall { - #[inline] - fn sample(&self, rng: &mut R) -> [N; 3] { - let uniform = Uniform::new(N::from(-1.), N::from(1.)); - let mut x1; - let mut x2; - let mut x3; - loop { - x1 = uniform.sample(rng); - x2 = uniform.sample(rng); - x3 = uniform.sample(rng); - if x1*x1 + x2*x2 + x3*x3 <= N::from(1.) { - break; - } - } - [x1, x2, x3] - } -} - -#[cfg(test)] -mod tests { - use crate::Distribution; - use super::UnitBall; - - #[test] - fn value_stability() { - let mut rng = crate::test::rng(2); - let expected = [ - [0.018035709265959987, -0.4348771383120438, -0.07982762085055706], - [0.10588569388223945, -0.4734350111375454, -0.7392104908825501], - [0.11060237642041049, -0.16065642822852677, -0.8444043930440075] - ]; - let samples: [[f64; 3]; 3] = [ - UnitBall.sample(&mut rng), - UnitBall.sample(&mut rng), - UnitBall.sample(&mut rng), - ]; - assert_eq!(samples, expected); - } -} diff --git a/rand/rand_distr/src/unit_circle.rs b/rand/rand_distr/src/unit_circle.rs deleted file mode 100644 index 5863a1a..0000000 --- a/rand/rand_distr/src/unit_circle.rs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rand::Rng; -use crate::{Distribution, Uniform, uniform::SampleUniform}; -use crate::utils::Float; - -/// Samples uniformly from the edge of the unit circle in two dimensions. -/// -/// Implemented via a method by von Neumann[^1]. -/// -/// -/// # Example -/// -/// ``` -/// use rand_distr::{UnitCircle, Distribution}; -/// -/// let v: [f64; 2] = UnitCircle.sample(&mut rand::thread_rng()); -/// println!("{:?} is from the unit circle.", v) -/// ``` -/// -/// [^1]: von Neumann, J. (1951) [*Various Techniques Used in Connection with -/// Random Digits.*](https://mcnp.lanl.gov/pdf_files/nbs_vonneumann.pdf) -/// NBS Appl. Math. Ser., No. 12. Washington, DC: U.S. Government Printing -/// Office, pp. 36-38. -#[derive(Clone, Copy, Debug)] -pub struct UnitCircle; - -impl Distribution<[N; 2]> for UnitCircle { - #[inline] - fn sample(&self, rng: &mut R) -> [N; 2] { - let uniform = Uniform::new(N::from(-1.), N::from(1.)); - let mut x1; - let mut x2; - let mut sum; - loop { - x1 = uniform.sample(rng); - x2 = uniform.sample(rng); - sum = x1*x1 + x2*x2; - if sum < N::from(1.) { - break; - } - } - let diff = x1*x1 - x2*x2; - [diff / sum, N::from(2.)*x1*x2 / sum] - } -} - -#[cfg(test)] -mod tests { - use crate::Distribution; - use super::UnitCircle; - - /// Assert that two numbers are almost equal to each other. - /// - /// On panic, this macro will print the values of the expressions with their - /// debug representations. - macro_rules! assert_almost_eq { - ($a:expr, $b:expr, $prec:expr) => ( - let diff = ($a - $b).abs(); - if diff > $prec { - panic!(format!( - "assertion failed: `abs(left - right) = {:.1e} < {:e}`, \ - (left: `{}`, right: `{}`)", - diff, $prec, $a, $b)); - } - ); - } - - #[test] - fn norm() { - let mut rng = crate::test::rng(1); - for _ in 0..1000 { - let x: [f64; 2] = UnitCircle.sample(&mut rng); - assert_almost_eq!(x[0]*x[0] + x[1]*x[1], 1., 1e-15); - } - } - - #[test] - fn value_stability() { - let mut rng = crate::test::rng(2); - let expected = [ - [-0.9965658683520504, -0.08280380447614634], - [-0.9790853270389644, -0.20345004884984505], - [-0.8449189758898707, 0.5348943112253227], - ]; - let samples: [[f64; 2]; 3] = [ - UnitCircle.sample(&mut rng), - UnitCircle.sample(&mut rng), - UnitCircle.sample(&mut rng), - ]; - assert_eq!(samples, expected); - } -} diff --git a/rand/rand_distr/src/unit_disc.rs b/rand/rand_distr/src/unit_disc.rs deleted file mode 100644 index 97abc2f..0000000 --- a/rand/rand_distr/src/unit_disc.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rand::Rng; -use crate::{Distribution, Uniform, uniform::SampleUniform}; -use crate::utils::Float; - -/// Samples uniformly from the unit disc in two dimensions. -/// -/// Implemented via rejection sampling. -/// -/// -/// # Example -/// -/// ``` -/// use rand_distr::{UnitDisc, Distribution}; -/// -/// let v: [f64; 2] = UnitDisc.sample(&mut rand::thread_rng()); -/// println!("{:?} is from the unit Disc.", v) -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct UnitDisc; - -impl Distribution<[N; 2]> for UnitDisc { - #[inline] - fn sample(&self, rng: &mut R) -> [N; 2] { - let uniform = Uniform::new(N::from(-1.), N::from(1.)); - let mut x1; - let mut x2; - loop { - x1 = uniform.sample(rng); - x2 = uniform.sample(rng); - if x1*x1 + x2*x2 <= N::from(1.) { - break; - } - } - [x1, x2] - } -} - -#[cfg(test)] -mod tests { - use crate::Distribution; - use super::UnitDisc; - - #[test] - fn value_stability() { - let mut rng = crate::test::rng(2); - let expected = [ - [0.018035709265959987, -0.4348771383120438], - [-0.07982762085055706, 0.7765329819820659], - [0.21450745997299503, 0.7398636984333291] - ]; - let samples: [[f64; 2]; 3] = [ - UnitDisc.sample(&mut rng), - UnitDisc.sample(&mut rng), - UnitDisc.sample(&mut rng), - ]; - assert_eq!(samples, expected); - } -} diff --git a/rand/rand_distr/src/unit_sphere.rs b/rand/rand_distr/src/unit_sphere.rs deleted file mode 100644 index 8e0c361..0000000 --- a/rand/rand_distr/src/unit_sphere.rs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2018-2019 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rand::Rng; -use crate::{Distribution, Uniform, uniform::SampleUniform}; -use crate::utils::Float; - -/// Samples uniformly from the surface of the unit sphere in three dimensions. -/// -/// Implemented via a method by Marsaglia[^1]. -/// -/// -/// # Example -/// -/// ``` -/// use rand_distr::{UnitSphere, Distribution}; -/// -/// let v: [f64; 3] = UnitSphere.sample(&mut rand::thread_rng()); -/// println!("{:?} is from the unit sphere surface.", v) -/// ``` -/// -/// [^1]: Marsaglia, George (1972). [*Choosing a Point from the Surface of a -/// Sphere.*](https://doi.org/10.1214/aoms/1177692644) -/// Ann. Math. Statist. 43, no. 2, 645--646. -#[derive(Clone, Copy, Debug)] -pub struct UnitSphere; - -impl Distribution<[N; 3]> for UnitSphere { - #[inline] - fn sample(&self, rng: &mut R) -> [N; 3] { - let uniform = Uniform::new(N::from(-1.), N::from(1.)); - loop { - let (x1, x2) = (uniform.sample(rng), uniform.sample(rng)); - let sum = x1*x1 + x2*x2; - if sum >= N::from(1.) { - continue; - } - let factor = N::from(2.) * (N::from(1.0) - sum).sqrt(); - return [x1 * factor, x2 * factor, N::from(1.) - N::from(2.)*sum]; - } - } -} - -#[cfg(test)] -mod tests { - use crate::Distribution; - use super::UnitSphere; - - /// Assert that two numbers are almost equal to each other. - /// - /// On panic, this macro will print the values of the expressions with their - /// debug representations. - macro_rules! assert_almost_eq { - ($a:expr, $b:expr, $prec:expr) => ( - let diff = ($a - $b).abs(); - if diff > $prec { - panic!(format!( - "assertion failed: `abs(left - right) = {:.1e} < {:e}`, \ - (left: `{}`, right: `{}`)", - diff, $prec, $a, $b)); - } - ); - } - - #[test] - fn norm() { - let mut rng = crate::test::rng(1); - for _ in 0..1000 { - let x: [f64; 3] = UnitSphere.sample(&mut rng); - assert_almost_eq!(x[0]*x[0] + x[1]*x[1] + x[2]*x[2], 1., 1e-15); - } - } - - #[test] - fn value_stability() { - let mut rng = crate::test::rng(2); - let expected = [ - [0.03247542860231647, -0.7830477442152738, 0.6211131755296027], - [-0.09978440840914075, 0.9706650829833128, -0.21875184231323952], - [0.2735582468624679, 0.9435374242279655, -0.1868234852870203], - ]; - let samples: [[f64; 3]; 3] = [ - UnitSphere.sample(&mut rng), - UnitSphere.sample(&mut rng), - UnitSphere.sample(&mut rng), - ]; - assert_eq!(samples, expected); - } -} diff --git a/rand/rand_distr/src/utils.rs b/rand/rand_distr/src/utils.rs deleted file mode 100644 index 75b3500..0000000 --- a/rand/rand_distr/src/utils.rs +++ /dev/null @@ -1,234 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Math helper functions - -use rand::Rng; -use crate::ziggurat_tables; -use rand::distributions::hidden_export::IntoFloat; -use core::{cmp, ops}; - -/// Trait for floating-point scalar types -/// -/// This allows many distributions to work with `f32` or `f64` parameters and is -/// potentially extensible. Note however that the `Exp1` and `StandardNormal` -/// distributions are implemented exclusively for `f32` and `f64`. -/// -/// The bounds and methods are based purely on internal -/// requirements, and will change as needed. -pub trait Float: Copy + Sized + cmp::PartialOrd - + ops::Neg - + ops::Add - + ops::Sub - + ops::Mul - + ops::Div - + ops::AddAssign + ops::SubAssign + ops::MulAssign + ops::DivAssign -{ - /// The constant π - fn pi() -> Self; - /// Support approximate representation of a f64 value - fn from(x: f64) -> Self; - /// Support converting to an unsigned integer. - fn to_u64(self) -> Option; - - /// Take the absolute value of self - fn abs(self) -> Self; - /// Take the largest integer less than or equal to self - fn floor(self) -> Self; - - /// Take the exponential of self - fn exp(self) -> Self; - /// Take the natural logarithm of self - fn ln(self) -> Self; - /// Take square root of self - fn sqrt(self) -> Self; - /// Take self to a floating-point power - fn powf(self, power: Self) -> Self; - - /// Take the tangent of self - fn tan(self) -> Self; - /// Take the logarithm of the gamma function of self - fn log_gamma(self) -> Self; -} - -impl Float for f32 { - #[inline] - fn pi() -> Self { core::f32::consts::PI } - #[inline] - fn from(x: f64) -> Self { x as f32 } - #[inline] - fn to_u64(self) -> Option { - if self >= 0. && self <= ::core::u64::MAX as f32 { - Some(self as u64) - } else { - None - } - } - - #[inline] - fn abs(self) -> Self { self.abs() } - #[inline] - fn floor(self) -> Self { self.floor() } - - #[inline] - fn exp(self) -> Self { self.exp() } - #[inline] - fn ln(self) -> Self { self.ln() } - #[inline] - fn sqrt(self) -> Self { self.sqrt() } - #[inline] - fn powf(self, power: Self) -> Self { self.powf(power) } - - #[inline] - fn tan(self) -> Self { self.tan() } - #[inline] - fn log_gamma(self) -> Self { - let result = log_gamma(self.into()); - assert!(result <= ::core::f32::MAX.into()); - assert!(result >= ::core::f32::MIN.into()); - result as f32 - } -} - -impl Float for f64 { - #[inline] - fn pi() -> Self { core::f64::consts::PI } - #[inline] - fn from(x: f64) -> Self { x } - #[inline] - fn to_u64(self) -> Option { - if self >= 0. && self <= ::core::u64::MAX as f64 { - Some(self as u64) - } else { - None - } - } - - #[inline] - fn abs(self) -> Self { self.abs() } - #[inline] - fn floor(self) -> Self { self.floor() } - - #[inline] - fn exp(self) -> Self { self.exp() } - #[inline] - fn ln(self) -> Self { self.ln() } - #[inline] - fn sqrt(self) -> Self { self.sqrt() } - #[inline] - fn powf(self, power: Self) -> Self { self.powf(power) } - - #[inline] - fn tan(self) -> Self { self.tan() } - #[inline] - fn log_gamma(self) -> Self { log_gamma(self) } -} - -/// Calculates ln(gamma(x)) (natural logarithm of the gamma -/// function) using the Lanczos approximation. -/// -/// The approximation expresses the gamma function as: -/// `gamma(z+1) = sqrt(2*pi)*(z+g+0.5)^(z+0.5)*exp(-z-g-0.5)*Ag(z)` -/// `g` is an arbitrary constant; we use the approximation with `g=5`. -/// -/// Noting that `gamma(z+1) = z*gamma(z)` and applying `ln` to both sides: -/// `ln(gamma(z)) = (z+0.5)*ln(z+g+0.5)-(z+g+0.5) + ln(sqrt(2*pi)*Ag(z)/z)` -/// -/// `Ag(z)` is an infinite series with coefficients that can be calculated -/// ahead of time - we use just the first 6 terms, which is good enough -/// for most purposes. -pub(crate) fn log_gamma(x: f64) -> f64 { - // precalculated 6 coefficients for the first 6 terms of the series - let coefficients: [f64; 6] = [ - 76.18009172947146, - -86.50532032941677, - 24.01409824083091, - -1.231739572450155, - 0.1208650973866179e-2, - -0.5395239384953e-5, - ]; - - // (x+0.5)*ln(x+g+0.5)-(x+g+0.5) - let tmp = x + 5.5; - let log = (x + 0.5) * tmp.ln() - tmp; - - // the first few terms of the series for Ag(x) - let mut a = 1.000000000190015; - let mut denom = x; - for &coeff in &coefficients { - denom += 1.0; - a += coeff / denom; - } - - // get everything together - // a is Ag(x) - // 2.5066... is sqrt(2pi) - log + (2.5066282746310005 * a / x).ln() -} - -/// Sample a random number using the Ziggurat method (specifically the -/// ZIGNOR variant from Doornik 2005). Most of the arguments are -/// directly from the paper: -/// -/// * `rng`: source of randomness -/// * `symmetric`: whether this is a symmetric distribution, or one-sided with P(x < 0) = 0. -/// * `X`: the $x_i$ abscissae. -/// * `F`: precomputed values of the PDF at the $x_i$, (i.e. $f(x_i)$) -/// * `F_DIFF`: precomputed values of $f(x_i) - f(x_{i+1})$ -/// * `pdf`: the probability density function -/// * `zero_case`: manual sampling from the tail when we chose the -/// bottom box (i.e. i == 0) - -// the perf improvement (25-50%) is definitely worth the extra code -// size from force-inlining. -#[inline(always)] -pub(crate) fn ziggurat( - rng: &mut R, - symmetric: bool, - x_tab: ziggurat_tables::ZigTable, - f_tab: ziggurat_tables::ZigTable, - mut pdf: P, - mut zero_case: Z) - -> f64 where P: FnMut(f64) -> f64, Z: FnMut(&mut R, f64) -> f64 { - loop { - // As an optimisation we re-implement the conversion to a f64. - // From the remaining 12 most significant bits we use 8 to construct `i`. - // This saves us generating a whole extra random number, while the added - // precision of using 64 bits for f64 does not buy us much. - let bits = rng.next_u64(); - let i = bits as usize & 0xff; - - let u = if symmetric { - // Convert to a value in the range [2,4) and substract to get [-1,1) - // We can't convert to an open range directly, that would require - // substracting `3.0 - EPSILON`, which is not representable. - // It is possible with an extra step, but an open range does not - // seem neccesary for the ziggurat algorithm anyway. - (bits >> 12).into_float_with_exponent(1) - 3.0 - } else { - // Convert to a value in the range [1,2) and substract to get (0,1) - (bits >> 12).into_float_with_exponent(0) - - (1.0 - std::f64::EPSILON / 2.0) - }; - let x = u * x_tab[i]; - - let test_x = if symmetric { x.abs() } else {x}; - - // algebraically equivalent to |u| < x_tab[i+1]/x_tab[i] (or u < x_tab[i+1]/x_tab[i]) - if test_x < x_tab[i + 1] { - return x; - } - if i == 0 { - return zero_case(rng, u); - } - // algebraically equivalent to f1 + DRanU()*(f0 - f1) < 1 - if f_tab[i + 1] + (f_tab[i] - f_tab[i + 1]) * rng.gen::() < pdf(x) { - return x; - } - } -} diff --git a/rand/rand_distr/src/weibull.rs b/rand/rand_distr/src/weibull.rs deleted file mode 100644 index ddde380..0000000 --- a/rand/rand_distr/src/weibull.rs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Weibull distribution. - -use rand::Rng; -use crate::{Distribution, OpenClosed01}; -use crate::utils::Float; - -/// Samples floating-point numbers according to the Weibull distribution -/// -/// # Example -/// ``` -/// use rand::prelude::*; -/// use rand_distr::Weibull; -/// -/// let val: f64 = thread_rng().sample(Weibull::new(1., 10.).unwrap()); -/// println!("{}", val); -/// ``` -#[derive(Clone, Copy, Debug)] -pub struct Weibull { - inv_shape: N, - scale: N, -} - -/// Error type returned from `Weibull::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Error { - /// `scale <= 0` or `nan`. - ScaleTooSmall, - /// `shape <= 0` or `nan`. - ShapeTooSmall, -} - -impl Weibull -where OpenClosed01: Distribution -{ - /// Construct a new `Weibull` distribution with given `scale` and `shape`. - pub fn new(scale: N, shape: N) -> Result, Error> { - if !(scale > N::from(0.0)) { - return Err(Error::ScaleTooSmall); - } - if !(shape > N::from(0.0)) { - return Err(Error::ShapeTooSmall); - } - Ok(Weibull { inv_shape: N::from(1.)/shape, scale }) - } -} - -impl Distribution for Weibull -where OpenClosed01: Distribution -{ - fn sample(&self, rng: &mut R) -> N { - let x: N = rng.sample(OpenClosed01); - self.scale * (-x.ln()).powf(self.inv_shape) - } -} - -#[cfg(test)] -mod tests { - use crate::Distribution; - use super::Weibull; - - #[test] - #[should_panic] - fn invalid() { - Weibull::new(0., 0.).unwrap(); - } - - #[test] - fn sample() { - let scale = 1.0; - let shape = 2.0; - let d = Weibull::new(scale, shape).unwrap(); - let mut rng = crate::test::rng(1); - for _ in 0..1000 { - let r = d.sample(&mut rng); - assert!(r >= 0.); - } - } -} diff --git a/rand/rand_distr/src/ziggurat_tables.rs b/rand/rand_distr/src/ziggurat_tables.rs deleted file mode 100644 index ca1ce30..0000000 --- a/rand/rand_distr/src/ziggurat_tables.rs +++ /dev/null @@ -1,279 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Tables for distributions which are sampled using the ziggurat -// algorithm. Autogenerated by `ziggurat_tables.py`. - -pub type ZigTable = &'static [f64; 257]; -pub const ZIG_NORM_R: f64 = 3.654152885361008796; -pub static ZIG_NORM_X: [f64; 257] = - [3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074, - 3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434, - 2.978603279880844834, 2.934366867207854224, 2.894121053612348060, 2.857138730872132548, - 2.822877396825325125, 2.790921174000785765, 2.760944005278822555, 2.732685359042827056, - 2.705933656121858100, 2.680514643284522158, 2.656283037575502437, 2.633116393630324570, - 2.610910518487548515, 2.589575986706995181, 2.569035452680536569, 2.549221550323460761, - 2.530075232158516929, 2.511544441625342294, 2.493583041269680667, 2.476149939669143318, - 2.459208374333311298, 2.442725318198956774, 2.426670984935725972, 2.411018413899685520, - 2.395743119780480601, 2.380822795170626005, 2.366237056715818632, 2.351967227377659952, - 2.337996148795031370, 2.324308018869623016, 2.310888250599850036, 2.297723348901329565, - 2.284800802722946056, 2.272108990226823888, 2.259637095172217780, 2.247375032945807760, - 2.235313384928327984, 2.223443340090905718, 2.211756642882544366, 2.200245546609647995, - 2.188902771624720689, 2.177721467738641614, 2.166695180352645966, 2.155817819875063268, - 2.145083634046203613, 2.134487182844320152, 2.124023315687815661, 2.113687150684933957, - 2.103474055713146829, 2.093379631137050279, 2.083399693996551783, 2.073530263516978778, - 2.063767547809956415, 2.054107931648864849, 2.044547965215732788, 2.035084353727808715, - 2.025713947862032960, 2.016433734904371722, 2.007240830558684852, 1.998132471356564244, - 1.989106007615571325, 1.980158896898598364, 1.971288697931769640, 1.962493064942461896, - 1.953769742382734043, 1.945116560006753925, 1.936531428273758904, 1.928012334050718257, - 1.919557336591228847, 1.911164563769282232, 1.902832208548446369, 1.894558525668710081, - 1.886341828534776388, 1.878180486290977669, 1.870072921069236838, 1.862017605397632281, - 1.854013059758148119, 1.846057850283119750, 1.838150586580728607, 1.830289919680666566, - 1.822474540091783224, 1.814703175964167636, 1.806974591348693426, 1.799287584547580199, - 1.791640986550010028, 1.784033659547276329, 1.776464495522344977, 1.768932414909077933, - 1.761436365316706665, 1.753975320315455111, 1.746548278279492994, 1.739154261283669012, - 1.731792314050707216, 1.724461502945775715, 1.717160915015540690, 1.709889657069006086, - 1.702646854797613907, 1.695431651932238548, 1.688243209434858727, 1.681080704722823338, - 1.673943330923760353, 1.666830296159286684, 1.659740822855789499, 1.652674147080648526, - 1.645629517902360339, 1.638606196773111146, 1.631603456932422036, 1.624620582830568427, - 1.617656869570534228, 1.610711622367333673, 1.603784156023583041, 1.596873794420261339, - 1.589979870021648534, 1.583101723393471438, 1.576238702733332886, 1.569390163412534456, - 1.562555467528439657, 1.555733983466554893, 1.548925085471535512, 1.542128153226347553, - 1.535342571438843118, 1.528567729435024614, 1.521803020758293101, 1.515047842773992404, - 1.508301596278571965, 1.501563685112706548, 1.494833515777718391, 1.488110497054654369, - 1.481394039625375747, 1.474683555695025516, 1.467978458615230908, 1.461278162507407830, - 1.454582081885523293, 1.447889631277669675, 1.441200224845798017, 1.434513276002946425, - 1.427828197027290358, 1.421144398672323117, 1.414461289772464658, 1.407778276843371534, - 1.401094763676202559, 1.394410150925071257, 1.387723835686884621, 1.381035211072741964, - 1.374343665770030531, 1.367648583594317957, 1.360949343030101844, 1.354245316759430606, - 1.347535871177359290, 1.340820365893152122, 1.334098153216083604, 1.327368577624624679, - 1.320630975217730096, 1.313884673146868964, 1.307128989027353860, 1.300363230327433728, - 1.293586693733517645, 1.286798664489786415, 1.279998415710333237, 1.273185207661843732, - 1.266358287014688333, 1.259516886060144225, 1.252660221891297887, 1.245787495544997903, - 1.238897891102027415, 1.231990574742445110, 1.225064693752808020, 1.218119375481726552, - 1.211153726239911244, 1.204166830140560140, 1.197157747875585931, 1.190125515422801650, - 1.183069142678760732, 1.175987612011489825, 1.168879876726833800, 1.161744859441574240, - 1.154581450355851802, 1.147388505416733873, 1.140164844363995789, 1.132909248648336975, - 1.125620459211294389, 1.118297174115062909, 1.110938046009249502, 1.103541679420268151, - 1.096106627847603487, 1.088631390649514197, 1.081114409698889389, 1.073554065787871714, - 1.065948674757506653, 1.058296483326006454, 1.050595664586207123, 1.042844313139370538, - 1.035040439828605274, 1.027181966030751292, 1.019266717460529215, 1.011292417434978441, - 1.003256679539591412, 0.995156999629943084, 0.986990747093846266, 0.978755155288937750, - 0.970447311058864615, 0.962064143217605250, 0.953602409875572654, 0.945058684462571130, - 0.936429340280896860, 0.927710533396234771, 0.918898183643734989, 0.909987953490768997, - 0.900975224455174528, 0.891855070726792376, 0.882622229578910122, 0.873271068082494550, - 0.863795545546826915, 0.854189171001560554, 0.844444954902423661, 0.834555354079518752, - 0.824512208745288633, 0.814306670128064347, 0.803929116982664893, 0.793369058833152785, - 0.782615023299588763, 0.771654424216739354, 0.760473406422083165, 0.749056662009581653, - 0.737387211425838629, 0.725446140901303549, 0.713212285182022732, 0.700661841097584448, - 0.687767892786257717, 0.674499822827436479, 0.660822574234205984, 0.646695714884388928, - 0.632072236375024632, 0.616896989996235545, 0.601104617743940417, 0.584616766093722262, - 0.567338257040473026, 0.549151702313026790, 0.529909720646495108, 0.509423329585933393, - 0.487443966121754335, 0.463634336771763245, 0.437518402186662658, 0.408389134588000746, - 0.375121332850465727, 0.335737519180459465, 0.286174591747260509, 0.215241895913273806, - 0.000000000000000000]; -pub static ZIG_NORM_F: [f64; 257] = - [0.000477467764586655, 0.001260285930498598, 0.002609072746106363, 0.004037972593371872, - 0.005522403299264754, 0.007050875471392110, 0.008616582769422917, 0.010214971439731100, - 0.011842757857943104, 0.013497450601780807, 0.015177088307982072, 0.016880083152595839, - 0.018605121275783350, 0.020351096230109354, 0.022117062707379922, 0.023902203305873237, - 0.025705804008632656, 0.027527235669693315, 0.029365939758230111, 0.031221417192023690, - 0.033093219458688698, 0.034980941461833073, 0.036884215688691151, 0.038802707404656918, - 0.040736110656078753, 0.042684144916619378, 0.044646552251446536, 0.046623094902089664, - 0.048613553216035145, 0.050617723861121788, 0.052635418276973649, 0.054666461325077916, - 0.056710690106399467, 0.058767952921137984, 0.060838108349751806, 0.062921024437977854, - 0.065016577971470438, 0.067124653828023989, 0.069245144397250269, 0.071377949059141965, - 0.073522973714240991, 0.075680130359194964, 0.077849336702372207, 0.080030515814947509, - 0.082223595813495684, 0.084428509570654661, 0.086645194450867782, 0.088873592068594229, - 0.091113648066700734, 0.093365311913026619, 0.095628536713353335, 0.097903279039215627, - 0.100189498769172020, 0.102487158942306270, 0.104796225622867056, 0.107116667775072880, - 0.109448457147210021, 0.111791568164245583, 0.114145977828255210, 0.116511665626037014, - 0.118888613443345698, 0.121276805485235437, 0.123676228202051403, 0.126086870220650349, - 0.128508722280473636, 0.130941777174128166, 0.133386029692162844, 0.135841476571757352, - 0.138308116449064322, 0.140785949814968309, 0.143274978974047118, 0.145775208006537926, - 0.148286642733128721, 0.150809290682410169, 0.153343161060837674, 0.155888264725064563, - 0.158444614156520225, 0.161012223438117663, 0.163591108232982951, 0.166181285765110071, - 0.168782774801850333, 0.171395595638155623, 0.174019770082499359, 0.176655321444406654, - 0.179302274523530397, 0.181960655600216487, 0.184630492427504539, 0.187311814224516926, - 0.190004651671193070, 0.192709036904328807, 0.195425003514885592, 0.198152586546538112, - 0.200891822495431333, 0.203642749311121501, 0.206405406398679298, 0.209179834621935651, - 0.211966076307852941, 0.214764175252008499, 0.217574176725178370, 0.220396127481011589, - 0.223230075764789593, 0.226076071323264877, 0.228934165415577484, 0.231804410825248525, - 0.234686861873252689, 0.237581574432173676, 0.240488605941449107, 0.243408015423711988, - 0.246339863502238771, 0.249284212419516704, 0.252241126056943765, 0.255210669955677150, - 0.258192911338648023, 0.261187919133763713, 0.264195763998317568, 0.267216518344631837, - 0.270250256366959984, 0.273297054069675804, 0.276356989296781264, 0.279430141762765316, - 0.282516593084849388, 0.285616426816658109, 0.288729728483353931, 0.291856585618280984, - 0.294997087801162572, 0.298151326697901342, 0.301319396102034120, 0.304501391977896274, - 0.307697412505553769, 0.310907558127563710, 0.314131931597630143, 0.317370638031222396, - 0.320623784958230129, 0.323891482377732021, 0.327173842814958593, 0.330470981380537099, - 0.333783015832108509, 0.337110066638412809, 0.340452257045945450, 0.343809713148291340, - 0.347182563958251478, 0.350570941482881204, 0.353974980801569250, 0.357394820147290515, - 0.360830600991175754, 0.364282468130549597, 0.367750569780596226, 0.371235057669821344, - 0.374736087139491414, 0.378253817247238111, 0.381788410875031348, 0.385340034841733958, - 0.388908860020464597, 0.392495061461010764, 0.396098818517547080, 0.399720314981931668, - 0.403359739222868885, 0.407017284331247953, 0.410693148271983222, 0.414387534042706784, - 0.418100649839684591, 0.421832709231353298, 0.425583931339900579, 0.429354541031341519, - 0.433144769114574058, 0.436954852549929273, 0.440785034667769915, 0.444635565397727750, - 0.448506701509214067, 0.452398706863882505, 0.456311852680773566, 0.460246417814923481, - 0.464202689050278838, 0.468180961407822172, 0.472181538469883255, 0.476204732721683788, - 0.480250865911249714, 0.484320269428911598, 0.488413284707712059, 0.492530263646148658, - 0.496671569054796314, 0.500837575128482149, 0.505028667945828791, 0.509245245998136142, - 0.513487720749743026, 0.517756517232200619, 0.522052074674794864, 0.526374847174186700, - 0.530725304406193921, 0.535103932383019565, 0.539511234259544614, 0.543947731192649941, - 0.548413963257921133, 0.552910490428519918, 0.557437893621486324, 0.561996775817277916, - 0.566587763258951771, 0.571211506738074970, 0.575868682975210544, 0.580559996103683473, - 0.585286179266300333, 0.590047996335791969, 0.594846243770991268, 0.599681752622167719, - 0.604555390700549533, 0.609468064928895381, 0.614420723892076803, 0.619414360609039205, - 0.624450015550274240, 0.629528779928128279, 0.634651799290960050, 0.639820277456438991, - 0.645035480824251883, 0.650298743114294586, 0.655611470583224665, 0.660975147780241357, - 0.666391343912380640, 0.671861719900766374, 0.677388036222513090, 0.682972161648791376, - 0.688616083008527058, 0.694321916130032579, 0.700091918140490099, 0.705928501336797409, - 0.711834248882358467, 0.717811932634901395, 0.723864533472881599, 0.729995264565802437, - 0.736207598131266683, 0.742505296344636245, 0.748892447223726720, 0.755373506511754500, - 0.761953346841546475, 0.768637315803334831, 0.775431304986138326, 0.782341832659861902, - 0.789376143571198563, 0.796542330428254619, 0.803849483176389490, 0.811307874318219935, - 0.818929191609414797, 0.826726833952094231, 0.834716292992930375, 0.842915653118441077, - 0.851346258465123684, 0.860033621203008636, 0.869008688043793165, 0.878309655816146839, - 0.887984660763399880, 0.898095921906304051, 0.908726440060562912, 0.919991505048360247, - 0.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328, - 1.000000000000000000]; -pub const ZIG_EXP_R: f64 = 7.697117470131050077; -pub static ZIG_EXP_X: [f64; 257] = - [8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, - 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, - 5.323090505754398016, 5.181487281301500047, 5.054288489981304089, 4.938777085901250530, - 4.832939741025112035, 4.735242996601741083, 4.644491885420085175, 4.559737061707351380, - 4.480211746528421912, 4.405287693473573185, 4.334443680317273007, 4.267242480277365857, - 4.203313713735184365, 4.142340865664051464, 4.084051310408297830, 4.028208544647936762, - 3.974606066673788796, 3.923062500135489739, 3.873417670399509127, 3.825529418522336744, - 3.779270992411667862, 3.734528894039797375, 3.691201090237418825, 3.649195515760853770, - 3.608428813128909507, 3.568825265648337020, 3.530315889129343354, 3.492837654774059608, - 3.456332821132760191, 3.420748357251119920, 3.386035442460300970, 3.352149030900109405, - 3.319047470970748037, 3.286692171599068679, 3.255047308570449882, 3.224079565286264160, - 3.193757903212240290, 3.164053358025972873, 3.134938858084440394, 3.106389062339824481, - 3.078380215254090224, 3.050890016615455114, 3.023897504455676621, 2.997382949516130601, - 2.971327759921089662, 2.945714394895045718, 2.920526286512740821, 2.895747768600141825, - 2.871364012015536371, 2.847360965635188812, 2.823725302450035279, 2.800444370250737780, - 2.777506146439756574, 2.754899196562344610, 2.732612636194700073, 2.710636095867928752, - 2.688959688741803689, 2.667573980773266573, 2.646469963151809157, 2.625639026797788489, - 2.605072938740835564, 2.584763820214140750, 2.564704126316905253, 2.544886627111869970, - 2.525304390037828028, 2.505950763528594027, 2.486819361740209455, 2.467904050297364815, - 2.449198932978249754, 2.430698339264419694, 2.412396812688870629, 2.394289099921457886, - 2.376370140536140596, 2.358635057409337321, 2.341079147703034380, 2.323697874390196372, - 2.306486858283579799, 2.289441870532269441, 2.272558825553154804, 2.255833774367219213, - 2.239262898312909034, 2.222842503111036816, 2.206569013257663858, 2.190438966723220027, - 2.174449009937774679, 2.158595893043885994, 2.142876465399842001, 2.127287671317368289, - 2.111826546019042183, 2.096490211801715020, 2.081275874393225145, 2.066180819490575526, - 2.051202409468584786, 2.036338080248769611, 2.021585338318926173, 2.006941757894518563, - 1.992404978213576650, 1.977972700957360441, 1.963642687789548313, 1.949412758007184943, - 1.935280786297051359, 1.921244700591528076, 1.907302480018387536, 1.893452152939308242, - 1.879691795072211180, 1.866019527692827973, 1.852433515911175554, 1.838931967018879954, - 1.825513128903519799, 1.812175288526390649, 1.798916770460290859, 1.785735935484126014, - 1.772631179231305643, 1.759600930889074766, 1.746643651946074405, 1.733757834985571566, - 1.720942002521935299, 1.708194705878057773, 1.695514524101537912, 1.682900062917553896, - 1.670349953716452118, 1.657862852574172763, 1.645437439303723659, 1.633072416535991334, - 1.620766508828257901, 1.608518461798858379, 1.596327041286483395, 1.584191032532688892, - 1.572109239386229707, 1.560080483527888084, 1.548103603714513499, 1.536177455041032092, - 1.524300908219226258, 1.512472848872117082, 1.500692176842816750, 1.488957805516746058, - 1.477268661156133867, 1.465623682245745352, 1.454021818848793446, 1.442462031972012504, - 1.430943292938879674, 1.419464582769983219, 1.408024891569535697, 1.396623217917042137, - 1.385258568263121992, 1.373929956328490576, 1.362636402505086775, 1.351376933258335189, - 1.340150580529504643, 1.328956381137116560, 1.317793376176324749, 1.306660610415174117, - 1.295557131686601027, 1.284481990275012642, 1.273434238296241139, 1.262412929069615330, - 1.251417116480852521, 1.240445854334406572, 1.229498195693849105, 1.218573192208790124, - 1.207669893426761121, 1.196787346088403092, 1.185924593404202199, 1.175080674310911677, - 1.164254622705678921, 1.153445466655774743, 1.142652227581672841, 1.131873919411078511, - 1.121109547701330200, 1.110358108727411031, 1.099618588532597308, 1.088889961938546813, - 1.078171191511372307, 1.067461226479967662, 1.056759001602551429, 1.046063435977044209, - 1.035373431790528542, 1.024687873002617211, 1.014005623957096480, 1.003325527915696735, - 0.992646405507275897, 0.981967053085062602, 0.971286240983903260, 0.960602711668666509, - 0.949915177764075969, 0.939222319955262286, 0.928522784747210395, 0.917815182070044311, - 0.907098082715690257, 0.896370015589889935, 0.885629464761751528, 0.874874866291025066, - 0.864104604811004484, 0.853317009842373353, 0.842510351810368485, 0.831682837734273206, - 0.820832606554411814, 0.809957724057418282, 0.799056177355487174, 0.788125868869492430, - 0.777164609759129710, 0.766170112735434672, 0.755139984181982249, 0.744071715500508102, - 0.732962673584365398, 0.721810090308756203, 0.710611050909655040, 0.699362481103231959, - 0.688061132773747808, 0.676703568029522584, 0.665286141392677943, 0.653804979847664947, - 0.642255960424536365, 0.630634684933490286, 0.618936451394876075, 0.607156221620300030, - 0.595288584291502887, 0.583327712748769489, 0.571267316532588332, 0.559100585511540626, - 0.546820125163310577, 0.534417881237165604, 0.521885051592135052, 0.509211982443654398, - 0.496388045518671162, 0.483401491653461857, 0.470239275082169006, 0.456886840931420235, - 0.443327866073552401, 0.429543940225410703, 0.415514169600356364, 0.401214678896277765, - 0.386617977941119573, 0.371692145329917234, 0.356399760258393816, 0.340696481064849122, - 0.324529117016909452, 0.307832954674932158, 0.290527955491230394, 0.272513185478464703, - 0.253658363385912022, 0.233790483059674731, 0.212671510630966620, 0.189958689622431842, - 0.165127622564187282, 0.137304980940012589, 0.104838507565818778, 0.063852163815001570, - 0.000000000000000000]; -pub static ZIG_EXP_F: [f64; 257] = - [0.000167066692307963, 0.000454134353841497, 0.000967269282327174, 0.001536299780301573, - 0.002145967743718907, 0.002788798793574076, 0.003460264777836904, 0.004157295120833797, - 0.004877655983542396, 0.005619642207205489, 0.006381905937319183, 0.007163353183634991, - 0.007963077438017043, 0.008780314985808977, 0.009614413642502212, 0.010464810181029981, - 0.011331013597834600, 0.012212592426255378, 0.013109164931254991, 0.014020391403181943, - 0.014945968011691148, 0.015885621839973156, 0.016839106826039941, 0.017806200410911355, - 0.018786700744696024, 0.019780424338009740, 0.020787204072578114, 0.021806887504283581, - 0.022839335406385240, 0.023884420511558174, 0.024942026419731787, 0.026012046645134221, - 0.027094383780955803, 0.028188948763978646, 0.029295660224637411, 0.030414443910466622, - 0.031545232172893622, 0.032687963508959555, 0.033842582150874358, 0.035009037697397431, - 0.036187284781931443, 0.037377282772959382, 0.038578995503074871, 0.039792391023374139, - 0.041017441380414840, 0.042254122413316254, 0.043502413568888197, 0.044762297732943289, - 0.046033761076175184, 0.047316792913181561, 0.048611385573379504, 0.049917534282706379, - 0.051235237055126281, 0.052564494593071685, 0.053905310196046080, 0.055257689676697030, - 0.056621641283742870, 0.057997175631200659, 0.059384305633420280, 0.060783046445479660, - 0.062193415408541036, 0.063615431999807376, 0.065049117786753805, 0.066494496385339816, - 0.067951593421936643, 0.069420436498728783, 0.070901055162371843, 0.072393480875708752, - 0.073897746992364746, 0.075413888734058410, 0.076941943170480517, 0.078481949201606435, - 0.080033947542319905, 0.081597980709237419, 0.083174093009632397, 0.084762330532368146, - 0.086362741140756927, 0.087975374467270231, 0.089600281910032886, 0.091237516631040197, - 0.092887133556043569, 0.094549189376055873, 0.096223742550432825, 0.097910853311492213, - 0.099610583670637132, 0.101322997425953631, 0.103048160171257702, 0.104786139306570145, - 0.106537004050001632, 0.108300825451033755, 0.110077676405185357, 0.111867631670056283, - 0.113670767882744286, 0.115487163578633506, 0.117316899211555525, 0.119160057175327641, - 0.121016721826674792, 0.122886979509545108, 0.124770918580830933, 0.126668629437510671, - 0.128580204545228199, 0.130505738468330773, 0.132445327901387494, 0.134399071702213602, - 0.136367070926428829, 0.138349428863580176, 0.140346251074862399, 0.142357645432472146, - 0.144383722160634720, 0.146424593878344889, 0.148480375643866735, 0.150551185001039839, - 0.152637142027442801, 0.154738369384468027, 0.156854992369365148, 0.158987138969314129, - 0.161134939917591952, 0.163298528751901734, 0.165478041874935922, 0.167673618617250081, - 0.169885401302527550, 0.172113535315319977, 0.174358169171353411, 0.176619454590494829, - 0.178897546572478278, 0.181192603475496261, 0.183504787097767436, 0.185834262762197083, - 0.188181199404254262, 0.190545769663195363, 0.192928149976771296, 0.195328520679563189, - 0.197747066105098818, 0.200183974691911210, 0.202639439093708962, 0.205113656293837654, - 0.207606827724221982, 0.210119159388988230, 0.212650861992978224, 0.215202151075378628, - 0.217773247148700472, 0.220364375843359439, 0.222975768058120111, 0.225607660116683956, - 0.228260293930716618, 0.230933917169627356, 0.233628783437433291, 0.236345152457059560, - 0.239083290262449094, 0.241843469398877131, 0.244625969131892024, 0.247431075665327543, - 0.250259082368862240, 0.253110290015629402, 0.255985007030415324, 0.258883549749016173, - 0.261806242689362922, 0.264753418835062149, 0.267725419932044739, 0.270722596799059967, - 0.273745309652802915, 0.276793928448517301, 0.279868833236972869, 0.282970414538780746, - 0.286099073737076826, 0.289255223489677693, 0.292439288161892630, 0.295651704281261252, - 0.298892921015581847, 0.302163400675693528, 0.305463619244590256, 0.308794066934560185, - 0.312155248774179606, 0.315547685227128949, 0.318971912844957239, 0.322428484956089223, - 0.325917972393556354, 0.329440964264136438, 0.332998068761809096, 0.336589914028677717, - 0.340217149066780189, 0.343880444704502575, 0.347580494621637148, 0.351318016437483449, - 0.355093752866787626, 0.358908472948750001, 0.362762973354817997, 0.366658079781514379, - 0.370594648435146223, 0.374573567615902381, 0.378595759409581067, 0.382662181496010056, - 0.386773829084137932, 0.390931736984797384, 0.395136981833290435, 0.399390684475231350, - 0.403694012530530555, 0.408048183152032673, 0.412454465997161457, 0.416914186433003209, - 0.421428728997616908, 0.425999541143034677, 0.430628137288459167, 0.435316103215636907, - 0.440065100842354173, 0.444876873414548846, 0.449753251162755330, 0.454696157474615836, - 0.459707615642138023, 0.464789756250426511, 0.469944825283960310, 0.475175193037377708, - 0.480483363930454543, 0.485871987341885248, 0.491343869594032867, 0.496901987241549881, - 0.502549501841348056, 0.508289776410643213, 0.514126393814748894, 0.520063177368233931, - 0.526104213983620062, 0.532253880263043655, 0.538516872002862246, 0.544898237672440056, - 0.551403416540641733, 0.558038282262587892, 0.564809192912400615, 0.571723048664826150, - 0.578787358602845359, 0.586010318477268366, 0.593400901691733762, 0.600968966365232560, - 0.608725382079622346, 0.616682180915207878, 0.624852738703666200, 0.633251994214366398, - 0.641896716427266423, 0.650805833414571433, 0.660000841079000145, 0.669506316731925177, - 0.679350572264765806, 0.689566496117078431, 0.700192655082788606, 0.711274760805076456, - 0.722867659593572465, 0.735038092431424039, 0.747868621985195658, 0.761463388849896838, - 0.775956852040116218, 0.791527636972496285, 0.808421651523009044, 0.826993296643051101, - 0.847785500623990496, 0.871704332381204705, 0.900469929925747703, 0.938143680862176477, - 1.000000000000000000]; diff --git a/rand/rand_distr/tests/uniformity.rs b/rand/rand_distr/tests/uniformity.rs deleted file mode 100644 index d0d9d97..0000000 --- a/rand/rand_distr/tests/uniformity.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use average::Histogram; -use rand::prelude::*; - -const N_BINS: usize = 100; -const N_SAMPLES: u32 = 1_000_000; -const TOL: f64 = 1e-3; -average::define_histogram!(hist, 100); -use hist::Histogram as Histogram100; - -#[test] -fn unit_sphere() { - const N_DIM: usize = 3; - let h = Histogram100::with_const_width(-1., 1.); - let mut histograms = [h.clone(), h.clone(), h]; - let dist = rand_distr::UnitSphere; - let mut rng = rand_pcg::Pcg32::from_entropy(); - for _ in 0..N_SAMPLES { - let v: [f64; 3] = dist.sample(&mut rng); - for i in 0..N_DIM { - histograms[i].add(v[i]).map_err( - |e| { println!("v: {}", v[i]); e } - ).unwrap(); - } - } - for h in &histograms { - let sum: u64 = h.bins().iter().sum(); - println!("{:?}", h); - for &b in h.bins() { - let p = (b as f64) / (sum as f64); - assert!((p - 1.0 / (N_BINS as f64)).abs() < TOL, "{}", p); - } - } -} - -#[test] -fn unit_circle() { - use std::f64::consts::PI; - let mut h = Histogram100::with_const_width(-PI, PI); - let dist = rand_distr::UnitCircle; - let mut rng = rand_pcg::Pcg32::from_entropy(); - for _ in 0..N_SAMPLES { - let v: [f64; 2] = dist.sample(&mut rng); - h.add(v[0].atan2(v[1])).unwrap(); - } - let sum: u64 = h.bins().iter().sum(); - println!("{:?}", h); - for &b in h.bins() { - let p = (b as f64) / (sum as f64); - assert!((p - 1.0 / (N_BINS as f64)).abs() < TOL, "{}", p); - } -} diff --git a/rand/rand_hc/CHANGELOG.md b/rand/rand_hc/CHANGELOG.md deleted file mode 100644 index a629d7d..0000000 --- a/rand/rand_hc/CHANGELOG.md +++ /dev/null @@ -1,16 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.2.0] - 2019-06-12 -- Bump minor crate version since rand_core bump is a breaking change -- Switch to Edition 2018 - -## [0.1.1] - 2019-06-06 - yanked -- Bump `rand_core` version -- Adjust usage of `#[inline]` - -## [0.1.0] - 2018-10-17 -- Pulled out of the Rand crate diff --git a/rand/rand_hc/COPYRIGHT b/rand/rand_hc/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_hc/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_hc/Cargo.toml b/rand/rand_hc/Cargo.toml deleted file mode 100644 index 40cea06..0000000 --- a/rand/rand_hc/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "rand_hc" -version = "0.2.0" -authors = ["The Rand Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_hc/" -homepage = "https://crates.io/crates/rand_hc" -description = """ -HC128 random number generator -""" -keywords = ["random", "rng", "hc128"] -categories = ["algorithms", "no-std"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[dependencies] -rand_core = { path = "../rand_core", version = "0.5" } diff --git a/rand/rand_hc/LICENSE-APACHE b/rand/rand_hc/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_hc/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_hc/LICENSE-MIT b/rand/rand_hc/LICENSE-MIT deleted file mode 100644 index cf65607..0000000 --- a/rand/rand_hc/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright 2018 Developers of the Rand project - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_hc/README.md b/rand/rand_hc/README.md deleted file mode 100644 index 36449c0..0000000 --- a/rand/rand_hc/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# rand_hc - -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_hc.svg)](https://crates.io/crates/rand_hc) -[[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_hc) -[![API](https://docs.rs/rand_hc/badge.svg)](https://docs.rs/rand_hc) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -A cryptographically secure random number generator that uses the HC-128 -algorithm. - -HC-128 is a stream cipher designed by Hongjun Wu[^1], that we use as an -RNG. It is selected as one of the "stream ciphers suitable for widespread -adoption" by eSTREAM[^2]. - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_hc) -- [API documentation (docs.rs)](https://docs.rs/rand_hc) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_hc/CHANGELOG.md) - -[rand]: https://crates.io/crates/rand -[^1]: Hongjun Wu (2008). ["The Stream Cipher HC-128"]( - http://www.ecrypt.eu.org/stream/p3ciphers/hc/hc128_p3.pdf). - *The eSTREAM Finalists*, LNCS 4986, pp. 39–47, Springer-Verlag. - -[^2]: [eSTREAM: the ECRYPT Stream Cipher Project]( - http://www.ecrypt.eu.org/stream/) - - -## Crate Features - -`rand_hc` is `no_std` compatible. It does not require any functionality -outside of the `core` lib, thus there are no features to configure. - - -# License - -`rand_hc` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_hc/src/hc128.rs b/rand/rand_hc/src/hc128.rs deleted file mode 100644 index a320f48..0000000 --- a/rand/rand_hc/src/hc128.rs +++ /dev/null @@ -1,464 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The HC-128 random number generator. - -use core::fmt; -use rand_core::{CryptoRng, RngCore, SeedableRng, Error, le}; -use rand_core::block::{BlockRngCore, BlockRng}; - -const SEED_WORDS: usize = 8; // 128 bit key followed by 128 bit iv - -/// A cryptographically secure random number generator that uses the HC-128 -/// algorithm. -/// -/// HC-128 is a stream cipher designed by Hongjun Wu[^1], that we use as an -/// RNG. It is selected as one of the "stream ciphers suitable for widespread -/// adoption" by eSTREAM[^2]. -/// -/// HC-128 is an array based RNG. In this it is similar to RC-4 and ISAAC before -/// it, but those have never been proven cryptographically secure (or have even -/// been significantly compromised, as in the case of RC-4[^5]). -/// -/// Because HC-128 works with simple indexing into a large array and with a few -/// operations that parallelize well, it has very good performance. The size of -/// the array it needs, 4kb, can however be a disadvantage. -/// -/// This implementation is not based on the version of HC-128 submitted to the -/// eSTREAM contest, but on a later version by the author with a few small -/// improvements from December 15, 2009[^3]. -/// -/// HC-128 has no known weaknesses that are easier to exploit than doing a -/// brute-force search of 2128. A very comprehensive analysis of the -/// current state of known attacks / weaknesses of HC-128 is given in *Some -/// Results On Analysis And Implementation Of HC-128 Stream Cipher*[^4]. -/// -/// The average cycle length is expected to be -/// 21024*32+10-1 = 232777. -/// We support seeding with a 256-bit array, which matches the 128-bit key -/// concatenated with a 128-bit IV from the stream cipher. -/// -/// This implementation uses an output buffer of sixteen `u32` words, and uses -/// [`BlockRng`] to implement the [`RngCore`] methods. -/// -/// ## References -/// [^1]: Hongjun Wu (2008). ["The Stream Cipher HC-128"]( -/// http://www.ecrypt.eu.org/stream/p3ciphers/hc/hc128_p3.pdf). -/// *The eSTREAM Finalists*, LNCS 4986, pp. 39–47, Springer-Verlag. -/// -/// [^2]: [eSTREAM: the ECRYPT Stream Cipher Project]( -/// http://www.ecrypt.eu.org/stream/) -/// -/// [^3]: Hongjun Wu, [Stream Ciphers HC-128 and HC-256]( -/// https://www.ntu.edu.sg/home/wuhj/research/hc/index.html) -/// -/// [^4]: Shashwat Raizada (January 2015),["Some Results On Analysis And -/// Implementation Of HC-128 Stream Cipher"]( -/// http://library.isical.ac.in:8080/jspui/bitstream/123456789/6636/1/TH431.pdf). -/// -/// [^5]: Internet Engineering Task Force (February 2015), -/// ["Prohibiting RC4 Cipher Suites"](https://tools.ietf.org/html/rfc7465). -#[derive(Clone, Debug)] -pub struct Hc128Rng(BlockRng); - -impl RngCore for Hc128Rng { - #[inline] - fn next_u32(&mut self) -> u32 { - self.0.next_u32() - } - - #[inline] - fn next_u64(&mut self) -> u64 { - self.0.next_u64() - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.0.fill_bytes(dest) - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.0.try_fill_bytes(dest) - } -} - -impl SeedableRng for Hc128Rng { - type Seed = ::Seed; - - #[inline] - fn from_seed(seed: Self::Seed) -> Self { - Hc128Rng(BlockRng::::from_seed(seed)) - } - - #[inline] - fn from_rng(rng: R) -> Result { - BlockRng::::from_rng(rng).map(Hc128Rng) - } -} - -impl CryptoRng for Hc128Rng {} - -/// The core of `Hc128Rng`, used with `BlockRng`. -#[derive(Clone)] -pub struct Hc128Core { - t: [u32; 1024], - counter1024: usize, -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for Hc128Core { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Hc128Core {{}}") - } -} - -impl BlockRngCore for Hc128Core { - type Item = u32; - type Results = [u32; 16]; - - fn generate(&mut self, results: &mut Self::Results) { - assert!(self.counter1024 % 16 == 0); - - let cc = self.counter1024 % 512; - let dd = (cc + 16) % 512; - let ee = cc.wrapping_sub(16) % 512; - - if self.counter1024 & 512 == 0 { - // P block - results[0] = self.step_p(cc+0, cc+1, ee+13, ee+6, ee+4); - results[1] = self.step_p(cc+1, cc+2, ee+14, ee+7, ee+5); - results[2] = self.step_p(cc+2, cc+3, ee+15, ee+8, ee+6); - results[3] = self.step_p(cc+3, cc+4, cc+0, ee+9, ee+7); - results[4] = self.step_p(cc+4, cc+5, cc+1, ee+10, ee+8); - results[5] = self.step_p(cc+5, cc+6, cc+2, ee+11, ee+9); - results[6] = self.step_p(cc+6, cc+7, cc+3, ee+12, ee+10); - results[7] = self.step_p(cc+7, cc+8, cc+4, ee+13, ee+11); - results[8] = self.step_p(cc+8, cc+9, cc+5, ee+14, ee+12); - results[9] = self.step_p(cc+9, cc+10, cc+6, ee+15, ee+13); - results[10] = self.step_p(cc+10, cc+11, cc+7, cc+0, ee+14); - results[11] = self.step_p(cc+11, cc+12, cc+8, cc+1, ee+15); - results[12] = self.step_p(cc+12, cc+13, cc+9, cc+2, cc+0); - results[13] = self.step_p(cc+13, cc+14, cc+10, cc+3, cc+1); - results[14] = self.step_p(cc+14, cc+15, cc+11, cc+4, cc+2); - results[15] = self.step_p(cc+15, dd+0, cc+12, cc+5, cc+3); - } else { - // Q block - results[0] = self.step_q(cc+0, cc+1, ee+13, ee+6, ee+4); - results[1] = self.step_q(cc+1, cc+2, ee+14, ee+7, ee+5); - results[2] = self.step_q(cc+2, cc+3, ee+15, ee+8, ee+6); - results[3] = self.step_q(cc+3, cc+4, cc+0, ee+9, ee+7); - results[4] = self.step_q(cc+4, cc+5, cc+1, ee+10, ee+8); - results[5] = self.step_q(cc+5, cc+6, cc+2, ee+11, ee+9); - results[6] = self.step_q(cc+6, cc+7, cc+3, ee+12, ee+10); - results[7] = self.step_q(cc+7, cc+8, cc+4, ee+13, ee+11); - results[8] = self.step_q(cc+8, cc+9, cc+5, ee+14, ee+12); - results[9] = self.step_q(cc+9, cc+10, cc+6, ee+15, ee+13); - results[10] = self.step_q(cc+10, cc+11, cc+7, cc+0, ee+14); - results[11] = self.step_q(cc+11, cc+12, cc+8, cc+1, ee+15); - results[12] = self.step_q(cc+12, cc+13, cc+9, cc+2, cc+0); - results[13] = self.step_q(cc+13, cc+14, cc+10, cc+3, cc+1); - results[14] = self.step_q(cc+14, cc+15, cc+11, cc+4, cc+2); - results[15] = self.step_q(cc+15, dd+0, cc+12, cc+5, cc+3); - } - self.counter1024 = self.counter1024.wrapping_add(16); - } -} - -impl Hc128Core { - // One step of HC-128, update P and generate 32 bits keystream - #[inline(always)] - fn step_p(&mut self, i: usize, i511: usize, i3: usize, i10: usize, i12: usize) - -> u32 - { - let (p, q) = self.t.split_at_mut(512); - // FIXME: it would be great if we the bounds checks here could be - // optimized out, and we would not need unsafe. - // This improves performance by about 7%. - unsafe { - let temp0 = p.get_unchecked(i511).rotate_right(23); - let temp1 = p.get_unchecked(i3).rotate_right(10); - let temp2 = p.get_unchecked(i10).rotate_right(8); - *p.get_unchecked_mut(i) = p.get_unchecked(i) - .wrapping_add(temp2) - .wrapping_add(temp0 ^ temp1); - let temp3 = { - // The h1 function in HC-128 - let a = *p.get_unchecked(i12) as u8; - let c = (p.get_unchecked(i12) >> 16) as u8; - q[a as usize].wrapping_add(q[256 + c as usize]) - }; - temp3 ^ p.get_unchecked(i) - } - } - - // One step of HC-128, update Q and generate 32 bits keystream - // Similar to `step_p`, but `p` and `q` are swapped, and the rotates are to - // the left instead of to the right. - #[inline(always)] - fn step_q(&mut self, i: usize, i511: usize, i3: usize, i10: usize, i12: usize) - -> u32 - { - let (p, q) = self.t.split_at_mut(512); - unsafe { - let temp0 = q.get_unchecked(i511).rotate_left(23); - let temp1 = q.get_unchecked(i3).rotate_left(10); - let temp2 = q.get_unchecked(i10).rotate_left(8); - *q.get_unchecked_mut(i) = q.get_unchecked(i) - .wrapping_add(temp2) - .wrapping_add(temp0 ^ temp1); - let temp3 = { - // The h2 function in HC-128 - let a = *q.get_unchecked(i12) as u8; - let c = (q.get_unchecked(i12) >> 16) as u8; - p[a as usize].wrapping_add(p[256 + c as usize]) - }; - temp3 ^ q.get_unchecked(i) - } - } - - fn sixteen_steps(&mut self) { - assert!(self.counter1024 % 16 == 0); - - let cc = self.counter1024 % 512; - let dd = (cc + 16) % 512; - let ee = cc.wrapping_sub(16) % 512; - - if self.counter1024 < 512 { - // P block - self.t[cc+0] = self.step_p(cc+0, cc+1, ee+13, ee+6, ee+4); - self.t[cc+1] = self.step_p(cc+1, cc+2, ee+14, ee+7, ee+5); - self.t[cc+2] = self.step_p(cc+2, cc+3, ee+15, ee+8, ee+6); - self.t[cc+3] = self.step_p(cc+3, cc+4, cc+0, ee+9, ee+7); - self.t[cc+4] = self.step_p(cc+4, cc+5, cc+1, ee+10, ee+8); - self.t[cc+5] = self.step_p(cc+5, cc+6, cc+2, ee+11, ee+9); - self.t[cc+6] = self.step_p(cc+6, cc+7, cc+3, ee+12, ee+10); - self.t[cc+7] = self.step_p(cc+7, cc+8, cc+4, ee+13, ee+11); - self.t[cc+8] = self.step_p(cc+8, cc+9, cc+5, ee+14, ee+12); - self.t[cc+9] = self.step_p(cc+9, cc+10, cc+6, ee+15, ee+13); - self.t[cc+10] = self.step_p(cc+10, cc+11, cc+7, cc+0, ee+14); - self.t[cc+11] = self.step_p(cc+11, cc+12, cc+8, cc+1, ee+15); - self.t[cc+12] = self.step_p(cc+12, cc+13, cc+9, cc+2, cc+0); - self.t[cc+13] = self.step_p(cc+13, cc+14, cc+10, cc+3, cc+1); - self.t[cc+14] = self.step_p(cc+14, cc+15, cc+11, cc+4, cc+2); - self.t[cc+15] = self.step_p(cc+15, dd+0, cc+12, cc+5, cc+3); - } else { - // Q block - self.t[cc+512+0] = self.step_q(cc+0, cc+1, ee+13, ee+6, ee+4); - self.t[cc+512+1] = self.step_q(cc+1, cc+2, ee+14, ee+7, ee+5); - self.t[cc+512+2] = self.step_q(cc+2, cc+3, ee+15, ee+8, ee+6); - self.t[cc+512+3] = self.step_q(cc+3, cc+4, cc+0, ee+9, ee+7); - self.t[cc+512+4] = self.step_q(cc+4, cc+5, cc+1, ee+10, ee+8); - self.t[cc+512+5] = self.step_q(cc+5, cc+6, cc+2, ee+11, ee+9); - self.t[cc+512+6] = self.step_q(cc+6, cc+7, cc+3, ee+12, ee+10); - self.t[cc+512+7] = self.step_q(cc+7, cc+8, cc+4, ee+13, ee+11); - self.t[cc+512+8] = self.step_q(cc+8, cc+9, cc+5, ee+14, ee+12); - self.t[cc+512+9] = self.step_q(cc+9, cc+10, cc+6, ee+15, ee+13); - self.t[cc+512+10] = self.step_q(cc+10, cc+11, cc+7, cc+0, ee+14); - self.t[cc+512+11] = self.step_q(cc+11, cc+12, cc+8, cc+1, ee+15); - self.t[cc+512+12] = self.step_q(cc+12, cc+13, cc+9, cc+2, cc+0); - self.t[cc+512+13] = self.step_q(cc+13, cc+14, cc+10, cc+3, cc+1); - self.t[cc+512+14] = self.step_q(cc+14, cc+15, cc+11, cc+4, cc+2); - self.t[cc+512+15] = self.step_q(cc+15, dd+0, cc+12, cc+5, cc+3); - } - self.counter1024 += 16; - } - - // Initialize an HC-128 random number generator. The seed has to be - // 256 bits in length (`[u32; 8]`), matching the 128 bit `key` followed by - // 128 bit `iv` when HC-128 where to be used as a stream cipher. - #[inline(always)] // single use: SeedableRng::from_seed - fn init(seed: [u32; SEED_WORDS]) -> Self { - #[inline] - fn f1(x: u32) -> u32 { - x.rotate_right(7) ^ x.rotate_right(18) ^ (x >> 3) - } - - #[inline] - fn f2(x: u32) -> u32 { - x.rotate_right(17) ^ x.rotate_right(19) ^ (x >> 10) - } - - let mut t = [0u32; 1024]; - - // Expand the key and iv into P and Q - let (key, iv) = seed.split_at(4); - t[..4].copy_from_slice(key); - t[4..8].copy_from_slice(key); - t[8..12].copy_from_slice(iv); - t[12..16].copy_from_slice(iv); - - // Generate the 256 intermediate values W[16] ... W[256+16-1], and - // copy the last 16 generated values to the start op P. - for i in 16..256+16 { - t[i] = f2(t[i-2]).wrapping_add(t[i-7]).wrapping_add(f1(t[i-15])) - .wrapping_add(t[i-16]).wrapping_add(i as u32); - } - { - let (p1, p2) = t.split_at_mut(256); - p1[0..16].copy_from_slice(&p2[0..16]); - } - - // Generate both the P and Q tables - for i in 16..1024 { - t[i] = f2(t[i-2]).wrapping_add(t[i-7]).wrapping_add(f1(t[i-15])) - .wrapping_add(t[i-16]).wrapping_add(256 + i as u32); - } - - let mut core = Self { t, counter1024: 0 }; - - // run the cipher 1024 steps - for _ in 0..64 { core.sixteen_steps() }; - core.counter1024 = 0; - core - } -} - -impl SeedableRng for Hc128Core { - type Seed = [u8; SEED_WORDS*4]; - - /// Create an HC-128 random number generator with a seed. The seed has to be - /// 256 bits in length, matching the 128 bit `key` followed by 128 bit `iv` - /// when HC-128 where to be used as a stream cipher. - fn from_seed(seed: Self::Seed) -> Self { - let mut seed_u32 = [0u32; SEED_WORDS]; - le::read_u32_into(&seed, &mut seed_u32); - Self::init(seed_u32) - } -} - -impl CryptoRng for Hc128Core {} - -#[cfg(test)] -mod test { - use ::rand_core::{RngCore, SeedableRng}; - use super::Hc128Rng; - - #[test] - // Test vector 1 from the paper "The Stream Cipher HC-128" - fn test_hc128_true_values_a() { - let seed = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // key - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; // iv - let mut rng = Hc128Rng::from_seed(seed); - - let mut results = [0u32; 16]; - for i in results.iter_mut() { *i = rng.next_u32(); } - let expected = [0x73150082, 0x3bfd03a0, 0xfb2fd77f, 0xaa63af0e, - 0xde122fc6, 0xa7dc29b6, 0x62a68527, 0x8b75ec68, - 0x9036db1e, 0x81896005, 0x00ade078, 0x491fbf9a, - 0x1cdc3013, 0x6c3d6e24, 0x90f664b2, 0x9cd57102]; - assert_eq!(results, expected); - } - - #[test] - // Test vector 2 from the paper "The Stream Cipher HC-128" - fn test_hc128_true_values_b() { - let seed = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // key - 1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; // iv - let mut rng = Hc128Rng::from_seed(seed); - - let mut results = [0u32; 16]; - for i in results.iter_mut() { *i = rng.next_u32(); } - let expected = [0xc01893d5, 0xb7dbe958, 0x8f65ec98, 0x64176604, - 0x36fc6724, 0xc82c6eec, 0x1b1c38a7, 0xc9b42a95, - 0x323ef123, 0x0a6a908b, 0xce757b68, 0x9f14f7bb, - 0xe4cde011, 0xaeb5173f, 0x89608c94, 0xb5cf46ca]; - assert_eq!(results, expected); - } - - #[test] - // Test vector 3 from the paper "The Stream Cipher HC-128" - fn test_hc128_true_values_c() { - let seed = [0x55,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // key - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; // iv - let mut rng = Hc128Rng::from_seed(seed); - - let mut results = [0u32; 16]; - for i in results.iter_mut() { *i = rng.next_u32(); } - let expected = [0x518251a4, 0x04b4930a, 0xb02af931, 0x0639f032, - 0xbcb4a47a, 0x5722480b, 0x2bf99f72, 0xcdc0e566, - 0x310f0c56, 0xd3cc83e8, 0x663db8ef, 0x62dfe07f, - 0x593e1790, 0xc5ceaa9c, 0xab03806f, 0xc9a6e5a0]; - assert_eq!(results, expected); - } - - #[test] - fn test_hc128_true_values_u64() { - let seed = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // key - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; // iv - let mut rng = Hc128Rng::from_seed(seed); - - let mut results = [0u64; 8]; - for i in results.iter_mut() { *i = rng.next_u64(); } - let expected = [0x3bfd03a073150082, 0xaa63af0efb2fd77f, - 0xa7dc29b6de122fc6, 0x8b75ec6862a68527, - 0x818960059036db1e, 0x491fbf9a00ade078, - 0x6c3d6e241cdc3013, 0x9cd5710290f664b2]; - assert_eq!(results, expected); - - // The RNG operates in a P block of 512 results and next a Q block. - // After skipping 2*800 u32 results we end up somewhere in the Q block - // of the second round - for _ in 0..800 { rng.next_u64(); } - - for i in results.iter_mut() { *i = rng.next_u64(); } - let expected = [0xd8c4d6ca84d0fc10, 0xf16a5d91dc66e8e7, - 0xd800de5bc37a8653, 0x7bae1f88c0dfbb4c, - 0x3bfe1f374e6d4d14, 0x424b55676be3fa06, - 0xe3a1e8758cbff579, 0x417f7198c5652bcd]; - assert_eq!(results, expected); - } - - #[test] - fn test_hc128_true_values_bytes() { - let seed = [0x55,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // key - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; // iv - let mut rng = Hc128Rng::from_seed(seed); - let expected = [0x31, 0xf9, 0x2a, 0xb0, 0x32, 0xf0, 0x39, 0x06, - 0x7a, 0xa4, 0xb4, 0xbc, 0x0b, 0x48, 0x22, 0x57, - 0x72, 0x9f, 0xf9, 0x2b, 0x66, 0xe5, 0xc0, 0xcd, - 0x56, 0x0c, 0x0f, 0x31, 0xe8, 0x83, 0xcc, 0xd3, - 0xef, 0xb8, 0x3d, 0x66, 0x7f, 0xe0, 0xdf, 0x62, - 0x90, 0x17, 0x3e, 0x59, 0x9c, 0xaa, 0xce, 0xc5, - 0x6f, 0x80, 0x03, 0xab, 0xa0, 0xe5, 0xa6, 0xc9, - 0x60, 0x95, 0x84, 0x7a, 0xa5, 0x68, 0x5a, 0x84, - 0xea, 0xd5, 0xf3, 0xea, 0x73, 0xa9, 0xad, 0x01, - 0x79, 0x7d, 0xbe, 0x9f, 0xea, 0xe3, 0xf9, 0x74, - 0x0e, 0xda, 0x2f, 0xa0, 0xe4, 0x7b, 0x4b, 0x1b, - 0xdd, 0x17, 0x69, 0x4a, 0xfe, 0x9f, 0x56, 0x95, - 0xad, 0x83, 0x6b, 0x9d, 0x60, 0xa1, 0x99, 0x96, - 0x90, 0x00, 0x66, 0x7f, 0xfa, 0x7e, 0x65, 0xe9, - 0xac, 0x8b, 0x92, 0x34, 0x77, 0xb4, 0x23, 0xd0, - 0xb9, 0xab, 0xb1, 0x47, 0x7d, 0x4a, 0x13, 0x0a]; - - // Pick a somewhat large buffer so we can test filling with the - // remainder from `state.results`, directly filling the buffer, and - // filling the remainder of the buffer. - let mut buffer = [0u8; 16*4*2]; - // Consume a value so that we have a remainder. - assert!(rng.next_u64() == 0x04b4930a518251a4); - rng.fill_bytes(&mut buffer); - - // [u8; 128] doesn't implement PartialEq - assert_eq!(buffer.len(), expected.len()); - for (b, e) in buffer.iter().zip(expected.iter()) { - assert_eq!(b, e); - } - } - - #[test] - fn test_hc128_clone() { - let seed = [0x55,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // key - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; // iv - let mut rng1 = Hc128Rng::from_seed(seed); - let mut rng2 = rng1.clone(); - for _ in 0..16 { - assert_eq!(rng1.next_u32(), rng2.next_u32()); - } - } -} diff --git a/rand/rand_hc/src/lib.rs b/rand/rand_hc/src/lib.rs deleted file mode 100644 index c1ae665..0000000 --- a/rand/rand_hc/src/lib.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The HC128 random number generator. - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] -#![doc(test(attr(allow(unused_variables), deny(warnings))))] - -#![no_std] - -mod hc128; - -pub use hc128::{Hc128Rng, Hc128Core}; diff --git a/rand/rand_isaac/CHANGELOG.md b/rand/rand_isaac/CHANGELOG.md deleted file mode 100644 index 0a5591f..0000000 --- a/rand/rand_isaac/CHANGELOG.md +++ /dev/null @@ -1,21 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.2.0] - 2019-06-12 -- Bump minor crate version since rand_core bump is a breaking change -- Switch to Edition 2018 - -## [0.1.2] - 2019-06-06 - yanked -- Bump `rand_core` version -- Remove deprecated code -- Adjust usage of `#[inline]` - -## [0.1.1] - 2018-11-26 -- Fix `rand_core` version requirement -- Fix doc links - -## [0.1.0] - 2018-10-17 -- Pulled out of the Rand crate diff --git a/rand/rand_isaac/COPYRIGHT b/rand/rand_isaac/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_isaac/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_isaac/Cargo.toml b/rand/rand_isaac/Cargo.toml deleted file mode 100644 index c11c305..0000000 --- a/rand/rand_isaac/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "rand_isaac" -version = "0.2.0" -authors = ["The Rand Project Developers", "The Rust Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_isaac/" -homepage = "https://crates.io/crates/rand_isaac" -description = """ -ISAAC random number generator -""" -keywords = ["random", "rng", "isaac"] -categories = ["algorithms", "no-std"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[features] -serde1 = ["serde", "rand_core/serde1"] - -[dependencies] -rand_core = { path = "../rand_core", version = "0.5" } -serde = { version = "1", features = ["derive"], optional = true } - -[dev-dependencies] -# This is for testing serde, unfortunately we can't specify feature-gated dev -# deps yet, see: https://github.com/rust-lang/cargo/issues/1596 -bincode = "1" diff --git a/rand/rand_isaac/LICENSE-APACHE b/rand/rand_isaac/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_isaac/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_isaac/LICENSE-MIT b/rand/rand_isaac/LICENSE-MIT deleted file mode 100644 index d93b5ba..0000000 --- a/rand/rand_isaac/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2018 Developers of the Rand project -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_isaac/README.md b/rand/rand_isaac/README.md deleted file mode 100644 index c16c63f..0000000 --- a/rand/rand_isaac/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# rand_isaac - -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_isaac.svg)](https://crates.io/crates/rand_isaac) -[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_isaac) -[![API](https://docs.rs/rand_isaac/badge.svg)](https://docs.rs/rand_isaac) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -Implements the ISAAC and ISAAC-64 random number generators. - -ISAAC stands for "Indirection, Shift, Accumulate, Add, and Count" which are -the principal bitwise operations employed. It is the most advanced of a -series of array based random number generator designed by Robert Jenkins -in 1996[^1][^2]. - -ISAAC is notably fast and produces excellent quality random numbers for -non-cryptographic applications. - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_isaac) -- [API documentation (docs.rs)](https://docs.rs/rand_isaac) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_isaac/CHANGELOG.md) - -[rand]: https://crates.io/crates/rand -[^1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number generator*](http://burtleburtle.net/bob/rand/isaacafa.html) -[^2]: Bob Jenkins, [*ISAAC and RC4*](http://burtleburtle.net/bob/rand/isaac.html) - - -## Crate Features - -`rand_isaac` is `no_std` compatible. It does not require any functionality -outside of the `core` lib, thus there are no features to configure. - -The `serde1` feature includes implementations of `Serialize` and `Deserialize` -for the included RNGs. - - -# License - -`rand_isaac` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_isaac/src/isaac.rs b/rand/rand_isaac/src/isaac.rs deleted file mode 100644 index 2caf61a..0000000 --- a/rand/rand_isaac/src/isaac.rs +++ /dev/null @@ -1,476 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2018 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The ISAAC random number generator. - -use core::{fmt, slice}; -use core::num::Wrapping as w; -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::{RngCore, SeedableRng, Error, le}; -use rand_core::block::{BlockRngCore, BlockRng}; -use crate::isaac_array::IsaacArray; - -#[allow(non_camel_case_types)] -type w32 = w; - -const RAND_SIZE_LEN: usize = 8; -const RAND_SIZE: usize = 1 << RAND_SIZE_LEN; - -/// A random number generator that uses the ISAAC algorithm. -/// -/// ISAAC stands for "Indirection, Shift, Accumulate, Add, and Count" which are -/// the principal bitwise operations employed. It is the most advanced of a -/// series of array based random number generator designed by Robert Jenkins -/// in 1996[^1][^2]. -/// -/// ISAAC is notably fast and produces excellent quality random numbers for -/// non-cryptographic applications. -/// -/// In spite of being designed with cryptographic security in mind, ISAAC hasn't -/// been stringently cryptanalyzed and thus cryptographers do not not -/// consensually trust it to be secure. When looking for a secure RNG, prefer -/// `Hc128Rng` from the [`rand_hc`] crate instead, which, like ISAAC, is an -/// array-based RNG and one of the stream-ciphers selected the by eSTREAM -/// -/// In 2006 an improvement to ISAAC was suggested by Jean-Philippe Aumasson, -/// named ISAAC+[^3]. But because the specification is not complete, because -/// there is no good implementation, and because the suggested bias may not -/// exist, it is not implemented here. -/// -/// ## Overview of the ISAAC algorithm: -/// (in pseudo-code) -/// -/// ```text -/// Input: a, b, c, s[256] // state -/// Output: r[256] // results -/// -/// mix(a,i) = a ^ a << 13 if i = 0 mod 4 -/// a ^ a >> 6 if i = 1 mod 4 -/// a ^ a << 2 if i = 2 mod 4 -/// a ^ a >> 16 if i = 3 mod 4 -/// -/// c = c + 1 -/// b = b + c -/// -/// for i in 0..256 { -/// x = s_[i] -/// a = f(a,i) + s[i+128 mod 256] -/// y = a + b + s[x>>2 mod 256] -/// s[i] = y -/// b = x + s[y>>10 mod 256] -/// r[i] = b -/// } -/// ``` -/// -/// Numbers are generated in blocks of 256. This means the function above only -/// runs once every 256 times you ask for a next random number. In all other -/// circumstances the last element of the results array is returned. -/// -/// ISAAC therefore needs a lot of memory, relative to other non-crypto RNGs. -/// 2 * 256 * 4 = 2 kb to hold the state and results. -/// -/// This implementation uses [`BlockRng`] to implement the [`RngCore`] methods. -/// -/// ## References -/// [^1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number generator*]( -/// http://burtleburtle.net/bob/rand/isaacafa.html) -/// -/// [^2]: Bob Jenkins, [*ISAAC and RC4*]( -/// http://burtleburtle.net/bob/rand/isaac.html) -/// -/// [^3]: Jean-Philippe Aumasson, [*On the pseudo-random generator ISAAC*]( -/// https://eprint.iacr.org/2006/438) -/// -/// [`rand_hc`]: https://docs.rs/rand_hc -#[derive(Clone, Debug)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct IsaacRng(BlockRng); - -impl RngCore for IsaacRng { - #[inline] - fn next_u32(&mut self) -> u32 { - self.0.next_u32() - } - - #[inline] - fn next_u64(&mut self) -> u64 { - self.0.next_u64() - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.0.fill_bytes(dest) - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.0.try_fill_bytes(dest) - } -} - -impl SeedableRng for IsaacRng { - type Seed = ::Seed; - - #[inline] - fn from_seed(seed: Self::Seed) -> Self { - IsaacRng(BlockRng::::from_seed(seed)) - } - - /// Create an ISAAC random number generator using an `u64` as seed. - /// If `seed == 0` this will produce the same stream of random numbers as - /// the reference implementation when used unseeded. - #[inline] - fn seed_from_u64(seed: u64) -> Self { - IsaacRng(BlockRng::::seed_from_u64(seed)) - } - - #[inline] - fn from_rng(rng: S) -> Result { - BlockRng::::from_rng(rng).map(|rng| IsaacRng(rng)) - } -} - -/// The core of [`IsaacRng`], used with [`BlockRng`]. -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct IsaacCore { - #[cfg_attr(feature="serde1",serde(with="super::isaac_array::isaac_array_serde"))] - mem: [w32; RAND_SIZE], - a: w32, - b: w32, - c: w32, -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for IsaacCore { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "IsaacCore {{}}") - } -} - -impl BlockRngCore for IsaacCore { - type Item = u32; - type Results = IsaacArray; - - /// Refills the output buffer, `results`. See also the pseudocode desciption - /// of the algorithm in the `IsaacRng` documentation. - /// - /// Optimisations used (similar to the reference implementation): - /// - /// - The loop is unrolled 4 times, once for every constant of mix(). - /// - The contents of the main loop are moved to a function `rngstep`, to - /// reduce code duplication. - /// - We use local variables for a and b, which helps with optimisations. - /// - We split the main loop in two, one that operates over 0..128 and one - /// over 128..256. This way we can optimise out the addition and modulus - /// from `s[i+128 mod 256]`. - /// - We maintain one index `i` and add `m` or `m2` as base (m2 for the - /// `s[i+128 mod 256]`), relying on the optimizer to turn it into pointer - /// arithmetic. - /// - We fill `results` backwards. The reference implementation reads values - /// from `results` in reverse. We read them in the normal direction, to - /// make `fill_bytes` a memcopy. To maintain compatibility we fill in - /// reverse. - fn generate(&mut self, results: &mut IsaacArray) { - self.c += w(1); - // abbreviations - let mut a = self.a; - let mut b = self.b + self.c; - const MIDPOINT: usize = RAND_SIZE / 2; - - #[inline] - fn ind(mem:&[w32; RAND_SIZE], v: w32, amount: usize) -> w32 { - let index = (v >> amount).0 as usize % RAND_SIZE; - mem[index] - } - - #[inline] - fn rngstep(mem: &mut [w32; RAND_SIZE], - results: &mut [u32; RAND_SIZE], - mix: w32, - a: &mut w32, - b: &mut w32, - base: usize, - m: usize, - m2: usize) { - let x = mem[base + m]; - *a = mix + mem[base + m2]; - let y = *a + *b + ind(&mem, x, 2); - mem[base + m] = y; - *b = x + ind(&mem, y, 2 + RAND_SIZE_LEN); - results[RAND_SIZE - 1 - base - m] = (*b).0; - } - - let mut m = 0; - let mut m2 = MIDPOINT; - for i in (0..MIDPOINT/4).map(|i| i * 4) { - rngstep(&mut self.mem, results, a ^ (a << 13), &mut a, &mut b, i + 0, m, m2); - rngstep(&mut self.mem, results, a ^ (a >> 6 ), &mut a, &mut b, i + 1, m, m2); - rngstep(&mut self.mem, results, a ^ (a << 2 ), &mut a, &mut b, i + 2, m, m2); - rngstep(&mut self.mem, results, a ^ (a >> 16), &mut a, &mut b, i + 3, m, m2); - } - - m = MIDPOINT; - m2 = 0; - for i in (0..MIDPOINT/4).map(|i| i * 4) { - rngstep(&mut self.mem, results, a ^ (a << 13), &mut a, &mut b, i + 0, m, m2); - rngstep(&mut self.mem, results, a ^ (a >> 6 ), &mut a, &mut b, i + 1, m, m2); - rngstep(&mut self.mem, results, a ^ (a << 2 ), &mut a, &mut b, i + 2, m, m2); - rngstep(&mut self.mem, results, a ^ (a >> 16), &mut a, &mut b, i + 3, m, m2); - } - - self.a = a; - self.b = b; - } -} - -impl IsaacCore { - /// Create a new ISAAC random number generator. - /// - /// The author Bob Jenkins describes how to best initialize ISAAC here: - /// - /// The answer is included here just in case: - /// - /// "No, you don't need a full 8192 bits of seed data. Normal key sizes will - /// do fine, and they should have their expected strength (eg a 40-bit key - /// will take as much time to brute force as 40-bit keys usually will). You - /// could fill the remainder with 0, but set the last array element to the - /// length of the key provided (to distinguish keys that differ only by - /// different amounts of 0 padding). You do still need to call `randinit()` - /// to make sure the initial state isn't uniform-looking." - /// "After publishing ISAAC, I wanted to limit the key to half the size of - /// `r[]`, and repeat it twice. That would have made it hard to provide a - /// key that sets the whole internal state to anything convenient. But I'd - /// already published it." - /// - /// And his answer to the question "For my code, would repeating the key - /// over and over to fill 256 integers be a better solution than - /// zero-filling, or would they essentially be the same?": - /// "If the seed is under 32 bytes, they're essentially the same, otherwise - /// repeating the seed would be stronger. randinit() takes a chunk of 32 - /// bytes, mixes it, and combines that with the next 32 bytes, et cetera. - /// Then loops over all the elements the same way a second time." - #[inline] - fn init(mut mem: [w32; RAND_SIZE], rounds: u32) -> Self { - fn mix(a: &mut w32, b: &mut w32, c: &mut w32, d: &mut w32, - e: &mut w32, f: &mut w32, g: &mut w32, h: &mut w32) { - *a ^= *b << 11; *d += *a; *b += *c; - *b ^= *c >> 2; *e += *b; *c += *d; - *c ^= *d << 8; *f += *c; *d += *e; - *d ^= *e >> 16; *g += *d; *e += *f; - *e ^= *f << 10; *h += *e; *f += *g; - *f ^= *g >> 4; *a += *f; *g += *h; - *g ^= *h << 8; *b += *g; *h += *a; - *h ^= *a >> 9; *c += *h; *a += *b; - } - - // These numbers are the result of initializing a...h with the - // fractional part of the golden ratio in binary (0x9e3779b9) - // and applying mix() 4 times. - let mut a = w(0x1367df5a); - let mut b = w(0x95d90059); - let mut c = w(0xc3163e4b); - let mut d = w(0x0f421ad8); - let mut e = w(0xd92a4a78); - let mut f = w(0xa51a3c49); - let mut g = w(0xc4efea1b); - let mut h = w(0x30609119); - - // Normally this should do two passes, to make all of the seed effect - // all of `mem` - for _ in 0..rounds { - for i in (0..RAND_SIZE/8).map(|i| i * 8) { - a += mem[i ]; b += mem[i+1]; - c += mem[i+2]; d += mem[i+3]; - e += mem[i+4]; f += mem[i+5]; - g += mem[i+6]; h += mem[i+7]; - mix(&mut a, &mut b, &mut c, &mut d, - &mut e, &mut f, &mut g, &mut h); - mem[i ] = a; mem[i+1] = b; - mem[i+2] = c; mem[i+3] = d; - mem[i+4] = e; mem[i+5] = f; - mem[i+6] = g; mem[i+7] = h; - } - } - - Self { mem, a: w(0), b: w(0), c: w(0) } - } -} - -impl SeedableRng for IsaacCore { - type Seed = [u8; 32]; - - fn from_seed(seed: Self::Seed) -> Self { - let mut seed_u32 = [0u32; 8]; - le::read_u32_into(&seed, &mut seed_u32); - // Convert the seed to `Wrapping` and zero-extend to `RAND_SIZE`. - let mut seed_extended = [w(0); RAND_SIZE]; - for (x, y) in seed_extended.iter_mut().zip(seed_u32.iter()) { - *x = w(*y); - } - Self::init(seed_extended, 2) - } - - /// Create an ISAAC random number generator using an `u64` as seed. - /// If `seed == 0` this will produce the same stream of random numbers as - /// the reference implementation when used unseeded. - fn seed_from_u64(seed: u64) -> Self { - let mut key = [w(0); RAND_SIZE]; - key[0] = w(seed as u32); - key[1] = w((seed >> 32) as u32); - // Initialize with only one pass. - // A second pass does not improve the quality here, because all of the - // seed was already available in the first round. - // Not doing the second pass has the small advantage that if - // `seed == 0` this method produces exactly the same state as the - // reference implementation when used unseeded. - Self::init(key, 1) - } - - fn from_rng(mut rng: R) -> Result { - // Custom `from_rng` implementation that fills a seed with the same size - // as the entire state. - let mut seed = [w(0u32); RAND_SIZE]; - unsafe { - let ptr = seed.as_mut_ptr() as *mut u8; - - let slice = slice::from_raw_parts_mut(ptr, RAND_SIZE * 4); - rng.try_fill_bytes(slice)?; - } - for i in seed.iter_mut() { - *i = w(i.0.to_le()); - } - - Ok(Self::init(seed, 2)) - } -} - -#[cfg(test)] -mod test { - use rand_core::{RngCore, SeedableRng}; - use super::IsaacRng; - - #[test] - fn test_isaac_construction() { - // Test that various construction techniques produce a working RNG. - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng1 = IsaacRng::from_seed(seed); - assert_eq!(rng1.next_u32(), 2869442790); - - let mut rng2 = IsaacRng::from_rng(rng1).unwrap(); - assert_eq!(rng2.next_u32(), 3094074039); - } - - #[test] - fn test_isaac_true_values_32() { - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 57,48,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng1 = IsaacRng::from_seed(seed); - let mut results = [0u32; 10]; - for i in results.iter_mut() { *i = rng1.next_u32(); } - let expected = [ - 2558573138, 873787463, 263499565, 2103644246, 3595684709, - 4203127393, 264982119, 2765226902, 2737944514, 3900253796]; - assert_eq!(results, expected); - - let seed = [57,48,0,0, 50,9,1,0, 49,212,0,0, 148,38,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng2 = IsaacRng::from_seed(seed); - // skip forward to the 10000th number - for _ in 0..10000 { rng2.next_u32(); } - - for i in results.iter_mut() { *i = rng2.next_u32(); } - let expected = [ - 3676831399, 3183332890, 2834741178, 3854698763, 2717568474, - 1576568959, 3507990155, 179069555, 141456972, 2478885421]; - assert_eq!(results, expected); - } - - #[test] - fn test_isaac_true_values_64() { - // As above, using little-endian versions of above values - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 57,48,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng = IsaacRng::from_seed(seed); - let mut results = [0u64; 5]; - for i in results.iter_mut() { *i = rng.next_u64(); } - let expected = [ - 3752888579798383186, 9035083239252078381,18052294697452424037, - 11876559110374379111, 16751462502657800130]; - assert_eq!(results, expected); - } - - #[test] - fn test_isaac_true_bytes() { - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 57,48,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng = IsaacRng::from_seed(seed); - let mut results = [0u8; 32]; - rng.fill_bytes(&mut results); - // Same as first values in test_isaac_true_values as bytes in LE order - let expected = [82, 186, 128, 152, 71, 240, 20, 52, - 45, 175, 180, 15, 86, 16, 99, 125, - 101, 203, 81, 214, 97, 162, 134, 250, - 103, 78, 203, 15, 150, 3, 210, 164]; - assert_eq!(results, expected); - } - - #[test] - fn test_isaac_new_uninitialized() { - // Compare the results from initializing `IsaacRng` with - // `seed_from_u64(0)`, to make sure it is the same as the reference - // implementation when used uninitialized. - // Note: We only test the first 16 integers, not the full 256 of the - // first block. - let mut rng = IsaacRng::seed_from_u64(0); - let mut results = [0u32; 16]; - for i in results.iter_mut() { *i = rng.next_u32(); } - let expected: [u32; 16] = [ - 0x71D71FD2, 0xB54ADAE7, 0xD4788559, 0xC36129FA, - 0x21DC1EA9, 0x3CB879CA, 0xD83B237F, 0xFA3CE5BD, - 0x8D048509, 0xD82E9489, 0xDB452848, 0xCA20E846, - 0x500F972E, 0x0EEFF940, 0x00D6B993, 0xBC12C17F]; - assert_eq!(results, expected); - } - - #[test] - fn test_isaac_clone() { - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 57,48,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng1 = IsaacRng::from_seed(seed); - let mut rng2 = rng1.clone(); - for _ in 0..16 { - assert_eq!(rng1.next_u32(), rng2.next_u32()); - } - } - - #[test] - #[cfg(feature="serde1")] - fn test_isaac_serde() { - use bincode; - use std::io::{BufWriter, BufReader}; - - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 57,48,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng = IsaacRng::from_seed(seed); - - let buf: Vec = Vec::new(); - let mut buf = BufWriter::new(buf); - bincode::serialize_into(&mut buf, &rng).expect("Could not serialize"); - - let buf = buf.into_inner().unwrap(); - let mut read = BufReader::new(&buf[..]); - let mut deserialized: IsaacRng = bincode::deserialize_from(&mut read).expect("Could not deserialize"); - - for _ in 0..300 { // more than the 256 buffered results - assert_eq!(rng.next_u32(), deserialized.next_u32()); - } - } -} diff --git a/rand/rand_isaac/src/isaac64.rs b/rand/rand_isaac/src/isaac64.rs deleted file mode 100644 index 7d4b88c..0000000 --- a/rand/rand_isaac/src/isaac64.rs +++ /dev/null @@ -1,466 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2018 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The ISAAC-64 random number generator. - -use core::{fmt, slice}; -use core::num::Wrapping as w; -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::{RngCore, SeedableRng, Error, le}; -use rand_core::block::{BlockRngCore, BlockRng64}; -use crate::isaac_array::IsaacArray; - -#[allow(non_camel_case_types)] -type w64 = w; - -const RAND_SIZE_LEN: usize = 8; -const RAND_SIZE: usize = 1 << RAND_SIZE_LEN; - -/// A random number generator that uses ISAAC-64, the 64-bit variant of the -/// ISAAC algorithm. -/// -/// ISAAC stands for "Indirection, Shift, Accumulate, Add, and Count" which are -/// the principal bitwise operations employed. It is the most advanced of a -/// series of array based random number generator designed by Robert Jenkins -/// in 1996[^1]. -/// -/// ISAAC-64 is mostly similar to ISAAC. Because it operates on 64-bit integers -/// instead of 32-bit, it uses twice as much memory to hold its state and -/// results. Also it uses different constants for shifts and indirect indexing, -/// optimized to give good results for 64bit arithmetic. -/// -/// ISAAC-64 is notably fast and produces excellent quality random numbers for -/// non-cryptographic applications. -/// -/// In spite of being designed with cryptographic security in mind, ISAAC hasn't -/// been stringently cryptanalyzed and thus cryptographers do not not -/// consensually trust it to be secure. When looking for a secure RNG, prefer -/// `Hc128Rng` from the [`rand_hc`] crate instead, which, like ISAAC, is an -/// array-based RNG and one of the stream-ciphers selected the by eSTREAM -/// -/// ## Overview of the ISAAC-64 algorithm: -/// (in pseudo-code) -/// -/// ```text -/// Input: a, b, c, s[256] // state -/// Output: r[256] // results -/// -/// mix(a,i) = !(a ^ a << 21) if i = 0 mod 4 -/// a ^ a >> 5 if i = 1 mod 4 -/// a ^ a << 12 if i = 2 mod 4 -/// a ^ a >> 33 if i = 3 mod 4 -/// -/// c = c + 1 -/// b = b + c -/// -/// for i in 0..256 { -/// x = s_[i] -/// a = mix(a,i) + s[i+128 mod 256] -/// y = a + b + s[x>>3 mod 256] -/// s[i] = y -/// b = x + s[y>>11 mod 256] -/// r[i] = b -/// } -/// ``` -/// -/// This implementation uses [`BlockRng64`] to implement the [`RngCore`] methods. -/// -/// See for more information the documentation of [`IsaacRng`]. -/// -/// [^1]: Bob Jenkins, [*ISAAC and RC4*]( -/// http://burtleburtle.net/bob/rand/isaac.html) -/// -/// [`IsaacRng`]: crate::isaac::IsaacRng -/// [`rand_hc`]: https://docs.rs/rand_hc -/// [`BlockRng64`]: rand_core::block::BlockRng64 -#[derive(Clone, Debug)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Isaac64Rng(BlockRng64); - -impl RngCore for Isaac64Rng { - #[inline] - fn next_u32(&mut self) -> u32 { - self.0.next_u32() - } - - #[inline] - fn next_u64(&mut self) -> u64 { - self.0.next_u64() - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.0.fill_bytes(dest) - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.0.try_fill_bytes(dest) - } -} - -impl SeedableRng for Isaac64Rng { - type Seed = ::Seed; - - #[inline] - fn from_seed(seed: Self::Seed) -> Self { - Isaac64Rng(BlockRng64::::from_seed(seed)) - } - - /// Create an ISAAC random number generator using an `u64` as seed. - /// If `seed == 0` this will produce the same stream of random numbers as - /// the reference implementation when used unseeded. - #[inline] - fn seed_from_u64(seed: u64) -> Self { - Isaac64Rng(BlockRng64::::seed_from_u64(seed)) - } - - #[inline] - fn from_rng(rng: S) -> Result { - BlockRng64::::from_rng(rng).map(|rng| Isaac64Rng(rng)) - } -} - -/// The core of `Isaac64Rng`, used with `BlockRng`. -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Isaac64Core { - #[cfg_attr(feature="serde1",serde(with="super::isaac_array::isaac_array_serde"))] - mem: [w64; RAND_SIZE], - a: w64, - b: w64, - c: w64, -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for Isaac64Core { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Isaac64Core {{}}") - } -} - -impl BlockRngCore for Isaac64Core { - type Item = u64; - type Results = IsaacArray; - - /// Refills the output buffer, `results`. See also the pseudocode desciption - /// of the algorithm in the `Isaac64Rng` documentation. - /// - /// Optimisations used (similar to the reference implementation): - /// - /// - The loop is unrolled 4 times, once for every constant of mix(). - /// - The contents of the main loop are moved to a function `rngstep`, to - /// reduce code duplication. - /// - We use local variables for a and b, which helps with optimisations. - /// - We split the main loop in two, one that operates over 0..128 and one - /// over 128..256. This way we can optimise out the addition and modulus - /// from `s[i+128 mod 256]`. - /// - We maintain one index `i` and add `m` or `m2` as base (m2 for the - /// `s[i+128 mod 256]`), relying on the optimizer to turn it into pointer - /// arithmetic. - /// - We fill `results` backwards. The reference implementation reads values - /// from `results` in reverse. We read them in the normal direction, to - /// make `fill_bytes` a memcopy. To maintain compatibility we fill in - /// reverse. - fn generate(&mut self, results: &mut IsaacArray) { - self.c += w(1); - // abbreviations - let mut a = self.a; - let mut b = self.b + self.c; - const MIDPOINT: usize = RAND_SIZE / 2; - - #[inline] - fn ind(mem:&[w64; RAND_SIZE], v: w64, amount: usize) -> w64 { - let index = (v >> amount).0 as usize % RAND_SIZE; - mem[index] - } - - #[inline] - fn rngstep(mem: &mut [w64; RAND_SIZE], - results: &mut [u64; RAND_SIZE], - mix: w64, - a: &mut w64, - b: &mut w64, - base: usize, - m: usize, - m2: usize) { - let x = mem[base + m]; - *a = mix + mem[base + m2]; - let y = *a + *b + ind(&mem, x, 3); - mem[base + m] = y; - *b = x + ind(&mem, y, 3 + RAND_SIZE_LEN); - results[RAND_SIZE - 1 - base - m] = (*b).0; - } - - let mut m = 0; - let mut m2 = MIDPOINT; - for i in (0..MIDPOINT/4).map(|i| i * 4) { - rngstep(&mut self.mem, results, !(a ^ (a << 21)), &mut a, &mut b, i + 0, m, m2); - rngstep(&mut self.mem, results, a ^ (a >> 5 ), &mut a, &mut b, i + 1, m, m2); - rngstep(&mut self.mem, results, a ^ (a << 12), &mut a, &mut b, i + 2, m, m2); - rngstep(&mut self.mem, results, a ^ (a >> 33), &mut a, &mut b, i + 3, m, m2); - } - - m = MIDPOINT; - m2 = 0; - for i in (0..MIDPOINT/4).map(|i| i * 4) { - rngstep(&mut self.mem, results, !(a ^ (a << 21)), &mut a, &mut b, i + 0, m, m2); - rngstep(&mut self.mem, results, a ^ (a >> 5 ), &mut a, &mut b, i + 1, m, m2); - rngstep(&mut self.mem, results, a ^ (a << 12), &mut a, &mut b, i + 2, m, m2); - rngstep(&mut self.mem, results, a ^ (a >> 33), &mut a, &mut b, i + 3, m, m2); - } - - self.a = a; - self.b = b; - } -} - -impl Isaac64Core { - /// Create a new ISAAC-64 random number generator. - fn init(mut mem: [w64; RAND_SIZE], rounds: u32) -> Self { - fn mix(a: &mut w64, b: &mut w64, c: &mut w64, d: &mut w64, - e: &mut w64, f: &mut w64, g: &mut w64, h: &mut w64) { - *a -= *e; *f ^= *h >> 9; *h += *a; - *b -= *f; *g ^= *a << 9; *a += *b; - *c -= *g; *h ^= *b >> 23; *b += *c; - *d -= *h; *a ^= *c << 15; *c += *d; - *e -= *a; *b ^= *d >> 14; *d += *e; - *f -= *b; *c ^= *e << 20; *e += *f; - *g -= *c; *d ^= *f >> 17; *f += *g; - *h -= *d; *e ^= *g << 14; *g += *h; - } - - // These numbers are the result of initializing a...h with the - // fractional part of the golden ratio in binary (0x9e3779b97f4a7c13) - // and applying mix() 4 times. - let mut a = w(0x647c4677a2884b7c); - let mut b = w(0xb9f8b322c73ac862); - let mut c = w(0x8c0ea5053d4712a0); - let mut d = w(0xb29b2e824a595524); - let mut e = w(0x82f053db8355e0ce); - let mut f = w(0x48fe4a0fa5a09315); - let mut g = w(0xae985bf2cbfc89ed); - let mut h = w(0x98f5704f6c44c0ab); - - // Normally this should do two passes, to make all of the seed effect - // all of `mem` - for _ in 0..rounds { - for i in (0..RAND_SIZE/8).map(|i| i * 8) { - a += mem[i ]; b += mem[i+1]; - c += mem[i+2]; d += mem[i+3]; - e += mem[i+4]; f += mem[i+5]; - g += mem[i+6]; h += mem[i+7]; - mix(&mut a, &mut b, &mut c, &mut d, - &mut e, &mut f, &mut g, &mut h); - mem[i ] = a; mem[i+1] = b; - mem[i+2] = c; mem[i+3] = d; - mem[i+4] = e; mem[i+5] = f; - mem[i+6] = g; mem[i+7] = h; - } - } - - Self { mem, a: w(0), b: w(0), c: w(0) } - } -} - -impl SeedableRng for Isaac64Core { - type Seed = [u8; 32]; - - fn from_seed(seed: Self::Seed) -> Self { - let mut seed_u64 = [0u64; 4]; - le::read_u64_into(&seed, &mut seed_u64); - // Convert the seed to `Wrapping` and zero-extend to `RAND_SIZE`. - let mut seed_extended = [w(0); RAND_SIZE]; - for (x, y) in seed_extended.iter_mut().zip(seed_u64.iter()) { - *x = w(*y); - } - Self::init(seed_extended, 2) - } - - fn seed_from_u64(seed: u64) -> Self { - let mut key = [w(0); RAND_SIZE]; - key[0] = w(seed); - // Initialize with only one pass. - // A second pass does not improve the quality here, because all of the - // seed was already available in the first round. - // Not doing the second pass has the small advantage that if - // `seed == 0` this method produces exactly the same state as the - // reference implementation when used unseeded. - Self::init(key, 1) - } - - fn from_rng(mut rng: R) -> Result { - // Custom `from_rng` implementation that fills a seed with the same size - // as the entire state. - let mut seed = [w(0u64); RAND_SIZE]; - unsafe { - let ptr = seed.as_mut_ptr() as *mut u8; - let slice = slice::from_raw_parts_mut(ptr, RAND_SIZE * 8); - rng.try_fill_bytes(slice)?; - } - for i in seed.iter_mut() { - *i = w(i.0.to_le()); - } - - Ok(Self::init(seed, 2)) - } -} - -#[cfg(test)] -mod test { - use rand_core::{RngCore, SeedableRng}; - use super::Isaac64Rng; - - #[test] - fn test_isaac64_construction() { - // Test that various construction techniques produce a working RNG. - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng1 = Isaac64Rng::from_seed(seed); - assert_eq!(rng1.next_u64(), 14964555543728284049); - - let mut rng2 = Isaac64Rng::from_rng(rng1).unwrap(); - assert_eq!(rng2.next_u64(), 919595328260451758); - } - - #[test] - fn test_isaac64_true_values_64() { - let seed = [1,0,0,0, 0,0,0,0, 23,0,0,0, 0,0,0,0, - 200,1,0,0, 0,0,0,0, 210,30,0,0, 0,0,0,0]; - let mut rng1 = Isaac64Rng::from_seed(seed); - let mut results = [0u64; 10]; - for i in results.iter_mut() { *i = rng1.next_u64(); } - let expected = [ - 15071495833797886820, 7720185633435529318, - 10836773366498097981, 5414053799617603544, - 12890513357046278984, 17001051845652595546, - 9240803642279356310, 12558996012687158051, - 14673053937227185542, 1677046725350116783]; - assert_eq!(results, expected); - - let seed = [57,48,0,0, 0,0,0,0, 50,9,1,0, 0,0,0,0, - 49,212,0,0, 0,0,0,0, 148,38,0,0, 0,0,0,0]; - let mut rng2 = Isaac64Rng::from_seed(seed); - // skip forward to the 10000th number - for _ in 0..10000 { rng2.next_u64(); } - - for i in results.iter_mut() { *i = rng2.next_u64(); } - let expected = [ - 18143823860592706164, 8491801882678285927, 2699425367717515619, - 17196852593171130876, 2606123525235546165, 15790932315217671084, - 596345674630742204, 9947027391921273664, 11788097613744130851, - 10391409374914919106]; - assert_eq!(results, expected); - } - - #[test] - fn test_isaac64_true_values_32() { - let seed = [1,0,0,0, 0,0,0,0, 23,0,0,0, 0,0,0,0, - 200,1,0,0, 0,0,0,0, 210,30,0,0, 0,0,0,0]; - let mut rng = Isaac64Rng::from_seed(seed); - let mut results = [0u32; 12]; - for i in results.iter_mut() { *i = rng.next_u32(); } - // Subset of above values, as an LE u32 sequence - let expected = [ - 3477963620, 3509106075, - 687845478, 1797495790, - 227048253, 2523132918, - 4044335064, 1260557630, - 4079741768, 3001306521, - 69157722, 3958365844]; - assert_eq!(results, expected); - } - - #[test] - fn test_isaac64_true_values_mixed() { - let seed = [1,0,0,0, 0,0,0,0, 23,0,0,0, 0,0,0,0, - 200,1,0,0, 0,0,0,0, 210,30,0,0, 0,0,0,0]; - let mut rng = Isaac64Rng::from_seed(seed); - // Test alternating between `next_u64` and `next_u32` works as expected. - // Values are the same as `test_isaac64_true_values` and - // `test_isaac64_true_values_32`. - assert_eq!(rng.next_u64(), 15071495833797886820); - assert_eq!(rng.next_u32(), 687845478); - assert_eq!(rng.next_u32(), 1797495790); - assert_eq!(rng.next_u64(), 10836773366498097981); - assert_eq!(rng.next_u32(), 4044335064); - // Skip one u32 - assert_eq!(rng.next_u64(), 12890513357046278984); - assert_eq!(rng.next_u32(), 69157722); - } - - #[test] - fn test_isaac64_true_bytes() { - let seed = [1,0,0,0, 0,0,0,0, 23,0,0,0, 0,0,0,0, - 200,1,0,0, 0,0,0,0, 210,30,0,0, 0,0,0,0]; - let mut rng = Isaac64Rng::from_seed(seed); - let mut results = [0u8; 32]; - rng.fill_bytes(&mut results); - // Same as first values in test_isaac64_true_values as bytes in LE order - let expected = [100, 131, 77, 207, 155, 181, 40, 209, - 102, 176, 255, 40, 238, 155, 35, 107, - 61, 123, 136, 13, 246, 243, 99, 150, - 216, 167, 15, 241, 62, 149, 34, 75]; - assert_eq!(results, expected); - } - - #[test] - fn test_isaac64_new_uninitialized() { - // Compare the results from initializing `IsaacRng` with - // `seed_from_u64(0)`, to make sure it is the same as the reference - // implementation when used uninitialized. - // Note: We only test the first 16 integers, not the full 256 of the - // first block. - let mut rng = Isaac64Rng::seed_from_u64(0); - let mut results = [0u64; 16]; - for i in results.iter_mut() { *i = rng.next_u64(); } - let expected: [u64; 16] = [ - 0xF67DFBA498E4937C, 0x84A5066A9204F380, 0xFEE34BD5F5514DBB, - 0x4D1664739B8F80D6, 0x8607459AB52A14AA, 0x0E78BC5A98529E49, - 0xFE5332822AD13777, 0x556C27525E33D01A, 0x08643CA615F3149F, - 0xD0771FAF3CB04714, 0x30E86F68A37B008D, 0x3074EBC0488A3ADF, - 0x270645EA7A2790BC, 0x5601A0A8D3763C6A, 0x2F83071F53F325DD, - 0xB9090F3D42D2D2EA]; - assert_eq!(results, expected); - } - - #[test] - fn test_isaac64_clone() { - let seed = [1,0,0,0, 0,0,0,0, 23,0,0,0, 0,0,0,0, - 200,1,0,0, 0,0,0,0, 210,30,0,0, 0,0,0,0]; - let mut rng1 = Isaac64Rng::from_seed(seed); - let mut rng2 = rng1.clone(); - for _ in 0..16 { - assert_eq!(rng1.next_u64(), rng2.next_u64()); - } - } - - #[test] - #[cfg(feature="serde1")] - fn test_isaac64_serde() { - use bincode; - use std::io::{BufWriter, BufReader}; - - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 57,48,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng = Isaac64Rng::from_seed(seed); - - let buf: Vec = Vec::new(); - let mut buf = BufWriter::new(buf); - bincode::serialize_into(&mut buf, &rng).expect("Could not serialize"); - - let buf = buf.into_inner().unwrap(); - let mut read = BufReader::new(&buf[..]); - let mut deserialized: Isaac64Rng = bincode::deserialize_from(&mut read).expect("Could not deserialize"); - - for _ in 0..300 { // more than the 256 buffered results - assert_eq!(rng.next_u64(), deserialized.next_u64()); - } - } -} diff --git a/rand/rand_isaac/src/isaac_array.rs b/rand/rand_isaac/src/isaac_array.rs deleted file mode 100644 index cbe4a59..0000000 --- a/rand/rand_isaac/src/isaac_array.rs +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2017-2018 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! ISAAC helper functions for 256-element arrays. - -// Terrible workaround because arrays with more than 32 elements do not -// implement `AsRef`, `Default`, `Serialize`, `Deserialize`, or any other -// traits for that matter. - -#[cfg(feature="serde")] use serde::{Serialize, Deserialize}; - -const RAND_SIZE_LEN: usize = 8; -const RAND_SIZE: usize = 1 << RAND_SIZE_LEN; - - -#[derive(Copy, Clone)] -#[allow(missing_debug_implementations)] -#[cfg_attr(feature="serde", derive(Serialize, Deserialize))] -pub struct IsaacArray { - #[cfg_attr(feature="serde",serde(with="isaac_array_serde"))] - #[cfg_attr(feature="serde", serde(bound( - serialize = "T: Serialize", - deserialize = "T: Deserialize<'de> + Copy + Default")))] - inner: [T; RAND_SIZE] -} - -impl ::core::convert::AsRef<[T]> for IsaacArray { - #[inline(always)] - fn as_ref(&self) -> &[T] { - &self.inner[..] - } -} - -impl ::core::convert::AsMut<[T]> for IsaacArray { - #[inline(always)] - fn as_mut(&mut self) -> &mut [T] { - &mut self.inner[..] - } -} - -impl ::core::ops::Deref for IsaacArray { - type Target = [T; RAND_SIZE]; - #[inline(always)] - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl ::core::ops::DerefMut for IsaacArray { - #[inline(always)] - fn deref_mut(&mut self) -> &mut [T; RAND_SIZE] { - &mut self.inner - } -} - -impl ::core::default::Default for IsaacArray where T: Copy + Default { - fn default() -> IsaacArray { - IsaacArray { inner: [T::default(); RAND_SIZE] } - } -} - - -#[cfg(feature="serde")] -pub(super) mod isaac_array_serde { - const RAND_SIZE_LEN: usize = 8; - const RAND_SIZE: usize = 1 << RAND_SIZE_LEN; - - use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use serde::de::{Visitor,SeqAccess}; - use serde::de; - - use core::fmt; - - pub fn serialize(arr: &[T;RAND_SIZE], ser: S) -> Result - where - T: Serialize, - S: Serializer - { - use serde::ser::SerializeTuple; - - let mut seq = ser.serialize_tuple(RAND_SIZE)?; - - for e in arr.iter() { - seq.serialize_element(&e)?; - } - - seq.end() - } - - #[inline] - pub fn deserialize<'de, T, D>(de: D) -> Result<[T;RAND_SIZE], D::Error> - where - T: Deserialize<'de>+Default+Copy, - D: Deserializer<'de>, - { - use core::marker::PhantomData; - struct ArrayVisitor { - _pd: PhantomData, - }; - impl<'de,T> Visitor<'de> for ArrayVisitor - where - T: Deserialize<'de>+Default+Copy - { - type Value = [T; RAND_SIZE]; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("Isaac state array") - } - - #[inline] - fn visit_seq(self, mut seq: A) -> Result<[T; RAND_SIZE], A::Error> - where - A: SeqAccess<'de>, - { - let mut out = [Default::default();RAND_SIZE]; - - for i in 0..RAND_SIZE { - match seq.next_element()? { - Some(val) => out[i] = val, - None => return Err(de::Error::invalid_length(i, &self)), - }; - } - - Ok(out) - } - } - - de.deserialize_tuple(RAND_SIZE, ArrayVisitor{_pd: PhantomData}) - } -} diff --git a/rand/rand_isaac/src/lib.rs b/rand/rand_isaac/src/lib.rs deleted file mode 100644 index 84cdf21..0000000 --- a/rand/rand_isaac/src/lib.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The ISAAC and ISAAC-64 random number generators. - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] -#![doc(test(attr(allow(unused_variables), deny(warnings))))] - -#![cfg_attr(not(all(feature="serde", test)), no_std)] - -pub mod isaac; -pub mod isaac64; - -mod isaac_array; - -pub use self::isaac::IsaacRng; -pub use self::isaac64::Isaac64Rng; diff --git a/rand/rand_jitter/CHANGELOG.md b/rand/rand_jitter/CHANGELOG.md deleted file mode 100644 index 9f4bb7e..0000000 --- a/rand/rand_jitter/CHANGELOG.md +++ /dev/null @@ -1,32 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.2.1] - 2019-08-16 -### Changed -- `TimerError` changed to `repr(u32)` (#864) -- `TimerError` enum values all increased by `1<<30` to match new `rand_core::Error` range (#864) - -## [0.2.0] - 2019-06-06 -- Bump `rand_core` version -- Support new `Error` type in `rand_core` 0.5 -- Remove CryptoRng trait bound (#699, #814) -- Enable doc-testing of README - -## [0.1.4] - 2019-05-02 -- Change error conversion code to partially fix #738 - -## [0.1.3] - 2019-02-05 -- Use libc in `no_std` mode to fix #723 - -## [0.1.2] - 2019-01-31 -- Fix for older rustc compilers on Windows (#722) - -## [0.1.1] - 2019-01-29 -- Fix for older rustc compilers on Mac OSX / iOS (#720) -- Misc. doc fixes - -## [0.1.0] - 2019-01-24 -Initial release. diff --git a/rand/rand_jitter/COPYRIGHT b/rand/rand_jitter/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_jitter/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_jitter/Cargo.toml b/rand/rand_jitter/Cargo.toml deleted file mode 100644 index 5b7e3c3..0000000 --- a/rand/rand_jitter/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "rand_jitter" -version = "0.2.1" -authors = ["The Rand Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://docs.rs/rand_jitter" -description = "Random number generator based on timing jitter" -keywords = ["random", "rng", "os"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[dependencies] -rand_core = { path = "../rand_core", version = "0.5" } -log = { version = "0.4", optional = true } - -[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] -# We don't need the 'use_std' feature and depending on it causes -# issues due to: https://github.com/rust-lang/cargo/issues/1197 -libc = { version = "0.2", default_features = false } - -[target.'cfg(target_os = "windows")'.dependencies] -winapi = { version = "0.3", features = ["profileapi"] } - -[features] -std = ["rand_core/std"] diff --git a/rand/rand_jitter/LICENSE-APACHE b/rand/rand_jitter/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_jitter/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_jitter/LICENSE-MIT b/rand/rand_jitter/LICENSE-MIT deleted file mode 100644 index d93b5ba..0000000 --- a/rand/rand_jitter/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2018 Developers of the Rand project -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_jitter/README.md b/rand/rand_jitter/README.md deleted file mode 100644 index 2091d6c..0000000 --- a/rand/rand_jitter/README.md +++ /dev/null @@ -1,119 +0,0 @@ -# rand_jitter -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_jitter.svg)](https://crates.io/crates/rand_jitter) -[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_jitter) -[![API](https://docs.rs/rand_jitter/badge.svg)](https://docs.rs/rand_jitter) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -Non-physical true random number generator based on timing jitter. - -Note that this RNG is not suited for use cases where cryptographic security is -required (also see [this -discussion](https://github.com/rust-random/rand/issues/699)). - -This crate depends on [rand_core](https://crates.io/crates/rand_core) and is -part of the [Rand project](https://github.com/rust-random/rand). - -This crate aims to support all of Rust's `std` platforms with a system-provided -entropy source. Unlike other Rand crates, this crate does not support `no_std` -(handling this gracefully is a current discussion topic). - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_jitter) -- [API documentation (docs.rs)](https://docs.rs/rand_jitter) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_jitter/CHANGELOG.md) - -## Features - -This crate has optional `std` support which is *disabled by default*; -this feature is required to provide the `JitterRng::new` function; -without `std` support a timer must be supplied via `JitterRng::new_with_timer`. - -## Quality testing - -`JitterRng::new()` has build-in, but limited, quality testing, however -before using `JitterRng` on untested hardware, or after changes that could -effect how the code is optimized (such as a new LLVM version), it is -recommend to run the much more stringent -[NIST SP 800-90B Entropy Estimation Suite](https://github.com/usnistgov/SP800-90B_EntropyAssessment). - -Use the following code using `timer_stats` to collect the data: - -```rust,no_run -use rand_jitter::JitterRng; - -use std::error::Error; -use std::fs::File; -use std::io::Write; - -fn get_nstime() -> u64 { - use std::time::{SystemTime, UNIX_EPOCH}; - - let dur = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); - // The correct way to calculate the current time is - // `dur.as_secs() * 1_000_000_000 + dur.subsec_nanos() as u64` - // But this is faster, and the difference in terms of entropy is - // negligible (log2(10^9) == 29.9). - dur.as_secs() << 30 | dur.subsec_nanos() as u64 -} - -fn main() -> Result<(), Box> { - let mut rng = JitterRng::new_with_timer(get_nstime); - - // 1_000_000 results are required for the - // NIST SP 800-90B Entropy Estimation Suite - const ROUNDS: usize = 1_000_000; - let mut deltas_variable: Vec = Vec::with_capacity(ROUNDS); - let mut deltas_minimal: Vec = Vec::with_capacity(ROUNDS); - - for _ in 0..ROUNDS { - deltas_variable.push(rng.timer_stats(true) as u8); - deltas_minimal.push(rng.timer_stats(false) as u8); - } - - // Write out after the statistics collection loop, to not disturb the - // test results. - File::create("jitter_rng_var.bin")?.write(&deltas_variable)?; - File::create("jitter_rng_min.bin")?.write(&deltas_minimal)?; - Ok(()) -} -``` - -This will produce two files: `jitter_rng_var.bin` and `jitter_rng_min.bin`. -Run the Entropy Estimation Suite in three configurations, as outlined below. -Every run has two steps. One step to produce an estimation, another to -validate the estimation. - -1. Estimate the expected amount of entropy that is at least available with - each round of the entropy collector. This number should be greater than - the amount estimated with `64 / test_timer()`. - ```sh - python noniid_main.py -v jitter_rng_var.bin 8 - restart.py -v jitter_rng_var.bin 8 - ``` -2. Estimate the expected amount of entropy that is available in the last 4 - bits of the timer delta after running noice sources. Note that a value of - `3.70` is the minimum estimated entropy for true randomness. - ```sh - python noniid_main.py -v -u 4 jitter_rng_var.bin 4 - restart.py -v -u 4 jitter_rng_var.bin 4 - ``` -3. Estimate the expected amount of entropy that is available to the entropy - collector if both noise sources only run their minimal number of times. - This measures the absolute worst-case, and gives a lower bound for the - available entropy. - ```sh - python noniid_main.py -v -u 4 jitter_rng_min.bin 4 - restart.py -v -u 4 jitter_rng_min.bin 4 - ``` - -## License - -`rand_jitter` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_jitter/benches/mod.rs b/rand/rand_jitter/benches/mod.rs deleted file mode 100644 index bf7c8a2..0000000 --- a/rand/rand_jitter/benches/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(test)] -#![cfg(std)] - -use test::Bencher; -use rand_jitter::rand_core::RngCore; - -#[bench] -fn bench_add_two(b: &mut Bencher) { - let mut rng = rand_jitter::JitterRng::new().unwrap(); - let mut buf = [0u8; 1024]; - b.iter(|| { - rng.fill_bytes(&mut buf[..]); - test::black_box(&buf); - }); - b.bytes = buf.len() as u64; -} - diff --git a/rand/rand_jitter/src/error.rs b/rand/rand_jitter/src/error.rs deleted file mode 100644 index b54fffa..0000000 --- a/rand/rand_jitter/src/error.rs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2015 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rand_core::Error; -use core::fmt; - -/// Base code for all `JitterRng` errors -const ERROR_BASE: u32 = 0xAE53_0400; - -/// An error that can occur when [`JitterRng::test_timer`] fails. -/// -/// All variants have a value of 0xAE530400 = 2924676096 plus a small -/// increment (1 through 5). -/// -/// [`JitterRng::test_timer`]: crate::JitterRng::test_timer -#[derive(Debug, Clone, PartialEq, Eq)] -#[repr(u32)] -pub enum TimerError { - /// No timer available. - NoTimer = ERROR_BASE + 1, - /// Timer too coarse to use as an entropy source. - CoarseTimer = ERROR_BASE + 2, - /// Timer is not monotonically increasing. - NotMonotonic = ERROR_BASE + 3, - /// Variations of deltas of time too small. - TinyVariantions = ERROR_BASE + 4, - /// Too many stuck results (indicating no added entropy). - TooManyStuck = ERROR_BASE + 5, - #[doc(hidden)] - __Nonexhaustive, -} - -impl TimerError { - fn description(&self) -> &'static str { - match *self { - TimerError::NoTimer => "no timer available", - TimerError::CoarseTimer => "coarse timer", - TimerError::NotMonotonic => "timer not monotonic", - TimerError::TinyVariantions => "time delta variations too small", - TimerError::TooManyStuck => "too many stuck results", - TimerError::__Nonexhaustive => unreachable!(), - } - } -} - -impl fmt::Display for TimerError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.description()) - } -} - -#[cfg(feature = "std")] -impl ::std::error::Error for TimerError { - fn description(&self) -> &str { - self.description() - } -} - -impl From for Error { - fn from(err: TimerError) -> Error { - // Timer check is already quite permissive of failures so we don't - // expect false-positive failures, i.e. any error is irrecoverable. - #[cfg(feature = "std")] { - Error::new(err) - } - #[cfg(not(feature = "std"))] { - Error::from(core::num::NonZeroU32::new(err as u32).unwrap()) - } - } -} - diff --git a/rand/rand_jitter/src/lib.rs b/rand/rand_jitter/src/lib.rs deleted file mode 100644 index 49c53e6..0000000 --- a/rand/rand_jitter/src/lib.rs +++ /dev/null @@ -1,750 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -// -// Based on jitterentropy-library, http://www.chronox.de/jent.html. -// Copyright Stephan Mueller , 2014 - 2017. -// -// With permission from Stephan Mueller to relicense the Rust translation under -// the MIT license. - -//! Non-physical true random number generator based on timing jitter. -//! -//! Note that this RNG is not suited for use cases where cryptographic security is -//! required (also see this [discussion]). -//! -//! This is a true random number generator, as opposed to pseudo-random -//! generators. Random numbers generated by `JitterRng` can be seen as fresh -//! entropy. A consequence is that it is orders of magnitude slower than `OsRng` -//! and PRNGs (about 103..106 slower). -//! -//! There are very few situations where using this RNG is appropriate. Only very -//! few applications require true entropy. A normal PRNG can be statistically -//! indistinguishable, and a cryptographic PRNG should also be as impossible to -//! predict. -//! -//! `JitterRng` can be used without the standard library, but not conveniently, -//! you must provide a high-precision timer and carefully have to follow the -//! instructions of [`JitterRng::new_with_timer`]. -//! -//! This implementation is based on [Jitterentropy] version 2.1.0. -//! -//! Note: There is no accurate timer available on WASM platforms, to help -//! prevent fingerprinting or timing side-channel attacks. Therefore -//! [`JitterRng::new()`] is not available on WASM. It is also unavailable -//! with disabled `std` feature. -//! -//! [Jitterentropy]: http://www.chronox.de/jent.html -//! [discussion]: https://github.com/rust-random/rand/issues/699 - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] -#![doc(test(attr(allow(unused_variables), deny(warnings))))] - -// Note: the C implementation of `Jitterentropy` relies on being compiled -// without optimizations. This implementation goes through lengths to make the -// compiler not optimize out code which does influence timing jitter, but is -// technically dead code. -#![no_std] -#[cfg(feature = "std")] -extern crate std; - -pub use rand_core; - -// Coming from https://crates.io/crates/doc-comment -#[cfg(test)] -macro_rules! doc_comment { - ($x:expr) => { - #[doc = $x] - extern {} - }; -} - -#[cfg(test)] -doc_comment!(include_str!("../README.md")); - -#[allow(unused)] -macro_rules! trace { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::trace!($($x)*) - } -) } -#[allow(unused)] -macro_rules! debug { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::debug!($($x)*) - } -) } -#[allow(unused)] -macro_rules! info { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::info!($($x)*) - } -) } -#[allow(unused)] -macro_rules! warn { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::warn!($($x)*) - } -) } -#[allow(unused)] -macro_rules! error { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::error!($($x)*) - } -) } - -#[cfg(feature = "std")] -mod platform; -mod error; - -use rand_core::{RngCore, Error, impls}; -pub use crate::error::TimerError; - -use core::{fmt, mem, ptr}; -#[cfg(feature = "std")] -use std::sync::atomic::{AtomicUsize, Ordering}; - -const MEMORY_BLOCKS: usize = 64; -const MEMORY_BLOCKSIZE: usize = 32; -const MEMORY_SIZE: usize = MEMORY_BLOCKS * MEMORY_BLOCKSIZE; - -/// A true random number generator based on jitter in the CPU execution time, -/// and jitter in memory access time. -/// -/// Note that this RNG is not suitable for use cases where cryptographic -/// security is required. -pub struct JitterRng { - data: u64, // Actual random number - // Number of rounds to run the entropy collector per 64 bits - rounds: u8, - // Timer used by `measure_jitter` - timer: fn() -> u64, - // Memory for the Memory Access noise source - mem_prev_index: u16, - // Make `next_u32` not waste 32 bits - data_half_used: bool, -} - -// Note: `JitterRng` maintains a small 64-bit entropy pool. With every -// `generate` 64 new bits should be integrated in the pool. If a round of -// `generate` were to collect less than the expected 64 bit, then the returned -// value, and the new state of the entropy pool, would be in some way related to -// the initial state. It is therefore better if the initial state of the entropy -// pool is different on each call to `generate`. This has a few implications: -// - `generate` should be called once before using `JitterRng` to produce the -// first usable value (this is done by default in `new`); -// - We do not zero the entropy pool after generating a result. The reference -// implementation also does not support zeroing, but recommends generating a -// new value without using it if you want to protect a previously generated -// 'secret' value from someone inspecting the memory; -// - Implementing `Clone` seems acceptable, as it would not cause the systematic -// bias a constant might cause. Only instead of one value that could be -// potentially related to the same initial state, there are now two. - -// Entropy collector state. -// These values are not necessary to preserve across runs. -struct EcState { - // Previous time stamp to determine the timer delta - prev_time: u64, - // Deltas used for the stuck test - last_delta: i32, - last_delta2: i32, - // Memory for the Memory Access noise source - mem: [u8; MEMORY_SIZE], -} - -impl EcState { - // Stuck test by checking the: - // - 1st derivation of the jitter measurement (time delta) - // - 2nd derivation of the jitter measurement (delta of time deltas) - // - 3rd derivation of the jitter measurement (delta of delta of time - // deltas) - // - // All values must always be non-zero. - // This test is a heuristic to see whether the last measurement holds - // entropy. - fn stuck(&mut self, current_delta: i32) -> bool { - let delta2 = self.last_delta - current_delta; - let delta3 = delta2 - self.last_delta2; - - self.last_delta = current_delta; - self.last_delta2 = delta2; - - current_delta == 0 || delta2 == 0 || delta3 == 0 - } -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for JitterRng { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "JitterRng {{}}") - } -} - -impl Clone for JitterRng { - fn clone(&self) -> JitterRng { - JitterRng { - data: self.data, - rounds: self.rounds, - timer: self.timer, - mem_prev_index: self.mem_prev_index, - // The 32 bits that may still be unused from the previous round are - // for the original to use, not for the clone. - data_half_used: false, - } - } -} - -// Initialise to zero; must be positive -#[cfg(all(feature = "std", not(target_arch = "wasm32")))] -static JITTER_ROUNDS: AtomicUsize = AtomicUsize::new(0); - -impl JitterRng { - /// Create a new `JitterRng`. Makes use of `std::time` for a timer, or a - /// platform-specific function with higher accuracy if necessary and - /// available. - /// - /// During initialization CPU execution timing jitter is measured a few - /// hundred times. If this does not pass basic quality tests, an error is - /// returned. The test result is cached to make subsequent calls faster. - #[cfg(all(feature = "std", not(target_arch = "wasm32")))] - pub fn new() -> Result { - if cfg!(target_arch = "wasm32") { - return Err(TimerError::NoTimer); - } - let mut state = JitterRng::new_with_timer(platform::get_nstime); - let mut rounds = JITTER_ROUNDS.load(Ordering::Relaxed) as u8; - if rounds == 0 { - // No result yet: run test. - // This allows the timer test to run multiple times; we don't care. - rounds = state.test_timer()?; - JITTER_ROUNDS.store(rounds as usize, Ordering::Relaxed); - info!("JitterRng: using {} rounds per u64 output", rounds); - } - state.set_rounds(rounds); - - // Fill `data` with a non-zero value. - state.gen_entropy(); - Ok(state) - } - - /// Create a new `JitterRng`. - /// A custom timer can be supplied, making it possible to use `JitterRng` in - /// `no_std` environments. - /// - /// The timer must have nanosecond precision. - /// - /// This method is more low-level than `new()`. It is the responsibility of - /// the caller to run [`test_timer`] before using any numbers generated with - /// `JitterRng`, and optionally call [`set_rounds`]. Also it is important to - /// consume at least one `u64` before using the first result to initialize - /// the entropy collection pool. - /// - /// # Example - /// - /// ``` - /// # use rand_jitter::rand_core::{RngCore, Error}; - /// use rand_jitter::JitterRng; - /// - /// # fn try_inner() -> Result<(), Error> { - /// fn get_nstime() -> u64 { - /// use std::time::{SystemTime, UNIX_EPOCH}; - /// - /// let dur = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); - /// // The correct way to calculate the current time is - /// // `dur.as_secs() * 1_000_000_000 + dur.subsec_nanos() as u64` - /// // But this is faster, and the difference in terms of entropy is - /// // negligible (log2(10^9) == 29.9). - /// dur.as_secs() << 30 | dur.subsec_nanos() as u64 - /// } - /// - /// let mut rng = JitterRng::new_with_timer(get_nstime); - /// let rounds = rng.test_timer()?; - /// rng.set_rounds(rounds); // optional - /// let _ = rng.next_u64(); - /// - /// // Ready for use - /// let v: u64 = rng.next_u64(); - /// # Ok(()) - /// # } - /// - /// # let _ = try_inner(); - /// ``` - /// - /// [`test_timer`]: JitterRng::test_timer - /// [`set_rounds`]: JitterRng::set_rounds - pub fn new_with_timer(timer: fn() -> u64) -> JitterRng { - JitterRng { - data: 0, - rounds: 64, - timer, - mem_prev_index: 0, - data_half_used: false, - } - } - - /// Configures how many rounds are used to generate each 64-bit value. - /// This must be greater than zero, and has a big impact on performance - /// and output quality. - /// - /// [`new_with_timer`] conservatively uses 64 rounds, but often less rounds - /// can be used. The `test_timer()` function returns the minimum number of - /// rounds required for full strength (platform dependent), so one may use - /// `rng.set_rounds(rng.test_timer()?);` or cache the value. - /// - /// [`new_with_timer`]: JitterRng::new_with_timer - pub fn set_rounds(&mut self, rounds: u8) { - assert!(rounds > 0); - self.rounds = rounds; - } - - // Calculate a random loop count used for the next round of an entropy - // collection, based on bits from a fresh value from the timer. - // - // The timer is folded to produce a number that contains at most `n_bits` - // bits. - // - // Note: A constant should be added to the resulting random loop count to - // prevent loops that run 0 times. - #[inline(never)] - fn random_loop_cnt(&mut self, n_bits: u32) -> u32 { - let mut rounds = 0; - - let mut time = (self.timer)(); - // Mix with the current state of the random number balance the random - // loop counter a bit more. - time ^= self.data; - - // We fold the time value as much as possible to ensure that as many - // bits of the time stamp are included as possible. - let folds = (64 + n_bits - 1) / n_bits; - let mask = (1 << n_bits) - 1; - for _ in 0..folds { - rounds ^= time & mask; - time >>= n_bits; - } - - rounds as u32 - } - - // CPU jitter noise source - // Noise source based on the CPU execution time jitter - // - // This function injects the individual bits of the time value into the - // entropy pool using an LFSR. - // - // The code is deliberately inefficient with respect to the bit shifting. - // This function not only acts as folding operation, but this function's - // execution is used to measure the CPU execution time jitter. Any change to - // the loop in this function implies that careful retesting must be done. - #[inline(never)] - fn lfsr_time(&mut self, time: u64, var_rounds: bool) { - fn lfsr(mut data: u64, time: u64) -> u64{ - for i in 1..65 { - let mut tmp = time << (64 - i); - tmp >>= 64 - 1; - - // Fibonacci LSFR with polynomial of - // x^64 + x^61 + x^56 + x^31 + x^28 + x^23 + 1 which is - // primitive according to - // http://poincare.matf.bg.ac.rs/~ezivkovm/publications/primpol1.pdf - // (the shift values are the polynomial values minus one - // due to counting bits from 0 to 63). As the current - // position is always the LSB, the polynomial only needs - // to shift data in from the left without wrap. - data ^= tmp; - data ^= (data >> 63) & 1; - data ^= (data >> 60) & 1; - data ^= (data >> 55) & 1; - data ^= (data >> 30) & 1; - data ^= (data >> 27) & 1; - data ^= (data >> 22) & 1; - data = data.rotate_left(1); - } - data - } - - // Note: in the reference implementation only the last round effects - // `self.data`, all the other results are ignored. To make sure the - // other rounds are not optimised out, we first run all but the last - // round on a throw-away value instead of the real `self.data`. - let mut lfsr_loop_cnt = 0; - if var_rounds { lfsr_loop_cnt = self.random_loop_cnt(4) }; - - let mut throw_away: u64 = 0; - for _ in 0..lfsr_loop_cnt { - throw_away = lfsr(throw_away, time); - } - black_box(throw_away); - - self.data = lfsr(self.data, time); - } - - // Memory Access noise source - // This is a noise source based on variations in memory access times - // - // This function performs memory accesses which will add to the timing - // variations due to an unknown amount of CPU wait states that need to be - // added when accessing memory. The memory size should be larger than the L1 - // caches as outlined in the documentation and the associated testing. - // - // The L1 cache has a very high bandwidth, albeit its access rate is usually - // slower than accessing CPU registers. Therefore, L1 accesses only add - // minimal variations as the CPU has hardly to wait. Starting with L2, - // significant variations are added because L2 typically does not belong to - // the CPU any more and therefore a wider range of CPU wait states is - // necessary for accesses. L3 and real memory accesses have even a wider - // range of wait states. However, to reliably access either L3 or memory, - // the `self.mem` memory must be quite large which is usually not desirable. - #[inline(never)] - fn memaccess(&mut self, mem: &mut [u8; MEMORY_SIZE], var_rounds: bool) { - let mut acc_loop_cnt = 128; - if var_rounds { acc_loop_cnt += self.random_loop_cnt(4) }; - - let mut index = self.mem_prev_index as usize; - for _ in 0..acc_loop_cnt { - // Addition of memblocksize - 1 to index with wrap around logic to - // ensure that every memory location is hit evenly. - // The modulus also allows the compiler to remove the indexing - // bounds check. - index = (index + MEMORY_BLOCKSIZE - 1) % MEMORY_SIZE; - - // memory access: just add 1 to one byte - // memory access implies read from and write to memory location - mem[index] = mem[index].wrapping_add(1); - } - self.mem_prev_index = index as u16; - } - - // This is the heart of the entropy generation: calculate time deltas and - // use the CPU jitter in the time deltas. The jitter is injected into the - // entropy pool. - // - // Ensure that `ec.prev_time` is primed before using the output of this - // function. This can be done by calling this function and not using its - // result. - fn measure_jitter(&mut self, ec: &mut EcState) -> Option<()> { - // Invoke one noise source before time measurement to add variations - self.memaccess(&mut ec.mem, true); - - // Get time stamp and calculate time delta to previous - // invocation to measure the timing variations - let time = (self.timer)(); - // Note: wrapping_sub combined with a cast to `i64` generates a correct - // delta, even in the unlikely case this is a timer that is not strictly - // monotonic. - let current_delta = time.wrapping_sub(ec.prev_time) as i64 as i32; - ec.prev_time = time; - - // Call the next noise source which also injects the data - self.lfsr_time(current_delta as u64, true); - - // Check whether we have a stuck measurement (i.e. does the last - // measurement holds entropy?). - if ec.stuck(current_delta) { return None }; - - // Rotate the data buffer by a prime number (any odd number would - // do) to ensure that every bit position of the input time stamp - // has an even chance of being merged with a bit position in the - // entropy pool. We do not use one here as the adjacent bits in - // successive time deltas may have some form of dependency. The - // chosen value of 7 implies that the low 7 bits of the next - // time delta value is concatenated with the current time delta. - self.data = self.data.rotate_left(7); - - Some(()) - } - - // Shuffle the pool a bit by mixing some value with a bijective function - // (XOR) into the pool. - // - // The function generates a mixer value that depends on the bits set and - // the location of the set bits in the random number generated by the - // entropy source. Therefore, based on the generated random number, this - // mixer value can have 2^64 different values. That mixer value is - // initialized with the first two SHA-1 constants. After obtaining the - // mixer value, it is XORed into the random number. - // - // The mixer value is not assumed to contain any entropy. But due to the - // XOR operation, it can also not destroy any entropy present in the - // entropy pool. - #[inline(never)] - fn stir_pool(&mut self) { - // This constant is derived from the first two 32 bit initialization - // vectors of SHA-1 as defined in FIPS 180-4 section 5.3.1 - // The order does not really matter as we do not rely on the specific - // numbers. We just pick the SHA-1 constants as they have a good mix of - // bit set and unset. - const CONSTANT: u64 = 0x67452301efcdab89; - - // The start value of the mixer variable is derived from the third - // and fourth 32 bit initialization vector of SHA-1 as defined in - // FIPS 180-4 section 5.3.1 - let mut mixer = 0x98badcfe10325476; - - // This is a constant time function to prevent leaking timing - // information about the random number. - // The normal code is: - // ``` - // for i in 0..64 { - // if ((self.data >> i) & 1) == 1 { mixer ^= CONSTANT; } - // } - // ``` - // This is a bit fragile, as LLVM really wants to use branches here, and - // we rely on it to not recognise the opportunity. - for i in 0..64 { - let apply = (self.data >> i) & 1; - let mask = !apply.wrapping_sub(1); - mixer ^= CONSTANT & mask; - mixer = mixer.rotate_left(1); - } - - self.data ^= mixer; - } - - fn gen_entropy(&mut self) -> u64 { - trace!("JitterRng: collecting entropy"); - - // Prime `ec.prev_time`, and run the noice sources to make sure the - // first loop round collects the expected entropy. - let mut ec = EcState { - prev_time: (self.timer)(), - last_delta: 0, - last_delta2: 0, - mem: [0; MEMORY_SIZE], - }; - let _ = self.measure_jitter(&mut ec); - - for _ in 0..self.rounds { - // If a stuck measurement is received, repeat measurement - // Note: we do not guard against an infinite loop, that would mean - // the timer suddenly became broken. - while self.measure_jitter(&mut ec).is_none() {} - } - - // Do a single read from `self.mem` to make sure the Memory Access noise - // source is not optimised out. - black_box(ec.mem[0]); - - self.stir_pool(); - self.data - } - - /// Basic quality tests on the timer, by measuring CPU timing jitter a few - /// hundred times. - /// - /// If successful, this will return the estimated number of rounds necessary - /// to collect 64 bits of entropy. Otherwise a [`TimerError`] with the cause - /// of the failure will be returned. - pub fn test_timer(&mut self) -> Result { - debug!("JitterRng: testing timer ..."); - // We could add a check for system capabilities such as `clock_getres` - // or check for `CONFIG_X86_TSC`, but it does not make much sense as the - // following sanity checks verify that we have a high-resolution timer. - - let mut delta_sum = 0; - let mut old_delta = 0; - - let mut time_backwards = 0; - let mut count_mod = 0; - let mut count_stuck = 0; - - let mut ec = EcState { - prev_time: (self.timer)(), - last_delta: 0, - last_delta2: 0, - mem: [0; MEMORY_SIZE], - }; - - // TESTLOOPCOUNT needs some loops to identify edge systems. - // 100 is definitely too little. - const TESTLOOPCOUNT: u64 = 300; - const CLEARCACHE: u64 = 100; - - for i in 0..(CLEARCACHE + TESTLOOPCOUNT) { - // Measure time delta of core entropy collection logic - let time = (self.timer)(); - self.memaccess(&mut ec.mem, true); - self.lfsr_time(time, true); - let time2 = (self.timer)(); - - // Test whether timer works - if time == 0 || time2 == 0 { - return Err(TimerError::NoTimer); - } - let delta = time2.wrapping_sub(time) as i64 as i32; - - // Test whether timer is fine grained enough to provide delta even - // when called shortly after each other -- this implies that we also - // have a high resolution timer - if delta == 0 { - return Err(TimerError::CoarseTimer); - } - - // Up to here we did not modify any variable that will be - // evaluated later, but we already performed some work. Thus we - // already have had an impact on the caches, branch prediction, - // etc. with the goal to clear it to get the worst case - // measurements. - if i < CLEARCACHE { continue; } - - if ec.stuck(delta) { count_stuck += 1; } - - // Test whether we have an increasing timer. - if !(time2 > time) { time_backwards += 1; } - - // Count the number of times the counter increases in steps of 100ns - // or greater. - if (delta % 100) == 0 { count_mod += 1; } - - // Ensure that we have a varying delta timer which is necessary for - // the calculation of entropy -- perform this check only after the - // first loop is executed as we need to prime the old_delta value - delta_sum += (delta - old_delta).abs() as u64; - old_delta = delta; - } - - // Do a single read from `self.mem` to make sure the Memory Access noise - // source is not optimised out. - black_box(ec.mem[0]); - - // We allow the time to run backwards for up to three times. - // This can happen if the clock is being adjusted by NTP operations. - // If such an operation just happens to interfere with our test, it - // should not fail. The value of 3 should cover the NTP case being - // performed during our test run. - if time_backwards > 3 { - return Err(TimerError::NotMonotonic); - } - - // Test that the available amount of entropy per round does not get to - // low. We expect 1 bit of entropy per round as a reasonable minimum - // (although less is possible, it means the collector loop has to run - // much more often). - // `assert!(delta_average >= log2(1))` - // `assert!(delta_sum / TESTLOOPCOUNT >= 1)` - // `assert!(delta_sum >= TESTLOOPCOUNT)` - if delta_sum < TESTLOOPCOUNT { - return Err(TimerError::TinyVariantions); - } - - // Ensure that we have variations in the time stamp below 100 for at - // least 10% of all checks -- on some platforms, the counter increments - // in multiples of 100, but not always - if count_mod > (TESTLOOPCOUNT * 9 / 10) { - return Err(TimerError::CoarseTimer); - } - - // If we have more than 90% stuck results, then this Jitter RNG is - // likely to not work well. - if count_stuck > (TESTLOOPCOUNT * 9 / 10) { - return Err(TimerError::TooManyStuck); - } - - // Estimate the number of `measure_jitter` rounds necessary for 64 bits - // of entropy. - // - // We don't try very hard to come up with a good estimate of the - // available bits of entropy per round here for two reasons: - // 1. Simple estimates of the available bits (like Shannon entropy) are - // too optimistic. - // 2. Unless we want to waste a lot of time during intialization, there - // only a small number of samples are available. - // - // Therefore we use a very simple and conservative estimate: - // `let bits_of_entropy = log2(delta_average) / 2`. - // - // The number of rounds `measure_jitter` should run to collect 64 bits - // of entropy is `64 / bits_of_entropy`. - let delta_average = delta_sum / TESTLOOPCOUNT; - - if delta_average >= 16 { - let log2 = 64 - delta_average.leading_zeros(); - // Do something similar to roundup(64/(log2/2)): - Ok( ((64u32 * 2 + log2 - 1) / log2) as u8) - } else { - // For values < 16 the rounding error becomes too large, use a - // lookup table. - // Values 0 and 1 are invalid, and filtered out by the - // `delta_sum < TESTLOOPCOUNT` test above. - let log2_lookup = [0, 0, 128, 81, 64, 56, 50, 46, - 43, 41, 39, 38, 36, 35, 34, 33]; - Ok(log2_lookup[delta_average as usize]) - } - } - - /// Statistical test: return the timer delta of one normal run of the - /// `JitterRng` entropy collector. - /// - /// Setting `var_rounds` to `true` will execute the memory access and the - /// CPU jitter noice sources a variable amount of times (just like a real - /// `JitterRng` round). - /// - /// Setting `var_rounds` to `false` will execute the noice sources the - /// minimal number of times. This can be used to measure the minimum amount - /// of entropy one round of the entropy collector can collect in the worst - /// case. - /// - /// See this crate's README on how to use `timer_stats` to test the quality - /// of `JitterRng`. - pub fn timer_stats(&mut self, var_rounds: bool) -> i64 { - let mut mem = [0; MEMORY_SIZE]; - - let time = (self.timer)(); - self.memaccess(&mut mem, var_rounds); - self.lfsr_time(time, var_rounds); - let time2 = (self.timer)(); - time2.wrapping_sub(time) as i64 - } -} - -// A function that is opaque to the optimizer to assist in avoiding dead-code -// elimination. Taken from `bencher`. -fn black_box(dummy: T) -> T { - unsafe { - let ret = ptr::read_volatile(&dummy); - mem::forget(dummy); - ret - } -} - -impl RngCore for JitterRng { - fn next_u32(&mut self) -> u32 { - // We want to use both parts of the generated entropy - if self.data_half_used { - self.data_half_used = false; - (self.data >> 32) as u32 - } else { - self.data = self.next_u64(); - self.data_half_used = true; - self.data as u32 - } - } - - fn next_u64(&mut self) -> u64 { - self.data_half_used = false; - self.gen_entropy() - } - - fn fill_bytes(&mut self, dest: &mut [u8]) { - // Fill using `next_u32`. This is faster for filling small slices (four - // bytes or less), while the overhead is negligible. - // - // This is done especially for wrappers that implement `next_u32` - // themselves via `fill_bytes`. - impls::fill_bytes_via_next(self, dest) - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - Ok(self.fill_bytes(dest)) - } -} diff --git a/rand/rand_jitter/src/platform.rs b/rand/rand_jitter/src/platform.rs deleted file mode 100644 index 8e3d0fb..0000000 --- a/rand/rand_jitter/src/platform.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2015 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))] -pub fn get_nstime() -> u64 { - use std::time::{SystemTime, UNIX_EPOCH}; - - let dur = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); - // The correct way to calculate the current time is - // `dur.as_secs() * 1_000_000_000 + dur.subsec_nanos() as u64` - // But this is faster, and the difference in terms of entropy is - // negligible (log2(10^9) == 29.9). - dur.as_secs() << 30 | dur.subsec_nanos() as u64 -} - -#[cfg(any(target_os = "macos", target_os = "ios"))] -pub fn get_nstime() -> u64 { - use libc; - - // On Mac OS and iOS std::time::SystemTime only has 1000ns resolution. - // We use `mach_absolute_time` instead. This provides a CPU dependent - // unit, to get real nanoseconds the result should by multiplied by - // numer/denom from `mach_timebase_info`. - // But we are not interested in the exact nanoseconds, just entropy. So - // we use the raw result. - unsafe { libc::mach_absolute_time() } -} - -#[cfg(target_os = "windows")] -pub fn get_nstime() -> u64 { - use winapi; - - unsafe { - let mut t = super::mem::zeroed(); - winapi::um::profileapi::QueryPerformanceCounter(&mut t); - *t.QuadPart() as u64 - } -} diff --git a/rand/rand_jitter/tests/mod.rs b/rand/rand_jitter/tests/mod.rs deleted file mode 100644 index 961dc27..0000000 --- a/rand/rand_jitter/tests/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -use rand_jitter::JitterRng; -#[cfg(feature = "std")] -use rand_core::RngCore; - -#[cfg(feature = "std")] -#[test] -fn test_jitter_init() { - // Because this is a debug build, measurements here are not representive - // of the final release build. - // Don't fail this test if initializing `JitterRng` fails because of a - // bad timer (the timer from the standard library may not have enough - // accuracy on all platforms). - match JitterRng::new() { - Ok(ref mut rng) => { - // false positives are possible, but extremely unlikely - assert!(rng.next_u32() | rng.next_u32() != 0); - }, - Err(_) => {}, - } -} - -#[test] -fn test_jitter_bad_timer() { - fn bad_timer() -> u64 { 0 } - let mut rng = JitterRng::new_with_timer(bad_timer); - assert!(rng.test_timer().is_err()); -} - diff --git a/rand/rand_os/CHANGELOG.md b/rand/rand_os/CHANGELOG.md deleted file mode 100644 index b0c6549..0000000 --- a/rand/rand_os/CHANGELOG.md +++ /dev/null @@ -1,35 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.2.2] - 2019-09-02 -### Changed -- `OsRng` added to `rand_core`, rendering this crate deprecated (#863) - -## [0.2.1] - 2019-08-08 -### Fixed -- Fix `no_std` support. - -## [0.2.0] - 2019-06-06 -### Changed -- Minimum Supported Rust Version has changed to 1.32. -- Replaced implementation with a backwards-compatible shim around -[getrandom](https://crates.io/crates/getrandom). - -## [0.1.3] - 2019-03-05 -### Fixed -- Fix support for Illumos (#730) -- Fix deprecation warnings from atomic init (#739) - -## [0.1.2] - 2019-01-28 -### Changed -- Fuchsia: Replaced fuchsia-zircon with fuchsia-cprng - -## [0.1.1] - 2019-01-08 -### Added -- Add support for x86_64-fortanix-unknown-sgx target (#670) - -## [0.1.0] - 2019-01-04 -Initial release. diff --git a/rand/rand_os/COPYRIGHT b/rand/rand_os/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_os/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_os/Cargo.toml b/rand/rand_os/Cargo.toml deleted file mode 100644 index c8010e2..0000000 --- a/rand/rand_os/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "rand_os" -version = "0.2.2" -authors = ["The Rand Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://docs.rs/rand_os" -homepage = "https://crates.io/crates/rand_os" -description = "OS backed Random Number Generator" -keywords = ["random", "rng", "os"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[features] -log = ["getrandom/log"] -# re-export optional WASM dependencies to avoid breakage: -wasm-bindgen = ["getrandom/wasm-bindgen"] -stdweb = ["getrandom/stdweb"] - -[dependencies] -rand_core = { path = "../rand_core", version = "0.5", features = ["getrandom"] } -getrandom = "0.1.1" diff --git a/rand/rand_os/LICENSE-APACHE b/rand/rand_os/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_os/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_os/LICENSE-MIT b/rand/rand_os/LICENSE-MIT deleted file mode 100644 index d93b5ba..0000000 --- a/rand/rand_os/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2018 Developers of the Rand project -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_os/README.md b/rand/rand_os/README.md deleted file mode 100644 index 7b68b35..0000000 --- a/rand/rand_os/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# rand_os - -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_os.svg)](https://crates.io/crates/rand_os) -[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_os) -[![API](https://docs.rs/rand_os/badge.svg)](https://docs.rs/rand_os) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -A random number generator that retrieves randomness straight from the -operating system. - -**This crate is deprecated:** `OsRng` is available in `rand_core` since version 0.5.1. - -This crate provides `OsRng` as a shim around -[getrandom](https://crates.io/crates/getrandom) -implementing `RngCore` from [rand_core](https://crates.io/crates/rand_core). - -Note: the `rand` crate provides an equivalent `OsRng`; the two implementations -are equivalent, though distinct types. - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_os) -- [API documentation (docs.rs)](https://docs.rs/rand_os) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_os/CHANGELOG.md) - -## License - -`rand_os` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_os/src/lib.rs b/rand/rand_os/src/lib.rs deleted file mode 100644 index abfdf79..0000000 --- a/rand/rand_os/src/lib.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2015 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Interface to the random number generator of the operating system. -// Note: keep this code in sync with the rand::rngs::os module! - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] -#![doc(test(attr(allow(unused_variables), deny(warnings))))] - -#![no_std] // but see getrandom crate - -#![deprecated(since="0.2.2", note="OsRng is now provided by rand_core and rand")] - -pub use rand_core; // re-export - -use getrandom::getrandom; -use rand_core::{CryptoRng, RngCore, Error, impls}; - -/// A random number generator that retrieves randomness from from the -/// operating system. -/// -/// This is a zero-sized struct. It can be freely constructed with `OsRng`. -/// -/// The implementation is provided by the [getrandom] crate. Refer to -/// [getrandom] documentation for details. -/// -/// # Blocking and error handling -/// -/// It is possible that when used during early boot the first call to `OsRng` -/// will block until the system's RNG is initialised. It is also possible -/// (though highly unlikely) for `OsRng` to fail on some platforms, most -/// likely due to system mis-configuration. -/// -/// After the first successful call, it is highly unlikely that failures or -/// significant delays will occur (although performance should be expected to -/// be much slower than a user-space PRNG). -/// -/// # Usage example -/// ``` -/// #![allow(deprecated)] -/// use rand_os::rand_core::RngCore; -/// use rand_os::OsRng; -/// -/// let mut key = [0u8; 16]; -/// OsRng.fill_bytes(&mut key); -/// let random_u64 = OsRng.next_u64(); -/// ``` -/// -/// [getrandom]: https://crates.io/crates/getrandom -#[derive(Clone, Copy, Debug, Default)] -pub struct OsRng; - -impl OsRng { - /// Create a new `OsRng`. - #[deprecated(since="0.2.0", note="replace OsRng::new().unwrap() with just OsRng")] - pub fn new() -> Result { - Ok(OsRng) - } -} - -impl CryptoRng for OsRng {} - -impl RngCore for OsRng { - fn next_u32(&mut self) -> u32 { - impls::next_u32_via_fill(self) - } - - fn next_u64(&mut self) -> u64 { - impls::next_u64_via_fill(self) - } - - fn fill_bytes(&mut self, dest: &mut [u8]) { - if let Err(e) = self.try_fill_bytes(dest) { - panic!("Error: {}", e); - } - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - getrandom(dest)?; - Ok(()) - } -} - -#[test] -fn test_os_rng() { - let x = OsRng.next_u64(); - let y = OsRng.next_u64(); - assert!(x != 0); - assert!(x != y); -} - -#[test] -fn test_construction() { - let mut rng = OsRng::default(); - assert!(rng.next_u64() != 0); -} diff --git a/rand/rand_pcg/CHANGELOG.md b/rand/rand_pcg/CHANGELOG.md deleted file mode 100644 index a9b82fd..0000000 --- a/rand/rand_pcg/CHANGELOG.md +++ /dev/null @@ -1,24 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.2.0] - 2019-06-12 -- Add `Lcg128Xsl64` aka `Pcg64` -- Bump minor crate version since rand_core bump is a breaking change -- Switch to Edition 2018 - -## [0.1.2] - 2019-02-23 -- require `bincode` 1.1.2 for i128 auto-detection -- make `bincode` a dev-dependency again #663 -- clean up tests and Serde support - -## [0.1.1] - 2018-10-04 -- make `bincode` an explicit dependency when using Serde - -## [0.1.0] - 2018-10-04 -Initial release, including: - -- `Lcg64Xsh32` aka `Pcg32` -- `Mcg128Xsl64` aka `Pcg64Mcg` diff --git a/rand/rand_pcg/COPYRIGHT b/rand/rand_pcg/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_pcg/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_pcg/Cargo.toml b/rand/rand_pcg/Cargo.toml deleted file mode 100644 index e2aa157..0000000 --- a/rand/rand_pcg/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -name = "rand_pcg" -version = "0.2.0" -authors = ["The Rand Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_pcg/" -homepage = "https://crates.io/crates/rand_pcg" -description = """ -Selected PCG random number generators -""" -keywords = ["random", "rng", "pcg"] -categories = ["algorithms", "no-std"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[features] -serde1 = ["serde"] - -[dependencies] -rand_core = { path = "../rand_core", version = "0.5" } -serde = { version = "1", features = ["derive"], optional = true } - -[dev-dependencies] -# This is for testing serde, unfortunately we can't specify feature-gated dev -# deps yet, see: https://github.com/rust-lang/cargo/issues/1596 -# We require at least 1.1.2 for i128 auto-detection -bincode = { version = "1.1.2" } diff --git a/rand/rand_pcg/LICENSE-APACHE b/rand/rand_pcg/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_pcg/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_pcg/LICENSE-MIT b/rand/rand_pcg/LICENSE-MIT deleted file mode 100644 index d46f058..0000000 --- a/rand/rand_pcg/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2014-2017 Melissa O'Neill and PCG Project contributors -Copyright 2018 Developers of the Rand project - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_pcg/README.md b/rand/rand_pcg/README.md deleted file mode 100644 index fe47f2d..0000000 --- a/rand/rand_pcg/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# rand_pcg - -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_pcg.svg)](https://crates.io/crates/rand_pcg) -[[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_pcg) -[![API](https://docs.rs/rand_pcg/badge.svg)](https://docs.rs/rand_pcg) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -Implements a selection of PCG random number generators. - -> PCG is a family of simple fast space-efficient statistically good algorithms -> for random number generation. [Melissa O'Neill, Harvey Mudd College, 2014]. - -The PCG algorithms are not suitable for cryptographic uses, but perform well -in statistical tests, use little memory and are fairly fast. -See the [pcg-random website](http://www.pcg-random.org/). - -This crate depends on [rand_core](https://crates.io/crates/rand_core) and is -part of the [Rand project](https://github.com/rust-random/rand). - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_pcg) -- [API documentation (docs.rs)](https://docs.rs/rand_pcg) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_pcg/CHANGELOG.md) - - -## Crate Features - -`rand_pcg` is `no_std` compatible by default. - -The `serde1` feature includes implementations of `Serialize` and `Deserialize` -for the included RNGs. - -## License - -`rand_pcg` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_pcg/src/lib.rs b/rand/rand_pcg/src/lib.rs deleted file mode 100644 index 22ba4a0..0000000 --- a/rand/rand_pcg/src/lib.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The PCG random number generators. -//! -//! This is a native Rust implementation of a small selection of PCG generators. -//! The primary goal of this crate is simple, minimal, well-tested code; in -//! other words it is explicitly not a goal to re-implement all of PCG. -//! -//! This crate provides: -//! -//! - `Pcg32` aka `Lcg64Xsh32`, officially known as `pcg32`, a general -//! purpose RNG. This is a good choice on both 32-bit and 64-bit CPUs -//! (for 32-bit output). -//! - `Pcg64` aka `Lcg128Xsl64`, officially known as `pcg64`, a general -//! purpose RNG. This is a good choice on 64-bit CPUs. -//! - `Pcg64Mcg` aka `Mcg128Xsl64`, officially known as `pcg64_fast`, -//! a general purpose RNG using 128-bit multiplications. This has poor -//! performance on 32-bit CPUs but is a good choice on 64-bit CPUs for -//! both 32-bit and 64-bit output. -//! -//! Both of these use 16 bytes of state and 128-bit seeds, and are considered -//! value-stable (i.e. any change affecting the output given a fixed seed would -//! be considered a breaking change to the crate). - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] - -#![allow(clippy::unreadable_literal)] - -#![no_std] - -mod pcg64; -#[cfg(not(target_os = "emscripten"))] mod pcg128; - -pub use self::pcg64::{Pcg32, Lcg64Xsh32}; -#[cfg(not(target_os = "emscripten"))] pub use self::pcg128::{ - Pcg64, Lcg128Xsl64, - Pcg64Mcg, Mcg128Xsl64, -}; diff --git a/rand/rand_pcg/src/pcg128.rs b/rand/rand_pcg/src/pcg128.rs deleted file mode 100644 index 311a41b..0000000 --- a/rand/rand_pcg/src/pcg128.rs +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2017 Paul Dicker. -// Copyright 2014-2017 Melissa O'Neill and PCG Project contributors -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! PCG random number generators - -// This is the default multiplier used by PCG for 64-bit state. -const MULTIPLIER: u128 = 0x2360_ED05_1FC6_5DA4_4385_DF64_9FCC_F645; - -use core::fmt; -use rand_core::{RngCore, SeedableRng, Error, le}; -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; - -/// A PCG random number generator (XSL RR 128/64 (LCG) variant). -/// -/// Permuted Congruential Generator with 128-bit state, internal Linear -/// Congruential Generator, and 64-bit output via "xorshift low (bits), -/// random rotation" output function. -/// -/// This is a 128-bit LCG with explicitly chosen stream with the PCG-XSL-RR -/// output function. This combination is the standard `pcg64`. -/// -/// Despite the name, this implementation uses 32 bytes (256 bit) space -/// comprising 128 bits of state and 128 bits stream selector. These are both -/// set by `SeedableRng`, using a 256-bit seed. -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize,Deserialize))] -pub struct Lcg128Xsl64 { - state: u128, - increment: u128, -} - -/// `Lcg128Xsl64` is also officially known as `pcg64`. -pub type Pcg64 = Lcg128Xsl64; - -impl Lcg128Xsl64 { - /// Construct an instance compatible with PCG seed and stream. - /// - /// Note that PCG specifies default values for both parameters: - /// - /// - `state = 0xcafef00dd15ea5e5` - /// - `stream = 0xa02bdbf7bb3c0a7ac28fa16a64abf96` - pub fn new(state: u128, stream: u128) -> Self { - // The increment must be odd, hence we discard one bit: - let increment = (stream << 1) | 1; - Lcg128Xsl64::from_state_incr(state, increment) - } - - #[inline] - fn from_state_incr(state: u128, increment: u128) -> Self { - let mut pcg = Lcg128Xsl64 { state, increment }; - // Move away from inital value: - pcg.state = pcg.state.wrapping_add(pcg.increment); - pcg.step(); - pcg - } - - #[inline] - fn step(&mut self) { - // prepare the LCG for the next round - self.state = self.state - .wrapping_mul(MULTIPLIER) - .wrapping_add(self.increment); - } -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for Lcg128Xsl64 { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Lcg128Xsl64 {{}}") - } -} - -/// We use a single 255-bit seed to initialise the state and select a stream. -/// One `seed` bit (lowest bit of `seed[8]`) is ignored. -impl SeedableRng for Lcg128Xsl64 { - type Seed = [u8; 32]; - - fn from_seed(seed: Self::Seed) -> Self { - let mut seed_u64 = [0u64; 4]; - le::read_u64_into(&seed, &mut seed_u64); - let state = u128::from(seed_u64[0]) | (u128::from(seed_u64[1]) << 64); - let incr = u128::from(seed_u64[2]) | (u128::from(seed_u64[3]) << 64); - - // The increment must be odd, hence we discard one bit: - Lcg128Xsl64::from_state_incr(state, incr | 1) - } -} - -impl RngCore for Lcg128Xsl64 { - #[inline] - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - self.step(); - output_xsl_rr(self.state) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_impl(self, dest) - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - - -/// A PCG random number generator (XSL 128/64 (MCG) variant). -/// -/// Permuted Congruential Generator with 128-bit state, internal Multiplicative -/// Congruential Generator, and 64-bit output via "xorshift low (bits), -/// random rotation" output function. -/// -/// This is a 128-bit MCG with the PCG-XSL-RR output function, also known as -/// `pcg64_fast`. -/// Note that compared to the standard `pcg64` (128-bit LCG with PCG-XSL-RR -/// output function), this RNG is faster, also has a long cycle, and still has -/// good performance on statistical tests. -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize,Deserialize))] -pub struct Mcg128Xsl64 { - state: u128, -} - -/// A friendly name for `Mcg128Xsl64` (also known as `pcg64_fast`). -pub type Pcg64Mcg = Mcg128Xsl64; - -impl Mcg128Xsl64 { - /// Construct an instance compatible with PCG seed. - /// - /// Note that PCG specifies a default value for the parameter: - /// - /// - `state = 0xcafef00dd15ea5e5` - pub fn new(state: u128) -> Self { - // Force low bit to 1, as in C version (C++ uses `state | 3` instead). - Mcg128Xsl64 { state: state | 1 } - } -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for Mcg128Xsl64 { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Mcg128Xsl64 {{}}") - } -} - -/// We use a single 126-bit seed to initialise the state and select a stream. -/// Two `seed` bits (lowest order of last byte) are ignored. -impl SeedableRng for Mcg128Xsl64 { - type Seed = [u8; 16]; - - fn from_seed(seed: Self::Seed) -> Self { - // Read as if a little-endian u128 value: - let mut seed_u64 = [0u64; 2]; - le::read_u64_into(&seed, &mut seed_u64); - let state = u128::from(seed_u64[0]) | - u128::from(seed_u64[1]) << 64; - Mcg128Xsl64::new(state) - } -} - -impl RngCore for Mcg128Xsl64 { - #[inline] - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - self.state = self.state.wrapping_mul(MULTIPLIER); - output_xsl_rr(self.state) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_impl(self, dest) - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -#[inline(always)] -fn output_xsl_rr(state: u128) -> u64 { - // Output function XSL RR ("xorshift low (bits), random rotation") - // Constants are for 128-bit state, 64-bit output - const XSHIFT: u32 = 64; // (128 - 64 + 64) / 2 - const ROTATE: u32 = 122; // 128 - 6 - - let rot = (state >> ROTATE) as u32; - let xsl = ((state >> XSHIFT) as u64) ^ (state as u64); - xsl.rotate_right(rot) -} - -#[inline(always)] -fn fill_bytes_impl(rng: &mut R, dest: &mut [u8]) { - let mut left = dest; - while left.len() >= 8 { - let (l, r) = {left}.split_at_mut(8); - left = r; - let chunk: [u8; 8] = rng.next_u64().to_le_bytes(); - l.copy_from_slice(&chunk); - } - let n = left.len(); - if n > 0 { - let chunk: [u8; 8] = rng.next_u64().to_le_bytes(); - left.copy_from_slice(&chunk[..n]); - } -} diff --git a/rand/rand_pcg/src/pcg64.rs b/rand/rand_pcg/src/pcg64.rs deleted file mode 100644 index fadc6dc..0000000 --- a/rand/rand_pcg/src/pcg64.rs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2017 Paul Dicker. -// Copyright 2014-2017 Melissa O'Neill and PCG Project contributors -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! PCG random number generators - -use core::fmt; -use rand_core::{RngCore, SeedableRng, Error, le, impls}; -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; - -// This is the default multiplier used by PCG for 64-bit state. -const MULTIPLIER: u64 = 6364136223846793005; - -/// A PCG random number generator (XSH RR 64/32 (LCG) variant). -/// -/// Permuted Congruential Generator with 64-bit state, internal Linear -/// Congruential Generator, and 32-bit output via "xorshift high (bits), -/// random rotation" output function. -/// -/// This is a 64-bit LCG with explicitly chosen stream with the PCG-XSH-RR -/// output function. This combination is the standard `pcg32`. -/// -/// Despite the name, this implementation uses 16 bytes (128 bit) space -/// comprising 64 bits of state and 64 bits stream selector. These are both set -/// by `SeedableRng`, using a 128-bit seed. -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize,Deserialize))] -pub struct Lcg64Xsh32 { - state: u64, - increment: u64, -} - -/// `Lcg64Xsh32` is also officially known as `pcg32`. -pub type Pcg32 = Lcg64Xsh32; - -impl Lcg64Xsh32 { - /// Construct an instance compatible with PCG seed and stream. - /// - /// Note that PCG specifies default values for both parameters: - /// - /// - `state = 0xcafef00dd15ea5e5` - /// - `stream = 0xa02bdbf7bb3c0a7` - // Note: stream is 1442695040888963407u64 >> 1 - pub fn new(state: u64, stream: u64) -> Self { - // The increment must be odd, hence we discard one bit: - let increment = (stream << 1) | 1; - Lcg64Xsh32::from_state_incr(state, increment) - } - - #[inline] - fn from_state_incr(state: u64, increment: u64) -> Self { - let mut pcg = Lcg64Xsh32 { state, increment }; - // Move away from inital value: - pcg.state = pcg.state.wrapping_add(pcg.increment); - pcg.step(); - pcg - } - - #[inline] - fn step(&mut self) { - // prepare the LCG for the next round - self.state = self.state - .wrapping_mul(MULTIPLIER) - .wrapping_add(self.increment); - } -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for Lcg64Xsh32 { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Lcg64Xsh32 {{}}") - } -} - -/// We use a single 127-bit seed to initialise the state and select a stream. -/// One `seed` bit (lowest bit of `seed[8]`) is ignored. -impl SeedableRng for Lcg64Xsh32 { - type Seed = [u8; 16]; - - fn from_seed(seed: Self::Seed) -> Self { - let mut seed_u64 = [0u64; 2]; - le::read_u64_into(&seed, &mut seed_u64); - - // The increment must be odd, hence we discard one bit: - Lcg64Xsh32::from_state_incr(seed_u64[0], seed_u64[1] | 1) - } -} - -impl RngCore for Lcg64Xsh32 { - #[inline] - fn next_u32(&mut self) -> u32 { - let state = self.state; - self.step(); - - // Output function XSH RR: xorshift high (bits), followed by a random rotate - // Constants are for 64-bit state, 32-bit output - const ROTATE: u32 = 59; // 64 - 5 - const XSHIFT: u32 = 18; // (5 + 32) / 2 - const SPARE: u32 = 27; // 64 - 32 - 5 - - let rot = (state >> ROTATE) as u32; - let xsh = (((state >> XSHIFT) ^ state) >> SPARE) as u32; - xsh.rotate_right(rot) - } - - #[inline] - fn next_u64(&mut self) -> u64 { - impls::next_u64_via_u32(self) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - impls::fill_bytes_via_next(self, dest) - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} diff --git a/rand/rand_pcg/tests/lcg128xsl64.rs b/rand/rand_pcg/tests/lcg128xsl64.rs deleted file mode 100644 index efc72ff..0000000 --- a/rand/rand_pcg/tests/lcg128xsl64.rs +++ /dev/null @@ -1,55 +0,0 @@ -use rand_core::{RngCore, SeedableRng}; -use rand_pcg::{Lcg128Xsl64, Pcg64}; - -#[test] -fn test_lcg128xsl64_construction() { - // Test that various construction techniques produce a working RNG. - let seed = [1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16, - 17,18,19,20, 21,22,23,24, 25,26,27,28, 29,30,31,32]; - let mut rng1 = Lcg128Xsl64::from_seed(seed); - assert_eq!(rng1.next_u64(), 8740028313290271629); - - let mut rng2 = Lcg128Xsl64::from_rng(&mut rng1).unwrap(); - assert_eq!(rng2.next_u64(), 1922280315005786345); - - let mut rng3 = Lcg128Xsl64::seed_from_u64(0); - assert_eq!(rng3.next_u64(), 2354861276966075475); - - // This is the same as Lcg128Xsl64, so we only have a single test: - let mut rng4 = Pcg64::seed_from_u64(0); - assert_eq!(rng4.next_u64(), 2354861276966075475); -} - -#[test] -fn test_lcg128xsl64_true_values() { - // Numbers copied from official test suite (C version). - let mut rng = Lcg128Xsl64::new(42, 54); - - let mut results = [0u64; 6]; - for i in results.iter_mut() { *i = rng.next_u64(); } - let expected: [u64; 6] = [0x86b1da1d72062b68, 0x1304aa46c9853d39, - 0xa3670e9e0dd50358, 0xf9090e529a7dae00, 0xc85b9fd837996f2c, 0x606121f8e3919196]; - assert_eq!(results, expected); -} - -#[cfg(feature="serde1")] -#[test] -fn test_lcg128xsl64_serde() { - use bincode; - use std::io::{BufWriter, BufReader}; - - let mut rng = Lcg128Xsl64::seed_from_u64(0); - - let buf: Vec = Vec::new(); - let mut buf = BufWriter::new(buf); - bincode::serialize_into(&mut buf, &rng).expect("Could not serialize"); - - let buf = buf.into_inner().unwrap(); - let mut read = BufReader::new(&buf[..]); - let mut deserialized: Lcg128Xsl64 = bincode::deserialize_from(&mut read) - .expect("Could not deserialize"); - - for _ in 0..16 { - assert_eq!(rng.next_u64(), deserialized.next_u64()); - } -} diff --git a/rand/rand_pcg/tests/lcg64xsh32.rs b/rand/rand_pcg/tests/lcg64xsh32.rs deleted file mode 100644 index e05bcc1..0000000 --- a/rand/rand_pcg/tests/lcg64xsh32.rs +++ /dev/null @@ -1,54 +0,0 @@ -use rand_core::{RngCore, SeedableRng}; -use rand_pcg::{Lcg64Xsh32, Pcg32}; - -#[test] -fn test_lcg64xsh32_construction() { - // Test that various construction techniques produce a working RNG. - let seed = [1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16]; - let mut rng1 = Lcg64Xsh32::from_seed(seed); - assert_eq!(rng1.next_u64(), 1204678643940597513); - - let mut rng2 = Lcg64Xsh32::from_rng(&mut rng1).unwrap(); - assert_eq!(rng2.next_u64(), 12384929573776311845); - - let mut rng3 = Lcg64Xsh32::seed_from_u64(0); - assert_eq!(rng3.next_u64(), 18195738587432868099); - - // This is the same as Lcg64Xsh32, so we only have a single test: - let mut rng4 = Pcg32::seed_from_u64(0); - assert_eq!(rng4.next_u64(), 18195738587432868099); -} - -#[test] -fn test_lcg64xsh32_true_values() { - // Numbers copied from official test suite. - let mut rng = Lcg64Xsh32::new(42, 54); - - let mut results = [0u32; 6]; - for i in results.iter_mut() { *i = rng.next_u32(); } - let expected: [u32; 6] = [0xa15c02b7, 0x7b47f409, 0xba1d3330, - 0x83d2f293, 0xbfa4784b, 0xcbed606e]; - assert_eq!(results, expected); -} - -#[cfg(feature="serde1")] -#[test] -fn test_lcg64xsh32_serde() { - use bincode; - use std::io::{BufWriter, BufReader}; - - let mut rng = Lcg64Xsh32::seed_from_u64(0); - - let buf: Vec = Vec::new(); - let mut buf = BufWriter::new(buf); - bincode::serialize_into(&mut buf, &rng).expect("Could not serialize"); - - let buf = buf.into_inner().unwrap(); - let mut read = BufReader::new(&buf[..]); - let mut deserialized: Lcg64Xsh32 = bincode::deserialize_from(&mut read) - .expect("Could not deserialize"); - - for _ in 0..16 { - assert_eq!(rng.next_u64(), deserialized.next_u64()); - } -} diff --git a/rand/rand_pcg/tests/mcg128xsl64.rs b/rand/rand_pcg/tests/mcg128xsl64.rs deleted file mode 100644 index d58fa75..0000000 --- a/rand/rand_pcg/tests/mcg128xsl64.rs +++ /dev/null @@ -1,54 +0,0 @@ -use rand_core::{RngCore, SeedableRng}; -use rand_pcg::{Mcg128Xsl64, Pcg64Mcg}; - -#[test] -fn test_mcg128xsl64_construction() { - // Test that various construction techniques produce a working RNG. - let seed = [1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16]; - let mut rng1 = Mcg128Xsl64::from_seed(seed); - assert_eq!(rng1.next_u64(), 7071994460355047496); - - let mut rng2 = Mcg128Xsl64::from_rng(&mut rng1).unwrap(); - assert_eq!(rng2.next_u64(), 12300796107712034932); - - let mut rng3 = Mcg128Xsl64::seed_from_u64(0); - assert_eq!(rng3.next_u64(), 6198063878555692194); - - // This is the same as Mcg128Xsl64, so we only have a single test: - let mut rng4 = Pcg64Mcg::seed_from_u64(0); - assert_eq!(rng4.next_u64(), 6198063878555692194); -} - -#[test] -fn test_mcg128xsl64_true_values() { - // Numbers copied from official test suite (C version). - let mut rng = Mcg128Xsl64::new(42); - - let mut results = [0u64; 6]; - for i in results.iter_mut() { *i = rng.next_u64(); } - let expected: [u64; 6] = [0x63b4a3a813ce700a, 0x382954200617ab24, - 0xa7fd85ae3fe950ce, 0xd715286aa2887737, 0x60c92fee2e59f32c, 0x84c4e96beff30017]; - assert_eq!(results, expected); -} - -#[cfg(feature="serde1")] -#[test] -fn test_mcg128xsl64_serde() { - use bincode; - use std::io::{BufWriter, BufReader}; - - let mut rng = Mcg128Xsl64::seed_from_u64(0); - - let buf: Vec = Vec::new(); - let mut buf = BufWriter::new(buf); - bincode::serialize_into(&mut buf, &rng).expect("Could not serialize"); - - let buf = buf.into_inner().unwrap(); - let mut read = BufReader::new(&buf[..]); - let mut deserialized: Mcg128Xsl64 = bincode::deserialize_from(&mut read) - .expect("Could not deserialize"); - - for _ in 0..16 { - assert_eq!(rng.next_u64(), deserialized.next_u64()); - } -} diff --git a/rand/rand_xorshift/CHANGELOG.md b/rand/rand_xorshift/CHANGELOG.md deleted file mode 100644 index ce3098a..0000000 --- a/rand/rand_xorshift/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.2.0] - 2019-06-12 -- Bump minor crate version since rand_core bump is a breaking change -- Switch to Edition 2018 - -## [0.1.2] - 2019-06-06 - yanked -- Bump `rand_core` version -- Make XorShiftRng::from_rng portable by enforcing Endianness (#815) - -## [0.1.1] - 2019-01-04 -- Reorganise code and tests; tweak doc - -## [0.1.0] - 2018-07-16 -- Pulled out of the Rand crate diff --git a/rand/rand_xorshift/COPYRIGHT b/rand/rand_xorshift/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_xorshift/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_xorshift/Cargo.toml b/rand/rand_xorshift/Cargo.toml deleted file mode 100644 index 9cb257b..0000000 --- a/rand/rand_xorshift/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "rand_xorshift" -version = "0.2.0" -authors = ["The Rand Project Developers", "The Rust Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://rust-random.github.io/rand/rand_xorshift/" -homepage = "https://crates.io/crates/rand_xorshift" -description = """ -Xorshift random number generator -""" -keywords = ["random", "rng", "xorshift"] -categories = ["algorithms", "no-std"] -edition = "2018" - -[badges] -travis-ci = { repository = "rust-random/rand" } -appveyor = { repository = "rust-random/rand" } - -[features] -serde1 = ["serde"] - -[dependencies] -rand_core = { path = "../rand_core", version = "0.5" } -serde = { version = "1", features = ["derive"], optional = true } - -[dev-dependencies] -# This is for testing serde, unfortunately we can't specify feature-gated dev -# deps yet, see: https://github.com/rust-lang/cargo/issues/1596 -bincode = "1" diff --git a/rand/rand_xorshift/LICENSE-APACHE b/rand/rand_xorshift/LICENSE-APACHE deleted file mode 100644 index 17d7468..0000000 --- a/rand/rand_xorshift/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_xorshift/LICENSE-MIT b/rand/rand_xorshift/LICENSE-MIT deleted file mode 100644 index d93b5ba..0000000 --- a/rand/rand_xorshift/LICENSE-MIT +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2018 Developers of the Rand project -Copyright (c) 2014 The Rust Project Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_xorshift/README.md b/rand/rand_xorshift/README.md deleted file mode 100644 index 57de284..0000000 --- a/rand/rand_xorshift/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# rand_xorshift - -[![Build Status](https://travis-ci.org/rust-random/rand.svg)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_xorshift.svg)](https://crates.io/crates/rand_xorshift) -[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_xorshift) -[![API](https://docs.rs/rand_xorshift/badge.svg)](https://docs.rs/rand_xorshift) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -Implements the Xorshift random number generator. - -The Xorshift[^1] algorithm is not suitable for cryptographic purposes -but is very fast. If you do not know for sure that it fits your -requirements, use a more secure one such as `StdRng` or `OsRng`. - -[^1]: Marsaglia, George (July 2003). - ["Xorshift RNGs"](https://www.jstatsoft.org/v08/i14/paper). - *Journal of Statistical Software*. Vol. 8 (Issue 14). - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_xorshift) -- [API documentation (docs.rs)](https://docs.rs/rand_xorshift) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_xorshift/CHANGELOG.md) - -[rand]: https://crates.io/crates/rand - - -## Crate Features - -`rand_xorshift` is `no_std` compatible. It does not require any functionality -outside of the `core` lib, thus there are no features to configure. - -The `serde1` feature includes implementations of `Serialize` and `Deserialize` -for the included RNGs. - - -## License - -`rand_xorshift` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_xorshift/src/lib.rs b/rand/rand_xorshift/src/lib.rs deleted file mode 100644 index b9fef23..0000000 --- a/rand/rand_xorshift/src/lib.rs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The xorshift random number generator. - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] - -#![no_std] - -use core::num::Wrapping as w; -use core::fmt; -use rand_core::{RngCore, SeedableRng, Error, impls, le}; -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; - -/// An Xorshift random number generator. -/// -/// The Xorshift[^1] algorithm is not suitable for cryptographic purposes -/// but is very fast. If you do not know for sure that it fits your -/// requirements, use a more secure one such as `StdRng` or `OsRng`. -/// -/// [^1]: Marsaglia, George (July 2003). -/// ["Xorshift RNGs"](https://www.jstatsoft.org/v08/i14/paper). -/// *Journal of Statistical Software*. Vol. 8 (Issue 14). -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize,Deserialize))] -pub struct XorShiftRng { - x: w, - y: w, - z: w, - w: w, -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for XorShiftRng { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "XorShiftRng {{}}") - } -} - -impl RngCore for XorShiftRng { - #[inline] - fn next_u32(&mut self) -> u32 { - let x = self.x; - let t = x ^ (x << 11); - self.x = self.y; - self.y = self.z; - self.z = self.w; - let w_ = self.w; - self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8)); - self.w.0 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - impls::next_u64_via_u32(self) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - impls::fill_bytes_via_next(self, dest) - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for XorShiftRng { - type Seed = [u8; 16]; - - fn from_seed(seed: Self::Seed) -> Self { - let mut seed_u32 = [0u32; 4]; - le::read_u32_into(&seed, &mut seed_u32); - - // Xorshift cannot be seeded with 0 and we cannot return an Error, but - // also do not wish to panic (because a random seed can legitimately be - // 0); our only option is therefore to use a preset value. - if seed_u32.iter().all(|&x| x == 0) { - seed_u32 = [0xBAD_5EED, 0xBAD_5EED, 0xBAD_5EED, 0xBAD_5EED]; - } - - XorShiftRng { - x: w(seed_u32[0]), - y: w(seed_u32[1]), - z: w(seed_u32[2]), - w: w(seed_u32[3]), - } - } - - fn from_rng(mut rng: R) -> Result { - let mut b = [0u8; 16]; - loop { - rng.try_fill_bytes(&mut b[..])?; - if !b.iter().all(|&x| x == 0) { - break; - } - } - - Ok(XorShiftRng { - x: w(u32::from_le_bytes([b[0], b[1], b[2], b[3]])), - y: w(u32::from_le_bytes([b[4], b[5], b[6], b[7]])), - z: w(u32::from_le_bytes([b[8], b[9], b[10], b[11]])), - w: w(u32::from_le_bytes([b[12], b[13], b[14], b[15]])), - }) - } -} diff --git a/rand/rand_xorshift/tests/mod.rs b/rand/rand_xorshift/tests/mod.rs deleted file mode 100644 index 7ecdeae..0000000 --- a/rand/rand_xorshift/tests/mod.rs +++ /dev/null @@ -1,89 +0,0 @@ -use rand_core::{RngCore, SeedableRng}; -use rand_xorshift::XorShiftRng; - -#[test] -fn test_xorshift_construction() { - // Test that various construction techniques produce a working RNG. - let seed = [1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16]; - let mut rng1 = XorShiftRng::from_seed(seed); - assert_eq!(rng1.next_u64(), 4325440999699518727); - - let mut rng2 = XorShiftRng::from_rng(&mut rng1).unwrap(); - // Yes, this makes rng2 a clone of rng1! - assert_eq!(rng1.next_u64(), 15614385950550801700); - assert_eq!(rng2.next_u64(), 15614385950550801700); -} - -#[test] -fn test_xorshift_true_values() { - let seed = [16,15,14,13, 12,11,10,9, 8,7,6,5, 4,3,2,1]; - let mut rng = XorShiftRng::from_seed(seed); - - let mut results = [0u32; 9]; - for i in results.iter_mut() { *i = rng.next_u32(); } - let expected: [u32; 9] = [ - 2081028795, 620940381, 269070770, 16943764, 854422573, 29242889, - 1550291885, 1227154591, 271695242]; - assert_eq!(results, expected); - - let mut results = [0u64; 9]; - for i in results.iter_mut() { *i = rng.next_u64(); } - let expected: [u64; 9] = [ - 9247529084182843387, 8321512596129439293, 14104136531997710878, - 6848554330849612046, 343577296533772213, 17828467390962600268, - 9847333257685787782, 7717352744383350108, 1133407547287910111]; - assert_eq!(results, expected); - - let mut results = [0u8; 32]; - rng.fill_bytes(&mut results); - let expected = [102, 57, 212, 16, 233, 130, 49, 183, - 158, 187, 44, 203, 63, 149, 45, 17, - 117, 129, 131, 160, 70, 121, 158, 155, - 224, 209, 192, 53, 10, 62, 57, 72]; - assert_eq!(results, expected); -} - -#[test] -fn test_xorshift_zero_seed() { - // Xorshift does not work with an all zero seed. - // Assert it does not panic. - let seed = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - let mut rng = XorShiftRng::from_seed(seed); - let a = rng.next_u64(); - let b = rng.next_u64(); - assert!(a != 0); - assert!(b != a); -} - -#[test] -fn test_xorshift_clone() { - let seed = [1,2,3,4, 5,5,7,8, 8,7,6,5, 4,3,2,1]; - let mut rng1 = XorShiftRng::from_seed(seed); - let mut rng2 = rng1.clone(); - for _ in 0..16 { - assert_eq!(rng1.next_u64(), rng2.next_u64()); - } -} - -#[cfg(feature="serde1")] -#[test] -fn test_xorshift_serde() { - use bincode; - use std::io::{BufWriter, BufReader}; - - let seed = [1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16]; - let mut rng = XorShiftRng::from_seed(seed); - - let buf: Vec = Vec::new(); - let mut buf = BufWriter::new(buf); - bincode::serialize_into(&mut buf, &rng).expect("Could not serialize"); - - let buf = buf.into_inner().unwrap(); - let mut read = BufReader::new(&buf[..]); - let mut deserialized: XorShiftRng = bincode::deserialize_from(&mut read) - .expect("Could not deserialize"); - - for _ in 0..16 { - assert_eq!(rng.next_u64(), deserialized.next_u64()); - } -} diff --git a/rand/rand_xoshiro/CHANGELOG.md b/rand/rand_xoshiro/CHANGELOG.md deleted file mode 100644 index 56cb9c2..0000000 --- a/rand/rand_xoshiro/CHANGELOG.md +++ /dev/null @@ -1,24 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.3.1] - 2019-08-06 -- Drop `byteorder`-dependency in favor of `stdlib`-implementation. - -## [0.3.0] - 2019-06-12 -- Bump minor crate version since rand_core bump is a breaking change -- Switch to Edition 2018 - -## [0.2.1] - 2019-06-06 - yanked -- Bump `rand_core` version -- Document crate features in README - -## [0.2.0] - 2019-05-28 -- Fix `seed_from_u64(0)` for `Xoroshiro64StarStar` and `Xoroshiro64Star`. This - breaks value stability for these generators if initialized with `seed_from_u64`. -- Implement Serde support. - -## [0.1.0] - 2019-01-04 -Initial release. diff --git a/rand/rand_xoshiro/COPYRIGHT b/rand/rand_xoshiro/COPYRIGHT deleted file mode 100644 index 468d907..0000000 --- a/rand/rand_xoshiro/COPYRIGHT +++ /dev/null @@ -1,12 +0,0 @@ -Copyrights in the Rand project are retained by their contributors. No -copyright assignment is required to contribute to the Rand project. - -For full authorship information, see the version control history. - -Except as otherwise noted (below and/or in individual files), Rand is -licensed under the Apache License, Version 2.0 or - or the MIT license - or , at your option. - -The Rand project includes code from the Rust project -published under these same licenses. diff --git a/rand/rand_xoshiro/Cargo.toml b/rand/rand_xoshiro/Cargo.toml deleted file mode 100644 index 128c213..0000000 --- a/rand/rand_xoshiro/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "rand_xoshiro" -version = "0.3.1" # NB: When modifying, also modify html_root_url in lib.rs -authors = ["The Rand Project Developers"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/rust-random/rand" -documentation = "https://docs.rs/rand_xoshiro" -homepage = "https://crates.io/crates/rand_xoshiro" -description = "Xoshiro, xoroshiro and splitmix64 random number generators" -keywords = ["random", "rng"] -categories = ["algorithms"] -edition = "2018" - -[features] -serde1 = ["serde"] - -[dependencies] -rand_core = { path = "../rand_core", version = "0.5" } -serde = { version = "1", features = ["derive"], optional=true } - -[dev-dependencies] -# This is for testing serde, unfortunately we can't specify feature-gated dev -# deps yet, see: https://github.com/rust-lang/cargo/issues/1596 -bincode = { version = "1" } diff --git a/rand/rand_xoshiro/LICENSE-APACHE b/rand/rand_xoshiro/LICENSE-APACHE deleted file mode 100644 index 16fe87b..0000000 --- a/rand/rand_xoshiro/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/rand/rand_xoshiro/LICENSE-MIT b/rand/rand_xoshiro/LICENSE-MIT deleted file mode 100644 index a5e040c..0000000 --- a/rand/rand_xoshiro/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2018 Developers of the Rand project - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rand/rand_xoshiro/README.md b/rand/rand_xoshiro/README.md deleted file mode 100644 index 1c02992..0000000 --- a/rand/rand_xoshiro/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# rand_xoshiro - -[![Build Status](https://travis-ci.org/rust-random/rand.svg?branch=master)](https://travis-ci.org/rust-random/rand) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/rand?svg=true)](https://ci.appveyor.com/project/rust-random/rand) -[![Latest version](https://img.shields.io/crates/v/rand_xoshiro.svg)](https://crates.io/crates/rand_xoshiro) -[![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) -[![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_xoshiro) -[![API](https://docs.rs/rand_xoshiro/badge.svg)](https://docs.rs/rand_xoshiro) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.32+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) - -Rust implementation of the [xoshiro, xoroshiro and splitmix64](http://xoshiro.di.unimi.it) random number generators. - -This crate depends on [rand_core](https://crates.io/crates/rand_core) and is -part of the [Rand project](https://github.com/rust-random/rand). - -Links: - -- [API documentation (master)](https://rust-random.github.io/rand/rand_xoshiro) -- [API documentation (docs.rs)](https://docs.rs/rand_xoshiro) -- [Changelog](https://github.com/rust-random/rand/blob/master/rand_xoshiro/CHANGELOG.md) - -## Crate Features - -`rand_xoshiro` is no_std compatible by default. - -The `serde1` feature includes implementations of `Serialize` and `Deserialize` for the included RNGs. - -## License - -`rand_xoshiro` is distributed under the terms of both the MIT license and the -Apache License (Version 2.0). - -See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and -[COPYRIGHT](COPYRIGHT) for details. diff --git a/rand/rand_xoshiro/src/common.rs b/rand/rand_xoshiro/src/common.rs deleted file mode 100644 index b188dd6..0000000 --- a/rand/rand_xoshiro/src/common.rs +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/// Initialize a RNG from a `u64` seed using `SplitMix64`. -macro_rules! from_splitmix { - ($seed:expr) => { { - let mut rng = crate::SplitMix64::seed_from_u64($seed); - Self::from_rng(&mut rng).unwrap() - } } -} - -/// Apply the ** scrambler used by some RNGs from the xoshiro family. -macro_rules! starstar_u64 { - ($x:expr) => { - $x.wrapping_mul(5).rotate_left(7).wrapping_mul(9) - } -} - -/// Apply the ** scrambler used by some RNGs from the xoshiro family. -macro_rules! starstar_u32 { - ($x:expr) => { - $x.wrapping_mul(0x9E3779BB).rotate_left(5).wrapping_mul(5) - } -} - -/// Implement a jump function for an RNG from the xoshiro family. -macro_rules! impl_jump { - (u32, $self:expr, [$j0:expr, $j1:expr]) => { - const JUMP: [u32; 2] = [$j0, $j1]; - let mut s0 = 0; - let mut s1 = 0; - for j in &JUMP { - for b in 0..32 { - if (j & 1 << b) != 0 { - s0 ^= $self.s0; - s1 ^= $self.s1; - } - $self.next_u32(); - } - } - $self.s0 = s0; - $self.s1 = s1; - }; - (u64, $self:expr, [$j0:expr, $j1:expr]) => { - const JUMP: [u64; 2] = [$j0, $j1]; - let mut s0 = 0; - let mut s1 = 0; - for j in &JUMP { - for b in 0..64 { - if (j & 1 << b) != 0 { - s0 ^= $self.s0; - s1 ^= $self.s1; - } - $self.next_u64(); - } - } - $self.s0 = s0; - $self.s1 = s1; - }; - (u32, $self:expr, [$j0:expr, $j1:expr, $j2:expr, $j3:expr]) => { - const JUMP: [u32; 4] = [$j0, $j1, $j2, $j3]; - let mut s0 = 0; - let mut s1 = 0; - let mut s2 = 0; - let mut s3 = 0; - for j in &JUMP { - for b in 0..32 { - if (j & 1 << b) != 0 { - s0 ^= $self.s[0]; - s1 ^= $self.s[1]; - s2 ^= $self.s[2]; - s3 ^= $self.s[3]; - } - $self.next_u32(); - } - } - $self.s[0] = s0; - $self.s[1] = s1; - $self.s[2] = s2; - $self.s[3] = s3; - }; - (u64, $self:expr, [$j0:expr, $j1:expr, $j2:expr, $j3:expr]) => { - const JUMP: [u64; 4] = [$j0, $j1, $j2, $j3]; - let mut s0 = 0; - let mut s1 = 0; - let mut s2 = 0; - let mut s3 = 0; - for j in &JUMP { - for b in 0..64 { - if (j & 1 << b) != 0 { - s0 ^= $self.s[0]; - s1 ^= $self.s[1]; - s2 ^= $self.s[2]; - s3 ^= $self.s[3]; - } - $self.next_u64(); - } - } - $self.s[0] = s0; - $self.s[1] = s1; - $self.s[2] = s2; - $self.s[3] = s3; - }; - (u64, $self:expr, [$j0:expr, $j1:expr, $j2:expr, $j3:expr, - $j4:expr, $j5:expr, $j6:expr, $j7:expr]) => { - const JUMP: [u64; 8] = [$j0, $j1, $j2, $j3, $j4, $j5, $j6, $j7]; - let mut s = [0; 8]; - for j in &JUMP { - for b in 0..64 { - if (j & 1 << b) != 0 { - s[0] ^= $self.s[0]; - s[1] ^= $self.s[1]; - s[2] ^= $self.s[2]; - s[3] ^= $self.s[3]; - s[4] ^= $self.s[4]; - s[5] ^= $self.s[5]; - s[6] ^= $self.s[6]; - s[7] ^= $self.s[7]; - } - $self.next_u64(); - } - } - $self.s = s; - }; -} - -/// Implement the xoroshiro iteration. -macro_rules! impl_xoroshiro_u32 { - ($self:expr) => { - $self.s1 ^= $self.s0; - $self.s0 = $self.s0.rotate_left(26) ^ $self.s1 ^ ($self.s1 << 9); - $self.s1 = $self.s1.rotate_left(13); - } -} - -/// Implement the xoroshiro iteration. -macro_rules! impl_xoroshiro_u64 { - ($self:expr) => { - $self.s1 ^= $self.s0; - $self.s0 = $self.s0.rotate_left(24) ^ $self.s1 ^ ($self.s1 << 16); - $self.s1 = $self.s1.rotate_left(37); - } -} - -/// Implement the xoshiro iteration for `u32` output. -macro_rules! impl_xoshiro_u32 { - ($self:expr) => { - let t = $self.s[1] << 9; - - $self.s[2] ^= $self.s[0]; - $self.s[3] ^= $self.s[1]; - $self.s[1] ^= $self.s[2]; - $self.s[0] ^= $self.s[3]; - - $self.s[2] ^= t; - - $self.s[3] = $self.s[3].rotate_left(11); - } -} - -/// Implement the xoshiro iteration for `u64` output. -macro_rules! impl_xoshiro_u64 { - ($self:expr) => { - let t = $self.s[1] << 17; - - $self.s[2] ^= $self.s[0]; - $self.s[3] ^= $self.s[1]; - $self.s[1] ^= $self.s[2]; - $self.s[0] ^= $self.s[3]; - - $self.s[2] ^= t; - - $self.s[3] = $self.s[3].rotate_left(45); - } -} - -/// Implement the large-state xoshiro iteration. -macro_rules! impl_xoshiro_large { - ($self:expr) => { - let t = $self.s[1] << 11; - - $self.s[2] ^= $self.s[0]; - $self.s[5] ^= $self.s[1]; - $self.s[1] ^= $self.s[2]; - $self.s[7] ^= $self.s[3]; - $self.s[3] ^= $self.s[4]; - $self.s[4] ^= $self.s[5]; - $self.s[0] ^= $self.s[6]; - $self.s[6] ^= $self.s[7]; - - $self.s[6] ^= t; - - $self.s[7] = $self.s[7].rotate_left(21); - } -} - -/// Map an all-zero seed to a different one. -macro_rules! deal_with_zero_seed { - ($seed:expr, $Self:ident) => { - if $seed.iter().all(|&x| x == 0) { - return $Self::seed_from_u64(0); - } - } -} - -/// 512-bit seed for a generator. -/// -/// This wrapper is necessary, because some traits required for a seed are not -/// implemented on large arrays. -#[derive(Clone)] -pub struct Seed512(pub [u8; 64]); - -use core; -impl Seed512 { - /// Return an iterator over the seed. - pub fn iter(&self) -> core::slice::Iter { - self.0.iter() - } -} - -impl core::fmt::Debug for Seed512 { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - self.0[..].fmt(f) - } -} - -impl Default for Seed512 { - fn default() -> Seed512 { - Seed512([0; 64]) - } -} - -impl AsMut<[u8]> for Seed512 { - fn as_mut(&mut self) -> &mut [u8] { - &mut self.0 - } -} - diff --git a/rand/rand_xoshiro/src/lib.rs b/rand/rand_xoshiro/src/lib.rs deleted file mode 100644 index 3047e92..0000000 --- a/rand/rand_xoshiro/src/lib.rs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! This crate implements the [xoshiro] family of pseudorandom number generators -//! designed by David Blackman and Sebastiano Vigna. They feature high -//! perfomance and a small state and superseed the previous xorshift-based -//! generators. However, they are no cryptographically secure and their output -//! can be predicted by observing a few samples. -//! -//! The following generators are implemented: -//! -//! # 64-bit generators -//! - [`Xoshiro256StarStar`]: Recommended for all purposes. Excellent speed and -//! a state space (256 bits) large enough for any parallel application. -//! - [`Xoshiro256Plus`]: Recommended for generating 64-bit floating-point -//! numbers. About 15% faster than `Xoshiro256StarStar`, but has a [low linear -//! complexity] in the lowest bits (which are discarded when generating -//! floats), making it fail linearity tests. This is unlikely to have any -//! impact in practise. -//! - [`Xoroshiro128StarStar`]: An alternative to `Xoshiro256StarStar`, having -//! the same speed but using half the state. Only suited for low-scale parallel -//! applications. -//! - [`Xoroshiro128Plus`]: An alternative to `Xoshiro256Plus`, having the same -//! speed but using half the state. Only suited for low-scale parallel -//! applications. Has a [low linear complexity] in the lowest bits (which are -//! discarded when generating floats), making it fail linearity tests. This is -//! unlikely to have any impact in practise. -//! - [`Xoshiro512StarStar`]: An alternative to `Xoshiro256StarStar` with more -//! state and the same speed. -//! - [`Xoshiro512Plus`]: An alternative to `Xoshiro512Plus` with more -//! state and the same speed. Has a [low linear complexity] in the lowest bits -//! (which are discarded when generating floats), making it fail linearity -//! tests. This is unlikely to have any impact in practise. -//! - [`SplitMix64`]: Recommended for initializing generators of the xoshiro -//! familiy from a 64-bit seed. Used for implementing `seed_from_u64`. -//! -//! # 32-bit generators -//! - [`Xoshiro128StarStar`]: Recommended for all purposes. Excellent speed. -//! - [`Xoshiro128Plus`]: Recommended for generating 32-bit floating-point -//! numbers. Faster than `Xoshiro128StarStar`, but has a [low linear -//! complexity] in the lowest bits (which are discarded when generating -//! floats), making it fail linearity tests. This is unlikely to have any -//! impact in practise. -//! - [`Xoroshiro64StarStar`]: An alternative to `Xoshiro128StarStar`, having -//! the same speed but using half the state. -//! - [`Xoroshiro64Star`]: An alternative to `Xoshiro128Plus`, having the -//! same speed but using half the state. Has a [low linear complexity] in the -//! lowest bits (which are discarded when generating floats), making it fail -//! linearity tests. This is unlikely to have any impact in practise. -//! -//! [xoshiro]: http://xoshiro.di.unimi.it/ -//! [low linear complexity]: http://xoshiro.di.unimi.it/lowcomp.php - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://docs.rs/rand_xoshiro/0.3.1")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] -#![allow(clippy::unreadable_literal)] -#![no_std] - -#[macro_use] -mod common; -mod splitmix64; -mod xoshiro128starstar; -mod xoshiro128plus; -mod xoshiro256starstar; -mod xoshiro256plus; -mod xoshiro512starstar; -mod xoshiro512plus; -mod xoroshiro128plus; -mod xoroshiro128starstar; -mod xoroshiro64starstar; -mod xoroshiro64star; - -pub use rand_core; -pub use splitmix64::SplitMix64; -pub use xoshiro128starstar::Xoshiro128StarStar; -pub use xoshiro128plus::Xoshiro128Plus; -pub use xoshiro256starstar::Xoshiro256StarStar; -pub use xoshiro256plus::Xoshiro256Plus; -pub use common::Seed512; -pub use xoshiro512starstar::Xoshiro512StarStar; -pub use xoshiro512plus::Xoshiro512Plus; -pub use xoroshiro128plus::Xoroshiro128Plus; -pub use xoroshiro128starstar::Xoroshiro128StarStar; -pub use xoroshiro64starstar::Xoroshiro64StarStar; -pub use xoroshiro64star::Xoroshiro64Star; diff --git a/rand/rand_xoshiro/src/splitmix64.rs b/rand/rand_xoshiro/src/splitmix64.rs deleted file mode 100644 index 3a41450..0000000 --- a/rand/rand_xoshiro/src/splitmix64.rs +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::le::read_u64_into; -use rand_core::impls::fill_bytes_via_next; -use rand_core::{RngCore, SeedableRng, Error}; - -/// A splitmix64 random number generator. -/// -/// The splitmix algorithm is not suitable for cryptographic purposes, but is -/// very fast and has a 64 bit state. -/// -/// The algorithm used here is translated from [the `splitmix64.c` -/// reference source code](http://xoshiro.di.unimi.it/splitmix64.c) by -/// Sebastiano Vigna. For `next_u32`, a more efficient mixing function taken -/// from [`dsiutils`](http://dsiutils.di.unimi.it/) is used. -#[allow(missing_copy_implementations)] -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct SplitMix64 { - x: u64, -} - -const PHI: u64 = 0x9e3779b97f4a7c15; - -impl RngCore for SplitMix64 { - #[inline] - fn next_u32(&mut self) -> u32 { - self.x = self.x.wrapping_add(PHI); - let mut z = self.x; - // David Stafford's - // (http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html) - // "Mix4" variant of the 64-bit finalizer in Austin Appleby's - // MurmurHash3 algorithm. - z = (z ^ (z >> 33)).wrapping_mul(0x62A9D9ED799705F5); - z = (z ^ (z >> 28)).wrapping_mul(0xCB24D0A5C88C35B3); - (z >> 32) as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - self.x = self.x.wrapping_add(PHI); - let mut z = self.x; - z = (z ^ (z >> 30)).wrapping_mul(0xbf58476d1ce4e5b9); - z = (z ^ (z >> 27)).wrapping_mul(0x94d049bb133111eb); - z ^ (z >> 31) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for SplitMix64 { - type Seed = [u8; 8]; - - /// Create a new `SplitMix64`. - fn from_seed(seed: [u8; 8]) -> SplitMix64 { - let mut state = [0; 1]; - read_u64_into(&seed, &mut state); - SplitMix64 { - x: state[0], - } - } - - /// Seed a `SplitMix64` from a `u64`. - fn seed_from_u64(seed: u64) -> SplitMix64 { - SplitMix64::from_seed(seed.to_le_bytes()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = SplitMix64::seed_from_u64(1477776061723855037); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/splitmix64.c - let expected : [u64 ; 50]= [ - 1985237415132408290, 2979275885539914483, 13511426838097143398, - 8488337342461049707, 15141737807933549159, 17093170987380407015, - 16389528042912955399, 13177319091862933652, 10841969400225389492, - 17094824097954834098, 3336622647361835228, 9678412372263018368, - 11111587619974030187, 7882215801036322410, 5709234165213761869, - 7799681907651786826, 4616320717312661886, 4251077652075509767, - 7836757050122171900, 5054003328188417616, 12919285918354108358, - 16477564761813870717, 5124667218451240549, 18099554314556827626, - 7603784838804469118, 6358551455431362471, 3037176434532249502, - 3217550417701719149, 9958699920490216947, 5965803675992506258, - 12000828378049868312, 12720568162811471118, 245696019213873792, - 8351371993958923852, 14378754021282935786, 5655432093647472106, - 5508031680350692005, 8515198786865082103, 6287793597487164412, - 14963046237722101617, 3630795823534910476, 8422285279403485710, - 10554287778700714153, 10871906555720704584, 8659066966120258468, - 9420238805069527062, 10338115333623340156, 13514802760105037173, - 14635952304031724449, 15419692541594102413, - ]; - for &e in expected.iter() { - assert_eq!(rng.next_u64(), e); - } - } - - #[test] - fn next_u32() { - let mut rng = SplitMix64::seed_from_u64(10); - // These values were produced with the reference implementation: - // http://dsiutils.di.unimi.it/dsiutils-2.5.1-src.tar.gz - let expected : [u32 ; 100]= [ - 3930361779, 4016923089, 4113052479, 925926767, 1755287528, - 802865554, 954171070, 3724185978, 173676273, 1414488795, 12664133, - 1784889697, 1303817078, 261610523, 941280008, 2571813643, - 2954453492, 378291111, 2546873158, 3923319175, 645257028, - 3881821278, 2681538690, 3037029984, 1999958137, 1853970361, - 2989951788, 2126166628, 839962987, 3989679659, 3656977858, - 684284364, 1673258011, 170979192, 3037622326, 1600748179, - 1780764218, 1141430714, 4139736875, 3336905707, 2262051600, - 3830850262, 2430765325, 1073032139, 1668888979, 2716938970, - 4102420032, 40305196, 386350562, 2754480591, 622869439, 2129598760, - 2306038241, 4218338739, 412298926, 3453855056, 3061469690, - 4284292697, 994843708, 1591016681, 414726151, 1238182607, 18073498, - 1237631493, 351884714, 2347486264, 2488990876, 802846256, 645670443, - 957607012, 3126589776, 1966356370, 3036485766, 868696717, - 2808613630, 2070968151, 1025536863, 1743949425, 466212687, - 2994327271, 209776458, 1246125124, 3344380309, 2203947859, - 968313105, 2805485302, 197484837, 3472483632, 3931823935, - 3288490351, 4165666529, 3671080416, 689542830, 1272555356, - 1039141475, 3984640460, 4142959054, 2252788890, 2459379590, - 991872507, - ]; - for &e in expected.iter() { - assert_eq!(rng.next_u32(), e); - } - } -} diff --git a/rand/rand_xoshiro/src/xoroshiro128plus.rs b/rand/rand_xoshiro/src/xoroshiro128plus.rs deleted file mode 100644 index a7b4ebc..0000000 --- a/rand/rand_xoshiro/src/xoroshiro128plus.rs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core; -use rand_core::le::read_u64_into; -use rand_core::impls::fill_bytes_via_next; -use rand_core::{RngCore, SeedableRng}; - -/// A xoroshiro128+ random number generator. -/// -/// The xoroshiro128+ algorithm is not suitable for cryptographic purposes, but -/// is very fast and has good statistical properties, besides a low linear -/// complexity in the lowest bits. -/// -/// The algorithm used here is translated from [the `xoroshiro128plus.c` -/// reference source code](http://xoshiro.di.unimi.it/xoroshiro128plus.c) by -/// David Blackman and Sebastiano Vigna. -#[allow(missing_copy_implementations)] -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoroshiro128Plus { - s0: u64, - s1: u64, -} - -impl Xoroshiro128Plus { - /// Jump forward, equivalently to 2^64 calls to `next_u64()`. - /// - /// This can be used to generate 2^64 non-overlapping subsequences for - /// parallel computations. - /// - /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128Plus; - /// - /// let rng1 = Xoroshiro128Plus::seed_from_u64(0); - /// let mut rng2 = rng1.clone(); - /// rng2.jump(); - /// let mut rng3 = rng2.clone(); - /// rng3.jump(); - /// ``` - pub fn jump(&mut self) { - impl_jump!(u64, self, [0xdf900294d8f554a5, 0x170865df4b3201fc]); - } - - /// Jump forward, equivalently to 2^96 calls to `next_u64()`. - /// - /// This can be used to generate 2^32 starting points, from each of which - /// `jump()` will generate 2^32 non-overlapping subsequences for parallel - /// distributed computations. - pub fn long_jump(&mut self) { - impl_jump!(u64, self, [0xd2a98b26625eee7b, 0xdddf9b1090aa7ac1]); - } -} - -impl RngCore for Xoroshiro128Plus { - #[inline] - fn next_u32(&mut self) -> u32 { - // The two lowest bits have some linear dependencies, so we use the - // upper bits instead. - (self.next_u64() >> 32) as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - let r = self.s0.wrapping_add(self.s1); - impl_xoroshiro_u64!(self); - r - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for Xoroshiro128Plus { - type Seed = [u8; 16]; - - /// Create a new `Xoroshiro128Plus`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - fn from_seed(seed: [u8; 16]) -> Xoroshiro128Plus { - deal_with_zero_seed!(seed, Self); - let mut s = [0; 2]; - read_u64_into(&seed, &mut s); - - Xoroshiro128Plus { - s0: s[0], - s1: s[1], - } - } - - /// Seed a `Xoroshiro128Plus` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoroshiro128Plus { - from_splitmix!(seed) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoroshiro128Plus::from_seed( - [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro128starstar.c - let expected = [ - 3, 412333834243, 2360170716294286339, 9295852285959843169, - 2797080929874688578, 6019711933173041966, 3076529664176959358, - 3521761819100106140, 7493067640054542992, 920801338098114767, - ]; - for &e in &expected { - assert_eq!(rng.next_u64(), e); - } - } -} diff --git a/rand/rand_xoshiro/src/xoroshiro128starstar.rs b/rand/rand_xoshiro/src/xoroshiro128starstar.rs deleted file mode 100644 index 21823f5..0000000 --- a/rand/rand_xoshiro/src/xoroshiro128starstar.rs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core; -use rand_core::le::read_u64_into; -use rand_core::impls::fill_bytes_via_next; -use rand_core::{RngCore, SeedableRng}; - -/// A xoroshiro128** random number generator. -/// -/// The xoroshiro128** algorithm is not suitable for cryptographic purposes, but -/// is very fast and has excellent statistical properties. -/// -/// The algorithm used here is translated from [the `xoroshiro128starstar.c` -/// reference source code](http://xoshiro.di.unimi.it/xoroshiro128starstar.c) by -/// David Blackman and Sebastiano Vigna. -#[allow(missing_copy_implementations)] -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoroshiro128StarStar { - s0: u64, - s1: u64, -} - -impl Xoroshiro128StarStar { - /// Jump forward, equivalently to 2^64 calls to `next_u64()`. - /// - /// This can be used to generate 2^64 non-overlapping subsequences for - /// parallel computations. - /// - /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128StarStar; - /// - /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); - /// let mut rng2 = rng1.clone(); - /// rng2.jump(); - /// let mut rng3 = rng2.clone(); - /// rng3.jump(); - /// ``` - pub fn jump(&mut self) { - impl_jump!(u64, self, [0xdf900294d8f554a5, 0x170865df4b3201fc]); - } - - /// Jump forward, equivalently to 2^96 calls to `next_u64()`. - /// - /// This can be used to generate 2^32 starting points, from each of which - /// `jump()` will generate 2^32 non-overlapping subsequences for parallel - /// distributed computations. - pub fn long_jump(&mut self) { - impl_jump!(u64, self, [0xd2a98b26625eee7b, 0xdddf9b1090aa7ac1]); - } -} - -impl RngCore for Xoroshiro128StarStar { - #[inline] - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - let r = starstar_u64!(self.s0); - impl_xoroshiro_u64!(self); - r - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for Xoroshiro128StarStar { - type Seed = [u8; 16]; - - /// Create a new `Xoroshiro128StarStar`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - fn from_seed(seed: [u8; 16]) -> Xoroshiro128StarStar { - deal_with_zero_seed!(seed, Self); - let mut s = [0; 2]; - read_u64_into(&seed, &mut s); - - Xoroshiro128StarStar { - s0: s[0], - s1: s[1], - } - } - - /// Seed a `Xoroshiro128StarStar` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoroshiro128StarStar { - from_splitmix!(seed) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoroshiro128StarStar::from_seed( - [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro128starstar.c - let expected = [ - 5760, 97769243520, 9706862127477703552, 9223447511460779954, - 8358291023205304566, 15695619998649302768, 8517900938696309774, - 16586480348202605369, 6959129367028440372, 16822147227405758281, - ]; - for &e in &expected { - assert_eq!(rng.next_u64(), e); - } - } -} diff --git a/rand/rand_xoshiro/src/xoroshiro64star.rs b/rand/rand_xoshiro/src/xoroshiro64star.rs deleted file mode 100644 index 6bb708a..0000000 --- a/rand/rand_xoshiro/src/xoroshiro64star.rs +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core; -use rand_core::le::read_u32_into; -use rand_core::impls::{fill_bytes_via_next, next_u64_via_u32}; -use rand_core::{RngCore, SeedableRng}; - -/// A xoroshiro64* random number generator. -/// -/// The xoroshiro64* algorithm is not suitable for cryptographic purposes, but -/// is very fast and has good statistical properties, besides a low linear -/// complexity in the lowest bits. -/// -/// The algorithm used here is translated from [the `xoroshiro64star.c` -/// reference source code](http://xoshiro.di.unimi.it/xoroshiro64star.c) by -/// David Blackman and Sebastiano Vigna. -#[allow(missing_copy_implementations)] -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoroshiro64Star { - s0: u32, - s1: u32, -} - -impl RngCore for Xoroshiro64Star { - #[inline] - fn next_u32(&mut self) -> u32 { - let r = self.s0.wrapping_mul(0x9E3779BB); - impl_xoroshiro_u32!(self); - r - } - - #[inline] - fn next_u64(&mut self) -> u64 { - next_u64_via_u32(self) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for Xoroshiro64Star { - type Seed = [u8; 8]; - - /// Create a new `Xoroshiro64Star`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - fn from_seed(seed: [u8; 8]) -> Xoroshiro64Star { - deal_with_zero_seed!(seed, Self); - let mut s = [0; 2]; - read_u32_into(&seed, &mut s); - - Xoroshiro64Star { - s0: s[0], - s1: s[1], - } - } - - /// Seed a `Xoroshiro64Star` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoroshiro64Star { - from_splitmix!(seed) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoroshiro64Star::from_seed([1, 0, 0, 0, 2, 0, 0, 0]); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro64star.c - let expected = [ - 2654435771, 327208753, 4063491769, 4259754937, 261922412, 168123673, - 552743735, 1672597395, 1031040050, 2755315674, - ]; - for &e in &expected { - assert_eq!(rng.next_u32(), e); - } - } - - #[test] - fn zero_seed() { - let mut rng = Xoroshiro64Star::seed_from_u64(0); - assert_ne!(rng.next_u64(), 0); - } -} diff --git a/rand/rand_xoshiro/src/xoroshiro64starstar.rs b/rand/rand_xoshiro/src/xoroshiro64starstar.rs deleted file mode 100644 index 8e1aea1..0000000 --- a/rand/rand_xoshiro/src/xoroshiro64starstar.rs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core; -use rand_core::le::read_u32_into; -use rand_core::impls::{fill_bytes_via_next, next_u64_via_u32}; -use rand_core::{RngCore, SeedableRng}; - -/// A xoroshiro64** random number generator. -/// -/// The xoshiro64** algorithm is not suitable for cryptographic purposes, but -/// is very fast and has excellent statistical properties. -/// -/// The algorithm used here is translated from [the `xoroshiro64starstar.c` -/// reference source code](http://xoshiro.di.unimi.it/xoroshiro64starstar.c) by -/// David Blackman and Sebastiano Vigna. -#[allow(missing_copy_implementations)] -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoroshiro64StarStar { - s0: u32, - s1: u32, -} - -impl RngCore for Xoroshiro64StarStar { - #[inline] - fn next_u32(&mut self) -> u32 { - let r = starstar_u32!(self.s0); - impl_xoroshiro_u32!(self); - r - } - - #[inline] - fn next_u64(&mut self) -> u64 { - next_u64_via_u32(self) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for Xoroshiro64StarStar { - type Seed = [u8; 8]; - - /// Create a new `Xoroshiro64StarStar`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - fn from_seed(seed: [u8; 8]) -> Xoroshiro64StarStar { - deal_with_zero_seed!(seed, Self); - let mut s = [0; 2]; - read_u32_into(&seed, &mut s); - - Xoroshiro64StarStar { - s0: s[0], - s1: s[1], - } - } - - /// Seed a `Xoroshiro64StarStar` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoroshiro64StarStar { - from_splitmix!(seed) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoroshiro64StarStar::from_seed([1, 0, 0, 0, 2, 0, 0, 0]); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro64starstar.c - let expected = [ - 3802928447, 813792938, 1618621494, 2955957307, 3252880261, - 1129983909, 2539651700, 1327610908, 1757650787, 2763843748, - ]; - for &e in &expected { - assert_eq!(rng.next_u32(), e); - } - } - - #[test] - fn zero_seed() { - let mut rng = Xoroshiro64StarStar::seed_from_u64(0); - assert_ne!(rng.next_u64(), 0); - } -} diff --git a/rand/rand_xoshiro/src/xoshiro128plus.rs b/rand/rand_xoshiro/src/xoshiro128plus.rs deleted file mode 100644 index 7cbd612..0000000 --- a/rand/rand_xoshiro/src/xoshiro128plus.rs +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::impls::{next_u64_via_u32, fill_bytes_via_next}; -use rand_core::le::read_u32_into; -use rand_core::{SeedableRng, RngCore, Error}; - -/// A xoshiro128+ random number generator. -/// -/// The xoshiro128+ algorithm is not suitable for cryptographic purposes, but -/// is very fast and has good statistical properties, besides a low linear -/// complexity in the lowest bits. -/// -/// The algorithm used here is translated from [the `xoshiro128starstar.c` -/// reference source code](http://xoshiro.di.unimi.it/xoshiro128starstar.c) by -/// David Blackman and Sebastiano Vigna. -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoshiro128Plus { - s: [u32; 4], -} - -impl Xoshiro128Plus { - /// Jump forward, equivalently to 2^64 calls to `next_u32()`. - /// - /// This can be used to generate 2^64 non-overlapping subsequences for - /// parallel computations. - /// - /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128StarStar; - /// - /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); - /// let mut rng2 = rng1.clone(); - /// rng2.jump(); - /// let mut rng3 = rng2.clone(); - /// rng3.jump(); - /// ``` - pub fn jump(&mut self) { - impl_jump!(u32, self, [0x8764000b, 0xf542d2d3, 0x6fa035c3, 0x77f2db5b]); - } -} - -impl SeedableRng for Xoshiro128Plus { - type Seed = [u8; 16]; - - /// Create a new `Xoshiro128Plus`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - #[inline] - fn from_seed(seed: [u8; 16]) -> Xoshiro128Plus { - deal_with_zero_seed!(seed, Self); - let mut state = [0; 4]; - read_u32_into(&seed, &mut state); - Xoshiro128Plus { s: state } - } - - /// Seed a `Xoshiro128Plus` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoshiro128Plus { - from_splitmix!(seed) - } -} - -impl RngCore for Xoshiro128Plus { - #[inline] - fn next_u32(&mut self) -> u32 { - let result_plus = self.s[0].wrapping_add(self.s[3]); - impl_xoshiro_u32!(self); - result_plus - } - - #[inline] - fn next_u64(&mut self) -> u64 { - next_u64_via_u32(self) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoshiro128Plus::from_seed( - [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro128plus.c - let expected = [ - 5, 12295, 25178119, 27286542, 39879690, 1140358681, 3276312097, - 4110231701, 399823256, 2144435200, - ]; - for &e in &expected { - assert_eq!(rng.next_u32(), e); - } - } -} diff --git a/rand/rand_xoshiro/src/xoshiro128starstar.rs b/rand/rand_xoshiro/src/xoshiro128starstar.rs deleted file mode 100644 index 7af1e50..0000000 --- a/rand/rand_xoshiro/src/xoshiro128starstar.rs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::impls::{next_u64_via_u32, fill_bytes_via_next}; -use rand_core::le::read_u32_into; -use rand_core::{SeedableRng, RngCore, Error}; - -/// A xoshiro128** random number generator. -/// -/// The xoshiro128** algorithm is not suitable for cryptographic purposes, but -/// is very fast and has excellent statistical properties. -/// -/// The algorithm used here is translated from [the `xoshiro128starstar.c` -/// reference source code](http://xoshiro.di.unimi.it/xoshiro128starstar.c) by -/// David Blackman and Sebastiano Vigna. -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoshiro128StarStar { - s: [u32; 4], -} - -impl Xoshiro128StarStar { - /// Jump forward, equivalently to 2^64 calls to `next_u32()`. - /// - /// This can be used to generate 2^64 non-overlapping subsequences for - /// parallel computations. - /// - /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoroshiro128StarStar; - /// - /// let rng1 = Xoroshiro128StarStar::seed_from_u64(0); - /// let mut rng2 = rng1.clone(); - /// rng2.jump(); - /// let mut rng3 = rng2.clone(); - /// rng3.jump(); - /// ``` - pub fn jump(&mut self) { - impl_jump!(u32, self, [0x8764000b, 0xf542d2d3, 0x6fa035c3, 0x77f2db5b]); - } -} - -impl SeedableRng for Xoshiro128StarStar { - type Seed = [u8; 16]; - - /// Create a new `Xoshiro128StarStar`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - #[inline] - fn from_seed(seed: [u8; 16]) -> Xoshiro128StarStar { - deal_with_zero_seed!(seed, Self); - let mut state = [0; 4]; - read_u32_into(&seed, &mut state); - Xoshiro128StarStar { s: state } - } - - /// Seed a `Xoshiro128StarStar` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoshiro128StarStar { - from_splitmix!(seed) - } -} - -impl RngCore for Xoshiro128StarStar { - #[inline] - fn next_u32(&mut self) -> u32 { - let result_starstar = starstar_u64!(self.s[0]); - impl_xoshiro_u32!(self); - result_starstar - } - - #[inline] - fn next_u64(&mut self) -> u64 { - next_u64_via_u32(self) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoshiro128StarStar::from_seed( - [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro128starstar.c - let expected = [ - 5760, 40320, 70819200, 3297914139, 2480851620, 1792823698, - 4118739149, 1251203317, 1581886583, 1721184582, - ]; - for &e in &expected { - assert_eq!(rng.next_u32(), e); - } - } -} diff --git a/rand/rand_xoshiro/src/xoshiro256plus.rs b/rand/rand_xoshiro/src/xoshiro256plus.rs deleted file mode 100644 index 396f588..0000000 --- a/rand/rand_xoshiro/src/xoshiro256plus.rs +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::impls::fill_bytes_via_next; -use rand_core::le::read_u64_into; -use rand_core::{SeedableRng, RngCore, Error}; - -/// A xoshiro256+ random number generator. -/// -/// The xoshiro256+ algorithm is not suitable for cryptographic purposes, but -/// is very fast and has good statistical properties, besides a low linear -/// complexity in the lowest bits. -/// -/// The algorithm used here is translated from [the `xoshiro256plus.c` -/// reference source code](http://xoshiro.di.unimi.it/xoshiro256plus.c) by -/// David Blackman and Sebastiano Vigna. -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoshiro256Plus { - s: [u64; 4], -} - -impl Xoshiro256Plus { - /// Jump forward, equivalently to 2^128 calls to `next_u64()`. - /// - /// This can be used to generate 2^128 non-overlapping subsequences for - /// parallel computations. - /// - /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro256Plus; - /// - /// let rng1 = Xoshiro256Plus::seed_from_u64(0); - /// let mut rng2 = rng1.clone(); - /// rng2.jump(); - /// let mut rng3 = rng2.clone(); - /// rng3.jump(); - /// ``` - pub fn jump(&mut self) { - impl_jump!(u64, self, [ - 0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, - 0xa9582618e03fc9aa, 0x39abdc4529b1661c - ]); - } - - /// Jump forward, equivalently to 2^192 calls to `next_u64()`. - /// - /// This can be used to generate 2^64 starting points, from each of which - /// `jump()` will generate 2^64 non-overlapping subsequences for parallel - /// distributed computations. - pub fn long_jump(&mut self) { - impl_jump!(u64, self, [ - 0x76e15d3efefdcbbf, 0xc5004e441c522fb3, - 0x77710069854ee241, 0x39109bb02acbe635 - ]); - } -} - -impl SeedableRng for Xoshiro256Plus { - type Seed = [u8; 32]; - - /// Create a new `Xoshiro256Plus`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - #[inline] - fn from_seed(seed: [u8; 32]) -> Xoshiro256Plus { - deal_with_zero_seed!(seed, Self); - let mut state = [0; 4]; - read_u64_into(&seed, &mut state); - Xoshiro256Plus { s: state } - } - - /// Seed a `Xoshiro256Plus` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoshiro256Plus { - from_splitmix!(seed) - } -} - -impl RngCore for Xoshiro256Plus { - #[inline] - fn next_u32(&mut self) -> u32 { - // The lowest bits have some linear dependencies, so we use the - // upper bits instead. - (self.next_u64() >> 32) as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - let result_plus = self.s[0].wrapping_add(self.s[3]); - impl_xoshiro_u64!(self); - result_plus - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoshiro256Plus::from_seed( - [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0]); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro256plus.c - let expected = [ - 5, 211106232532999, 211106635186183, 9223759065350669058, - 9250833439874351877, 13862484359527728515, 2346507365006083650, - 1168864526675804870, 34095955243042024, 3466914240207415127, - ]; - for &e in &expected { - assert_eq!(rng.next_u64(), e); - } - } -} diff --git a/rand/rand_xoshiro/src/xoshiro256starstar.rs b/rand/rand_xoshiro/src/xoshiro256starstar.rs deleted file mode 100644 index 2cc2029..0000000 --- a/rand/rand_xoshiro/src/xoshiro256starstar.rs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::impls::fill_bytes_via_next; -use rand_core::le::read_u64_into; -use rand_core::{SeedableRng, RngCore, Error}; - -/// A xoshiro256** random number generator. -/// -/// The xoshiro256** algorithm is not suitable for cryptographic purposes, but -/// is very fast and has excellent statistical properties. -/// -/// The algorithm used here is translated from [the `xoshiro256starstar.c` -/// reference source code](http://xoshiro.di.unimi.it/xoshiro256starstar.c) by -/// David Blackman and Sebastiano Vigna. -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoshiro256StarStar { - s: [u64; 4], -} - -impl Xoshiro256StarStar { - /// Jump forward, equivalently to 2^128 calls to `next_u64()`. - /// - /// This can be used to generate 2^128 non-overlapping subsequences for - /// parallel computations. - /// - /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro256StarStar; - /// - /// let rng1 = Xoshiro256StarStar::seed_from_u64(0); - /// let mut rng2 = rng1.clone(); - /// rng2.jump(); - /// let mut rng3 = rng2.clone(); - /// rng3.jump(); - /// ``` - pub fn jump(&mut self) { - impl_jump!(u64, self, [ - 0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, - 0xa9582618e03fc9aa, 0x39abdc4529b1661c - ]); - } - - /// Jump forward, equivalently to 2^192 calls to `next_u64()`. - /// - /// This can be used to generate 2^64 starting points, from each of which - /// `jump()` will generate 2^64 non-overlapping subsequences for parallel - /// distributed computations. - pub fn long_jump(&mut self) { - impl_jump!(u64, self, [ - 0x76e15d3efefdcbbf, 0xc5004e441c522fb3, - 0x77710069854ee241, 0x39109bb02acbe635 - ]); - } -} - -impl SeedableRng for Xoshiro256StarStar { - type Seed = [u8; 32]; - - /// Create a new `Xoshiro256StarStar`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - #[inline] - fn from_seed(seed: [u8; 32]) -> Xoshiro256StarStar { - deal_with_zero_seed!(seed, Self); - let mut state = [0; 4]; - read_u64_into(&seed, &mut state); - Xoshiro256StarStar { s: state } - } - - /// Seed a `Xoshiro256StarStar` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoshiro256StarStar { - from_splitmix!(seed) - } -} - -impl RngCore for Xoshiro256StarStar { - #[inline] - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - let result_starstar = starstar_u64!(self.s[1]); - impl_xoshiro_u64!(self); - result_starstar - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoshiro256StarStar::from_seed( - [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0]); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro128starstar.c - let expected = [ - 11520, 0, 1509978240, 1215971899390074240, 1216172134540287360, - 607988272756665600, 16172922978634559625, 8476171486693032832, - 10595114339597558777, 2904607092377533576, - ]; - for &e in &expected { - assert_eq!(rng.next_u64(), e); - } - } -} diff --git a/rand/rand_xoshiro/src/xoshiro512plus.rs b/rand/rand_xoshiro/src/xoshiro512plus.rs deleted file mode 100644 index 4b589f2..0000000 --- a/rand/rand_xoshiro/src/xoshiro512plus.rs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::impls::fill_bytes_via_next; -use rand_core::le::read_u64_into; -use rand_core::{SeedableRng, RngCore, Error}; - -use crate::Seed512; - -/// A xoshiro512+ random number generator. -/// -/// The xoshiro512+ algorithm is not suitable for cryptographic purposes, but -/// is very fast and has good statistical properties, besides a low linear -/// complexity in the lowest bits. -/// -/// The algorithm used here is translated from [the `xoshiro512plus.c` -/// reference source code](http://xoshiro.di.unimi.it/xoshiro512plus.c) by -/// David Blackman and Sebastiano Vigna. -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoshiro512Plus { - s: [u64; 8], -} - -impl Xoshiro512Plus { - /// Jump forward, equivalently to 2^256 calls to `next_u64()`. - /// - /// This can be used to generate 2^256 non-overlapping subsequences for - /// parallel computations. - /// - /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro512Plus; - /// - /// let rng1 = Xoshiro512Plus::seed_from_u64(0); - /// let mut rng2 = rng1.clone(); - /// rng2.jump(); - /// let mut rng3 = rng2.clone(); - /// rng3.jump(); - /// ``` - pub fn jump(&mut self) { - impl_jump!(u64, self, [ - 0x33ed89b6e7a353f9, 0x760083d7955323be, 0x2837f2fbb5f22fae, - 0x4b8c5674d309511c, 0xb11ac47a7ba28c25, 0xf1be7667092bcc1c, - 0x53851efdb6df0aaf, 0x1ebbc8b23eaf25db - ]); - } -} - -impl SeedableRng for Xoshiro512Plus { - type Seed = Seed512; - - /// Create a new `Xoshiro512Plus`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - #[inline] - fn from_seed(seed: Seed512) -> Xoshiro512Plus { - deal_with_zero_seed!(seed, Self); - let mut state = [0; 8]; - read_u64_into(&seed.0, &mut state); - Xoshiro512Plus { s: state } - } - - /// Seed a `Xoshiro512Plus` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoshiro512Plus { - from_splitmix!(seed) - } -} - -impl RngCore for Xoshiro512Plus { - #[inline] - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - let result_plus = self.s[0].wrapping_add(self.s[2]); - impl_xoshiro_large!(self); - result_plus - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoshiro512Plus::from_seed(Seed512( - [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, - 7, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0])); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro512plus.c - let expected = [ - 4, 8, 4113, 25169936, 52776585412635, 57174648719367, - 9223482039571869716, 9331471677901559830, 9340533895746033672, - 14078399799840753678, - ]; - for &e in &expected { - assert_eq!(rng.next_u64(), e); - } - } -} diff --git a/rand/rand_xoshiro/src/xoshiro512starstar.rs b/rand/rand_xoshiro/src/xoshiro512starstar.rs deleted file mode 100644 index 2db9ac1..0000000 --- a/rand/rand_xoshiro/src/xoshiro512starstar.rs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; -use rand_core::impls::fill_bytes_via_next; -use rand_core::le::read_u64_into; -use rand_core::{SeedableRng, RngCore, Error}; - -use crate::Seed512; - -/// A xoshiro512** random number generator. -/// -/// The xoshiro512** algorithm is not suitable for cryptographic purposes, but -/// is very fast and has excellent statistical properties. -/// -/// The algorithm used here is translated from [the `xoshiro512starstar.c` -/// reference source code](http://xoshiro.di.unimi.it/xoshiro512starstar.c) by -/// David Blackman and Sebastiano Vigna. -#[derive(Debug, Clone)] -#[cfg_attr(feature="serde1", derive(Serialize, Deserialize))] -pub struct Xoshiro512StarStar { - s: [u64; 8], -} - -impl Xoshiro512StarStar { - /// Jump forward, equivalently to 2^256 calls to `next_u64()`. - /// - /// This can be used to generate 2^256 non-overlapping subsequences for - /// parallel computations. - /// - /// ``` - /// use rand_xoshiro::rand_core::SeedableRng; - /// use rand_xoshiro::Xoshiro512StarStar; - /// - /// let rng1 = Xoshiro512StarStar::seed_from_u64(0); - /// let mut rng2 = rng1.clone(); - /// rng2.jump(); - /// let mut rng3 = rng2.clone(); - /// rng3.jump(); - /// ``` - pub fn jump(&mut self) { - impl_jump!(u64, self, [ - 0x33ed89b6e7a353f9, 0x760083d7955323be, 0x2837f2fbb5f22fae, - 0x4b8c5674d309511c, 0xb11ac47a7ba28c25, 0xf1be7667092bcc1c, - 0x53851efdb6df0aaf, 0x1ebbc8b23eaf25db - ]); - } -} - - -impl SeedableRng for Xoshiro512StarStar { - type Seed = Seed512; - - /// Create a new `Xoshiro512StarStar`. If `seed` is entirely 0, it will be - /// mapped to a different seed. - #[inline] - fn from_seed(seed: Seed512) -> Xoshiro512StarStar { - deal_with_zero_seed!(seed, Self); - let mut state = [0; 8]; - read_u64_into(&seed.0, &mut state); - Xoshiro512StarStar { s: state } - } - - /// Seed a `Xoshiro512StarStar` from a `u64` using `SplitMix64`. - fn seed_from_u64(seed: u64) -> Xoshiro512StarStar { - from_splitmix!(seed) - } -} - -impl RngCore for Xoshiro512StarStar { - #[inline] - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - let result_starstar = starstar_u64!(self.s[1]); - impl_xoshiro_large!(self); - result_starstar - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn reference() { - let mut rng = Xoshiro512StarStar::from_seed(Seed512( - [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, - 7, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0])); - // These values were produced with the reference implementation: - // http://xoshiro.di.unimi.it/xoshiro512starstar.c - let expected = [ - 11520, 0, 23040, 23667840, 144955163520, 303992986974289920, - 25332796375735680, 296904390158016, 13911081092387501979, - 15304787717237593024, - ]; - for &e in &expected { - assert_eq!(rng.next_u64(), e); - } - } -} diff --git a/rand/rand_xoshiro/tests/serde.rs b/rand/rand_xoshiro/tests/serde.rs deleted file mode 100644 index ee23a1d..0000000 --- a/rand/rand_xoshiro/tests/serde.rs +++ /dev/null @@ -1,83 +0,0 @@ -#![cfg(feature="serde1")] - -use rand_core::{RngCore, SeedableRng}; -use rand_xoshiro::{SplitMix64, Xoroshiro64StarStar, Xoroshiro64Star, - Xoroshiro128Plus, Xoroshiro128StarStar, Xoshiro128StarStar, Xoshiro128Plus, - Xoshiro256StarStar, Xoshiro256Plus, Xoshiro512StarStar, Xoshiro512Plus}; - -macro_rules! serde_rng { - ($rng:ident) => { - use bincode; - use std::io::{BufWriter, BufReader}; - - let mut rng = $rng::seed_from_u64(0); - - let buf: Vec = Vec::new(); - let mut buf = BufWriter::new(buf); - bincode::serialize_into(&mut buf, &rng).expect("Could not serialize"); - - let buf = buf.into_inner().unwrap(); - let mut read = BufReader::new(&buf[..]); - let mut deserialized: $rng = bincode::deserialize_from(&mut read) - .expect("Could not deserialize"); - - for _ in 0..16 { - assert_eq!(rng.next_u64(), deserialized.next_u64()); - } - } -} - -#[test] -fn test_splitmix64() { - serde_rng!(SplitMix64); -} - -#[test] -fn test_xoroshiro64starstar() { - serde_rng!(Xoroshiro64StarStar); -} - -#[test] -fn test_xoroshiro64star() { - serde_rng!(Xoroshiro64Star); -} - -#[test] -fn test_xoroshiro128plus() { - serde_rng!(Xoroshiro128Plus); -} - -#[test] -fn test_xoroshiro128starstar() { - serde_rng!(Xoroshiro128StarStar); -} - -#[test] -fn test_xoshiro128starstar() { - serde_rng!(Xoshiro128StarStar); -} - -#[test] -fn test_xoshiro128plus() { - serde_rng!(Xoshiro128Plus); -} - -#[test] -fn test_xoshiro256starstar() { - serde_rng!(Xoshiro256StarStar); -} - -#[test] -fn test_xoshiro256plus() { - serde_rng!(Xoshiro256Plus); -} - -#[test] -fn test_xoshiro512starstar() { - serde_rng!(Xoshiro512StarStar); -} - -#[test] -fn test_xoshiro512plus() { - serde_rng!(Xoshiro512Plus); -} diff --git a/rand/rustfmt.toml b/rand/rustfmt.toml deleted file mode 100644 index 6b2aba3..0000000 --- a/rand/rustfmt.toml +++ /dev/null @@ -1,30 +0,0 @@ -# This rustfmt file is added for configuration, but in practice much of our -# code is hand-formatted, frequently with more readable results. - -# Comments: -normalize_comments = true -wrap_comments = false -format_doc_comments = true -comment_width = 90 # small excess is okay but prefer 80 - -# Arguments: -use_small_heuristics = "max" -fn_args_density = "compressed" -fn_single_line = false -overflow_delimited_expr = true -where_single_line = true - -# enum_discrim_align_threshold = 20 -# struct_field_align_threshold = 20 - -# Compatibility: -edition = "2018" # we require compatibility back to 1.32.0 - -# Misc: -blank_lines_upper_bound = 2 -reorder_impl_items = true -# report_todo = "Unnumbered" -# report_fixme = "Unnumbered" - -# Ignored files: -ignore = [] diff --git a/rand/src/distributions/bernoulli.rs b/rand/src/distributions/bernoulli.rs deleted file mode 100644 index eadd056..0000000 --- a/rand/src/distributions/bernoulli.rs +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Bernoulli distribution. - -use crate::Rng; -use crate::distributions::Distribution; - -/// The Bernoulli distribution. -/// -/// This is a special case of the Binomial distribution where `n = 1`. -/// -/// # Example -/// -/// ```rust -/// use rand::distributions::{Bernoulli, Distribution}; -/// -/// let d = Bernoulli::new(0.3).unwrap(); -/// let v = d.sample(&mut rand::thread_rng()); -/// println!("{} is from a Bernoulli distribution", v); -/// ``` -/// -/// # Precision -/// -/// This `Bernoulli` distribution uses 64 bits from the RNG (a `u64`), -/// so only probabilities that are multiples of 2-64 can be -/// represented. -#[derive(Clone, Copy, Debug)] -pub struct Bernoulli { - /// Probability of success, relative to the maximal integer. - p_int: u64, -} - -// To sample from the Bernoulli distribution we use a method that compares a -// random `u64` value `v < (p * 2^64)`. -// -// If `p == 1.0`, the integer `v` to compare against can not represented as a -// `u64`. We manually set it to `u64::MAX` instead (2^64 - 1 instead of 2^64). -// Note that value of `p < 1.0` can never result in `u64::MAX`, because an -// `f64` only has 53 bits of precision, and the next largest value of `p` will -// result in `2^64 - 2048`. -// -// Also there is a 100% theoretical concern: if someone consistenly wants to -// generate `true` using the Bernoulli distribution (i.e. by using a probability -// of `1.0`), just using `u64::MAX` is not enough. On average it would return -// false once every 2^64 iterations. Some people apparently care about this -// case. -// -// That is why we special-case `u64::MAX` to always return `true`, without using -// the RNG, and pay the performance price for all uses that *are* reasonable. -// Luckily, if `new()` and `sample` are close, the compiler can optimize out the -// extra check. -const ALWAYS_TRUE: u64 = ::core::u64::MAX; - -// This is just `2.0.powi(64)`, but written this way because it is not available -// in `no_std` mode. -const SCALE: f64 = 2.0 * (1u64 << 63) as f64; - -/// Error type returned from `Bernoulli::new`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum BernoulliError { - /// `p < 0` or `p > 1`. - InvalidProbability, -} - -impl Bernoulli { - /// Construct a new `Bernoulli` with the given probability of success `p`. - /// - /// # Precision - /// - /// For `p = 1.0`, the resulting distribution will always generate true. - /// For `p = 0.0`, the resulting distribution will always generate false. - /// - /// This method is accurate for any input `p` in the range `[0, 1]` which is - /// a multiple of 2-64. (Note that not all multiples of - /// 2-64 in `[0, 1]` can be represented as a `f64`.) - #[inline] - pub fn new(p: f64) -> Result { - if p < 0.0 || p >= 1.0 { - if p == 1.0 { return Ok(Bernoulli { p_int: ALWAYS_TRUE }) } - return Err(BernoulliError::InvalidProbability); - } - Ok(Bernoulli { p_int: (p * SCALE) as u64 }) - } - - /// Construct a new `Bernoulli` with the probability of success of - /// `numerator`-in-`denominator`. I.e. `new_ratio(2, 3)` will return - /// a `Bernoulli` with a 2-in-3 chance, or about 67%, of returning `true`. - /// - /// If `numerator == denominator` then the returned `Bernoulli` will always - /// return `true`. If `numerator == 0` it will always return `false`. - #[inline] - pub fn from_ratio(numerator: u32, denominator: u32) -> Result { - if numerator > denominator { - return Err(BernoulliError::InvalidProbability); - } - if numerator == denominator { - return Ok(Bernoulli { p_int: ALWAYS_TRUE }) - } - let p_int = ((f64::from(numerator) / f64::from(denominator)) * SCALE) as u64; - Ok(Bernoulli { p_int }) - } -} - -impl Distribution for Bernoulli { - #[inline] - fn sample(&self, rng: &mut R) -> bool { - // Make sure to always return true for p = 1.0. - if self.p_int == ALWAYS_TRUE { return true; } - let v: u64 = rng.gen(); - v < self.p_int - } -} - -#[cfg(test)] -mod test { - use crate::Rng; - use crate::distributions::Distribution; - use super::Bernoulli; - - #[test] - fn test_trivial() { - let mut r = crate::test::rng(1); - let always_false = Bernoulli::new(0.0).unwrap(); - let always_true = Bernoulli::new(1.0).unwrap(); - for _ in 0..5 { - assert_eq!(r.sample::(&always_false), false); - assert_eq!(r.sample::(&always_true), true); - assert_eq!(Distribution::::sample(&always_false, &mut r), false); - assert_eq!(Distribution::::sample(&always_true, &mut r), true); - } - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_average() { - const P: f64 = 0.3; - const NUM: u32 = 3; - const DENOM: u32 = 10; - let d1 = Bernoulli::new(P).unwrap(); - let d2 = Bernoulli::from_ratio(NUM, DENOM).unwrap(); - const N: u32 = 100_000; - - let mut sum1: u32 = 0; - let mut sum2: u32 = 0; - let mut rng = crate::test::rng(2); - for _ in 0..N { - if d1.sample(&mut rng) { - sum1 += 1; - } - if d2.sample(&mut rng) { - sum2 += 1; - } - } - let avg1 = (sum1 as f64) / (N as f64); - assert!((avg1 - P).abs() < 5e-3); - - let avg2 = (sum2 as f64) / (N as f64); - assert!((avg2 - (NUM as f64)/(DENOM as f64)).abs() < 5e-3); - } -} diff --git a/rand/src/distributions/binomial.rs b/rand/src/distributions/binomial.rs deleted file mode 100644 index 8fc290a..0000000 --- a/rand/src/distributions/binomial.rs +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2016-2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The binomial distribution. -#![allow(deprecated)] -#![allow(clippy::all)] - -use crate::Rng; -use crate::distributions::{Distribution, Uniform}; - -/// The binomial distribution `Binomial(n, p)`. -/// -/// This distribution has density function: -/// `f(k) = n!/(k! (n-k)!) p^k (1-p)^(n-k)` for `k >= 0`. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Binomial { - /// Number of trials. - n: u64, - /// Probability of success. - p: f64, -} - -impl Binomial { - /// Construct a new `Binomial` with the given shape parameters `n` (number - /// of trials) and `p` (probability of success). - /// - /// Panics if `p < 0` or `p > 1`. - pub fn new(n: u64, p: f64) -> Binomial { - assert!(p >= 0.0, "Binomial::new called with p < 0"); - assert!(p <= 1.0, "Binomial::new called with p > 1"); - Binomial { n, p } - } -} - -/// Convert a `f64` to an `i64`, panicing on overflow. -// In the future (Rust 1.34), this might be replaced with `TryFrom`. -fn f64_to_i64(x: f64) -> i64 { - assert!(x < (::std::i64::MAX as f64)); - x as i64 -} - -impl Distribution for Binomial { - fn sample(&self, rng: &mut R) -> u64 { - // Handle these values directly. - if self.p == 0.0 { - return 0; - } else if self.p == 1.0 { - return self.n; - } - - // The binomial distribution is symmetrical with respect to p -> 1-p, - // k -> n-k switch p so that it is less than 0.5 - this allows for lower - // expected values we will just invert the result at the end - let p = if self.p <= 0.5 { - self.p - } else { - 1.0 - self.p - }; - - let result; - let q = 1. - p; - - // For small n * min(p, 1 - p), the BINV algorithm based on the inverse - // transformation of the binomial distribution is efficient. Otherwise, - // the BTPE algorithm is used. - // - // Voratas Kachitvichyanukul and Bruce W. Schmeiser. 1988. Binomial - // random variate generation. Commun. ACM 31, 2 (February 1988), - // 216-222. http://dx.doi.org/10.1145/42372.42381 - - // Threshold for prefering the BINV algorithm. The paper suggests 10, - // Ranlib uses 30, and GSL uses 14. - const BINV_THRESHOLD: f64 = 10.; - - if (self.n as f64) * p < BINV_THRESHOLD && - self.n <= (::std::i32::MAX as u64) { - // Use the BINV algorithm. - let s = p / q; - let a = ((self.n + 1) as f64) * s; - let mut r = q.powi(self.n as i32); - let mut u: f64 = rng.gen(); - let mut x = 0; - while u > r as f64 { - u -= r; - x += 1; - r *= a / (x as f64) - s; - } - result = x; - } else { - // Use the BTPE algorithm. - - // Threshold for using the squeeze algorithm. This can be freely - // chosen based on performance. Ranlib and GSL use 20. - const SQUEEZE_THRESHOLD: i64 = 20; - - // Step 0: Calculate constants as functions of `n` and `p`. - let n = self.n as f64; - let np = n * p; - let npq = np * q; - let f_m = np + p; - let m = f64_to_i64(f_m); - // radius of triangle region, since height=1 also area of region - let p1 = (2.195 * npq.sqrt() - 4.6 * q).floor() + 0.5; - // tip of triangle - let x_m = (m as f64) + 0.5; - // left edge of triangle - let x_l = x_m - p1; - // right edge of triangle - let x_r = x_m + p1; - let c = 0.134 + 20.5 / (15.3 + (m as f64)); - // p1 + area of parallelogram region - let p2 = p1 * (1. + 2. * c); - - fn lambda(a: f64) -> f64 { - a * (1. + 0.5 * a) - } - - let lambda_l = lambda((f_m - x_l) / (f_m - x_l * p)); - let lambda_r = lambda((x_r - f_m) / (x_r * q)); - // p1 + area of left tail - let p3 = p2 + c / lambda_l; - // p1 + area of right tail - let p4 = p3 + c / lambda_r; - - // return value - let mut y: i64; - - let gen_u = Uniform::new(0., p4); - let gen_v = Uniform::new(0., 1.); - - loop { - // Step 1: Generate `u` for selecting the region. If region 1 is - // selected, generate a triangularly distributed variate. - let u = gen_u.sample(rng); - let mut v = gen_v.sample(rng); - if !(u > p1) { - y = f64_to_i64(x_m - p1 * v + u); - break; - } - - if !(u > p2) { - // Step 2: Region 2, parallelograms. Check if region 2 is - // used. If so, generate `y`. - let x = x_l + (u - p1) / c; - v = v * c + 1.0 - (x - x_m).abs() / p1; - if v > 1. { - continue; - } else { - y = f64_to_i64(x); - } - } else if !(u > p3) { - // Step 3: Region 3, left exponential tail. - y = f64_to_i64(x_l + v.ln() / lambda_l); - if y < 0 { - continue; - } else { - v *= (u - p2) * lambda_l; - } - } else { - // Step 4: Region 4, right exponential tail. - y = f64_to_i64(x_r - v.ln() / lambda_r); - if y > 0 && (y as u64) > self.n { - continue; - } else { - v *= (u - p3) * lambda_r; - } - } - - // Step 5: Acceptance/rejection comparison. - - // Step 5.0: Test for appropriate method of evaluating f(y). - let k = (y - m).abs(); - if !(k > SQUEEZE_THRESHOLD && (k as f64) < 0.5 * npq - 1.) { - // Step 5.1: Evaluate f(y) via the recursive relationship. Start the - // search from the mode. - let s = p / q; - let a = s * (n + 1.); - let mut f = 1.0; - if m < y { - let mut i = m; - loop { - i += 1; - f *= a / (i as f64) - s; - if i == y { - break; - } - } - } else if m > y { - let mut i = y; - loop { - i += 1; - f /= a / (i as f64) - s; - if i == m { - break; - } - } - } - if v > f { - continue; - } else { - break; - } - } - - // Step 5.2: Squeezing. Check the value of ln(v) againts upper and - // lower bound of ln(f(y)). - let k = k as f64; - let rho = (k / npq) * ((k * (k / 3. + 0.625) + 1./6.) / npq + 0.5); - let t = -0.5 * k*k / npq; - let alpha = v.ln(); - if alpha < t - rho { - break; - } - if alpha > t + rho { - continue; - } - - // Step 5.3: Final acceptance/rejection test. - let x1 = (y + 1) as f64; - let f1 = (m + 1) as f64; - let z = (f64_to_i64(n) + 1 - m) as f64; - let w = (f64_to_i64(n) - y + 1) as f64; - - fn stirling(a: f64) -> f64 { - let a2 = a * a; - (13860. - (462. - (132. - (99. - 140. / a2) / a2) / a2) / a2) / a / 166320. - } - - if alpha > x_m * (f1 / x1).ln() - + (n - (m as f64) + 0.5) * (z / w).ln() - + ((y - m) as f64) * (w * p / (x1 * q)).ln() - // We use the signs from the GSL implementation, which are - // different than the ones in the reference. According to - // the GSL authors, the new signs were verified to be - // correct by one of the original designers of the - // algorithm. - + stirling(f1) + stirling(z) - stirling(x1) - stirling(w) - { - continue; - } - - break; - } - assert!(y >= 0); - result = y as u64; - } - - // Invert the result for p < 0.5. - if p != self.p { - self.n - result - } else { - result - } - } -} - -#[cfg(test)] -mod test { - use crate::Rng; - use crate::distributions::Distribution; - use super::Binomial; - - fn test_binomial_mean_and_variance(n: u64, p: f64, rng: &mut R) { - let binomial = Binomial::new(n, p); - - let expected_mean = n as f64 * p; - let expected_variance = n as f64 * p * (1.0 - p); - - let mut results = [0.0; 1000]; - for i in results.iter_mut() { *i = binomial.sample(rng) as f64; } - - let mean = results.iter().sum::() / results.len() as f64; - assert!((mean as f64 - expected_mean).abs() < expected_mean / 50.0, - "mean: {}, expected_mean: {}", mean, expected_mean); - - let variance = - results.iter().map(|x| (x - mean) * (x - mean)).sum::() - / results.len() as f64; - assert!((variance - expected_variance).abs() < expected_variance / 10.0, - "variance: {}, expected_variance: {}", variance, expected_variance); - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_binomial() { - let mut rng = crate::test::rng(351); - test_binomial_mean_and_variance(150, 0.1, &mut rng); - test_binomial_mean_and_variance(70, 0.6, &mut rng); - test_binomial_mean_and_variance(40, 0.5, &mut rng); - test_binomial_mean_and_variance(20, 0.7, &mut rng); - test_binomial_mean_and_variance(20, 0.5, &mut rng); - } - - #[test] - fn test_binomial_end_points() { - let mut rng = crate::test::rng(352); - assert_eq!(rng.sample(Binomial::new(20, 0.0)), 0); - assert_eq!(rng.sample(Binomial::new(20, 1.0)), 20); - } - - #[test] - #[should_panic] - fn test_binomial_invalid_lambda_neg() { - Binomial::new(20, -10.0); - } -} diff --git a/rand/src/distributions/cauchy.rs b/rand/src/distributions/cauchy.rs deleted file mode 100644 index 0a5d149..0000000 --- a/rand/src/distributions/cauchy.rs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2016-2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Cauchy distribution. -#![allow(deprecated)] -#![allow(clippy::all)] - -use crate::Rng; -use crate::distributions::Distribution; -use std::f64::consts::PI; - -/// The Cauchy distribution `Cauchy(median, scale)`. -/// -/// This distribution has a density function: -/// `f(x) = 1 / (pi * scale * (1 + ((x - median) / scale)^2))` -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Cauchy { - median: f64, - scale: f64 -} - -impl Cauchy { - /// Construct a new `Cauchy` with the given shape parameters - /// `median` the peak location and `scale` the scale factor. - /// Panics if `scale <= 0`. - pub fn new(median: f64, scale: f64) -> Cauchy { - assert!(scale > 0.0, "Cauchy::new called with scale factor <= 0"); - Cauchy { - median, - scale - } - } -} - -impl Distribution for Cauchy { - fn sample(&self, rng: &mut R) -> f64 { - // sample from [0, 1) - let x = rng.gen::(); - // get standard cauchy random number - // note that π/2 is not exactly representable, even if x=0.5 the result is finite - let comp_dev = (PI * x).tan(); - // shift and scale according to parameters - let result = self.median + self.scale * comp_dev; - result - } -} - -#[cfg(test)] -mod test { - use crate::distributions::Distribution; - use super::Cauchy; - - fn median(mut numbers: &mut [f64]) -> f64 { - sort(&mut numbers); - let mid = numbers.len() / 2; - numbers[mid] - } - - fn sort(numbers: &mut [f64]) { - numbers.sort_by(|a, b| a.partial_cmp(b).unwrap()); - } - - #[test] - #[cfg(not(miri))] // Miri doesn't support transcendental functions - fn test_cauchy_averages() { - // NOTE: given that the variance and mean are undefined, - // this test does not have any rigorous statistical meaning. - let cauchy = Cauchy::new(10.0, 5.0); - let mut rng = crate::test::rng(123); - let mut numbers: [f64; 1000] = [0.0; 1000]; - let mut sum = 0.0; - for i in 0..1000 { - numbers[i] = cauchy.sample(&mut rng); - sum += numbers[i]; - } - let median = median(&mut numbers); - println!("Cauchy median: {}", median); - assert!((median - 10.0).abs() < 0.4); // not 100% certain, but probable enough - let mean = sum / 1000.0; - println!("Cauchy mean: {}", mean); - // for a Cauchy distribution the mean should not converge - assert!((mean - 10.0).abs() > 0.4); // not 100% certain, but probable enough - } - - #[test] - #[should_panic] - fn test_cauchy_invalid_scale_zero() { - Cauchy::new(0.0, 0.0); - } - - #[test] - #[should_panic] - fn test_cauchy_invalid_scale_neg() { - Cauchy::new(0.0, -10.0); - } -} diff --git a/rand/src/distributions/dirichlet.rs b/rand/src/distributions/dirichlet.rs deleted file mode 100644 index 1ce01fd..0000000 --- a/rand/src/distributions/dirichlet.rs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The dirichlet distribution. -#![allow(deprecated)] -#![allow(clippy::all)] - -use crate::Rng; -use crate::distributions::Distribution; -use crate::distributions::gamma::Gamma; - -/// The dirichelet distribution `Dirichlet(alpha)`. -/// -/// The Dirichlet distribution is a family of continuous multivariate -/// probability distributions parameterized by a vector alpha of positive reals. -/// It is a multivariate generalization of the beta distribution. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Debug)] -pub struct Dirichlet { - /// Concentration parameters (alpha) - alpha: Vec, -} - -impl Dirichlet { - /// Construct a new `Dirichlet` with the given alpha parameter `alpha`. - /// - /// # Panics - /// - if `alpha.len() < 2` - /// - #[inline] - pub fn new>>(alpha: V) -> Dirichlet { - let a = alpha.into(); - assert!(a.len() > 1); - for i in 0..a.len() { - assert!(a[i] > 0.0); - } - - Dirichlet { alpha: a } - } - - /// Construct a new `Dirichlet` with the given shape parameter `alpha` and `size`. - /// - /// # Panics - /// - if `alpha <= 0.0` - /// - if `size < 2` - /// - #[inline] - pub fn new_with_param(alpha: f64, size: usize) -> Dirichlet { - assert!(alpha > 0.0); - assert!(size > 1); - Dirichlet { - alpha: vec![alpha; size], - } - } -} - -impl Distribution> for Dirichlet { - fn sample(&self, rng: &mut R) -> Vec { - let n = self.alpha.len(); - let mut samples = vec![0.0f64; n]; - let mut sum = 0.0f64; - - for i in 0..n { - let g = Gamma::new(self.alpha[i], 1.0); - samples[i] = g.sample(rng); - sum += samples[i]; - } - let invacc = 1.0 / sum; - for i in 0..n { - samples[i] *= invacc; - } - samples - } -} - -#[cfg(test)] -mod test { - use super::Dirichlet; - use crate::distributions::Distribution; - - #[test] - fn test_dirichlet() { - let d = Dirichlet::new(vec![1.0, 2.0, 3.0]); - let mut rng = crate::test::rng(221); - let samples = d.sample(&mut rng); - let _: Vec = samples - .into_iter() - .map(|x| { - assert!(x > 0.0); - x - }) - .collect(); - } - - #[test] - fn test_dirichlet_with_param() { - let alpha = 0.5f64; - let size = 2; - let d = Dirichlet::new_with_param(alpha, size); - let mut rng = crate::test::rng(221); - let samples = d.sample(&mut rng); - let _: Vec = samples - .into_iter() - .map(|x| { - assert!(x > 0.0); - x - }) - .collect(); - } - - #[test] - #[should_panic] - fn test_dirichlet_invalid_length() { - Dirichlet::new_with_param(0.5f64, 1); - } - - #[test] - #[should_panic] - fn test_dirichlet_invalid_alpha() { - Dirichlet::new_with_param(0.0f64, 2); - } -} diff --git a/rand/src/distributions/exponential.rs b/rand/src/distributions/exponential.rs deleted file mode 100644 index 0278248..0000000 --- a/rand/src/distributions/exponential.rs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The exponential distribution. -#![allow(deprecated)] - -use crate::{Rng}; -use crate::distributions::{ziggurat_tables, Distribution}; -use crate::distributions::utils::ziggurat; - -/// Samples floating-point numbers according to the exponential distribution, -/// with rate parameter `λ = 1`. This is equivalent to `Exp::new(1.0)` or -/// sampling with `-rng.gen::().ln()`, but faster. -/// -/// See `Exp` for the general exponential distribution. -/// -/// Implemented via the ZIGNOR variant[^1] of the Ziggurat method. The exact -/// description in the paper was adjusted to use tables for the exponential -/// distribution rather than normal. -/// -/// [^1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to -/// Generate Normal Random Samples*]( -/// https://www.doornik.com/research/ziggurat.pdf). -/// Nuffield College, Oxford -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Exp1; - -// This could be done via `-rng.gen::().ln()` but that is slower. -impl Distribution for Exp1 { - #[inline] - fn sample(&self, rng: &mut R) -> f64 { - #[inline] - fn pdf(x: f64) -> f64 { - (-x).exp() - } - #[inline] - fn zero_case(rng: &mut R, _u: f64) -> f64 { - ziggurat_tables::ZIG_EXP_R - rng.gen::().ln() - } - - ziggurat(rng, false, - &ziggurat_tables::ZIG_EXP_X, - &ziggurat_tables::ZIG_EXP_F, - pdf, zero_case) - } -} - -/// The exponential distribution `Exp(lambda)`. -/// -/// This distribution has density function: `f(x) = lambda * exp(-lambda * x)` -/// for `x > 0`. -/// -/// Note that [`Exp1`](crate::distributions::Exp1) is an optimised implementation for `lambda = 1`. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Exp { - /// `lambda` stored as `1/lambda`, since this is what we scale by. - lambda_inverse: f64 -} - -impl Exp { - /// Construct a new `Exp` with the given shape parameter - /// `lambda`. Panics if `lambda <= 0`. - #[inline] - pub fn new(lambda: f64) -> Exp { - assert!(lambda > 0.0, "Exp::new called with `lambda` <= 0"); - Exp { lambda_inverse: 1.0 / lambda } - } -} - -impl Distribution for Exp { - fn sample(&self, rng: &mut R) -> f64 { - let n: f64 = rng.sample(Exp1); - n * self.lambda_inverse - } -} - -#[cfg(test)] -mod test { - use crate::distributions::Distribution; - use super::Exp; - - #[test] - fn test_exp() { - let exp = Exp::new(10.0); - let mut rng = crate::test::rng(221); - for _ in 0..1000 { - assert!(exp.sample(&mut rng) >= 0.0); - } - } - #[test] - #[should_panic] - fn test_exp_invalid_lambda_zero() { - Exp::new(0.0); - } - #[test] - #[should_panic] - fn test_exp_invalid_lambda_neg() { - Exp::new(-10.0); - } -} diff --git a/rand/src/distributions/float.rs b/rand/src/distributions/float.rs deleted file mode 100644 index bda523a..0000000 --- a/rand/src/distributions/float.rs +++ /dev/null @@ -1,259 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Basic floating-point number distributions - -use core::mem; -use crate::Rng; -use crate::distributions::{Distribution, Standard}; -use crate::distributions::utils::FloatSIMDUtils; -#[cfg(feature="simd_support")] -use packed_simd::*; - -/// A distribution to sample floating point numbers uniformly in the half-open -/// interval `(0, 1]`, i.e. including 1 but not 0. -/// -/// All values that can be generated are of the form `n * ε/2`. For `f32` -/// the 23 most significant random bits of a `u32` are used and for `f64` the -/// 53 most significant bits of a `u64` are used. The conversion uses the -/// multiplicative method. -/// -/// See also: [`Standard`] which samples from `[0, 1)`, [`Open01`] -/// which samples from `(0, 1)` and [`Uniform`] which samples from arbitrary -/// ranges. -/// -/// # Example -/// ``` -/// use rand::{thread_rng, Rng}; -/// use rand::distributions::OpenClosed01; -/// -/// let val: f32 = thread_rng().sample(OpenClosed01); -/// println!("f32 from (0, 1): {}", val); -/// ``` -/// -/// [`Standard`]: crate::distributions::Standard -/// [`Open01`]: crate::distributions::Open01 -/// [`Uniform`]: crate::distributions::uniform::Uniform -#[derive(Clone, Copy, Debug)] -pub struct OpenClosed01; - -/// A distribution to sample floating point numbers uniformly in the open -/// interval `(0, 1)`, i.e. not including either endpoint. -/// -/// All values that can be generated are of the form `n * ε + ε/2`. For `f32` -/// the 22 most significant random bits of an `u32` are used, for `f64` 52 from -/// an `u64`. The conversion uses a transmute-based method. -/// -/// See also: [`Standard`] which samples from `[0, 1)`, [`OpenClosed01`] -/// which samples from `(0, 1]` and [`Uniform`] which samples from arbitrary -/// ranges. -/// -/// # Example -/// ``` -/// use rand::{thread_rng, Rng}; -/// use rand::distributions::Open01; -/// -/// let val: f32 = thread_rng().sample(Open01); -/// println!("f32 from (0, 1): {}", val); -/// ``` -/// -/// [`Standard`]: crate::distributions::Standard -/// [`OpenClosed01`]: crate::distributions::OpenClosed01 -/// [`Uniform`]: crate::distributions::uniform::Uniform -#[derive(Clone, Copy, Debug)] -pub struct Open01; - - -// This trait is needed by both this lib and rand_distr hence is a hidden export -#[doc(hidden)] -pub trait IntoFloat { - type F; - - /// Helper method to combine the fraction and a contant exponent into a - /// float. - /// - /// Only the least significant bits of `self` may be set, 23 for `f32` and - /// 52 for `f64`. - /// The resulting value will fall in a range that depends on the exponent. - /// As an example the range with exponent 0 will be - /// [20..21), which is [1..2). - fn into_float_with_exponent(self, exponent: i32) -> Self::F; -} - -macro_rules! float_impls { - ($ty:ident, $uty:ident, $f_scalar:ident, $u_scalar:ty, - $fraction_bits:expr, $exponent_bias:expr) => { - impl IntoFloat for $uty { - type F = $ty; - #[inline(always)] - fn into_float_with_exponent(self, exponent: i32) -> $ty { - // The exponent is encoded using an offset-binary representation - let exponent_bits: $u_scalar = - (($exponent_bias + exponent) as $u_scalar) << $fraction_bits; - $ty::from_bits(self | exponent_bits) - } - } - - impl Distribution<$ty> for Standard { - fn sample(&self, rng: &mut R) -> $ty { - // Multiply-based method; 24/53 random bits; [0, 1) interval. - // We use the most significant bits because for simple RNGs - // those are usually more random. - let float_size = mem::size_of::<$f_scalar>() as u32 * 8; - let precision = $fraction_bits + 1; - let scale = 1.0 / ((1 as $u_scalar << precision) as $f_scalar); - - let value: $uty = rng.gen(); - let value = value >> (float_size - precision); - scale * $ty::cast_from_int(value) - } - } - - impl Distribution<$ty> for OpenClosed01 { - fn sample(&self, rng: &mut R) -> $ty { - // Multiply-based method; 24/53 random bits; (0, 1] interval. - // We use the most significant bits because for simple RNGs - // those are usually more random. - let float_size = mem::size_of::<$f_scalar>() as u32 * 8; - let precision = $fraction_bits + 1; - let scale = 1.0 / ((1 as $u_scalar << precision) as $f_scalar); - - let value: $uty = rng.gen(); - let value = value >> (float_size - precision); - // Add 1 to shift up; will not overflow because of right-shift: - scale * $ty::cast_from_int(value + 1) - } - } - - impl Distribution<$ty> for Open01 { - fn sample(&self, rng: &mut R) -> $ty { - // Transmute-based method; 23/52 random bits; (0, 1) interval. - // We use the most significant bits because for simple RNGs - // those are usually more random. - use core::$f_scalar::EPSILON; - let float_size = mem::size_of::<$f_scalar>() as u32 * 8; - - let value: $uty = rng.gen(); - let fraction = value >> (float_size - $fraction_bits); - fraction.into_float_with_exponent(0) - (1.0 - EPSILON / 2.0) - } - } - } -} - -float_impls! { f32, u32, f32, u32, 23, 127 } -float_impls! { f64, u64, f64, u64, 52, 1023 } - -#[cfg(feature="simd_support")] -float_impls! { f32x2, u32x2, f32, u32, 23, 127 } -#[cfg(feature="simd_support")] -float_impls! { f32x4, u32x4, f32, u32, 23, 127 } -#[cfg(feature="simd_support")] -float_impls! { f32x8, u32x8, f32, u32, 23, 127 } -#[cfg(feature="simd_support")] -float_impls! { f32x16, u32x16, f32, u32, 23, 127 } - -#[cfg(feature="simd_support")] -float_impls! { f64x2, u64x2, f64, u64, 52, 1023 } -#[cfg(feature="simd_support")] -float_impls! { f64x4, u64x4, f64, u64, 52, 1023 } -#[cfg(feature="simd_support")] -float_impls! { f64x8, u64x8, f64, u64, 52, 1023 } - - -#[cfg(test)] -mod tests { - use crate::Rng; - use crate::distributions::{Open01, OpenClosed01}; - use crate::rngs::mock::StepRng; - #[cfg(feature="simd_support")] - use packed_simd::*; - - const EPSILON32: f32 = ::core::f32::EPSILON; - const EPSILON64: f64 = ::core::f64::EPSILON; - - macro_rules! test_f32 { - ($fnn:ident, $ty:ident, $ZERO:expr, $EPSILON:expr) => { - #[test] - fn $fnn() { - // Standard - let mut zeros = StepRng::new(0, 0); - assert_eq!(zeros.gen::<$ty>(), $ZERO); - let mut one = StepRng::new(1 << 8 | 1 << (8 + 32), 0); - assert_eq!(one.gen::<$ty>(), $EPSILON / 2.0); - let mut max = StepRng::new(!0, 0); - assert_eq!(max.gen::<$ty>(), 1.0 - $EPSILON / 2.0); - - // OpenClosed01 - let mut zeros = StepRng::new(0, 0); - assert_eq!(zeros.sample::<$ty, _>(OpenClosed01), - 0.0 + $EPSILON / 2.0); - let mut one = StepRng::new(1 << 8 | 1 << (8 + 32), 0); - assert_eq!(one.sample::<$ty, _>(OpenClosed01), $EPSILON); - let mut max = StepRng::new(!0, 0); - assert_eq!(max.sample::<$ty, _>(OpenClosed01), $ZERO + 1.0); - - // Open01 - let mut zeros = StepRng::new(0, 0); - assert_eq!(zeros.sample::<$ty, _>(Open01), 0.0 + $EPSILON / 2.0); - let mut one = StepRng::new(1 << 9 | 1 << (9 + 32), 0); - assert_eq!(one.sample::<$ty, _>(Open01), $EPSILON / 2.0 * 3.0); - let mut max = StepRng::new(!0, 0); - assert_eq!(max.sample::<$ty, _>(Open01), 1.0 - $EPSILON / 2.0); - } - } - } - test_f32! { f32_edge_cases, f32, 0.0, EPSILON32 } - #[cfg(feature="simd_support")] - test_f32! { f32x2_edge_cases, f32x2, f32x2::splat(0.0), f32x2::splat(EPSILON32) } - #[cfg(feature="simd_support")] - test_f32! { f32x4_edge_cases, f32x4, f32x4::splat(0.0), f32x4::splat(EPSILON32) } - #[cfg(feature="simd_support")] - test_f32! { f32x8_edge_cases, f32x8, f32x8::splat(0.0), f32x8::splat(EPSILON32) } - #[cfg(feature="simd_support")] - test_f32! { f32x16_edge_cases, f32x16, f32x16::splat(0.0), f32x16::splat(EPSILON32) } - - macro_rules! test_f64 { - ($fnn:ident, $ty:ident, $ZERO:expr, $EPSILON:expr) => { - #[test] - fn $fnn() { - // Standard - let mut zeros = StepRng::new(0, 0); - assert_eq!(zeros.gen::<$ty>(), $ZERO); - let mut one = StepRng::new(1 << 11, 0); - assert_eq!(one.gen::<$ty>(), $EPSILON / 2.0); - let mut max = StepRng::new(!0, 0); - assert_eq!(max.gen::<$ty>(), 1.0 - $EPSILON / 2.0); - - // OpenClosed01 - let mut zeros = StepRng::new(0, 0); - assert_eq!(zeros.sample::<$ty, _>(OpenClosed01), - 0.0 + $EPSILON / 2.0); - let mut one = StepRng::new(1 << 11, 0); - assert_eq!(one.sample::<$ty, _>(OpenClosed01), $EPSILON); - let mut max = StepRng::new(!0, 0); - assert_eq!(max.sample::<$ty, _>(OpenClosed01), $ZERO + 1.0); - - // Open01 - let mut zeros = StepRng::new(0, 0); - assert_eq!(zeros.sample::<$ty, _>(Open01), 0.0 + $EPSILON / 2.0); - let mut one = StepRng::new(1 << 12, 0); - assert_eq!(one.sample::<$ty, _>(Open01), $EPSILON / 2.0 * 3.0); - let mut max = StepRng::new(!0, 0); - assert_eq!(max.sample::<$ty, _>(Open01), 1.0 - $EPSILON / 2.0); - } - } - } - test_f64! { f64_edge_cases, f64, 0.0, EPSILON64 } - #[cfg(feature="simd_support")] - test_f64! { f64x2_edge_cases, f64x2, f64x2::splat(0.0), f64x2::splat(EPSILON64) } - #[cfg(feature="simd_support")] - test_f64! { f64x4_edge_cases, f64x4, f64x4::splat(0.0), f64x4::splat(EPSILON64) } - #[cfg(feature="simd_support")] - test_f64! { f64x8_edge_cases, f64x8, f64x8::splat(0.0), f64x8::splat(EPSILON64) } -} diff --git a/rand/src/distributions/gamma.rs b/rand/src/distributions/gamma.rs deleted file mode 100644 index b5a97f5..0000000 --- a/rand/src/distributions/gamma.rs +++ /dev/null @@ -1,371 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Gamma and derived distributions. -#![allow(deprecated)] - -use self::GammaRepr::*; -use self::ChiSquaredRepr::*; - -use crate::Rng; -use crate::distributions::normal::StandardNormal; -use crate::distributions::{Distribution, Exp, Open01}; - -/// The Gamma distribution `Gamma(shape, scale)` distribution. -/// -/// The density function of this distribution is -/// -/// ```text -/// f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k) -/// ``` -/// -/// where `Γ` is the Gamma function, `k` is the shape and `θ` is the -/// scale and both `k` and `θ` are strictly positive. -/// -/// The algorithm used is that described by Marsaglia & Tsang 2000[^1], -/// falling back to directly sampling from an Exponential for `shape -/// == 1`, and using the boosting technique described in that paper for -/// `shape < 1`. -/// -/// [^1]: George Marsaglia and Wai Wan Tsang. 2000. "A Simple Method for -/// Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3 -/// (September 2000), 363-372. -/// DOI:[10.1145/358407.358414](https://doi.acm.org/10.1145/358407.358414) -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Gamma { - repr: GammaRepr, -} - -#[derive(Clone, Copy, Debug)] -enum GammaRepr { - Large(GammaLargeShape), - One(Exp), - Small(GammaSmallShape) -} - -// These two helpers could be made public, but saving the -// match-on-Gamma-enum branch from using them directly (e.g. if one -// knows that the shape is always > 1) doesn't appear to be much -// faster. - -/// Gamma distribution where the shape parameter is less than 1. -/// -/// Note, samples from this require a compulsory floating-point `pow` -/// call, which makes it significantly slower than sampling from a -/// gamma distribution where the shape parameter is greater than or -/// equal to 1. -/// -/// See `Gamma` for sampling from a Gamma distribution with general -/// shape parameters. -#[derive(Clone, Copy, Debug)] -struct GammaSmallShape { - inv_shape: f64, - large_shape: GammaLargeShape -} - -/// Gamma distribution where the shape parameter is larger than 1. -/// -/// See `Gamma` for sampling from a Gamma distribution with general -/// shape parameters. -#[derive(Clone, Copy, Debug)] -struct GammaLargeShape { - scale: f64, - c: f64, - d: f64 -} - -impl Gamma { - /// Construct an object representing the `Gamma(shape, scale)` - /// distribution. - /// - /// Panics if `shape <= 0` or `scale <= 0`. - #[inline] - pub fn new(shape: f64, scale: f64) -> Gamma { - assert!(shape > 0.0, "Gamma::new called with shape <= 0"); - assert!(scale > 0.0, "Gamma::new called with scale <= 0"); - - let repr = if shape == 1.0 { - One(Exp::new(1.0 / scale)) - } else if shape < 1.0 { - Small(GammaSmallShape::new_raw(shape, scale)) - } else { - Large(GammaLargeShape::new_raw(shape, scale)) - }; - Gamma { repr } - } -} - -impl GammaSmallShape { - fn new_raw(shape: f64, scale: f64) -> GammaSmallShape { - GammaSmallShape { - inv_shape: 1. / shape, - large_shape: GammaLargeShape::new_raw(shape + 1.0, scale) - } - } -} - -impl GammaLargeShape { - fn new_raw(shape: f64, scale: f64) -> GammaLargeShape { - let d = shape - 1. / 3.; - GammaLargeShape { - scale, - c: 1. / (9. * d).sqrt(), - d - } - } -} - -impl Distribution for Gamma { - fn sample(&self, rng: &mut R) -> f64 { - match self.repr { - Small(ref g) => g.sample(rng), - One(ref g) => g.sample(rng), - Large(ref g) => g.sample(rng), - } - } -} -impl Distribution for GammaSmallShape { - fn sample(&self, rng: &mut R) -> f64 { - let u: f64 = rng.sample(Open01); - - self.large_shape.sample(rng) * u.powf(self.inv_shape) - } -} -impl Distribution for GammaLargeShape { - fn sample(&self, rng: &mut R) -> f64 { - loop { - let x = rng.sample(StandardNormal); - let v_cbrt = 1.0 + self.c * x; - if v_cbrt <= 0.0 { // a^3 <= 0 iff a <= 0 - continue - } - - let v = v_cbrt * v_cbrt * v_cbrt; - let u: f64 = rng.sample(Open01); - - let x_sqr = x * x; - if u < 1.0 - 0.0331 * x_sqr * x_sqr || - u.ln() < 0.5 * x_sqr + self.d * (1.0 - v + v.ln()) { - return self.d * v * self.scale - } - } - } -} - -/// The chi-squared distribution `χ²(k)`, where `k` is the degrees of -/// freedom. -/// -/// For `k > 0` integral, this distribution is the sum of the squares -/// of `k` independent standard normal random variables. For other -/// `k`, this uses the equivalent characterisation -/// `χ²(k) = Gamma(k/2, 2)`. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct ChiSquared { - repr: ChiSquaredRepr, -} - -#[derive(Clone, Copy, Debug)] -enum ChiSquaredRepr { - // k == 1, Gamma(alpha, ..) is particularly slow for alpha < 1, - // e.g. when alpha = 1/2 as it would be for this case, so special- - // casing and using the definition of N(0,1)^2 is faster. - DoFExactlyOne, - DoFAnythingElse(Gamma), -} - -impl ChiSquared { - /// Create a new chi-squared distribution with degrees-of-freedom - /// `k`. Panics if `k < 0`. - pub fn new(k: f64) -> ChiSquared { - let repr = if k == 1.0 { - DoFExactlyOne - } else { - assert!(k > 0.0, "ChiSquared::new called with `k` < 0"); - DoFAnythingElse(Gamma::new(0.5 * k, 2.0)) - }; - ChiSquared { repr } - } -} -impl Distribution for ChiSquared { - fn sample(&self, rng: &mut R) -> f64 { - match self.repr { - DoFExactlyOne => { - // k == 1 => N(0,1)^2 - let norm = rng.sample(StandardNormal); - norm * norm - } - DoFAnythingElse(ref g) => g.sample(rng) - } - } -} - -/// The Fisher F distribution `F(m, n)`. -/// -/// This distribution is equivalent to the ratio of two normalised -/// chi-squared distributions, that is, `F(m,n) = (χ²(m)/m) / -/// (χ²(n)/n)`. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct FisherF { - numer: ChiSquared, - denom: ChiSquared, - // denom_dof / numer_dof so that this can just be a straight - // multiplication, rather than a division. - dof_ratio: f64, -} - -impl FisherF { - /// Create a new `FisherF` distribution, with the given - /// parameter. Panics if either `m` or `n` are not positive. - pub fn new(m: f64, n: f64) -> FisherF { - assert!(m > 0.0, "FisherF::new called with `m < 0`"); - assert!(n > 0.0, "FisherF::new called with `n < 0`"); - - FisherF { - numer: ChiSquared::new(m), - denom: ChiSquared::new(n), - dof_ratio: n / m - } - } -} -impl Distribution for FisherF { - fn sample(&self, rng: &mut R) -> f64 { - self.numer.sample(rng) / self.denom.sample(rng) * self.dof_ratio - } -} - -/// The Student t distribution, `t(nu)`, where `nu` is the degrees of -/// freedom. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct StudentT { - chi: ChiSquared, - dof: f64 -} - -impl StudentT { - /// Create a new Student t distribution with `n` degrees of - /// freedom. Panics if `n <= 0`. - pub fn new(n: f64) -> StudentT { - assert!(n > 0.0, "StudentT::new called with `n <= 0`"); - StudentT { - chi: ChiSquared::new(n), - dof: n - } - } -} -impl Distribution for StudentT { - fn sample(&self, rng: &mut R) -> f64 { - let norm = rng.sample(StandardNormal); - norm * (self.dof / self.chi.sample(rng)).sqrt() - } -} - -/// The Beta distribution with shape parameters `alpha` and `beta`. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Beta { - gamma_a: Gamma, - gamma_b: Gamma, -} - -impl Beta { - /// Construct an object representing the `Beta(alpha, beta)` - /// distribution. - /// - /// Panics if `shape <= 0` or `scale <= 0`. - pub fn new(alpha: f64, beta: f64) -> Beta { - assert!((alpha > 0.) & (beta > 0.)); - Beta { - gamma_a: Gamma::new(alpha, 1.), - gamma_b: Gamma::new(beta, 1.), - } - } -} - -impl Distribution for Beta { - fn sample(&self, rng: &mut R) -> f64 { - let x = self.gamma_a.sample(rng); - let y = self.gamma_b.sample(rng); - x / (x + y) - } -} - -#[cfg(test)] -mod test { - use crate::distributions::Distribution; - use super::{Beta, ChiSquared, StudentT, FisherF}; - - const N: u32 = 100; - - #[test] - fn test_chi_squared_one() { - let chi = ChiSquared::new(1.0); - let mut rng = crate::test::rng(201); - for _ in 0..N { - chi.sample(&mut rng); - } - } - #[test] - fn test_chi_squared_small() { - let chi = ChiSquared::new(0.5); - let mut rng = crate::test::rng(202); - for _ in 0..N { - chi.sample(&mut rng); - } - } - #[test] - fn test_chi_squared_large() { - let chi = ChiSquared::new(30.0); - let mut rng = crate::test::rng(203); - for _ in 0..N { - chi.sample(&mut rng); - } - } - #[test] - #[should_panic] - fn test_chi_squared_invalid_dof() { - ChiSquared::new(-1.0); - } - - #[test] - fn test_f() { - let f = FisherF::new(2.0, 32.0); - let mut rng = crate::test::rng(204); - for _ in 0..N { - f.sample(&mut rng); - } - } - - #[test] - fn test_t() { - let t = StudentT::new(11.0); - let mut rng = crate::test::rng(205); - for _ in 0..N { - t.sample(&mut rng); - } - } - - #[test] - fn test_beta() { - let beta = Beta::new(1.0, 2.0); - let mut rng = crate::test::rng(201); - for _ in 0..N { - beta.sample(&mut rng); - } - } - - #[test] - #[should_panic] - fn test_beta_invalid_dof() { - Beta::new(0., 0.); - } -} diff --git a/rand/src/distributions/integer.rs b/rand/src/distributions/integer.rs deleted file mode 100644 index 5238339..0000000 --- a/rand/src/distributions/integer.rs +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The implementations of the `Standard` distribution for integer types. - -use crate::{Rng}; -use crate::distributions::{Distribution, Standard}; -use core::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize}; -#[cfg(not(target_os = "emscripten"))] use core::num::NonZeroU128; -#[cfg(feature="simd_support")] -use packed_simd::*; -#[cfg(all(target_arch = "x86", feature="nightly"))] -use core::arch::x86::*; -#[cfg(all(target_arch = "x86_64", feature="nightly"))] -use core::arch::x86_64::*; - -impl Distribution for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> u8 { - rng.next_u32() as u8 - } -} - -impl Distribution for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> u16 { - rng.next_u32() as u16 - } -} - -impl Distribution for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> u32 { - rng.next_u32() - } -} - -impl Distribution for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> u64 { - rng.next_u64() - } -} - -#[cfg(not(target_os = "emscripten"))] -impl Distribution for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> u128 { - // Use LE; we explicitly generate one value before the next. - let x = u128::from(rng.next_u64()); - let y = u128::from(rng.next_u64()); - (y << 64) | x - } -} - -impl Distribution for Standard { - #[inline] - #[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))] - fn sample(&self, rng: &mut R) -> usize { - rng.next_u32() as usize - } - - #[inline] - #[cfg(target_pointer_width = "64")] - fn sample(&self, rng: &mut R) -> usize { - rng.next_u64() as usize - } -} - -macro_rules! impl_int_from_uint { - ($ty:ty, $uty:ty) => { - impl Distribution<$ty> for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> $ty { - rng.gen::<$uty>() as $ty - } - } - } -} - -impl_int_from_uint! { i8, u8 } -impl_int_from_uint! { i16, u16 } -impl_int_from_uint! { i32, u32 } -impl_int_from_uint! { i64, u64 } -#[cfg(not(target_os = "emscripten"))] impl_int_from_uint! { i128, u128 } -impl_int_from_uint! { isize, usize } - -macro_rules! impl_nzint { - ($ty:ty, $new:path) => { - impl Distribution<$ty> for Standard { - fn sample(&self, rng: &mut R) -> $ty { - loop { - if let Some(nz) = $new(rng.gen()) { - break nz; - } - } - } - } - } -} - -impl_nzint!(NonZeroU8, NonZeroU8::new); -impl_nzint!(NonZeroU16, NonZeroU16::new); -impl_nzint!(NonZeroU32, NonZeroU32::new); -impl_nzint!(NonZeroU64, NonZeroU64::new); -#[cfg(not(target_os = "emscripten"))] impl_nzint!(NonZeroU128, NonZeroU128::new); -impl_nzint!(NonZeroUsize, NonZeroUsize::new); - -#[cfg(feature="simd_support")] -macro_rules! simd_impl { - ($(($intrinsic:ident, $vec:ty),)+) => {$( - impl Distribution<$intrinsic> for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> $intrinsic { - $intrinsic::from_bits(rng.gen::<$vec>()) - } - } - )+}; - - ($bits:expr,) => {}; - ($bits:expr, $ty:ty, $($ty_more:ty,)*) => { - simd_impl!($bits, $($ty_more,)*); - - impl Distribution<$ty> for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> $ty { - let mut vec: $ty = Default::default(); - unsafe { - let ptr = &mut vec; - let b_ptr = &mut *(ptr as *mut $ty as *mut [u8; $bits/8]); - rng.fill_bytes(b_ptr); - } - vec.to_le() - } - } - }; -} - -#[cfg(feature="simd_support")] -simd_impl!(16, u8x2, i8x2,); -#[cfg(feature="simd_support")] -simd_impl!(32, u8x4, i8x4, u16x2, i16x2,); -#[cfg(feature="simd_support")] -simd_impl!(64, u8x8, i8x8, u16x4, i16x4, u32x2, i32x2,); -#[cfg(feature="simd_support")] -simd_impl!(128, u8x16, i8x16, u16x8, i16x8, u32x4, i32x4, u64x2, i64x2,); -#[cfg(feature="simd_support")] -simd_impl!(256, u8x32, i8x32, u16x16, i16x16, u32x8, i32x8, u64x4, i64x4,); -#[cfg(feature="simd_support")] -simd_impl!(512, u8x64, i8x64, u16x32, i16x32, u32x16, i32x16, u64x8, i64x8,); -#[cfg(all(feature="simd_support", feature="nightly", any(target_arch="x86", target_arch="x86_64")))] -simd_impl!((__m64, u8x8), (__m128i, u8x16), (__m256i, u8x32),); - -#[cfg(test)] -mod tests { - use crate::Rng; - use crate::distributions::{Standard}; - - #[test] - fn test_integers() { - let mut rng = crate::test::rng(806); - - rng.sample::(Standard); - rng.sample::(Standard); - rng.sample::(Standard); - rng.sample::(Standard); - rng.sample::(Standard); - #[cfg(not(target_os = "emscripten"))] - rng.sample::(Standard); - - rng.sample::(Standard); - rng.sample::(Standard); - rng.sample::(Standard); - rng.sample::(Standard); - rng.sample::(Standard); - #[cfg(not(target_os = "emscripten"))] - rng.sample::(Standard); - } -} diff --git a/rand/src/distributions/mod.rs b/rand/src/distributions/mod.rs deleted file mode 100644 index 02ece6f..0000000 --- a/rand/src/distributions/mod.rs +++ /dev/null @@ -1,381 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Generating random samples from probability distributions -//! -//! This module is the home of the [`Distribution`] trait and several of its -//! implementations. It is the workhorse behind some of the convenient -//! functionality of the [`Rng`] trait, e.g. [`Rng::gen`], [`Rng::gen_range`] and -//! of course [`Rng::sample`]. -//! -//! Abstractly, a [probability distribution] describes the probability of -//! occurance of each value in its sample space. -//! -//! More concretely, an implementation of `Distribution` for type `X` is an -//! algorithm for choosing values from the sample space (a subset of `T`) -//! according to the distribution `X` represents, using an external source of -//! randomness (an RNG supplied to the `sample` function). -//! -//! A type `X` may implement `Distribution` for multiple types `T`. -//! Any type implementing [`Distribution`] is stateless (i.e. immutable), -//! but it may have internal parameters set at construction time (for example, -//! [`Uniform`] allows specification of its sample space as a range within `T`). -//! -//! -//! # The `Standard` distribution -//! -//! The [`Standard`] distribution is important to mention. This is the -//! distribution used by [`Rng::gen()`] and represents the "default" way to -//! produce a random value for many different types, including most primitive -//! types, tuples, arrays, and a few derived types. See the documentation of -//! [`Standard`] for more details. -//! -//! Implementing `Distribution` for [`Standard`] for user types `T` makes it -//! possible to generate type `T` with [`Rng::gen()`], and by extension also -//! with the [`random()`] function. -//! -//! ## Random characters -//! -//! [`Alphanumeric`] is a simple distribution to sample random letters and -//! numbers of the `char` type; in contrast [`Standard`] may sample any valid -//! `char`. -//! -//! -//! # Uniform numeric ranges -//! -//! The [`Uniform`] distribution is more flexible than [`Standard`], but also -//! more specialised: it supports fewer target types, but allows the sample -//! space to be specified as an arbitrary range within its target type `T`. -//! Both [`Standard`] and [`Uniform`] are in some sense uniform distributions. -//! -//! Values may be sampled from this distribution using [`Rng::gen_range`] or -//! by creating a distribution object with [`Uniform::new`], -//! [`Uniform::new_inclusive`] or `From`. When the range limits are not -//! known at compile time it is typically faster to reuse an existing -//! distribution object than to call [`Rng::gen_range`]. -//! -//! User types `T` may also implement `Distribution` for [`Uniform`], -//! although this is less straightforward than for [`Standard`] (see the -//! documentation in the [`uniform`] module. Doing so enables generation of -//! values of type `T` with [`Rng::gen_range`]. -//! -//! ## Open and half-open ranges -//! -//! There are surprisingly many ways to uniformly generate random floats. A -//! range between 0 and 1 is standard, but the exact bounds (open vs closed) -//! and accuracy differ. In addition to the [`Standard`] distribution Rand offers -//! [`Open01`] and [`OpenClosed01`]. See "Floating point implementation" section of -//! [`Standard`] documentation for more details. -//! -//! # Non-uniform sampling -//! -//! Sampling a simple true/false outcome with a given probability has a name: -//! the [`Bernoulli`] distribution (this is used by [`Rng::gen_bool`]). -//! -//! For weighted sampling from a sequence of discrete values, use the -//! [`weighted`] module. -//! -//! This crate no longer includes other non-uniform distributions; instead -//! it is recommended that you use either [`rand_distr`] or [`statrs`]. -//! -//! -//! [probability distribution]: https://en.wikipedia.org/wiki/Probability_distribution -//! [`rand_distr`]: https://crates.io/crates/rand_distr -//! [`statrs`]: https://crates.io/crates/statrs - -//! [`Alphanumeric`]: distributions::Alphanumeric -//! [`Bernoulli`]: distributions::Bernoulli -//! [`Open01`]: distributions::Open01 -//! [`OpenClosed01`]: distributions::OpenClosed01 -//! [`Standard`]: distributions::Standard -//! [`Uniform`]: distributions::Uniform -//! [`Uniform::new`]: distributions::Uniform::new -//! [`Uniform::new_inclusive`]: distributions::Uniform::new_inclusive -//! [`weighted`]: distributions::weighted -//! [`rand_distr`]: https://crates.io/crates/rand_distr -//! [`statrs`]: https://crates.io/crates/statrs - -use core::iter; -use crate::Rng; - -pub use self::other::Alphanumeric; -#[doc(inline)] pub use self::uniform::Uniform; -pub use self::float::{OpenClosed01, Open01}; -pub use self::bernoulli::{Bernoulli, BernoulliError}; -#[cfg(feature="alloc")] pub use self::weighted::{WeightedIndex, WeightedError}; - -// The following are all deprecated after being moved to rand_distr -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::unit_sphere::UnitSphereSurface; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::unit_circle::UnitCircle; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::gamma::{Gamma, ChiSquared, FisherF, - StudentT, Beta}; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::normal::{Normal, LogNormal, StandardNormal}; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::exponential::{Exp, Exp1}; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::pareto::Pareto; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::poisson::Poisson; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::binomial::Binomial; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::cauchy::Cauchy; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::dirichlet::Dirichlet; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::triangular::Triangular; -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::weibull::Weibull; - -pub mod uniform; -mod bernoulli; -#[cfg(feature="alloc")] pub mod weighted; -#[cfg(feature="std")] mod unit_sphere; -#[cfg(feature="std")] mod unit_circle; -#[cfg(feature="std")] mod gamma; -#[cfg(feature="std")] mod normal; -#[cfg(feature="std")] mod exponential; -#[cfg(feature="std")] mod pareto; -#[cfg(feature="std")] mod poisson; -#[cfg(feature="std")] mod binomial; -#[cfg(feature="std")] mod cauchy; -#[cfg(feature="std")] mod dirichlet; -#[cfg(feature="std")] mod triangular; -#[cfg(feature="std")] mod weibull; - -mod float; -#[doc(hidden)] pub mod hidden_export { - pub use super::float::IntoFloat; // used by rand_distr -} -mod integer; -mod other; -mod utils; -#[cfg(feature="std")] mod ziggurat_tables; - -/// Types (distributions) that can be used to create a random instance of `T`. -/// -/// It is possible to sample from a distribution through both the -/// `Distribution` and [`Rng`] traits, via `distr.sample(&mut rng)` and -/// `rng.sample(distr)`. They also both offer the [`sample_iter`] method, which -/// produces an iterator that samples from the distribution. -/// -/// All implementations are expected to be immutable; this has the significant -/// advantage of not needing to consider thread safety, and for most -/// distributions efficient state-less sampling algorithms are available. -/// -/// [`sample_iter`]: Distribution::method.sample_iter -pub trait Distribution { - /// Generate a random value of `T`, using `rng` as the source of randomness. - fn sample(&self, rng: &mut R) -> T; - - /// Create an iterator that generates random values of `T`, using `rng` as - /// the source of randomness. - /// - /// Note that this function takes `self` by value. This works since - /// `Distribution` is impl'd for `&D` where `D: Distribution`, - /// however borrowing is not automatic hence `distr.sample_iter(...)` may - /// need to be replaced with `(&distr).sample_iter(...)` to borrow or - /// `(&*distr).sample_iter(...)` to reborrow an existing reference. - /// - /// # Example - /// - /// ``` - /// use rand::thread_rng; - /// use rand::distributions::{Distribution, Alphanumeric, Uniform, Standard}; - /// - /// let rng = thread_rng(); - /// - /// // Vec of 16 x f32: - /// let v: Vec = Standard.sample_iter(rng).take(16).collect(); - /// - /// // String: - /// let s: String = Alphanumeric.sample_iter(rng).take(7).collect(); - /// - /// // Dice-rolling: - /// let die_range = Uniform::new_inclusive(1, 6); - /// let mut roll_die = die_range.sample_iter(rng); - /// while roll_die.next().unwrap() != 6 { - /// println!("Not a 6; rolling again!"); - /// } - /// ``` - fn sample_iter(self, rng: R) -> DistIter - where R: Rng, Self: Sized - { - DistIter { - distr: self, - rng, - phantom: ::core::marker::PhantomData, - } - } -} - -impl<'a, T, D: Distribution> Distribution for &'a D { - fn sample(&self, rng: &mut R) -> T { - (*self).sample(rng) - } -} - - -/// An iterator that generates random values of `T` with distribution `D`, -/// using `R` as the source of randomness. -/// -/// This `struct` is created by the [`sample_iter`] method on [`Distribution`]. -/// See its documentation for more. -/// -/// [`sample_iter`]: Distribution::sample_iter -#[derive(Debug)] -pub struct DistIter { - distr: D, - rng: R, - phantom: ::core::marker::PhantomData, -} - -impl Iterator for DistIter - where D: Distribution, R: Rng -{ - type Item = T; - - #[inline(always)] - fn next(&mut self) -> Option { - // Here, self.rng may be a reference, but we must take &mut anyway. - // Even if sample could take an R: Rng by value, we would need to do this - // since Rng is not copyable and we cannot enforce that this is "reborrowable". - Some(self.distr.sample(&mut self.rng)) - } - - fn size_hint(&self) -> (usize, Option) { - (usize::max_value(), None) - } -} - -impl iter::FusedIterator for DistIter - where D: Distribution, R: Rng {} - -#[cfg(features = "nightly")] -impl iter::TrustedLen for DistIter - where D: Distribution, R: Rng {} - - -/// A generic random value distribution, implemented for many primitive types. -/// Usually generates values with a numerically uniform distribution, and with a -/// range appropriate to the type. -/// -/// ## Provided implementations -/// -/// Assuming the provided `Rng` is well-behaved, these implementations -/// generate values with the following ranges and distributions: -/// -/// * Integers (`i32`, `u32`, `isize`, `usize`, etc.): Uniformly distributed -/// over all values of the type. -/// * `char`: Uniformly distributed over all Unicode scalar values, i.e. all -/// code points in the range `0...0x10_FFFF`, except for the range -/// `0xD800...0xDFFF` (the surrogate code points). This includes -/// unassigned/reserved code points. -/// * `bool`: Generates `false` or `true`, each with probability 0.5. -/// * Floating point types (`f32` and `f64`): Uniformly distributed in the -/// half-open range `[0, 1)`. See notes below. -/// * Wrapping integers (`Wrapping`), besides the type identical to their -/// normal integer variants. -/// -/// The `Standard` distribution also supports generation of the following -/// compound types where all component types are supported: -/// -/// * Tuples (up to 12 elements): each element is generated sequentially. -/// * Arrays (up to 32 elements): each element is generated sequentially; -/// see also [`Rng::fill`] which supports arbitrary array length for integer -/// types and tends to be faster for `u32` and smaller types. -/// * `Option` first generates a `bool`, and if true generates and returns -/// `Some(value)` where `value: T`, otherwise returning `None`. -/// -/// ## Custom implementations -/// -/// The [`Standard`] distribution may be implemented for user types as follows: -/// -/// ``` -/// # #![allow(dead_code)] -/// use rand::Rng; -/// use rand::distributions::{Distribution, Standard}; -/// -/// struct MyF32 { -/// x: f32, -/// } -/// -/// impl Distribution for Standard { -/// fn sample(&self, rng: &mut R) -> MyF32 { -/// MyF32 { x: rng.gen() } -/// } -/// } -/// ``` -/// -/// ## Example usage -/// ``` -/// use rand::prelude::*; -/// use rand::distributions::Standard; -/// -/// let val: f32 = StdRng::from_entropy().sample(Standard); -/// println!("f32 from [0, 1): {}", val); -/// ``` -/// -/// # Floating point implementation -/// The floating point implementations for `Standard` generate a random value in -/// the half-open interval `[0, 1)`, i.e. including 0 but not 1. -/// -/// All values that can be generated are of the form `n * ε/2`. For `f32` -/// the 23 most significant random bits of a `u32` are used and for `f64` the -/// 53 most significant bits of a `u64` are used. The conversion uses the -/// multiplicative method: `(rng.gen::<$uty>() >> N) as $ty * (ε/2)`. -/// -/// See also: [`Open01`] which samples from `(0, 1)`, [`OpenClosed01`] which -/// samples from `(0, 1]` and `Rng::gen_range(0, 1)` which also samples from -/// `[0, 1)`. Note that `Open01` and `gen_range` (which uses [`Uniform`]) use -/// transmute-based methods which yield 1 bit less precision but may perform -/// faster on some architectures (on modern Intel CPUs all methods have -/// approximately equal performance). -/// -/// [`Uniform`]: uniform::Uniform -#[derive(Clone, Copy, Debug)] -pub struct Standard; - - -#[cfg(all(test, feature = "std"))] -mod tests { - use crate::Rng; - use super::{Distribution, Uniform}; - - #[test] - fn test_distributions_iter() { - use crate::distributions::Open01; - let mut rng = crate::test::rng(210); - let distr = Open01; - let results: Vec = distr.sample_iter(&mut rng).take(100).collect(); - println!("{:?}", results); - } - - #[test] - fn test_make_an_iter() { - fn ten_dice_rolls_other_than_five<'a, R: Rng>(rng: &'a mut R) -> impl Iterator + 'a { - Uniform::new_inclusive(1, 6) - .sample_iter(rng) - .filter(|x| *x != 5) - .take(10) - } - - let mut rng = crate::test::rng(211); - let mut count = 0; - for val in ten_dice_rolls_other_than_five(&mut rng) { - assert!(val >= 1 && val <= 6 && val != 5); - count += 1; - } - assert_eq!(count, 10); - } -} diff --git a/rand/src/distributions/normal.rs b/rand/src/distributions/normal.rs deleted file mode 100644 index 7808baf..0000000 --- a/rand/src/distributions/normal.rs +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The normal and derived distributions. -#![allow(deprecated)] - -use crate::Rng; -use crate::distributions::{ziggurat_tables, Distribution, Open01}; -use crate::distributions::utils::ziggurat; - -/// Samples floating-point numbers according to the normal distribution -/// `N(0, 1)` (a.k.a. a standard normal, or Gaussian). This is equivalent to -/// `Normal::new(0.0, 1.0)` but faster. -/// -/// See `Normal` for the general normal distribution. -/// -/// Implemented via the ZIGNOR variant[^1] of the Ziggurat method. -/// -/// [^1]: Jurgen A. Doornik (2005). [*An Improved Ziggurat Method to -/// Generate Normal Random Samples*]( -/// https://www.doornik.com/research/ziggurat.pdf). -/// Nuffield College, Oxford -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct StandardNormal; - -impl Distribution for StandardNormal { - fn sample(&self, rng: &mut R) -> f64 { - #[inline] - fn pdf(x: f64) -> f64 { - (-x*x/2.0).exp() - } - #[inline] - fn zero_case(rng: &mut R, u: f64) -> f64 { - // compute a random number in the tail by hand - - // strange initial conditions, because the loop is not - // do-while, so the condition should be true on the first - // run, they get overwritten anyway (0 < 1, so these are - // good). - let mut x = 1.0f64; - let mut y = 0.0f64; - - while -2.0 * y < x * x { - let x_: f64 = rng.sample(Open01); - let y_: f64 = rng.sample(Open01); - - x = x_.ln() / ziggurat_tables::ZIG_NORM_R; - y = y_.ln(); - } - - if u < 0.0 { x - ziggurat_tables::ZIG_NORM_R } else { ziggurat_tables::ZIG_NORM_R - x } - } - - ziggurat(rng, true, // this is symmetric - &ziggurat_tables::ZIG_NORM_X, - &ziggurat_tables::ZIG_NORM_F, - pdf, zero_case) - } -} - -/// The normal distribution `N(mean, std_dev**2)`. -/// -/// This uses the ZIGNOR variant of the Ziggurat method, see [`StandardNormal`] -/// for more details. -/// -/// Note that [`StandardNormal`] is an optimised implementation for mean 0, and -/// standard deviation 1. -/// -/// [`StandardNormal`]: crate::distributions::StandardNormal -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Normal { - mean: f64, - std_dev: f64, -} - -impl Normal { - /// Construct a new `Normal` distribution with the given mean and - /// standard deviation. - /// - /// # Panics - /// - /// Panics if `std_dev < 0`. - #[inline] - pub fn new(mean: f64, std_dev: f64) -> Normal { - assert!(std_dev >= 0.0, "Normal::new called with `std_dev` < 0"); - Normal { - mean, - std_dev - } - } -} -impl Distribution for Normal { - fn sample(&self, rng: &mut R) -> f64 { - let n = rng.sample(StandardNormal); - self.mean + self.std_dev * n - } -} - - -/// The log-normal distribution `ln N(mean, std_dev**2)`. -/// -/// If `X` is log-normal distributed, then `ln(X)` is `N(mean, std_dev**2)` -/// distributed. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct LogNormal { - norm: Normal -} - -impl LogNormal { - /// Construct a new `LogNormal` distribution with the given mean - /// and standard deviation. - /// - /// # Panics - /// - /// Panics if `std_dev < 0`. - #[inline] - pub fn new(mean: f64, std_dev: f64) -> LogNormal { - assert!(std_dev >= 0.0, "LogNormal::new called with `std_dev` < 0"); - LogNormal { norm: Normal::new(mean, std_dev) } - } -} -impl Distribution for LogNormal { - fn sample(&self, rng: &mut R) -> f64 { - self.norm.sample(rng).exp() - } -} - -#[cfg(test)] -mod tests { - use crate::distributions::Distribution; - use super::{Normal, LogNormal}; - - #[test] - fn test_normal() { - let norm = Normal::new(10.0, 10.0); - let mut rng = crate::test::rng(210); - for _ in 0..1000 { - norm.sample(&mut rng); - } - } - #[test] - #[should_panic] - fn test_normal_invalid_sd() { - Normal::new(10.0, -1.0); - } - - - #[test] - fn test_log_normal() { - let lnorm = LogNormal::new(10.0, 10.0); - let mut rng = crate::test::rng(211); - for _ in 0..1000 { - lnorm.sample(&mut rng); - } - } - #[test] - #[should_panic] - fn test_log_normal_invalid_sd() { - LogNormal::new(10.0, -1.0); - } -} diff --git a/rand/src/distributions/other.rs b/rand/src/distributions/other.rs deleted file mode 100644 index 6ec0473..0000000 --- a/rand/src/distributions/other.rs +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The implementations of the `Standard` distribution for other built-in types. - -use core::char; -use core::num::Wrapping; - -use crate::Rng; -use crate::distributions::{Distribution, Standard, Uniform}; - -// ----- Sampling distributions ----- - -/// Sample a `char`, uniformly distributed over ASCII letters and numbers: -/// a-z, A-Z and 0-9. -/// -/// # Example -/// -/// ``` -/// use std::iter; -/// use rand::{Rng, thread_rng}; -/// use rand::distributions::Alphanumeric; -/// -/// let mut rng = thread_rng(); -/// let chars: String = iter::repeat(()) -/// .map(|()| rng.sample(Alphanumeric)) -/// .take(7) -/// .collect(); -/// println!("Random chars: {}", chars); -/// ``` -#[derive(Debug)] -pub struct Alphanumeric; - - -// ----- Implementations of distributions ----- - -impl Distribution for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> char { - // A valid `char` is either in the interval `[0, 0xD800)` or - // `(0xDFFF, 0x11_0000)`. All `char`s must therefore be in - // `[0, 0x11_0000)` but not in the "gap" `[0xD800, 0xDFFF]` which is - // reserved for surrogates. This is the size of that gap. - const GAP_SIZE: u32 = 0xDFFF - 0xD800 + 1; - - // Uniform::new(0, 0x11_0000 - GAP_SIZE) can also be used but it - // seemed slower. - let range = Uniform::new(GAP_SIZE, 0x11_0000); - - let mut n = range.sample(rng); - if n <= 0xDFFF { - n -= GAP_SIZE; - } - unsafe { char::from_u32_unchecked(n) } - } -} - -impl Distribution for Alphanumeric { - fn sample(&self, rng: &mut R) -> char { - const RANGE: u32 = 26 + 26 + 10; - const GEN_ASCII_STR_CHARSET: &[u8] = - b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ - abcdefghijklmnopqrstuvwxyz\ - 0123456789"; - // We can pick from 62 characters. This is so close to a power of 2, 64, - // that we can do better than `Uniform`. Use a simple bitshift and - // rejection sampling. We do not use a bitmask, because for small RNGs - // the most significant bits are usually of higher quality. - loop { - let var = rng.next_u32() >> (32 - 6); - if var < RANGE { - return GEN_ASCII_STR_CHARSET[var as usize] as char - } - } - } -} - -impl Distribution for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> bool { - // We can compare against an arbitrary bit of an u32 to get a bool. - // Because the least significant bits of a lower quality RNG can have - // simple patterns, we compare against the most significant bit. This is - // easiest done using a sign test. - (rng.next_u32() as i32) < 0 - } -} - -macro_rules! tuple_impl { - // use variables to indicate the arity of the tuple - ($($tyvar:ident),* ) => { - // the trailing commas are for the 1 tuple - impl< $( $tyvar ),* > - Distribution<( $( $tyvar ),* , )> - for Standard - where $( Standard: Distribution<$tyvar> ),* - { - #[inline] - fn sample(&self, _rng: &mut R) -> ( $( $tyvar ),* , ) { - ( - // use the $tyvar's to get the appropriate number of - // repeats (they're not actually needed) - $( - _rng.gen::<$tyvar>() - ),* - , - ) - } - } - } -} - -impl Distribution<()> for Standard { - #[allow(clippy::unused_unit)] - #[inline] - fn sample(&self, _: &mut R) -> () { () } -} -tuple_impl!{A} -tuple_impl!{A, B} -tuple_impl!{A, B, C} -tuple_impl!{A, B, C, D} -tuple_impl!{A, B, C, D, E} -tuple_impl!{A, B, C, D, E, F} -tuple_impl!{A, B, C, D, E, F, G} -tuple_impl!{A, B, C, D, E, F, G, H} -tuple_impl!{A, B, C, D, E, F, G, H, I} -tuple_impl!{A, B, C, D, E, F, G, H, I, J} -tuple_impl!{A, B, C, D, E, F, G, H, I, J, K} -tuple_impl!{A, B, C, D, E, F, G, H, I, J, K, L} - -macro_rules! array_impl { - // recursive, given at least one type parameter: - {$n:expr, $t:ident, $($ts:ident,)*} => { - array_impl!{($n - 1), $($ts,)*} - - impl Distribution<[T; $n]> for Standard where Standard: Distribution { - #[inline] - fn sample(&self, _rng: &mut R) -> [T; $n] { - [_rng.gen::<$t>(), $(_rng.gen::<$ts>()),*] - } - } - }; - // empty case: - {$n:expr,} => { - impl Distribution<[T; $n]> for Standard { - fn sample(&self, _rng: &mut R) -> [T; $n] { [] } - } - }; -} - -array_impl!{32, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,} - -impl Distribution> for Standard where Standard: Distribution { - #[inline] - fn sample(&self, rng: &mut R) -> Option { - // UFCS is needed here: https://github.com/rust-lang/rust/issues/24066 - if rng.gen::() { - Some(rng.gen()) - } else { - None - } - } -} - -impl Distribution> for Standard where Standard: Distribution { - #[inline] - fn sample(&self, rng: &mut R) -> Wrapping { - Wrapping(rng.gen()) - } -} - - -#[cfg(test)] -mod tests { - use crate::{Rng, RngCore, Standard}; - use crate::distributions::Alphanumeric; - #[cfg(all(not(feature="std"), feature="alloc"))] use alloc::string::String; - - #[test] - fn test_misc() { - let rng: &mut dyn RngCore = &mut crate::test::rng(820); - - rng.sample::(Standard); - rng.sample::(Standard); - } - - #[cfg(feature="alloc")] - #[test] - fn test_chars() { - use core::iter; - let mut rng = crate::test::rng(805); - - // Test by generating a relatively large number of chars, so we also - // take the rejection sampling path. - let word: String = iter::repeat(()) - .map(|()| rng.gen::()).take(1000).collect(); - assert!(word.len() != 0); - } - - #[test] - fn test_alphanumeric() { - let mut rng = crate::test::rng(806); - - // Test by generating a relatively large number of chars, so we also - // take the rejection sampling path. - let mut incorrect = false; - for _ in 0..100 { - let c = rng.sample(Alphanumeric); - incorrect |= !((c >= '0' && c <= '9') || - (c >= 'A' && c <= 'Z') || - (c >= 'a' && c <= 'z') ); - } - assert!(incorrect == false); - } -} diff --git a/rand/src/distributions/pareto.rs b/rand/src/distributions/pareto.rs deleted file mode 100644 index edc9122..0000000 --- a/rand/src/distributions/pareto.rs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Pareto distribution. -#![allow(deprecated)] - -use crate::Rng; -use crate::distributions::{Distribution, OpenClosed01}; - -/// Samples floating-point numbers according to the Pareto distribution -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Pareto { - scale: f64, - inv_neg_shape: f64, -} - -impl Pareto { - /// Construct a new Pareto distribution with given `scale` and `shape`. - /// - /// In the literature, `scale` is commonly written as xm or k and - /// `shape` is often written as α. - /// - /// # Panics - /// - /// `scale` and `shape` have to be non-zero and positive. - pub fn new(scale: f64, shape: f64) -> Pareto { - assert!((scale > 0.) & (shape > 0.)); - Pareto { scale, inv_neg_shape: -1.0 / shape } - } -} - -impl Distribution for Pareto { - fn sample(&self, rng: &mut R) -> f64 { - let u: f64 = rng.sample(OpenClosed01); - self.scale * u.powf(self.inv_neg_shape) - } -} - -#[cfg(test)] -mod tests { - use crate::distributions::Distribution; - use super::Pareto; - - #[test] - #[should_panic] - fn invalid() { - Pareto::new(0., 0.); - } - - #[test] - fn sample() { - let scale = 1.0; - let shape = 2.0; - let d = Pareto::new(scale, shape); - let mut rng = crate::test::rng(1); - for _ in 0..1000 { - let r = d.sample(&mut rng); - assert!(r >= scale); - } - } -} diff --git a/rand/src/distributions/poisson.rs b/rand/src/distributions/poisson.rs deleted file mode 100644 index 9fd6e99..0000000 --- a/rand/src/distributions/poisson.rs +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2016-2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Poisson distribution. -#![allow(deprecated)] - -use crate::Rng; -use crate::distributions::{Distribution, Cauchy}; -use crate::distributions::utils::log_gamma; - -/// The Poisson distribution `Poisson(lambda)`. -/// -/// This distribution has a density function: -/// `f(k) = lambda^k * exp(-lambda) / k!` for `k >= 0`. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Poisson { - lambda: f64, - // precalculated values - exp_lambda: f64, - log_lambda: f64, - sqrt_2lambda: f64, - magic_val: f64, -} - -impl Poisson { - /// Construct a new `Poisson` with the given shape parameter - /// `lambda`. Panics if `lambda <= 0`. - pub fn new(lambda: f64) -> Poisson { - assert!(lambda > 0.0, "Poisson::new called with lambda <= 0"); - let log_lambda = lambda.ln(); - Poisson { - lambda, - exp_lambda: (-lambda).exp(), - log_lambda, - sqrt_2lambda: (2.0 * lambda).sqrt(), - magic_val: lambda * log_lambda - log_gamma(1.0 + lambda), - } - } -} - -impl Distribution for Poisson { - fn sample(&self, rng: &mut R) -> u64 { - // using the algorithm from Numerical Recipes in C - - // for low expected values use the Knuth method - if self.lambda < 12.0 { - let mut result = 0; - let mut p = 1.0; - while p > self.exp_lambda { - p *= rng.gen::(); - result += 1; - } - result - 1 - } - // high expected values - rejection method - else { - let mut int_result: u64; - - // we use the Cauchy distribution as the comparison distribution - // f(x) ~ 1/(1+x^2) - let cauchy = Cauchy::new(0.0, 1.0); - - loop { - let mut result; - let mut comp_dev; - - loop { - // draw from the Cauchy distribution - comp_dev = rng.sample(cauchy); - // shift the peak of the comparison ditribution - result = self.sqrt_2lambda * comp_dev + self.lambda; - // repeat the drawing until we are in the range of possible values - if result >= 0.0 { - break; - } - } - // now the result is a random variable greater than 0 with Cauchy distribution - // the result should be an integer value - result = result.floor(); - int_result = result as u64; - - // this is the ratio of the Poisson distribution to the comparison distribution - // the magic value scales the distribution function to a range of approximately 0-1 - // since it is not exact, we multiply the ratio by 0.9 to avoid ratios greater than 1 - // this doesn't change the resulting distribution, only increases the rate of failed drawings - let check = 0.9 * (1.0 + comp_dev * comp_dev) - * (result * self.log_lambda - log_gamma(1.0 + result) - self.magic_val).exp(); - - // check with uniform random value - if below the threshold, we are within the target distribution - if rng.gen::() <= check { - break; - } - } - int_result - } - } -} - -#[cfg(test)] -mod test { - use crate::distributions::Distribution; - use super::Poisson; - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_poisson_10() { - let poisson = Poisson::new(10.0); - let mut rng = crate::test::rng(123); - let mut sum = 0; - for _ in 0..1000 { - sum += poisson.sample(&mut rng); - } - let avg = (sum as f64) / 1000.0; - println!("Poisson average: {}", avg); - assert!((avg - 10.0).abs() < 0.5); // not 100% certain, but probable enough - } - - #[test] - #[cfg(not(miri))] // Miri doesn't support transcendental functions - fn test_poisson_15() { - // Take the 'high expected values' path - let poisson = Poisson::new(15.0); - let mut rng = crate::test::rng(123); - let mut sum = 0; - for _ in 0..1000 { - sum += poisson.sample(&mut rng); - } - let avg = (sum as f64) / 1000.0; - println!("Poisson average: {}", avg); - assert!((avg - 15.0).abs() < 0.5); // not 100% certain, but probable enough - } - - #[test] - #[should_panic] - fn test_poisson_invalid_lambda_zero() { - Poisson::new(0.0); - } - - #[test] - #[should_panic] - fn test_poisson_invalid_lambda_neg() { - Poisson::new(-10.0); - } -} diff --git a/rand/src/distributions/triangular.rs b/rand/src/distributions/triangular.rs deleted file mode 100644 index 3e8f8b0..0000000 --- a/rand/src/distributions/triangular.rs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The triangular distribution. -#![allow(deprecated)] - -use crate::Rng; -use crate::distributions::{Distribution, Standard}; - -/// The triangular distribution. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Triangular { - min: f64, - max: f64, - mode: f64, -} - -impl Triangular { - /// Construct a new `Triangular` with minimum `min`, maximum `max` and mode - /// `mode`. - /// - /// # Panics - /// - /// If `max < mode`, `mode < max` or `max == min`. - /// - #[inline] - pub fn new(min: f64, max: f64, mode: f64) -> Triangular { - assert!(max >= mode); - assert!(mode >= min); - assert!(max != min); - Triangular { min, max, mode } - } -} - -impl Distribution for Triangular { - #[inline] - fn sample(&self, rng: &mut R) -> f64 { - let f: f64 = rng.sample(Standard); - let diff_mode_min = self.mode - self.min; - let diff_max_min = self.max - self.min; - if f * diff_max_min < diff_mode_min { - self.min + (f * diff_max_min * diff_mode_min).sqrt() - } else { - self.max - ((1. - f) * diff_max_min * (self.max - self.mode)).sqrt() - } - } -} - -#[cfg(test)] -mod test { - use crate::distributions::Distribution; - use super::Triangular; - - #[test] - fn test_new() { - for &(min, max, mode) in &[ - (-1., 1., 0.), (1., 2., 1.), (5., 25., 25.), (1e-5, 1e5, 1e-3), - (0., 1., 0.9), (-4., -0.5, -2.), (-13.039, 8.41, 1.17), - ] { - println!("{} {} {}", min, max, mode); - let _ = Triangular::new(min, max, mode); - } - } - - #[test] - fn test_sample() { - let norm = Triangular::new(0., 1., 0.5); - let mut rng = crate::test::rng(1); - for _ in 0..1000 { - norm.sample(&mut rng); - } - } -} diff --git a/rand/src/distributions/uniform.rs b/rand/src/distributions/uniform.rs deleted file mode 100644 index 8c90f4e..0000000 --- a/rand/src/distributions/uniform.rs +++ /dev/null @@ -1,1270 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A distribution uniformly sampling numbers within a given range. -//! -//! [`Uniform`] is the standard distribution to sample uniformly from a range; -//! e.g. `Uniform::new_inclusive(1, 6)` can sample integers from 1 to 6, like a -//! standard die. [`Rng::gen_range`] supports any type supported by -//! [`Uniform`]. -//! -//! This distribution is provided with support for several primitive types -//! (all integer and floating-point types) as well as [`std::time::Duration`], -//! and supports extension to user-defined types via a type-specific *back-end* -//! implementation. -//! -//! The types [`UniformInt`], [`UniformFloat`] and [`UniformDuration`] are the -//! back-ends supporting sampling from primitive integer and floating-point -//! ranges as well as from [`std::time::Duration`]; these types do not normally -//! need to be used directly (unless implementing a derived back-end). -//! -//! # Example usage -//! -//! ``` -//! use rand::{Rng, thread_rng}; -//! use rand::distributions::Uniform; -//! -//! let mut rng = thread_rng(); -//! let side = Uniform::new(-10.0, 10.0); -//! -//! // sample between 1 and 10 points -//! for _ in 0..rng.gen_range(1, 11) { -//! // sample a point from the square with sides -10 - 10 in two dimensions -//! let (x, y) = (rng.sample(side), rng.sample(side)); -//! println!("Point: {}, {}", x, y); -//! } -//! ``` -//! -//! # Extending `Uniform` to support a custom type -//! -//! To extend [`Uniform`] to support your own types, write a back-end which -//! implements the [`UniformSampler`] trait, then implement the [`SampleUniform`] -//! helper trait to "register" your back-end. See the `MyF32` example below. -//! -//! At a minimum, the back-end needs to store any parameters needed for sampling -//! (e.g. the target range) and implement `new`, `new_inclusive` and `sample`. -//! Those methods should include an assert to check the range is valid (i.e. -//! `low < high`). The example below merely wraps another back-end. -//! -//! The `new`, `new_inclusive` and `sample_single` functions use arguments of -//! type SampleBorrow in order to support passing in values by reference or -//! by value. In the implementation of these functions, you can choose to -//! simply use the reference returned by [`SampleBorrow::borrow`], or you can choose -//! to copy or clone the value, whatever is appropriate for your type. -//! -//! ``` -//! use rand::prelude::*; -//! use rand::distributions::uniform::{Uniform, SampleUniform, -//! UniformSampler, UniformFloat, SampleBorrow}; -//! -//! struct MyF32(f32); -//! -//! #[derive(Clone, Copy, Debug)] -//! struct UniformMyF32 { -//! inner: UniformFloat, -//! } -//! -//! impl UniformSampler for UniformMyF32 { -//! type X = MyF32; -//! fn new(low: B1, high: B2) -> Self -//! where B1: SampleBorrow + Sized, -//! B2: SampleBorrow + Sized -//! { -//! UniformMyF32 { -//! inner: UniformFloat::::new(low.borrow().0, high.borrow().0), -//! } -//! } -//! fn new_inclusive(low: B1, high: B2) -> Self -//! where B1: SampleBorrow + Sized, -//! B2: SampleBorrow + Sized -//! { -//! UniformSampler::new(low, high) -//! } -//! fn sample(&self, rng: &mut R) -> Self::X { -//! MyF32(self.inner.sample(rng)) -//! } -//! } -//! -//! impl SampleUniform for MyF32 { -//! type Sampler = UniformMyF32; -//! } -//! -//! let (low, high) = (MyF32(17.0f32), MyF32(22.0f32)); -//! let uniform = Uniform::new(low, high); -//! let x = uniform.sample(&mut thread_rng()); -//! ``` -//! -//! [`SampleUniform`]: crate::distributions::uniform::SampleUniform -//! [`UniformSampler`]: crate::distributions::uniform::UniformSampler -//! [`UniformInt`]: crate::distributions::uniform::UniformInt -//! [`UniformFloat`]: crate::distributions::uniform::UniformFloat -//! [`UniformDuration`]: crate::distributions::uniform::UniformDuration -//! [`SampleBorrow::borrow`]: crate::distributions::uniform::SampleBorrow::borrow - -#[cfg(feature = "std")] -use std::time::Duration; -#[cfg(not(feature = "std"))] -use core::time::Duration; - -use crate::Rng; -use crate::distributions::Distribution; -use crate::distributions::float::IntoFloat; -use crate::distributions::utils::{WideningMultiply, FloatSIMDUtils, FloatAsSIMD, BoolAsSIMD}; - -#[cfg(not(feature = "std"))] -#[allow(unused_imports)] // rustc doesn't detect that this is actually used -use crate::distributions::utils::Float; - - -#[cfg(feature="simd_support")] -use packed_simd::*; - -/// Sample values uniformly between two bounds. -/// -/// [`Uniform::new`] and [`Uniform::new_inclusive`] construct a uniform -/// distribution sampling from the given range; these functions may do extra -/// work up front to make sampling of multiple values faster. -/// -/// When sampling from a constant range, many calculations can happen at -/// compile-time and all methods should be fast; for floating-point ranges and -/// the full range of integer types this should have comparable performance to -/// the `Standard` distribution. -/// -/// Steps are taken to avoid bias which might be present in naive -/// implementations; for example `rng.gen::() % 170` samples from the range -/// `[0, 169]` but is twice as likely to select numbers less than 85 than other -/// values. Further, the implementations here give more weight to the high-bits -/// generated by the RNG than the low bits, since with some RNGs the low-bits -/// are of lower quality than the high bits. -/// -/// Implementations must sample in `[low, high)` range for -/// `Uniform::new(low, high)`, i.e., excluding `high`. In particular care must -/// be taken to ensure that rounding never results values `< low` or `>= high`. -/// -/// # Example -/// -/// ``` -/// use rand::distributions::{Distribution, Uniform}; -/// -/// fn main() { -/// let between = Uniform::from(10..10000); -/// let mut rng = rand::thread_rng(); -/// let mut sum = 0; -/// for _ in 0..1000 { -/// sum += between.sample(&mut rng); -/// } -/// println!("{}", sum); -/// } -/// ``` -/// -/// [`new`]: Uniform::new -/// [`new_inclusive`]: Uniform::new_inclusive -#[derive(Clone, Copy, Debug)] -pub struct Uniform { - inner: X::Sampler, -} - -impl Uniform { - /// Create a new `Uniform` instance which samples uniformly from the half - /// open range `[low, high)` (excluding `high`). Panics if `low >= high`. - pub fn new(low: B1, high: B2) -> Uniform - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - Uniform { inner: X::Sampler::new(low, high) } - } - - /// Create a new `Uniform` instance which samples uniformly from the closed - /// range `[low, high]` (inclusive). Panics if `low > high`. - pub fn new_inclusive(low: B1, high: B2) -> Uniform - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - Uniform { inner: X::Sampler::new_inclusive(low, high) } - } -} - -impl Distribution for Uniform { - fn sample(&self, rng: &mut R) -> X { - self.inner.sample(rng) - } -} - -/// Helper trait for creating objects using the correct implementation of -/// [`UniformSampler`] for the sampling type. -/// -/// See the [module documentation] on how to implement [`Uniform`] range -/// sampling for a custom type. -/// -/// [module documentation]: crate::distributions::uniform -pub trait SampleUniform: Sized { - /// The `UniformSampler` implementation supporting type `X`. - type Sampler: UniformSampler; -} - -/// Helper trait handling actual uniform sampling. -/// -/// See the [module documentation] on how to implement [`Uniform`] range -/// sampling for a custom type. -/// -/// Implementation of [`sample_single`] is optional, and is only useful when -/// the implementation can be faster than `Self::new(low, high).sample(rng)`. -/// -/// [module documentation]: crate::distributions::uniform -/// [`sample_single`]: UniformSampler::sample_single -pub trait UniformSampler: Sized { - /// The type sampled by this implementation. - type X; - - /// Construct self, with inclusive lower bound and exclusive upper bound - /// `[low, high)`. - /// - /// Usually users should not call this directly but instead use - /// `Uniform::new`, which asserts that `low < high` before calling this. - fn new(low: B1, high: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized; - - /// Construct self, with inclusive bounds `[low, high]`. - /// - /// Usually users should not call this directly but instead use - /// `Uniform::new_inclusive`, which asserts that `low <= high` before - /// calling this. - fn new_inclusive(low: B1, high: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized; - - /// Sample a value. - fn sample(&self, rng: &mut R) -> Self::X; - - /// Sample a single value uniformly from a range with inclusive lower bound - /// and exclusive upper bound `[low, high)`. - /// - /// By default this is implemented using - /// `UniformSampler::new(low, high).sample(rng)`. However, for some types - /// more optimal implementations for single usage may be provided via this - /// method (which is the case for integers and floats). - /// Results may not be identical. - fn sample_single(low: B1, high: B2, rng: &mut R) - -> Self::X - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let uniform: Self = UniformSampler::new(low, high); - uniform.sample(rng) - } -} - -impl From<::core::ops::Range> for Uniform { - fn from(r: ::core::ops::Range) -> Uniform { - Uniform::new(r.start, r.end) - } -} - -impl From<::core::ops::RangeInclusive> for Uniform { - fn from(r: ::core::ops::RangeInclusive) -> Uniform { - Uniform::new_inclusive(r.start(), r.end()) - } -} - -/// Helper trait similar to [`Borrow`] but implemented -/// only for SampleUniform and references to SampleUniform in -/// order to resolve ambiguity issues. -/// -/// [`Borrow`]: std::borrow::Borrow -pub trait SampleBorrow { - /// Immutably borrows from an owned value. See [`Borrow::borrow`] - /// - /// [`Borrow::borrow`]: std::borrow::Borrow::borrow - fn borrow(&self) -> &Borrowed; -} -impl SampleBorrow for Borrowed where Borrowed: SampleUniform { - #[inline(always)] - fn borrow(&self) -> &Borrowed { self } -} -impl<'a, Borrowed> SampleBorrow for &'a Borrowed where Borrowed: SampleUniform { - #[inline(always)] - fn borrow(&self) -> &Borrowed { *self } -} - -//////////////////////////////////////////////////////////////////////////////// - -// What follows are all back-ends. - - -/// The back-end implementing [`UniformSampler`] for integer types. -/// -/// Unless you are implementing [`UniformSampler`] for your own type, this type -/// should not be used directly, use [`Uniform`] instead. -/// -/// # Implementation notes -/// -/// For simplicity, we use the same generic struct `UniformInt` for all -/// integer types `X`. This gives us only one field type, `X`; to store unsigned -/// values of this size, we take use the fact that these conversions are no-ops. -/// -/// For a closed range, the number of possible numbers we should generate is -/// `range = (high - low + 1)`. To avoid bias, we must ensure that the size of -/// our sample space, `zone`, is a multiple of `range`; other values must be -/// rejected (by replacing with a new random sample). -/// -/// As a special case, we use `range = 0` to represent the full range of the -/// result type (i.e. for `new_inclusive($ty::MIN, $ty::MAX)`). -/// -/// The optimum `zone` is the largest product of `range` which fits in our -/// (unsigned) target type. We calculate this by calculating how many numbers we -/// must reject: `reject = (MAX + 1) % range = (MAX - range + 1) % range`. Any (large) -/// product of `range` will suffice, thus in `sample_single` we multiply by a -/// power of 2 via bit-shifting (faster but may cause more rejections). -/// -/// The smallest integer PRNGs generate is `u32`. For 8- and 16-bit outputs we -/// use `u32` for our `zone` and samples (because it's not slower and because -/// it reduces the chance of having to reject a sample). In this case we cannot -/// store `zone` in the target type since it is too large, however we know -/// `ints_to_reject < range <= $unsigned::MAX`. -/// -/// An alternative to using a modulus is widening multiply: After a widening -/// multiply by `range`, the result is in the high word. Then comparing the low -/// word against `zone` makes sure our distribution is uniform. -#[derive(Clone, Copy, Debug)] -pub struct UniformInt { - low: X, - range: X, - z: X, // either ints_to_reject or zone depending on implementation -} - -macro_rules! uniform_int_impl { - ($ty:ty, $unsigned:ident, $u_large:ident) => { - impl SampleUniform for $ty { - type Sampler = UniformInt<$ty>; - } - - impl UniformSampler for UniformInt<$ty> { - // We play free and fast with unsigned vs signed here - // (when $ty is signed), but that's fine, since the - // contract of this macro is for $ty and $unsigned to be - // "bit-equal", so casting between them is a no-op. - - type X = $ty; - - #[inline] // if the range is constant, this helps LLVM to do the - // calculations at compile-time. - fn new(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low < high, "Uniform::new called with `low >= high`"); - UniformSampler::new_inclusive(low, high - 1) - } - - #[inline] // if the range is constant, this helps LLVM to do the - // calculations at compile-time. - fn new_inclusive(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low <= high, - "Uniform::new_inclusive called with `low > high`"); - let unsigned_max = ::core::$u_large::MAX; - - let range = high.wrapping_sub(low).wrapping_add(1) as $unsigned; - let ints_to_reject = - if range > 0 { - let range = $u_large::from(range); - (unsigned_max - range + 1) % range - } else { - 0 - }; - - UniformInt { - low: low, - // These are really $unsigned values, but store as $ty: - range: range as $ty, - z: ints_to_reject as $unsigned as $ty - } - } - - fn sample(&self, rng: &mut R) -> Self::X { - let range = self.range as $unsigned as $u_large; - if range > 0 { - let unsigned_max = ::core::$u_large::MAX; - let zone = unsigned_max - (self.z as $unsigned as $u_large); - loop { - let v: $u_large = rng.gen(); - let (hi, lo) = v.wmul(range); - if lo <= zone { - return self.low.wrapping_add(hi as $ty); - } - } - } else { - // Sample from the entire integer range. - rng.gen() - } - } - - fn sample_single(low_b: B1, high_b: B2, rng: &mut R) - -> Self::X - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low < high, - "UniformSampler::sample_single: low >= high"); - let range = high.wrapping_sub(low) as $unsigned as $u_large; - let zone = - if ::core::$unsigned::MAX <= ::core::u16::MAX as $unsigned { - // Using a modulus is faster than the approximation for - // i8 and i16. I suppose we trade the cost of one - // modulus for near-perfect branch prediction. - let unsigned_max: $u_large = ::core::$u_large::MAX; - let ints_to_reject = (unsigned_max - range + 1) % range; - unsigned_max - ints_to_reject - } else { - // conservative but fast approximation. `- 1` is necessary to allow the - // same comparison without bias. - (range << range.leading_zeros()).wrapping_sub(1) - }; - - loop { - let v: $u_large = rng.gen(); - let (hi, lo) = v.wmul(range); - if lo <= zone { - return low.wrapping_add(hi as $ty); - } - } - } - } - } -} - -uniform_int_impl! { i8, u8, u32 } -uniform_int_impl! { i16, u16, u32 } -uniform_int_impl! { i32, u32, u32 } -uniform_int_impl! { i64, u64, u64 } -#[cfg(not(target_os = "emscripten"))] -uniform_int_impl! { i128, u128, u128 } -uniform_int_impl! { isize, usize, usize } -uniform_int_impl! { u8, u8, u32 } -uniform_int_impl! { u16, u16, u32 } -uniform_int_impl! { u32, u32, u32 } -uniform_int_impl! { u64, u64, u64 } -uniform_int_impl! { usize, usize, usize } -#[cfg(not(target_os = "emscripten"))] -uniform_int_impl! { u128, u128, u128 } - -#[cfg(all(feature = "simd_support", feature = "nightly"))] -macro_rules! uniform_simd_int_impl { - ($ty:ident, $unsigned:ident, $u_scalar:ident) => { - // The "pick the largest zone that can fit in an `u32`" optimization - // is less useful here. Multiple lanes complicate things, we don't - // know the PRNG's minimal output size, and casting to a larger vector - // is generally a bad idea for SIMD performance. The user can still - // implement it manually. - - // TODO: look into `Uniform::::new(0u32, 100)` functionality - // perhaps `impl SampleUniform for $u_scalar`? - impl SampleUniform for $ty { - type Sampler = UniformInt<$ty>; - } - - impl UniformSampler for UniformInt<$ty> { - type X = $ty; - - #[inline] // if the range is constant, this helps LLVM to do the - // calculations at compile-time. - fn new(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low.lt(high).all(), "Uniform::new called with `low >= high`"); - UniformSampler::new_inclusive(low, high - 1) - } - - #[inline] // if the range is constant, this helps LLVM to do the - // calculations at compile-time. - fn new_inclusive(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low.le(high).all(), - "Uniform::new_inclusive called with `low > high`"); - let unsigned_max = ::core::$u_scalar::MAX; - - // NOTE: these may need to be replaced with explicitly - // wrapping operations if `packed_simd` changes - let range: $unsigned = ((high - low) + 1).cast(); - // `% 0` will panic at runtime. - let not_full_range = range.gt($unsigned::splat(0)); - // replacing 0 with `unsigned_max` allows a faster `select` - // with bitwise OR - let modulo = not_full_range.select(range, $unsigned::splat(unsigned_max)); - // wrapping addition - let ints_to_reject = (unsigned_max - range + 1) % modulo; - // When `range` is 0, `lo` of `v.wmul(range)` will always be - // zero which means only one sample is needed. - let zone = unsigned_max - ints_to_reject; - - UniformInt { - low: low, - // These are really $unsigned values, but store as $ty: - range: range.cast(), - z: zone.cast(), - } - } - - fn sample(&self, rng: &mut R) -> Self::X { - let range: $unsigned = self.range.cast(); - let zone: $unsigned = self.z.cast(); - - // This might seem very slow, generating a whole new - // SIMD vector for every sample rejection. For most uses - // though, the chance of rejection is small and provides good - // general performance. With multiple lanes, that chance is - // multiplied. To mitigate this, we replace only the lanes of - // the vector which fail, iteratively reducing the chance of - // rejection. The replacement method does however add a little - // overhead. Benchmarking or calculating probabilities might - // reveal contexts where this replacement method is slower. - let mut v: $unsigned = rng.gen(); - loop { - let (hi, lo) = v.wmul(range); - let mask = lo.le(zone); - if mask.all() { - let hi: $ty = hi.cast(); - // wrapping addition - let result = self.low + hi; - // `select` here compiles to a blend operation - // When `range.eq(0).none()` the compare and blend - // operations are avoided. - let v: $ty = v.cast(); - return range.gt($unsigned::splat(0)).select(result, v); - } - // Replace only the failing lanes - v = mask.select(v, rng.gen()); - } - } - } - }; - - // bulk implementation - ($(($unsigned:ident, $signed:ident),)+ $u_scalar:ident) => { - $( - uniform_simd_int_impl!($unsigned, $unsigned, $u_scalar); - uniform_simd_int_impl!($signed, $unsigned, $u_scalar); - )+ - }; -} - -#[cfg(all(feature = "simd_support", feature = "nightly"))] -uniform_simd_int_impl! { - (u64x2, i64x2), - (u64x4, i64x4), - (u64x8, i64x8), - u64 -} - -#[cfg(all(feature = "simd_support", feature = "nightly"))] -uniform_simd_int_impl! { - (u32x2, i32x2), - (u32x4, i32x4), - (u32x8, i32x8), - (u32x16, i32x16), - u32 -} - -#[cfg(all(feature = "simd_support", feature = "nightly"))] -uniform_simd_int_impl! { - (u16x2, i16x2), - (u16x4, i16x4), - (u16x8, i16x8), - (u16x16, i16x16), - (u16x32, i16x32), - u16 -} - -#[cfg(all(feature = "simd_support", feature = "nightly"))] -uniform_simd_int_impl! { - (u8x2, i8x2), - (u8x4, i8x4), - (u8x8, i8x8), - (u8x16, i8x16), - (u8x32, i8x32), - (u8x64, i8x64), - u8 -} - - -/// The back-end implementing [`UniformSampler`] for floating-point types. -/// -/// Unless you are implementing [`UniformSampler`] for your own type, this type -/// should not be used directly, use [`Uniform`] instead. -/// -/// # Implementation notes -/// -/// Instead of generating a float in the `[0, 1)` range using [`Standard`], the -/// `UniformFloat` implementation converts the output of an PRNG itself. This -/// way one or two steps can be optimized out. -/// -/// The floats are first converted to a value in the `[1, 2)` interval using a -/// transmute-based method, and then mapped to the expected range with a -/// multiply and addition. Values produced this way have what equals 22 bits of -/// random digits for an `f32`, and 52 for an `f64`. -/// -/// [`new`]: UniformSampler::new -/// [`new_inclusive`]: UniformSampler::new_inclusive -/// [`Standard`]: crate::distributions::Standard -#[derive(Clone, Copy, Debug)] -pub struct UniformFloat { - low: X, - scale: X, -} - -macro_rules! uniform_float_impl { - ($ty:ty, $uty:ident, $f_scalar:ident, $u_scalar:ident, $bits_to_discard:expr) => { - impl SampleUniform for $ty { - type Sampler = UniformFloat<$ty>; - } - - impl UniformSampler for UniformFloat<$ty> { - type X = $ty; - - fn new(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low.all_lt(high), - "Uniform::new called with `low >= high`"); - assert!(low.all_finite() && high.all_finite(), - "Uniform::new called with non-finite boundaries"); - let max_rand = <$ty>::splat((::core::$u_scalar::MAX >> $bits_to_discard) - .into_float_with_exponent(0) - 1.0); - - let mut scale = high - low; - - loop { - let mask = (scale * max_rand + low).ge_mask(high); - if mask.none() { - break; - } - scale = scale.decrease_masked(mask); - } - - debug_assert!(<$ty>::splat(0.0).all_le(scale)); - - UniformFloat { low, scale } - } - - fn new_inclusive(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low.all_le(high), - "Uniform::new_inclusive called with `low > high`"); - assert!(low.all_finite() && high.all_finite(), - "Uniform::new_inclusive called with non-finite boundaries"); - let max_rand = <$ty>::splat((::core::$u_scalar::MAX >> $bits_to_discard) - .into_float_with_exponent(0) - 1.0); - - let mut scale = (high - low) / max_rand; - - loop { - let mask = (scale * max_rand + low).gt_mask(high); - if mask.none() { - break; - } - scale = scale.decrease_masked(mask); - } - - debug_assert!(<$ty>::splat(0.0).all_le(scale)); - - UniformFloat { low, scale } - } - - fn sample(&self, rng: &mut R) -> Self::X { - // Generate a value in the range [1, 2) - let value1_2 = (rng.gen::<$uty>() >> $bits_to_discard) - .into_float_with_exponent(0); - - // Get a value in the range [0, 1) in order to avoid - // overflowing into infinity when multiplying with scale - let value0_1 = value1_2 - 1.0; - - // We don't use `f64::mul_add`, because it is not available with - // `no_std`. Furthermore, it is slower for some targets (but - // faster for others). However, the order of multiplication and - // addition is important, because on some platforms (e.g. ARM) - // it will be optimized to a single (non-FMA) instruction. - value0_1 * self.scale + self.low - } - - #[inline] - fn sample_single(low_b: B1, high_b: B2, rng: &mut R) - -> Self::X - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low.all_lt(high), - "UniformSampler::sample_single: low >= high"); - let mut scale = high - low; - - loop { - // Generate a value in the range [1, 2) - let value1_2 = (rng.gen::<$uty>() >> $bits_to_discard) - .into_float_with_exponent(0); - - // Get a value in the range [0, 1) in order to avoid - // overflowing into infinity when multiplying with scale - let value0_1 = value1_2 - 1.0; - - // Doing multiply before addition allows some architectures - // to use a single instruction. - let res = value0_1 * scale + low; - - debug_assert!(low.all_le(res) || !scale.all_finite()); - if res.all_lt(high) { - return res; - } - - // This handles a number of edge cases. - // * `low` or `high` is NaN. In this case `scale` and - // `res` are going to end up as NaN. - // * `low` is negative infinity and `high` is finite. - // `scale` is going to be infinite and `res` will be - // NaN. - // * `high` is positive infinity and `low` is finite. - // `scale` is going to be infinite and `res` will - // be infinite or NaN (if value0_1 is 0). - // * `low` is negative infinity and `high` is positive - // infinity. `scale` will be infinite and `res` will - // be NaN. - // * `low` and `high` are finite, but `high - low` - // overflows to infinite. `scale` will be infinite - // and `res` will be infinite or NaN (if value0_1 is 0). - // So if `high` or `low` are non-finite, we are guaranteed - // to fail the `res < high` check above and end up here. - // - // While we technically should check for non-finite `low` - // and `high` before entering the loop, by doing the checks - // here instead, we allow the common case to avoid these - // checks. But we are still guaranteed that if `low` or - // `high` are non-finite we'll end up here and can do the - // appropriate checks. - // - // Likewise `high - low` overflowing to infinity is also - // rare, so handle it here after the common case. - let mask = !scale.finite_mask(); - if mask.any() { - assert!(low.all_finite() && high.all_finite(), - "Uniform::sample_single: low and high must be finite"); - scale = scale.decrease_masked(mask); - } - } - } - } - } -} - -uniform_float_impl! { f32, u32, f32, u32, 32 - 23 } -uniform_float_impl! { f64, u64, f64, u64, 64 - 52 } - -#[cfg(feature="simd_support")] -uniform_float_impl! { f32x2, u32x2, f32, u32, 32 - 23 } -#[cfg(feature="simd_support")] -uniform_float_impl! { f32x4, u32x4, f32, u32, 32 - 23 } -#[cfg(feature="simd_support")] -uniform_float_impl! { f32x8, u32x8, f32, u32, 32 - 23 } -#[cfg(feature="simd_support")] -uniform_float_impl! { f32x16, u32x16, f32, u32, 32 - 23 } - -#[cfg(feature="simd_support")] -uniform_float_impl! { f64x2, u64x2, f64, u64, 64 - 52 } -#[cfg(feature="simd_support")] -uniform_float_impl! { f64x4, u64x4, f64, u64, 64 - 52 } -#[cfg(feature="simd_support")] -uniform_float_impl! { f64x8, u64x8, f64, u64, 64 - 52 } - - - -/// The back-end implementing [`UniformSampler`] for `Duration`. -/// -/// Unless you are implementing [`UniformSampler`] for your own types, this type -/// should not be used directly, use [`Uniform`] instead. -#[derive(Clone, Copy, Debug)] -pub struct UniformDuration { - mode: UniformDurationMode, - offset: u32, -} - -#[derive(Debug, Copy, Clone)] -enum UniformDurationMode { - Small { - secs: u64, - nanos: Uniform, - }, - Medium { - nanos: Uniform, - }, - Large { - max_secs: u64, - max_nanos: u32, - secs: Uniform, - } -} - -impl SampleUniform for Duration { - type Sampler = UniformDuration; -} - -impl UniformSampler for UniformDuration { - type X = Duration; - - #[inline] - fn new(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low < high, "Uniform::new called with `low >= high`"); - UniformDuration::new_inclusive(low, high - Duration::new(0, 1)) - } - - #[inline] - fn new_inclusive(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low <= high, "Uniform::new_inclusive called with `low > high`"); - - let low_s = low.as_secs(); - let low_n = low.subsec_nanos(); - let mut high_s = high.as_secs(); - let mut high_n = high.subsec_nanos(); - - if high_n < low_n { - high_s -= 1; - high_n += 1_000_000_000; - } - - let mode = if low_s == high_s { - UniformDurationMode::Small { - secs: low_s, - nanos: Uniform::new_inclusive(low_n, high_n), - } - } else { - let max = high_s - .checked_mul(1_000_000_000) - .and_then(|n| n.checked_add(u64::from(high_n))); - - if let Some(higher_bound) = max { - let lower_bound = low_s * 1_000_000_000 + u64::from(low_n); - UniformDurationMode::Medium { - nanos: Uniform::new_inclusive(lower_bound, higher_bound), - } - } else { - // An offset is applied to simplify generation of nanoseconds - let max_nanos = high_n - low_n; - UniformDurationMode::Large { - max_secs: high_s, - max_nanos, - secs: Uniform::new_inclusive(low_s, high_s), - } - } - }; - UniformDuration { - mode, - offset: low_n, - } - } - - #[inline] - fn sample(&self, rng: &mut R) -> Duration { - match self.mode { - UniformDurationMode::Small { secs, nanos } => { - let n = nanos.sample(rng); - Duration::new(secs, n) - } - UniformDurationMode::Medium { nanos } => { - let nanos = nanos.sample(rng); - Duration::new(nanos / 1_000_000_000, (nanos % 1_000_000_000) as u32) - } - UniformDurationMode::Large { max_secs, max_nanos, secs } => { - // constant folding means this is at least as fast as `gen_range` - let nano_range = Uniform::new(0, 1_000_000_000); - loop { - let s = secs.sample(rng); - let n = nano_range.sample(rng); - if !(s == max_secs && n > max_nanos) { - let sum = n + self.offset; - break Duration::new(s, sum); - } - } - } - } - } -} - -#[cfg(test)] -mod tests { - use crate::Rng; - use crate::rngs::mock::StepRng; - use crate::distributions::uniform::Uniform; - use crate::distributions::utils::FloatAsSIMD; - #[cfg(feature="simd_support")] use packed_simd::*; - - #[should_panic] - #[test] - fn test_uniform_bad_limits_equal_int() { - Uniform::new(10, 10); - } - - #[test] - fn test_uniform_good_limits_equal_int() { - let mut rng = crate::test::rng(804); - let dist = Uniform::new_inclusive(10, 10); - for _ in 0..20 { - assert_eq!(rng.sample(dist), 10); - } - } - - #[should_panic] - #[test] - fn test_uniform_bad_limits_flipped_int() { - Uniform::new(10, 5); - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_integers() { - use core::{i8, i16, i32, i64, isize}; - use core::{u8, u16, u32, u64, usize}; - #[cfg(not(target_os = "emscripten"))] - use core::{i128, u128}; - - let mut rng = crate::test::rng(251); - macro_rules! t { - ($ty:ident, $v:expr, $le:expr, $lt:expr) => {{ - for &(low, high) in $v.iter() { - let my_uniform = Uniform::new(low, high); - for _ in 0..1000 { - let v: $ty = rng.sample(my_uniform); - assert!($le(low, v) && $lt(v, high)); - } - - let my_uniform = Uniform::new_inclusive(low, high); - for _ in 0..1000 { - let v: $ty = rng.sample(my_uniform); - assert!($le(low, v) && $le(v, high)); - } - - let my_uniform = Uniform::new(&low, high); - for _ in 0..1000 { - let v: $ty = rng.sample(my_uniform); - assert!($le(low, v) && $lt(v, high)); - } - - let my_uniform = Uniform::new_inclusive(&low, &high); - for _ in 0..1000 { - let v: $ty = rng.sample(my_uniform); - assert!($le(low, v) && $le(v, high)); - } - - for _ in 0..1000 { - let v: $ty = rng.gen_range(low, high); - assert!($le(low, v) && $lt(v, high)); - } - } - }}; - - // scalar bulk - ($($ty:ident),*) => {{ - $(t!( - $ty, - [(0, 10), (10, 127), ($ty::MIN, $ty::MAX)], - |x, y| x <= y, - |x, y| x < y - );)* - }}; - - // simd bulk - ($($ty:ident),* => $scalar:ident) => {{ - $(t!( - $ty, - [ - ($ty::splat(0), $ty::splat(10)), - ($ty::splat(10), $ty::splat(127)), - ($ty::splat($scalar::MIN), $ty::splat($scalar::MAX)), - ], - |x: $ty, y| x.le(y).all(), - |x: $ty, y| x.lt(y).all() - );)* - }}; - } - t!(i8, i16, i32, i64, isize, - u8, u16, u32, u64, usize); - #[cfg(not(target_os = "emscripten"))] - t!(i128, u128); - - #[cfg(all(feature = "simd_support", feature = "nightly"))] - { - t!(u8x2, u8x4, u8x8, u8x16, u8x32, u8x64 => u8); - t!(i8x2, i8x4, i8x8, i8x16, i8x32, i8x64 => i8); - t!(u16x2, u16x4, u16x8, u16x16, u16x32 => u16); - t!(i16x2, i16x4, i16x8, i16x16, i16x32 => i16); - t!(u32x2, u32x4, u32x8, u32x16 => u32); - t!(i32x2, i32x4, i32x8, i32x16 => i32); - t!(u64x2, u64x4, u64x8 => u64); - t!(i64x2, i64x4, i64x8 => i64); - } - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_floats() { - let mut rng = crate::test::rng(252); - let mut zero_rng = StepRng::new(0, 0); - let mut max_rng = StepRng::new(0xffff_ffff_ffff_ffff, 0); - macro_rules! t { - ($ty:ty, $f_scalar:ident, $bits_shifted:expr) => {{ - let v: &[($f_scalar, $f_scalar)]= - &[(0.0, 100.0), - (-1e35, -1e25), - (1e-35, 1e-25), - (-1e35, 1e35), - (<$f_scalar>::from_bits(0), <$f_scalar>::from_bits(3)), - (-<$f_scalar>::from_bits(10), -<$f_scalar>::from_bits(1)), - (-<$f_scalar>::from_bits(5), 0.0), - (-<$f_scalar>::from_bits(7), -0.0), - (10.0, ::core::$f_scalar::MAX), - (-100.0, ::core::$f_scalar::MAX), - (-::core::$f_scalar::MAX / 5.0, ::core::$f_scalar::MAX), - (-::core::$f_scalar::MAX, ::core::$f_scalar::MAX / 5.0), - (-::core::$f_scalar::MAX * 0.8, ::core::$f_scalar::MAX * 0.7), - (-::core::$f_scalar::MAX, ::core::$f_scalar::MAX), - ]; - for &(low_scalar, high_scalar) in v.iter() { - for lane in 0..<$ty>::lanes() { - let low = <$ty>::splat(0.0 as $f_scalar).replace(lane, low_scalar); - let high = <$ty>::splat(1.0 as $f_scalar).replace(lane, high_scalar); - let my_uniform = Uniform::new(low, high); - let my_incl_uniform = Uniform::new_inclusive(low, high); - for _ in 0..100 { - let v = rng.sample(my_uniform).extract(lane); - assert!(low_scalar <= v && v < high_scalar); - let v = rng.sample(my_incl_uniform).extract(lane); - assert!(low_scalar <= v && v <= high_scalar); - let v = rng.gen_range(low, high).extract(lane); - assert!(low_scalar <= v && v < high_scalar); - } - - assert_eq!(rng.sample(Uniform::new_inclusive(low, low)).extract(lane), low_scalar); - - assert_eq!(zero_rng.sample(my_uniform).extract(lane), low_scalar); - assert_eq!(zero_rng.sample(my_incl_uniform).extract(lane), low_scalar); - assert_eq!(zero_rng.gen_range(low, high).extract(lane), low_scalar); - assert!(max_rng.sample(my_uniform).extract(lane) < high_scalar); - assert!(max_rng.sample(my_incl_uniform).extract(lane) <= high_scalar); - - // Don't run this test for really tiny differences between high and low - // since for those rounding might result in selecting high for a very - // long time. - if (high_scalar - low_scalar) > 0.0001 { - let mut lowering_max_rng = - StepRng::new(0xffff_ffff_ffff_ffff, - (-1i64 << $bits_shifted) as u64); - assert!(lowering_max_rng.gen_range(low, high).extract(lane) < high_scalar); - } - } - } - - assert_eq!(rng.sample(Uniform::new_inclusive(::core::$f_scalar::MAX, - ::core::$f_scalar::MAX)), - ::core::$f_scalar::MAX); - assert_eq!(rng.sample(Uniform::new_inclusive(-::core::$f_scalar::MAX, - -::core::$f_scalar::MAX)), - -::core::$f_scalar::MAX); - }} - } - - t!(f32, f32, 32 - 23); - t!(f64, f64, 64 - 52); - #[cfg(feature="simd_support")] - { - t!(f32x2, f32, 32 - 23); - t!(f32x4, f32, 32 - 23); - t!(f32x8, f32, 32 - 23); - t!(f32x16, f32, 32 - 23); - t!(f64x2, f64, 64 - 52); - t!(f64x4, f64, 64 - 52); - t!(f64x8, f64, 64 - 52); - } - } - - #[test] - #[cfg(all(feature="std", - not(target_arch = "wasm32"), - not(target_arch = "asmjs")))] - #[cfg(not(miri))] // Miri does not support catching panics - fn test_float_assertions() { - use std::panic::catch_unwind; - use super::SampleUniform; - fn range(low: T, high: T) { - let mut rng = crate::test::rng(253); - rng.gen_range(low, high); - } - - macro_rules! t { - ($ty:ident, $f_scalar:ident) => {{ - let v: &[($f_scalar, $f_scalar)] = - &[(::std::$f_scalar::NAN, 0.0), - (1.0, ::std::$f_scalar::NAN), - (::std::$f_scalar::NAN, ::std::$f_scalar::NAN), - (1.0, 0.5), - (::std::$f_scalar::MAX, -::std::$f_scalar::MAX), - (::std::$f_scalar::INFINITY, ::std::$f_scalar::INFINITY), - (::std::$f_scalar::NEG_INFINITY, ::std::$f_scalar::NEG_INFINITY), - (::std::$f_scalar::NEG_INFINITY, 5.0), - (5.0, ::std::$f_scalar::INFINITY), - (::std::$f_scalar::NAN, ::std::$f_scalar::INFINITY), - (::std::$f_scalar::NEG_INFINITY, ::std::$f_scalar::NAN), - (::std::$f_scalar::NEG_INFINITY, ::std::$f_scalar::INFINITY), - ]; - for &(low_scalar, high_scalar) in v.iter() { - for lane in 0..<$ty>::lanes() { - let low = <$ty>::splat(0.0 as $f_scalar).replace(lane, low_scalar); - let high = <$ty>::splat(1.0 as $f_scalar).replace(lane, high_scalar); - assert!(catch_unwind(|| range(low, high)).is_err()); - assert!(catch_unwind(|| Uniform::new(low, high)).is_err()); - assert!(catch_unwind(|| Uniform::new_inclusive(low, high)).is_err()); - assert!(catch_unwind(|| range(low, low)).is_err()); - assert!(catch_unwind(|| Uniform::new(low, low)).is_err()); - } - } - }} - } - - t!(f32, f32); - t!(f64, f64); - #[cfg(feature="simd_support")] - { - t!(f32x2, f32); - t!(f32x4, f32); - t!(f32x8, f32); - t!(f32x16, f32); - t!(f64x2, f64); - t!(f64x4, f64); - t!(f64x8, f64); - } - } - - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_durations() { - #[cfg(feature = "std")] - use std::time::Duration; - #[cfg(not(feature = "std"))] - use core::time::Duration; - - let mut rng = crate::test::rng(253); - - let v = &[(Duration::new(10, 50000), Duration::new(100, 1234)), - (Duration::new(0, 100), Duration::new(1, 50)), - (Duration::new(0, 0), Duration::new(u64::max_value(), 999_999_999))]; - for &(low, high) in v.iter() { - let my_uniform = Uniform::new(low, high); - for _ in 0..1000 { - let v = rng.sample(my_uniform); - assert!(low <= v && v < high); - } - } - } - - #[test] - fn test_custom_uniform() { - use crate::distributions::uniform::{UniformSampler, UniformFloat, SampleUniform, SampleBorrow}; - #[derive(Clone, Copy, PartialEq, PartialOrd)] - struct MyF32 { - x: f32, - } - #[derive(Clone, Copy, Debug)] - struct UniformMyF32 { - inner: UniformFloat, - } - impl UniformSampler for UniformMyF32 { - type X = MyF32; - fn new(low: B1, high: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - UniformMyF32 { - inner: UniformFloat::::new(low.borrow().x, high.borrow().x), - } - } - fn new_inclusive(low: B1, high: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - UniformSampler::new(low, high) - } - fn sample(&self, rng: &mut R) -> Self::X { - MyF32 { x: self.inner.sample(rng) } - } - } - impl SampleUniform for MyF32 { - type Sampler = UniformMyF32; - } - - let (low, high) = (MyF32{ x: 17.0f32 }, MyF32{ x: 22.0f32 }); - let uniform = Uniform::new(low, high); - let mut rng = crate::test::rng(804); - for _ in 0..100 { - let x: MyF32 = rng.sample(uniform); - assert!(low <= x && x < high); - } - } - - #[test] - fn test_uniform_from_std_range() { - let r = Uniform::from(2u32..7); - assert_eq!(r.inner.low, 2); - assert_eq!(r.inner.range, 5); - let r = Uniform::from(2.0f64..7.0); - assert_eq!(r.inner.low, 2.0); - assert_eq!(r.inner.scale, 5.0); - } - - #[test] - fn test_uniform_from_std_range_inclusive() { - let r = Uniform::from(2u32..=6); - assert_eq!(r.inner.low, 2); - assert_eq!(r.inner.range, 5); - let r = Uniform::from(2.0f64..=7.0); - assert_eq!(r.inner.low, 2.0); - assert!(r.inner.scale > 5.0); - assert!(r.inner.scale < 5.0 + 1e-14); - } -} diff --git a/rand/src/distributions/unit_circle.rs b/rand/src/distributions/unit_circle.rs deleted file mode 100644 index 56e75b6..0000000 --- a/rand/src/distributions/unit_circle.rs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(deprecated)] -#![allow(clippy::all)] - -use crate::Rng; -use crate::distributions::{Distribution, Uniform}; - -/// Samples uniformly from the edge of the unit circle in two dimensions. -/// -/// Implemented via a method by von Neumann[^1]. -/// -/// [^1]: von Neumann, J. (1951) [*Various Techniques Used in Connection with -/// Random Digits.*](https://mcnp.lanl.gov/pdf_files/nbs_vonneumann.pdf) -/// NBS Appl. Math. Ser., No. 12. Washington, DC: U.S. Government Printing -/// Office, pp. 36-38. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct UnitCircle; - -impl UnitCircle { - /// Construct a new `UnitCircle` distribution. - #[inline] - pub fn new() -> UnitCircle { - UnitCircle - } -} - -impl Distribution<[f64; 2]> for UnitCircle { - #[inline] - fn sample(&self, rng: &mut R) -> [f64; 2] { - let uniform = Uniform::new(-1., 1.); - let mut x1; - let mut x2; - let mut sum; - loop { - x1 = uniform.sample(rng); - x2 = uniform.sample(rng); - sum = x1*x1 + x2*x2; - if sum < 1. { - break; - } - } - let diff = x1*x1 - x2*x2; - [diff / sum, 2.*x1*x2 / sum] - } -} - -#[cfg(test)] -mod tests { - use crate::distributions::Distribution; - use super::UnitCircle; - - /// Assert that two numbers are almost equal to each other. - /// - /// On panic, this macro will print the values of the expressions with their - /// debug representations. - macro_rules! assert_almost_eq { - ($a:expr, $b:expr, $prec:expr) => ( - let diff = ($a - $b).abs(); - if diff > $prec { - panic!(format!( - "assertion failed: `abs(left - right) = {:.1e} < {:e}`, \ - (left: `{}`, right: `{}`)", - diff, $prec, $a, $b)); - } - ); - } - - #[test] - fn norm() { - let mut rng = crate::test::rng(1); - let dist = UnitCircle::new(); - for _ in 0..1000 { - let x = dist.sample(&mut rng); - assert_almost_eq!(x[0]*x[0] + x[1]*x[1], 1., 1e-15); - } - } - - #[test] - fn value_stability() { - let mut rng = crate::test::rng(2); - let expected = [ - [-0.9965658683520504, -0.08280380447614634], - [-0.9790853270389644, -0.20345004884984505], - [-0.8449189758898707, 0.5348943112253227], - ]; - let samples = [ - UnitCircle.sample(&mut rng), - UnitCircle.sample(&mut rng), - UnitCircle.sample(&mut rng), - ]; - assert_eq!(samples, expected); - } -} diff --git a/rand/src/distributions/unit_sphere.rs b/rand/src/distributions/unit_sphere.rs deleted file mode 100644 index 188f48c..0000000 --- a/rand/src/distributions/unit_sphere.rs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(deprecated)] -#![allow(clippy::all)] - -use crate::Rng; -use crate::distributions::{Distribution, Uniform}; - -/// Samples uniformly from the surface of the unit sphere in three dimensions. -/// -/// Implemented via a method by Marsaglia[^1]. -/// -/// [^1]: Marsaglia, George (1972). [*Choosing a Point from the Surface of a -/// Sphere.*](https://doi.org/10.1214/aoms/1177692644) -/// Ann. Math. Statist. 43, no. 2, 645--646. -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct UnitSphereSurface; - -impl UnitSphereSurface { - /// Construct a new `UnitSphereSurface` distribution. - #[inline] - pub fn new() -> UnitSphereSurface { - UnitSphereSurface - } -} - -impl Distribution<[f64; 3]> for UnitSphereSurface { - #[inline] - fn sample(&self, rng: &mut R) -> [f64; 3] { - let uniform = Uniform::new(-1., 1.); - loop { - let (x1, x2) = (uniform.sample(rng), uniform.sample(rng)); - let sum = x1*x1 + x2*x2; - if sum >= 1. { - continue; - } - let factor = 2. * (1.0_f64 - sum).sqrt(); - return [x1 * factor, x2 * factor, 1. - 2.*sum]; - } - } -} - -#[cfg(test)] -mod tests { - use crate::distributions::Distribution; - use super::UnitSphereSurface; - - /// Assert that two numbers are almost equal to each other. - /// - /// On panic, this macro will print the values of the expressions with their - /// debug representations. - macro_rules! assert_almost_eq { - ($a:expr, $b:expr, $prec:expr) => ( - let diff = ($a - $b).abs(); - if diff > $prec { - panic!(format!( - "assertion failed: `abs(left - right) = {:.1e} < {:e}`, \ - (left: `{}`, right: `{}`)", - diff, $prec, $a, $b)); - } - ); - } - - #[test] - fn norm() { - let mut rng = crate::test::rng(1); - let dist = UnitSphereSurface::new(); - for _ in 0..1000 { - let x = dist.sample(&mut rng); - assert_almost_eq!(x[0]*x[0] + x[1]*x[1] + x[2]*x[2], 1., 1e-15); - } - } - - #[test] - fn value_stability() { - let mut rng = crate::test::rng(2); - let expected = [ - [0.03247542860231647, -0.7830477442152738, 0.6211131755296027], - [-0.09978440840914075, 0.9706650829833128, -0.21875184231323952], - [0.2735582468624679, 0.9435374242279655, -0.1868234852870203], - ]; - let samples = [ - UnitSphereSurface.sample(&mut rng), - UnitSphereSurface.sample(&mut rng), - UnitSphereSurface.sample(&mut rng), - ]; - assert_eq!(samples, expected); - } -} diff --git a/rand/src/distributions/utils.rs b/rand/src/distributions/utils.rs deleted file mode 100644 index 3af4e86..0000000 --- a/rand/src/distributions/utils.rs +++ /dev/null @@ -1,488 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Math helper functions - -#[cfg(feature="simd_support")] -use packed_simd::*; -#[cfg(feature="std")] -use crate::distributions::ziggurat_tables; -#[cfg(feature="std")] -use crate::Rng; - - -pub trait WideningMultiply { - type Output; - - fn wmul(self, x: RHS) -> Self::Output; -} - -macro_rules! wmul_impl { - ($ty:ty, $wide:ty, $shift:expr) => { - impl WideningMultiply for $ty { - type Output = ($ty, $ty); - - #[inline(always)] - fn wmul(self, x: $ty) -> Self::Output { - let tmp = (self as $wide) * (x as $wide); - ((tmp >> $shift) as $ty, tmp as $ty) - } - } - }; - - // simd bulk implementation - ($(($ty:ident, $wide:ident),)+, $shift:expr) => { - $( - impl WideningMultiply for $ty { - type Output = ($ty, $ty); - - #[inline(always)] - fn wmul(self, x: $ty) -> Self::Output { - // For supported vectors, this should compile to a couple - // supported multiply & swizzle instructions (no actual - // casting). - // TODO: optimize - let y: $wide = self.cast(); - let x: $wide = x.cast(); - let tmp = y * x; - let hi: $ty = (tmp >> $shift).cast(); - let lo: $ty = tmp.cast(); - (hi, lo) - } - } - )+ - }; -} -wmul_impl! { u8, u16, 8 } -wmul_impl! { u16, u32, 16 } -wmul_impl! { u32, u64, 32 } -#[cfg(not(target_os = "emscripten"))] -wmul_impl! { u64, u128, 64 } - -// This code is a translation of the __mulddi3 function in LLVM's -// compiler-rt. It is an optimised variant of the common method -// `(a + b) * (c + d) = ac + ad + bc + bd`. -// -// For some reason LLVM can optimise the C version very well, but -// keeps shuffling registers in this Rust translation. -macro_rules! wmul_impl_large { - ($ty:ty, $half:expr) => { - impl WideningMultiply for $ty { - type Output = ($ty, $ty); - - #[inline(always)] - fn wmul(self, b: $ty) -> Self::Output { - const LOWER_MASK: $ty = !0 >> $half; - let mut low = (self & LOWER_MASK).wrapping_mul(b & LOWER_MASK); - let mut t = low >> $half; - low &= LOWER_MASK; - t += (self >> $half).wrapping_mul(b & LOWER_MASK); - low += (t & LOWER_MASK) << $half; - let mut high = t >> $half; - t = low >> $half; - low &= LOWER_MASK; - t += (b >> $half).wrapping_mul(self & LOWER_MASK); - low += (t & LOWER_MASK) << $half; - high += t >> $half; - high += (self >> $half).wrapping_mul(b >> $half); - - (high, low) - } - } - }; - - // simd bulk implementation - (($($ty:ty,)+) $scalar:ty, $half:expr) => { - $( - impl WideningMultiply for $ty { - type Output = ($ty, $ty); - - #[inline(always)] - fn wmul(self, b: $ty) -> Self::Output { - // needs wrapping multiplication - const LOWER_MASK: $scalar = !0 >> $half; - let mut low = (self & LOWER_MASK) * (b & LOWER_MASK); - let mut t = low >> $half; - low &= LOWER_MASK; - t += (self >> $half) * (b & LOWER_MASK); - low += (t & LOWER_MASK) << $half; - let mut high = t >> $half; - t = low >> $half; - low &= LOWER_MASK; - t += (b >> $half) * (self & LOWER_MASK); - low += (t & LOWER_MASK) << $half; - high += t >> $half; - high += (self >> $half) * (b >> $half); - - (high, low) - } - } - )+ - }; -} -#[cfg(target_os = "emscripten")] -wmul_impl_large! { u64, 32 } -#[cfg(not(target_os = "emscripten"))] -wmul_impl_large! { u128, 64 } - -macro_rules! wmul_impl_usize { - ($ty:ty) => { - impl WideningMultiply for usize { - type Output = (usize, usize); - - #[inline(always)] - fn wmul(self, x: usize) -> Self::Output { - let (high, low) = (self as $ty).wmul(x as $ty); - (high as usize, low as usize) - } - } - } -} -#[cfg(target_pointer_width = "32")] -wmul_impl_usize! { u32 } -#[cfg(target_pointer_width = "64")] -wmul_impl_usize! { u64 } - -#[cfg(all(feature = "simd_support", feature = "nightly"))] -mod simd_wmul { - #[cfg(target_arch = "x86")] - use core::arch::x86::*; - #[cfg(target_arch = "x86_64")] - use core::arch::x86_64::*; - use super::*; - - wmul_impl! { - (u8x2, u16x2), - (u8x4, u16x4), - (u8x8, u16x8), - (u8x16, u16x16), - (u8x32, u16x32),, - 8 - } - - wmul_impl! { (u16x2, u32x2),, 16 } - #[cfg(not(target_feature = "sse2"))] - wmul_impl! { (u16x4, u32x4),, 16 } - #[cfg(not(target_feature = "sse4.2"))] - wmul_impl! { (u16x8, u32x8),, 16 } - #[cfg(not(target_feature = "avx2"))] - wmul_impl! { (u16x16, u32x16),, 16 } - - // 16-bit lane widths allow use of the x86 `mulhi` instructions, which - // means `wmul` can be implemented with only two instructions. - #[allow(unused_macros)] - macro_rules! wmul_impl_16 { - ($ty:ident, $intrinsic:ident, $mulhi:ident, $mullo:ident) => { - impl WideningMultiply for $ty { - type Output = ($ty, $ty); - - #[inline(always)] - fn wmul(self, x: $ty) -> Self::Output { - let b = $intrinsic::from_bits(x); - let a = $intrinsic::from_bits(self); - let hi = $ty::from_bits(unsafe { $mulhi(a, b) }); - let lo = $ty::from_bits(unsafe { $mullo(a, b) }); - (hi, lo) - } - } - }; - } - - #[cfg(target_feature = "sse2")] - wmul_impl_16! { u16x4, __m64, _mm_mulhi_pu16, _mm_mullo_pi16 } - #[cfg(target_feature = "sse4.2")] - wmul_impl_16! { u16x8, __m128i, _mm_mulhi_epu16, _mm_mullo_epi16 } - #[cfg(target_feature = "avx2")] - wmul_impl_16! { u16x16, __m256i, _mm256_mulhi_epu16, _mm256_mullo_epi16 } - // FIXME: there are no `__m512i` types in stdsimd yet, so `wmul::` - // cannot use the same implementation. - - wmul_impl! { - (u32x2, u64x2), - (u32x4, u64x4), - (u32x8, u64x8),, - 32 - } - - // TODO: optimize, this seems to seriously slow things down - wmul_impl_large! { (u8x64,) u8, 4 } - wmul_impl_large! { (u16x32,) u16, 8 } - wmul_impl_large! { (u32x16,) u32, 16 } - wmul_impl_large! { (u64x2, u64x4, u64x8,) u64, 32 } -} -#[cfg(all(feature = "simd_support", feature = "nightly"))] -pub use self::simd_wmul::*; - - -/// Helper trait when dealing with scalar and SIMD floating point types. -pub(crate) trait FloatSIMDUtils { - // `PartialOrd` for vectors compares lexicographically. We want to compare all - // the individual SIMD lanes instead, and get the combined result over all - // lanes. This is possible using something like `a.lt(b).all()`, but we - // implement it as a trait so we can write the same code for `f32` and `f64`. - // Only the comparison functions we need are implemented. - fn all_lt(self, other: Self) -> bool; - fn all_le(self, other: Self) -> bool; - fn all_finite(self) -> bool; - - type Mask; - fn finite_mask(self) -> Self::Mask; - fn gt_mask(self, other: Self) -> Self::Mask; - fn ge_mask(self, other: Self) -> Self::Mask; - - // Decrease all lanes where the mask is `true` to the next lower value - // representable by the floating-point type. At least one of the lanes - // must be set. - fn decrease_masked(self, mask: Self::Mask) -> Self; - - // Convert from int value. Conversion is done while retaining the numerical - // value, not by retaining the binary representation. - type UInt; - fn cast_from_int(i: Self::UInt) -> Self; -} - -/// Implement functions available in std builds but missing from core primitives -#[cfg(not(std))] -pub(crate) trait Float : Sized { - fn is_nan(self) -> bool; - fn is_infinite(self) -> bool; - fn is_finite(self) -> bool; -} - -/// Implement functions on f32/f64 to give them APIs similar to SIMD types -pub(crate) trait FloatAsSIMD : Sized { - #[inline(always)] - fn lanes() -> usize { 1 } - #[inline(always)] - fn splat(scalar: Self) -> Self { scalar } - #[inline(always)] - fn extract(self, index: usize) -> Self { debug_assert_eq!(index, 0); self } - #[inline(always)] - fn replace(self, index: usize, new_value: Self) -> Self { debug_assert_eq!(index, 0); new_value } -} - -pub(crate) trait BoolAsSIMD : Sized { - fn any(self) -> bool; - fn all(self) -> bool; - fn none(self) -> bool; -} - -impl BoolAsSIMD for bool { - #[inline(always)] - fn any(self) -> bool { self } - #[inline(always)] - fn all(self) -> bool { self } - #[inline(always)] - fn none(self) -> bool { !self } -} - -macro_rules! scalar_float_impl { - ($ty:ident, $uty:ident) => { - #[cfg(not(std))] - impl Float for $ty { - #[inline] - fn is_nan(self) -> bool { - self != self - } - - #[inline] - fn is_infinite(self) -> bool { - self == ::core::$ty::INFINITY || self == ::core::$ty::NEG_INFINITY - } - - #[inline] - fn is_finite(self) -> bool { - !(self.is_nan() || self.is_infinite()) - } - } - - impl FloatSIMDUtils for $ty { - type Mask = bool; - #[inline(always)] - fn all_lt(self, other: Self) -> bool { self < other } - #[inline(always)] - fn all_le(self, other: Self) -> bool { self <= other } - #[inline(always)] - fn all_finite(self) -> bool { self.is_finite() } - #[inline(always)] - fn finite_mask(self) -> Self::Mask { self.is_finite() } - #[inline(always)] - fn gt_mask(self, other: Self) -> Self::Mask { self > other } - #[inline(always)] - fn ge_mask(self, other: Self) -> Self::Mask { self >= other } - #[inline(always)] - fn decrease_masked(self, mask: Self::Mask) -> Self { - debug_assert!(mask, "At least one lane must be set"); - <$ty>::from_bits(self.to_bits() - 1) - } - type UInt = $uty; - fn cast_from_int(i: Self::UInt) -> Self { i as $ty } - } - - impl FloatAsSIMD for $ty {} - } -} - -scalar_float_impl!(f32, u32); -scalar_float_impl!(f64, u64); - - -#[cfg(feature="simd_support")] -macro_rules! simd_impl { - ($ty:ident, $f_scalar:ident, $mty:ident, $uty:ident) => { - impl FloatSIMDUtils for $ty { - type Mask = $mty; - #[inline(always)] - fn all_lt(self, other: Self) -> bool { self.lt(other).all() } - #[inline(always)] - fn all_le(self, other: Self) -> bool { self.le(other).all() } - #[inline(always)] - fn all_finite(self) -> bool { self.finite_mask().all() } - #[inline(always)] - fn finite_mask(self) -> Self::Mask { - // This can possibly be done faster by checking bit patterns - let neg_inf = $ty::splat(::core::$f_scalar::NEG_INFINITY); - let pos_inf = $ty::splat(::core::$f_scalar::INFINITY); - self.gt(neg_inf) & self.lt(pos_inf) - } - #[inline(always)] - fn gt_mask(self, other: Self) -> Self::Mask { self.gt(other) } - #[inline(always)] - fn ge_mask(self, other: Self) -> Self::Mask { self.ge(other) } - #[inline(always)] - fn decrease_masked(self, mask: Self::Mask) -> Self { - // Casting a mask into ints will produce all bits set for - // true, and 0 for false. Adding that to the binary - // representation of a float means subtracting one from - // the binary representation, resulting in the next lower - // value representable by $ty. This works even when the - // current value is infinity. - debug_assert!(mask.any(), "At least one lane must be set"); - <$ty>::from_bits(<$uty>::from_bits(self) + <$uty>::from_bits(mask)) - } - type UInt = $uty; - #[inline] - fn cast_from_int(i: Self::UInt) -> Self { i.cast() } - } - } -} - -#[cfg(feature="simd_support")] simd_impl! { f32x2, f32, m32x2, u32x2 } -#[cfg(feature="simd_support")] simd_impl! { f32x4, f32, m32x4, u32x4 } -#[cfg(feature="simd_support")] simd_impl! { f32x8, f32, m32x8, u32x8 } -#[cfg(feature="simd_support")] simd_impl! { f32x16, f32, m32x16, u32x16 } -#[cfg(feature="simd_support")] simd_impl! { f64x2, f64, m64x2, u64x2 } -#[cfg(feature="simd_support")] simd_impl! { f64x4, f64, m64x4, u64x4 } -#[cfg(feature="simd_support")] simd_impl! { f64x8, f64, m64x8, u64x8 } - -/// Calculates ln(gamma(x)) (natural logarithm of the gamma -/// function) using the Lanczos approximation. -/// -/// The approximation expresses the gamma function as: -/// `gamma(z+1) = sqrt(2*pi)*(z+g+0.5)^(z+0.5)*exp(-z-g-0.5)*Ag(z)` -/// `g` is an arbitrary constant; we use the approximation with `g=5`. -/// -/// Noting that `gamma(z+1) = z*gamma(z)` and applying `ln` to both sides: -/// `ln(gamma(z)) = (z+0.5)*ln(z+g+0.5)-(z+g+0.5) + ln(sqrt(2*pi)*Ag(z)/z)` -/// -/// `Ag(z)` is an infinite series with coefficients that can be calculated -/// ahead of time - we use just the first 6 terms, which is good enough -/// for most purposes. -#[cfg(feature="std")] -pub fn log_gamma(x: f64) -> f64 { - // precalculated 6 coefficients for the first 6 terms of the series - let coefficients: [f64; 6] = [ - 76.18009172947146, - -86.50532032941677, - 24.01409824083091, - -1.231739572450155, - 0.1208650973866179e-2, - -0.5395239384953e-5, - ]; - - // (x+0.5)*ln(x+g+0.5)-(x+g+0.5) - let tmp = x + 5.5; - let log = (x + 0.5) * tmp.ln() - tmp; - - // the first few terms of the series for Ag(x) - let mut a = 1.000000000190015; - let mut denom = x; - for coeff in &coefficients { - denom += 1.0; - a += coeff / denom; - } - - // get everything together - // a is Ag(x) - // 2.5066... is sqrt(2pi) - log + (2.5066282746310005 * a / x).ln() -} - -/// Sample a random number using the Ziggurat method (specifically the -/// ZIGNOR variant from Doornik 2005). Most of the arguments are -/// directly from the paper: -/// -/// * `rng`: source of randomness -/// * `symmetric`: whether this is a symmetric distribution, or one-sided with P(x < 0) = 0. -/// * `X`: the $x_i$ abscissae. -/// * `F`: precomputed values of the PDF at the $x_i$, (i.e. $f(x_i)$) -/// * `F_DIFF`: precomputed values of $f(x_i) - f(x_{i+1})$ -/// * `pdf`: the probability density function -/// * `zero_case`: manual sampling from the tail when we chose the -/// bottom box (i.e. i == 0) - -// the perf improvement (25-50%) is definitely worth the extra code -// size from force-inlining. -#[cfg(feature="std")] -#[inline(always)] -pub fn ziggurat( - rng: &mut R, - symmetric: bool, - x_tab: ziggurat_tables::ZigTable, - f_tab: ziggurat_tables::ZigTable, - mut pdf: P, - mut zero_case: Z) - -> f64 where P: FnMut(f64) -> f64, Z: FnMut(&mut R, f64) -> f64 { - use crate::distributions::float::IntoFloat; - loop { - // As an optimisation we re-implement the conversion to a f64. - // From the remaining 12 most significant bits we use 8 to construct `i`. - // This saves us generating a whole extra random number, while the added - // precision of using 64 bits for f64 does not buy us much. - let bits = rng.next_u64(); - let i = bits as usize & 0xff; - - let u = if symmetric { - // Convert to a value in the range [2,4) and substract to get [-1,1) - // We can't convert to an open range directly, that would require - // substracting `3.0 - EPSILON`, which is not representable. - // It is possible with an extra step, but an open range does not - // seem neccesary for the ziggurat algorithm anyway. - (bits >> 12).into_float_with_exponent(1) - 3.0 - } else { - // Convert to a value in the range [1,2) and substract to get (0,1) - (bits >> 12).into_float_with_exponent(0) - - (1.0 - ::core::f64::EPSILON / 2.0) - }; - let x = u * x_tab[i]; - - let test_x = if symmetric { x.abs() } else {x}; - - // algebraically equivalent to |u| < x_tab[i+1]/x_tab[i] (or u < x_tab[i+1]/x_tab[i]) - if test_x < x_tab[i + 1] { - return x; - } - if i == 0 { - return zero_case(rng, u); - } - // algebraically equivalent to f1 + DRanU()*(f0 - f1) < 1 - if f_tab[i + 1] + (f_tab[i] - f_tab[i + 1]) * rng.gen::() < pdf(x) { - return x; - } - } -} diff --git a/rand/src/distributions/weibull.rs b/rand/src/distributions/weibull.rs deleted file mode 100644 index 483714f..0000000 --- a/rand/src/distributions/weibull.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Weibull distribution. -#![allow(deprecated)] - -use crate::Rng; -use crate::distributions::{Distribution, OpenClosed01}; - -/// Samples floating-point numbers according to the Weibull distribution -#[deprecated(since="0.7.0", note="moved to rand_distr crate")] -#[derive(Clone, Copy, Debug)] -pub struct Weibull { - inv_shape: f64, - scale: f64, -} - -impl Weibull { - /// Construct a new `Weibull` distribution with given `scale` and `shape`. - /// - /// # Panics - /// - /// `scale` and `shape` have to be non-zero and positive. - pub fn new(scale: f64, shape: f64) -> Weibull { - assert!((scale > 0.) & (shape > 0.)); - Weibull { inv_shape: 1./shape, scale } - } -} - -impl Distribution for Weibull { - fn sample(&self, rng: &mut R) -> f64 { - let x: f64 = rng.sample(OpenClosed01); - self.scale * (-x.ln()).powf(self.inv_shape) - } -} - -#[cfg(test)] -mod tests { - use crate::distributions::Distribution; - use super::Weibull; - - #[test] - #[should_panic] - fn invalid() { - Weibull::new(0., 0.); - } - - #[test] - fn sample() { - let scale = 1.0; - let shape = 2.0; - let d = Weibull::new(scale, shape); - let mut rng = crate::test::rng(1); - for _ in 0..1000 { - let r = d.sample(&mut rng); - assert!(r >= 0.); - } - } -} diff --git a/rand/src/distributions/weighted/alias_method.rs b/rand/src/distributions/weighted/alias_method.rs deleted file mode 100644 index bdd4ba0..0000000 --- a/rand/src/distributions/weighted/alias_method.rs +++ /dev/null @@ -1,499 +0,0 @@ -//! This module contains an implementation of alias method for sampling random -//! indices with probabilities proportional to a collection of weights. - -use super::WeightedError; -#[cfg(not(feature = "std"))] -use crate::alloc::vec::Vec; -#[cfg(not(feature = "std"))] -use crate::alloc::vec; -use core::fmt; -use core::iter::Sum; -use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; -use crate::distributions::uniform::SampleUniform; -use crate::distributions::Distribution; -use crate::distributions::Uniform; -use crate::Rng; - -/// A distribution using weighted sampling to pick a discretely selected item. -/// -/// Sampling a [`WeightedIndex`] distribution returns the index of a randomly -/// selected element from the vector used to create the [`WeightedIndex`]. -/// The chance of a given element being picked is proportional to the value of -/// the element. The weights can have any type `W` for which a implementation of -/// [`Weight`] exists. -/// -/// # Performance -/// -/// Given that `n` is the number of items in the vector used to create an -/// [`WeightedIndex`], [`WeightedIndex`] will require `O(n)` amount of -/// memory. More specifically it takes up some constant amount of memory plus -/// the vector used to create it and a [`Vec`] with capacity `n`. -/// -/// Time complexity for the creation of a [`WeightedIndex`] is `O(n)`. -/// Sampling is `O(1)`, it makes a call to [`Uniform::sample`] and a call -/// to [`Uniform::sample`]. -/// -/// # Example -/// -/// ``` -/// use rand::distributions::weighted::alias_method::WeightedIndex; -/// use rand::prelude::*; -/// -/// let choices = vec!['a', 'b', 'c']; -/// let weights = vec![2, 1, 1]; -/// let dist = WeightedIndex::new(weights).unwrap(); -/// let mut rng = thread_rng(); -/// for _ in 0..100 { -/// // 50% chance to print 'a', 25% chance to print 'b', 25% chance to print 'c' -/// println!("{}", choices[dist.sample(&mut rng)]); -/// } -/// -/// let items = [('a', 0), ('b', 3), ('c', 7)]; -/// let dist2 = WeightedIndex::new(items.iter().map(|item| item.1).collect()).unwrap(); -/// for _ in 0..100 { -/// // 0% chance to print 'a', 30% chance to print 'b', 70% chance to print 'c' -/// println!("{}", items[dist2.sample(&mut rng)].0); -/// } -/// ``` -/// -/// [`WeightedIndex`]: crate::distributions::weighted::alias_method::WeightedIndex -/// [`Weight`]: crate::distributions::weighted::alias_method::Weight -/// [`Vec`]: Vec -/// [`Uniform::sample`]: Distribution::sample -/// [`Uniform::sample`]: Distribution::sample -pub struct WeightedIndex { - aliases: Vec, - no_alias_odds: Vec, - uniform_index: Uniform, - uniform_within_weight_sum: Uniform, -} - -impl WeightedIndex { - /// Creates a new [`WeightedIndex`]. - /// - /// Returns an error if: - /// - The vector is empty. - /// - The vector is longer than `u32::MAX`. - /// - For any weight `w`: `w < 0` or `w > max` where `max = W::MAX / - /// weights.len()`. - /// - The sum of weights is zero. - pub fn new(weights: Vec) -> Result { - let n = weights.len(); - if n == 0 { - return Err(WeightedError::NoItem); - } else if n > ::core::u32::MAX as usize { - return Err(WeightedError::TooMany); - } - let n = n as u32; - - let max_weight_size = W::try_from_u32_lossy(n) - .map(|n| W::MAX / n) - .unwrap_or(W::ZERO); - if !weights - .iter() - .all(|&w| W::ZERO <= w && w <= max_weight_size) - { - return Err(WeightedError::InvalidWeight); - } - - // The sum of weights will represent 100% of no alias odds. - let weight_sum = Weight::sum(weights.as_slice()); - // Prevent floating point overflow due to rounding errors. - let weight_sum = if weight_sum > W::MAX { - W::MAX - } else { - weight_sum - }; - if weight_sum == W::ZERO { - return Err(WeightedError::AllWeightsZero); - } - - // `weight_sum` would have been zero if `try_from_lossy` causes an error here. - let n_converted = W::try_from_u32_lossy(n).unwrap(); - - let mut no_alias_odds = weights; - for odds in no_alias_odds.iter_mut() { - *odds *= n_converted; - // Prevent floating point overflow due to rounding errors. - *odds = if *odds > W::MAX { W::MAX } else { *odds }; - } - - /// This struct is designed to contain three data structures at once, - /// sharing the same memory. More precisely it contains two linked lists - /// and an alias map, which will be the output of this method. To keep - /// the three data structures from getting in each other's way, it must - /// be ensured that a single index is only ever in one of them at the - /// same time. - struct Aliases { - aliases: Vec, - smalls_head: u32, - bigs_head: u32, - } - - impl Aliases { - fn new(size: u32) -> Self { - Aliases { - aliases: vec![0; size as usize], - smalls_head: ::core::u32::MAX, - bigs_head: ::core::u32::MAX, - } - } - - fn push_small(&mut self, idx: u32) { - self.aliases[idx as usize] = self.smalls_head; - self.smalls_head = idx; - } - - fn push_big(&mut self, idx: u32) { - self.aliases[idx as usize] = self.bigs_head; - self.bigs_head = idx; - } - - fn pop_small(&mut self) -> u32 { - let popped = self.smalls_head; - self.smalls_head = self.aliases[popped as usize]; - popped - } - - fn pop_big(&mut self) -> u32 { - let popped = self.bigs_head; - self.bigs_head = self.aliases[popped as usize]; - popped - } - - fn smalls_is_empty(&self) -> bool { - self.smalls_head == ::core::u32::MAX - } - - fn bigs_is_empty(&self) -> bool { - self.bigs_head == ::core::u32::MAX - } - - fn set_alias(&mut self, idx: u32, alias: u32) { - self.aliases[idx as usize] = alias; - } - } - - let mut aliases = Aliases::new(n); - - // Split indices into those with small weights and those with big weights. - for (index, &odds) in no_alias_odds.iter().enumerate() { - if odds < weight_sum { - aliases.push_small(index as u32); - } else { - aliases.push_big(index as u32); - } - } - - // Build the alias map by finding an alias with big weight for each index with - // small weight. - while !aliases.smalls_is_empty() && !aliases.bigs_is_empty() { - let s = aliases.pop_small(); - let b = aliases.pop_big(); - - aliases.set_alias(s, b); - no_alias_odds[b as usize] = no_alias_odds[b as usize] - - weight_sum - + no_alias_odds[s as usize]; - - if no_alias_odds[b as usize] < weight_sum { - aliases.push_small(b); - } else { - aliases.push_big(b); - } - } - - // The remaining indices should have no alias odds of about 100%. This is due to - // numeric accuracy. Otherwise they would be exactly 100%. - while !aliases.smalls_is_empty() { - no_alias_odds[aliases.pop_small() as usize] = weight_sum; - } - while !aliases.bigs_is_empty() { - no_alias_odds[aliases.pop_big() as usize] = weight_sum; - } - - // Prepare distributions for sampling. Creating them beforehand improves - // sampling performance. - let uniform_index = Uniform::new(0, n); - let uniform_within_weight_sum = Uniform::new(W::ZERO, weight_sum); - - Ok(Self { - aliases: aliases.aliases, - no_alias_odds, - uniform_index, - uniform_within_weight_sum, - }) - } -} - -impl Distribution for WeightedIndex { - fn sample(&self, rng: &mut R) -> usize { - let candidate = rng.sample(self.uniform_index); - if rng.sample(&self.uniform_within_weight_sum) < self.no_alias_odds[candidate as usize] { - candidate as usize - } else { - self.aliases[candidate as usize] as usize - } - } -} - -impl fmt::Debug for WeightedIndex -where - W: fmt::Debug, - Uniform: fmt::Debug, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("WeightedIndex") - .field("aliases", &self.aliases) - .field("no_alias_odds", &self.no_alias_odds) - .field("uniform_index", &self.uniform_index) - .field("uniform_within_weight_sum", &self.uniform_within_weight_sum) - .finish() - } -} - -impl Clone for WeightedIndex -where - Uniform: Clone, -{ - fn clone(&self) -> Self { - Self { - aliases: self.aliases.clone(), - no_alias_odds: self.no_alias_odds.clone(), - uniform_index: self.uniform_index.clone(), - uniform_within_weight_sum: self.uniform_within_weight_sum.clone(), - } - } -} - -/// Trait that must be implemented for weights, that are used with -/// [`WeightedIndex`]. Currently no guarantees on the correctness of -/// [`WeightedIndex`] are given for custom implementations of this trait. -pub trait Weight: - Sized - + Copy - + SampleUniform - + PartialOrd - + Add - + AddAssign - + Sub - + SubAssign - + Mul - + MulAssign - + Div - + DivAssign - + Sum -{ - /// Maximum number representable by `Self`. - const MAX: Self; - - /// Element of `Self` equivalent to 0. - const ZERO: Self; - - /// Produce an instance of `Self` from a `u32` value, or return `None` if - /// out of range. Loss of precision (where `Self` is a floating point type) - /// is acceptable. - fn try_from_u32_lossy(n: u32) -> Option; - - /// Sums all values in slice `values`. - fn sum(values: &[Self]) -> Self { - values.iter().map(|x| *x).sum() - } -} - -macro_rules! impl_weight_for_float { - ($T: ident) => { - impl Weight for $T { - const MAX: Self = ::core::$T::MAX; - const ZERO: Self = 0.0; - - fn try_from_u32_lossy(n: u32) -> Option { - Some(n as $T) - } - - fn sum(values: &[Self]) -> Self { - pairwise_sum(values) - } - } - }; -} - -/// In comparison to naive accumulation, the pairwise sum algorithm reduces -/// rounding errors when there are many floating point values. -fn pairwise_sum(values: &[T]) -> T { - if values.len() <= 32 { - values.iter().map(|x| *x).sum() - } else { - let mid = values.len() / 2; - let (a, b) = values.split_at(mid); - pairwise_sum(a) + pairwise_sum(b) - } -} - -macro_rules! impl_weight_for_int { - ($T: ident) => { - impl Weight for $T { - const MAX: Self = ::core::$T::MAX; - const ZERO: Self = 0; - - fn try_from_u32_lossy(n: u32) -> Option { - let n_converted = n as Self; - if n_converted >= Self::ZERO && n_converted as u32 == n { - Some(n_converted) - } else { - None - } - } - } - }; -} - -impl_weight_for_float!(f64); -impl_weight_for_float!(f32); -impl_weight_for_int!(usize); -#[cfg(not(target_os = "emscripten"))] -impl_weight_for_int!(u128); -impl_weight_for_int!(u64); -impl_weight_for_int!(u32); -impl_weight_for_int!(u16); -impl_weight_for_int!(u8); -impl_weight_for_int!(isize); -#[cfg(not(target_os = "emscripten"))] -impl_weight_for_int!(i128); -impl_weight_for_int!(i64); -impl_weight_for_int!(i32); -impl_weight_for_int!(i16); -impl_weight_for_int!(i8); - -#[cfg(test)] -mod test { - use super::*; - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_weighted_index_f32() { - test_weighted_index(f32::into); - - // Floating point special cases - assert_eq!( - WeightedIndex::new(vec![::core::f32::INFINITY]).unwrap_err(), - WeightedError::InvalidWeight - ); - assert_eq!( - WeightedIndex::new(vec![-0_f32]).unwrap_err(), - WeightedError::AllWeightsZero - ); - assert_eq!( - WeightedIndex::new(vec![-1_f32]).unwrap_err(), - WeightedError::InvalidWeight - ); - assert_eq!( - WeightedIndex::new(vec![-::core::f32::INFINITY]).unwrap_err(), - WeightedError::InvalidWeight - ); - assert_eq!( - WeightedIndex::new(vec![::core::f32::NAN]).unwrap_err(), - WeightedError::InvalidWeight - ); - } - - #[cfg(not(target_os = "emscripten"))] - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_weighted_index_u128() { - test_weighted_index(|x: u128| x as f64); - } - - #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_weighted_index_i128() { - test_weighted_index(|x: i128| x as f64); - - // Signed integer special cases - assert_eq!( - WeightedIndex::new(vec![-1_i128]).unwrap_err(), - WeightedError::InvalidWeight - ); - assert_eq!( - WeightedIndex::new(vec![::core::i128::MIN]).unwrap_err(), - WeightedError::InvalidWeight - ); - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_weighted_index_u8() { - test_weighted_index(u8::into); - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_weighted_index_i8() { - test_weighted_index(i8::into); - - // Signed integer special cases - assert_eq!( - WeightedIndex::new(vec![-1_i8]).unwrap_err(), - WeightedError::InvalidWeight - ); - assert_eq!( - WeightedIndex::new(vec![::core::i8::MIN]).unwrap_err(), - WeightedError::InvalidWeight - ); - } - - fn test_weighted_index f64>(w_to_f64: F) - where - WeightedIndex: fmt::Debug, - { - const NUM_WEIGHTS: u32 = 10; - const ZERO_WEIGHT_INDEX: u32 = 3; - const NUM_SAMPLES: u32 = 15000; - let mut rng = crate::test::rng(0x9c9fa0b0580a7031); - - let weights = { - let mut weights = Vec::with_capacity(NUM_WEIGHTS as usize); - let random_weight_distribution = crate::distributions::Uniform::new_inclusive( - W::ZERO, - W::MAX / W::try_from_u32_lossy(NUM_WEIGHTS).unwrap(), - ); - for _ in 0..NUM_WEIGHTS { - weights.push(rng.sample(&random_weight_distribution)); - } - weights[ZERO_WEIGHT_INDEX as usize] = W::ZERO; - weights - }; - let weight_sum = weights.iter().map(|w| *w).sum::(); - let expected_counts = weights - .iter() - .map(|&w| w_to_f64(w) / w_to_f64(weight_sum) * NUM_SAMPLES as f64) - .collect::>(); - let weight_distribution = WeightedIndex::new(weights).unwrap(); - - let mut counts = vec![0; NUM_WEIGHTS as usize]; - for _ in 0..NUM_SAMPLES { - counts[rng.sample(&weight_distribution)] += 1; - } - - assert_eq!(counts[ZERO_WEIGHT_INDEX as usize], 0); - for (count, expected_count) in counts.into_iter().zip(expected_counts) { - let difference = (count as f64 - expected_count).abs(); - let max_allowed_difference = NUM_SAMPLES as f64 / NUM_WEIGHTS as f64 * 0.1; - assert!(difference <= max_allowed_difference); - } - - assert_eq!( - WeightedIndex::::new(vec![]).unwrap_err(), - WeightedError::NoItem - ); - assert_eq!( - WeightedIndex::new(vec![W::ZERO]).unwrap_err(), - WeightedError::AllWeightsZero - ); - assert_eq!( - WeightedIndex::new(vec![W::MAX, W::MAX]).unwrap_err(), - WeightedError::InvalidWeight - ); - } -} diff --git a/rand/src/distributions/weighted/mod.rs b/rand/src/distributions/weighted/mod.rs deleted file mode 100644 index 2711637..0000000 --- a/rand/src/distributions/weighted/mod.rs +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Weighted index sampling -//! -//! This module provides two implementations for sampling indices: -//! -//! * [`WeightedIndex`] allows `O(log N)` sampling -//! * [`alias_method::WeightedIndex`] allows `O(1)` sampling, but with -//! much greater set-up cost -//! -//! [`alias_method::WeightedIndex`]: alias_method/struct.WeightedIndex.html - -pub mod alias_method; - -use crate::Rng; -use crate::distributions::Distribution; -use crate::distributions::uniform::{UniformSampler, SampleUniform, SampleBorrow}; -use core::cmp::PartialOrd; -use core::fmt; - -// Note that this whole module is only imported if feature="alloc" is enabled. -#[cfg(not(feature="std"))] use crate::alloc::vec::Vec; - -/// A distribution using weighted sampling to pick a discretely selected -/// item. -/// -/// Sampling a `WeightedIndex` distribution returns the index of a randomly -/// selected element from the iterator used when the `WeightedIndex` was -/// created. The chance of a given element being picked is proportional to the -/// value of the element. The weights can use any type `X` for which an -/// implementation of [`Uniform`] exists. -/// -/// # Performance -/// -/// A `WeightedIndex` contains a `Vec` and a [`Uniform`] and so its -/// size is the sum of the size of those objects, possibly plus some alignment. -/// -/// Creating a `WeightedIndex` will allocate enough space to hold `N - 1` -/// weights of type `X`, where `N` is the number of weights. However, since -/// `Vec` doesn't guarantee a particular growth strategy, additional memory -/// might be allocated but not used. Since the `WeightedIndex` object also -/// contains, this might cause additional allocations, though for primitive -/// types, ['Uniform`] doesn't allocate any memory. -/// -/// Time complexity of sampling from `WeightedIndex` is `O(log N)` where -/// `N` is the number of weights. -/// -/// Sampling from `WeightedIndex` will result in a single call to -/// `Uniform::sample` (method of the [`Distribution`] trait), which typically -/// will request a single value from the underlying [`RngCore`], though the -/// exact number depends on the implementaiton of `Uniform::sample`. -/// -/// # Example -/// -/// ``` -/// use rand::prelude::*; -/// use rand::distributions::WeightedIndex; -/// -/// let choices = ['a', 'b', 'c']; -/// let weights = [2, 1, 1]; -/// let dist = WeightedIndex::new(&weights).unwrap(); -/// let mut rng = thread_rng(); -/// for _ in 0..100 { -/// // 50% chance to print 'a', 25% chance to print 'b', 25% chance to print 'c' -/// println!("{}", choices[dist.sample(&mut rng)]); -/// } -/// -/// let items = [('a', 0), ('b', 3), ('c', 7)]; -/// let dist2 = WeightedIndex::new(items.iter().map(|item| item.1)).unwrap(); -/// for _ in 0..100 { -/// // 0% chance to print 'a', 30% chance to print 'b', 70% chance to print 'c' -/// println!("{}", items[dist2.sample(&mut rng)].0); -/// } -/// ``` -/// -/// [`Uniform`]: crate::distributions::uniform::Uniform -/// [`RngCore`]: crate::RngCore -#[derive(Debug, Clone)] -pub struct WeightedIndex { - cumulative_weights: Vec, - total_weight: X, - weight_distribution: X::Sampler, -} - -impl WeightedIndex { - /// Creates a new a `WeightedIndex` [`Distribution`] using the values - /// in `weights`. The weights can use any type `X` for which an - /// implementation of [`Uniform`] exists. - /// - /// Returns an error if the iterator is empty, if any weight is `< 0`, or - /// if its total value is 0. - /// - /// [`Uniform`]: crate::distributions::uniform::Uniform - pub fn new(weights: I) -> Result, WeightedError> - where I: IntoIterator, - I::Item: SampleBorrow, - X: for<'a> ::core::ops::AddAssign<&'a X> + - Clone + - Default { - let mut iter = weights.into_iter(); - let mut total_weight: X = iter.next() - .ok_or(WeightedError::NoItem)? - .borrow() - .clone(); - - let zero = ::default(); - if total_weight < zero { - return Err(WeightedError::InvalidWeight); - } - - let mut weights = Vec::::with_capacity(iter.size_hint().0); - for w in iter { - if *w.borrow() < zero { - return Err(WeightedError::InvalidWeight); - } - weights.push(total_weight.clone()); - total_weight += w.borrow(); - } - - if total_weight == zero { - return Err(WeightedError::AllWeightsZero); - } - let distr = X::Sampler::new(zero, total_weight.clone()); - - Ok(WeightedIndex { cumulative_weights: weights, total_weight, weight_distribution: distr }) - } - - /// Update a subset of weights, without changing the number of weights. - /// - /// `new_weights` must be sorted by the index. - /// - /// Using this method instead of `new` might be more efficient if only a small number of - /// weights is modified. No allocations are performed, unless the weight type `X` uses - /// allocation internally. - /// - /// In case of error, `self` is not modified. - pub fn update_weights(&mut self, new_weights: &[(usize, &X)]) -> Result<(), WeightedError> - where X: for<'a> ::core::ops::AddAssign<&'a X> + - for<'a> ::core::ops::SubAssign<&'a X> + - Clone + - Default { - if new_weights.is_empty() { - return Ok(()); - } - - let zero = ::default(); - - let mut total_weight = self.total_weight.clone(); - - // Check for errors first, so we don't modify `self` in case something - // goes wrong. - let mut prev_i = None; - for &(i, w) in new_weights { - if let Some(old_i) = prev_i { - if old_i >= i { - return Err(WeightedError::InvalidWeight); - } - } - if *w < zero { - return Err(WeightedError::InvalidWeight); - } - if i >= self.cumulative_weights.len() + 1 { - return Err(WeightedError::TooMany); - } - - let mut old_w = if i < self.cumulative_weights.len() { - self.cumulative_weights[i].clone() - } else { - self.total_weight.clone() - }; - if i > 0 { - old_w -= &self.cumulative_weights[i - 1]; - } - - total_weight -= &old_w; - total_weight += w; - prev_i = Some(i); - } - if total_weight == zero { - return Err(WeightedError::AllWeightsZero); - } - - // Update the weights. Because we checked all the preconditions in the - // previous loop, this should never panic. - let mut iter = new_weights.iter(); - - let mut prev_weight = zero.clone(); - let mut next_new_weight = iter.next(); - let &(first_new_index, _) = next_new_weight.unwrap(); - let mut cumulative_weight = if first_new_index > 0 { - self.cumulative_weights[first_new_index - 1].clone() - } else { - zero.clone() - }; - for i in first_new_index..self.cumulative_weights.len() { - match next_new_weight { - Some(&(j, w)) if i == j => { - cumulative_weight += w; - next_new_weight = iter.next(); - }, - _ => { - let mut tmp = self.cumulative_weights[i].clone(); - tmp -= &prev_weight; // We know this is positive. - cumulative_weight += &tmp; - } - } - prev_weight = cumulative_weight.clone(); - core::mem::swap(&mut prev_weight, &mut self.cumulative_weights[i]); - } - - self.total_weight = total_weight; - self.weight_distribution = X::Sampler::new(zero, self.total_weight.clone()); - - Ok(()) - } -} - -impl Distribution for WeightedIndex where - X: SampleUniform + PartialOrd { - fn sample(&self, rng: &mut R) -> usize { - use ::core::cmp::Ordering; - let chosen_weight = self.weight_distribution.sample(rng); - // Find the first item which has a weight *higher* than the chosen weight. - self.cumulative_weights.binary_search_by( - |w| if *w <= chosen_weight { Ordering::Less } else { Ordering::Greater }).unwrap_err() - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_weightedindex() { - let mut r = crate::test::rng(700); - const N_REPS: u32 = 5000; - let weights = [1u32, 2, 3, 0, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7]; - let total_weight = weights.iter().sum::() as f32; - - let verify = |result: [i32; 14]| { - for (i, count) in result.iter().enumerate() { - let exp = (weights[i] * N_REPS) as f32 / total_weight; - let mut err = (*count as f32 - exp).abs(); - if err != 0.0 { - err /= exp; - } - assert!(err <= 0.25); - } - }; - - // WeightedIndex from vec - let mut chosen = [0i32; 14]; - let distr = WeightedIndex::new(weights.to_vec()).unwrap(); - for _ in 0..N_REPS { - chosen[distr.sample(&mut r)] += 1; - } - verify(chosen); - - // WeightedIndex from slice - chosen = [0i32; 14]; - let distr = WeightedIndex::new(&weights[..]).unwrap(); - for _ in 0..N_REPS { - chosen[distr.sample(&mut r)] += 1; - } - verify(chosen); - - // WeightedIndex from iterator - chosen = [0i32; 14]; - let distr = WeightedIndex::new(weights.iter()).unwrap(); - for _ in 0..N_REPS { - chosen[distr.sample(&mut r)] += 1; - } - verify(chosen); - - for _ in 0..5 { - assert_eq!(WeightedIndex::new(&[0, 1]).unwrap().sample(&mut r), 1); - assert_eq!(WeightedIndex::new(&[1, 0]).unwrap().sample(&mut r), 0); - assert_eq!(WeightedIndex::new(&[0, 0, 0, 0, 10, 0]).unwrap().sample(&mut r), 4); - } - - assert_eq!(WeightedIndex::new(&[10][0..0]).unwrap_err(), WeightedError::NoItem); - assert_eq!(WeightedIndex::new(&[0]).unwrap_err(), WeightedError::AllWeightsZero); - assert_eq!(WeightedIndex::new(&[10, 20, -1, 30]).unwrap_err(), WeightedError::InvalidWeight); - assert_eq!(WeightedIndex::new(&[-10, 20, 1, 30]).unwrap_err(), WeightedError::InvalidWeight); - assert_eq!(WeightedIndex::new(&[-10]).unwrap_err(), WeightedError::InvalidWeight); - } - - #[test] - fn test_update_weights() { - let data = [ - (&[10u32, 2, 3, 4][..], - &[(1, &100), (2, &4)][..], // positive change - &[10, 100, 4, 4][..]), - (&[1u32, 2, 3, 0, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7][..], - &[(2, &1), (5, &1), (13, &100)][..], // negative change and last element - &[1u32, 2, 1, 0, 5, 1, 7, 1, 2, 3, 4, 5, 6, 100][..]), - ]; - - for (weights, update, expected_weights) in data.into_iter() { - let total_weight = weights.iter().sum::(); - let mut distr = WeightedIndex::new(weights.to_vec()).unwrap(); - assert_eq!(distr.total_weight, total_weight); - - distr.update_weights(update).unwrap(); - let expected_total_weight = expected_weights.iter().sum::(); - let expected_distr = WeightedIndex::new(expected_weights.to_vec()).unwrap(); - assert_eq!(distr.total_weight, expected_total_weight); - assert_eq!(distr.total_weight, expected_distr.total_weight); - assert_eq!(distr.cumulative_weights, expected_distr.cumulative_weights); - } - } -} - -/// Error type returned from `WeightedIndex::new`. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum WeightedError { - /// The provided weight collection contains no items. - NoItem, - - /// A weight is either less than zero, greater than the supported maximum or - /// otherwise invalid. - InvalidWeight, - - /// All items in the provided weight collection are zero. - AllWeightsZero, - - /// Too many weights are provided (length greater than `u32::MAX`) - TooMany, -} - -impl WeightedError { - fn msg(&self) -> &str { - match *self { - WeightedError::NoItem => "No weights provided.", - WeightedError::InvalidWeight => "A weight is invalid.", - WeightedError::AllWeightsZero => "All weights are zero.", - WeightedError::TooMany => "Too many weights (hit u32::MAX)", - } - } -} - -#[cfg(feature="std")] -impl ::std::error::Error for WeightedError { - fn description(&self) -> &str { - self.msg() - } - fn cause(&self) -> Option<&dyn (::std::error::Error)> { - None - } -} - -impl fmt::Display for WeightedError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.msg()) - } -} diff --git a/rand/src/distributions/ziggurat_tables.rs b/rand/src/distributions/ziggurat_tables.rs deleted file mode 100644 index ca1ce30..0000000 --- a/rand/src/distributions/ziggurat_tables.rs +++ /dev/null @@ -1,279 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Tables for distributions which are sampled using the ziggurat -// algorithm. Autogenerated by `ziggurat_tables.py`. - -pub type ZigTable = &'static [f64; 257]; -pub const ZIG_NORM_R: f64 = 3.654152885361008796; -pub static ZIG_NORM_X: [f64; 257] = - [3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074, - 3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434, - 2.978603279880844834, 2.934366867207854224, 2.894121053612348060, 2.857138730872132548, - 2.822877396825325125, 2.790921174000785765, 2.760944005278822555, 2.732685359042827056, - 2.705933656121858100, 2.680514643284522158, 2.656283037575502437, 2.633116393630324570, - 2.610910518487548515, 2.589575986706995181, 2.569035452680536569, 2.549221550323460761, - 2.530075232158516929, 2.511544441625342294, 2.493583041269680667, 2.476149939669143318, - 2.459208374333311298, 2.442725318198956774, 2.426670984935725972, 2.411018413899685520, - 2.395743119780480601, 2.380822795170626005, 2.366237056715818632, 2.351967227377659952, - 2.337996148795031370, 2.324308018869623016, 2.310888250599850036, 2.297723348901329565, - 2.284800802722946056, 2.272108990226823888, 2.259637095172217780, 2.247375032945807760, - 2.235313384928327984, 2.223443340090905718, 2.211756642882544366, 2.200245546609647995, - 2.188902771624720689, 2.177721467738641614, 2.166695180352645966, 2.155817819875063268, - 2.145083634046203613, 2.134487182844320152, 2.124023315687815661, 2.113687150684933957, - 2.103474055713146829, 2.093379631137050279, 2.083399693996551783, 2.073530263516978778, - 2.063767547809956415, 2.054107931648864849, 2.044547965215732788, 2.035084353727808715, - 2.025713947862032960, 2.016433734904371722, 2.007240830558684852, 1.998132471356564244, - 1.989106007615571325, 1.980158896898598364, 1.971288697931769640, 1.962493064942461896, - 1.953769742382734043, 1.945116560006753925, 1.936531428273758904, 1.928012334050718257, - 1.919557336591228847, 1.911164563769282232, 1.902832208548446369, 1.894558525668710081, - 1.886341828534776388, 1.878180486290977669, 1.870072921069236838, 1.862017605397632281, - 1.854013059758148119, 1.846057850283119750, 1.838150586580728607, 1.830289919680666566, - 1.822474540091783224, 1.814703175964167636, 1.806974591348693426, 1.799287584547580199, - 1.791640986550010028, 1.784033659547276329, 1.776464495522344977, 1.768932414909077933, - 1.761436365316706665, 1.753975320315455111, 1.746548278279492994, 1.739154261283669012, - 1.731792314050707216, 1.724461502945775715, 1.717160915015540690, 1.709889657069006086, - 1.702646854797613907, 1.695431651932238548, 1.688243209434858727, 1.681080704722823338, - 1.673943330923760353, 1.666830296159286684, 1.659740822855789499, 1.652674147080648526, - 1.645629517902360339, 1.638606196773111146, 1.631603456932422036, 1.624620582830568427, - 1.617656869570534228, 1.610711622367333673, 1.603784156023583041, 1.596873794420261339, - 1.589979870021648534, 1.583101723393471438, 1.576238702733332886, 1.569390163412534456, - 1.562555467528439657, 1.555733983466554893, 1.548925085471535512, 1.542128153226347553, - 1.535342571438843118, 1.528567729435024614, 1.521803020758293101, 1.515047842773992404, - 1.508301596278571965, 1.501563685112706548, 1.494833515777718391, 1.488110497054654369, - 1.481394039625375747, 1.474683555695025516, 1.467978458615230908, 1.461278162507407830, - 1.454582081885523293, 1.447889631277669675, 1.441200224845798017, 1.434513276002946425, - 1.427828197027290358, 1.421144398672323117, 1.414461289772464658, 1.407778276843371534, - 1.401094763676202559, 1.394410150925071257, 1.387723835686884621, 1.381035211072741964, - 1.374343665770030531, 1.367648583594317957, 1.360949343030101844, 1.354245316759430606, - 1.347535871177359290, 1.340820365893152122, 1.334098153216083604, 1.327368577624624679, - 1.320630975217730096, 1.313884673146868964, 1.307128989027353860, 1.300363230327433728, - 1.293586693733517645, 1.286798664489786415, 1.279998415710333237, 1.273185207661843732, - 1.266358287014688333, 1.259516886060144225, 1.252660221891297887, 1.245787495544997903, - 1.238897891102027415, 1.231990574742445110, 1.225064693752808020, 1.218119375481726552, - 1.211153726239911244, 1.204166830140560140, 1.197157747875585931, 1.190125515422801650, - 1.183069142678760732, 1.175987612011489825, 1.168879876726833800, 1.161744859441574240, - 1.154581450355851802, 1.147388505416733873, 1.140164844363995789, 1.132909248648336975, - 1.125620459211294389, 1.118297174115062909, 1.110938046009249502, 1.103541679420268151, - 1.096106627847603487, 1.088631390649514197, 1.081114409698889389, 1.073554065787871714, - 1.065948674757506653, 1.058296483326006454, 1.050595664586207123, 1.042844313139370538, - 1.035040439828605274, 1.027181966030751292, 1.019266717460529215, 1.011292417434978441, - 1.003256679539591412, 0.995156999629943084, 0.986990747093846266, 0.978755155288937750, - 0.970447311058864615, 0.962064143217605250, 0.953602409875572654, 0.945058684462571130, - 0.936429340280896860, 0.927710533396234771, 0.918898183643734989, 0.909987953490768997, - 0.900975224455174528, 0.891855070726792376, 0.882622229578910122, 0.873271068082494550, - 0.863795545546826915, 0.854189171001560554, 0.844444954902423661, 0.834555354079518752, - 0.824512208745288633, 0.814306670128064347, 0.803929116982664893, 0.793369058833152785, - 0.782615023299588763, 0.771654424216739354, 0.760473406422083165, 0.749056662009581653, - 0.737387211425838629, 0.725446140901303549, 0.713212285182022732, 0.700661841097584448, - 0.687767892786257717, 0.674499822827436479, 0.660822574234205984, 0.646695714884388928, - 0.632072236375024632, 0.616896989996235545, 0.601104617743940417, 0.584616766093722262, - 0.567338257040473026, 0.549151702313026790, 0.529909720646495108, 0.509423329585933393, - 0.487443966121754335, 0.463634336771763245, 0.437518402186662658, 0.408389134588000746, - 0.375121332850465727, 0.335737519180459465, 0.286174591747260509, 0.215241895913273806, - 0.000000000000000000]; -pub static ZIG_NORM_F: [f64; 257] = - [0.000477467764586655, 0.001260285930498598, 0.002609072746106363, 0.004037972593371872, - 0.005522403299264754, 0.007050875471392110, 0.008616582769422917, 0.010214971439731100, - 0.011842757857943104, 0.013497450601780807, 0.015177088307982072, 0.016880083152595839, - 0.018605121275783350, 0.020351096230109354, 0.022117062707379922, 0.023902203305873237, - 0.025705804008632656, 0.027527235669693315, 0.029365939758230111, 0.031221417192023690, - 0.033093219458688698, 0.034980941461833073, 0.036884215688691151, 0.038802707404656918, - 0.040736110656078753, 0.042684144916619378, 0.044646552251446536, 0.046623094902089664, - 0.048613553216035145, 0.050617723861121788, 0.052635418276973649, 0.054666461325077916, - 0.056710690106399467, 0.058767952921137984, 0.060838108349751806, 0.062921024437977854, - 0.065016577971470438, 0.067124653828023989, 0.069245144397250269, 0.071377949059141965, - 0.073522973714240991, 0.075680130359194964, 0.077849336702372207, 0.080030515814947509, - 0.082223595813495684, 0.084428509570654661, 0.086645194450867782, 0.088873592068594229, - 0.091113648066700734, 0.093365311913026619, 0.095628536713353335, 0.097903279039215627, - 0.100189498769172020, 0.102487158942306270, 0.104796225622867056, 0.107116667775072880, - 0.109448457147210021, 0.111791568164245583, 0.114145977828255210, 0.116511665626037014, - 0.118888613443345698, 0.121276805485235437, 0.123676228202051403, 0.126086870220650349, - 0.128508722280473636, 0.130941777174128166, 0.133386029692162844, 0.135841476571757352, - 0.138308116449064322, 0.140785949814968309, 0.143274978974047118, 0.145775208006537926, - 0.148286642733128721, 0.150809290682410169, 0.153343161060837674, 0.155888264725064563, - 0.158444614156520225, 0.161012223438117663, 0.163591108232982951, 0.166181285765110071, - 0.168782774801850333, 0.171395595638155623, 0.174019770082499359, 0.176655321444406654, - 0.179302274523530397, 0.181960655600216487, 0.184630492427504539, 0.187311814224516926, - 0.190004651671193070, 0.192709036904328807, 0.195425003514885592, 0.198152586546538112, - 0.200891822495431333, 0.203642749311121501, 0.206405406398679298, 0.209179834621935651, - 0.211966076307852941, 0.214764175252008499, 0.217574176725178370, 0.220396127481011589, - 0.223230075764789593, 0.226076071323264877, 0.228934165415577484, 0.231804410825248525, - 0.234686861873252689, 0.237581574432173676, 0.240488605941449107, 0.243408015423711988, - 0.246339863502238771, 0.249284212419516704, 0.252241126056943765, 0.255210669955677150, - 0.258192911338648023, 0.261187919133763713, 0.264195763998317568, 0.267216518344631837, - 0.270250256366959984, 0.273297054069675804, 0.276356989296781264, 0.279430141762765316, - 0.282516593084849388, 0.285616426816658109, 0.288729728483353931, 0.291856585618280984, - 0.294997087801162572, 0.298151326697901342, 0.301319396102034120, 0.304501391977896274, - 0.307697412505553769, 0.310907558127563710, 0.314131931597630143, 0.317370638031222396, - 0.320623784958230129, 0.323891482377732021, 0.327173842814958593, 0.330470981380537099, - 0.333783015832108509, 0.337110066638412809, 0.340452257045945450, 0.343809713148291340, - 0.347182563958251478, 0.350570941482881204, 0.353974980801569250, 0.357394820147290515, - 0.360830600991175754, 0.364282468130549597, 0.367750569780596226, 0.371235057669821344, - 0.374736087139491414, 0.378253817247238111, 0.381788410875031348, 0.385340034841733958, - 0.388908860020464597, 0.392495061461010764, 0.396098818517547080, 0.399720314981931668, - 0.403359739222868885, 0.407017284331247953, 0.410693148271983222, 0.414387534042706784, - 0.418100649839684591, 0.421832709231353298, 0.425583931339900579, 0.429354541031341519, - 0.433144769114574058, 0.436954852549929273, 0.440785034667769915, 0.444635565397727750, - 0.448506701509214067, 0.452398706863882505, 0.456311852680773566, 0.460246417814923481, - 0.464202689050278838, 0.468180961407822172, 0.472181538469883255, 0.476204732721683788, - 0.480250865911249714, 0.484320269428911598, 0.488413284707712059, 0.492530263646148658, - 0.496671569054796314, 0.500837575128482149, 0.505028667945828791, 0.509245245998136142, - 0.513487720749743026, 0.517756517232200619, 0.522052074674794864, 0.526374847174186700, - 0.530725304406193921, 0.535103932383019565, 0.539511234259544614, 0.543947731192649941, - 0.548413963257921133, 0.552910490428519918, 0.557437893621486324, 0.561996775817277916, - 0.566587763258951771, 0.571211506738074970, 0.575868682975210544, 0.580559996103683473, - 0.585286179266300333, 0.590047996335791969, 0.594846243770991268, 0.599681752622167719, - 0.604555390700549533, 0.609468064928895381, 0.614420723892076803, 0.619414360609039205, - 0.624450015550274240, 0.629528779928128279, 0.634651799290960050, 0.639820277456438991, - 0.645035480824251883, 0.650298743114294586, 0.655611470583224665, 0.660975147780241357, - 0.666391343912380640, 0.671861719900766374, 0.677388036222513090, 0.682972161648791376, - 0.688616083008527058, 0.694321916130032579, 0.700091918140490099, 0.705928501336797409, - 0.711834248882358467, 0.717811932634901395, 0.723864533472881599, 0.729995264565802437, - 0.736207598131266683, 0.742505296344636245, 0.748892447223726720, 0.755373506511754500, - 0.761953346841546475, 0.768637315803334831, 0.775431304986138326, 0.782341832659861902, - 0.789376143571198563, 0.796542330428254619, 0.803849483176389490, 0.811307874318219935, - 0.818929191609414797, 0.826726833952094231, 0.834716292992930375, 0.842915653118441077, - 0.851346258465123684, 0.860033621203008636, 0.869008688043793165, 0.878309655816146839, - 0.887984660763399880, 0.898095921906304051, 0.908726440060562912, 0.919991505048360247, - 0.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328, - 1.000000000000000000]; -pub const ZIG_EXP_R: f64 = 7.697117470131050077; -pub static ZIG_EXP_X: [f64; 257] = - [8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, - 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, - 5.323090505754398016, 5.181487281301500047, 5.054288489981304089, 4.938777085901250530, - 4.832939741025112035, 4.735242996601741083, 4.644491885420085175, 4.559737061707351380, - 4.480211746528421912, 4.405287693473573185, 4.334443680317273007, 4.267242480277365857, - 4.203313713735184365, 4.142340865664051464, 4.084051310408297830, 4.028208544647936762, - 3.974606066673788796, 3.923062500135489739, 3.873417670399509127, 3.825529418522336744, - 3.779270992411667862, 3.734528894039797375, 3.691201090237418825, 3.649195515760853770, - 3.608428813128909507, 3.568825265648337020, 3.530315889129343354, 3.492837654774059608, - 3.456332821132760191, 3.420748357251119920, 3.386035442460300970, 3.352149030900109405, - 3.319047470970748037, 3.286692171599068679, 3.255047308570449882, 3.224079565286264160, - 3.193757903212240290, 3.164053358025972873, 3.134938858084440394, 3.106389062339824481, - 3.078380215254090224, 3.050890016615455114, 3.023897504455676621, 2.997382949516130601, - 2.971327759921089662, 2.945714394895045718, 2.920526286512740821, 2.895747768600141825, - 2.871364012015536371, 2.847360965635188812, 2.823725302450035279, 2.800444370250737780, - 2.777506146439756574, 2.754899196562344610, 2.732612636194700073, 2.710636095867928752, - 2.688959688741803689, 2.667573980773266573, 2.646469963151809157, 2.625639026797788489, - 2.605072938740835564, 2.584763820214140750, 2.564704126316905253, 2.544886627111869970, - 2.525304390037828028, 2.505950763528594027, 2.486819361740209455, 2.467904050297364815, - 2.449198932978249754, 2.430698339264419694, 2.412396812688870629, 2.394289099921457886, - 2.376370140536140596, 2.358635057409337321, 2.341079147703034380, 2.323697874390196372, - 2.306486858283579799, 2.289441870532269441, 2.272558825553154804, 2.255833774367219213, - 2.239262898312909034, 2.222842503111036816, 2.206569013257663858, 2.190438966723220027, - 2.174449009937774679, 2.158595893043885994, 2.142876465399842001, 2.127287671317368289, - 2.111826546019042183, 2.096490211801715020, 2.081275874393225145, 2.066180819490575526, - 2.051202409468584786, 2.036338080248769611, 2.021585338318926173, 2.006941757894518563, - 1.992404978213576650, 1.977972700957360441, 1.963642687789548313, 1.949412758007184943, - 1.935280786297051359, 1.921244700591528076, 1.907302480018387536, 1.893452152939308242, - 1.879691795072211180, 1.866019527692827973, 1.852433515911175554, 1.838931967018879954, - 1.825513128903519799, 1.812175288526390649, 1.798916770460290859, 1.785735935484126014, - 1.772631179231305643, 1.759600930889074766, 1.746643651946074405, 1.733757834985571566, - 1.720942002521935299, 1.708194705878057773, 1.695514524101537912, 1.682900062917553896, - 1.670349953716452118, 1.657862852574172763, 1.645437439303723659, 1.633072416535991334, - 1.620766508828257901, 1.608518461798858379, 1.596327041286483395, 1.584191032532688892, - 1.572109239386229707, 1.560080483527888084, 1.548103603714513499, 1.536177455041032092, - 1.524300908219226258, 1.512472848872117082, 1.500692176842816750, 1.488957805516746058, - 1.477268661156133867, 1.465623682245745352, 1.454021818848793446, 1.442462031972012504, - 1.430943292938879674, 1.419464582769983219, 1.408024891569535697, 1.396623217917042137, - 1.385258568263121992, 1.373929956328490576, 1.362636402505086775, 1.351376933258335189, - 1.340150580529504643, 1.328956381137116560, 1.317793376176324749, 1.306660610415174117, - 1.295557131686601027, 1.284481990275012642, 1.273434238296241139, 1.262412929069615330, - 1.251417116480852521, 1.240445854334406572, 1.229498195693849105, 1.218573192208790124, - 1.207669893426761121, 1.196787346088403092, 1.185924593404202199, 1.175080674310911677, - 1.164254622705678921, 1.153445466655774743, 1.142652227581672841, 1.131873919411078511, - 1.121109547701330200, 1.110358108727411031, 1.099618588532597308, 1.088889961938546813, - 1.078171191511372307, 1.067461226479967662, 1.056759001602551429, 1.046063435977044209, - 1.035373431790528542, 1.024687873002617211, 1.014005623957096480, 1.003325527915696735, - 0.992646405507275897, 0.981967053085062602, 0.971286240983903260, 0.960602711668666509, - 0.949915177764075969, 0.939222319955262286, 0.928522784747210395, 0.917815182070044311, - 0.907098082715690257, 0.896370015589889935, 0.885629464761751528, 0.874874866291025066, - 0.864104604811004484, 0.853317009842373353, 0.842510351810368485, 0.831682837734273206, - 0.820832606554411814, 0.809957724057418282, 0.799056177355487174, 0.788125868869492430, - 0.777164609759129710, 0.766170112735434672, 0.755139984181982249, 0.744071715500508102, - 0.732962673584365398, 0.721810090308756203, 0.710611050909655040, 0.699362481103231959, - 0.688061132773747808, 0.676703568029522584, 0.665286141392677943, 0.653804979847664947, - 0.642255960424536365, 0.630634684933490286, 0.618936451394876075, 0.607156221620300030, - 0.595288584291502887, 0.583327712748769489, 0.571267316532588332, 0.559100585511540626, - 0.546820125163310577, 0.534417881237165604, 0.521885051592135052, 0.509211982443654398, - 0.496388045518671162, 0.483401491653461857, 0.470239275082169006, 0.456886840931420235, - 0.443327866073552401, 0.429543940225410703, 0.415514169600356364, 0.401214678896277765, - 0.386617977941119573, 0.371692145329917234, 0.356399760258393816, 0.340696481064849122, - 0.324529117016909452, 0.307832954674932158, 0.290527955491230394, 0.272513185478464703, - 0.253658363385912022, 0.233790483059674731, 0.212671510630966620, 0.189958689622431842, - 0.165127622564187282, 0.137304980940012589, 0.104838507565818778, 0.063852163815001570, - 0.000000000000000000]; -pub static ZIG_EXP_F: [f64; 257] = - [0.000167066692307963, 0.000454134353841497, 0.000967269282327174, 0.001536299780301573, - 0.002145967743718907, 0.002788798793574076, 0.003460264777836904, 0.004157295120833797, - 0.004877655983542396, 0.005619642207205489, 0.006381905937319183, 0.007163353183634991, - 0.007963077438017043, 0.008780314985808977, 0.009614413642502212, 0.010464810181029981, - 0.011331013597834600, 0.012212592426255378, 0.013109164931254991, 0.014020391403181943, - 0.014945968011691148, 0.015885621839973156, 0.016839106826039941, 0.017806200410911355, - 0.018786700744696024, 0.019780424338009740, 0.020787204072578114, 0.021806887504283581, - 0.022839335406385240, 0.023884420511558174, 0.024942026419731787, 0.026012046645134221, - 0.027094383780955803, 0.028188948763978646, 0.029295660224637411, 0.030414443910466622, - 0.031545232172893622, 0.032687963508959555, 0.033842582150874358, 0.035009037697397431, - 0.036187284781931443, 0.037377282772959382, 0.038578995503074871, 0.039792391023374139, - 0.041017441380414840, 0.042254122413316254, 0.043502413568888197, 0.044762297732943289, - 0.046033761076175184, 0.047316792913181561, 0.048611385573379504, 0.049917534282706379, - 0.051235237055126281, 0.052564494593071685, 0.053905310196046080, 0.055257689676697030, - 0.056621641283742870, 0.057997175631200659, 0.059384305633420280, 0.060783046445479660, - 0.062193415408541036, 0.063615431999807376, 0.065049117786753805, 0.066494496385339816, - 0.067951593421936643, 0.069420436498728783, 0.070901055162371843, 0.072393480875708752, - 0.073897746992364746, 0.075413888734058410, 0.076941943170480517, 0.078481949201606435, - 0.080033947542319905, 0.081597980709237419, 0.083174093009632397, 0.084762330532368146, - 0.086362741140756927, 0.087975374467270231, 0.089600281910032886, 0.091237516631040197, - 0.092887133556043569, 0.094549189376055873, 0.096223742550432825, 0.097910853311492213, - 0.099610583670637132, 0.101322997425953631, 0.103048160171257702, 0.104786139306570145, - 0.106537004050001632, 0.108300825451033755, 0.110077676405185357, 0.111867631670056283, - 0.113670767882744286, 0.115487163578633506, 0.117316899211555525, 0.119160057175327641, - 0.121016721826674792, 0.122886979509545108, 0.124770918580830933, 0.126668629437510671, - 0.128580204545228199, 0.130505738468330773, 0.132445327901387494, 0.134399071702213602, - 0.136367070926428829, 0.138349428863580176, 0.140346251074862399, 0.142357645432472146, - 0.144383722160634720, 0.146424593878344889, 0.148480375643866735, 0.150551185001039839, - 0.152637142027442801, 0.154738369384468027, 0.156854992369365148, 0.158987138969314129, - 0.161134939917591952, 0.163298528751901734, 0.165478041874935922, 0.167673618617250081, - 0.169885401302527550, 0.172113535315319977, 0.174358169171353411, 0.176619454590494829, - 0.178897546572478278, 0.181192603475496261, 0.183504787097767436, 0.185834262762197083, - 0.188181199404254262, 0.190545769663195363, 0.192928149976771296, 0.195328520679563189, - 0.197747066105098818, 0.200183974691911210, 0.202639439093708962, 0.205113656293837654, - 0.207606827724221982, 0.210119159388988230, 0.212650861992978224, 0.215202151075378628, - 0.217773247148700472, 0.220364375843359439, 0.222975768058120111, 0.225607660116683956, - 0.228260293930716618, 0.230933917169627356, 0.233628783437433291, 0.236345152457059560, - 0.239083290262449094, 0.241843469398877131, 0.244625969131892024, 0.247431075665327543, - 0.250259082368862240, 0.253110290015629402, 0.255985007030415324, 0.258883549749016173, - 0.261806242689362922, 0.264753418835062149, 0.267725419932044739, 0.270722596799059967, - 0.273745309652802915, 0.276793928448517301, 0.279868833236972869, 0.282970414538780746, - 0.286099073737076826, 0.289255223489677693, 0.292439288161892630, 0.295651704281261252, - 0.298892921015581847, 0.302163400675693528, 0.305463619244590256, 0.308794066934560185, - 0.312155248774179606, 0.315547685227128949, 0.318971912844957239, 0.322428484956089223, - 0.325917972393556354, 0.329440964264136438, 0.332998068761809096, 0.336589914028677717, - 0.340217149066780189, 0.343880444704502575, 0.347580494621637148, 0.351318016437483449, - 0.355093752866787626, 0.358908472948750001, 0.362762973354817997, 0.366658079781514379, - 0.370594648435146223, 0.374573567615902381, 0.378595759409581067, 0.382662181496010056, - 0.386773829084137932, 0.390931736984797384, 0.395136981833290435, 0.399390684475231350, - 0.403694012530530555, 0.408048183152032673, 0.412454465997161457, 0.416914186433003209, - 0.421428728997616908, 0.425999541143034677, 0.430628137288459167, 0.435316103215636907, - 0.440065100842354173, 0.444876873414548846, 0.449753251162755330, 0.454696157474615836, - 0.459707615642138023, 0.464789756250426511, 0.469944825283960310, 0.475175193037377708, - 0.480483363930454543, 0.485871987341885248, 0.491343869594032867, 0.496901987241549881, - 0.502549501841348056, 0.508289776410643213, 0.514126393814748894, 0.520063177368233931, - 0.526104213983620062, 0.532253880263043655, 0.538516872002862246, 0.544898237672440056, - 0.551403416540641733, 0.558038282262587892, 0.564809192912400615, 0.571723048664826150, - 0.578787358602845359, 0.586010318477268366, 0.593400901691733762, 0.600968966365232560, - 0.608725382079622346, 0.616682180915207878, 0.624852738703666200, 0.633251994214366398, - 0.641896716427266423, 0.650805833414571433, 0.660000841079000145, 0.669506316731925177, - 0.679350572264765806, 0.689566496117078431, 0.700192655082788606, 0.711274760805076456, - 0.722867659593572465, 0.735038092431424039, 0.747868621985195658, 0.761463388849896838, - 0.775956852040116218, 0.791527636972496285, 0.808421651523009044, 0.826993296643051101, - 0.847785500623990496, 0.871704332381204705, 0.900469929925747703, 0.938143680862176477, - 1.000000000000000000]; diff --git a/rand/src/lib.rs b/rand/src/lib.rs deleted file mode 100644 index b4167c3..0000000 --- a/rand/src/lib.rs +++ /dev/null @@ -1,720 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013-2017 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Utilities for random number generation -//! -//! Rand provides utilities to generate random numbers, to convert them to -//! useful types and distributions, and some randomness-related algorithms. -//! -//! # Quick Start -//! -//! To get you started quickly, the easiest and highest-level way to get -//! a random value is to use [`random()`]; alternatively you can use -//! [`thread_rng()`]. The [`Rng`] trait provides a useful API on all RNGs, while -//! the [`distributions`] and [`seq`] modules provide further -//! functionality on top of RNGs. -//! -//! ``` -//! use rand::prelude::*; -//! -//! if rand::random() { // generates a boolean -//! // Try printing a random unicode code point (probably a bad idea)! -//! println!("char: {}", rand::random::()); -//! } -//! -//! let mut rng = rand::thread_rng(); -//! let y: f64 = rng.gen(); // generates a float between 0 and 1 -//! -//! let mut nums: Vec = (1..100).collect(); -//! nums.shuffle(&mut rng); -//! ``` -//! -//! # The Book -//! -//! For the user guide and futher documentation, please read -//! [The Rust Rand Book](https://rust-random.github.io/book). - - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] -#![doc(test(attr(allow(unused_variables), deny(warnings))))] - -#![cfg_attr(not(feature="std"), no_std)] -#![cfg_attr(all(feature="simd_support", feature="nightly"), feature(stdsimd))] - -#![allow(clippy::excessive_precision, clippy::unreadable_literal, clippy::float_cmp)] - -#[cfg(all(feature="alloc", not(feature="std")))] -extern crate alloc; - -#[cfg(feature = "getrandom")] -use getrandom_package as getrandom; - -#[allow(unused)] -macro_rules! trace { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::trace!($($x)*) - } -) } -#[allow(unused)] -macro_rules! debug { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::debug!($($x)*) - } -) } -#[allow(unused)] -macro_rules! info { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::info!($($x)*) - } -) } -#[allow(unused)] -macro_rules! warn { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::warn!($($x)*) - } -) } -#[allow(unused)] -macro_rules! error { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::error!($($x)*) - } -) } - -// Re-exports from rand_core -pub use rand_core::{RngCore, CryptoRng, SeedableRng, Error}; - -// Public exports -#[cfg(feature="std")] pub use crate::rngs::thread::thread_rng; - -// Public modules -pub mod distributions; -pub mod prelude; -pub mod rngs; -pub mod seq; - - -use core::{mem, slice}; -use core::num::Wrapping; -use crate::distributions::{Distribution, Standard}; -use crate::distributions::uniform::{SampleUniform, UniformSampler, SampleBorrow}; - -/// An automatically-implemented extension trait on [`RngCore`] providing high-level -/// generic methods for sampling values and other convenience methods. -/// -/// This is the primary trait to use when generating random values. -/// -/// # Generic usage -/// -/// The basic pattern is `fn foo(rng: &mut R)`. Some -/// things are worth noting here: -/// -/// - Since `Rng: RngCore` and every `RngCore` implements `Rng`, it makes no -/// difference whether we use `R: Rng` or `R: RngCore`. -/// - The `+ ?Sized` un-bounding allows functions to be called directly on -/// type-erased references; i.e. `foo(r)` where `r: &mut RngCore`. Without -/// this it would be necessary to write `foo(&mut r)`. -/// -/// An alternative pattern is possible: `fn foo(rng: R)`. This has some -/// trade-offs. It allows the argument to be consumed directly without a `&mut` -/// (which is how `from_rng(thread_rng())` works); also it still works directly -/// on references (including type-erased references). Unfortunately within the -/// function `foo` it is not known whether `rng` is a reference type or not, -/// hence many uses of `rng` require an extra reference, either explicitly -/// (`distr.sample(&mut rng)`) or implicitly (`rng.gen()`); one may hope the -/// optimiser can remove redundant references later. -/// -/// Example: -/// -/// ``` -/// # use rand::thread_rng; -/// use rand::Rng; -/// -/// fn foo(rng: &mut R) -> f32 { -/// rng.gen() -/// } -/// -/// # let v = foo(&mut thread_rng()); -/// ``` -pub trait Rng: RngCore { - /// Return a random value supporting the [`Standard`] distribution. - /// - /// # Example - /// - /// ``` - /// use rand::{thread_rng, Rng}; - /// - /// let mut rng = thread_rng(); - /// let x: u32 = rng.gen(); - /// println!("{}", x); - /// println!("{:?}", rng.gen::<(f64, bool)>()); - /// ``` - /// - /// # Arrays and tuples - /// - /// The `rng.gen()` method is able to generate arrays (up to 32 elements) - /// and tuples (up to 12 elements), so long as all element types can be - /// generated. - /// - /// For arrays of integers, especially for those with small element types - /// (< 64 bit), it will likely be faster to instead use [`Rng::fill`]. - /// - /// ``` - /// use rand::{thread_rng, Rng}; - /// - /// let mut rng = thread_rng(); - /// let tuple: (u8, i32, char) = rng.gen(); // arbitrary tuple support - /// - /// let arr1: [f32; 32] = rng.gen(); // array construction - /// let mut arr2 = [0u8; 128]; - /// rng.fill(&mut arr2); // array fill - /// ``` - /// - /// [`Standard`]: distributions::Standard - #[inline] - fn gen(&mut self) -> T - where Standard: Distribution { - Standard.sample(self) - } - - /// Generate a random value in the range [`low`, `high`), i.e. inclusive of - /// `low` and exclusive of `high`. - /// - /// This function is optimised for the case that only a single sample is - /// made from the given range. See also the [`Uniform`] distribution - /// type which may be faster if sampling from the same range repeatedly. - /// - /// # Panics - /// - /// Panics if `low >= high`. - /// - /// # Example - /// - /// ``` - /// use rand::{thread_rng, Rng}; - /// - /// let mut rng = thread_rng(); - /// let n: u32 = rng.gen_range(0, 10); - /// println!("{}", n); - /// let m: f64 = rng.gen_range(-40.0f64, 1.3e5f64); - /// println!("{}", m); - /// ``` - /// - /// [`Uniform`]: distributions::uniform::Uniform - fn gen_range(&mut self, low: B1, high: B2) -> T - where - B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized, - { - T::Sampler::sample_single(low, high, self) - } - - /// Sample a new value, using the given distribution. - /// - /// ### Example - /// - /// ``` - /// use rand::{thread_rng, Rng}; - /// use rand::distributions::Uniform; - /// - /// let mut rng = thread_rng(); - /// let x = rng.sample(Uniform::new(10u32, 15)); - /// // Type annotation requires two types, the type and distribution; the - /// // distribution can be inferred. - /// let y = rng.sample::(Uniform::new(10, 15)); - /// ``` - fn sample>(&mut self, distr: D) -> T { - distr.sample(self) - } - - /// Create an iterator that generates values using the given distribution. - /// - /// Note that this function takes its arguments by value. This works since - /// `(&mut R): Rng where R: Rng` and - /// `(&D): Distribution where D: Distribution`, - /// however borrowing is not automatic hence `rng.sample_iter(...)` may - /// need to be replaced with `(&mut rng).sample_iter(...)`. - /// - /// # Example - /// - /// ``` - /// use rand::{thread_rng, Rng}; - /// use rand::distributions::{Alphanumeric, Uniform, Standard}; - /// - /// let rng = thread_rng(); - /// - /// // Vec of 16 x f32: - /// let v: Vec = rng.sample_iter(Standard).take(16).collect(); - /// - /// // String: - /// let s: String = rng.sample_iter(Alphanumeric).take(7).collect(); - /// - /// // Combined values - /// println!("{:?}", rng.sample_iter(Standard).take(5) - /// .collect::>()); - /// - /// // Dice-rolling: - /// let die_range = Uniform::new_inclusive(1, 6); - /// let mut roll_die = rng.sample_iter(die_range); - /// while roll_die.next().unwrap() != 6 { - /// println!("Not a 6; rolling again!"); - /// } - /// ``` - fn sample_iter(self, distr: D) -> distributions::DistIter - where D: Distribution, Self: Sized { - distr.sample_iter(self) - } - - /// Fill `dest` entirely with random bytes (uniform value distribution), - /// where `dest` is any type supporting [`AsByteSliceMut`], namely slices - /// and arrays over primitive integer types (`i8`, `i16`, `u32`, etc.). - /// - /// On big-endian platforms this performs byte-swapping to ensure - /// portability of results from reproducible generators. - /// - /// This uses [`fill_bytes`] internally which may handle some RNG errors - /// implicitly (e.g. waiting if the OS generator is not ready), but panics - /// on other errors. See also [`try_fill`] which returns errors. - /// - /// # Example - /// - /// ``` - /// use rand::{thread_rng, Rng}; - /// - /// let mut arr = [0i8; 20]; - /// thread_rng().fill(&mut arr[..]); - /// ``` - /// - /// [`fill_bytes`]: RngCore::fill_bytes - /// [`try_fill`]: Rng::try_fill - fn fill(&mut self, dest: &mut T) { - self.fill_bytes(dest.as_byte_slice_mut()); - dest.to_le(); - } - - /// Fill `dest` entirely with random bytes (uniform value distribution), - /// where `dest` is any type supporting [`AsByteSliceMut`], namely slices - /// and arrays over primitive integer types (`i8`, `i16`, `u32`, etc.). - /// - /// On big-endian platforms this performs byte-swapping to ensure - /// portability of results from reproducible generators. - /// - /// This is identical to [`fill`] except that it uses [`try_fill_bytes`] - /// internally and forwards RNG errors. - /// - /// # Example - /// - /// ``` - /// # use rand::Error; - /// use rand::{thread_rng, Rng}; - /// - /// # fn try_inner() -> Result<(), Error> { - /// let mut arr = [0u64; 4]; - /// thread_rng().try_fill(&mut arr[..])?; - /// # Ok(()) - /// # } - /// - /// # try_inner().unwrap() - /// ``` - /// - /// [`try_fill_bytes`]: RngCore::try_fill_bytes - /// [`fill`]: Rng::fill - fn try_fill(&mut self, dest: &mut T) -> Result<(), Error> { - self.try_fill_bytes(dest.as_byte_slice_mut())?; - dest.to_le(); - Ok(()) - } - - /// Return a bool with a probability `p` of being true. - /// - /// See also the [`Bernoulli`] distribution, which may be faster if - /// sampling from the same probability repeatedly. - /// - /// # Example - /// - /// ``` - /// use rand::{thread_rng, Rng}; - /// - /// let mut rng = thread_rng(); - /// println!("{}", rng.gen_bool(1.0 / 3.0)); - /// ``` - /// - /// # Panics - /// - /// If `p < 0` or `p > 1`. - /// - /// [`Bernoulli`]: distributions::bernoulli::Bernoulli - #[inline] - fn gen_bool(&mut self, p: f64) -> bool { - let d = distributions::Bernoulli::new(p).unwrap(); - self.sample(d) - } - - /// Return a bool with a probability of `numerator/denominator` of being - /// true. I.e. `gen_ratio(2, 3)` has chance of 2 in 3, or about 67%, of - /// returning true. If `numerator == denominator`, then the returned value - /// is guaranteed to be `true`. If `numerator == 0`, then the returned - /// value is guaranteed to be `false`. - /// - /// See also the [`Bernoulli`] distribution, which may be faster if - /// sampling from the same `numerator` and `denominator` repeatedly. - /// - /// # Panics - /// - /// If `denominator == 0` or `numerator > denominator`. - /// - /// # Example - /// - /// ``` - /// use rand::{thread_rng, Rng}; - /// - /// let mut rng = thread_rng(); - /// println!("{}", rng.gen_ratio(2, 3)); - /// ``` - /// - /// [`Bernoulli`]: distributions::bernoulli::Bernoulli - #[inline] - fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool { - let d = distributions::Bernoulli::from_ratio(numerator, denominator).unwrap(); - self.sample(d) - } -} - -impl Rng for R {} - -/// Trait for casting types to byte slices -/// -/// This is used by the [`Rng::fill`] and [`Rng::try_fill`] methods. -pub trait AsByteSliceMut { - /// Return a mutable reference to self as a byte slice - fn as_byte_slice_mut(&mut self) -> &mut [u8]; - - /// Call `to_le` on each element (i.e. byte-swap on Big Endian platforms). - fn to_le(&mut self); -} - -impl AsByteSliceMut for [u8] { - fn as_byte_slice_mut(&mut self) -> &mut [u8] { - self - } - - fn to_le(&mut self) {} -} - -macro_rules! impl_as_byte_slice { - () => {}; - ($t:ty) => { - impl AsByteSliceMut for [$t] { - fn as_byte_slice_mut(&mut self) -> &mut [u8] { - if self.len() == 0 { - unsafe { - // must not use null pointer - slice::from_raw_parts_mut(0x1 as *mut u8, 0) - } - } else { - unsafe { - slice::from_raw_parts_mut(self.as_mut_ptr() - as *mut u8, - self.len() * mem::size_of::<$t>() - ) - } - } - } - - fn to_le(&mut self) { - for x in self { - *x = x.to_le(); - } - } - } - - impl AsByteSliceMut for [Wrapping<$t>] { - fn as_byte_slice_mut(&mut self) -> &mut [u8] { - if self.len() == 0 { - unsafe { - // must not use null pointer - slice::from_raw_parts_mut(0x1 as *mut u8, 0) - } - } else { - unsafe { - slice::from_raw_parts_mut(self.as_mut_ptr() - as *mut u8, - self.len() * mem::size_of::<$t>() - ) - } - } - } - - fn to_le(&mut self) { - for x in self { - *x = Wrapping(x.0.to_le()); - } - } - } - }; - ($t:ty, $($tt:ty,)*) => { - impl_as_byte_slice!($t); - // TODO: this could replace above impl once Rust #32463 is fixed - // impl_as_byte_slice!(Wrapping<$t>); - impl_as_byte_slice!($($tt,)*); - } -} - -impl_as_byte_slice!(u16, u32, u64, usize,); -#[cfg(not(target_os = "emscripten"))] impl_as_byte_slice!(u128); -impl_as_byte_slice!(i8, i16, i32, i64, isize,); -#[cfg(not(target_os = "emscripten"))] impl_as_byte_slice!(i128); - -macro_rules! impl_as_byte_slice_arrays { - ($n:expr,) => {}; - ($n:expr, $N:ident) => { - impl AsByteSliceMut for [T; $n] where [T]: AsByteSliceMut { - fn as_byte_slice_mut(&mut self) -> &mut [u8] { - self[..].as_byte_slice_mut() - } - - fn to_le(&mut self) { - self[..].to_le() - } - } - }; - ($n:expr, $N:ident, $($NN:ident,)*) => { - impl_as_byte_slice_arrays!($n, $N); - impl_as_byte_slice_arrays!($n - 1, $($NN,)*); - }; - (!div $n:expr,) => {}; - (!div $n:expr, $N:ident, $($NN:ident,)*) => { - impl_as_byte_slice_arrays!($n, $N); - impl_as_byte_slice_arrays!(!div $n / 2, $($NN,)*); - }; -} -impl_as_byte_slice_arrays!(32, N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,); -impl_as_byte_slice_arrays!(!div 4096, N,N,N,N,N,N,N,); - -/// Generates a random value using the thread-local random number generator. -/// -/// This is simply a shortcut for `thread_rng().gen()`. See [`thread_rng`] for -/// documentation of the entropy source and [`Standard`] for documentation of -/// distributions and type-specific generation. -/// -/// # Examples -/// -/// ``` -/// let x = rand::random::(); -/// println!("{}", x); -/// -/// let y = rand::random::(); -/// println!("{}", y); -/// -/// if rand::random() { // generates a boolean -/// println!("Better lucky than good!"); -/// } -/// ``` -/// -/// If you're calling `random()` in a loop, caching the generator as in the -/// following example can increase performance. -/// -/// ``` -/// use rand::Rng; -/// -/// let mut v = vec![1, 2, 3]; -/// -/// for x in v.iter_mut() { -/// *x = rand::random() -/// } -/// -/// // can be made faster by caching thread_rng -/// -/// let mut rng = rand::thread_rng(); -/// -/// for x in v.iter_mut() { -/// *x = rng.gen(); -/// } -/// ``` -/// -/// [`Standard`]: distributions::Standard -#[cfg(feature="std")] -#[inline] -pub fn random() -> T -where Standard: Distribution { - thread_rng().gen() -} - -#[cfg(test)] -mod test { - use crate::rngs::mock::StepRng; - use super::*; - #[cfg(all(not(feature="std"), feature="alloc"))] use alloc::boxed::Box; - - /// Construct a deterministic RNG with the given seed - pub fn rng(seed: u64) -> impl RngCore { - // For tests, we want a statistically good, fast, reproducible RNG. - // PCG32 will do fine, and will be easy to embed if we ever need to. - const INC: u64 = 11634580027462260723; - rand_pcg::Pcg32::new(seed, INC) - } - - #[test] - fn test_fill_bytes_default() { - let mut r = StepRng::new(0x11_22_33_44_55_66_77_88, 0); - - // check every remainder mod 8, both in small and big vectors. - let lengths = [0, 1, 2, 3, 4, 5, 6, 7, - 80, 81, 82, 83, 84, 85, 86, 87]; - for &n in lengths.iter() { - let mut buffer = [0u8; 87]; - let v = &mut buffer[0..n]; - r.fill_bytes(v); - - // use this to get nicer error messages. - for (i, &byte) in v.iter().enumerate() { - if byte == 0 { - panic!("byte {} of {} is zero", i, n) - } - } - } - } - - #[test] - fn test_fill() { - let x = 9041086907909331047; // a random u64 - let mut rng = StepRng::new(x, 0); - - // Convert to byte sequence and back to u64; byte-swap twice if BE. - let mut array = [0u64; 2]; - rng.fill(&mut array[..]); - assert_eq!(array, [x, x]); - assert_eq!(rng.next_u64(), x); - - // Convert to bytes then u32 in LE order - let mut array = [0u32; 2]; - rng.fill(&mut array[..]); - assert_eq!(array, [x as u32, (x >> 32) as u32]); - assert_eq!(rng.next_u32(), x as u32); - - // Check equivalence using wrapped arrays - let mut warray = [Wrapping(0u32); 2]; - rng.fill(&mut warray[..]); - assert_eq!(array[0], warray[0].0); - assert_eq!(array[1], warray[1].0); - } - - #[test] - fn test_fill_empty() { - let mut array = [0u32; 0]; - let mut rng = StepRng::new(0, 1); - rng.fill(&mut array); - rng.fill(&mut array[..]); - } - - #[test] - fn test_gen_range() { - let mut r = rng(101); - for _ in 0..1000 { - let a = r.gen_range(-4711, 17); - assert!(a >= -4711 && a < 17); - let a = r.gen_range(-3i8, 42); - assert!(a >= -3i8 && a < 42i8); - let a = r.gen_range(&10u16, 99); - assert!(a >= 10u16 && a < 99u16); - let a = r.gen_range(-100i32, &2000); - assert!(a >= -100i32 && a < 2000i32); - let a = r.gen_range(&12u32, &24u32); - assert!(a >= 12u32 && a < 24u32); - - assert_eq!(r.gen_range(0u32, 1), 0u32); - assert_eq!(r.gen_range(-12i64, -11), -12i64); - assert_eq!(r.gen_range(3_000_000, 3_000_001), 3_000_000); - } - } - - #[test] - #[should_panic] - fn test_gen_range_panic_int() { - let mut r = rng(102); - r.gen_range(5, -2); - } - - #[test] - #[should_panic] - fn test_gen_range_panic_usize() { - let mut r = rng(103); - r.gen_range(5, 2); - } - - #[test] - fn test_gen_bool() { - let mut r = rng(105); - for _ in 0..5 { - assert_eq!(r.gen_bool(0.0), false); - assert_eq!(r.gen_bool(1.0), true); - } - } - - #[test] - fn test_rng_trait_object() { - use crate::distributions::{Distribution, Standard}; - let mut rng = rng(109); - let mut r = &mut rng as &mut dyn RngCore; - r.next_u32(); - r.gen::(); - assert_eq!(r.gen_range(0, 1), 0); - let _c: u8 = Standard.sample(&mut r); - } - - #[test] - #[cfg(feature="alloc")] - fn test_rng_boxed_trait() { - use crate::distributions::{Distribution, Standard}; - let rng = rng(110); - let mut r = Box::new(rng) as Box; - r.next_u32(); - r.gen::(); - assert_eq!(r.gen_range(0, 1), 0); - let _c: u8 = Standard.sample(&mut r); - } - - #[test] - #[cfg(feature="std")] - fn test_random() { - // not sure how to test this aside from just getting some values - let _n : usize = random(); - let _f : f32 = random(); - let _o : Option> = random(); - let _many : ((), - (usize, - isize, - Option<(u32, (bool,))>), - (u8, i8, u16, i16, u32, i32, u64, i64), - (f32, (f64, (f64,)))) = random(); - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_gen_ratio_average() { - const NUM: u32 = 3; - const DENOM: u32 = 10; - const N: u32 = 100_000; - - let mut sum: u32 = 0; - let mut rng = rng(111); - for _ in 0..N { - if rng.gen_ratio(NUM, DENOM) { - sum += 1; - } - } - // Have Binomial(N, NUM/DENOM) distribution - let expected = (NUM * N) / DENOM; // exact integer - assert!(((sum - expected) as i32).abs() < 500); - } -} diff --git a/rand/src/prelude.rs b/rand/src/prelude.rs deleted file mode 100644 index 3c386e8..0000000 --- a/rand/src/prelude.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Convenience re-export of common members -//! -//! Like the standard library's prelude, this module simplifies importing of -//! common items. Unlike the standard prelude, the contents of this module must -//! be imported manually: -//! -//! ``` -//! use rand::prelude::*; -//! # let mut r = StdRng::from_rng(thread_rng()).unwrap(); -//! # let _: f32 = r.gen(); -//! ``` - -#[doc(no_inline)] pub use crate::distributions::Distribution; -#[doc(no_inline)] pub use crate::rngs::StdRng; -#[cfg(feature="small_rng")] -#[doc(no_inline)] pub use crate::rngs::SmallRng; -#[doc(no_inline)] #[cfg(feature="std")] pub use crate::rngs::ThreadRng; -#[doc(no_inline)] pub use crate::{Rng, RngCore, CryptoRng, SeedableRng}; -#[doc(no_inline)] #[cfg(feature="std")] pub use crate::{random, thread_rng}; -#[doc(no_inline)] pub use crate::seq::{SliceRandom, IteratorRandom}; diff --git a/rand/src/rngs/adapter/mod.rs b/rand/src/rngs/adapter/mod.rs deleted file mode 100644 index 659ff26..0000000 --- a/rand/src/rngs/adapter/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Wrappers / adapters forming RNGs - -#[cfg(feature="std")] mod read; -mod reseeding; - -#[cfg(feature="std")] pub use self::read::{ReadRng, ReadError}; -pub use self::reseeding::ReseedingRng; diff --git a/rand/src/rngs/adapter/read.rs b/rand/src/rngs/adapter/read.rs deleted file mode 100644 index 901462e..0000000 --- a/rand/src/rngs/adapter/read.rs +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A wrapper around any Read to treat it as an RNG. - -use std::io::Read; -use std::fmt; - -use rand_core::{RngCore, Error, impls}; - - -/// An RNG that reads random bytes straight from any type supporting -/// [`std::io::Read`], for example files. -/// -/// This will work best with an infinite reader, but that is not required. -/// -/// This can be used with `/dev/urandom` on Unix but it is recommended to use -/// [`OsRng`] instead. -/// -/// # Panics -/// -/// `ReadRng` uses [`std::io::Read::read_exact`], which retries on interrupts. -/// All other errors from the underlying reader, including when it does not -/// have enough data, will only be reported through [`try_fill_bytes`]. -/// The other [`RngCore`] methods will panic in case of an error. -/// -/// # Example -/// -/// ``` -/// use rand::Rng; -/// use rand::rngs::adapter::ReadRng; -/// -/// let data = vec![1, 2, 3, 4, 5, 6, 7, 8]; -/// let mut rng = ReadRng::new(&data[..]); -/// println!("{:x}", rng.gen::()); -/// ``` -/// -/// [`OsRng`]: crate::rngs::OsRng -/// [`try_fill_bytes`]: RngCore::try_fill_bytes -#[derive(Debug)] -pub struct ReadRng { - reader: R -} - -impl ReadRng { - /// Create a new `ReadRng` from a `Read`. - pub fn new(r: R) -> ReadRng { - ReadRng { - reader: r - } - } -} - -impl RngCore for ReadRng { - fn next_u32(&mut self) -> u32 { - impls::next_u32_via_fill(self) - } - - fn next_u64(&mut self) -> u64 { - impls::next_u64_via_fill(self) - } - - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.try_fill_bytes(dest).unwrap_or_else(|err| - panic!("reading random bytes from Read implementation failed; error: {}", err)); - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - if dest.is_empty() { return Ok(()); } - // Use `std::io::read_exact`, which retries on `ErrorKind::Interrupted`. - self.reader.read_exact(dest).map_err(|e| Error::new(ReadError(e))) - } -} - -/// `ReadRng` error type -#[derive(Debug)] -pub struct ReadError(std::io::Error); - -impl fmt::Display for ReadError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "ReadError: {}", self.0) - } -} - -impl std::error::Error for ReadError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - Some(&self.0) - } -} - - -#[cfg(test)] -mod test { - use super::ReadRng; - use crate::RngCore; - - #[test] - fn test_reader_rng_u64() { - // transmute from the target to avoid endianness concerns. - let v = vec![0u8, 0, 0, 0, 0, 0, 0, 1, - 0 , 0, 0, 0, 0, 0, 0, 2, - 0, 0, 0, 0, 0, 0, 0, 3]; - let mut rng = ReadRng::new(&v[..]); - - assert_eq!(rng.next_u64(), 1_u64.to_be()); - assert_eq!(rng.next_u64(), 2_u64.to_be()); - assert_eq!(rng.next_u64(), 3_u64.to_be()); - } - - #[test] - fn test_reader_rng_u32() { - let v = vec![0u8, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3]; - let mut rng = ReadRng::new(&v[..]); - - assert_eq!(rng.next_u32(), 1_u32.to_be()); - assert_eq!(rng.next_u32(), 2_u32.to_be()); - assert_eq!(rng.next_u32(), 3_u32.to_be()); - } - - #[test] - fn test_reader_rng_fill_bytes() { - let v = [1u8, 2, 3, 4, 5, 6, 7, 8]; - let mut w = [0u8; 8]; - - let mut rng = ReadRng::new(&v[..]); - rng.fill_bytes(&mut w); - - assert!(v == w); - } - - #[test] - fn test_reader_rng_insufficient_bytes() { - let v = [1u8, 2, 3, 4, 5, 6, 7, 8]; - let mut w = [0u8; 9]; - - let mut rng = ReadRng::new(&v[..]); - - let result = rng.try_fill_bytes(&mut w); - assert!(result.is_err()); - println!("Error: {}", result.unwrap_err()); - } -} diff --git a/rand/src/rngs/adapter/reseeding.rs b/rand/src/rngs/adapter/reseeding.rs deleted file mode 100644 index ec88efe..0000000 --- a/rand/src/rngs/adapter/reseeding.rs +++ /dev/null @@ -1,357 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A wrapper around another PRNG that reseeds it after it -//! generates a certain number of random bytes. - -use core::mem::size_of; - -use rand_core::{RngCore, CryptoRng, SeedableRng, Error}; -use rand_core::block::{BlockRngCore, BlockRng}; - -/// A wrapper around any PRNG that implements [`BlockRngCore`], that adds the -/// ability to reseed it. -/// -/// `ReseedingRng` reseeds the underlying PRNG in the following cases: -/// -/// - On a manual call to [`reseed()`]. -/// - After `clone()`, the clone will be reseeded on first use. -/// - After a process is forked, the RNG in the child process is reseeded within -/// the next few generated values, depending on the block size of the -/// underlying PRNG. For ChaCha and Hc128 this is a maximum of -/// 15 `u32` values before reseeding. -/// - After the PRNG has generated a configurable number of random bytes. -/// -/// # When should reseeding after a fixed number of generated bytes be used? -/// -/// Reseeding after a fixed number of generated bytes is never strictly -/// *necessary*. Cryptographic PRNGs don't have a limited number of bytes they -/// can output, or at least not a limit reachable in any practical way. There is -/// no such thing as 'running out of entropy'. -/// -/// Occasionally reseeding can be seen as some form of 'security in depth'. Even -/// if in the future a cryptographic weakness is found in the CSPRNG being used, -/// or a flaw in the implementation, occasionally reseeding should make -/// exploiting it much more difficult or even impossible. -/// -/// Use [`ReseedingRng::new`] with a `threshold` of `0` to disable reseeding -/// after a fixed number of generated bytes. -/// -/// # Error handling -/// -/// Although unlikely, reseeding the wrapped PRNG can fail. `ReseedingRng` will -/// never panic but try to handle the error intelligently through some -/// combination of retrying and delaying reseeding until later. -/// If handling the source error fails `ReseedingRng` will continue generating -/// data from the wrapped PRNG without reseeding. -/// -/// Manually calling [`reseed()`] will not have this retry or delay logic, but -/// reports the error. -/// -/// # Example -/// -/// ``` -/// use rand::prelude::*; -/// use rand_chacha::ChaCha20Core; // Internal part of ChaChaRng that -/// // implements BlockRngCore -/// use rand::rngs::OsRng; -/// use rand::rngs::adapter::ReseedingRng; -/// -/// let prng = ChaCha20Core::from_entropy(); -/// let mut reseeding_rng = ReseedingRng::new(prng, 0, OsRng); -/// -/// println!("{}", reseeding_rng.gen::()); -/// -/// let mut cloned_rng = reseeding_rng.clone(); -/// assert!(reseeding_rng.gen::() != cloned_rng.gen::()); -/// ``` -/// -/// [`BlockRngCore`]: rand_core::block::BlockRngCore -/// [`ReseedingRng::new`]: ReseedingRng::new -/// [`reseed()`]: ReseedingRng::reseed -#[derive(Debug)] -pub struct ReseedingRng(BlockRng>) -where R: BlockRngCore + SeedableRng, - Rsdr: RngCore; - -impl ReseedingRng -where R: BlockRngCore + SeedableRng, - Rsdr: RngCore -{ - /// Create a new `ReseedingRng` from an existing PRNG, combined with a RNG - /// to use as reseeder. - /// - /// `threshold` sets the number of generated bytes after which to reseed the - /// PRNG. Set it to zero to never reseed based on the number of generated - /// values. - pub fn new(rng: R, threshold: u64, reseeder: Rsdr) -> Self { - ReseedingRng(BlockRng::new(ReseedingCore::new(rng, threshold, reseeder))) - } - - /// Reseed the internal PRNG. - pub fn reseed(&mut self) -> Result<(), Error> { - self.0.core.reseed() - } -} - -// TODO: this should be implemented for any type where the inner type -// implements RngCore, but we can't specify that because ReseedingCore is private -impl RngCore for ReseedingRng -where R: BlockRngCore + SeedableRng, - ::Results: AsRef<[u32]> + AsMut<[u32]> -{ - #[inline(always)] - fn next_u32(&mut self) -> u32 { - self.0.next_u32() - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - self.0.next_u64() - } - - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.0.fill_bytes(dest) - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.0.try_fill_bytes(dest) - } -} - -impl Clone for ReseedingRng -where R: BlockRngCore + SeedableRng + Clone, - Rsdr: RngCore + Clone -{ - fn clone(&self) -> ReseedingRng { - // Recreating `BlockRng` seems easier than cloning it and resetting - // the index. - ReseedingRng(BlockRng::new(self.0.core.clone())) - } -} - -impl CryptoRng for ReseedingRng -where R: BlockRngCore + SeedableRng + CryptoRng, - Rsdr: RngCore + CryptoRng {} - -#[derive(Debug)] -struct ReseedingCore { - inner: R, - reseeder: Rsdr, - threshold: i64, - bytes_until_reseed: i64, - fork_counter: usize, -} - -impl BlockRngCore for ReseedingCore -where R: BlockRngCore + SeedableRng, - Rsdr: RngCore -{ - type Item = ::Item; - type Results = ::Results; - - fn generate(&mut self, results: &mut Self::Results) { - let global_fork_counter = fork::get_fork_counter(); - if self.bytes_until_reseed <= 0 || - self.is_forked(global_fork_counter) { - // We get better performance by not calling only `reseed` here - // and continuing with the rest of the function, but by directly - // returning from a non-inlined function. - return self.reseed_and_generate(results, global_fork_counter); - } - let num_bytes = results.as_ref().len() * size_of::(); - self.bytes_until_reseed -= num_bytes as i64; - self.inner.generate(results); - } -} - -impl ReseedingCore -where R: BlockRngCore + SeedableRng, - Rsdr: RngCore -{ - /// Create a new `ReseedingCore`. - fn new(rng: R, threshold: u64, reseeder: Rsdr) -> Self { - use ::core::i64::MAX; - fork::register_fork_handler(); - - // Because generating more values than `i64::MAX` takes centuries on - // current hardware, we just clamp to that value. - // Also we set a threshold of 0, which indicates no limit, to that - // value. - let threshold = - if threshold == 0 { MAX } - else if threshold <= MAX as u64 { threshold as i64 } - else { MAX }; - - ReseedingCore { - inner: rng, - reseeder, - threshold: threshold as i64, - bytes_until_reseed: threshold as i64, - fork_counter: 0, - } - } - - /// Reseed the internal PRNG. - fn reseed(&mut self) -> Result<(), Error> { - R::from_rng(&mut self.reseeder).map(|result| { - self.bytes_until_reseed = self.threshold; - self.inner = result - }) - } - - fn is_forked(&self, global_fork_counter: usize) -> bool { - // In theory, on 32-bit platforms, it is possible for - // `global_fork_counter` to wrap around after ~4e9 forks. - // - // This check will detect a fork in the normal case where - // `fork_counter < global_fork_counter`, and also when the difference - // between both is greater than `isize::MAX` (wrapped around). - // - // It will still fail to detect a fork if there have been more than - // `isize::MAX` forks, without any reseed in between. Seems unlikely - // enough. - (self.fork_counter.wrapping_sub(global_fork_counter) as isize) < 0 - } - - #[inline(never)] - fn reseed_and_generate(&mut self, - results: &mut ::Results, - global_fork_counter: usize) - { - #![allow(clippy::if_same_then_else)] // false positive - if self.is_forked(global_fork_counter) { - info!("Fork detected, reseeding RNG"); - } else { - trace!("Reseeding RNG (periodic reseed)"); - } - - let num_bytes = - results.as_ref().len() * size_of::<::Item>(); - - if let Err(e) = self.reseed() { - warn!("Reseeding RNG failed: {}", e); - let _ = e; - } - self.fork_counter = global_fork_counter; - - self.bytes_until_reseed = self.threshold - num_bytes as i64; - self.inner.generate(results); - } -} - -impl Clone for ReseedingCore -where R: BlockRngCore + SeedableRng + Clone, - Rsdr: RngCore + Clone -{ - fn clone(&self) -> ReseedingCore { - ReseedingCore { - inner: self.inner.clone(), - reseeder: self.reseeder.clone(), - threshold: self.threshold, - bytes_until_reseed: 0, // reseed clone on first use - fork_counter: self.fork_counter, - } - } -} - -impl CryptoRng for ReseedingCore -where R: BlockRngCore + SeedableRng + CryptoRng, - Rsdr: RngCore + CryptoRng {} - - -#[cfg(all(unix, not(target_os="emscripten")))] -mod fork { - use core::sync::atomic::{AtomicUsize, AtomicBool, Ordering}; - #[allow(deprecated)] // Required for compatibility with Rust < 1.24. - use core::sync::atomic::{ATOMIC_USIZE_INIT, ATOMIC_BOOL_INIT}; - - // Fork protection - // - // We implement fork protection on Unix using `pthread_atfork`. - // When the process is forked, we increment `RESEEDING_RNG_FORK_COUNTER`. - // Every `ReseedingRng` stores the last known value of the static in - // `fork_counter`. If the cached `fork_counter` is less than - // `RESEEDING_RNG_FORK_COUNTER`, it is time to reseed this RNG. - // - // If reseeding fails, we don't deal with this by setting a delay, but just - // don't update `fork_counter`, so a reseed is attempted as soon as - // possible. - - #[allow(deprecated)] - static RESEEDING_RNG_FORK_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT; - - pub fn get_fork_counter() -> usize { - RESEEDING_RNG_FORK_COUNTER.load(Ordering::Relaxed) - } - - #[allow(deprecated)] - static FORK_HANDLER_REGISTERED: AtomicBool = ATOMIC_BOOL_INIT; - - extern fn fork_handler() { - // Note: fetch_add is defined to wrap on overflow - // (which is what we want). - RESEEDING_RNG_FORK_COUNTER.fetch_add(1, Ordering::Relaxed); - } - - pub fn register_fork_handler() { - if !FORK_HANDLER_REGISTERED.load(Ordering::Relaxed) { - unsafe { libc::pthread_atfork(None, None, Some(fork_handler)) }; - FORK_HANDLER_REGISTERED.store(true, Ordering::Relaxed); - } - } -} - -#[cfg(not(all(unix, not(target_os="emscripten"))))] -mod fork { - pub fn get_fork_counter() -> usize { 0 } - pub fn register_fork_handler() {} -} - - -#[cfg(test)] -mod test { - use crate::{Rng, SeedableRng}; - use crate::rngs::std::Core; - use crate::rngs::mock::StepRng; - use super::ReseedingRng; - - #[test] - fn test_reseeding() { - let mut zero = StepRng::new(0, 0); - let rng = Core::from_rng(&mut zero).unwrap(); - let thresh = 1; // reseed every time the buffer is exhausted - let mut reseeding = ReseedingRng::new(rng, thresh, zero); - - // RNG buffer size is [u32; 64] - // Debug is only implemented up to length 32 so use two arrays - let mut buf = ([0u32; 32], [0u32; 32]); - reseeding.fill(&mut buf.0); - reseeding.fill(&mut buf.1); - let seq = buf; - for _ in 0..10 { - reseeding.fill(&mut buf.0); - reseeding.fill(&mut buf.1); - assert_eq!(buf, seq); - } - } - - #[test] - fn test_clone_reseeding() { - let mut zero = StepRng::new(0, 0); - let rng = Core::from_rng(&mut zero).unwrap(); - let mut rng1 = ReseedingRng::new(rng, 32*4, zero); - - let first: u32 = rng1.gen(); - for _ in 0..10 { let _ = rng1.gen::(); } - - let mut rng2 = rng1.clone(); - assert_eq!(first, rng2.gen::()); - } -} diff --git a/rand/src/rngs/entropy.rs b/rand/src/rngs/entropy.rs deleted file mode 100644 index 1ed59ab..0000000 --- a/rand/src/rngs/entropy.rs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Entropy generator, or wrapper around external generators - -#![allow(deprecated)] // whole module is deprecated - -use rand_core::{RngCore, CryptoRng, Error}; -use crate::rngs::OsRng; - -/// An interface returning random data from external source(s), provided -/// specifically for securely seeding algorithmic generators (PRNGs). -/// -/// This is deprecated. It is suggested you use [`rngs::OsRng`] instead. -/// -/// [`rngs::OsRng`]: crate::rngs::OsRng -#[derive(Debug)] -#[deprecated(since="0.7.0", note="use rngs::OsRng instead")] -pub struct EntropyRng { - source: OsRng, -} - -impl EntropyRng { - /// Create a new `EntropyRng`. - /// - /// This method will do no system calls or other initialization routines, - /// those are done on first use. This is done to make `new` infallible, - /// and `try_fill_bytes` the only place to report errors. - pub fn new() -> Self { - EntropyRng { source: OsRng } - } -} - -impl Default for EntropyRng { - fn default() -> Self { - EntropyRng::new() - } -} - -impl RngCore for EntropyRng { - fn next_u32(&mut self) -> u32 { - self.source.next_u32() - } - - fn next_u64(&mut self) -> u64 { - self.source.next_u64() - } - - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.source.fill_bytes(dest) - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.source.try_fill_bytes(dest) - } -} - -impl CryptoRng for EntropyRng {} - - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_entropy() { - let mut rng = EntropyRng::new(); - let n = (rng.next_u32() ^ rng.next_u32()).count_ones(); - assert!(n >= 2); // p(failure) approx 1e-7 - } -} diff --git a/rand/src/rngs/mock.rs b/rand/src/rngs/mock.rs deleted file mode 100644 index b4081da..0000000 --- a/rand/src/rngs/mock.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Mock random number generator - -use rand_core::{RngCore, Error, impls}; - -/// A simple implementation of `RngCore` for testing purposes. -/// -/// This generates an arithmetic sequence (i.e. adds a constant each step) -/// over a `u64` number, using wrapping arithmetic. If the increment is 0 -/// the generator yields a constant. -/// -/// ``` -/// use rand::Rng; -/// use rand::rngs::mock::StepRng; -/// -/// let mut my_rng = StepRng::new(2, 1); -/// let sample: [u64; 3] = my_rng.gen(); -/// assert_eq!(sample, [2, 3, 4]); -/// ``` -#[derive(Debug, Clone)] -pub struct StepRng { - v: u64, - a: u64, -} - -impl StepRng { - /// Create a `StepRng`, yielding an arithmetic sequence starting with - /// `initial` and incremented by `increment` each time. - pub fn new(initial: u64, increment: u64) -> Self { - StepRng { v: initial, a: increment } - } -} - -impl RngCore for StepRng { - #[inline] - fn next_u32(&mut self) -> u32 { - self.next_u64() as u32 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - let result = self.v; - self.v = self.v.wrapping_add(self.a); - result - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - impls::fill_bytes_via_next(self, dest); - } - - #[inline] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} diff --git a/rand/src/rngs/mod.rs b/rand/src/rngs/mod.rs deleted file mode 100644 index abf3243..0000000 --- a/rand/src/rngs/mod.rs +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Random number generators and adapters -//! -//! ## Background: Random number generators (RNGs) -//! -//! Computers cannot produce random numbers from nowhere. We classify -//! random number generators as follows: -//! -//! - "True" random number generators (TRNGs) use hard-to-predict data sources -//! (e.g. the high-resolution parts of event timings and sensor jitter) to -//! harvest random bit-sequences, apply algorithms to remove bias and -//! estimate available entropy, then combine these bits into a byte-sequence -//! or an entropy pool. This job is usually done by the operating system or -//! a hardware generator (HRNG). -//! - "Pseudo"-random number generators (PRNGs) use algorithms to transform a -//! seed into a sequence of pseudo-random numbers. These generators can be -//! fast and produce well-distributed unpredictable random numbers (or not). -//! They are usually deterministic: given algorithm and seed, the output -//! sequence can be reproduced. They have finite period and eventually loop; -//! with many algorithms this period is fixed and can be proven sufficiently -//! long, while others are chaotic and the period depends on the seed. -//! - "Cryptographically secure" pseudo-random number generators (CSPRNGs) -//! are the sub-set of PRNGs which are secure. Security of the generator -//! relies both on hiding the internal state and using a strong algorithm. -//! -//! ## Traits and functionality -//! -//! All RNGs implement the [`RngCore`] trait, as a consequence of which the -//! [`Rng`] extension trait is automatically implemented. Secure RNGs may -//! additionally implement the [`CryptoRng`] trait. -//! -//! All PRNGs require a seed to produce their random number sequence. The -//! [`SeedableRng`] trait provides three ways of constructing PRNGs: -//! -//! - `from_seed` accepts a type specific to the PRNG -//! - `from_rng` allows a PRNG to be seeded from any other RNG -//! - `seed_from_u64` allows any PRNG to be seeded from a `u64` insecurely -//! - `from_entropy` securely seeds a PRNG from fresh entropy -//! -//! Use the [`rand_core`] crate when implementing your own RNGs. -//! -//! ## Our generators -//! -//! This crate provides several random number generators: -//! -//! - [`OsRng`] is an interface to the operating system's random number -//! source. Typically the operating system uses a CSPRNG with entropy -//! provided by a TRNG and some type of on-going re-seeding. -//! - [`ThreadRng`], provided by the [`thread_rng`] function, is a handle to a -//! thread-local CSPRNG with periodic seeding from [`OsRng`]. Because this -//! is local, it is typically much faster than [`OsRng`]. It should be -//! secure, though the paranoid may prefer [`OsRng`]. -//! - [`StdRng`] is a CSPRNG chosen for good performance and trust of security -//! (based on reviews, maturity and usage). The current algorithm is ChaCha20, -//! which is well established and rigorously analysed. -//! [`StdRng`] provides the algorithm used by [`ThreadRng`] but without -//! periodic reseeding. -//! - [`SmallRng`] is an **insecure** PRNG designed to be fast, simple, require -//! little memory, and have good output quality. -//! -//! The algorithms selected for [`StdRng`] and [`SmallRng`] may change in any -//! release and may be platform-dependent, therefore they should be considered -//! **not reproducible**. -//! -//! ## Additional generators -//! -//! **TRNGs**: The [`rdrand`] crate provides an interface to the RDRAND and -//! RDSEED instructions available in modern Intel and AMD CPUs. -//! The [`rand_jitter`] crate provides a user-space implementation of -//! entropy harvesting from CPU timer jitter, but is very slow and has -//! [security issues](https://github.com/rust-random/rand/issues/699). -//! -//! **PRNGs**: Several companion crates are available, providing individual or -//! families of PRNG algorithms. These provide the implementations behind -//! [`StdRng`] and [`SmallRng`] but can also be used directly, indeed *should* -//! be used directly when **reproducibility** matters. -//! Some suggestions are: [`rand_chacha`], [`rand_pcg`], [`rand_xoshiro`]. -//! A full list can be found by searching for crates with the [`rng` tag]. -//! -//! [`SmallRng`]: rngs::SmallRng -//! [`StdRng`]: rngs::StdRng -//! [`OsRng`]: rngs::OsRng -//! [`ThreadRng`]: rngs::ThreadRng -//! [`mock::StepRng`]: rngs::mock::StepRng -//! [`adapter::ReadRng`]: rngs::adapter::ReadRng -//! [`adapter::ReseedingRng`]: rngs::adapter::ReseedingRng -//! [`rdrand`]: https://crates.io/crates/rdrand -//! [`rand_jitter`]: https://crates.io/crates/rand_jitter -//! [`rand_chacha`]: https://crates.io/crates/rand_chacha -//! [`rand_pcg`]: https://crates.io/crates/rand_pcg -//! [`rand_xoshiro`]: https://crates.io/crates/rand_xoshiro -//! [`rng` tag]: https://crates.io/keywords/rng - -pub mod adapter; - -#[cfg(feature="std")] mod entropy; -pub mod mock; // Public so we don't export `StepRng` directly, making it a bit - // more clear it is intended for testing. -#[cfg(feature="small_rng")] -mod small; -mod std; -#[cfg(feature="std")] pub(crate) mod thread; - -#[allow(deprecated)] -#[cfg(feature="std")] pub use self::entropy::EntropyRng; - -#[cfg(feature="small_rng")] -pub use self::small::SmallRng; -pub use self::std::StdRng; -#[cfg(feature="std")] pub use self::thread::ThreadRng; - -#[cfg(feature="getrandom")] pub use rand_core::OsRng; diff --git a/rand/src/rngs/small.rs b/rand/src/rngs/small.rs deleted file mode 100644 index 6571363..0000000 --- a/rand/src/rngs/small.rs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A small fast RNG - -use rand_core::{RngCore, SeedableRng, Error}; - -#[cfg(all(not(target_os = "emscripten"), target_pointer_width = "64"))] -type Rng = rand_pcg::Pcg64Mcg; -#[cfg(not(all(not(target_os = "emscripten"), target_pointer_width = "64")))] -type Rng = rand_pcg::Pcg32; - -/// A small-state, fast non-crypto PRNG -/// -/// `SmallRng` may be a good choice when a PRNG with small state, cheap -/// initialization, good statistical quality and good performance are required. -/// It is **not** a good choice when security against prediction or -/// reproducibility are important. -/// -/// This PRNG is **feature-gated**: to use, you must enable the crate feature -/// `small_rng`. -/// -/// The algorithm is deterministic but should not be considered reproducible -/// due to dependence on platform and possible replacement in future -/// library versions. For a reproducible generator, use a named PRNG from an -/// external crate, e.g. [rand_pcg] or [rand_chacha]. -/// Refer also to [The Book](https://rust-random.github.io/book/guide-rngs.html). -/// -/// The PRNG algorithm in `SmallRng` is chosen to be -/// efficient on the current platform, without consideration for cryptography -/// or security. The size of its state is much smaller than [`StdRng`]. -/// The current algorithm is [`Pcg64Mcg`](rand_pcg::Pcg64Mcg) on 64-bit -/// platforms and [`Pcg32`](rand_pcg::Pcg32) on 32-bit platforms. Both are -/// implemented by the [rand_pcg] crate. -/// -/// # Examples -/// -/// Initializing `SmallRng` with a random seed can be done using [`SeedableRng::from_entropy`]: -/// -/// ``` -/// use rand::{Rng, SeedableRng}; -/// use rand::rngs::SmallRng; -/// -/// // Create small, cheap to initialize and fast RNG with a random seed. -/// // The randomness is supplied by the operating system. -/// let mut small_rng = SmallRng::from_entropy(); -/// # let v: u32 = small_rng.gen(); -/// ``` -/// -/// When initializing a lot of `SmallRng`'s, using [`thread_rng`] can be more -/// efficient: -/// -/// ``` -/// use std::iter; -/// use rand::{SeedableRng, thread_rng}; -/// use rand::rngs::SmallRng; -/// -/// // Create a big, expensive to initialize and slower, but unpredictable RNG. -/// // This is cached and done only once per thread. -/// let mut thread_rng = thread_rng(); -/// // Create small, cheap to initialize and fast RNGs with random seeds. -/// // One can generally assume this won't fail. -/// let rngs: Vec = iter::repeat(()) -/// .map(|()| SmallRng::from_rng(&mut thread_rng).unwrap()) -/// .take(10) -/// .collect(); -/// ``` -/// -/// [`StdRng`]: crate::rngs::StdRng -/// [`thread_rng`]: crate::thread_rng -/// [rand_chacha]: https://crates.io/crates/rand_chacha -/// [rand_pcg]: https://crates.io/crates/rand_pcg -#[derive(Clone, Debug)] -pub struct SmallRng(Rng); - -impl RngCore for SmallRng { - #[inline(always)] - fn next_u32(&mut self) -> u32 { - self.0.next_u32() - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - self.0.next_u64() - } - - #[inline(always)] - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.0.fill_bytes(dest); - } - - #[inline(always)] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.0.try_fill_bytes(dest) - } -} - -impl SeedableRng for SmallRng { - type Seed = ::Seed; - - #[inline(always)] - fn from_seed(seed: Self::Seed) -> Self { - SmallRng(Rng::from_seed(seed)) - } - - #[inline(always)] - fn from_rng(rng: R) -> Result { - Rng::from_rng(rng).map(SmallRng) - } -} diff --git a/rand/src/rngs/std.rs b/rand/src/rngs/std.rs deleted file mode 100644 index 22e08ae..0000000 --- a/rand/src/rngs/std.rs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The standard RNG - -use crate::{RngCore, CryptoRng, Error, SeedableRng}; - -#[cfg(target_os = "emscripten")] pub(crate) use rand_hc::Hc128Core as Core; -#[cfg(not(target_os = "emscripten"))] pub(crate) use rand_chacha::ChaCha20Core as Core; -#[cfg(target_os = "emscripten")] use rand_hc::Hc128Rng as Rng; -#[cfg(not(target_os = "emscripten"))] use rand_chacha::ChaCha20Rng as Rng; - -/// The standard RNG. The PRNG algorithm in `StdRng` is chosen to be efficient -/// on the current platform, to be statistically strong and unpredictable -/// (meaning a cryptographically secure PRNG). -/// -/// The current algorithm used is the ChaCha block cipher with either 20 or 12 -/// rounds (see the `stdrng_*` feature flags, documented in the README). -/// This may change as new evidence of cipher security and performance -/// becomes available. -/// -/// The algorithm is deterministic but should not be considered reproducible -/// due to dependence on configuration and possible replacement in future -/// library versions. For a secure reproducible generator, we recommend use of -/// the [rand_chacha] crate directly. -/// -/// [rand_chacha]: https://crates.io/crates/rand_chacha -#[derive(Clone, Debug)] -pub struct StdRng(Rng); - -impl RngCore for StdRng { - #[inline(always)] - fn next_u32(&mut self) -> u32 { - self.0.next_u32() - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - self.0.next_u64() - } - - #[inline(always)] - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.0.fill_bytes(dest); - } - - #[inline(always)] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.0.try_fill_bytes(dest) - } -} - -impl SeedableRng for StdRng { - type Seed = ::Seed; - - #[inline(always)] - fn from_seed(seed: Self::Seed) -> Self { - StdRng(Rng::from_seed(seed)) - } - - #[inline(always)] - fn from_rng(rng: R) -> Result { - Rng::from_rng(rng).map(StdRng) - } -} - -impl CryptoRng for StdRng {} - - -#[cfg(test)] -mod test { - use crate::{RngCore, SeedableRng}; - use crate::rngs::StdRng; - - #[test] - fn test_stdrng_construction() { - // Test value-stability of StdRng. This is expected to break any time - // the algorithm is changed. - let seed = [1,0,0,0, 23,0,0,0, 200,1,0,0, 210,30,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]; - - #[cfg(any(feature="stdrng_strong", not(feature="stdrng_fast")))] - let target = [3950704604716924505, 5573172343717151650]; - #[cfg(all(not(feature="stdrng_strong"), feature="stdrng_fast"))] - let target = [10719222850664546238, 14064965282130556830]; - - let mut rng0 = StdRng::from_seed(seed); - let x0 = rng0.next_u64(); - - let mut rng1 = StdRng::from_rng(rng0).unwrap(); - let x1 = rng1.next_u64(); - - assert_eq!([x0, x1], target); - } -} diff --git a/rand/src/rngs/thread.rs b/rand/src/rngs/thread.rs deleted file mode 100644 index 2006f41..0000000 --- a/rand/src/rngs/thread.rs +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Thread-local random number generator - -use std::cell::UnsafeCell; -use std::ptr::NonNull; - -use crate::{RngCore, CryptoRng, SeedableRng, Error}; -use crate::rngs::adapter::ReseedingRng; -use crate::rngs::OsRng; -use super::std::Core; - -// Rationale for using `UnsafeCell` in `ThreadRng`: -// -// Previously we used a `RefCell`, with an overhead of ~15%. There will only -// ever be one mutable reference to the interior of the `UnsafeCell`, because -// we only have such a reference inside `next_u32`, `next_u64`, etc. Within a -// single thread (which is the definition of `ThreadRng`), there will only ever -// be one of these methods active at a time. -// -// A possible scenario where there could be multiple mutable references is if -// `ThreadRng` is used inside `next_u32` and co. But the implementation is -// completely under our control. We just have to ensure none of them use -// `ThreadRng` internally, which is nonsensical anyway. We should also never run -// `ThreadRng` in destructors of its implementation, which is also nonsensical. - - -// Number of generated bytes after which to reseed `ThreadRng`. -// According to benchmarks, reseeding has a noticable impact with thresholds -// of 32 kB and less. We choose 64 kB to avoid significant overhead. -const THREAD_RNG_RESEED_THRESHOLD: u64 = 1024 * 64; - -/// The type returned by [`thread_rng`], essentially just a reference to the -/// PRNG in thread-local memory. -/// -/// `ThreadRng` uses the same PRNG as [`StdRng`] for security and performance. -/// As hinted by the name, the generator is thread-local. `ThreadRng` is a -/// handle to this generator and thus supports `Copy`, but not `Send` or `Sync`. -/// -/// Unlike `StdRng`, `ThreadRng` uses the [`ReseedingRng`] wrapper to reseed -/// the PRNG from fresh entropy every 64 kiB of random data. -/// [`OsRng`] is used to provide seed data. -/// -/// Note that the reseeding is done as an extra precaution against side-channel -/// attacks and mis-use (e.g. if somehow weak entropy were supplied initially). -/// The PRNG algorithms used are assumed to be secure. -/// -/// [`ReseedingRng`]: crate::rngs::adapter::ReseedingRng -/// [`StdRng`]: crate::rngs::StdRng -#[derive(Copy, Clone, Debug)] -pub struct ThreadRng { - // inner raw pointer implies type is neither Send nor Sync - rng: NonNull>, -} - -thread_local!( - static THREAD_RNG_KEY: UnsafeCell> = { - let r = Core::from_rng(OsRng).unwrap_or_else(|err| - panic!("could not initialize thread_rng: {}", err)); - let rng = ReseedingRng::new(r, - THREAD_RNG_RESEED_THRESHOLD, - OsRng); - UnsafeCell::new(rng) - } -); - -/// Retrieve the lazily-initialized thread-local random number generator, -/// seeded by the system. Intended to be used in method chaining style, -/// e.g. `thread_rng().gen::()`, or cached locally, e.g. -/// `let mut rng = thread_rng();`. Invoked by the `Default` trait, making -/// `ThreadRng::default()` equivalent. -/// -/// For more information see [`ThreadRng`]. -pub fn thread_rng() -> ThreadRng { - let raw = THREAD_RNG_KEY.with(|t| t.get()); - let nn = NonNull::new(raw).unwrap(); - ThreadRng { rng: nn } -} - -impl Default for ThreadRng { - fn default() -> ThreadRng { - crate::prelude::thread_rng() - } -} - -impl RngCore for ThreadRng { - #[inline(always)] - fn next_u32(&mut self) -> u32 { - unsafe { self.rng.as_mut().next_u32() } - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - unsafe { self.rng.as_mut().next_u64() } - } - - fn fill_bytes(&mut self, dest: &mut [u8]) { - unsafe { self.rng.as_mut().fill_bytes(dest) } - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - unsafe { self.rng.as_mut().try_fill_bytes(dest) } - } -} - -impl CryptoRng for ThreadRng {} - - -#[cfg(test)] -mod test { - #[test] - fn test_thread_rng() { - use crate::Rng; - let mut r = crate::thread_rng(); - r.gen::(); - assert_eq!(r.gen_range(0, 1), 0); - } -} diff --git a/rand/src/seq/index.rs b/rand/src/seq/index.rs deleted file mode 100644 index 22a5733..0000000 --- a/rand/src/seq/index.rs +++ /dev/null @@ -1,409 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Low-level API for sampling indices - -#[cfg(feature="alloc")] use core::slice; - -#[cfg(feature="std")] use std::vec; -#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::vec::{self, Vec}; -// BTreeMap is not as fast in tests, but better than nothing. -#[cfg(feature="std")] use std::collections::{HashSet}; -#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::collections::BTreeSet; - -#[cfg(feature="alloc")] use crate::distributions::{Distribution, Uniform, uniform::SampleUniform}; -use crate::Rng; - -/// A vector of indices. -/// -/// Multiple internal representations are possible. -#[derive(Clone, Debug)] -pub enum IndexVec { - #[doc(hidden)] U32(Vec), - #[doc(hidden)] USize(Vec), -} - -impl IndexVec { - /// Returns the number of indices - #[inline] - pub fn len(&self) -> usize { - match *self { - IndexVec::U32(ref v) => v.len(), - IndexVec::USize(ref v) => v.len(), - } - } - - /// Returns `true` if the length is 0. - #[inline] - pub fn is_empty(&self) -> bool { - match *self { - IndexVec::U32(ref v) => v.is_empty(), - IndexVec::USize(ref v) => v.is_empty(), - } - } - - /// Return the value at the given `index`. - /// - /// (Note: we cannot implement [`std::ops::Index`] because of lifetime - /// restrictions.) - #[inline] - pub fn index(&self, index: usize) -> usize { - match *self { - IndexVec::U32(ref v) => v[index] as usize, - IndexVec::USize(ref v) => v[index], - } - } - - /// Return result as a `Vec`. Conversion may or may not be trivial. - #[inline] - pub fn into_vec(self) -> Vec { - match self { - IndexVec::U32(v) => v.into_iter().map(|i| i as usize).collect(), - IndexVec::USize(v) => v, - } - } - - /// Iterate over the indices as a sequence of `usize` values - #[inline] - pub fn iter(&self) -> IndexVecIter<'_> { - match *self { - IndexVec::U32(ref v) => IndexVecIter::U32(v.iter()), - IndexVec::USize(ref v) => IndexVecIter::USize(v.iter()), - } - } - - /// Convert into an iterator over the indices as a sequence of `usize` values - #[inline] - pub fn into_iter(self) -> IndexVecIntoIter { - match self { - IndexVec::U32(v) => IndexVecIntoIter::U32(v.into_iter()), - IndexVec::USize(v) => IndexVecIntoIter::USize(v.into_iter()), - } - } -} - -impl PartialEq for IndexVec { - fn eq(&self, other: &IndexVec) -> bool { - use self::IndexVec::*; - match (self, other) { - (&U32(ref v1), &U32(ref v2)) => v1 == v2, - (&USize(ref v1), &USize(ref v2)) => v1 == v2, - (&U32(ref v1), &USize(ref v2)) => (v1.len() == v2.len()) - && (v1.iter().zip(v2.iter()).all(|(x, y)| *x as usize == *y)), - (&USize(ref v1), &U32(ref v2)) => (v1.len() == v2.len()) - && (v1.iter().zip(v2.iter()).all(|(x, y)| *x == *y as usize)), - } - } -} - -impl From> for IndexVec { - #[inline] - fn from(v: Vec) -> Self { - IndexVec::U32(v) - } -} - -impl From> for IndexVec { - #[inline] - fn from(v: Vec) -> Self { - IndexVec::USize(v) - } -} - -/// Return type of `IndexVec::iter`. -#[derive(Debug)] -pub enum IndexVecIter<'a> { - #[doc(hidden)] U32(slice::Iter<'a, u32>), - #[doc(hidden)] USize(slice::Iter<'a, usize>), -} - -impl<'a> Iterator for IndexVecIter<'a> { - type Item = usize; - #[inline] - fn next(&mut self) -> Option { - use self::IndexVecIter::*; - match *self { - U32(ref mut iter) => iter.next().map(|i| *i as usize), - USize(ref mut iter) => iter.next().cloned(), - } - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - match *self { - IndexVecIter::U32(ref v) => v.size_hint(), - IndexVecIter::USize(ref v) => v.size_hint(), - } - } -} - -impl<'a> ExactSizeIterator for IndexVecIter<'a> {} - -/// Return type of `IndexVec::into_iter`. -#[derive(Clone, Debug)] -pub enum IndexVecIntoIter { - #[doc(hidden)] U32(vec::IntoIter), - #[doc(hidden)] USize(vec::IntoIter), -} - -impl Iterator for IndexVecIntoIter { - type Item = usize; - - #[inline] - fn next(&mut self) -> Option { - use self::IndexVecIntoIter::*; - match *self { - U32(ref mut v) => v.next().map(|i| i as usize), - USize(ref mut v) => v.next(), - } - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - use self::IndexVecIntoIter::*; - match *self { - U32(ref v) => v.size_hint(), - USize(ref v) => v.size_hint(), - } - } -} - -impl ExactSizeIterator for IndexVecIntoIter {} - - -/// Randomly sample exactly `amount` distinct indices from `0..length`, and -/// return them in random order (fully shuffled). -/// -/// This method is used internally by the slice sampling methods, but it can -/// sometimes be useful to have the indices themselves so this is provided as -/// an alternative. -/// -/// The implementation used is not specified; we automatically select the -/// fastest available algorithm for the `length` and `amount` parameters -/// (based on detailed profiling on an Intel Haswell CPU). Roughly speaking, -/// complexity is `O(amount)`, except that when `amount` is small, performance -/// is closer to `O(amount^2)`, and when `length` is close to `amount` then -/// `O(length)`. -/// -/// Note that performance is significantly better over `u32` indices than over -/// `u64` indices. Because of this we hide the underlying type behind an -/// abstraction, `IndexVec`. -/// -/// If an allocation-free `no_std` function is required, it is suggested -/// to adapt the internal `sample_floyd` implementation. -/// -/// Panics if `amount > length`. -pub fn sample(rng: &mut R, length: usize, amount: usize) -> IndexVec -where R: Rng + ?Sized { - if amount > length { - panic!("`amount` of samples must be less than or equal to `length`"); - } - if length > (::core::u32::MAX as usize) { - // We never want to use inplace here, but could use floyd's alg - // Lazy version: always use the cache alg. - return sample_rejection(rng, length, amount); - } - let amount = amount as u32; - let length = length as u32; - - // Choice of algorithm here depends on both length and amount. See: - // https://github.com/rust-random/rand/pull/479 - // We do some calculations with f32. Accuracy is not very important. - - if amount < 163 { - const C: [[f32; 2]; 2] = [[1.6, 8.0/45.0], [10.0, 70.0/9.0]]; - let j = if length < 500_000 { 0 } else { 1 }; - let amount_fp = amount as f32; - let m4 = C[0][j] * amount_fp; - // Short-cut: when amount < 12, floyd's is always faster - if amount > 11 && (length as f32) < (C[1][j] + m4) * amount_fp { - sample_inplace(rng, length, amount) - } else { - sample_floyd(rng, length, amount) - } - } else { - const C: [f32; 2] = [270.0, 330.0/9.0]; - let j = if length < 500_000 { 0 } else { 1 }; - if (length as f32) < C[j] * (amount as f32) { - sample_inplace(rng, length, amount) - } else { - sample_rejection(rng, length, amount) - } - } -} - -/// Randomly sample exactly `amount` indices from `0..length`, using Floyd's -/// combination algorithm. -/// -/// The output values are fully shuffled. (Overhead is under 50%.) -/// -/// This implementation uses `O(amount)` memory and `O(amount^2)` time. -fn sample_floyd(rng: &mut R, length: u32, amount: u32) -> IndexVec -where R: Rng + ?Sized { - // For small amount we use Floyd's fully-shuffled variant. For larger - // amounts this is slow due to Vec::insert performance, so we shuffle - // afterwards. Benchmarks show little overhead from extra logic. - let floyd_shuffle = amount < 50; - - debug_assert!(amount <= length); - let mut indices = Vec::with_capacity(amount as usize); - for j in length - amount .. length { - let t = rng.gen_range(0, j + 1); - if floyd_shuffle { - if let Some(pos) = indices.iter().position(|&x| x == t) { - indices.insert(pos, j); - continue; - } - } else if indices.contains(&t) { - indices.push(j); - continue; - } - indices.push(t); - } - if !floyd_shuffle { - // Reimplement SliceRandom::shuffle with smaller indices - for i in (1..amount).rev() { - // invariant: elements with index > i have been locked in place. - indices.swap(i as usize, rng.gen_range(0, i + 1) as usize); - } - } - IndexVec::from(indices) -} - -/// Randomly sample exactly `amount` indices from `0..length`, using an inplace -/// partial Fisher-Yates method. -/// Sample an amount of indices using an inplace partial fisher yates method. -/// -/// This allocates the entire `length` of indices and randomizes only the first `amount`. -/// It then truncates to `amount` and returns. -/// -/// This method is not appropriate for large `length` and potentially uses a lot -/// of memory; because of this we only implement for `u32` index (which improves -/// performance in all cases). -/// -/// Set-up is `O(length)` time and memory and shuffling is `O(amount)` time. -fn sample_inplace(rng: &mut R, length: u32, amount: u32) -> IndexVec -where R: Rng + ?Sized { - debug_assert!(amount <= length); - let mut indices: Vec = Vec::with_capacity(length as usize); - indices.extend(0..length); - for i in 0..amount { - let j: u32 = rng.gen_range(i, length); - indices.swap(i as usize, j as usize); - } - indices.truncate(amount as usize); - debug_assert_eq!(indices.len(), amount as usize); - IndexVec::from(indices) -} - -trait UInt: Copy + PartialOrd + Ord + PartialEq + Eq + SampleUniform + core::hash::Hash { - fn zero() -> Self; - fn as_usize(self) -> usize; -} -impl UInt for u32 { - #[inline] fn zero() -> Self { 0 } - #[inline] fn as_usize(self) -> usize { self as usize } -} -impl UInt for usize { - #[inline] fn zero() -> Self { 0 } - #[inline] fn as_usize(self) -> usize { self } -} - -/// Randomly sample exactly `amount` indices from `0..length`, using rejection -/// sampling. -/// -/// Since `amount <<< length` there is a low chance of a random sample in -/// `0..length` being a duplicate. We test for duplicates and resample where -/// necessary. The algorithm is `O(amount)` time and memory. -/// -/// This function is generic over X primarily so that results are value-stable -/// over 32-bit and 64-bit platforms. -fn sample_rejection(rng: &mut R, length: X, amount: X) -> IndexVec -where R: Rng + ?Sized, IndexVec: From> { - debug_assert!(amount < length); - #[cfg(feature="std")] let mut cache = HashSet::with_capacity(amount.as_usize()); - #[cfg(not(feature="std"))] let mut cache = BTreeSet::new(); - let distr = Uniform::new(X::zero(), length); - let mut indices = Vec::with_capacity(amount.as_usize()); - for _ in 0..amount.as_usize() { - let mut pos = distr.sample(rng); - while !cache.insert(pos) { - pos = distr.sample(rng); - } - indices.push(pos); - } - - debug_assert_eq!(indices.len(), amount.as_usize()); - IndexVec::from(indices) -} - -#[cfg(test)] -mod test { - #[cfg(feature="std")] use std::vec; - #[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::vec; - use super::*; - - #[test] - fn test_sample_boundaries() { - let mut r = crate::test::rng(404); - - assert_eq!(sample_inplace(&mut r, 0, 0).len(), 0); - assert_eq!(sample_inplace(&mut r, 1, 0).len(), 0); - assert_eq!(sample_inplace(&mut r, 1, 1).into_vec(), vec![0]); - - assert_eq!(sample_rejection(&mut r, 1u32, 0).len(), 0); - - assert_eq!(sample_floyd(&mut r, 0, 0).len(), 0); - assert_eq!(sample_floyd(&mut r, 1, 0).len(), 0); - assert_eq!(sample_floyd(&mut r, 1, 1).into_vec(), vec![0]); - - // These algorithms should be fast with big numbers. Test average. - let sum: usize = sample_rejection(&mut r, 1 << 25, 10u32) - .into_iter().sum(); - assert!(1 << 25 < sum && sum < (1 << 25) * 25); - - let sum: usize = sample_floyd(&mut r, 1 << 25, 10) - .into_iter().sum(); - assert!(1 << 25 < sum && sum < (1 << 25) * 25); - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_sample_alg() { - let seed_rng = crate::test::rng; - - // We can't test which algorithm is used directly, but Floyd's alg - // should produce different results from the others. (Also, `inplace` - // and `cached` currently use different sizes thus produce different results.) - - // A small length and relatively large amount should use inplace - let (length, amount): (usize, usize) = (100, 50); - let v1 = sample(&mut seed_rng(420), length, amount); - let v2 = sample_inplace(&mut seed_rng(420), length as u32, amount as u32); - assert!(v1.iter().all(|e| e < length)); - assert_eq!(v1, v2); - - // Test Floyd's alg does produce different results - let v3 = sample_floyd(&mut seed_rng(420), length as u32, amount as u32); - assert!(v1 != v3); - - // A large length and small amount should use Floyd - let (length, amount): (usize, usize) = (1<<20, 50); - let v1 = sample(&mut seed_rng(421), length, amount); - let v2 = sample_floyd(&mut seed_rng(421), length as u32, amount as u32); - assert!(v1.iter().all(|e| e < length)); - assert_eq!(v1, v2); - - // A large length and larger amount should use cache - let (length, amount): (usize, usize) = (1<<20, 600); - let v1 = sample(&mut seed_rng(422), length, amount); - let v2 = sample_rejection(&mut seed_rng(422), length as u32, amount as u32); - assert!(v1.iter().all(|e| e < length)); - assert_eq!(v1, v2); - } -} diff --git a/rand/src/seq/mod.rs b/rand/src/seq/mod.rs deleted file mode 100644 index cec9bb1..0000000 --- a/rand/src/seq/mod.rs +++ /dev/null @@ -1,791 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Sequence-related functionality -//! -//! This module provides: -//! -//! * [`seq::SliceRandom`] slice sampling and mutation -//! * [`seq::IteratorRandom`] iterator sampling -//! * [`seq::index::sample`] low-level API to choose multiple indices from -//! `0..length` -//! -//! Also see: -//! -//! * [`distributions::weighted`] module which provides implementations of -//! weighted index sampling. -//! -//! In order to make results reproducible across 32-64 bit architectures, all -//! `usize` indices are sampled as a `u32` where possible (also providing a -//! small performance boost in some cases). - - -#[cfg(feature="alloc")] pub mod index; - -#[cfg(feature="alloc")] use core::ops::Index; - -#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::vec::Vec; - -use crate::Rng; -#[cfg(feature="alloc")] use crate::distributions::WeightedError; -#[cfg(feature="alloc")] use crate::distributions::uniform::{SampleUniform, SampleBorrow}; - -/// Extension trait on slices, providing random mutation and sampling methods. -/// -/// This trait is implemented on all `[T]` slice types, providing several -/// methods for choosing and shuffling elements. You must `use` this trait: -/// -/// ``` -/// use rand::seq::SliceRandom; -/// -/// fn main() { -/// let mut rng = rand::thread_rng(); -/// let mut bytes = "Hello, random!".to_string().into_bytes(); -/// bytes.shuffle(&mut rng); -/// let str = String::from_utf8(bytes).unwrap(); -/// println!("{}", str); -/// } -/// ``` -/// Example output (non-deterministic): -/// ```none -/// l,nmroHado !le -/// ``` -pub trait SliceRandom { - /// The element type. - type Item; - - /// Returns a reference to one random element of the slice, or `None` if the - /// slice is empty. - /// - /// For slices, complexity is `O(1)`. - /// - /// # Example - /// - /// ``` - /// use rand::thread_rng; - /// use rand::seq::SliceRandom; - /// - /// let choices = [1, 2, 4, 8, 16, 32]; - /// let mut rng = thread_rng(); - /// println!("{:?}", choices.choose(&mut rng)); - /// assert_eq!(choices[..0].choose(&mut rng), None); - /// ``` - fn choose(&self, rng: &mut R) -> Option<&Self::Item> - where R: Rng + ?Sized; - - /// Returns a mutable reference to one random element of the slice, or - /// `None` if the slice is empty. - /// - /// For slices, complexity is `O(1)`. - fn choose_mut(&mut self, rng: &mut R) -> Option<&mut Self::Item> - where R: Rng + ?Sized; - - /// Chooses `amount` elements from the slice at random, without repetition, - /// and in random order. The returned iterator is appropriate both for - /// collection into a `Vec` and filling an existing buffer (see example). - /// - /// In case this API is not sufficiently flexible, use [`index::sample`]. - /// - /// For slices, complexity is the same as [`index::sample`]. - /// - /// # Example - /// ``` - /// use rand::seq::SliceRandom; - /// - /// let mut rng = &mut rand::thread_rng(); - /// let sample = "Hello, audience!".as_bytes(); - /// - /// // collect the results into a vector: - /// let v: Vec = sample.choose_multiple(&mut rng, 3).cloned().collect(); - /// - /// // store in a buffer: - /// let mut buf = [0u8; 5]; - /// for (b, slot) in sample.choose_multiple(&mut rng, buf.len()).zip(buf.iter_mut()) { - /// *slot = *b; - /// } - /// ``` - #[cfg(feature = "alloc")] - fn choose_multiple(&self, rng: &mut R, amount: usize) -> SliceChooseIter - where R: Rng + ?Sized; - - /// Similar to [`choose`], but where the likelihood of each outcome may be - /// specified. - /// - /// The specified function `weight` maps each item `x` to a relative - /// likelihood `weight(x)`. The probability of each item being selected is - /// therefore `weight(x) / s`, where `s` is the sum of all `weight(x)`. - /// - /// For slices of length `n`, complexity is `O(n)`. - /// See also [`choose_weighted_mut`], [`distributions::weighted`]. - /// - /// # Example - /// - /// ``` - /// use rand::prelude::*; - /// - /// let choices = [('a', 2), ('b', 1), ('c', 1)]; - /// let mut rng = thread_rng(); - /// // 50% chance to print 'a', 25% chance to print 'b', 25% chance to print 'c' - /// println!("{:?}", choices.choose_weighted(&mut rng, |item| item.1).unwrap().0); - /// ``` - /// [`choose`]: SliceRandom::choose - /// [`choose_weighted_mut`]: SliceRandom::choose_weighted_mut - /// [`distributions::weighted`]: crate::distributions::weighted - #[cfg(feature = "alloc")] - fn choose_weighted( - &self, rng: &mut R, weight: F, - ) -> Result<&Self::Item, WeightedError> - where - R: Rng + ?Sized, - F: Fn(&Self::Item) -> B, - B: SampleBorrow, - X: SampleUniform - + for<'a> ::core::ops::AddAssign<&'a X> - + ::core::cmp::PartialOrd - + Clone - + Default; - - /// Similar to [`choose_mut`], but where the likelihood of each outcome may - /// be specified. - /// - /// The specified function `weight` maps each item `x` to a relative - /// likelihood `weight(x)`. The probability of each item being selected is - /// therefore `weight(x) / s`, where `s` is the sum of all `weight(x)`. - /// - /// For slices of length `n`, complexity is `O(n)`. - /// See also [`choose_weighted`], [`distributions::weighted`]. - /// - /// [`choose_mut`]: SliceRandom::choose_mut - /// [`choose_weighted`]: SliceRandom::choose_weighted - /// [`distributions::weighted`]: crate::distributions::weighted - #[cfg(feature = "alloc")] - fn choose_weighted_mut( - &mut self, rng: &mut R, weight: F, - ) -> Result<&mut Self::Item, WeightedError> - where - R: Rng + ?Sized, - F: Fn(&Self::Item) -> B, - B: SampleBorrow, - X: SampleUniform - + for<'a> ::core::ops::AddAssign<&'a X> - + ::core::cmp::PartialOrd - + Clone - + Default; - - /// Shuffle a mutable slice in place. - /// - /// For slices of length `n`, complexity is `O(n)`. - /// - /// # Example - /// - /// ``` - /// use rand::seq::SliceRandom; - /// use rand::thread_rng; - /// - /// let mut rng = thread_rng(); - /// let mut y = [1, 2, 3, 4, 5]; - /// println!("Unshuffled: {:?}", y); - /// y.shuffle(&mut rng); - /// println!("Shuffled: {:?}", y); - /// ``` - fn shuffle(&mut self, rng: &mut R) - where R: Rng + ?Sized; - - /// Shuffle a slice in place, but exit early. - /// - /// Returns two mutable slices from the source slice. The first contains - /// `amount` elements randomly permuted. The second has the remaining - /// elements that are not fully shuffled. - /// - /// This is an efficient method to select `amount` elements at random from - /// the slice, provided the slice may be mutated. - /// - /// If you only need to choose elements randomly and `amount > self.len()/2` - /// then you may improve performance by taking - /// `amount = values.len() - amount` and using only the second slice. - /// - /// If `amount` is greater than the number of elements in the slice, this - /// will perform a full shuffle. - /// - /// For slices, complexity is `O(m)` where `m = amount`. - fn partial_shuffle( - &mut self, rng: &mut R, amount: usize, - ) -> (&mut [Self::Item], &mut [Self::Item]) - where R: Rng + ?Sized; -} - -/// Extension trait on iterators, providing random sampling methods. -/// -/// This trait is implemented on all sized iterators, providing methods for -/// choosing one or more elements. You must `use` this trait: -/// -/// ``` -/// use rand::seq::IteratorRandom; -/// -/// fn main() { -/// let mut rng = rand::thread_rng(); -/// -/// let faces = "😀😎😐😕😠😢"; -/// println!("I am {}!", faces.chars().choose(&mut rng).unwrap()); -/// } -/// ``` -/// Example output (non-deterministic): -/// ```none -/// I am 😀! -/// ``` -pub trait IteratorRandom: Iterator + Sized { - /// Choose one element at random from the iterator. - /// - /// Returns `None` if and only if the iterator is empty. - /// - /// This method uses [`Iterator::size_hint`] for optimisation. With an - /// accurate hint and where [`Iterator::nth`] is a constant-time operation - /// this method can offer `O(1)` performance. Where no size hint is - /// available, complexity is `O(n)` where `n` is the iterator length. - /// Partial hints (where `lower > 0`) also improve performance. - /// - /// For slices, prefer [`SliceRandom::choose`] which guarantees `O(1)` - /// performance. - fn choose(mut self, rng: &mut R) -> Option - where R: Rng + ?Sized { - let (mut lower, mut upper) = self.size_hint(); - let mut consumed = 0; - let mut result = None; - - if upper == Some(lower) { - return if lower == 0 { None } else { self.nth(gen_index(rng, lower)) }; - } - - // Continue until the iterator is exhausted - loop { - if lower > 1 { - let ix = gen_index(rng, lower + consumed); - let skip = if ix < lower { - result = self.nth(ix); - lower - (ix + 1) - } else { - lower - }; - if upper == Some(lower) { - return result; - } - consumed += lower; - if skip > 0 { - self.nth(skip - 1); - } - } else { - let elem = self.next(); - if elem.is_none() { - return result; - } - consumed += 1; - let denom = consumed as f64; // accurate to 2^53 elements - if rng.gen_bool(1.0 / denom) { - result = elem; - } - } - - let hint = self.size_hint(); - lower = hint.0; - upper = hint.1; - } - } - - /// Collects values at random from the iterator into a supplied buffer - /// until that buffer is filled. - /// - /// Although the elements are selected randomly, the order of elements in - /// the buffer is neither stable nor fully random. If random ordering is - /// desired, shuffle the result. - /// - /// Returns the number of elements added to the buffer. This equals the length - /// of the buffer unless the iterator contains insufficient elements, in which - /// case this equals the number of elements available. - /// - /// Complexity is `O(n)` where `n` is the length of the iterator. - /// For slices, prefer [`SliceRandom::choose_multiple`]. - fn choose_multiple_fill(mut self, rng: &mut R, buf: &mut [Self::Item]) -> usize - where R: Rng + ?Sized { - let amount = buf.len(); - let mut len = 0; - while len < amount { - if let Some(elem) = self.next() { - buf[len] = elem; - len += 1; - } else { - // Iterator exhausted; stop early - return len; - } - } - - // Continue, since the iterator was not exhausted - for (i, elem) in self.enumerate() { - let k = gen_index(rng, i + 1 + amount); - if let Some(slot) = buf.get_mut(k) { - *slot = elem; - } - } - len - } - - /// Collects `amount` values at random from the iterator into a vector. - /// - /// This is equivalent to `choose_multiple_fill` except for the result type. - /// - /// Although the elements are selected randomly, the order of elements in - /// the buffer is neither stable nor fully random. If random ordering is - /// desired, shuffle the result. - /// - /// The length of the returned vector equals `amount` unless the iterator - /// contains insufficient elements, in which case it equals the number of - /// elements available. - /// - /// Complexity is `O(n)` where `n` is the length of the iterator. - /// For slices, prefer [`SliceRandom::choose_multiple`]. - #[cfg(feature = "alloc")] - fn choose_multiple(mut self, rng: &mut R, amount: usize) -> Vec - where R: Rng + ?Sized { - let mut reservoir = Vec::with_capacity(amount); - reservoir.extend(self.by_ref().take(amount)); - - // Continue unless the iterator was exhausted - // - // note: this prevents iterators that "restart" from causing problems. - // If the iterator stops once, then so do we. - if reservoir.len() == amount { - for (i, elem) in self.enumerate() { - let k = gen_index(rng, i + 1 + amount); - if let Some(slot) = reservoir.get_mut(k) { - *slot = elem; - } - } - } else { - // Don't hang onto extra memory. There is a corner case where - // `amount` was much less than `self.len()`. - reservoir.shrink_to_fit(); - } - reservoir - } -} - - -impl SliceRandom for [T] { - type Item = T; - - fn choose(&self, rng: &mut R) -> Option<&Self::Item> - where R: Rng + ?Sized { - if self.is_empty() { - None - } else { - Some(&self[gen_index(rng, self.len())]) - } - } - - fn choose_mut(&mut self, rng: &mut R) -> Option<&mut Self::Item> - where R: Rng + ?Sized { - if self.is_empty() { - None - } else { - let len = self.len(); - Some(&mut self[gen_index(rng, len)]) - } - } - - #[cfg(feature = "alloc")] - fn choose_multiple(&self, rng: &mut R, amount: usize) -> SliceChooseIter - where R: Rng + ?Sized { - let amount = ::core::cmp::min(amount, self.len()); - SliceChooseIter { - slice: self, - _phantom: Default::default(), - indices: index::sample(rng, self.len(), amount).into_iter(), - } - } - - #[cfg(feature = "alloc")] - fn choose_weighted( - &self, rng: &mut R, weight: F, - ) -> Result<&Self::Item, WeightedError> - where - R: Rng + ?Sized, - F: Fn(&Self::Item) -> B, - B: SampleBorrow, - X: SampleUniform - + for<'a> ::core::ops::AddAssign<&'a X> - + ::core::cmp::PartialOrd - + Clone - + Default, - { - use crate::distributions::{Distribution, WeightedIndex}; - let distr = WeightedIndex::new(self.iter().map(weight))?; - Ok(&self[distr.sample(rng)]) - } - - #[cfg(feature = "alloc")] - fn choose_weighted_mut( - &mut self, rng: &mut R, weight: F, - ) -> Result<&mut Self::Item, WeightedError> - where - R: Rng + ?Sized, - F: Fn(&Self::Item) -> B, - B: SampleBorrow, - X: SampleUniform - + for<'a> ::core::ops::AddAssign<&'a X> - + ::core::cmp::PartialOrd - + Clone - + Default, - { - use crate::distributions::{Distribution, WeightedIndex}; - let distr = WeightedIndex::new(self.iter().map(weight))?; - Ok(&mut self[distr.sample(rng)]) - } - - fn shuffle(&mut self, rng: &mut R) - where R: Rng + ?Sized { - for i in (1..self.len()).rev() { - // invariant: elements with index > i have been locked in place. - self.swap(i, gen_index(rng, i + 1)); - } - } - - fn partial_shuffle( - &mut self, rng: &mut R, amount: usize, - ) -> (&mut [Self::Item], &mut [Self::Item]) - where R: Rng + ?Sized { - // This applies Durstenfeld's algorithm for the - // [Fisher–Yates shuffle](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm) - // for an unbiased permutation, but exits early after choosing `amount` - // elements. - - let len = self.len(); - let end = if amount >= len { 0 } else { len - amount }; - - for i in (end..len).rev() { - // invariant: elements with index > i have been locked in place. - self.swap(i, gen_index(rng, i + 1)); - } - let r = self.split_at_mut(end); - (r.1, r.0) - } -} - -impl IteratorRandom for I where I: Iterator + Sized {} - - -/// An iterator over multiple slice elements. -/// -/// This struct is created by -/// [`SliceRandom::choose_multiple`](trait.SliceRandom.html#tymethod.choose_multiple). -#[cfg(feature = "alloc")] -#[derive(Debug)] -pub struct SliceChooseIter<'a, S: ?Sized + 'a, T: 'a> { - slice: &'a S, - _phantom: ::core::marker::PhantomData, - indices: index::IndexVecIntoIter, -} - -#[cfg(feature = "alloc")] -impl<'a, S: Index + ?Sized + 'a, T: 'a> Iterator for SliceChooseIter<'a, S, T> { - type Item = &'a T; - - fn next(&mut self) -> Option { - // TODO: investigate using SliceIndex::get_unchecked when stable - self.indices.next().map(|i| &self.slice[i as usize]) - } - - fn size_hint(&self) -> (usize, Option) { - (self.indices.len(), Some(self.indices.len())) - } -} - -#[cfg(feature = "alloc")] -impl<'a, S: Index + ?Sized + 'a, T: 'a> ExactSizeIterator - for SliceChooseIter<'a, S, T> -{ - fn len(&self) -> usize { - self.indices.len() - } -} - - -// Sample a number uniformly between 0 and `ubound`. Uses 32-bit sampling where -// possible, primarily in order to produce the same output on 32-bit and 64-bit -// platforms. -#[inline] -fn gen_index(rng: &mut R, ubound: usize) -> usize { - if ubound <= (core::u32::MAX as usize) { - rng.gen_range(0, ubound as u32) as usize - } else { - rng.gen_range(0, ubound) - } -} - - -#[cfg(test)] -mod test { - use super::*; - #[cfg(feature = "alloc")] use crate::Rng; - #[cfg(all(feature="alloc", not(feature="std")))] - use alloc::vec::Vec; - - #[test] - fn test_slice_choose() { - let mut r = crate::test::rng(107); - let chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']; - let mut chosen = [0i32; 14]; - // The below all use a binomial distribution with n=1000, p=1/14. - // binocdf(40, 1000, 1/14) ~= 2e-5; 1-binocdf(106, ..) ~= 2e-5 - for _ in 0..1000 { - let picked = *chars.choose(&mut r).unwrap(); - chosen[(picked as usize) - ('a' as usize)] += 1; - } - for count in chosen.iter() { - assert!(40 < *count && *count < 106); - } - - chosen.iter_mut().for_each(|x| *x = 0); - for _ in 0..1000 { - *chosen.choose_mut(&mut r).unwrap() += 1; - } - for count in chosen.iter() { - assert!(40 < *count && *count < 106); - } - - let mut v: [isize; 0] = []; - assert_eq!(v.choose(&mut r), None); - assert_eq!(v.choose_mut(&mut r), None); - } - - #[derive(Clone)] - struct UnhintedIterator { - iter: I, - } - impl Iterator for UnhintedIterator { - type Item = I::Item; - fn next(&mut self) -> Option { - self.iter.next() - } - } - - #[derive(Clone)] - struct ChunkHintedIterator { - iter: I, - chunk_remaining: usize, - chunk_size: usize, - hint_total_size: bool, - } - impl Iterator for ChunkHintedIterator { - type Item = I::Item; - fn next(&mut self) -> Option { - if self.chunk_remaining == 0 { - self.chunk_remaining = ::core::cmp::min(self.chunk_size, - self.iter.len()); - } - self.chunk_remaining = self.chunk_remaining.saturating_sub(1); - - self.iter.next() - } - fn size_hint(&self) -> (usize, Option) { - (self.chunk_remaining, - if self.hint_total_size { Some(self.iter.len()) } else { None }) - } - } - - #[derive(Clone)] - struct WindowHintedIterator { - iter: I, - window_size: usize, - hint_total_size: bool, - } - impl Iterator for WindowHintedIterator { - type Item = I::Item; - fn next(&mut self) -> Option { - self.iter.next() - } - fn size_hint(&self) -> (usize, Option) { - (::core::cmp::min(self.iter.len(), self.window_size), - if self.hint_total_size { Some(self.iter.len()) } else { None }) - } - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_iterator_choose() { - let r = &mut crate::test::rng(109); - fn test_iter + Clone>(r: &mut R, iter: Iter) { - let mut chosen = [0i32; 9]; - for _ in 0..1000 { - let picked = iter.clone().choose(r).unwrap(); - chosen[picked] += 1; - } - for count in chosen.iter() { - // Samples should follow Binomial(1000, 1/9) - // Octave: binopdf(x, 1000, 1/9) gives the prob of *count == x - // Note: have seen 153, which is unlikely but not impossible. - assert!(72 < *count && *count < 154, "count not close to 1000/9: {}", count); - } - } - - test_iter(r, 0..9); - test_iter(r, [0, 1, 2, 3, 4, 5, 6, 7, 8].iter().cloned()); - #[cfg(feature = "alloc")] - test_iter(r, (0..9).collect::>().into_iter()); - test_iter(r, UnhintedIterator { iter: 0..9 }); - test_iter(r, ChunkHintedIterator { iter: 0..9, chunk_size: 4, chunk_remaining: 4, hint_total_size: false }); - test_iter(r, ChunkHintedIterator { iter: 0..9, chunk_size: 4, chunk_remaining: 4, hint_total_size: true }); - test_iter(r, WindowHintedIterator { iter: 0..9, window_size: 2, hint_total_size: false }); - test_iter(r, WindowHintedIterator { iter: 0..9, window_size: 2, hint_total_size: true }); - - assert_eq!((0..0).choose(r), None); - assert_eq!(UnhintedIterator{ iter: 0..0 }.choose(r), None); - } - - #[test] - #[cfg(not(miri))] // Miri is too slow - fn test_shuffle() { - let mut r = crate::test::rng(108); - let empty: &mut [isize] = &mut []; - empty.shuffle(&mut r); - let mut one = [1]; - one.shuffle(&mut r); - let b: &[_] = &[1]; - assert_eq!(one, b); - - let mut two = [1, 2]; - two.shuffle(&mut r); - assert!(two == [1, 2] || two == [2, 1]); - - fn move_last(slice: &mut [usize], pos: usize) { - // use slice[pos..].rotate_left(1); once we can use that - let last_val = slice[pos]; - for i in pos..slice.len() - 1 { - slice[i] = slice[i + 1]; - } - *slice.last_mut().unwrap() = last_val; - } - let mut counts = [0i32; 24]; - for _ in 0..10000 { - let mut arr: [usize; 4] = [0, 1, 2, 3]; - arr.shuffle(&mut r); - let mut permutation = 0usize; - let mut pos_value = counts.len(); - for i in 0..4 { - pos_value /= 4 - i; - let pos = arr.iter().position(|&x| x == i).unwrap(); - assert!(pos < (4 - i)); - permutation += pos * pos_value; - move_last(&mut arr, pos); - assert_eq!(arr[3], i); - } - for i in 0..4 { - assert_eq!(arr[i], i); - } - counts[permutation] += 1; - } - for count in counts.iter() { - // Binomial(10000, 1/24) with average 416.667 - // Octave: binocdf(n, 10000, 1/24) - // 99.9% chance samples lie within this range: - assert!(352 <= *count && *count <= 483, "count: {}", count); - } - } - - #[test] - fn test_partial_shuffle() { - let mut r = crate::test::rng(118); - - let mut empty: [u32; 0] = []; - let res = empty.partial_shuffle(&mut r, 10); - assert_eq!((res.0.len(), res.1.len()), (0, 0)); - - let mut v = [1, 2, 3, 4, 5]; - let res = v.partial_shuffle(&mut r, 2); - assert_eq!((res.0.len(), res.1.len()), (2, 3)); - assert!(res.0[0] != res.0[1]); - // First elements are only modified if selected, so at least one isn't modified: - assert!(res.1[0] == 1 || res.1[1] == 2 || res.1[2] == 3); - } - - #[test] - #[cfg(feature = "alloc")] - fn test_sample_iter() { - let min_val = 1; - let max_val = 100; - - let mut r = crate::test::rng(401); - let vals = (min_val..max_val).collect::>(); - let small_sample = vals.iter().choose_multiple(&mut r, 5); - let large_sample = vals.iter().choose_multiple(&mut r, vals.len() + 5); - - assert_eq!(small_sample.len(), 5); - assert_eq!(large_sample.len(), vals.len()); - // no randomization happens when amount >= len - assert_eq!(large_sample, vals.iter().collect::>()); - - assert!(small_sample.iter().all(|e| { - **e >= min_val && **e <= max_val - })); - } - - #[test] - #[cfg(feature = "alloc")] - #[cfg(not(miri))] // Miri is too slow - fn test_weighted() { - let mut r = crate::test::rng(406); - const N_REPS: u32 = 3000; - let weights = [1u32, 2, 3, 0, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7]; - let total_weight = weights.iter().sum::() as f32; - - let verify = |result: [i32; 14]| { - for (i, count) in result.iter().enumerate() { - let exp = (weights[i] * N_REPS) as f32 / total_weight; - let mut err = (*count as f32 - exp).abs(); - if err != 0.0 { - err /= exp; - } - assert!(err <= 0.25); - } - }; - - // choose_weighted - fn get_weight(item: &(u32, T)) -> u32 { - item.0 - } - let mut chosen = [0i32; 14]; - let mut items = [(0u32, 0usize); 14]; // (weight, index) - for (i, item) in items.iter_mut().enumerate() { - *item = (weights[i], i); - } - for _ in 0..N_REPS { - let item = items.choose_weighted(&mut r, get_weight).unwrap(); - chosen[item.1] += 1; - } - verify(chosen); - - // choose_weighted_mut - let mut items = [(0u32, 0i32); 14]; // (weight, count) - for (i, item) in items.iter_mut().enumerate() { - *item = (weights[i], 0); - } - for _ in 0..N_REPS { - items.choose_weighted_mut(&mut r, get_weight).unwrap().1 += 1; - } - for (ch, item) in chosen.iter_mut().zip(items.iter()) { - *ch = item.1; - } - verify(chosen); - - // Check error cases - let empty_slice = &mut [10][0..0]; - assert_eq!(empty_slice.choose_weighted(&mut r, |_| 1), Err(WeightedError::NoItem)); - assert_eq!(empty_slice.choose_weighted_mut(&mut r, |_| 1), Err(WeightedError::NoItem)); - assert_eq!(['x'].choose_weighted_mut(&mut r, |_| 0), Err(WeightedError::AllWeightsZero)); - assert_eq!([0, -1].choose_weighted_mut(&mut r, |x| *x), Err(WeightedError::InvalidWeight)); - assert_eq!([-1, 0].choose_weighted_mut(&mut r, |x| *x), Err(WeightedError::InvalidWeight)); - } -} diff --git a/rand/tests/wasm_bindgen/Cargo.toml b/rand/tests/wasm_bindgen/Cargo.toml deleted file mode 100644 index e83c174..0000000 --- a/rand/tests/wasm_bindgen/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "rand_wasm_bindgen_test" -description = "Minimal crate to test that rand can be build for web assembly target" -version = "0.1.0" -authors = ["The Rand Project Developers"] -publish = false -license = "MIT OR Apache-2.0" -edition = "2018" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -rand = { path = "../..", features = ["wasm-bindgen"] } -wasm-bindgen = "0.2" -wasm-bindgen-test = "0.2" diff --git a/rand/tests/wasm_bindgen/js/index.js b/rand/tests/wasm_bindgen/js/index.js deleted file mode 100644 index a02fb59..0000000 --- a/rand/tests/wasm_bindgen/js/index.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -const rand_wasm_bindgen_test = require('./rand_wasm_bindgen_test'); - -console.log(rand_wasm_bindgen_test.generate_from_entropy()); -console.log(rand_wasm_bindgen_test.generate_from_os_rand()); -console.log(rand_wasm_bindgen_test.generate_from_seed()); diff --git a/rand/tests/wasm_bindgen/src/lib.rs b/rand/tests/wasm_bindgen/src/lib.rs deleted file mode 100644 index 9af0b9e..0000000 --- a/rand/tests/wasm_bindgen/src/lib.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Crate to test WASM with the `wasm-bindgen` lib. - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png")] - -use rand::rngs::{OsRng, StdRng}; -use rand::{Rng, SeedableRng}; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -pub fn generate_from_seed(seed: u32) -> i32 { - StdRng::seed_from_u64(seed as u64).gen() -} - -#[wasm_bindgen] -pub fn generate_from_os_rand() -> i32 { - OsRng.gen() -} - -#[wasm_bindgen] -pub fn generate_from_entropy() -> i32 { - StdRng::from_entropy().gen() -} - -pub mod tests { - use wasm_bindgen_test::*; - - #[wasm_bindgen_test] - fn generate_from_seed() { - let _ = super::generate_from_seed(42); - } - - #[wasm_bindgen_test] - fn generate_from_os_rand() { - let _ = super::generate_from_os_rand(); - } - - #[wasm_bindgen_test] - fn generate_from_entropy() { - let _ = super::generate_from_entropy(); - } -} diff --git a/rand/utils/ci/install.sh b/rand/utils/ci/install.sh deleted file mode 100644 index 8e636e1..0000000 --- a/rand/utils/ci/install.sh +++ /dev/null @@ -1,49 +0,0 @@ -# From https://github.com/japaric/trust - -set -ex - -main() { - local target= - if [ $TRAVIS_OS_NAME = linux ]; then - target=x86_64-unknown-linux-musl - sort=sort - else - target=x86_64-apple-darwin - sort=gsort # for `sort --sort-version`, from brew's coreutils. - fi - - # Builds for iOS are done on OSX, but require the specific target to be - # installed. - case $TARGET in - aarch64-apple-ios) - rustup target install aarch64-apple-ios - ;; - armv7-apple-ios) - rustup target install armv7-apple-ios - ;; - armv7s-apple-ios) - rustup target install armv7s-apple-ios - ;; - i386-apple-ios) - rustup target install i386-apple-ios - ;; - x86_64-apple-ios) - rustup target install x86_64-apple-ios - ;; - esac - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0.1.0-9.]+$' \ - | $sort --version-sort \ - | tail -n1) - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git japaric/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/rand/utils/ci/install_cargo_web.sh b/rand/utils/ci/install_cargo_web.sh deleted file mode 100755 index b35f069..0000000 --- a/rand/utils/ci/install_cargo_web.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -euo pipefail -IFS=$'\n\t' - -CARGO_WEB_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/koute/cargo-web/releases/latest) -CARGO_WEB_VERSION=$(echo $CARGO_WEB_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') -CARGO_WEB_URL="https://github.com/koute/cargo-web/releases/download/$CARGO_WEB_VERSION/cargo-web-x86_64-unknown-linux-gnu.gz" - -echo "Downloading cargo-web from: $CARGO_WEB_URL" -curl -L $CARGO_WEB_URL | gzip -d > cargo-web -chmod +x cargo-web - -mkdir -p ~/.cargo/bin -mv cargo-web ~/.cargo/bin diff --git a/rand/utils/ci/miri.sh b/rand/utils/ci/miri.sh deleted file mode 100644 index 209adf2..0000000 --- a/rand/utils/ci/miri.sh +++ /dev/null @@ -1,23 +0,0 @@ -set -ex - -MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri) -echo "Installing latest nightly with Miri: $MIRI_NIGHTLY" -rustup default "$MIRI_NIGHTLY" - -rustup component add miri -cargo miri setup - -cargo miri test --no-default-features -- -- -Zunstable-options --exclude-should-panic -cargo miri test --features=log -- -- -Zunstable-options --exclude-should-panic -cargo miri test --manifest-path rand_core/Cargo.toml -cargo miri test --manifest-path rand_core/Cargo.toml --features=serde1 -cargo miri test --manifest-path rand_core/Cargo.toml --no-default-features -#cargo miri test --manifest-path rand_distr/Cargo.toml # no unsafe and lots of slow tests -cargo miri test --manifest-path rand_isaac/Cargo.toml --features=serde1 -cargo miri test --manifest-path rand_pcg/Cargo.toml --features=serde1 -cargo miri test --manifest-path rand_xorshift/Cargo.toml --features=serde1 -cargo miri test --manifest-path rand_xoshiro/Cargo.toml --features=serde1 -cargo miri test --manifest-path rand_chacha/Cargo.toml --no-default-features -cargo miri test --manifest-path rand_hc/Cargo.toml -cargo miri test --manifest-path rand_jitter/Cargo.toml -cargo miri test --manifest-path rand_os/Cargo.toml diff --git a/rand/utils/ci/script.sh b/rand/utils/ci/script.sh deleted file mode 100644 index 852a850..0000000 --- a/rand/utils/ci/script.sh +++ /dev/null @@ -1,27 +0,0 @@ -# Derived from https://github.com/japaric/trust - -set -ex - -main() { - cross test --target $TARGET --tests --no-default-features - # TODO: add simd_support feature: - cross test --target $TARGET --features=log - cross test --target $TARGET --examples - cross test --target $TARGET --manifest-path rand_core/Cargo.toml - cross test --target $TARGET --manifest-path rand_core/Cargo.toml --features=serde1 - cross test --target $TARGET --manifest-path rand_core/Cargo.toml --no-default-features - cross test --target $TARGET --manifest-path rand_distr/Cargo.toml - cross test --target $TARGET --manifest-path rand_isaac/Cargo.toml --features=serde1 - cross test --target $TARGET --manifest-path rand_pcg/Cargo.toml --features=serde1 - cross test --target $TARGET --manifest-path rand_xorshift/Cargo.toml --features=serde1 - cross test --target $TARGET --manifest-path rand_xoshiro/Cargo.toml --features=serde1 - cross test --target $TARGET --manifest-path rand_chacha/Cargo.toml - cross test --target $TARGET --manifest-path rand_hc/Cargo.toml - cross test --target $TARGET --manifest-path rand_os/Cargo.toml - cross test --target $TARGET --manifest-path rand_jitter/Cargo.toml -} - -# we don't run the "test phase" when doing deploys -if [ -z $TRAVIS_TAG ]; then - main -fi diff --git a/rand/utils/ziggurat_tables.py b/rand/utils/ziggurat_tables.py deleted file mode 100755 index 88cfdab..0000000 --- a/rand/utils/ziggurat_tables.py +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2018 Developers of the Rand project. -# Copyright 2013 The Rust Project Developers. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -# This creates the tables used for distributions implemented using the -# ziggurat algorithm in `rand::distributions;`. They are -# (basically) the tables as used in the ZIGNOR variant (Doornik 2005). -# They are changed rarely, so the generated file should be checked in -# to git. -# -# It creates 3 tables: X as in the paper, F which is f(x_i), and -# F_DIFF which is f(x_i) - f(x_{i-1}). The latter two are just cached -# values which is not done in that paper (but is done in other -# variants). Note that the adZigR table is unnecessary because of -# algebra. -# -# It is designed to be compatible with Python 2 and 3. - -from math import exp, sqrt, log, floor -import random - -# The order should match the return value of `tables` -TABLE_NAMES = ['X', 'F'] - -# The actual length of the table is 1 more, to stop -# index-out-of-bounds errors. This should match the bitwise operation -# to find `i` in `zigurrat` in `libstd/rand/mod.rs`. Also the *_R and -# *_V constants below depend on this value. -TABLE_LEN = 256 - -# equivalent to `zigNorInit` in Doornik2005, but generalised to any -# distribution. r = dR, v = dV, f = probability density function, -# f_inv = inverse of f -def tables(r, v, f, f_inv): - # compute the x_i - xvec = [0]*(TABLE_LEN+1) - - xvec[0] = v / f(r) - xvec[1] = r - - for i in range(2, TABLE_LEN): - last = xvec[i-1] - xvec[i] = f_inv(v / last + f(last)) - - # cache the f's - fvec = [0]*(TABLE_LEN+1) - for i in range(TABLE_LEN+1): - fvec[i] = f(xvec[i]) - - return xvec, fvec - -# Distributions -# N(0, 1) -def norm_f(x): - return exp(-x*x/2.0) -def norm_f_inv(y): - return sqrt(-2.0*log(y)) - -NORM_R = 3.6541528853610088 -NORM_V = 0.00492867323399 - -NORM = tables(NORM_R, NORM_V, - norm_f, norm_f_inv) - -# Exp(1) -def exp_f(x): - return exp(-x) -def exp_f_inv(y): - return -log(y) - -EXP_R = 7.69711747013104972 -EXP_V = 0.0039496598225815571993 - -EXP = tables(EXP_R, EXP_V, - exp_f, exp_f_inv) - - -# Output the tables/constants/types - -def render_static(name, type, value): - # no space or - return 'pub static %s: %s =%s;\n' % (name, type, value) - -# static `name`: [`type`, .. `len(values)`] = -# [values[0], ..., values[3], -# values[4], ..., values[7], -# ... ]; -def render_table(name, values): - rows = [] - # 4 values on each row - for i in range(0, len(values), 4): - row = values[i:i+4] - rows.append(', '.join('%.18f' % f for f in row)) - - rendered = '\n [%s]' % ',\n '.join(rows) - return render_static(name, '[f64, .. %d]' % len(values), rendered) - - -with open('ziggurat_tables.rs', 'w') as f: - f.write('''// Copyright 2018 Developers of the Rand project. -// Copyright 2013 The Rust Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Tables for distributions which are sampled using the ziggurat -// algorithm. Autogenerated by `ziggurat_tables.py`. - -pub type ZigTable = &\'static [f64, .. %d]; -''' % (TABLE_LEN + 1)) - for name, tables, r in [('NORM', NORM, NORM_R), - ('EXP', EXP, EXP_R)]: - f.write(render_static('ZIG_%s_R' % name, 'f64', ' %.18f' % r)) - for (tabname, table) in zip(TABLE_NAMES, tables): - f.write(render_table('ZIG_%s_%s' % (name, tabname), table)) -- cgit v1.2.3