diff --git a/cfileop.cpp b/cfileop.cpp index a1d9741..67eeead 100644 --- a/cfileop.cpp +++ b/cfileop.cpp @@ -70,6 +70,13 @@ int fileop_isdir(const char* path, int* result) { return r ? 1 : 0; } +#if _WIN32 +int fileop_isdrive(const char* path) { + if (!path) return 0; + return fileop::isdrive(path) ? 1 : 0; +} +#endif + int fileop_mkdir(const char* path, int mode) { if (!path) return 0; return fileop::mkdir(path, mode) ? 1 : 0; diff --git a/cfileop.h b/cfileop.h index b000d81..3435614 100644 --- a/cfileop.h +++ b/cfileop.h @@ -9,6 +9,9 @@ extern "C" { #include #include #include +#if _WIN32 +#include +#endif /** * @brief Check file exists * @param fn File name @@ -78,6 +81,14 @@ char* fileop_join(const char* path, const char* path2); * @return 0 if error occured otherwise 1 */ int fileop_isdir(const char* path, int* result); +#if _WIN32 +/** + * @brief Check if a path only contains drive. + * @param path Path + * @return 1 if true otherwise 0 +*/ +int fileop_isdrive(const char* path); +#endif /** * @brief Creates a new directory. * @param path Path for a new directory. diff --git a/err.cpp b/err.cpp index a23f3a8..3ec05d4 100644 --- a/err.cpp +++ b/err.cpp @@ -8,6 +8,7 @@ #if _WIN32 #include "Windows.h" #endif +#include "cpp2c.h" bool err::get_errno_message(std::string &out, int errnum) { #if _WIN32 @@ -60,3 +61,11 @@ bool err::get_errno_message(std::string &out, int errnum) { #endif #endif } + +char* err_get_errno_message(int errnum) { + std::string msg; + if (!err::get_errno_message(msg, errnum)) return nullptr; + char* tmp; + if (!cpp2c::string2char(msg, tmp)) return nullptr; + return tmp; +} diff --git a/err.h b/err.h index e40f0f5..ffdd6fd 100644 --- a/err.h +++ b/err.h @@ -1,5 +1,6 @@ #ifndef _UTILS_ERR_H #define _UTILS_ERR_H +#if __cplusplus #include namespace err { @@ -11,4 +12,15 @@ namespace err { */ bool get_errno_message(std::string &out, int errnum); } +extern "C" { +#endif +/** + * @brief Get error message from errno + * @param errnum errno + * @return Output string. Need free memory by calling free. +*/ +char* err_get_errno_message(int errnum); +#if __cplusplus +} +#endif #endif