Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fvbe.git;a=commitdiff;h=adadbbfb9fb6b3fe9ea0dc5ff8533af4c1c043cd

commit adadbbfb9fb6b3fe9ea0dc5ff8533af4c1c043cd
Author: James Buren <[email protected]>
Date:   Fri Oct 18 16:57:15 2013 -0500

utility: add ispathpresent functon to replace general usages of stat, checking 
for file type, and permissions

diff --git a/src/local.h b/src/local.h
index 74b43c7..2082ae2 100644
--- a/src/local.h
+++ b/src/local.h
@@ -181,6 +181,7 @@ struct tool
};

extern void iniparser_unset_section(dictionary *d,const char *s);
+extern bool ispathpresent(const char *path,int type,int mode);
extern bool readlink0(const char *path,char *buf,size_t size);
extern int charpp_qsort(const void *A,const void *B);
extern void charpp_free(char **pp);
diff --git a/src/utility.c b/src/utility.c
index de7c833..4aeed4c 100644
--- a/src/utility.c
+++ b/src/utility.c
@@ -78,6 +78,29 @@ extern void iniparser_unset_section(dictionary *d,const char 
*s)
free(p);
}

+extern bool ispathpresent(const char *path,int type,int mode)
+{
+  struct stat st = {0};
+
+  if(path == 0)
+  {
+    errno = EINVAL;
+    error(strerror(errno));
+    return false;
+  }
+
+  if(stat(path,&st) == -1)
+    return false;
+
+  if(type > 0 && (st.st_mode & type) != type)
+    return false;
+
+  if(mode > 0 && (st.st_mode & 0777) != mode)
+    return false;
+
+  return true;
+}
+
extern bool readlink0(const char *path,char *buf,size_t size)
{
ssize_t n = -1;
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to