Browse Source

sys: check for <unistd.h> and use getcwd() properly on non-Windows systems.

legacy
Sam Hocevar sam 12 years ago
parent
commit
937f3e4522
2 changed files with 13 additions and 6 deletions
  1. +1
    -1
      configure.ac
  2. +12
    -5
      src/sys/init.cpp

+ 1
- 1
configure.ac View File

@@ -73,7 +73,7 @@ AC_ARG_ENABLE(doc,
[ --enable-doc build documentation (needs doxygen and LaTeX)])

AC_CHECK_HEADERS(stdio.h stdarg.h inttypes.h endian.h stdint.h getopt.h)
AC_CHECK_HEADERS(fastmath.h pthread.h libutil.h util.h pty.h glob.h)
AC_CHECK_HEADERS(fastmath.h pthread.h libutil.h util.h pty.h glob.h unistd.h)
AC_CHECK_HEADERS(sys/ioctl.h sys/ptrace.h sys/stat.h sys/syscall.h sys/user.h)
AC_CHECK_HEADERS(sys/wait.h)
AC_CHECK_HEADERS(linux/kdev_t.h linux/major.h)


+ 12
- 5
src/sys/init.cpp View File

@@ -12,6 +12,10 @@
# include "config.h"
#endif

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

#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# include <direct.h>
@@ -39,15 +43,15 @@ void Init(int argc, char *argv[],
*/

#if defined _WIN32
char const *cwd = _getcwd(NULL, 0);
String binarydir = String(cwd ? cwd : ".") + SEPARATOR;
free((void *)cwd);
char *cwd = _getcwd(NULL, 0);
#else
String binarydir = String(getcwd()) + SEPARATOR;
char *cwd = getcwd(NULL, 0);
#endif
String binarydir = String(cwd ? cwd : ".") + SEPARATOR;
free(cwd);
if (argc > 0)
{
char const *last_sep = strchr(argv[0], SEPARATOR);
char const *last_sep = strrchr(argv[0], SEPARATOR);
if (last_sep)
binarydir = String(argv[0], last_sep - argv[0] + 1);
}
@@ -82,6 +86,9 @@ void Init(int argc, char *argv[],
SetDataDir(&binarydir[0]);
got_rootdir = true;
}

Log::Debug("binary dir: %s\n", &binarydir[0]);
Log::Debug("root dir: %s\n", GetDataDir());
}

/*


Loading…
Cancel
Save