diff --git a/sources/dir.c b/sources/dir.c index e5c541a..b71bb86 100644 --- a/sources/dir.c +++ b/sources/dir.c @@ -42,6 +42,11 @@ __declspec(dllimport) unsigned long __stdcall GetLastError(void); #define INVALID_HANDLE_VALUE ((void *)(__int64)-1) +int dir_exists(const char *dirname) { + // Windows-specific placeholder + return -1; +} + directory open_dir(const char *dirname) { char pattern[1024]; strcpy(pattern, dirname); @@ -84,6 +89,16 @@ void close_dir(directory *dir) { #include #include +int dir_exists(const char *dirname) { + struct stat dir_info; + + if (stat(dirname, &dir_info) != 0){ + return 0; + } + + return S_ISDIR(dir_info.st_mode); +} + directory open_dir(const char *dirname) { directory dir; dir.handle = opendir(dirname); diff --git a/sources/dir.h b/sources/dir.h index 98f9d18..9d59819 100644 --- a/sources/dir.h +++ b/sources/dir.h @@ -19,6 +19,7 @@ typedef struct file { directory open_dir(const char *dirname); file read_next_file(directory *dir); void close_dir(directory *dir); +int dir_exists(const char* dirname); #ifdef __cplusplus } diff --git a/sources/kong.c b/sources/kong.c index e9f3bbe..b16dafe 100644 --- a/sources/kong.c +++ b/sources/kong.c @@ -267,6 +267,7 @@ int main(int argc, char **argv) { check(mode == MODE_MODECHECK, context, "Wrong parameter syntax"); check(inputs_size > 0, context, "no input parameters found"); check(output != NULL, context, "output parameter not found"); + check(dir_exists(output) == 1, context, "output directory doesn't exist or isn't a directory"); check(api != API_DEFAULT, context, "api parameter not found"); names_init();