Check if a file path and descriptor are indeed the same file. This function is needed for TACTOU avoidance. Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- include/fileutils.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/fileutils.h b/include/fileutils.h index be6d1f7..55df1a7 100644 --- a/include/fileutils.h +++ b/include/fileutils.h @@ -4,6 +4,7 @@ #include <stdio.h> #include <fcntl.h> #include <unistd.h> +#include <sys/stat.h> #include "c.h" @@ -25,6 +26,19 @@ static inline FILE *xfmkstemp(char **tmpname, const char *dir, const char *prefi return ret; } +static inline int is_same_inode(const int fd, const char *path) +{ + struct stat f, p; + + if (fstat(fd, &f) < 0) + return 0; + if (stat(path, &p) < 0) + return 0; + if (f.st_dev != p.st_dev || f.st_ino != p.st_ino) + return 0; + return 1; +} + extern int dup_fd_cloexec(int oldfd, int lowfd); extern int get_fd_tabsize(void); -- 2.6.2 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html