Q_MKDIR: use std::filesystem::create_directories
This commit is contained in:
parent
c217ad981a
commit
396fe81cd2
1
Makefile
1
Makefile
|
|
@ -1064,6 +1064,7 @@ $(INSTALLDIR)/modules/shaders.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) -Ilibs
|
|||
$(INSTALLDIR)/modules/shaders.$(DLL): \
|
||||
plugins/shaders/plugin.o \
|
||||
plugins/shaders/shaders.o \
|
||||
libcommandlib.$(A) \
|
||||
|
||||
$(INSTALLDIR)/modules/vfspk3.$(DLL): LIBS_EXTRA := $(LIBS_GLIB)
|
||||
$(INSTALLDIR)/modules/vfspk3.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) -Ilibs -Iinclude
|
||||
|
|
|
|||
|
|
@ -28,9 +28,6 @@
|
|||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
#include "string/string.h"
|
||||
#include "os/path.h"
|
||||
|
||||
|
||||
#if defined ( POSIX )
|
||||
|
||||
|
|
@ -134,3 +131,11 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
bool Q_mkdir( const char* path ){
|
||||
std::error_code err;
|
||||
std::filesystem::create_directories( path, err );
|
||||
return !err;
|
||||
}
|
||||
|
|
@ -25,8 +25,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
|
||||
|
||||
// TTimo started adding portability code:
|
||||
// return true if spawning was successful, false otherwise
|
||||
|
|
@ -47,14 +45,4 @@ bool Q_Exec( const char *cmd, char *cmdline, const char *execdir, bool bCreateCo
|
|||
|
||||
// Q_mkdir
|
||||
// returns true if succeeded in creating directory
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
inline bool Q_mkdir( const char* name ){
|
||||
return _mkdir( name ) != -1;
|
||||
}
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
inline bool Q_mkdir( const char* name ){
|
||||
return mkdir( name, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) != -1; // rwxrwxr-x
|
||||
}
|
||||
#endif
|
||||
bool Q_mkdir( const char* path );
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <ctime>
|
||||
#include <cerrno>
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
|
|
@ -124,36 +125,11 @@ void Q_getwd( char *out ){
|
|||
}
|
||||
|
||||
|
||||
void Q_mkdir( const char *path ){
|
||||
char parentbuf[256];
|
||||
const char *p = NULL;
|
||||
int retry = 2;
|
||||
while ( retry-- )
|
||||
{
|
||||
#ifdef WIN32
|
||||
if ( _mkdir( path ) != -1 ) {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if ( mkdir( path, 0777 ) != -1 ) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if ( errno == ENOENT ) {
|
||||
p = path_get_last_separator( path );
|
||||
}
|
||||
if ( !strEmptyOrNull( p ) ) {
|
||||
strcpyQ( parentbuf, path, p - path + 1 );
|
||||
if ( ( p - path ) < (ptrdiff_t) sizeof( parentbuf ) ) {
|
||||
Sys_Printf( "mkdir: %s: creating parent %s first\n", path, parentbuf );
|
||||
Q_mkdir( parentbuf );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( errno != EEXIST ) {
|
||||
Error( "mkdir %s: %s", path, strerror( errno ) );
|
||||
void Q_mkdir( const char* path ){
|
||||
std::error_code err;
|
||||
std::filesystem::create_directories( path, err );
|
||||
if ( err ) {
|
||||
Error( "Q_mkdir %s: %s", path, err.message().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user