diff options
Diffstat (limited to 'src/sysdeps')
-rw-r--r-- | src/sysdeps/tryaccept4.c | 4 | ||||
-rw-r--r-- | src/sysdeps/trygetrandom.c | 18 | ||||
-rw-r--r-- | src/sysdeps/trypipe2.c | 3 | ||||
-rw-r--r-- | src/sysdeps/tryppoll.c | 11 | ||||
-rw-r--r-- | src/sysdeps/trysplice.c | 27 |
5 files changed, 30 insertions, 33 deletions
diff --git a/src/sysdeps/tryaccept4.c b/src/sysdeps/tryaccept4.c index 98a75e6..ea3baaa 100644 --- a/src/sysdeps/tryaccept4.c +++ b/src/sysdeps/tryaccept4.c @@ -11,6 +11,10 @@ #define _GNU_SOURCE #endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif + #include <sys/socket.h> #include <sys/stat.h> #include <fcntl.h> diff --git a/src/sysdeps/trygetrandom.c b/src/sysdeps/trygetrandom.c index 8abe3dd..cc2426b 100644 --- a/src/sysdeps/trygetrandom.c +++ b/src/sysdeps/trygetrandom.c @@ -1,24 +1,10 @@ /* ISC license. */ -#undef _POSIX_C_SOURCE -#undef _XOPEN_SOURCE - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include <sys/types.h> -#include <unistd.h> -#include <sys/syscall.h> - -static int getrandom (void *buf, size_t buflen, unsigned int flags) -{ - return syscall(SYS_getrandom, buf, buflen, flags) ; -} +#include <sys/random.h> int main (void) { char buf[4] ; - if (getrandom(buf, 4, 0) < 0) return 1 ; + if (getrandom(buf, 4, GRND_NONBLOCK) < 0) return 1 ; return 0 ; } diff --git a/src/sysdeps/trypipe2.c b/src/sysdeps/trypipe2.c index 0b8cb3c..173b815 100644 --- a/src/sysdeps/trypipe2.c +++ b/src/sysdeps/trypipe2.c @@ -12,6 +12,9 @@ #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif #ifndef _NETBSD_SOURCE #define _NETBSD_SOURCE #endif diff --git a/src/sysdeps/tryppoll.c b/src/sysdeps/tryppoll.c index 1502f2c..18f7615 100644 --- a/src/sysdeps/tryppoll.c +++ b/src/sysdeps/tryppoll.c @@ -1,9 +1,20 @@ /* ISC license. */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif + #include <sys/stat.h> #include <fcntl.h> #include <time.h> diff --git a/src/sysdeps/trysplice.c b/src/sysdeps/trysplice.c index 8e8bd72..969c5ea 100644 --- a/src/sysdeps/trysplice.c +++ b/src/sysdeps/trysplice.c @@ -1,29 +1,22 @@ /* ISC license. */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif -#include <sys/stat.h> #include <fcntl.h> -#include <unistd.h> - -#define N 4096 +#include <sys/uio.h> int main (void) { - int p[2] ; - int fd ; - if (pipe(p) < 0) return 111 ; - fd = open("./src/sysdeps/trysplice.c", O_RDONLY) ; - if (fd < 0) return 111 ; - - for (;;) - { - ssize_t r = splice(fd, 0, p[1], 0, N, 0) ; - if (r < 0) return 1 ; - if (!r) break ; - if (splice(p[0], 0, 1, 0, r, 0) < r) return 2 ; - } + char s[2][2] ; + struct iovec v[2] = { { .iov_base = s[0], .iov_len = 2 }, { .iov_base = s[1], .iov_len = 2 } } ; + loff_t in, out ; + ssize_t r = splice(0, &in, 1, &out, 4096, SPLICE_F_MOVE) ; + r = tee(0, 1, 4096, SPLICE_F_NONBLOCK) ; + r = vmsplice(0, v, 2, 0) ; return 0 ; } |