From c78b889adeb5720a31d73a30389d21caec77bcc7 Mon Sep 17 00:00:00 2001 From: n-a-c-h <> Date: Sun, 10 Jul 2005 01:30:07 +0000 Subject: [PATCH] Added function to handle file or directories. --- zsnes/src/tools/fileutil.cpp | 15 +++++++++++++++ zsnes/src/tools/fileutil.h | 1 + 2 files changed, 16 insertions(+) diff --git a/zsnes/src/tools/fileutil.cpp b/zsnes/src/tools/fileutil.cpp index c65a0364..99095c0d 100644 --- a/zsnes/src/tools/fileutil.cpp +++ b/zsnes/src/tools/fileutil.cpp @@ -61,3 +61,18 @@ bool parse_dir(const char *dir_loc, void (*func)(const char *, struct stat&)) } return(false); } + +bool parse_path(const char *path, void (*func)(const char *, struct stat&)) +{ + struct stat stat_buffer; + if (!stat(path, &stat_buffer)) + { + if (S_ISDIR(stat_buffer.st_mode)) + { + return(parse_dir(path, func)); + } + func(path, stat_buffer); + return(true); + } + return(false); +} diff --git a/zsnes/src/tools/fileutil.h b/zsnes/src/tools/fileutil.h index fbfccaf3..cd573257 100644 --- a/zsnes/src/tools/fileutil.h +++ b/zsnes/src/tools/fileutil.h @@ -28,6 +28,7 @@ This is part of a toolkit used to assist in ZSNES development #include bool parse_dir(const char *, void (*func)(const char *, struct stat&)); +bool parse_path(const char *, void (*func)(const char *, struct stat&)); inline bool extension_match(const char *filename, const char *ext) {