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:
parent
2d247fd827
commit
6ac76b1830
3 changed files with 17 additions and 3 deletions
1
Makefile
1
Makefile
|
|
@ -33,6 +33,7 @@ obj += src/path.o
|
||||||
obj += src/strbuf.o
|
obj += src/strbuf.o
|
||||||
obj += src/xalloc.o
|
obj += src/xalloc.o
|
||||||
obj += src/die.o
|
obj += src/die.o
|
||||||
|
obj += src/file.o
|
||||||
|
|
||||||
obj += src/inotify.o
|
obj += src/inotify.o
|
||||||
obj += src/event.o
|
obj += src/event.o
|
||||||
|
|
|
||||||
15
src/file.c
Normal file
15
src/file.c
Normal 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);
|
||||||
|
}
|
||||||
|
|
@ -11,12 +11,10 @@
|
||||||
#ifndef __COMMON_UTIL_H
|
#ifndef __COMMON_UTIL_H
|
||||||
#define __COMMON_UTIL_H
|
#define __COMMON_UTIL_H
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void die(const char *, ...);
|
void die(const char *, ...);
|
||||||
|
|
||||||
void die_errno(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 */
|
#endif /* __COMMOT_UTIL_H */
|
||||||
|
|
|
||||||
Reference in a new issue