diff --git a/Makefile b/Makefile index c2d6dccf..375d0014 100644 --- a/Makefile +++ b/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 diff --git a/libs/commandlib.cpp b/libs/commandlib.cpp index 24defa59..6e530a02 100644 --- a/libs/commandlib.cpp +++ b/libs/commandlib.cpp @@ -28,9 +28,6 @@ #include #include -#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 + +bool Q_mkdir( const char* path ){ + std::error_code err; + std::filesystem::create_directories( path, err ); + return !err; +} \ No newline at end of file diff --git a/libs/commandlib.h b/libs/commandlib.h index c0db6a65..b356b09b 100644 --- a/libs/commandlib.h +++ b/libs/commandlib.h @@ -25,8 +25,6 @@ #pragma once -#include - // 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 -inline bool Q_mkdir( const char* name ){ - return _mkdir( name ) != -1; -} -#else -#include -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 ); diff --git a/tools/quake3/common/cmdlib.cpp b/tools/quake3/common/cmdlib.cpp index 2bab9070..db18eecf 100644 --- a/tools/quake3/common/cmdlib.cpp +++ b/tools/quake3/common/cmdlib.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #ifdef WIN32 #include @@ -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() ); } }