From 958dc058a48ed65070e09929a64cf04c3733402f Mon Sep 17 00:00:00 2001 From: ewt Date: Wed, 13 Dec 1995 20:11:31 +0000 Subject: [PATCH] added exists() function CVS patchset: 26 CVS date: 1995/12/13 20:11:31 --- lib/misc.c | 16 ++++++++++++++++ lib/misc.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/lib/misc.c b/lib/misc.c index a08da13..737fca6 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -1,4 +1,6 @@ +#include #include +#include #include "misc.h" @@ -40,3 +42,17 @@ void freeSplitString(char ** list) { free(list[0]); free(list); } + +int exists(char * filespec) { + struct stat buf; + + if (stat(filespec, &buf)) { + switch(errno) { + case ENOENT: + case EINVAL: + return 0; + } + } + + return 1; +} diff --git a/lib/misc.h b/lib/misc.h index c82a9a9..444b3f8 100644 --- a/lib/misc.h +++ b/lib/misc.h @@ -4,4 +4,6 @@ char ** splitString(char * str, int length, char sep); void freeSplitString(char ** list); +int exists(char * filespec); + #endif -- 2.7.4