Просмотр исходного кода

xmltest: create dir resources/out to avoid crashes

Since many of the tests reopen files generated under resources/out
to reuse as input without performing error checking, explicity
create directory to mitigate segfaults.
kbinny62 8 лет назад
Родитель
Сommit
bf29a15242
1 измененных файлов с 14 добавлено и 1 удалено
  1. 14 1
      xmltest.cpp

+ 14 - 1
xmltest.cpp

@@ -5,16 +5,20 @@
 #endif
 
 #include "tinyxml2.h"
+#include <cerrno>
 #include <cstdlib>
 #include <cstring>
 #include <ctime>
 
-#if defined( _MSC_VER )
+#if defined( _MSC_VER ) || defined (WIN32)
 	#include <crtdbg.h>
 	#define WIN32_LEAN_AND_MEAN
 	#include <windows.h>
 	_CrtMemState startMemState;
 	_CrtMemState endMemState;
+#else
+	#include <sys/stat.h>
+	#include <sys/types.h>
 #endif
 
 using namespace tinyxml2;
@@ -334,6 +338,15 @@ int main( int argc, const char ** argv )
 	}
 	fclose( fp );
 
+#if defined WIN32
+	if ( !CreateDirectory( "resources/out", NULL ) && GetLastError() != ERROR_ALREADY_EXISTS ) {
+#else
+	if ( mkdir( "resources/out", 0750 ) == -1 && errno != EEXIST ) {
+#endif
+		printf( "Unable to create directory 'resources/out': %s\n", strerror( errno ) );
+		exit( 1 );
+	}
+
 	XMLTest( "Example-1", 0, example_1() );
 	XMLTest( "Example-2", 0, example_2() );
 	XMLTest( "Example-3", 0, example_3() );