xref: /trunk/main/sal/osl/w32/path_helper.hxx (revision 0bc0886b)
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 #include <rtl/alloc.h>
34 
35 namespace osl
36 {
37 
38 /*******************************************************************
39  osl_systemPathEnsureSeparator
40  Adds a trailing path separator to the given system path if not
41  already there and if the path is not the root path or a logical
42  drive alone
43  ******************************************************************/
44 
systemPathEnsureSeparator(rtl::OUString & Path)45 inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path)
46 {
47     osl_systemPathEnsureSeparator(&Path.pData);
48 }
49 
50 /*******************************************************************
51  osl_systemPathRemoveSeparator
52  Removes the last separator from the given system path if any and
53  if the path is not the root path '\'
54  ******************************************************************/
55 
systemPathRemoveSeparator(rtl::OUString & Path)56 inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path)
57 {
58     osl_systemPathRemoveSeparator(&Path.pData);
59 }
60 
61 /*******************************************************************
62  osl_systemPathIsLogicalDrivePattern
63  ******************************************************************/
64 
systemPathIsLogicalDrivePattern(const rtl::OUString & path)65 inline bool systemPathIsLogicalDrivePattern(/*in*/ const rtl::OUString& path)
66 {
67     return osl_systemPathIsLogicalDrivePattern(path.pData);
68 }
69 
70 /*******************************************************************
71  LongPathBuffer
72  ******************************************************************/
73 template< class T >
74 class LongPathBuffer
75 {
76     T* m_pBuffer;
77     sal_uInt32 m_nCharNum;
78 
79     LongPathBuffer();
80     LongPathBuffer( const LongPathBuffer& );
81     LongPathBuffer& operator=( const LongPathBuffer& );
82 
83 public:
LongPathBuffer(sal_uInt32 nCharNum)84     LongPathBuffer( sal_uInt32 nCharNum )
85     : m_pBuffer( reinterpret_cast<T*>( rtl_allocateMemory( nCharNum * sizeof( T ) ) ) )
86     , m_nCharNum( nCharNum )
87     {
88         OSL_ENSURE( m_pBuffer, "Can not allocate the buffer!" );
89     }
90 
~LongPathBuffer()91     ~LongPathBuffer()
92     {
93         if ( m_pBuffer )
94             rtl_freeMemory( m_pBuffer );
95         m_pBuffer = 0;
96     }
97 
getBufSizeInSymbols()98     sal_uInt32 getBufSizeInSymbols()
99     {
100         return m_nCharNum;
101     }
102 
operator T*()103     operator T* ()
104     {
105         return m_pBuffer;
106     }
107 
108 };
109 
mingw_reinterpret_cast(LongPathBuffer<T> & a)110     template< class U, class T > U mingw_reinterpret_cast(LongPathBuffer<T>& a) { return reinterpret_cast<U>(static_cast<T*>(a)); }
111 
112 } // end namespace osl
113 
114 #endif
115