summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Lillqvist <tlillqvist@suse.com>2012-01-17 12:45:45 +0200
committerTor Lillqvist <tlillqvist@suse.com>2012-01-18 23:15:42 +0200
commita64db11b6ca1c0c99937cd99129758dbbe575ac2 (patch)
tree0132ea0e43c6311a8163daa757e10b906ec117fa
parentdecompose() should return the original rotation angle and scales. (diff)
downloadcore-a64db11b6ca1c0c99937cd99129758dbbe575ac2.tar.gz
core-a64db11b6ca1c0c99937cd99129758dbbe575ac2.zip
Add some non-public API to be used by SvFileStream
Having SvFileStream call the file opening etc functions here, instead of calling open() directly itself, means we won't have to duplicate the Android .apk hooks there, too.
-rw-r--r--sal/Package_inc.mk1
-rw-r--r--sal/inc/osl/detail/file.h87
-rw-r--r--sal/osl/unx/file.cxx77
-rw-r--r--sal/osl/unx/file_stat.cxx23
-rw-r--r--sal/osl/unx/uunxapi.cxx34
-rw-r--r--sal/osl/unx/uunxapi.h6
-rw-r--r--sal/osl/w32/file.cxx16
-rw-r--r--sal/util/sal.map8
8 files changed, 224 insertions, 28 deletions
diff --git a/sal/Package_inc.mk b/sal/Package_inc.mk
index e4dd5292c10b..7a5a77c320a8 100644
--- a/sal/Package_inc.mk
+++ b/sal/Package_inc.mk
@@ -63,6 +63,7 @@ $(eval $(call gb_Package_add_file,sal_inc,inc/osl/thread.h,osl/thread.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/thread.hxx,osl/thread.hxx))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/time.h,osl/time.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/util.h,osl/util.h))
+$(eval $(call gb_Package_add_file,sal_inc,inc/osl/detail/file.h,osl/detail/file.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/allocator.hxx,rtl/allocator.hxx))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/alloc.h,rtl/alloc.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/bootstrap.h,rtl/bootstrap.h))
diff --git a/sal/inc/osl/detail/file.h b/sal/inc/osl/detail/file.h
new file mode 100644
index 000000000000..19415a2623fa
--- /dev/null
+++ b/sal/inc/osl/detail/file.h
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2012 Tor Lillqvist <tml@iki.fi> (initial developer)
+ * Copyright (C) 2012 SUSE Linux http://suse.com (initial developer's employer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef INCLUDED_OSL_DETAIL_FILE_H
+#define INCLUDED_OSL_DETAIL_FILE_H
+
+#include <sys/stat.h>
+#include "sal/types.h"
+
+/** @cond INTERNAL */
+
+/* Some additions to the osl file functions for LibreOffice internal
+ use. Needed for details in the Android support.
+ */
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+/* More flags needed for semantics that match the open() call that
+ used to be in SvFileStream::Open().
+*/
+#define osl_File_OpenFlag_Trunc 0x00000010L
+#define osl_File_OpenFlag_NoExcl 0x00000020L
+
+/* Variant of osl_openFile that takes the file pathname directly as a
+ char*
+*/
+
+SAL_DLLPUBLIC oslFileError SAL_CALL osl_openFilePath(
+ const char *cpFilePath,
+ oslFileHandle *pHandle,
+ sal_uInt32 uFlags );
+
+/* Wrappers for stat() and lstat() with Android-specific hook
+ for files inside the .apk.
+*/
+
+SAL_DLLPUBLIC oslFileError SAL_CALL osl_statFilePath(
+ const char *cpFilePath,
+ struct stat *statb );
+
+SAL_DLLPUBLIC oslFileError SAL_CALL osl_lstatFilePath(
+ const char *cpFilePath,
+ struct stat *statb );
+
+/* Get the OS specific "handle" of an open file. */
+
+SAL_DLLPUBLIC oslFileError SAL_CALL osl_getFileOSHandle(
+ oslFileHandle Handle,
+ sal_IntPtr *piFileHandle );
+
+#if defined __cplusplus
+}
+#endif
+
+/** @endcond */
+
+#endif /* INCLUDED_OSL_DETAIL_FILE_H */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 4bb30cfb6eab..64ce977d960e 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -28,6 +28,7 @@
#include "osl/file.hxx"
+#include "osl/detail/file.h"
#include "osl/diagnose.h"
#include "rtl/alloc.h"
@@ -885,40 +886,27 @@ SAL_CALL osl_openMemoryAsFile( void *address, size_t size, oslFileHandle *pHandl
***************************************************************************/
#ifdef HAVE_O_EXLOCK
#define OPEN_WRITE_FLAGS ( O_RDWR | O_EXLOCK | O_NONBLOCK )
-#define OPEN_CREATE_FLAGS ( O_CREAT | O_EXCL | O_RDWR | O_EXLOCK | O_NONBLOCK )
+#define OPEN_CREATE_FLAGS ( O_CREAT | O_RDWR | O_EXLOCK | O_NONBLOCK )
#else
#define OPEN_WRITE_FLAGS ( O_RDWR )
-#define OPEN_CREATE_FLAGS ( O_CREAT | O_EXCL | O_RDWR )
+#define OPEN_CREATE_FLAGS ( O_CREAT | O_RDWR )
#endif
oslFileError
-SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags )
+SAL_CALL osl_openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags )
{
oslFileError eRet;
- if ((ustrFileURL == 0) || (ustrFileURL->length == 0) || (pHandle == 0))
- return osl_File_E_INVAL;
-
- /* convert file URL to system path */
- char buffer[PATH_MAX];
- eRet = FileURLToPath (buffer, sizeof(buffer), ustrFileURL);
- if (eRet != osl_File_E_None)
- return eRet;
-#ifdef MACOSX
- if (macxp_resolveAlias (buffer, sizeof(buffer)) != 0)
- return oslTranslateFileError (OSL_FET_ERROR, errno);
-#endif /* MACOSX */
-
#ifdef ANDROID
/* Opening a file from /assets read-only means
* we should mmap it from the .apk file
*/
if (!(uFlags & osl_File_OpenFlag_Write) &&
- strncmp (buffer, "/assets/", sizeof ("/assets/") - 1) == 0)
+ strncmp (cpFilePath, "/assets/", sizeof ("/assets/") - 1) == 0)
{
void *address;
size_t size;
- address = lo_apkentry(buffer, &size);
+ address = lo_apkentry(cpFilePath, &size);
return osl_openMemoryAsFile(address, size, pHandle);
}
#endif
@@ -936,6 +924,13 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn
mode |= S_IWUSR | S_IWGRP | S_IWOTH;
flags = OPEN_CREATE_FLAGS;
}
+
+ /* Check for flags passed in from SvFileStream::Open() */
+ if (uFlags & osl_File_OpenFlag_Trunc)
+ flags |= O_TRUNC;
+ if (!(uFlags & osl_File_OpenFlag_NoExcl))
+ flags |= O_EXCL;
+
if (uFlags & osl_File_OpenFlag_NoLock)
{
#ifdef HAVE_O_EXLOCK
@@ -944,11 +939,11 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn
}
else
{
- flags = osl_file_adjustLockFlags (buffer, flags);
+ flags = osl_file_adjustLockFlags (cpFilePath, flags);
}
/* open the file */
- int fd = open( buffer, flags, mode );
+ int fd = open( cpFilePath, flags, mode );
if (-1 == fd)
return oslTranslateFileError (OSL_FET_ERROR, errno);
@@ -1018,7 +1013,7 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn
}
/* allocate memory for impl structure */
- FileHandle_Impl * pImpl = new FileHandle_Impl (fd, FileHandle_Impl::KIND_FD, buffer);
+ FileHandle_Impl * pImpl = new FileHandle_Impl (fd, FileHandle_Impl::KIND_FD, cpFilePath);
if (!pImpl)
{
eRet = oslTranslateFileError (OSL_FET_ERROR, ENOMEM);
@@ -1037,6 +1032,28 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn
return osl_File_E_None;
}
+oslFileError
+SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags )
+{
+ oslFileError eRet;
+
+ if ((ustrFileURL == 0) || (ustrFileURL->length == 0) || (pHandle == 0))
+ return osl_File_E_INVAL;
+
+ /* convert file URL to system path */
+ char buffer[PATH_MAX];
+ eRet = FileURLToPath (buffer, sizeof(buffer), ustrFileURL);
+ if (eRet != osl_File_E_None)
+ return eRet;
+
+#ifdef MACOSX
+ if (macxp_resolveAlias (buffer, sizeof(buffer)) != 0)
+ return oslTranslateFileError (OSL_FET_ERROR, errno);
+#endif /* MACOSX */
+
+ return osl_openFilePath (buffer, pHandle, uFlags);
+}
+
/****************************************************************************/
/* osl_closeFile */
/****************************************************************************/
@@ -1104,6 +1121,24 @@ SAL_CALL osl_syncFile(oslFileHandle Handle)
return osl_File_E_None;
}
+/************************************************
+ * osl_fileGetOSHandle
+ ***********************************************/
+oslFileError
+SAL_CALL osl_getFileOSHandle(
+ oslFileHandle Handle,
+ sal_IntPtr *piFileHandle )
+{
+ FileHandle_Impl* pImpl = static_cast<FileHandle_Impl*>(Handle);
+
+ if (0 == pImpl || pImpl->m_kind != FileHandle_Impl::KIND_FD || -1 == pImpl->m_fd)
+ return osl_File_E_INVAL;
+
+ *piFileHandle = pImpl->m_fd;
+
+ return osl_File_E_None;
+}
+
/*******************************************
osl_mapFile
********************************************/
diff --git a/sal/osl/unx/file_stat.cxx b/sal/osl/unx/file_stat.cxx
index ffeb885c37a3..9cbb39af0edc 100644
--- a/sal/osl/unx/file_stat.cxx
+++ b/sal/osl/unx/file_stat.cxx
@@ -28,6 +28,7 @@
#include "osl/file.h"
+#include "osl/detail/file.h"
#include "system.h"
#include <sys/types.h>
@@ -447,4 +448,26 @@ oslFileError SAL_CALL osl_setFileTime (
return osl_psz_setFileTime( path, pCreationTime, pLastAccessTime, pLastWriteTime );
}
+oslFileError
+SAL_CALL osl_statFilePath( const char *cpFilePath, struct stat *statb )
+{
+ int rc = stat_c( cpFilePath, statb );
+
+ if (rc == -1)
+ return oslTranslateFileError(OSL_FET_ERROR, errno);
+ else
+ return osl_File_E_None;
+}
+
+oslFileError
+SAL_CALL osl_lstatFilePath( const char *cpFilePath, struct stat *statb )
+{
+ int rc = lstat_c( cpFilePath, statb );
+
+ if (rc == -1)
+ return oslTranslateFileError(OSL_FET_ERROR, errno);
+ else
+ return osl_File_E_None;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx
index 86e86e2bb32d..8abe57f3b2f7 100644
--- a/sal/osl/unx/uunxapi.cxx
+++ b/sal/osl/unx/uunxapi.cxx
@@ -145,18 +145,38 @@
}
//#########################
+ //stat_c
+ int stat_c(const char* cpPath, struct stat* buf)
+ {
+#ifdef ANDROID
+ if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 &&
+ (cpPath[sizeof("/assets")-1] == '\0' ||
+ cpPath[sizeof("/assets")-1] == '/'))
+ return lo_apk_lstat(cpPath, buf);
+#endif
+ return stat(cpPath, buf);
+ }
+
+ //#########################
+ //lstat_c
+ int lstat_c(const char* cpPath, struct stat* buf)
+ {
+#ifdef ANDROID
+ if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 &&
+ (cpPath[sizeof("/assets")-1] == '\0' ||
+ cpPath[sizeof("/assets")-1] == '/'))
+ return lo_apk_lstat(cpPath, buf);
+#endif
+ return lstat(cpPath, buf);
+ }
+
+ //#########################
//lstat_u
int lstat_u(const rtl_uString* pustrPath, struct stat* buf)
{
#ifndef MACOSX // not MACOSX
rtl::OString fn = OUStringToOString(pustrPath);
-#ifdef ANDROID
- if (strncmp(fn.getStr(), "/assets", sizeof("/assets")-1) == 0 &&
- (fn.getStr()[sizeof("/assets")-1] == '\0' ||
- fn.getStr()[sizeof("/assets")-1] == '/'))
- return lo_apk_lstat(fn.getStr(), buf);
-#endif
- return lstat(fn.getStr(), buf);
+ return lstat_c(fn.getStr(), buf);
#else
return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf);
#endif
diff --git a/sal/osl/unx/uunxapi.h b/sal/osl/unx/uunxapi.h
index 9ac7ddd7ebb5..3696ab49f327 100644
--- a/sal/osl/unx/uunxapi.h
+++ b/sal/osl/unx/uunxapi.h
@@ -72,6 +72,12 @@
const rtl_uString* pustrFileName,
rtl_uString** ppustrResolvedName);
+ /* @see stat */
+ int stat_c(const char *cpPath, struct stat* buf);
+
+ /* @see lstat */
+ int lstat_c(const char *cpPath, struct stat* buf);
+
/* @see lstat */
int lstat_u(const rtl_uString* pustrPath, struct stat* buf);
diff --git a/sal/osl/w32/file.cxx b/sal/osl/w32/file.cxx
index 5e73dbf62f3a..e581a11bd82d 100644
--- a/sal/osl/w32/file.cxx
+++ b/sal/osl/w32/file.cxx
@@ -767,6 +767,22 @@ SAL_CALL osl_syncFile(oslFileHandle Handle)
//#############################################
oslFileError
+SAL_CALL osl_getFileOSHandle(
+ oslFileHandle Handle,
+ sal_IntPtr *piFileHandle )
+{
+ FileHandle_Impl* pImpl = static_cast<FileHandle_Impl*>(Handle);
+
+ if (0 == pImpl || !IsValidHandle(pImpl->m_hFile))
+ return osl_File_E_INVAL;
+
+ *piFileHandle = (sal_IntPtr) pImpl->m_hFile;
+
+ return osl_File_E_None;
+}
+
+//#############################################
+oslFileError
SAL_CALL osl_closeFile(oslFileHandle Handle)
{
FileHandle_Impl * pImpl = static_cast<FileHandle_Impl*>(Handle);
diff --git a/sal/util/sal.map b/sal/util/sal.map
index a22661c4829b..879d252a9ee8 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -645,6 +645,14 @@ PRIVATE_textenc.1 { # LibreOffice 3.6
_ZN3sal6detail7textenc37handleBadInputUnicodeToTextConversion*;
};
+PRIVATE_file.1 { # LibreOffice 3.6
+ global:
+ osl_openFilePath;
+ osl_statFilePath;
+ osl_lstatFilePath;
+ osl_getFileOSHandle;
+};
+
# Unique libstdc++ symbols:
GLIBCXX_3.4 {
global: