
# Copyright (C) Igor Sysoev
# Copyright (C) NGINX, Inc.


# Linux 2.6, FreeBSD 8.2, 9.1, Solaris 11.

nxt_feature="posix_fadvise()"
nxt_feature_name=NXT_HAVE_POSIX_FADVISE
nxt_feature_run=
nxt_feature_incs=
nxt_feature_libs=
nxt_feature_test="#include <fcntl.h>

                  int main(void) {
                      (void) posix_fadvise(0, 0, 0, POSIX_FADV_WILLNEED);
                      return 0;
                  }"
. auto/feature


# FreeBSD 8.0.

nxt_feature="fcntl(F_READAHEAD)"
nxt_feature_name=NXT_HAVE_READAHEAD
nxt_feature_run=
nxt_feature_incs=
nxt_feature_libs=
nxt_feature_test="#include <fcntl.h>

                  int main(void) {
                      (void) fcntl(0, F_READAHEAD, 1024);
                      return 0;
                  }"
. auto/feature


# MacOSX, FreeBSD 8.0.

nxt_feature="fcntl(F_RDAHEAD)"
nxt_feature_name=NXT_HAVE_RDAHEAD
nxt_feature_run=
nxt_feature_incs=
nxt_feature_libs=
nxt_feature_test="#include <fcntl.h>

                  int main(void) {
                      (void) fcntl(0, F_RDAHEAD, 1);
                      return 0;
                  }"
. auto/feature


# pipe2(), Linux 2.6.27/glibc 2.9, FreeBSD 10.0, NetBSD 6.0, OpenBSD 5.7.

nxt_feature="pipe2()"
nxt_feature_name=NXT_HAVE_PIPE2
nxt_feature_run=
nxt_feature_incs=
nxt_feature_libs=
nxt_feature_test="#define _GNU_SOURCE
                  #include <fcntl.h>
                  #include <unistd.h>

                  int main(void) {
                      int  pp[2];
                      return pipe2(pp, O_CLOEXEC);
                  }"
. auto/feature


# close_range(), Linux 5.9 with glibc 2.34, FreeBSD 12.2.

nxt_feature="close_range()"
nxt_feature_name=NXT_HAVE_CLOSE_RANGE
nxt_feature_run=
nxt_feature_incs=
nxt_feature_libs=
nxt_feature_test="#define _GNU_SOURCE
                  #include <unistd.h>

                  int main(void) {
                      return close_range(3, ~0U, 0);
                  }"
. auto/feature


if [ $nxt_found = no ]; then

    # A libc without the wrapper, such as musl, may still have the number.

    nxt_feature="close_range() syscall"
    nxt_feature_name=NXT_HAVE_SYS_CLOSE_RANGE
    nxt_feature_test="#include <unistd.h>
                      #include <sys/syscall.h>

                      int main(void) {
                          return syscall(SYS_close_range, 3, ~0U, 0);
                      }"
    . auto/feature
fi


# closefrom(), FreeBSD 8.0, NetBSD 3.0, OpenBSD 3.5, Solaris 9.
# Solaris and illumos declare it in <stdlib.h>, the others in <unistd.h>.

nxt_feature="closefrom()"
nxt_feature_name=NXT_HAVE_CLOSEFROM
nxt_feature_run=
nxt_feature_incs=
nxt_feature_libs=
nxt_feature_test="#include <stdlib.h>
                  #include <unistd.h>

                  int main(void) {
                      closefrom(3);
                      return 0;
                  }"
. auto/feature


nxt_feature="openat2()"
nxt_feature_name=NXT_HAVE_OPENAT2
nxt_feature_run=
nxt_feature_incs=
nxt_feature_libs=
nxt_feature_test="#include <fcntl.h>
                  #include <unistd.h>
                  #include <sys/syscall.h>
                  #include <linux/openat2.h>
                  #include <string.h>

                  int main(void) {
                      struct open_how  how;

                      memset(&how, 0, sizeof(how));

                      how.flags = O_RDONLY;
                      how.mode = O_NONBLOCK;
                      how.resolve = RESOLVE_IN_ROOT
                                    | RESOLVE_NO_SYMLINKS
                                    | RESOLVE_NO_XDEV;

                      int fd = syscall(SYS_openat2, AT_FDCWD, \".\",
                                       &how, sizeof(how));
                      if (fd == -1)
                          return 1;

                      return 0;
                  }"
. auto/feature
