]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/cwd.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / tools / build / src / engine / cwd.cpp
1 /*
2 * Copyright 2002. Vladimir Prus
3 * Copyright 2005. Rene Rivera
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 */
8
9 #include "cwd.h"
10
11 #include "jam.h"
12 #include "mem.h"
13 #include "pathsys.h"
14
15 #include <assert.h>
16 #include <errno.h>
17 #include <limits.h>
18
19 /* MinGW on Windows declares PATH_MAX in limits.h */
20 #if defined( NT ) && !defined( __GNUC__ )
21 # include <direct.h>
22 # define PATH_MAX _MAX_PATH
23 #else
24 # include <unistd.h>
25 # if defined( __COMO__ )
26 # include <linux/limits.h>
27 # endif
28 #endif
29
30 #ifndef PATH_MAX
31 # define PATH_MAX 1024
32 #endif
33
34
35 static OBJECT * cwd_;
36
37
38 void cwd_init( void )
39 {
40 int buffer_size = PATH_MAX;
41 char * cwd_buffer = 0;
42 int error;
43
44 assert( !cwd_ );
45
46 do
47 {
48 char * const buffer = (char *)BJAM_MALLOC_RAW( buffer_size );
49 #ifdef OS_VMS
50 /* cwd in POSIX-format */
51 cwd_buffer = getcwd( buffer, buffer_size, 0 );
52 #else
53 cwd_buffer = getcwd( buffer, buffer_size );
54 #endif
55 error = errno;
56 if ( cwd_buffer )
57 {
58 /* We store the path using its canonical/long/key format. */
59 OBJECT * const cwd = object_new( cwd_buffer );
60 cwd_ = path_as_key( cwd );
61 object_free( cwd );
62 }
63 buffer_size *= 2;
64 BJAM_FREE_RAW( buffer );
65 }
66 while ( !cwd_ && error == ERANGE );
67
68 if ( !cwd_ )
69 {
70 perror( "can not get current working directory" );
71 exit( EXITBAD );
72 }
73 }
74
75
76 OBJECT * cwd( void )
77 {
78 assert( cwd_ );
79 return cwd_;
80 }
81
82
83 void cwd_done( void )
84 {
85 assert( cwd_ );
86 object_free( cwd_ );
87 cwd_ = NULL;
88 }