Archived
1
0
Fork 0

src/util.h: switched file_exists macro to function.

the macro returns true for directories aswell, using stat.h instead.
This commit is contained in:
Henrik Hautakoski 2010-10-23 11:11:08 +02:00
parent 2d247fd827
commit 6ac76b1830
3 changed files with 17 additions and 3 deletions

View file

@ -33,6 +33,7 @@ obj += src/path.o
obj += src/strbuf.o
obj += src/xalloc.o
obj += src/die.o
obj += src/file.o
obj += src/inotify.o
obj += src/event.o

15
src/file.c Normal file
View file

@ -0,0 +1,15 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "util.h"
int file_exists(const char *path) {
struct stat st;
if (stat(path, &st) < 0)
return 0;
return S_ISREG(st.st_mode);
}

View file

@ -11,12 +11,10 @@
#ifndef __COMMON_UTIL_H
#define __COMMON_UTIL_H
#include <unistd.h>
void die(const char *, ...);
void die_errno(const char *);
#define file_exists(s) (access((s), F_OK) == 0)
int file_exists(const char *);
#endif /* __COMMOT_UTIL_H */