about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--cmake/fstatat.c9
-rw-r--r--runtime/POSIX/CMakeLists.txt5
-rw-r--r--runtime/POSIX/fd.c15
3 files changed, 24 insertions, 5 deletions
diff --git a/cmake/fstatat.c b/cmake/fstatat.c
new file mode 100644
index 00000000..58aa9301
--- /dev/null
+++ b/cmake/fstatat.c
@@ -0,0 +1,9 @@
+#include <fcntl.h>
+#include <stddef.h>
+#include <sys/stat.h>
+
+int main(void) {
+  struct stat buf;
+  #pragma GCC diagnostic error "-Wnonnull"
+  fstatat(0, NULL, &buf, 0);
+}
diff --git a/runtime/POSIX/CMakeLists.txt b/runtime/POSIX/CMakeLists.txt
index 02d06736..d8208d9b 100644
--- a/runtime/POSIX/CMakeLists.txt
+++ b/runtime/POSIX/CMakeLists.txt
@@ -20,6 +20,11 @@ set(SRC_FILES
         stubs.c
         )
 
+try_compile (FSTATAT_PATH_ACCEPTS_NULL
+        ${CMAKE_BINARY_DIR}
+        ${PROJECT_SOURCE_DIR}/cmake/fstatat.c
+        )
+
 # Build it
 include("${CMAKE_SOURCE_DIR}/cmake/compile_bitcode_library.cmake")
 prefix_with_path("${SRC_FILES}" "${CMAKE_CURRENT_SOURCE_DIR}/" prefixed_files)
diff --git a/runtime/POSIX/fd.c b/runtime/POSIX/fd.c
index 35d0d315..0aba0ade 100644
--- a/runtime/POSIX/fd.c
+++ b/runtime/POSIX/fd.c
@@ -568,16 +568,21 @@ int fstatat(int fd, const char *path, struct stat *buf, int flags) {
     return 0;
   } 
 
+#ifdef FSTATAT_PATH_ACCEPTS_NULL
+  #define PATHPARAM (path ? __concretize_string(path) : NULL)
+#else
+  assert(path);
+  #define PATHPARAM (__concretize_string(path))
+#endif
+
 #if (defined __NR_newfstatat) && (__NR_newfstatat != 0)
-  return syscall(__NR_newfstatat, (long)fd,
-                 (path ? __concretize_string(path) : NULL), buf, (long)flags);
+  return syscall(__NR_newfstatat, (long)fd, PATHPARAM, buf, (long)flags);
 #else
-  return syscall(__NR_fstatat64, (long)fd,
-                 (path ? __concretize_string(path) : NULL), buf, (long)flags);
+  return syscall(__NR_fstatat64, (long)fd, PATHPARAM, buf, (long)flags);
 #endif
+#undef PATHPARAM
 }
 
-
 int __fd_lstat(const char *path, struct stat64 *buf) {
   exe_disk_file_t *dfile = __get_sym_file(path);
   if (dfile) {