Kaydet (Commit) a64db11b authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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.
üst 800806ba
......@@ -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))
......
/* -*- 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: */
......@@ -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
********************************************/
......
......@@ -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: */
......@@ -144,19 +144,39 @@
return bRet;
}
//#########################
//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
......
......@@ -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);
......
......@@ -765,6 +765,22 @@ SAL_CALL osl_syncFile(oslFileHandle Handle)
return osl_File_E_None;
}
//#############################################
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)
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment