From d1eb250c11a35e30aaaf0652a24daa27b6b90b8f Mon Sep 17 00:00:00 2001 From: Esben Mose Hansen Date: Tue, 10 Nov 2009 21:58:04 +0100 Subject: [PATCH 1/2] Add gitfo_is_diretory --- src/errors.c | 1 + src/fileops.c | 11 +++++++++++ src/fileops.h | 5 +++++ src/git/common.h | 3 +++ 4 files changed, 20 insertions(+), 0 deletions(-) diff --git a/src/errors.c b/src/errors.c index f348997..074c01c 100644 --- a/src/errors.c +++ b/src/errors.c @@ -36,6 +36,7 @@ static struct { { GIT_ENOTOID, "Not a git oid" }, { GIT_ENOTFOUND, "Object does not exist in the scope searched" }, { GIT_ENOMEM, "Not enough space" }, + { GIT_ENOTDIR, "Not a directory" } }; const char *git_strerror(int num) diff --git a/src/fileops.c b/src/fileops.c index 5de89cb..47a8681 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -274,3 +274,14 @@ int gitfo_dirent( closedir(dir); return GIT_SUCCESS; } + +int gitfo_is_directory(const char* path) { + struct stat path_stat; + if (stat(path, &path_stat)) { + return GIT_EOSERR; + } + if (!S_ISDIR(path_stat.st_mode)) { + return GIT_ENOTDIR; + } + return GIT_SUCCESS; +} diff --git a/src/fileops.h b/src/fileops.h index 02e4e5b..73eb72c 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -126,4 +126,9 @@ extern int gitfo_write_cached(gitfo_cache *ioc, void *buf, size_t len); extern int gitfo_flush_cached(gitfo_cache *ioc); extern int gitfo_close_cached(gitfo_cache *ioc); +/** + * Check if path is a directory + */ +extern int gitfo_is_directory(const char* path); + #endif /* INCLUDE_fileops_h__ */ diff --git a/src/git/common.h b/src/git/common.h index c470e0e..96f2971 100644 --- a/src/git/common.h +++ b/src/git/common.h @@ -65,6 +65,9 @@ /** Consult the OS error information. */ #define GIT_EOSERR (GIT_ERROR - 4) +/** The path is not a directory */ +#define GIT_ENOTDIR (GIT_ERROR - 5) + GIT_BEGIN_DECL /** A revision traversal pool. */ -- 1.6.3.3