Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3202>
#if defined(__linux__)
#include <fcntl.h>
+#include <linux/kcmp.h>
#include <sys/stat.h>
+#include <sys/syscall.h>
#include <unistd.h>
return buf;
}
+bool
+os_same_file_description(int fd1, int fd2)
+{
+ pid_t pid = getpid();
+
+ return syscall(SYS_kcmp, pid, pid, KCMP_FILE, fd1, fd2) == 0;
+}
+
#else
+#include "u_debug.h"
+
char *
os_read_file(const char *filename)
{
return NULL;
}
+bool
+os_same_file_description(int fd1, int fd2)
+{
+ if (fd1 == fd2)
+ return true;
+
+ debug_warn_once("Can't tell if different file descriptors reference the same"
+ " file description, false negatives might cause trouble!\n");
+ return false;
+}
+
#endif
#ifndef _OS_FILE_H_
#define _OS_FILE_H_
+#include <stdbool.h>
#include <stdio.h>
#ifdef __cplusplus
char *
os_read_file(const char *filename);
+/*
+ * Returns true if the two file descriptors passed in can be determined to
+ * reference the same file description, false otherwise
+ */
+bool
+os_same_file_description(int fd1, int fd2);
+
#ifdef __cplusplus
}
#endif