xref: /trunk/main/sal/osl/w32/path_helper.hxx (revision 22076bf1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifdef _MSC_VER
25 #pragma warning (disable : 4800)
26 #endif
27 
28 #ifndef _PATH_HELPER_HXX_
29 #define _PATH_HELPER_HXX_
30 
31 #include "path_helper.h"
32 #include <rtl/ustring.hxx>
33 
34 namespace osl
35 {
36 
37 /*******************************************************************
38  osl_systemPathEnsureSeparator
39  Adds a trailing path separator to the given system path if not
40  already there and if the path is not the root path or a logical
41  drive alone
42  ******************************************************************/
43 
44 inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path)
45 {
46     osl_systemPathEnsureSeparator(&Path.pData);
47 }
48 
49 /*******************************************************************
50  osl_systemPathRemoveSeparator
51  Removes the last separator from the given system path if any and
52  if the path is not the root path '\'
53  ******************************************************************/
54 
55 inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path)
56 {
57     osl_systemPathRemoveSeparator(&Path.pData);
58 }
59 
60 /*******************************************************************
61  osl_systemPathIsLogicalDrivePattern
62  ******************************************************************/
63 
64 inline bool systemPathIsLogicalDrivePattern(/*in*/ const rtl::OUString& path)
65 {
66     return osl_systemPathIsLogicalDrivePattern(path.pData);
67 }
68 
69 /*******************************************************************
70  LongPathBuffer
71  ******************************************************************/
72 template< class T >
73 class LongPathBuffer
74 {
75     T* m_pBuffer;
76     sal_uInt32 m_nCharNum;
77 
78     LongPathBuffer();
79     LongPathBuffer( const LongPathBuffer& );
80     LongPathBuffer& operator=( const LongPathBuffer& );
81 
82 public:
83     LongPathBuffer( sal_uInt32 nCharNum )
84     : m_pBuffer( reinterpret_cast<T*>( rtl_allocateMemory( nCharNum * sizeof( T ) ) ) )
85     , m_nCharNum( nCharNum )
86     {
87         OSL_ENSURE( m_pBuffer, "Can not allocate the buffer!" );
88     }
89 
90     ~LongPathBuffer()
91     {
92         if ( m_pBuffer )
93             rtl_freeMemory( m_pBuffer );
94         m_pBuffer = 0;
95     }
96 
97     sal_uInt32 getBufSizeInSymbols()
98     {
99         return m_nCharNum;
100     }
101 
102     operator T* ()
103     {
104         return m_pBuffer;
105     }
106 
107 };
108 
109     template< class U, class T > U mingw_reinterpret_cast(LongPathBuffer<T>& a) { return reinterpret_cast<U>(static_cast<T*>(a)); }
110 
111 } // end namespace osl
112 
113 #endif
114