Adding utils.c.
This commit is contained in:
parent
e78f8bea4d
commit
c1b99a9e7e
2 changed files with 23 additions and 0 deletions
13
utils.c
Normal file
13
utils.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#include <sys/stat.h>
|
||||
#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;
|
||||
}
|
||||
10
utils.h
Normal file
10
utils.h
Normal file
|
|
@ -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 */
|
||||
Reference in a new issue