blob: 93d8126032919ab39831c778d5e0baa563158926 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/* 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 "object.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 OBJECT * 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
OBJECT * result = object_new(result_buffer);
pwd_result = short_path_to_long_path(result);
object_free( result );
#else
pwd_result = object_new(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( object_copy( pwd_result ) );
}
void pwd_done( void )
{
if( pwd_result )
{
object_free( pwd_result );
}
}
|