xref: /aoo4110/main/sal/osl/unx/uunxapi.cxx (revision b1cdbd2c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sal.hxx"
26 
27  #ifndef _OSL_UUNXAPI_H_
28  #include "uunxapi.h"
29  #endif
30 
31  #ifndef __OSL_SYSTEM_H__
32  #include "system.h"
33  #endif
34 
35  #ifndef _LIMITS_H
36  #include <limits.h>
37  #endif
38 
39  #ifndef _RTL_USTRING_HXX_
40  #include <rtl/ustring.hxx>
41  #endif
42 
43  #ifndef _OSL_THREAD_H_
44  #include <osl/thread.h>
45  #endif
46 
47  //###########################
OUStringToOString(const rtl_uString * s)48  inline rtl::OString OUStringToOString(const rtl_uString* s)
49  {
50     return rtl::OUStringToOString(
51         rtl::OUString(const_cast<rtl_uString*>(s)),
52         osl_getThreadTextEncoding());
53  }
54 
55  //###########################
56 #ifdef MACOSX
57 /*
58  * Helper function for resolving Mac native alias files (not the same as unix alias files)
59  * and to return the resolved alias as rtl::OString
60  */
macxp_resolveAliasAndConvert(const rtl_uString * s)61  inline rtl::OString macxp_resolveAliasAndConvert(const rtl_uString* s)
62  {
63   rtl::OString p = OUStringToOString(s);
64   sal_Char path[PATH_MAX];
65   if (p.getLength() < PATH_MAX)
66     {
67       strcpy(path, p.getStr());
68       macxp_resolveAlias(path, PATH_MAX);
69       p = rtl::OString(path);
70     }
71   return p;
72  }
73 #endif /* MACOSX */
74 
75  //###########################
76  //access_u
access_u(const rtl_uString * pustrPath,int mode)77  int access_u(const rtl_uString* pustrPath, int mode)
78  {
79 #ifndef MACOSX // not MACOSX
80 	return access(OUStringToOString(pustrPath).getStr(), mode);
81 #else
82 	return access(macxp_resolveAliasAndConvert(pustrPath).getStr(), mode);
83 #endif
84  }
85 
86  //#########################
87  //realpath_u
realpath_u(const rtl_uString * pustrFileName,rtl_uString ** ppustrResolvedName)88  sal_Bool realpath_u(const rtl_uString* pustrFileName, rtl_uString** ppustrResolvedName)
89  {
90 #ifndef MACOSX // not MACOSX
91         rtl::OString fn = OUStringToOString(pustrFileName);
92 #else
93 	rtl::OString fn = macxp_resolveAliasAndConvert(pustrFileName);
94 #endif
95 	char  rp[PATH_MAX];
96 	bool  bRet = realpath(fn.getStr(), rp);
97 
98 	if (bRet)
99 	{
100 		rtl::OUString resolved = rtl::OStringToOUString(
101 			rtl::OString(static_cast<sal_Char*>(rp)),
102 			osl_getThreadTextEncoding());
103 
104 		rtl_uString_assign(ppustrResolvedName, resolved.pData);
105 	}
106 	return bRet;
107  }
108 
109  //#########################
110  //lstat_u
lstat_u(const rtl_uString * pustrPath,struct stat * buf)111   int lstat_u(const rtl_uString* pustrPath, struct stat* buf)
112  {
113 #ifndef MACOSX  // not MACOSX
114 	return lstat(OUStringToOString(pustrPath).getStr(), buf);
115 #else
116 	return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf);
117 #endif
118  }
119 
120  //#########################
121  // @see mkdir
mkdir_u(const rtl_uString * path,mode_t mode)122  int mkdir_u(const rtl_uString* path, mode_t mode)
123  {
124     return mkdir(OUStringToOString(path).getStr(), mode);
125  }
126 
127