OSDN Git Service

file/stat.hpp Add.
authorMyun2 <myun2@nwhite.info>
Wed, 7 Sep 2011 06:04:44 +0000 (15:04 +0900)
committerMyun2 <myun2@nwhite.info>
Wed, 7 Sep 2011 06:04:44 +0000 (15:04 +0900)
roast/include/roast/file/stat.hpp [new file with mode: 0644]

diff --git a/roast/include/roast/file/stat.hpp b/roast/include/roast/file/stat.hpp
new file mode 100644 (file)
index 0000000..74efcd6
--- /dev/null
@@ -0,0 +1,80 @@
+//     Roast+ License
+/*
+       file/stat
+*/
+#ifndef __SFJP_ROAST__file__stat_HPP__
+#define __SFJP_ROAST__file__stat_HPP__
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+namespace roast
+{
+       namespace file
+       {
+               namespace _stat
+               {
+#ifdef WIN32
+                       //      Windows
+ #ifdef __stat64
+                       typedef struct _stat32          info;   /* 64bit ready VC++ : use 32bit stat */
+ #else
+                       typedef struct _stat            info;
+ #endif
+                       typedef unsigned long           mode;
+#else
+                       //      Linux/UNIX
+                       typedef struct stat                     info;
+                       typedef mode_t                          mode;
+#endif
+
+                       inline int _statapi(const char *path, info *p_stat_out)
+                       {
+#ifdef WIN32
+ #ifdef __stat64
+                               return _stat32(path,p_stat_out);
+ #else
+                               return _stat(path,p_stat_out);
+ #endif
+#else
+                               return stat(path,p_stat_out);
+#endif
+                       }
+               }
+               
+               ///////////////////////////////////////////
+               
+               bool inline is_file(const char* filepath)
+               {
+                       _stat::info inf;
+                       int apiret = _stat::_statapi(filepath, &inf);
+                       if ( apiret != 0 )
+                               return false;
+
+#ifdef WIN32
+                       return (inf.st_mode & _S_IFREG) ? true : false;
+#else
+                       return (S_ISREG(inf)) ? true : false;
+#endif
+               }
+
+               bool inline is_directory(const char* filepath)
+               {
+                       _stat::info inf;
+                       int apiret = _stat::_statapi(filepath, &inf);
+                       if ( apiret != 0 )
+                               return false;
+
+#ifdef WIN32
+                       return (inf.st_mode & _S_IFDIR) ? true : false;
+#else
+                       return (S_ISDIR(inf)) ? true : false;
+#endif
+               }
+               bool inline is_dir(const char* filepath){ return is_directory(filepath); }
+               
+               ///////////////////////////////////////////
+       }
+}
+
+#endif//__SFJP_ROAST__file__stat_HPP__