Commit cf9c985b authored by npzacs's avatar npzacs
Browse files

Move system-dependent code to own file

parent da8a5fb8
......@@ -22,10 +22,6 @@
#include "util/attributes.h"
#ifdef _WIN32
BD_PRIVATE int win32_mkdir(const char *dir);
#endif
/*
* Config, cache and data dirs
*/
......
......@@ -34,14 +34,6 @@
#include <direct.h>
int win32_mkdir(const char *dir)
{
wchar_t wdir[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH);
return _wmkdir(wdir);
}
char *file_get_config_home(void)
{
return file_get_data_home();
......
......@@ -46,5 +46,10 @@
BD_PRIVATE extern AACS_FILE_H *(*file_open)(const char* filename, const char *mode);
/*
* local filesystem
*/
BD_PRIVATE int file_mkdir(const char *dir);
#endif /* FILE_H_ */
......@@ -29,6 +29,9 @@
#include <inttypes.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
static void file_close_linux(AACS_FILE_H *file)
{
if (file) {
......@@ -85,3 +88,8 @@ static AACS_FILE_H *file_open_linux(const char* filename, const char *mode)
}
AACS_FILE_H* (*file_open)(const char* filename, const char *mode) = file_open_linux;
int file_mkdir(const char *dir)
{
return mkdir(dir, S_IRWXU);
}
......@@ -112,3 +112,13 @@ static AACS_FILE_H *_file_open(const char* filename, const char *mode)
}
AACS_FILE_H* (*file_open)(const char* filename, const char *mode) = _file_open;
int file_mkdir(const char *dir)
{
wchar_t wdir[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH);
if (!CreateDirectoryW(wdir, NULL))
return -1;
return 0;
}
......@@ -20,6 +20,7 @@
#include "keydbcfg.h"
#include "dirs.h"
#include "file.h"
#include "util/strutl.h"
#include "util/logging.h"
......@@ -31,15 +32,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _WIN32
# define mkdir(p,m) win32_mkdir(p)
# define DIR_SEP_CHAR '\\'
# define DIR_SEP "\\"
#else
# define DIR_SEP_CHAR '/'
# define DIR_SEP "/"
#endif
#define CFG_DIR "aacs"
......@@ -73,7 +65,7 @@ static int _mkpath(const char *path)
if (stat(dir, &s) != 0 || !S_ISDIR(s.st_mode)) {
BD_DEBUG(DBG_FILE, "Creating directory %s\n", dir);
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
if (file_mkdir(dir) == -1) {
BD_DEBUG(DBG_FILE | DBG_CRIT, "Error creating directory %s\n", dir);
result = 0;
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment