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