1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include <rtl/ustring.hxx>
24 #include <osl/thread.h>
27 #include <osl/detail/android-bootstrap.h>
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 //###########################
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
);
58 //###########################
60 int access_u(const rtl_uString
* pustrPath
, int mode
)
62 #ifndef MACOSX // not MACOSX
63 rtl::OString fn
= OUStringToOString(pustrPath
);
65 if (strncmp(fn
.getStr(), "/assets", sizeof("/assets")-1) == 0 &&
66 (fn
.getStr()[sizeof("/assets")-1] == '\0' ||
67 fn
.getStr()[sizeof("/assets")-1] == '/'))
70 if (lo_apk_lstat(fn
.getStr(), &stat
) == -1)
80 return access(fn
.getStr(), mode
);
82 return access(macxp_resolveAliasAndConvert(pustrPath
).getStr(), mode
);
86 //#########################
88 sal_Bool
realpath_u(const rtl_uString
* pustrFileName
, rtl_uString
** ppustrResolvedName
)
90 #ifndef MACOSX // not MACOSX
91 rtl::OString fn
= OUStringToOString(pustrFileName
);
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)
100 rtl_uString
silly(*pustrFileName
);
101 rtl_uString_assign(ppustrResolvedName
, &silly
);
107 rtl::OString fn
= macxp_resolveAliasAndConvert(pustrFileName
);
110 bool bRet
= realpath(fn
.getStr(), rp
);
114 rtl::OUString resolved
= rtl::OStringToOUString(
115 rtl::OString(static_cast<sal_Char
*>(rp
)),
116 osl_getThreadTextEncoding());
118 rtl_uString_assign(ppustrResolvedName
, resolved
.pData
);
123 //#########################
125 int stat_c(const char* cpPath
, struct stat
* buf
)
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
);
133 return stat(cpPath
, buf
);
136 //#########################
138 int lstat_c(const char* cpPath
, struct stat
* buf
)
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
);
146 return lstat(cpPath
, buf
);
149 //#########################
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
);
157 return lstat(macxp_resolveAliasAndConvert(pustrPath
).getStr(), buf
);
161 //#########################
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: */