This commit is contained in:
2022-02-15 13:42:40 +08:00
parent 0c8dba0a0a
commit a64c19d111
4 changed files with 39 additions and 0 deletions

View File

@@ -70,6 +70,13 @@ int fileop_isdir(const char* path, int* result) {
return r ? 1 : 0; 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) { int fileop_mkdir(const char* path, int mode) {
if (!path) return 0; if (!path) return 0;
return fileop::mkdir(path, mode) ? 1 : 0; return fileop::mkdir(path, mode) ? 1 : 0;

View File

@@ -9,6 +9,9 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
#if _WIN32
#include <io.h>
#endif
/** /**
* @brief Check file exists * @brief Check file exists
* @param fn File name * @param fn File name
@@ -78,6 +81,14 @@ char* fileop_join(const char* path, const char* path2);
* @return 0 if error occured otherwise 1 * @return 0 if error occured otherwise 1
*/ */
int fileop_isdir(const char* path, int* result); 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. * @brief Creates a new directory.
* @param path Path for a new directory. * @param path Path for a new directory.

View File

@@ -8,6 +8,7 @@
#if _WIN32 #if _WIN32
#include "Windows.h" #include "Windows.h"
#endif #endif
#include "cpp2c.h"
bool err::get_errno_message(std::string &out, int errnum) { bool err::get_errno_message(std::string &out, int errnum) {
#if _WIN32 #if _WIN32
@@ -60,3 +61,11 @@ bool err::get_errno_message(std::string &out, int errnum) {
#endif #endif
#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;
}

12
err.h
View File

@@ -1,5 +1,6 @@
#ifndef _UTILS_ERR_H #ifndef _UTILS_ERR_H
#define _UTILS_ERR_H #define _UTILS_ERR_H
#if __cplusplus
#include <string> #include <string>
namespace err { namespace err {
@@ -11,4 +12,15 @@ namespace err {
*/ */
bool get_errno_message(std::string &out, int errnum); 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 #endif