1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _OSL_FILE_PATH_HELPER_HXX_ 29*cdf0e10cSrcweir #define _OSL_FILE_PATH_HELPER_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #ifndef _OSL_FILE_PATH_HELPER_H_ 33*cdf0e10cSrcweir #include "file_path_helper.h" 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <rtl/ustring.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir namespace osl 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir /******************************************* 43*cdf0e10cSrcweir systemPathRemoveSeparator 44*cdf0e10cSrcweir Removes the last separator from the 45*cdf0e10cSrcweir given system path if any and if the path 46*cdf0e10cSrcweir is not the root path '/' 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir @param ppustrPath [inout] a system path 49*cdf0e10cSrcweir if the path is not the root path 50*cdf0e10cSrcweir and the last character is a 51*cdf0e10cSrcweir path separator it will be cut off 52*cdf0e10cSrcweir ppustrPath must not be NULL and 53*cdf0e10cSrcweir must point to a valid rtl_uString 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir @returns nothing 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir ******************************************/ 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir inline void systemPathRemoveSeparator(/*inout*/ rtl::OUString& Path) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir osl_systemPathRemoveSeparator(Path.pData); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir /******************************************* 65*cdf0e10cSrcweir systemPathEnsureSeparator 66*cdf0e10cSrcweir Adds a trailing path separator to the 67*cdf0e10cSrcweir given system path if not already there 68*cdf0e10cSrcweir and if the path is not the root path '/' 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir @param pustrPath [inout] a system path 71*cdf0e10cSrcweir if the path is not the root path 72*cdf0e10cSrcweir '/' and has no trailing separator 73*cdf0e10cSrcweir a separator will be added 74*cdf0e10cSrcweir ppustrPath must not be NULL and 75*cdf0e10cSrcweir must point to a valid rtl_uString 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir @returns nothing 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir ******************************************/ 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir inline void systemPathEnsureSeparator(/*inout*/ rtl::OUString& Path) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir osl_systemPathEnsureSeparator(&Path.pData); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir /******************************************* 87*cdf0e10cSrcweir systemPathIsRelativePath 88*cdf0e10cSrcweir Returns true if the given path is a 89*cdf0e10cSrcweir relative path and so starts not with '/' 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir @param pustrPath [in] a system path 92*cdf0e10cSrcweir pustrPath must not be NULL 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir @returns sal_True if the given path 95*cdf0e10cSrcweir doesn't start with a separator 96*cdf0e10cSrcweir else sal_False will be returned 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir ******************************************/ 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir inline bool systemPathIsRelativePath(const rtl::OUString& Path) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir return osl_systemPathIsRelativePath(Path.pData); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir /****************************************** 106*cdf0e10cSrcweir systemPathMakeAbsolutePath 107*cdf0e10cSrcweir Append a relative path to a base path 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir @param pustrBasePath [in] a system 110*cdf0e10cSrcweir path that will be considered as 111*cdf0e10cSrcweir base path 112*cdf0e10cSrcweir pustrBasePath must not be NULL 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir @param pustrRelPath [in] a system path 115*cdf0e10cSrcweir that will be considered as 116*cdf0e10cSrcweir relative path 117*cdf0e10cSrcweir pustrBasePath must not be NULL 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir @param ppustrAbsolutePath [out] the 120*cdf0e10cSrcweir resulting path which is a 121*cdf0e10cSrcweir concatination of the base and 122*cdf0e10cSrcweir the relative path 123*cdf0e10cSrcweir if base path is empty the 124*cdf0e10cSrcweir resulting absolute path is the 125*cdf0e10cSrcweir relative path 126*cdf0e10cSrcweir if relative path is empty the 127*cdf0e10cSrcweir resulting absolute path is the 128*cdf0e10cSrcweir base path 129*cdf0e10cSrcweir if base and relative path are 130*cdf0e10cSrcweir empty the resulting absolute 131*cdf0e10cSrcweir path is also empty 132*cdf0e10cSrcweir ppustrAbsolutePath must not be 133*cdf0e10cSrcweir NULL and *ppustrAbsolutePath 134*cdf0e10cSrcweir must be 0 or point to a valid 135*cdf0e10cSrcweir rtl_uString 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir *****************************************/ 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir inline void systemPathMakeAbsolutePath( 140*cdf0e10cSrcweir const rtl::OUString& BasePath, 141*cdf0e10cSrcweir const rtl::OUString& RelPath, 142*cdf0e10cSrcweir rtl::OUString& AbsolutePath) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir osl_systemPathMakeAbsolutePath( 145*cdf0e10cSrcweir BasePath.pData, RelPath.pData, &AbsolutePath.pData); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir /***************************************** 149*cdf0e10cSrcweir systemPathGetFileOrLastDirectoryPart 150*cdf0e10cSrcweir Returns the file or the directory part 151*cdf0e10cSrcweir of the given path 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir @param pustrPath [in] a system path, 154*cdf0e10cSrcweir must not be NULL 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir @param ppustrFileOrDirPart [out] on 157*cdf0e10cSrcweir return receives the last part 158*cdf0e10cSrcweir of the given directory or the 159*cdf0e10cSrcweir file name 160*cdf0e10cSrcweir if pustrPath is the root path 161*cdf0e10cSrcweir '/' an empty string will be 162*cdf0e10cSrcweir returned 163*cdf0e10cSrcweir if pustrPath has a trailing 164*cdf0e10cSrcweir '/' the last part before the 165*cdf0e10cSrcweir '/' will be returned else 166*cdf0e10cSrcweir the part after the last '/' 167*cdf0e10cSrcweir will be returned 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir @returns nothing 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir ****************************************/ 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir inline void systemPathGetFileNameOrLastDirectoryPart( 174*cdf0e10cSrcweir const rtl::OUString& Path, 175*cdf0e10cSrcweir rtl::OUString& FileNameOrLastDirPart) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir osl_systemPathGetFileNameOrLastDirectoryPart( 178*cdf0e10cSrcweir Path.pData, &FileNameOrLastDirPart.pData); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir /******************************************** 183*cdf0e10cSrcweir systemPathIsHiddenFileOrDirectoryEntry 184*cdf0e10cSrcweir Returns sal_True if the last part of 185*cdf0e10cSrcweir given system path is not '.' or '..' 186*cdf0e10cSrcweir alone and starts with a '.' 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir @param pustrPath [in] a system path, 189*cdf0e10cSrcweir must not be NULL 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir @returns sal_True if the last part of 192*cdf0e10cSrcweir the given system path starts 193*cdf0e10cSrcweir with '.' or sal_False the last 194*cdf0e10cSrcweir part is '.' or '..' alone or 195*cdf0e10cSrcweir doesn't start with a dot 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir *********************************************/ 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir inline bool systemPathIsHiddenFileOrDirectoryEntry( 200*cdf0e10cSrcweir const rtl::OUString& Path) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir return osl_systemPathIsHiddenFileOrDirectoryEntry(Path.pData); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir /************************************************ 207*cdf0e10cSrcweir systemPathIsLocalOrParentDirectoryEntry 208*cdf0e10cSrcweir Returns sal_True if the last part of the given 209*cdf0e10cSrcweir system path is the local directory entry '.' 210*cdf0e10cSrcweir or the parent directory entry '..' 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir @param pustrPath [in] a system path, 213*cdf0e10cSrcweir must not be NULL 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir @returns sal_True if the last part of the 216*cdf0e10cSrcweir given system path is '.' or '..' 217*cdf0e10cSrcweir else sal_False 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir ************************************************/ 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir inline bool systemPathIsLocalOrParentDirectoryEntry( 222*cdf0e10cSrcweir const rtl::OUString& Path) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir return osl_systemPathIsLocalOrParentDirectoryEntry(Path.pData); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir /************************************************ 228*cdf0e10cSrcweir searchPath 229*cdf0e10cSrcweir ***********************************************/ 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir inline bool searchPath( 232*cdf0e10cSrcweir const rtl::OUString& ustrFilePath, 233*cdf0e10cSrcweir const rtl::OUString& ustrSearchPathList, 234*cdf0e10cSrcweir rtl::OUString& ustrPathFound) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir return osl_searchPath( 237*cdf0e10cSrcweir ustrFilePath.pData, 238*cdf0e10cSrcweir ustrSearchPathList.pData, 239*cdf0e10cSrcweir &ustrPathFound.pData); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir } // namespace osl 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir #endif /* #ifndef _OSL_PATH_HELPER_HXX_ */ 247*cdf0e10cSrcweir 248