merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / osl / unx / uunxapi.cxx
blob299ea4198fdc8dc49fb3ee22bfcee8bf10383ade
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
31 #ifndef _OSL_UUNXAPI_H_
32 #include "uunxapi.h"
33 #endif
35 #ifndef __OSL_SYSTEM_H__
36 #include "system.h"
37 #endif
39 #ifndef _LIMITS_H
40 #include <limits.h>
41 #endif
43 #ifndef _RTL_USTRING_HXX_
44 #include <rtl/ustring.hxx>
45 #endif
47 #ifndef _OSL_THREAD_H_
48 #include <osl/thread.h>
49 #endif
51 //###########################
52 inline rtl::OString OUStringToOString(const rtl_uString* s)
54 return rtl::OUStringToOString(
55 rtl::OUString(const_cast<rtl_uString*>(s)),
56 osl_getThreadTextEncoding());
59 //###########################
60 #ifdef MACOSX
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
65 inline rtl::OString macxp_resolveAliasAndConvert(const rtl_uString* s)
67 rtl::OString p = OUStringToOString(s);
68 sal_Char path[PATH_MAX];
69 if (p.getLength() < PATH_MAX)
71 strcpy(path, p.getStr());
72 macxp_resolveAlias(path, PATH_MAX);
73 p = rtl::OString(path);
75 return p;
77 #endif /* MACOSX */
79 //###########################
80 //access_u
81 int access_u(const rtl_uString* pustrPath, int mode)
83 #ifndef MACOSX // not MACOSX
84 return access(OUStringToOString(pustrPath).getStr(), mode);
85 #else
86 return access(macxp_resolveAliasAndConvert(pustrPath).getStr(), mode);
87 #endif
90 //#########################
91 //realpath_u
92 sal_Bool realpath_u(const rtl_uString* pustrFileName, rtl_uString** ppustrResolvedName)
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);
102 if (bRet)
104 rtl::OUString resolved = rtl::OStringToOUString(
105 rtl::OString(static_cast<sal_Char*>(rp)),
106 osl_getThreadTextEncoding());
108 rtl_uString_assign(ppustrResolvedName, resolved.pData);
110 return bRet;
113 //#########################
114 //lstat_u
115 int lstat_u(const rtl_uString* pustrPath, struct stat* buf)
117 #ifndef MACOSX // not MACOSX
118 return lstat(OUStringToOString(pustrPath).getStr(), buf);
119 #else
120 return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf);
121 #endif
124 //#########################
125 // @see mkdir
126 int mkdir_u(const rtl_uString* path, mode_t mode)
128 return mkdir(OUStringToOString(path).getStr(), mode);