[quake3-commits] r1738 - in trunk/code: qcommon sys

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Nov 7 11:43:02 EST 2009


Author: tma
Date: 2009-11-07 11:43:02 -0500 (Sat, 07 Nov 2009)
New Revision: 1738

Modified:
   trunk/code/qcommon/files.c
   trunk/code/sys/sys_win32.c
Log:
* Rewrite win32 Sys_Mkdir to use CreateDirectory
* Make FS_ReplaceSeparators filter out runs of multiple separators
* Make FS_CreatePath skip creation of the root directory


Modified: trunk/code/qcommon/files.c
===================================================================
--- trunk/code/qcommon/files.c	2009-11-06 16:25:14 UTC (rev 1737)
+++ trunk/code/qcommon/files.c	2009-11-07 16:43:02 UTC (rev 1738)
@@ -437,10 +437,18 @@
 */
 static void FS_ReplaceSeparators( char *path ) {
 	char	*s;
+	qboolean lastCharWasSep = qfalse;
 
 	for ( s = path ; *s ; s++ ) {
 		if ( *s == '/' || *s == '\\' ) {
-			*s = PATH_SEP;
+			if ( !lastCharWasSep ) {
+				*s = PATH_SEP;
+				lastCharWasSep = qtrue;
+			} else {
+				memmove (s, s + 1, strlen (s));
+			}
+		} else {
+			lastCharWasSep = qfalse;
 		}
 	}
 }
@@ -464,7 +472,7 @@
 	}
 
 	Com_sprintf( temp, sizeof(temp), "/%s/%s", game, qpath );
-	FS_ReplaceSeparators( temp );	
+	FS_ReplaceSeparators( temp );
 	Com_sprintf( ospath[toggle], sizeof( ospath[0] ), "%s%s", base, temp );
 	
 	return ospath[toggle];
@@ -480,6 +488,7 @@
 */
 qboolean FS_CreatePath (char *OSPath) {
 	char	*ofs;
+	char	path[MAX_OSPATH];
 	
 	// make absolutely sure that it can't back up the path
 	// FIXME: is c: allowed???
@@ -488,17 +497,25 @@
 		return qtrue;
 	}
 
-	for (ofs = OSPath+1 ; *ofs ; ofs++) {
-		if (*ofs == PATH_SEP) {	
+	Q_strncpyz( path, OSPath, sizeof( path ) );
+	FS_ReplaceSeparators( path );
+
+	// Skip creation of the root directory as it will always be there
+	ofs = strchr( path, PATH_SEP );
+	ofs++;
+
+	for (; ofs != NULL && *ofs ; ofs++) {
+		if (*ofs == PATH_SEP) {
 			// create the directory
 			*ofs = 0;
-			if (!Sys_Mkdir (OSPath)) {
+			if (!Sys_Mkdir (path)) {
 				Com_Error( ERR_FATAL, "FS_CreatePath: failed to create path \"%s\"\n",
-					OSPath );
+					path );
 			}
 			*ofs = PATH_SEP;
 		}
 	}
+
 	return qfalse;
 }
 
@@ -2970,7 +2987,7 @@
 			"the correct place and that every file "
 			"in the \"%s\" directory is present and readable", BASEGAME));
 
-		Com_Error(ERR_FATAL, errorText);
+		Com_Error(ERR_FATAL, "%s", errorText);
 	}
 	
 	if(foundPak & 1)

Modified: trunk/code/sys/sys_win32.c
===================================================================
--- trunk/code/sys/sys_win32.c	2009-11-06 16:25:14 UTC (rev 1737)
+++ trunk/code/sys/sys_win32.c	2009-11-07 16:43:02 UTC (rev 1738)
@@ -273,11 +273,12 @@
 */
 qboolean Sys_Mkdir( const char *path )
 {
-	int result = _mkdir( path );
+	if( !CreateDirectory( path, NULL ) )
+	{
+		if( GetLastError( ) != ERROR_ALREADY_EXISTS )
+			return qfalse;
+	}
 
-	if( result != 0 )
-		return errno == EEXIST;
-
 	return qtrue;
 }
 



More information about the quake3-commits mailing list