bump product version to 4.1.6.2
[LibreOffice.git] / sal / osl / unx / uunxapi.cxx
blob7d62eee86f2a5957884e9801676a277adc977b57
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "uunxapi.h"
21 #include "system.h"
22 #include <limits.h>
23 #include <rtl/ustring.hxx>
24 #include <osl/thread.h>
26 #ifdef ANDROID
27 #include <osl/detail/android-bootstrap.h>
28 #endif
30 //###########################
31 inline rtl::OString OUStringToOString(const rtl_uString* s)
33 return rtl::OUStringToOString(
34 rtl::OUString(const_cast<rtl_uString*>(s)),
35 osl_getThreadTextEncoding());
38 //###########################
39 #ifdef MACOSX
41 * Helper function for resolving Mac native alias files (not the same as unix alias files)
42 * and to return the resolved alias as rtl::OString
44 inline rtl::OString macxp_resolveAliasAndConvert(const rtl_uString* s)
46 rtl::OString p = OUStringToOString(s);
47 sal_Char path[PATH_MAX];
48 if (p.getLength() < PATH_MAX)
50 strcpy(path, p.getStr());
51 macxp_resolveAlias(path, PATH_MAX);
52 p = rtl::OString(path);
54 return p;
56 #endif /* MACOSX */
58 //###########################
59 //access_u
60 int access_u(const rtl_uString* pustrPath, int mode)
62 #ifndef MACOSX // not MACOSX
63 rtl::OString fn = OUStringToOString(pustrPath);
64 #ifdef ANDROID
65 if (strncmp(fn.getStr(), "/assets", sizeof("/assets")-1) == 0 &&
66 (fn.getStr()[sizeof("/assets")-1] == '\0' ||
67 fn.getStr()[sizeof("/assets")-1] == '/'))
69 struct stat stat;
70 if (lo_apk_lstat(fn.getStr(), &stat) == -1)
71 return -1;
72 if (mode & W_OK)
74 errno = EACCES;
75 return -1;
77 return 0;
79 #endif
80 return access(fn.getStr(), mode);
81 #else
82 return access(macxp_resolveAliasAndConvert(pustrPath).getStr(), mode);
83 #endif
86 //#########################
87 //realpath_u
88 sal_Bool realpath_u(const rtl_uString* pustrFileName, rtl_uString** ppustrResolvedName)
90 #ifndef MACOSX // not MACOSX
91 rtl::OString fn = OUStringToOString(pustrFileName);
92 #ifdef ANDROID
93 if (strncmp(fn.getStr(), "/assets", sizeof("/assets")-1) == 0 &&
94 (fn.getStr()[sizeof("/assets")-1] == '\0' ||
95 fn.getStr()[sizeof("/assets")-1] == '/'))
97 if (access_u(pustrFileName, F_OK) == -1)
98 return sal_False;
100 rtl_uString silly(*pustrFileName);
101 rtl_uString_assign(ppustrResolvedName, &silly);
103 return sal_True;
105 #endif
106 #else
107 rtl::OString fn = macxp_resolveAliasAndConvert(pustrFileName);
108 #endif
109 char rp[PATH_MAX];
110 bool bRet = realpath(fn.getStr(), rp);
112 if (bRet)
114 rtl::OUString resolved = rtl::OStringToOUString(
115 rtl::OString(static_cast<sal_Char*>(rp)),
116 osl_getThreadTextEncoding());
118 rtl_uString_assign(ppustrResolvedName, resolved.pData);
120 return bRet;
123 //#########################
124 //stat_c
125 int stat_c(const char* cpPath, struct stat* buf)
127 #ifdef ANDROID
128 if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 &&
129 (cpPath[sizeof("/assets")-1] == '\0' ||
130 cpPath[sizeof("/assets")-1] == '/'))
131 return lo_apk_lstat(cpPath, buf);
132 #endif
133 return stat(cpPath, buf);
136 //#########################
137 //lstat_c
138 int lstat_c(const char* cpPath, struct stat* buf)
140 #ifdef ANDROID
141 if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 &&
142 (cpPath[sizeof("/assets")-1] == '\0' ||
143 cpPath[sizeof("/assets")-1] == '/'))
144 return lo_apk_lstat(cpPath, buf);
145 #endif
146 return lstat(cpPath, buf);
149 //#########################
150 //lstat_u
151 int lstat_u(const rtl_uString* pustrPath, struct stat* buf)
153 #ifndef MACOSX // not MACOSX
154 rtl::OString fn = OUStringToOString(pustrPath);
155 return lstat_c(fn.getStr(), buf);
156 #else
157 return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf);
158 #endif
161 //#########################
162 // @see mkdir
163 int mkdir_u(const rtl_uString* path, mode_t mode)
165 return mkdir(OUStringToOString(path).getStr(), mode);
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */