From 937f3e4522b181f760d0f54d5ce392f8fbb01dbf Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 22 Jan 2013 20:46:28 +0000 Subject: [PATCH] sys: check for and use getcwd() properly on non-Windows systems. --- configure.ac | 2 +- src/sys/init.cpp | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 85dda77d..d5de0908 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/src/sys/init.cpp b/src/sys/init.cpp index 853f32dc..01740474 100644 --- a/src/sys/init.cpp +++ b/src/sys/init.cpp @@ -12,6 +12,10 @@ # include "config.h" #endif +#if defined HAVE_UNISTD_H +# include +#endif + #ifdef _WIN32 # define WIN32_LEAN_AND_MEAN # include @@ -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()); } /*