diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-05-13 03:35:30 +0200 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-05-13 03:35:30 +0200 |
commit | 670a8f984fc6d8342180c59ae9e96b0b76f34d3d (patch) | |
tree | 9f2ce7eec1a77e56b3bb1ad0ad40f212d7a996b0 /jam-files/engine/pwd.c | |
parent | eb3ee28dc0eb1d3e5ed01ba0df843be329ae450d (diff) | |
parent | 2f64af3e06a518b93f7ca2c30a9d0aeb2c947031 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'jam-files/engine/pwd.c')
-rw-r--r-- | jam-files/engine/pwd.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/jam-files/engine/pwd.c b/jam-files/engine/pwd.c new file mode 100644 index 00000000..90c8eb17 --- /dev/null +++ b/jam-files/engine/pwd.c @@ -0,0 +1,66 @@ +/* Copyright Vladimir Prus 2002, Rene Rivera 2005. Distributed under the Boost */ +/* Software License, Version 1.0. (See accompanying */ +/* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ + +#include "jam.h" +#include "lists.h" +#include "newstr.h" +#include "pathsys.h" +#include "mem.h" + +#include <limits.h> +#include <errno.h> + +/* MinGW on windows declares PATH_MAX in limits.h */ +#if defined(NT) && ! defined(__GNUC__) +#include <direct.h> +#define PATH_MAX _MAX_PATH +#else +#include <unistd.h> +#if defined(__COMO__) + #include <linux/limits.h> +#endif +#endif + +#ifndef PATH_MAX + #define PATH_MAX 1024 +#endif + +/* The current directory can't change in bjam, so optimize this to cache +** the result. +*/ +static char * pwd_result = NULL; + + +LIST* +pwd(void) +{ + if (!pwd_result) + { + int buffer_size = PATH_MAX; + char * result_buffer = 0; + do + { + char * buffer = BJAM_MALLOC_RAW(buffer_size); + result_buffer = getcwd(buffer,buffer_size); + if (result_buffer) + { + #ifdef NT + pwd_result = short_path_to_long_path(result_buffer); + #else + pwd_result = newstr(result_buffer); + #endif + } + buffer_size *= 2; + BJAM_FREE_RAW(buffer); + } + while (!pwd_result && errno == ERANGE); + + if (!pwd_result) + { + perror("can not get current directory"); + return L0; + } + } + return list_new(L0, pwd_result); +} |