xref: /aoo4110/main/tools/inc/tools/pathutils.hxx (revision b1cdbd2c)
1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski #ifndef INCLUDED_TOOLS_PATHUTILS_HXX
25*b1cdbd2cSJim Jagielski #define INCLUDED_TOOLS_PATHUTILS_HXX
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski #include "sal/config.h"
28*b1cdbd2cSJim Jagielski 
29*b1cdbd2cSJim Jagielski #if defined WNT
30*b1cdbd2cSJim Jagielski 
31*b1cdbd2cSJim Jagielski #include <cstddef>
32*b1cdbd2cSJim Jagielski 
33*b1cdbd2cSJim Jagielski #define WIN32_LEAN_AND_MEAN
34*b1cdbd2cSJim Jagielski #include <windows.h>
35*b1cdbd2cSJim Jagielski 
36*b1cdbd2cSJim Jagielski // The compiled code is not part of the tl dynamic library, but is delivered as
37*b1cdbd2cSJim Jagielski // pathutils-obj and pathutils-slo objects (it is linked into special
38*b1cdbd2cSJim Jagielski // executables and dynamic libraries that do not link against OOo libraries):
39*b1cdbd2cSJim Jagielski 
40*b1cdbd2cSJim Jagielski namespace tools {
41*b1cdbd2cSJim Jagielski 
42*b1cdbd2cSJim Jagielski // Determine the filename part of a path.
43*b1cdbd2cSJim Jagielski //
44*b1cdbd2cSJim Jagielski // @param path
45*b1cdbd2cSJim Jagielski // A non-NULL pointer to a null-terminated path.
46*b1cdbd2cSJim Jagielski //
47*b1cdbd2cSJim Jagielski // @return
48*b1cdbd2cSJim Jagielski // A pointer to the trailing filename part of the given path.
49*b1cdbd2cSJim Jagielski WCHAR * filename(WCHAR * path);
50*b1cdbd2cSJim Jagielski 
51*b1cdbd2cSJim Jagielski // Concatenate two paths.
52*b1cdbd2cSJim Jagielski //
53*b1cdbd2cSJim Jagielski // Either the first path is empty and the second path is an absolute path.  Or
54*b1cdbd2cSJim Jagielski // the first path is an absolute path that ends in a backslash and the second
55*b1cdbd2cSJim Jagielski // path is a relative path.  In the latter case, to avoid paths that grow too
56*b1cdbd2cSJim Jagielski // long, leading .. segments of the second path are removed together with
57*b1cdbd2cSJim Jagielski // trailing segments from the first path.  This should not cause problems as
58*b1cdbd2cSJim Jagielski // long as there are no symbolic links on Windows (as with symbolic links,
59*b1cdbd2cSJim Jagielski // x\y\.. and x might denote different directories).
60*b1cdbd2cSJim Jagielski //
61*b1cdbd2cSJim Jagielski // @param path
62*b1cdbd2cSJim Jagielski // An output paremeter taking the resulting path; must point at a valid range of
63*b1cdbd2cSJim Jagielski // memory of size at least MAX_PATH.  If NULL is returned, the content is
64*b1cdbd2cSJim Jagielski // unspecified.
65*b1cdbd2cSJim Jagielski //
66*b1cdbd2cSJim Jagielski // @param frontBegin, frontEnd
67*b1cdbd2cSJim Jagielski // Forms a valid range [frontBegin .. frontEnd) of less than MAX_PATH size.
68*b1cdbd2cSJim Jagielski //
69*b1cdbd2cSJim Jagielski // @param backBegin, backLength
70*b1cdbd2cSJim Jagielski // Forms a valid range [backBeghin .. backBegin + backLength) of less than
71*b1cdbd2cSJim Jagielski // MAX_PATH size.
72*b1cdbd2cSJim Jagielski //
73*b1cdbd2cSJim Jagielski // @return
74*b1cdbd2cSJim Jagielski // A pointer to the terminating null character of the concatenation, or NULL if
75*b1cdbd2cSJim Jagielski // a failure occurred.
76*b1cdbd2cSJim Jagielski WCHAR * buildPath(
77*b1cdbd2cSJim Jagielski     WCHAR * path, WCHAR const * frontBegin, WCHAR const * frontEnd,
78*b1cdbd2cSJim Jagielski     WCHAR const * backBegin, std::size_t backLength);
79*b1cdbd2cSJim Jagielski 
80*b1cdbd2cSJim Jagielski // Resolve a link file.
81*b1cdbd2cSJim Jagielski //
82*b1cdbd2cSJim Jagielski // @param path
83*b1cdbd2cSJim Jagielski // An input/output parameter taking the path; must point at a valid range of
84*b1cdbd2cSJim Jagielski // memory of size at least MAX_PATH.  On input, contains the null-terminated
85*b1cdbd2cSJim Jagielski // full path of the link file.  On output, contains the null-terminated full
86*b1cdbd2cSJim Jagielski // path of the resolved link; if NULL is returned, the content is unspecified.
87*b1cdbd2cSJim Jagielski //
88*b1cdbd2cSJim Jagielski // @return
89*b1cdbd2cSJim Jagielski // A pointer to the terminating null character of path, or NULL if a failure
90*b1cdbd2cSJim Jagielski // occurred.
91*b1cdbd2cSJim Jagielski WCHAR * resolveLink(WCHAR * path);
92*b1cdbd2cSJim Jagielski 
93*b1cdbd2cSJim Jagielski }
94*b1cdbd2cSJim Jagielski 
95*b1cdbd2cSJim Jagielski #endif
96*b1cdbd2cSJim Jagielski 
97*b1cdbd2cSJim Jagielski #endif
98