diff --git a/src/wayland-os.c b/src/wayland-os.c
index a9066cae9c93..8bf13bf37544 100644
--- a/src/wayland-os.c
+++ b/src/wayland-os.c
@@ -42,6 +42,9 @@
#include "wayland-os.h"
+/* used by tests */
+int (*wl_fcntl)(int fildes, int cmd, ...) = fcntl;
+
static int
set_cloexec_or_close(int fd)
{
@@ -50,11 +53,11 @@ set_cloexec_or_close(int fd)
if (fd == -1)
return -1;
- flags = fcntl(fd, F_GETFD);
+ flags = wl_fcntl(fd, F_GETFD);
if (flags == -1)
goto err;
- if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+ if (wl_fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
goto err;
return fd;
@@ -124,13 +127,13 @@ wl_os_dupfd_cloexec(int fd, int minfd)
{
int newfd;
- newfd = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
+ newfd = wl_fcntl(fd, F_DUPFD_CLOEXEC, minfd);
if (newfd >= 0)
return newfd;
if (errno != EINVAL)
return -1;
- newfd = fcntl(fd, F_DUPFD, minfd);
+ newfd = wl_fcntl(fd, F_DUPFD, minfd);
return set_cloexec_or_close(newfd);
}