]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/pathvms.cpp
2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * Copyright 2001-2004 David Abrahams.
9 * Copyright 2005 Rene Rivera.
10 * Copyright 2015 Artur Shepilko.
11 * Distributed under the Boost Software License, Version 1.0.
12 * (See accompanying file LICENSE_1_0.txt or copy at
13 * http://www.boost.org/LICENSE_1_0.txt)
18 * pathvms.c - VMS-specific path manipulation support
20 * This implementation is based on POSIX-style path manipulation.
22 * VMS CTRL directly supports both POSIX- and native VMS-style path expressions,
23 * with the POSIX-to-VMS path translation performed internally by the same
24 * set of functions. For the most part such processing is transparent, with
25 * few differences mainly related to file-versions (in POSIX mode only the recent
26 * version is visible).
28 * This should allow us to some extent re-use pathunix.c implementation.
30 * Thus in jam-files the path references can also remain POSIX/UNIX-like on all
31 * levels EXCEPT in actions scope, where the path references must be translated
32 * to the native VMS-style. This approach is somewhat similar to jam CYGWIN
41 * External routines called only via routines in pathsys.c:
42 * path_get_process_id_()
43 * path_get_temp_path_()
44 * path_translate_to_os_()
56 #include <unistd.h> /* needed for getpid() */
57 #include <unixlib.h> /* needed for decc$to_vms() */
61 * path_get_process_id_()
64 unsigned long path_get_process_id_( void )
71 * path_get_temp_path_()
74 void path_get_temp_path_( string
* buffer
)
76 char const * t
= getenv( "TMPDIR" );
77 string_append( buffer
, t
? t
: "/tmp" );
82 * translate_path_posix2vms()
84 * POSIX-to-VMS file specification translation:
86 * Translation is performed with decc$to_vms() CTRL routine (default decc$features)
87 * Some limitations apply:
88 * -- ODS-2 compliant file specs only (no spaces, punctuation chars etc.)
90 * -- wild-cards are not allowed
91 * In general decc$to_vms() can expand the wildcard for existing files,
92 * yet it cannot retain wild-cards in translated spec. Use GLOB for this.
94 * -- rooted path must refer to an existing/defined device or root-dir
95 * (e.g. /defconcealed/dir/file.ext or /existingrootdir/dir/file.ext )
97 * -- POSIX dir/no-type-file path ambiguity (e.g. dir/newsubdir vs. dir/newfile
98 * is handled as follows:
100 * 1) first try as directory:
101 * -- if translated (may be a dir): means the file-path has no .type/suffix
102 * -- if not translated, then it may be a file (has .type) OR invalid spec
103 * 2) then try as file:
104 * -- if translated and also is a dir -- check if such file exists (stat)
105 * -- if not translated, but is a dir -- return as dir
107 * NOTE: on VMS it's possible to have both a file and a dir of the same name
108 * appear in the same directory. In such case _directory_ intent is assumed.
110 * It's preferable to avoid such naming ambiguity in this context, so
111 * append an empty .type to specify a no-type file (eg. "filename.")
116 static string
* m_vmsfilespec
= NULL
;
119 * copy_vmsfilespec() - decc$to_vms action routine for matched filenames
122 static int copy_vmsfilespec( char * f
, int type
)
124 assert ( NULL
!= m_vmsfilespec
&& "Must be bound to a valid object" );
126 string_copy( m_vmsfilespec
, f
);
128 /* 0:Exit on first match (1:Process all) */
133 static int translate_path_posix2vms( string
* path
)
142 unsigned char is_dir
;
143 unsigned char is_file
;
144 unsigned char is_ambiguous
;
146 string_new( as_dir
);
147 string_new( as_file
);
150 m_vmsfilespec
= as_dir
;
152 /* MATCH 0:do not allow wildcards, 0:allow directories (2:dir only) */
153 dir_count
= decc$
to_vms( path
->value
, copy_vmsfilespec
, 0, 2 );
156 m_vmsfilespec
= as_file
;
158 /* MATCH 0:do not allow wildcards, 0:allow directories (2:dir only) */
159 file_count
= decc$
to_vms( path
->value
, copy_vmsfilespec
, 0, 0 );
161 m_vmsfilespec
= NULL
;
164 translated
= ( file_count
|| dir_count
);
166 if ( file_count
&& dir_count
)
170 /* use as_file only when exists AND as_dir does not exist
171 * otherwise use as_dir
173 if ( stat(as_dir
->value
, &statbuf
) < 0
174 && stat(as_file
->value
, &statbuf
) > 0
175 && ( statbuf
.st_mode
& S_IFREG
) )
177 string_truncate( path
, 0 );
178 string_append( path
, as_file
->value
);
182 string_truncate( path
, 0 );
183 string_append( path
, as_dir
->value
);
186 else if ( file_count
)
188 string_truncate( path
, 0 );
189 string_append( path
, as_file
->value
);
191 else if ( dir_count
)
193 string_truncate( path
, 0 );
194 string_append( path
, as_dir
->value
);
198 /* error: unable to translate path to native format */
202 string_free( as_dir
);
203 string_free( as_file
);
210 * path_translate_to_os_()
213 int path_translate_to_os_( char const * f
, string
* file
)
217 /* by default, pass on the original path */
218 string_copy( file
, f
);
220 translated
= translate_path_posix2vms( file
);
227 * path_register_key()
230 void path_register_key( OBJECT
* path
)
239 OBJECT
* path_as_key( OBJECT
* path
)
241 return object_copy( path
);
249 void path_done( void )