1dnl openbsd in it's neverending brokenness requires stdint.h for intptr_t,
2dnl but that header isn't very portable...
3AC_CHECK_HEADERS([stdint.h sys/syscall.h sys/prctl.h])
4
5AC_SEARCH_LIBS(
6   pthread_create,
7   [pthread pthreads pthreadVC2],
8   ,
9   [AC_MSG_ERROR(pthread functions not found)]
10)
11
12AC_CACHE_CHECK(for utimes, ac_cv_utimes, [AC_LINK_IFELSE([[
13#include <sys/types.h>
14#include <sys/time.h>
15#include <utime.h>
16struct timeval tv[2];
17int res;
18int main (void)
19{
20   res = utimes ("/", tv);
21   return 0;
22}
23]],ac_cv_utimes=yes,ac_cv_utimes=no)])
24test $ac_cv_utimes = yes && AC_DEFINE(HAVE_UTIMES, 1, utimes(2) is available)
25
26AC_CACHE_CHECK(for futimes, ac_cv_futimes, [AC_LINK_IFELSE([[
27#include <sys/types.h>
28#include <sys/time.h>
29#include <utime.h>
30struct timeval tv[2];
31int res;
32int fd;
33int main (void)
34{
35   res = futimes (fd, tv);
36   return 0;
37}
38]],ac_cv_futimes=yes,ac_cv_futimes=no)])
39test $ac_cv_futimes = yes && AC_DEFINE(HAVE_FUTIMES, 1, futimes(2) is available)
40
41AC_CACHE_CHECK(for readahead, ac_cv_readahead, [AC_LINK_IFELSE([
42#include <fcntl.h>
43int main (void)
44{
45   int fd = 0;
46   size_t count = 2;
47   ssize_t res;
48   res = readahead (fd, 0, count);
49   return 0;
50}
51],ac_cv_readahead=yes,ac_cv_readahead=no)])
52test $ac_cv_readahead = yes && AC_DEFINE(HAVE_READAHEAD, 1, readahead(2) is available (linux))
53
54AC_CACHE_CHECK(for fdatasync, ac_cv_fdatasync, [AC_LINK_IFELSE([
55#include <unistd.h>
56int main (void)
57{
58   int fd = 0;
59   fdatasync (fd);
60   return 0;
61}
62],ac_cv_fdatasync=yes,ac_cv_fdatasync=no)])
63test $ac_cv_fdatasync = yes && AC_DEFINE(HAVE_FDATASYNC, 1, fdatasync(2) is available)
64
65AC_CACHE_CHECK(for sendfile, ac_cv_sendfile, [AC_LINK_IFELSE([
66# include <sys/types.h>
67#if __linux
68# include <sys/sendfile.h>
69#elif __FreeBSD__ || defined __APPLE__
70# include <sys/socket.h>
71# include <sys/uio.h>
72#elif __hpux
73# include <sys/socket.h>
74#else
75# error unsupported architecture
76#endif
77int main (void)
78{
79   int fd = 0;
80   off_t offset = 1;
81   size_t count = 2;
82   ssize_t res;
83#if __linux
84   res = sendfile (fd, fd, offset, count);
85#elif __FreeBSD__
86   res = sendfile (fd, fd, offset, count, 0, &offset, 0);
87#elif __hpux
88   res = sendfile (fd, fd, offset, count, 0, 0);
89#endif
90   return 0;
91}
92],ac_cv_sendfile=yes,ac_cv_sendfile=no)])
93test $ac_cv_sendfile = yes && AC_DEFINE(HAVE_SENDFILE, 1, sendfile(2) is available and supported)
94
95AC_CACHE_CHECK(for sync_file_range, ac_cv_sync_file_range, [AC_LINK_IFELSE([
96#include <fcntl.h>
97int main (void)
98{
99   int fd = 0;
100   off64_t offset = 1;
101   off64_t nbytes = 1;
102   unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER;
103   ssize_t res;
104   res = sync_file_range (fd, offset, nbytes, flags);
105   return 0;
106}
107],ac_cv_sync_file_range=yes,ac_cv_sync_file_range=no)])
108test $ac_cv_sync_file_range = yes && AC_DEFINE(HAVE_SYNC_FILE_RANGE, 1, sync_file_range(2) is available)
109
110AC_CACHE_CHECK(for fallocate, ac_cv_linux_fallocate, [AC_LINK_IFELSE([
111#include <fcntl.h>
112int main (void)
113{
114   int fd = 0;
115   int mode = 0;
116   off_t offset = 1;
117   off_t len = 1;
118   int res;
119   res = fallocate (fd, mode, offset, len);
120   return 0;
121}
122],ac_cv_linux_fallocate=yes,ac_cv_linux_fallocate=no)])
123test $ac_cv_linux_fallocate = yes && AC_DEFINE(HAVE_LINUX_FALLOCATE, 1, fallocate(2) is available)
124
125AC_CACHE_CHECK(for sys_syncfs, ac_cv_sys_syncfs, [AC_LINK_IFELSE([
126#include <unistd.h>
127#include <sys/syscall.h>
128int main (void)
129{
130  int res = syscall (__NR_syncfs, (int)0);
131}
132],ac_cv_sys_syncfs=yes,ac_cv_sys_syncfs=no)])
133test $ac_cv_sys_syncfs = yes && AC_DEFINE(HAVE_SYS_SYNCFS, 1, syscall(__NR_syncfs) is available)
134
135AC_CACHE_CHECK(for prctl_set_name, ac_cv_prctl_set_name, [AC_LINK_IFELSE([
136#include <sys/prctl.h>
137int main (void)
138{
139  char name[] = "test123";
140  int res = prctl (PR_SET_NAME, (unsigned long)name, 0, 0, 0);
141}
142],ac_cv_prctl_set_name=yes,ac_cv_prctl_set_name=no)])
143test $ac_cv_prctl_set_name = yes && AC_DEFINE(HAVE_PRCTL_SET_NAME, 1, prctl(PR_SET_NAME) is available)
144
145dnl #############################################################################
146dnl # these checks exist for the benefit of IO::AIO
147
148dnl at least uclibc defines _POSIX_ADVISORY_INFO without *any* of the required
149dnl functionality actually being present. ugh.
150AC_CACHE_CHECK(for posix_madvise, ac_cv_posix_madvise, [AC_LINK_IFELSE([
151#include <sys/mman.h>
152int main (void)
153{
154   int res = posix_madvise ((void *)0, (size_t)0, POSIX_MADV_NORMAL);
155   int a = POSIX_MADV_SEQUENTIAL;
156   int b = POSIX_MADV_RANDOM;
157   int c = POSIX_MADV_WILLNEED;
158   int d = POSIX_MADV_DONTNEED;
159   return 0;
160}
161],ac_cv_posix_madvise=yes,ac_cv_posix_madvise=no)])
162test $ac_cv_posix_madvise = yes && AC_DEFINE(HAVE_POSIX_MADVISE, 1, posix_madvise(2) is available)
163
164AC_CACHE_CHECK(for posix_fadvise, ac_cv_posix_fadvise, [AC_LINK_IFELSE([
165#define _XOPEN_SOURCE 600
166#include <fcntl.h>
167int main (void)
168{
169   int res = posix_fadvise ((int)0, (off_t)0, (off_t)0, POSIX_FADV_NORMAL);
170   int a = POSIX_FADV_SEQUENTIAL;
171   int b = POSIX_FADV_NOREUSE;
172   int c = POSIX_FADV_RANDOM;
173   int d = POSIX_FADV_WILLNEED;
174   int e = POSIX_FADV_DONTNEED;
175   return 0;
176}
177],ac_cv_posix_fadvise=yes,ac_cv_posix_fadvise=no)])
178test $ac_cv_posix_fadvise = yes && AC_DEFINE(HAVE_POSIX_FADVISE, 1, posix_fadvise(2) is available)
179
180dnl lots of linux specifics
181AC_CHECK_HEADERS([linux/fs.h linux/fiemap.h])
182
183AC_CACHE_CHECK([for splice, vmsplice and tee], ac_cv_linux_splice, [AC_LINK_IFELSE([
184#include <fcntl.h>
185int main (void)
186{
187   ssize_t res;
188   res = splice ((int)0, (loff_t)0, (int)0, (loff_t *)0, (size_t)0, SPLICE_F_MOVE | SPLICE_F_NONBLOCK | SPLICE_F_MORE);
189   res = tee ((int)0, (int)0, (size_t)0, SPLICE_F_NONBLOCK);
190   res = vmsplice ((int)0, (struct iovec *)0, 0, SPLICE_F_NONBLOCK | SPLICE_F_GIFT);
191   return 0;
192}
193],ac_cv_linux_splice=yes,ac_cv_linux_splice=no)])
194test $ac_cv_linux_splice = yes && AC_DEFINE(HAVE_LINUX_SPLICE, 1, splice/vmsplice/tee(2) are available)
195
196