Bump for 3.6-28
[LibreOffice.git] / sal / osl / unx / uunxapi.cxx
blob270f5c33513a243140c637eed2a17b2e21be8353
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #ifndef _OSL_UUNXAPI_H_
31 #include "uunxapi.h"
32 #endif
34 #ifndef __OSL_SYSTEM_H__
35 #include "system.h"
36 #endif
38 #ifndef _LIMITS_H
39 #include <limits.h>
40 #endif
42 #ifndef _RTL_USTRING_HXX_
43 #include <rtl/ustring.hxx>
44 #endif
46 #ifndef _OSL_THREAD_H_
47 #include <osl/thread.h>
48 #endif
50 #ifdef ANDROID
51 #include <osl/detail/android-bootstrap.h>
52 #endif
54 //###########################
55 inline rtl::OString OUStringToOString(const rtl_uString* s)
57 return rtl::OUStringToOString(
58 rtl::OUString(const_cast<rtl_uString*>(s)),
59 osl_getThreadTextEncoding());
62 //###########################
63 #ifdef MACOSX
65 * Helper function for resolving Mac native alias files (not the same as unix alias files)
66 * and to return the resolved alias as rtl::OString
68 inline rtl::OString macxp_resolveAliasAndConvert(const rtl_uString* s)
70 rtl::OString p = OUStringToOString(s);
71 sal_Char path[PATH_MAX];
72 if (p.getLength() < PATH_MAX)
74 strcpy(path, p.getStr());
75 macxp_resolveAlias(path, PATH_MAX);
76 p = rtl::OString(path);
78 return p;
80 #endif /* MACOSX */
82 //###########################
83 //access_u
84 int access_u(const rtl_uString* pustrPath, int mode)
86 #ifndef MACOSX // not MACOSX
87 rtl::OString fn = OUStringToOString(pustrPath);
88 #ifdef ANDROID
89 if (strncmp(fn.getStr(), "/assets", sizeof("/assets")-1) == 0 &&
90 (fn.getStr()[sizeof("/assets")-1] == '\0' ||
91 fn.getStr()[sizeof("/assets")-1] == '/'))
93 struct stat stat;
94 if (lo_apk_lstat(fn.getStr(), &stat) == -1)
95 return -1;
96 if (mode & W_OK)
98 errno = EACCES;
99 return -1;
101 return 0;
103 #endif
104 return access(fn.getStr(), mode);
105 #else
106 return access(macxp_resolveAliasAndConvert(pustrPath).getStr(), mode);
107 #endif
110 //#########################
111 //realpath_u
112 sal_Bool realpath_u(const rtl_uString* pustrFileName, rtl_uString** ppustrResolvedName)
114 #ifndef MACOSX // not MACOSX
115 rtl::OString fn = OUStringToOString(pustrFileName);
116 #ifdef ANDROID
117 if (strncmp(fn.getStr(), "/assets", sizeof("/assets")-1) == 0 &&
118 (fn.getStr()[sizeof("/assets")-1] == '\0' ||
119 fn.getStr()[sizeof("/assets")-1] == '/'))
121 if (access_u(pustrFileName, F_OK) == -1)
122 return sal_False;
124 rtl_uString silly(*pustrFileName);
125 rtl_uString_assign(ppustrResolvedName, &silly);
127 return sal_True;
129 #endif
130 #else
131 rtl::OString fn = macxp_resolveAliasAndConvert(pustrFileName);
132 #endif
133 char rp[PATH_MAX];
134 bool bRet = realpath(fn.getStr(), rp);
136 if (bRet)
138 rtl::OUString resolved = rtl::OStringToOUString(
139 rtl::OString(static_cast<sal_Char*>(rp)),
140 osl_getThreadTextEncoding());
142 rtl_uString_assign(ppustrResolvedName, resolved.pData);
144 return bRet;
147 //#########################
148 //stat_c
149 int stat_c(const char* cpPath, struct stat* buf)
151 #ifdef ANDROID
152 if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 &&
153 (cpPath[sizeof("/assets")-1] == '\0' ||
154 cpPath[sizeof("/assets")-1] == '/'))
155 return lo_apk_lstat(cpPath, buf);
156 #endif
157 return stat(cpPath, buf);
160 //#########################
161 //lstat_c
162 int lstat_c(const char* cpPath, struct stat* buf)
164 #ifdef ANDROID
165 if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 &&
166 (cpPath[sizeof("/assets")-1] == '\0' ||
167 cpPath[sizeof("/assets")-1] == '/'))
168 return lo_apk_lstat(cpPath, buf);
169 #endif
170 return lstat(cpPath, buf);
173 //#########################
174 //lstat_u
175 int lstat_u(const rtl_uString* pustrPath, struct stat* buf)
177 #ifndef MACOSX // not MACOSX
178 rtl::OString fn = OUStringToOString(pustrPath);
179 return lstat_c(fn.getStr(), buf);
180 #else
181 return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf);
182 #endif
185 //#########################
186 // @see mkdir
187 int mkdir_u(const rtl_uString* path, mode_t mode)
189 return mkdir(OUStringToOString(path).getStr(), mode);
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */