Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: third_party/openvr/src/src/vrcommon/dirtools_public.cpp

Issue 2754253003: Add OpenVR SDK to third_party (Closed)
Patch Set: feedback Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/openvr/src/src/vrcommon/dirtools_public.cpp
diff --git a/third_party/openvr/src/src/vrcommon/dirtools_public.cpp b/third_party/openvr/src/src/vrcommon/dirtools_public.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b6489b70050aa067e7a8dd75599e746e707bbc84
--- /dev/null
+++ b/third_party/openvr/src/src/vrcommon/dirtools_public.cpp
@@ -0,0 +1,101 @@
+//========= Copyright Valve Corporation ============//
+#include "dirtools_public.h"
+#include "strtools_public.h"
+#include "pathtools_public.h"
+
+#include <errno.h>
+#include <string.h>
+
+#ifdef _WIN32
+#include "windows.h"
+#else
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#endif
+
+#if defined( OSX )
+#include <sys/syslimits.h>
+#endif
+
+
+//-----------------------------------------------------------------------------
+// Purpose: utility function to create dirs & subdirs
+//-----------------------------------------------------------------------------
+bool BCreateDirectoryRecursive( const char *pchPath )
+{
+ // Does it already exist?
+ if ( Path_IsDirectory( pchPath ) )
+ return true;
+
+ // copy the path into something we can munge
+ int len = (int)strlen( pchPath );
+ char *path = (char *)malloc( len + 1 );
+ strcpy( path, pchPath );
+
+ // Walk backwards to first non-existing dir that we find
+ char *s = path + len - 1;
+
+ const char slash = Path_GetSlash();
+ while ( s > path )
+ {
+ if ( *s == slash )
+ {
+ *s = '\0';
+ bool bExists = Path_IsDirectory( path );
+ *s = slash;
+
+ if ( bExists )
+ {
+ ++s;
+ break;
+ }
+ }
+ --s;
+ }
+
+ // and then move forwards from there
+
+ while ( *s )
+ {
+ if ( *s == slash )
+ {
+ *s = '\0';
+ BCreateDirectory( path );
+ *s = slash;
+ }
+ s++;
+ }
+
+ bool bRetVal = BCreateDirectory( path );
+ free( path );
+ return bRetVal;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Creates the directory, returning true if it is created, or if it already existed
+//-----------------------------------------------------------------------------
+bool BCreateDirectory( const char *pchPath )
+{
+#ifdef WIN32
+ std::wstring wPath = UTF8to16( pchPath );
+ if ( ::CreateDirectoryW( wPath.c_str(), NULL ) )
+ return true;
+
+ if ( ::GetLastError() == ERROR_ALREADY_EXISTS )
+ return true;
+
+ return false;
+#else
+ int i = mkdir( pchPath, S_IRWXU | S_IRWXG | S_IRWXO );
+ if ( i == 0 )
+ return true;
+ if ( errno == EEXIST )
+ return true;
+
+ return false;
+#endif
+}
+
« no previous file with comments | « third_party/openvr/src/src/vrcommon/dirtools_public.h ('k') | third_party/openvr/src/src/vrcommon/envvartools_public.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698