linux下文件夹创建跟windows不同,根据宏定义选择编译:
#ifdef _WIN32
#include <direct.h>
#include <io.h>
#else // Linux/Unix
#include <sys/io.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#endif
#include <string>
#include <iostream>
std::string database_dir = "******/******";
if (access(database_dir.c_str(), 0) < 0)
{
#ifdef _WIN32
mkdir(database_dir.c_str());
#else
if(mkdir(database_dir.c_str(), S_IRWXU)<0)
{
LPFACE_LOG(LOG_ERROR, "Fail to create database directory.");
throw std::exception();
}
#endif
}
linux stat.h 关于mkdir的描述:
/* Create a new directory named PATH, with permission bits MODE. */
extern int mkdir (const char *__path, __mode_t __mode)
//有如下model:
#define S_IRUSR __S_IREAD /* Read by owner. */
#define S_IWUSR __S_IWRITE /* Write by owner. */
#define S_IXUSR __S_IEXEC /* Execute by owner. */
/* Read, write, and execute by owner. */
#define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)