xref: /aoo41x/main/sal/osl/unx/uunxapi.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
30 
31  #ifndef _OSL_UUNXAPI_H_
32  #include "uunxapi.h"
33  #endif
34 
35  #ifndef __OSL_SYSTEM_H__
36  #include "system.h"
37  #endif
38 
39  #ifndef _LIMITS_H
40  #include <limits.h>
41  #endif
42 
43  #ifndef _RTL_USTRING_HXX_
44  #include <rtl/ustring.hxx>
45  #endif
46 
47  #ifndef _OSL_THREAD_H_
48  #include <osl/thread.h>
49  #endif
50 
51  //###########################
52  inline rtl::OString OUStringToOString(const rtl_uString* s)
53  {
54     return rtl::OUStringToOString(
55         rtl::OUString(const_cast<rtl_uString*>(s)),
56         osl_getThreadTextEncoding());
57  }
58 
59  //###########################
60 #ifdef MACOSX
61 /*
62  * Helper function for resolving Mac native alias files (not the same as unix alias files)
63  * and to return the resolved alias as rtl::OString
64  */
65  inline rtl::OString macxp_resolveAliasAndConvert(const rtl_uString* s)
66  {
67   rtl::OString p = OUStringToOString(s);
68   sal_Char path[PATH_MAX];
69   if (p.getLength() < PATH_MAX)
70     {
71       strcpy(path, p.getStr());
72       macxp_resolveAlias(path, PATH_MAX);
73       p = rtl::OString(path);
74     }
75   return p;
76  }
77 #endif /* MACOSX */
78 
79  //###########################
80  //access_u
81  int access_u(const rtl_uString* pustrPath, int mode)
82  {
83 #ifndef MACOSX // not MACOSX
84 	return access(OUStringToOString(pustrPath).getStr(), mode);
85 #else
86 	return access(macxp_resolveAliasAndConvert(pustrPath).getStr(), mode);
87 #endif
88  }
89 
90  //#########################
91  //realpath_u
92  sal_Bool realpath_u(const rtl_uString* pustrFileName, rtl_uString** ppustrResolvedName)
93  {
94 #ifndef MACOSX // not MACOSX
95         rtl::OString fn = OUStringToOString(pustrFileName);
96 #else
97 	rtl::OString fn = macxp_resolveAliasAndConvert(pustrFileName);
98 #endif
99 	char  rp[PATH_MAX];
100 	bool  bRet = realpath(fn.getStr(), rp);
101 
102 	if (bRet)
103 	{
104 		rtl::OUString resolved = rtl::OStringToOUString(
105 			rtl::OString(static_cast<sal_Char*>(rp)),
106 			osl_getThreadTextEncoding());
107 
108 		rtl_uString_assign(ppustrResolvedName, resolved.pData);
109 	}
110 	return bRet;
111  }
112 
113  //#########################
114  //lstat_u
115   int lstat_u(const rtl_uString* pustrPath, struct stat* buf)
116  {
117 #ifndef MACOSX  // not MACOSX
118 	return lstat(OUStringToOString(pustrPath).getStr(), buf);
119 #else
120 	return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf);
121 #endif
122  }
123 
124  //#########################
125  // @see mkdir
126  int mkdir_u(const rtl_uString* path, mode_t mode)
127  {
128     return mkdir(OUStringToOString(path).getStr(), mode);
129  }
130 
131