Browse Source

sys: refactor the binarydir detection code.

legacy
Sam Hocevar sam 11 years ago
parent
commit
3f67db703e
1 changed files with 24 additions and 17 deletions
  1. +24
    -17
      src/sys/init.cpp

+ 24
- 17
src/sys/init.cpp View File

@@ -8,15 +8,15 @@
// http://www.wtfpl.net/ for more details. // http://www.wtfpl.net/ for more details.
// //


#if defined HAVE_CONFIG_H
#if HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif


#if defined HAVE_UNISTD_H
#if HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif


#ifdef _WIN32
#if _WIN32
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <direct.h> # include <direct.h>
#endif #endif
@@ -29,7 +29,7 @@ namespace lol
namespace System namespace System
{ {


#if defined _WIN32
#if _WIN32
# define SEPARATOR '\\' # define SEPARATOR '\\'
#else #else
# define SEPARATOR '/' # define SEPARATOR '/'
@@ -45,23 +45,29 @@ void Init(int argc, char *argv[],
using namespace std; using namespace std;


/* /*
* Retrieve binary directory, defaulting to current dir.
* Retrieve binary directory, defaulting to no directory on Android
* and emscripten, and the current directory on other platforms.
*/ */


#if __ANDROID__
/* Android assets are accessed using no prefix at all. */
#if __ANDROID__ || EMSCRIPTEN
String binarydir = ""; String binarydir = "";
#elif defined HAVE_GETCWD
char *cwd = getcwd(nullptr, 0);
String binarydir = String(cwd ? cwd : ".") + SEPARATOR;
free(cwd);
#elif defined HAVE__GETCWD || (defined _WIN32 && !defined _XBOX)
char *cwd = _getcwd(nullptr, 0);
String binarydir = String(cwd ? cwd : ".") + SEPARATOR;
free(cwd);
#else #else
String binarydir = "./";
#endif
String binarydir = ".";
char *cwd = nullptr;

# if HAVE_GETCWD
cwd = getcwd(nullptr, 0);
# elif HAVE__GETCWD || (_WIN32 && !_XBOX)
cwd = _getcwd(nullptr, 0);
# endif

if (cwd)
{
binarydir = cwd;
free(cwd);
}

binarydir += SEPARATOR;


if (argc > 0) if (argc > 0)
{ {
@@ -69,6 +75,7 @@ void Init(int argc, char *argv[],
if (last_sep) if (last_sep)
binarydir = String(argv[0], last_sep - argv[0] + 1); binarydir = String(argv[0], last_sep - argv[0] + 1);
} }
#endif


/* /*
* Find the common prefix between project dir and solution dir. * Find the common prefix between project dir and solution dir.


Loading…
Cancel
Save