From c1b99a9e7e7332022876f577aa14cc6527b87d96 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 8 Feb 2013 21:54:54 +0100 Subject: [PATCH] Adding utils.c. --- utils.c | 13 +++++++++++++ utils.h | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 utils.c create mode 100644 utils.h diff --git a/utils.c b/utils.c new file mode 100644 index 0000000..e55ba5d --- /dev/null +++ b/utils.c @@ -0,0 +1,13 @@ + +#include +#include "utils.h" + +int file_cmp(const char *a, const char *b) { + + struct stat sa, sb; + + if (stat(a, &sa) < 0 || stat(b, &sb) < 0) + return 0; + return sa.st_dev == sb.st_dev && + sa.st_ino == sb.st_ino; +} diff --git a/utils.h b/utils.h new file mode 100644 index 0000000..0f185c0 --- /dev/null +++ b/utils.h @@ -0,0 +1,10 @@ + +#ifndef UTILS_H +#define UTILS_H + +/* compare two files at a system level. + Returns a non zero value if a and b are the same file. zero otherwise. + ("same" in this context is the same location on the filesystem) */ +int file_cmp(const char *a, const char *b); + +#endif /* UTILS_H */ \ No newline at end of file