Fix fallocate erroneously returning ENOSYS on Linux systems
[fio.git] / helpers.c
index 9c76d305ba51ba6b35fdd8a6bfd6816b417464c7..5be45ccf5f3954b3c87494132d7f0cdf94825814 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -1,39 +1,52 @@
-#include <malloc.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
+#include <unistd.h>
 
 #include "compiler/compiler.h"
+#include "arch/arch.h"
+#include "os/os.h"
 
-int __weak posix_memalign(void **ptr, size_t align, size_t size)
+#ifndef FIO_HAVE_LINUX_FALLOCATE 
+int _weak fallocate(int fd, int mode, off_t offset, off_t len)
 {
-       *ptr = memalign(align, size);
-       if (*ptr)
-               return 0;
-
-       return ENOMEM;
+       errno = ENOSYS;
+       return -1;
 }
+#endif
 
-int __weak posix_fallocate(int fd, off_t offset, off_t len)
+#ifndef __NR_fallocate
+int _weak posix_fallocate(int fd, off_t offset, off_t len)
 {
        return 0;
 }
+#endif
 
-int __weak inet_aton(const char *cp, struct in_addr *inp)
+int _weak inet_aton(const char *cp, struct in_addr *inp)
 {
        return 0;
 }
 
-int __weak clock_gettime(clockid_t clk_id, struct timespec *ts)
+int _weak clock_gettime(clockid_t clk_id, struct timespec *ts)
 {
        struct timeval tv;
        int ret;
 
        ret = gettimeofday(&tv, NULL);
 
-       ts->ts_sec = tv.tv_sec;
-       ts->ts_nsec = tv.tv_usec * 1000;
+       ts->tv_sec = tv.tv_sec;
+       ts->tv_nsec = tv.tv_usec * 1000;
 
        return ret;
 }
+
+#ifndef __NR_sync_file_range
+int _weak sync_file_range(int fd, off64_t offset, off64_t nbytes,
+                          unsigned int flags)
+{
+       errno = ENOSYS;
+       return -1;
+}
+#endif