summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-09-20 18:22:27 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-09-20 18:22:27 +0000
commit6011d413604df8224b91ca9f9b3d50663b60e117 (patch)
treeca36404ebcc87922d26664dd93e2c0ebd23bef67 /src
parent98d3a523be4fff36f65e71c37df8b9e127b12b83 (diff)
downloadskalibs-6011d413604df8224b91ca9f9b3d50663b60e117.tar.xz
sysdeps redesign: first part: minimize clr tests
Remaining clr: emptyregex: can be safely guessed to no nullispointer: can't be safely guessed, but do we need the test? devurandom: can't be safely guessed malloc0: can more or less be safely guessed to no
Diffstat (limited to 'src')
-rw-r--r--src/librandom/random_string.c11
-rw-r--r--src/sysdeps/tryaccept4.c4
-rw-r--r--src/sysdeps/trygetrandom.c18
-rw-r--r--src/sysdeps/trypipe2.c3
-rw-r--r--src/sysdeps/tryppoll.c11
-rw-r--r--src/sysdeps/trysplice.c27
6 files changed, 32 insertions, 42 deletions
diff --git a/src/librandom/random_string.c b/src/librandom/random_string.c
index f8cabc3..acdec69 100644
--- a/src/librandom/random_string.c
+++ b/src/librandom/random_string.c
@@ -16,21 +16,14 @@ void random_string (char *s, size_t n)
#else
#ifdef SKALIBS_HASGETRANDOM
-#include <skalibs/nonposix.h>
-#include <unistd.h>
-#include <sys/syscall.h>
+#include <sys/random.h>
#include <skalibs/random.h>
-static int getrandom (void *buf, size_t buflen, unsigned int flags)
-{
- return syscall(SYS_getrandom, buf, buflen, flags) ;
-}
-
void random_string (char *s, size_t n)
{
while (n)
{
- int r = getrandom(s, n, 0) ;
+ ssize_t r = getrandom(s, n, 0) ;
if (r >= 0)
{
s += r ;
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 ;
}