From 63fb0c4c42c5272cb643b0fb7a8d1c2661a011c6 Mon Sep 17 00:00:00 2001 From: Oliver Bolte Date: Mon, 7 Sep 2009 14:41:16 +0000 Subject: CWS-TOOLING: integrate CWS dr72 2009-08-26 10:24:00 +0200 dr r275402 : #i92645# CODEPAGE is encrypted... 2009-08-24 14:37:36 +0200 dr r275316 : #i10000# enable exceptions for xlroot.cxx 2009-08-24 14:33:15 +0200 dr r275313 : #i10000# link openssl under solaris correctly 2009-08-21 17:41:16 +0200 dr r275267 : #i10000# unxlngi6 warning 2009-08-21 15:35:56 +0200 dr r275265 : #i10000# remove files again, already deleted in previous milestone... 2009-08-21 11:24:57 +0200 dr r275227 : #160401# port to DEV300 2009-08-21 09:53:45 +0200 dr r275221 : #i92645# full support for encrypted Word2007 files 2009-08-21 09:50:52 +0200 dr r275219 : #i92645# final changes for decryption 2009-08-20 19:48:40 +0200 dr r275195 : #i104370# missing parentheses, patch from cmc 2009-08-20 18:28:22 +0200 dr r275193 : #i92645# rework package decryption to repair 'Reload Document' functionality 2009-08-20 13:55:14 +0200 dr r275179 : #i92645# add new property names 2009-08-19 19:24:21 +0200 dr r275159 : #160401# open writeprotected files read-only, merged to DEV300 2009-08-18 14:41:47 +0200 dr r275109 : #i92645# add 'Aborted' property 2009-08-18 11:20:34 +0200 dr r275084 : #i92645# write back password to medium 2009-08-17 17:52:51 +0200 dr r275066 : #i92645# detect Word2007 docs with oox detection impl, this adds support of encryped Word2007; correct detection of templates and macro-enabled docs 2009-08-17 17:51:31 +0200 dr r275065 : #i92645# detect Word2007 docs with oox detection impl, this adds support of encryped Word2007; correct detection of templates and macro-enabled docs 2009-08-17 11:06:39 +0200 dr r275035 : #i92645# more password handling 2009-08-17 11:05:21 +0200 dr r275034 : #i92645# use new password input mechanism for BIFF filter and dumper in oox 2009-08-14 16:33:53 +0200 nn r274996 : #i104228# DelBroadcastAreasInRange: remove area from hash_set before deleting 2009-08-14 16:27:12 +0200 nn r274995 : #i104059# restore a change lost in the integration of fhawfixes1 2009-08-14 16:24:00 +0200 dr r274994 : #i92645# adapt BIFF import to latest changes 2009-08-14 16:21:30 +0200 dr r274993 : #i92645# adapt BIFF import to latest changes 2009-08-14 16:20:43 +0200 dr r274992 : #i92645# do not add default passwords to media descriptor 2009-08-13 19:20:45 +0200 dr r274965 : #i92645# add a helper to request a document password 2009-08-13 19:09:35 +0200 dr r274964 : #i92645# add a helper to request a document password 2009-08-13 19:09:03 +0200 dr r274963 : #i92645# add a helper to request a document password 2009-08-13 14:35:01 +0200 dr r274946 : #i92645# comment typo 2009-08-13 14:33:47 +0200 dr r274945 : #i92645# add a helper to request a document password 2009-08-13 14:04:47 +0200 dr r274941 : #i92645# add a helper to request a document password 2009-08-13 14:04:22 +0200 dr r274940 : #i92645# add a helper to request a document password 2009-08-13 11:16:27 +0200 dr r274927 : #i42303# show quick help if field name too long for button 2009-08-13 10:55:48 +0200 dr r274925 : #i31600# cut field name and add ellipsis, if too long for button 2009-08-12 18:47:26 +0200 dr r274914 : #i92645# ask user for a password 2009-08-12 18:02:39 +0200 dr r274909 : #i104183# move svtools/DocPasswordRequest to comphelper to be able to use it in oox 2009-08-12 16:59:11 +0200 dr r274906 : #i104183# move svtools/DocPasswordRequest to comphelper to be able to use it in oox 2009-08-12 16:41:18 +0200 dr r274905 : #i104183# move svtools/DocPasswordRequest to comphelper to be able to use it in oox 2009-08-12 16:40:33 +0200 dr r274904 : #i104183# move svtools/DocPasswordRequest to comphelper to be able to use it in oox 2009-08-12 16:40:08 +0200 dr r274903 : #i104183# move svtools/DocPasswordRequest to comphelper to be able to use it in oox 2009-08-12 16:39:30 +0200 dr r274902 : #i104183# move svtools/DocPasswordRequest to comphelper to be able to use it in oox 2009-08-12 16:15:28 +0200 dr r274899 : #i104183# move svtools/DocPasswordRequest to comphelper to be able to use it in oox 2009-08-11 19:51:12 +0200 dr r274877 : #i92645# open encrypted MSOOXML package protected with standard XL password 'VelvetSweatshop' --- offapi/com/sun/star/document/MediaDescriptor.idl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/offapi/com/sun/star/document/MediaDescriptor.idl b/offapi/com/sun/star/document/MediaDescriptor.idl index 7fb3698f90b7..49c9cf285b3a 100644 --- a/offapi/com/sun/star/document/MediaDescriptor.idl +++ b/offapi/com/sun/star/document/MediaDescriptor.idl @@ -83,6 +83,12 @@ module com { module sun { module star { module document { */ published service MediaDescriptor { + //------------------------------------------------------------------------- + /** May be set by filters or detection services if user has choosen to + abort loading/saving, e.g. while entering a password. + */ + [optional,property] boolean Aborted; + //------------------------------------------------------------------------- /** document is a template -- cgit From b12afe90956bca6b626e677c58893947a46b8c97 Mon Sep 17 00:00:00 2001 From: Oliver Bolte Date: Tue, 8 Sep 2009 07:19:21 +0000 Subject: CWS-TOOLING: integrate CWS jl132 2009-08-31 13:06:06 +0200 jl r275601 : #i104650# increase versions of assemblies 2009-08-31 13:01:07 +0200 jl r275598 : #i104650# increase versions of assemblies 2009-08-31 12:36:40 +0200 jl r275597 : #i104650# new test library for 3.1.1 versions 2009-08-31 10:30:39 +0200 jl r275586 : CWS-TOOLING: rebase CWS jl132 to trunk@275331 (milestone: DEV300:m56) --- cli_ure/version/version.txt | 24 ++++++++++++------------ unoil/climaker/version.txt | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cli_ure/version/version.txt b/cli_ure/version/version.txt index d6115b807f62..4676c40d4c95 100644 --- a/cli_ure/version/version.txt +++ b/cli_ure/version/version.txt @@ -29,23 +29,23 @@ # #************************************************************************* -CLI_URETYPES_NEW_VERSION=1.0.3.0 -CLI_URETYPES_OLD_VERSION=1.0.0.0-1.0.2.0 -CLI_URETYPES_POLICY_VERSION=3.0.0.0 +CLI_URETYPES_NEW_VERSION=1.0.4.0 +CLI_URETYPES_OLD_VERSION=1.0.0.0-1.0.3.0 +CLI_URETYPES_POLICY_VERSION=4.0.0.0 CLI_URETYPES_POLICY_ASSEMBLY=policy.1.0.cli_uretypes -CLI_BASETYPES_NEW_VERSION=1.0.14.0 -CLI_BASETYPES_OLD_VERSION=1.0.0.0-1.0.13.0 -CLI_BASETYPES_POLICY_VERSION=14.0.0.0 +CLI_BASETYPES_NEW_VERSION=1.0.15.0 +CLI_BASETYPES_OLD_VERSION=1.0.0.0-1.0.14.0 +CLI_BASETYPES_POLICY_VERSION=15.0.0.0 CLI_BASETYPES_POLICY_ASSEMBLY=policy.1.0.cli_basetypes -CLI_URE_NEW_VERSION=1.0.17.0 -CLI_URE_OLD_VERSION=1.0.0.0-1.0.16.0 -CLI_URE_POLICY_VERSION=17.0.0.0 +CLI_URE_NEW_VERSION=1.0.18.0 +CLI_URE_OLD_VERSION=1.0.0.0-1.0.17.0 +CLI_URE_POLICY_VERSION=18.0.0.0 CLI_URE_POLICY_ASSEMBLY=policy.1.0.cli_ure -CLI_CPPUHELPER_NEW_VERSION=1.0.17.0 -CLI_CPPUHELPER_OLD_VERSION=1.0.0.0-1.0.16.0 -CLI_CPPUHELPER_POLICY_VERSION=17.0.0.0 +CLI_CPPUHELPER_NEW_VERSION=1.0.18.0 +CLI_CPPUHELPER_OLD_VERSION=1.0.0.0-1.0.17.0 +CLI_CPPUHELPER_POLICY_VERSION=18.0.0.0 CLI_CPPUHELPER_POLICY_ASSEMBLY=policy.1.0.cli_cppuhelper diff --git a/unoil/climaker/version.txt b/unoil/climaker/version.txt index 867c3d411c64..4824a36ed3eb 100644 --- a/unoil/climaker/version.txt +++ b/unoil/climaker/version.txt @@ -29,8 +29,8 @@ # #************************************************************************* -CLI_OOOTYPES_NEW_VERSION=1.0.3.0 -CLI_OOOTYPES_OLD_VERSION=1.0.0.0-1.0.2.0 -CLI_OOOTYPES_POLICY_VERSION=3.0.0.0 +CLI_OOOTYPES_NEW_VERSION=1.0.4.0 +CLI_OOOTYPES_OLD_VERSION=1.0.0.0-1.0.3.0 +CLI_OOOTYPES_POLICY_VERSION=4.0.0.0 CLI_OOOTYPES_POLICY_ASSEMBLY=policy.1.0.cli_oootypes -- cgit From 78497fa4e72049611317dacf33cad591aca6a8db Mon Sep 17 00:00:00 2001 From: Oliver Bolte Date: Wed, 9 Sep 2009 09:19:53 +0000 Subject: CWS-TOOLING: integrate CWS impress174 2009-08-27 18:21:38 +0200 af r275502 : #i73289# Fixed detection of the cases when the layout menu is be disabled. 2009-08-24 17:45:50 +0200 sj r275326 : #i103360# only setting filltype if there is also a correct fill element 2009-08-24 16:11:06 +0200 cl r275322 : #i73871# only remove replaced objects from mark list if replaced by SdrEditView::ReplaceObjectAtView(). see issue for reason 2009-08-24 15:03:33 +0200 cl r275319 : fixed merge error 2009-08-20 12:45:29 +0200 sj r275174 : CWS-TOOLING: rebase CWS impress174 to trunk@275001 (milestone: DEV300:m55) 2009-08-19 15:54:47 +0200 sj r275153 : #158486# text of flipped shapes is not flipped in word 2009-08-17 17:30:16 +0200 sj r275063 : #158486# also correcting text bound for additional text rotation 2009-08-05 11:09:32 +0200 sj r274643 : #i102797# adapted customshape coloring (fixed fontwork) 2009-08-04 14:17:36 +0200 sj r274620 : #i99501# pdf export: fixed export of rotated graphics 2009-07-30 16:15:44 +0200 sj r274494 : #158653# binary ppt import: fixed table border lines 2009-07-27 18:28:02 +0200 sj r274376 : added shape text clipping for customshapes 2009-07-20 18:09:14 +0200 sj r274154 : #i101918# fixed gallery preview (now taking the correct mapmode) 2009-07-13 18:00:58 +0200 cl r273948 : #i103238# clear hard set attributes only if new style set is manually applied 2009-07-13 17:58:07 +0200 cl r273947 : #i73289# do not expand a toolpanel when it gets enabled 2009-07-08 12:39:49 +0200 sj r273827 : #i101566# applied patch from cmc to solve font width inconsistencies 2009-07-08 12:11:13 +0200 sj r273826 : #i87727# added PDFDialog service 2009-07-06 17:22:40 +0200 sj r273755 : #i103360# fixed a merge problem, no more looping when loading transparence gradients on background page 2009-07-03 14:42:07 +0200 sj r273701 : #102797# added patch from thb (Adapted customshape coloring) 2009-07-03 14:09:44 +0200 sj r273696 : #102797# removed warning 2009-07-03 14:01:47 +0200 sj r273695 : #102797# added patch from thb (Adapted customshape coloring) 2009-07-03 13:13:39 +0200 sj r273688 : #102797# added patch from thb (Adapted customshape coloring) 2009-07-03 11:25:30 +0200 sj r273684 : #i103278# fixed import of lines 2009-07-01 16:23:47 +0200 cl r273599 : #i96820# correctly call setChanged on model if table is modified 2009-07-01 14:43:09 +0200 cl r273588 : #i8770# Patch: fix missing type provider for pdf export dialog 2009-07-01 14:40:28 +0200 cl r273586 : #i73871# activate picture bar after converting shape to bitmap 2009-07-01 14:39:05 +0200 cl r273584 : #i73871# activate picture bar after converting shape to bitmap 2009-07-01 14:04:53 +0200 cl r273578 : #i73289# PATCH: Disable layout pane on the masterslide --- offapi/com/sun/star/document/PDFDialog.idl | 67 ++++++++++++++++++++++++++++++ offapi/com/sun/star/document/makefile.mk | 3 +- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 offapi/com/sun/star/document/PDFDialog.idl diff --git a/offapi/com/sun/star/document/PDFDialog.idl b/offapi/com/sun/star/document/PDFDialog.idl new file mode 100644 index 000000000000..91d2628e3eab --- /dev/null +++ b/offapi/com/sun/star/document/PDFDialog.idl @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile:$ + * $Revision:$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_document_PDFDialog_idl__ +#define __com_sun_star_document_PDFDialog_idl__ + +#ifndef __com_sun_star_ui_dialogs_FilterOptionsDialog_idl__ +#include +#endif + +//============================================================================= + +module com { module sun { module star { module document { + +//============================================================================= + +/** This service is for a PDFDialog + */ +service PDFDialog +{ + service com::sun::star::ui::dialogs::FilterOptionsDialog; + + //------------------------------------------------------------------------- + /** PDFDialog options can be set as sequence of + com.sun.star.beans.PropertyValue at the FilterData property of the + MediaDescriptor. The PropertyValues which are supported within the + sequence are described in the registry at Office.Common/Filter/PDF/Export + + The source of this registry can be found in following file: + "officecfg/registry/schema/org/openoffice/Office/Common.xcs" + */ + + //------------------------------------------------------------------------- +}; + +//============================================================================= + +}; }; }; }; + +#endif + diff --git a/offapi/com/sun/star/document/makefile.mk b/offapi/com/sun/star/document/makefile.mk index f196d99fe095..3bc2db2f9e46 100644 --- a/offapi/com/sun/star/document/makefile.mk +++ b/offapi/com/sun/star/document/makefile.mk @@ -71,6 +71,7 @@ IDLFILES=\ OfficeDocument.idl\ OleEmbeddedServerRegistration.idl\ OwnLockOnDocumentRequest.idl\ + PDFDialog.idl\ PrinterIndependentLayout.idl\ RedlineDisplayType.idl \ Settings.idl\ @@ -105,7 +106,7 @@ IDLFILES=\ XLinkTargetSupplier.idl\ XMimeTypeInfo.idl\ XOOXMLDocumentPropertiesImporter.idl\ - XRedlinesSupplier.idl \ + XRedlinesSupplier.idl \ XScriptInvocationContext.idl\ XStandaloneDocumentInfo.idl\ XStorageBasedDocument.idl\ -- cgit From b76cb86eaa0aec1d02c5ff29c5a43e1e7a675b27 Mon Sep 17 00:00:00 2001 From: Oliver Bolte Date: Wed, 9 Sep 2009 09:38:41 +0000 Subject: CWS-TOOLING: integrate CWS mhu20 2009-09-01 15:18:43 +0200 mhu r275662 : #i32526# Fixed missing includes, and a wrong cast 2009-08-28 13:30:05 +0200 mhu r275530 : #i32526# Fixed missing includes and remaining merge conflicts. 2009-08-28 13:28:45 +0200 mhu r275529 : #i32526# osl_readLine() now implemented in sal/osl//file.cxx 2009-08-26 19:47:53 +0200 mhu r275445 : CWS-TOOLING: rebase CWS mhu20 to trunk@275331 (milestone: DEV300:m56) 2009-08-25 15:47:00 +0200 mhu r275365 : #i32526# Also maintain phys. file offset. 2009-08-25 15:24:56 +0200 mhu r275364 : #i32526# Added buffered file I/O; refactored file.cxx into multiple files. 2009-08-24 10:38:15 +0200 mhu r275294 : #i32526# Correct OpenFlags for osl_openFile(). 2009-05-25 11:07:34 +0200 mhu r272225 : #i32526# Added support for non-seekable file handles (pipe et al.). 2009-05-25 11:01:50 +0200 mhu r272223 : #i32526# Add osl_readLine() test, cleanup obsolete tests. 2009-05-25 10:56:14 +0200 mhu r272221 : #i32526# Add missing include 2009-05-25 10:48:51 +0200 mhu r272220 : #i32526# Accept OpenJDK (IcedTea6) 1.6.0_0 version string 2009-05-15 19:18:20 +0200 mhu r271965 : #i32526# Initial osl/unx buffered file I/O implementation. 2009-05-15 17:41:57 +0200 mhu r271959 : CWS-TOOLING: rebase CWS mhu20 to trunk@271830 (milestone: DEV300:m48) 2009-03-26 17:28:53 +0100 mhu r270091 : CWS-TOOLING: rebase CWS mhu20 to trunk@270033 (milestone: DEV300:m45) --- jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx | 2 +- jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 18 +- sal/osl/all/makefile.mk | 6 +- sal/osl/all/readline.c | 311 -- sal/osl/unx/file.cxx | 4449 +++++----------------- sal/osl/unx/file_impl.hxx | 43 +- sal/osl/unx/file_misc.cxx | 1084 ++++++ sal/osl/unx/file_stat.cxx | 281 +- sal/osl/unx/file_url.cxx | 177 +- sal/osl/unx/file_url.h | 58 +- sal/osl/unx/file_volume.cxx | 1570 ++++++++ sal/osl/unx/makefile.mk | 12 +- sal/osl/w32/MAKEFILE.MK | 8 + sal/osl/w32/file.cxx | 4313 +++++---------------- sal/osl/w32/file_dirvol.cxx | 1774 +++++++++ sal/osl/w32/file_error.c | 154 + sal/osl/w32/file_error.h | 54 + sal/osl/w32/file_url.cxx | 1013 +++++ sal/osl/w32/file_url.h | 95 + sal/osl/w32/procimpl.cxx | 8 +- sal/osl/w32/tempfile.cxx | 279 ++ sal/workben/makefile.mk | 23 +- sal/workben/t_layer.c | 314 -- sal/workben/t_readline.c | 58 + sal/workben/t_tls.c | 257 -- sal/workben/t_zip.c | 183 - store/source/lockbyte.cxx | 2 +- store/workben/makefile.mk | 11 +- 28 files changed, 8418 insertions(+), 8139 deletions(-) delete mode 100644 sal/osl/all/readline.c create mode 100644 sal/osl/unx/file_misc.cxx create mode 100644 sal/osl/unx/file_volume.cxx create mode 100644 sal/osl/w32/file_dirvol.cxx create mode 100644 sal/osl/w32/file_error.c create mode 100644 sal/osl/w32/file_error.h create mode 100644 sal/osl/w32/file_url.cxx create mode 100644 sal/osl/w32/file_url.h create mode 100644 sal/osl/w32/tempfile.cxx delete mode 100644 sal/workben/t_layer.c create mode 100644 sal/workben/t_readline.c delete mode 100644 sal/workben/t_tls.c delete mode 100644 sal/workben/t_zip.c diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx index f3586af32bb5..56972ea0e66f 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx @@ -159,7 +159,7 @@ bool SunVersion::init(const char *szVersion) { //1.4.1_01-, 1.4.1_01a, the numerical part may only be 2 chars. int len = pCur - pLast; - if (len != 2) + if (len > 2) return false; //we've got the update: 01, 02 etc strncpy(buf, pLast, len); diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx index 055bdae919f3..57b7166d01f6 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx @@ -241,9 +241,9 @@ FileHandleReader::readLine(rtl::OString * pLine) { if (m_nIndex == m_nSize) { - sal_uInt64 nRead; + sal_uInt64 nRead = 0; switch (osl_readFile( - m_aGuard.getHandle(), m_aBuffer, BUFFER_SIZE, &nRead)) + m_aGuard.getHandle(), m_aBuffer, sizeof(m_aBuffer), &nRead)) { case osl_File_E_PIPE: //HACK! for windows nRead = 0; @@ -256,8 +256,8 @@ FileHandleReader::readLine(rtl::OString * pLine) m_nIndex = 0; m_nSize = static_cast< int >(nRead); break; - case osl_File_E_INTR: - continue; + case osl_File_E_INTR: + continue; default: return RESULT_ERROR; @@ -483,19 +483,21 @@ bool getJavaProps(const OUString & exePath, */ rtl::OUString decodeOutput(const rtl::OString& s) { - OUString sEncoded = OStringToOUString(s, RTL_TEXTENCODING_ASCII_US); OUStringBuffer buff(512); sal_Int32 nIndex = 0; do { - OUString aToken = sEncoded.getToken( 0, ' ', nIndex ); + OString aToken = s.getToken( 0, ' ', nIndex ); if (aToken.getLength()) { - sal_Unicode value = (sal_Unicode) aToken.toInt32(); + sal_Unicode value = (sal_Unicode)(aToken.toInt32()); buff.append(value); } } while (nIndex >= 0); - return buff.makeStringAndClear(); + + OUString sDecoded(buff.makeStringAndClear()); + JFW_TRACE2(sDecoded); + return sDecoded; } diff --git a/sal/osl/all/makefile.mk b/sal/osl/all/makefile.mk index 6bed1c53cfaa..bbb46b89d44e 100644 --- a/sal/osl/all/makefile.mk +++ b/sal/osl/all/makefile.mk @@ -57,18 +57,20 @@ CXXFLAGS+= $(LFS_CFLAGS) SLOFILES= \ $(SLO)$/utility.obj\ - $(SLO)$/readline.obj\ $(SLO)$/filepath.obj\ $(SLO)$/debugbase.obj\ $(SLO)$/loadmodulerelative.obj +# $(SLO)$/readline.obj\ + #.IF "$(UPDATER)"=="YES" OBJFILES= \ $(OBJ)$/utility.obj\ - $(OBJ)$/readline.obj\ $(OBJ)$/filepath.obj\ $(OBJ)$/debugbase.obj\ $(OBJ)$/loadmodulerelative.obj + +# $(OBJ)$/readline.obj\ #.ENDIF # --- Targets ------------------------------------------------------ diff --git a/sal/osl/all/readline.c b/sal/osl/all/readline.c deleted file mode 100644 index 9fc4bced83aa..000000000000 --- a/sal/osl/all/readline.c +++ /dev/null @@ -1,311 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: readline.c,v $ - * $Revision: 1.9 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include -#include -#include -#include - - -/* Test cases: - - 1. A file without line ends - 2. A file with lines longer than the initial buffer size - 3. An empty file - 4. -*/ - -/** Some defines -*/ -#define CR 0x0D -#define LF 0x0A - -#define INITIAL_BUFF_SIZE 80 -#define BUFFER_GROW_FACTOR 2 -#define READ_BLOCK_SIZE (INITIAL_BUFF_SIZE - 1) - -/** Helper data and function -*/ - -struct _Buffer -{ - sal_Char* m_pMem; - sal_uInt64 m_Capacity; /* elements possible in buffer */ - sal_uInt64 m_Size; /* elements actually in buffer */ - sal_uInt64 m_ActiveSectionStart; /* buffer was lastly filled from here to - (m_Size - 1) */ -}; - -typedef struct _Buffer Buffer; - - -/** Allocate the memory of the buffer - @Returns sal_True on succes -*/ -static sal_Bool AllocateBuffer(Buffer* pBuffer, sal_uInt64 Capacity) -{ - sal_Bool rc = sal_False; - - OSL_ASSERT(pBuffer); - - pBuffer->m_pMem = (sal_Char*)rtl_allocateZeroMemory((sal_uInt32)Capacity); - if (pBuffer->m_pMem) - { - pBuffer->m_Capacity = Capacity; - pBuffer->m_Size = 0; - pBuffer->m_ActiveSectionStart = 0; - rc = sal_True; - } - - return rc; -} - -/** Release the memory occupied by the buffer -*/ -static void FreeBuffer(Buffer* pBuffer) -{ - OSL_ASSERT(pBuffer); - - rtl_freeMemory(pBuffer->m_pMem); - pBuffer->m_pMem = 0; - pBuffer->m_Capacity = 0; - pBuffer->m_Size = 0; - pBuffer->m_ActiveSectionStart = 0; -} - -/** Grow the buffer by the specified factor (usually doubling - the buffer size) - In case of failure, growing the buffer, the original buffer - stays untouched - - @Returns sal_True on success -*/ -static sal_Bool GrowBuffer(Buffer* pBuffer, size_t factor) -{ - sal_Bool rc = sal_False; - void* p; - - OSL_ASSERT(pBuffer); - - p = rtl_reallocateMemory( - pBuffer->m_pMem, (sal_uInt32)(pBuffer->m_Capacity * factor)); - if (p) - { - pBuffer->m_pMem = (sal_Char*)p; - pBuffer->m_Capacity *= factor; - rc = sal_True; - } - - return rc; -} - -/** Read n bytes from file into buffer, - grow the buffer if necessary - - @Returns osl_File_E_None on success else - an error code -*/ -static oslFileError ReadFromFile(oslFileHandle hFile, Buffer* pBuffer, sal_uInt64 Requested, sal_uInt64* pRead) -{ - oslFileError rc; - - OSL_ASSERT(pBuffer); - OSL_ASSERT(hFile); - OSL_ASSERT(pRead); - - if (((pBuffer->m_Size + Requested) > pBuffer->m_Capacity) && - !GrowBuffer(pBuffer, BUFFER_GROW_FACTOR)) - return osl_File_E_NOMEM; - - pBuffer->m_ActiveSectionStart = pBuffer->m_Size; - - rc = osl_readFile( - hFile, - pBuffer->m_pMem + pBuffer->m_ActiveSectionStart, - Requested, - pRead); - - if (osl_File_E_None == rc) - pBuffer->m_Size += *pRead; - - return rc; -} - -/** Makes a sequence from the given buffer and release the memory - occupied by the buffer -*/ -static void MakeSequenceFreeBuffer(sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Length) -{ - OSL_ASSERT(ppSequence); - OSL_ASSERT(pBuffer); - OSL_ASSERT(Length <= pBuffer->m_Capacity); - - rtl_byte_sequence_constructFromArray(ppSequence, (sal_Int8*)pBuffer->m_pMem, (sal_Int32)Length); - FreeBuffer(pBuffer); -} - -/** Handle occurence of LF character: - construct a sequence from buffer - correct file pointer (maybe we have read more than necessary) - - @Returns osl_File_E_None on success else - an error code -*/ -static oslFileError HandleLFFreeBuffer(oslFileHandle hFile, sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Pos) -{ - sal_Int64 offset = 0; - oslFileError rc = osl_File_E_None; - - OSL_ASSERT(hFile); - OSL_ASSERT(pBuffer); - OSL_ASSERT(LF == pBuffer->m_pMem[Pos]); - - /* correct file pointer pos in case we have read to far */ - offset = pBuffer->m_Size - (Pos + 1); - rc = osl_setFilePos(hFile, osl_Pos_Current, -offset); - - if (osl_File_E_None == rc) - MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos); - else - FreeBuffer(pBuffer); - - return rc; -} - -/** Handle occurence of CR character - construct a sequence from buffer - correct file pointer (maybe we have read more than necessary) - - @Returns osl_File_E_None on success else - an error code -*/ -static oslFileError HandleCRFreeBuffer(oslFileHandle hFile, sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Pos) -{ - sal_Int64 offset = 0; - sal_uInt64 nread = 0; - oslFileError rc = osl_File_E_None; - - OSL_ASSERT(hFile); - OSL_ASSERT(pBuffer); - OSL_ASSERT(CR == pBuffer->m_pMem[Pos]); - - if (Pos == (pBuffer->m_Size - 1)) - { - /* only need to check if the next byte is a LF - that's why reading only one byte from file */ - rc = ReadFromFile(hFile, pBuffer, 1, &nread); - - if (osl_File_E_None != rc) - { - FreeBuffer(pBuffer); - return rc; - } - else if (0 == nread) - { - MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos); - return osl_File_E_None; - } - } - - if (LF == pBuffer->m_pMem[Pos + 1]) - Pos++; - - /* correct the file pointer */ - offset = pBuffer->m_Size - (Pos + 1); - rc = osl_setFilePos(hFile, osl_Pos_Current, -offset); - - if (osl_File_E_None == rc) - MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos - 1); - else - FreeBuffer(pBuffer); - - return rc; -} - -/*************************************************************************** - osl_readLine (platform independent) - Reads a line from given file. The new line delimiter(s) are NOT returned! - Valid line ends: \n, \r\n or \r - - @param Handle [in] Handle to an open file. - @param ppSequence [in/out] a pointer to a valid sequence. - - @return osl_File_E_None on success otherwise one of the following errorcodes:

- - osl_File_E_INVAL the format of the parameters was not valid
- osl_File_E_NOMEM the necessary memory could not be allocated -****************************************************************************/ - -oslFileError SAL_CALL osl_readLine(oslFileHandle Handle, sal_Sequence** ppSeq) -{ - oslFileError rc; - sal_uInt64 nread = 0; - Buffer line_buffer; - sal_uInt64 pos; - - OSL_PRECOND(Handle, "invalid handle"); - OSL_PRECOND(ppSeq, "invalid parameter detected"); - - if (!AllocateBuffer(&line_buffer, INITIAL_BUFF_SIZE)) - return osl_File_E_NOMEM; - - for(;;) - { - rc = ReadFromFile(Handle, &line_buffer, READ_BLOCK_SIZE, &nread); - - if (osl_File_E_None != rc) - { - FreeBuffer(&line_buffer); - return rc; - } - else if (0 == nread) - { - /* EOF */ - nread = line_buffer.m_Size; - MakeSequenceFreeBuffer(ppSeq, &line_buffer, nread); - if (0 < nread) - return osl_File_E_None; - else - return osl_File_E_AGAIN; - } - - /* scan buffer for line end */ - for (pos = line_buffer.m_ActiveSectionStart; pos < line_buffer.m_Size; pos++) - { - switch(line_buffer.m_pMem[pos]) - { - case LF: - return HandleLFFreeBuffer(Handle, ppSeq, &line_buffer, pos); - case CR: - return HandleCRFreeBuffer(Handle, ppSeq, &line_buffer, pos); - } - } - } /* end for */ -} diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index bd5b54a6d8c3..c8ebf5ad11c5 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -31,612 +31,730 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sal.hxx" - -/************************************************************************ - * ToDo - * - * Fix osl_getCanonicalName - * - * - Fix: check for corresponding struct sizes in exported functions - * - check size/use of oslDirectory - * - check size/use of oslDirectoryItem - * - check size/use of oslFileStatus - * - check size/use of oslVolumeDeviceHandle - * - check size/use of oslVolumeInfo - * - check size/use of oslFileHandle - ***********************************************************************/ - -#include -#include -#include "system.h" -#include - #include "osl/file.hxx" +#include "osl/diagnose.h" +#include "rtl/alloc.h" -#include -#include -#include +#include "system.h" #include "file_error_transl.h" -#include - -#ifndef _FILE_URL_H_ #include "file_url.h" -#endif - -#include "file_path_helper.hxx" -#include "uunxapi.hxx" +#include +#include -#include - -#ifdef HAVE_STATFS_H -#undef HAVE_STATFS_H -#endif - -#ifndef _STRING_H #include -#endif - -#if defined(SOLARIS) -#include -#include -#define HAVE_STATFS_H -#include -static const sal_Char* MOUNTTAB="/etc/mnttab"; - -#elif defined(LINUX) -#include -#include -#define HAVE_STATFS_H -#include -#include -static const sal_Char* MOUNTTAB="/etc/mtab"; - -#elif defined(NETBSD) || defined(FREEBSD) -#include -#include -#include -#include -#include -#define HAVE_STATFS_H -/* No mounting table on *BSD - * This information is stored only in the kernel. */ -/* static const sal_Char* MOUNTTAB="/etc/mtab"; */ - -#elif defined(IRIX) -#include -#include -#include -#define HAVE_STATFS_H -#include -#include -static const sal_Char* MOUNTTAB="/etc/mtab"; +#include -#elif defined(MACOSX) -#include -#include -// static const sal_Char* MOUNTTAB="/etc/mtab"; +#if defined(MACOSX) #include #include -#define HAVE_STATFS_H #define HAVE_O_EXLOCK // add MACOSX Time Value - #define TimeValue CFTimeValue #include #undef TimeValue -#endif - -#ifdef _DIRENT_HAVE_D_TYPE -#include "file_impl.hxx" - oslDirectoryItemImpl* oslDirectoryItemImpl_CreateNew( rtl_uString* _ustrFilePath, bool _bHasDType, unsigned char _DType ) - { - oslDirectoryItemImpl *pItemObject = (oslDirectoryItemImpl*) malloc( sizeof( oslDirectoryItemImpl ) ); - pItemObject->RefCount = 1; - pItemObject->bHasType = _bHasDType; - pItemObject->DType = _DType; - pItemObject->ustrFilePath = _ustrFilePath; - - return pItemObject; - } - - void oslDirectoryItemImpl_Destroy( oslDirectoryItemImpl* pItem ) - { - if( pItem->ustrFilePath ) { - rtl_uString_release( pItem->ustrFilePath ); - pItem->ustrFilePath = NULL; - } - free( pItem ); - } - - void oslDirectoryItemImpl_acquire( oslDirectoryItemImpl* pItem ) - { - pItem->RefCount ++; - } - - void oslDirectoryItemImpl_release( oslDirectoryItemImpl* pItem ) - { - pItem->RefCount --; - - if( pItem->RefCount <= 0 ) - oslDirectoryItemImpl_Destroy( pItem ); - } -#endif - -#if OSL_DEBUG_LEVEL > 1 - - extern void debug_ustring(rtl_uString*); - -#endif - +#endif /* MACOSX */ #ifdef DEBUG_OSL_FILE +# define OSL_FILE_TRACE 0 ? (void)(0) : osl_trace # define PERROR( a, b ) perror( a ); fprintf( stderr, b ) #else +# define OSL_FILE_TRACE 1 ? (void)(0) : osl_trace # define PERROR( a, b ) #endif -extern "C" oslFileHandle osl_createFileHandleFromFD( int fd ); - -/****************************************************************************** +/******************************************************************* * - * Data Type Definition + * FileHandle_Impl interface * - ******************************************************************************/ - -#if 0 -/* FIXME: reintroducing this may save some extra bytes per Item */ -typedef struct -{ - rtl_uString* ustrFileName; /* holds native file name */ - rtl_uString* ustrDirPath; /* holds native dir path */ - sal_uInt32 RefCount; -} oslDirectoryItemImpl; -#endif - -typedef struct -{ - rtl_uString* ustrPath; /* holds native directory path */ - DIR* pDirStruct; -} oslDirectoryImpl; - - -typedef struct + ******************************************************************/ +struct FileHandle_Impl { - rtl_uString* ustrFilePath; /* holds native file path */ - int fd; - sal_Bool bLocked; -} oslFileHandleImpl; - + rtl_String * m_strFilePath; /* holds native file path */ + int m_fd; -typedef struct _oslVolumeDeviceHandleImpl -{ - sal_Char pszMountPoint[PATH_MAX]; - sal_Char pszFilePath[PATH_MAX]; - sal_Char pszDevice[PATH_MAX]; - sal_Char ident[4]; - sal_uInt32 RefCount; -} oslVolumeDeviceHandleImpl; + /** State + */ + enum StateBits + { + STATE_SEEKABLE = 1, /* default */ + STATE_READABLE = 2, /* default */ + STATE_WRITEABLE = 4, /* open() sets, write() requires, else osl_File_E_BADF */ + STATE_MODIFIED = 8 /* write() sets, flush() resets */ + }; + int m_state; + sal_uInt64 m_size; /* file size */ + off_t m_offset; /* physical offset from begin of file */ + off_t m_fileptr; /* logical offset from begin of file */ -/****************************************************************************** - * - * static members - * - *****************************************************************************/ + off_t m_bufptr; /* buffer offset from begin of file */ + size_t m_buflen; /* buffer filled [0, m_bufsiz - 1] */ -static const char * pFileLockEnvVar = (char *) -1; + size_t m_bufsiz; + sal_uInt8 * m_buffer; + explicit FileHandle_Impl (int fd, char const * path = ""); + ~FileHandle_Impl(); -/****************************************************************************** - * - * C-String Function Declarations - * - *****************************************************************************/ + static void* operator new (size_t n); + static void operator delete (void * p, size_t); -static oslFileError osl_psz_getVolumeInformation(const sal_Char* , oslVolumeInfo* pInfo, sal_uInt32 uFieldMask); -static oslFileError osl_psz_removeFile(const sal_Char* pszPath); -static oslFileError osl_psz_createDirectory(const sal_Char* pszPath); -static oslFileError osl_psz_removeDirectory(const sal_Char* pszPath); -static oslFileError osl_psz_copyFile(const sal_Char* pszPath, const sal_Char* pszDestPath); -static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* pszDestPath); -static oslFileError osl_psz_setFileAttributes(const sal_Char* pszFilePath, sal_uInt64 uAttributes); -static oslFileError osl_psz_setFileTime(const sal_Char* strFilePath, const TimeValue* pCreationTime, const TimeValue* pLastAccessTime, const TimeValue* pLastWriteTime); + static size_t getpagesize(); + sal_uInt64 getPos() const; + oslFileError setPos (sal_uInt64 uPos); -/****************************************************************************** - * - * Static Module Utility Function Declarations - * - *****************************************************************************/ + sal_uInt64 getSize() const; -static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, mode_t nMode, size_t nSourceSize, int DestFileExists); -static oslFileError oslChangeFileModes(const sal_Char* pszFileName, mode_t nMode, time_t nAcTime, time_t nModTime, uid_t nUID, gid_t nGID); -static int oslDoCopyLink(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName); -static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, size_t nSourceSize, mode_t mode); -static oslFileError oslDoMoveFile(const sal_Char* pszPath, const sal_Char* pszDestPath); -static rtl_uString* oslMakeUStrFromPsz(const sal_Char* pszStr,rtl_uString** uStr); + oslFileError readAt ( + off_t nOffset, + void * pBuffer, + size_t nBytesRequested, + sal_uInt64 * pBytesRead); -/****************************************************************************** - * - * Non-Static Utility Function Declarations - * - *****************************************************************************/ + oslFileError writeAt ( + off_t nOffset, + void const * pBuffer, + size_t nBytesToWrite, + sal_uInt64 * pBytesWritten); -extern "C" int UnicodeToText( char *, size_t, const sal_Unicode *, sal_Int32 ); -extern "C" int TextToUnicode( - const char* text, size_t text_buffer_size, sal_Unicode* unic_text, sal_Int32 unic_text_buffer_size); + oslFileError readFileAt ( + off_t nOffset, + void * pBuffer, + size_t nBytesRequested, + sal_uInt64 * pBytesRead); -/****************************************************************************** - * - * 'removeable device' aka floppy functions - * - *****************************************************************************/ + oslFileError writeFileAt ( + off_t nOffset, + void const * pBuffer, + size_t nBytesToWrite, + sal_uInt64 * pBytesWritten); -static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath); -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy); -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy); + oslFileError readLineAt ( + off_t nOffset, + sal_Sequence ** ppSequence, + sal_uInt64 * pBytesRead); + oslFileError writeSequence_Impl ( + sal_Sequence ** ppSequence, + size_t * pnOffset, + const void * pBuffer, + size_t nBytes); -#if defined(SOLARIS) -static sal_Bool osl_isFloppyMounted(sal_Char* pszPath, sal_Char* pszMountPath); -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, sal_Char* pBuffer); -static sal_Bool osl_checkFloppyPath(sal_Char* pszPath, sal_Char* pszFilePath, sal_Char* pszDevicePath); -#endif + oslFileError syncFile(); -#if defined(LINUX) -static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice); -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem); -#endif + /** Buffer cache / allocator. + */ + class Allocator + { + rtl_cache_type * m_cache; + size_t m_bufsiz; + Allocator (Allocator const &); + Allocator & operator= (Allocator const &); -#if defined(IRIX) -static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice); -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem); -#endif + public: + static Allocator & get(); -#ifdef DEBUG_OSL_FILE -static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* hFloppy); -#endif + void allocate (sal_uInt8 ** ppBuffer, size_t * pnSize); + void deallocate (sal_uInt8 * pBuffer); -#ifdef MACOSX + protected: + Allocator(); + ~Allocator(); + }; +}; /******************************************************************* - * adjustLockFlags + * + * FileHandle_Impl implementation + * ******************************************************************/ -/* The AFP implementation of MacOS X 10.4 treats O_EXLOCK in a way - * that makes it impossible for OOo to create a backup copy of the - * file it keeps opened. OTOH O_SHLOCK for AFP behaves as desired by - * the OOo file handling, so we need to check the path of the file - * for the filesystem name. - */ - -static int adjustLockFlags(const char * path, int flags) +FileHandle_Impl::Allocator & +FileHandle_Impl::Allocator::get() { - struct statfs s; + static Allocator g_aBufferAllocator; + return g_aBufferAllocator; +} - if( 0 <= statfs( path, &s ) ) +FileHandle_Impl::Allocator::Allocator() + : m_cache (0), + m_bufsiz (0) +{ + size_t const pagesize = FileHandle_Impl::getpagesize(); + if (size_t(-1) != pagesize) { - if( 0 == strncmp("afpfs", s.f_fstypename, 5) ) - { - flags &= ~O_EXLOCK; - flags |= O_SHLOCK; - } - else - { - /* Needed flags to allow opening a webdav file */ - flags &= ~( O_EXLOCK | O_SHLOCK ); - } + m_cache = rtl_cache_create ( + "osl_file_buffer_cache", pagesize, 0, 0, 0, 0, 0, 0, 0); + if (0 != m_cache) + m_bufsiz = pagesize; } - - return flags; +} +FileHandle_Impl::Allocator::~Allocator() +{ + rtl_cache_destroy (m_cache), m_cache = 0; } -#endif +void FileHandle_Impl::Allocator::allocate (sal_uInt8 ** ppBuffer, size_t * pnSize) +{ + OSL_PRECOND((0 != ppBuffer) && (0 != pnSize), "FileHandle_Impl::Allocator::allocate(): contract violation"); + *ppBuffer = static_cast< sal_uInt8* >(rtl_cache_alloc(m_cache)), *pnSize = m_bufsiz; +} +void FileHandle_Impl::Allocator::deallocate (sal_uInt8 * pBuffer) +{ + if (0 != pBuffer) + rtl_cache_free (m_cache, pBuffer); +} +FileHandle_Impl::FileHandle_Impl (int fd, char const * path) + : m_strFilePath (0), + m_fd (fd), + m_state (STATE_SEEKABLE | STATE_READABLE), + m_size (0), + m_offset (0), + m_fileptr (0), + m_bufptr (-1), + m_buflen (0), + m_bufsiz (0), + m_buffer (0) +{ + rtl_string_newFromStr (&m_strFilePath, path); + Allocator::get().allocate (&m_buffer, &m_bufsiz); + if (0 != m_buffer) + memset (m_buffer, 0, m_bufsiz); +} +FileHandle_Impl::~FileHandle_Impl() +{ + Allocator::get().deallocate (m_buffer), m_buffer = 0; + rtl_string_release (m_strFilePath), m_strFilePath = 0; +} -/******************************************************************* - * osl_openDirectory - ******************************************************************/ +void* FileHandle_Impl::operator new (size_t n) +{ + return rtl_allocateMemory(n); +} +void FileHandle_Impl::operator delete (void * p, size_t) +{ + rtl_freeMemory(p); +} -oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirectory* pDirectory) +size_t FileHandle_Impl::getpagesize() { - rtl_uString* ustrSystemPath = NULL; - oslFileError eRet; +#if defined(FREEBSD) || defined(NETBSD) || defined(MACOSX) + return sal::static_int_cast< size_t >(::getpagesize()); +#else /* POSIX */ + return sal::static_int_cast< size_t >(::sysconf(_SC_PAGESIZE)); +#endif /* xBSD || POSIX */ +} - char path[PATH_MAX]; +sal_uInt64 FileHandle_Impl::getPos() const +{ + return sal::static_int_cast< sal_uInt64 >(m_fileptr); +} - OSL_ASSERT(ustrDirectoryURL && (ustrDirectoryURL->length > 0)); - OSL_ASSERT(pDirectory); +oslFileError FileHandle_Impl::setPos (sal_uInt64 uPos) +{ + OSL_FILE_TRACE("FileHandle_Impl::setPos(%d, %lld) => %lld", m_fd, getPos(), uPos); + m_fileptr = sal::static_int_cast< off_t >(uPos); + return osl_File_E_None; +} - if (0 == ustrDirectoryURL->length ) - return osl_File_E_INVAL; +sal_uInt64 FileHandle_Impl::getSize() const +{ + off_t const bufend = std::max((off_t)(0), m_bufptr) + m_buflen; + return std::max(m_size, sal::static_int_cast< sal_uInt64 >(bufend)); +} - /* convert file URL to system path */ - eRet = osl_getSystemPathFromFileURL_Ex(ustrDirectoryURL, &ustrSystemPath, sal_False); +oslFileError FileHandle_Impl::readAt ( + off_t nOffset, + void * pBuffer, + size_t nBytesRequested, + sal_uInt64 * pBytesRead) +{ + OSL_PRECOND((m_state & STATE_SEEKABLE), "FileHandle_Impl::readAt(): not seekable"); + if (!(m_state & STATE_SEEKABLE)) + return osl_File_E_SPIPE; - if( osl_File_E_None != eRet ) - return eRet; + OSL_PRECOND((m_state & STATE_READABLE), "FileHandle_Impl::readAt(): not readable"); + if (!(m_state & STATE_READABLE)) + return osl_File_E_BADF; - osl_systemPathRemoveSeparator(ustrSystemPath); +#if defined(LINUX) || defined(SOLARIS) - /* convert unicode path to text */ - if ( UnicodeToText( path, PATH_MAX, ustrSystemPath->buffer, ustrSystemPath->length ) -#ifdef MACOSX - && macxp_resolveAlias( path, PATH_MAX ) == 0 -#endif /* MACOSX */ - ) + ssize_t nBytes = ::pread (m_fd, pBuffer, nBytesRequested, nOffset); + if ((-1 == nBytes) && (EOVERFLOW == errno)) { - /* open directory */ - DIR *pdir = opendir( path ); - - if( pdir ) - { - /* create and initialize impl structure */ - oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) rtl_allocateMemory( sizeof(oslDirectoryImpl) ); + /* Some 'pread()'s fail with EOVERFLOW when reading at (or past) + * end-of-file, different from 'lseek() + read()' behaviour. + * Returning '0 bytes read' and 'osl_File_E_None' instead. + */ + nBytes = 0; + } + if (-1 == nBytes) + return oslTranslateFileError (OSL_FET_ERROR, errno); - if( pDirImpl ) - { - pDirImpl->pDirStruct = pdir; - pDirImpl->ustrPath = ustrSystemPath; +#else /* !(LINUX || SOLARIS) */ - *pDirectory = (oslDirectory) pDirImpl; - return osl_File_E_None; - } - else - { - errno = ENOMEM; - closedir( pdir ); - } - } - else - { - /* should be removed by optimizer in product version */ - PERROR( "osl_openDirectory", path ); - } + if (nOffset != m_offset) + { + if (-1 == ::lseek (m_fd, nOffset, SEEK_SET)) + return oslTranslateFileError (OSL_FET_ERROR, errno); + m_offset = nOffset; } - rtl_uString_release( ustrSystemPath ); + ssize_t nBytes = ::read (m_fd, pBuffer, nBytesRequested); + if (-1 == nBytes) + return oslTranslateFileError (OSL_FET_ERROR, errno); + m_offset += nBytes; - return oslTranslateFileError(OSL_FET_ERROR, errno); -} +#endif /* !(LINUX || SOLARIS) */ -/****************************************************************************/ -/* osl_closeDirectory */ -/****************************************************************************/ + OSL_FILE_TRACE("FileHandle_Impl::readAt(%d, %lld, %ld)", m_fd, nOffset, nBytes); + *pBytesRead = nBytes; + return osl_File_E_None; +} -oslFileError SAL_CALL osl_closeDirectory( oslDirectory Directory ) +oslFileError FileHandle_Impl::writeAt ( + off_t nOffset, + void const * pBuffer, + size_t nBytesToWrite, + sal_uInt64 * pBytesWritten) { - oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) Directory; - oslFileError err = osl_File_E_None; + OSL_PRECOND((m_state & STATE_SEEKABLE), "FileHandle_Impl::writeAt(): not seekable"); + if (!(m_state & STATE_SEEKABLE)) + return osl_File_E_SPIPE; - OSL_ASSERT( Directory ); + OSL_PRECOND((m_state & STATE_WRITEABLE), "FileHandle_Impl::writeAt(): not writeable"); + if (!(m_state & STATE_WRITEABLE)) + return osl_File_E_BADF; - if( NULL == pDirImpl ) - return osl_File_E_INVAL; +#if defined(LINUX) || defined(SOLARIS) + + ssize_t nBytes = ::pwrite (m_fd, pBuffer, nBytesToWrite, nOffset); + if (-1 == nBytes) + return oslTranslateFileError (OSL_FET_ERROR, errno); + +#else /* !(LINUX || SOLARIS) */ - /* close directory */ - if( closedir( pDirImpl->pDirStruct ) ) + if (nOffset != m_offset) { - err = oslTranslateFileError(OSL_FET_ERROR, errno); + if (-1 == ::lseek (m_fd, nOffset, SEEK_SET)) + return oslTranslateFileError (OSL_FET_ERROR, errno); + m_offset = nOffset; } - /* cleanup members */ - rtl_uString_release( pDirImpl->ustrPath ); + ssize_t nBytes = ::write (m_fd, pBuffer, nBytesToWrite); + if (-1 == nBytes) + return oslTranslateFileError (OSL_FET_ERROR, errno); + m_offset += nBytes; - rtl_freeMemory( pDirImpl ); +#endif /* !(LINUX || SOLARIS) */ - return err; -} + OSL_FILE_TRACE("FileHandle_Impl::writeAt(%d, %lld, %ld)", m_fd, nOffset, nBytes); + m_size = std::max (m_size, sal::static_int_cast< sal_uInt64 >(nOffset + nBytes)); -/********************************************** - * osl_readdir_impl_ - * - * readdir wrapper, filters out "." and ".." - * on request - *********************************************/ + *pBytesWritten = nBytes; + return osl_File_E_None; +} -static struct dirent* osl_readdir_impl_(DIR* pdir, sal_Bool bFilterLocalAndParentDir) +oslFileError FileHandle_Impl::readFileAt ( + off_t nOffset, + void * pBuffer, + size_t nBytesRequested, + sal_uInt64 * pBytesRead) { - struct dirent* pdirent; - - while ((pdirent = readdir(pdir)) != NULL) + if (0 == (m_state & STATE_SEEKABLE)) { - if (bFilterLocalAndParentDir && - ((0 == strcmp(pdirent->d_name, ".")) || (0 == strcmp(pdirent->d_name, "..")))) - continue; - else - break; + // not seekable (pipe) + ssize_t nBytes = ::read (m_fd, pBuffer, nBytesRequested); + if (-1 == nBytes) + return oslTranslateFileError (OSL_FET_ERROR, errno); + *pBytesRead = nBytes; + return osl_File_E_None; } + else if (0 == m_buffer) + { + // not buffered + return readAt (nOffset, pBuffer, nBytesRequested, pBytesRead); + } + else + { + sal_uInt8 * buffer = static_cast(pBuffer); + for (*pBytesRead = 0; nBytesRequested > 0; ) + { + off_t const bufptr = (nOffset / m_bufsiz) * m_bufsiz; + size_t const bufpos = (nOffset % m_bufsiz); - return pdirent; -} + if (bufptr != m_bufptr) + { + // flush current buffer + oslFileError result = syncFile(); + if (result != osl_File_E_None) + return (result); -/**************************************************************************** - * osl_getNextDirectoryItem - ***************************************************************************/ + if (nBytesRequested >= m_bufsiz) + { + // buffer too small, read through from file + sal_uInt64 uDone = 0; + result = readAt (nOffset, &(buffer[*pBytesRead]), nBytesRequested, &uDone); + if (result != osl_File_E_None) + return (result); -oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory Directory, oslDirectoryItem* pItem, sal_uInt32 /*uHint*/) -{ - oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*)Directory; - rtl_uString* ustrFileName = NULL; - rtl_uString* ustrFilePath = NULL; - struct dirent* pEntry; + nBytesRequested -= uDone, *pBytesRead += uDone; + return osl_File_E_None; + } - OSL_ASSERT(Directory); - OSL_ASSERT(pItem); + // update buffer (pointer) + sal_uInt64 uDone = 0; + result = readAt (bufptr, m_buffer, m_bufsiz, &uDone); + if (result != osl_File_E_None) + return (result); + m_bufptr = bufptr, m_buflen = uDone; + } + if (bufpos >= m_buflen) + { + // end of file + return osl_File_E_None; + } - if ((NULL == Directory) || (NULL == pItem)) - return osl_File_E_INVAL; + size_t const bytes = std::min (m_buflen - bufpos, nBytesRequested); + OSL_FILE_TRACE("FileHandle_Impl::readFileAt(%d, %lld, %ld)", m_fd, nOffset, bytes); - pEntry = osl_readdir_impl_(pDirImpl->pDirStruct, sal_True); + memcpy (&(buffer[*pBytesRead]), &(m_buffer[bufpos]), bytes); + nBytesRequested -= bytes, *pBytesRead += bytes, nOffset += bytes; + } + return osl_File_E_None; + } +} - if (NULL == pEntry) - return osl_File_E_NOENT; +oslFileError FileHandle_Impl::writeFileAt ( + off_t nOffset, + void const * pBuffer, + size_t nBytesToWrite, + sal_uInt64 * pBytesWritten) +{ + if (0 == (m_state & STATE_SEEKABLE)) + { + // not seekable (pipe) + ssize_t nBytes = ::write (m_fd, pBuffer, nBytesToWrite); + if (-1 == nBytes) + return oslTranslateFileError (OSL_FET_ERROR, errno); + *pBytesWritten = nBytes; + return osl_File_E_None; + } + else if (0 == m_buffer) + { + // not buffered + return writeAt (nOffset, pBuffer, nBytesToWrite, pBytesWritten); + } + else + { + sal_uInt8 const * buffer = static_cast(pBuffer); + for (*pBytesWritten = 0; nBytesToWrite > 0; ) + { + off_t const bufptr = (nOffset / m_bufsiz) * m_bufsiz; + size_t const bufpos = (nOffset % m_bufsiz); + if (bufptr != m_bufptr) + { + // flush current buffer + oslFileError result = syncFile(); + if (result != osl_File_E_None) + return (result); + if (nBytesToWrite >= m_bufsiz) + { + // buffer to small, write through to file + sal_uInt64 uDone = 0; + result = writeAt (nOffset, &(buffer[*pBytesWritten]), nBytesToWrite, &uDone); + if (result != osl_File_E_None) + return (result); + if (uDone != nBytesToWrite) + return osl_File_E_IO; + + nBytesToWrite -= uDone, *pBytesWritten += uDone; + return osl_File_E_None; + } -#if defined(MACOSX) + // update buffer (pointer) + sal_uInt64 uDone = 0; + result = readAt (bufptr, m_buffer, m_bufsiz, &uDone); + if (result != osl_File_E_None) + return (result); + m_bufptr = bufptr, m_buflen = uDone; + } - // convert decomposed filename to precomposed unicode - char composed_name[BUFSIZ]; - CFMutableStringRef strRef = CFStringCreateMutable (NULL, 0 ); - CFStringAppendCString( strRef, pEntry->d_name, kCFStringEncodingUTF8 ); //UTF8 is default on Mac OSX - CFStringNormalize( strRef, kCFStringNormalizationFormC ); - CFStringGetCString( strRef, composed_name, BUFSIZ, kCFStringEncodingUTF8 ); - CFRelease( strRef ); - rtl_string2UString( &ustrFileName, composed_name, strlen( composed_name), - osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); - -#else // not MACOSX - /* convert file name to unicode */ - rtl_string2UString( &ustrFileName, pEntry->d_name, strlen( pEntry->d_name ), - osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); - OSL_ASSERT(ustrFileName != 0); + size_t const bytes = std::min (m_bufsiz - bufpos, nBytesToWrite); + OSL_FILE_TRACE("FileHandle_Impl::writeFileAt(%d, %lld, %ld)", m_fd, nOffset, bytes); -#endif + memcpy (&(m_buffer[bufpos]), &(buffer[*pBytesWritten]), bytes); + nBytesToWrite -= bytes, *pBytesWritten += bytes, nOffset += bytes; - osl_systemPathMakeAbsolutePath(pDirImpl->ustrPath, ustrFileName, &ustrFilePath); - rtl_uString_release( ustrFileName ); + m_buflen = std::max(m_buflen, bufpos + bytes); + m_state |= STATE_MODIFIED; + } + return osl_File_E_None; + } +} -#ifdef _DIRENT_HAVE_D_TYPE - if(*pItem) - oslDirectoryItemImpl_release( ( oslDirectoryItemImpl* )( *pItem ) ); +oslFileError FileHandle_Impl::readLineAt ( + off_t nOffset, + sal_Sequence ** ppSequence, + sal_uInt64 * pBytesRead) +{ + oslFileError result = osl_File_E_None; - *pItem = (oslDirectoryItem) oslDirectoryItemImpl_CreateNew( ustrFilePath, true, pEntry->d_type ); -#else - /* use path as directory item */ - *pItem = (oslDirectoryItem) ustrFilePath; -#endif + off_t bufptr = nOffset / m_bufsiz * m_bufsiz; + if (bufptr != m_bufptr) + { + /* flush current buffer */ + result = syncFile(); + if (result != osl_File_E_None) + return (result); - return osl_File_E_None; -} + /* update buffer (pointer) */ + sal_uInt64 uDone = 0; + result = readAt (bufptr, m_buffer, m_bufsiz, &uDone); + if (result != osl_File_E_None) + return (result); -/****************************************************************************/ -/* osl_getDirectoryItem */ -/****************************************************************************/ + m_bufptr = bufptr, m_buflen = uDone; + } -oslFileError SAL_CALL osl_getDirectoryItem( rtl_uString* ustrFileURL, oslDirectoryItem* pItem ) -{ - rtl_uString* ustrSystemPath = NULL; - oslFileError osl_error = osl_File_E_INVAL; + static int const LINE_STATE_BEGIN = 0; + static int const LINE_STATE_CR = 1; + static int const LINE_STATE_LF = 2; - OSL_ASSERT(ustrFileURL); - OSL_ASSERT(pItem); + size_t bufpos = nOffset - m_bufptr, curpos = bufpos, dstpos = 0; + int state = (bufpos >= m_buflen) ? LINE_STATE_LF : LINE_STATE_BEGIN; - if (0 == ustrFileURL->length || NULL == pItem) - return osl_File_E_INVAL; + for ( ; state != LINE_STATE_LF; ) + { + if (curpos >= m_buflen) + { + /* buffer examined */ + if (0 < (curpos - bufpos)) + { + /* flush buffer to sequence */ + result = writeSequence_Impl ( + ppSequence, &dstpos, &(m_buffer[bufpos]), curpos - bufpos); + if (result != osl_File_E_None) + return (result); + *pBytesRead += curpos - bufpos, nOffset += curpos - bufpos; + } - osl_error = osl_getSystemPathFromFileURL_Ex(ustrFileURL, &ustrSystemPath, sal_False); + bufptr = nOffset / m_bufsiz * m_bufsiz; + if (bufptr != m_bufptr) + { + /* update buffer (pointer) */ + sal_uInt64 uDone = 0; + result = readAt (bufptr, m_buffer, m_bufsiz, &uDone); + if (result != osl_File_E_None) + return (result); + m_bufptr = bufptr, m_buflen = uDone; + } - if (osl_File_E_None != osl_error) - return osl_error; + bufpos = nOffset - m_bufptr, curpos = bufpos; + if (bufpos >= m_buflen) + break; + } + switch (state) + { + case LINE_STATE_CR: + state = LINE_STATE_LF; + switch (m_buffer[curpos]) + { + case 0x0A: /* CRLF */ + /* eat current char */ + curpos++; + break; + default: /* single CR */ + /* keep current char */ + break; + } + break; + default: + /* determine next state */ + switch (m_buffer[curpos]) + { + case 0x0A: /* single LF */ + state = LINE_STATE_LF; + break; + case 0x0D: /* CR */ + state = LINE_STATE_CR; + break; + default: /* advance to next char */ + curpos++; + break; + } + if (state != LINE_STATE_BEGIN) + { + /* store (and eat) the newline char */ + m_buffer[curpos] = 0x0A, curpos++; + + /* flush buffer to sequence */ + result = writeSequence_Impl ( + ppSequence, &dstpos, &(m_buffer[bufpos]), curpos - bufpos - 1); + if (result != osl_File_E_None) + return (result); + *pBytesRead += curpos - bufpos, nOffset += curpos - bufpos; + } + break; + } + } - osl_systemPathRemoveSeparator(ustrSystemPath); + result = writeSequence_Impl (ppSequence, &dstpos, 0, 0); + if (result != osl_File_E_None) + return (result); + if (0 < dstpos) + return osl_File_E_None; + if (bufpos >= m_buflen) + return osl_File_E_AGAIN; + return osl_File_E_None; +} - if (0 == access_u(ustrSystemPath, F_OK)) +oslFileError FileHandle_Impl::writeSequence_Impl ( + sal_Sequence ** ppSequence, + size_t * pnOffset, + const void * pBuffer, + size_t nBytes) +{ + sal_Int32 nElements = *pnOffset + nBytes; + if (!*ppSequence) { -#ifdef _DIRENT_HAVE_D_TYPE - *pItem = (oslDirectoryItem) oslDirectoryItemImpl_CreateNew( ustrSystemPath, false ); -#else - *pItem = (oslDirectoryItem)ustrSystemPath; -#endif - osl_error = osl_File_E_None; + /* construct sequence */ + rtl_byte_sequence_constructNoDefault(ppSequence, nElements); } - else + else if (nElements != (*ppSequence)->nElements) + { + /* resize sequence */ + rtl_byte_sequence_realloc(ppSequence, nElements); + } + if (*ppSequence != 0) { - osl_error = oslTranslateFileError(OSL_FET_ERROR, errno); - rtl_uString_release(ustrSystemPath); + /* fill sequence */ + memcpy(&((*ppSequence)->elements[*pnOffset]), pBuffer, nBytes), *pnOffset += nBytes; } - return osl_error; + return (*ppSequence != 0) ? osl_File_E_None : osl_File_E_NOMEM; } +oslFileError FileHandle_Impl::syncFile() +{ + oslFileError result = osl_File_E_None; + if (m_state & STATE_MODIFIED) + { + sal_uInt64 uDone = 0; + result = writeAt (m_bufptr, m_buffer, m_buflen, &uDone); + if (result != osl_File_E_None) + return (result); + if (uDone != m_buflen) + return osl_File_E_IO; + m_state &= ~STATE_MODIFIED; + } + return (result); +} -/****************************************************************************/ -/* osl_acquireDirectoryItem */ -/****************************************************************************/ - -oslFileError osl_acquireDirectoryItem( oslDirectoryItem Item ) +/**************************************************************************** + * osl_createFileHandleFromFD + ***************************************************************************/ +extern "C" oslFileHandle osl_createFileHandleFromFD( int fd ) { -#ifdef _DIRENT_HAVE_D_TYPE - oslDirectoryItemImpl* pImpl = (oslDirectoryItemImpl*) Item; -#else - rtl_uString* ustrFilePath = (rtl_uString *) Item; -#endif + if (-1 == fd) + return 0; // EINVAL - OSL_ASSERT( Item ); + struct stat aFileStat; + if (-1 == fstat (fd, &aFileStat)) + return 0; // EBADF -#ifdef _DIRENT_HAVE_D_TYPE - if( pImpl ) - oslDirectoryItemImpl_acquire( pImpl ); -#else - if( ustrFilePath ) - rtl_uString_acquire( ustrFilePath ); -#endif + FileHandle_Impl * pImpl = new FileHandle_Impl (fd); + if (0 == pImpl) + return 0; // ENOMEM - return osl_File_E_None; -} + // assume writeable + pImpl->m_state |= FileHandle_Impl::STATE_WRITEABLE; + if (!S_ISREG(aFileStat.st_mode)) + { + /* not a regular file, mark not seekable */ + pImpl->m_state &= ~FileHandle_Impl::STATE_SEEKABLE; + } + else + { + /* regular file, init current size */ + pImpl->m_size = sal::static_int_cast< sal_uInt64 >(aFileStat.st_size); + } -/****************************************************************************/ -/* osl_releaseDirectoryItem */ -/****************************************************************************/ + OSL_FILE_TRACE("osl_createFileHandleFromFD(%d, writeable) => %s", + pImpl->m_fd, rtl_string_getStr(pImpl->m_strFilePath)); + return (oslFileHandle)(pImpl); +} -oslFileError osl_releaseDirectoryItem( oslDirectoryItem Item ) +/******************************************************************* + * osl_file_adjustLockFlags + ******************************************************************/ +static int osl_file_adjustLockFlags (const char * path, int flags) { -#ifdef _DIRENT_HAVE_D_TYPE - oslDirectoryItemImpl* pImpl = (oslDirectoryItemImpl*) Item; -#else - rtl_uString* ustrFilePath = (rtl_uString *) Item; -#endif - - OSL_ASSERT( Item ); - -#ifdef _DIRENT_HAVE_D_TYPE - if( pImpl ) - oslDirectoryItemImpl_release( pImpl ); -#else - if( ustrFilePath ) - rtl_uString_release( ustrFilePath ); -#endif +#ifdef MACOSX + /* + * The AFP implementation of MacOS X 10.4 treats O_EXLOCK in a way + * that makes it impossible for OOo to create a backup copy of the + * file it keeps opened. OTOH O_SHLOCK for AFP behaves as desired by + * the OOo file handling, so we need to check the path of the file + * for the filesystem name. + */ + struct statfs s; + if( 0 <= statfs( path, &s ) ) + { + if( 0 == strncmp("afpfs", s.f_fstypename, 5) ) + { + flags &= ~O_EXLOCK; + flags |= O_SHLOCK; + } + else + { + /* Needed flags to allow opening a webdav file */ + flags &= ~(O_EXLOCK | O_SHLOCK | O_NONBLOCK); + } + } +#endif /* MACOSX */ - return osl_File_E_None; + (void) path; + return flags; } /**************************************************************************** - * osl_createFileHandleFromFD + * osl_file_queryLocking ***************************************************************************/ - -oslFileHandle osl_createFileHandleFromFD( int fd ) +struct Locking_Impl { - oslFileHandleImpl* pHandleImpl = NULL; - - if ( fd >= 0 ) + int m_enabled; + Locking_Impl() : m_enabled(0) { - pHandleImpl = (oslFileHandleImpl*) rtl_allocateMemory( sizeof(oslFileHandleImpl) ); - - if( pHandleImpl ) +#ifndef HAVE_O_EXLOCK + m_enabled = ((getenv("SAL_ENABLE_FILE_LOCKING") != 0) || (getenv("STAR_ENABLE_FILE_LOCKING") != 0)); +#endif /* HAVE_O_EXLOCK */ + } +}; +static int osl_file_queryLocking (sal_uInt32 uFlags) +{ + if (!(uFlags & osl_File_OpenFlag_NoLock)) + { + if ((uFlags & osl_File_OpenFlag_Write) || (uFlags & osl_File_OpenFlag_Create)) { - pHandleImpl->ustrFilePath = NULL; - rtl_uString_new( &pHandleImpl->ustrFilePath ); - pHandleImpl->fd = fd; - - /* FIXME: it should be detected whether the file has been locked */ - pHandleImpl->bLocked = sal_True; + static Locking_Impl g_locking; + return (g_locking.m_enabled != 0); } } - - return (oslFileHandle)pHandleImpl; + return 0; } - /**************************************************************************** * osl_openFile ***************************************************************************/ - #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 ) @@ -645,3104 +763,581 @@ oslFileHandle osl_createFileHandleFromFD( int fd ) #define OPEN_CREATE_FLAGS ( O_CREAT | O_EXCL | O_RDWR ) #endif -oslFileError osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags ) +oslFileError +SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags ) { - oslFileHandleImpl* pHandleImpl = NULL; oslFileError eRet; - rtl_uString* ustrFilePath = NULL; - - char buffer[PATH_MAX]; - int fd; - int mode = S_IRUSR | S_IRGRP | S_IROTH; - int flags = O_RDONLY; - - struct flock aflock; - /* locking the complete file */ - aflock.l_type = 0; - aflock.l_whence = SEEK_SET; - aflock.l_start = 0; - aflock.l_len = 0; - - OSL_ASSERT( ustrFileURL ); - OSL_ASSERT( pHandle ); - - if( ( 0 == ustrFileURL->length ) ) + if ((ustrFileURL == 0) || (ustrFileURL->length == 0) || (pHandle == 0)) return osl_File_E_INVAL; /* convert file URL to system path */ - eRet = osl_getSystemPathFromFileURL( ustrFileURL, &ustrFilePath ); - - if( osl_File_E_None != eRet ) + char buffer[PATH_MAX]; + eRet = FileURLToPath (buffer, sizeof(buffer), ustrFileURL); + if (eRet != osl_File_E_None) return eRet; - - osl_systemPathRemoveSeparator(ustrFilePath); - - /* convert unicode path to text */ - if( UnicodeToText( buffer, PATH_MAX, ustrFilePath->buffer, ustrFilePath->length ) #ifdef MACOSX - && macxp_resolveAlias( buffer, PATH_MAX ) == 0 + if (macxp_resolveAlias (buffer, sizeof(buffer)) != 0) + return oslTranslateFileError (OSL_FET_ERROR, errno); #endif /* MACOSX */ - ) + + /* set mode and flags */ + int mode = S_IRUSR | S_IRGRP | S_IROTH; + int flags = O_RDONLY; + if (uFlags & osl_File_OpenFlag_Write) { - /* we do not open devices or such here */ - if( !( uFlags & osl_File_OpenFlag_Create ) ) - { - struct stat aFileStat; + mode |= S_IWUSR | S_IWGRP | S_IWOTH; + flags = OPEN_WRITE_FLAGS; + } + if (uFlags & osl_File_OpenFlag_Create) + { + mode |= S_IWUSR | S_IWGRP | S_IWOTH; + flags = OPEN_CREATE_FLAGS; + } + if (uFlags & osl_File_OpenFlag_NoLock) + { +#ifdef HAVE_O_EXLOCK + flags &= ~(O_EXLOCK | O_SHLOCK | O_NONBLOCK); +#endif /* HAVE_O_EXLOCK */ + } + else + { + flags = osl_file_adjustLockFlags (buffer, flags); + } - if( 0 > stat( buffer, &aFileStat ) ) - { - PERROR( "osl_openFile", buffer ); - eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); - } + /* open the file */ + int fd = open( buffer, flags, mode ); + if (-1 == fd) + return oslTranslateFileError (OSL_FET_ERROR, errno); - else if( !S_ISREG( aFileStat.st_mode ) ) - { - eRet = osl_File_E_INVAL; - } + /* reset O_NONBLOCK flag */ + if (flags & O_NONBLOCK) + { + int f = fcntl (fd, F_GETFL, 0); + if (-1 == f) + { + eRet = oslTranslateFileError (OSL_FET_ERROR, errno); + (void) close(fd); + return eRet; } - - if( osl_File_E_None == eRet ) + if (-1 == fcntl (fd, F_SETFL, (f & ~O_NONBLOCK))) { - /* - * set flags and mode - */ + eRet = oslTranslateFileError (OSL_FET_ERROR, errno); + (void) close(fd); + return eRet; + } + } - if ( uFlags & osl_File_OpenFlag_Write ) - { - mode |= S_IWUSR | S_IWGRP | S_IWOTH; - flags = OPEN_WRITE_FLAGS; -#ifdef MACOSX - flags = adjustLockFlags(buffer, flags); -#endif - aflock.l_type = F_WRLCK; - } + /* get file status (mode, size) */ + struct stat aFileStat; + if (-1 == fstat (fd, &aFileStat)) + { + eRet = oslTranslateFileError (OSL_FET_ERROR, errno); + (void) close(fd); + return eRet; + } + if (!S_ISREG(aFileStat.st_mode)) + { + /* we only open regular files here */ + (void) close(fd); + return osl_File_E_INVAL; + } - if ( uFlags & osl_File_OpenFlag_Create ) - { - mode |= S_IWUSR | S_IWGRP | S_IWOTH; - flags = OPEN_CREATE_FLAGS; + if (osl_file_queryLocking (uFlags)) + { #ifdef MACOSX - flags = adjustLockFlags(buffer, flags); -#endif - } - - sal_Bool bNeedsLock = ( ( uFlags & osl_File_OpenFlag_NoLock ) == 0 ); - if ( !bNeedsLock ) + if (-1 == flock (fd, LOCK_EX | LOCK_NB)) + { + /* Mac OSX returns ENOTSUP for webdav drives. We should try read lock */ + if ((errno != ENOTSUP) || ((-1 == flock (fd, LOCK_SH | LOCK_NB)) && (errno != ENOTSUP))) { -#ifdef MACOSX - flags &= ~O_EXLOCK; - flags &= ~O_SHLOCK; -#endif + eRet = oslTranslateFileError (OSL_FET_ERROR, errno); + (void) close(fd); + return eRet; } + } +#else /* F_SETLK */ + { + struct flock aflock; - /* open the file */ - fd = open( buffer, flags, mode ); - if ( fd >= 0 ) - { - sal_Bool bLocked = sal_False; - if( bNeedsLock ) - { -#ifndef HAVE_O_EXLOCK - /* check if file lock is enabled and clear l_type member of flock otherwise */ - if( (char *) -1 == pFileLockEnvVar ) - { - /* FIXME: this is not MT safe */ - pFileLockEnvVar = getenv("SAL_ENABLE_FILE_LOCKING"); - - if( NULL == pFileLockEnvVar) - pFileLockEnvVar = getenv("STAR_ENABLE_FILE_LOCKING"); - } -#else - /* disable range based locking */ - pFileLockEnvVar = NULL; - - /* remove the NONBLOCK flag again */ - flags = fcntl(fd, F_GETFL, NULL); - flags &= ~O_NONBLOCK; - if( 0 > fcntl(fd, F_SETFL, flags) ) - { - close(fd); - return oslTranslateFileError(OSL_FET_ERROR, errno); - } -#endif - if( NULL == pFileLockEnvVar ) - aflock.l_type = 0; - - /* lock the file if flock.l_type is set */ -#ifdef MACOSX - bLocked = ( F_WRLCK != aflock.l_type ); - if (!bLocked) - { - /* Mac OSX returns ENOTSUP for webdav drives. We should try read lock */ - if ( 0 == flock( fd, LOCK_EX | LOCK_NB ) || errno == ENOTSUP ) - bLocked = ( errno != ENOTSUP ) || ( 0 == flock( fd, LOCK_SH | LOCK_NB ) || errno == ENOTSUP ); - } -#else /* MACOSX */ - bLocked = ( F_WRLCK != aflock.l_type || -1 != fcntl( fd, F_SETLK, &aflock ) ); -#endif /* MACOSX */ - - } - - if ( !bNeedsLock || bLocked ) - { - /* allocate memory for impl structure */ - pHandleImpl = (oslFileHandleImpl*) rtl_allocateMemory( sizeof(oslFileHandleImpl) ); - if( pHandleImpl ) - { - pHandleImpl->ustrFilePath = ustrFilePath; - pHandleImpl->fd = fd; - pHandleImpl->bLocked = bLocked; - - *pHandle = (oslFileHandle) pHandleImpl; - - return osl_File_E_None; - } - else - { - errno = ENOMEM; - } - } + aflock.l_type = F_WRLCK; + aflock.l_whence = SEEK_SET; + aflock.l_start = 0; + aflock.l_len = 0; - close( fd ); + if (-1 == fcntl (fd, F_SETLK, &aflock)) + { + eRet = oslTranslateFileError (OSL_FET_ERROR, errno); + (void) close(fd); + return eRet; } - - PERROR( "osl_openFile", buffer ); - eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); } +#endif /* F_SETLK */ } - else - eRet = osl_File_E_INVAL; - rtl_uString_release( ustrFilePath ); - return eRet; + /* allocate memory for impl structure */ + FileHandle_Impl * pImpl = new FileHandle_Impl (fd, buffer); + if (!pImpl) + { + eRet = oslTranslateFileError (OSL_FET_ERROR, ENOMEM); + (void) close(fd); + return eRet; + } + if (flags & O_RDWR) + pImpl->m_state |= FileHandle_Impl::STATE_WRITEABLE; + pImpl->m_size = sal::static_int_cast< sal_uInt64 >(aFileStat.st_size); + + OSL_TRACE("osl_openFile(%d, %s) => %s", pImpl->m_fd, + flags & O_RDWR ? "writeable":"readonly", + rtl_string_getStr(pImpl->m_strFilePath)); + + *pHandle = (oslFileHandle)(pImpl); + return osl_File_E_None; } /****************************************************************************/ /* osl_closeFile */ /****************************************************************************/ - -oslFileError osl_closeFile( oslFileHandle Handle ) +oslFileError +SAL_CALL osl_closeFile( oslFileHandle Handle ) { - oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl *) Handle; - oslFileError eRet = osl_File_E_INVAL; + FileHandle_Impl* pImpl = static_cast(Handle); - OSL_ASSERT( Handle ); + if ((pImpl == 0) || (pImpl->m_fd < 0)) + return osl_File_E_INVAL; - if( pHandleImpl ) + /* close(2) implicitly (and unconditionally) unlocks */ + OSL_TRACE("osl_closeFile(%d) => %s", pImpl->m_fd, rtl_string_getStr(pImpl->m_strFilePath)); + oslFileError result = pImpl->syncFile(); + if (result != osl_File_E_None) { - rtl_uString_release( pHandleImpl->ustrFilePath ); - - /* release file lock if locking is enabled */ - if( pFileLockEnvVar ) - { - struct flock aflock; + /* close, ignoring double failure */ + (void) close (pImpl->m_fd); + } + else if (-1 == close (pImpl->m_fd)) + { + /* translate error code */ + result = oslTranslateFileError (OSL_FET_ERROR, errno); + } - aflock.l_type = F_UNLCK; - aflock.l_whence = SEEK_SET; - aflock.l_start = 0; - aflock.l_len = 0; + delete pImpl; + return (result); +} - if ( pHandleImpl->bLocked ) - { - /* FIXME: check if file is really locked ? */ - - /* release the file share lock on this file */ -#ifdef MACOSX - /* Mac OSX will return ENOTSUP for webdav drives. We should ignore the error */ - if ( 0 != flock( pHandleImpl->fd, LOCK_UN | LOCK_NB ) && errno != ENOTSUP ) -#else /* MACOSX */ - if( -1 == fcntl( pHandleImpl->fd, F_SETLK, &aflock ) ) -#endif /* MACOSX */ - { - PERROR( "osl_closeFile", "unlock failed" ); - } - } - } +/************************************************ + * osl_syncFile + ***********************************************/ +oslFileError +SAL_CALL osl_syncFile(oslFileHandle Handle) +{ + FileHandle_Impl* pImpl = static_cast(Handle); - if( 0 > close( pHandleImpl->fd ) ) - { - eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); - } - else - eRet = osl_File_E_None; + if ((0 == pImpl) || (-1 == pImpl->m_fd)) + return osl_File_E_INVAL; - rtl_freeMemory( pHandleImpl ); - } + OSL_FILE_TRACE("osl_syncFile(%d)", pImpl->m_fd); + oslFileError result = pImpl->syncFile(); + if (result != osl_File_E_None) + return (result); + if (-1 == fsync (pImpl->m_fd)) + return oslTranslateFileError (OSL_FET_ERROR, errno); - return eRet; + return osl_File_E_None; } -/****************************************************************************/ -/* osl_isEndOfFile */ -/****************************************************************************/ - -oslFileError SAL_CALL osl_isEndOfFile( oslFileHandle Handle, sal_Bool *pIsEOF ) +/******************************************* + osl_mapFile +********************************************/ +oslFileError +SAL_CALL osl_mapFile ( + oslFileHandle Handle, + void** ppAddr, + sal_uInt64 uLength, + sal_uInt64 uOffset, + sal_uInt32 uFlags +) { - oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl *) Handle; - oslFileError eRet = osl_File_E_INVAL; + FileHandle_Impl* pImpl = static_cast(Handle); - if ( pHandleImpl) - { - long curPos = lseek( pHandleImpl->fd, 0, SEEK_CUR ); + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == ppAddr)) + return osl_File_E_INVAL; + *ppAddr = 0; + + static sal_uInt64 const g_limit_size_t = std::numeric_limits< size_t >::max(); + if (g_limit_size_t < uLength) + return osl_File_E_OVERFLOW; + size_t const nLength = sal::static_int_cast< size_t >(uLength); + + static sal_uInt64 const g_limit_off_t = std::numeric_limits< off_t >::max(); + if (g_limit_off_t < uOffset) + return osl_File_E_OVERFLOW; + off_t const nOffset = sal::static_int_cast< off_t >(uOffset); + + void* p = mmap(NULL, nLength, PROT_READ, MAP_SHARED, pImpl->m_fd, nOffset); + if (MAP_FAILED == p) + return oslTranslateFileError(OSL_FET_ERROR, errno); + *ppAddr = p; - if ( curPos >= 0 ) + if (uFlags & osl_File_MapFlag_RandomAccess) + { + // Determine memory pagesize. + size_t const nPageSize = FileHandle_Impl::getpagesize(); + if (size_t(-1) != nPageSize) { - long endPos = lseek( pHandleImpl->fd, 0, SEEK_END ); + /* + * Pagein, touching first byte of every memory page. + * Note: volatile disables optimizing the loop away. + */ + sal_uInt8 * pData (reinterpret_cast(*ppAddr)); + size_t nSize (nLength); - if ( endPos >= 0 ) + volatile sal_uInt8 c = 0; + while (nSize > nPageSize) { - *pIsEOF = ( curPos == endPos ); - curPos = lseek( pHandleImpl->fd, curPos, SEEK_SET ); - - if ( curPos >= 0 ) - eRet = osl_File_E_None; - else - eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); + c ^= pData[0]; + pData += nPageSize; + nSize -= nPageSize; + } + if (nSize > 0) + { + c^= pData[0]; + pData += nSize; + nSize -= nSize; } - else - eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); } - else - eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); } - - return eRet; + return osl_File_E_None; } - -/****************************************************************************/ -/* osl_moveFile */ -/****************************************************************************/ - -oslFileError osl_moveFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL ) +/******************************************* + osl_unmapFile +********************************************/ +oslFileError +SAL_CALL osl_unmapFile (void* pAddr, sal_uInt64 uLength) { - char srcPath[PATH_MAX]; - char destPath[PATH_MAX]; - oslFileError eRet; + if (0 == pAddr) + return osl_File_E_INVAL; + + static sal_uInt64 const g_limit_size_t = std::numeric_limits< size_t >::max(); + if (g_limit_size_t < uLength) + return osl_File_E_OVERFLOW; + size_t const nLength = sal::static_int_cast< size_t >(uLength); - OSL_ASSERT( ustrFileURL ); - OSL_ASSERT( ustrDestURL ); + if (-1 == munmap(static_cast(pAddr), nLength)) + return oslTranslateFileError(OSL_FET_ERROR, errno); - /* convert source url to system path */ - eRet = FileURLToPath( srcPath, PATH_MAX, ustrFileURL ); - if( eRet != osl_File_E_None ) - return eRet; + return osl_File_E_None; +} - /* convert destination url to system path */ - eRet = FileURLToPath( destPath, PATH_MAX, ustrDestURL ); - if( eRet != osl_File_E_None ) - return eRet; +/******************************************* + osl_readLine +********************************************/ +oslFileError +SAL_CALL osl_readLine ( + oslFileHandle Handle, + sal_Sequence ** ppSequence) +{ + FileHandle_Impl * pImpl = static_cast(Handle); -#ifdef MACOSX - if ( macxp_resolveAlias( srcPath, PATH_MAX ) != 0 || macxp_resolveAlias( destPath, PATH_MAX ) != 0 ) - return oslTranslateFileError( OSL_FET_ERROR, errno ); -#endif/* MACOSX */ + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == ppSequence)) + return osl_File_E_INVAL; + sal_uInt64 uBytesRead = 0; - return oslDoMoveFile( srcPath, destPath ); + // read at current fileptr; fileptr += uBytesRead; + oslFileError result = pImpl->readLineAt ( + pImpl->m_fileptr, ppSequence, &uBytesRead); + if (result == osl_File_E_None) + pImpl->m_fileptr += uBytesRead; + return (result); } -/****************************************************************************/ -/* osl_copyFile */ -/****************************************************************************/ - -oslFileError osl_copyFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL ) +/******************************************* + osl_readFile +********************************************/ +oslFileError +SAL_CALL osl_readFile ( + oslFileHandle Handle, + void * pBuffer, + sal_uInt64 uBytesRequested, + sal_uInt64 * pBytesRead) { - char srcPath[PATH_MAX]; - char destPath[PATH_MAX]; - oslFileError eRet; - - OSL_ASSERT( ustrFileURL ); - OSL_ASSERT( ustrDestURL ); - - /* convert source url to system path */ - eRet = FileURLToPath( srcPath, PATH_MAX, ustrFileURL ); - if( eRet != osl_File_E_None ) - return eRet; + FileHandle_Impl* pImpl = static_cast(Handle); - /* convert destination url to system path */ - eRet = FileURLToPath( destPath, PATH_MAX, ustrDestURL ); - if( eRet != osl_File_E_None ) - return eRet; + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pBuffer) || (0 == pBytesRead)) + return osl_File_E_INVAL; -#ifdef MACOSX - if ( macxp_resolveAlias( srcPath, PATH_MAX ) != 0 || macxp_resolveAlias( destPath, PATH_MAX ) != 0 ) - return oslTranslateFileError( OSL_FET_ERROR, errno ); -#endif/* MACOSX */ + static sal_uInt64 const g_limit_ssize_t = std::numeric_limits< ssize_t >::max(); + if (g_limit_ssize_t < uBytesRequested) + return osl_File_E_OVERFLOW; + size_t const nBytesRequested = sal::static_int_cast< size_t >(uBytesRequested); - return osl_psz_copyFile( srcPath, destPath ); + // read at current fileptr; fileptr += *pBytesRead; + oslFileError result = pImpl->readFileAt ( + pImpl->m_fileptr, pBuffer, nBytesRequested, pBytesRead); + if (result == osl_File_E_None) + pImpl->m_fileptr += *pBytesRead; + return (result); } -/****************************************************************************/ -/* osl_removeFile */ -/****************************************************************************/ - -oslFileError osl_removeFile( rtl_uString* ustrFileURL ) +/******************************************* + osl_writeFile +********************************************/ +oslFileError +SAL_CALL osl_writeFile ( + oslFileHandle Handle, + const void * pBuffer, + sal_uInt64 uBytesToWrite, + sal_uInt64 * pBytesWritten) { - char path[PATH_MAX]; - oslFileError eRet; + FileHandle_Impl* pImpl = static_cast(Handle); - OSL_ASSERT( ustrFileURL ); - - /* convert file url to system path */ - eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); - if( eRet != osl_File_E_None ) - return eRet; + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pBuffer) || (0 == pBytesWritten)) + return osl_File_E_INVAL; + if (0 == (pImpl->m_state & FileHandle_Impl::STATE_WRITEABLE)) + return osl_File_E_BADF; -#ifdef MACOSX - if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) - return oslTranslateFileError( OSL_FET_ERROR, errno ); -#endif/* MACOSX */ + static sal_uInt64 const g_limit_ssize_t = std::numeric_limits< ssize_t >::max(); + if (g_limit_ssize_t < uBytesToWrite) + return osl_File_E_OVERFLOW; + size_t const nBytesToWrite = sal::static_int_cast< size_t >(uBytesToWrite); - return osl_psz_removeFile( path ); + // write at current fileptr; fileptr += *pBytesWritten; + oslFileError result = pImpl->writeFileAt ( + pImpl->m_fileptr, pBuffer, nBytesToWrite, pBytesWritten); + if (result == osl_File_E_None) + pImpl->m_fileptr += *pBytesWritten; + return (result); } -/****************************************************************************/ -/* osl_getVolumeInformation */ -/****************************************************************************/ - -oslFileError osl_getVolumeInformation( rtl_uString* ustrDirectoryURL, oslVolumeInfo* pInfo, sal_uInt32 uFieldMask ) +/******************************************* + osl_readFileAt +********************************************/ +oslFileError +SAL_CALL osl_readFileAt ( + oslFileHandle Handle, + sal_uInt64 uOffset, + void* pBuffer, + sal_uInt64 uBytesRequested, + sal_uInt64* pBytesRead) { - char path[PATH_MAX]; - oslFileError eRet; + FileHandle_Impl* pImpl = static_cast(Handle); - OSL_ASSERT( ustrDirectoryURL ); - OSL_ASSERT( pInfo ); + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pBuffer) || (0 == pBytesRead)) + return osl_File_E_INVAL; + if (0 == (pImpl->m_state & FileHandle_Impl::STATE_SEEKABLE)) + return osl_File_E_SPIPE; - /* convert directory url to system path */ - eRet = FileURLToPath( path, PATH_MAX, ustrDirectoryURL ); - if( eRet != osl_File_E_None ) - return eRet; + static sal_uInt64 const g_limit_off_t = std::numeric_limits< off_t >::max(); + if (g_limit_off_t < uOffset) + return osl_File_E_OVERFLOW; + off_t const nOffset = sal::static_int_cast< off_t >(uOffset); -#ifdef MACOSX - if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) - return oslTranslateFileError( OSL_FET_ERROR, errno ); -#endif/* MACOSX */ + static sal_uInt64 const g_limit_ssize_t = std::numeric_limits< ssize_t >::max(); + if (g_limit_ssize_t < uBytesRequested) + return osl_File_E_OVERFLOW; + size_t const nBytesRequested = sal::static_int_cast< size_t >(uBytesRequested); - return osl_psz_getVolumeInformation( path, pInfo, uFieldMask); + // read at specified fileptr + return pImpl->readFileAt (nOffset, pBuffer, nBytesRequested, pBytesRead); } -/****************************************************************************/ -/* osl_createDirectory */ -/****************************************************************************/ - -oslFileError osl_createDirectory( rtl_uString* ustrDirectoryURL ) +/******************************************* + osl_writeFileAt +********************************************/ +oslFileError +SAL_CALL osl_writeFileAt ( + oslFileHandle Handle, + sal_uInt64 uOffset, + const void* pBuffer, + sal_uInt64 uBytesToWrite, + sal_uInt64* pBytesWritten) { - char path[PATH_MAX]; - oslFileError eRet; + FileHandle_Impl* pImpl = static_cast(Handle); - OSL_ASSERT( ustrDirectoryURL ); + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pBuffer) || (0 == pBytesWritten)) + return osl_File_E_INVAL; + if (0 == (pImpl->m_state & FileHandle_Impl::STATE_SEEKABLE)) + return osl_File_E_SPIPE; + if (0 == (pImpl->m_state & FileHandle_Impl::STATE_WRITEABLE)) + return osl_File_E_BADF; - /* convert directory url to system path */ - eRet = FileURLToPath( path, PATH_MAX, ustrDirectoryURL ); - if( eRet != osl_File_E_None ) - return eRet; + static sal_uInt64 const g_limit_off_t = std::numeric_limits< off_t >::max(); + if (g_limit_off_t < uOffset) + return osl_File_E_OVERFLOW; + off_t const nOffset = sal::static_int_cast< off_t >(uOffset); -#ifdef MACOSX - if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) - return oslTranslateFileError( OSL_FET_ERROR, errno ); -#endif/* MACOSX */ + static sal_uInt64 const g_limit_ssize_t = std::numeric_limits< ssize_t >::max(); + if (g_limit_ssize_t < uBytesToWrite) + return osl_File_E_OVERFLOW; + size_t const nBytesToWrite = sal::static_int_cast< size_t >(uBytesToWrite); - return osl_psz_createDirectory( path ); + // write at specified fileptr + return pImpl->writeFileAt (nOffset, pBuffer, nBytesToWrite, pBytesWritten); } /****************************************************************************/ -/* osl_removeDirectory */ +/* osl_isEndOfFile */ /****************************************************************************/ - -oslFileError osl_removeDirectory( rtl_uString* ustrDirectoryURL ) -{ - char path[PATH_MAX]; - oslFileError eRet; - - OSL_ASSERT( ustrDirectoryURL ); - - /* convert directory url to system path */ - eRet = FileURLToPath( path, PATH_MAX, ustrDirectoryURL ); - if( eRet != osl_File_E_None ) - return eRet; - -#ifdef MACOSX - if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) - return oslTranslateFileError( OSL_FET_ERROR, errno ); -#endif/* MACOSX */ - - return osl_psz_removeDirectory( path ); -} - -//############################################# -int path_make_parent(sal_Unicode* path) +oslFileError +SAL_CALL osl_isEndOfFile( oslFileHandle Handle, sal_Bool *pIsEOF ) { - int i = rtl_ustr_lastIndexOfChar(path, '/'); - - if (i > 0) - { - *(path + i) = 0; - return i; - } - else - return 0; -} + FileHandle_Impl* pImpl = static_cast(Handle); -//############################################# -int create_dir_with_callback( - sal_Unicode* directory_path, - oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, - void* pData) -{ - int mode = S_IRWXU | S_IRWXG | S_IRWXO; + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pIsEOF)) + return osl_File_E_INVAL; - if (osl::mkdir(directory_path, mode) == 0) - { - if (aDirectoryCreationCallbackFunc) - { - rtl::OUString url; - osl::FileBase::getFileURLFromSystemPath(directory_path, url); - aDirectoryCreationCallbackFunc(pData, url.pData); - } - return 0; - } - return errno; + *pIsEOF = (pImpl->getPos() == pImpl->getSize()); + return osl_File_E_None; } -//############################################# -oslFileError create_dir_recursively_( - sal_Unicode* dir_path, - oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, - void* pData) +/************************************************ + * osl_getFilePos + ***********************************************/ +oslFileError +SAL_CALL osl_getFilePos( oslFileHandle Handle, sal_uInt64* pPos ) { - OSL_PRECOND((rtl_ustr_getLength(dir_path) > 0) && ((dir_path + (rtl_ustr_getLength(dir_path) - 1)) != (dir_path + rtl_ustr_lastIndexOfChar(dir_path, '/'))), \ - "Path must not end with a slash"); - - int native_err = create_dir_with_callback( - dir_path, aDirectoryCreationCallbackFunc, pData); - - if (native_err == 0) - return osl_File_E_None; + FileHandle_Impl* pImpl = static_cast(Handle); - if (native_err != ENOENT) - return oslTranslateFileError(OSL_FET_ERROR, native_err); - - // we step back until '/a_dir' at maximum because - // we should get an error unequal ENOENT when - // we try to create 'a_dir' at '/' and would so - // return before - int pos = path_make_parent(dir_path); - - oslFileError osl_error = create_dir_recursively_( - dir_path, aDirectoryCreationCallbackFunc, pData); - - if (osl_File_E_None != osl_error) - return osl_error; - - dir_path[pos] = '/'; - - return create_dir_recursively_(dir_path, aDirectoryCreationCallbackFunc, pData); -} - -//####################################### -oslFileError SAL_CALL osl_createDirectoryPath( - rtl_uString* aDirectoryUrl, - oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, - void* pData) -{ - if (aDirectoryUrl == NULL) + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pPos)) return osl_File_E_INVAL; - rtl::OUString sys_path; - oslFileError osl_error = osl_getSystemPathFromFileURL_Ex( - aDirectoryUrl, &sys_path.pData, sal_False); - - if (osl_error != osl_File_E_None) - return osl_error; - - osl::systemPathRemoveSeparator(sys_path); - - // const_cast because sys_path is a local copy which we want to modify inplace instead of - // coyp it into another buffer on the heap again - return create_dir_recursively_(sys_path.pData->buffer, aDirectoryCreationCallbackFunc, pData); + *pPos = pImpl->getPos(); + return osl_File_E_None; } -/****************************************************************************/ -/* osl_getCanonicalName */ -/****************************************************************************/ - -oslFileError osl_getCanonicalName( rtl_uString* ustrFileURL, rtl_uString** pustrValidURL ) +/******************************************* + osl_setFilePos +********************************************/ +oslFileError +SAL_CALL osl_setFilePos (oslFileHandle Handle, sal_uInt32 uHow, sal_Int64 uOffset) { - OSL_ENSURE(sal_False, "osl_getCanonicalName not implemented"); - - rtl_uString_newFromString(pustrValidURL, ustrFileURL); - return osl_File_E_None; -} + FileHandle_Impl* pImpl = static_cast(Handle); + if ((0 == pImpl) || (-1 == pImpl->m_fd)) + return osl_File_E_INVAL; -/****************************************************************************/ -/* osl_setFileAttributes */ -/****************************************************************************/ + static sal_Int64 const g_limit_off_t = std::numeric_limits< off_t >::max(); + if (g_limit_off_t < uOffset) + return osl_File_E_OVERFLOW; + off_t nPos = 0, nOffset = sal::static_int_cast< off_t >(uOffset); -oslFileError osl_setFileAttributes( rtl_uString* ustrFileURL, sal_uInt64 uAttributes ) -{ - char path[PATH_MAX]; - oslFileError eRet; + switch(uHow) + { + case osl_Pos_Absolut: + if (0 > nOffset) + return osl_File_E_INVAL; + break; - OSL_ASSERT( ustrFileURL ); + case osl_Pos_Current: + nPos = sal::static_int_cast< off_t >(pImpl->getPos()); + if ((0 > nOffset) && (-1*nOffset > nPos)) + return osl_File_E_INVAL; + if (g_limit_off_t < nPos + nOffset) + return osl_File_E_OVERFLOW; + break; - /* convert file url to system path */ - eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); - if( eRet != osl_File_E_None ) - return eRet; + case osl_Pos_End: + nPos = sal::static_int_cast< off_t >(pImpl->getSize()); + if ((0 > nOffset) && (-1*nOffset > nPos)) + return osl_File_E_INVAL; + if (g_limit_off_t < nPos + nOffset) + return osl_File_E_OVERFLOW; + break; -#ifdef MACOSX - if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) - return oslTranslateFileError( OSL_FET_ERROR, errno ); -#endif/* MACOSX */ + default: + return osl_File_E_INVAL; + } - return osl_psz_setFileAttributes( path, uAttributes ); + return pImpl->setPos (nPos + nOffset); } -/****************************************************************************/ -/* osl_setFileTime */ -/****************************************************************************/ - -oslFileError osl_setFileTime( rtl_uString* ustrFileURL, const TimeValue* pCreationTime, - const TimeValue* pLastAccessTime, const TimeValue* pLastWriteTime ) +/**************************************************************************** + * osl_getFileSize + ****************************************************************************/ +oslFileError +SAL_CALL osl_getFileSize( oslFileHandle Handle, sal_uInt64* pSize ) { - char path[PATH_MAX]; - oslFileError eRet; - - OSL_ASSERT( ustrFileURL ); - - /* convert file url to system path */ - eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); - if( eRet != osl_File_E_None ) - return eRet; + FileHandle_Impl* pImpl = static_cast(Handle); -#ifdef MACOSX - if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) - return oslTranslateFileError( OSL_FET_ERROR, errno ); -#endif/* MACOSX */ + if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pSize)) + return osl_File_E_INVAL; - return osl_psz_setFileTime( path, pCreationTime, pLastAccessTime, pLastWriteTime ); + *pSize = pImpl->getSize(); + return osl_File_E_None; } -/****************************************************************************** - * - * Exported Module Functions - * (independent of C or Unicode Strings) - * - *****************************************************************************/ - -/******************************************* - osl_mapFile -********************************************/ +/************************************************ + * osl_setFileSize + ***********************************************/ oslFileError -SAL_CALL osl_mapFile ( - oslFileHandle Handle, - void** ppAddr, - sal_uInt64 uLength, - sal_uInt64 uOffset, - sal_uInt32 uFlags -) +SAL_CALL osl_setFileSize( oslFileHandle Handle, sal_uInt64 uSize ) { - oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl*)Handle; + FileHandle_Impl* pImpl = static_cast(Handle); - if ((0 == pHandleImpl) || (-1 == pHandleImpl->fd) || (0 == ppAddr)) + if ((0 == pImpl) || (-1 == pImpl->m_fd)) return osl_File_E_INVAL; - *ppAddr = 0; - - static sal_uInt64 const g_limit_size_t = std::numeric_limits< size_t >::max(); - if (g_limit_size_t < uLength) - return osl_File_E_OVERFLOW; - size_t const nLength = sal::static_int_cast< size_t >(uLength); + if (0 == (pImpl->m_state & FileHandle_Impl::STATE_WRITEABLE)) + return osl_File_E_BADF; static sal_uInt64 const g_limit_off_t = std::numeric_limits< off_t >::max(); - if (g_limit_off_t < uOffset) + if (g_limit_off_t < uSize) return osl_File_E_OVERFLOW; - off_t const nOffset = sal::static_int_cast< off_t >(uOffset); + off_t const nSize = sal::static_int_cast< off_t >(uSize); - void* p = mmap(NULL, nLength, PROT_READ, MAP_SHARED, pHandleImpl->fd, nOffset); - if (MAP_FAILED == p) - return oslTranslateFileError(OSL_FET_ERROR, errno); - *ppAddr = p; + oslFileError result = pImpl->syncFile(); + if (result != osl_File_E_None) + return (result); - if (uFlags & osl_File_MapFlag_RandomAccess) + if (-1 == ftruncate (pImpl->m_fd, nSize)) { - // Determine memory pagesize. -#if defined(FREEBSD) || defined(NETBSD) || defined(MACOSX) - size_t const nPageSize = getpagesize(); -#else /* POSIX */ - size_t const nPageSize = sysconf(_SC_PAGESIZE); -#endif /* xBSD || POSIX */ - if (size_t(-1) != nPageSize) + /* Failure. Try fallback algorithm */ + off_t nCurPos; + + /* Save original result */ + result = oslTranslateFileError (OSL_FET_ERROR, errno); + PERROR("ftruncate", "Try osl_setFileSize [fallback]\n"); + + /* Check against current size. Fail upon 'shrink' */ + if (uSize <= pImpl->getSize()) { - /* - * Pagein, touching first byte of every memory page. - * Note: volatile disables optimizing the loop away. - */ - sal_uInt8 * pData (reinterpret_cast(*ppAddr)); - size_t nSize (nLength); + /* Failure upon 'shrink'. Return original result */ + return (result); + } - volatile sal_uInt8 c = 0; - while (nSize > nPageSize) - { - c ^= pData[0]; - pData += nPageSize; - nSize -= nPageSize; - } - if (nSize > 0) + /* Save current position *//* @@@ pImpl->m_offset @@@ */ + nCurPos = (off_t)lseek (pImpl->m_fd, (off_t)0, SEEK_CUR); + if (nCurPos == (off_t)(-1)) + { + PERROR("ftruncate: lseek", "Out osl_setFileSize [error]\n"); + return (result); + } + + /* Try 'expand' via 'lseek()' and 'write()' */ + if (lseek (pImpl->m_fd, (off_t)(nSize - 1), SEEK_SET) < 0) + { + PERROR("ftruncate: lseek", "Out osl_setFileSize [error]\n"); + return (result); + } + if (write (pImpl->m_fd, (char*)"", (size_t)1) < 0) + { + /* Failure. Restore saved position */ + PERROR("ftruncate: write", "Out osl_setFileSize [error]\n"); + if (lseek (pImpl->m_fd, (off_t)nCurPos, SEEK_SET) < 0) { - c^= pData[0]; - pData += nSize; - nSize -= nSize; + PERROR("ftruncate: lseek", "ignoring"); } + return (result); } - } - return osl_File_E_None; -} -/******************************************* - osl_unmapFile -********************************************/ -oslFileError -SAL_CALL osl_unmapFile (void* pAddr, sal_uInt64 uLength) -{ - if (0 == pAddr) - return osl_File_E_INVAL; - - static sal_uInt64 const g_limit_size_t = std::numeric_limits< size_t >::max(); - if (g_limit_size_t < uLength) - return osl_File_E_OVERFLOW; - size_t const nLength = sal::static_int_cast< size_t >(uLength); - - if (-1 == munmap(static_cast(pAddr), nLength)) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - return osl_File_E_None; -} - -/******************************************* - osl_readFile -********************************************/ - -oslFileError osl_readFile(oslFileHandle Handle, void* pBuffer, sal_uInt64 uBytesRequested, sal_uInt64* pBytesRead) -{ - ssize_t nBytes = 0; - oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl*)Handle; - - if ((0 == pHandleImpl) || (pHandleImpl->fd < 0) || (0 == pBuffer) || (0 == pBytesRead)) - return osl_File_E_INVAL; - - nBytes = read( - pHandleImpl->fd, pBuffer, - ((uBytesRequested - <= static_cast< size_t >(std::numeric_limits< ssize_t >::max())) - ? static_cast< size_t >(uBytesRequested) - : static_cast< size_t >(std::numeric_limits< ssize_t >::max()))); - - if (-1 == nBytes) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - *pBytesRead = nBytes; - return osl_File_E_None; -} - -/******************************************* - osl_writeFile -********************************************/ - -oslFileError osl_writeFile(oslFileHandle Handle, const void* pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64* pBytesWritten) -{ - ssize_t nBytes = 0; - oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl*)Handle; - - OSL_ASSERT(pHandleImpl); - OSL_ASSERT(pBuffer); - OSL_ASSERT(pBytesWritten); - - if ((0 == pHandleImpl) || (0 == pBuffer) || (0 == pBytesWritten)) - return osl_File_E_INVAL; - - OSL_ASSERT(pHandleImpl->fd >= 0); - - if (pHandleImpl->fd < 0) - return osl_File_E_INVAL; - - nBytes = write( - pHandleImpl->fd, pBuffer, - ((uBytesToWrite - <= static_cast< size_t >(std::numeric_limits< ssize_t >::max())) - ? static_cast< size_t >(uBytesToWrite) - : static_cast< size_t >(std::numeric_limits< ssize_t >::max()))); - - if (-1 == nBytes) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - *pBytesWritten = nBytes; - return osl_File_E_None; -} - -/******************************************* - osl_readFileAt -********************************************/ -oslFileError -SAL_CALL osl_readFileAt ( - oslFileHandle Handle, - sal_uInt64 uOffset, - void* pBuffer, - sal_uInt64 uBytesRequested, - sal_uInt64* pBytesRead) -{ - oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl*)Handle; - - if ((0 == pHandleImpl) || (pHandleImpl->fd < 0) || (0 == pBuffer) || (0 == pBytesRead)) - return osl_File_E_INVAL; - - static sal_uInt64 const g_limit_off_t = std::numeric_limits< off_t >::max(); - if (g_limit_off_t < uOffset) - return osl_File_E_OVERFLOW; - off_t const nOffset = sal::static_int_cast< off_t >(uOffset); - - static sal_uInt64 const g_limit_ssize_t = std::numeric_limits< ssize_t >::max(); - if (g_limit_ssize_t < uBytesRequested) - return osl_File_E_OVERFLOW; - size_t const nBytesRequested = sal::static_int_cast< size_t >(uBytesRequested); - -#if defined(LINUX) || defined(SOLARIS) - - ssize_t nBytes = ::pread(pHandleImpl->fd, pBuffer, nBytesRequested, nOffset); - if ((-1 == nBytes) && (EOVERFLOW == errno)) - { - /* - * Workaround for 'pread()' failure at end-of-file: - * - * Some 'pread()'s fail with EOVERFLOW when reading at (or past) - * end-of-file, different from 'lseek() + read()' behaviour. - * Returning '0 bytes read' and 'osl_File_E_None' instead. - */ - nBytes = 0; - } - -#else /* LINUX || SOLARIS */ - - if (-1 == ::lseek (pHandleImpl->fd, nOffset, SEEK_SET)) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - ssize_t nBytes = ::read(pHandleImpl->fd, pBuffer, nBytesRequested); - -#endif /* LINUX || SOLARIS */ - - if (-1 == nBytes) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - *pBytesRead = nBytes; - return osl_File_E_None; -} - -/******************************************* - osl_writeFileAt -********************************************/ -oslFileError -SAL_CALL osl_writeFileAt ( - oslFileHandle Handle, - sal_uInt64 uOffset, - const void* pBuffer, - sal_uInt64 uBytesToWrite, - sal_uInt64* pBytesWritten) -{ - oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl*)Handle; - - if ((0 == pHandleImpl) || (pHandleImpl->fd < 0) || (0 == pBuffer) || (0 == pBytesWritten)) - return osl_File_E_INVAL; - - static sal_uInt64 const g_limit_off_t = std::numeric_limits< off_t >::max(); - if (g_limit_off_t < uOffset) - return osl_File_E_OVERFLOW; - off_t const nOffset = sal::static_int_cast< off_t >(uOffset); - - static sal_uInt64 const g_limit_ssize_t = std::numeric_limits< ssize_t >::max(); - if (g_limit_ssize_t < uBytesToWrite) - return osl_File_E_OVERFLOW; - size_t const nBytesToWrite = sal::static_int_cast< size_t >(uBytesToWrite); - -#if defined(LINUX) || defined(SOLARIS) - - ssize_t nBytes = ::pwrite(pHandleImpl->fd, pBuffer, nBytesToWrite, nOffset); - -#else /* LINUX || SOLARIS */ - - if (-1 == ::lseek(pHandleImpl->fd, nOffset, SEEK_SET)) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - ssize_t nBytes = ::write(pHandleImpl->fd, pBuffer, nBytesToWrite); - -#endif /* LINUX || SOLARIS */ - - if (-1 == nBytes) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - *pBytesWritten = nBytes; - return osl_File_E_None; -} - -/******************************************* - osl_setFilePos -********************************************/ - -oslFileError osl_setFilePos( oslFileHandle Handle, sal_uInt32 uHow, sal_Int64 uPos ) -{ - oslFileHandleImpl* pHandleImpl=0; - int nRet=0; - off_t nOffset=0; - - pHandleImpl = (oslFileHandleImpl*) Handle; - if ( pHandleImpl == 0 ) - { - return osl_File_E_INVAL; - } - - if ( pHandleImpl->fd < 0 ) - { - return osl_File_E_INVAL; - } - - /* FIXME mfe: setFilePos: Do we have any runtime function to determine LONG_MAX? */ - if ( uPos > LONG_MAX ) - { - return osl_File_E_OVERFLOW; - } - - nOffset=(off_t)uPos; - - switch(uHow) - { - case osl_Pos_Absolut: - nOffset = lseek(pHandleImpl->fd,nOffset,SEEK_SET); - break; - - case osl_Pos_Current: - nOffset = lseek(pHandleImpl->fd,nOffset,SEEK_CUR); - break; - - case osl_Pos_End: - nOffset = lseek(pHandleImpl->fd,nOffset,SEEK_END); - break; - - default: - return osl_File_E_INVAL; - } - - if ( nOffset < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - return osl_File_E_None; -} - -/************************************************ - * osl_getFilePos - ***********************************************/ - -oslFileError osl_getFilePos( oslFileHandle Handle, sal_uInt64* pPos ) -{ - oslFileHandleImpl* pHandleImpl=0; - off_t nOffset=0; - int nRet=0; - - pHandleImpl = (oslFileHandleImpl*) Handle; - if ( pHandleImpl == 0 || pPos == 0) - { - return osl_File_E_INVAL; - } - - if ( pHandleImpl->fd < 0 ) - { - return osl_File_E_INVAL; - } - - nOffset = lseek(pHandleImpl->fd,0,SEEK_CUR); - - if (nOffset < 0) - { - nRet =errno; - - /* *pPos =0; */ - - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - *pPos=nOffset; - - return osl_File_E_None; -} - -/**************************************************************************** - * osl_getFileSize - ****************************************************************************/ - -oslFileError osl_getFileSize( oslFileHandle Handle, sal_uInt64* pSize ) -{ - oslFileHandleImpl* pHandleImpl=(oslFileHandleImpl*) Handle; - if (pHandleImpl == 0) - return osl_File_E_INVAL; - - struct stat file_stat; - if (fstat(pHandleImpl->fd, &file_stat) == -1) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - *pSize = file_stat.st_size; - return osl_File_E_None; -} - -/************************************************ - * osl_setFileSize - ***********************************************/ - -oslFileError osl_setFileSize( oslFileHandle Handle, sal_uInt64 uSize ) -{ - oslFileHandleImpl* pHandleImpl=0; - off_t nOffset=0; - - pHandleImpl = (oslFileHandleImpl*) Handle; - if ( pHandleImpl == 0 ) - { - return osl_File_E_INVAL; - } - - if ( pHandleImpl->fd < 0 ) - { - return osl_File_E_INVAL; - } - - /* FIXME: mfe: setFileSize: Do we have any runtime function to determine LONG_MAX? */ - if ( uSize > LONG_MAX ) - { - return osl_File_E_OVERFLOW; - } - - nOffset = (off_t)uSize; - if (ftruncate (pHandleImpl->fd, nOffset) < 0) - { - /* Failure. Try fallback algorithm */ - oslFileError result; - struct stat aStat; - off_t nCurPos; - - /* Save original result */ - result = oslTranslateFileError (OSL_FET_ERROR, errno); - PERROR("ftruncate", "Try osl_setFileSize [fallback]\n"); - - /* Check against current size. Fail upon 'shrink' */ - if (fstat (pHandleImpl->fd, &aStat) < 0) - { - PERROR("ftruncate: fstat", "Out osl_setFileSize [error]\n"); - return (result); - } - if ((0 <= nOffset) && (nOffset <= aStat.st_size)) - { - /* Failure upon 'shrink'. Return original result */ - return (result); - } - - /* Save current position */ - nCurPos = (off_t)lseek (pHandleImpl->fd, (off_t)0, SEEK_CUR); - if (nCurPos == (off_t)(-1)) - { - PERROR("ftruncate: lseek", "Out osl_setFileSize [error]\n"); - return (result); - } - - /* Try 'expand' via 'lseek()' and 'write()' */ - if (lseek (pHandleImpl->fd, (off_t)(nOffset - 1), SEEK_SET) < 0) - { - PERROR("ftruncate: lseek", "Out osl_setFileSize [error]\n"); - return (result); - } - if (write (pHandleImpl->fd, (char*)"", (size_t)1) < 0) - { - /* Failure. Restore saved position */ - PERROR("ftruncate: write", "Out osl_setFileSize [error]\n"); - if (lseek (pHandleImpl->fd, (off_t)nCurPos, SEEK_SET) < 0) - { -#ifdef DEBUG_OSL_FILE - perror("ftruncate: lseek"); -#endif /* DEBUG_OSL_FILE */ - } - return (result); - } - - /* Success. Restore saved position */ - if (lseek (pHandleImpl->fd, (off_t)nCurPos, SEEK_SET) < 0) - { - PERROR("ftruncate: lseek", "Out osl_setFileSize [error]"); - return (result); - } - } - - return (osl_File_E_None); -} - -/*###############################################*/ -oslFileError SAL_CALL osl_syncFile(oslFileHandle Handle) -{ - oslFileHandleImpl* handle_impl = (oslFileHandleImpl*)Handle; - - if (handle_impl == 0) - return osl_File_E_INVAL; - - if (fsync(handle_impl->fd) == -1) - return oslTranslateFileError(OSL_FET_ERROR, errno); - - return osl_File_E_None; -} - -/****************************************************************************** - * - * C-String Versions of Exported Module Functions - * - *****************************************************************************/ - -#ifdef HAVE_STATFS_H - -#if defined(FREEBSD) || defined(NETBSD) || defined(MACOSX) -# define __OSL_STATFS_STRUCT struct statfs -# define __OSL_STATFS(dir, sfs) statfs((dir), (sfs)) -# define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_bsize)) -# define __OSL_STATFS_TYPENAME(a) ((a).f_fstypename) -# define __OSL_STATFS_ISREMOTE(a) (((a).f_type & MNT_LOCAL) == 0) - -/* always return true if queried for the properties of - the file system. If you think this is wrong under any - of the target platforms fix it!!!! */ -# define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) -# define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) -#endif /* FREEBSD || NETBSD || MACOSX */ - -#if defined(LINUX) -# define __OSL_NFS_SUPER_MAGIC 0x6969 -# define __OSL_SMB_SUPER_MAGIC 0x517B -# define __OSL_MSDOS_SUPER_MAGIC 0x4d44 -# define __OSL_NTFS_SUPER_MAGIC 0x5346544e -# define __OSL_STATFS_STRUCT struct statfs -# define __OSL_STATFS(dir, sfs) statfs((dir), (sfs)) -# define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_bsize)) -# define __OSL_STATFS_IS_NFS(a) (__OSL_NFS_SUPER_MAGIC == (a).f_type) -# define __OSL_STATFS_IS_SMB(a) (__OSL_SMB_SUPER_MAGIC == (a).f_type) -# define __OSL_STATFS_ISREMOTE(a) (__OSL_STATFS_IS_NFS((a)) || __OSL_STATFS_IS_SMB((a))) -# define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) ((__OSL_MSDOS_SUPER_MAGIC != (a).f_type) && (__OSL_NTFS_SUPER_MAGIC != (a).f_type)) -# define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) ((__OSL_MSDOS_SUPER_MAGIC != (a).f_type)) -#endif /* LINUX */ - -#if defined(SOLARIS) || defined(IRIX) -# define __OSL_STATFS_STRUCT struct statvfs -# define __OSL_STATFS(dir, sfs) statvfs((dir), (sfs)) -# define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_frsize)) -# define __OSL_STATFS_TYPENAME(a) ((a).f_basetype) -# define __OSL_STATFS_ISREMOTE(a) (rtl_str_compare((a).f_basetype, "nfs") == 0) - -/* always return true if queried for the properties of - the file system. If you think this is wrong under any - of the target platforms fix it!!!! */ -# define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) -# define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) -#endif /* SOLARIS || IRIX*/ - -# define __OSL_STATFS_INIT(a) (memset(&(a), 0, sizeof(__OSL_STATFS_STRUCT))) - -#else /* no statfs available */ - -# define __OSL_STATFS_STRUCT struct dummy {int i;} -# define __OSL_STATFS_INIT(a) ((void)0) -# define __OSL_STATFS(dir, sfs) (1) -# define __OSL_STATFS_ISREMOTE(sfs) (0) -# define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) -# define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) -#endif /* HAVE_STATFS_H */ - - -static oslFileError osl_psz_getVolumeInformation ( - const sal_Char* pszDirectory, oslVolumeInfo* pInfo, sal_uInt32 uFieldMask) -{ - __OSL_STATFS_STRUCT sfs; - - if (!pInfo) - return osl_File_E_INVAL; - - __OSL_STATFS_INIT(sfs); - - pInfo->uValidFields = 0; - pInfo->uAttributes = 0; - - if ((__OSL_STATFS(pszDirectory, &sfs)) < 0) - { - oslFileError result = oslTranslateFileError(OSL_FET_ERROR, errno); - return (result); - } - - /* FIXME: how to detect the kind of storage (fixed, cdrom, ...) */ - if (uFieldMask & osl_VolumeInfo_Mask_Attributes) - { - if (__OSL_STATFS_ISREMOTE(sfs)) - pInfo->uAttributes |= osl_Volume_Attribute_Remote; - - pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; - } - - if (uFieldMask & osl_VolumeInfo_Mask_FileSystemCaseHandling) - { - if (__OSL_STATFS_IS_CASE_SENSITIVE_FS(sfs)) - pInfo->uAttributes |= osl_Volume_Attribute_Case_Sensitive; - - if (__OSL_STATFS_IS_CASE_PRESERVING_FS(sfs)) - pInfo->uAttributes |= osl_Volume_Attribute_Case_Is_Preserved; - - pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; - } - - pInfo->uTotalSpace = 0; - pInfo->uFreeSpace = 0; - pInfo->uUsedSpace = 0; - -#if defined(__OSL_STATFS_BLKSIZ) - - if ((uFieldMask & osl_VolumeInfo_Mask_TotalSpace) || - (uFieldMask & osl_VolumeInfo_Mask_UsedSpace)) - { - pInfo->uTotalSpace = __OSL_STATFS_BLKSIZ(sfs); - pInfo->uTotalSpace *= (sal_uInt64)(sfs.f_blocks); - pInfo->uValidFields |= osl_VolumeInfo_Mask_TotalSpace; - } - - if ((uFieldMask & osl_VolumeInfo_Mask_FreeSpace) || - (uFieldMask & osl_VolumeInfo_Mask_UsedSpace)) - { - pInfo->uFreeSpace = __OSL_STATFS_BLKSIZ(sfs); - - if (getuid() == 0) - pInfo->uFreeSpace *= (sal_uInt64)(sfs.f_bfree); - else - pInfo->uFreeSpace *= (sal_uInt64)(sfs.f_bavail); - - pInfo->uValidFields |= osl_VolumeInfo_Mask_FreeSpace; - } - -#endif /* __OSL_STATFS_BLKSIZ */ - - if ((pInfo->uValidFields & osl_VolumeInfo_Mask_TotalSpace) && - (pInfo->uValidFields & osl_VolumeInfo_Mask_FreeSpace )) - { - pInfo->uUsedSpace = pInfo->uTotalSpace - pInfo->uFreeSpace; - pInfo->uValidFields |= osl_VolumeInfo_Mask_UsedSpace; - } - - pInfo->uMaxNameLength = 0; - if (uFieldMask & osl_VolumeInfo_Mask_MaxNameLength) - { - long nLen = pathconf(pszDirectory, _PC_NAME_MAX); - if (nLen > 0) - { - pInfo->uMaxNameLength = (sal_uInt32)nLen; - pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxNameLength; - } - } - - pInfo->uMaxPathLength = 0; - if (uFieldMask & osl_VolumeInfo_Mask_MaxPathLength) - { - long nLen = pathconf (pszDirectory, _PC_PATH_MAX); - if (nLen > 0) - { - pInfo->uMaxPathLength = (sal_uInt32)nLen; - pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxPathLength; - } - } - -#if defined(__OSL_STATFS_TYPENAME) - - if (uFieldMask & osl_VolumeInfo_Mask_FileSystemName) - { - rtl_string2UString( - &(pInfo->ustrFileSystemName), - __OSL_STATFS_TYPENAME(sfs), - rtl_str_getLength(__OSL_STATFS_TYPENAME(sfs)), - osl_getThreadTextEncoding(), - OUSTRING_TO_OSTRING_CVTFLAGS); - OSL_ASSERT(pInfo->ustrFileSystemName != 0); - - pInfo->uValidFields |= osl_VolumeInfo_Mask_FileSystemName; - } - -#endif /* __OSL_STATFS_TYPENAME */ - - if (uFieldMask & osl_VolumeInfo_Mask_DeviceHandle) - { - /* FIXME: check also entries in mntent for the device - and fill it with correct values */ - - *pInfo->pDeviceHandle = osl_isFloppyDrive(pszDirectory); - - if (*pInfo->pDeviceHandle) - { - pInfo->uValidFields |= osl_VolumeInfo_Mask_DeviceHandle; - pInfo->uAttributes |= osl_Volume_Attribute_Removeable; - pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; - } - } - return osl_File_E_None; -} - -/************************************* - * osl_psz_setFileAttributes - ************************************/ - -static oslFileError osl_psz_setFileAttributes( const sal_Char* pszFilePath, sal_uInt64 uAttributes ) -{ - oslFileError osl_error = osl_File_E_None; - mode_t nNewMode = 0; - - OSL_ENSURE(!(osl_File_Attribute_Hidden & uAttributes), "osl_File_Attribute_Hidden doesn't work under Unix"); - - if (uAttributes & osl_File_Attribute_OwnRead) - nNewMode |= S_IRUSR; - - if (uAttributes & osl_File_Attribute_OwnWrite) - nNewMode|=S_IWUSR; - - if (uAttributes & osl_File_Attribute_OwnExe) - nNewMode|=S_IXUSR; - - if (uAttributes & osl_File_Attribute_GrpRead) - nNewMode|=S_IRGRP; - - if (uAttributes & osl_File_Attribute_GrpWrite) - nNewMode|=S_IWGRP; - - if (uAttributes & osl_File_Attribute_GrpExe) - nNewMode|=S_IXGRP; - - if (uAttributes & osl_File_Attribute_OthRead) - nNewMode|=S_IROTH; - - if (uAttributes & osl_File_Attribute_OthWrite) - nNewMode|=S_IWOTH; - - if (uAttributes & osl_File_Attribute_OthExe) - nNewMode|=S_IXOTH; - - if (chmod(pszFilePath, nNewMode) < 0) - osl_error = oslTranslateFileError(OSL_FET_ERROR, errno); - - return osl_error; -} - -/****************************************** - * osl_psz_setFileTime - *****************************************/ - -static oslFileError osl_psz_setFileTime( const sal_Char* pszFilePath, - const TimeValue* /*pCreationTime*/, - const TimeValue* pLastAccessTime, - const TimeValue* pLastWriteTime ) -{ - int nRet=0; - struct utimbuf aTimeBuffer; - struct stat aFileStat; -#ifdef DEBUG_OSL_FILE - struct tm* pTM=0; -#endif - - nRet = lstat(pszFilePath,&aFileStat); - - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"File Times are (in localtime):\n"); - pTM=localtime(&aFileStat.st_ctime); - fprintf(stderr,"CreationTime is '%s'\n",asctime(pTM)); - pTM=localtime(&aFileStat.st_atime); - fprintf(stderr,"AccessTime is '%s'\n",asctime(pTM)); - pTM=localtime(&aFileStat.st_mtime); - fprintf(stderr,"Modification is '%s'\n",asctime(pTM)); - - fprintf(stderr,"File Times are (in UTC):\n"); - fprintf(stderr,"CreationTime is '%s'\n",ctime(&aFileStat.st_ctime)); - fprintf(stderr,"AccessTime is '%s'\n",ctime(&aTimeBuffer.actime)); - fprintf(stderr,"Modification is '%s'\n",ctime(&aTimeBuffer.modtime)); -#endif - - if ( pLastAccessTime != 0 ) - { - aTimeBuffer.actime=pLastAccessTime->Seconds; - } - else - { - aTimeBuffer.actime=aFileStat.st_atime; - } - - if ( pLastWriteTime != 0 ) - { - aTimeBuffer.modtime=pLastWriteTime->Seconds; - } - else - { - aTimeBuffer.modtime=aFileStat.st_mtime; - } - - /* mfe: Creation time not used here! */ - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"File Times are (in localtime):\n"); - pTM=localtime(&aFileStat.st_ctime); - fprintf(stderr,"CreationTime now '%s'\n",asctime(pTM)); - pTM=localtime(&aTimeBuffer.actime); - fprintf(stderr,"AccessTime now '%s'\n",asctime(pTM)); - pTM=localtime(&aTimeBuffer.modtime); - fprintf(stderr,"Modification now '%s'\n",asctime(pTM)); - - fprintf(stderr,"File Times are (in UTC):\n"); - fprintf(stderr,"CreationTime now '%s'\n",ctime(&aFileStat.st_ctime)); - fprintf(stderr,"AccessTime now '%s'\n",ctime(&aTimeBuffer.actime)); - fprintf(stderr,"Modification now '%s'\n",ctime(&aTimeBuffer.modtime)); -#endif - - nRet=utime(pszFilePath,&aTimeBuffer); - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - return osl_File_E_None; -} - - -/***************************************** - * osl_psz_removeFile - ****************************************/ - -static oslFileError osl_psz_removeFile( const sal_Char* pszPath ) -{ - int nRet=0; - struct stat aStat; - - nRet = lstat(pszPath,&aStat); - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - if ( S_ISDIR(aStat.st_mode) ) - { - return osl_File_E_ISDIR; - } - - nRet = unlink(pszPath); - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - return osl_File_E_None; -} - -/***************************************** - * osl_psz_createDirectory - ****************************************/ - -static oslFileError osl_psz_createDirectory( const sal_Char* pszPath ) -{ - int nRet=0; - int mode = S_IRWXU | S_IRWXG | S_IRWXO; - - nRet = mkdir(pszPath,mode); - - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - return osl_File_E_None; -} - -/***************************************** - * osl_psz_removeDirectory - ****************************************/ - -static oslFileError osl_psz_removeDirectory( const sal_Char* pszPath ) -{ - int nRet=0; - - nRet = rmdir(pszPath); - - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - return osl_File_E_None; -} - -/***************************************** - * oslDoMoveFile - ****************************************/ - -static oslFileError oslDoMoveFile( const sal_Char* pszPath, const sal_Char* pszDestPath) -{ - oslFileError tErr=osl_File_E_invalidError; - - tErr = osl_psz_moveFile(pszPath,pszDestPath); - if ( tErr == osl_File_E_None ) - { - return tErr; - } - - if ( tErr != osl_File_E_XDEV ) - { - return tErr; - } - - tErr=osl_psz_copyFile(pszPath,pszDestPath); - - if ( tErr != osl_File_E_None ) - { - oslFileError tErrRemove; - tErrRemove=osl_psz_removeFile(pszDestPath); - return tErr; - } - - tErr=osl_psz_removeFile(pszPath); - - return tErr; -} - -/***************************************** - * osl_psz_moveFile - ****************************************/ - -static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* pszDestPath) -{ - - int nRet = 0; - - nRet = rename(pszPath,pszDestPath); - - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - return osl_File_E_None; -} - -/***************************************** - * osl_psz_copyFile - ****************************************/ - -static oslFileError osl_psz_copyFile( const sal_Char* pszPath, const sal_Char* pszDestPath ) -{ - time_t nAcTime=0; - time_t nModTime=0; - uid_t nUID=0; - gid_t nGID=0; - int nRet=0; - mode_t nMode=0; - struct stat aFileStat; - oslFileError tErr=osl_File_E_invalidError; - size_t nSourceSize=0; - int DestFileExists=1; - - /* mfe: does the source file really exists? */ - nRet = lstat(pszPath,&aFileStat); - - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - /* mfe: we do only copy files here! */ - if ( S_ISDIR(aFileStat.st_mode) ) - { - return osl_File_E_ISDIR; - } - - nSourceSize=(size_t)aFileStat.st_size; - nMode=aFileStat.st_mode; - nAcTime=aFileStat.st_atime; - nModTime=aFileStat.st_mtime; - nUID=aFileStat.st_uid; - nGID=aFileStat.st_gid; - - nRet = stat(pszDestPath,&aFileStat); - if ( nRet < 0 ) - { - nRet=errno; - - if ( nRet == ENOENT ) - { - DestFileExists=0; - } -/* return oslTranslateFileError(nRet);*/ - } - - /* mfe: the destination file must not be a directory! */ - if ( nRet == 0 && S_ISDIR(aFileStat.st_mode) ) - { - return osl_File_E_ISDIR; - } - else - { - /* mfe: file does not exists or is no dir */ - } - - tErr = oslDoCopy(pszPath,pszDestPath,nMode,nSourceSize,DestFileExists); - - if ( tErr != osl_File_E_None ) - { - return tErr; - } - - /* - * mfe: ignore return code - * since only the success of the copy is - * important - */ - oslChangeFileModes(pszDestPath,nMode,nAcTime,nModTime,nUID,nGID); - - return tErr; -} - - -/****************************************************************************** - * - * Utility Functions - * - *****************************************************************************/ - -/***************************************** - * oslDoCopy - ****************************************/ - -#define TMP_DEST_FILE_EXTENSION ".osl-tmp" - -static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, mode_t nMode, size_t nSourceSize, int DestFileExists) -{ - int nRet=0; - sal_Char pszTmpDestFile[PATH_MAX]; - size_t size_tmp_dest_buff = sizeof(pszTmpDestFile); - - /* Quick fix for #106048, the whole copy file function seems - to be erroneous anyway and needs to be rewritten. - Besides osl_copyFile is currently not used from OO/SO code. - */ - memset(pszTmpDestFile, 0, size_tmp_dest_buff); - - if ( DestFileExists ) - { - strncpy(pszTmpDestFile, pszDestFileName, size_tmp_dest_buff - 1); - - if ((strlen(pszTmpDestFile) + strlen(TMP_DEST_FILE_EXTENSION)) >= size_tmp_dest_buff) - return osl_File_E_NAMETOOLONG; - - strncat(pszTmpDestFile, TMP_DEST_FILE_EXTENSION, strlen(TMP_DEST_FILE_EXTENSION)); - - /* FIXME: what if pszTmpDestFile already exists? */ - /* with getcanonical??? */ - nRet=rename(pszDestFileName,pszTmpDestFile); - } - - /* mfe: should be S_ISREG */ - if ( !S_ISLNK(nMode) ) - { - /* copy SourceFile to DestFile */ - nRet = oslDoCopyFile(pszSourceFileName,pszDestFileName,nSourceSize, nMode); - } - /* mfe: OK redundant at the moment */ - else if ( S_ISLNK(nMode) ) - { - nRet = oslDoCopyLink(pszSourceFileName,pszDestFileName); - } - else - { - /* mfe: what to do here? */ - nRet=ENOSYS; - } - - if ( nRet > 0 && DestFileExists == 1 ) - { - unlink(pszDestFileName); - rename(pszTmpDestFile,pszDestFileName); - } - - if ( nRet > 0 ) - { - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - if ( DestFileExists == 1 ) - { - unlink(pszTmpDestFile); - } - - return osl_File_E_None; -} - -/***************************************** - * oslChangeFileModes - ****************************************/ - -static oslFileError oslChangeFileModes( const sal_Char* pszFileName, mode_t nMode, time_t nAcTime, time_t nModTime, uid_t nUID, gid_t nGID) -{ - int nRet=0; - struct utimbuf aTimeBuffer; - - nRet = chmod(pszFileName,nMode); - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - aTimeBuffer.actime=nAcTime; - aTimeBuffer.modtime=nModTime; - nRet=utime(pszFileName,&aTimeBuffer); - if ( nRet < 0 ) - { - nRet=errno; - return oslTranslateFileError(OSL_FET_ERROR, nRet); - } - - if ( nUID != getuid() ) - { - nUID=getuid(); - } - - nRet=chown(pszFileName,nUID,nGID); - if ( nRet < 0 ) - { - nRet=errno; - - /* mfe: do not return an error here! */ - /* return oslTranslateFileError(nRet);*/ - } - - return osl_File_E_None; -} - -/***************************************** - * oslDoCopyLink - ****************************************/ - -static int oslDoCopyLink(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName) -{ - int nRet=0; - - /* mfe: if dest file is symbolic link remove the link and place the file instead (hro says so) */ - /* mfe: if source is a link copy the link and not the file it points to (hro says so) */ - sal_Char pszLinkContent[PATH_MAX]; - - pszLinkContent[0] = '\0'; - - nRet = readlink(pszSourceFileName,pszLinkContent,PATH_MAX); - - if ( nRet < 0 ) - { - nRet=errno; - return nRet; - } - else - pszLinkContent[ nRet ] = 0; - - nRet = symlink(pszLinkContent,pszDestFileName); - - if ( nRet < 0 ) - { - nRet=errno; - return nRet; - } - - return 0; -} - -/***************************************** - * oslDoCopyFile - ****************************************/ - -static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, size_t nSourceSize, mode_t mode) -{ - int SourceFileFD=0; - int DestFileFD=0; - int nRet=0; - void* pSourceFile=0; - - SourceFileFD=open(pszSourceFileName,O_RDONLY); - if ( SourceFileFD < 0 ) - { - nRet=errno; - return nRet; - } - - DestFileFD=open(pszDestFileName, O_WRONLY | O_CREAT, mode); - - if ( DestFileFD < 0 ) - { - nRet=errno; - close(SourceFileFD); - return nRet; - } - - /* HACK: because memory mapping fails on various - platforms if the size of the source file is 0 byte */ - if (0 == nSourceSize) - { - close(SourceFileFD); - close(DestFileFD); - return 0; - } - - /* FIXME doCopy: fall back code for systems not having mmap */ - /* mmap file -- open dest file -- write once -- fsync it */ - pSourceFile=mmap(0,nSourceSize,PROT_READ,MAP_PRIVATE,SourceFileFD,0); - - if ( pSourceFile == MAP_FAILED ) - { - /* it's important to set nRet before the hack - otherwise errno may be changed by lstat */ - nRet = errno; - close(SourceFileFD); - close(DestFileFD); - - return nRet; - } - - nRet = write(DestFileFD,pSourceFile,nSourceSize); - - /* #112584# if 'write' could not write the requested number of bytes - we have to fail of course; because it's not exactly specified if 'write' - sets errno if less than requested byte could be written we set nRet - explicitly to ENOSPC */ - if ((nRet < 0) || (nRet != sal::static_int_cast< int >(nSourceSize))) - { - if (nRet < 0) - nRet = errno; - else - nRet = ENOSPC; - - close(SourceFileFD); - close(DestFileFD); - munmap((char*)pSourceFile,nSourceSize); - return nRet; - } - - nRet = munmap((char*)pSourceFile,nSourceSize); - if ( nRet < 0 ) - { - nRet=errno; - close(SourceFileFD); - close(DestFileFD); - return nRet; - } - - close(SourceFileFD); - - // Removed call to 'fsync' again (#112584#) and instead - // evaluate the return value of 'close' in order to detect - // and report ENOSPC and other erronous conditions on close - if (close(DestFileFD) == -1) - return errno; - else - return 0; -} - -/***************************************** - * oslMakeUStrFromPsz - ****************************************/ - -static rtl_uString* oslMakeUStrFromPsz(const sal_Char* pszStr, rtl_uString** ustrValid) -{ - rtl_string2UString( - ustrValid, - pszStr, - rtl_str_getLength( pszStr ), - osl_getThreadTextEncoding(), - OUSTRING_TO_OSTRING_CVTFLAGS ); - OSL_ASSERT(*ustrValid != 0); - - return *ustrValid; -} - -/***************************************************************************** - * UnicodeToText - * converting unicode to text manually saves us the penalty of a temporary - * rtl_String object. - ****************************************************************************/ - -int UnicodeToText( char * buffer, size_t bufLen, const sal_Unicode * uniText, sal_Int32 uniTextLen ) -{ - rtl_UnicodeToTextConverter hConverter; - sal_uInt32 nInfo; - sal_Size nSrcChars, nDestBytes; - - /* stolen from rtl/string.c */ - hConverter = rtl_createUnicodeToTextConverter( osl_getThreadTextEncoding() ); - - nDestBytes = rtl_convertUnicodeToText( hConverter, 0, uniText, uniTextLen, - buffer, bufLen, - OUSTRING_TO_OSTRING_CVTFLAGS | RTL_UNICODETOTEXT_FLAGS_FLUSH, - &nInfo, &nSrcChars ); - - rtl_destroyUnicodeToTextConverter( hConverter ); - - if( nInfo & RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL ) - { - errno = EOVERFLOW; - return 0; - } - - /* ensure trailing '\0' */ - buffer[nDestBytes] = '\0'; - - return nDestBytes; -} - -/***************************************************************************** - TextToUnicode - - @param text - The text to convert. - - @param text_buffer_size - The number of characters. - - @param unic_text - The unicode buffer. - - @param unic_text_buffer_size - The size in characters of the unicode buffer. - - ****************************************************************************/ - -int TextToUnicode( - const char* text, - size_t text_buffer_size, - sal_Unicode* unic_text, - sal_Int32 unic_text_buffer_size) -{ - rtl_TextToUnicodeConverter hConverter; - sal_uInt32 nInfo; - sal_Size nSrcChars; - sal_Size nDestBytes; - - /* stolen from rtl/string.c */ - hConverter = rtl_createTextToUnicodeConverter(osl_getThreadTextEncoding()); - - nDestBytes = rtl_convertTextToUnicode(hConverter, - 0, - text, text_buffer_size, - unic_text, unic_text_buffer_size, - OSTRING_TO_OUSTRING_CVTFLAGS | RTL_TEXTTOUNICODE_FLAGS_FLUSH, - &nInfo, &nSrcChars); - - rtl_destroyTextToUnicodeConverter(hConverter); - - if (nInfo & RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL) - { - errno = EOVERFLOW; - return 0; - } - - /* ensure trailing '\0' */ - unic_text[nDestBytes] = '\0'; - - return nDestBytes; -} - -/****************************************************************************** - * - * GENERIC FLOPPY FUNCTIONS - * - *****************************************************************************/ - - -/***************************************** - * osl_unmountVolumeDevice - ****************************************/ - -oslFileError osl_unmountVolumeDevice( oslVolumeDeviceHandle Handle ) -{ - oslFileError tErr = osl_File_E_NOSYS; - - tErr = osl_unmountFloppy(Handle); - - /* Perhaps current working directory is set to mount point */ - - if ( tErr ) - { - sal_Char *pszHomeDir = getenv("HOME"); - - if ( pszHomeDir && strlen( pszHomeDir ) && 0 == chdir( pszHomeDir ) ) - { - /* try again */ - - tErr = osl_unmountFloppy(Handle); - - OSL_ENSURE( tErr, "osl_unmountvolumeDevice: CWD was set to volume mount point" ); - } - } - - return tErr; -} - -/***************************************** - * osl_automountVolumeDevice - ****************************************/ - -oslFileError osl_automountVolumeDevice( oslVolumeDeviceHandle Handle ) -{ - oslFileError tErr = osl_File_E_NOSYS; - - tErr = osl_mountFloppy(Handle); - - return tErr; -} - -/***************************************** - * osl_getVolumeDeviceMountPath - ****************************************/ - -oslFileError osl_getVolumeDeviceMountPath( oslVolumeDeviceHandle Handle, rtl_uString **pstrPath ) -{ - oslVolumeDeviceHandleImpl* pItem = (oslVolumeDeviceHandleImpl*) Handle; - sal_Char Buffer[PATH_MAX]; - - Buffer[0] = '\0'; - - if ( pItem == 0 || pstrPath == 0 ) - { - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { - return osl_File_E_INVAL; - } - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"Handle is:\n"); - osl_printFloppyHandle(pItem); -#endif - - snprintf(Buffer, sizeof(Buffer), "file://%s", pItem->pszMountPoint); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"Mount Point is: '%s'\n",Buffer); -#endif - - oslMakeUStrFromPsz(Buffer, pstrPath); - - return osl_File_E_None; -} - -/***************************************** - * osl_acquireVolumeDeviceHandle - ****************************************/ - -oslFileError SAL_CALL osl_acquireVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) -{ - oslVolumeDeviceHandleImpl* pItem =(oslVolumeDeviceHandleImpl*) Handle; - - if ( pItem == 0 ) - { - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { - return osl_File_E_INVAL; - } - - ++pItem->RefCount; - - return osl_File_E_None; -} - -/***************************************** - * osl_releaseVolumeDeviceHandle - ****************************************/ - -oslFileError osl_releaseVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) -{ - oslVolumeDeviceHandleImpl* pItem =(oslVolumeDeviceHandleImpl*) Handle; - - if ( pItem == 0 ) - { - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { - return osl_File_E_INVAL; - } - - --pItem->RefCount; - - if ( pItem->RefCount == 0 ) - { - rtl_freeMemory(pItem); - } - - return osl_File_E_None; -} - -#ifndef MACOSX - -/***************************************** - * osl_newVolumeDeviceHandleImpl - ****************************************/ - -static oslVolumeDeviceHandleImpl* osl_newVolumeDeviceHandleImpl() -{ - oslVolumeDeviceHandleImpl* pHandle; - const size_t nSizeOfHandle = sizeof(oslVolumeDeviceHandleImpl); - - pHandle = (oslVolumeDeviceHandleImpl*) rtl_allocateMemory (nSizeOfHandle); - if (pHandle != NULL) - { - pHandle->ident[0] = 'O'; - pHandle->ident[1] = 'V'; - pHandle->ident[2] = 'D'; - pHandle->ident[3] = 'H'; - pHandle->pszMountPoint[0] = '\0'; - pHandle->pszFilePath[0] = '\0'; - pHandle->pszDevice[0] = '\0'; - pHandle->RefCount = 1; - } - return pHandle; -} - -/***************************************** - * osl_freeVolumeDeviceHandleImpl - ****************************************/ - -static void osl_freeVolumeDeviceHandleImpl (oslVolumeDeviceHandleImpl* pHandle) -{ - if (pHandle != NULL) - rtl_freeMemory (pHandle); -} -#endif - -/****************************************************************************** - * - * SOLARIS FLOPPY FUNCTIONS - * - *****************************************************************************/ - -#if defined(SOLARIS) -/* compare a given devicename with the typical device names on a Solaris box */ -static sal_Bool -osl_isAFloppyDevice (const char* pDeviceName) -{ - const char* pFloppyDevice [] = { - "/dev/fd", "/dev/rfd", - "/dev/diskette", "/dev/rdiskette", - "/vol/dev/diskette", "/vol/dev/rdiskette" - }; - - int i; - for (i = 0; i < (sizeof(pFloppyDevice)/sizeof(pFloppyDevice[0])); i++) - { - if (strncmp(pDeviceName, pFloppyDevice[i], strlen(pFloppyDevice[i])) == 0) - return sal_True; - } - return sal_False; -} - -/* compare two directories whether the first may be a parent of the second. this - * does not realpath() resolving */ -static sal_Bool -osl_isAParentDirectory (const char* pParentDir, const char* pSubDir) -{ - return strncmp(pParentDir, pSubDir, strlen(pParentDir)) == 0; -} - -/* the name of the routine is obviously silly. But anyway create a - * oslVolumeDeviceHandle with correct mount point, device name and a resolved filepath - * only if pszPath points to file or directory on a floppy */ -static oslVolumeDeviceHandle -osl_isFloppyDrive(const sal_Char* pszPath) -{ - FILE* pMountTab; - struct mnttab aMountEnt; - oslVolumeDeviceHandleImpl* pHandle; - - if ((pHandle = osl_newVolumeDeviceHandleImpl()) == NULL) - { - return NULL; - } - if (realpath(pszPath, pHandle->pszFilePath) == NULL) - { - osl_freeVolumeDeviceHandleImpl (pHandle); - return NULL; - } - if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) - { - osl_freeVolumeDeviceHandleImpl (pHandle); - return NULL; - } - - while (getmntent(pMountTab, &aMountEnt) == 0) - { - const char *pMountPoint = aMountEnt.mnt_mountp; - const char *pDevice = aMountEnt.mnt_special; - if ( osl_isAParentDirectory (aMountEnt.mnt_mountp, pHandle->pszFilePath) - && osl_isAFloppyDevice (aMountEnt.mnt_special)) - { - /* skip the last item for it is the name of the disk */ - char * pc = strrchr( aMountEnt.mnt_special, '/' ); - - if ( NULL != pc ) - { - int len = pc - aMountEnt.mnt_special; - - strncpy( pHandle->pszDevice, aMountEnt.mnt_special, len ); - pHandle->pszDevice[len] = '\0'; - } - else - { - /* #106048 use save str functions to avoid buffer overflows */ - memset(pHandle->pszDevice, 0, sizeof(pHandle->pszDevice)); - strncpy(pHandle->pszDevice, aMountEnt.mnt_special, sizeof(pHandle->pszDevice) - 1); - } - - /* remember the mount point */ - memset(pHandle->pszMountPoint, 0, sizeof(pHandle->pszMountPoint)); - strncpy(pHandle->pszMountPoint, aMountEnt.mnt_mountp, sizeof(pHandle->pszMountPoint) - 1); - - fclose (pMountTab); - return pHandle; - } - } - - fclose (pMountTab); - osl_freeVolumeDeviceHandleImpl (pHandle); - return NULL; -} - -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) -{ - FILE* pMountTab; - struct mnttab aMountEnt; - oslVolumeDeviceHandleImpl* pHandle = (oslVolumeDeviceHandleImpl*) hFloppy; - - int nRet=0; - sal_Char pszCmd[512] = ""; - - if ( pHandle == 0 ) - return osl_File_E_INVAL; - - /* FIXME: don't know what this is good for */ - if ( pHandle->ident[0] != 'O' || pHandle->ident[1] != 'V' || pHandle->ident[2] != 'D' || pHandle->ident[3] != 'H' ) - return osl_File_E_INVAL; - - snprintf(pszCmd, sizeof(pszCmd), "eject -q %s > /dev/null 2>&1", pHandle->pszDevice); - - nRet = system( pszCmd ); - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - { - /* lookup the device in mount tab again */ - if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) - return osl_File_E_BUSY; - - while (getmntent(pMountTab, &aMountEnt) == 0) - { - const char *pMountPoint = aMountEnt.mnt_mountp; - const char *pDevice = aMountEnt.mnt_special; - if ( 0 == strncmp( pHandle->pszDevice, aMountEnt.mnt_special, strlen(pHandle->pszDevice) ) ) - { - memset(pHandle->pszMountPoint, 0, sizeof(pHandle->pszMountPoint)); - strncpy (pHandle->pszMountPoint, aMountEnt.mnt_mountp, sizeof(pHandle->pszMountPoint) - 1); - - fclose (pMountTab); - return osl_File_E_None; - } - } - - fclose (pMountTab); - return osl_File_E_BUSY; - } - //break; // break not necessary here, see return statements before - - case 1: - return osl_File_E_BUSY; - - default: - break; - } - - return osl_File_E_BUSY; -} - -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) -{ -// FILE* pMountTab; -// struct mnttab aMountEnt; - oslVolumeDeviceHandleImpl* pHandle = (oslVolumeDeviceHandleImpl*) hFloppy; - - int nRet=0; - sal_Char pszCmd[512] = ""; - - if ( pHandle == 0 ) - return osl_File_E_INVAL; - - /* FIXME: don't know what this is good for */ - if ( pHandle->ident[0] != 'O' || pHandle->ident[1] != 'V' || pHandle->ident[2] != 'D' || pHandle->ident[3] != 'H' ) - return osl_File_E_INVAL; - - snprintf(pszCmd, sizeof(pszCmd), "eject %s > /dev/null 2>&1", pHandle->pszDevice); - - nRet = system( pszCmd ); - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - { - FILE* pMountTab; - struct mnttab aMountEnt; - - /* lookup if device is still in mount tab */ - if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) - return osl_File_E_BUSY; - - while (getmntent(pMountTab, &aMountEnt) == 0) - { - const char *pMountPoint = aMountEnt.mnt_mountp; - const char *pDevice = aMountEnt.mnt_special; - if ( 0 == strncmp( pHandle->pszDevice, aMountEnt.mnt_special, strlen(pHandle->pszDevice) ) ) - { - fclose (pMountTab); - return osl_File_E_BUSY; - } - } - - fclose (pMountTab); - pHandle->pszMountPoint[0] = 0; - return osl_File_E_None; - } - - //break; //break not necessary, see return statements before - - case 1: - return osl_File_E_NODEV; - - case 4: - pHandle->pszMountPoint[0] = 0; - return osl_File_E_None; - - default: - break; - } - - return osl_File_E_BUSY; -} - -#endif /* SOLARIS */ - -/****************************************************************************** - * - * LINUX FLOPPY FUNCTIONS - * - *****************************************************************************/ - -#if defined(LINUX) -static oslVolumeDeviceHandle -osl_isFloppyDrive (const sal_Char* pszPath) -{ - oslVolumeDeviceHandleImpl* pItem = osl_newVolumeDeviceHandleImpl(); - if (osl_getFloppyMountEntry(pszPath, pItem)) - return (oslVolumeDeviceHandle) pItem; - - osl_freeVolumeDeviceHandleImpl (pItem); - return 0; -} -#endif /* LINUX */ - -#if defined(LINUX) -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) -{ - sal_Bool bRet = sal_False; - oslVolumeDeviceHandleImpl* pItem=0; - int nRet; - sal_Char pszCmd[PATH_MAX]; - const sal_Char* pszMountProg = "mount"; - sal_Char* pszSuDo = 0; - sal_Char* pszTmp = 0; - - pszCmd[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_mountFloppy\n"); -#endif - - pItem = (oslVolumeDeviceHandleImpl*) hFloppy; - - if ( pItem == 0 ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_mountFloppy [pItem == 0]\n"); -#endif - - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_mountFloppy [invalid handle]\n"); -#endif - return osl_File_E_INVAL; - } - - bRet = osl_isFloppyMounted(pItem); - if ( bRet == sal_True ) - { -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"detected mounted floppy at '%s'\n",pItem->pszMountPoint); -#endif - return osl_File_E_BUSY; - } - - /* mfe: we can't use the mount(2) system call!!! */ - /* even if we are root */ - /* since mtab is not updated!!! */ - /* but we need it to be updated */ - /* some "magic" must be done */ - -/* nRet = mount(pItem->pszDevice,pItem->pszMountPoint,0,0,0); */ -/* if ( nRet != 0 ) */ -/* { */ -/* nRet=errno; */ -/* #ifdef DEBUG_OSL_FILE */ -/* perror("mount"); */ -/* #endif */ -/* } */ - - pszTmp = getenv("SAL_MOUNT_MOUNTPROG"); - if ( pszTmp != 0 ) - { - pszMountProg=pszTmp; - } - - pszTmp=getenv("SAL_MOUNT_SU_DO"); - if ( pszTmp != 0 ) - { - pszSuDo=pszTmp; - } - - if ( pszSuDo != 0 ) - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s %s %s",pszSuDo,pszMountProg,pItem->pszDevice,pItem->pszMountPoint); - } - else - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszMountProg,pItem->pszMountPoint); - } - - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"executing '%s'\n",pszCmd); -#endif - - nRet = system(pszCmd); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"call returned '%i'\n",nRet); - fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); -#endif - - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - nRet=0; - break; - - case 2: - nRet=EPERM; - break; - - case 4: - nRet=ENOENT; - break; - - case 8: - nRet=EINTR; - break; - - case 16: - nRet=EPERM; - break; - - case 32: - nRet=EBUSY; - break; - - case 64: - nRet=EAGAIN; - break; - - default: - nRet=EBUSY; - break; - } - - return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); -} -#endif /* LINUX */ - - -#if defined(LINUX) -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) -{ - oslVolumeDeviceHandleImpl* pItem=0; - int nRet=0; - sal_Char pszCmd[PATH_MAX]; - sal_Char* pszTmp = 0; - sal_Char* pszSuDo = 0; - const sal_Char* pszUmountProg = "umount"; - - pszCmd[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_unmountFloppy\n"); -#endif - - pItem = (oslVolumeDeviceHandleImpl*) hFloppy; - - if ( pItem == 0 ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [pItem==0]\n"); -#endif - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [invalid handle]\n"); -#endif - return osl_File_E_INVAL; - } - - /* mfe: we can't use the umount(2) system call!!! */ - /* even if we are root */ - /* since mtab is not updated!!! */ - /* but we need it to be updated */ - /* some "magic" must be done */ - -/* nRet=umount(pItem->pszDevice); */ -/* if ( nRet != 0 ) */ -/* { */ -/* nRet = errno; */ - -/* #ifdef DEBUG_OSL_FILE */ -/* perror("mount"); */ -/* #endif */ -/* } */ - - - pszTmp = getenv("SAL_MOUNT_UMOUNTPROG"); - if ( pszTmp != 0 ) - { - pszUmountProg=pszTmp; - } - - pszTmp = getenv("SAL_MOUNT_SU_DO"); - if ( pszTmp != 0 ) - { - pszSuDo=pszTmp; - } - - if ( pszSuDo != 0 ) - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s %s",pszSuDo,pszUmountProg,pItem->pszMountPoint); - } - else - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszUmountProg,pItem->pszMountPoint); - } - - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"executing '%s'\n",pszCmd); -#endif - - nRet = system(pszCmd); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"call returned '%i'\n",nRet); - fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); -#endif - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - nRet=0; - break; - - default: - nRet=EBUSY; - break; - } - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [ok]\n"); -#endif - - return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); - -/* return osl_File_E_None;*/ -} - -#endif /* LINUX */ - -#if defined(LINUX) -static sal_Bool -osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) -{ - struct mntent* pMountEnt; - FILE* pMountTab; - - pMountTab = setmntent (MOUNTTAB, "r"); - if (pMountTab == 0) - return sal_False; - - while ((pMountEnt = getmntent(pMountTab)) != 0) - { - if ( strncmp(pMountEnt->mnt_dir, pszPath, strlen(pMountEnt->mnt_dir)) == 0 - && strncmp(pMountEnt->mnt_fsname, "/dev/fd", strlen("/dev/fd")) == 0) - { - memset(pItem->pszMountPoint, 0, sizeof(pItem->pszMountPoint)); - strncpy(pItem->pszMountPoint, pMountEnt->mnt_dir, sizeof(pItem->pszMountPoint) - 1); - - memset(pItem->pszFilePath, 0, sizeof(pItem->pszFilePath)); - strncpy(pItem->pszFilePath, pMountEnt->mnt_dir, sizeof(pItem->pszFilePath) - 1); - - memset(pItem->pszDevice, 0, sizeof(pItem->pszDevice)); - strncpy(pItem->pszDevice, pMountEnt->mnt_fsname, sizeof(pItem->pszDevice) - 1); - - endmntent (pMountTab); - return sal_True; - } - } - - endmntent (pMountTab); - return sal_False; -} -#endif /* LINUX */ - -#if defined(LINUX) -static sal_Bool -osl_isFloppyMounted (oslVolumeDeviceHandleImpl* pDevice) -{ - oslVolumeDeviceHandleImpl aItem; - - if ( osl_getFloppyMountEntry (pDevice->pszMountPoint, &aItem) - && strcmp (aItem.pszMountPoint, pDevice->pszMountPoint) == 0 - && strcmp (aItem.pszDevice, pDevice->pszDevice) == 0) - { - return sal_True; - } - return sal_False; -} -#endif /* LINUX */ - -/****************************************************************************** - * - * IRIX FLOPPY FUNCTIONS - * - *****************************************************************************/ - -#if defined(IRIX) -static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath) -{ - oslVolumeDeviceHandleImpl* pItem = osl_newVolumeDeviceHandleImpl (); - sal_Bool bRet = sal_False; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_isFloppyDrive\n"); -#endif - - bRet=osl_getFloppyMountEntry(pszPath,pItem); - - if ( bRet == sal_False ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyDrive [not a floppy]\n"); -#endif - rtl_freeMemory(pItem); - return 0; - } - - -#ifdef DEBUG_OSL_FILE - osl_printFloppyHandle(pItem); -#endif -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyDrive [ok]\n"); -#endif - - return (oslVolumeDeviceHandle) pItem; -} - - -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) -{ - sal_Bool bRet = sal_False; - oslVolumeDeviceHandleImpl* pItem=0; - int nRet; - sal_Char pszCmd[PATH_MAX]; - sal_Char* pszMountProg = "mount"; - sal_Char* pszSuDo = 0; - sal_Char* pszTmp = 0; - - pszCmd[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_mountFloppy\n"); -#endif - - pItem = (oslVolumeDeviceHandleImpl*) hFloppy; - - if ( pItem == 0 ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_mountFloppy [pItem == 0]\n"); -#endif - - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_mountFloppy [invalid handle]\n"); -#endif - return osl_File_E_INVAL; - } - - bRet = osl_isFloppyMounted(pItem); - if ( bRet == sal_True ) - { -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"detected mounted floppy at '%s'\n",pItem->pszMountPoint); -#endif - return osl_File_E_BUSY; - } - - /* mfe: we can't use the mount(2) system call!!! */ - /* even if we are root */ - /* since mtab is not updated!!! */ - /* but we need it to be updated */ - /* some "magic" must be done */ - -/* nRet = mount(pItem->pszDevice,pItem->pszMountPoint,0,0,0); */ -/* if ( nRet != 0 ) */ -/* { */ -/* nRet=errno; */ -/* #ifdef DEBUG_OSL_FILE */ -/* perror("mount"); */ -/* #endif */ -/* } */ - - pszTmp = getenv("SAL_MOUNT_MOUNTPROG"); - if ( pszTmp != 0 ) - { - pszMountProg=pszTmp; - } - - pszTmp=getenv("SAL_MOUNT_SU_DO"); - if ( pszTmp != 0 ) - { - pszSuDo=pszTmp; - } - - if ( pszSuDo != 0 ) - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s %s %s",pszSuDo,pszMountProg,pItem->pszDevice,pItem->pszMountPoint); - } - else - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszMountProg,pItem->pszMountPoint); - } - - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"executing '%s'\n",pszCmd); -#endif - - nRet = system(pszCmd); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"call returned '%i'\n",nRet); - fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); -#endif - - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - nRet=0; - break; - - case 2: - nRet=EPERM; - break; - - case 4: - nRet=ENOENT; - break; - - case 8: - nRet=EINTR; - break; - - case 16: - nRet=EPERM; - break; - - case 32: - nRet=EBUSY; - break; - - case 64: - nRet=EAGAIN; - break; - - default: - nRet=EBUSY; - break; - } - - return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); -} - -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) -{ - oslVolumeDeviceHandleImpl* pItem=0; - int nRet=0; - sal_Char pszCmd[PATH_MAX]; - sal_Char* pszTmp = 0; - sal_Char* pszSuDo = 0; - sal_Char* pszUmountProg = "umount"; - - pszCmd[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_unmountFloppy\n"); -#endif - - pItem = (oslVolumeDeviceHandleImpl*) hFloppy; - - if ( pItem == 0 ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [pItem==0]\n"); -#endif - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [invalid handle]\n"); -#endif - return osl_File_E_INVAL; - } - - /* mfe: we can't use the umount(2) system call!!! */ - /* even if we are root */ - /* since mtab is not updated!!! */ - /* but we need it to be updated */ - /* some "magic" must be done */ - -/* nRet=umount(pItem->pszDevice); */ -/* if ( nRet != 0 ) */ -/* { */ -/* nRet = errno; */ - -/* #ifdef DEBUG_OSL_FILE */ -/* perror("mount"); */ -/* #endif */ -/* } */ - - - pszTmp = getenv("SAL_MOUNT_UMOUNTPROG"); - if ( pszTmp != 0 ) - { - pszUmountProg=pszTmp; - } - - pszTmp = getenv("SAL_MOUNT_SU_DO"); - if ( pszTmp != 0 ) - { - pszSuDo=pszTmp; - } - - if ( pszSuDo != 0 ) - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s %s",pszSuDo,pszUmountProg,pItem->pszMountPoint); - } - else - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszUmountProg,pItem->pszMountPoint); - } - - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"executing '%s'\n",pszCmd); -#endif - - nRet = system(pszCmd); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"call returned '%i'\n",nRet); - fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); -#endif - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - nRet=0; - break; - - default: - nRet=EBUSY; - break; - } - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [ok]\n"); -#endif - - return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); - -/* return osl_File_E_None;*/ -} - -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) -{ - struct mntent* pMountEnt=0; - sal_Char buffer[PATH_MAX]; - FILE* mntfile=0; - int nRet=0; - - buffer[0] = '\0'; - - mntfile = setmntent(MOUNTTAB,"r"); - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_getFloppyMountEntry\n"); -#endif - - memset(buffer, 0, sizeof(buffer)); - strncpy(buffer, pszPath, sizeof(buffer) - 1); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"Checking mount of %s\n",buffer); -#endif - - - if ( mntfile == 0 ) - { - nRet=errno; -#ifdef DEBUG_OSL_FILE - perror("mounttab"); -#endif -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_getFloppyMountEntry [mntfile]\n"); -#endif - return sal_False; - } - - pMountEnt=getmntent(mntfile); - while ( pMountEnt != 0 ) - { -#ifdef DEBUG_OSL_FILE -/* fprintf(stderr,"mnt_fsname : %s\n",pMountEnt->mnt_fsname); */ -/* fprintf(stderr,"mnt_dir : %s\n",pMountEnt->mnt_dir); */ -/* fprintf(stderr,"mnt_type : %s\n",pMountEnt->mnt_type);*/ -#endif - if ( strcmp(pMountEnt->mnt_dir,buffer) == 0 && - strncmp(pMountEnt->mnt_fsname,"/dev/fd",strlen("/dev/fd")) == 0 ) + /* Success. Restore saved position */ + if (lseek (pImpl->m_fd, (off_t)nCurPos, SEEK_SET) < 0) { - - memset(pItem->pszMountPoint, 0, sizeof(pItem->pszMountPoint)); - strncpy(pItem->pszMountPoint, pMountEnt->mnt_dir, sizeof(pItem->pszMountPoint) - 1); - - memset(pItem->pszFilePath, 0, sizeof(pItem->pszFilePath)); - strncpy(pItem->pszFilePath, pMountEnt->mnt_dir, sizeof(pItem->pszFilePath) - 1); - - memset(pItem->pszDevice, 0, sizeof(pItem->pszDevice)); - strncpy(pItem->pszDevice, pMountEnt->mnt_fsname, sizeof(pItem->pszDevice) - 1); - - fclose(mntfile); -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"Mount Point found '%s'\n",pItem->pszMountPoint); -#endif -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_getFloppyMountEntry [found]\n"); -#endif - return sal_True; + PERROR("ftruncate: lseek", "Out osl_setFileSize [error]"); + return (result); } -#ifdef DEBUG_OSL_FILE -/* fprintf(stderr,"=================\n");*/ -#endif - pMountEnt=getmntent(mntfile); } -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_getFloppyMountEntry [not found]\n"); -#endif - - fclose(mntfile); - return sal_False; -} - -static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice) -{ - sal_Char buffer[PATH_MAX]; - oslVolumeDeviceHandleImpl* pItem=0; - sal_Bool bRet=0; - - buffer[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_isFloppyMounted\n"); -#endif - - pItem = osl_newVolumeDeviceHandleImpl (); - if ( pItem == 0 ) - return osl_File_E_NOMEM; - - memset(buffer, 0, sizeof(buffer)); - strncpy(buffer, pDevice->pszMountPoint, sizeof(buffer) - 1); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"Checking mount of %s\n",buffer); -#endif - - bRet = osl_getFloppyMountEntry(buffer,pItem); - - if ( bRet == sal_False ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyMounted [not mounted]\n"); -#endif - return sal_False; - } - - if (strcmp(pItem->pszMountPoint, pDevice->pszMountPoint) == 0 && - strcmp(pItem->pszDevice,pDevice->pszDevice) == 0) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyMounted [is mounted]\n"); -#endif - rtl_freeMemory(pItem); - return sal_True; - } - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyMounted [may be EBUSY]\n"); -#endif - - rtl_freeMemory(pItem); - return sal_False; -} -#endif /* IRIX */ - - -/* NetBSD floppy functions have to be added here. Until we have done that, - * we use the MACOSX definitions for nonexistent floppy. - * */ - -/****************************************************************************** - * - * MAC OS X FLOPPY FUNCTIONS - * - *****************************************************************************/ - -#if (defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) -static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath) -{ - return NULL; -} -#endif /* MACOSX */ - -#if ( defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) -{ - return osl_File_E_BUSY; -} -#endif /* MACOSX */ - -#if ( defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) -{ - return osl_File_E_BUSY; -} -#endif /* MACOSX */ - -#if ( defined(NETBSD) || defined(FREEBSD) ) -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) -{ - return sal_False; -} -#endif /* NETBSD || FREEBSD */ - -#if ( defined(NETBSD) || defined(FREEBSD) ) -static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice) -{ - return sal_False; -} -#endif /* NETBSD || FREEBSD */ - - -#ifdef DEBUG_OSL_FILE -static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* pItem) -{ - if (pItem == 0 ) - { - fprintf(stderr,"NULL Handle\n"); - return; - } - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Invalid Handle]\n"); -#endif - return; - } - - - fprintf(stderr,"MountPoint : '%s'\n",pItem->pszMountPoint); - fprintf(stderr,"FilePath : '%s'\n",pItem->pszFilePath); - fprintf(stderr,"Device : '%s'\n",pItem->pszDevice); - - return; + OSL_FILE_TRACE("osl_setFileSize(%d, %lld) => %ld", pImpl->m_fd, pImpl->getSize(), nSize); + pImpl->m_size = sal::static_int_cast< sal_uInt64 >(nSize); + return osl_File_E_None; } -#endif - diff --git a/sal/osl/unx/file_impl.hxx b/sal/osl/unx/file_impl.hxx index ae9d56ca85f3..db85b00cbfef 100644 --- a/sal/osl/unx/file_impl.hxx +++ b/sal/osl/unx/file_impl.hxx @@ -28,21 +28,30 @@ * ************************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif -typedef struct +#ifndef INCLUDED_FILE_IMPL_HXX +#define INCLUDED_FILE_IMPL_HXX + +#include "osl/file.h" +#include + +struct DirectoryItem_Impl { - rtl_uString* ustrFilePath; /* holds native file name */ - unsigned char DType; - bool bHasType; - sal_uInt32 RefCount; -} oslDirectoryItemImpl; - - oslDirectoryItemImpl* oslDirectoryItemImpl_CreateNew( rtl_uString* _ustrFilePath, bool _bHasDType, unsigned char _DType=0 ); - void oslDirectoryItemImpl_Destroy( oslDirectoryItemImpl* pItem ); - void oslDirectoryItemImpl_acquire( oslDirectoryItemImpl* pItem ); - void oslDirectoryItemImpl_release( oslDirectoryItemImpl* pItem ); -#ifdef __cplusplus -} /* extern "C" */ -#endif + sal_Int32 m_RefCount; + + rtl_uString * m_ustrFilePath; /* holds native file name */ + unsigned char m_DType; + + explicit DirectoryItem_Impl( + rtl_uString * ustrFilePath, unsigned char DType = 0); + ~DirectoryItem_Impl(); + + static void * operator new(size_t n); + static void operator delete (void * p, size_t); + + void acquire(); /* @see osl_acquireDirectoryItem() */ + void release(); /* @see osl_releaseDirectoryItem() */ + + oslFileType getFileType() const; +}; + +#endif /* INCLUDED_FILE_IMPL_HXX */ diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx new file mode 100644 index 000000000000..3f3cf02fb010 --- /dev/null +++ b/sal/osl/unx/file_misc.cxx @@ -0,0 +1,1084 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "osl/file.hxx" + +#include "osl/diagnose.h" +#include "osl/thread.h" +#include "rtl/alloc.h" + +#include "system.h" +#include "file_impl.hxx" +#include "file_error_transl.h" +#include "file_path_helper.hxx" +#include "file_url.h" +#include "uunxapi.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/************************************************************************ + * ToDo + * + * - Fix: check for corresponding struct sizes in exported functions + * - check size/use of oslDirectory + * - check size/use of oslDirectoryItem + ***********************************************************************/ +/****************************************************************************** + * + * Data Type Definition + * + ******************************************************************************/ + +typedef struct +{ + rtl_uString* ustrPath; /* holds native directory path */ + DIR* pDirStruct; +} oslDirectoryImpl; + +#if 0 +/* FIXME: reintroducing this may save some extra bytes per Item */ +typedef struct +{ + rtl_uString* ustrFileName; /* holds native file name */ + rtl_uString* ustrDirPath; /* holds native dir path */ + sal_uInt32 RefCount; +} oslDirectoryItemImpl; +#endif + +DirectoryItem_Impl::DirectoryItem_Impl( + rtl_uString * ustrFilePath, unsigned char DType) + : m_RefCount (1), + m_ustrFilePath (ustrFilePath), + m_DType (DType) +{ + if (m_ustrFilePath != 0) + rtl_uString_acquire(m_ustrFilePath); +} +DirectoryItem_Impl::~DirectoryItem_Impl() +{ + if (m_ustrFilePath != 0) + rtl_uString_release(m_ustrFilePath); +} + +void * DirectoryItem_Impl::operator new(size_t n) +{ + return rtl_allocateMemory(n); +} +void DirectoryItem_Impl::operator delete(void * p, size_t) +{ + rtl_freeMemory(p); +} + +void DirectoryItem_Impl::acquire() +{ + ++m_RefCount; +} +void DirectoryItem_Impl::release() +{ + if (0 == --m_RefCount) + delete this; +} + +oslFileType DirectoryItem_Impl::getFileType() const +{ + switch (m_DType) + { +#ifdef _DIRENT_HAVE_D_TYPE + case DT_LNK: + return osl_File_Type_Link; + case DT_DIR: + return osl_File_Type_Directory; + case DT_REG: + return osl_File_Type_Regular; + case DT_FIFO: + return osl_File_Type_Fifo; + case DT_SOCK: + return osl_File_Type_Socket; + case DT_CHR: + case DT_BLK: + return osl_File_Type_Special; +#endif /* _DIRENT_HAVE_D_TYPE */ + default: + break; + } + return osl_File_Type_Unknown; +} + +/****************************************************************************** + * + * C-String Function Declarations + * + *****************************************************************************/ + +static oslFileError osl_psz_createDirectory(const sal_Char* pszPath); +static oslFileError osl_psz_removeDirectory(const sal_Char* pszPath); + +/******************************************************************* + * osl_openDirectory + ******************************************************************/ + +oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirectory* pDirectory) +{ + rtl_uString* ustrSystemPath = NULL; + oslFileError eRet; + + char path[PATH_MAX]; + + if ((0 == ustrDirectoryURL) || (0 == ustrDirectoryURL->length) || (0 == pDirectory)) + return osl_File_E_INVAL; + + /* convert file URL to system path */ + eRet = osl_getSystemPathFromFileURL_Ex(ustrDirectoryURL, &ustrSystemPath, sal_False); + + if( osl_File_E_None != eRet ) + return eRet; + + osl_systemPathRemoveSeparator(ustrSystemPath); + + /* convert unicode path to text */ + if ( UnicodeToText( path, PATH_MAX, ustrSystemPath->buffer, ustrSystemPath->length ) +#ifdef MACOSX + && macxp_resolveAlias( path, PATH_MAX ) == 0 +#endif /* MACOSX */ + ) + { + /* open directory */ + DIR *pdir = opendir( path ); + + if( pdir ) + { + /* create and initialize impl structure */ + oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) rtl_allocateMemory( sizeof(oslDirectoryImpl) ); + + if( pDirImpl ) + { + pDirImpl->pDirStruct = pdir; + pDirImpl->ustrPath = ustrSystemPath; + + *pDirectory = (oslDirectory) pDirImpl; + return osl_File_E_None; + } + else + { + errno = ENOMEM; + closedir( pdir ); + } + } + else + { +#ifdef DEBUG_OSL_FILE + perror ("osl_openDirectory"); fprintf (stderr, path); +#endif + } + } + + rtl_uString_release( ustrSystemPath ); + + return oslTranslateFileError(OSL_FET_ERROR, errno); +} + +/****************************************************************************/ +/* osl_closeDirectory */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_closeDirectory( oslDirectory Directory ) +{ + oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) Directory; + oslFileError err = osl_File_E_None; + + OSL_ASSERT( Directory ); + + if( NULL == pDirImpl ) + return osl_File_E_INVAL; + + /* close directory */ + if( closedir( pDirImpl->pDirStruct ) ) + { + err = oslTranslateFileError(OSL_FET_ERROR, errno); + } + + /* cleanup members */ + rtl_uString_release( pDirImpl->ustrPath ); + + rtl_freeMemory( pDirImpl ); + + return err; +} + +/********************************************** + * osl_readdir_impl_ + * + * readdir wrapper, filters out "." and ".." + * on request + *********************************************/ + +static struct dirent* osl_readdir_impl_(DIR* pdir, sal_Bool bFilterLocalAndParentDir) +{ + struct dirent* pdirent; + + while ((pdirent = readdir(pdir)) != NULL) + { + if (bFilterLocalAndParentDir && + ((0 == strcmp(pdirent->d_name, ".")) || (0 == strcmp(pdirent->d_name, "..")))) + continue; + else + break; + } + + return pdirent; +} + +/**************************************************************************** + * osl_getNextDirectoryItem + ***************************************************************************/ + +oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory Directory, oslDirectoryItem* pItem, sal_uInt32 /*uHint*/) +{ + oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*)Directory; + rtl_uString* ustrFileName = NULL; + rtl_uString* ustrFilePath = NULL; + struct dirent* pEntry; + + OSL_ASSERT(Directory); + OSL_ASSERT(pItem); + + if ((NULL == Directory) || (NULL == pItem)) + return osl_File_E_INVAL; + + pEntry = osl_readdir_impl_(pDirImpl->pDirStruct, sal_True); + + if (NULL == pEntry) + return osl_File_E_NOENT; + + +#if defined(MACOSX) + + // convert decomposed filename to precomposed unicode + char composed_name[BUFSIZ]; + CFMutableStringRef strRef = CFStringCreateMutable (NULL, 0 ); + CFStringAppendCString( strRef, pEntry->d_name, kCFStringEncodingUTF8 ); //UTF8 is default on Mac OSX + CFStringNormalize( strRef, kCFStringNormalizationFormC ); + CFStringGetCString( strRef, composed_name, BUFSIZ, kCFStringEncodingUTF8 ); + CFRelease( strRef ); + rtl_string2UString( &ustrFileName, composed_name, strlen( composed_name), + osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); + +#else // not MACOSX + /* convert file name to unicode */ + rtl_string2UString( &ustrFileName, pEntry->d_name, strlen( pEntry->d_name ), + osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); + OSL_ASSERT(ustrFileName != 0); + +#endif + + osl_systemPathMakeAbsolutePath(pDirImpl->ustrPath, ustrFileName, &ustrFilePath); + rtl_uString_release( ustrFileName ); + + DirectoryItem_Impl * pImpl = static_cast< DirectoryItem_Impl* >(*pItem); + if (0 != pImpl) + { + pImpl->release(), pImpl = 0; + } +#ifdef _DIRENT_HAVE_D_TYPE + pImpl = new DirectoryItem_Impl(ustrFilePath, pEntry->d_type); +#else + pImpl = new DirectoryItem_Impl(ustrFilePath); +#endif /* _DIRENT_HAVE_D_TYPE */ + *pItem = pImpl; + rtl_uString_release( ustrFilePath ); + + return osl_File_E_None; +} + +/****************************************************************************/ +/* osl_getDirectoryItem */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_getDirectoryItem( rtl_uString* ustrFileURL, oslDirectoryItem* pItem ) +{ + rtl_uString* ustrSystemPath = NULL; + oslFileError osl_error = osl_File_E_INVAL; + + OSL_ASSERT(ustrFileURL); + OSL_ASSERT(pItem); + + if (0 == ustrFileURL->length || NULL == pItem) + return osl_File_E_INVAL; + + osl_error = osl_getSystemPathFromFileURL_Ex(ustrFileURL, &ustrSystemPath, sal_False); + if (osl_File_E_None != osl_error) + return osl_error; + + osl_systemPathRemoveSeparator(ustrSystemPath); + + if (-1 == access_u(ustrSystemPath, F_OK)) + { + osl_error = oslTranslateFileError(OSL_FET_ERROR, errno); + } + else + { + *pItem = new DirectoryItem_Impl(ustrSystemPath); + } + rtl_uString_release(ustrSystemPath); + + return osl_error; +} + + +/****************************************************************************/ +/* osl_acquireDirectoryItem */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_acquireDirectoryItem( oslDirectoryItem Item ) +{ + DirectoryItem_Impl * pImpl = static_cast< DirectoryItem_Impl* >(Item); + if (0 == pImpl) + return osl_File_E_INVAL; + + pImpl->acquire(); + return osl_File_E_None; +} + +/****************************************************************************/ +/* osl_releaseDirectoryItem */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_releaseDirectoryItem( oslDirectoryItem Item ) +{ + DirectoryItem_Impl * pImpl = static_cast< DirectoryItem_Impl* >(Item); + if (0 == pImpl) + return osl_File_E_INVAL; + + pImpl->release(); + return osl_File_E_None; +} + +/****************************************************************************/ +/* osl_createDirectory */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_createDirectory( rtl_uString* ustrDirectoryURL ) +{ + char path[PATH_MAX]; + oslFileError eRet; + + OSL_ASSERT( ustrDirectoryURL ); + + /* convert directory url to system path */ + eRet = FileURLToPath( path, PATH_MAX, ustrDirectoryURL ); + if( eRet != osl_File_E_None ) + return eRet; + +#ifdef MACOSX + if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) + return oslTranslateFileError( OSL_FET_ERROR, errno ); +#endif/* MACOSX */ + + return osl_psz_createDirectory( path ); +} + +/****************************************************************************/ +/* osl_removeDirectory */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_removeDirectory( rtl_uString* ustrDirectoryURL ) +{ + char path[PATH_MAX]; + oslFileError eRet; + + OSL_ASSERT( ustrDirectoryURL ); + + /* convert directory url to system path */ + eRet = FileURLToPath( path, PATH_MAX, ustrDirectoryURL ); + if( eRet != osl_File_E_None ) + return eRet; + +#ifdef MACOSX + if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) + return oslTranslateFileError( OSL_FET_ERROR, errno ); +#endif/* MACOSX */ + + return osl_psz_removeDirectory( path ); +} + +/***************************************** + * osl_psz_createDirectory + ****************************************/ + +static oslFileError osl_psz_createDirectory( const sal_Char* pszPath ) +{ + int nRet=0; + int mode = S_IRWXU | S_IRWXG | S_IRWXO; + + nRet = mkdir(pszPath,mode); + + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + return osl_File_E_None; +} + +/***************************************** + * osl_psz_removeDirectory + ****************************************/ + +static oslFileError osl_psz_removeDirectory( const sal_Char* pszPath ) +{ + int nRet=0; + + nRet = rmdir(pszPath); + + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + return osl_File_E_None; +} + +/****************************************************************************/ +/* osl_createDirectoryPath */ +/****************************************************************************/ + +static int path_make_parent(sal_Unicode* path) +{ + int i = rtl_ustr_lastIndexOfChar(path, '/'); + + if (i > 0) + { + *(path + i) = 0; + return i; + } + else + return 0; +} + +static int create_dir_with_callback( + sal_Unicode* directory_path, + oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, + void* pData) +{ + int mode = S_IRWXU | S_IRWXG | S_IRWXO; + + if (osl::mkdir(directory_path, mode) == 0) + { + if (aDirectoryCreationCallbackFunc) + { + rtl::OUString url; + osl::FileBase::getFileURLFromSystemPath(directory_path, url); + aDirectoryCreationCallbackFunc(pData, url.pData); + } + return 0; + } + return errno; +} + +static oslFileError create_dir_recursively_( + sal_Unicode* dir_path, + oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, + void* pData) +{ + OSL_PRECOND((rtl_ustr_getLength(dir_path) > 0) && ((dir_path + (rtl_ustr_getLength(dir_path) - 1)) != (dir_path + rtl_ustr_lastIndexOfChar(dir_path, '/'))), \ + "Path must not end with a slash"); + + int native_err = create_dir_with_callback( + dir_path, aDirectoryCreationCallbackFunc, pData); + + if (native_err == 0) + return osl_File_E_None; + + if (native_err != ENOENT) + return oslTranslateFileError(OSL_FET_ERROR, native_err); + + // we step back until '/a_dir' at maximum because + // we should get an error unequal ENOENT when + // we try to create 'a_dir' at '/' and would so + // return before + int pos = path_make_parent(dir_path); + + oslFileError osl_error = create_dir_recursively_( + dir_path, aDirectoryCreationCallbackFunc, pData); + + if (osl_File_E_None != osl_error) + return osl_error; + + dir_path[pos] = '/'; + + return create_dir_recursively_(dir_path, aDirectoryCreationCallbackFunc, pData); +} + +oslFileError SAL_CALL osl_createDirectoryPath( + rtl_uString* aDirectoryUrl, + oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, + void* pData) +{ + if (aDirectoryUrl == NULL) + return osl_File_E_INVAL; + + rtl::OUString sys_path; + oslFileError osl_error = osl_getSystemPathFromFileURL_Ex( + aDirectoryUrl, &sys_path.pData, sal_False); + + if (osl_error != osl_File_E_None) + return osl_error; + + osl::systemPathRemoveSeparator(sys_path); + + // const_cast because sys_path is a local copy which we want to modify inplace instead of + // coyp it into another buffer on the heap again + return create_dir_recursively_(sys_path.pData->buffer, aDirectoryCreationCallbackFunc, pData); +} + +/****************************************************************************** + * + * C-String Function Declarations + * + *****************************************************************************/ + +static oslFileError osl_psz_removeFile(const sal_Char* pszPath); +static oslFileError osl_psz_copyFile(const sal_Char* pszPath, const sal_Char* pszDestPath); +static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* pszDestPath); + + +/****************************************************************************** + * + * Static Module Utility Function Declarations + * + *****************************************************************************/ + +static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, mode_t nMode, size_t nSourceSize, int DestFileExists); +static oslFileError oslChangeFileModes(const sal_Char* pszFileName, mode_t nMode, time_t nAcTime, time_t nModTime, uid_t nUID, gid_t nGID); +static int oslDoCopyLink(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName); +static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, size_t nSourceSize, mode_t mode); +static oslFileError oslDoMoveFile(const sal_Char* pszPath, const sal_Char* pszDestPath); + +/****************************************************************************/ +/* osl_moveFile */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_moveFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL ) +{ + char srcPath[PATH_MAX]; + char destPath[PATH_MAX]; + oslFileError eRet; + + OSL_ASSERT( ustrFileURL ); + OSL_ASSERT( ustrDestURL ); + + /* convert source url to system path */ + eRet = FileURLToPath( srcPath, PATH_MAX, ustrFileURL ); + if( eRet != osl_File_E_None ) + return eRet; + + /* convert destination url to system path */ + eRet = FileURLToPath( destPath, PATH_MAX, ustrDestURL ); + if( eRet != osl_File_E_None ) + return eRet; + +#ifdef MACOSX + if ( macxp_resolveAlias( srcPath, PATH_MAX ) != 0 || macxp_resolveAlias( destPath, PATH_MAX ) != 0 ) + return oslTranslateFileError( OSL_FET_ERROR, errno ); +#endif/* MACOSX */ + + return oslDoMoveFile( srcPath, destPath ); +} + +/****************************************************************************/ +/* osl_copyFile */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_copyFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL ) +{ + char srcPath[PATH_MAX]; + char destPath[PATH_MAX]; + oslFileError eRet; + + OSL_ASSERT( ustrFileURL ); + OSL_ASSERT( ustrDestURL ); + + /* convert source url to system path */ + eRet = FileURLToPath( srcPath, PATH_MAX, ustrFileURL ); + if( eRet != osl_File_E_None ) + return eRet; + + /* convert destination url to system path */ + eRet = FileURLToPath( destPath, PATH_MAX, ustrDestURL ); + if( eRet != osl_File_E_None ) + return eRet; + +#ifdef MACOSX + if ( macxp_resolveAlias( srcPath, PATH_MAX ) != 0 || macxp_resolveAlias( destPath, PATH_MAX ) != 0 ) + return oslTranslateFileError( OSL_FET_ERROR, errno ); +#endif/* MACOSX */ + + return osl_psz_copyFile( srcPath, destPath ); +} + +/****************************************************************************/ +/* osl_removeFile */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_removeFile( rtl_uString* ustrFileURL ) +{ + char path[PATH_MAX]; + oslFileError eRet; + + OSL_ASSERT( ustrFileURL ); + + /* convert file url to system path */ + eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); + if( eRet != osl_File_E_None ) + return eRet; + +#ifdef MACOSX + if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) + return oslTranslateFileError( OSL_FET_ERROR, errno ); +#endif/* MACOSX */ + + return osl_psz_removeFile( path ); +} + +/****************************************************************************** + * + * Utility Functions + * + *****************************************************************************/ + +/***************************************** + * oslDoMoveFile + ****************************************/ + +static oslFileError oslDoMoveFile( const sal_Char* pszPath, const sal_Char* pszDestPath) +{ + oslFileError tErr=osl_File_E_invalidError; + + tErr = osl_psz_moveFile(pszPath,pszDestPath); + if ( tErr == osl_File_E_None ) + { + return tErr; + } + + if ( tErr != osl_File_E_XDEV ) + { + return tErr; + } + + tErr=osl_psz_copyFile(pszPath,pszDestPath); + + if ( tErr != osl_File_E_None ) + { + oslFileError tErrRemove; + tErrRemove=osl_psz_removeFile(pszDestPath); + return tErr; + } + + tErr=osl_psz_removeFile(pszPath); + + return tErr; +} + +/***************************************** + * osl_psz_removeFile + ****************************************/ +static oslFileError osl_psz_removeFile( const sal_Char* pszPath ) +{ + int nRet=0; + struct stat aStat; + + nRet = lstat(pszPath,&aStat); + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + if ( S_ISDIR(aStat.st_mode) ) + { + return osl_File_E_ISDIR; + } + + nRet = unlink(pszPath); + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + return osl_File_E_None; +} + +/***************************************** + * osl_psz_moveFile + ****************************************/ + +static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* pszDestPath) +{ + + int nRet = 0; + + nRet = rename(pszPath,pszDestPath); + + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + return osl_File_E_None; +} + +/***************************************** + * osl_psz_copyFile + ****************************************/ + +static oslFileError osl_psz_copyFile( const sal_Char* pszPath, const sal_Char* pszDestPath ) +{ + time_t nAcTime=0; + time_t nModTime=0; + uid_t nUID=0; + gid_t nGID=0; + int nRet=0; + mode_t nMode=0; + struct stat aFileStat; + oslFileError tErr=osl_File_E_invalidError; + size_t nSourceSize=0; + int DestFileExists=1; + + /* mfe: does the source file really exists? */ + nRet = lstat(pszPath,&aFileStat); + + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + /* mfe: we do only copy files here! */ + if ( S_ISDIR(aFileStat.st_mode) ) + { + return osl_File_E_ISDIR; + } + + nSourceSize=(size_t)aFileStat.st_size; + nMode=aFileStat.st_mode; + nAcTime=aFileStat.st_atime; + nModTime=aFileStat.st_mtime; + nUID=aFileStat.st_uid; + nGID=aFileStat.st_gid; + + nRet = stat(pszDestPath,&aFileStat); + if ( nRet < 0 ) + { + nRet=errno; + + if ( nRet == ENOENT ) + { + DestFileExists=0; + } +/* return oslTranslateFileError(nRet);*/ + } + + /* mfe: the destination file must not be a directory! */ + if ( nRet == 0 && S_ISDIR(aFileStat.st_mode) ) + { + return osl_File_E_ISDIR; + } + else + { + /* mfe: file does not exists or is no dir */ + } + + tErr = oslDoCopy(pszPath,pszDestPath,nMode,nSourceSize,DestFileExists); + + if ( tErr != osl_File_E_None ) + { + return tErr; + } + + /* + * mfe: ignore return code + * since only the success of the copy is + * important + */ + oslChangeFileModes(pszDestPath,nMode,nAcTime,nModTime,nUID,nGID); + + return tErr; +} + + +/****************************************************************************** + * + * Utility Functions + * + *****************************************************************************/ + +/***************************************** + * oslDoCopy + ****************************************/ + +#define TMP_DEST_FILE_EXTENSION ".osl-tmp" + +static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, mode_t nMode, size_t nSourceSize, int DestFileExists) +{ + int nRet=0; + sal_Char pszTmpDestFile[PATH_MAX]; + size_t size_tmp_dest_buff = sizeof(pszTmpDestFile); + + /* Quick fix for #106048, the whole copy file function seems + to be erroneous anyway and needs to be rewritten. + Besides osl_copyFile is currently not used from OO/SO code. + */ + memset(pszTmpDestFile, 0, size_tmp_dest_buff); + + if ( DestFileExists ) + { + strncpy(pszTmpDestFile, pszDestFileName, size_tmp_dest_buff - 1); + + if ((strlen(pszTmpDestFile) + strlen(TMP_DEST_FILE_EXTENSION)) >= size_tmp_dest_buff) + return osl_File_E_NAMETOOLONG; + + strncat(pszTmpDestFile, TMP_DEST_FILE_EXTENSION, strlen(TMP_DEST_FILE_EXTENSION)); + + /* FIXME: what if pszTmpDestFile already exists? */ + /* with getcanonical??? */ + nRet=rename(pszDestFileName,pszTmpDestFile); + } + + /* mfe: should be S_ISREG */ + if ( !S_ISLNK(nMode) ) + { + /* copy SourceFile to DestFile */ + nRet = oslDoCopyFile(pszSourceFileName,pszDestFileName,nSourceSize, nMode); + } + /* mfe: OK redundant at the moment */ + else if ( S_ISLNK(nMode) ) + { + nRet = oslDoCopyLink(pszSourceFileName,pszDestFileName); + } + else + { + /* mfe: what to do here? */ + nRet=ENOSYS; + } + + if ( nRet > 0 && DestFileExists == 1 ) + { + unlink(pszDestFileName); + rename(pszTmpDestFile,pszDestFileName); + } + + if ( nRet > 0 ) + { + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + if ( DestFileExists == 1 ) + { + unlink(pszTmpDestFile); + } + + return osl_File_E_None; +} + +/***************************************** + * oslChangeFileModes + ****************************************/ + +static oslFileError oslChangeFileModes( const sal_Char* pszFileName, mode_t nMode, time_t nAcTime, time_t nModTime, uid_t nUID, gid_t nGID) +{ + int nRet=0; + struct utimbuf aTimeBuffer; + + nRet = chmod(pszFileName,nMode); + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + aTimeBuffer.actime=nAcTime; + aTimeBuffer.modtime=nModTime; + nRet=utime(pszFileName,&aTimeBuffer); + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + if ( nUID != getuid() ) + { + nUID=getuid(); + } + + nRet=chown(pszFileName,nUID,nGID); + if ( nRet < 0 ) + { + nRet=errno; + + /* mfe: do not return an error here! */ + /* return oslTranslateFileError(nRet);*/ + } + + return osl_File_E_None; +} + +/***************************************** + * oslDoCopyLink + ****************************************/ + +static int oslDoCopyLink(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName) +{ + int nRet=0; + + /* mfe: if dest file is symbolic link remove the link and place the file instead (hro says so) */ + /* mfe: if source is a link copy the link and not the file it points to (hro says so) */ + sal_Char pszLinkContent[PATH_MAX]; + + pszLinkContent[0] = '\0'; + + nRet = readlink(pszSourceFileName,pszLinkContent,PATH_MAX); + + if ( nRet < 0 ) + { + nRet=errno; + return nRet; + } + else + pszLinkContent[ nRet ] = 0; + + nRet = symlink(pszLinkContent,pszDestFileName); + + if ( nRet < 0 ) + { + nRet=errno; + return nRet; + } + + return 0; +} + +/***************************************** + * oslDoCopyFile + ****************************************/ + +static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, size_t nSourceSize, mode_t mode) +{ + int SourceFileFD=0; + int DestFileFD=0; + int nRet=0; + void* pSourceFile=0; + + SourceFileFD=open(pszSourceFileName,O_RDONLY); + if ( SourceFileFD < 0 ) + { + nRet=errno; + return nRet; + } + + DestFileFD=open(pszDestFileName, O_WRONLY | O_CREAT, mode); + + if ( DestFileFD < 0 ) + { + nRet=errno; + close(SourceFileFD); + return nRet; + } + + /* HACK: because memory mapping fails on various + platforms if the size of the source file is 0 byte */ + if (0 == nSourceSize) + { + close(SourceFileFD); + close(DestFileFD); + return 0; + } + + /* FIXME doCopy: fall back code for systems not having mmap */ + /* mmap file -- open dest file -- write once -- fsync it */ + pSourceFile=mmap(0,nSourceSize,PROT_READ,MAP_PRIVATE,SourceFileFD,0); + + if ( pSourceFile == MAP_FAILED ) + { + /* it's important to set nRet before the hack + otherwise errno may be changed by lstat */ + nRet = errno; + close(SourceFileFD); + close(DestFileFD); + + return nRet; + } + + nRet = write(DestFileFD,pSourceFile,nSourceSize); + + /* #112584# if 'write' could not write the requested number of bytes + we have to fail of course; because it's not exactly specified if 'write' + sets errno if less than requested byte could be written we set nRet + explicitly to ENOSPC */ + if ((nRet < 0) || (nRet != sal::static_int_cast< int >(nSourceSize))) + { + if (nRet < 0) + nRet = errno; + else + nRet = ENOSPC; + + close(SourceFileFD); + close(DestFileFD); + munmap((char*)pSourceFile,nSourceSize); + return nRet; + } + + nRet = munmap((char*)pSourceFile,nSourceSize); + if ( nRet < 0 ) + { + nRet=errno; + close(SourceFileFD); + close(DestFileFD); + return nRet; + } + + close(SourceFileFD); + + // Removed call to 'fsync' again (#112584#) and instead + // evaluate the return value of 'close' in order to detect + // and report ENOSPC and other erronous conditions on close + if (close(DestFileFD) == -1) + return errno; + else + return 0; +} diff --git a/sal/osl/unx/file_stat.cxx b/sal/osl/unx/file_stat.cxx index 3a710743a1b2..d56c2a1fad6a 100644 --- a/sal/osl/unx/file_stat.cxx +++ b/sal/osl/unx/file_stat.cxx @@ -31,39 +31,20 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sal.hxx" -#ifndef _TYPES_H -#include -#endif - -#ifndef _LIMITS_H -#include -#endif - -#ifndef _UNISTD_H -#include -#endif +#include "osl/file.h" -#ifndef _DIRENT_H +#include "system.h" +#include #include -#endif - -#include - -#ifndef _ERRNO_H #include -#endif - -#include - -#ifndef _OSL_UUNXAPI_H_ -#include "uunxapi.hxx" -#endif -#include "file_path_helper.hxx" -#include "file_error_transl.h" +#include +#include -#ifdef _DIRENT_HAVE_D_TYPE #include "file_impl.hxx" -#endif +#include "file_error_transl.h" +#include "file_path_helper.hxx" +#include "file_url.h" +#include "uunxapi.hxx" namespace /* private */ { @@ -231,19 +212,10 @@ namespace /* private */ /* we only need to call stat or lstat if one of the following flags is set */ -#ifdef _DIRENT_HAVE_D_TYPE - inline bool is_stat_call_necessary(sal_uInt32 field_mask, oslDirectoryItemImpl *pImpl) -#else - inline bool is_stat_call_necessary(sal_uInt32 field_mask) -#endif + inline bool is_stat_call_necessary(sal_uInt32 field_mask, oslFileType file_type = osl_File_Type_Unknown) { return ( -/* on linux the dirent might have d_type */ -#ifdef _DIRENT_HAVE_D_TYPE - ((field_mask & osl_FileStatus_Mask_Type) && (!pImpl->bHasType || pImpl->DType == DT_UNKNOWN)) || -#else - (field_mask & osl_FileStatus_Mask_Type) || -#endif + ((field_mask & osl_FileStatus_Mask_Type) && (file_type == osl_File_Type_Unknown)) || (field_mask & osl_FileStatus_Mask_Attributes) || (field_mask & osl_FileStatus_Mask_CreationTime) || (field_mask & osl_FileStatus_Mask_AccessTime) || @@ -267,24 +239,18 @@ namespace /* private */ return osl_File_E_None; } - inline oslFileError setup_osl_getFileStatus(oslDirectoryItem Item, oslFileStatus* pStat, rtl::OUString& file_path) + inline oslFileError setup_osl_getFileStatus( + DirectoryItem_Impl * pImpl, oslFileStatus* pStat, rtl::OUString& file_path) { - if ((NULL == Item) || (NULL == pStat)) + if ((NULL == pImpl) || (NULL == pStat)) return osl_File_E_INVAL; -#ifdef _DIRENT_HAVE_D_TYPE - file_path = rtl::OUString(reinterpret_cast(((oslDirectoryItemImpl* ) Item)->ustrFilePath)); -#else - file_path = rtl::OUString(reinterpret_cast(Item)); -#endif - + file_path = rtl::OUString(pImpl->m_ustrFilePath); OSL_ASSERT(file_path.getLength() > 0); - if (file_path.getLength() <= 0) return osl_File_E_INVAL; pStat->uValidFields = 0; - return osl_File_E_None; } @@ -297,8 +263,10 @@ namespace /* private */ oslFileError SAL_CALL osl_getFileStatus(oslDirectoryItem Item, oslFileStatus* pStat, sal_uInt32 uFieldMask) { + DirectoryItem_Impl * pImpl = static_cast< DirectoryItem_Impl* >(Item); + rtl::OUString file_path; - oslFileError osl_error = setup_osl_getFileStatus(Item, pStat, file_path); + oslFileError osl_error = setup_osl_getFileStatus(pImpl, pStat, file_path); if (osl_File_E_None != osl_error) return osl_error; @@ -308,13 +276,7 @@ oslFileError SAL_CALL osl_getFileStatus(oslDirectoryItem Item, oslFileStatus* pS struct stat file_stat; #endif -#ifdef _DIRENT_HAVE_D_TYPE - oslDirectoryItemImpl* pImpl = (oslDirectoryItemImpl*) Item; - bool bStatNeeded = is_stat_call_necessary(uFieldMask, pImpl); -#else - bool bStatNeeded = is_stat_call_necessary(uFieldMask); -#endif - + bool bStatNeeded = is_stat_call_necessary(uFieldMask, pImpl->getFileType()); if (bStatNeeded && (0 != osl::lstat(file_path, file_stat))) return oslTranslateFileError(OSL_FET_ERROR, errno); @@ -338,37 +300,10 @@ oslFileError SAL_CALL osl_getFileStatus(oslDirectoryItem Item, oslFileStatus* pS #ifdef _DIRENT_HAVE_D_TYPE else if (uFieldMask & osl_FileStatus_Mask_Type) { - OSL_ASSERT(pImpl->bHasType); - - switch(pImpl->DType) - { - case DT_LNK: - pStat->eType = osl_File_Type_Link; - break; - case DT_DIR: - pStat->eType = osl_File_Type_Directory; - break; - case DT_REG: - pStat->eType = osl_File_Type_Regular; - break; - case DT_FIFO: - pStat->eType = osl_File_Type_Fifo; - break; - case DT_SOCK: - pStat->eType = osl_File_Type_Socket; - break; - case DT_CHR: - case DT_BLK: - pStat->eType = osl_File_Type_Special; - break; - default: - OSL_ASSERT(0); - pStat->eType = osl_File_Type_Unknown; - } - - pStat->uValidFields |= osl_FileStatus_Mask_Type; + pStat->eType = pImpl->getFileType(); + pStat->uValidFields |= osl_FileStatus_Mask_Type; } -#endif +#endif /* _DIRENT_HAVE_D_TYPE */ if (uFieldMask & osl_FileStatus_Mask_FileURL) { @@ -386,3 +321,175 @@ oslFileError SAL_CALL osl_getFileStatus(oslDirectoryItem Item, oslFileStatus* pS return osl_File_E_None; } +/****************************************************************************/ +/* osl_setFileAttributes */ +/****************************************************************************/ + +static oslFileError osl_psz_setFileAttributes( const sal_Char* pszFilePath, sal_uInt64 uAttributes ) +{ + oslFileError osl_error = osl_File_E_None; + mode_t nNewMode = 0; + + OSL_ENSURE(!(osl_File_Attribute_Hidden & uAttributes), "osl_File_Attribute_Hidden doesn't work under Unix"); + + if (uAttributes & osl_File_Attribute_OwnRead) + nNewMode |= S_IRUSR; + + if (uAttributes & osl_File_Attribute_OwnWrite) + nNewMode|=S_IWUSR; + + if (uAttributes & osl_File_Attribute_OwnExe) + nNewMode|=S_IXUSR; + + if (uAttributes & osl_File_Attribute_GrpRead) + nNewMode|=S_IRGRP; + + if (uAttributes & osl_File_Attribute_GrpWrite) + nNewMode|=S_IWGRP; + + if (uAttributes & osl_File_Attribute_GrpExe) + nNewMode|=S_IXGRP; + + if (uAttributes & osl_File_Attribute_OthRead) + nNewMode|=S_IROTH; + + if (uAttributes & osl_File_Attribute_OthWrite) + nNewMode|=S_IWOTH; + + if (uAttributes & osl_File_Attribute_OthExe) + nNewMode|=S_IXOTH; + + if (chmod(pszFilePath, nNewMode) < 0) + osl_error = oslTranslateFileError(OSL_FET_ERROR, errno); + + return osl_error; +} + +oslFileError SAL_CALL osl_setFileAttributes( rtl_uString* ustrFileURL, sal_uInt64 uAttributes ) +{ + char path[PATH_MAX]; + oslFileError eRet; + + OSL_ASSERT( ustrFileURL ); + + /* convert file url to system path */ + eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); + if( eRet != osl_File_E_None ) + return eRet; + +#ifdef MACOSX + if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) + return oslTranslateFileError( OSL_FET_ERROR, errno ); +#endif/* MACOSX */ + + return osl_psz_setFileAttributes( path, uAttributes ); +} + +/****************************************************************************/ +/* osl_setFileTime */ +/****************************************************************************/ + +static oslFileError osl_psz_setFileTime ( + const sal_Char* pszFilePath, + const TimeValue* /*pCreationTime*/, + const TimeValue* pLastAccessTime, + const TimeValue* pLastWriteTime ) +{ + int nRet=0; + struct utimbuf aTimeBuffer; + struct stat aFileStat; +#ifdef DEBUG_OSL_FILE + struct tm* pTM=0; +#endif + + nRet = lstat(pszFilePath,&aFileStat); + + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"File Times are (in localtime):\n"); + pTM=localtime(&aFileStat.st_ctime); + fprintf(stderr,"CreationTime is '%s'\n",asctime(pTM)); + pTM=localtime(&aFileStat.st_atime); + fprintf(stderr,"AccessTime is '%s'\n",asctime(pTM)); + pTM=localtime(&aFileStat.st_mtime); + fprintf(stderr,"Modification is '%s'\n",asctime(pTM)); + + fprintf(stderr,"File Times are (in UTC):\n"); + fprintf(stderr,"CreationTime is '%s'\n",ctime(&aFileStat.st_ctime)); + fprintf(stderr,"AccessTime is '%s'\n",ctime(&aTimeBuffer.actime)); + fprintf(stderr,"Modification is '%s'\n",ctime(&aTimeBuffer.modtime)); +#endif + + if ( pLastAccessTime != 0 ) + { + aTimeBuffer.actime=pLastAccessTime->Seconds; + } + else + { + aTimeBuffer.actime=aFileStat.st_atime; + } + + if ( pLastWriteTime != 0 ) + { + aTimeBuffer.modtime=pLastWriteTime->Seconds; + } + else + { + aTimeBuffer.modtime=aFileStat.st_mtime; + } + + /* mfe: Creation time not used here! */ + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"File Times are (in localtime):\n"); + pTM=localtime(&aFileStat.st_ctime); + fprintf(stderr,"CreationTime now '%s'\n",asctime(pTM)); + pTM=localtime(&aTimeBuffer.actime); + fprintf(stderr,"AccessTime now '%s'\n",asctime(pTM)); + pTM=localtime(&aTimeBuffer.modtime); + fprintf(stderr,"Modification now '%s'\n",asctime(pTM)); + + fprintf(stderr,"File Times are (in UTC):\n"); + fprintf(stderr,"CreationTime now '%s'\n",ctime(&aFileStat.st_ctime)); + fprintf(stderr,"AccessTime now '%s'\n",ctime(&aTimeBuffer.actime)); + fprintf(stderr,"Modification now '%s'\n",ctime(&aTimeBuffer.modtime)); +#endif + + nRet=utime(pszFilePath,&aTimeBuffer); + if ( nRet < 0 ) + { + nRet=errno; + return oslTranslateFileError(OSL_FET_ERROR, nRet); + } + + return osl_File_E_None; +} + +oslFileError SAL_CALL osl_setFileTime ( + rtl_uString* ustrFileURL, + const TimeValue* pCreationTime, + const TimeValue* pLastAccessTime, + const TimeValue* pLastWriteTime ) +{ + char path[PATH_MAX]; + oslFileError eRet; + + OSL_ASSERT( ustrFileURL ); + + /* convert file url to system path */ + eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); + if( eRet != osl_File_E_None ) + return eRet; + +#ifdef MACOSX + if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) + return oslTranslateFileError( OSL_FET_ERROR, errno ); +#endif/* MACOSX */ + + return osl_psz_setFileTime( path, pCreationTime, pLastAccessTime, pLastWriteTime ); +} diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx index 1d6b9172bc6d..1bcd2afb4505 100644 --- a/sal/osl/unx/file_url.cxx +++ b/sal/osl/unx/file_url.cxx @@ -30,45 +30,31 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sal.hxx" + +#include "file_url.h" + #include "system.h" -#ifndef _LIMITS_H #include -#endif - -#ifndef _ERRNO_H #include -#endif - -#ifndef _STRINGS_H #include -#endif - -#ifndef _UNISTD_H #include -#endif -#include + +#include "osl/file.hxx" #include -#include #include +#include +#include + +#include #include #include +#include "rtl/textcvt.h" -#ifndef _OSL_TREAD_H_ -#include -#endif -#include -#include #include "file_error_transl.h" - -#ifndef _FILE_URL_H_ -#include "file_url.h" -#endif #include "file_path_helper.hxx" -#ifndef _OSL_UUNXAPI_HXX_ #include "uunxapi.hxx" -#endif /*************************************************** @@ -84,16 +70,14 @@ so this code should be consolidated. **************************************************/ +/************************************************************************ + * ToDo + * + * Fix osl_getCanonicalName + * + ***********************************************************************/ - -/*************************************************** - * forward - **************************************************/ - -extern "C" int UnicodeToText(char *, size_t, const sal_Unicode *, sal_Int32); -extern "C" int TextToUnicode(const char* text, size_t text_buffer_size, sal_Unicode* unic_text, sal_Int32 unic_text_buffer_size); - /*************************************************** * namespace directives **************************************************/ @@ -150,6 +134,18 @@ static sal_Bool findWrongUsage( const sal_Unicode *path, sal_Int32 len ) } */ +/****************************************************************************/ +/* osl_getCanonicalName */ +/****************************************************************************/ + +oslFileError SAL_CALL osl_getCanonicalName( rtl_uString* ustrFileURL, rtl_uString** pustrValidURL ) +{ + OSL_ENSURE(0, "osl_getCanonicalName not implemented"); + + rtl_uString_newFromString(pustrValidURL, ustrFileURL); + return osl_File_E_None; +} + /****************************************************************************/ /* osl_getSystemPathFromFileURL */ /****************************************************************************/ @@ -850,3 +846,120 @@ oslFileError FileURLToPath(char * buffer, size_t bufLen, rtl_uString* ustrFileUR return osl_error; } + +/***************************************************************************** + * UnicodeToText + ****************************************************************************/ + +namespace /* private */ +{ + class UnicodeToTextConverter_Impl + { + rtl_UnicodeToTextConverter m_converter; + + UnicodeToTextConverter_Impl() + : m_converter (rtl_createUnicodeToTextConverter (osl_getThreadTextEncoding())) + {} + + ~UnicodeToTextConverter_Impl() + { + rtl_destroyUnicodeToTextConverter (m_converter); + } + public: + static UnicodeToTextConverter_Impl & getInstance() + { + static UnicodeToTextConverter_Impl g_theConverter; + return g_theConverter; + } + + sal_Size convert( + sal_Unicode const * pSrcBuf, sal_Size nSrcChars, sal_Char * pDstBuf, sal_Size nDstBytes, + sal_uInt32 nFlags, sal_uInt32 * pInfo, sal_Size * pSrcCvtChars) + { + OSL_ASSERT(m_converter != 0); + return rtl_convertUnicodeToText ( + m_converter, 0, pSrcBuf, nSrcChars, pDstBuf, nDstBytes, nFlags, pInfo, pSrcCvtChars); + } + }; +} // end namespace private + +int UnicodeToText( char * buffer, size_t bufLen, const sal_Unicode * uniText, sal_Int32 uniTextLen ) +{ + sal_uInt32 nInfo = 0; + sal_Size nSrcChars = 0; + + sal_Size nDestBytes = UnicodeToTextConverter_Impl::getInstance().convert ( + uniText, uniTextLen, buffer, bufLen, + OUSTRING_TO_OSTRING_CVTFLAGS | RTL_UNICODETOTEXT_FLAGS_FLUSH, &nInfo, &nSrcChars); + + if( nInfo & RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL ) + { + errno = EOVERFLOW; + return 0; + } + + /* ensure trailing '\0' */ + buffer[nDestBytes] = '\0'; + return nDestBytes; +} + +/***************************************************************************** + * TextToUnicode + ****************************************************************************/ + +namespace /* private */ +{ + class TextToUnicodeConverter_Impl + { + rtl_TextToUnicodeConverter m_converter; + + TextToUnicodeConverter_Impl() + : m_converter (rtl_createTextToUnicodeConverter (osl_getThreadTextEncoding())) + {} + + ~TextToUnicodeConverter_Impl() + { + rtl_destroyTextToUnicodeConverter (m_converter); + } + + public: + static TextToUnicodeConverter_Impl & getInstance() + { + static TextToUnicodeConverter_Impl g_theConverter; + return g_theConverter; + } + + sal_Size convert( + sal_Char const * pSrcBuf, sal_Size nSrcBytes, sal_Unicode * pDstBuf, sal_Size nDstChars, + sal_uInt32 nFlags, sal_uInt32 * pInfo, sal_Size * pSrcCvtBytes) + { + OSL_ASSERT(m_converter != 0); + return rtl_convertTextToUnicode ( + m_converter, 0, pSrcBuf, nSrcBytes, pDstBuf, nDstChars, nFlags, pInfo, pSrcCvtBytes); + } + }; +} // end namespace private + +int TextToUnicode( + const char* text, + size_t text_buffer_size, + sal_Unicode* unic_text, + sal_Int32 unic_text_buffer_size) +{ + sal_uInt32 nInfo = 0; + sal_Size nSrcChars = 0; + + sal_Size nDestBytes = TextToUnicodeConverter_Impl::getInstance().convert( + text, text_buffer_size, unic_text, unic_text_buffer_size, + OSTRING_TO_OUSTRING_CVTFLAGS | RTL_TEXTTOUNICODE_FLAGS_FLUSH, &nInfo, &nSrcChars); + + if (nInfo & RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL) + { + errno = EOVERFLOW; + return 0; + } + + /* ensure trailing '\0' */ + unic_text[nDestBytes] = '\0'; + return nDestBytes; +} diff --git a/sal/osl/unx/file_url.h b/sal/osl/unx/file_url.h index 4d89239567c5..721bc9d3d698 100644 --- a/sal/osl/unx/file_url.h +++ b/sal/osl/unx/file_url.h @@ -28,43 +28,45 @@ * ************************************************************************/ - /*************************************************** - * Internal header file, declares all functions - * that are not part of the offical API and are - * not defined in the osl header files - **************************************************/ +#ifndef INCLUDED_FILE_URL_H +#define INCLUDED_FILE_URL_H - #ifndef _FILE_URL_H_ - #define _FILE_URL_H_ +#include "osl/file.h" - #ifndef _FILE_H_ - #include - #endif +#ifdef __cplusplus +extern "C" +{ +#endif - #ifdef __cplusplus - extern "C" - { - #endif +/************************************************** + * osl_getSystemPathFromFileURL_Ex + *************************************************/ - /************************************************** - * _osl_getSystemPathFromFileURL - *************************************************/ +#define FURL_ALLOW_RELATIVE sal_True +#define FURL_DENY_RELATIVE sal_False - #define FURL_ALLOW_RELATIVE sal_True - #define FURL_DENY_RELATIVE sal_False +oslFileError osl_getSystemPathFromFileURL_Ex(rtl_uString *ustrFileURL, rtl_uString **pustrSystemPath, sal_Bool bAllowRelative); - oslFileError osl_getSystemPathFromFileURL_Ex(rtl_uString *ustrFileURL, rtl_uString **pustrSystemPath, sal_Bool bAllowRelative); +/************************************************** + * FileURLToPath + *************************************************/ - /************************************************** - * FileURLToPath - *************************************************/ +oslFileError FileURLToPath(char * buffer, size_t bufLen, rtl_uString* ustrFileURL); - oslFileError FileURLToPath(char * buffer, size_t bufLen, rtl_uString* ustrFileURL); +/*************************************************** + * UnicodeToText + **************************************************/ +int UnicodeToText(char * buffer, size_t bufLen, const sal_Unicode * uniText, sal_Int32 uniTextLen); - #ifdef __cplusplus - } - #endif +/*************************************************** + * TextToUniCode + **************************************************/ +int TextToUnicode(const char* text, size_t text_buffer_size, sal_Unicode* unic_text, sal_Int32 unic_text_buffer_size); - #endif /* #define _FILE_URL_H_ */ +#ifdef __cplusplus +} +#endif + +#endif /* #define INCLUDED_FILE_URL_H */ diff --git a/sal/osl/unx/file_volume.cxx b/sal/osl/unx/file_volume.cxx new file mode 100644 index 000000000000..a3b7109123b7 --- /dev/null +++ b/sal/osl/unx/file_volume.cxx @@ -0,0 +1,1570 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "osl/file.h" + +#include "osl/diagnose.h" +#include "osl/thread.h" +#include "rtl/alloc.h" + +#include "file_error_transl.h" +#include "file_url.h" +#include "system.h" + +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_STATFS_H +#undef HAVE_STATFS_H +#endif + +#if defined(SOLARIS) + +#include +#include +#define HAVE_STATFS_H +#include +static const sal_Char* MOUNTTAB="/etc/mnttab"; + +#elif defined(LINUX) + +#include +#include +#define HAVE_STATFS_H +#include +//#include +static const sal_Char* MOUNTTAB="/etc/mtab"; + +#elif defined(NETBSD) || defined(FREEBSD) + +#include +#include +#include +#include +//#include +#define HAVE_STATFS_H + +/* No mounting table on *BSD + * This information is stored only in the kernel. */ +/* static const sal_Char* MOUNTTAB="/etc/mtab"; */ + +#elif defined(IRIX) + +#include +#include +#include +#define HAVE_STATFS_H +#include +//#include +static const sal_Char* MOUNTTAB="/etc/mtab"; + +#elif defined(MACOSX) + +#include +//#include +#include +#include +#define HAVE_STATFS_H +// static const sal_Char* MOUNTTAB="/etc/mtab"; + +#endif /* HAVE_STATFS_H */ + +/************************************************************************ + * ToDo + * + * - Fix: check for corresponding struct sizes in exported functions + * - check size/use of oslVolumeDeviceHandle + * - check size/use of oslVolumeInfo + ***********************************************************************/ +/****************************************************************************** + * + * Data Type Definition + * + ******************************************************************************/ + +typedef struct _oslVolumeDeviceHandleImpl +{ + sal_Char pszMountPoint[PATH_MAX]; + sal_Char pszFilePath[PATH_MAX]; + sal_Char pszDevice[PATH_MAX]; + sal_Char ident[4]; + sal_uInt32 RefCount; +} oslVolumeDeviceHandleImpl; + +/****************************************************************************** + * + * 'removeable device' aka floppy functions + * + *****************************************************************************/ + +static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath); +static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy); +static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy); + +#if defined(SOLARIS) +static sal_Bool osl_isFloppyMounted(sal_Char* pszPath, sal_Char* pszMountPath); +static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, sal_Char* pBuffer); +static sal_Bool osl_checkFloppyPath(sal_Char* pszPath, sal_Char* pszFilePath, sal_Char* pszDevicePath); +#endif /* SOLARIS */ + +#if defined(LINUX) +static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice); +static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem); +#endif /* LINUX */ + + +#if defined(IRIX) +static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice); +static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem); +#endif /* IRIX */ + +#ifdef DEBUG_OSL_FILE +static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* hFloppy); +#endif /* DEBUG_OSL_FILE */ + +/****************************************************************************** + * + * C-String Function Declarations + * + *****************************************************************************/ + +static oslFileError osl_psz_getVolumeInformation(const sal_Char* , oslVolumeInfo* pInfo, sal_uInt32 uFieldMask); + +/****************************************************************************/ +/* osl_getVolumeInformation */ +/****************************************************************************/ + +oslFileError osl_getVolumeInformation( rtl_uString* ustrDirectoryURL, oslVolumeInfo* pInfo, sal_uInt32 uFieldMask ) +{ + char path[PATH_MAX]; + oslFileError eRet; + + OSL_ASSERT( ustrDirectoryURL ); + OSL_ASSERT( pInfo ); + + /* convert directory url to system path */ + eRet = FileURLToPath( path, PATH_MAX, ustrDirectoryURL ); + if( eRet != osl_File_E_None ) + return eRet; + +#ifdef MACOSX + if ( macxp_resolveAlias( path, PATH_MAX ) != 0 ) + return oslTranslateFileError( OSL_FET_ERROR, errno ); +#endif/* MACOSX */ + + return osl_psz_getVolumeInformation( path, pInfo, uFieldMask); +} + +/****************************************************************************** + * + * C-String Versions of Exported Module Functions + * + *****************************************************************************/ + +#ifdef HAVE_STATFS_H + +#if defined(FREEBSD) || defined(NETBSD) || defined(MACOSX) +# define __OSL_STATFS_STRUCT struct statfs +# define __OSL_STATFS(dir, sfs) statfs((dir), (sfs)) +# define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_bsize)) +# define __OSL_STATFS_TYPENAME(a) ((a).f_fstypename) +# define __OSL_STATFS_ISREMOTE(a) (((a).f_type & MNT_LOCAL) == 0) + +/* always return true if queried for the properties of + the file system. If you think this is wrong under any + of the target platforms fix it!!!! */ +# define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) +# define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) +#endif /* FREEBSD || NETBSD || MACOSX */ + +#if defined(LINUX) +# define __OSL_NFS_SUPER_MAGIC 0x6969 +# define __OSL_SMB_SUPER_MAGIC 0x517B +# define __OSL_MSDOS_SUPER_MAGIC 0x4d44 +# define __OSL_NTFS_SUPER_MAGIC 0x5346544e +# define __OSL_STATFS_STRUCT struct statfs +# define __OSL_STATFS(dir, sfs) statfs((dir), (sfs)) +# define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_bsize)) +# define __OSL_STATFS_IS_NFS(a) (__OSL_NFS_SUPER_MAGIC == (a).f_type) +# define __OSL_STATFS_IS_SMB(a) (__OSL_SMB_SUPER_MAGIC == (a).f_type) +# define __OSL_STATFS_ISREMOTE(a) (__OSL_STATFS_IS_NFS((a)) || __OSL_STATFS_IS_SMB((a))) +# define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) ((__OSL_MSDOS_SUPER_MAGIC != (a).f_type) && (__OSL_NTFS_SUPER_MAGIC != (a).f_type)) +# define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) ((__OSL_MSDOS_SUPER_MAGIC != (a).f_type)) +#endif /* LINUX */ + +#if defined(SOLARIS) || defined(IRIX) +# define __OSL_STATFS_STRUCT struct statvfs +# define __OSL_STATFS(dir, sfs) statvfs((dir), (sfs)) +# define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_frsize)) +# define __OSL_STATFS_TYPENAME(a) ((a).f_basetype) +# define __OSL_STATFS_ISREMOTE(a) (rtl_str_compare((a).f_basetype, "nfs") == 0) + +/* always return true if queried for the properties of + the file system. If you think this is wrong under any + of the target platforms fix it!!!! */ +# define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) +# define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) +#endif /* SOLARIS || IRIX*/ + +# define __OSL_STATFS_INIT(a) (memset(&(a), 0, sizeof(__OSL_STATFS_STRUCT))) + +#else /* no statfs available */ + +# define __OSL_STATFS_STRUCT struct dummy {int i;} +# define __OSL_STATFS_INIT(a) ((void)0) +# define __OSL_STATFS(dir, sfs) (1) +# define __OSL_STATFS_ISREMOTE(sfs) (0) +# define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) +# define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) +#endif /* HAVE_STATFS_H */ + + +static oslFileError osl_psz_getVolumeInformation ( + const sal_Char* pszDirectory, oslVolumeInfo* pInfo, sal_uInt32 uFieldMask) +{ + __OSL_STATFS_STRUCT sfs; + + if (!pInfo) + return osl_File_E_INVAL; + + __OSL_STATFS_INIT(sfs); + + pInfo->uValidFields = 0; + pInfo->uAttributes = 0; + + if ((__OSL_STATFS(pszDirectory, &sfs)) < 0) + { + oslFileError result = oslTranslateFileError(OSL_FET_ERROR, errno); + return (result); + } + + /* FIXME: how to detect the kind of storage (fixed, cdrom, ...) */ + if (uFieldMask & osl_VolumeInfo_Mask_Attributes) + { + if (__OSL_STATFS_ISREMOTE(sfs)) + pInfo->uAttributes |= osl_Volume_Attribute_Remote; + + pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; + } + + if (uFieldMask & osl_VolumeInfo_Mask_FileSystemCaseHandling) + { + if (__OSL_STATFS_IS_CASE_SENSITIVE_FS(sfs)) + pInfo->uAttributes |= osl_Volume_Attribute_Case_Sensitive; + + if (__OSL_STATFS_IS_CASE_PRESERVING_FS(sfs)) + pInfo->uAttributes |= osl_Volume_Attribute_Case_Is_Preserved; + + pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; + } + + pInfo->uTotalSpace = 0; + pInfo->uFreeSpace = 0; + pInfo->uUsedSpace = 0; + +#if defined(__OSL_STATFS_BLKSIZ) + + if ((uFieldMask & osl_VolumeInfo_Mask_TotalSpace) || + (uFieldMask & osl_VolumeInfo_Mask_UsedSpace)) + { + pInfo->uTotalSpace = __OSL_STATFS_BLKSIZ(sfs); + pInfo->uTotalSpace *= (sal_uInt64)(sfs.f_blocks); + pInfo->uValidFields |= osl_VolumeInfo_Mask_TotalSpace; + } + + if ((uFieldMask & osl_VolumeInfo_Mask_FreeSpace) || + (uFieldMask & osl_VolumeInfo_Mask_UsedSpace)) + { + pInfo->uFreeSpace = __OSL_STATFS_BLKSIZ(sfs); + + if (getuid() == 0) + pInfo->uFreeSpace *= (sal_uInt64)(sfs.f_bfree); + else + pInfo->uFreeSpace *= (sal_uInt64)(sfs.f_bavail); + + pInfo->uValidFields |= osl_VolumeInfo_Mask_FreeSpace; + } + +#endif /* __OSL_STATFS_BLKSIZ */ + + if ((pInfo->uValidFields & osl_VolumeInfo_Mask_TotalSpace) && + (pInfo->uValidFields & osl_VolumeInfo_Mask_FreeSpace )) + { + pInfo->uUsedSpace = pInfo->uTotalSpace - pInfo->uFreeSpace; + pInfo->uValidFields |= osl_VolumeInfo_Mask_UsedSpace; + } + + pInfo->uMaxNameLength = 0; + if (uFieldMask & osl_VolumeInfo_Mask_MaxNameLength) + { + long nLen = pathconf(pszDirectory, _PC_NAME_MAX); + if (nLen > 0) + { + pInfo->uMaxNameLength = (sal_uInt32)nLen; + pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxNameLength; + } + } + + pInfo->uMaxPathLength = 0; + if (uFieldMask & osl_VolumeInfo_Mask_MaxPathLength) + { + long nLen = pathconf (pszDirectory, _PC_PATH_MAX); + if (nLen > 0) + { + pInfo->uMaxPathLength = (sal_uInt32)nLen; + pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxPathLength; + } + } + +#if defined(__OSL_STATFS_TYPENAME) + + if (uFieldMask & osl_VolumeInfo_Mask_FileSystemName) + { + rtl_string2UString( + &(pInfo->ustrFileSystemName), + __OSL_STATFS_TYPENAME(sfs), + rtl_str_getLength(__OSL_STATFS_TYPENAME(sfs)), + osl_getThreadTextEncoding(), + OUSTRING_TO_OSTRING_CVTFLAGS); + OSL_ASSERT(pInfo->ustrFileSystemName != 0); + + pInfo->uValidFields |= osl_VolumeInfo_Mask_FileSystemName; + } + +#endif /* __OSL_STATFS_TYPENAME */ + + if (uFieldMask & osl_VolumeInfo_Mask_DeviceHandle) + { + /* FIXME: check also entries in mntent for the device + and fill it with correct values */ + + *pInfo->pDeviceHandle = osl_isFloppyDrive(pszDirectory); + + if (*pInfo->pDeviceHandle) + { + pInfo->uValidFields |= osl_VolumeInfo_Mask_DeviceHandle; + pInfo->uAttributes |= osl_Volume_Attribute_Removeable; + pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; + } + } + return osl_File_E_None; +} + +/****************************************************************************** + * + * GENERIC FLOPPY FUNCTIONS + * + *****************************************************************************/ + + +/***************************************** + * osl_unmountVolumeDevice + ****************************************/ + +oslFileError osl_unmountVolumeDevice( oslVolumeDeviceHandle Handle ) +{ + oslFileError tErr = osl_File_E_NOSYS; + + tErr = osl_unmountFloppy(Handle); + + /* Perhaps current working directory is set to mount point */ + + if ( tErr ) + { + sal_Char *pszHomeDir = getenv("HOME"); + + if ( pszHomeDir && strlen( pszHomeDir ) && 0 == chdir( pszHomeDir ) ) + { + /* try again */ + + tErr = osl_unmountFloppy(Handle); + + OSL_ENSURE( tErr, "osl_unmountvolumeDevice: CWD was set to volume mount point" ); + } + } + + return tErr; +} + +/***************************************** + * osl_automountVolumeDevice + ****************************************/ + +oslFileError osl_automountVolumeDevice( oslVolumeDeviceHandle Handle ) +{ + oslFileError tErr = osl_File_E_NOSYS; + + tErr = osl_mountFloppy(Handle); + + return tErr; +} + +/***************************************** + * osl_getVolumeDeviceMountPath + ****************************************/ +static rtl_uString* oslMakeUStrFromPsz(const sal_Char* pszStr, rtl_uString** ustrValid) +{ + rtl_string2UString( + ustrValid, + pszStr, + rtl_str_getLength( pszStr ), + osl_getThreadTextEncoding(), + OUSTRING_TO_OSTRING_CVTFLAGS ); + OSL_ASSERT(*ustrValid != 0); + + return *ustrValid; +} + +oslFileError osl_getVolumeDeviceMountPath( oslVolumeDeviceHandle Handle, rtl_uString **pstrPath ) +{ + oslVolumeDeviceHandleImpl* pItem = (oslVolumeDeviceHandleImpl*) Handle; + sal_Char Buffer[PATH_MAX]; + + Buffer[0] = '\0'; + + if ( pItem == 0 || pstrPath == 0 ) + { + return osl_File_E_INVAL; + } + + if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) + { + return osl_File_E_INVAL; + } + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"Handle is:\n"); + osl_printFloppyHandle(pItem); +#endif + + snprintf(Buffer, sizeof(Buffer), "file://%s", pItem->pszMountPoint); + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"Mount Point is: '%s'\n",Buffer); +#endif + + oslMakeUStrFromPsz(Buffer, pstrPath); + + return osl_File_E_None; +} + +/***************************************** + * osl_acquireVolumeDeviceHandle + ****************************************/ + +oslFileError SAL_CALL osl_acquireVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) +{ + oslVolumeDeviceHandleImpl* pItem =(oslVolumeDeviceHandleImpl*) Handle; + + if ( pItem == 0 ) + { + return osl_File_E_INVAL; + } + + if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) + { + return osl_File_E_INVAL; + } + + ++pItem->RefCount; + + return osl_File_E_None; +} + +/***************************************** + * osl_releaseVolumeDeviceHandle + ****************************************/ + +oslFileError osl_releaseVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) +{ + oslVolumeDeviceHandleImpl* pItem =(oslVolumeDeviceHandleImpl*) Handle; + + if ( pItem == 0 ) + { + return osl_File_E_INVAL; + } + + if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) + { + return osl_File_E_INVAL; + } + + --pItem->RefCount; + + if ( pItem->RefCount == 0 ) + { + rtl_freeMemory(pItem); + } + + return osl_File_E_None; +} + +#ifndef MACOSX + +/***************************************** + * osl_newVolumeDeviceHandleImpl + ****************************************/ + +static oslVolumeDeviceHandleImpl* osl_newVolumeDeviceHandleImpl() +{ + oslVolumeDeviceHandleImpl* pHandle; + const size_t nSizeOfHandle = sizeof(oslVolumeDeviceHandleImpl); + + pHandle = (oslVolumeDeviceHandleImpl*) rtl_allocateMemory (nSizeOfHandle); + if (pHandle != NULL) + { + pHandle->ident[0] = 'O'; + pHandle->ident[1] = 'V'; + pHandle->ident[2] = 'D'; + pHandle->ident[3] = 'H'; + pHandle->pszMountPoint[0] = '\0'; + pHandle->pszFilePath[0] = '\0'; + pHandle->pszDevice[0] = '\0'; + pHandle->RefCount = 1; + } + return pHandle; +} + +/***************************************** + * osl_freeVolumeDeviceHandleImpl + ****************************************/ + +static void osl_freeVolumeDeviceHandleImpl (oslVolumeDeviceHandleImpl* pHandle) +{ + if (pHandle != NULL) + rtl_freeMemory (pHandle); +} +#endif + +/****************************************************************************** + * + * SOLARIS FLOPPY FUNCTIONS + * + *****************************************************************************/ + +#if defined(SOLARIS) +/* compare a given devicename with the typical device names on a Solaris box */ +static sal_Bool +osl_isAFloppyDevice (const char* pDeviceName) +{ + const char* pFloppyDevice [] = { + "/dev/fd", "/dev/rfd", + "/dev/diskette", "/dev/rdiskette", + "/vol/dev/diskette", "/vol/dev/rdiskette" + }; + + int i; + for (i = 0; i < (sizeof(pFloppyDevice)/sizeof(pFloppyDevice[0])); i++) + { + if (strncmp(pDeviceName, pFloppyDevice[i], strlen(pFloppyDevice[i])) == 0) + return sal_True; + } + return sal_False; +} + +/* compare two directories whether the first may be a parent of the second. this + * does not realpath() resolving */ +static sal_Bool +osl_isAParentDirectory (const char* pParentDir, const char* pSubDir) +{ + return strncmp(pParentDir, pSubDir, strlen(pParentDir)) == 0; +} + +/* the name of the routine is obviously silly. But anyway create a + * oslVolumeDeviceHandle with correct mount point, device name and a resolved filepath + * only if pszPath points to file or directory on a floppy */ +static oslVolumeDeviceHandle +osl_isFloppyDrive(const sal_Char* pszPath) +{ + FILE* pMountTab; + struct mnttab aMountEnt; + oslVolumeDeviceHandleImpl* pHandle; + + if ((pHandle = osl_newVolumeDeviceHandleImpl()) == NULL) + { + return NULL; + } + if (realpath(pszPath, pHandle->pszFilePath) == NULL) + { + osl_freeVolumeDeviceHandleImpl (pHandle); + return NULL; + } + if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) + { + osl_freeVolumeDeviceHandleImpl (pHandle); + return NULL; + } + + while (getmntent(pMountTab, &aMountEnt) == 0) + { + const char *pMountPoint = aMountEnt.mnt_mountp; + const char *pDevice = aMountEnt.mnt_special; + if ( osl_isAParentDirectory (aMountEnt.mnt_mountp, pHandle->pszFilePath) + && osl_isAFloppyDevice (aMountEnt.mnt_special)) + { + /* skip the last item for it is the name of the disk */ + char * pc = strrchr( aMountEnt.mnt_special, '/' ); + + if ( NULL != pc ) + { + int len = pc - aMountEnt.mnt_special; + + strncpy( pHandle->pszDevice, aMountEnt.mnt_special, len ); + pHandle->pszDevice[len] = '\0'; + } + else + { + /* #106048 use save str functions to avoid buffer overflows */ + memset(pHandle->pszDevice, 0, sizeof(pHandle->pszDevice)); + strncpy(pHandle->pszDevice, aMountEnt.mnt_special, sizeof(pHandle->pszDevice) - 1); + } + + /* remember the mount point */ + memset(pHandle->pszMountPoint, 0, sizeof(pHandle->pszMountPoint)); + strncpy(pHandle->pszMountPoint, aMountEnt.mnt_mountp, sizeof(pHandle->pszMountPoint) - 1); + + fclose (pMountTab); + return pHandle; + } + } + + fclose (pMountTab); + osl_freeVolumeDeviceHandleImpl (pHandle); + return NULL; +} + +static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) +{ + FILE* pMountTab; + struct mnttab aMountEnt; + oslVolumeDeviceHandleImpl* pHandle = (oslVolumeDeviceHandleImpl*) hFloppy; + + int nRet=0; + sal_Char pszCmd[512] = ""; + + if ( pHandle == 0 ) + return osl_File_E_INVAL; + + /* FIXME: don't know what this is good for */ + if ( pHandle->ident[0] != 'O' || pHandle->ident[1] != 'V' || pHandle->ident[2] != 'D' || pHandle->ident[3] != 'H' ) + return osl_File_E_INVAL; + + snprintf(pszCmd, sizeof(pszCmd), "eject -q %s > /dev/null 2>&1", pHandle->pszDevice); + + nRet = system( pszCmd ); + + switch ( WEXITSTATUS(nRet) ) + { + case 0: + { + /* lookup the device in mount tab again */ + if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) + return osl_File_E_BUSY; + + while (getmntent(pMountTab, &aMountEnt) == 0) + { + const char *pMountPoint = aMountEnt.mnt_mountp; + const char *pDevice = aMountEnt.mnt_special; + if ( 0 == strncmp( pHandle->pszDevice, aMountEnt.mnt_special, strlen(pHandle->pszDevice) ) ) + { + memset(pHandle->pszMountPoint, 0, sizeof(pHandle->pszMountPoint)); + strncpy (pHandle->pszMountPoint, aMountEnt.mnt_mountp, sizeof(pHandle->pszMountPoint) - 1); + + fclose (pMountTab); + return osl_File_E_None; + } + } + + fclose (pMountTab); + return osl_File_E_BUSY; + } + //break; // break not necessary here, see return statements before + + case 1: + return osl_File_E_BUSY; + + default: + break; + } + + return osl_File_E_BUSY; +} + +static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) +{ +// FILE* pMountTab; +// struct mnttab aMountEnt; + oslVolumeDeviceHandleImpl* pHandle = (oslVolumeDeviceHandleImpl*) hFloppy; + + int nRet=0; + sal_Char pszCmd[512] = ""; + + if ( pHandle == 0 ) + return osl_File_E_INVAL; + + /* FIXME: don't know what this is good for */ + if ( pHandle->ident[0] != 'O' || pHandle->ident[1] != 'V' || pHandle->ident[2] != 'D' || pHandle->ident[3] != 'H' ) + return osl_File_E_INVAL; + + snprintf(pszCmd, sizeof(pszCmd), "eject %s > /dev/null 2>&1", pHandle->pszDevice); + + nRet = system( pszCmd ); + + switch ( WEXITSTATUS(nRet) ) + { + case 0: + { + FILE* pMountTab; + struct mnttab aMountEnt; + + /* lookup if device is still in mount tab */ + if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) + return osl_File_E_BUSY; + + while (getmntent(pMountTab, &aMountEnt) == 0) + { + const char *pMountPoint = aMountEnt.mnt_mountp; + const char *pDevice = aMountEnt.mnt_special; + if ( 0 == strncmp( pHandle->pszDevice, aMountEnt.mnt_special, strlen(pHandle->pszDevice) ) ) + { + fclose (pMountTab); + return osl_File_E_BUSY; + } + } + + fclose (pMountTab); + pHandle->pszMountPoint[0] = 0; + return osl_File_E_None; + } + + //break; //break not necessary, see return statements before + + case 1: + return osl_File_E_NODEV; + + case 4: + pHandle->pszMountPoint[0] = 0; + return osl_File_E_None; + + default: + break; + } + + return osl_File_E_BUSY; +} + +#endif /* SOLARIS */ + +/****************************************************************************** + * + * LINUX FLOPPY FUNCTIONS + * + *****************************************************************************/ + +#if defined(LINUX) +static oslVolumeDeviceHandle +osl_isFloppyDrive (const sal_Char* pszPath) +{ + oslVolumeDeviceHandleImpl* pItem = osl_newVolumeDeviceHandleImpl(); + if (osl_getFloppyMountEntry(pszPath, pItem)) + return (oslVolumeDeviceHandle) pItem; + + osl_freeVolumeDeviceHandleImpl (pItem); + return 0; +} +#endif /* LINUX */ + +#if defined(LINUX) +static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) +{ + sal_Bool bRet = sal_False; + oslVolumeDeviceHandleImpl* pItem=0; + int nRet; + sal_Char pszCmd[PATH_MAX]; + const sal_Char* pszMountProg = "mount"; + sal_Char* pszSuDo = 0; + sal_Char* pszTmp = 0; + + pszCmd[0] = '\0'; + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"In osl_mountFloppy\n"); +#endif + + pItem = (oslVolumeDeviceHandleImpl*) hFloppy; + + if ( pItem == 0 ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_mountFloppy [pItem == 0]\n"); +#endif + + return osl_File_E_INVAL; + } + + if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_mountFloppy [invalid handle]\n"); +#endif + return osl_File_E_INVAL; + } + + bRet = osl_isFloppyMounted(pItem); + if ( bRet == sal_True ) + { +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"detected mounted floppy at '%s'\n",pItem->pszMountPoint); +#endif + return osl_File_E_BUSY; + } + + /* mfe: we can't use the mount(2) system call!!! */ + /* even if we are root */ + /* since mtab is not updated!!! */ + /* but we need it to be updated */ + /* some "magic" must be done */ + +/* nRet = mount(pItem->pszDevice,pItem->pszMountPoint,0,0,0); */ +/* if ( nRet != 0 ) */ +/* { */ +/* nRet=errno; */ +/* #ifdef DEBUG_OSL_FILE */ +/* perror("mount"); */ +/* #endif */ +/* } */ + + pszTmp = getenv("SAL_MOUNT_MOUNTPROG"); + if ( pszTmp != 0 ) + { + pszMountProg=pszTmp; + } + + pszTmp=getenv("SAL_MOUNT_SU_DO"); + if ( pszTmp != 0 ) + { + pszSuDo=pszTmp; + } + + if ( pszSuDo != 0 ) + { + snprintf(pszCmd, sizeof(pszCmd), "%s %s %s %s",pszSuDo,pszMountProg,pItem->pszDevice,pItem->pszMountPoint); + } + else + { + snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszMountProg,pItem->pszMountPoint); + } + + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"executing '%s'\n",pszCmd); +#endif + + nRet = system(pszCmd); + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"call returned '%i'\n",nRet); + fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); +#endif + + + switch ( WEXITSTATUS(nRet) ) + { + case 0: + nRet=0; + break; + + case 2: + nRet=EPERM; + break; + + case 4: + nRet=ENOENT; + break; + + case 8: + nRet=EINTR; + break; + + case 16: + nRet=EPERM; + break; + + case 32: + nRet=EBUSY; + break; + + case 64: + nRet=EAGAIN; + break; + + default: + nRet=EBUSY; + break; + } + + return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); +} +#endif /* LINUX */ + + +#if defined(LINUX) +static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) +{ + oslVolumeDeviceHandleImpl* pItem=0; + int nRet=0; + sal_Char pszCmd[PATH_MAX]; + sal_Char* pszTmp = 0; + sal_Char* pszSuDo = 0; + const sal_Char* pszUmountProg = "umount"; + + pszCmd[0] = '\0'; + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"In osl_unmountFloppy\n"); +#endif + + pItem = (oslVolumeDeviceHandleImpl*) hFloppy; + + if ( pItem == 0 ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_unmountFloppy [pItem==0]\n"); +#endif + return osl_File_E_INVAL; + } + + if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_unmountFloppy [invalid handle]\n"); +#endif + return osl_File_E_INVAL; + } + + /* mfe: we can't use the umount(2) system call!!! */ + /* even if we are root */ + /* since mtab is not updated!!! */ + /* but we need it to be updated */ + /* some "magic" must be done */ + +/* nRet=umount(pItem->pszDevice); */ +/* if ( nRet != 0 ) */ +/* { */ +/* nRet = errno; */ + +/* #ifdef DEBUG_OSL_FILE */ +/* perror("mount"); */ +/* #endif */ +/* } */ + + + pszTmp = getenv("SAL_MOUNT_UMOUNTPROG"); + if ( pszTmp != 0 ) + { + pszUmountProg=pszTmp; + } + + pszTmp = getenv("SAL_MOUNT_SU_DO"); + if ( pszTmp != 0 ) + { + pszSuDo=pszTmp; + } + + if ( pszSuDo != 0 ) + { + snprintf(pszCmd, sizeof(pszCmd), "%s %s %s",pszSuDo,pszUmountProg,pItem->pszMountPoint); + } + else + { + snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszUmountProg,pItem->pszMountPoint); + } + + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"executing '%s'\n",pszCmd); +#endif + + nRet = system(pszCmd); + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"call returned '%i'\n",nRet); + fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); +#endif + + switch ( WEXITSTATUS(nRet) ) + { + case 0: + nRet=0; + break; + + default: + nRet=EBUSY; + break; + } + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_unmountFloppy [ok]\n"); +#endif + + return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); + +/* return osl_File_E_None;*/ +} + +#endif /* LINUX */ + +#if defined(LINUX) +static sal_Bool +osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) +{ + struct mntent* pMountEnt; + FILE* pMountTab; + + pMountTab = setmntent (MOUNTTAB, "r"); + if (pMountTab == 0) + return sal_False; + + while ((pMountEnt = getmntent(pMountTab)) != 0) + { + if ( strncmp(pMountEnt->mnt_dir, pszPath, strlen(pMountEnt->mnt_dir)) == 0 + && strncmp(pMountEnt->mnt_fsname, "/dev/fd", strlen("/dev/fd")) == 0) + { + memset(pItem->pszMountPoint, 0, sizeof(pItem->pszMountPoint)); + strncpy(pItem->pszMountPoint, pMountEnt->mnt_dir, sizeof(pItem->pszMountPoint) - 1); + + memset(pItem->pszFilePath, 0, sizeof(pItem->pszFilePath)); + strncpy(pItem->pszFilePath, pMountEnt->mnt_dir, sizeof(pItem->pszFilePath) - 1); + + memset(pItem->pszDevice, 0, sizeof(pItem->pszDevice)); + strncpy(pItem->pszDevice, pMountEnt->mnt_fsname, sizeof(pItem->pszDevice) - 1); + + endmntent (pMountTab); + return sal_True; + } + } + + endmntent (pMountTab); + return sal_False; +} +#endif /* LINUX */ + +#if defined(LINUX) +static sal_Bool +osl_isFloppyMounted (oslVolumeDeviceHandleImpl* pDevice) +{ + oslVolumeDeviceHandleImpl aItem; + + if ( osl_getFloppyMountEntry (pDevice->pszMountPoint, &aItem) + && strcmp (aItem.pszMountPoint, pDevice->pszMountPoint) == 0 + && strcmp (aItem.pszDevice, pDevice->pszDevice) == 0) + { + return sal_True; + } + return sal_False; +} +#endif /* LINUX */ + +/****************************************************************************** + * + * IRIX FLOPPY FUNCTIONS + * + *****************************************************************************/ + +#if defined(IRIX) +static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath) +{ + oslVolumeDeviceHandleImpl* pItem = osl_newVolumeDeviceHandleImpl (); + sal_Bool bRet = sal_False; + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"In osl_isFloppyDrive\n"); +#endif + + bRet=osl_getFloppyMountEntry(pszPath,pItem); + + if ( bRet == sal_False ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_isFloppyDrive [not a floppy]\n"); +#endif + rtl_freeMemory(pItem); + return 0; + } + + +#ifdef DEBUG_OSL_FILE + osl_printFloppyHandle(pItem); +#endif +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_isFloppyDrive [ok]\n"); +#endif + + return (oslVolumeDeviceHandle) pItem; +} + + +static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) +{ + sal_Bool bRet = sal_False; + oslVolumeDeviceHandleImpl* pItem=0; + int nRet; + sal_Char pszCmd[PATH_MAX]; + sal_Char* pszMountProg = "mount"; + sal_Char* pszSuDo = 0; + sal_Char* pszTmp = 0; + + pszCmd[0] = '\0'; + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"In osl_mountFloppy\n"); +#endif + + pItem = (oslVolumeDeviceHandleImpl*) hFloppy; + + if ( pItem == 0 ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_mountFloppy [pItem == 0]\n"); +#endif + + return osl_File_E_INVAL; + } + + if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_mountFloppy [invalid handle]\n"); +#endif + return osl_File_E_INVAL; + } + + bRet = osl_isFloppyMounted(pItem); + if ( bRet == sal_True ) + { +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"detected mounted floppy at '%s'\n",pItem->pszMountPoint); +#endif + return osl_File_E_BUSY; + } + + /* mfe: we can't use the mount(2) system call!!! */ + /* even if we are root */ + /* since mtab is not updated!!! */ + /* but we need it to be updated */ + /* some "magic" must be done */ + +/* nRet = mount(pItem->pszDevice,pItem->pszMountPoint,0,0,0); */ +/* if ( nRet != 0 ) */ +/* { */ +/* nRet=errno; */ +/* #ifdef DEBUG_OSL_FILE */ +/* perror("mount"); */ +/* #endif */ +/* } */ + + pszTmp = getenv("SAL_MOUNT_MOUNTPROG"); + if ( pszTmp != 0 ) + { + pszMountProg=pszTmp; + } + + pszTmp=getenv("SAL_MOUNT_SU_DO"); + if ( pszTmp != 0 ) + { + pszSuDo=pszTmp; + } + + if ( pszSuDo != 0 ) + { + snprintf(pszCmd, sizeof(pszCmd), "%s %s %s %s",pszSuDo,pszMountProg,pItem->pszDevice,pItem->pszMountPoint); + } + else + { + snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszMountProg,pItem->pszMountPoint); + } + + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"executing '%s'\n",pszCmd); +#endif + + nRet = system(pszCmd); + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"call returned '%i'\n",nRet); + fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); +#endif + + + switch ( WEXITSTATUS(nRet) ) + { + case 0: + nRet=0; + break; + + case 2: + nRet=EPERM; + break; + + case 4: + nRet=ENOENT; + break; + + case 8: + nRet=EINTR; + break; + + case 16: + nRet=EPERM; + break; + + case 32: + nRet=EBUSY; + break; + + case 64: + nRet=EAGAIN; + break; + + default: + nRet=EBUSY; + break; + } + + return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); +} + +static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) +{ + oslVolumeDeviceHandleImpl* pItem=0; + int nRet=0; + sal_Char pszCmd[PATH_MAX]; + sal_Char* pszTmp = 0; + sal_Char* pszSuDo = 0; + sal_Char* pszUmountProg = "umount"; + + pszCmd[0] = '\0'; + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"In osl_unmountFloppy\n"); +#endif + + pItem = (oslVolumeDeviceHandleImpl*) hFloppy; + + if ( pItem == 0 ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_unmountFloppy [pItem==0]\n"); +#endif + return osl_File_E_INVAL; + } + + if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_unmountFloppy [invalid handle]\n"); +#endif + return osl_File_E_INVAL; + } + + /* mfe: we can't use the umount(2) system call!!! */ + /* even if we are root */ + /* since mtab is not updated!!! */ + /* but we need it to be updated */ + /* some "magic" must be done */ + +/* nRet=umount(pItem->pszDevice); */ +/* if ( nRet != 0 ) */ +/* { */ +/* nRet = errno; */ + +/* #ifdef DEBUG_OSL_FILE */ +/* perror("mount"); */ +/* #endif */ +/* } */ + + + pszTmp = getenv("SAL_MOUNT_UMOUNTPROG"); + if ( pszTmp != 0 ) + { + pszUmountProg=pszTmp; + } + + pszTmp = getenv("SAL_MOUNT_SU_DO"); + if ( pszTmp != 0 ) + { + pszSuDo=pszTmp; + } + + if ( pszSuDo != 0 ) + { + snprintf(pszCmd, sizeof(pszCmd), "%s %s %s",pszSuDo,pszUmountProg,pItem->pszMountPoint); + } + else + { + snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszUmountProg,pItem->pszMountPoint); + } + + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"executing '%s'\n",pszCmd); +#endif + + nRet = system(pszCmd); + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"call returned '%i'\n",nRet); + fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); +#endif + + switch ( WEXITSTATUS(nRet) ) + { + case 0: + nRet=0; + break; + + default: + nRet=EBUSY; + break; + } + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_unmountFloppy [ok]\n"); +#endif + + return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); + +/* return osl_File_E_None;*/ +} + +static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) +{ + struct mntent* pMountEnt=0; + sal_Char buffer[PATH_MAX]; + FILE* mntfile=0; + int nRet=0; + + buffer[0] = '\0'; + + mntfile = setmntent(MOUNTTAB,"r"); + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"In osl_getFloppyMountEntry\n"); +#endif + + memset(buffer, 0, sizeof(buffer)); + strncpy(buffer, pszPath, sizeof(buffer) - 1); + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"Checking mount of %s\n",buffer); +#endif + + + if ( mntfile == 0 ) + { + nRet=errno; +#ifdef DEBUG_OSL_FILE + perror("mounttab"); +#endif +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_getFloppyMountEntry [mntfile]\n"); +#endif + return sal_False; + } + + pMountEnt=getmntent(mntfile); + while ( pMountEnt != 0 ) + { +#ifdef DEBUG_OSL_FILE +/* fprintf(stderr,"mnt_fsname : %s\n",pMountEnt->mnt_fsname); */ +/* fprintf(stderr,"mnt_dir : %s\n",pMountEnt->mnt_dir); */ +/* fprintf(stderr,"mnt_type : %s\n",pMountEnt->mnt_type);*/ +#endif + if ( strcmp(pMountEnt->mnt_dir,buffer) == 0 && + strncmp(pMountEnt->mnt_fsname,"/dev/fd",strlen("/dev/fd")) == 0 ) + { + + memset(pItem->pszMountPoint, 0, sizeof(pItem->pszMountPoint)); + strncpy(pItem->pszMountPoint, pMountEnt->mnt_dir, sizeof(pItem->pszMountPoint) - 1); + + memset(pItem->pszFilePath, 0, sizeof(pItem->pszFilePath)); + strncpy(pItem->pszFilePath, pMountEnt->mnt_dir, sizeof(pItem->pszFilePath) - 1); + + memset(pItem->pszDevice, 0, sizeof(pItem->pszDevice)); + strncpy(pItem->pszDevice, pMountEnt->mnt_fsname, sizeof(pItem->pszDevice) - 1); + + fclose(mntfile); +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"Mount Point found '%s'\n",pItem->pszMountPoint); +#endif +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_getFloppyMountEntry [found]\n"); +#endif + return sal_True; + } +#ifdef DEBUG_OSL_FILE +/* fprintf(stderr,"=================\n");*/ +#endif + pMountEnt=getmntent(mntfile); + } + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_getFloppyMountEntry [not found]\n"); +#endif + + fclose(mntfile); + return sal_False; +} + +static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice) +{ + sal_Char buffer[PATH_MAX]; + oslVolumeDeviceHandleImpl* pItem=0; + sal_Bool bRet=0; + + buffer[0] = '\0'; + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"In osl_isFloppyMounted\n"); +#endif + + pItem = osl_newVolumeDeviceHandleImpl (); + if ( pItem == 0 ) + return osl_File_E_NOMEM; + + memset(buffer, 0, sizeof(buffer)); + strncpy(buffer, pDevice->pszMountPoint, sizeof(buffer) - 1); + +#ifdef DEBUG_OSL_FILE + fprintf(stderr,"Checking mount of %s\n",buffer); +#endif + + bRet = osl_getFloppyMountEntry(buffer,pItem); + + if ( bRet == sal_False ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_isFloppyMounted [not mounted]\n"); +#endif + return sal_False; + } + + if (strcmp(pItem->pszMountPoint, pDevice->pszMountPoint) == 0 && + strcmp(pItem->pszDevice,pDevice->pszDevice) == 0) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_isFloppyMounted [is mounted]\n"); +#endif + rtl_freeMemory(pItem); + return sal_True; + } + +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Out osl_isFloppyMounted [may be EBUSY]\n"); +#endif + + rtl_freeMemory(pItem); + return sal_False; +} +#endif /* IRIX */ + + +/* NetBSD floppy functions have to be added here. Until we have done that, + * we use the MACOSX definitions for nonexistent floppy. + * */ + +/****************************************************************************** + * + * MAC OS X FLOPPY FUNCTIONS + * + *****************************************************************************/ + +#if (defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) +static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath) +{ + return NULL; +} +#endif /* MACOSX */ + +#if ( defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) +static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) +{ + return osl_File_E_BUSY; +} +#endif /* MACOSX */ + +#if ( defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) +static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) +{ + return osl_File_E_BUSY; +} +#endif /* MACOSX */ + +#if ( defined(NETBSD) || defined(FREEBSD) ) +static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) +{ + return sal_False; +} +#endif /* NETBSD || FREEBSD */ + +#if ( defined(NETBSD) || defined(FREEBSD) ) +static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice) +{ + return sal_False; +} +#endif /* NETBSD || FREEBSD */ + + +#ifdef DEBUG_OSL_FILE +static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* pItem) +{ + if (pItem == 0 ) + { + fprintf(stderr,"NULL Handle\n"); + return; + } + if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) + { +#ifdef TRACE_OSL_FILE + fprintf(stderr,"Invalid Handle]\n"); +#endif + return; + } + + + fprintf(stderr,"MountPoint : '%s'\n",pItem->pszMountPoint); + fprintf(stderr,"FilePath : '%s'\n",pItem->pszFilePath); + fprintf(stderr,"Device : '%s'\n",pItem->pszDevice); + + return; +} +#endif diff --git a/sal/osl/unx/makefile.mk b/sal/osl/unx/makefile.mk index 1717d836e647..0e728c29dbcd 100644 --- a/sal/osl/unx/makefile.mk +++ b/sal/osl/unx/makefile.mk @@ -68,18 +68,20 @@ SLOFILES= $(SLO)$/conditn.obj \ $(SLO)$/security.obj \ $(SLO)$/profile.obj \ $(SLO)$/time.obj \ - $(SLO)$/file.obj \ $(SLO)$/signal.obj \ $(SLO)$/pipe.obj \ $(SLO)$/system.obj \ $(SLO)$/util.obj \ $(SLO)$/tempfile.obj\ + $(SLO)$/file.obj \ + $(SLO)$/file_misc.obj \ $(SLO)$/file_url.obj\ $(SLO)$/file_error_transl.obj\ $(SLO)$/file_path_helper.obj\ + $(SLO)$/file_stat.obj \ + $(SLO)$/file_volume.obj \ $(SLO)$/uunxapi.obj\ $(SLO)$/process_impl.obj\ - $(SLO)$/file_stat.obj \ $(SLO)$/salinit.obj #.IF "$(UPDATER)"=="YES" @@ -96,18 +98,20 @@ OBJFILES= $(OBJ)$/conditn.obj \ $(OBJ)$/security.obj \ $(OBJ)$/profile.obj \ $(OBJ)$/time.obj \ - $(OBJ)$/file.obj \ $(OBJ)$/signal.obj \ $(OBJ)$/pipe.obj \ $(OBJ)$/system.obj \ $(OBJ)$/util.obj \ $(OBJ)$/tempfile.obj\ + $(OBJ)$/file.obj \ + $(OBJ)$/file_misc.obj \ $(OBJ)$/file_url.obj\ $(OBJ)$/file_error_transl.obj\ $(OBJ)$/file_path_helper.obj\ + $(OBJ)$/file_stat.obj \ + $(OBJ)$/file_volume.obj \ $(OBJ)$/uunxapi.obj\ $(OBJ)$/process_impl.obj\ - $(OBJ)$/file_stat.obj \ $(OBJ)$/salinit.obj #.ENDIF diff --git a/sal/osl/w32/MAKEFILE.MK b/sal/osl/w32/MAKEFILE.MK index e6a33854366d..cd52ef549c8d 100644 --- a/sal/osl/w32/MAKEFILE.MK +++ b/sal/osl/w32/MAKEFILE.MK @@ -78,6 +78,10 @@ SLOFILES= $(SLO)$/conditn.obj \ $(SLO)$/pipe.obj \ $(SLO)$/util.obj \ $(SLO)$/file.obj\ + $(SLO)$/file_dirvol.obj\ + $(SLO)$/file_error.obj\ + $(SLO)$/file_url.obj\ + $(SLO)$/tempfile.obj\ $(SLO)$/path_helper.obj\ $(SLO)$/procimpl.obj \ $(SLO)$/salinit.obj @@ -101,6 +105,10 @@ OBJFILES= $(OBJ)$/conditn.obj \ $(OBJ)$/pipe.obj \ $(OBJ)$/util.obj \ $(OBJ)$/file.obj\ + $(OBJ)$/file_dirvol.obj\ + $(OBJ)$/file_error.obj\ + $(OBJ)$/file_url.obj\ + $(OBJ)$/tempfile.obj\ $(OBJ)$/path_helper.obj\ $(OBJ)$/procimpl.obj \ $(OBJ)$/salinit.obj diff --git a/sal/osl/w32/file.cxx b/sal/osl/w32/file.cxx index 7ba66ed3e69c..b6a7c64ee873 100644 --- a/sal/osl/w32/file.cxx +++ b/sal/osl/w32/file.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: file.cxx,v $ - * $Revision: 1.19 $ + * $Revision: 1.0 $ * * This file is part of OpenOffice.org. * @@ -34,26 +34,19 @@ #define UNICODE #define _UNICODE #define _WIN32_WINNT 0x0500 -#include "systools\win32\uwinapi.h" +#include "systools/win32/uwinapi.h" -#include "path_helper.hxx" +#include "osl/file.hxx" -#include "sal/types.h" +#include "file_url.h" +#include "file_error.h" -#include "osl/file.hxx" #include "osl/diagnose.h" -#include "rtl/ustring.hxx" #include "rtl/alloc.h" -#include "rtl/tencinfo.h" -#include "osl/thread.h" -#include "osl/mutex.h" #include "rtl/byteseq.h" -#include "osl/time.h" -//#include -#include +#include "rtl/ustring.hxx" -#define WIN32_LEAN_AND_MEAN -#include +#include #include #ifdef __MINGW32__ @@ -61,3686 +54,1094 @@ #include #endif -#include #include #include #ifdef max /* conflict w/ std::numeric_limits::max() */ #undef max #endif +#ifdef min +#undef min +#endif -//##################################################### -// BEGIN global -//##################################################### - -extern "C" oslMutex g_CurrentDirectoryMutex; /* Initialized in dllentry.c */ -oslMutex g_CurrentDirectoryMutex; - -//##################################################### -extern "C" BOOL TimeValueToFileTime(const TimeValue *cpTimeVal, FILETIME *pFTime) +//################################################################## +// File handle implementation +//################################################################## +struct FileHandle_Impl { - SYSTEMTIME BaseSysTime; - FILETIME BaseFileTime; - FILETIME FTime; - __int64 localTime; - BOOL fSuccess = FALSE; - - BaseSysTime.wYear = 1970; - BaseSysTime.wMonth = 1; - BaseSysTime.wDayOfWeek = 0; - BaseSysTime.wDay = 1; - BaseSysTime.wHour = 0; - BaseSysTime.wMinute = 0; - BaseSysTime.wSecond = 0; - BaseSysTime.wMilliseconds = 0; - - if (cpTimeVal==NULL) - return fSuccess; - - if ( SystemTimeToFileTime(&BaseSysTime, &BaseFileTime) ) - { - __int64 timeValue; - localTime=cpTimeVal->Seconds*(__int64)10000000+cpTimeVal->Nanosec/100; - *(__int64 *)&FTime=localTime; - fSuccess = 0 <= (timeValue= *((__int64 *)&BaseFileTime) + *((__int64 *) &FTime)); - if (fSuccess) - *(__int64 *)pFTime=timeValue; - } - return fSuccess; -} + HANDLE m_hFile; -//##################################################### -extern "C" BOOL FileTimeToTimeValue(const FILETIME *cpFTime, TimeValue *pTimeVal) -{ - SYSTEMTIME BaseSysTime; - FILETIME BaseFileTime; - BOOL fSuccess = FALSE; /* Assume failure */ - - BaseSysTime.wYear = 1970; - BaseSysTime.wMonth = 1; - BaseSysTime.wDayOfWeek = 0; - BaseSysTime.wDay = 1; - BaseSysTime.wHour = 0; - BaseSysTime.wMinute = 0; - BaseSysTime.wSecond = 0; - BaseSysTime.wMilliseconds = 0; - - if ( SystemTimeToFileTime(&BaseSysTime, &BaseFileTime) ) + /** State + */ + enum StateBits { - __int64 Value; + STATE_SEEKABLE = 1, /* open() sets, iff regular file */ + STATE_READABLE = 2, /* open() sets, read() requires */ + STATE_WRITEABLE = 4, /* open() sets, write() requires */ + STATE_MODIFIED = 8 /* write() sets, flush() resets */ + }; + int m_state; - fSuccess = 0 <= (Value = *((__int64 *)cpFTime) - *((__int64 *)&BaseFileTime)); + sal_uInt64 m_size; /* file size */ + LONGLONG m_offset; /* physical offset from begin of file */ + LONGLONG m_filepos; /* logical offset from begin of file */ - if ( fSuccess ) - { - pTimeVal->Seconds = (unsigned long) (Value / 10000000L); - pTimeVal->Nanosec = (unsigned long)((Value % 10000000L) * 100); - } - } - return fSuccess; -} + LONGLONG m_bufptr; /* buffer offset from begin of file */ + SIZE_T m_buflen; /* buffer filled [0, m_bufsiz - 1] */ -//##################################################### -extern "C" oslFileHandle SAL_CALL osl_createFileHandleFromOSHandle(HANDLE hFile) -{ - if ( IsValidHandle(hFile) ) - return (oslFileHandle)hFile; - else - return NULL; -} + SIZE_T m_bufsiz; + sal_uInt8 * m_buffer; -//##################################################### -// End global -//##################################################### + explicit FileHandle_Impl (HANDLE hFile); + ~FileHandle_Impl(); + static void* operator new(size_t n); + static void operator delete(void * p, size_t); + static SIZE_T getpagesize(); -using namespace osl; + sal_uInt64 getPos() const; + oslFileError setPos (sal_uInt64 uPos); -#define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0]))) + sal_uInt64 getSize() const; -// Allocate n number of t's on the stack return a pointer to it in p -#ifdef __MINGW32__ -#define STACK_ALLOC(p, t, n) (p) = reinterpret_cast(_alloca((n)*sizeof(t))); -#else -#define STACK_ALLOC(p, t, n) __try {(p) = reinterpret_cast(_alloca((n)*sizeof(t)));} \ - __except(EXCEPTION_EXECUTE_HANDLER) {(p) = NULL;} -#endif + oslFileError readAt ( + LONGLONG nOffset, + void * pBuffer, + DWORD nBytesRequested, + sal_uInt64 * pBytesRead); -#if OSL_DEBUG_LEVEL > 0 -#define OSL_ENSURE_FILE( cond, msg, file ) ( (cond) ? (void)0 : _osl_warnFile( msg, file ) ) -#else -#define OSL_ENSURE_FILE( cond, msg, file ) ((void)0) -#endif + oslFileError writeAt ( + LONGLONG nOffset, + void const * pBuffer, + DWORD nBytesToWrite, + sal_uInt64 * pBytesWritten); -#define PATHTYPE_ERROR 0 -#define PATHTYPE_RELATIVE 1 -#define PATHTYPE_ABSOLUTE_UNC 2 -#define PATHTYPE_ABSOLUTE_LOCAL 3 -#define PATHTYPE_MASK_TYPE 0xFF -#define PATHTYPE_IS_VOLUME 0x0100 -#define PATHTYPE_IS_SERVER 0x0200 + oslFileError readFileAt ( + LONGLONG nOffset, + void * pBuffer, + sal_uInt64 uBytesRequested, + sal_uInt64 * pBytesRead); -#define VALIDATEPATH_NORMAL 0x0000 -#define VALIDATEPATH_ALLOW_WILDCARDS 0x0001 -#define VALIDATEPATH_ALLOW_ELLIPSE 0x0002 -#define VALIDATEPATH_ALLOW_RELATIVE 0x0004 -#define VALIDATEPATH_ALLOW_UNC 0x0008 + oslFileError writeFileAt ( + LONGLONG nOffset, + void const * pBuffer, + sal_uInt64 uBytesToWrite, + sal_uInt64 * pBytesWritten); -#define WSTR_SYSTEM_ROOT_PATH L"\\\\.\\" + oslFileError readLineAt ( + LONGLONG nOffset, + sal_Sequence ** ppSequence, + sal_uInt64 * pBytesRead); -typedef struct { - UINT uType; + oslFileError writeSequence_Impl ( + sal_Sequence ** ppSequence, + SIZE_T * pnOffset, + const void * pBuffer, + SIZE_T nBytes); - union { - WIN32_FIND_DATA FindData; - TCHAR cDriveString[MAX_PATH]; - }; - TCHAR szFullPath[MAX_PATH]; - BOOL bFullPathNormalized; - int nRefCount; -}DirectoryItem_Impl; - -#define DIRECTORYTYPE_LOCALROOT 0 -#define DIRECTORYTYPE_NETROOT 1 -#define DIRECTORYTYPE_NETRESORCE 2 -#define DIRECTORYTYPE_FILESYSTEM 3 - -#define DIRECTORYITEM_DRIVE 0 -#define DIRECTORYITEM_FILE 1 -#define DIRECTORYITEM_SERVER 2 - -typedef struct { - UINT uType; - union { - HANDLE hDirectory; - HANDLE hEnumDrives; - }; - TCHAR szDirectoryPath[MAX_PATH]; -} Directory_Impl; + oslFileError syncFile(); -/* Different types of paths */ -typedef enum _PATHTYPE -{ - PATHTYPE_SYNTAXERROR = 0, - PATHTYPE_NETROOT, - PATHTYPE_NETSERVER, - PATHTYPE_VOLUME, - PATHTYPE_FILE -} PATHTYPE; + /** Buffer cache / allocator. + */ + class Allocator + { + rtl_cache_type * m_cache; + SIZE_T m_bufsiz; + Allocator (Allocator const &); + Allocator & operator= (Allocator const &); -namespace /* private */ -{ - // forward - void _osl_warnFile(const char*, rtl_uString*); - oslFileError SAL_CALL _osl_getFileURLFromSystemPath(rtl_uString* , rtl_uString**); - DWORD WINAPI IsValidFilePath(rtl_uString*, LPCTSTR*, DWORD, rtl_uString**); - HANDLE WINAPI OpenLogicalDrivesEnum(void); - BOOL WINAPI EnumLogicalDrives(HANDLE, LPTSTR); - BOOL WINAPI CloseLogicalDrivesEnum(HANDLE); - HANDLE WINAPI OpenDirectory(LPCTSTR); - BOOL WINAPI CloseDirectory(HANDLE); - BOOL WINAPI EnumDirectory(HANDLE, LPWIN32_FIND_DATA); - DWORD WINAPI GetCaseCorrectPathName(LPCTSTR, LPTSTR, DWORD); - oslFileError SAL_CALL _osl_getSystemPathFromFileURL(rtl_uString*, rtl_uString**, sal_Bool); - - /* OS error to errno values mapping table */ - struct errentry { - unsigned long oscode; /* OS return value */ - int errnocode; /* System V error code */ - }; + public: + static Allocator & get(); - struct errentry errtable[] = { - { ERROR_SUCCESS, osl_File_E_None }, /* 0 */ - { ERROR_INVALID_FUNCTION, osl_File_E_INVAL }, /* 1 */ - { ERROR_FILE_NOT_FOUND, osl_File_E_NOENT }, /* 2 */ - { ERROR_PATH_NOT_FOUND, osl_File_E_NOENT }, /* 3 */ - { ERROR_TOO_MANY_OPEN_FILES, osl_File_E_MFILE }, /* 4 */ - { ERROR_ACCESS_DENIED, osl_File_E_ACCES }, /* 5 */ - { ERROR_INVALID_HANDLE, osl_File_E_BADF }, /* 6 */ - { ERROR_ARENA_TRASHED, osl_File_E_NOMEM }, /* 7 */ - { ERROR_NOT_ENOUGH_MEMORY, osl_File_E_NOMEM }, /* 8 */ - { ERROR_INVALID_BLOCK, osl_File_E_NOMEM }, /* 9 */ - { ERROR_BAD_ENVIRONMENT, osl_File_E_2BIG }, /* 10 */ - { ERROR_BAD_FORMAT, osl_File_E_NOEXEC }, /* 11 */ - { ERROR_INVALID_ACCESS, osl_File_E_INVAL }, /* 12 */ - { ERROR_INVALID_DATA, osl_File_E_INVAL }, /* 13 */ - { ERROR_INVALID_DRIVE, osl_File_E_NOENT }, /* 15 */ - { ERROR_CURRENT_DIRECTORY, osl_File_E_ACCES }, /* 16 */ - { ERROR_NOT_SAME_DEVICE, osl_File_E_XDEV }, /* 17 */ - { ERROR_NO_MORE_FILES, osl_File_E_NOENT }, /* 18 */ - { ERROR_NOT_READY, osl_File_E_NOTREADY }, /* 21 */ - { ERROR_LOCK_VIOLATION, osl_File_E_ACCES }, /* 33 */ - { ERROR_BAD_NETPATH, osl_File_E_NOENT }, /* 53 */ - { ERROR_NETWORK_ACCESS_DENIED, osl_File_E_ACCES }, /* 65 */ - { ERROR_BAD_NET_NAME, osl_File_E_NOENT }, /* 67 */ - { ERROR_FILE_EXISTS, osl_File_E_EXIST }, /* 80 */ - { ERROR_CANNOT_MAKE, osl_File_E_ACCES }, /* 82 */ - { ERROR_FAIL_I24, osl_File_E_ACCES }, /* 83 */ - { ERROR_INVALID_PARAMETER, osl_File_E_INVAL }, /* 87 */ - { ERROR_NO_PROC_SLOTS, osl_File_E_AGAIN }, /* 89 */ - { ERROR_DRIVE_LOCKED, osl_File_E_ACCES }, /* 108 */ - { ERROR_BROKEN_PIPE, osl_File_E_PIPE }, /* 109 */ - { ERROR_DISK_FULL, osl_File_E_NOSPC }, /* 112 */ - { ERROR_INVALID_TARGET_HANDLE, osl_File_E_BADF }, /* 114 */ - { ERROR_INVALID_HANDLE, osl_File_E_INVAL }, /* 124 */ - { ERROR_WAIT_NO_CHILDREN, osl_File_E_CHILD }, /* 128 */ - { ERROR_CHILD_NOT_COMPLETE, osl_File_E_CHILD }, /* 129 */ - { ERROR_DIRECT_ACCESS_HANDLE, osl_File_E_BADF }, /* 130 */ - { ERROR_NEGATIVE_SEEK, osl_File_E_INVAL }, /* 131 */ - { ERROR_SEEK_ON_DEVICE, osl_File_E_ACCES }, /* 132 */ - { ERROR_DIR_NOT_EMPTY, osl_File_E_NOTEMPTY }, /* 145 */ - { ERROR_NOT_LOCKED, osl_File_E_ACCES }, /* 158 */ - { ERROR_BAD_PATHNAME, osl_File_E_NOENT }, /* 161 */ - { ERROR_MAX_THRDS_REACHED, osl_File_E_AGAIN }, /* 164 */ - { ERROR_LOCK_FAILED, osl_File_E_ACCES }, /* 167 */ - { ERROR_ALREADY_EXISTS, osl_File_E_EXIST }, /* 183 */ - { ERROR_FILENAME_EXCED_RANGE, osl_File_E_NOENT }, /* 206 */ - { ERROR_NESTING_NOT_ALLOWED, osl_File_E_AGAIN }, /* 215 */ - { ERROR_DIRECTORY, osl_File_E_NOENT }, /* 267 */ - { ERROR_NOT_ENOUGH_QUOTA, osl_File_E_NOMEM }, /* 1816 */ - { ERROR_UNEXP_NET_ERR, osl_File_E_NETWORK } /* 59 */ - }; + void allocate (sal_uInt8 ** ppBuffer, SIZE_T * pnSize); + void deallocate (sal_uInt8 * pBuffer); - /* The following two constants must be the minimum and maximum - values in the (contiguous) range of osl_File_E_xec Failure errors. */ - #define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG - #define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN + protected: + Allocator(); + ~Allocator(); + }; +}; - /* These are the low and high value in the range of errors that are - access violations */ - #define MIN_EACCES_RANGE ERROR_WRITE_PROTECT - #define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED +FileHandle_Impl::Allocator & +FileHandle_Impl::Allocator::get() +{ + static Allocator g_aBufferAllocator; + return g_aBufferAllocator; +} - //##################################################### - oslFileError MapError(DWORD dwError) - { - for (int i = 0; i < ELEMENTS_OF_ARRAY(errtable); ++i ) - { - if (dwError == errtable[i].oscode) - return static_cast(errtable[i].errnocode); - } +FileHandle_Impl::Allocator::Allocator() + : m_cache (0), + m_bufsiz (0) +{ + SIZE_T const pagesize = FileHandle_Impl::getpagesize(); + m_cache = rtl_cache_create ( + "osl_file_buffer_cache", pagesize, 0, 0, 0, 0, 0, 0, 0); + if (0 != m_cache) + m_bufsiz = pagesize; +} - /* The error code wasn't in the table. We check for a range of - osl_File_E_ACCES errors or exec failure errors (ENOEXEC). - Otherwise osl_File_E_INVAL is returned. */ - if ( dwError >= MIN_EACCES_RANGE && dwError <= MAX_EACCES_RANGE) - return osl_File_E_ACCES; - else if ( dwError >= MIN_EXEC_ERROR && dwError <= MAX_EXEC_ERROR) - return osl_File_E_NOEXEC; - else - return osl_File_E_INVAL; - } +FileHandle_Impl::Allocator::~Allocator() +{ + rtl_cache_destroy(m_cache), m_cache = 0; +} - //##################################################### - oslFileError SAL_CALL osl_openLocalRoot( - rtl_uString *strDirectoryPath, oslDirectory *pDirectory) - { - rtl_uString *strSysPath = NULL; - oslFileError error; +void FileHandle_Impl::Allocator::allocate (sal_uInt8 ** ppBuffer, SIZE_T * pnSize) +{ + OSL_PRECOND((0 != ppBuffer) && (0 != pnSize), "FileHandle_Impl::Allocator::allocate(): contract violation"); + *ppBuffer = static_cast< sal_uInt8* >(rtl_cache_alloc(m_cache)), *pnSize = m_bufsiz; +} - if ( !pDirectory ) - return osl_File_E_INVAL; +void FileHandle_Impl::Allocator::deallocate (sal_uInt8 * pBuffer) +{ + if (0 != pBuffer) + rtl_cache_free (m_cache, pBuffer); +} - *pDirectory = NULL; +FileHandle_Impl::FileHandle_Impl(HANDLE hFile) + : m_hFile (hFile), + m_state (STATE_READABLE | STATE_WRITEABLE), + m_size (0), + m_offset (0), + m_filepos (0), + m_bufptr (-1), + m_buflen (0), + m_bufsiz (0), + m_buffer (0) +{ + Allocator::get().allocate (&m_buffer, &m_bufsiz); + if (m_buffer != 0) + memset (m_buffer, 0, m_bufsiz); +} - error = _osl_getSystemPathFromFileURL( strDirectoryPath, &strSysPath, sal_False ); +FileHandle_Impl::~FileHandle_Impl() +{ + Allocator::get().deallocate (m_buffer), m_buffer = 0; +} - if ( osl_File_E_None == error ) - { - Directory_Impl *pDirImpl; +void * FileHandle_Impl::operator new(size_t n) +{ + return rtl_allocateMemory(n); +} - pDirImpl = reinterpret_cast(rtl_allocateMemory( sizeof(Directory_Impl))); - _tcscpy( pDirImpl->szDirectoryPath, reinterpret_cast(rtl_uString_getStr(strSysPath)) ); +void FileHandle_Impl::operator delete(void * p, size_t) +{ + rtl_freeMemory(p); +} - /* Append backslash if neccessary */ +SIZE_T FileHandle_Impl::getpagesize() +{ + SYSTEM_INFO info; + ::GetSystemInfo (&info); + return sal::static_int_cast< SIZE_T >(info.dwPageSize); +} - /* @@@ToDo - use function ensure backslash - */ - if ( pDirImpl->szDirectoryPath[_tcslen(pDirImpl->szDirectoryPath) - 1] != L'\\' ) - _tcscat( pDirImpl->szDirectoryPath, L"\\" ); +sal_uInt64 FileHandle_Impl::getPos() const +{ + return sal::static_int_cast< sal_uInt64 >(m_filepos); +} - pDirImpl->uType = DIRECTORYTYPE_LOCALROOT; - pDirImpl->hEnumDrives = OpenLogicalDrivesEnum(); +oslFileError FileHandle_Impl::setPos (sal_uInt64 uPos) +{ + m_filepos = sal::static_int_cast< LONGLONG >(uPos); + return osl_File_E_None; +} - /* @@@ToDo - Use IsValidHandle(...) - */ - if ( pDirImpl->hEnumDrives != INVALID_HANDLE_VALUE ) - { - *pDirectory = (oslDirectory)pDirImpl; - error = osl_File_E_None; - } - else - { - if ( pDirImpl ) - rtl_freeMemory(pDirImpl); +sal_uInt64 FileHandle_Impl::getSize() const +{ + LONGLONG bufend = std::max((LONGLONG)(0), m_bufptr) + m_buflen; + return std::max(m_size, sal::static_int_cast< sal_uInt64 >(bufend)); +} - error = MapError( GetLastError() ); - } +oslFileError FileHandle_Impl::readAt ( + LONGLONG nOffset, + void * pBuffer, + DWORD nBytesRequested, + sal_uInt64 * pBytesRead) +{ + OSL_PRECOND(m_state & STATE_SEEKABLE, "FileHandle_Impl::readAt(): not seekable"); + if (!(m_state & STATE_SEEKABLE)) + return osl_File_E_SPIPE; - rtl_uString_release( strSysPath ); - } - return error; - } + OSL_PRECOND(m_state & STATE_READABLE, "FileHandle_Impl::readAt(): not readable"); + if (!(m_state & STATE_READABLE)) + return osl_File_E_BADF; - //##################################################### - oslFileError SAL_CALL osl_openFileDirectory( - rtl_uString *strDirectoryPath, oslDirectory *pDirectory) + if (nOffset != m_offset) { - // MT: Done in osl_openDirectory! -// rtl_uString *strSysPath = NULL; - oslFileError error; + LARGE_INTEGER liOffset; liOffset.QuadPart = nOffset; + if (!::SetFilePointerEx(m_hFile, liOffset, 0, FILE_BEGIN)) + return oslTranslateFileError( GetLastError() ); + m_offset = nOffset; + } - //MT: Not done in osl_openNetworkServer, why here? - if ( !pDirectory ) - return osl_File_E_INVAL; + DWORD dwDone = 0; + if (!::ReadFile(m_hFile, pBuffer, nBytesRequested, &dwDone, 0)) + return oslTranslateFileError( GetLastError() ); + m_offset += dwDone; - *pDirectory = NULL; + *pBytesRead = dwDone; + return osl_File_E_None; +} - // MT: Done in osl_openDirectory! -// error = _osl_getSystemPathFromFileURL( strDirectoryPath, &strSysPath, sal_False ); -// if ( osl_File_E_None == error ) - { - Directory_Impl *pDirImpl; +oslFileError FileHandle_Impl::writeAt ( + LONGLONG nOffset, + void const * pBuffer, + DWORD nBytesToWrite, + sal_uInt64 * pBytesWritten) +{ + OSL_PRECOND(m_state & STATE_SEEKABLE, "FileHandle_Impl::writeAt(): not seekable"); + if (!(m_state & STATE_SEEKABLE)) + return osl_File_E_SPIPE; - pDirImpl = reinterpret_cast(rtl_allocateMemory(sizeof(Directory_Impl))); - _tcscpy( pDirImpl->szDirectoryPath, reinterpret_cast(rtl_uString_getStr(strDirectoryPath)) ); + OSL_PRECOND(m_state & STATE_WRITEABLE, "FileHandle_Impl::writeAt(): not writeable"); + if (!(m_state & STATE_WRITEABLE)) + return osl_File_E_BADF; - /* Append backslash if neccessary */ + if (nOffset != m_offset) + { + LARGE_INTEGER liOffset; liOffset.QuadPart = nOffset; + if (!::SetFilePointerEx (m_hFile, liOffset, 0, FILE_BEGIN)) + return oslTranslateFileError( GetLastError() ); + m_offset = nOffset; + } - /* @@@ToDo - use function ensure backslash - */ - if ( pDirImpl->szDirectoryPath[_tcslen(pDirImpl->szDirectoryPath) - 1] != L'\\' ) - _tcscat( pDirImpl->szDirectoryPath, L"\\" ); - // MT: ??? - // GetCaseCorrectPathName( pDirImpl->szDirectoryPath, pDirImpl->szDirectoryPath, sizeof(pDirImpl->szDirectoryPath) ); + DWORD dwDone = 0; + if (!::WriteFile(m_hFile, pBuffer, nBytesToWrite, &dwDone, 0)) + return oslTranslateFileError( GetLastError() ); + m_offset += dwDone; - pDirImpl->uType = DIRECTORYTYPE_FILESYSTEM; - pDirImpl->hDirectory = OpenDirectory( pDirImpl->szDirectoryPath ); + m_size = std::max(m_size, sal::static_int_cast< sal_uInt64 >(m_offset)); - if ( pDirImpl->hDirectory ) - { - *pDirectory = (oslDirectory)pDirImpl; - error = osl_File_E_None; - } - else - { - if ( pDirImpl ) - rtl_freeMemory(pDirImpl); + *pBytesWritten = dwDone; + return osl_File_E_None; +} - error = MapError( GetLastError() ); - } +oslFileError FileHandle_Impl::readFileAt ( + LONGLONG nOffset, + void * pBuffer, + sal_uInt64 uBytesRequested, + sal_uInt64 * pBytesRead) +{ + static sal_uInt64 const g_limit_dword = std::numeric_limits< DWORD >::max(); + if (g_limit_dword < uBytesRequested) + return osl_File_E_OVERFLOW; + DWORD nBytesRequested = sal::static_int_cast< DWORD >(uBytesRequested); -// rtl_uString_release( strSysPath ); - } - return error; + if (0 == (m_state & STATE_SEEKABLE)) + { + // not seekable (pipe) + DWORD dwDone = 0; + if (!::ReadFile(m_hFile, pBuffer, nBytesRequested, &dwDone, 0)) + return oslTranslateFileError( GetLastError() ); + *pBytesRead = dwDone; + return osl_File_E_None; } - - typedef struct tagDIRECTORY + else if (0 == m_buffer) { - HANDLE hFind; - WIN32_FIND_DATA aFirstData; - } DIRECTORY, *PDIRECTORY, FAR *LPDIRECTORY; - - //##################################################### - HANDLE WINAPI OpenDirectory(LPCTSTR lpszPath) + // not buffered + return readAt (nOffset, pBuffer, nBytesRequested, pBytesRead); + } + else { - LPDIRECTORY pDirectory = (LPDIRECTORY)HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECTORY)); - - if (pDirectory) + sal_uInt8 * buffer = static_cast< sal_uInt8* >(pBuffer); + for (*pBytesRead = 0; nBytesRequested > 0; ) { - TCHAR szFileMask[MAX_PATH]; - int nLen; - - _tcscpy( szFileMask, lpszPath ); - nLen = _tcslen( szFileMask ); + LONGLONG const bufptr = (nOffset / m_bufsiz) * m_bufsiz; + SIZE_T const bufpos = (nOffset % m_bufsiz); - if (nLen && szFileMask[nLen-1] != '\\') - _tcscat(szFileMask, TEXT("\\*.*")); - else - _tcscat(szFileMask, TEXT("*.*")); - - pDirectory->hFind = FindFirstFile(szFileMask, &pDirectory->aFirstData); - - if (!IsValidHandle(pDirectory->hFind)) + if (bufptr != m_bufptr) { - if ( GetLastError() != ERROR_NO_MORE_FILES ) + // flush current buffer + oslFileError result = syncFile(); + if (result != osl_File_E_None) + return (result); + + if (nBytesRequested >= m_bufsiz) { - HeapFree(GetProcessHeap(), 0, pDirectory); - pDirectory = NULL; + // buffer too small, read through from file + sal_uInt64 uDone = 0; + result = readAt (nOffset, &(buffer[*pBytesRead]), nBytesRequested, &uDone); + if (result != osl_File_E_None) + return (result); + + nBytesRequested -= sal::static_int_cast< DWORD >(uDone), *pBytesRead += uDone; + return osl_File_E_None; } + + // update buffer (pointer) + sal_uInt64 uDone = 0; + result = readAt (bufptr, m_buffer, m_bufsiz, &uDone); + if (result != osl_File_E_None) + return (result); + m_bufptr = bufptr, m_buflen = sal::static_int_cast< SIZE_T >(uDone); } + if (bufpos >= m_buflen) + { + // end of file + return osl_File_E_None; + } + + SIZE_T const bytes = std::min(m_buflen - bufpos, nBytesRequested); + memcpy (&(buffer[*pBytesRead]), &(m_buffer[bufpos]), bytes); + nBytesRequested -= bytes, *pBytesRead += bytes, nOffset += bytes; } - return (HANDLE)pDirectory; + return osl_File_E_None; } +} - //##################################################### - BOOL WINAPI CloseDirectory(HANDLE hDirectory) - { - BOOL fSuccess = FALSE; - LPDIRECTORY pDirectory = (LPDIRECTORY)hDirectory; - - if (pDirectory) - { - if (IsValidHandle(pDirectory->hFind)) - fSuccess = FindClose(pDirectory->hFind); - - fSuccess = HeapFree(GetProcessHeap(), 0, pDirectory) && fSuccess; - } - else - SetLastError(ERROR_INVALID_HANDLE); +oslFileError FileHandle_Impl::writeFileAt ( + LONGLONG nOffset, + void const * pBuffer, + sal_uInt64 uBytesToWrite, + sal_uInt64 * pBytesWritten) +{ + static sal_uInt64 const g_limit_dword = std::numeric_limits< DWORD >::max(); + if (g_limit_dword < uBytesToWrite) + return osl_File_E_OVERFLOW; + DWORD nBytesToWrite = sal::static_int_cast< DWORD >(uBytesToWrite); - return fSuccess; + if (0 == (m_state & STATE_SEEKABLE)) + { + // not seekable (pipe) + DWORD dwDone = 0; + if (!::WriteFile(m_hFile, pBuffer, nBytesToWrite, &dwDone, 0)) + return oslTranslateFileError( GetLastError() ); + *pBytesWritten = dwDone; + return osl_File_E_None; } - - //##################################################### - BOOL WINAPI EnumDirectory(HANDLE hDirectory, LPWIN32_FIND_DATA pFindData) + else if (0 == m_buffer) { - BOOL fSuccess = FALSE; - LPDIRECTORY pDirectory = (LPDIRECTORY)hDirectory; - - if ( pDirectory ) + // not buffered + return writeAt(nOffset, pBuffer, nBytesToWrite, pBytesWritten); + } + else + { + sal_uInt8 const * buffer = static_cast< sal_uInt8 const* >(pBuffer); + for (*pBytesWritten = 0; nBytesToWrite > 0; ) { - BOOL fValid; - - do + LONGLONG const bufptr = (nOffset / m_bufsiz) * m_bufsiz; + SIZE_T const bufpos = (nOffset % m_bufsiz); + if (bufptr != m_bufptr) { - if ( pDirectory->aFirstData.cFileName[0] ) - { - *pFindData = pDirectory->aFirstData; - fSuccess = TRUE; - pDirectory->aFirstData.cFileName[0] = 0; - } - else if ( IsValidHandle( pDirectory->hFind ) ) - fSuccess = FindNextFile( pDirectory->hFind, pFindData ); - else + // flush current buffer + oslFileError result = syncFile(); + if (result != osl_File_E_None) + return (result); + + if (nBytesToWrite >= m_bufsiz) { - fSuccess = FALSE; - SetLastError( ERROR_NO_MORE_FILES ); + // buffer too small, write through to file + sal_uInt64 uDone = 0; + result = writeAt (nOffset, &(buffer[*pBytesWritten]), nBytesToWrite, &uDone); + if (result != osl_File_E_None) + return (result); + if (uDone != nBytesToWrite) + return osl_File_E_IO; + + nBytesToWrite -= sal::static_int_cast< DWORD >(uDone), *pBytesWritten += uDone; + return osl_File_E_None; } - fValid = fSuccess && _tcscmp( TEXT("."), pFindData->cFileName ) != 0 && _tcscmp( TEXT(".."), pFindData->cFileName ) != 0; - - } while( fSuccess && !fValid ); - } - else - SetLastError( ERROR_INVALID_HANDLE ); - - return fSuccess; - } - - //##################################################### - oslFileError SAL_CALL osl_openNetworkServer(rtl_uString *strSysDirPath, oslDirectory *pDirectory) - { - NETRESOURCEW aNetResource; - HANDLE hEnum; - DWORD dwError; - - ZeroMemory( &aNetResource, sizeof(aNetResource) ); - - aNetResource.lpRemoteName = reinterpret_cast(strSysDirPath->buffer); - - dwError = WNetOpenEnumW( - RESOURCE_GLOBALNET, - RESOURCETYPE_DISK, - RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER, - &aNetResource, - &hEnum ); + // update buffer (pointer) + sal_uInt64 uDone = 0; + result = readAt (bufptr, m_buffer, m_bufsiz, &uDone); + if (result != osl_File_E_None) + return (result); + m_bufptr = bufptr, m_buflen = sal::static_int_cast< SIZE_T >(uDone); + } - if ( ERROR_SUCCESS == dwError ) - { - Directory_Impl *pDirImpl; + SIZE_T const bytes = std::min(m_bufsiz - bufpos, nBytesToWrite); + memcpy (&(m_buffer[bufpos]), &(buffer[*pBytesWritten]), bytes); + nBytesToWrite -= bytes, *pBytesWritten += bytes, nOffset += bytes; - pDirImpl = reinterpret_cast(rtl_allocateMemory(sizeof(Directory_Impl))); - pDirImpl->uType = DIRECTORYTYPE_NETROOT; - pDirImpl->hDirectory = hEnum; - *pDirectory = (oslDirectory)pDirImpl; + m_buflen = std::max(m_buflen, bufpos + bytes); + m_state |= STATE_MODIFIED; } - return MapError( dwError ); + return osl_File_E_None; } +} - //##################################################### - oslFileError SAL_CALL osl_getNextNetResource( - oslDirectory Directory, - oslDirectoryItem *pItem, - sal_uInt32 uHint ) - { - Directory_Impl *pDirImpl = (Directory_Impl *)Directory; - DirectoryItem_Impl *pItemImpl = NULL; - BYTE buffer[16384]; - LPNETRESOURCEW lpNetResource = (LPNETRESOURCEW)buffer; - DWORD dwError, dwCount, dwBufSize; +oslFileError FileHandle_Impl::readLineAt ( + LONGLONG nOffset, + sal_Sequence ** ppSequence, + sal_uInt64 * pBytesRead) +{ + oslFileError result = osl_File_E_None; - uHint = uHint; /* to get no warning */ + LONGLONG bufptr = (nOffset / m_bufsiz) * m_bufsiz; + if (bufptr != m_bufptr) + { + /* flush current buffer */ + result = syncFile(); + if (result != osl_File_E_None) + return (result); - if ( !pItem ) - return osl_File_E_INVAL; + /* update buffer (pointer) */ + sal_uInt64 uDone = 0; + result = readAt (bufptr, m_buffer, m_bufsiz, &uDone); + if (result != osl_File_E_None) + return (result); - *pItem = NULL; + m_bufptr = bufptr, m_buflen = sal::static_int_cast< SIZE_T >(uDone); + } - if ( !pDirImpl ) - return osl_File_E_INVAL; + static int const LINE_STATE_BEGIN = 0; + static int const LINE_STATE_CR = 1; + static int const LINE_STATE_LF = 2; - dwCount = 1; - dwBufSize = sizeof(buffer); - dwError = WNetEnumResource( pDirImpl->hDirectory, &dwCount, lpNetResource, &dwBufSize ); + SIZE_T bufpos = sal::static_int_cast< SIZE_T >(nOffset - m_bufptr), curpos = bufpos, dstpos = 0; + int state = (bufpos >= m_buflen) ? LINE_STATE_LF : LINE_STATE_BEGIN; - switch ( dwError ) + for ( ; state != LINE_STATE_LF; ) + { + if (curpos >= m_buflen) { - case NO_ERROR: - case ERROR_MORE_DATA: + /* buffer examined */ + if (0 < (curpos - bufpos)) { - pItemImpl = reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); - if ( !pItemImpl ) - return osl_File_E_NOMEM; - - ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); - pItemImpl->uType = DIRECTORYITEM_DRIVE; - osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); + /* flush buffer to sequence */ + result = writeSequence_Impl ( + ppSequence, &dstpos, &(m_buffer[bufpos]), curpos - bufpos); + if (result != osl_File_E_None) + return (result); + *pBytesRead += curpos - bufpos, nOffset += curpos - bufpos; + } - wcscpy( pItemImpl->cDriveString, lpNetResource->lpRemoteName ); + bufptr = nOffset / m_bufsiz * m_bufsiz; + if (bufptr != m_bufptr) + { + /* update buffer (pointer) */ + sal_uInt64 uDone = 0; + result = readAt (bufptr, m_buffer, m_bufsiz, &uDone); + if (result != osl_File_E_None) + return (result); + m_bufptr = bufptr, m_buflen = sal::static_int_cast< SIZE_T >(uDone); + } - *pItem = pItemImpl; + bufpos = sal::static_int_cast< SIZE_T >(nOffset - m_bufptr), curpos = bufpos; + if (bufpos >= m_buflen) + break; + } + switch (state) + { + case LINE_STATE_CR: + state = LINE_STATE_LF; + switch (m_buffer[curpos]) + { + case 0x0A: /* CRLF */ + /* eat current char */ + curpos++; + break; + default: /* single CR */ + /* keep current char */ + break; } - return osl_File_E_None; - case ERROR_NO_MORE_ITEMS: - return osl_File_E_NOENT; + break; default: - return MapError( dwError ); + /* determine next state */ + switch (m_buffer[curpos]) + { + case 0x0A: /* single LF */ + state = LINE_STATE_LF; + break; + case 0x0D: /* CR */ + state = LINE_STATE_CR; + break; + default: /* advance to next char */ + curpos++; + break; + } + if (state != LINE_STATE_BEGIN) + { + /* store (and eat) the newline char */ + m_buffer[curpos] = 0x0A, curpos++; + + /* flush buffer to sequence */ + result = writeSequence_Impl ( + ppSequence, &dstpos, &(m_buffer[bufpos]), curpos - bufpos - 1); + if (result != osl_File_E_None) + return (result); + *pBytesRead += curpos - bufpos, nOffset += curpos - bufpos; + } + break; } } - //##################################################### - oslFileError SAL_CALL osl_getNextDrive( - oslDirectory Directory, oslDirectoryItem *pItem, sal_uInt32 uHint ) - { - Directory_Impl *pDirImpl = (Directory_Impl *)Directory; - DirectoryItem_Impl *pItemImpl = NULL; - BOOL fSuccess; - - uHint = uHint; /* avoid warnings */ - - if ( !pItem ) - return osl_File_E_INVAL; - - *pItem = NULL; + result = writeSequence_Impl (ppSequence, &dstpos, 0, 0); + if (result != osl_File_E_None) + return (result); + if (0 < dstpos) + return osl_File_E_None; + if (bufpos >= m_buflen) + return osl_File_E_AGAIN; + return osl_File_E_None; +} - if ( !pDirImpl ) - return osl_File_E_INVAL; +oslFileError FileHandle_Impl::writeSequence_Impl ( + sal_Sequence ** ppSequence, + SIZE_T * pnOffset, + const void * pBuffer, + SIZE_T nBytes) +{ + sal_Int32 nElements = *pnOffset + nBytes; + if (!*ppSequence) + { + /* construct sequence */ + rtl_byte_sequence_constructNoDefault(ppSequence, nElements); + } + else if (nElements != (*ppSequence)->nElements) + { + /* resize sequence */ + rtl_byte_sequence_realloc(ppSequence, nElements); + } + if (*ppSequence != 0) + { + /* fill sequence */ + memcpy(&((*ppSequence)->elements[*pnOffset]), pBuffer, nBytes), *pnOffset += nBytes; + } + return (*ppSequence != 0) ? osl_File_E_None : osl_File_E_NOMEM; +} - pItemImpl = reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); - if ( !pItemImpl ) - return osl_File_E_NOMEM; +oslFileError FileHandle_Impl::syncFile() +{ + oslFileError result = osl_File_E_None; + if (m_state & STATE_MODIFIED) + { + sal_uInt64 uDone = 0; + result = writeAt (m_bufptr, m_buffer, m_buflen, &uDone); + if (result != osl_File_E_None) + return (result); + if (uDone != m_buflen) + return osl_File_E_IO; + m_state &= ~STATE_MODIFIED; + } + return (result); +} +//################################################################## +// File I/O functions +//################################################################## - ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); - pItemImpl->uType = DIRECTORYITEM_DRIVE; - osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); - fSuccess = EnumLogicalDrives( pDirImpl->hEnumDrives, pItemImpl->cDriveString ); +extern "C" oslFileHandle +SAL_CALL osl_createFileHandleFromOSHandle ( + HANDLE hFile, + sal_uInt32 uFlags) +{ + if ( !IsValidHandle(hFile) ) + return 0; // EINVAL - if ( fSuccess ) - { - *pItem = pItemImpl; - return osl_File_E_None; - } - else - { - rtl_freeMemory( pItemImpl ); - return MapError( GetLastError() ); - } + FileHandle_Impl * pImpl = new FileHandle_Impl(hFile); + if (pImpl == 0) + { + // cleanup and fail + (void) ::CloseHandle(hFile); + return 0; // ENOMEM } - //##################################################### - oslFileError SAL_CALL osl_getNextFileItem( - oslDirectory Directory, oslDirectoryItem *pItem, sal_uInt32 uHint) + /* check for regular file */ + if (FILE_TYPE_DISK == GetFileType(hFile)) { - Directory_Impl *pDirImpl = (Directory_Impl *)Directory; - DirectoryItem_Impl *pItemImpl = NULL; - BOOL fFound; - - uHint = uHint; /* avoid warnings */ + /* mark seekable */ + pImpl->m_state |= FileHandle_Impl::STATE_SEEKABLE; - if ( !pItem ) - return osl_File_E_INVAL; + /* init current size */ + LARGE_INTEGER uSize = { 0, 0 }; + (void) ::GetFileSizeEx(hFile, &uSize); + pImpl->m_size = (sal::static_int_cast(uSize.HighPart) << 32) + uSize.LowPart; + } - *pItem = NULL; + if (!(uFlags & osl_File_OpenFlag_Read)) + pImpl->m_state &= ~FileHandle_Impl::STATE_READABLE; + if (!(uFlags & osl_File_OpenFlag_Write)) + pImpl->m_state &= ~FileHandle_Impl::STATE_WRITEABLE; - if ( !pDirImpl ) - return osl_File_E_INVAL; + OSL_POSTCOND( + (uFlags & osl_File_OpenFlag_Read) || (uFlags & osl_File_OpenFlag_Write), + "osl_createFileHandleFromOSHandle(): missing read/write access flags"); + return (oslFileHandle)(pImpl); +} - pItemImpl = reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); - if ( !pItemImpl ) - return osl_File_E_NOMEM; +//############################################# +oslFileError +SAL_CALL osl_openFile( + rtl_uString * strPath, + oslFileHandle * pHandle, + sal_uInt32 uFlags ) +{ + rtl_uString * strSysPath = 0; + oslFileError result = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); + if (result != osl_File_E_None) + return (result); - memset( pItemImpl, 0, sizeof(DirectoryItem_Impl) ); - fFound = EnumDirectory( pDirImpl->hDirectory, &pItemImpl->FindData ); + DWORD dwAccess = GENERIC_READ, dwShare = FILE_SHARE_READ, dwCreation = 0, dwAttributes = 0; - if ( fFound ) - { - pItemImpl->uType = DIRECTORYITEM_FILE; - pItemImpl->nRefCount = 1; - _tcscpy( pItemImpl->szFullPath, pDirImpl->szDirectoryPath ); - _tcscat( pItemImpl->szFullPath, pItemImpl->FindData.cFileName ); - pItemImpl->bFullPathNormalized = FALSE; - *pItem = (oslDirectoryItem)pItemImpl; - return osl_File_E_None; - } - else - { - rtl_freeMemory( pItemImpl ); - return MapError( GetLastError() ); - } - } + if ( uFlags & osl_File_OpenFlag_Write ) + dwAccess |= GENERIC_WRITE; + else + dwShare |= FILE_SHARE_WRITE; - //##################################################### - oslFileError SAL_CALL osl_getDriveInfo( - oslDirectoryItem Item, oslFileStatus *pStatus, sal_uInt32 uFieldMask) - { - DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; - TCHAR cDrive[3] = TEXT("A:"); - TCHAR cRoot[4] = TEXT("A:\\"); + if ( uFlags & osl_File_OpenFlag_NoLock ) + dwShare |= FILE_SHARE_WRITE; - if ( !pItemImpl ) - return osl_File_E_INVAL; + if ( uFlags & osl_File_OpenFlag_Create ) + dwCreation |= CREATE_NEW; + else + dwCreation |= OPEN_EXISTING; - pStatus->uValidFields = 0; + HANDLE hFile = CreateFileW( + reinterpret_cast(rtl_uString_getStr( strSysPath )), + dwAccess, dwShare, NULL, dwCreation, dwAttributes, NULL ); - cDrive[0] = pItemImpl->cDriveString[0]; - cRoot[0] = pItemImpl->cDriveString[0]; + // @@@ ERROR HANDLING @@@ + if ( !IsValidHandle( hFile ) ) + result = oslTranslateFileError( GetLastError() ); - if ( uFieldMask & osl_FileStatus_Mask_FileName ) - { - if ( pItemImpl->cDriveString[0] == '\\' && - pItemImpl->cDriveString[1] == '\\' ) - { - LPCWSTR lpFirstBkSlash = wcschr( &pItemImpl->cDriveString[2], '\\' ); + *pHandle = osl_createFileHandleFromOSHandle (hFile, uFlags | osl_File_OpenFlag_Read); - if ( lpFirstBkSlash && lpFirstBkSlash[1] ) - { - LPCWSTR lpLastBkSlash = wcschr( &lpFirstBkSlash[1], '\\' ); + rtl_uString_release( strSysPath ); + return (result); +} - if ( lpLastBkSlash ) - rtl_uString_newFromStr_WithLength( &pStatus->ustrFileName, reinterpret_cast(&lpFirstBkSlash[1]), lpLastBkSlash - lpFirstBkSlash - 1 ); - else - rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(&lpFirstBkSlash[1]) ); - pStatus->uValidFields |= osl_FileStatus_Mask_FileName; - } - } - else switch ( GetDriveType( cRoot ) ) - { - case DRIVE_REMOTE: - { - TCHAR szBuffer[1024]; - DWORD dwBufsize = ELEMENTS_OF_ARRAY(szBuffer); - DWORD dwResult = WNetGetConnection( cDrive, szBuffer, &dwBufsize ); - - if ( NO_ERROR == dwResult ) - { - TCHAR szFileName[ELEMENTS_OF_ARRAY(szBuffer) + 16]; - - swprintf( szFileName, L"%s [%s]", cDrive, szBuffer ); - rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(szFileName) ); - } - else - rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(cDrive) ); - } - pStatus->uValidFields |= osl_FileStatus_Mask_FileName; - break; - case DRIVE_FIXED: - { - TCHAR szVolumeNameBuffer[1024]; +//############################################# +oslFileError +SAL_CALL osl_syncFile(oslFileHandle Handle) +{ + FileHandle_Impl * pImpl = static_cast(Handle); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile)) + return osl_File_E_INVAL; - if ( GetVolumeInformation( cRoot, szVolumeNameBuffer, ELEMENTS_OF_ARRAY(szVolumeNameBuffer), NULL, NULL, NULL, NULL, 0 ) ) - { - TCHAR szFileName[ELEMENTS_OF_ARRAY(szVolumeNameBuffer) + 16]; + oslFileError result = pImpl->syncFile(); + if (result != osl_File_E_None) + return result; - swprintf( szFileName, L"%s [%s]", cDrive, szVolumeNameBuffer ); - rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(szFileName) ); - } - else - rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(cDrive) ); - } - pStatus->uValidFields |= osl_FileStatus_Mask_FileName; - break; - case DRIVE_CDROM: - case DRIVE_REMOVABLE: - pStatus->uValidFields |= osl_FileStatus_Mask_FileName; - rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(cRoot) ); - break; - case DRIVE_UNKNOWN: - default: - break; - } - } + if (!FlushFileBuffers(pImpl->m_hFile)) + return oslTranslateFileError(GetLastError()); - pStatus->eType = osl_File_Type_Volume; - pStatus->uValidFields |= osl_FileStatus_Mask_Type; + return osl_File_E_None; +} - if ( uFieldMask & osl_FileStatus_Mask_FileURL ) - { - rtl_uString *ustrSystemPath = NULL; +//############################################# +oslFileError +SAL_CALL osl_closeFile(oslFileHandle Handle) +{ + FileHandle_Impl * pImpl = static_cast(Handle); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile)) + return osl_File_E_INVAL; - rtl_uString_newFromStr( &ustrSystemPath, reinterpret_cast(pItemImpl->cDriveString) ); - osl_getFileURLFromSystemPath( ustrSystemPath, &pStatus->ustrFileURL ); - rtl_uString_release( ustrSystemPath ); - pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; - } - return osl_File_E_None; + oslFileError result = pImpl->syncFile(); + if (result != osl_File_E_None) + { + /* ignore double failure */ + (void)::CloseHandle(pImpl->m_hFile); } - - //##################################################### - oslFileError SAL_CALL osl_getServerInfo( - oslDirectoryItem Item, oslFileStatus *pStatus, sal_uInt32 uFieldMask ) + else if (!::CloseHandle(pImpl->m_hFile)) { - DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; + /* translate error code */ + result = oslTranslateFileError( GetLastError() ); + } - if ( !pItemImpl ) - return osl_File_E_INVAL; - - pStatus->uValidFields = 0; - - // pStatus->uValidFields |= osl_FileStatus_Mask_FileName; - - // if ( _tcscmp( pItemImpl->FindData.cFileName, TEXT(".") ) == 0 ) - // rtl_uString_newFromAscii( &pStatus->ustrFileName, "/" ); - // else - // rtl_uString_newFromStr( &pStatus->ustrFileName, pItemImpl->FindData.cFileName ); - - pStatus->eType = osl_File_Type_Directory; - pStatus->uValidFields |= osl_FileStatus_Mask_Type; - - if ( uFieldMask & osl_FileStatus_Mask_FileURL ) - { - rtl_uString *ustrSystemPath = NULL; - - rtl_uString_newFromStr( &ustrSystemPath, reinterpret_cast(pItemImpl->szFullPath) ); - osl_getFileURLFromSystemPath( ustrSystemPath, &pStatus->ustrFileURL ); - rtl_uString_release( ustrSystemPath ); - pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; - } - return osl_File_E_None; - } - - typedef struct tagDRIVEENUM { - LPCTSTR lpIdent; - TCHAR cBuffer[/*('Z' - 'A' + 1) * sizeof("A:\\") + 1*/256]; - LPCTSTR lpCurrent; - } DRIVEENUM, * PDRIVEENUM, FAR * LPDRIVEENUM; - - //##################################################### - HANDLE WINAPI OpenLogicalDrivesEnum(void) - { - LPDRIVEENUM pEnum = NULL; - - pEnum = (LPDRIVEENUM)HeapAlloc( GetProcessHeap(), 0, sizeof(DRIVEENUM) ); - - if ( pEnum ) - { - DWORD dwNumCopied = GetLogicalDriveStrings( (sizeof(pEnum->cBuffer) - 1) / sizeof(TCHAR), pEnum->cBuffer ); - - if ( dwNumCopied && dwNumCopied < sizeof(pEnum->cBuffer) / sizeof(TCHAR) ) - { - pEnum->lpCurrent = pEnum->cBuffer; - pEnum->lpIdent = L"tagDRIVEENUM"; - } - else - { - HeapFree( GetProcessHeap(), 0, pEnum ); - pEnum = NULL; - } - } - return pEnum ? (HANDLE)pEnum : INVALID_HANDLE_VALUE; - } - - //##################################################### - BOOL WINAPI EnumLogicalDrives(HANDLE hEnum, LPTSTR lpBuffer) - { - BOOL fSuccess = FALSE; - LPDRIVEENUM pEnum = (LPDRIVEENUM)hEnum; - - if ( pEnum ) - { - int nLen = _tcslen( pEnum->lpCurrent ); - - if ( nLen ) - { - CopyMemory( lpBuffer, pEnum->lpCurrent, (nLen + 1) * sizeof(TCHAR) ); - pEnum->lpCurrent += nLen + 1; - fSuccess = TRUE; - } - else - SetLastError( ERROR_NO_MORE_FILES ); - } - else - SetLastError( ERROR_INVALID_HANDLE ); - - return fSuccess; - } - - //##################################################### - BOOL WINAPI CloseLogicalDrivesEnum(HANDLE hEnum) - { - BOOL fSuccess = FALSE; - LPDRIVEENUM pEnum = (LPDRIVEENUM)hEnum; - - if ( pEnum ) - { - HeapFree( GetProcessHeap(), 0, pEnum ); - fSuccess = TRUE; - } - else - SetLastError( ERROR_INVALID_HANDLE ); - - return fSuccess; - } - - //##################################################### - //Undocumented in SHELL32.DLL ordinal 35 - BOOL WINAPI PathRemoveFileSpec(LPTSTR lpPath) - { - BOOL fSuccess = FALSE; // Assume failure - LPTSTR lpLastBkSlash = _tcsrchr( lpPath, '\\' ); - LPTSTR lpLastSlash = _tcsrchr( lpPath, '/' ); - LPTSTR lpLastDelimiter = lpLastSlash > lpLastBkSlash ? lpLastSlash : lpLastBkSlash; - - if ( lpLastDelimiter ) - { - if ( 0 == *(lpLastDelimiter + 1) ) - { - if ( lpLastDelimiter > lpPath && *(lpLastDelimiter - 1) != ':' ) - { - *lpLastDelimiter = 0; - fSuccess = TRUE; - } - } - else - { - *(++lpLastDelimiter) = 0; - fSuccess = TRUE; - } - } - return fSuccess; - } - - //##################################################### - // Undocumented in SHELL32.DLL ordinal 32 - LPTSTR WINAPI PathAddBackslash(LPTSTR lpPath) - { - LPTSTR lpEndPath = NULL; - - if ( lpPath ) - { - int nLen = _tcslen(lpPath); - - if ( !nLen || lpPath[nLen-1] != '\\' && lpPath[nLen-1] != '/' && nLen < MAX_PATH - 1 ) - { - lpEndPath = lpPath + nLen; - *lpEndPath++ = '\\'; - *lpEndPath = 0; - } - } - return lpEndPath; - } - -#if 1 - //##################################################### - // Same as GetLongPathName but also 95/NT4 - DWORD WINAPI GetCaseCorrectPathNameEx( - LPCTSTR lpszShortPath, // file name - LPTSTR lpszLongPath, // path buffer - DWORD cchBuffer, // size of path buffer - DWORD nSkipLevels - ) - { -// log file doesn't work, because initialization of rtl log init() calls this method... -// RTL_LOGFILE_TRACE1( "SAL: GetCaseCorrectPathNameEx: %s (Skip:%n)", lpszShortPath,nSkipLevels ); - - TCHAR szPath[MAX_PATH]; - BOOL fSuccess; - - cchBuffer = cchBuffer; /* avoid warnings */ - - _tcscpy( szPath, lpszShortPath ); - - fSuccess = PathRemoveFileSpec( szPath ); - - if ( fSuccess ) - { - int nLen = _tcslen( szPath ); - LPCTSTR lpszFileSpec = lpszShortPath + nLen; - BOOL bSkipThis; - - if ( 0 == _tcscmp( lpszFileSpec, TEXT("..") ) ) - { - bSkipThis = TRUE; - nSkipLevels += 1; - } - else if ( - 0 == _tcscmp( lpszFileSpec, TEXT(".") ) || - 0 == _tcscmp( lpszFileSpec, TEXT("\\") ) || - 0 == _tcscmp( lpszFileSpec, TEXT("/") ) - ) - { - bSkipThis = TRUE; - } - else if ( nSkipLevels ) - { - bSkipThis = TRUE; - nSkipLevels--; - } - else - bSkipThis = FALSE; - - GetCaseCorrectPathNameEx( szPath, szPath, MAX_PATH, nSkipLevels ); - - PathAddBackslash( szPath ); - - /* Analyze parent if not only a trailing backslash was cutted but a real file spec */ - if ( !bSkipThis ) - { - WIN32_FIND_DATA aFindFileData; - HANDLE hFind = FindFirstFile( lpszShortPath, &aFindFileData ); - - if ( IsValidHandle(hFind) ) - { - _tcscat( szPath, aFindFileData.cFileName[0] ? aFindFileData.cFileName : aFindFileData.cAlternateFileName ); - - FindClose( hFind ); - } - else - return 0; - } - } - else - { - /* File specification can't be removed therefore the short path is either a drive - or a network share. If still levels to skip are left, the path specification - tries to travel below the file system root */ - if ( nSkipLevels ) - return 0; - - _tcsupr( szPath ); - } - - _tcscpy( lpszLongPath, szPath ); - - return _tcslen( lpszLongPath ); - } -#endif - -#if 0 - inline size_t wcstoupper( LPWSTR lpStr ) - { - size_t nLen = wcslen( lpStr ); - - for ( LPWSTR p = lpStr; p < lpStr + nLen; p++ ) - { - *p = towupper(*p); - } - - return nLen; - } - -#endif - - //##################################################### - DWORD WINAPI GetCaseCorrectPathName( - LPCTSTR lpszShortPath, // file name - LPTSTR lpszLongPath, // path buffer - DWORD cchBuffer // size of path buffer - ) -#if 0 - { - /* Special handling for "\\.\" as system root */ - if ( lpszShortPath && 0 == wcscmp( lpszShortPath, WSTR_SYSTEM_ROOT_PATH ) ) - { - if ( cchBuffer >= ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) ) - { - wcscpy( lpszLongPath, WSTR_SYSTEM_ROOT_PATH ); - return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; - } - else - return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH); - } - else - { - DWORD nSrcLen = wcslen( lpszShortPath ); - - if ( cchBuffer > nSrcLen ) - { - wcscpy( lpszLongPath, lpszShortPath ); - wcstoupper( lpszLongPath ); - } - else - nSrcLen++; - - return nSrcLen; - } - } -#else - { - /* Special handling for "\\.\" as system root */ - if ( lpszShortPath && 0 == wcscmp( lpszShortPath, WSTR_SYSTEM_ROOT_PATH ) ) - { - if ( cchBuffer >= ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) ) - { - wcscpy( lpszLongPath, WSTR_SYSTEM_ROOT_PATH ); - return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; - } - else - return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; - } - else - return GetCaseCorrectPathNameEx( lpszShortPath, lpszLongPath, cchBuffer, 0 ); - } - -#endif - - //##################################################### - #define CHARSET_SEPARATOR TEXT("\\/") - - BOOL WINAPI IsValidFilePathComponent( - LPCTSTR lpComponent, LPCTSTR *lppComponentEnd, DWORD dwFlags) - { - LPCTSTR lpComponentEnd = NULL; - LPCTSTR lpCurrent = lpComponent; - BOOL fValid = TRUE; /* Assume success */ - TCHAR cLast = 0; - - /* Path component length must not exceed MAX_PATH */ - - while ( !lpComponentEnd && lpCurrent && lpCurrent - lpComponent < MAX_PATH ) - { - switch ( *lpCurrent ) - { - /* Both backslash and slash determine the end of a path component */ - case '\0': - case '/': - case '\\': - switch ( cLast ) - { - /* Component must not end with '.' or blank and can't be empty */ - - case '.': - if ( dwFlags & VALIDATEPATH_ALLOW_ELLIPSE ) - { - if ( 1 == lpCurrent - lpComponent ) - { - /* Current directory is O.K. */ - lpComponentEnd = lpCurrent; - break; - } - else if ( 2 == lpCurrent - lpComponent && '.' == *lpComponent ) - { - /* Parent directory is O.K. */ - lpComponentEnd = lpCurrent; - break; - } - } - case 0: - case ' ': - lpComponentEnd = lpCurrent - 1; - fValid = FALSE; - break; - default: - lpComponentEnd = lpCurrent; - break; - } - break; - /* '?' and '*' are valid wildcards but not valid file name characters */ - case '?': - case '*': - if ( dwFlags & VALIDATEPATH_ALLOW_WILDCARDS ) - break; - /* The following characters are reserved */ - case '<': - case '>': - case '\"': - case '|': - case ':': - lpComponentEnd = lpCurrent; - fValid = FALSE; - break; - default: - /* Characters below ASCII 32 are not allowed */ - if ( *lpCurrent < ' ' ) - { - lpComponentEnd = lpCurrent; - fValid = FALSE; - } - break; - } - cLast = *lpCurrent++; - } - - /* If we don't reached the end of the component the length of the component was to long - ( See condition of while loop ) */ - if ( !lpComponentEnd ) - { - fValid = FALSE; - lpComponentEnd = lpCurrent; - } - - /* Test wether the component specifies a device name what is not allowed */ - - // MT: PERFORMANCE: - // This is very expensive. A lot of calls to _tcsicmp. - // in SRC6870m71 67.000 calls of this method while empty office start result into more than 1.500.00 calls of _tcsicmp! - // Possible optimizations - // - Array should be const static - // - Sorted array, use binary search - // - More intelligent check for com1-9, lpt1-9 - // Maybe make szComponent upper case, don't search case intensitive - // Talked to HRO: Could be removed. Shouldn't be used in OOo, and if used for something like a filename, it will lead to an error anyway. - /* - if ( fValid ) - { - LPCTSTR alpDeviceNames[] = - { - TEXT("CON"), - TEXT("PRN"), - TEXT("AUX"), - TEXT("CLOCK$"), - TEXT("NUL"), - TEXT("LPT1"), - TEXT("LPT2"), - TEXT("LPT3"), - TEXT("LPT4"), - TEXT("LPT5"), - TEXT("LPT6"), - TEXT("LPT7"), - TEXT("LPT8"), - TEXT("LPT9"), - TEXT("COM1"), - TEXT("COM2"), - TEXT("COM3"), - TEXT("COM4"), - TEXT("COM5"), - TEXT("COM6"), - TEXT("COM7"), - TEXT("COM8"), - TEXT("COM9") - }; - - TCHAR szComponent[MAX_PATH]; - int nComponentLength; - LPCTSTR lpDot; - int i; - - // A device name with an extension is also invalid - lpDot = _tcschr( lpComponent, '.' ); - - if ( !lpDot || lpDot > lpComponentEnd ) - nComponentLength = lpComponentEnd - lpComponent; - else - nComponentLength = lpDot - lpComponent; - - _tcsncpy( szComponent, lpComponent, nComponentLength ); - szComponent[nComponentLength] = 0; - - for ( i = 0; i < sizeof( alpDeviceNames ) / sizeof(LPCTSTR); i++ ) - { - if ( 0 == _tcsicmp( szComponent, alpDeviceNames[i] ) ) - { - lpComponentEnd = lpComponent; - fValid = FALSE; - break; - } - } - } - */ - - if ( fValid ) - { - // Empty components are not allowed - if ( lpComponentEnd - lpComponent < 1 ) - fValid = FALSE; - - // If we reached the end of the string NULL is returned - else if ( !*lpComponentEnd ) - lpComponentEnd = NULL; - - } - - if ( lppComponentEnd ) - *lppComponentEnd = lpComponentEnd; - - return fValid; - } - - //##################################################### - DWORD WINAPI IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_uString **corrected) - { - LPCTSTR lpszPath = reinterpret_cast< LPCTSTR >(path->buffer); - LPCTSTR lpComponent; - BOOL fValid = TRUE; - DWORD dwPathType = PATHTYPE_ERROR; - - if ( dwFlags & VALIDATEPATH_ALLOW_RELATIVE ) - dwFlags |= VALIDATEPATH_ALLOW_ELLIPSE; - - if ( !lpszPath ) - { - fValid = FALSE; - lpComponent = lpszPath; - } - - /* Test for UNC path notation */ - if ( 2 == _tcsspn( lpszPath, CHARSET_SEPARATOR ) ) - { - /* Place the pointer behind the leading to backslashes */ - - lpComponent = lpszPath + 2; - - fValid = IsValidFilePathComponent( lpComponent, &lpComponent, VALIDATEPATH_ALLOW_ELLIPSE ); - - /* So far we have a valid servername. Now let's see if we also have a network resource */ - - dwPathType = PATHTYPE_ABSOLUTE_UNC; - - if ( fValid ) - { - if ( lpComponent && !*++lpComponent ) - lpComponent = NULL; - - if ( !lpComponent ) - { - #if 0 - /* We only have a Server specification what is invalid */ - - lpComponent = lpszPath; - fValid = FALSE; - #else - dwPathType |= PATHTYPE_IS_SERVER; - #endif - } - else - { - /* Now test the network resource */ - - fValid = IsValidFilePathComponent( lpComponent, &lpComponent, 0 ); - - /* If we now reached the end of the path, everything is O.K. */ - - - if ( fValid && (!lpComponent || lpComponent && !*++lpComponent ) ) - { - lpComponent = NULL; - dwPathType |= PATHTYPE_IS_VOLUME; - } - } - } - } - - /* Local path verification. Must start with : */ - else if ( _istalpha( lpszPath[0] ) && ':' == lpszPath[1] ) - { - /* Place pointer behind correct drive specification */ - - lpComponent = lpszPath + 2; - - if ( 1 == _tcsspn( lpComponent, CHARSET_SEPARATOR ) ) - lpComponent++; - else if ( *lpComponent ) - fValid = FALSE; - - dwPathType = PATHTYPE_ABSOLUTE_LOCAL; - - /* Now we are behind the backslash or it was a simple drive without backslash */ - - if ( fValid && !*lpComponent ) - { - lpComponent = NULL; - dwPathType |= PATHTYPE_IS_VOLUME; - } - } - - /* Can be a relative path */ - else if ( dwFlags & VALIDATEPATH_ALLOW_RELATIVE ) - { - lpComponent = lpszPath; - - /* Relative path can start with a backslash */ - - if ( 1 == _tcsspn( lpComponent, CHARSET_SEPARATOR ) ) - { - lpComponent++; - if ( !*lpComponent ) - lpComponent = NULL; - } - - dwPathType = PATHTYPE_RELATIVE; - } - - /* Anything else is an error */ - else - { - fValid = FALSE; - lpComponent = lpszPath; - } - - /* Now validate each component of the path */ - while ( fValid && lpComponent ) - { - // Correct path by merging consecutive slashes: - if (*lpComponent == '\\' && corrected != NULL) { - sal_Int32 i = lpComponent - lpszPath; - rtl_uString_newReplaceStrAt(corrected, path, i, 1, NULL); - //TODO: handle out-of-memory - lpszPath = reinterpret_cast< LPCTSTR >((*corrected)->buffer); - lpComponent = lpszPath + i; - } - - fValid = IsValidFilePathComponent( lpComponent, &lpComponent, dwFlags ); - - if ( fValid && lpComponent ) - { - lpComponent++; - - /* If the string behind the backslash is empty, we've done */ - - if ( !*lpComponent ) - lpComponent = NULL; - } - } - - if ( fValid && _tcslen( lpszPath ) >= MAX_PATH ) - { - fValid = FALSE; - lpComponent = lpszPath + MAX_PATH; - } - - if ( lppError ) - *lppError = lpComponent; - - return fValid ? dwPathType : PATHTYPE_ERROR; - } - - //##################################################### - bool is_floppy_drive(const rtl::OUString& path); - - //##################################################### - struct Component - { - Component() : - begin_(0), end_(0) - {} - - bool isPresent() const - { return (static_cast(end_ - begin_) > 0); } - - const sal_Unicode* begin_; - const sal_Unicode* end_; - }; - - //##################################################### - struct UNCComponents - { - Component server_; - Component share_; - Component resource_; - }; - - //##################################################### - const wchar_t UNC_PREFIX[] = L"\\\\"; - const wchar_t BACKSLASH = '\\'; - const wchar_t SLASH = '/'; - - bool is_UNC_path(const sal_Unicode* path) - { return (0 == wcsncmp(UNC_PREFIX, reinterpret_cast(path), ELEMENTS_OF_ARRAY(UNC_PREFIX) - 1)); } - - //##################################################### - bool is_UNC_path(const rtl::OUString& path) - { return is_UNC_path(path.getStr()); } - - //##################################################### - void parse_UNC_path(const sal_Unicode* path, UNCComponents* puncc) - { - OSL_PRECOND(is_UNC_path(path), "Precondition violated: No UNC path"); - OSL_PRECOND(rtl_ustr_indexOfChar(path, SLASH) != -1, "Path must not contain slashes"); - - const sal_Unicode* pend = path + rtl_ustr_getLength(path); - const sal_Unicode* ppos = path + 2; - - puncc->server_.begin_ = ppos; - while ((ppos < pend) && (*ppos != BACKSLASH)) - ppos++; - - puncc->server_.end_ = ppos; - - if (BACKSLASH == *ppos) - { - puncc->share_.begin_ = ++ppos; - while ((ppos < pend) && (*ppos != BACKSLASH)) - ppos++; - - puncc->share_.end_ = ppos; - - if (BACKSLASH == *ppos) - { - puncc->resource_.begin_ = ++ppos; - while (ppos < pend) - ppos++; - - puncc->resource_.end_ = ppos; - } - } - - OSL_POSTCOND(puncc->server_.isPresent() && puncc->share_.isPresent(), \ - "Postcondition violated: Invalid UNC path detected"); - } - - //##################################################### - void parse_UNC_path(const rtl::OUString& path, UNCComponents* puncc) - { parse_UNC_path(path.getStr(), puncc); } - - //##################################################### - bool is_volume_mount_point(const rtl::OUString& path) - { - rtl::OUString p(path); - osl::systemPathRemoveSeparator(p); - - bool is_volume_root = false; - - if (!is_floppy_drive(p)) - { - DWORD fattr = GetFileAttributes(reinterpret_cast(p.getStr())); - - if ((INVALID_FILE_ATTRIBUTES != fattr) && - (FILE_ATTRIBUTE_REPARSE_POINT & fattr)) - { - WIN32_FIND_DATA find_data; - HANDLE h_find = FindFirstFile(reinterpret_cast(p.getStr()), &find_data); - - if (IsValidHandle(h_find) && - (FILE_ATTRIBUTE_REPARSE_POINT & find_data.dwFileAttributes) && - (IO_REPARSE_TAG_MOUNT_POINT == find_data.dwReserved0)) - { - is_volume_root = true; - } - if (IsValidHandle(h_find)) - FindClose(h_find); - } - } - return is_volume_root; - } - - //##################################################### - // Has the given path a parent or are we already there, - // e.g. 'c:\' or '\\server\share\'? - bool has_path_parent(const sal_Unicode* path) - { - bool has_parent = false; - - if (is_UNC_path(path)) - { - UNCComponents unc_comp; - parse_UNC_path(path, &unc_comp); - has_parent = unc_comp.resource_.isPresent(); - } - else - { - has_parent = !osl::systemPathIsLogicalDrivePattern(path); - } - return has_parent; - } - - //##################################################### - // @see bool has_path_parent(const sal_Unicode* path) - bool has_path_parent(const rtl::OUString& path) - { return has_path_parent(path.getStr()); } - - //##################################################### - bool path_get_parent(rtl::OUString& path) - { - OSL_PRECOND(path.lastIndexOf(SLASH) == -1, "Path must not have slashes"); - - if (!has_path_parent(path)) - { - sal_Int32 i = path.lastIndexOf(BACKSLASH); - if (-1 < i) - { - path = rtl::OUString(path.getStr(), i); - return true; - } - } - return false; - } - - //############################################# - /* Cut off the last part of the given path to - get the parent only, e.g. 'c:\dir\subdir' -> - 'c:\dir' or '\\share\sub\dir' -> '\\share\sub' - @return The position where the path has been cut - off (this is the posistion of the last backslash). - If there are no more parents 0 will be returned, - e.g. 'c:\' or '\\Share' have no more parents */ - int path_make_parent(sal_Unicode* path) - { - OSL_PRECOND(rtl_ustr_indexOfChar(path, SLASH) != -1, "Path must not contain slashes"); - OSL_PRECOND(has_path_parent(path), "Path must have a parent"); - - sal_Unicode* pos_last_backslash = path + rtl_ustr_lastIndexOfChar(path, BACKSLASH); - *pos_last_backslash = 0; - return (pos_last_backslash - path); - } - - //##################################################### - void path_travel_to_volume_root(const rtl::OUString& system_path, rtl::OUString& volume_root) - { - rtl::OUString sys_path(system_path); - - while(!is_volume_mount_point(sys_path) && path_get_parent(sys_path)) - /**/; - - volume_root = sys_path; - osl_systemPathEnsureSeparator(&volume_root.pData); - } - - //##################################################### - inline bool is_floppy_A_present() - { return (GetLogicalDrives() & 1); } - - //##################################################### - inline bool is_floppy_B_present() - { return (GetLogicalDrives() & 2); } - - //##################################################### - // determines if a volume mount point shows to a floppy - // disk by comparing the unique volume names - const LPWSTR FLOPPY_A = L"A:\\"; - const LPWSTR FLOPPY_B = L"B:\\"; - - bool is_floppy_volume_mount_point(const rtl::OUString& path) - { - rtl::OUString p(path); - osl_systemPathEnsureSeparator(&p.pData); - - TCHAR vn[51]; - if (GetVolumeNameForVolumeMountPoint(reinterpret_cast(p.getStr()), vn, ELEMENTS_OF_ARRAY(vn))) - { - TCHAR vnfloppy[51]; - if (is_floppy_A_present() && - GetVolumeNameForVolumeMountPoint(FLOPPY_A, vnfloppy, ELEMENTS_OF_ARRAY(vnfloppy)) && - (0 == wcscmp(vn, vnfloppy))) - return true; - - if (is_floppy_B_present() && - GetVolumeNameForVolumeMountPoint(FLOPPY_B, vnfloppy, ELEMENTS_OF_ARRAY(vnfloppy)) && - (0 == wcscmp(vn, vnfloppy))) - return true; - } - return false; - } - - //################################################ - // we must take into account that even a floppy - // drive may be mounted to a directory so checking - // for the drive letter alone is not sufficient - // we must compare the unique volume name with - // that of the available floppy disks - LPCWSTR FLOPPY_DRV_LETTERS = TEXT("AaBb"); - - bool is_floppy_drive(const rtl::OUString& path) - { - const sal_Unicode* pf = path.getStr(); - const sal_Unicode* ps = path.getStr() + 1; - return ((wcschr(FLOPPY_DRV_LETTERS, *pf) && (L':' == *ps)) || - is_floppy_volume_mount_point(path)); - } - - //############################################# - UINT get_volume_mount_point_drive_type(const rtl::OUString& path) - { - if (0 == path.getLength()) - return GetDriveType(NULL); - - rtl::OUString p(path); - osl_systemPathEnsureSeparator(&p.pData); - - TCHAR vn[51]; - if (GetVolumeNameForVolumeMountPoint(reinterpret_cast(p.getStr()), vn, ELEMENTS_OF_ARRAY(vn))) - return GetDriveType(vn); - - return DRIVE_NO_ROOT_DIR; - } - - //############################################# - oslFileError osl_get_drive_type(const rtl::OUString& path, oslVolumeInfo* pInfo) - { - // GetDriveType fails on empty volume mount points - // see Knowledge Base Q244089 - UINT drive_type; - if (is_volume_mount_point(path)) - drive_type = get_volume_mount_point_drive_type(path); - else - drive_type = GetDriveType(reinterpret_cast(path.getStr())); - - if (DRIVE_NO_ROOT_DIR == drive_type) - return MapError(ERROR_INVALID_DRIVE); - - pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; - - switch (drive_type) - { - case DRIVE_CDROM: - pInfo->uAttributes |= osl_Volume_Attribute_CompactDisc | osl_Volume_Attribute_Removeable; - break; - case DRIVE_REMOVABLE: - pInfo->uAttributes |= osl_Volume_Attribute_Removeable; - if (is_floppy_drive(path)) - pInfo->uAttributes |= osl_Volume_Attribute_FloppyDisk; - break; - case DRIVE_FIXED: - pInfo->uAttributes |= osl_Volume_Attribute_FixedDisk; - break; - case DRIVE_RAMDISK: - pInfo->uAttributes |= osl_Volume_Attribute_RAMDisk; - break; - case DRIVE_REMOTE: - pInfo->uAttributes |= osl_Volume_Attribute_Remote; - break; - case DRIVE_UNKNOWN: - pInfo->uAttributes = 0; - break; - default: - pInfo->uValidFields &= ~osl_VolumeInfo_Mask_Attributes; - pInfo->uAttributes = 0; - break; - } - return osl_File_E_None; - } - - //############################################# - inline bool is_volume_space_info_request(sal_uInt32 field_mask) - { - return (field_mask & - (osl_VolumeInfo_Mask_TotalSpace | - osl_VolumeInfo_Mask_UsedSpace | - osl_VolumeInfo_Mask_FreeSpace)); - } - - //############################################# - void get_volume_space_information(const rtl::OUString& path, oslVolumeInfo *pInfo) - { - BOOL ret = GetDiskFreeSpaceEx( - reinterpret_cast(path.getStr()), - (PULARGE_INTEGER)&pInfo->uFreeSpace, - (PULARGE_INTEGER)&pInfo->uTotalSpace, - NULL); - - if (ret) - { - pInfo->uUsedSpace = pInfo->uTotalSpace - pInfo->uFreeSpace; - pInfo->uValidFields |= osl_VolumeInfo_Mask_TotalSpace | - osl_VolumeInfo_Mask_UsedSpace | - osl_VolumeInfo_Mask_FreeSpace; - } - } - - //############################################# - inline bool is_filesystem_attributes_request(sal_uInt32 field_mask) - { - return (field_mask & - (osl_VolumeInfo_Mask_MaxNameLength | - osl_VolumeInfo_Mask_MaxPathLength | - osl_VolumeInfo_Mask_FileSystemName | - osl_VolumeInfo_Mask_FileSystemCaseHandling)); - } - - //############################################# - inline bool is_drivetype_request(sal_uInt32 field_mask) - { - return (field_mask & osl_VolumeInfo_Mask_Attributes); - } - - //############################################# - oslFileError get_filesystem_attributes(const rtl::OUString& path, sal_uInt32 field_mask, oslVolumeInfo* pInfo) - { - pInfo->uAttributes = 0; - - oslFileError osl_error = osl_File_E_None; - - // osl_get_drive_type must be called first because - // this function resets osl_VolumeInfo_Mask_Attributes - // on failure - if (is_drivetype_request(field_mask)) - osl_error = osl_get_drive_type(path, pInfo); - - if ((osl_File_E_None == osl_error) && is_filesystem_attributes_request(field_mask)) - { - WCHAR vn[MAX_PATH]; - WCHAR fsn[MAX_PATH]; - DWORD serial; - DWORD mcl; - DWORD flags; - - if (GetVolumeInformation(reinterpret_cast(path.getStr()), vn, MAX_PATH, &serial, &mcl, &flags, fsn, MAX_PATH)) - { - pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxNameLength; - pInfo->uMaxNameLength = mcl; - - pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxPathLength; - pInfo->uMaxPathLength = MAX_PATH; - - pInfo->uValidFields |= osl_VolumeInfo_Mask_FileSystemName; - rtl_uString_newFromStr(&pInfo->ustrFileSystemName, reinterpret_cast(fsn)); - - // volumes (even NTFS) will always be considered case - // insensitive because the Win32 API is not able to - // deal with case sensitive volumes see M$ Knowledge Base - // article 100625 that's why we never set the attribute - // osl_Volume_Attribute_Case_Sensitive - - if (flags & FS_CASE_IS_PRESERVED) - pInfo->uAttributes |= osl_Volume_Attribute_Case_Is_Preserved; - - pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; - } - } - return osl_error; - } - - //############################################# - // Create the specified directory and call the - // user specified callback function. On success - // the function returns ERROR_SUCCESS else a - // Win32 error code. - DWORD create_dir_with_callback( - sal_Unicode* dir_path, - oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, - void* pData) - { - if (CreateDirectory(reinterpret_cast(dir_path), NULL)) - { - if (aDirectoryCreationCallbackFunc) - { - rtl::OUString url; - FileBase::getFileURLFromSystemPath(dir_path, url); - aDirectoryCreationCallbackFunc(pData, url.pData); - } - return ERROR_SUCCESS; - } - return GetLastError(); - } - - //############################################# - DWORD create_dir_recursively_( - sal_Unicode* dir_path, - oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, - void* pData) - { - OSL_PRECOND(rtl_ustr_getLength(dir_path) > 0 && (rtl_ustr_lastIndexOfChar(dir_path, BACKSLASH) != rtl_ustr_getLength(dir_path) - 1), \ - "Path must not end with a backslash"); - - DWORD w32_error = create_dir_with_callback( - dir_path, aDirectoryCreationCallbackFunc, pData); - - if (w32_error == ERROR_SUCCESS) - return ERROR_SUCCESS; - - if ((w32_error != ERROR_PATH_NOT_FOUND) || !has_path_parent(dir_path)) - return w32_error; - - int pos = path_make_parent(dir_path); - - w32_error = create_dir_recursively_( - dir_path, aDirectoryCreationCallbackFunc, pData); - - if (ERROR_SUCCESS != w32_error) - return w32_error; - - dir_path[pos] = BACKSLASH; - - return create_dir_recursively_( - dir_path, aDirectoryCreationCallbackFunc, pData); - } - - //##################################################### - // Temp file - //##################################################### - - - //##################################################### - oslFileError osl_setup_base_directory_impl_( - rtl_uString* pustrDirectoryURL, - rtl_uString** ppustr_base_dir) - { - rtl_uString* dir_url = 0; - rtl_uString* dir = 0; - oslFileError error = osl_File_E_None; - - if (pustrDirectoryURL) - rtl_uString_assign(&dir_url, pustrDirectoryURL); - else - error = osl_getTempDirURL(&dir_url); - - if (osl_File_E_None == error) - { - error = _osl_getSystemPathFromFileURL(dir_url, &dir, sal_False); - rtl_uString_release(dir_url); - } - - if (osl_File_E_None == error ) - { - rtl_uString_assign(ppustr_base_dir, dir); - rtl_uString_release(dir); - } - - return error; - } - - //##################################################### - oslFileError osl_setup_createTempFile_impl_( - rtl_uString* pustrDirectoryURL, - oslFileHandle* pHandle, - rtl_uString** ppustrTempFileURL, - rtl_uString** ppustr_base_dir, - sal_Bool* b_delete_on_close) - { - oslFileError osl_error; - - OSL_PRECOND(((0 != pHandle) || (0 != ppustrTempFileURL)), "Invalid parameter!"); - - if ((0 == pHandle) && (0 == ppustrTempFileURL)) - { - osl_error = osl_File_E_INVAL; - } - else - { - osl_error = osl_setup_base_directory_impl_( - pustrDirectoryURL, ppustr_base_dir); - - *b_delete_on_close = (sal_Bool)(0 == ppustrTempFileURL); - } - - return osl_error; - } - - //##################################################### - oslFileError osl_win32_GetTempFileName_impl_( - rtl_uString* base_directory, LPWSTR temp_file_name) - { - oslFileError osl_error = osl_File_E_None; - - if (0 == GetTempFileNameW( - reinterpret_cast(rtl_uString_getStr(base_directory)), - L"", - 0, - temp_file_name)) - { - osl_error = MapError(GetLastError()); - } - - return osl_error; - } - - //##################################################### - sal_Bool osl_win32_CreateFile_impl_( - LPCWSTR file_name, sal_Bool b_delete_on_close, oslFileHandle* p_handle) - { - DWORD flags = FILE_ATTRIBUTE_NORMAL; - HANDLE hFile; - - OSL_ASSERT(p_handle); - - if (b_delete_on_close) - flags |= FILE_FLAG_DELETE_ON_CLOSE; - - hFile = CreateFileW( - file_name, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - TRUNCATE_EXISTING, - flags, - NULL); - - if (IsValidHandle(hFile)) - *p_handle = (oslFileHandle)hFile; - - return (sal_Bool)IsValidHandle(hFile); - } - - //############################################# - oslFileError osl_createTempFile_impl_( - rtl_uString* base_directory, - LPWSTR tmp_name, - sal_Bool b_delete_on_close, - oslFileHandle* pHandle, - rtl_uString** ppustrTempFileURL) - { - oslFileError osl_error; - - do - { - osl_error = osl_win32_GetTempFileName_impl_(base_directory, tmp_name); - - /* if file could not be opened try again */ - - if ((osl_File_E_None != osl_error) || (0 == pHandle) || - osl_win32_CreateFile_impl_(tmp_name, b_delete_on_close, pHandle)) - break; - - } while(1); // try until success - - if ((osl_File_E_None == osl_error) && !b_delete_on_close) - { - rtl_uString* pustr = 0; - rtl_uString_newFromStr(&pustr, reinterpret_cast(tmp_name)); - osl_getFileURLFromSystemPath(pustr, ppustrTempFileURL); - rtl_uString_release(pustr); - } - - return osl_error; - } - - //##################################################### - // End Temp file - //##################################################### - - - //############################################# - sal_Bool _osl_decodeURL( rtl_String* strUTF8, rtl_uString** pstrDecodedURL ) - { - sal_Char *pBuffer; - const sal_Char *pSrcEnd; - const sal_Char *pSrc; - sal_Char *pDest; - sal_Int32 nSrcLen; - sal_Bool bValidEncoded = sal_True; /* Assume success */ - - /* The resulting decoded string length is shorter or equal to the source length */ - - nSrcLen = rtl_string_getLength(strUTF8); - pBuffer = reinterpret_cast(rtl_allocateMemory(nSrcLen + 1)); - - pDest = pBuffer; - pSrc = rtl_string_getStr(strUTF8); - pSrcEnd = pSrc + nSrcLen; - - /* Now decode the URL what should result in an UTF8 string */ - while ( bValidEncoded && pSrc < pSrcEnd ) - { - switch ( *pSrc ) - { - case '%': - { - sal_Char aToken[3]; - sal_Char aChar; - - pSrc++; - aToken[0] = *pSrc++; - aToken[1] = *pSrc++; - aToken[2] = 0; - - aChar = (sal_Char)strtoul( aToken, NULL, 16 ); - - /* The chars are path delimiters and must not be encoded */ - - if ( 0 == aChar || '\\' == aChar || '/' == aChar || ':' == aChar ) - bValidEncoded = sal_False; - else - *pDest++ = aChar; - } - break; - default: - *pDest++ = *pSrc++; - break; - } - } - - *pDest++ = 0; - - if ( bValidEncoded ) { - rtl_string2UString( pstrDecodedURL, pBuffer, rtl_str_getLength(pBuffer), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS ); - OSL_ASSERT(*pstrDecodedURL != 0); - } - - rtl_freeMemory( pBuffer ); - - return bValidEncoded; - } - - //############################################# - void _osl_encodeURL( rtl_uString *strURL, rtl_String **pstrEncodedURL ) - { - /* Encode non ascii characters within the URL */ - - rtl_String *strUTF8 = NULL; - sal_Char *pszEncodedURL; - const sal_Char *pURLScan; - sal_Char *pURLDest; - sal_Int32 nURLScanLen; - sal_Int32 nURLScanCount; - - rtl_uString2String( &strUTF8, rtl_uString_getStr( strURL ), rtl_uString_getLength( strURL ), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS ); - - pszEncodedURL = (sal_Char*) rtl_allocateMemory( (rtl_string_getLength( strUTF8 ) * 3 + 1) * sizeof(sal_Char) ); - - pURLDest = pszEncodedURL; - pURLScan = rtl_string_getStr( strUTF8 ); - nURLScanLen = rtl_string_getLength( strUTF8 ); - nURLScanCount = 0; - - while ( nURLScanCount < nURLScanLen ) - { - sal_Char cCurrent = *pURLScan; - - switch ( cCurrent ) - { - default: - if (!( ( cCurrent >= 'a' && cCurrent <= 'z' ) || ( cCurrent >= 'A' && cCurrent <= 'Z' ) || ( cCurrent >= '0' && cCurrent <= '9' ) ) ) - { - sprintf( pURLDest, "%%%02X", (unsigned char)cCurrent ); - pURLDest += 3; - break; - } - case '!': - case '\'': - case '(': - case ')': - case '*': - case '-': - case '.': - case '_': - case '~': - case '$': - case '&': - case '+': - case ',': - case '=': - case '@': - case ':': - case '/': - case '\\': - case '|': - *pURLDest++ = cCurrent; - break; - case 0: - break; - } - - pURLScan++; - nURLScanCount++; - } - - - *pURLDest = 0; - - rtl_string_release( strUTF8 ); - rtl_string_newFromStr( pstrEncodedURL, pszEncodedURL ); - rtl_freeMemory( pszEncodedURL ); - } - - //############################################# - oslFileError SAL_CALL _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **pustrPath, sal_Bool bAllowRelative ) - { - rtl_String *strUTF8 = NULL; - rtl_uString *strDecodedURL = NULL; - rtl_uString *strTempPath = NULL; - const sal_Unicode *pDecodedURL; - sal_uInt32 nDecodedLen; - sal_Bool bValidEncoded; - oslFileError nError = osl_File_E_INVAL; /* Assume failure */ - - /* If someone hasn't encoded the complete URL we convert it to UTF8 now to prevent from - having a mixed encoded URL later */ - - rtl_uString2String( &strUTF8, rtl_uString_getStr( strURL ), rtl_uString_getLength( strURL ), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS ); - - /* If the length of strUTF8 and strURL differs it indicates that the URL was not correct encoded */ - - OSL_ENSURE_FILE( - strUTF8->length == strURL->length || - 0 != rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( strURL->buffer, strURL->length, "file:\\\\", 7 ) - ,"osl_getSystemPathFromFileURL: \"%s\" is not encoded !!!", strURL ); - - bValidEncoded = _osl_decodeURL( strUTF8, &strDecodedURL ); - - /* Release the encoded UTF8 string */ - - rtl_string_release( strUTF8 ); - - - if ( bValidEncoded ) - { - /* Replace backslashes and pipes */ - - rtl_uString_newReplace( &strDecodedURL, strDecodedURL, '/', '\\' ); - rtl_uString_newReplace( &strDecodedURL, strDecodedURL, '|', ':' ); - - pDecodedURL = rtl_uString_getStr( strDecodedURL ); - nDecodedLen = rtl_uString_getLength( strDecodedURL ); - - /* Must start with "file://" */ - - if ( 0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL, nDecodedLen, "file:\\\\", 7 ) ) - { - sal_uInt32 nSkip; - - if ( 0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL, nDecodedLen, "file:\\\\\\", 8 ) ) - nSkip = 8; - else if ( - 0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL, nDecodedLen, "file:\\\\localhost\\", 17 ) || - 0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL, nDecodedLen, "file:\\\\127.0.0.1\\", 17 ) - ) - nSkip = 17; - else - nSkip = 5; - - /* Indicates local root */ - if ( nDecodedLen == nSkip ) - rtl_uString_newFromStr_WithLength( &strTempPath, reinterpret_cast(WSTR_SYSTEM_ROOT_PATH), ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1 ); - else - rtl_uString_newFromStr_WithLength( &strTempPath, pDecodedURL + nSkip, nDecodedLen - nSkip ); - - if ( IsValidFilePath( strTempPath, NULL, VALIDATEPATH_ALLOW_ELLIPSE, &strTempPath ) ) - nError = osl_File_E_None; - } - else if ( bAllowRelative ) /* This maybe a relative file URL */ - { - rtl_uString_assign( &strTempPath, strDecodedURL ); - - if ( IsValidFilePath( strTempPath, NULL, VALIDATEPATH_ALLOW_RELATIVE | VALIDATEPATH_ALLOW_ELLIPSE, &strTempPath ) ) - nError = osl_File_E_None; - } - /* - else - OSL_ENSURE_FILE( !nError, "osl_getSystemPathFromFileURL: \"%s\" is not an absolute FileURL !!!", strURL ); - */ - - } - - if ( strDecodedURL ) - rtl_uString_release( strDecodedURL ); - - if ( osl_File_E_None == nError ) - rtl_uString_assign( pustrPath, strTempPath ); - - if ( strTempPath ) - rtl_uString_release( strTempPath ); - - /* - OSL_ENSURE_FILE( !nError, "osl_getSystemPathFromFileURL: \"%s\" is not a FileURL !!!", strURL ); - */ - - return nError; - } - - //############################################# - oslFileError SAL_CALL _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString** pstrURL ) - { - oslFileError nError = osl_File_E_INVAL; /* Assume failure */ - rtl_uString *strTempURL = NULL; - DWORD dwPathType = PATHTYPE_ERROR; - - if (strPath) - dwPathType = IsValidFilePath(strPath, NULL, VALIDATEPATH_ALLOW_RELATIVE, NULL); - - if (dwPathType) - { - rtl_uString *strTempPath = NULL; - - /* Replace backslashes */ - - rtl_uString_newReplace( &strTempPath, strPath, '\\', '/' ); - - switch ( dwPathType & PATHTYPE_MASK_TYPE ) - { - case PATHTYPE_RELATIVE: - rtl_uString_assign( &strTempURL, strTempPath ); - nError = osl_File_E_None; - break; - case PATHTYPE_ABSOLUTE_UNC: - rtl_uString_newFromAscii( &strTempURL, "file:" ); - rtl_uString_newConcat( &strTempURL, strTempURL, strTempPath ); - nError = osl_File_E_None; - break; - case PATHTYPE_ABSOLUTE_LOCAL: - rtl_uString_newFromAscii( &strTempURL, "file:///" ); - rtl_uString_newConcat( &strTempURL, strTempURL, strTempPath ); - nError = osl_File_E_None; - break; - default: - break; - } - - /* Release temp path */ - - rtl_uString_release( strTempPath ); - } - - if ( osl_File_E_None == nError ) - { - rtl_String *strEncodedURL = NULL; - - /* Encode the URL */ - - _osl_encodeURL( strTempURL, &strEncodedURL ); - - /* Provide URL via unicode string */ - - rtl_string2UString( pstrURL, rtl_string_getStr(strEncodedURL), rtl_string_getLength(strEncodedURL), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS ); - OSL_ASSERT(*pstrURL != 0); - rtl_string_release( strEncodedURL ); - } - - /* Release temp URL */ - - if ( strTempURL ) - rtl_uString_release( strTempURL ); - - /* - OSL_ENSURE_FILE( !nError, "osl_getFileURLFromSystemPath: \"%s\" is not a systemPath !!!", strPath ); - */ - - return nError; - } - -#if OSL_DEBUG_LEVEL > 0 - - //##################################################### - void _osl_warnFile( const char *message, rtl_uString *ustrFile ) - { - char szBuffer[2048]; - - if (ustrFile) - { - rtl_String *strFile = NULL; - - rtl_uString2String( &strFile, rtl_uString_getStr( ustrFile ), rtl_uString_getLength( ustrFile ), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS ); - snprintf( szBuffer, sizeof(szBuffer), message, strFile->buffer ); - rtl_string_release( strFile ); - - message = szBuffer; - } - OSL_ENSURE( 0, message ); - } - -#endif // OSL_DEBUG_LEVEL > 0 - -} // end namespace private - - -//##################################################### -// Exported OSL API -//##################################################### - - -//############################################# -oslFileError SAL_CALL osl_getVolumeInformation( - rtl_uString *ustrURL, oslVolumeInfo *pInfo, sal_uInt32 uFieldMask ) -{ - if (!pInfo) - return osl_File_E_INVAL; - - rtl::OUString system_path; - oslFileError error = _osl_getSystemPathFromFileURL(ustrURL, &system_path.pData, sal_False); - - if (osl_File_E_None != error) - return error; - - rtl::OUString volume_root; - path_travel_to_volume_root(system_path, volume_root); - - pInfo->uValidFields = 0; - - if ((error = get_filesystem_attributes(volume_root, uFieldMask, pInfo)) != osl_File_E_None) - return error; - - if (is_volume_space_info_request(uFieldMask)) - get_volume_space_information(volume_root, pInfo); - - if (uFieldMask & osl_VolumeInfo_Mask_DeviceHandle) - { - pInfo->uValidFields |= osl_VolumeInfo_Mask_DeviceHandle; - osl_getFileURLFromSystemPath(volume_root.pData, (rtl_uString**)&pInfo->pDeviceHandle); - } - - return osl_File_E_None; -} - - -//############################################# -oslFileError SAL_CALL osl_createDirectoryPath( - rtl_uString* aDirectoryUrl, - oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, - void* pData) -{ - if (aDirectoryUrl == NULL) - return osl_File_E_INVAL; - - rtl::OUString sys_path; - oslFileError osl_error = - _osl_getSystemPathFromFileURL(aDirectoryUrl, &sys_path.pData, sal_False); - - if (osl_error != osl_File_E_None) - return osl_error; - - systemPathRemoveSeparator(sys_path); - - // const_cast because sys_path is a local copy - // which we want to modify inplace instead of - // coyp it into another buffer on the heap again - return MapError(create_dir_recursively_( - sys_path.pData->buffer, aDirectoryCreationCallbackFunc, pData)); -} - -//############################################# -oslFileError SAL_CALL osl_createTempFile( - rtl_uString* pustrDirectoryURL, - oslFileHandle* pHandle, - rtl_uString** ppustrTempFileURL) -{ - rtl_uString* base_directory = 0; - LPWSTR tmp_name; - sal_Bool b_delete_on_close; - oslFileError osl_error; - - osl_error = osl_setup_createTempFile_impl_( - pustrDirectoryURL, - pHandle, - ppustrTempFileURL, - &base_directory, - &b_delete_on_close); - - if (osl_File_E_None != osl_error) - return osl_error; - - /* allocate enough space on the stack */ - STACK_ALLOC(tmp_name, WCHAR, (rtl_uString_getLength(base_directory) + MAX_PATH)); - - if (tmp_name) - { - osl_createTempFile_impl_( - base_directory, - tmp_name, - b_delete_on_close, - pHandle, - ppustrTempFileURL); - } - else // stack alloc failed - { - osl_error = osl_File_E_NOMEM; - } - - if (base_directory) - rtl_uString_release(base_directory); - - return osl_error; -} - -//############################################# -oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) -{ - WCHAR szBuffer[MAX_PATH]; - LPWSTR lpBuffer = szBuffer; - DWORD nBufferLength = ELEMENTS_OF_ARRAY(szBuffer) - 1; - - DWORD nLength; - oslFileError error; - - do - { - nLength = GetTempPathW( ELEMENTS_OF_ARRAY(szBuffer), lpBuffer ); - if ( nLength > nBufferLength ) - { - nLength++; - lpBuffer = reinterpret_cast(alloca( sizeof(WCHAR) * nLength )); - nBufferLength = nLength - 1; - } - } while ( nLength > nBufferLength ); - - if ( nLength ) - { - rtl_uString *ustrTempPath = NULL; - - if ( '\\' == lpBuffer[nLength-1] ) - lpBuffer[nLength-1] = 0; - - rtl_uString_newFromStr( &ustrTempPath, reinterpret_cast(lpBuffer) ); - - error = osl_getFileURLFromSystemPath( ustrTempPath, pustrTempDir ); - - rtl_uString_release( ustrTempPath ); - } - else - error = MapError( GetLastError() ); - - return error; -} - -//################################################################## -// File handling functions -//################################################################## - - -//############################################# -oslFileError SAL_CALL osl_openFile( - rtl_uString *strPath, oslFileHandle *pHandle, sal_uInt32 uFlags ) -{ - rtl_uString *strSysPath = NULL; - oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); - - if ( osl_File_E_None == error ) - { - DWORD dwAccess = 0, dwShare = FILE_SHARE_READ, dwCreation = 0, dwAttributes = 0; - HANDLE hFile; - - if ( uFlags & osl_File_OpenFlag_Read ) - dwAccess |= GENERIC_READ; - - if ( uFlags & osl_File_OpenFlag_Write ) - dwAccess |= GENERIC_WRITE; - else - dwShare |= FILE_SHARE_WRITE; - - if ( uFlags & osl_File_OpenFlag_NoLock ) - dwShare |= FILE_SHARE_WRITE; - - if ( uFlags & osl_File_OpenFlag_Create ) - dwCreation |= CREATE_NEW; - else - dwCreation |= OPEN_EXISTING; - - hFile = CreateFileW( reinterpret_cast(rtl_uString_getStr( strSysPath )), dwAccess, dwShare, NULL, dwCreation, dwAttributes, NULL ); - - *pHandle = osl_createFileHandleFromOSHandle( hFile ); - - if ( !IsValidHandle( hFile ) ) - error = MapError( GetLastError() ); - - rtl_uString_release( strSysPath ); - } - - return error; -} - -//############################################# -oslFileError SAL_CALL osl_syncFile(oslFileHandle Handle) -{ - if (!IsValidHandle((HANDLE)Handle)) - return osl_File_E_INVAL; - - if (!FlushFileBuffers((HANDLE)Handle)) - return MapError(GetLastError()); - - return osl_File_E_None; -} - -//############################################# -oslFileError SAL_CALL osl_closeFile(oslFileHandle Handle) -{ - oslFileError error; - HANDLE hFile = (HANDLE)Handle; - - if ( IsValidHandle(hFile) ) - error = CloseHandle( hFile ) ? osl_File_E_None : MapError( GetLastError() ); - else - error = osl_File_E_INVAL; - - return error; -} - -//############################################# -oslFileError SAL_CALL osl_isEndOfFile(oslFileHandle Handle, sal_Bool *pIsEOF) -{ - oslFileError error = osl_File_E_INVAL; - HANDLE hFile = (HANDLE)Handle; - - if ( IsValidHandle(hFile) ) - { - LONG lDistanceToMove, lDistanceToMoveHigh; - sal_uInt64 nCurPos; - - /* Return value INVALID_SET_FILE_POINTER is no error indication and LastError could - be set from previous IO call */ - - SetLastError( NOERROR ); - - lDistanceToMoveHigh = 0; - lDistanceToMove = SetFilePointer( hFile, 0, &lDistanceToMoveHigh, FILE_CURRENT ); - - error = MapError( GetLastError() ); - - if ( osl_File_E_None == error ) - { - nCurPos = (sal_uInt64)lDistanceToMove + ((sal_uInt64)lDistanceToMoveHigh << 32); - - lDistanceToMoveHigh = 0; - lDistanceToMove = SetFilePointer( hFile, 0, &lDistanceToMoveHigh, FILE_END ); - - error = MapError( GetLastError() ); - - if ( osl_File_E_None == error ) - { - sal_uInt64 nEndPos = (sal_uInt64)lDistanceToMove + ((sal_uInt64)lDistanceToMoveHigh << 32); - - *pIsEOF = (sal_Bool)(nEndPos == nCurPos); - - lDistanceToMoveHigh = (LONG)(nCurPos >> 32); - SetFilePointer( hFile, (LONG)(nCurPos & 0xFFFFFFFF), &lDistanceToMoveHigh, FILE_BEGIN ); - - error = MapError( GetLastError() ); - } - } - } - return error; -} - -//############################################# -oslFileError SAL_CALL osl_setFilePos(oslFileHandle Handle, sal_uInt32 uHow, sal_Int64 uPos) -{ - HANDLE hFile = (HANDLE)Handle; - if (!IsValidHandle(hFile)) - return osl_File_E_INVAL; - - DWORD dwMoveMethod = 0; - switch ( uHow ) - { - case osl_Pos_Current: - dwMoveMethod = FILE_CURRENT; - break; - case osl_Pos_End: - dwMoveMethod = FILE_END; - break; - case osl_Pos_Absolut: - default: - dwMoveMethod = FILE_BEGIN; - break; - } - - LONG nOffsetLo = sal::static_int_cast(uPos & 0xFFFFFFFF); - LONG nOffsetHi = sal::static_int_cast(uPos >> 32); - - SetLastError(0); - DWORD dwPosLo = SetFilePointer( hFile, nOffsetLo, &nOffsetHi, dwMoveMethod ); - if (INVALID_SET_FILE_POINTER == dwPosLo) - { - DWORD dwError = GetLastError(); - if (NO_ERROR != dwError) - return MapError( dwError ); - } - return osl_File_E_None; -} - -//############################################# -oslFileError SAL_CALL osl_getFilePos(oslFileHandle Handle, sal_uInt64 *pPos) -{ - oslFileError error; - HANDLE hFile = (HANDLE)Handle; - - if ( IsValidHandle(hFile) ) - { - LONG lDistanceToMove, lDistanceToMoveHigh; - - /* Return value INVALID_SET_FILE_POINTER is no error indication and LastError could - be set from previous IO call */ - - SetLastError( NOERROR ); - - lDistanceToMoveHigh = 0; - lDistanceToMove = SetFilePointer( hFile, 0, &lDistanceToMoveHigh, FILE_CURRENT ); - - error = MapError( GetLastError() ); - - if ( osl_File_E_None == error ) - *pPos = (sal_uInt64)lDistanceToMove + ((sal_uInt64)lDistanceToMoveHigh << 32); - } - else - error = osl_File_E_INVAL; - - return error; -} - -//############################################# -oslFileError SAL_CALL osl_getFileSize(oslFileHandle Handle, sal_uInt64 *pSize) -{ - HANDLE hFile = (HANDLE)Handle; - if ( !IsValidHandle(hFile) ) - return osl_File_E_INVAL; - - DWORD nSize = GetFileSize(hFile, NULL); - if (nSize == INVALID_FILE_SIZE) - { - DWORD nError = GetLastError(); - if (nError != NO_ERROR) - return MapError(nError); - } - - *pSize = (sal_uInt64)(nSize); - return osl_File_E_None; -} - -oslFileError SAL_CALL osl_setFileSize(oslFileHandle Handle, sal_uInt64 uSize) -{ - oslFileError error = osl_setFilePos( Handle, osl_Pos_Absolut, uSize ); - if ( osl_File_E_None == error ) - { - if ( !SetEndOfFile( (HANDLE)Handle ) ) - error = MapError( osl_File_E_None ); - } - - return error; -} - -//############################################# -oslFileError SAL_CALL osl_mapFile( - oslFileHandle Handle, - void** ppAddr, - sal_uInt64 uLength, - sal_uInt64 uOffset, - sal_uInt32 uFlags) -{ - struct FileMapping - { - HANDLE m_handle; - - explicit FileMapping (HANDLE hMap) - : m_handle (hMap) - {} - - ~FileMapping() - { - (void)::CloseHandle(m_handle); - } - }; - - HANDLE hFile = (HANDLE)(Handle); - if (!IsValidHandle(hFile) || (0 == ppAddr)) - return osl_File_E_INVAL; - *ppAddr = 0; - - static SIZE_T const nLimit = std::numeric_limits< SIZE_T >::max(); - if (uLength > nLimit) - return osl_File_E_OVERFLOW; - SIZE_T const nLength = sal::static_int_cast< SIZE_T >(uLength); - - OSVERSIONINFO osinfo; - osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - (void)::GetVersionEx(&osinfo); - - if (VER_PLATFORM_WIN32_NT != osinfo.dwPlatformId) - return osl_File_E_NOSYS; // Unsupported - - FileMapping aMap( ::CreateFileMapping (hFile, NULL, SEC_COMMIT | PAGE_READONLY, 0, 0, NULL) ); - if (!IsValidHandle(aMap.m_handle)) - return MapError( GetLastError() ); - - DWORD const dwOffsetHi = sal::static_int_cast(uOffset >> 32); - DWORD const dwOffsetLo = sal::static_int_cast(uOffset & 0xFFFFFFFF); - - *ppAddr = ::MapViewOfFile( aMap.m_handle, FILE_MAP_READ, dwOffsetHi, dwOffsetLo, nLength ); - if (0 == *ppAddr) - return MapError( GetLastError() ); - - if (uFlags & osl_File_MapFlag_RandomAccess) - { - // Determine memory pagesize. - SYSTEM_INFO info; - ::GetSystemInfo( &info ); - DWORD const dwPageSize = info.dwPageSize; - - /* - * Pagein, touching first byte of each memory page. - * Note: volatile disables optimizing the loop away. - */ - BYTE * pData (reinterpret_cast(*ppAddr)); - SIZE_T nSize (nLength); - - volatile BYTE c = 0; - while (nSize > dwPageSize) - { - c ^= pData[0]; - pData += dwPageSize; - nSize -= dwPageSize; - } - if (nSize > 0) - { - c ^= pData[0]; - pData += nSize; - nSize -= nSize; - } - } - return osl_File_E_None; -} - -//############################################# -oslFileError SAL_CALL osl_unmapFile(void* pAddr, sal_uInt64 /* uLength */) -{ - if (0 == pAddr) - return osl_File_E_INVAL; - - if (!::UnmapViewOfFile (pAddr)) - return MapError( GetLastError() ); - - return osl_File_E_None; -} - -//############################################# -oslFileError SAL_CALL osl_readFile( - oslFileHandle Handle, - void *pBuffer, - sal_uInt64 uBytesRequested, - sal_uInt64 *pBytesRead ) -{ - oslFileError error; - HANDLE hFile = (HANDLE)Handle; - - if ( IsValidHandle(hFile) ) - { - DWORD dwBytesToRead = (DWORD)uBytesRequested; - DWORD dwBytesRead; - - if ( ReadFile( hFile, pBuffer, dwBytesToRead, &dwBytesRead, NULL ) ) - { - *pBytesRead = (sal_uInt64)dwBytesRead; - error = osl_File_E_None; - } - else - error = MapError( GetLastError() ); - } - else - error = osl_File_E_INVAL; - - return error; -} - -//############################################# -oslFileError SAL_CALL osl_writeFile( - oslFileHandle Handle, - const void *pBuffer, - sal_uInt64 uBytesToWrite, - sal_uInt64 *pBytesWritten ) -{ - oslFileError error; - HANDLE hFile = (HANDLE)Handle; - - if ( IsValidHandle(hFile) ) - { - DWORD dwBytesToWrite = (DWORD)uBytesToWrite; - DWORD dwBytesWritten; - - if ( WriteFile( hFile, pBuffer, dwBytesToWrite, &dwBytesWritten, NULL ) ) - { - *pBytesWritten = (sal_uInt64)dwBytesWritten; - error = osl_File_E_None; - } - else - error = MapError( GetLastError() ); - } - else - error = osl_File_E_INVAL; - - return error; -} - -//############################################# -oslFileError SAL_CALL osl_readFileAt( - oslFileHandle Handle, - sal_uInt64 uOffset, - void* pBuffer, - sal_uInt64 uBytesRequested, - sal_uInt64* pBytesRead) -{ - HANDLE hFile = (HANDLE)(Handle); - if (!IsValidHandle(hFile) || (0 == pBuffer)) - return osl_File_E_INVAL; - - static sal_uInt64 const g_limit_dword = std::numeric_limits< DWORD >::max(); - if (g_limit_dword < uBytesRequested) - return osl_File_E_OVERFLOW; - DWORD const dwBytes = sal::static_int_cast< DWORD >(uBytesRequested); - - if (0 == pBytesRead) - return osl_File_E_INVAL; - *pBytesRead = 0; - - oslFileError error = osl_setFilePos(Handle, osl_Pos_Absolut, uOffset); - if (osl_File_E_None != error) - return error; - - DWORD dwDone = 0; - if (!::ReadFile(hFile, pBuffer, dwBytes, &dwDone, NULL)) - return MapError( GetLastError() ); - - *pBytesRead = dwDone; - return osl_File_E_None; + delete pImpl; + return (result); } //############################################# -oslFileError SAL_CALL osl_writeFileAt( +oslFileError +SAL_CALL osl_mapFile( oslFileHandle Handle, + void** ppAddr, + sal_uInt64 uLength, sal_uInt64 uOffset, - const void* pBuffer, - sal_uInt64 uBytesToWrite, - sal_uInt64* pBytesWritten) -{ - HANDLE hFile = (HANDLE)(Handle); - if (!IsValidHandle(hFile) || (0 == pBuffer)) - return osl_File_E_INVAL; - - static sal_uInt64 const g_limit_dword = std::numeric_limits< DWORD >::max(); - if (g_limit_dword < uBytesToWrite) - return osl_File_E_OVERFLOW; - DWORD const dwBytes = sal::static_int_cast< DWORD >(uBytesToWrite); - - if (0 == pBytesWritten) - return osl_File_E_INVAL; - *pBytesWritten = 0; - - oslFileError error = osl_setFilePos(Handle, osl_Pos_Absolut, uOffset); - if (osl_File_E_None != error) - return error; - - DWORD dwDone = 0; - if (!::WriteFile(hFile, pBuffer, dwBytes, &dwDone, NULL)) - return MapError( GetLastError() ); - - *pBytesWritten = dwDone; - return osl_File_E_None; -} - -//############################################# -oslFileError SAL_CALL osl_removeFile( rtl_uString* strPath ) -{ - rtl_uString *strSysPath = NULL; - oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); - - if ( osl_File_E_None == error ) - { - if ( DeleteFile( reinterpret_cast(rtl_uString_getStr( strSysPath )) ) ) - error = osl_File_E_None; - else - error = MapError( GetLastError() ); - - rtl_uString_release( strSysPath ); - } - return error; -} - -//############################################# -#define osl_File_CopyRecursive 0x0001 -#define osl_File_CopyOverwrite 0x0002 - -oslFileError SAL_CALL osl_copyFile( rtl_uString* strPath, rtl_uString *strDestPath ) -{ - rtl_uString *strSysPath = NULL, *strSysDestPath = NULL; - oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); - - if ( osl_File_E_None == error ) - error = _osl_getSystemPathFromFileURL( strDestPath, &strSysDestPath, sal_False ); - - if ( osl_File_E_None == error ) - { - if ( CopyFile( reinterpret_cast(rtl_uString_getStr( strSysPath )), reinterpret_cast(rtl_uString_getStr( strSysDestPath )), FALSE ) ) - error = osl_File_E_None; - else - error = MapError( GetLastError() ); - } - - if ( strSysPath ) - rtl_uString_release( strSysPath ); - if ( strSysDestPath ) - rtl_uString_release( strSysDestPath ); - - return error; -} - -//############################################# -oslFileError SAL_CALL osl_moveFile( rtl_uString* strPath, rtl_uString *strDestPath ) -{ - rtl_uString *strSysPath = NULL, *strSysDestPath = NULL; - oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); - - if ( osl_File_E_None == error ) - error = _osl_getSystemPathFromFileURL( strDestPath, &strSysDestPath, sal_False ); - - if ( osl_File_E_None == error ) - { - if ( MoveFileEx( reinterpret_cast(rtl_uString_getStr( strSysPath )), reinterpret_cast(rtl_uString_getStr( strSysDestPath )), MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING ) ) - error = osl_File_E_None; - else - error = MapError( GetLastError() ); - } - - if ( strSysPath ) - rtl_uString_release( strSysPath ); - if ( strSysDestPath ) - rtl_uString_release( strSysDestPath ); - - return error; -} - -//############################################# -oslFileError SAL_CALL osl_setFileAttributes( - rtl_uString *ustrFileURL, - sal_uInt64 uAttributes ) -{ - oslFileError error; - rtl_uString *ustrSysPath = NULL; - DWORD dwFileAttributes; - BOOL fSuccess; - - // Converts the normalized path into a systempath - error = _osl_getSystemPathFromFileURL( ustrFileURL, &ustrSysPath, sal_False ); - - if ( osl_File_E_None != error ) - return error; - - dwFileAttributes = GetFileAttributes( reinterpret_cast(rtl_uString_getStr(ustrSysPath)) ); - - if ( (DWORD)-1 != dwFileAttributes ) - { - dwFileAttributes &= ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN); - - if ( uAttributes & osl_File_Attribute_ReadOnly ) - dwFileAttributes |= FILE_ATTRIBUTE_READONLY; - - if ( uAttributes & osl_File_Attribute_Hidden ) - dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN; - - fSuccess = SetFileAttributes( reinterpret_cast(rtl_uString_getStr(ustrSysPath)), dwFileAttributes ); - } - else - fSuccess = FALSE; - - if ( !fSuccess ) - error = MapError( GetLastError() ); - - rtl_uString_release( ustrSysPath ); - - return error; -} - -//##################################################### -oslFileError SAL_CALL osl_setFileTime( - rtl_uString *filePath, - const TimeValue *aCreationTime, - const TimeValue *aLastAccessTime, - const TimeValue *aLastWriteTime) -{ - oslFileError error; - rtl_uString *sysPath=NULL; - FILETIME *lpCreationTime=NULL; - FILETIME *lpLastAccessTime=NULL; - FILETIME *lpLastWriteTime=NULL; - FILETIME ftCreationTime; - FILETIME ftLastAccessTime; - FILETIME ftLastWriteTime; - HANDLE hFile; - BOOL fSuccess; - - - error=_osl_getSystemPathFromFileURL(filePath, &sysPath, sal_False); - - if (error==osl_File_E_INVAL) - return error; - - hFile=CreateFileW(reinterpret_cast(rtl_uString_getStr(sysPath)), GENERIC_WRITE, 0, NULL , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - rtl_uString_release(sysPath); - - if (hFile==INVALID_HANDLE_VALUE) - return osl_File_E_NOENT; - - if (TimeValueToFileTime(aCreationTime, &ftCreationTime)) - lpCreationTime=&ftCreationTime; - - if (TimeValueToFileTime(aLastAccessTime, &ftLastAccessTime)) - lpLastAccessTime=&ftLastAccessTime; - - if (TimeValueToFileTime(aLastWriteTime, &ftLastWriteTime)) - lpLastWriteTime=&ftLastWriteTime; - - fSuccess=SetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime); - - CloseHandle(hFile); - - if (!fSuccess) - return osl_File_E_INVAL; - else - return osl_File_E_None; -} - -//##################################################### -oslFileError SAL_CALL osl_getFileStatus( - oslDirectoryItem Item, - oslFileStatus *pStatus, - sal_uInt32 uFieldMask ) + sal_uInt32 uFlags) { - DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; - - if ( !pItemImpl ) - return osl_File_E_INVAL; - - switch ( pItemImpl->uType ) - { - case DIRECTORYITEM_DRIVE: - return osl_getDriveInfo( Item, pStatus, uFieldMask ); - case DIRECTORYITEM_SERVER: - return osl_getServerInfo( Item, pStatus, uFieldMask ); - default: - break; - } - - if ( uFieldMask & osl_FileStatus_Mask_Validate ) - { - HANDLE hFind = FindFirstFile( pItemImpl->szFullPath, &pItemImpl->FindData ); - - if ( hFind != INVALID_HANDLE_VALUE ) - FindClose( hFind ); - else - return MapError( GetLastError() ); - - uFieldMask &= ~ osl_FileStatus_Mask_Validate; - } - - /* If no fields to retrieve left ignore pStatus */ - if ( !uFieldMask ) - return osl_File_E_None; - - /* Otherwise, this must be a valid pointer */ - if ( !pStatus ) - return osl_File_E_INVAL; - - if ( pStatus->uStructSize != sizeof(oslFileStatus) ) - return osl_File_E_INVAL; - - pStatus->uValidFields = 0; - - /* File time stamps */ - - if ( (uFieldMask & osl_FileStatus_Mask_ModifyTime) && - FileTimeToTimeValue( &pItemImpl->FindData.ftLastWriteTime, &pStatus->aModifyTime ) ) - pStatus->uValidFields |= osl_FileStatus_Mask_ModifyTime; - - if ( (uFieldMask & osl_FileStatus_Mask_AccessTime) && - FileTimeToTimeValue( &pItemImpl->FindData.ftLastAccessTime, &pStatus->aAccessTime ) ) - pStatus->uValidFields |= osl_FileStatus_Mask_AccessTime; - - if ( (uFieldMask & osl_FileStatus_Mask_CreationTime) && - FileTimeToTimeValue( &pItemImpl->FindData.ftCreationTime, &pStatus->aCreationTime ) ) - pStatus->uValidFields |= osl_FileStatus_Mask_CreationTime; - - /* Most of the fields are already set, regardless of requiered fields */ - - rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(pItemImpl->FindData.cFileName) ); - pStatus->uValidFields |= osl_FileStatus_Mask_FileName; - - if ((FILE_ATTRIBUTE_REPARSE_POINT & pItemImpl->FindData.dwFileAttributes) && - (IO_REPARSE_TAG_MOUNT_POINT == pItemImpl->FindData.dwReserved0)) - pStatus->eType = osl_File_Type_Volume; - else if (pItemImpl->FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - pStatus->eType = osl_File_Type_Directory; - else - pStatus->eType = osl_File_Type_Regular; - - pStatus->uValidFields |= osl_FileStatus_Mask_Type; - - pStatus->uAttributes = pItemImpl->FindData.dwFileAttributes; - pStatus->uValidFields |= osl_FileStatus_Mask_Attributes; - - pStatus->uFileSize = (sal_uInt64)pItemImpl->FindData.nFileSizeLow + ((sal_uInt64)pItemImpl->FindData.nFileSizeHigh << 32); - pStatus->uValidFields |= osl_FileStatus_Mask_FileSize; - - if ( uFieldMask & osl_FileStatus_Mask_LinkTargetURL ) - { - rtl_uString *ustrFullPath = NULL; - - rtl_uString_newFromStr( &ustrFullPath, reinterpret_cast(pItemImpl->szFullPath) ); - osl_getFileURLFromSystemPath( ustrFullPath, &pStatus->ustrLinkTargetURL ); - rtl_uString_release( ustrFullPath ); - - pStatus->uValidFields |= osl_FileStatus_Mask_LinkTargetURL; - } - - if ( uFieldMask & osl_FileStatus_Mask_FileURL ) + struct FileMapping { - rtl_uString *ustrFullPath = NULL; - - - if ( !pItemImpl->bFullPathNormalized ) - { - GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) ); - pItemImpl->bFullPathNormalized = TRUE; - } - rtl_uString_newFromStr( &ustrFullPath, reinterpret_cast(pItemImpl->szFullPath) ); - osl_getFileURLFromSystemPath( ustrFullPath, &pStatus->ustrFileURL ); - rtl_uString_release( ustrFullPath ); - pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; - } - - return osl_File_E_None; -} - -//################################################################## -// directory handling functions -//################################################################## - + HANDLE m_handle; -//##################################################### -oslFileError SAL_CALL osl_createDirectory(rtl_uString* strPath) -{ - rtl_uString *strSysPath = NULL; - oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); + explicit FileMapping (HANDLE hMap) + : m_handle (hMap) + {} - if ( osl_File_E_None == error ) - { - if ( CreateDirectoryW( reinterpret_cast(rtl_uString_getStr( strSysPath )), NULL ) ) - error = osl_File_E_None; -/*@@@ToDo - The else case is a hack because the ucb or the webtop had some - problems with the error code that CreateDirectory returns in - case the path is only a logical drive, should be removed! -*/ - else + ~FileMapping() { - const sal_Unicode *pBuffer = rtl_uString_getStr( strSysPath ); - sal_Int32 nLen = rtl_uString_getLength( strSysPath ); - - if ( - ( pBuffer[0] >= 'A' && pBuffer[0] <= 'Z' || - pBuffer[0] >= 'a' && pBuffer[0] <= 'z' ) && - pBuffer[1] == ':' && ( nLen ==2 || nLen == 3 && pBuffer[2] == '\\' ) - ) - SetLastError( ERROR_ALREADY_EXISTS ); - - error = MapError( GetLastError() ); + (void)::CloseHandle(m_handle); } + }; - rtl_uString_release( strSysPath ); - } - return error; -} + FileHandle_Impl * pImpl = static_cast(Handle); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == ppAddr)) + return osl_File_E_INVAL; + *ppAddr = 0; -//##################################################### -oslFileError SAL_CALL osl_removeDirectory(rtl_uString* strPath) -{ - rtl_uString *strSysPath = NULL; - oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); + static SIZE_T const nLimit = std::numeric_limits< SIZE_T >::max(); + if (uLength > nLimit) + return osl_File_E_OVERFLOW; + SIZE_T const nLength = sal::static_int_cast< SIZE_T >(uLength); - if ( osl_File_E_None == error ) - { - if ( RemoveDirectory( reinterpret_cast(rtl_uString_getStr( strSysPath )) ) ) - error = osl_File_E_None; - else - error = MapError( GetLastError() ); + OSVERSIONINFO osinfo; + osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + (void)::GetVersionEx(&osinfo); - rtl_uString_release( strSysPath ); - } - return error; -} + if (VER_PLATFORM_WIN32_NT != osinfo.dwPlatformId) + return osl_File_E_NOSYS; // Unsupported -//##################################################### -oslFileError SAL_CALL osl_openDirectory(rtl_uString *strDirectoryPath, oslDirectory *pDirectory) -{ - oslFileError error; + FileMapping aMap( ::CreateFileMapping (pImpl->m_hFile, NULL, SEC_COMMIT | PAGE_READONLY, 0, 0, NULL) ); + if (!IsValidHandle(aMap.m_handle)) + return oslTranslateFileError( GetLastError() ); - if ( 0 == rtl_ustr_ascii_compareIgnoreAsciiCase( strDirectoryPath->buffer, "file:///" ) ) - error = osl_openLocalRoot( strDirectoryPath, pDirectory ); - else - { - rtl_uString *strSysDirectoryPath = NULL; -// WCHAR szCorrectedPathName[MAX_PATH]; - DWORD dwPathType; + DWORD const dwOffsetHi = sal::static_int_cast(uOffset >> 32); + DWORD const dwOffsetLo = sal::static_int_cast(uOffset & 0xFFFFFFFF); - error = _osl_getSystemPathFromFileURL( strDirectoryPath, &strSysDirectoryPath, sal_False ); + *ppAddr = ::MapViewOfFile( aMap.m_handle, FILE_MAP_READ, dwOffsetHi, dwOffsetLo, nLength ); + if (0 == *ppAddr) + return oslTranslateFileError( GetLastError() ); - if ( osl_File_E_None != error ) - return error; + if (uFlags & osl_File_MapFlag_RandomAccess) + { + // Determine memory pagesize. + SYSTEM_INFO info; + ::GetSystemInfo( &info ); + DWORD const dwPageSize = info.dwPageSize; - // MT Perform05 /* - if ( GetCaseCorrectPathName( strSysDirectoryPath->buffer, szCorrectedPathName, MAX_PATH ) ) + * Pagein, touching first byte of each memory page. + * Note: volatile disables optimizing the loop away. + */ + BYTE * pData (reinterpret_cast(*ppAddr)); + SIZE_T nSize (nLength); + + volatile BYTE c = 0; + while (nSize > dwPageSize) { - rtl_uString_newFromStr( &strSysDirectoryPath, szCorrectedPathName ); + c ^= pData[0]; + pData += dwPageSize; + nSize -= dwPageSize; } - */ - - dwPathType = IsValidFilePath( strSysDirectoryPath, NULL, VALIDATEPATH_NORMAL, NULL ); - - if ( dwPathType & PATHTYPE_IS_SERVER ) + if (nSize > 0) { - error = osl_openNetworkServer( strSysDirectoryPath, pDirectory ); + c ^= pData[0]; + pData += nSize; + nSize -= nSize; } - else - error = osl_openFileDirectory( strSysDirectoryPath, pDirectory ); - - rtl_uString_release( strSysDirectoryPath ); } - return error; + return osl_File_E_None; } -//##################################################### -oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory Directory, oslDirectoryItem *pItem, sal_uInt32 uHint) +//############################################# +oslFileError +SAL_CALL osl_unmapFile(void* pAddr, sal_uInt64 /* uLength */) { - Directory_Impl *pDirImpl = (Directory_Impl *)Directory; - - /* Assume failure */ - - if ( !pItem ) + if (0 == pAddr) return osl_File_E_INVAL; - *pItem = NULL; + if (!::UnmapViewOfFile (pAddr)) + return oslTranslateFileError( GetLastError() ); - if ( !pDirImpl ) - return osl_File_E_INVAL; + return osl_File_E_None; +} - switch ( pDirImpl->uType ) - { - case DIRECTORYTYPE_LOCALROOT: - return osl_getNextDrive( Directory, pItem, uHint ); - case DIRECTORYTYPE_NETROOT: - return osl_getNextNetResource( Directory, pItem, uHint ); - case DIRECTORYTYPE_FILESYSTEM: - return osl_getNextFileItem( Directory, pItem, uHint ); - default: +//############################################# +oslFileError +SAL_CALL osl_readLine( + oslFileHandle Handle, + sal_Sequence ** ppSequence) +{ + FileHandle_Impl * pImpl = static_cast(Handle); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == ppSequence)) return osl_File_E_INVAL; - } + sal_uInt64 uBytesRead = 0; + + // read at current filepos; filepos += uBytesRead; + oslFileError result = pImpl->readLineAt ( + pImpl->m_filepos, ppSequence, &uBytesRead); + if (result == osl_File_E_None) + pImpl->m_filepos += uBytesRead; + return (result); } -//##################################################### -oslFileError SAL_CALL osl_closeDirectory(oslDirectory Directory) +//############################################# +oslFileError +SAL_CALL osl_readFile( + oslFileHandle Handle, + void * pBuffer, + sal_uInt64 uBytesRequested, + sal_uInt64 * pBytesRead) { - Directory_Impl *pDirImpl = (Directory_Impl *)Directory; - oslFileError eError = osl_File_E_INVAL; - - if ( pDirImpl ) - { - switch ( pDirImpl->uType ) - { - case DIRECTORYTYPE_FILESYSTEM: - eError = CloseDirectory( pDirImpl->hDirectory ) ? osl_File_E_None : MapError( GetLastError() ); - break; - case DIRECTORYTYPE_LOCALROOT: - eError = CloseLogicalDrivesEnum( pDirImpl->hEnumDrives ) ? osl_File_E_None : MapError( GetLastError() ); - break; - case DIRECTORYTYPE_NETROOT: - { - DWORD err = WNetCloseEnum(pDirImpl->hDirectory); - eError = (err == NO_ERROR) ? osl_File_E_None : MapError(err); - } - break; - default: - OSL_ENSURE( 0, "Invalid directory type" ); - break; - } + FileHandle_Impl * pImpl = static_cast(Handle); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pBuffer) || (0 == pBytesRead)) + return osl_File_E_INVAL; - rtl_freeMemory(pDirImpl); - } - return eError; + // read at current filepos; filepos += *pBytesRead; + oslFileError result = pImpl->readFileAt ( + pImpl->m_filepos, pBuffer, uBytesRequested, pBytesRead); + if (result == osl_File_E_None) + pImpl->m_filepos += *pBytesRead; + return (result); } -//##################################################### -oslFileError SAL_CALL osl_getDirectoryItem(rtl_uString *strFilePath, oslDirectoryItem *pItem) +//############################################# +oslFileError +SAL_CALL osl_writeFile( + oslFileHandle Handle, + const void * pBuffer, + sal_uInt64 uBytesToWrite, + sal_uInt64 * pBytesWritten ) { - oslFileError error = osl_File_E_None; - rtl_uString* strSysFilePath = NULL; - PATHTYPE type = PATHTYPE_FILE; - DWORD dwPathType; -// TCHAR szCorrectedPathName[MAX_PATH]; + FileHandle_Impl * pImpl = static_cast(Handle); - /* Assume failure */ - - if ( !pItem ) + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pBuffer) || (0 == pBytesWritten)) return osl_File_E_INVAL; - *pItem = NULL; - - - error = _osl_getSystemPathFromFileURL( strFilePath, &strSysFilePath, sal_False ); - - if ( osl_File_E_None != error ) - return error; - - // MT: I can't imagine a case where this is good for! - /* - if ( GetCaseCorrectPathName( strSysFilePath->buffer, szCorrectedPathName, MAX_PATH ) ) - { - rtl_uString_newFromStr( &strSysFilePath, szCorrectedPathName ); - } - */ - - dwPathType = IsValidFilePath( strSysFilePath, NULL, VALIDATEPATH_NORMAL, NULL ); - - if ( dwPathType & PATHTYPE_IS_VOLUME ) - type = PATHTYPE_VOLUME; - else if ( dwPathType & PATHTYPE_IS_SERVER ) - type = PATHTYPE_NETSERVER; - else - type = PATHTYPE_FILE; - - switch ( type ) - { - case PATHTYPE_NETSERVER: - { - DirectoryItem_Impl* pItemImpl = - reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); - - if ( !pItemImpl ) - error = osl_File_E_NOMEM; + // write at current filepos; filepos += *pBytesWritten; + oslFileError result = pImpl->writeFileAt ( + pImpl->m_filepos, pBuffer, uBytesToWrite, pBytesWritten); + if (result == osl_File_E_None) + pImpl->m_filepos += *pBytesWritten; + return (result); +} - if ( osl_File_E_None == error ) - { - ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); - pItemImpl->uType = DIRECTORYITEM_SERVER; +//############################################# +oslFileError +SAL_CALL osl_readFileAt( + oslFileHandle Handle, + sal_uInt64 uOffset, + void* pBuffer, + sal_uInt64 uBytesRequested, + sal_uInt64* pBytesRead) +{ + FileHandle_Impl * pImpl = static_cast(Handle); - osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pBuffer) || (0 == pBytesRead)) + return osl_File_E_INVAL; + if (0 == (pImpl->m_state & FileHandle_Impl::STATE_SEEKABLE)) + return osl_File_E_SPIPE; - _tcscpy( pItemImpl->szFullPath, reinterpret_cast(strSysFilePath->buffer) ); + static sal_uInt64 const g_limit_longlong = std::numeric_limits< LONGLONG >::max(); + if (g_limit_longlong < uOffset) + return osl_File_E_OVERFLOW; + LONGLONG const nOffset = sal::static_int_cast< LONGLONG >(uOffset); - // Assign a title anyway - { - int iSrc = 2; - int iDst = 0; + // read at specified fileptr + return pImpl->readFileAt (nOffset, pBuffer, uBytesRequested, pBytesRead); +} - while( iSrc < strSysFilePath->length && strSysFilePath->buffer[iSrc] && strSysFilePath->buffer[iSrc] != '\\' ) - { - pItemImpl->FindData.cFileName[iDst++] = strSysFilePath->buffer[iSrc++]; - } - } +//############################################# +oslFileError +SAL_CALL osl_writeFileAt( + oslFileHandle Handle, + sal_uInt64 uOffset, + const void* pBuffer, + sal_uInt64 uBytesToWrite, + sal_uInt64* pBytesWritten) +{ + FileHandle_Impl * pImpl = static_cast(Handle); - *pItem = pItemImpl; - } - } - break; - case PATHTYPE_VOLUME: - { - DirectoryItem_Impl* pItemImpl = - reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pBuffer) || (0 == pBytesWritten)) + return osl_File_E_INVAL; + if (0 == (pImpl->m_state & FileHandle_Impl::STATE_SEEKABLE)) + return osl_File_E_SPIPE; - if ( !pItemImpl ) - error = osl_File_E_NOMEM; + static sal_uInt64 const g_limit_longlong = std::numeric_limits< LONGLONG >::max(); + if (g_limit_longlong < uOffset) + return osl_File_E_OVERFLOW; + LONGLONG const nOffset = sal::static_int_cast< LONGLONG >(uOffset); - if ( osl_File_E_None == error ) - { - ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); - pItemImpl->uType = DIRECTORYITEM_DRIVE; + // write at specified fileptr + return pImpl->writeFileAt (nOffset, pBuffer, uBytesToWrite, pBytesWritten); +} - osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); +//############################################# +oslFileError +SAL_CALL osl_isEndOfFile (oslFileHandle Handle, sal_Bool *pIsEOF) +{ + FileHandle_Impl * pImpl = static_cast(Handle); - _tcscpy( pItemImpl->cDriveString, reinterpret_cast(strSysFilePath->buffer) ); - pItemImpl->cDriveString[0] = _toupper( pItemImpl->cDriveString[0] ); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pIsEOF)) + return osl_File_E_INVAL; - if ( pItemImpl->cDriveString[_tcslen(pItemImpl->cDriveString) - 1] != '\\' ) - _tcscat( pItemImpl->cDriveString, TEXT( "\\" ) ); + *pIsEOF = (pImpl->getPos() == pImpl->getSize()); + return osl_File_E_None; +} - *pItem = pItemImpl; - } - } - break; - case PATHTYPE_SYNTAXERROR: - case PATHTYPE_NETROOT: - case PATHTYPE_FILE: - { - HANDLE hFind; - WIN32_FIND_DATA aFindData; +//############################################# +oslFileError +SAL_CALL osl_getFilePos(oslFileHandle Handle, sal_uInt64 *pPos) +{ + FileHandle_Impl * pImpl = static_cast(Handle); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pPos)) + return osl_File_E_INVAL; - if ( strSysFilePath->length > 0 && strSysFilePath->buffer[strSysFilePath->length - 1] == '\\' ) - rtl_uString_newFromStr_WithLength( &strSysFilePath, strSysFilePath->buffer, strSysFilePath->length - 1 ); + *pPos = pImpl->getPos(); + return osl_File_E_None; +} - hFind = FindFirstFile( reinterpret_cast(rtl_uString_getStr(strSysFilePath)), &aFindData ); +//############################################# +oslFileError +SAL_CALL osl_setFilePos(oslFileHandle Handle, sal_uInt32 uHow, sal_Int64 uOffset) +{ + FileHandle_Impl * pImpl = static_cast(Handle); + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile)) + return osl_File_E_INVAL; - if ( hFind != INVALID_HANDLE_VALUE ) - { - DirectoryItem_Impl *pItemImpl = - reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); + static sal_Int64 const g_limit_longlong = std::numeric_limits< LONGLONG >::max(); + if (g_limit_longlong < uOffset) + return osl_File_E_OVERFLOW; + LONGLONG nPos = 0, nOffset = sal::static_int_cast< LONGLONG >(uOffset); - ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); - osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); + switch (uHow) + { + case osl_Pos_Absolut: + if (0 > nOffset) + return osl_File_E_INVAL; + break; - CopyMemory( &pItemImpl->FindData, &aFindData, sizeof(WIN32_FIND_DATA) ); - _tcscpy( pItemImpl->szFullPath, reinterpret_cast(rtl_uString_getStr(strSysFilePath)) ); + case osl_Pos_Current: + nPos = sal::static_int_cast< LONGLONG >(pImpl->getPos()); + if ((0 > nOffset) && (-1*nOffset > nPos)) + return osl_File_E_INVAL; + if (g_limit_longlong < nPos + nOffset) + return osl_File_E_OVERFLOW; + break; - // MT: This costs 600ms startup time on fast v60x! - // GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) ); + case osl_Pos_End: + nPos = sal::static_int_cast< LONGLONG >(pImpl->getSize()); + if ((0 > nOffset) && (-1*nOffset > nPos)) + return osl_File_E_INVAL; + if (g_limit_longlong < nPos + nOffset) + return osl_File_E_OVERFLOW; + break; - pItemImpl->uType = DIRECTORYITEM_FILE; - *pItem = pItemImpl; - FindClose( hFind ); - } - else - error = MapError( GetLastError() ); - } - break; + default: + return osl_File_E_INVAL; } - if ( strSysFilePath ) - rtl_uString_release( strSysFilePath ); - - return error; + return pImpl->setPos (nPos + nOffset); } -//##################################################### -oslFileError SAL_CALL osl_acquireDirectoryItem( oslDirectoryItem Item ) +//############################################# +oslFileError +SAL_CALL osl_getFileSize (oslFileHandle Handle, sal_uInt64 *pSize) { - DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; + FileHandle_Impl * pImpl = static_cast(Handle); - if ( !pItemImpl ) + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pSize)) return osl_File_E_INVAL; - pItemImpl->nRefCount++; + *pSize = pImpl->getSize(); return osl_File_E_None; } -//##################################################### -oslFileError SAL_CALL osl_releaseDirectoryItem( oslDirectoryItem Item ) +//############################################# +oslFileError +SAL_CALL osl_setFileSize (oslFileHandle Handle, sal_uInt64 uSize) { - DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; + FileHandle_Impl * pImpl = static_cast(Handle); - if ( !pItemImpl ) + if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile)) return osl_File_E_INVAL; + if (0 == (pImpl->m_state & FileHandle_Impl::STATE_WRITEABLE)) + return osl_File_E_BADF; - if ( ! --pItemImpl->nRefCount ) - rtl_freeMemory( pItemImpl ); - return osl_File_E_None; -} + static sal_uInt64 const g_limit_longlong = std::numeric_limits< LONGLONG >::max(); + if (g_limit_longlong < uSize) + return osl_File_E_OVERFLOW; -//##################################################### -oslFileError SAL_CALL osl_unmountVolumeDevice( oslVolumeDeviceHandle Handle ) -{ - if ( Handle ) - return osl_File_E_None; - else - return osl_File_E_INVAL; -} + oslFileError result = pImpl->syncFile(); + if (result != osl_File_E_None) + return (result); -//##################################################### -oslFileError SAL_CALL osl_automountVolumeDevice( oslVolumeDeviceHandle Handle ) -{ - if ( Handle ) - return osl_File_E_None; - else - return osl_File_E_INVAL; -} + LARGE_INTEGER nDstPos; nDstPos.QuadPart = sal::static_int_cast< LONGLONG >(uSize); + if (!::SetFilePointerEx(pImpl->m_hFile, nDstPos, 0, FILE_BEGIN)) + return oslTranslateFileError( GetLastError() ); -//##################################################### -oslFileError SAL_CALL osl_acquireVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) -{ - if ( Handle ) - { - rtl_uString_acquire( (rtl_uString *)Handle ); - return osl_File_E_None; - } - else - return osl_File_E_INVAL; -} + if (!::SetEndOfFile(pImpl->m_hFile)) + return oslTranslateFileError( GetLastError() ); + pImpl->m_size = uSize; -//##################################################### -oslFileError SAL_CALL osl_releaseVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) -{ - if ( Handle ) - { - rtl_uString_release( (rtl_uString *)Handle ); - return osl_File_E_None; - } - else - return osl_File_E_INVAL; -} + nDstPos.QuadPart = pImpl->m_offset; + if (!::SetFilePointerEx(pImpl->m_hFile, nDstPos, 0, FILE_BEGIN)) + return oslTranslateFileError( GetLastError() ); -//##################################################### -oslFileError SAL_CALL osl_getVolumeDeviceMountPath( oslVolumeDeviceHandle Handle, rtl_uString **pstrPath ) -{ - if ( Handle && pstrPath ) - { - rtl_uString_assign( pstrPath, (rtl_uString *)Handle ); - return osl_File_E_None; - } - else - return osl_File_E_INVAL; + return osl_File_E_None; } - //################################################################## -// FileURL functions +// File handling functions //################################################################## - -//##################################################### -oslFileError SAL_CALL osl_getFileURLFromSystemPath( - rtl_uString* ustrPath, rtl_uString** pustrURL ) +//############################################# +oslFileError SAL_CALL osl_removeFile( rtl_uString* strPath ) { - return _osl_getFileURLFromSystemPath( ustrPath, pustrURL ); -} + rtl_uString *strSysPath = NULL; + oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); -//##################################################### -oslFileError SAL_CALL osl_getSystemPathFromFileURL( - rtl_uString *ustrURL, rtl_uString **pustrPath) -{ - return _osl_getSystemPathFromFileURL( ustrURL, pustrPath, sal_True ); + if ( osl_File_E_None == error ) + { + if ( DeleteFile( reinterpret_cast(rtl_uString_getStr( strSysPath )) ) ) + error = osl_File_E_None; + else + error = oslTranslateFileError( GetLastError() ); + + rtl_uString_release( strSysPath ); + } + return error; } -//##################################################### -oslFileError SAL_CALL osl_searchFileURL( - rtl_uString *ustrFileName, - rtl_uString *ustrSystemSearchPath, - rtl_uString **pustrPath) -{ - rtl_uString *ustrUNCPath = NULL; - rtl_uString *ustrSysPath = NULL; - oslFileError error; +//############################################# +#define osl_File_CopyRecursive 0x0001 +#define osl_File_CopyOverwrite 0x0002 - /* First try to interpret the file name as an URL even a relative one */ - error = _osl_getSystemPathFromFileURL( ustrFileName, &ustrUNCPath, sal_True ); +oslFileError SAL_CALL osl_copyFile( rtl_uString* strPath, rtl_uString *strDestPath ) +{ + rtl_uString *strSysPath = NULL, *strSysDestPath = NULL; + oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); - /* So far we either have an UNC path or something invalid - Now create a system path */ if ( osl_File_E_None == error ) - error = _osl_getSystemPathFromFileURL( ustrUNCPath, &ustrSysPath, sal_True ); + error = _osl_getSystemPathFromFileURL( strDestPath, &strSysDestPath, sal_False ); if ( osl_File_E_None == error ) { - DWORD nBufferLength; - DWORD dwResult; - LPTSTR lpBuffer = NULL; - LPTSTR lpszFilePart; - - /* Repeat calling SearchPath ... - Start with MAX_PATH for the buffer. In most cases this - will be enough and does not force the loop to runtwice */ - dwResult = MAX_PATH; - - do - { - /* If search path is empty use a NULL pointer instead according to MSDN documentation of SearchPath */ - LPCTSTR lpszSearchPath = ustrSystemSearchPath && ustrSystemSearchPath->length ? reinterpret_cast(ustrSystemSearchPath->buffer) : NULL; - LPCTSTR lpszSearchFile = reinterpret_cast(ustrSysPath->buffer); - - /* Allocate space for buffer according to previous returned count of required chars */ - /* +1 is not neccessary if we follow MSDN documentation but for robustness we do so */ - nBufferLength = dwResult + 1; - lpBuffer = lpBuffer ? - reinterpret_cast(rtl_reallocateMemory(lpBuffer, nBufferLength * sizeof(TCHAR))) : - reinterpret_cast(rtl_allocateMemory(nBufferLength * sizeof(TCHAR))); - - dwResult = SearchPath( lpszSearchPath, lpszSearchFile, NULL, nBufferLength, lpBuffer, &lpszFilePart ); - } while ( dwResult && dwResult >= nBufferLength ); - - /* ... until an error occures or buffer is large enough. - dwResult == nBufferLength can not happen according to documentation but lets be robust ;-) */ + LPCTSTR src = reinterpret_cast(rtl_uString_getStr( strSysPath )); + LPCTSTR dst = reinterpret_cast(rtl_uString_getStr( strSysDestPath )); - if ( dwResult ) - { - rtl_uString_newFromStr( &ustrSysPath, reinterpret_cast(lpBuffer) ); - error = osl_getFileURLFromSystemPath( ustrSysPath, pustrPath ); - } + if ( CopyFile( src, dst, FALSE ) ) + error = osl_File_E_None; else - { - WIN32_FIND_DATA aFindFileData; - HANDLE hFind; - - /* Somthing went wrong, perhaps the path was absolute */ - error = MapError( GetLastError() ); - - hFind = FindFirstFile( reinterpret_cast(ustrSysPath->buffer), &aFindFileData ); - - if ( IsValidHandle(hFind) ) - { - error = osl_getFileURLFromSystemPath( ustrSysPath, pustrPath ); - FindClose( hFind ); - } - } - - rtl_freeMemory( lpBuffer ); + error = oslTranslateFileError( GetLastError() ); } - if ( ustrSysPath ) - rtl_uString_release( ustrSysPath ); - - if ( ustrUNCPath ) - rtl_uString_release( ustrUNCPath ); + if ( strSysPath ) + rtl_uString_release( strSysPath ); + if ( strSysDestPath ) + rtl_uString_release( strSysDestPath ); return error; } -//##################################################### - -oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uString* ustrRelativeURL, rtl_uString** pustrAbsoluteURL ) +//############################################# +oslFileError SAL_CALL osl_moveFile( rtl_uString* strPath, rtl_uString *strDestPath ) { - oslFileError eError; - rtl_uString *ustrRelSysPath = NULL; - rtl_uString *ustrBaseSysPath = NULL; - - if ( ustrBaseURL && ustrBaseURL->length ) - { - eError = _osl_getSystemPathFromFileURL( ustrBaseURL, &ustrBaseSysPath, sal_False ); - OSL_ENSURE( osl_File_E_None == eError, "osl_getAbsoluteFileURL called with relative or invalid base URL" ); + rtl_uString *strSysPath = NULL, *strSysDestPath = NULL; + oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); - eError = _osl_getSystemPathFromFileURL( ustrRelativeURL, &ustrRelSysPath, sal_True ); - } - else - { - eError = _osl_getSystemPathFromFileURL( ustrRelativeURL, &ustrRelSysPath, sal_False ); - OSL_ENSURE( osl_File_E_None == eError, "osl_getAbsoluteFileURL called with empty base URL and/or invalid relative URL" ); - } + if ( osl_File_E_None == error ) + error = _osl_getSystemPathFromFileURL( strDestPath, &strSysDestPath, sal_False ); - if ( !eError ) + if ( osl_File_E_None == error ) { - TCHAR szBuffer[MAX_PATH]; - TCHAR szCurrentDir[MAX_PATH]; - LPTSTR lpFilePart = NULL; - DWORD dwResult; - -/*@@@ToDo - Bad, bad hack, this only works if the base path - really exists which is not necessary according - to RFC2396 - The whole FileURL implementation should be merged - with the rtl/uri class. -*/ - if ( ustrBaseSysPath ) - { - osl_acquireMutex( g_CurrentDirectoryMutex ); - - GetCurrentDirectory( MAX_PATH, szCurrentDir ); - SetCurrentDirectory( reinterpret_cast(ustrBaseSysPath->buffer) ); - } - - dwResult = GetFullPathName( reinterpret_cast(ustrRelSysPath->buffer), MAX_PATH, szBuffer, &lpFilePart ); - - if ( ustrBaseSysPath ) - { - SetCurrentDirectory( szCurrentDir ); - - osl_releaseMutex( g_CurrentDirectoryMutex ); - } - - if ( dwResult ) - { - if ( dwResult >= MAX_PATH ) - eError = osl_File_E_INVAL; - else - { - rtl_uString *ustrAbsSysPath = NULL; - - rtl_uString_newFromStr( &ustrAbsSysPath, reinterpret_cast(szBuffer) ); + LPCTSTR src = reinterpret_cast(rtl_uString_getStr( strSysPath )); + LPCTSTR dst = reinterpret_cast(rtl_uString_getStr( strSysDestPath )); - eError = osl_getFileURLFromSystemPath( ustrAbsSysPath, pustrAbsoluteURL ); - - if ( ustrAbsSysPath ) - rtl_uString_release( ustrAbsSysPath ); - } - } + if ( MoveFileEx( src, dst, MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING ) ) + error = osl_File_E_None; else - eError = MapError( GetLastError() ); + error = oslTranslateFileError( GetLastError() ); } - if ( ustrBaseSysPath ) - rtl_uString_release( ustrBaseSysPath ); - - if ( ustrRelSysPath ) - rtl_uString_release( ustrRelSysPath ); - - return eError; -} + if ( strSysPath ) + rtl_uString_release( strSysPath ); + if ( strSysDestPath ) + rtl_uString_release( strSysDestPath ); -//##################################################### -oslFileError SAL_CALL osl_getCanonicalName( rtl_uString *strRequested, rtl_uString **strValid ) -{ - rtl_uString_newFromString(strValid, strRequested); - return osl_File_E_None; + return error; } diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx new file mode 100644 index 000000000000..53aa1c40cd2b --- /dev/null +++ b/sal/osl/w32/file_dirvol.cxx @@ -0,0 +1,1774 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: file.cxx,v $ + * $Revision: 1.19 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#define UNICODE +#define _UNICODE +#define _WIN32_WINNT_0x0500 +#include "systools/win32/uwinapi.h" + +#include "osl/file.h" + +#include "file_url.h" +#include "file_error.h" +#include "path_helper.hxx" + +#include "osl/diagnose.h" +#include "osl/time.h" +#include "rtl/alloc.h" +#include "rtl/ustring.hxx" + +#include + +//##################################################### +#define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0]))) + +static const wchar_t UNC_PREFIX[] = L"\\\\"; +static const wchar_t BACKSLASH = '\\'; +static const wchar_t SLASH = '/'; + +//##################################################### +extern "C" BOOL TimeValueToFileTime(const TimeValue *cpTimeVal, FILETIME *pFTime) +{ + SYSTEMTIME BaseSysTime; + FILETIME BaseFileTime; + FILETIME FTime; + __int64 localTime; + BOOL fSuccess = FALSE; + + BaseSysTime.wYear = 1970; + BaseSysTime.wMonth = 1; + BaseSysTime.wDayOfWeek = 0; + BaseSysTime.wDay = 1; + BaseSysTime.wHour = 0; + BaseSysTime.wMinute = 0; + BaseSysTime.wSecond = 0; + BaseSysTime.wMilliseconds = 0; + + if (cpTimeVal==NULL) + return fSuccess; + + if ( SystemTimeToFileTime(&BaseSysTime, &BaseFileTime) ) + { + __int64 timeValue; + localTime=cpTimeVal->Seconds*(__int64)10000000+cpTimeVal->Nanosec/100; + *(__int64 *)&FTime=localTime; + fSuccess = 0 <= (timeValue= *((__int64 *)&BaseFileTime) + *((__int64 *) &FTime)); + if (fSuccess) + *(__int64 *)pFTime=timeValue; + } + return fSuccess; +} + +//##################################################### +extern "C" BOOL FileTimeToTimeValue(const FILETIME *cpFTime, TimeValue *pTimeVal) +{ + SYSTEMTIME BaseSysTime; + FILETIME BaseFileTime; + BOOL fSuccess = FALSE; /* Assume failure */ + + BaseSysTime.wYear = 1970; + BaseSysTime.wMonth = 1; + BaseSysTime.wDayOfWeek = 0; + BaseSysTime.wDay = 1; + BaseSysTime.wHour = 0; + BaseSysTime.wMinute = 0; + BaseSysTime.wSecond = 0; + BaseSysTime.wMilliseconds = 0; + + if ( SystemTimeToFileTime(&BaseSysTime, &BaseFileTime) ) + { + __int64 Value; + + fSuccess = 0 <= (Value = *((__int64 *)cpFTime) - *((__int64 *)&BaseFileTime)); + + if ( fSuccess ) + { + pTimeVal->Seconds = (unsigned long) (Value / 10000000L); + pTimeVal->Nanosec = (unsigned long)((Value % 10000000L) * 100); + } + } + return fSuccess; +} + +//##################################################### +namespace /* private */ +{ + //##################################################### + struct Component + { + Component() : + begin_(0), end_(0) + {} + + bool isPresent() const + { return (static_cast(end_ - begin_) > 0); } + + const sal_Unicode* begin_; + const sal_Unicode* end_; + }; + + //##################################################### + struct UNCComponents + { + Component server_; + Component share_; + Component resource_; + }; + + //##################################################### + inline bool is_UNC_path(const sal_Unicode* path) + { return (0 == wcsncmp(UNC_PREFIX, reinterpret_cast(path), ELEMENTS_OF_ARRAY(UNC_PREFIX) - 1)); } + + //##################################################### + inline bool is_UNC_path(const rtl::OUString& path) + { return is_UNC_path(path.getStr()); } + + //##################################################### + void parse_UNC_path(const sal_Unicode* path, UNCComponents* puncc) + { + OSL_PRECOND(is_UNC_path(path), "Precondition violated: No UNC path"); + OSL_PRECOND(rtl_ustr_indexOfChar(path, SLASH) != -1, "Path must not contain slashes"); + + const sal_Unicode* pend = path + rtl_ustr_getLength(path); + const sal_Unicode* ppos = path + 2; + + puncc->server_.begin_ = ppos; + while ((ppos < pend) && (*ppos != BACKSLASH)) + ppos++; + + puncc->server_.end_ = ppos; + + if (BACKSLASH == *ppos) + { + puncc->share_.begin_ = ++ppos; + while ((ppos < pend) && (*ppos != BACKSLASH)) + ppos++; + + puncc->share_.end_ = ppos; + + if (BACKSLASH == *ppos) + { + puncc->resource_.begin_ = ++ppos; + while (ppos < pend) + ppos++; + + puncc->resource_.end_ = ppos; + } + } + + OSL_POSTCOND(puncc->server_.isPresent() && puncc->share_.isPresent(), \ + "Postcondition violated: Invalid UNC path detected"); + } + + //##################################################### + void parse_UNC_path(const rtl::OUString& path, UNCComponents* puncc) + { parse_UNC_path(path.getStr(), puncc); } + + + //##################################################### + bool has_path_parent(const sal_Unicode* path) + { + // Has the given path a parent or are we already there, + // e.g. 'c:\' or '\\server\share\'? + + bool has_parent = false; + if (is_UNC_path(path)) + { + UNCComponents unc_comp; + parse_UNC_path(path, &unc_comp); + has_parent = unc_comp.resource_.isPresent(); + } + else + { + has_parent = !osl::systemPathIsLogicalDrivePattern(path); + } + return has_parent; + } + + //##################################################### + inline bool has_path_parent(const rtl::OUString& path) + { return has_path_parent(path.getStr()); } + +} // end namespace private + +//##################################################### +// volume handling functions +//##################################################### + +//##################################################### +oslFileError SAL_CALL osl_unmountVolumeDevice( oslVolumeDeviceHandle Handle ) +{ + if ( Handle ) + return osl_File_E_None; + else + return osl_File_E_INVAL; +} + +//##################################################### +oslFileError SAL_CALL osl_automountVolumeDevice( oslVolumeDeviceHandle Handle ) +{ + if ( Handle ) + return osl_File_E_None; + else + return osl_File_E_INVAL; +} + +//##################################################### +oslFileError SAL_CALL osl_acquireVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) +{ + if ( Handle ) + { + rtl_uString_acquire( (rtl_uString *)Handle ); + return osl_File_E_None; + } + else + return osl_File_E_INVAL; +} + +//##################################################### +oslFileError SAL_CALL osl_releaseVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) +{ + if ( Handle ) + { + rtl_uString_release( (rtl_uString *)Handle ); + return osl_File_E_None; + } + else + return osl_File_E_INVAL; +} + +//##################################################### +oslFileError SAL_CALL osl_getVolumeDeviceMountPath( oslVolumeDeviceHandle Handle, rtl_uString **pstrPath ) +{ + if ( Handle && pstrPath ) + { + rtl_uString_assign( pstrPath, (rtl_uString *)Handle ); + return osl_File_E_None; + } + else + return osl_File_E_INVAL; +} + +//################################################################## +// directory handling functions +//################################################################## + +#define DIRECTORYITEM_DRIVE 0 +#define DIRECTORYITEM_FILE 1 +#define DIRECTORYITEM_SERVER 2 + +struct DirectoryItem_Impl +{ + UINT uType; + union { + WIN32_FIND_DATA FindData; + TCHAR cDriveString[MAX_PATH]; + }; + TCHAR szFullPath[MAX_PATH]; + BOOL bFullPathNormalized; + int nRefCount; +}; + +//##################################################### + +#define DIRECTORYTYPE_LOCALROOT 0 +#define DIRECTORYTYPE_NETROOT 1 +#define DIRECTORYTYPE_NETRESORCE 2 +#define DIRECTORYTYPE_FILESYSTEM 3 + +struct Directory_Impl +{ + UINT uType; + union { + HANDLE hDirectory; + HANDLE hEnumDrives; + }; + TCHAR szDirectoryPath[MAX_PATH]; +}; + +//##################################################### + +typedef struct tagDRIVEENUM +{ + LPCTSTR lpIdent; + TCHAR cBuffer[/*('Z' - 'A' + 1) * sizeof("A:\\") + 1*/256]; + LPCTSTR lpCurrent; +} DRIVEENUM, * PDRIVEENUM, FAR * LPDRIVEENUM; + +//##################################################### + +static HANDLE WINAPI OpenLogicalDrivesEnum(void) +{ + LPDRIVEENUM pEnum = (LPDRIVEENUM)HeapAlloc( GetProcessHeap(), 0, sizeof(DRIVEENUM) ); + if ( pEnum ) + { + DWORD dwNumCopied = GetLogicalDriveStrings( (sizeof(pEnum->cBuffer) - 1) / sizeof(TCHAR), pEnum->cBuffer ); + + if ( dwNumCopied && dwNumCopied < sizeof(pEnum->cBuffer) / sizeof(TCHAR) ) + { + pEnum->lpCurrent = pEnum->cBuffer; + pEnum->lpIdent = L"tagDRIVEENUM"; + } + else + { + HeapFree( GetProcessHeap(), 0, pEnum ); + pEnum = NULL; + } + } + return pEnum ? (HANDLE)pEnum : INVALID_HANDLE_VALUE; +} + +//##################################################### +static BOOL WINAPI EnumLogicalDrives(HANDLE hEnum, LPTSTR lpBuffer) +{ + BOOL fSuccess = FALSE; + LPDRIVEENUM pEnum = (LPDRIVEENUM)hEnum; + + if ( pEnum ) + { + int nLen = _tcslen( pEnum->lpCurrent ); + + if ( nLen ) + { + CopyMemory( lpBuffer, pEnum->lpCurrent, (nLen + 1) * sizeof(TCHAR) ); + pEnum->lpCurrent += nLen + 1; + fSuccess = TRUE; + } + else + SetLastError( ERROR_NO_MORE_FILES ); + } + else + SetLastError( ERROR_INVALID_HANDLE ); + + return fSuccess; +} + +//##################################################### +static BOOL WINAPI CloseLogicalDrivesEnum(HANDLE hEnum) +{ + BOOL fSuccess = FALSE; + LPDRIVEENUM pEnum = (LPDRIVEENUM)hEnum; + + if ( pEnum ) + { + HeapFree( GetProcessHeap(), 0, pEnum ); + fSuccess = TRUE; + } + else + SetLastError( ERROR_INVALID_HANDLE ); + + return fSuccess; +} + +//##################################################### +typedef struct tagDIRECTORY +{ + HANDLE hFind; + WIN32_FIND_DATA aFirstData; +} DIRECTORY, *PDIRECTORY, FAR *LPDIRECTORY; + +//##################################################### +static HANDLE WINAPI OpenDirectory(LPCTSTR lpszPath) +{ + LPDIRECTORY pDirectory = (LPDIRECTORY)HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECTORY)); + + if (pDirectory) + { + TCHAR szFileMask[MAX_PATH]; + int nLen; + + _tcscpy( szFileMask, lpszPath ); + nLen = _tcslen( szFileMask ); + + if (nLen && szFileMask[nLen-1] != '\\') + _tcscat(szFileMask, TEXT("\\*.*")); + else + _tcscat(szFileMask, TEXT("*.*")); + + pDirectory->hFind = FindFirstFile(szFileMask, &pDirectory->aFirstData); + + if (!IsValidHandle(pDirectory->hFind)) + { + if ( GetLastError() != ERROR_NO_MORE_FILES ) + { + HeapFree(GetProcessHeap(), 0, pDirectory); + pDirectory = NULL; + } + } + } + return (HANDLE)pDirectory; +} + +//##################################################### +BOOL WINAPI EnumDirectory(HANDLE hDirectory, LPWIN32_FIND_DATA pFindData) +{ + BOOL fSuccess = FALSE; + LPDIRECTORY pDirectory = (LPDIRECTORY)hDirectory; + + if ( pDirectory ) + { + BOOL fValid; + + do + { + if ( pDirectory->aFirstData.cFileName[0] ) + { + *pFindData = pDirectory->aFirstData; + fSuccess = TRUE; + pDirectory->aFirstData.cFileName[0] = 0; + } + else if ( IsValidHandle( pDirectory->hFind ) ) + fSuccess = FindNextFile( pDirectory->hFind, pFindData ); + else + { + fSuccess = FALSE; + SetLastError( ERROR_NO_MORE_FILES ); + } + + fValid = fSuccess && _tcscmp( TEXT("."), pFindData->cFileName ) != 0 && _tcscmp( TEXT(".."), pFindData->cFileName ) != 0; + + } while( fSuccess && !fValid ); + } + else + SetLastError( ERROR_INVALID_HANDLE ); + + return fSuccess; +} + +//##################################################### +static BOOL WINAPI CloseDirectory(HANDLE hDirectory) +{ + BOOL fSuccess = FALSE; + LPDIRECTORY pDirectory = (LPDIRECTORY)hDirectory; + + if (pDirectory) + { + if (IsValidHandle(pDirectory->hFind)) + fSuccess = FindClose(pDirectory->hFind); + + fSuccess = HeapFree(GetProcessHeap(), 0, pDirectory) && fSuccess; + } + else + SetLastError(ERROR_INVALID_HANDLE); + + return fSuccess; +} + +//##################################################### +static oslFileError osl_openLocalRoot( + rtl_uString *strDirectoryPath, oslDirectory *pDirectory) +{ + rtl_uString *strSysPath = NULL; + oslFileError error; + + if ( !pDirectory ) + return osl_File_E_INVAL; + + *pDirectory = NULL; + + error = _osl_getSystemPathFromFileURL( strDirectoryPath, &strSysPath, sal_False ); + if ( osl_File_E_None == error ) + { + Directory_Impl *pDirImpl; + + pDirImpl = reinterpret_cast(rtl_allocateMemory( sizeof(Directory_Impl))); + _tcscpy( pDirImpl->szDirectoryPath, reinterpret_cast(rtl_uString_getStr(strSysPath)) ); + + /* Append backslash if neccessary */ + + /* @@@ToDo + use function ensure backslash + */ + if ( pDirImpl->szDirectoryPath[_tcslen(pDirImpl->szDirectoryPath) - 1] != L'\\' ) + _tcscat( pDirImpl->szDirectoryPath, L"\\" ); + + pDirImpl->uType = DIRECTORYTYPE_LOCALROOT; + pDirImpl->hEnumDrives = OpenLogicalDrivesEnum(); + + /* @@@ToDo + Use IsValidHandle(...) + */ + if ( pDirImpl->hEnumDrives != INVALID_HANDLE_VALUE ) + { + *pDirectory = (oslDirectory)pDirImpl; + error = osl_File_E_None; + } + else + { + if ( pDirImpl ) + rtl_freeMemory(pDirImpl); + + error = oslTranslateFileError( GetLastError() ); + } + + rtl_uString_release( strSysPath ); + } + return error; +} + +//##################################################### +static oslFileError SAL_CALL osl_openFileDirectory( + rtl_uString *strDirectoryPath, oslDirectory *pDirectory) +{ + oslFileError error = osl_File_E_None; + + if ( !pDirectory ) + return osl_File_E_INVAL; + *pDirectory = NULL; + + Directory_Impl *pDirImpl = reinterpret_cast(rtl_allocateMemory(sizeof(Directory_Impl))); + _tcscpy( pDirImpl->szDirectoryPath, reinterpret_cast(rtl_uString_getStr(strDirectoryPath)) ); + + /* Append backslash if neccessary */ + + /* @@@ToDo + use function ensure backslash + */ + if ( pDirImpl->szDirectoryPath[_tcslen(pDirImpl->szDirectoryPath) - 1] != L'\\' ) + _tcscat( pDirImpl->szDirectoryPath, L"\\" ); + + pDirImpl->uType = DIRECTORYTYPE_FILESYSTEM; + pDirImpl->hDirectory = OpenDirectory( pDirImpl->szDirectoryPath ); + + if ( !pDirImpl->hDirectory ) + { + error = oslTranslateFileError( GetLastError() ); + + rtl_freeMemory(pDirImpl), pDirImpl = 0; + } + + *pDirectory = (oslDirectory)(pDirImpl); + return error; +} + +//##################################################### +static oslFileError SAL_CALL osl_openNetworkServer( + rtl_uString *strSysDirPath, oslDirectory *pDirectory) +{ + NETRESOURCEW aNetResource; + HANDLE hEnum; + DWORD dwError; + + ZeroMemory( &aNetResource, sizeof(aNetResource) ); + + aNetResource.lpRemoteName = reinterpret_cast(strSysDirPath->buffer); + + dwError = WNetOpenEnumW( + RESOURCE_GLOBALNET, + RESOURCETYPE_DISK, + RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER, + &aNetResource, + &hEnum ); + + if ( ERROR_SUCCESS == dwError ) + { + Directory_Impl *pDirImpl; + + pDirImpl = reinterpret_cast(rtl_allocateMemory(sizeof(Directory_Impl))); + pDirImpl->uType = DIRECTORYTYPE_NETROOT; + pDirImpl->hDirectory = hEnum; + *pDirectory = (oslDirectory)pDirImpl; + } + return oslTranslateFileError( dwError ); +} + +//############################################# +static DWORD create_dir_with_callback( + rtl_uString * dir_path, + oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, + void* pData) +{ + // Create the specified directory and call the + // user specified callback function. On success + // the function returns ERROR_SUCCESS else a Win32 error code. + + if (CreateDirectory(reinterpret_cast(dir_path->buffer), NULL)) + { + if (aDirectoryCreationCallbackFunc) + { + rtl::OUString url; + _osl_getFileURLFromSystemPath(dir_path, &(url.pData)); + aDirectoryCreationCallbackFunc(pData, url.pData); + } + return ERROR_SUCCESS; + } + return GetLastError(); +} + +//############################################# +static int path_make_parent(sal_Unicode* path) +{ + /* Cut off the last part of the given path to + get the parent only, e.g. 'c:\dir\subdir' -> + 'c:\dir' or '\\share\sub\dir' -> '\\share\sub' + @return The position where the path has been cut + off (this is the posistion of the last backslash). + If there are no more parents 0 will be returned, + e.g. 'c:\' or '\\Share' have no more parents */ + + OSL_PRECOND(rtl_ustr_indexOfChar(path, SLASH) != -1, "Path must not contain slashes"); + OSL_PRECOND(has_path_parent(path), "Path must have a parent"); + + sal_Unicode* pos_last_backslash = path + rtl_ustr_lastIndexOfChar(path, BACKSLASH); + *pos_last_backslash = 0; + return (pos_last_backslash - path); +} + +//############################################# +static DWORD create_dir_recursively_( + rtl_uString * dir_path, + oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, + void* pData) +{ + OSL_PRECOND( + rtl_ustr_lastIndexOfChar_WithLength(dir_path->buffer, dir_path->length, BACKSLASH) != dir_path->length, + "Path must not end with a backslash"); + + DWORD w32_error = create_dir_with_callback( + dir_path, aDirectoryCreationCallbackFunc, pData); + if (w32_error == ERROR_SUCCESS) + return ERROR_SUCCESS; + + if ((w32_error != ERROR_PATH_NOT_FOUND) || !has_path_parent(dir_path->buffer)) + return w32_error; + + int pos = path_make_parent(dir_path->buffer); // dir_path->buffer[pos] = 0, restore below + + w32_error = create_dir_recursively_( + dir_path, aDirectoryCreationCallbackFunc, pData); + + dir_path->buffer[pos] = BACKSLASH; // restore + + if (ERROR_SUCCESS != w32_error) + return w32_error; + + return create_dir_recursively_(dir_path, aDirectoryCreationCallbackFunc, pData); +} + +//############################################# +oslFileError SAL_CALL osl_createDirectoryPath( + rtl_uString* aDirectoryUrl, + oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, + void* pData) +{ + if (aDirectoryUrl == NULL) + return osl_File_E_INVAL; + + rtl::OUString sys_path; + oslFileError osl_error = + _osl_getSystemPathFromFileURL(aDirectoryUrl, &sys_path.pData, sal_False); + + if (osl_error != osl_File_E_None) + return osl_error; + + osl::systemPathRemoveSeparator(sys_path); + + // const_cast because sys_path is a local copy + // which we want to modify inplace instead of + // coyp it into another buffer on the heap again + return oslTranslateFileError(create_dir_recursively_( + sys_path.pData, aDirectoryCreationCallbackFunc, pData)); +} + +//##################################################### +oslFileError SAL_CALL osl_createDirectory(rtl_uString* strPath) +{ + rtl_uString *strSysPath = NULL; + oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); + + if ( osl_File_E_None == error ) + { + if ( CreateDirectoryW( reinterpret_cast(rtl_uString_getStr( strSysPath )), NULL ) ) + error = osl_File_E_None; +/*@@@ToDo + The else case is a hack because the ucb or the webtop had some + problems with the error code that CreateDirectory returns in + case the path is only a logical drive, should be removed! +*/ + else + { + const sal_Unicode *pBuffer = rtl_uString_getStr( strSysPath ); + sal_Int32 nLen = rtl_uString_getLength( strSysPath ); + + if ( + ( pBuffer[0] >= 'A' && pBuffer[0] <= 'Z' || + pBuffer[0] >= 'a' && pBuffer[0] <= 'z' ) && + pBuffer[1] == ':' && ( nLen ==2 || nLen == 3 && pBuffer[2] == '\\' ) + ) + SetLastError( ERROR_ALREADY_EXISTS ); + + error = oslTranslateFileError( GetLastError() ); + } + + rtl_uString_release( strSysPath ); + } + return error; +} + +//##################################################### +oslFileError SAL_CALL osl_removeDirectory(rtl_uString* strPath) +{ + rtl_uString *strSysPath = NULL; + oslFileError error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False ); + + if ( osl_File_E_None == error ) + { + if ( RemoveDirectory( reinterpret_cast(rtl_uString_getStr( strSysPath )) ) ) + error = osl_File_E_None; + else + error = oslTranslateFileError( GetLastError() ); + + rtl_uString_release( strSysPath ); + } + return error; +} + +//##################################################### +oslFileError SAL_CALL osl_openDirectory(rtl_uString *strDirectoryPath, oslDirectory *pDirectory) +{ + oslFileError error; + + if ( 0 == rtl_ustr_ascii_compareIgnoreAsciiCase( strDirectoryPath->buffer, "file:///" ) ) + error = osl_openLocalRoot( strDirectoryPath, pDirectory ); + else + { + rtl_uString *strSysDirectoryPath = NULL; + DWORD dwPathType; + + error = _osl_getSystemPathFromFileURL( strDirectoryPath, &strSysDirectoryPath, sal_False ); + + if ( osl_File_E_None != error ) + return error; + + dwPathType = IsValidFilePath( strSysDirectoryPath, NULL, VALIDATEPATH_NORMAL, NULL ); + + if ( dwPathType & PATHTYPE_IS_SERVER ) + { + error = osl_openNetworkServer( strSysDirectoryPath, pDirectory ); + } + else + error = osl_openFileDirectory( strSysDirectoryPath, pDirectory ); + + rtl_uString_release( strSysDirectoryPath ); + } + return error; +} + +//##################################################### +static oslFileError SAL_CALL osl_getNextNetResource( + oslDirectory Directory, oslDirectoryItem *pItem, sal_uInt32 uHint ) +{ + Directory_Impl *pDirImpl = (Directory_Impl *)Directory; + DirectoryItem_Impl *pItemImpl = NULL; + BYTE buffer[16384]; + LPNETRESOURCEW lpNetResource = (LPNETRESOURCEW)buffer; + DWORD dwError, dwCount, dwBufSize; + + uHint = uHint; /* to get no warning */ + + if ( !pItem ) + return osl_File_E_INVAL; + *pItem = NULL; + + if ( !pDirImpl ) + return osl_File_E_INVAL; + + dwCount = 1; + dwBufSize = sizeof(buffer); + dwError = WNetEnumResource( pDirImpl->hDirectory, &dwCount, lpNetResource, &dwBufSize ); + + switch ( dwError ) + { + case NO_ERROR: + case ERROR_MORE_DATA: + { + pItemImpl = reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); + if ( !pItemImpl ) + return osl_File_E_NOMEM; + + ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); + pItemImpl->uType = DIRECTORYITEM_DRIVE; + osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); + + wcscpy( pItemImpl->cDriveString, lpNetResource->lpRemoteName ); + + *pItem = pItemImpl; + } + return osl_File_E_None; + case ERROR_NO_MORE_ITEMS: + return osl_File_E_NOENT; + default: + return oslTranslateFileError( dwError ); + } +} + +//##################################################### +static oslFileError SAL_CALL osl_getNextDrive( + oslDirectory Directory, oslDirectoryItem *pItem, sal_uInt32 uHint ) +{ + Directory_Impl *pDirImpl = (Directory_Impl *)Directory; + DirectoryItem_Impl *pItemImpl = NULL; + BOOL fSuccess; + + uHint = uHint; /* avoid warnings */ + + if ( !pItem ) + return osl_File_E_INVAL; + *pItem = NULL; + + if ( !pDirImpl ) + return osl_File_E_INVAL; + + pItemImpl = reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); + if ( !pItemImpl ) + return osl_File_E_NOMEM; + + ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); + pItemImpl->uType = DIRECTORYITEM_DRIVE; + osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); + fSuccess = EnumLogicalDrives( pDirImpl->hEnumDrives, pItemImpl->cDriveString ); + + if ( fSuccess ) + { + *pItem = pItemImpl; + return osl_File_E_None; + } + else + { + rtl_freeMemory( pItemImpl ); + return oslTranslateFileError( GetLastError() ); + } +} + +//##################################################### +static oslFileError SAL_CALL osl_getNextFileItem( + oslDirectory Directory, oslDirectoryItem *pItem, sal_uInt32 uHint) +{ + Directory_Impl *pDirImpl = (Directory_Impl *)Directory; + DirectoryItem_Impl *pItemImpl = NULL; + BOOL fFound; + + uHint = uHint; /* avoid warnings */ + + if ( !pItem ) + return osl_File_E_INVAL; + *pItem = NULL; + + if ( !pDirImpl ) + return osl_File_E_INVAL; + + pItemImpl = reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); + if ( !pItemImpl ) + return osl_File_E_NOMEM; + + memset( pItemImpl, 0, sizeof(DirectoryItem_Impl) ); + fFound = EnumDirectory( pDirImpl->hDirectory, &pItemImpl->FindData ); + + if ( fFound ) + { + pItemImpl->uType = DIRECTORYITEM_FILE; + pItemImpl->nRefCount = 1; + _tcscpy( pItemImpl->szFullPath, pDirImpl->szDirectoryPath ); + _tcscat( pItemImpl->szFullPath, pItemImpl->FindData.cFileName ); + pItemImpl->bFullPathNormalized = FALSE; + *pItem = (oslDirectoryItem)pItemImpl; + return osl_File_E_None; + } + else + { + rtl_freeMemory( pItemImpl ); + return oslTranslateFileError( GetLastError() ); + } +} + +//##################################################### +oslFileError SAL_CALL osl_getNextDirectoryItem( + oslDirectory Directory, oslDirectoryItem *pItem, sal_uInt32 uHint) +{ + Directory_Impl *pDirImpl = (Directory_Impl *)Directory; + + /* Assume failure */ + + if ( !pItem ) + return osl_File_E_INVAL; + *pItem = NULL; + + if ( !pDirImpl ) + return osl_File_E_INVAL; + + switch ( pDirImpl->uType ) + { + case DIRECTORYTYPE_LOCALROOT: + return osl_getNextDrive( Directory, pItem, uHint ); + case DIRECTORYTYPE_NETROOT: + return osl_getNextNetResource( Directory, pItem, uHint ); + case DIRECTORYTYPE_FILESYSTEM: + return osl_getNextFileItem( Directory, pItem, uHint ); + default: + return osl_File_E_INVAL; + } +} + +//##################################################### +oslFileError SAL_CALL osl_closeDirectory(oslDirectory Directory) +{ + Directory_Impl *pDirImpl = (Directory_Impl *)Directory; + oslFileError eError = osl_File_E_INVAL; + + if ( pDirImpl ) + { + switch ( pDirImpl->uType ) + { + case DIRECTORYTYPE_FILESYSTEM: + eError = CloseDirectory( pDirImpl->hDirectory ) ? osl_File_E_None : oslTranslateFileError( GetLastError() ); + break; + case DIRECTORYTYPE_LOCALROOT: + eError = CloseLogicalDrivesEnum( pDirImpl->hEnumDrives ) ? osl_File_E_None : oslTranslateFileError( GetLastError() ); + break; + case DIRECTORYTYPE_NETROOT: + { + DWORD err = WNetCloseEnum(pDirImpl->hDirectory); + eError = (err == NO_ERROR) ? osl_File_E_None : oslTranslateFileError(err); + } + break; + default: + OSL_ENSURE( 0, "Invalid directory type" ); + break; + } + + rtl_freeMemory(pDirImpl); + } + return eError; +} + +//##################################################### +/* Different types of paths */ +typedef enum _PATHTYPE +{ + PATHTYPE_SYNTAXERROR = 0, + PATHTYPE_NETROOT, + PATHTYPE_NETSERVER, + PATHTYPE_VOLUME, + PATHTYPE_FILE +} PATHTYPE; + +oslFileError SAL_CALL osl_getDirectoryItem(rtl_uString *strFilePath, oslDirectoryItem *pItem) +{ + oslFileError error = osl_File_E_None; + rtl_uString* strSysFilePath = NULL; + PATHTYPE type = PATHTYPE_FILE; + DWORD dwPathType; + + /* Assume failure */ + + if ( !pItem ) + return osl_File_E_INVAL; + + *pItem = NULL; + + + error = _osl_getSystemPathFromFileURL( strFilePath, &strSysFilePath, sal_False ); + + if ( osl_File_E_None != error ) + return error; + + dwPathType = IsValidFilePath( strSysFilePath, NULL, VALIDATEPATH_NORMAL, NULL ); + + if ( dwPathType & PATHTYPE_IS_VOLUME ) + type = PATHTYPE_VOLUME; + else if ( dwPathType & PATHTYPE_IS_SERVER ) + type = PATHTYPE_NETSERVER; + else + type = PATHTYPE_FILE; + + switch ( type ) + { + case PATHTYPE_NETSERVER: + { + DirectoryItem_Impl* pItemImpl = + reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); + + if ( !pItemImpl ) + error = osl_File_E_NOMEM; + + if ( osl_File_E_None == error ) + { + ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); + pItemImpl->uType = DIRECTORYITEM_SERVER; + + osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); + + _tcscpy( pItemImpl->szFullPath, reinterpret_cast(strSysFilePath->buffer) ); + + // Assign a title anyway + { + int iSrc = 2; + int iDst = 0; + + while( iSrc < strSysFilePath->length && strSysFilePath->buffer[iSrc] && strSysFilePath->buffer[iSrc] != '\\' ) + { + pItemImpl->FindData.cFileName[iDst++] = strSysFilePath->buffer[iSrc++]; + } + } + + *pItem = pItemImpl; + } + } + break; + case PATHTYPE_VOLUME: + { + DirectoryItem_Impl* pItemImpl = + reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); + + if ( !pItemImpl ) + error = osl_File_E_NOMEM; + + if ( osl_File_E_None == error ) + { + ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); + pItemImpl->uType = DIRECTORYITEM_DRIVE; + + osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); + + _tcscpy( pItemImpl->cDriveString, reinterpret_cast(strSysFilePath->buffer) ); + pItemImpl->cDriveString[0] = _toupper( pItemImpl->cDriveString[0] ); + + if ( pItemImpl->cDriveString[_tcslen(pItemImpl->cDriveString) - 1] != '\\' ) + _tcscat( pItemImpl->cDriveString, TEXT( "\\" ) ); + + *pItem = pItemImpl; + } + } + break; + case PATHTYPE_SYNTAXERROR: + case PATHTYPE_NETROOT: + case PATHTYPE_FILE: + { + HANDLE hFind; + WIN32_FIND_DATA aFindData; + + if ( strSysFilePath->length > 0 && strSysFilePath->buffer[strSysFilePath->length - 1] == '\\' ) + rtl_uString_newFromStr_WithLength( &strSysFilePath, strSysFilePath->buffer, strSysFilePath->length - 1 ); + + hFind = FindFirstFile( reinterpret_cast(rtl_uString_getStr(strSysFilePath)), &aFindData ); + + if ( hFind != INVALID_HANDLE_VALUE ) + { + DirectoryItem_Impl *pItemImpl = + reinterpret_cast(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); + + ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); + osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); + + CopyMemory( &pItemImpl->FindData, &aFindData, sizeof(WIN32_FIND_DATA) ); + _tcscpy( pItemImpl->szFullPath, reinterpret_cast(rtl_uString_getStr(strSysFilePath)) ); + + // MT: This costs 600ms startup time on fast v60x! + // GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) ); + + pItemImpl->uType = DIRECTORYITEM_FILE; + *pItem = pItemImpl; + FindClose( hFind ); + } + else + error = oslTranslateFileError( GetLastError() ); + } + break; + } + + if ( strSysFilePath ) + rtl_uString_release( strSysFilePath ); + + return error; +} + +//##################################################### +oslFileError SAL_CALL osl_acquireDirectoryItem( oslDirectoryItem Item ) +{ + DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; + + if ( !pItemImpl ) + return osl_File_E_INVAL; + + pItemImpl->nRefCount++; + return osl_File_E_None; +} + +//##################################################### +oslFileError SAL_CALL osl_releaseDirectoryItem( oslDirectoryItem Item ) +{ + DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; + + if ( !pItemImpl ) + return osl_File_E_INVAL; + + if ( ! --pItemImpl->nRefCount ) + rtl_freeMemory( pItemImpl ); + return osl_File_E_None; +} + +//##################################################### +// volume / file info handling functions +//##################################################### + +//##################################################### +static inline bool is_floppy_A_present() +{ return (GetLogicalDrives() & 1); } + +//##################################################### +static inline bool is_floppy_B_present() +{ return (GetLogicalDrives() & 2); } + +//##################################################### +bool is_floppy_volume_mount_point(const rtl::OUString& path) +{ + // determines if a volume mount point shows to a floppy + // disk by comparing the unique volume names + static const LPWSTR FLOPPY_A = L"A:\\"; + static const LPWSTR FLOPPY_B = L"B:\\"; + + rtl::OUString p(path); + osl::systemPathEnsureSeparator(p); + + TCHAR vn[51]; + if (GetVolumeNameForVolumeMountPoint(reinterpret_cast(p.getStr()), vn, ELEMENTS_OF_ARRAY(vn))) + { + TCHAR vnfloppy[51]; + if (is_floppy_A_present() && + GetVolumeNameForVolumeMountPoint(FLOPPY_A, vnfloppy, ELEMENTS_OF_ARRAY(vnfloppy)) && + (0 == wcscmp(vn, vnfloppy))) + return true; + + if (is_floppy_B_present() && + GetVolumeNameForVolumeMountPoint(FLOPPY_B, vnfloppy, ELEMENTS_OF_ARRAY(vnfloppy)) && + (0 == wcscmp(vn, vnfloppy))) + return true; + } + return false; +} + +//################################################ +static bool is_floppy_drive(const rtl::OUString& path) +{ + static const LPWSTR FLOPPY_DRV_LETTERS = TEXT("AaBb"); + + // we must take into account that even a floppy + // drive may be mounted to a directory so checking + // for the drive letter alone is not sufficient + // we must compare the unique volume name with + // that of the available floppy disks + + const sal_Unicode* pszPath = path.getStr(); + return ((wcschr(FLOPPY_DRV_LETTERS, pszPath[0]) && (L':' == pszPath[1])) || is_floppy_volume_mount_point(path)); +} + +//##################################################### +static bool is_volume_mount_point(const rtl::OUString& path) +{ + rtl::OUString p(path); + osl::systemPathRemoveSeparator(p); + + bool is_volume_root = false; + + if (!is_floppy_drive(p)) + { + DWORD fattr = GetFileAttributes(reinterpret_cast(p.getStr())); + + if ((INVALID_FILE_ATTRIBUTES != fattr) && + (FILE_ATTRIBUTE_REPARSE_POINT & fattr)) + { + WIN32_FIND_DATA find_data; + HANDLE h_find = FindFirstFile(reinterpret_cast(p.getStr()), &find_data); + + if (IsValidHandle(h_find) && + (FILE_ATTRIBUTE_REPARSE_POINT & find_data.dwFileAttributes) && + (IO_REPARSE_TAG_MOUNT_POINT == find_data.dwReserved0)) + { + is_volume_root = true; + } + if (IsValidHandle(h_find)) + FindClose(h_find); + } + } + return is_volume_root; +} + +//############################################# +static UINT get_volume_mount_point_drive_type(const rtl::OUString& path) +{ + if (0 == path.getLength()) + return GetDriveType(NULL); + + rtl::OUString p(path); + osl::systemPathEnsureSeparator(p); + + TCHAR vn[51]; + if (GetVolumeNameForVolumeMountPoint(reinterpret_cast(p.getStr()), vn, ELEMENTS_OF_ARRAY(vn))) + return GetDriveType(vn); + + return DRIVE_NO_ROOT_DIR; +} + +//############################################# +static inline bool is_drivetype_request(sal_uInt32 field_mask) +{ + return (field_mask & osl_VolumeInfo_Mask_Attributes); +} + +//############################################# +static oslFileError osl_get_drive_type( + const rtl::OUString& path, oslVolumeInfo* pInfo) +{ + // GetDriveType fails on empty volume mount points + // see Knowledge Base Q244089 + UINT drive_type; + if (is_volume_mount_point(path)) + drive_type = get_volume_mount_point_drive_type(path); + else + drive_type = GetDriveType(reinterpret_cast(path.getStr())); + + if (DRIVE_NO_ROOT_DIR == drive_type) + return oslTranslateFileError(ERROR_INVALID_DRIVE); + + pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; + + switch (drive_type) + { + case DRIVE_CDROM: + pInfo->uAttributes |= osl_Volume_Attribute_CompactDisc | osl_Volume_Attribute_Removeable; + break; + case DRIVE_REMOVABLE: + pInfo->uAttributes |= osl_Volume_Attribute_Removeable; + if (is_floppy_drive(path)) + pInfo->uAttributes |= osl_Volume_Attribute_FloppyDisk; + break; + case DRIVE_FIXED: + pInfo->uAttributes |= osl_Volume_Attribute_FixedDisk; + break; + case DRIVE_RAMDISK: + pInfo->uAttributes |= osl_Volume_Attribute_RAMDisk; + break; + case DRIVE_REMOTE: + pInfo->uAttributes |= osl_Volume_Attribute_Remote; + break; + case DRIVE_UNKNOWN: + pInfo->uAttributes = 0; + break; + default: + pInfo->uValidFields &= ~osl_VolumeInfo_Mask_Attributes; + pInfo->uAttributes = 0; + break; + } + return osl_File_E_None; +} + +//############################################# +static inline bool is_volume_space_info_request(sal_uInt32 field_mask) +{ + return (field_mask & + (osl_VolumeInfo_Mask_TotalSpace | + osl_VolumeInfo_Mask_UsedSpace | + osl_VolumeInfo_Mask_FreeSpace)); +} + +//############################################# +static void get_volume_space_information( + const rtl::OUString& path, oslVolumeInfo *pInfo) +{ + BOOL ret = GetDiskFreeSpaceEx( + reinterpret_cast(path.getStr()), + (PULARGE_INTEGER)&(pInfo->uFreeSpace), + (PULARGE_INTEGER)&(pInfo->uTotalSpace), + NULL); + + if (ret) + { + pInfo->uUsedSpace = pInfo->uTotalSpace - pInfo->uFreeSpace; + pInfo->uValidFields |= osl_VolumeInfo_Mask_TotalSpace | + osl_VolumeInfo_Mask_UsedSpace | + osl_VolumeInfo_Mask_FreeSpace; + } +} + +//############################################# +static inline bool is_filesystem_attributes_request(sal_uInt32 field_mask) +{ + return (field_mask & + (osl_VolumeInfo_Mask_MaxNameLength | + osl_VolumeInfo_Mask_MaxPathLength | + osl_VolumeInfo_Mask_FileSystemName | + osl_VolumeInfo_Mask_FileSystemCaseHandling)); +} + +//############################################# +static oslFileError get_filesystem_attributes( + const rtl::OUString& path, sal_uInt32 field_mask, oslVolumeInfo* pInfo) +{ + pInfo->uAttributes = 0; + + // osl_get_drive_type must be called first because + // this function resets osl_VolumeInfo_Mask_Attributes + // on failure + if (is_drivetype_request(field_mask)) + { + oslFileError osl_error = osl_get_drive_type(path, pInfo); + if (osl_File_E_None != osl_error) + return osl_error; + } + if (is_filesystem_attributes_request(field_mask)) + { + WCHAR vn[MAX_PATH]; + WCHAR fsn[MAX_PATH]; + DWORD serial; + DWORD mcl; + DWORD flags; + + LPCTSTR pszPath = reinterpret_cast(path.getStr()); + if (GetVolumeInformation(pszPath, vn, MAX_PATH, &serial, &mcl, &flags, fsn, MAX_PATH)) + { + pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxNameLength; + pInfo->uMaxNameLength = mcl; + + pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxPathLength; + pInfo->uMaxPathLength = MAX_PATH; + + pInfo->uValidFields |= osl_VolumeInfo_Mask_FileSystemName; + rtl_uString_newFromStr(&pInfo->ustrFileSystemName, reinterpret_cast(fsn)); + + // volumes (even NTFS) will always be considered case + // insensitive because the Win32 API is not able to + // deal with case sensitive volumes see M$ Knowledge Base + // article 100625 that's why we never set the attribute + // osl_Volume_Attribute_Case_Sensitive + + if (flags & FS_CASE_IS_PRESERVED) + pInfo->uAttributes |= osl_Volume_Attribute_Case_Is_Preserved; + + pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; + } + } + return osl_File_E_None; +} + +//##################################################### +static bool path_get_parent(rtl::OUString& path) +{ + OSL_PRECOND(path.lastIndexOf(SLASH) == -1, "Path must not have slashes"); + + if (!has_path_parent(path)) + { + sal_Int32 i = path.lastIndexOf(BACKSLASH); + if (-1 < i) + { + path = rtl::OUString(path.getStr(), i); + return true; + } + } + return false; +} + +//##################################################### +static void path_travel_to_volume_root(const rtl::OUString& system_path, rtl::OUString& volume_root) +{ + rtl::OUString sys_path(system_path); + + while(!is_volume_mount_point(sys_path) && path_get_parent(sys_path)) + /**/; + + volume_root = sys_path; + osl::systemPathEnsureSeparator(volume_root); +} + +//############################################# +oslFileError SAL_CALL osl_getVolumeInformation( + rtl_uString *ustrURL, oslVolumeInfo *pInfo, sal_uInt32 uFieldMask ) +{ + if (!pInfo) + return osl_File_E_INVAL; + + rtl::OUString system_path; + oslFileError error = _osl_getSystemPathFromFileURL(ustrURL, &system_path.pData, sal_False); + + if (osl_File_E_None != error) + return error; + + rtl::OUString volume_root; + path_travel_to_volume_root(system_path, volume_root); + + pInfo->uValidFields = 0; + + if ((error = get_filesystem_attributes(volume_root, uFieldMask, pInfo)) != osl_File_E_None) + return error; + + if (is_volume_space_info_request(uFieldMask)) + get_volume_space_information(volume_root, pInfo); + + if (uFieldMask & osl_VolumeInfo_Mask_DeviceHandle) + { + pInfo->uValidFields |= osl_VolumeInfo_Mask_DeviceHandle; + osl_getFileURLFromSystemPath(volume_root.pData, (rtl_uString**)&pInfo->pDeviceHandle); + } + + return osl_File_E_None; +} + +//##################################################### +static oslFileError SAL_CALL osl_getDriveInfo( + oslDirectoryItem Item, oslFileStatus *pStatus, sal_uInt32 uFieldMask) +{ + DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; + TCHAR cDrive[3] = TEXT("A:"); + TCHAR cRoot[4] = TEXT("A:\\"); + + if ( !pItemImpl ) + return osl_File_E_INVAL; + + pStatus->uValidFields = 0; + + cDrive[0] = pItemImpl->cDriveString[0]; + cRoot[0] = pItemImpl->cDriveString[0]; + + if ( uFieldMask & osl_FileStatus_Mask_FileName ) + { + if ( pItemImpl->cDriveString[0] == '\\' && pItemImpl->cDriveString[1] == '\\' ) + { + LPCWSTR lpFirstBkSlash = wcschr( &pItemImpl->cDriveString[2], '\\' ); + + if ( lpFirstBkSlash && lpFirstBkSlash[1] ) + { + LPCWSTR lpLastBkSlash = wcschr( &lpFirstBkSlash[1], '\\' ); + + if ( lpLastBkSlash ) + rtl_uString_newFromStr_WithLength( &pStatus->ustrFileName, reinterpret_cast(&lpFirstBkSlash[1]), lpLastBkSlash - lpFirstBkSlash - 1 ); + else + rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(&lpFirstBkSlash[1]) ); + pStatus->uValidFields |= osl_FileStatus_Mask_FileName; + } + } + else switch ( GetDriveType( cRoot ) ) + { + case DRIVE_REMOTE: + { + TCHAR szBuffer[1024]; + DWORD const dwBufsizeConst = ELEMENTS_OF_ARRAY(szBuffer); + DWORD dwBufsize = dwBufsizeConst; + + DWORD dwResult = WNetGetConnection( cDrive, szBuffer, &dwBufsize ); + if ( NO_ERROR == dwResult ) + { + TCHAR szFileName[dwBufsizeConst + 16]; + + swprintf( szFileName, L"%s [%s]", cDrive, szBuffer ); + rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(szFileName) ); + } + else + rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(cDrive) ); + } + pStatus->uValidFields |= osl_FileStatus_Mask_FileName; + break; + case DRIVE_FIXED: + { + TCHAR szVolumeNameBuffer[1024]; + DWORD const dwBufsizeConst = ELEMENTS_OF_ARRAY(szVolumeNameBuffer); + + if ( GetVolumeInformation( cRoot, szVolumeNameBuffer, dwBufsizeConst, NULL, NULL, NULL, NULL, 0 ) ) + { + TCHAR szFileName[dwBufsizeConst + 16]; + + swprintf( szFileName, L"%s [%s]", cDrive, szVolumeNameBuffer ); + rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(szFileName) ); + } + else + rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(cDrive) ); + } + pStatus->uValidFields |= osl_FileStatus_Mask_FileName; + break; + case DRIVE_CDROM: + case DRIVE_REMOVABLE: + pStatus->uValidFields |= osl_FileStatus_Mask_FileName; + rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(cRoot) ); + break; + case DRIVE_UNKNOWN: + default: + break; + } + } + + pStatus->eType = osl_File_Type_Volume; + pStatus->uValidFields |= osl_FileStatus_Mask_Type; + + if ( uFieldMask & osl_FileStatus_Mask_FileURL ) + { + rtl_uString *ustrSystemPath = NULL; + + rtl_uString_newFromStr( &ustrSystemPath, reinterpret_cast(pItemImpl->cDriveString) ); + osl_getFileURLFromSystemPath( ustrSystemPath, &pStatus->ustrFileURL ); + rtl_uString_release( ustrSystemPath ); + pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; + } + return osl_File_E_None; +} + +//##################################################### +static oslFileError SAL_CALL osl_getServerInfo( + oslDirectoryItem Item, oslFileStatus *pStatus, sal_uInt32 uFieldMask ) +{ + DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; + if ( !pItemImpl ) + return osl_File_E_INVAL; + + pStatus->uValidFields = 0; + + // pStatus->uValidFields |= osl_FileStatus_Mask_FileName; + + // if ( _tcscmp( pItemImpl->FindData.cFileName, TEXT(".") ) == 0 ) + // rtl_uString_newFromAscii( &pStatus->ustrFileName, "/" ); + // else + // rtl_uString_newFromStr( &pStatus->ustrFileName, pItemImpl->FindData.cFileName ); + + pStatus->eType = osl_File_Type_Directory; + pStatus->uValidFields |= osl_FileStatus_Mask_Type; + + if ( uFieldMask & osl_FileStatus_Mask_FileURL ) + { + rtl_uString *ustrSystemPath = NULL; + + rtl_uString_newFromStr( &ustrSystemPath, reinterpret_cast(pItemImpl->szFullPath) ); + osl_getFileURLFromSystemPath( ustrSystemPath, &pStatus->ustrFileURL ); + rtl_uString_release( ustrSystemPath ); + pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; + } + return osl_File_E_None; +} + +//############################################# +oslFileError SAL_CALL osl_getFileStatus( + oslDirectoryItem Item, + oslFileStatus *pStatus, + sal_uInt32 uFieldMask ) +{ + DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; + + if ( !pItemImpl ) + return osl_File_E_INVAL; + + switch ( pItemImpl->uType ) + { + case DIRECTORYITEM_DRIVE: + return osl_getDriveInfo( Item, pStatus, uFieldMask ); + case DIRECTORYITEM_SERVER: + return osl_getServerInfo( Item, pStatus, uFieldMask ); + default: + break; + } + + if ( uFieldMask & osl_FileStatus_Mask_Validate ) + { + HANDLE hFind = FindFirstFile( pItemImpl->szFullPath, &pItemImpl->FindData ); + + if ( hFind != INVALID_HANDLE_VALUE ) + FindClose( hFind ); + else + return oslTranslateFileError( GetLastError() ); + + uFieldMask &= ~ osl_FileStatus_Mask_Validate; + } + + /* If no fields to retrieve left ignore pStatus */ + if ( !uFieldMask ) + return osl_File_E_None; + + /* Otherwise, this must be a valid pointer */ + if ( !pStatus ) + return osl_File_E_INVAL; + + if ( pStatus->uStructSize != sizeof(oslFileStatus) ) + return osl_File_E_INVAL; + + pStatus->uValidFields = 0; + + /* File time stamps */ + + if ( (uFieldMask & osl_FileStatus_Mask_ModifyTime) && + FileTimeToTimeValue( &pItemImpl->FindData.ftLastWriteTime, &pStatus->aModifyTime ) ) + pStatus->uValidFields |= osl_FileStatus_Mask_ModifyTime; + + if ( (uFieldMask & osl_FileStatus_Mask_AccessTime) && + FileTimeToTimeValue( &pItemImpl->FindData.ftLastAccessTime, &pStatus->aAccessTime ) ) + pStatus->uValidFields |= osl_FileStatus_Mask_AccessTime; + + if ( (uFieldMask & osl_FileStatus_Mask_CreationTime) && + FileTimeToTimeValue( &pItemImpl->FindData.ftCreationTime, &pStatus->aCreationTime ) ) + pStatus->uValidFields |= osl_FileStatus_Mask_CreationTime; + + /* Most of the fields are already set, regardless of requiered fields */ + + rtl_uString_newFromStr( &pStatus->ustrFileName, reinterpret_cast(pItemImpl->FindData.cFileName) ); + pStatus->uValidFields |= osl_FileStatus_Mask_FileName; + + if ((FILE_ATTRIBUTE_REPARSE_POINT & pItemImpl->FindData.dwFileAttributes) && + (IO_REPARSE_TAG_MOUNT_POINT == pItemImpl->FindData.dwReserved0)) + pStatus->eType = osl_File_Type_Volume; + else if (pItemImpl->FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + pStatus->eType = osl_File_Type_Directory; + else + pStatus->eType = osl_File_Type_Regular; + + pStatus->uValidFields |= osl_FileStatus_Mask_Type; + + pStatus->uAttributes = pItemImpl->FindData.dwFileAttributes; + pStatus->uValidFields |= osl_FileStatus_Mask_Attributes; + + pStatus->uFileSize = (sal_uInt64)pItemImpl->FindData.nFileSizeLow + ((sal_uInt64)pItemImpl->FindData.nFileSizeHigh << 32); + pStatus->uValidFields |= osl_FileStatus_Mask_FileSize; + + if ( uFieldMask & osl_FileStatus_Mask_LinkTargetURL ) + { + rtl_uString *ustrFullPath = NULL; + + rtl_uString_newFromStr( &ustrFullPath, reinterpret_cast(pItemImpl->szFullPath) ); + osl_getFileURLFromSystemPath( ustrFullPath, &pStatus->ustrLinkTargetURL ); + rtl_uString_release( ustrFullPath ); + + pStatus->uValidFields |= osl_FileStatus_Mask_LinkTargetURL; + } + + if ( uFieldMask & osl_FileStatus_Mask_FileURL ) + { + rtl_uString *ustrFullPath = NULL; + + + if ( !pItemImpl->bFullPathNormalized ) + { + GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) ); + pItemImpl->bFullPathNormalized = TRUE; + } + rtl_uString_newFromStr( &ustrFullPath, reinterpret_cast(pItemImpl->szFullPath) ); + osl_getFileURLFromSystemPath( ustrFullPath, &pStatus->ustrFileURL ); + rtl_uString_release( ustrFullPath ); + pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; + } + + return osl_File_E_None; +} + +//##################################################### +// file attributes handling functions +//##################################################### + +//############################################# +oslFileError SAL_CALL osl_setFileAttributes( + rtl_uString *ustrFileURL, + sal_uInt64 uAttributes ) +{ + oslFileError error; + rtl_uString *ustrSysPath = NULL; + DWORD dwFileAttributes; + BOOL fSuccess; + + // Converts the normalized path into a systempath + error = _osl_getSystemPathFromFileURL( ustrFileURL, &ustrSysPath, sal_False ); + + if ( osl_File_E_None != error ) + return error; + + dwFileAttributes = GetFileAttributes( reinterpret_cast(rtl_uString_getStr(ustrSysPath)) ); + + if ( (DWORD)-1 != dwFileAttributes ) + { + dwFileAttributes &= ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN); + + if ( uAttributes & osl_File_Attribute_ReadOnly ) + dwFileAttributes |= FILE_ATTRIBUTE_READONLY; + + if ( uAttributes & osl_File_Attribute_Hidden ) + dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN; + + fSuccess = SetFileAttributes( reinterpret_cast(rtl_uString_getStr(ustrSysPath)), dwFileAttributes ); + } + else + fSuccess = FALSE; + + if ( !fSuccess ) + error = oslTranslateFileError( GetLastError() ); + + rtl_uString_release( ustrSysPath ); + + return error; +} + +//##################################################### +oslFileError SAL_CALL osl_setFileTime( + rtl_uString *filePath, + const TimeValue *aCreationTime, + const TimeValue *aLastAccessTime, + const TimeValue *aLastWriteTime) +{ + oslFileError error; + rtl_uString *sysPath=NULL; + FILETIME *lpCreationTime=NULL; + FILETIME *lpLastAccessTime=NULL; + FILETIME *lpLastWriteTime=NULL; + FILETIME ftCreationTime; + FILETIME ftLastAccessTime; + FILETIME ftLastWriteTime; + HANDLE hFile; + BOOL fSuccess; + + + error=_osl_getSystemPathFromFileURL(filePath, &sysPath, sal_False); + + if (error==osl_File_E_INVAL) + return error; + + hFile=CreateFileW(reinterpret_cast(rtl_uString_getStr(sysPath)), GENERIC_WRITE, 0, NULL , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + rtl_uString_release(sysPath); + + if (hFile==INVALID_HANDLE_VALUE) + return osl_File_E_NOENT; + + if (TimeValueToFileTime(aCreationTime, &ftCreationTime)) + lpCreationTime=&ftCreationTime; + + if (TimeValueToFileTime(aLastAccessTime, &ftLastAccessTime)) + lpLastAccessTime=&ftLastAccessTime; + + if (TimeValueToFileTime(aLastWriteTime, &ftLastWriteTime)) + lpLastWriteTime=&ftLastWriteTime; + + fSuccess=SetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime); + + CloseHandle(hFile); + + if (!fSuccess) + return osl_File_E_INVAL; + else + return osl_File_E_None; +} diff --git a/sal/osl/w32/file_error.c b/sal/osl/w32/file_error.c new file mode 100644 index 000000000000..3942420eb8da --- /dev/null +++ b/sal/osl/w32/file_error.c @@ -0,0 +1,154 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: file_error.c,v $ + * $Revision: 1.0 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#define UNICODE +#define _UNICODE +#define _WIN32_WINNT_0x0500 +#include "systools/win32/uwinapi.h" + +#include "file_error.h" + +#include "osl/diagnose.h" +#include "osl/thread.h" + +/* OS error to oslFileError values mapping table */ +struct osl_file_error_entry +{ + unsigned long oscode; /* OS return value */ + int errnocode; /* oslFileError code */ +}; + +static const struct osl_file_error_entry errtable[] = { + { ERROR_SUCCESS, osl_File_E_None }, /* 0 */ + { ERROR_INVALID_FUNCTION, osl_File_E_INVAL }, /* 1 */ + { ERROR_FILE_NOT_FOUND, osl_File_E_NOENT }, /* 2 */ + { ERROR_PATH_NOT_FOUND, osl_File_E_NOENT }, /* 3 */ + { ERROR_TOO_MANY_OPEN_FILES, osl_File_E_MFILE }, /* 4 */ + { ERROR_ACCESS_DENIED, osl_File_E_ACCES }, /* 5 */ + { ERROR_INVALID_HANDLE, osl_File_E_BADF }, /* 6 */ + { ERROR_ARENA_TRASHED, osl_File_E_NOMEM }, /* 7 */ + { ERROR_NOT_ENOUGH_MEMORY, osl_File_E_NOMEM }, /* 8 */ + { ERROR_INVALID_BLOCK, osl_File_E_NOMEM }, /* 9 */ + { ERROR_BAD_ENVIRONMENT, osl_File_E_2BIG }, /* 10 */ + { ERROR_BAD_FORMAT, osl_File_E_NOEXEC }, /* 11 */ + { ERROR_INVALID_ACCESS, osl_File_E_INVAL }, /* 12 */ + { ERROR_INVALID_DATA, osl_File_E_INVAL }, /* 13 */ + { ERROR_INVALID_DRIVE, osl_File_E_NOENT }, /* 15 */ + { ERROR_CURRENT_DIRECTORY, osl_File_E_ACCES }, /* 16 */ + { ERROR_NOT_SAME_DEVICE, osl_File_E_XDEV }, /* 17 */ + { ERROR_NO_MORE_FILES, osl_File_E_NOENT }, /* 18 */ + { ERROR_NOT_READY, osl_File_E_NOTREADY }, /* 21 */ + { ERROR_LOCK_VIOLATION, osl_File_E_ACCES }, /* 33 */ + { ERROR_BAD_NETPATH, osl_File_E_NOENT }, /* 53 */ + { ERROR_NETWORK_ACCESS_DENIED, osl_File_E_ACCES }, /* 65 */ + { ERROR_BAD_NET_NAME, osl_File_E_NOENT }, /* 67 */ + { ERROR_FILE_EXISTS, osl_File_E_EXIST }, /* 80 */ + { ERROR_CANNOT_MAKE, osl_File_E_ACCES }, /* 82 */ + { ERROR_FAIL_I24, osl_File_E_ACCES }, /* 83 */ + { ERROR_INVALID_PARAMETER, osl_File_E_INVAL }, /* 87 */ + { ERROR_NO_PROC_SLOTS, osl_File_E_AGAIN }, /* 89 */ + { ERROR_DRIVE_LOCKED, osl_File_E_ACCES }, /* 108 */ + { ERROR_BROKEN_PIPE, osl_File_E_PIPE }, /* 109 */ + { ERROR_DISK_FULL, osl_File_E_NOSPC }, /* 112 */ + { ERROR_INVALID_TARGET_HANDLE, osl_File_E_BADF }, /* 114 */ + { ERROR_INVALID_HANDLE, osl_File_E_INVAL }, /* 124 */ + { ERROR_WAIT_NO_CHILDREN, osl_File_E_CHILD }, /* 128 */ + { ERROR_CHILD_NOT_COMPLETE, osl_File_E_CHILD }, /* 129 */ + { ERROR_DIRECT_ACCESS_HANDLE, osl_File_E_BADF }, /* 130 */ + { ERROR_NEGATIVE_SEEK, osl_File_E_INVAL }, /* 131 */ + { ERROR_SEEK_ON_DEVICE, osl_File_E_ACCES }, /* 132 */ + { ERROR_DIR_NOT_EMPTY, osl_File_E_NOTEMPTY }, /* 145 */ + { ERROR_NOT_LOCKED, osl_File_E_ACCES }, /* 158 */ + { ERROR_BAD_PATHNAME, osl_File_E_NOENT }, /* 161 */ + { ERROR_MAX_THRDS_REACHED, osl_File_E_AGAIN }, /* 164 */ + { ERROR_LOCK_FAILED, osl_File_E_ACCES }, /* 167 */ + { ERROR_ALREADY_EXISTS, osl_File_E_EXIST }, /* 183 */ + { ERROR_FILENAME_EXCED_RANGE, osl_File_E_NOENT }, /* 206 */ + { ERROR_NESTING_NOT_ALLOWED, osl_File_E_AGAIN }, /* 215 */ + { ERROR_DIRECTORY, osl_File_E_NOENT }, /* 267 */ + { ERROR_NOT_ENOUGH_QUOTA, osl_File_E_NOMEM }, /* 1816 */ + { ERROR_UNEXP_NET_ERR, osl_File_E_NETWORK } /* 59 */ +}; + +/* The following two constants must be the minimum and maximum + values in the (contiguous) range of osl_File_E_xec Failure errors. +*/ +#define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG +#define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN + +/* These are the low and high value in the range of errors that are + access violations +*/ +#define MIN_EACCES_RANGE ERROR_WRITE_PROTECT +#define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED + +oslFileError oslTranslateFileError (/*DWORD*/ unsigned long dwError) +{ + static const int n = sizeof(errtable)/sizeof(errtable[0]); + + int i; + for (i = 0; i < n; ++i ) + { + if (dwError == errtable[i].oscode) + return (oslFileError)(errtable[i].errnocode); + } + + /* The error code wasn't in the table. We check for a range of + osl_File_E_ACCES errors or exec failure errors (ENOEXEC). + Otherwise osl_File_E_INVAL is returned. + */ + if ( (dwError >= MIN_EACCES_RANGE) && (dwError <= MAX_EACCES_RANGE) ) + return osl_File_E_ACCES; + else if ( (dwError >= MIN_EXEC_ERROR) && (dwError <= MAX_EXEC_ERROR) ) + return osl_File_E_NOEXEC; + else + return osl_File_E_INVAL; +} + +//##################################################### +#if OSL_DEBUG_LEVEL > 0 +void _osl_warnFile( const char *message, rtl_uString *ustrFile ) +{ + char szBuffer[2048]; + + if (ustrFile) + { + rtl_String *strFile = NULL; + + rtl_uString2String( &strFile, rtl_uString_getStr( ustrFile ), rtl_uString_getLength( ustrFile ), + osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS ); + snprintf( szBuffer, sizeof(szBuffer), message, strFile->buffer ); + rtl_string_release( strFile ); + + message = szBuffer; + } + OSL_ENSURE( 0, message ); +} +#endif /* OSL_DEBUG_LEVEL */ diff --git a/sal/osl/w32/file_error.h b/sal/osl/w32/file_error.h new file mode 100644 index 000000000000..caebbdb1c560 --- /dev/null +++ b/sal/osl/w32/file_error.h @@ -0,0 +1,54 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: file_error.h,v $ + * $Revision: 1.0 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_OSL_FILE_ERROR_H +#define INCLUDED_OSL_FILE_ERROR_H + +#include "osl/file.h" +#include "rtl/ustring.h" + +#ifdef __cplusplus +extern "C" { +#endif + +oslFileError oslTranslateFileError (/*DWORD*/ unsigned long dwError); + +#if OSL_DEBUG_LEVEL > 0 +void _osl_warnFile (const char * message, rtl_uString * ustrFile); +#define OSL_ENSURE_FILE( cond, msg, file ) ( (cond) ? (void)0 : _osl_warnFile( msg, file ) ) +#else +#define OSL_ENSURE_FILE( cond, msg, file ) ((void)0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* INCLUDED_OSL_FILE_ERROR_H */ diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx new file mode 100644 index 000000000000..968c4bccc95e --- /dev/null +++ b/sal/osl/w32/file_url.cxx @@ -0,0 +1,1013 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: file_url.cxx,v $ + * $Revision: 1.0 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#define UNICODE +#define _UNICODE +#define _WIN32_WINNT_0x0500 +#include "systools/win32/uwinapi.h" + +#include "file_url.h" +#include "file_error.h" + +#include "rtl/alloc.h" +#include "osl/diagnose.h" +#include "osl/file.h" +#include "osl/mutex.h" + +#include +#include + +#if OSL_DEBUG_LEVEL > 0 +#define OSL_ENSURE_FILE( cond, msg, file ) ( (cond) ? (void)0 : _osl_warnFile( msg, file ) ) +#else +#define OSL_ENSURE_FILE( cond, msg, file ) ((void)0) +#endif + +#define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0]))) + +//################################################################## +// FileURL functions +//################################################################## + +extern "C" oslMutex g_CurrentDirectoryMutex; /* Initialized in dllentry.c */ +oslMutex g_CurrentDirectoryMutex = 0; + +//##################################################### +static BOOL IsValidFilePathComponent( + LPCTSTR lpComponent, LPCTSTR *lppComponentEnd, DWORD dwFlags) +{ + LPCTSTR lpComponentEnd = NULL; + LPCTSTR lpCurrent = lpComponent; + BOOL fValid = TRUE; /* Assume success */ + TCHAR cLast = 0; + + /* Path component length must not exceed MAX_PATH */ + + while ( !lpComponentEnd && lpCurrent && lpCurrent - lpComponent < MAX_PATH ) + { + switch ( *lpCurrent ) + { + /* Both backslash and slash determine the end of a path component */ + case '\0': + case '/': + case '\\': + switch ( cLast ) + { + /* Component must not end with '.' or blank and can't be empty */ + + case '.': + if ( dwFlags & VALIDATEPATH_ALLOW_ELLIPSE ) + { + if ( 1 == lpCurrent - lpComponent ) + { + /* Current directory is O.K. */ + lpComponentEnd = lpCurrent; + break; + } + else if ( 2 == lpCurrent - lpComponent && '.' == *lpComponent ) + { + /* Parent directory is O.K. */ + lpComponentEnd = lpCurrent; + break; + } + } + case 0: + case ' ': + lpComponentEnd = lpCurrent - 1; + fValid = FALSE; + break; + default: + lpComponentEnd = lpCurrent; + break; + } + break; + /* '?' and '*' are valid wildcards but not valid file name characters */ + case '?': + case '*': + if ( dwFlags & VALIDATEPATH_ALLOW_WILDCARDS ) + break; + /* The following characters are reserved */ + case '<': + case '>': + case '\"': + case '|': + case ':': + lpComponentEnd = lpCurrent; + fValid = FALSE; + break; + default: + /* Characters below ASCII 32 are not allowed */ + if ( *lpCurrent < ' ' ) + { + lpComponentEnd = lpCurrent; + fValid = FALSE; + } + break; + } + cLast = *lpCurrent++; + } + + /* If we don't reached the end of the component the length of the component was to long + ( See condition of while loop ) */ + if ( !lpComponentEnd ) + { + fValid = FALSE; + lpComponentEnd = lpCurrent; + } + + /* Test wether the component specifies a device name what is not allowed */ + + // MT: PERFORMANCE: + // This is very expensive. A lot of calls to _tcsicmp. + // in SRC6870m71 67.000 calls of this method while empty office start result into more than 1.500.00 calls of _tcsicmp! + // Possible optimizations + // - Array should be const static + // - Sorted array, use binary search + // - More intelligent check for com1-9, lpt1-9 + // Maybe make szComponent upper case, don't search case intensitive + // Talked to HRO: Could be removed. Shouldn't be used in OOo, and if used for something like a filename, it will lead to an error anyway. + /* + if ( fValid ) + { + LPCTSTR alpDeviceNames[] = + { + TEXT("CON"), + TEXT("PRN"), + TEXT("AUX"), + TEXT("CLOCK$"), + TEXT("NUL"), + TEXT("LPT1"), + TEXT("LPT2"), + TEXT("LPT3"), + TEXT("LPT4"), + TEXT("LPT5"), + TEXT("LPT6"), + TEXT("LPT7"), + TEXT("LPT8"), + TEXT("LPT9"), + TEXT("COM1"), + TEXT("COM2"), + TEXT("COM3"), + TEXT("COM4"), + TEXT("COM5"), + TEXT("COM6"), + TEXT("COM7"), + TEXT("COM8"), + TEXT("COM9") + }; + + TCHAR szComponent[MAX_PATH]; + int nComponentLength; + LPCTSTR lpDot; + int i; + + // A device name with an extension is also invalid + lpDot = _tcschr( lpComponent, '.' ); + + if ( !lpDot || lpDot > lpComponentEnd ) + nComponentLength = lpComponentEnd - lpComponent; + else + nComponentLength = lpDot - lpComponent; + + _tcsncpy( szComponent, lpComponent, nComponentLength ); + szComponent[nComponentLength] = 0; + + for ( i = 0; i < sizeof( alpDeviceNames ) / sizeof(LPCTSTR); i++ ) + { + if ( 0 == _tcsicmp( szComponent, alpDeviceNames[i] ) ) + { + lpComponentEnd = lpComponent; + fValid = FALSE; + break; + } + } + } + */ + + if ( fValid ) + { + // Empty components are not allowed + if ( lpComponentEnd - lpComponent < 1 ) + fValid = FALSE; + + // If we reached the end of the string NULL is returned + else if ( !*lpComponentEnd ) + lpComponentEnd = NULL; + + } + + if ( lppComponentEnd ) + *lppComponentEnd = lpComponentEnd; + + return fValid; +} + +//##################################################### +#define CHARSET_SEPARATOR TEXT("\\/") + +DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_uString **corrected) +{ + LPCTSTR lpszPath = reinterpret_cast< LPCTSTR >(path->buffer); + LPCTSTR lpComponent; + BOOL fValid = TRUE; + DWORD dwPathType = PATHTYPE_ERROR; + + if ( dwFlags & VALIDATEPATH_ALLOW_RELATIVE ) + dwFlags |= VALIDATEPATH_ALLOW_ELLIPSE; + + if ( !lpszPath ) + { + fValid = FALSE; + lpComponent = lpszPath; + } + + /* Test for UNC path notation */ + if ( 2 == _tcsspn( lpszPath, CHARSET_SEPARATOR ) ) + { + /* Place the pointer behind the leading to backslashes */ + + lpComponent = lpszPath + 2; + + fValid = IsValidFilePathComponent( lpComponent, &lpComponent, VALIDATEPATH_ALLOW_ELLIPSE ); + + /* So far we have a valid servername. Now let's see if we also have a network resource */ + + dwPathType = PATHTYPE_ABSOLUTE_UNC; + + if ( fValid ) + { + if ( lpComponent && !*++lpComponent ) + lpComponent = NULL; + + if ( !lpComponent ) + { + #if 0 + /* We only have a Server specification what is invalid */ + + lpComponent = lpszPath; + fValid = FALSE; + #else + dwPathType |= PATHTYPE_IS_SERVER; + #endif + } + else + { + /* Now test the network resource */ + + fValid = IsValidFilePathComponent( lpComponent, &lpComponent, 0 ); + + /* If we now reached the end of the path, everything is O.K. */ + + + if ( fValid && (!lpComponent || lpComponent && !*++lpComponent ) ) + { + lpComponent = NULL; + dwPathType |= PATHTYPE_IS_VOLUME; + } + } + } + } + + /* Local path verification. Must start with : */ + else if ( _istalpha( lpszPath[0] ) && ':' == lpszPath[1] ) + { + /* Place pointer behind correct drive specification */ + + lpComponent = lpszPath + 2; + + if ( 1 == _tcsspn( lpComponent, CHARSET_SEPARATOR ) ) + lpComponent++; + else if ( *lpComponent ) + fValid = FALSE; + + dwPathType = PATHTYPE_ABSOLUTE_LOCAL; + + /* Now we are behind the backslash or it was a simple drive without backslash */ + + if ( fValid && !*lpComponent ) + { + lpComponent = NULL; + dwPathType |= PATHTYPE_IS_VOLUME; + } + } + + /* Can be a relative path */ + else if ( dwFlags & VALIDATEPATH_ALLOW_RELATIVE ) + { + lpComponent = lpszPath; + + /* Relative path can start with a backslash */ + + if ( 1 == _tcsspn( lpComponent, CHARSET_SEPARATOR ) ) + { + lpComponent++; + if ( !*lpComponent ) + lpComponent = NULL; + } + + dwPathType = PATHTYPE_RELATIVE; + } + + /* Anything else is an error */ + else + { + fValid = FALSE; + lpComponent = lpszPath; + } + + /* Now validate each component of the path */ + while ( fValid && lpComponent ) + { + // Correct path by merging consecutive slashes: + if (*lpComponent == '\\' && corrected != NULL) { + sal_Int32 i = lpComponent - lpszPath; + rtl_uString_newReplaceStrAt(corrected, path, i, 1, NULL); + //TODO: handle out-of-memory + lpszPath = reinterpret_cast< LPCTSTR >((*corrected)->buffer); + lpComponent = lpszPath + i; + } + + fValid = IsValidFilePathComponent( lpComponent, &lpComponent, dwFlags ); + + if ( fValid && lpComponent ) + { + lpComponent++; + + /* If the string behind the backslash is empty, we've done */ + + if ( !*lpComponent ) + lpComponent = NULL; + } + } + + if ( fValid && _tcslen( lpszPath ) >= MAX_PATH ) + { + fValid = FALSE; + lpComponent = lpszPath + MAX_PATH; + } + + if ( lppError ) + *lppError = lpComponent; + + return fValid ? dwPathType : PATHTYPE_ERROR; +} + +//############################################# +//##################################################### +//Undocumented in SHELL32.DLL ordinal 35 +static BOOL PathRemoveFileSpec(LPTSTR lpPath) +{ + BOOL fSuccess = FALSE; // Assume failure + LPTSTR lpLastBkSlash = _tcsrchr( lpPath, '\\' ); + LPTSTR lpLastSlash = _tcsrchr( lpPath, '/' ); + LPTSTR lpLastDelimiter = lpLastSlash > lpLastBkSlash ? lpLastSlash : lpLastBkSlash; + + if ( lpLastDelimiter ) + { + if ( 0 == *(lpLastDelimiter + 1) ) + { + if ( lpLastDelimiter > lpPath && *(lpLastDelimiter - 1) != ':' ) + { + *lpLastDelimiter = 0; + fSuccess = TRUE; + } + } + else + { + *(++lpLastDelimiter) = 0; + fSuccess = TRUE; + } + } + return fSuccess; +} + +//##################################################### +// Undocumented in SHELL32.DLL ordinal 32 +static LPTSTR PathAddBackslash(LPTSTR lpPath) +{ + LPTSTR lpEndPath = NULL; + + if ( lpPath ) + { + int nLen = _tcslen(lpPath); + + if ( !nLen || lpPath[nLen-1] != '\\' && lpPath[nLen-1] != '/' && nLen < MAX_PATH - 1 ) + { + lpEndPath = lpPath + nLen; + *lpEndPath++ = '\\'; + *lpEndPath = 0; + } + } + return lpEndPath; +} + +//##################################################### +// Same as GetLongPathName but also 95/NT4 +static DWORD GetCaseCorrectPathNameEx( + LPCTSTR lpszShortPath, // file name + LPTSTR lpszLongPath, // path buffer + DWORD cchBuffer, // size of path buffer + DWORD nSkipLevels +) +{ + TCHAR szPath[MAX_PATH]; + BOOL fSuccess; + + cchBuffer = cchBuffer; /* avoid warnings */ + + _tcscpy( szPath, lpszShortPath ); + + fSuccess = PathRemoveFileSpec( szPath ); + + if ( fSuccess ) + { + int nLen = _tcslen( szPath ); + LPCTSTR lpszFileSpec = lpszShortPath + nLen; + BOOL bSkipThis; + + if ( 0 == _tcscmp( lpszFileSpec, TEXT("..") ) ) + { + bSkipThis = TRUE; + nSkipLevels += 1; + } + else if ( + 0 == _tcscmp( lpszFileSpec, TEXT(".") ) || + 0 == _tcscmp( lpszFileSpec, TEXT("\\") ) || + 0 == _tcscmp( lpszFileSpec, TEXT("/") ) + ) + { + bSkipThis = TRUE; + } + else if ( nSkipLevels ) + { + bSkipThis = TRUE; + nSkipLevels--; + } + else + bSkipThis = FALSE; + + GetCaseCorrectPathNameEx( szPath, szPath, MAX_PATH, nSkipLevels ); + + PathAddBackslash( szPath ); + + /* Analyze parent if not only a trailing backslash was cutted but a real file spec */ + if ( !bSkipThis ) + { + WIN32_FIND_DATA aFindFileData; + HANDLE hFind = FindFirstFile( lpszShortPath, &aFindFileData ); + + if ( IsValidHandle(hFind) ) + { + _tcscat( szPath, aFindFileData.cFileName[0] ? aFindFileData.cFileName : aFindFileData.cAlternateFileName ); + + FindClose( hFind ); + } + else + return 0; + } + } + else + { + /* File specification can't be removed therefore the short path is either a drive + or a network share. If still levels to skip are left, the path specification + tries to travel below the file system root */ + if ( nSkipLevels ) + return 0; + + _tcsupr( szPath ); + } + + _tcscpy( lpszLongPath, szPath ); + + return _tcslen( lpszLongPath ); +} + +//##################################################### +#define WSTR_SYSTEM_ROOT_PATH L"\\\\.\\" + +DWORD GetCaseCorrectPathName( + LPCTSTR lpszShortPath, // file name + LPTSTR lpszLongPath, // path buffer + DWORD cchBuffer // size of path buffer +) +{ + /* Special handling for "\\.\" as system root */ + if ( lpszShortPath && 0 == wcscmp( lpszShortPath, WSTR_SYSTEM_ROOT_PATH ) ) + { + if ( cchBuffer >= ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) ) + { + wcscpy( lpszLongPath, WSTR_SYSTEM_ROOT_PATH ); + return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; + } + else + { + return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; + } + } + else + { + return GetCaseCorrectPathNameEx( lpszShortPath, lpszLongPath, cchBuffer, 0 ); + } +} + +//############################################# +static sal_Bool _osl_decodeURL( rtl_String* strUTF8, rtl_uString** pstrDecodedURL ) +{ + sal_Char *pBuffer; + const sal_Char *pSrcEnd; + const sal_Char *pSrc; + sal_Char *pDest; + sal_Int32 nSrcLen; + sal_Bool bValidEncoded = sal_True; /* Assume success */ + + /* The resulting decoded string length is shorter or equal to the source length */ + + nSrcLen = rtl_string_getLength(strUTF8); + pBuffer = reinterpret_cast(rtl_allocateMemory(nSrcLen + 1)); + + pDest = pBuffer; + pSrc = rtl_string_getStr(strUTF8); + pSrcEnd = pSrc + nSrcLen; + + /* Now decode the URL what should result in an UTF8 string */ + while ( bValidEncoded && pSrc < pSrcEnd ) + { + switch ( *pSrc ) + { + case '%': + { + sal_Char aToken[3]; + sal_Char aChar; + + pSrc++; + aToken[0] = *pSrc++; + aToken[1] = *pSrc++; + aToken[2] = 0; + + aChar = (sal_Char)strtoul( aToken, NULL, 16 ); + + /* The chars are path delimiters and must not be encoded */ + + if ( 0 == aChar || '\\' == aChar || '/' == aChar || ':' == aChar ) + bValidEncoded = sal_False; + else + *pDest++ = aChar; + } + break; + default: + *pDest++ = *pSrc++; + break; + } + } + + *pDest++ = 0; + + if ( bValidEncoded ) + { + rtl_string2UString( pstrDecodedURL, pBuffer, rtl_str_getLength(pBuffer), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS ); + OSL_ASSERT(*pstrDecodedURL != 0); + } + + rtl_freeMemory( pBuffer ); + + return bValidEncoded; +} + +//############################################# +static void _osl_encodeURL( rtl_uString *strURL, rtl_String **pstrEncodedURL ) +{ + /* Encode non ascii characters within the URL */ + + rtl_String *strUTF8 = NULL; + sal_Char *pszEncodedURL; + const sal_Char *pURLScan; + sal_Char *pURLDest; + sal_Int32 nURLScanLen; + sal_Int32 nURLScanCount; + + rtl_uString2String( &strUTF8, rtl_uString_getStr( strURL ), rtl_uString_getLength( strURL ), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS ); + + pszEncodedURL = (sal_Char*) rtl_allocateMemory( (rtl_string_getLength( strUTF8 ) * 3 + 1) * sizeof(sal_Char) ); + + pURLDest = pszEncodedURL; + pURLScan = rtl_string_getStr( strUTF8 ); + nURLScanLen = rtl_string_getLength( strUTF8 ); + nURLScanCount = 0; + + while ( nURLScanCount < nURLScanLen ) + { + sal_Char cCurrent = *pURLScan; + switch ( cCurrent ) + { + default: + if (!( ( cCurrent >= 'a' && cCurrent <= 'z' ) || ( cCurrent >= 'A' && cCurrent <= 'Z' ) || ( cCurrent >= '0' && cCurrent <= '9' ) ) ) + { + sprintf( pURLDest, "%%%02X", (unsigned char)cCurrent ); + pURLDest += 3; + break; + } + case '!': + case '\'': + case '(': + case ')': + case '*': + case '-': + case '.': + case '_': + case '~': + case '$': + case '&': + case '+': + case ',': + case '=': + case '@': + case ':': + case '/': + case '\\': + case '|': + *pURLDest++ = cCurrent; + break; + case 0: + break; + } + + pURLScan++; + nURLScanCount++; + } + + *pURLDest = 0; + + rtl_string_release( strUTF8 ); + rtl_string_newFromStr( pstrEncodedURL, pszEncodedURL ); + rtl_freeMemory( pszEncodedURL ); +} + +//############################################# +#define WSTR_SYSTEM_ROOT_PATH L"\\\\.\\" + +oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **pustrPath, sal_Bool bAllowRelative ) +{ + rtl_String *strUTF8 = NULL; + rtl_uString *strDecodedURL = NULL; + rtl_uString *strTempPath = NULL; + const sal_Unicode *pDecodedURL; + sal_uInt32 nDecodedLen; + sal_Bool bValidEncoded; + oslFileError nError = osl_File_E_INVAL; /* Assume failure */ + + /* If someone hasn't encoded the complete URL we convert it to UTF8 now to prevent from + having a mixed encoded URL later */ + + rtl_uString2String( &strUTF8, rtl_uString_getStr( strURL ), rtl_uString_getLength( strURL ), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS ); + + /* If the length of strUTF8 and strURL differs it indicates that the URL was not correct encoded */ + + OSL_ENSURE_FILE( + strUTF8->length == strURL->length || + 0 != rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( strURL->buffer, strURL->length, "file:\\\\", 7 ) + ,"osl_getSystemPathFromFileURL: \"%s\" is not encoded !!!", strURL ); + + bValidEncoded = _osl_decodeURL( strUTF8, &strDecodedURL ); + + /* Release the encoded UTF8 string */ + rtl_string_release( strUTF8 ); + + if ( bValidEncoded ) + { + /* Replace backslashes and pipes */ + + rtl_uString_newReplace( &strDecodedURL, strDecodedURL, '/', '\\' ); + rtl_uString_newReplace( &strDecodedURL, strDecodedURL, '|', ':' ); + + pDecodedURL = rtl_uString_getStr( strDecodedURL ); + nDecodedLen = rtl_uString_getLength( strDecodedURL ); + + /* Must start with "file://" */ + if ( 0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL, nDecodedLen, "file:\\\\", 7 ) ) + { + sal_uInt32 nSkip; + + if ( 0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL, nDecodedLen, "file:\\\\\\", 8 ) ) + nSkip = 8; + else if ( + 0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL, nDecodedLen, "file:\\\\localhost\\", 17 ) || + 0 == rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL, nDecodedLen, "file:\\\\127.0.0.1\\", 17 ) + ) + nSkip = 17; + else + nSkip = 5; + + /* Indicates local root */ + if ( nDecodedLen == nSkip ) + rtl_uString_newFromStr_WithLength( &strTempPath, reinterpret_cast(WSTR_SYSTEM_ROOT_PATH), ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1 ); + else + rtl_uString_newFromStr_WithLength( &strTempPath, pDecodedURL + nSkip, nDecodedLen - nSkip ); + + if ( IsValidFilePath( strTempPath, NULL, VALIDATEPATH_ALLOW_ELLIPSE, &strTempPath ) ) + nError = osl_File_E_None; + } + else if ( bAllowRelative ) /* This maybe a relative file URL */ + { + rtl_uString_assign( &strTempPath, strDecodedURL ); + + if ( IsValidFilePath( strTempPath, NULL, VALIDATEPATH_ALLOW_RELATIVE | VALIDATEPATH_ALLOW_ELLIPSE, &strTempPath ) ) + nError = osl_File_E_None; + } + /* + else + OSL_ENSURE_FILE( !nError, "osl_getSystemPathFromFileURL: \"%s\" is not an absolute FileURL !!!", strURL ); + */ + + } + + if ( strDecodedURL ) + rtl_uString_release( strDecodedURL ); + + if ( osl_File_E_None == nError ) + rtl_uString_assign( pustrPath, strTempPath ); + + if ( strTempPath ) + rtl_uString_release( strTempPath ); + + /* + OSL_ENSURE_FILE( !nError, "osl_getSystemPathFromFileURL: \"%s\" is not a FileURL !!!", strURL ); + */ + + return nError; +} + +//############################################# +oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString** pstrURL ) +{ + oslFileError nError = osl_File_E_INVAL; /* Assume failure */ + rtl_uString *strTempURL = NULL; + DWORD dwPathType = PATHTYPE_ERROR; + + if (strPath) + dwPathType = IsValidFilePath(strPath, NULL, VALIDATEPATH_ALLOW_RELATIVE, NULL); + + if (dwPathType) + { + rtl_uString *strTempPath = NULL; + + /* Replace backslashes */ + rtl_uString_newReplace( &strTempPath, strPath, '\\', '/' ); + + switch ( dwPathType & PATHTYPE_MASK_TYPE ) + { + case PATHTYPE_RELATIVE: + rtl_uString_assign( &strTempURL, strTempPath ); + nError = osl_File_E_None; + break; + case PATHTYPE_ABSOLUTE_UNC: + rtl_uString_newFromAscii( &strTempURL, "file:" ); + rtl_uString_newConcat( &strTempURL, strTempURL, strTempPath ); + nError = osl_File_E_None; + break; + case PATHTYPE_ABSOLUTE_LOCAL: + rtl_uString_newFromAscii( &strTempURL, "file:///" ); + rtl_uString_newConcat( &strTempURL, strTempURL, strTempPath ); + nError = osl_File_E_None; + break; + default: + break; + } + + /* Release temp path */ + rtl_uString_release( strTempPath ); + } + + if ( osl_File_E_None == nError ) + { + rtl_String *strEncodedURL = NULL; + + /* Encode the URL */ + _osl_encodeURL( strTempURL, &strEncodedURL ); + + /* Provide URL via unicode string */ + rtl_string2UString( pstrURL, rtl_string_getStr(strEncodedURL), rtl_string_getLength(strEncodedURL), RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS ); + OSL_ASSERT(*pstrURL != 0); + rtl_string_release( strEncodedURL ); + } + + /* Release temp URL */ + if ( strTempURL ) + rtl_uString_release( strTempURL ); + + /* + OSL_ENSURE_FILE( !nError, "osl_getFileURLFromSystemPath: \"%s\" is not a systemPath !!!", strPath ); + */ + return nError; +} + +//##################################################### +oslFileError SAL_CALL osl_getFileURLFromSystemPath( + rtl_uString* ustrPath, rtl_uString** pustrURL ) +{ + return _osl_getFileURLFromSystemPath( ustrPath, pustrURL ); +} + +//##################################################### +oslFileError SAL_CALL osl_getSystemPathFromFileURL( + rtl_uString *ustrURL, rtl_uString **pustrPath) +{ + return _osl_getSystemPathFromFileURL( ustrURL, pustrPath, sal_True ); +} + +//##################################################### +oslFileError SAL_CALL osl_searchFileURL( + rtl_uString *ustrFileName, + rtl_uString *ustrSystemSearchPath, + rtl_uString **pustrPath) +{ + rtl_uString *ustrUNCPath = NULL; + rtl_uString *ustrSysPath = NULL; + oslFileError error; + + /* First try to interpret the file name as an URL even a relative one */ + error = _osl_getSystemPathFromFileURL( ustrFileName, &ustrUNCPath, sal_True ); + + /* So far we either have an UNC path or something invalid + Now create a system path */ + if ( osl_File_E_None == error ) + error = _osl_getSystemPathFromFileURL( ustrUNCPath, &ustrSysPath, sal_True ); + + if ( osl_File_E_None == error ) + { + DWORD nBufferLength; + DWORD dwResult; + LPTSTR lpBuffer = NULL; + LPTSTR lpszFilePart; + + /* Repeat calling SearchPath ... + Start with MAX_PATH for the buffer. In most cases this + will be enough and does not force the loop to runtwice */ + dwResult = MAX_PATH; + + do + { + /* If search path is empty use a NULL pointer instead according to MSDN documentation of SearchPath */ + LPCTSTR lpszSearchPath = ustrSystemSearchPath && ustrSystemSearchPath->length ? reinterpret_cast(ustrSystemSearchPath->buffer) : NULL; + LPCTSTR lpszSearchFile = reinterpret_cast(ustrSysPath->buffer); + + /* Allocate space for buffer according to previous returned count of required chars */ + /* +1 is not neccessary if we follow MSDN documentation but for robustness we do so */ + nBufferLength = dwResult + 1; + lpBuffer = lpBuffer ? + reinterpret_cast(rtl_reallocateMemory(lpBuffer, nBufferLength * sizeof(TCHAR))) : + reinterpret_cast(rtl_allocateMemory(nBufferLength * sizeof(TCHAR))); + + dwResult = SearchPath( lpszSearchPath, lpszSearchFile, NULL, nBufferLength, lpBuffer, &lpszFilePart ); + } while ( dwResult && dwResult >= nBufferLength ); + + /* ... until an error occures or buffer is large enough. + dwResult == nBufferLength can not happen according to documentation but lets be robust ;-) */ + + if ( dwResult ) + { + rtl_uString_newFromStr( &ustrSysPath, reinterpret_cast(lpBuffer) ); + error = osl_getFileURLFromSystemPath( ustrSysPath, pustrPath ); + } + else + { + WIN32_FIND_DATA aFindFileData; + HANDLE hFind; + + /* Somthing went wrong, perhaps the path was absolute */ + error = oslTranslateFileError( GetLastError() ); + + hFind = FindFirstFile( reinterpret_cast(ustrSysPath->buffer), &aFindFileData ); + + if ( IsValidHandle(hFind) ) + { + error = osl_getFileURLFromSystemPath( ustrSysPath, pustrPath ); + FindClose( hFind ); + } + } + + rtl_freeMemory( lpBuffer ); + } + + if ( ustrSysPath ) + rtl_uString_release( ustrSysPath ); + + if ( ustrUNCPath ) + rtl_uString_release( ustrUNCPath ); + + return error; +} + +//##################################################### + +oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uString* ustrRelativeURL, rtl_uString** pustrAbsoluteURL ) +{ + oslFileError eError; + rtl_uString *ustrRelSysPath = NULL; + rtl_uString *ustrBaseSysPath = NULL; + + if ( ustrBaseURL && ustrBaseURL->length ) + { + eError = _osl_getSystemPathFromFileURL( ustrBaseURL, &ustrBaseSysPath, sal_False ); + OSL_ENSURE( osl_File_E_None == eError, "osl_getAbsoluteFileURL called with relative or invalid base URL" ); + + eError = _osl_getSystemPathFromFileURL( ustrRelativeURL, &ustrRelSysPath, sal_True ); + } + else + { + eError = _osl_getSystemPathFromFileURL( ustrRelativeURL, &ustrRelSysPath, sal_False ); + OSL_ENSURE( osl_File_E_None == eError, "osl_getAbsoluteFileURL called with empty base URL and/or invalid relative URL" ); + } + + if ( !eError ) + { + TCHAR szBuffer[MAX_PATH]; + TCHAR szCurrentDir[MAX_PATH]; + LPTSTR lpFilePart = NULL; + DWORD dwResult; + +/*@@@ToDo + Bad, bad hack, this only works if the base path + really exists which is not necessary according + to RFC2396 + The whole FileURL implementation should be merged + with the rtl/uri class. +*/ + if ( ustrBaseSysPath ) + { + osl_acquireMutex( g_CurrentDirectoryMutex ); + + GetCurrentDirectory( MAX_PATH, szCurrentDir ); + SetCurrentDirectory( reinterpret_cast(ustrBaseSysPath->buffer) ); + } + + dwResult = GetFullPathName( reinterpret_cast(ustrRelSysPath->buffer), MAX_PATH, szBuffer, &lpFilePart ); + + if ( ustrBaseSysPath ) + { + SetCurrentDirectory( szCurrentDir ); + + osl_releaseMutex( g_CurrentDirectoryMutex ); + } + + if ( dwResult ) + { + if ( dwResult >= MAX_PATH ) + eError = osl_File_E_INVAL; + else + { + rtl_uString *ustrAbsSysPath = NULL; + + rtl_uString_newFromStr( &ustrAbsSysPath, reinterpret_cast(szBuffer) ); + + eError = osl_getFileURLFromSystemPath( ustrAbsSysPath, pustrAbsoluteURL ); + + if ( ustrAbsSysPath ) + rtl_uString_release( ustrAbsSysPath ); + } + } + else + eError = oslTranslateFileError( GetLastError() ); + } + + if ( ustrBaseSysPath ) + rtl_uString_release( ustrBaseSysPath ); + + if ( ustrRelSysPath ) + rtl_uString_release( ustrRelSysPath ); + + return eError; +} + +//##################################################### +oslFileError SAL_CALL osl_getCanonicalName( rtl_uString *strRequested, rtl_uString **strValid ) +{ + rtl_uString_newFromString(strValid, strRequested); + return osl_File_E_None; +} diff --git a/sal/osl/w32/file_url.h b/sal/osl/w32/file_url.h new file mode 100644 index 000000000000..af23203fa0a7 --- /dev/null +++ b/sal/osl/w32/file_url.h @@ -0,0 +1,95 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: file_url.h,v $ + * $Revision: 1.0 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_OSL_FILE_URL_H +#define INCLUDED_OSL_FILE_URL_H + +#include "sal/types.h" +#include "rtl/ustring.h" +#include "osl/file.h" + +#ifdef _MSC_VER +#pragma warning(push,1) +#endif + +#define WINDOWS_LEAN_AND_MEAN +#include + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define PATHTYPE_ERROR 0 +#define PATHTYPE_RELATIVE 1 +#define PATHTYPE_ABSOLUTE_UNC 2 +#define PATHTYPE_ABSOLUTE_LOCAL 3 +#define PATHTYPE_MASK_TYPE 0xFF +#define PATHTYPE_IS_VOLUME 0x0100 +#define PATHTYPE_IS_SERVER 0x0200 + +#define VALIDATEPATH_NORMAL 0x0000 +#define VALIDATEPATH_ALLOW_WILDCARDS 0x0001 +#define VALIDATEPATH_ALLOW_ELLIPSE 0x0002 +#define VALIDATEPATH_ALLOW_RELATIVE 0x0004 +#define VALIDATEPATH_ALLOW_UNC 0x0008 + +DWORD IsValidFilePath ( + rtl_uString * path, + LPCTSTR * lppError, + DWORD dwFlags, + rtl_uString ** corrected +); + +DWORD GetCaseCorrectPathName ( + LPCTSTR lpszShortPath, // file name + LPTSTR lpszLongPath, // path buffer + DWORD cchBuffer // size of path buffer +); + +oslFileError _osl_getSystemPathFromFileURL ( + rtl_uString * strURL, + rtl_uString ** pustrPath, + sal_Bool bAllowRelative +); + +oslFileError _osl_getFileURLFromSystemPath ( + rtl_uString * strPath, + rtl_uString ** pstrURL +); + +#ifdef __cplusplus +} +#endif + +#endif /* INCLUDED_OSL_FILE_URL_H */ diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx index 512cd3551f47..379caeb5affc 100644 --- a/sal/osl/w32/procimpl.cxx +++ b/sal/osl/w32/procimpl.cxx @@ -59,7 +59,7 @@ #include //################################################# -extern "C" oslFileHandle SAL_CALL osl_createFileHandleFromOSHandle( HANDLE hFile ); +extern "C" oslFileHandle SAL_CALL osl_createFileHandleFromOSHandle( HANDLE hFile, sal_uInt32 uFlags ); //################################################# const sal_Unicode NAME_VALUE_SEPARATOR = TEXT('='); @@ -576,13 +576,13 @@ oslProcessError SAL_CALL osl_executeProcess_WithRedirectedIO( WaitForSingleObject(pProcImpl->m_hProcess, INFINITE); if (pProcessInputWrite) - *pProcessInputWrite = osl_createFileHandleFromOSHandle(hInputWrite); + *pProcessInputWrite = osl_createFileHandleFromOSHandle(hInputWrite, osl_File_OpenFlag_Write); if (pProcessOutputRead) - *pProcessOutputRead = osl_createFileHandleFromOSHandle(hOutputRead); + *pProcessOutputRead = osl_createFileHandleFromOSHandle(hOutputRead, osl_File_OpenFlag_Read); if (pProcessErrorRead) - *pProcessErrorRead = osl_createFileHandleFromOSHandle(hErrorRead); + *pProcessErrorRead = osl_createFileHandleFromOSHandle(hErrorRead, osl_File_OpenFlag_Read); return osl_Process_E_None; } diff --git a/sal/osl/w32/tempfile.cxx b/sal/osl/w32/tempfile.cxx new file mode 100644 index 000000000000..6c591eae8972 --- /dev/null +++ b/sal/osl/w32/tempfile.cxx @@ -0,0 +1,279 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: file.cxx,v $ + * $Revision: 1.0 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#define UNICODE +#define _UNICODE +#define _WIN32_WINNT_0x0500 +#include "systools/win32/uwinapi.h" + +#include "osl/file.h" + +#include "file_error.h" +#include "file_url.h" + +#include "osl/diagnose.h" + +#include +#include + +//##################################################### +#define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0]))) + +// Allocate n number of t's on the stack return a pointer to it in p +#ifdef __MINGW32__ +#define STACK_ALLOC(p, t, n) (p) = reinterpret_cast(_alloca((n)*sizeof(t))); +#else +#define STACK_ALLOC(p, t, n) __try {(p) = reinterpret_cast(_alloca((n)*sizeof(t)));} \ + __except(EXCEPTION_EXECUTE_HANDLER) {(p) = 0;} +#endif + +extern "C" oslFileHandle SAL_CALL osl_createFileHandleFromOSHandle(HANDLE hFile, sal_uInt32 uFlags); + +//##################################################### +// Temp file functions +//##################################################### + +static oslFileError osl_setup_base_directory_impl_( + rtl_uString* pustrDirectoryURL, + rtl_uString** ppustr_base_dir) +{ + rtl_uString* dir_url = 0; + rtl_uString* dir = 0; + oslFileError error = osl_File_E_None; + + if (pustrDirectoryURL) + rtl_uString_assign(&dir_url, pustrDirectoryURL); + else + error = osl_getTempDirURL(&dir_url); + + if (osl_File_E_None == error) + { + error = _osl_getSystemPathFromFileURL(dir_url, &dir, sal_False); + rtl_uString_release(dir_url); + } + + if (osl_File_E_None == error ) + { + rtl_uString_assign(ppustr_base_dir, dir); + rtl_uString_release(dir); + } + + return error; +} + +//##################################################### +static oslFileError osl_setup_createTempFile_impl_( + rtl_uString* pustrDirectoryURL, + oslFileHandle* pHandle, + rtl_uString** ppustrTempFileURL, + rtl_uString** ppustr_base_dir, + sal_Bool* b_delete_on_close) +{ + oslFileError osl_error; + + OSL_PRECOND(((0 != pHandle) || (0 != ppustrTempFileURL)), "Invalid parameter!"); + + if ((0 == pHandle) && (0 == ppustrTempFileURL)) + { + osl_error = osl_File_E_INVAL; + } + else + { + osl_error = osl_setup_base_directory_impl_( + pustrDirectoryURL, ppustr_base_dir); + + *b_delete_on_close = (sal_Bool)(0 == ppustrTempFileURL); + } + + return osl_error; +} + +//##################################################### +static oslFileError osl_win32_GetTempFileName_impl_( + rtl_uString* base_directory, LPWSTR temp_file_name) +{ + oslFileError osl_error = osl_File_E_None; + + if (0 == GetTempFileNameW( + reinterpret_cast(rtl_uString_getStr(base_directory)), + L"", + 0, + temp_file_name)) + { + osl_error = oslTranslateFileError(GetLastError()); + } + + return osl_error; +} + +//##################################################### +static sal_Bool osl_win32_CreateFile_impl_( + LPCWSTR file_name, sal_Bool b_delete_on_close, oslFileHandle* p_handle) +{ + DWORD flags = FILE_ATTRIBUTE_NORMAL; + HANDLE hFile; + + OSL_ASSERT(p_handle); + + if (b_delete_on_close) + flags |= FILE_FLAG_DELETE_ON_CLOSE; + + hFile = CreateFileW( + file_name, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + TRUNCATE_EXISTING, + flags, + NULL); + + // @@@ ERROR HANDLING @@@ + if (IsValidHandle(hFile)) + *p_handle = osl_createFileHandleFromOSHandle(hFile, osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); + + return (sal_Bool)IsValidHandle(hFile); +} + +//############################################# +static oslFileError osl_createTempFile_impl_( + rtl_uString* base_directory, + LPWSTR tmp_name, + sal_Bool b_delete_on_close, + oslFileHandle* pHandle, + rtl_uString** ppustrTempFileURL) +{ + oslFileError osl_error; + + do + { + osl_error = osl_win32_GetTempFileName_impl_(base_directory, tmp_name); + + /* if file could not be opened try again */ + + if ((osl_File_E_None != osl_error) || (0 == pHandle) || + osl_win32_CreateFile_impl_(tmp_name, b_delete_on_close, pHandle)) + break; + + } while(1); // try until success + + if ((osl_File_E_None == osl_error) && !b_delete_on_close) + { + rtl_uString* pustr = 0; + rtl_uString_newFromStr(&pustr, reinterpret_cast(tmp_name)); + osl_getFileURLFromSystemPath(pustr, ppustrTempFileURL); + rtl_uString_release(pustr); + } + + return osl_error; +} + +//############################################# +oslFileError SAL_CALL osl_createTempFile( + rtl_uString* pustrDirectoryURL, + oslFileHandle* pHandle, + rtl_uString** ppustrTempFileURL) +{ + rtl_uString* base_directory = 0; + LPWSTR tmp_name; + sal_Bool b_delete_on_close; + oslFileError osl_error; + + osl_error = osl_setup_createTempFile_impl_( + pustrDirectoryURL, + pHandle, + ppustrTempFileURL, + &base_directory, + &b_delete_on_close); + + if (osl_File_E_None != osl_error) + return osl_error; + + /* allocate enough space on the stack */ + STACK_ALLOC(tmp_name, WCHAR, (rtl_uString_getLength(base_directory) + MAX_PATH)); + + if (tmp_name) + { + osl_createTempFile_impl_( + base_directory, + tmp_name, + b_delete_on_close, + pHandle, + ppustrTempFileURL); + } + else // stack alloc failed + { + osl_error = osl_File_E_NOMEM; + } + + if (base_directory) + rtl_uString_release(base_directory); + + return osl_error; +} + +//############################################# +oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) +{ + WCHAR szBuffer[MAX_PATH]; + LPWSTR lpBuffer = szBuffer; + DWORD nBufferLength = ELEMENTS_OF_ARRAY(szBuffer) - 1; + + DWORD nLength; + oslFileError error; + + do + { + nLength = GetTempPathW( ELEMENTS_OF_ARRAY(szBuffer), lpBuffer ); + if ( nLength > nBufferLength ) + { + nLength++; + lpBuffer = reinterpret_cast(alloca( sizeof(WCHAR) * nLength )); + nBufferLength = nLength - 1; + } + } while ( nLength > nBufferLength ); + + if ( nLength ) + { + rtl_uString *ustrTempPath = NULL; + + if ( '\\' == lpBuffer[nLength-1] ) + lpBuffer[nLength-1] = 0; + + rtl_uString_newFromStr( &ustrTempPath, reinterpret_cast(lpBuffer) ); + + error = osl_getFileURLFromSystemPath( ustrTempPath, pustrTempDir ); + + rtl_uString_release( ustrTempPath ); + } + else + error = oslTranslateFileError( GetLastError() ); + + return error; +} diff --git a/sal/workben/makefile.mk b/sal/workben/makefile.mk index 05afbbb223ea..5f20dd07bd4a 100644 --- a/sal/workben/makefile.mk +++ b/sal/workben/makefile.mk @@ -35,9 +35,10 @@ PRJNAME=sal TARGET=workben LIBTARGET=NO TARGETTYPE=CUI -ENABLE_EXCEPTIONS=TRUE +#ENABLE_EXCEPTIONS=TRUE +NO_DEFAULT_STL=YES -TESTAPP=test_osl_getVolInfo +#TESTAPP=test_osl_getVolInfo #TESTAPP=test_osl_joinProcess #TESTAPP=getlocaleinfotest #TESTAPP=test_osl_joinProcess @@ -45,6 +46,7 @@ TESTAPP=test_osl_getVolInfo #TESTAPP=salstattest #TESTAPP=saldyntest +TESTAPP=t_readline #TESTAPP=t_cipher #TESTAPP=t_digest #TESTAPP=t_random @@ -173,6 +175,23 @@ DEF1EXPORTFILE=export.exp .ENDIF # salstattest +# +# t_readline +# +.IF "$(TESTAPP)" == "t_readline" + +CFILES= t_readline.c +OBJFILES= $(OBJ)$/t_readline.obj + +APP1TARGET= t_readline +APP1OBJS= $(OBJFILES) +APP1STDLIBS=$(SALLIB) +APP1DEPN= $(SLB)$/sal.lib + +APP1RPATH=UREBIN + +.ENDIF # t_readline + # # t_cipher # diff --git a/sal/workben/t_layer.c b/sal/workben/t_layer.c deleted file mode 100644 index 5ceeb7ce21e3..000000000000 --- a/sal/workben/t_layer.c +++ /dev/null @@ -1,314 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: t_layer.c,v $ - * $Revision: 1.6 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include -#include -#include -#include -#ifndef _OSL_ISOCKET_H_ -#include -#endif - -/*======================================================================== - * - * osl/debug.c - * - *======================================================================*/ -/* - * __osl_debug_create. - */ -static oslSocketResult SAL_CALL __osl_debug_create ( - oslSocketDescriptor *socket, - oslAddrFamily family, - oslSocketType type, - oslProtocol protocol) -{ - oslSocketResult result; - - if (!(socket->m_lower)) - { - oslSocketDescriptor *lower; - lower = osl_socket_createSocketLayer (osl_socket_getSocketMethods()); - osl_socket_pushSocketLayer (socket, lower); - } - - result = (socket->m_lower->m_methods->m_create)( - socket->m_lower, family, type, protocol); - if (!(result == osl_Socket_Ok)) - return (result); - - if (!(socket->m_private)) - { - /* ... */ - } - return (osl_Socket_Ok); -} - -/* - * __osl_debug_delete. - */ -static void SAL_CALL __osl_debug_delete (oslSocketDescriptor *socket) -{ - if (socket->m_private) - { - /* ... */ - } - if (socket->m_lower) - { - (socket->m_lower->m_methods->m_delete)(socket->m_lower); - osl_socket_deleteSocketLayer (socket->m_lower); - } -} - -/* - * __osl_debug_getOption. - */ -static oslSocketResult SAL_CALL __osl_debug_getOption ( - oslSocketDescriptor *socket, - oslSocketOptionLevel level, - oslSocketOption option, - void *buffer, - sal_uInt32 length) -{ - if (level == osl_Socket_LevelSocketLayer) - { - /* ... */ - return (osl_Socket_Ok); - } - - return (socket->m_lower->m_methods->m_getoption)( - socket->m_lower, level, option, buffer, length); -} - -/* - * __osl_debug_setOption. - */ -static oslSocketResult SAL_CALL __osl_debug_setOption ( - oslSocketDescriptor *socket, - oslSocketOptionLevel level, - oslSocketOption option, - const void *buffer, - sal_uInt32 length) -{ - if (level == osl_Socket_LevelSocketLayer) - { - /* ... */ - return (osl_Socket_Ok); - } - - return (socket->m_lower->m_methods->m_setoption)( - socket->m_lower, level, option, buffer, length); -} - -/* - * __osl_debug_accept. - */ -static oslSocketDescriptor* SAL_CALL __osl_debug_accept ( - oslSocketDescriptor *socket, oslSocketAddr *fromaddr) -{ - oslSocketDescriptor *lower; - lower = (socket->m_lower->m_methods->m_accept)(socket->m_lower, fromaddr); - if (lower) - { - oslSocketDescriptor *upper; - upper = osl_socket_createSocketLayer (socket->m_methods); - osl_socket_pushSocketLayer (upper, lower); - return (upper); - } - return ((oslSocketDescriptor*)NULL); -} - -/* - * __osl_debug_connect. - */ -static oslSocketResult SAL_CALL __osl_debug_connect ( - oslSocketDescriptor *socket, oslSocketAddr addr) -{ - return (socket->m_lower->m_methods->m_connect)(socket->m_lower, addr); -} - -/* - * __osl_debug_close. - */ -static void SAL_CALL __osl_debug_close (oslSocketDescriptor *socket) -{ - (socket->m_lower->m_methods->m_close)(socket->m_lower); -} - -/* - * __osl_shutdown. - */ -static void SAL_CALL __osl_debug_shutdown ( - oslSocketDescriptor *socket, oslSocketDirection direction) -{ - (socket->m_lower->m_methods->m_shutdown)(socket->m_lower, direction); -} - -/* - * __osl_debug_methods. - */ -static oslSocketMethods __osl_debug_methods = -{ - NULL /* initialized on demand */ -}; - -/* - * osl_debug_getSocketMethods. - */ -const oslSocketMethods* SAL_CALL osl_debug_getSocketMethods (void) -{ - static oslInterlockedCount nonce = 0; - if (osl_incrementInterlockedCount (&nonce) == 1) - { - const oslSocketMethods *methods = osl_socket_getDefaultSocketMethods(); - __osl_debug_methods = *methods; - - __osl_debug_methods.m_create = __osl_debug_create; - __osl_debug_methods.m_delete = __osl_debug_delete; - - __osl_debug_methods.m_getoption = __osl_debug_getOption; - __osl_debug_methods.m_setoption = __osl_debug_setOption; - - __osl_debug_methods.m_accept = __osl_debug_accept; - __osl_debug_methods.m_connect = __osl_debug_connect; - __osl_debug_methods.m_close = __osl_debug_close; - - __osl_debug_methods.m_shutdown = __osl_debug_shutdown; - - osl_incrementInterlockedCount (&nonce); - } - - osl_decrementInterlockedCount (&nonce); - return (&__osl_debug_methods); -} - -/*======================================================================== - * - * osl/socket.c (physical, bottom layer). - * - *======================================================================*/ -#if 0 /* NYI */ - -static oslSocketResult SAL_CALL __osl_socket_create ( - oslSocketDescriptor *socket, - oslAddrFamily family, - oslSocketType type, - oslProtocol protocol) -{ -#if OSL_DEBUG_LEVEL > 1 - const oslSocketMethods *debug = osl_debug_getSocketMethods(); - if (!(socket->m_upper || socket->m_upper->m_methods == debug)) - { - oslSocketDescriptor *upper; - - upper = osl_socket_createSocketLayer (debug); - osl_socket_pushSocketLayer (upper, socket); - - return (upper->m_methods->m_create)(upper, family, type, protocol); - } -#endif /* OSL_DEBUG_LEVEL */ - if (!(socket->m_private)) - { - /* ... */ - socket->m_private = osl_createSocket (family, type, protocol); - } - return (osl_Socket_Ok); -} - -#endif /* NYI */ - -/*======================================================================== - * - * main. - * - *======================================================================*/ -int SAL_CALL main (int argc, char **argv) -{ - oslSocketDescriptor *socket; - - socket = osl_socket_createSocketLayer (osl_debug_getSocketMethods()); - if (socket) - { - oslSocketDescriptor *connection; - oslSocketResult result; - oslSocketAddr addr, from; - sal_Int32 option = 1; - - result = osl_socket_create ( - socket, - osl_Socket_FamilyInet, - osl_Socket_TypeStream, - osl_Socket_ProtocolIp); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_setOption ( - socket, - osl_Socket_LevelSocket, - osl_Socket_OptionReuseAddr, - &option, sizeof(option)); - OSL_ASSERT(result == osl_Socket_Ok); - - addr = osl_createEmptySocketAddr (osl_Socket_FamilyInet); - osl_setInetPortOfSocketAddr (addr, 7777); - - result = osl_socket_bind (socket, addr); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_listen (socket, 1); - OSL_ASSERT(result == osl_Socket_Ok); - - connection = osl_socket_accept (socket, &from); - if (connection) - { - sal_Char buffer[1024]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - - while ((k = osl_socket_recv (connection, buffer, n, flag)) > 0) - { - if (osl_socket_send (connection, buffer, k, flag) < 0) - break; - } - - osl_socket_close (connection); - osl_socket_delete (connection); - - osl_socket_deleteSocketLayer (connection); - } - - osl_socket_close (socket); - osl_socket_delete (socket); - - osl_socket_deleteSocketLayer (socket); - } - - return 0; -} - diff --git a/sal/workben/t_readline.c b/sal/workben/t_readline.c new file mode 100644 index 000000000000..9cbc7d39cf20 --- /dev/null +++ b/sal/workben/t_readline.c @@ -0,0 +1,58 @@ +/* + * t_readline.c + */ + +#include "osl/file.h" + +#include "osl/diagnose.h" +#include "rtl/ustring.h" +#include "rtl/byteseq.h" + +#include + +/* main */ +int main (int argc, char ** argv) +{ + if (argc > 1) + { + oslFileError result; + oslFileHandle hFile = 0; + + rtl_uString * pSystemPath = 0; + rtl_uString * pFileUrl = 0; + + rtl_uString_newFromAscii (&pSystemPath, argv[1]); + + result = osl_getFileURLFromSystemPath (pSystemPath, &pFileUrl); + rtl_uString_release (pSystemPath), pSystemPath = 0; + if (result != osl_File_E_None) + return (result); + + result = osl_openFile (pFileUrl, &hFile, osl_File_OpenFlag_Read); + rtl_uString_release (pFileUrl), pFileUrl = 0; + if (result == osl_File_E_None) + { + sal_Sequence * pBuffer = 0; + for ( ;; ) + { + sal_Int32 i, n; + + result = osl_readLine (hFile, &pBuffer); + if (result != osl_File_E_None) + break; +#if 0 + if (pBuffer->elements[0] == 0) + /* @@@ cannot distinguish empty line from EOF @@@ */ + break; +#endif + for (i = 0, n = pBuffer->nElements; i < n; i++) + printf ("%c", (char)(pBuffer->elements[i])); + printf("\n"); + } + + rtl_byte_sequence_release (pBuffer), pBuffer = 0; + (void) osl_closeFile (hFile); + } + } + return 0; +} diff --git a/sal/workben/t_tls.c b/sal/workben/t_tls.c deleted file mode 100644 index 2f82bee0a11f..000000000000 --- a/sal/workben/t_tls.c +++ /dev/null @@ -1,257 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: t_tls.c,v $ - * $Revision: 1.5 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include -#include -#include -#include -#include -#include -#ifndef _OSL_ISOCKET_H_ -#include -#endif - -#ifndef _OSL_TLS_H_ -#include -#endif - -#include -#include - -/*======================================================================== - * - * Internals. - * - *======================================================================*/ -void SAL_CALL __rtl_sequence_release (sal_Sequence *value) -{ - if (value) - { - if (osl_decrementInterlockedCount (&(value->nRefCount)) == 0) - rtl_freeMemory (value); - } -} - -void SAL_CALL __rtl_sequence_new (sal_Sequence **value, sal_Int32 length) -{ - if (value) - { - __rtl_sequence_release (*value); - - *value = (sal_Sequence*)rtl_allocateMemory ( - SAL_SEQUENCE_HEADER_SIZE + length); - - (*value)->nRefCount = 1; - (*value)->nElements = 0; - } -} - -void load_sequence (sal_Sequence **ppSequence, const sal_Char *name) -{ - oslFileError result; - rtl_uString *pName, *pPath; - - if (ppSequence) - { - __rtl_sequence_release (*ppSequence); - *ppSequence = NULL; - } - - pName = NULL; - rtl_uString_newFromAscii (&pName, name); - - pPath = NULL; - result = osl_searchNormalizedPath (pName, NULL, &pPath); - if (result == osl_File_E_None) - { - oslFileHandle hFile; - - result = osl_openFile (pPath, &hFile, osl_File_OpenFlag_Read); - if (result == osl_File_E_None) - { - sal_uInt64 nSize = 0, nRead = 0; - - osl_setFilePos (hFile, osl_Pos_End, 0); - osl_getFilePos (hFile, &nSize); - osl_setFilePos (hFile, osl_Pos_Absolut, 0); - - __rtl_sequence_new (ppSequence, (sal_Int32)nSize); - - osl_readFile (hFile, (*ppSequence)->elements, nSize, &nRead); - (*ppSequence)->nElements = (sal_Int32)nRead; - } - osl_closeFile (hFile); - - rtl_uString_release (pPath); - } - - rtl_uString_release (pName); -} - -/*======================================================================== - * - * main. - * - *======================================================================*/ -int SAL_CALL main (int argc, char **argv) -{ - static const sal_Char p[] = "GET / HTTP/1.0\015\012\015\012"; - oslSocketDescriptor *socket; - - - socket = osl_socket_createSocketLayer (osl_tls_getSocketMethods()); - if (socket) - { - oslSocketAddr target; - oslSocketResult result; - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - rtl_uString *dotted = NULL; - - - rtl_uString_newFromAscii (&dotted, argv[1]); - target = osl_createInetSocketAddr (dotted, 443); - rtl_uString_release (dotted); - - result = osl_socket_create ( - socket, - osl_Socket_FamilyInet, - osl_Socket_TypeStream, - osl_Socket_ProtocolIp); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_connect (socket, target); - osl_destroySocketAddr (target); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_connect_handshake (socket, target); - OSL_ASSERT(result == osl_Socket_Ok); - - if (osl_socket_send (socket, p, strlen(p), flag) > 0) - { - sal_Char buffer[1024]; - sal_Int32 k, n = sizeof(buffer); - - while ((k = osl_socket_recv (socket, buffer, n, flag)) > 0) - fwrite (buffer, 1, k, stdout); - } - - osl_socket_shutdown (socket, osl_Socket_DirReadWrite); - osl_socket_close (socket); - - osl_socket_delete (socket); - osl_socket_deleteSocketLayer (socket); - } - - - socket = osl_socket_createSocketLayer (osl_tls_getSocketMethods()); - if (socket) - { - oslSocketDescriptor *connection; - oslSocketResult result; - oslSocketAddr addr, from; - sal_Int32 option = 1; - sal_Sequence *data = NULL; - - - result = osl_socket_create ( - socket, - osl_Socket_FamilyInet, - osl_Socket_TypeStream, - osl_Socket_ProtocolIp); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_setOption ( - socket, - osl_Socket_LevelSocket, - osl_Socket_OptionReuseAddr, - &option, sizeof(option)); - OSL_ASSERT(result == osl_Socket_Ok); - - addr = osl_createEmptySocketAddr (osl_Socket_FamilyInet); - osl_setInetPortOfSocketAddr (addr, 7777); - - result = osl_socket_bind (socket, addr); - OSL_ASSERT(result == osl_Socket_Ok); - - load_sequence (&data, "s_cert.der"); - if (data && data->nElements) - { - result = osl_socket_setOption ( - socket, - osl_Socket_LevelTLS, - osl_Socket_OptionCertificate, - data->elements, data->nElements); - OSL_ASSERT(result == osl_Socket_Ok); - } - - load_sequence (&data, "s_pkey.der"); - if (data && data->nElements) - { - result = osl_socket_setOption ( - socket, - osl_Socket_LevelTLS, - osl_Socket_OptionPrivateKey, - data->elements, data->nElements); - OSL_ASSERT(result == osl_Socket_Ok); - } - __rtl_sequence_release (data); - - result = osl_socket_listen (socket, 1); - OSL_ASSERT(result == osl_Socket_Ok); - - connection = osl_socket_accept (socket, &from); - if (connection) - { - sal_Char buffer[1024]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - - result = osl_socket_accept_handshake (connection, from); - OSL_ASSERT(result == osl_Socket_Ok); - - while ((k = osl_socket_recv (connection, buffer, n, flag)) > 0) - { - if (osl_socket_send (connection, buffer, k, flag) < 0) - break; - } - - osl_socket_close (connection); - - osl_socket_delete (connection); - osl_socket_deleteSocketLayer (connection); - } - - osl_socket_delete (socket); - osl_socket_deleteSocketLayer (socket); - } - - return 0; -} - diff --git a/sal/workben/t_zip.c b/sal/workben/t_zip.c deleted file mode 100644 index 42bb819f0256..000000000000 --- a/sal/workben/t_zip.c +++ /dev/null @@ -1,183 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: t_zip.c,v $ - * $Revision: 1.5 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include -#include -#include -#include -#ifndef _OSL_ZSOCKET_H_ -#include -#endif - -#include - -/*======================================================================== - * - * internals. - * - *======================================================================*/ -void SAL_CALL clientSocketReader (void *pData) -{ - oslSocketDescriptor *socket; - - socket = (oslSocketDescriptor*)pData; - if (socket) - { - sal_Char buffer[128]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - - while ((k = osl_socket_recv (socket, buffer, n, flag)) > 0) - { - fwrite (buffer, 1, k, stdout); - fflush (stdout); - } - } -} - -/*======================================================================== - * - * main. - * - *======================================================================*/ -int SAL_CALL main (int argc, char **argv) -{ - oslSocketDescriptor *socket; - - socket = osl_socket_createSocketLayer (osl_zlib_getSocketMethods()); - if (socket) - { - oslSocketAddr addr = 0; - oslSocketResult result; - - result = osl_socket_create ( - socket, - osl_Socket_FamilyInet, - osl_Socket_TypeStream, - osl_Socket_ProtocolIp); - OSL_ASSERT(result == osl_Socket_Ok); - - if (argc > 1) - { - rtl_uString *host = 0; - - rtl_uString_newFromAscii (&host, argv[1]); - addr = osl_resolveHostname (host); - rtl_uString_release (host); - } - - if (addr) - { - sal_Char buffer[128]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - oslThread reader; - - osl_setInetPortOfSocketAddr (addr, 7777); - - result = osl_socket_connect (socket, addr); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_connect_handshake (socket, addr); - osl_destroySocketAddr (addr); - OSL_ASSERT(result == osl_Socket_Ok); - - reader = osl_createSuspendedThread (clientSocketReader, socket); - OSL_ASSERT(reader); - osl_resumeThread (reader); - - while ((k = fread (buffer, 1, n, stdin)) > 0) - { - if (osl_socket_send (socket, buffer, k, flag) < 0) - break; - } - - osl_socket_shutdown (socket, osl_Socket_DirReadWrite); - osl_socket_close (socket); - - osl_joinWithThread (reader); - osl_destroyThread (reader); - } - else - { - oslSocketDescriptor *connection; - oslSocketAddr from = 0; - sal_Int32 option = 1; - - addr = osl_createEmptySocketAddr (osl_Socket_FamilyInet); - osl_setInetPortOfSocketAddr (addr, 7777); - - result = osl_socket_setOption ( - socket, - osl_Socket_LevelSocket, - osl_Socket_OptionReuseAddr, - &option, sizeof(option)); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_bind (socket, addr); - osl_destroySocketAddr (addr); - OSL_ASSERT(result == osl_Socket_Ok); - - result = osl_socket_listen (socket, 1); - OSL_ASSERT(result == osl_Socket_Ok); - - connection = osl_socket_accept (socket, &from); - if (connection) - { - sal_Char buffer[64]; - sal_Int32 k, n = sizeof(buffer); - oslSocketMsgFlag flag = osl_Socket_MsgNormal; - - result = osl_socket_accept_handshake (connection, from); - osl_destroySocketAddr (from); - OSL_ASSERT(result == osl_Socket_Ok); - - while ((k = osl_socket_recv (connection, buffer, n, flag)) > 0) - { - if (osl_socket_send (connection, buffer, k, flag) < 0) - break; - } - - osl_socket_close (connection); - - osl_socket_delete (connection); - osl_socket_deleteSocketLayer (connection); - } - - osl_socket_close (socket); - } - - osl_socket_delete (socket); - osl_socket_deleteSocketLayer (socket); - } - - return 0; -} - diff --git a/store/source/lockbyte.cxx b/store/source/lockbyte.cxx index a38aa768908d..a03628bfb740 100644 --- a/store/source/lockbyte.cxx +++ b/store/source/lockbyte.cxx @@ -297,7 +297,7 @@ struct FileHandle if (result == osl_File_E_EXIST) { // Already existing (O_CREAT | O_EXCL). - result = osl_openFile (aFileUrl.pData, &m_handle, osl_File_OpenFlag_Write); + result = osl_openFile (aFileUrl.pData, &m_handle, osl_File_OpenFlag_Read | osl_File_OpenFlag_Write); if ((result == osl_File_E_None) && (eAccessMode == store_AccessCreate)) { // Truncate existing file. diff --git a/store/workben/makefile.mk b/store/workben/makefile.mk index 334585710522..4b58d26409a0 100644 --- a/store/workben/makefile.mk +++ b/store/workben/makefile.mk @@ -93,11 +93,12 @@ APP3STDLIBS= $(STOREDBGLIB) APP3STDLIBS+= $(SALLIB) APP3DEPN= $(STOREDBGLIB) - APP4TARGET= t_store - APP4OBJS= $(OBJ)$/t_store.obj - APP4STDLIBS= $(STORELIB) - APP4STDLIBS+= $(SALLIB) - APP4DEPN= $(SLB)$/store.lib +APP4TARGET= t_store +APP4OBJS= $(OBJ)$/t_store.obj +APP4STDLIBS= $(STORELIB) +APP4STDLIBS+= $(SALLIB) +APP4DEPN= $(SLB)$/store.lib +APP4RPATH= UREBIN APP5TARGET= t_leak APP5OBJS= $(OBJ)$/t_leak.obj -- cgit From 49749239ca71441a4a3b404771617e4c8d2a0886 Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Thu, 10 Sep 2009 22:38:33 +0000 Subject: CWS-TOOLING: integrate CWS mingwport23 2009-08-29 07:07:53 +0200 tono r275555 : i#104522: mingw port graphite 2009-08-29 07:07:26 +0200 tono r275554 : i#104522: mingw port printf format fix --- sal/inc/sal/types.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sal/inc/sal/types.h b/sal/inc/sal/types.h index 23c7529eed26..eec07286f2c5 100644 --- a/sal/inc/sal/types.h +++ b/sal/inc/sal/types.h @@ -124,10 +124,17 @@ typedef unsigned char sal_uInt8; #define SAL_CONST_INT64(x) x##ll #define SAL_CONST_UINT64(x) x##ull + #ifdef __MINGW32__ + #define SAL_PRIdINT64 "I64d" + #define SAL_PRIuUINT64 "I64u" + #define SAL_PRIxUINT64 "I64x" + #define SAL_PRIXUINT64 "I64X" + #else #define SAL_PRIdINT64 "lld" #define SAL_PRIuUINT64 "llu" #define SAL_PRIxUINT64 "llx" #define SAL_PRIXUINT64 "llX" + #endif #else #error "Could not find 64-bit type, add support for your architecture" #endif @@ -170,7 +177,7 @@ typedef void * sal_Handle; /* printf-style conversion specification length modifiers for size_t and ptrdiff_t (most platforms support C99, MSC has its own extension) */ -#if defined _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) #define SAL_PRI_SIZET "I" #define SAL_PRI_PTRDIFFT "I" #else -- cgit From cf6a1e41bcf4b7ab7c5ddc948683efe4ee5a680d Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Thu, 10 Sep 2009 22:44:47 +0000 Subject: CWS-TOOLING: integrate CWS os2port06dev300 2009-09-05 22:49:00 +0200 ydario r275858 : #i99588# applied os2port06 diff to DEV300 tree. --- bridges/source/cpp_uno/gcc3_os2_intel/cpp2uno.cxx | 3 +- .../OpenOfficeorg/javavendors_os2.xml | 4 +- jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx | 6 +- jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx | 2 - jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 5 + pyuno/prj/d.lst | 1 + pyuno/source/module/makefile.mk | 3 + sal/osl/os2/debug.c | 47 +- sal/osl/os2/except.c | 44 +- sal/osl/os2/helpers/debug.h | 42 +- sal/osl/os2/helpers/dosh.h | 927 +-------------------- sal/osl/os2/helpers/except.h | 42 +- sal/osl/os2/helpers/setup.h | 32 + sal/osl/os2/module.c | 2 +- sal/osl/os2/process.c | 10 +- ure/source/makefile.mk | 2 +- xml2cmp/source/xcd/filebuff.cxx | 4 - 17 files changed, 225 insertions(+), 951 deletions(-) diff --git a/bridges/source/cpp_uno/gcc3_os2_intel/cpp2uno.cxx b/bridges/source/cpp_uno/gcc3_os2_intel/cpp2uno.cxx index d4584227cdc1..d6589b8d86cf 100644 --- a/bridges/source/cpp_uno/gcc3_os2_intel/cpp2uno.cxx +++ b/bridges/source/cpp_uno/gcc3_os2_intel/cpp2uno.cxx @@ -163,7 +163,8 @@ static typelib_TypeClass cpp2uno_call( (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc ); #if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, ">cpp2uno_call pUnoExc %x\n", pUnoExc); + if (pUnoExc != NULL) + fprintf( stderr, ">cpp2uno_call pUnoExc %x\n", pUnoExc); #endif // in case an exception occured... diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors_os2.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_os2.xml index 372254d4ee71..2de585472b86 100644 --- a/jvmfwk/distributions/OpenOfficeorg/javavendors_os2.xml +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_os2.xml @@ -7,10 +7,10 @@ - 1.5.0 + 1.4.2 - 1.5.0 + 1.4.2 diff --git a/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx index c80d1c091571..b59a30f887d2 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx @@ -65,11 +65,15 @@ char const* const* OtherInfo::getJavaExePaths(int * size) char const* const* OtherInfo::getRuntimePaths(int * size) { static char const* ar[]= { -#if defined(WNT) || defined(OS2) +#if defined(WNT) "/bin/client/jvm.dll", "/bin/hotspot/jvm.dll", "/bin/classic/jvm.dll", "/bin/jrockit/jvm.dll" +#elif defined(OS2) + "/bin/classic/jvm.dll", + "/bin/client/jvm.dll", + "/bin/hotspot/jvm.dll" #elif UNX #ifdef MACOSX "/../../../JavaVM" diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx index fec7d0b60136..247c5092ab44 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx @@ -74,8 +74,6 @@ char const* const* SunInfo::getRuntimePaths(int * size) "/bin/classic/jvm.dll" #elif defined(OS2) "/bin/classic/jvm.dll", - "/bin/client/jvm.dll", - "/bin/hotspot/jvm.dll" #elif UNX "/lib/" JFW_PLUGIN_ARCH "/client/libjvm.so", "/lib/" JFW_PLUGIN_ARCH "/server/libjvm.so", diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx index 57b7166d01f6..a823d551af88 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx @@ -65,6 +65,7 @@ using namespace rtl; using namespace osl; using namespace std; +#define CHAR_POINTER(oustr) ::rtl::OUStringToOString(oustr,RTL_TEXTENCODING_UTF8).pData->buffer #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) #ifdef WNT #define HKEY_SUN_JRE L"Software\\JavaSoft\\Java Runtime Environment" @@ -449,7 +450,11 @@ bool getJavaProps(const OUString & exePath, rs = stdoutReader.readLine( & aLine); if (rs != FileHandleReader::RESULT_OK) break; + JFW_TRACE2(OString("[Java framework] line:\" ") + + aLine + OString(" \".\n")); OUString sLine = decodeOutput(aLine); + JFW_TRACE2(OString("[Java framework] line:\" ") + + OString( CHAR_POINTER(sLine)) + OString(" \".\n")); sLine = sLine.trim(); if (sLine.getLength() == 0) continue; diff --git a/pyuno/prj/d.lst b/pyuno/prj/d.lst index 16631ada6fbd..5fe7400a8d58 100644 --- a/pyuno/prj/d.lst +++ b/pyuno/prj/d.lst @@ -16,6 +16,7 @@ mkdir: %_DEST%\lib%_EXT%\pyuno ..\%__SRC%\bin\uno.py %_DEST%\bin%_EXT%\pyuno\uno.py ..\%__SRC%\bin\pyuno_services.rdb %_DEST%\bin%_EXT%\pyuno_services.rdb ..\%__SRC%\bin\pyuno.pyd %_DEST%\bin%_EXT%\pyuno.pyd +..\%__SRC%\bin\pyuno.dll %_DEST%\bin%_EXT%\pyuno.dll ..\%__SRC%\bin\pythonl*.dll %_DEST%\bin%_EXT%\pythonl*.dll ..\%__SRC%\misc\pyunorc %_DEST%\lib%_EXT%\pyunorc diff --git a/pyuno/source/module/makefile.mk b/pyuno/source/module/makefile.mk index 94de195e750f..cb1ef41f0784 100644 --- a/pyuno/source/module/makefile.mk +++ b/pyuno/source/module/makefile.mk @@ -56,6 +56,9 @@ EXTRA_FRAMEWORK_FLAG=-framework Python # pyuno.so even on Mac OS X, because it is a python module PYUNO_MODULE=$(DLLDEST)$/pyuno.so PYUNORC=pyunorc +.ELIF "$(GUI)" == "OS2" +.INCLUDE : pyversion.mk +PYUNORC=pyuno.ini .ELSE .INCLUDE : pyversion.mk PYUNORC=pyuno.ini diff --git a/sal/osl/os2/debug.c b/sal/osl/os2/debug.c index 67fc7a1e709f..78a2df07056e 100644 --- a/sal/osl/os2/debug.c +++ b/sal/osl/os2/debug.c @@ -1,3 +1,33 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile:$ + * $Revision:$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + /* *@@sourcefile debug.c: * this file contains debugging functions for the @@ -27,20 +57,15 @@ */ /* - * This file Copyright (C) 1992-99 Ulrich M”ller, + * This file Copyright (C) 1992-99 Ulrich M�ller, * Kim Rasmussen, * Marc Fiammante, * John Currier, * Anthony Cruise. * This file is part of the "XWorkplace helpers" source package. - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation, in version 2 as it comes in the - * "COPYING" file of the XWorkplace main distribution. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * + * 2009-06-15 published under LGPL3 with Ulrich M�ller permission. + * */ //#define DEBUG_SYMDUMP // enable to dump sym file to log @@ -1484,7 +1509,7 @@ void dbgPrintVariables(FILE *LogFile, // in: text log file to write to (PVOID)stackofs, func_name); fprintf(LogFile, " Offset Name Type Value \n"); - fprintf(LogFile, " ÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n"); + fprintf(LogFile, " ������ �������������������� ��������������������������������� �����������������\n"); } // If it's one of the simple types @@ -1880,7 +1905,7 @@ VOID dbgPrintStack(FILE *LogFile, // in: text log file to write to fprintf(LogFile, "\n\nCall stack:\n"); fprintf(LogFile, " Source Line Nearest\n"); fprintf(LogFile, " EBP Address Module Obj# File Numbr Public Symbol\n"); - fprintf(LogFile, " ÄÄÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄ- ÄÄÄÄÄÄÄÄ ÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄ ÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄ-\n"); + fprintf(LogFile, " �������� ��������- �������� ���� ������������ ����� ������������-\n"); do { diff --git a/sal/osl/os2/except.c b/sal/osl/os2/except.c index e1ae9fb7bd06..0dd2a35d1fcd 100644 --- a/sal/osl/os2/except.c +++ b/sal/osl/os2/except.c @@ -1,3 +1,32 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile:$ + * $Revision:$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ /* *@@sourcefile except.c: @@ -178,7 +207,7 @@ * exception handling DLL, available at Hobbes). * * If not explicitly stated otherwise, the code has been written - * by me, Ulrich M”ller. + * by me, Ulrich M�ller. * * Note: Version numbering in this file relates to XWorkplace version * numbering. @@ -187,7 +216,7 @@ */ /* - * This file Copyright (C) 1992-99 Ulrich M”ller, + * This file Copyright (C) 1992-99 Ulrich M�ller, * Monte Copeland, * Roman Stangl, * Kim Rasmussen, @@ -195,14 +224,9 @@ * John Currier, * Anthony Cruise. * This file is part of the "XWorkplace helpers" source package. - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation, in version 2 as it comes in the - * "COPYING" file of the XWorkplace main distribution. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * + * 2009-06-15 published under LGPL3 with Ulrich M�ller permission. + * */ #define OS2EMX_PLAIN_CHAR diff --git a/sal/osl/os2/helpers/debug.h b/sal/osl/os2/helpers/debug.h index be35be3d3326..b03508b70379 100644 --- a/sal/osl/os2/helpers/debug.h +++ b/sal/osl/os2/helpers/debug.h @@ -1,3 +1,32 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile:$ + * $Revision:$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ /* *@@sourcefile debug.h: @@ -21,19 +50,14 @@ * Anthony Cruise (EXCEPT3.ZIP package for a generic * exception handling DLL, available at Hobbes). * - * This file Copyright (C) 1992-99 Ulrich M”ller, + * This file Copyright (C) 1992-99 Ulrich M�ller, * Kim Rasmussen, * Marc Fiammante, * John Currier, * Anthony Cruise. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, in version 2 as it comes in the COPYING - * file of the XFolder main distribution. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * + * 2009-06-15 published under LGPL3 with Ulrich M�ller permission. + * */ #ifndef DEBUG_HEADER_INCLUDED diff --git a/sal/osl/os2/helpers/dosh.h b/sal/osl/os2/helpers/dosh.h index d2e936a57447..518f979fd4de 100644 --- a/sal/osl/os2/helpers/dosh.h +++ b/sal/osl/os2/helpers/dosh.h @@ -1,28 +1,39 @@ - -/* - *@@sourcefile dosh.h: - * header file for dosh.c. See remarks there. +/************************************************************************* * - * Note: Version numbering in this file relates to XWorkplace version - * numbering. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - *@@include #define INCL_DOSPROCESS - *@@include #define INCL_DOSDEVIOCTL // for doshQueryDiskParams only - *@@include #include - *@@include #include "helpers\dosh.h" - */ + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile:$ + * $Revision:$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ -/* This file Copyright (C) 1997-2001 Ulrich M”ller, +/* This file Copyright (C) 1997-2006 Ulrich M�ller, * Dmitry A. Steklenev. * This file is part of the "XWorkplace helpers" source package. - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation, in version 2 as it comes in the - * "COPYING" file of the XWorkplace main distribution. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * + * 2009-06-15 published under LGPL3 with Ulrich M�ller permission. + * */ #if __cplusplus @@ -32,886 +43,10 @@ extern "C" { #ifndef DOSH_HEADER_INCLUDED #define DOSH_HEADER_INCLUDED - /* ****************************************************************** - * - * Wrappers - * - ********************************************************************/ - - // if DOSH_STANDARDWRAPPERS is #define'd before including dosh.h, - // all the following Dos* API calls are redirected to the dosh* - // counterparts - - #ifdef DOSH_STANDARDWRAPPERS - - #ifdef INCL_DOSPROCESS - - APIRET XWPENTRY doshSleep(ULONG msec); - #define DosSleep(a) doshSleep((a)) - - #endif - - #ifdef INCL_DOSSEMAPHORES - - APIRET XWPENTRY doshCreateMutexSem(PSZ pszName, - PHMTX phmtx, - ULONG flAttr, - BOOL32 fState); - #define DosCreateMutexSem(a, b, c, d) doshCreateMutexSem((a), (b), (c), (d)) - - APIRET XWPENTRY doshRequestMutexSem(HMTX hmtx, ULONG ulTimeout); - #define DosRequestMutexSem(h, t) doshRequestMutexSem((h), (t)) - - APIRET XWPENTRY doshReleaseMutexSem(HMTX hmtx); - #define DosReleaseMutexSem(h) doshReleaseMutexSem((h)) - - #endif - - #ifdef INCL_DOSEXCEPTIONS - - APIRET XWPENTRY doshSetExceptionHandler(PEXCEPTIONREGISTRATIONRECORD pERegRec); - #define DosSetExceptionHandler(a) doshSetExceptionHandler((a)) - - APIRET XWPENTRY doshUnsetExceptionHandler(PEXCEPTIONREGISTRATIONRECORD pERegRec); - #define DosUnsetExceptionHandler(a) doshUnsetExceptionHandler((a)) - - #endif - - #endif - - /* ****************************************************************** - * - * Miscellaneous - * - ********************************************************************/ - - CHAR doshGetChar(VOID); - - BOOL doshQueryShiftState(VOID); - - ULONG doshIsWarp4(VOID); - - PSZ doshQuerySysErrorMsg(APIRET arc); - - ULONG doshQuerySysUptime(VOID); - - /* ****************************************************************** - * - * Memory helpers - * - ********************************************************************/ - - PVOID doshMalloc(ULONG cb, - APIRET *parc); - - APIRET doshAllocArray(ULONG c, - ULONG cbArrayItem, - PBYTE *ppv, - PULONG pcbAllocated); - - PVOID doshAllocSharedMem(ULONG ulSize, - const char* pcszName); - - PVOID doshRequestSharedMem(PCSZ pcszName); - - /* ****************************************************************** - * - * Drive helpers - * - ********************************************************************/ - - APIRET doshIsFixedDisk(ULONG ulLogicalDrive, - PBOOL pfFixed); - - #ifdef INCL_DOSDEVIOCTL - - // #pragma pack(1) - - /* - * DRIVEPARAMS: - * structure used for doshQueryDiskParams. - * removed this, we can directly use BIOSPARAMETERBLOCK - * V0.9.13 (2001-06-14) [umoeller] - */ - - /* typedef struct _DRIVEPARAMS - { - BIOSPARAMETERBLOCK bpb; - // BIOS parameter block. This is the first sector - // (at byte 0) in each partition. This is defined - // in the OS2 headers as follows: - - typedef struct _BIOSPARAMETERBLOCK { - 0 USHORT usBytesPerSector; - // Number of bytes per sector. - 2 BYTE bSectorsPerCluster; - // Number of sectors per cluster. - 3 USHORT usReservedSectors; - // Number of reserved sectors. - 5 BYTE cFATs; - // Number of FATs. - 6 USHORT cRootEntries; - // Number of root directory entries. - 8 USHORT cSectors; - // Number of sectors. - 10 BYTE bMedia; - // Media descriptor. - 11 USHORT usSectorsPerFAT; - // Number of secctors per FAT. - 13 USHORT usSectorsPerTrack; - // Number of sectors per track. - 15 USHORT cHeads; - // Number of heads. - 17 ULONG cHiddenSectors; - // Number of hidden sectors. - 21 ULONG cLargeSectors; - // Number of large sectors. - 25 BYTE abReserved[6]; - // Reserved. - 31 USHORT cCylinders; - // Number of cylinders defined for the physical - // device. - 33 BYTE bDeviceType; - // Physical layout of the specified device. - 34 USHORT fsDeviceAttr; - // A bit field that returns flag information - // about the specified drive. - } BIOSPARAMETERBLOCK; - - // removed the following fields... these are already - // in the extended BPB structure, as defined in the - // Toolkit's BIOSPARAMETERBLOCK struct. Checked this, - // the definition is the same for the Toolkit 3 and 4.5. - - USHORT usCylinders; - // no. of cylinders - UCHAR ucDeviceType; - // device type; according to the IBM Control - // Program Reference (see DSK_GETDEVICEPARAMS), - // this value can be: - // -- 0: 48 TPI low-density diskette drive - // -- 1: 96 TPI high-density diskette drive - // -- 2: 3.5-inch 720KB diskette drive - // -- 3: 8-Inch single-density diskette drive - // -- 4: 8-Inch double-density diskette drive - // -- 5: Fixed disk - // -- 6: Tape drive - // -- 7: Other (includes 1.44MB 3.5-inch diskette drive - // and CD-ROMs) - // -- 8: R/W optical disk - // -- 9: 3.5-inch 4.0MB diskette drive (2.88MB formatted) - USHORT usDeviceAttrs; - // DEVATTR_* flags - } DRIVEPARAMS, *PDRIVEPARAMS; - #pragma pack() */ - - APIRET doshQueryDiskParams(ULONG ulLogicalDrive, - PBIOSPARAMETERBLOCK pdp); - - BYTE doshQueryDriveType(ULONG ulLogicalDrive, - PBIOSPARAMETERBLOCK pdp, - BOOL fFixed); - - APIRET XWPENTRY doshHasAudioCD(ULONG ulLogicalDrive, - HFILE hfDrive, - BOOL fMixedModeCD, - PBOOL pfAudio); - - #endif - - VOID XWPENTRY doshEnumDrives(PSZ pszBuffer, - PCSZ pcszFileSystem, - BOOL fSkipRemoveables); - typedef VOID XWPENTRY DOSHENUMDRIVES(PSZ pszBuffer, - PCSZ pcszFileSystem, - BOOL fSkipRemoveables); - typedef DOSHENUMDRIVES *PDOSHENUMDRIVES; - CHAR doshQueryBootDrive(VOID); - #define ERROR_AUDIO_CD_ROM 10000 - - #define DRVFL_MIXEDMODECD 0x0001 - #define DRVFL_TOUCHFLOPPIES 0x0002 - #define DRVFL_CHECKEAS 0x0004 - #define DRVFL_CHECKLONGNAMES 0x0008 - - APIRET doshAssertDrive(ULONG ulLogicalDrive, - ULONG fl); - - #ifdef INCL_DOSDEVIOCTL - - /* - *@@ XDISKINFO: - * - *@@added V0.9.16 (2002-01-13) [umoeller] - */ - - typedef struct _XDISKINFO - { - CHAR cDriveLetter; // drive letter - CHAR cLogicalDrive; // logical drive no. - - BOOL fPresent; // if FALSE, drive does not exist - - // the following are only valid if fPresent == TRUE - - BIOSPARAMETERBLOCK bpb; - // 0x00 USHORT usBytesPerSector; - // 0x02 BYTE bSectorsPerCluster; - // 0x03 USHORT usReservedSectors; - // 0x05 BYTE cFATs; - // 0x06 USHORT cRootEntries; - // 0x08 USHORT cSectors; - // 0x0a BYTE bMedia; - // 0x0b USHORT usSectorsPerFAT; - // 0x0d USHORT usSectorsPerTrack; - // 0x0f USHORT cHeads; - // 0x11 ULONG cHiddenSectors; - // 0x15 ULONG cLargeSectors; - // 0x19 BYTE abReserved[6]; - // 0x1a USHORT cCylinders; - // 0x1c BYTE bDeviceType; - #ifndef DEVTYPE_48TPI - #define DEVTYPE_48TPI 0x0000 - #define DEVTYPE_96TPI 0x0001 - #define DEVTYPE_35 0x0002 - #define DEVTYPE_8SD 0x0003 - #define DEVTYPE_8DD 0x0004 - #define DEVTYPE_FIXED 0x0005 - #define DEVTYPE_TAPE 0x0006 - #endif - #define DEVTYPE_OTHER 0x0007 - // includes 1.44 3.5" floppy - #define DEVTYPE_RWOPTICAL 0x0008 - #define DEVTYPE_35_288MB 0x0009 - // 0x1d USHORT fsDeviceAttr; - #define DEVATTR_REMOVEABLE 0x0001 - // drive is removeable - #define DEVATTR_CHANGELINE 0x0002 - // device can determine whether media has - // been removed since last I/O operation - #define DEVATTR_GREATER16MB 0x0004 - // physical device driver supports physical - // addresses > 16 MB - #define DEVATTR_PARTITIONALREMOVEABLE 0x0008 - // undocumented flag; set for ZIP drives - - BYTE bType; - // do not change these codes, XWorkplace relies - // on them too to parse WPDisk data - #define DRVTYPE_HARDDISK 0 - #define DRVTYPE_FLOPPY 1 - #define DRVTYPE_TAPE 2 - #define DRVTYPE_VDISK 3 - #define DRVTYPE_CDROM 4 - #define DRVTYPE_LAN 5 - #define DRVTYPE_PARTITIONABLEREMOVEABLE 6 - #define DRVTYPE_UNKNOWN 255 - - ULONG flDevice; - // any combination of the following: - #define DFL_REMOTE 0x0001 - // drive is remote (not local) - #define DFL_FIXED 0x0002 - // drive is fixed; otherwise it is removeable! - // always set for harddisks and zip drives - #define DFL_PARTITIONABLEREMOVEABLE 0x0004 - // set for zip drives; - // in that case, DFL_FIXED is set also - #define DFL_BOOTDRIVE 0x0008 - // drive was booted from - - // media flags: - - #define DFL_MEDIA_PRESENT 0x1000 - // media is present in drive; - // -- always set for harddisks, - // unless the file system is not - // understood - // -- always set for remove drives - // -- always set for A: and B: - // -- set for CD-ROMS only if data - // CD-ROM is inserted - #define DFL_AUDIO_CD 0x2000 - // set for CD-ROMs only, if an audio CD - // is currently inserted; in that case, - // DFL_MEDIA_PRESENT is _not_ set - #define DFL_SUPPORTS_EAS 0x4000 - // drive supports extended attributes - // (assumption based on DosFSCtl, - // might not be correct for remote drives; - // reports correctly for FAT32 though) - #define DFL_SUPPORTS_LONGNAMES 0x8000 - // drive supports long names; this does not - // necessarily mean that we support all IFS - // characters also - - // the following are only valid if DFL_MEDIA_PRESENT is set; - // they are always set for drives A: and B: - - CHAR szFileSystem[30]; - // e.g. "FAT" or "HPFS" or "JFS" or "CDFS" - - LONG lFileSystem; - // do not change these codes, XWorkplace relies - // on them too to parse WPDisk data - #define FSYS_UNKNOWN 0 - // drive not formatted, or unknown file system - #define FSYS_FAT 1 - #define FSYS_HPFS_JFS 2 - #define FSYS_CDFS 3 - #define FSYS_CDWFS 6 // not used by WPS! - // added V0.9.19 (2002-04-25) [umoeller] - #define FSYS_TVFS 7 // not used by WPS! - #define FSYS_FAT32_EXT2 8 // not used by WPS! - #define FSYS_RAMFS 9 // not used by WPS! - #define FSYS_REMOTE 10 - // NOTE: if this has a negative value, this is - // the APIRET code from DosQueryFSAttach - - // error codes for various operations - APIRET arcIsFixedDisk, - arcQueryDiskParams, - arcQueryMedia, - arcOpenLongnames; - - } XDISKINFO, *PXDISKINFO; - - APIRET doshGetDriveInfo(ULONG ulLogicalDrive, - ULONG fl, - PXDISKINFO pdi); - - #endif - - APIRET doshSetLogicalMap(ULONG ulLogicalDrive); - - APIRET XWPENTRY doshQueryDiskSize(ULONG ulLogicalDrive, double *pdSize); - typedef APIRET XWPENTRY DOSHQUERYDISKSIZE(ULONG ulLogicalDrive, double *pdSize); - typedef DOSHQUERYDISKSIZE *PDOSHQUERYDISKSIZE; - - APIRET XWPENTRY doshQueryDiskFree(ULONG ulLogicalDrive, double *pdFree); - typedef APIRET XWPENTRY DOSHQUERYDISKFREE(ULONG ulLogicalDrive, double *pdFree); - typedef DOSHQUERYDISKFREE *PDOSHQUERYDISKFREE; - - APIRET XWPENTRY doshQueryDiskFSType(ULONG ulLogicalDrive, PSZ pszBuf, ULONG cbBuf); - typedef APIRET XWPENTRY DOSHQUERYDISKFSTYPE(ULONG ulLogicalDrive, PSZ pszBuf, ULONG cbBuf); - typedef DOSHQUERYDISKFSTYPE *PDOSHQUERYDISKFSTYPE; - - APIRET doshQueryDiskLabel(ULONG ulLogicalDrive, - PSZ pszVolumeLabel); - - APIRET doshSetDiskLabel(ULONG ulLogicalDrive, - PSZ pszNewLabel); - - /* ****************************************************************** - * - * Module handling helpers - * - ********************************************************************/ - - APIRET doshQueryProcAddr(PCSZ pcszModuleName, - ULONG ulOrdinal, - PFN *ppfn); - - /* - *@@ RESOLVEFUNCTION: - * one of these structures each define - * a single function import to doshResolveImports. - * - *@@added V0.9.3 (2000-04-25) [umoeller] - */ - - typedef struct _RESOLVEFUNCTION - { - const char *pcszFunctionName; - PFN *ppFuncAddress; - } RESOLVEFUNCTION, *PRESOLVEFUNCTION; - - typedef const struct _RESOLVEFUNCTION *PCRESOLVEFUNCTION; - - APIRET doshResolveImports(PCSZ pcszModuleName, - HMODULE *phmod, - PCRESOLVEFUNCTION paResolves, - ULONG cResolves); - - /* ****************************************************************** - * - * Performance Counters (CPU Load) - * - ********************************************************************/ - - #define CMD_PERF_INFO 0x41 - #define CMD_KI_ENABLE 0x60 - #define CMD_KI_DISABLE 0x61 - #ifndef CMD_KI_RDCNT - #define CMD_KI_RDCNT 0x63 - typedef APIRET APIENTRY FNDOSPERFSYSCALL(ULONG ulCommand, - ULONG ulParm1, - ULONG ulParm2, - ULONG ulParm3); - typedef FNDOSPERFSYSCALL *PFNDOSPERFSYSCALL; - #endif - - typedef struct _CPUUTIL - { - ULONG ulTimeLow; // low 32 bits of time stamp - ULONG ulTimeHigh; // high 32 bits of time stamp - ULONG ulIdleLow; // low 32 bits of idle time - ULONG ulIdleHigh; // high 32 bits of idle time - ULONG ulBusyLow; // low 32 bits of busy time - ULONG ulBusyHigh; // high 32 bits of busy time - ULONG ulIntrLow; // low 32 bits of interrupt time - ULONG ulIntrHigh; // high 32 bits of interrupt time - } CPUUTIL, *PCPUUTIL; - - // macro to convert 8-byte (low, high) time value to double - #define LL2F(high, low) (4294967296.0*(high)+(low)) - - /* - *@@ DOSHPERFSYS: - * structure used with doshPerfOpen. - * - *@@added V0.9.7 (2000-12-02) [umoeller] - *@@changed V0.9.9 (2001-03-14) [umoeller]: added interrupt load - */ - - typedef struct _DOSHPERFSYS - { - // output: no. of processors on the system - ULONG cProcessors; - // output: one CPU load for each CPU - PLONG palLoads; - - // output: one CPU interrupt load for each CPU - PLONG palIntrs; - - // each of the following ptrs points to an array of cProcessors items - PCPUUTIL paCPUUtils; // CPUUTIL structures - double *padBusyPrev; // previous "busy" calculations - double *padTimePrev; // previous "time" calculations - double *padIntrPrev; // previous "intr" calculations - - // private stuff - HMODULE hmod; - BOOL fInitialized; - PFNDOSPERFSYSCALL pDosPerfSysCall; - } DOSHPERFSYS, *PDOSHPERFSYS; - - APIRET doshPerfOpen(PDOSHPERFSYS *ppPerfSys); - - APIRET doshPerfGet(PDOSHPERFSYS pPerfSys); - - APIRET doshPerfClose(PDOSHPERFSYS *ppPerfSys); - - /* ****************************************************************** - * - * File name parsing - * - ********************************************************************/ - - APIRET doshGetDriveSpec(PCSZ pcszFullFile, - PSZ pszDrive, - PULONG pulDriveLen, - PBOOL pfIsUNC); - - PSZ doshGetExtension(PCSZ pcszFilename); - - /* ****************************************************************** - * - * File helpers - * - ********************************************************************/ - - BOOL doshIsFileOnFAT(const char* pcszFileName); - - APIRET doshIsValidFileName(const char* pcszFile, - BOOL fFullyQualified); - - BOOL doshMakeRealName(PSZ pszTarget, PSZ pszSource, CHAR cReplace, BOOL fIsFAT); - - APIRET doshQueryFileSize(HFILE hFile, - PULONG pulSize); - - APIRET doshQueryPathSize(PCSZ pcszFile, - PULONG pulSize); - - APIRET doshQueryPathAttr(const char* pcszFile, - PULONG pulAttr); - - APIRET doshSetPathAttr(const char* pcszFile, - ULONG ulAttr); - - /* ****************************************************************** - * - * XFILEs - * - ********************************************************************/ - - /* - *@@ XFILE: - * - *@@added V0.9.16 (2001-10-19) [umoeller] - */ - - typedef struct _XFILE - { - HFILE hf; - - PSZ pszFilename; // as given to doshOpen - ULONG flOpenMode; // as given to doshOpen - - ULONG cbInitial, // intial file size on open (can be 0 if new) - cbCurrent; // current file size (raised with each write) - - PBYTE pbCache; // if != NULL, cached data from doshReadAt - ULONG cbCache, // size of data in cbCache - ulReadFrom; // file offset where pbCache was read from - } XFILE, *PXFILE; - - #define XOPEN_READ_EXISTING 0x0001 - #define XOPEN_READWRITE_EXISTING 0x0002 - #define XOPEN_READWRITE_APPEND 0x0003 - #define XOPEN_READWRITE_NEW 0x0004 - #define XOPEN_ACCESS_MASK 0xffff - - #define XOPEN_BINARY 0x10000000 - - APIRET doshOpen(PCSZ pcszFilename, - ULONG flOpenMode, - PULONG pcbFile, - PXFILE *ppFile); - - #define DRFL_NOCACHE 0x0001 - #define DRFL_FAILIFLESS 0x0002 - - APIRET doshReadAt(PXFILE pFile, - ULONG ulOffset, - PULONG pcb, - PBYTE pbData, - ULONG fl); - - APIRET doshWrite(PXFILE pFile, - ULONG cb, - PCSZ pbData); - - APIRET doshWriteAt(PXFILE pFile, - ULONG ulOffset, - ULONG cb, - PCSZ pbData); - - APIRET doshWriteLogEntry(PXFILE pFile, - const char* pcszFormat, - ...); - - APIRET doshClose(PXFILE *ppFile); - - APIRET doshReadText(PXFILE pFile, - PSZ* ppszContent, - PULONG pcbRead); - - APIRET doshLoadTextFile(PCSZ pcszFile, - PSZ* ppszContent, - PULONG pcbRead); - - PSZ doshCreateBackupFileName(const char* pszExisting); - - APIRET doshCreateTempFileName(PSZ pszTempFileName, - PCSZ pcszDir, - PCSZ pcszPrefix, - PCSZ pcszExt); - - APIRET doshWriteTextFile(const char* pszFile, - const char* pszContent, - PULONG pulWritten, - PSZ pszBackup); - - - /* ****************************************************************** - * - * Directory helpers - * - ********************************************************************/ - - BOOL doshQueryDirExist(PCSZ pcszDir); - - APIRET doshCreatePath(PCSZ pcszPath, - BOOL fHidden); - - APIRET doshQueryCurrentDir(PSZ pszBuf); - - APIRET doshSetCurrentDir(PCSZ pcszDir); - - #define DOSHDELDIR_RECURSE 0x0001 - #define DOSHDELDIR_DELETEFILES 0x0002 - - APIRET doshDeleteDir(PCSZ pcszDir, - ULONG flFlags, - PULONG pulDirs, - PULONG pulFiles); - - APIRET doshCanonicalize(PCSZ pcszFileIn, - PSZ pszFileOut, - ULONG cbFileOut); - - /* ****************************************************************** - * - * Process helpers - * - ********************************************************************/ - - ULONG XWPENTRY doshMyPID(VOID); - typedef ULONG XWPENTRY DOSHMYPID(VOID); - typedef DOSHMYPID *PDOSHMYPID; - - ULONG XWPENTRY doshMyTID(VOID); - typedef ULONG XWPENTRY DOSHMYTID(VOID); - typedef DOSHMYTID *PDOSHMYTID; - - APIRET doshExecVIO(PCSZ pcszExecWithArgs, - PLONG plExitCode); - - APIRET doshQuickStartSession(PCSZ pcszPath, - PCSZ pcszParams, - BOOL fForeground, - USHORT usPgmCtl, - BOOL fWait, - PULONG pulSID, - PPID ppid, - PUSHORT pusReturn); - - APIRET doshSearchPath(PCSZ pcszPath, - PCSZ pcszFile, - PSZ pszExecutable, - ULONG cbExecutable); - - APIRET doshFindExecutable(PCSZ pcszCommand, - PSZ pszExecutable, - ULONG cbExecutable, - PCSZ *papcszExtensions, - ULONG cExtensions); - - /******************************************************************** - * - * Partition functions - * - ********************************************************************/ - - /* - *@@ LVMINFO: - * informational structure created by - * doshQueryLVMInfo. - * - *@@added V0.9.9 (2001-04-07) [umoeller] - */ - - typedef struct _LVMINFO - { - HMODULE hmodLVM; - - } LVMINFO, *PLVMINFO; - - /* #define DOSH_PARTITIONS_LIMIT 10 - - #define PAR_UNUSED 0x00 // Unused - #define PAR_FAT12SMALL 0x01 // DOS FAT 12-bit < 10 Mb - #define PAR_XENIXROOT 0x02 // XENIX root - #define PAR_XENIXUSER 0x03 // XENIX user - #define PAR_FAT16SMALL 0x04 // DOS FAT 16-bit < 32 Mb - #define PAR_EXTENDED 0x05 // Extended partition - #define PAR_FAT16BIG 0x06 // DOS FAT 16-bit > 32 Mb - #define PAR_HPFS 0x07 // OS/2 HPFS - #define PAR_AIXBOOT 0x08 // AIX bootable partition - #define PAR_AIXDATA 0x09 // AIX bootable partition - #define PAR_BOOTMANAGER 0x0A // OS/2 Boot Manager - #define PAR_WINDOWS95 0x0B // Windows 95 32-bit FAT - #define PAR_WINDOWS95LB 0x0C // Windows 95 32-bit FAT with LBA - #define PAR_VFAT16BIG 0x0E // LBA VFAT (same as 06h but using LBA-mode) - #define PAR_VFAT16EXT 0x0F // LBA VFAT (same as 05h but using LBA-mode) - #define PAR_OPUS 0x10 // OPUS - #define PAR_HID12SMALL 0x11 // OS/2 hidden DOS FAT 12-bit - #define PAR_COMPAQDIAG 0x12 // Compaq diagnostic - #define PAR_HID16SMALL 0x14 // OS/2 hidden DOS FAT 16-bit - #define PAR_HID16BIG 0x16 // OS/2 hidden DOS FAT 16-bit - #define PAR_HIDHPFS 0x17 // OS/2 hidden HPFS - #define PAR_WINDOWSSWP 0x18 // AST Windows Swap File - #define PAR_NECDOS 0x24 // NEC MS-DOS 3.x - #define PAR_THEOS 0x38 // THEOS - #define PAR_VENIX 0x40 // VENIX - #define PAR_RISCBOOT 0x41 // Personal RISC boot - #define PAR_SFS 0x42 // SFS - #define PAR_ONTRACK 0x50 // Ontrack - #define PAR_ONTRACKEXT 0x51 // Ontrack extended partition - #define PAR_CPM 0x52 // CP/M - #define PAR_UNIXSYSV 0x63 // UNIX SysV/386 - #define PAR_NOVELL_64 0x64 // Novell - #define PAR_NOVELL_65 0x65 // Novell - #define PAR_NOVELL_67 0x67 // Novell - #define PAR_NOVELL_68 0x68 // Novell - #define PAR_NOVELL_69 0x69 // Novell - #define PAR_PCIX 0x75 // PCIX - #define PAR_MINIX 0x80 // MINIX - #define PAR_LINUX 0x81 // Linux - #define PAR_LINUXSWAP 0x82 // Linux Swap Partition - #define PAR_LINUXFILE 0x83 // Linux File System - #define PAR_FREEBSD 0xA5 // FreeBSD - #define PAR_BBT 0xFF // BBT - */ - - // one-byte alignment - #pragma pack(1) - - /* - *@@ PAR_INFO: - * partition table - */ - - typedef struct _PAR_INFO - { - BYTE bBootFlag; // 0=not active, 80H = active (boot this partition - BYTE bBeginHead; // partition begins at this head... - USHORT rBeginSecCyl; // ...and this sector and cylinder (see below) - BYTE bFileSysCode; // file system type - BYTE bEndHead; // partition ends at this head... - USHORT bEndSecCyl; // ...and this sector and cylinder (see below) - ULONG lBeginAbsSec; // partition begins at this absolute sector # - ULONG lTotalSects; // total sectors in this partition - } PAR_INFO, *PPAR_INFO; - - /* - *@@ MBR_INFO: - * master boot record table. - * This has the four primary partitions. - */ - - typedef struct _MBR_INFO // MBR - { - BYTE aBootCode[0x1BE]; // abBootCode master boot executable code - PAR_INFO sPrtnInfo[4]; // primary partition entries - USHORT wPrtnTblSig; // partition table signature (aa55H) - } MBR_INFO, *PMBR_INFO; - - /* - *@@ SYS_INFO: - * - */ - - typedef struct _SYS_INFO - { - BYTE startable; - BYTE unknown[3]; - BYTE bootable; - BYTE name[8]; - BYTE reservd[3]; - } SYS_INFO, *PSYS_INFO; - - /* - *@@ SYE_INFO: - * - */ - - typedef struct _SYE_INFO - { - BYTE bootable; - BYTE name[8]; - } SYE_INFO, *PSYE_INFO; - - /* - *@@ EXT_INFO: - * - */ - - typedef struct _EXT_INFO - { - BYTE aBootCode[0x18A]; // abBootCode master boot executable code - SYE_INFO sBmNames[4]; // System Names - BYTE bReserved[16]; // reserved - PAR_INFO sPrtnInfo[4]; // partitioms entrys - USHORT wPrtnTblSig; // partition table signature (aa55H) - } EXT_INFO, *PEXT_INFO; - - typedef struct _PARTITIONINFO *PPARTITIONINFO; - - /* - *@@ PARTITIONINFO: - * informational structure returned - * by doshGetPartitionsList. One of - * these items is created for each - * bootable partition. - */ - - typedef struct _PARTITIONINFO - { - BYTE bDisk; // drive number - CHAR cLetter; // probable drive letter or ' ' if none - BYTE bFSType; // file system type - PCSZ pcszFSType; // file system name (as returned by - // doshType2FSName, can be NULL!) - BOOL fPrimary; // primary partition? - BOOL fBootable; // bootable by Boot Manager? - CHAR szBootName[21]; // Boot Manager name, if (fBootable) - // extended for LVM names V0.9.20 (2002-08-10) [umoeller] - ULONG ulSize; // size MBytes - PPARTITIONINFO pNext; // next info or NULL if last - } PARTITIONINFO; - - UINT doshQueryDiskCount(VOID); - - APIRET doshReadSector(USHORT disk, - void *buff, - USHORT head, - USHORT cylinder, - USHORT sector); - - // restore original alignment - #pragma pack() - - const char* doshType2FSName(unsigned char bFSType); - - APIRET doshGetBootManager(USHORT *pusDisk, - USHORT *pusPart, - PAR_INFO *BmInfo); - - typedef struct _PARTITIONSLIST - { - PLVMINFO pLVMInfo; // != NULL if LVM is installed - - // partitions array - PPARTITIONINFO pPartitionInfo; - USHORT cPartitions; - } PARTITIONSLIST, *PPARTITIONSLIST; - - APIRET doshGetPartitionsList(PPARTITIONSLIST *ppList, - PUSHORT pusContext); - - APIRET doshFreePartitionsList(PPARTITIONSLIST ppList); - - APIRET doshQueryLVMInfo(PLVMINFO *ppLVMInfo); - - APIRET doshReadLVMPartitions(PLVMINFO pInfo, - PPARTITIONINFO *ppPartitionInfo, - PUSHORT pcPartitions); - - VOID doshFreeLVMInfo(PLVMINFO pInfo); - - /* ****************************************************************** - * - * Wildcard matching - * - ********************************************************************/ - - BOOL doshMatchCase(PCSZ pcszMask, - PCSZ pcszName); - - BOOL doshMatchCaseNoPath(const char *pcszMask, - const char *pcszName); - - BOOL doshMatch(PCSZ pcszMask, - PCSZ pcszName); - #endif #if __cplusplus } #endif - diff --git a/sal/osl/os2/helpers/except.h b/sal/osl/os2/helpers/except.h index 6a898ba84c99..b2d6b17ca702 100644 --- a/sal/osl/os2/helpers/except.h +++ b/sal/osl/os2/helpers/except.h @@ -1,3 +1,32 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile:$ + * $Revision:$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ /* *@@sourcefile except.h: @@ -15,15 +44,10 @@ */ /* - * Copyright (C) 1999-2000 Ulrich M”ller. - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, in version 2 as it comes in the COPYING - * file of the XFolder main distribution. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Copyright (C) 1999-2000 Ulrich M�ller. + * + * 2009-06-15 published under LGPL3 with Ulrich M�ller permission. + * */ #if __cplusplus diff --git a/sal/osl/os2/helpers/setup.h b/sal/osl/os2/helpers/setup.h index 015d93019f21..6c02d8b655fb 100644 --- a/sal/osl/os2/helpers/setup.h +++ b/sal/osl/os2/helpers/setup.h @@ -1,3 +1,35 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile:$ + * $Revision:$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + * 2009-06-15 published under LGPL3 with Ulrich M�ller permission. + * + * + ************************************************************************/ /* * setup.h: diff --git a/sal/osl/os2/module.c b/sal/osl/os2/module.c index c8c9731a95ed..901c029429c4 100644 --- a/sal/osl/os2/module.c +++ b/sal/osl/os2/module.c @@ -109,7 +109,7 @@ oslModule SAL_CALL osl_loadModule(rtl_uString *ustrModuleName, sal_Int32 nRtldMo pModule = (oslModule)hModule; else { - sal_Char szError[ 120 ]; + sal_Char szError[ PATH_MAX*2 ]; sprintf( szError, "Module: %s; rc: %d;\nReason: %s;\n" "Please contact technical support and report above informations.\n\n", buffer, rc, szErrorMessage ); diff --git a/sal/osl/os2/process.c b/sal/osl/os2/process.c index 793be57950b6..a3408ddbf7d0 100644 --- a/sal/osl/os2/process.c +++ b/sal/osl/os2/process.c @@ -551,7 +551,8 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName, { for (i = first; pszArguments[i] != NULL; i++) n += strlen(pszArguments[i]) + 1; - args = (sal_Char*)malloc(n); + // YD DosStartSession requires low-mem buffers! + args = (sal_Char*)_tmalloc(n); *args = '\0'; for (i = first; pszArguments[i] != NULL; i++) { @@ -567,7 +568,8 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName, { for (i = 0; pszEnvironments[i] != NULL; i++) n += strlen(pszEnvironments[i]) + 1; - envs = (sal_Char*)malloc(n + 1); + // YD DosStartSession requires low-mem buffers! + envs = (sal_Char*)_tmalloc(n + 1); pStr = (sal_Char*)envs; for (i = 0; pszEnvironments[i] != NULL; i++) { @@ -660,9 +662,9 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName, if(envs) - free(envs); + _tfree(envs); if(args) - free(args); + _tfree(args); if( rc != NO_ERROR ) return osl_Process_E_Unknown; diff --git a/ure/source/makefile.mk b/ure/source/makefile.mk index 17dbdb322de2..9736ca597aed 100644 --- a/ure/source/makefile.mk +++ b/ure/source/makefile.mk @@ -35,7 +35,7 @@ TARGET := $(PRJNAME) .INCLUDE: settings.mk -.IF "$(OS)" == "WNT" +.IF "$(OS)" == "WNT" || "$(OS)" == "OS2" MY_RC = .ini .ELSE MY_RC = rc diff --git a/xml2cmp/source/xcd/filebuff.cxx b/xml2cmp/source/xcd/filebuff.cxx index e958c274b552..8035d697ae4d 100644 --- a/xml2cmp/source/xcd/filebuff.cxx +++ b/xml2cmp/source/xcd/filebuff.cxx @@ -59,11 +59,7 @@ LoadXmlFile( Buffer & o_rBuffer, // Read file: aXmlFile.read(o_rBuffer.Data(), (int) nBufferSize); -#ifdef OS2 // YD eof&fail are set, so check for fail&bad - bool ret = aXmlFile.fail() != 0; -#else bool ret = aXmlFile.good() != 0; -#endif aXmlFile.close(); return ret; } -- cgit From 4f371d43226d7800a5011aa11c3afcec7f5a8ba2 Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Fri, 11 Sep 2009 11:45:29 +0000 Subject: CWS-TOOLING: integrate CWS jl131 2009-09-02 16:42:40 +0200 jl r275720 : #i97896# 2009-08-31 13:01:53 +0200 jl r275599 : CWS-TOOLING: rebase CWS jl131 to trunk@275331 (milestone: DEV300:m56) 2009-07-31 14:35:30 +0200 jl r274531 : CWS-TOOLING: rebase CWS jl131 to trunk@274203 (milestone: DEV300:m53) 2009-07-23 14:20:32 +0200 jl r274272 : #i79839# better error text when trying to modify shared layer without having write permission, eg. unopkg add --shared, unopkg remove --shared, unopkg reinstall --shared 2009-07-22 16:38:02 +0200 jl r274252 : #i97896# localize error message for lock file 2009-07-22 16:37:22 +0200 jl r274251 : #i80462# unprecise wording in updatedialog 2009-07-22 16:36:06 +0200 jl r274250 : #i97896# localize error message for lock file 2009-07-22 16:35:20 +0200 jl r274249 : #i97896# localize error message for lock file 2009-07-22 15:07:30 +0200 jl r274242 : #i98873# minimum java version is 1.5 since OOo 3.0 --- jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml index 020c11b4973e..2dd5fe35f555 100644 --- a/jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml @@ -7,13 +7,13 @@ - 1.3.1 + 1.5.0 1.6.0 - 1.4.2 + 1.5.0 -- cgit From 7c85fd2d1cbb8bf6fde7a7455f60ce0b8eb85c91 Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Fri, 11 Sep 2009 14:29:45 +0000 Subject: CWS-TOOLING: integrate CWS odfmetadata3 2009-09-11 Michael Stahl merge DEV300_m58 2009-09-07 Michael Stahl SwFmtFld::Modify(): do nothing on RES_OBJECTDYING 2009-08-27 Michael Stahl #i91565#, #i91566#: TextPortionEnumerationTest.java: add test document 2009-08-27 Michael Stahl #i91565#, #i91566#: add complex test: TextPortionEnumerationTest.java 2009-08-27 Michael Stahl CLiteral::initialize(): zero-length literals probably not an error 2009-08-27 Michael Stahl #i91565#, #i91566#: offapi: new InContentMetadata and MetadataField services adapt TextPortion for InContentMetadata 2009-08-27 Michael Stahl #i91564#: xmloff: load/store xml:id and RDFa for text:bookmark(-start). 2009-08-27 Michael Stahl #i91564#: sw core: add support for xml:id at bookmarks: sw::mark::Bookmark: derive from Metadatable. SwHistoryBookmark, SaveBookmark: store a MetadatableUndo. ndcopy.cxx: lcl_CopyBookmarks(): copy the xml:id. SwXBookmark: derive from MetadatableMixin. 2009-08-27 Michael Stahl #i91565#, #i91566#: xmloff: refactor ruby import so nested meta(-field) works: remove XMLRubyHint_Impl. XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl(): insert ruby directly. 2009-08-27 Michael Stahl #i91565#, #i91566#: xmloff: fix text:meta(-field) import/export: new XMLTextParagraphExport::exportTextField() overload for XTextField. CreateAndInsertMark(): set xml:id after insertion. fix meta(-field) service names, bugs etc. 2009-08-27 Michael Stahl #i91565#, #i91566#: sw text formatting: paint background of meta(-field) body: SwFont: add member m_nMetaCount. txttypes.hxx: add POR_META. atrstck.cxx: handle RES_TXTATR_META(FIELD). itrform2.cxx: SwTxtFormatter::WhichTxtPor(): create new class SwMetaPortion. 2009-08-27 Michael Stahl #i91566#: sw text formatting: display meta-field prefix and suffix: SwAttrIter::GetAttr(): replace with call to GetTxtAttrForCharAt(). SwTxtFormatter::NewExtraPortion(): handle meta-field prefix. SwTxtFormatter: new member m_nHintEndIndex. SwTxtFormatter::WhichFirstPortion(): call TryNewNoLengthPortion(). SwTxtFormatter::TryNewNoLengthPortion(): new; handle suffix of meta-field. SwTxtFormatter::UnderFlow(): UGLY HACK: decrement m_nHintEndIndex. SwFldPortion: add flag m_bNoLength: portion has zero length (for suffix). 2009-08-27 Michael Stahl #i91565#, #i91566#: extend text:meta(-field) uno wrapper with XText interface: unoobj.hxx: new CursorType CURSOR_META. unoobj2.cxx: refactor SwXText implementation to ensure that when the SwXText belongs to a SwXMeta, content is always inserted inside the meta(-field). unoobj.cxx: new SwXTextCursor::ForceIntoMeta(): cursor stays in meta(-field). unometa.hxx: SwXMeta implements XText, forwarding to a member SwXMetaText. DocInsertStringSplitCR(), SwX*::attachToRange(), SwX*::DeleteAndInsert(): use FORCEHINTEXPAND hack to ensure insert into the meta(-field) at the end. 2009-08-27 Michael Stahl #i91565#, #i91566#: add text:meta(-field) uno wrapper to sw: fmtmeta.hxx, fmtatr2.cxx: new class sw::MetaField, new sw::MetaFieldManager. doc.hxx, docnew.cxx: new SwDoc::GetMetaFieldManager(). unocoll.hxx,.cxx: new SW_SERVICE_FIELDTYPE_METAFIELD, SW_SERVICE_TYPE_META. unomap.hxx,.cxx: new PROPERTY_MAP_METAFIELD. unoprnms.hxx: new UNO_NAME_META. unoport.hxx: new PORTION_META; add "InContentMetadata" prop to SwXTextPortion. new unometa.hxx: new class SwXMeta and SwXMetaField. unofield.cxx: SwXFieldEnumeration: include meta-fields. unoportenum.cxx: handle RES_TXTATR_META(FIELD) by using a portion list stack. unotext.cxx: SwXText::insertTextContent(): handle meta(-field) as attribute. 2009-08-27 Michael Stahl #i91565#, #i91566#: ndhints.cxx: remove sort number from SwTxtAttrNesting 2009-08-27 Michael Stahl #i91565#, #i91566#: add support for hints with end and CH_TXTATR to sw core: doc.hxx, docedt.cxx: replace SwDoc::Delete(), DeleteAndJoin(), ReplaceRange() with wrappers that split at left-overlapped end+CH_TXTATR hints. txatbase.hxx: new member SwTxtAttr::m_bHasDummyChar. ndtxt.hxx: rename SwTxtNode::GetTxtAttr() to GetTxtAttrForCharAt(). ndtxt.cxx: SwTxtNode::CopyText(): copy end+CH_TXTATR hints iff copy CH_TXTATR. txtatr2.cxx, thints.cxx: SwTxtMeta gets a CH_TXTATR. 2009-08-27 Michael Stahl #i91565#, #i91566#: add text:meta(-field) to sw core: txatbase.hxx: new member SwTxtAttr::m_bNesting. hintids.hxx: new ids RES_TXTATR_META, RES_TXTATR_METAFIELD. txtatr.hxx: new base class SwTxtAttrNesting. new hint SwTxtMeta. SwTxtRuby derives from SwTxtAttrNesting. txtinet.hxx: SwTxtINetFmt derives from SwTxtAttrNesting. new header fmtmeta.hxx: new pool item SwFmtMeta. new class sw::Meta. ndhints.hxx, thints.cxx: new method SwpHints::TryInsertNesting(). thints.cxx: refactoring: BuildPortions() no longer handles Ruby/Hyperlink, but TryInsertNesting(), which also handles meta(-field). SwTxtNode::InsertItem(): check if the hint is actually inserted. ndhints.cxx: sort nesting hints based on sort number. ndtxt.cxx: lcl_CopyHint(): handle copy of meta/meta-field. 2009-08-27 Michael Stahl enable expanding hints with m_bLockExpandFlag set: add new InsertFlag: INS_FORCEHINTEXPAND. add new SetAttrMode: SETATTR_FORCEHINTEXPAND. rename SwEditShell::Insert() to Insert2() because changed signature fails to compile when SwWrtShell tries to overwrite these non-virtual members... SwWrtShell::Insert() sets FOCEHINTEXPAND if range was selected/deleted. adapt SwUndoInsert to store flags. 2009-08-27 Michael Stahl change formal parameters of item insertion methods to type SetAttrMode 2009-08-27 Michael Stahl fix incorrect resetting of text attributes in SwUndoInsSection, SwUndoInserts 2009-08-27 Michael Stahl clean up SwTxtNode::CutImpl() and lcl_CopyHint() 2009-08-27 Michael Stahl rename SwDoc::Copy() to CopyRange(), and _Copy() to CopyImpl() 2009-08-27 Michael Stahl rename SwNodes::Move() to MoveRange(), and remove unused parameter 2009-08-27 Michael Stahl rename SwDoc::Move() to MoveRange()/MoveNodeRange() 2009-08-27 Michael Stahl rename SwDoc::Insert() to InsertString(), and remove sal_Unicode variant 2009-08-27 Michael Stahl rename SwDoc::Insert() to InsertPoolItem()/InsertItemSet()/InsertSwSection() 2009-08-27 Michael Stahl rename SwDoc::Replace() to ReplaceRange() 2009-08-27 Michael Stahl remove SwDoc::Overwrite() sal_Unicode variant 2009-08-27 Michael Stahl split up SwDoc::DeleteAndJoin(): factor out DeleteAndJoinWithRedline() 2009-08-27 Michael Stahl rename overloaded SwDoc::Delete() to DeleteRange()/DeleteTOXMark() 2009-08-27 Michael Stahl rename SwTxtNode::Copy() to CopyText() 2009-08-27 Michael Stahl rename SwTxtNode::Cut() to CutText(), and _Cut() to CutImpl() 2009-08-27 Michael Stahl rename SwTxtNode::Delete() to DeleteAttribute()/DeleteAttributes() 2009-08-27 Michael Stahl rename SwTxtNode::Replace() to ReplaceText(), and remove the xub_Unicode variant 2009-08-27 Michael Stahl rename SwTxtNode::Erase() to EraseText() 2009-08-27 Michael Stahl rename SwTxtNode::Insert() to InsertText(), and remove the xub_Unicode variant 2009-08-27 Michael Stahl clean up SwTxtNode::Update() 2009-08-27 Michael Stahl remove SwTxtAttr::RemoveFromPool() and make destructor non-public, to be invoked by new method SwTxtAttr::Destroy() 2009-08-27 Michael Stahl ensure that SwDoc::Insert() for item (set) returns success indicator: replace SwRegHistory constructor with method InsertItems(), returning bool. refactor InsAttr() so that it checks if InsertItems() succeeds. 2009-08-27 Michael Stahl move SwXTextPortionEnumeration from unoobj.hxx to unoport.hxx 2009-08-27 Michael Stahl add missing SolarMutex in SwXTextPortion methods 2009-08-27 Michael Stahl SwXTextPortion: new member m_xTextField (so the TextField property need not be returned indirectly via SwUnoCursorHelper). factor out function CreateSwXTextField(). 2009-08-27 Michael Stahl SwXTextPortion: remove PORTION_CONTROL_CHAR and implementation of XTextField 2009-08-27 Michael Stahl remove obsolete hint SwTxtHardBlank and formats SwFmtHardBlank/SwFmtSoftHyph 2009-08-27 Michael Stahl clean up SwTxtAttr and friends: remove many accessor methods for obsolete (due to autofmt) char format items. remove unused flag SwTxtAttr::m_bDontMergeAttr. MakeRedlineTxtAttr() now dedicated function, no longer calls MakeTxtAttr(). 2009-08-27 Michael Stahl remove obsolete attribute SwTxt2Lines 2009-08-27 Michael Stahl SwXTextPortionEnumeration: finish refactoring CreatePortions change ExportHints so it always returns a text portion for hint w/ CH_TXTATR. remove special case for handling end of paragraph. unfortunately had to refactor the fieldmarks export as well (got in the way). 2009-08-27 Michael Stahl SwXTextPortionEnumeration: refactor CreatePortions: frames export extract function ExportFrames() from CreatePortions(). remove (un)dead code that calls evil MovePara(fnParaCurr, fnParaEnd) 2009-08-27 Michael Stahl clean up SwXParaFrameEnumeration 2009-08-27 Michael Stahl CollectFrameAtNode: replace SwDependArr with STL based FrameDependList_t 2009-08-27 Michael Stahl SwXTextPortionEnumeration: tweak refmark/toxmark export so ExportHints returns the portion for point marks 2009-08-27 Michael Stahl clean up SwXTextPortionEnumeration: prefix members, remove casts, replace SvWeirdArray with STL, etc. make CreatePortions() method a function, and remove lots of members. extract fieldmarks function from CreatePortions. 2009-08-27 Michael Stahl remove FOREACHUNOPAM_START/END macros 2009-08-27 Michael Stahl clean up SwXTextPortion: prefix members, remove casts, etc. remove SwXRubyPortion: replace it with another SwXTextPortion constructor 2009-08-27 Michael Stahl #i102541# SwXReferenceMark::InsertRefMark(): use flag SETATTR_DONTEXPAND 2009-08-27 Michael Stahl rename SwTxtNode::Insert to SwTxtNode::InsertHint, and fix constness in SwTxtNode::InsertItem 2009-08-27 Michael Stahl turn SwTxtNode::MakeTxtAttr() methods into global functions in ndhints.hxx 2009-08-27 Michael Stahl remove obsolete sw/inc/bookmrk.hxx 2009-08-27 Michael Stahl pam.cxx: fix ComparePosition functions (returned wrong result in one case) 2009-08-27 Michael Stahl #i103613# only import RDF metadata on normal open of a document 2009-09-11 kz CWS-TOOLING: integrate CWS impress176 2009-09-08 20:18:24 +0200 sj r275957 : fixed warning (shadowed variable) 2009-09-08 18:02:05 +0200 cl r275948 : #i104315# added missing tab pages 2009-09-08 17:35:18 +0200 cl r275947 : #i104866# fixed angle import 2009-09-08 17:32:53 +0200 cl r275946 : #i104841# fixed angle import 2009-09-08 17:01:25 +0200 cl r275943 : #i103935# fixed the SID_EVENTCONFIG mess 2009-09-08 14:32:57 +0200 sj r275928 : #i104685# only comments 2009-09-07 12:37:36 +0200 sj r275886 : #i104683# fixed import of bold/italic attributes for normal text shapes 2009-09-04 15:07:46 +0200 sj r275808 : #104689# fixed bullet color problem 2009-09-03 15:25:07 +0200 sj r275753 : #160200# added vertical alignment of table cells 2009-09-11 kz CWS-TOOLING: integrate CWS dv14 2009-09-10 15:16:32 +0200 sg r276035 : #160513# updated wfs scheme to accept ports 2009-09-10 07:41:47 +0200 dv r276019 : #i104942# Better renaming algorithmen 2009-08-31 13:41:11 +0200 dv r275604 : #160505# Setting APP1PRODUCTNAME must not overwrite APP1PRODUCTDEF 2009-09-11 kz CWS-TOOLING: integrate CWS jl131 2009-09-02 16:42:40 +0200 jl r275720 : #i97896# 2009-08-31 13:01:53 +0200 jl r275599 : CWS-TOOLING: rebase CWS jl131 to trunk@275331 (milestone: DEV300:m56) 2009-07-31 14:35:30 +0200 jl r274531 : CWS-TOOLING: rebase CWS jl131 to trunk@274203 (milestone: DEV300:m53) 2009-07-23 14:20:32 +0200 jl r274272 : #i79839# better error text when trying to modify shared layer without having write permission, eg. unopkg add --shared, unopkg remove --shared, unopkg reinstall --shared 2009-07-22 16:38:02 +0200 jl r274252 : #i97896# localize error message for lock file 2009-07-22 16:37:22 +0200 jl r274251 : #i80462# unprecise wording in updatedialog 2009-07-22 16:36:06 +0200 jl r274250 : #i97896# localize error message for lock file 2009-07-22 16:35:20 +0200 jl r274249 : #i97896# localize error message for lock file 2009-07-22 15:07:30 +0200 jl r274242 : #i98873# minimum java version is 1.5 since OOo 3.0 2009-09-11 kz CWS-TOOLING: integrate CWS changehc 2009-08-31 19:38:50 +0200 pl r275633 : remove dbug printf 2009-08-31 17:41:50 +0200 pl r275623 : CWS-TOOLING: rebase CWS changehc to trunk@275331 (milestone: DEV300:m56) 2009-07-15 19:45:46 +0200 pl r274028 : #i35482# use HC flag to decide high contrast mode 2009-07-15 17:40:52 +0200 pl r274020 : #i35482# use HC flag to decide high contrast mode 2009-07-15 17:39:50 +0200 pl r274019 : #i35482# update autohc correctly in MergeSystemSettings 2009-07-15 17:38:57 +0200 pl r274018 : #i35482# update autohc correctly in MergeSystemSettings 2009-09-11 kz CWS-TOOLING: integrate CWS notes10 2009-08-24 07:25:57 +0200 mod r275287 : 2009-07-26 02:38:32 +0200 mod r274343 : #i#i103645# 2009-07-26 02:01:53 +0200 mod r274342 : #i103645# 2009-07-26 01:52:42 +0200 mod r274341 : #i103490# 2009-07-22 08:31:48 +0200 mod r274215 : #i103373# 2009-07-15 00:55:11 +0200 mod r273987 : #i101419# 2009-07-14 07:07:55 +0200 mod r273956 : #i101419# 2009-07-14 07:07:43 +0200 mod r273955 : #i101419# 2009-07-14 07:02:10 +0200 mod r273954 : changes from notes9 2009-07-14 06:14:25 +0200 mod r273953 : #i103476# 2009-09-11 kz CWS-TOOLING: integrate CWS ab70 2009-09-10 15:12:54 +0200 jsk r276034 : #i85434# - mandatory automatic update test 2009-09-10 15:11:06 +0200 jsk r276033 : #i85434# - mandatory automatic update test 2009-09-02 09:49:24 +0200 ab r275698 : #i85434# Dialog Import 2009-09-11 kz CWS-TOOLING: integrate CWS hb32bugs02 2009-09-02 Henning Brinkmann #i102420# revert changes 2009-08-26 Henning Brinkmann merged DEV300_m56 2009-08-19 Henning Brinkmann merged DEV300_m55 2009-08-14 Henning Brinkmann merged changes from wntmsci12 2009-08-12 Henning Brinkmann Implemented NoSpaceEdit constructor and destructor in .cxx to allow compile with debug on wntmsci12. 2009-08-12 Henning Brinkmann Added some SW_DLLPUBLIC to make compilable on wntmsci12. 2009-08-11 Henning Brinkmann #i102420# dbg_out: surround output for SwNodes with . 2009-08-10 Henning Brinkmann #i102420# rewritten debug output for SwNodes. 2009-08-07 Henning Brinkmann #i102420# debug _MoveNodes: output the destination, too. Break after two iterations. 2009-08-07 Henning Brinkmann #i102420# _MoveNodes: Additionally check if destination index is inside source => false Check if current range was already handled => loop Debug output current range 2009-08-06 Henning Brinkmann merged DEV300_m54 2009-08-06 Henning Brinkmann added master fix 2009-08-06 Henning Brinkmann debug output for SwNodeRange 2009-08-04 Henning Brinkmann #i102844# robustness: check for NULL pointer to prevent crash 2009-08-03 Henning Brinkmann #i103475# applied patch and verified 2009-08-03 Henning Brinkmann Removed code preventing build of sw with DEBUG. 2009-09-11 convert-repo update tags 2009-09-10 kz CWS-TOOLING: integrate CWS os2port06dev300 2009-09-05 22:49:00 +0200 ydario r275858 : #i99588# applied os2port06 diff to DEV300 tree. 2009-09-10 kz CWS-TOOLING: integrate CWS mingwport23 2009-08-29 07:07:53 +0200 tono r275555 : i#104522: mingw port graphite 2009-08-29 07:07:26 +0200 tono r275554 : i#104522: mingw port printf format fix 2009-09-10 kz CWS-TOOLING: integrate CWS mh232 2009-08-26 03:52:57 +0200 mh r275385 : #i102182# FreeBSD patch 2009-08-26 03:43:20 +0200 mh r275384 : #i101333# patch for FreeBSD 2009-08-26 03:11:20 +0200 mh r275383 : #i39230 2009-08-26 03:07:51 +0200 mh r275382 : #i39230# more space for initials field 2009-08-26 02:41:19 +0200 mh r275380 : #i39230# use vos::osecurity for reading the user name 2009-08-18 22:06:00 +0200 mh r275130 : #i104243#, line ending problem with newer perl 2009-08-18 21:53:21 +0200 mh r275129 : #i39230# read initials via getpwnam 2009-08-18 21:34:05 +0200 mh r275128 : enable CAIROCANVAS for Linux and Mac, #i88613# 2009-08-17 18:02:59 +0200 mh r275067 : #i95498# make compile with gcc3 2009-09-10 kz CWS-TOOLING: integrate CWS tkr24 2009-09-07 14:31:06 +0200 is r275898 : #160081# adding NO_LICENSE_INTO_COPYRIGHT 2009-09-10 releng #i10000# change KeyMapping to SingletonRef 2009-09-11 convert-repo update tags 2009-09-10 kz CWS-TOOLING: integrate CWS os2port06dev300 2009-09-05 22:49:00 +0200 ydario r275858 : #i99588# applied os2port06 diff to DEV300 tree. 2009-09-10 kz CWS-TOOLING: integrate CWS mingwport23 2009-08-29 07:07:53 +0200 tono r275555 : i#104522: mingw port graphite 2009-08-29 07:07:26 +0200 tono r275554 : i#104522: mingw port printf format fix 2009-09-10 kz CWS-TOOLING: integrate CWS mh232 2009-08-26 03:52:57 +0200 mh r275385 : #i102182# FreeBSD patch 2009-08-26 03:43:20 +0200 mh r275384 : #i101333# patch for FreeBSD 2009-08-26 03:11:20 +0200 mh r275383 : #i39230 2009-08-26 03:07:51 +0200 mh r275382 : #i39230# more space for initials field 2009-08-26 02:41:19 +0200 mh r275380 : #i39230# use vos::osecurity for reading the user name 2009-08-18 22:06:00 +0200 mh r275130 : #i104243#, line ending problem with newer perl 2009-08-18 21:53:21 +0200 mh r275129 : #i39230# read initials via getpwnam 2009-08-18 21:34:05 +0200 mh r275128 : enable CAIROCANVAS for Linux and Mac, #i88613# 2009-08-17 18:02:59 +0200 mh r275067 : #i95498# make compile with gcc3 2009-09-10 kz CWS-TOOLING: integrate CWS tkr24 2009-09-07 14:31:06 +0200 is r275898 : #160081# adding NO_LICENSE_INTO_COPYRIGHT 2009-09-10 releng #i10000# change KeyMapping to SingletonRef --- offapi/com/sun/star/text/TextPortion.idl | 9 +++++++++ offapi/com/sun/star/text/makefile.mk | 1 + offapi/com/sun/star/text/textfield/makefile.mk | 1 + 3 files changed, 11 insertions(+) diff --git a/offapi/com/sun/star/text/TextPortion.idl b/offapi/com/sun/star/text/TextPortion.idl index 26ad5bd5ba6c..d4ab79f88323 100644 --- a/offapi/com/sun/star/text/TextPortion.idl +++ b/offapi/com/sun/star/text/TextPortion.idl @@ -113,6 +113,7 @@ published service TextPortion

Ruby
a ruby attribute which is used in Asian text
Frame
a frame
SoftPageBreak
a soft page break
+
InContentMetadata
a text range with attached metadata

For Reference marks, document index marks, etc., 2 text portions will be generated, one for the start position and one for the @@ -123,6 +124,7 @@ published service TextPortion //------------------------------------------------------------------------- /** contains the control character of a text portion of type ControlCharacter. + @deprecated type ControlCharacter no longer implemented */ [readonly, property] short ControlCharacter; @@ -152,6 +154,13 @@ published service TextPortion [optional, readonly, property] ::com::sun::star::text::XTextField TextField; + //------------------------------------------------------------------------- + /** contains the text range of a text portion of type InContentMetadata. + @since OOo 3.2 + */ + [optional, readonly, property] + ::com::sun::star::text::XTextContent InContentMetadata; + //------------------------------------------------------------------------- /** contains whether the portion is a point only. */ [optional, readonly, property] boolean IsCollapsed; diff --git a/offapi/com/sun/star/text/makefile.mk b/offapi/com/sun/star/text/makefile.mk index 18ad6abbe2a1..c018c9479049 100644 --- a/offapi/com/sun/star/text/makefile.mk +++ b/offapi/com/sun/star/text/makefile.mk @@ -107,6 +107,7 @@ IDLFILES=\ HorizontalAdjust.idl\ HypertextDocument.idl\ IllustrationsIndex.idl\ + InContentMetadata.idl\ InvalidTextContentException.idl\ LabelFollow.idl\ LineNumberingProperties.idl\ diff --git a/offapi/com/sun/star/text/textfield/makefile.mk b/offapi/com/sun/star/text/textfield/makefile.mk index 46506a4eff8c..0defebd69dfc 100644 --- a/offapi/com/sun/star/text/textfield/makefile.mk +++ b/offapi/com/sun/star/text/textfield/makefile.mk @@ -70,6 +70,7 @@ IDLFILES=\ InputUser.idl\ JumpEdit.idl\ Macro.idl\ + MetadataField.idl\ PageCount.idl\ PageNumber.idl\ ParagraphCount.idl\ -- cgit From 8d9861ec8872a105664a908fc86f90222f07cb0a Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Fri, 11 Sep 2009 16:06:18 +0000 Subject: CWS-TOOLING: integrate CWS chartuseability01 2009-09-07 17:26:44 +0200 iha r275906 : CWS-TOOLING: rebase CWS chartuseability01 to trunk@275801 (milestone: DEV300:m57) 2009-08-27 13:48:16 +0200 iha r275481 : #7049# listbox to select chart elements 2009-08-27 11:54:53 +0200 iha r275464 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-26 16:49:58 +0200 iha r275435 : #i102820# added missing case 'floor' 2009-08-26 15:33:51 +0200 iha r275427 : #i102820# make 'insert legend' work properly 2009-08-25 16:35:00 +0200 ufi r275369 : i104087 2009-08-25 15:12:17 +0200 iha r275360 : #i104087# 'Object Properties' -> 'Format Selection' 2009-08-25 15:11:31 +0200 iha r275359 : #i104087# 'Object Properties' -> 'Format Selection' 2009-08-25 15:11:15 +0200 iha r275358 : #i104087# 'Object Properties' -> 'Format Selection' 2009-08-25 11:57:43 +0200 iha r275344 : #i104087# changed behavior of insert menu 2009-08-18 12:53:54 +0200 oc r275093 : #i104082,104086,104089# multiple changes because of changed chartUI 2009-08-10 16:46:17 +0200 ufi r274824 : i104083 i104087 i104090 2009-08-07 14:04:34 +0200 iha r274763 : #7049# listbox to select chart elements 2009-08-07 13:06:05 +0200 iha r274760 : #7049# listbox to select chart elements 2009-08-07 13:05:06 +0200 iha r274759 : #7049# listbox to select chart elements 2009-08-07 12:32:31 +0200 iha r274756 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-07 12:31:54 +0200 iha r274755 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-06 19:00:48 +0200 iha r274742 : #i103593# make insert menu behavior selection dependent 2009-08-06 19:00:14 +0200 iha r274741 : #i103593# make insert menu behavior selection dependent 2009-08-06 15:34:01 +0200 iha r274731 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-06 14:39:20 +0200 iha r274728 : #i86146# ease adding R-squared value with an equation 2009-08-06 14:37:02 +0200 iha r274727 : #i86146# ease adding R-squared value with an equation 2009-08-06 13:37:54 +0200 iha r274724 : #i86146# ease adding R-squared value with an equation 2009-08-06 13:37:15 +0200 iha r274723 : #i86146# ease adding R-squared value with an equation 2009-08-06 13:04:27 +0200 iha r274722 : #i103593# make insert menu behavior selection dependent 2009-08-06 13:03:35 +0200 iha r274721 : #i103593# make insert menu behavior selection dependent 2009-08-05 18:26:31 +0200 iha r274693 : #i104033# inconsistent wording 'error indicator' <-> 'error bar' 2009-08-05 16:51:45 +0200 iha r274688 : #i104028# rename font tabpage 'Characters'->'Font' 2009-08-05 16:30:21 +0200 iha r274685 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-05 15:34:11 +0200 iha r274680 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-05 15:32:43 +0200 iha r274679 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-05 15:31:26 +0200 iha r274678 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-05 15:17:51 +0200 iha r274676 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-05 15:16:22 +0200 iha r274675 : #i58163# #i69422# #i102820# enhance chart context menu 2009-08-05 14:58:59 +0200 iha r274674 : #7049# listbox to select chart elements 2009-08-05 14:33:54 +0200 iha r274669 : #7049# listbox to select chart elements 2009-08-05 14:22:17 +0200 iha r274665 : #7049# listbox to select chart elements 2009-08-05 13:21:05 +0200 iha r274656 : #i102820# offer insertion of several elements in context menu also if nothing is selected 2009-08-05 11:56:06 +0200 iha r274647 : #7049# listbox to select chart elements 2009-08-05 11:43:40 +0200 iha r274645 : #7049# listbox to select chart elements 2009-07-24 19:46:50 +0200 iha r274318 : #i58163# #i69422# #i102820# enhance chart context menu 2009-07-24 16:23:13 +0200 iha r274313 : #i58163# #i69422# #i102820# enhance chart context menu 2009-07-24 16:13:22 +0200 iha r274311 : #i58163# #i69422# #i102820# enhance chart context menu --- offapi/com/sun/star/chart2/XDataSeries.idl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/offapi/com/sun/star/chart2/XDataSeries.idl b/offapi/com/sun/star/chart2/XDataSeries.idl index 206dac223578..eeebc966511c 100644 --- a/offapi/com/sun/star/chart2/XDataSeries.idl +++ b/offapi/com/sun/star/chart2/XDataSeries.idl @@ -58,22 +58,28 @@ module chart2 */ interface XDataSeries : ::com::sun::star::uno::XInterface { - /** set the coordinate system in which this series should be - represented. - */ -// void setCoordinateSystem( [in] XCoordinateSystem aCoordSystem ); - /** @returns the element at the specified index. - @param Index - specifies the position in the array. The first index is 0. + @param nIndex + specifies the index of the data point within the series. The first index is 0. @throws com::sun::star::lang::IndexOutOfBoundException if the index is not valid. */ ::com::sun::star::beans::XPropertySet getDataPointByIndex( [in] long nIndex ) raises( ::com::sun::star::lang::IndexOutOfBoundsException ); + + /** the formatting of the specified data point is cleared + + @param nIndex + specifies the index of the data point within the series. The first index is 0. + */ + void resetDataPoint( [in] long nIndex ); + + /** all data point formattings are cleared + */ + void resetAllDataPoints(); }; } ; // chart2 -- cgit From f70de5267d7d9b7b6946cd72fe26e91bb6ac8431 Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Fri, 11 Sep 2009 18:55:06 +0000 Subject: CWS-TOOLING: integrate CWS odff06 2009-09-10 18:58:49 +0200 dr r276042 : #i104954# excel export: fixed broken handling of unary operators 2009-09-06 19:30:43 +0200 er r275861 : warnings 2009-09-05 19:48:41 +0200 er r275849 : warnings; wntmsci12 tries to be too smart 2009-09-05 19:37:47 +0200 er r275848 : warnings 2009-09-03 22:45:42 +0200 er r275776 : #i5658# GetCellValueOrZero: missed the formula cell case 2009-09-03 14:28:41 +0200 er r275752 : #i90759# better description of ZTEST 2009-09-03 03:34:03 +0200 er r275739 : warnings 2009-09-03 03:31:19 +0200 er r275738 : warnings 2009-09-03 03:16:46 +0200 er r275737 : warnings 2009-09-03 03:11:42 +0200 er r275736 : CELLTYPE_DESTROYED only if DBG_UTIL 2009-09-03 03:06:31 +0200 er r275735 : warnings 2009-09-03 03:00:30 +0200 er r275734 : warnings 2009-09-03 02:32:35 +0200 er r275733 : fix broken rebase merge 2009-09-02 22:27:53 +0200 er r275730 : CWS-TOOLING: rebase CWS odff06 to trunk@275331 (milestone: DEV300:m56) 2009-09-02 14:45:05 +0200 er r275712 : #i5658# calculate with string operands as long as they unambiguously represent an integer or ISO 8601 date and/or time value 2009-08-29 22:05:31 +0200 er r275559 : #i99140# CONVERT_ADD new conversions as per ODFF; patch from , slightly changed 2009-08-25 13:23:59 +0200 er r275349 : #i90759# rewording of ZTEST description 2009-08-21 00:10:22 +0200 er r275204 : #i82007# correct description of POWER and parameters; patch from 2009-08-20 23:58:20 +0200 er r275203 : #i74704# B correct calculation for SP arguments 0 and 1; patch from 2009-08-20 22:58:57 +0200 er r275201 : #i90759# ZTEST correct calculation using the 3rd parameter sigma 2009-08-14 17:55:45 +0200 er r275000 : #i81214# LOOKUP with single values, data arrays and result arrays; based on a patch from 2009-08-11 00:47:48 +0200 er r274845 : unxlngi6 compiler warnings 2009-08-11 00:43:06 +0200 er r274844 : unxlngi6 compiler warnings 2009-08-10 23:59:05 +0200 er r274843 : #91351# make HYPERLINK accept and return numeric values, propagate errors 2009-07-08 18:46:00 +0200 dr r273846 : #i102022# export 3D refs to cond. formats and data validation 2009-07-02 17:59:40 +0200 dr r273667 : #i102702# adapt changes from sc/source/filter/excel 2009-07-02 15:20:37 +0200 dr r273656 : #i102702# reimplementation of formula token class export 2009-07-02 14:41:02 +0200 er r273653 : a surrogate with value 0x10000 is also valid (ran into when testing #i99900# Calc's UNICHAR function), and Unicode ends at 0x10ffff 2009-07-01 00:10:16 +0200 er r273536 : #i99900# iterateCodePoints: check index against string length to avoid assertion; caught this when testing Calc's new UNICHAR function, with the result of a surrogate pair forming one character. 2009-07-01 00:03:57 +0200 er r273535 : #i99900# new UNICODE and UNICHAR functions; patch from 2009-06-15 16:42:06 +0200 er r272999 : merge patch from #i102701 2009-06-15 11:15:16 +0200 dr r272970 : #i102702# in BIFF, the SKIP flag may be missing for the tAttrSkip token 2009-06-11 13:27:46 +0200 er r272867 : CWS-TOOLING: rebase CWS odff06 to trunk@272827 (milestone: DEV300:m50) 2009-04-30 18:28:02 +0200 er r271423 : #i94618# on status bar, ignore error of cell for COUNT and COUNTA if selection; patch from 2009-04-30 13:58:44 +0200 er r271413 : get rid of that ugly mail address thingie in RTL_LOGFILE_CONTEXT_AUTHOR introduced by CWS frmdlg ... 2009-04-30 12:32:44 +0200 er r271411 : #i94618# do not display error of cell for COUNT and COUNTA status bar functions 2009-04-30 01:32:38 +0200 er r271399 : #i101316# improve accuracy of STDEV on equal values; patch from 2009-04-30 01:18:54 +0200 er r271398 : #i97605# improve accuracy of ASINH and ACOSH; patch from 2009-04-30 00:46:00 +0200 er r271397 : #i59153# improve accuracy of MOD; patch from 2009-04-30 00:29:43 +0200 er r271396 : #i69069# improve accuracy of NORMSDIST and POISSON; patch from 2009-04-29 23:53:28 +0200 er r271395 : #i100119# NORMDIST and LOGNORMDIST optional parameters, plus improvement in accuracy also of NORMSDIST (part of i69069); patch from 2009-04-28 18:22:07 +0200 er r271337 : #i97052# REPLACE with no length of text to be removed simply inserts new text; patch from , slightly modified 2009-03-24 17:29:36 +0100 er r269982 : #i97091# moved implementation of erf() and erfc() from scaddins to sal to provide C99 functions for compilers lacking it --- sal/inc/rtl/math.h | 36 +++++++ sal/inc/rtl/math.hxx | 29 ++++++ sal/rtl/source/math.cxx | 250 ++++++++++++++++++++++++++++++++++++++++++++++++ sal/util/sal.map | 4 + 4 files changed, 319 insertions(+) diff --git a/sal/inc/rtl/math.h b/sal/inc/rtl/math.h index 4d72bcaa39d1..fed06e511b26 100644 --- a/sal/inc/rtl/math.h +++ b/sal/inc/rtl/math.h @@ -434,6 +434,42 @@ double SAL_CALL rtl_math_log1p(double fValue) SAL_THROW_EXTERN_C(); */ double SAL_CALL rtl_math_atanh(double fValue) SAL_THROW_EXTERN_C(); +/** Returns values of the Errorfunction erf. + + erf is part of the C99 standard, but not provided by some compilers. + + @param fValue + The value x in the term erf(x). + */ +double SAL_CALL rtl_math_erf(double fValue) SAL_THROW_EXTERN_C(); + +/** Returns values of the complement Errorfunction erfc. + + erfc is part of the C99 standard, but not provided by some compilers. + + @param fValue + The value x in the term erfc(x). + */ +double SAL_CALL rtl_math_erfc(double fValue) SAL_THROW_EXTERN_C(); + +/** Returns values of the inverse hyperbolic sine. + + asinh is part of the C99 standard, but not provided by some compilers. + + @param fValue + The value x in the term asinh(x). + */ +double SAL_CALL rtl_math_asinh(double fValue) SAL_THROW_EXTERN_C(); + +/** Returns values of the inverse hyperbolic cosine. + + acosh is part of the C99 standard, but not provided by some compilers. + + @param fValue + The value x in the term acosh(x). + */ +double SAL_CALL rtl_math_acosh(double fValue) SAL_THROW_EXTERN_C(); + #if defined __cplusplus } #endif /* __cplusplus */ diff --git a/sal/inc/rtl/math.hxx b/sal/inc/rtl/math.hxx index b61cf9b9806f..5760340cc6a4 100644 --- a/sal/inc/rtl/math.hxx +++ b/sal/inc/rtl/math.hxx @@ -221,6 +221,35 @@ inline double atanh(double fValue) return rtl_math_atanh(fValue); } +/** A wrapper around rtl_math_erf. + */ +inline double erf(double fValue) +{ + return rtl_math_erf(fValue); +} + +/** A wrapper around rtl_math_erfc. + */ +inline double erfc(double fValue) +{ + return rtl_math_erfc(fValue); +} + +/** A wrapper around rtl_math_asinh. + */ +inline double asinh(double fValue) +{ + return rtl_math_asinh(fValue); +} + +/** A wrapper around rtl_math_acosh. + */ +inline double acosh(double fValue) +{ + return rtl_math_acosh(fValue); +} + + /** Test equality of two values with an accuracy of the magnitude of the given values scaled by 2^-48 (4 bits roundoff stripped). diff --git a/sal/rtl/source/math.cxx b/sal/rtl/source/math.cxx index 3f41d5a9c105..a255ca21b13a 100644 --- a/sal/rtl/source/math.cxx +++ b/sal/rtl/source/math.cxx @@ -79,6 +79,130 @@ static double getN10Exp( int nExp ) return 1.0; } +/** Approximation algorithm for erf for 0 < x < 0.65. */ +void lcl_Erf0065( double x, double& fVal ) +{ + static const double pn[] = { + 1.12837916709551256, + 1.35894887627277916E-1, + 4.03259488531795274E-2, + 1.20339380863079457E-3, + 6.49254556481904354E-5 + }; + static const double qn[] = { + 1.00000000000000000, + 4.53767041780002545E-1, + 8.69936222615385890E-2, + 8.49717371168693357E-3, + 3.64915280629351082E-4 + }; + double fPSum = 0.0; + double fQSum = 0.0; + double fXPow = 1.0; + for ( unsigned int i = 0; i <= 4; ++i ) + { + fPSum += pn[i]*fXPow; + fQSum += qn[i]*fXPow; + fXPow *= x*x; + } + fVal = x * fPSum / fQSum; +} + +/** Approximation algorithm for erfc for 0.65 < x < 6.0. */ +void lcl_Erfc0600( double x, double& fVal ) +{ + double fPSum = 0.0; + double fQSum = 0.0; + double fXPow = 1.0; + const double *pn; + const double *qn; + + if ( x < 2.2 ) + { + static const double pn22[] = { + 9.99999992049799098E-1, + 1.33154163936765307, + 8.78115804155881782E-1, + 3.31899559578213215E-1, + 7.14193832506776067E-2, + 7.06940843763253131E-3 + }; + static const double qn22[] = { + 1.00000000000000000, + 2.45992070144245533, + 2.65383972869775752, + 1.61876655543871376, + 5.94651311286481502E-1, + 1.26579413030177940E-1, + 1.25304936549413393E-2 + }; + pn = pn22; + qn = qn22; + } + else /* if ( x < 6.0 ) this is true, but the compiler does not know */ + { + static const double pn60[] = { + 9.99921140009714409E-1, + 1.62356584489366647, + 1.26739901455873222, + 5.81528574177741135E-1, + 1.57289620742838702E-1, + 2.25716982919217555E-2 + }; + static const double qn60[] = { + 1.00000000000000000, + 2.75143870676376208, + 3.37367334657284535, + 2.38574194785344389, + 1.05074004614827206, + 2.78788439273628983E-1, + 4.00072964526861362E-2 + }; + pn = pn60; + qn = qn60; + } + + for ( unsigned int i = 0; i < 6; ++i ) + { + fPSum += pn[i]*fXPow; + fQSum += qn[i]*fXPow; + fXPow *= x; + } + fQSum += qn[6]*fXPow; + fVal = exp( -1.0*x*x )* fPSum / fQSum; +} + +/** Approximation algorithm for erfc for 6.0 < x < 26.54 (but used for all + x > 6.0). */ +void lcl_Erfc2654( double x, double& fVal ) +{ + static const double pn[] = { + 5.64189583547756078E-1, + 8.80253746105525775, + 3.84683103716117320E1, + 4.77209965874436377E1, + 8.08040729052301677 + }; + static const double qn[] = { + 1.00000000000000000, + 1.61020914205869003E1, + 7.54843505665954743E1, + 1.12123870801026015E2, + 3.73997570145040850E1 + }; + + double fPSum = 0.0; + double fQSum = 0.0; + double fXPow = 1.0; + + for ( unsigned int i = 0; i <= 4; ++i ) + { + fPSum += pn[i]*fXPow; + fQSum += qn[i]*fXPow; + fXPow /= x*x; + } + fVal = exp(-1.0*x*x)*fPSum / (x*fQSum); +} namespace { @@ -991,3 +1115,129 @@ double SAL_CALL rtl_math_atanh( double fValue ) SAL_THROW_EXTERN_C() { return 0.5 * rtl_math_log1p( 2.0 * fValue / (1.0-fValue) ); } + + +/** Parent error function (erf) that calls different algorithms based on the + value of x. It takes care of cases where x is negative as erf is an odd + function i.e. erf(-x) = -erf(x). + + Kramer, W., and Blomquist, F., 2000, Algorithms with Guaranteed Error Bounds + for the Error Function and the Complementary Error Function + + http://www.math.uni-wuppertal.de/wrswt/literatur_en.html + + @author Kohei Yoshida + + @see #i55735# + */ +double SAL_CALL rtl_math_erf( double x ) SAL_THROW_EXTERN_C() +{ + if( x == 0.0 ) + return 0.0; + + bool bNegative = false; + if ( x < 0.0 ) + { + x = fabs( x ); + bNegative = true; + } + + double fErf = 1.0; + if ( x < 1.0e-10 ) + fErf = (double) (x*1.1283791670955125738961589031215452L); + else if ( x < 0.65 ) + lcl_Erf0065( x, fErf ); + else + fErf = 1.0 - rtl_math_erfc( x ); + + if ( bNegative ) + fErf *= -1.0; + + return fErf; +} + + +/** Parent complementary error function (erfc) that calls different algorithms + based on the value of x. It takes care of cases where x is negative as erfc + satisfies relationship erfc(-x) = 2 - erfc(x). See the comment for Erf(x) + for the source publication. + + @author Kohei Yoshida + + @see #i55735#, moved from module scaddins (#i97091#) + + */ +double SAL_CALL rtl_math_erfc( double x ) SAL_THROW_EXTERN_C() +{ + if ( x == 0.0 ) + return 1.0; + + bool bNegative = false; + if ( x < 0.0 ) + { + x = fabs( x ); + bNegative = true; + } + + double fErfc = 0.0; + if ( x >= 0.65 ) + { + if ( x < 6.0 ) + lcl_Erfc0600( x, fErfc ); + else + lcl_Erfc2654( x, fErfc ); + } + else + fErfc = 1.0 - rtl_math_erf( x ); + + if ( bNegative ) + fErfc = 2.0 - fErfc; + + return fErfc; +} + +/** improved accuracy of asinh for |x| large and for x near zero + @see #i97605# + */ +double SAL_CALL rtl_math_asinh( double fX ) SAL_THROW_EXTERN_C() +{ + double fSign = 1.0; + if ( fX == 0.0 ) + return 0.0; + else + { + if ( fX < 0.0 ) + { + fX = - fX; + fSign = -1.0; + } + if ( fX < 0.125 ) + return fSign * rtl_math_log1p( fX + fX*fX / (1.0 + sqrt( 1.0 + fX*fX))); + else if ( fX < 1.25e7 ) + return fSign * log( fX + sqrt( 1.0 + fX*fX)); + else + return fSign * log( 2.0*fX); + } +} + +/** improved accuracy of acosh for x large and for x near 1 + @see #i97605# + */ +double SAL_CALL rtl_math_acosh( double fX ) SAL_THROW_EXTERN_C() +{ + volatile double fZ = fX - 1.0; + if ( fX < 1.0 ) + { + double fResult; + ::rtl::math::setNan( &fResult ); + return fResult; + } + else if ( fX == 1.0 ) + return 0.0; + else if ( fX < 1.1 ) + return rtl_math_log1p( fZ + sqrt( fZ*fZ + 2.0*fZ)); + else if ( fX < 1.25e7 ) + return log( fX + sqrt( fX*fX - 1.0)); + else + return log( 2.0*fX); +} diff --git a/sal/util/sal.map b/sal/util/sal.map index ad063f3794d4..d5faa563ae3f 100755 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -591,6 +591,10 @@ UDK_3.9 { # OOo 3.1 UDK_3.10 { # OOo 3.2 global: rtl_logfile_hasLogFile; + rtl_math_erf; + rtl_math_erfc; + rtl_math_asinh; + rtl_math_acosh; } UDK_3.9; PRIVATE_1.0 { -- cgit From 7e8e9768acd968b4b7422384a151f44066e7c5a1 Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Mon, 14 Sep 2009 09:36:01 +0000 Subject: #i10000# cws odfmetadata3 corrected --- offapi/com/sun/star/text/InContentMetadata.idl | 81 ++++++++++++++++ .../com/sun/star/text/textfield/MetadataField.idl | 102 +++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100755 offapi/com/sun/star/text/InContentMetadata.idl create mode 100755 offapi/com/sun/star/text/textfield/MetadataField.idl diff --git a/offapi/com/sun/star/text/InContentMetadata.idl b/offapi/com/sun/star/text/InContentMetadata.idl new file mode 100755 index 000000000000..7a7a20adc877 --- /dev/null +++ b/offapi/com/sun/star/text/InContentMetadata.idl @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: TextField.idl,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __com_sun_star_text_InContentMetadata_idl__ +#define __com_sun_star_text_InContentMetadata_idl__ + +#ifndef __com_sun_star_container_XEnumerationAccess_idl__ +#include +#endif + +#ifndef __com_sun_star_text_TextContent_idl__ +#include +#endif + +#ifndef __com_sun_star_rdf_XMetadatable_idl__ +#include +#endif + + +//============================================================================= + +module com { module sun { module star { module text { + +//============================================================================= + +/** is a TextContent that can be used to attach RDF metadata + to a range of text. + + @since OOo 3.2 + */ +service InContentMetadata +{ + //------------------------------------------------------------------------- + /** None of the properties of TextContent are + supported. */ + service com::sun::star::text::TextContent; + + //------------------------------------------------------------------------- + /** The InContentMetadata can have RDF metadata attached. */ + interface com::sun::star::rdf::XMetadatable; + + //------------------------------------------------------------------------- + /** The TextContents that are contained in the + annotated range of text can be enumerated. */ + interface com::sun::star::container::XEnumerationAccess; + +}; + + +//============================================================================= + +}; }; }; }; + +#endif diff --git a/offapi/com/sun/star/text/textfield/MetadataField.idl b/offapi/com/sun/star/text/textfield/MetadataField.idl new file mode 100755 index 000000000000..f82276213527 --- /dev/null +++ b/offapi/com/sun/star/text/textfield/MetadataField.idl @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: MetadataField.idl,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __com_sun_star_text_textfield_MetadataField_idl__ +#define __com_sun_star_text_textfield_MetadataField_idl__ + +#ifndef __com_sun_star_container_XEnumerationAccess_idl__ +#include +#endif + +#ifndef __com_sun_star_text_TextField_idl__ +#include +#endif + +#ifndef __com_sun_star_text_XText_idl__ +#include +#endif + +#ifndef __com_sun_star_rdf_XMetadatable_idl__ +#include +#endif + + +//============================================================================= + +module com { module sun { module star { module text { module textfield { + +//============================================================================= +/** is a TextField whose content is specified by RDF metadata. + + @since OOo 3.2 + + @see com::sun::star::rdf +*/ +service MetadataField +{ + //------------------------------------------------------------------------- + /** None of the properties of TextContent are + supported. */ + service com::sun::star::text::TextField; + + //------------------------------------------------------------------------- + /** The MetadataField can have RDF metadata attached. */ + interface com::sun::star::rdf::XMetadatable; + + //------------------------------------------------------------------------- + /** Allows for insertion of text content into, and creating cursors + that are bound within, the MetadataField. */ + interface com::sun::star::text::XText; + + //------------------------------------------------------------------------- + /** The TextContents that are contained in the + MetadataField can be enumerated. */ + interface com::sun::star::container::XEnumerationAccess; + + //------------------------------------------------------------------------- + /** this is the number format for this field. + @see com::sun::star::util::NumberFormatter + */ + [optional, property] long NumberFormat; + + //------------------------------------------------------------------------- + /** determines whether changes in language attributes at the + position of the text field also change the number format + as appropriate for this language. + */ + [optional, property] boolean IsFixedLanguage; +}; + +//============================================================================= + +}; }; }; }; }; + +#endif + -- cgit From c5249dfe913603ea3e679690eb4d8604a9c87deb Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Mon, 14 Sep 2009 10:57:16 +0000 Subject: CWS-TOOLING: integrate CWS chart41 2009-09-07 11:17:59 +0200 iha r275880 : #i104854# ODF: Fallback to bar chart for surface charts as long as surface charts are not implemented 2009-09-03 10:07:24 +0200 iha r275745 : #i104020# Y axis scaling problem with stock chart 2009-09-02 17:11:42 +0200 iha r275723 : #i103984# XChartDataArray / setDataArray broken 2009-09-02 17:05:16 +0200 iha r275721 : #i103984# XChartDataArray / setDataArray broken 2009-08-31 18:18:21 +0200 iha r275629 : #i103076# ODF, chart from MS-Office2007sp2 doesn't load caused be different xlink:href syntax 2009-08-28 18:35:52 +0200 iha r275548 : #i103460# ODF charts without svg:width and svg:height are not imported correctly 2009-08-28 18:35:25 +0200 iha r275547 : #i103460# ODF charts without svg:width and svg:height are not imported correctly 2009-08-28 18:25:45 +0200 iha r275546 : #i103460# ODF charts without svg:width and svg:height are not imported correctly 2009-08-28 18:23:21 +0200 iha r275544 : #i103460# ODF charts without svg:width and svg:height are not imported correctly 2009-08-28 18:18:34 +0200 iha r275543 : #i103460# ODF charts without svg:width and svg:height are not imported correctly 2009-08-27 15:57:20 +0200 iha r275490 : #i104160# report designer broken --- .../sun/star/chart2/XDefaultSizeTransmitter.idl | 67 ++++++++++++++++++++++ offapi/com/sun/star/chart2/makefile.mk | 1 + 2 files changed, 68 insertions(+) create mode 100644 offapi/com/sun/star/chart2/XDefaultSizeTransmitter.idl diff --git a/offapi/com/sun/star/chart2/XDefaultSizeTransmitter.idl b/offapi/com/sun/star/chart2/XDefaultSizeTransmitter.idl new file mode 100644 index 000000000000..a834bb310eda --- /dev/null +++ b/offapi/com/sun/star/chart2/XDefaultSizeTransmitter.idl @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: XDefaultSizeTransmitter.idl,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef com_sun_star_chart2_xdefaultsizetransmitter_idl +#define com_sun_star_chart2_xdefaultsizetransmitter_idl + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include +#endif + +#ifndef __com_sun_star_awt_Size_idl__ +#include +#endif + +module com +{ +module sun +{ +module star +{ +module chart2 +{ + +/** Allows to set a default size. This size will be used in case no further informations are available. + */ +interface XDefaultSizeTransmitter : ::com::sun::star::uno::XInterface +{ + /** set a default size + @param aSize_100TH_MM + specifies a size in hundredth mm. + */ + void setDefaultSize( [in] ::com::sun::star::awt::Size aSize_100TH_MM ); +}; + +} ; // chart2 +} ; // com +} ; // sun +} ; // star + + +#endif diff --git a/offapi/com/sun/star/chart2/makefile.mk b/offapi/com/sun/star/chart2/makefile.mk index d82862c69268..700ecc633d7a 100644 --- a/offapi/com/sun/star/chart2/makefile.mk +++ b/offapi/com/sun/star/chart2/makefile.mk @@ -85,6 +85,7 @@ IDLFILES= \ XDataInterpreter.idl \ XDataSeries.idl \ XDataSeriesContainer.idl \ + XDefaultSizeTransmitter.idl \ XDiagram.idl \ XDiagramProvider.idl \ XFastPropertyState.idl \ -- cgit From a580a1837bedb94e3c95fa48ce602a2ac04b7117 Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Mon, 14 Sep 2009 11:18:01 +0000 Subject: CWS-TOOLING: integrate CWS dba32g 2009-09-09 07:53:55 +0200 oj r275964 : replace strlen with rtl_str_getLength 2009-09-07 20:59:10 +0200 fs r275913 : disable the CopyTableWizard test until issue 104869 is fixed 2009-09-07 12:17:31 +0200 oj r275885 : #i104810# remove de as lang 2009-09-05 22:26:21 +0200 fs r275857 : protect StateChanged against re-entrance 2009-09-05 22:25:52 +0200 fs r275856 : don't attempt to classify the parent of a form as control 2009-09-05 22:25:29 +0200 fs r275855 : protect against re-entrance 2009-09-05 00:11:40 +0200 fs r275835 : #i10000# 2009-09-04 23:25:50 +0200 fs r275834 : #i10000# 2009-09-04 23:23:47 +0200 fs r275833 : #i10000# 2009-09-04 21:49:37 +0200 fs r275830 : #i10000# correct wrong conflict resolution 2009-09-04 20:59:51 +0200 fs r275829 : CWS-TOOLING: rebase CWS dba32g to trunk@275801 (milestone: DEV300:m57) 2009-09-04 11:08:32 +0200 oj r275791 : #i104780# new version 1.2.0 2009-09-03 22:29:21 +0200 fs r275775 : OSL_TRACE doesn't need \n anymore 2009-09-03 08:33:21 +0200 fs r275743 : CWS-TOOLING: rebase CWS dba32g to trunk@275331 (milestone: DEV300:m56) 2009-09-02 13:48:12 +0200 fs r275708 : removed useless include 2009-09-02 13:45:43 +0200 fs r275707 : more since tags, which are used across offapi/udkapi 2009-09-02 13:23:04 +0200 fs r275705 : should *not* have the dtor, copy ctor, and assignment operator compiler-generated, else we run into trouble as soon as the compiler creates different versions of our singleton member's static data in different libraries 2009-09-02 12:32:45 +0200 fs r275704 : AutoIncrementIsPrimaryKey is a driver setting, not a data source setting 2009-09-02 11:42:49 +0200 fs r275701 : URL meta data are meta data which are valid for all connections of this type, not per-data-source properties. Settings them as data source properties is a hack. 2009-09-02 08:43:34 +0200 fs r275696 : 3.x.x is not a valid 'since' tag 2009-09-01 16:05:24 +0200 fs r275665 : #i104686# don't treat controls bound to read-only columns as required 2009-09-01 13:10:22 +0200 fs r275657 : #i104574# use PageUp/Down to scroll through the complete page 2009-09-01 07:04:48 +0200 oj r275641 : #i104104# correct line ends 2009-08-31 15:52:34 +0200 fs r275612 : #i104410# 2009-08-31 12:29:05 +0200 fs r275596 : #i104364# 2009-08-31 12:28:56 +0200 fs r275595 : #i104364# 2009-08-31 11:43:09 +0200 fs r275593 : #i104649# JavaDriverClassPath is also a known JDBC-bridge setting 2009-08-31 11:41:37 +0200 fs r275592 : #i104649# 2009-08-28 21:48:27 +0200 fs r275552 : during #i96862#: renamed the configuration data which controls availability of certain DBA-related UI 2009-08-28 21:48:17 +0200 fs r275551 : #i96862# do not show the 'Create a new database' option when a) no embedded/dBase driver is installed or b) the configuration requests to hide the option 2009-08-28 21:47:19 +0200 fs r275550 : during #i96862#: renamed the configuration data which controls availability of certain DBA-related UI 2009-08-28 21:46:41 +0200 fs r275549 : #i96862# renamed and extended the configuration data which controls availability of certain DBA-related UI 2009-08-28 15:10:19 +0200 fs r275535 : #i96862# if no embedded driver is installed, use dBase for creating new DBs. If no dBase driver is installed, too, do not offer the 'Create new database' option 2009-08-28 14:03:04 +0200 fs r275532 : #i104454# allow multiple fields to display the same column 2009-08-28 13:14:00 +0200 fs r275528 : #i104584# driver meta data do not belong into a data source's settings 2009-08-28 13:09:57 +0200 fs r275527 : properly chech the MySQL type buttons (else next/back in the wizard leads to state with two buttons checked) 2009-08-28 13:09:17 +0200 fs r275526 : #i104584# driver meta data do not belong into a data source's settings 2009-08-28 13:07:18 +0200 fs r275525 : BooleanComparisonMode is a property, or a feature - but not a driver meta data 2009-08-28 11:00:31 +0200 fs r275521 : #i104580# 2009-08-28 10:40:05 +0200 fs r275519 : #i104577# correct assertion: If the template node type is ANY, then any value type is allowed 2009-08-28 10:09:30 +0200 fs r275518 : #i104575# implement Named Pipe UI 2009-08-28 10:09:07 +0200 fs r275517 : pass the trigger-event to IWindowOperator::operateOn / work with VclWindowEvents, not VclSimpleEvents 2009-08-27 14:27:36 +0200 fs r275484 : ImplPosTabPage: respect mbEmptyViewMargin for WINDOWALIGN_LEFT 2009-08-27 13:43:56 +0200 fs r275480 : merging latest changes from CWS dba32f herein 2009-08-27 13:23:07 +0200 fs r275475 : #i103882# 2009-08-27 11:56:55 +0200 fs r275466 : #i104544# SetState: Do not call Update at the window which we just set text for. It should (sic\!) not be needed, but causes trouble 2009-08-27 11:55:34 +0200 fs r275465 : #i104544# do not allow re-entrance for impl_ensureControl_nothrow Actually, this is part of the fix only. I also removed the code which triggered this re-entrance (from the grid control implementation), but to ensure it won't happen, again, I added some safety herein. 2009-08-27 10:14:11 +0200 fs r275459 : preparations for supporting a 'NamedPipe' parameter for the MySQL Connector/OOo 2009-08-27 10:13:21 +0200 fs r275458 : preparations for supporting a 'NamedPipe' setting for the MySQL Connector/OOo 2009-08-27 10:11:14 +0200 fs r275456 : outsourced the MySQLNative settings into a dedicated class, to not duplicate all the code in two tab page implementations 2009-08-26 14:18:13 +0200 fs r275422 : #i10000# 2009-08-26 13:26:36 +0200 fs r275419 : ignore output paths 2009-08-26 13:23:38 +0200 fs r275417 : support the LocalSocket property for the MySQL native driver 2009-08-26 13:17:05 +0200 fs r275416 : some re-factoring, to outsource the tab page for setting up the MySQLNative connection, into a dedicated class (needed later) 2009-08-26 13:15:15 +0200 fs r275415 : support a NoThousandSep property for NumericFormatters - I'm tired of correcting this at runtime, instead of controlling it in the resource 2009-08-26 11:45:08 +0200 fs r275410 : oops, 'flat' shouldn't have got lost 2009-08-26 09:38:57 +0200 fs r275398 : #i102631# when saving the document fails, ensure that the interaction handler really can handle/display the error 2009-08-26 09:37:05 +0200 fs r275397 : #i102631# don't let non-IO/RuntimeExceptions escape from DatabaseDocument::store*, wrap them into an IOException 2009-08-26 09:35:39 +0200 fs r275395 : let the default interaction handler implement XInteractionHandler2 2009-08-25 13:51:34 +0200 fs r275352 : #i102631# createTempFile: pass URL through FileHelper.getOOoCompatibleFileURL 2009-08-25 13:49:23 +0200 fs r275351 : #i102631# createTempFileURL: immediately delete the file implicitly created by createTempFile, we really only need the URL 2009-08-24 14:49:07 +0200 fs r275318 : #i10000# 2009-08-24 14:36:03 +0200 fs r275315 : properly terminate message with 0 character 2009-08-24 14:35:45 +0200 fs r275314 : trace method concepts in non-pro, if special flag is enabled 2009-08-24 14:24:17 +0200 fs r275312 : #i98973# filter some more events for grid control columns 2009-08-24 14:15:23 +0200 fs r275311 : #i98973# implement XComboBox for combo box cells 2009-08-24 13:39:24 +0200 fs r275308 : #i98973# do not display the 'actionPerformed' event for grid combo box columns 2009-08-24 12:52:03 +0200 fs r275303 : #i98973# implement XCheckBox and XButton for check box cells 2009-08-24 11:56:05 +0200 oj r275300 : #i104447# wrong default for orientation 2009-08-24 10:51:21 +0200 fs r275296 : in the script selector dialog, interpret a double click onto a function as OK 2009-08-24 10:50:56 +0200 fs r275295 : localize some to-be-displayed names, consolidate some code regarding form/control naming 2009-08-21 14:28:05 +0200 fs r275255 : #i98973# implement KeyListeners 2009-08-21 14:27:20 +0200 fs r275254 : #i98973# move the conversion VCL[Mouse|Key]Event->Awt[Mouse|Key]Event from vclxwindow.cxx to VCLUnoHelper 2009-08-21 14:08:50 +0200 fs r275248 : #i98973# implement Mouse- and MouseMotion-broadcasting 2009-08-21 13:31:08 +0200 fs r275244 : #i98973# implement text and change listeners at text cells 2009-08-21 12:47:38 +0200 fs r275234 : #i104399# some refactoring: If the MySQL Connector/OOo is installed, it registers for the sdbc:mysqlc: protocol (now known as DST_MYSQL_NATIVE_DIRECT). However, we do not want to display this in the UI, instead we display "MySQL" only, which collects DST_MYSQL_ODBC, DST_MYSQL_JDBC, and DST_MYSQL_NATIVE. 2009-08-21 12:45:18 +0200 fs r275232 : #i104399# also register for the sdbc:mysql:mysqlc protocol, decide at runtime (depending on the availability of sdbc:mysqlc:), whether it is really accepted. This prevents that the C/OOo extension needs to register *our* implementation name for the sdbc:mysql:mysqlc: protocol, which would be somewhat weird 2009-08-20 16:18:48 +0200 fs r275190 : merging the latest changes from CWS dba32f (which this CWS was created from) 2009-08-19 20:19:59 +0200 fs r275160 : add some spacing between the radios 2009-08-19 14:50:15 +0200 fs r275150 : #i98973# slightly refactoring the grid cell implementations, to prepare for proper events being fired. Implement focus events for the moment, more to come. 2009-08-19 10:53:38 +0200 fs r275142 : #i99936# initialize newly created models 2009-08-18 23:03:48 +0200 fs r275132 : merging latest changes from CWS dba32f 2009-08-18 15:14:08 +0200 fs r275110 : #i102819# SetColumnPos: SCROLL_CLIP is deadly here --- .../sun/star/task/DocumentMSPasswordRequest.idl | 2 +- sal/osl/w32/diagnose.c | 5 ++- stoc/source/inspect/introspection.cxx | 46 +++++++++++----------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/offapi/com/sun/star/task/DocumentMSPasswordRequest.idl b/offapi/com/sun/star/task/DocumentMSPasswordRequest.idl index 6e4adec10720..717e590c12ba 100644 --- a/offapi/com/sun/star/task/DocumentMSPasswordRequest.idl +++ b/offapi/com/sun/star/task/DocumentMSPasswordRequest.idl @@ -49,7 +49,7 @@ module com { module sun { module star { module task { the mentioned service are Abort and Approve.

- @since OOo 3.x.x + @since OOo 3.2 */ published exception DocumentMSPasswordRequest: PasswordRequest { diff --git a/sal/osl/w32/diagnose.c b/sal/osl/w32/diagnose.c index 6a67c1aa5b0f..b2d22808dcd7 100644 --- a/sal/osl/w32/diagnose.c +++ b/sal/osl/w32/diagnose.c @@ -92,7 +92,10 @@ void SAL_CALL osl_trace(const sal_Char* lpszFormat, ...) sal_Char szMessage[512]; szMessage[sizeof(szMessage)-1] = 0; written = _vsnprintf( szMessage, sizeof(szMessage) - 2, lpszFormat, args ); - szMessage[ written == -1 ? sizeof(szMessage) - 2 : written ] = '\n'; + if ( written == -1 ) + written = sizeof(szMessage) - 2; + szMessage[ written++ ] = '\n'; + szMessage[ written ] = 0; OutputDebugString( szMessage ); } diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index 011fafe9d6e9..518c6029ddd2 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -43,6 +43,7 @@ #endif #include #include +#include #include #include #include @@ -1421,28 +1422,29 @@ Sequence< Reference > ImplIntrospectionAccess::getMethods(sal_Int32 if( nConcept & MethodConcepts ) pDestMethods[ iDest++ ] = pSourceMethods[ i ]; - /* - // Methode mit Concepts ausgeben - const XIdlMethodRef& rxMethod = pSourceMethods[ i ]; - OUString aMethName = rxMethod->getName(); - String aNameStr = OOUStringToString(aMethName, CHARSET_SYSTEM); - String ConceptStr; - if( nConcept & DANGEROUS ) - ConceptStr += "DANGEROUS |"; - if( nConcept & PROPERTY ) - ConceptStr += "PROPERTY |"; - if( nConcept & LISTENER ) - ConceptStr += "LISTENER |"; - if( nConcept & ENUMERATION ) - ConceptStr += "ENUMERATION |"; - if( nConcept & NAMECONTAINER ) - ConceptStr += "NAMECONTAINER |"; - if( nConcept & INDEXCONTAINER ) - ConceptStr += "INDEXCONTAINER |"; - if( nConcept & NORMAL_IMPL ) - ConceptStr += "NORMAL_IMPL |"; - printf( "Method %ld: %s, Concepts = %s\n", i, aNameStr.GetStr(), ConceptStr.GetStr() ); - */ + #if OSL_DEBUG_LEVEL > 0 + static bool debug = false; + if ( debug ) + { + // Methode mit Concepts ausgeben + const Reference< XIdlMethod >& rxMethod = pSourceMethods[ i ]; + ::rtl::OString aNameStr = ::rtl::OUStringToOString( rxMethod->getName(), osl_getThreadTextEncoding() ); + ::rtl::OString ConceptStr; + if( nConcept & MethodConcept::DANGEROUS ) + ConceptStr += "DANGEROUS |"; + if( nConcept & MethodConcept::PROPERTY ) + ConceptStr += "PROPERTY |"; + if( nConcept & MethodConcept::LISTENER ) + ConceptStr += "LISTENER |"; + if( nConcept & MethodConcept::ENUMERATION ) + ConceptStr += "ENUMERATION |"; + if( nConcept & MethodConcept::NAMECONTAINER ) + ConceptStr += "NAMECONTAINER |"; + if( nConcept & MethodConcept::INDEXCONTAINER ) + ConceptStr += "INDEXCONTAINER |"; + OSL_TRACE( "Method %ld: %s, Concepts = %s", i, aNameStr.getStr(), ConceptStr.getStr() ); + } + #endif } // Auf die richtige Laenge bringen -- cgit From fcd1e07f252c3e44a5707e9e9ee429a5cef98fc8 Mon Sep 17 00:00:00 2001 From: Ivo Hinkelmann Date: Wed, 16 Sep 2009 11:45:54 +0000 Subject: CWS-TOOLING: integrate CWS l10nframework01 --- io/inc/makefile.mk | 6 ++++-- io/source/TextInputStream/makefile.mk | 2 ++ io/source/TextOutputStream/makefile.mk | 2 ++ io/source/acceptor/makefile.mk | 3 +++ io/source/connector/makefile.mk | 2 ++ io/source/stm/makefile.mk | 4 ++++ io/test/makefile.mk | 2 ++ io/test/stm/makefile.mk | 2 ++ pyuno/source/loader/makefile.mk | 6 ++++-- pyuno/source/module/makefile.mk | 5 ++++- pyuno/zipcore/makefile.mk | 7 ++++++- remotebridges/source/bridge/makefile.mk | 2 ++ remotebridges/source/dynamicloader/makefile.mk | 2 ++ remotebridges/source/factory/makefile.mk | 2 ++ remotebridges/source/unourl_resolver/makefile.mk | 2 ++ 15 files changed, 43 insertions(+), 6 deletions(-) diff --git a/io/inc/makefile.mk b/io/inc/makefile.mk index 7a15edc58216..ce9aa9036c6a 100644 --- a/io/inc/makefile.mk +++ b/io/inc/makefile.mk @@ -36,16 +36,18 @@ TARGET=inc # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk - +.IF "$(L10N_framework)"=="" # --- Files -------------------------------------------------------- # --- Targets ------------------------------------------------------- +.ENDIF # L10N_framework .INCLUDE : target.mk - +.IF "$(L10N_framework)"=="" .IF "$(ENABLE_PCH)"!="" ALLTAR : \ $(SLO)$/precompiled.pch \ $(SLO)$/precompiled_ex.pch .ENDIF # "$(ENABLE_PCH)"!="" +.ENDIF # L10N_framework diff --git a/io/source/TextInputStream/makefile.mk b/io/source/TextInputStream/makefile.mk index fcca36f0e576..1fb5aa33743a 100644 --- a/io/source/TextInputStream/makefile.mk +++ b/io/source/TextInputStream/makefile.mk @@ -37,6 +37,7 @@ ENABLE_EXCEPTIONS=TRUE # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = SLOFILES= \ @@ -59,5 +60,6 @@ SHL1RPATH= URELIB DEF1NAME= $(SHL1TARGET) # --- Targets ------------------------------------------------------ +.ENDIF # L10N_framework .INCLUDE : target.mk diff --git a/io/source/TextOutputStream/makefile.mk b/io/source/TextOutputStream/makefile.mk index 5359458ad8b4..7a4c0d6ba37f 100644 --- a/io/source/TextOutputStream/makefile.mk +++ b/io/source/TextOutputStream/makefile.mk @@ -37,6 +37,7 @@ ENABLE_EXCEPTIONS=TRUE # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = # ------------------------------------------------------------------ @@ -60,5 +61,6 @@ SHL1RPATH= URELIB DEF1NAME= $(SHL1TARGET) # --- Targets ------------------------------------------------------ +.ENDIF # L10N_framework .INCLUDE : target.mk diff --git a/io/source/acceptor/makefile.mk b/io/source/acceptor/makefile.mk index b537b2087078..843f26296dae 100644 --- a/io/source/acceptor/makefile.mk +++ b/io/source/acceptor/makefile.mk @@ -40,6 +40,7 @@ COMPRDB=$(SOLARBINDIR)$/udkapi.rdb # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = # ------------------------------------------------------------------ @@ -71,4 +72,6 @@ SHL1DEF= $(MISC)$/$(SHL1TARGET).def DEF1NAME= $(SHL1TARGET) # --- Targets ------------------------------------------------------ +.ENDIF # L10N_framework + .INCLUDE : target.mk diff --git a/io/source/connector/makefile.mk b/io/source/connector/makefile.mk index d726ac4c87c7..471f6b9d258f 100644 --- a/io/source/connector/makefile.mk +++ b/io/source/connector/makefile.mk @@ -40,6 +40,7 @@ COMPRDB=$(SOLARBINDIR)$/udkapi.rdb # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = # ------------------------------------------------------------------ @@ -71,5 +72,6 @@ SHL1DEF= $(MISC)$/$(SHL1TARGET).def DEF1NAME= $(SHL1TARGET) # --- Targets ------------------------------------------------------ +.ENDIF # L10N_framework .INCLUDE : target.mk diff --git a/io/source/stm/makefile.mk b/io/source/stm/makefile.mk index e4b8ad326b1d..43b6f2566ddf 100644 --- a/io/source/stm/makefile.mk +++ b/io/source/stm/makefile.mk @@ -32,6 +32,7 @@ PRJ=..$/.. PRJNAME=io TARGET = streams.uno + ENABLE_EXCEPTIONS=TRUE NO_BSYMBOLIC=TRUE COMP1TYPELIST = stm @@ -39,6 +40,7 @@ COMPRDB=$(SOLARBINDIR)$/udkapi.rdb # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = # --- Files -------------------------------------------------------- UNOUCRDEP=$(SOLARBINDIR)$/udkapi.rdb @@ -73,5 +75,7 @@ DEF1NAME= $(SHL1TARGET) # --- Targets ------------------------------------------------------ +.ENDIF # L10N_framework + .INCLUDE : target.mk diff --git a/io/test/makefile.mk b/io/test/makefile.mk index af032ba8efb1..b7acf670684f 100644 --- a/io/test/makefile.mk +++ b/io/test/makefile.mk @@ -41,6 +41,7 @@ ENABLE_EXCEPTIONS=TRUE # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" # --- Files -------------------------------------------------------- OBJFILES= $(OBJ)$/testcomponent.obj \ @@ -90,5 +91,6 @@ $(BIN)$/applicat.rdb: $(SOLARBINDIR)$/udkapi.rdb rm -f $@ regmerge $@ / $? +.ENDIF # L10N_framework .INCLUDE : target.mk diff --git a/io/test/stm/makefile.mk b/io/test/stm/makefile.mk index cb5f6b0c803a..01d334edb998 100644 --- a/io/test/stm/makefile.mk +++ b/io/test/stm/makefile.mk @@ -37,6 +37,7 @@ ENABLE_EXCEPTIONS=TRUE # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" # --- Files -------------------------------------------------------- UNOUCRDEP=$(SOLARBINDIR)$/udkapi.rdb UNOUCRRDB=$(SOLARBINDIR)$/udkapi.rdb @@ -97,5 +98,6 @@ DEF1EXPORTFILE= exports.dxp # --- Targets ------------------------------------------------------ +.ENDIF # L10N_framework .INCLUDE : target.mk diff --git a/pyuno/source/loader/makefile.mk b/pyuno/source/loader/makefile.mk index 11ece4796301..6acb867618be 100644 --- a/pyuno/source/loader/makefile.mk +++ b/pyuno/source/loader/makefile.mk @@ -37,7 +37,7 @@ ENABLE_EXCEPTIONS=TRUE # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk - +.IF "$(L10N_framework)"=="" DLLPRE = #------------------------------------------------------------------- @@ -101,9 +101,10 @@ COMPONENTS= \ ALL : ALLTAR \ $(DLLDEST)$/pythonloader.py \ $(DLLDEST)$/pyuno_services.rdb +.ENDIF # L10N_framework .INCLUDE : target.mk - +.IF "$(L10N_framework)"=="" $(DLLDEST)$/%.py: %.py cp $? $@ @@ -115,4 +116,5 @@ $(DLLDEST)$/pyuno_services.rdb : makefile.mk $(DLLDEST)$/$(DLLPRE)$(TARGET)$(DLL cd $(DLLDEST) && $(REGCOMP) -register -r pyuno_services.tmp -wop $(foreach,i,$(COMPONENTS) -c $(i)) .ENDIF # "$(GUI)$(COM)"=="WNTGCC" cd $(DLLDEST) && mv pyuno_services.tmp pyuno_services.rdb +.ENDIF # L10N_framework diff --git a/pyuno/source/module/makefile.mk b/pyuno/source/module/makefile.mk index cb1ef41f0784..2357d0062ed0 100644 --- a/pyuno/source/module/makefile.mk +++ b/pyuno/source/module/makefile.mk @@ -39,6 +39,7 @@ LINKFLAGSDEFS = # do not fail with missing symbols # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" #------------------------------------------------------------------- .IF "$(OS)$(CPU)$(COMEX)" == "SOLARISS4" @@ -128,10 +129,11 @@ ALLTAR : \ $(DLLDEST)$/unohelper.py \ $(PYUNO_MODULE) \ $(MISC)$/$(PYUNORC) +.ENDIF .ENDIF .INCLUDE : target.mk - +.IF "$(L10N_framework)"=="" $(DLLDEST)$/%.py: %.py cp $? $@ @@ -163,4 +165,5 @@ $(MISC)$/$(PYUNORC) : pyuno $(MISC)$/pyuno.flt : pyuno.flt -rm -f $@ cat $? > $@ +.ENDIF # L10N_framework diff --git a/pyuno/zipcore/makefile.mk b/pyuno/zipcore/makefile.mk index f46106dc8afe..a820c1a59f4f 100755 --- a/pyuno/zipcore/makefile.mk +++ b/pyuno/zipcore/makefile.mk @@ -36,7 +36,7 @@ TARGET=zipcore LIBTARGET=NO .INCLUDE : settings.mk - +.IF "$(L10N_framework)"=="" UWINAPILIB = .IF "$(SYSTEM_PYTHON)" == "YES" || "$(GUI)" == "OS2" @@ -74,6 +74,7 @@ APP1RPATH = BRAND OBJFILES = $(OBJ)$/python.obj .ENDIF + .INCLUDE: target.mk ALLTAR: \ @@ -129,3 +130,7 @@ $(DESTROOT)$/bin$/python$(EXECPOST) : $(SOLARBINDIR)$/python$(EXECPOST) .ENDIF .ENDIF +.ELSE +ivo: + $(ECHO) +.ENDIF # L10N_framework diff --git a/remotebridges/source/bridge/makefile.mk b/remotebridges/source/bridge/makefile.mk index ef02b1bcebc9..75b5f3a6152e 100644 --- a/remotebridges/source/bridge/makefile.mk +++ b/remotebridges/source/bridge/makefile.mk @@ -38,6 +38,7 @@ COMP1TYPELIST = remotebridge # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = # ------------------------------------------------------------------ @@ -61,6 +62,7 @@ SHL1DEF= $(MISC)$/$(SHL1TARGET).def SHL1RPATH= URELIB DEF1NAME= $(SHL1TARGET) +.ENDIF # L10N_framework # --- Targets ------------------------------------------------------ .INCLUDE : target.mk diff --git a/remotebridges/source/dynamicloader/makefile.mk b/remotebridges/source/dynamicloader/makefile.mk index 1a4364c74062..95a80e107ffb 100755 --- a/remotebridges/source/dynamicloader/makefile.mk +++ b/remotebridges/source/dynamicloader/makefile.mk @@ -39,6 +39,7 @@ COMP1TYPELIST = dynamicloader # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = # ------------------------------------------------------------------ @@ -65,6 +66,7 @@ SHL1DEF=$(MISC)$/$(SHL1TARGET).def DEF1NAME= $(SHL1TARGET) +.ENDIF # L10N_framework # --- Targets ------------------------------------------------------ diff --git a/remotebridges/source/factory/makefile.mk b/remotebridges/source/factory/makefile.mk index 280ed38829f8..97eb02415a47 100644 --- a/remotebridges/source/factory/makefile.mk +++ b/remotebridges/source/factory/makefile.mk @@ -38,6 +38,7 @@ COMP1TYPELIST = brdgfctr # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = # ------------------------------------------------------------------ @@ -61,6 +62,7 @@ SHL1DEF= $(MISC)$/$(SHL1TARGET).def SHL1RPATH= URELIB DEF1NAME= $(SHL1TARGET) +.ENDIF # L10N_framework # --- Targets ------------------------------------------------------ diff --git a/remotebridges/source/unourl_resolver/makefile.mk b/remotebridges/source/unourl_resolver/makefile.mk index bb005dc167c4..81f8b1c67609 100644 --- a/remotebridges/source/unourl_resolver/makefile.mk +++ b/remotebridges/source/unourl_resolver/makefile.mk @@ -38,6 +38,7 @@ COMP1TYPELIST = uuresolver # --- Settings ----------------------------------------------------- .INCLUDE : settings.mk +.IF "$(L10N_framework)"=="" DLLPRE = # ------------------------------------------------------------------ @@ -60,6 +61,7 @@ SHL1DEF= $(MISC)$/$(SHL1TARGET).def SHL1RPATH= URELIB DEF1NAME= $(SHL1TARGET) +.ENDIF # L10N_framework # --- Targets ------------------------------------------------------ -- cgit From 36fc972942594e186e6924bfc1568bfb0096733e Mon Sep 17 00:00:00 2001 From: Ivo Hinkelmann Date: Wed, 16 Sep 2009 13:55:36 +0000 Subject: CWS-TOOLING: integrate CWS impressnotes01 2009-09-11 13:52:41 +0200 cl r276061 : CWS-TOOLING: rebase CWS impressnotes01 to trunk@276043 (milestone: DEV300:m58) 2009-09-10 15:44:57 +0200 cl r276039 : #i103139# continued work on the impress annotation feature 2009-09-10 14:52:31 +0200 cl r276032 : #i103139# continued work on the impress annotation feature 2009-09-10 14:50:32 +0200 cl r276031 : #i103139# continued work on the impress annotation feature 2009-09-10 14:48:29 +0200 cl r276030 : #i103139# continued work on the impress annotation feature 2009-09-10 11:36:11 +0200 cl r276027 : #i103139# continued work on the impress annotation feature 2009-09-09 20:22:41 +0200 cl r276018 : #i103139# continued work on the impress annotation feature 2009-09-09 20:21:45 +0200 cl r276017 : #i103139# continued work on the impress annotation feature 2009-09-09 19:32:29 +0200 sj r276015 : #i103139# added import of comments (ppt binary) 2009-09-09 19:31:07 +0200 sj r276014 : #i103139# added import of comments (ppt binary) 2009-09-09 19:16:41 +0200 cl r276011 : #i103139# continued work on the impress annotation feature 2009-09-09 19:15:19 +0200 cl r276010 : #i103139# continued work on the impress annotation feature 2009-09-09 16:27:19 +0200 cl r276001 : #i104579# fixed isEmptyPresObj() 2009-09-09 15:12:02 +0200 cl r275997 : #i103139# continued work on the impress annotation feature 2009-09-09 15:06:29 +0200 sj r275996 : #i103139# added import of comments (ppt binary) 2009-09-09 14:53:01 +0200 cl r275995 : #i103139# continued work on the impress annotation feature 2009-09-09 14:51:32 +0200 cl r275994 : #i103139# continued work on the impress annotation feature 2009-09-09 12:11:17 +0200 cl r275982 : #i103139# continued work on the impress annotation feature 2009-09-09 11:47:55 +0200 cl r275981 : #i103139# continued work on the impress annotation feature 2009-09-09 11:47:23 +0200 cl r275980 : #i103139# continued work on the impress annotation feature 2009-09-09 11:44:47 +0200 cl r275978 : #i104315# added missing tab pages 2009-09-08 16:04:44 +0200 cl r275936 : #i103139# continued work on the impress annotation feature 2009-09-08 16:03:28 +0200 cl r275935 : #i103139# continued work on the impress annotation feature 2009-09-08 11:45:47 +0200 cl r275920 : #i103139# continued work on the impress annotation feature 2009-09-08 11:41:51 +0200 cl r275919 : #i103139# continued work on the impress annotation feature 2009-09-07 18:30:55 +0200 cl r275910 : #i103139# continued work on the impress annotation feature 2009-09-07 18:29:37 +0200 cl r275909 : #i103139# continued work on the impress annotation feature 2009-09-07 17:25:43 +0200 cl r275905 : #i103139# continued work on the impress annotation feature 2009-09-07 12:00:28 +0200 cl r275884 : #i103139# continued work on the impress annotation feature 2009-09-06 14:14:00 +0200 cl r275859 : #i103139# continued work on the impress annotation feature 2009-09-05 20:57:24 +0200 cl r275854 : #i103139# continued work on the impress annotation feature 2009-09-05 20:56:29 +0200 cl r275853 : #i103139# continued work on the impress annotation feature 2009-09-05 20:55:27 +0200 cl r275852 : #i103139# continued work on the impress annotation feature 2009-09-05 20:11:42 +0200 cl r275851 : #i103139# continued work on the impress annotation feature 2009-09-05 20:11:09 +0200 cl r275850 : #i103139# continued work on the impress annotation feature 2009-09-05 17:43:33 +0200 cl r275845 : #i103139# continued work on the impress annotation feature 2009-09-05 17:04:41 +0200 cl r275843 : #i103139# continued work on the impress annotation feature 2009-09-05 17:03:26 +0200 cl r275842 : #i103139# continued work on the impress annotation feature 2009-09-05 17:02:53 +0200 cl r275841 : #i103139# continued work on the impress annotation feature 2009-09-05 13:15:04 +0200 pl r275839 : #i104823# WB_NEEDSFOCUS 2009-09-05 13:14:41 +0200 pl r275838 : #i104823# WB_NEEDSFOCUS 2009-09-04 17:48:21 +0200 cl r275826 : #i103139# continued work on the impress annotation feature 2009-09-04 17:35:03 +0200 cl r275825 : #i103139# continued work on the impress annotation feature 2009-09-04 17:15:46 +0200 cl r275824 : #i103139# continued work on the impress annotation feature 2009-09-04 17:12:54 +0200 cl r275823 : #i103139# continued work on the impress annotation feature 2009-09-04 17:05:23 +0200 cl r275822 : #i103139# continued work on the impress annotation feature 2009-09-04 16:48:28 +0200 cl r275820 : #i103139# continued work on the impress annotation feature 2009-09-04 16:44:02 +0200 cl r275818 : #i103139# continued work on the impress annotation feature 2009-09-04 16:43:23 +0200 cl r275817 : #i103139# continued work on the impress annotation feature 2009-09-04 16:06:04 +0200 cl r275812 : #i103139# continued work on the impress annotation feature 2009-09-04 16:05:45 +0200 cl r275811 : #i103139# continued work on the impress annotation feature 2009-09-04 15:04:33 +0200 cl r275806 : #i103139# continued work on the impress annotation feature 2009-09-04 11:43:14 +0200 cl r275795 : #i103139# continued work on the impress annotation feature 2009-09-04 11:27:10 +0200 cl r275793 : #i103139# continued work on the impress annotation feature 2009-09-04 11:10:02 +0200 cl r275792 : #i103139# continued work on the impress annotation feature 2009-09-04 11:07:05 +0200 cl r275790 : #i103139# continued work on the impress annotation feature 2009-09-04 11:05:01 +0200 cl r275789 : #i103139# continued work on the impress annotation feature 2009-09-04 10:55:51 +0200 cl r275785 : #i103139# renamed notes to comments 2009-09-04 10:54:57 +0200 cl r275784 : #i103139# renamed notes to comments 2009-09-03 20:37:35 +0200 cl r275772 : #i103139# continued work on the impress annotation feature 2009-09-03 20:35:31 +0200 cl r275771 : #i103139# continued work on the impress annotation feature 2009-09-01 18:17:55 +0200 cl r275680 : #i103139# continued work on the impress annotation feature 2009-09-01 18:15:08 +0200 cl r275678 : #i103139# continued work on the impress annotation feature 2009-09-01 18:13:38 +0200 cl r275677 : #i103139# continued work on the impress annotation feature 2009-08-18 12:35:42 +0200 cl r275089 : fixed merge error 2009-08-18 11:39:58 +0200 cl r275086 : CWS-TOOLING: rebase CWS impressnotes01 to trunk@275001 (milestone: DEV300:m55) 2009-07-30 13:45:10 +0200 cl r274481 : fixed merge errrors 2009-07-30 13:41:21 +0200 cl r274480 : fixed merge errrors 2009-07-30 13:39:40 +0200 cl r274478 : fixed merge errrors 2009-07-22 18:07:30 +0200 cl r274256 : CWS-TOOLING: rebase CWS impressnotes01 to trunk@273858 (milestone: DEV300:m52) 2009-07-21 17:21:31 +0200 cl r274208 : merging 2009-07-20 14:28:34 +0200 cl r274137 : #i103139# annotation support for impress 2009-07-20 14:28:04 +0200 cl r274136 : #i103139# annotation support for impress 2009-07-20 14:27:20 +0200 cl r274135 : #i103139# annotation support for impress 2009-07-20 14:21:17 +0200 cl r274134 : #i103139# annotation support for impress 2009-07-20 14:20:56 +0200 cl r274133 : #i103139# annotation support for impress 2009-07-20 14:20:09 +0200 cl r274132 : #i103139# annotation support for impress 2009-07-20 14:19:00 +0200 cl r274131 : #i103139# annotation support for impress 2009-07-20 14:17:50 +0200 cl r274130 : #i103139# annotation support for impress 2009-07-20 14:12:24 +0200 cl r274129 : #i103139# annotation support for impress 2009-07-20 13:52:03 +0200 cl r274128 : #i103139# annotation support for impress 2009-07-20 13:51:11 +0200 cl r274127 : #i103139# annotation support for impress 2009-07-20 13:48:59 +0200 cl r274126 : #i103139# annotation support for impress 2009-07-20 13:43:56 +0200 cl r274125 : #i103139# annotation support for impress 2009-07-20 13:31:55 +0200 cl r274123 : #i103139# annotation support for impress 2009-07-20 13:30:45 +0200 cl r274122 : #i103139# annotation support for impress --- offapi/com/sun/star/modules.idl | 3 + offapi/com/sun/star/office/XAnnotation.idl | 105 +++++++++++++++++++++ offapi/com/sun/star/office/XAnnotationAccess.idl | 75 +++++++++++++++ .../com/sun/star/office/XAnnotationEnumeration.idl | 74 +++++++++++++++ offapi/com/sun/star/office/makefile.mk | 51 ++++++++++ offapi/prj/build.lst | 3 +- offapi/util/makefile.mk | 1 + offuh/prj/d.lst | 4 +- 8 files changed, 314 insertions(+), 2 deletions(-) create mode 100644 offapi/com/sun/star/office/XAnnotation.idl create mode 100644 offapi/com/sun/star/office/XAnnotationAccess.idl create mode 100644 offapi/com/sun/star/office/XAnnotationEnumeration.idl create mode 100644 offapi/com/sun/star/office/makefile.mk diff --git a/offapi/com/sun/star/modules.idl b/offapi/com/sun/star/modules.idl index 4a0f4efcd12c..d91c8edad1ff 100644 --- a/offapi/com/sun/star/modules.idl +++ b/offapi/com/sun/star/modules.idl @@ -90,6 +90,9 @@ module datatransfer {}; /// Office document related interfaces. module document {}; +/// Office document content related interfaces. +module office {}; + /// Drawing and shape specific interfaces. module drawing {}; diff --git a/offapi/com/sun/star/office/XAnnotation.idl b/offapi/com/sun/star/office/XAnnotation.idl new file mode 100644 index 000000000000..ff7c4127bb82 --- /dev/null +++ b/offapi/com/sun/star/office/XAnnotation.idl @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: XGalleryItem.idl,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __com_sun_star_office_XAnnotation_idl__ +#define __com_sun_star_office_XAnnotation_idl__ + +#ifndef __com_sun_star_beans_XPropertySet_idl__ +#include +#endif + +#ifndef __com_sun_star_beans_XMultiPropertySet_idl__ +#include +#endif + +#ifndef __com_sun_star_util_DateTime_idl__ +#include +#endif + +#ifndef __com_sun_star_text_XText_idl__ +#include +#endif + +#ifndef __com_sun_star_geometry_RealPoint2D_idl__ +#include +#endif + +#ifndef __com_sun_star_geometry_RealSize2D_idl__ +#include +#endif + +#ifndef __com_sun_star_lang_XComponent_idl__ +#include +#endif + +//============================================================================= + +module com { module sun { module star { module office { + +//============================================================================= + +/** This interface gives access to an annotation inside a document. + */ +interface XAnnotation +{ + /** All attributes are also available as properties. */ + interface ::com::sun::star::beans::XPropertySet; + + /** manages the lifetime of this annotation, should only be used + by the owner of the annotation which should be the document itself. */ + interface ::com::sun::star::lang::XComponent; + + /** a reference to the document content this annotation is anchored to. */ + [attribute, readonly] any Anchor; + + /** this is an optional position that gives the user interface a hint where + the annotation should be rendered. This could be an offset to the + annotations anchor. */ + [attribute] ::com::sun::star::geometry::RealPoint2D Position; + + /** this is an optional size that gives the user interface a hint how + large the annotation should be rendered. */ + [attribute] ::com::sun::star::geometry::RealSize2D Size; + + /** stores the full name of the author who created this annotation. */ + [attribute] string Author; + + /** stores the date and time this annotation was last edited. */ + [attribute] ::com::sun::star::util::DateTime DateTime; + + /** gives access to the annotations text. */ + [attribute, readonly] ::com::sun::star::text::XText TextRange; +}; + +//============================================================================= + +}; }; }; }; + +#endif diff --git a/offapi/com/sun/star/office/XAnnotationAccess.idl b/offapi/com/sun/star/office/XAnnotationAccess.idl new file mode 100644 index 000000000000..074312ef6fec --- /dev/null +++ b/offapi/com/sun/star/office/XAnnotationAccess.idl @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: XGalleryItem.idl,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __com_sun_star_office_XAnnotationAccess_idl__ +#define __com_sun_star_office_XAnnotationAccess_idl__ + +#ifndef __com_sun_star_office_XAnnotationEnumeration_idl__ +#include +#endif + +#ifndef __com_sun_star_lang_IllegalArgumentException_idl__ +#include +#endif + +#ifndef __com_sun_star_office_XAnnotation_idl__ +#include +#endif + +//============================================================================= + +module com { module sun { module star { module office { + +//============================================================================= + +/** This interface gives access to the annotation for a document content. + */ +interface XAnnotationAccess +{ + /** creates a new annotation and inserts it into the document content. + */ + XAnnotation createAndInsertAnnotation(); + + /** removes the annotation from this document content. + */ + void removeAnnotation( [in] XAnnotation annotation ) raises ( com::sun::star::lang::IllegalArgumentException ); + + /** @returns + a new enumeration object for this annotation container. + It returns NULL if there are no objects in this container. + */ + XAnnotationEnumeration createAnnotationEnumeration(); +}; + +//============================================================================= + +}; }; }; }; + +#endif diff --git a/offapi/com/sun/star/office/XAnnotationEnumeration.idl b/offapi/com/sun/star/office/XAnnotationEnumeration.idl new file mode 100644 index 000000000000..e81666e0b698 --- /dev/null +++ b/offapi/com/sun/star/office/XAnnotationEnumeration.idl @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: XEnumeration.idl,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_office_XAnnotationEnumeration_idl__ +#define __com_sun_star_office_XAnnotationEnumeration_idl__ + +#ifndef __com_sun_star_office_XAnnotation_idl__ +#include +#endif + +#ifndef __com_sun_star_container_NoSuchElementException_idl__ +#include +#endif + +//============================================================================= + +module com { module sun { module star { module office { + +//============================================================================= + +/** An enumeration for a set of annotations. + */ +interface XAnnotationEnumeration +{ + //------------------------------------------------------------------------- + + /** tests whether this enumeration contains more elements. + */ + boolean hasMoreElements(); + + //------------------------------------------------------------------------- + + /** @returns + the next element of this enumeration. + + @throws NoSuchElementException + if no more elements exist. + */ + XAnnotation nextElement() + raises( com::sun::star::container::NoSuchElementException ); + +}; + +//============================================================================= + +}; }; }; }; + +#endif diff --git a/offapi/com/sun/star/office/makefile.mk b/offapi/com/sun/star/office/makefile.mk new file mode 100644 index 000000000000..404c23c45e32 --- /dev/null +++ b/offapi/com/sun/star/office/makefile.mk @@ -0,0 +1,51 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.5 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/..$/.. +PRJNAME=offapi +TARGET=cssoffice +PACKAGE=com$/sun$/star$/office + +# --- Settings ----------------------------------------------------- + +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# ------------------------------------------------------------------------ + +IDLFILES=\ + XAnnotation.idl\ + XAnnotationEnumeration.idl\ + XAnnotationAccess.idl + +# ------------------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : $(PRJ)$/util$/target.pmk diff --git a/offapi/prj/build.lst b/offapi/prj/build.lst index 6b4a0b95a054..6ddea0190596 100644 --- a/offapi/prj/build.lst +++ b/offapi/prj/build.lst @@ -103,5 +103,6 @@ oa offapi\com\sun\star\xml\wrapper nmake - all oa_wrapper oa_sax NULL oa offapi\com\sun\star\geometry nmake - all oa_geometry NULL oa offapi\com\sun\star\rendering nmake - all oa_rendering oa_geometry NULL oa offapi\com\sun\star\rdf nmake - all oa_rdf oa_datatransfer oa_text NULL +oa offapi\com\sun\star\office nmake - all oa_office oa_text NULL oa offapi\drafts\com\sun\star\form nmake - all oa_drafts_form NULL -oa offapi\util nmake - all oa_util oa_auth oa_awt oa_awttree oa_awtgrid oa_chart oa_chart2 oa_chart2_data oa_config oa_configbootstrap oa_configbackend oa_configbackend_xml oa_datatrans_clip oa_datatrans_dnd oa_datatransfer oa_docu oa_draw oa_draw_framework oa_embed oa_fcomp oa_finsp oa_fcontr oa_fieldmaster oa_form oa_xforms oa_formula oa_frame oa_i18n oa_inst oa_ldap oa_ling2 oa_logging oa_mail oa_media oa_mozilla oa_packages oa_manifest oa_zippackage oa_plug oa_pres oa_animations oa_putil oa_resrc oa_sax oa_xml_input oa_scan oa_sdb oa_sdbtools oa_sdbapp oa_sdbc oa_sdbcx oa_setup oa_sheet oa_style oa_svg oa_sync oa_sync2 oa_system oa_table oa_task oa_text oa_textfield oa_docinfo oa_ucb oa_view oa_xml oa_xml_dom oa_xml_xpath oa_xml_views oa_xml_events oa_image oa_xsd oa_inspection oa_ui oa_ui_dialogs oa_accessibility oa_form_binding oa_form_validation oa_form_submission oa_fruntime oa_geometry oa_rendering oa_sfprovider oa_sfbrowse oa_drafts_form oa_deployment oa_deploymenttest oa_deployment_ui oa_frame_status oa_gallery oa_graphic oa_security oa_crypto_sax oa_crypto oa_csax oa_wrapper oa_script oa_smarttags oa_report oa_reportins oa_reportmeta oa_rdf oa_oooimprovement NULL +oa offapi\util nmake - all oa_util oa_auth oa_awt oa_awttree oa_awtgrid oa_chart oa_chart2 oa_chart2_data oa_config oa_configbootstrap oa_configbackend oa_configbackend_xml oa_datatrans_clip oa_datatrans_dnd oa_datatransfer oa_docu oa_draw oa_draw_framework oa_embed oa_fcomp oa_finsp oa_fcontr oa_fieldmaster oa_form oa_xforms oa_formula oa_frame oa_i18n oa_inst oa_ldap oa_ling2 oa_logging oa_mail oa_media oa_mozilla oa_packages oa_manifest oa_zippackage oa_plug oa_pres oa_animations oa_putil oa_resrc oa_sax oa_xml_input oa_scan oa_sdb oa_sdbtools oa_sdbapp oa_sdbc oa_sdbcx oa_setup oa_sheet oa_style oa_svg oa_sync oa_sync2 oa_system oa_table oa_task oa_text oa_textfield oa_docinfo oa_ucb oa_view oa_xml oa_xml_dom oa_xml_xpath oa_xml_views oa_xml_events oa_image oa_xsd oa_inspection oa_ui oa_ui_dialogs oa_accessibility oa_form_binding oa_form_validation oa_form_submission oa_fruntime oa_geometry oa_rendering oa_sfprovider oa_sfbrowse oa_drafts_form oa_deployment oa_deploymenttest oa_deployment_ui oa_frame_status oa_gallery oa_graphic oa_security oa_crypto_sax oa_crypto oa_csax oa_wrapper oa_script oa_smarttags oa_report oa_reportins oa_reportmeta oa_rdf oa_oooimprovement oa_office NULL diff --git a/offapi/util/makefile.mk b/offapi/util/makefile.mk index fcf3e4bd6c02..b0fa7a30cf46 100644 --- a/offapi/util/makefile.mk +++ b/offapi/util/makefile.mk @@ -144,6 +144,7 @@ UNOIDLDBFILES= \ $(UCR)$/cssreport.db \ $(UCR)$/cssrptins.db \ $(UCR)$/cssrptmeta.db \ + $(UCR)$/cssoffice.db \ $(UCR)$/cssrdf.db diff --git a/offuh/prj/d.lst b/offuh/prj/d.lst index 0e85b261e8e2..bedbc8d112d4 100644 --- a/offuh/prj/d.lst +++ b/offuh/prj/d.lst @@ -51,6 +51,7 @@ mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\lang mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\linguistic2 mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\logging mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\oooimprovement +mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\office mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\mail mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\media mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\packages @@ -226,6 +227,8 @@ mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\rdf ..\%__SRC%\inc\offuh\com\sun\star\linguistic2\*.hpp %_DEST%\inc%_EXT%\offuh\com\sun\star\linguistic2\*.hpp ..\%__SRC%\inc\offuh\com\sun\star\logging\*.hdl %_DEST%\inc%_EXT%\offuh\com\sun\star\logging\*.hdl ..\%__SRC%\inc\offuh\com\sun\star\logging\*.hpp %_DEST%\inc%_EXT%\offuh\com\sun\star\logging\*.hpp +..\%__SRC%\inc\offuh\com\sun\star\office\*.hpp %_DEST%\inc%_EXT%\offuh\com\sun\star\office\*.hpp +..\%__SRC%\inc\offuh\com\sun\star\office\*.hdl %_DEST%\inc%_EXT%\offuh\com\sun\star\office\*.hdl ..\%__SRC%\inc\offuh\com\sun\star\oooimprovement\*.hdl %_DEST%\inc%_EXT%\offuh\com\sun\star\oooimprovement\*.hdl ..\%__SRC%\inc\offuh\com\sun\star\oooimprovement\*.hpp %_DEST%\inc%_EXT%\offuh\com\sun\star\oooimprovement\*.hpp ..\%__SRC%\inc\offuh\com\sun\star\mail\*.hpp %_DEST%\inc%_EXT%\offuh\com\sun\star\mail\*.hpp @@ -371,4 +374,3 @@ mkdir: %_DEST%\inc%_EXT%\offuh\com\sun\star\rdf ..\%__SRC%\inc\offuh\com\sun\star\rdf\*.hpp %_DEST%\inc%_EXT%\offuh\com\sun\star\rdf\*.hpp ..\%__SRC%\inc\offuh\com\sun\star\rdf\*.hdl %_DEST%\inc%_EXT%\offuh\com\sun\star\rdf\*.hdl - -- cgit From c7788533a2565593405e55b617d09425e08ef439 Mon Sep 17 00:00:00 2001 From: Jens-Heiner Rechtien Date: Wed, 16 Sep 2009 14:37:52 +0000 Subject: CWS-TOOLING: integrate CWS sb113 2009-09-01 sb #i76393# second attempt at properly #ifdef-ing previous HG commit d598efdbf012 2009-08-28 sb #i102469# change back to just on queryInterface, to avoid binary incompatibility (method changing its signature from (Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/Object; to (Ljava/lang/Class;Ljava/lang/Object;)Lcom/sun/star/uno/XInterface;) 2009-08-28 sb #i76393# properly #ifdef previous HG commit d598efdbf012 2009-08-27 sb #i94421# work around compiler error (based on a patch supplied by cloph) 2009-08-26 sb merged in DEV300_m56 2009-08-26 sb #i76393# on Linux, include dynamic section offset in crash report so as to be able to map "prelinked" callstacks back to original (patch by cmc) 2009-08-26 sb #i88162# remove unnecessary whitespace lines from per-locale xcu files (patch by tora) 2009-08-17 Juergen Schmidt #i104292# set context classloader after create new custom UNO loader 2009-08-17 Juergen Schmidt #i103749# integrate patch 2009-08-14 sb #i103269# cherry-picked ssh://hg@hg.services.openoffice.org/cws/sb111 -r 5124ebd5edd1 ("#i101955# changed encoding of XML file content from erroneous ISO-8859-1 to UTF-8") 2009-08-12 sb #i102469# fixed mis-applications of UnoRuntime.queryInterface (detected via the simplified UnoRuntime.queryInterface, the HG changeset 29de35fc9554) to use AnyConverter instead; changed qadevOOo's lib.MultiMethodTest.before to allow throwing arbitrary exceptions, to cater for IllegalArgumentException thrown by AnyConverter 2009-08-12 sb #i104178# drop extra libxml2-config script from libxmlsec 2009-08-10 sb #i101754# simplified osl_getProcessInfo for LINUX (patch by cmc) 2009-08-10 sb #i95018# avoid closing -1 fds (patch supplied by cmc) 2009-08-10 sb #i103585# removed (apparently unnecessary) zlib support from libxml2; in turn, removed zlib dependencies from libxmlsec, libxslt, and redland (assuming those were transitive dependencies brought in by direct dependencies on libxml2) 2009-08-10 sb #i102469# simplified UnoRuntime.queryInterface using Java 5 generics; adapted URE-related modules accordingly 2009-08-10 sb #i101213# adapted setsolar env (solenv/config/) to set PYTHONPATH (and not set PYTHONHOME) in accordance with configure env (set_soenv.in); fixed testtools/source/bridgetest/pyuno (which now should work everywhere out of the box, thanks to the fixed setsolar PYTHONPATH) 2009-08-10 sb cherry-picked ssh://hg@hg.services.openoffice.org/cws/sb111 -r ea8de6d9396b ("#i101955# work in progress for a .hgignore file, continued") --- .../source/cpp_uno/gcc3_macosx_powerpc/uno2cpp.cxx | 3 + bridges/test/com/sun/star/lib/TestBed.java | 4 +- .../uno/bridges/java_remote/Bug107753_Test.java | 14 +- .../uno/bridges/java_remote/Bug108825_Test.java | 2 +- .../uno/bridges/java_remote/Bug110892_Test.java | 2 +- .../uno/bridges/java_remote/Bug111153_Test.java | 2 +- .../lib/uno/bridges/java_remote/Bug51323_Test.java | 2 +- .../lib/uno/bridges/java_remote/Bug92174_Test.java | 2 +- .../lib/uno/bridges/java_remote/Bug97697_Test.java | 2 +- .../lib/uno/bridges/java_remote/Bug98508_Test.java | 2 +- .../lib/uno/bridges/java_remote/MethodIdTest.java | 2 +- .../uno/bridges/java_remote/PolyStructTest.java | 2 +- .../java_remote/StopMessageDispatcherTest.java | 2 +- bridges/test/java_uno/acquire/TestAcquire.java | 4 +- bridges/test/java_uno/any/TestRemote.java | 2 +- bridges/test/java_uno/equals/TestEquals.java | 40 ++--- bridges/test/java_uno/nativethreadpool/Relay.java | 2 +- bridges/test/testclient.java | 4 +- cpputools/source/regcomplazy/regcomplazy.cxx | 2 + .../com/sun/star/comp/helper/Bootstrap.java | 20 +-- .../com/sun/star/comp/helper/ComponentContext.java | 12 +- .../star/comp/helper/RegistryServiceFactory.java | 2 +- .../sun/star/comp/helper/SharedLibraryLoader.java | 4 +- .../comp/juhtest/SmoketestCommandEnvironment.java | 2 - .../com/sun/star/lib/uno/helper/Factory.java | 2 +- .../star/lib/uno/helper/InterfaceContainer.java | 2 +- .../com/sun/star/lib/uno/helper/PropertySet.java | 2 +- .../sun/star/lib/uno/helper/PropertySetMixin.java | 94 ++++++----- .../com/sun/star/comp/helper/Bootstrap_Test.java | 4 +- .../star/comp/helper/ComponentContext_Test.java | 2 +- .../star/comp/helper/SharedLibraryLoader_Test.java | 10 +- .../star/lib/uno/helper/ComponentBase_Test.java | 6 +- .../com/sun/star/lib/uno/helper/Factory_Test.java | 8 +- .../sun/star/comp/bridgefactory/BridgeFactory.java | 8 +- jurt/com/sun/star/comp/loader/FactoryHelper.java | 4 +- jurt/com/sun/star/comp/loader/JavaLoader.java | 2 +- .../star/comp/servicemanager/ServiceManager.java | 18 +-- .../com/sun/star/comp/urlresolver/UrlResolver.java | 4 +- jurt/com/sun/star/uno/WeakReference.java | 4 +- jurt/demo/com/sun/star/demo/DemoServer.java | 4 +- jurt/demo/com/sun/star/demo/TestOffice.java | 18 +-- .../comp/bridgefactory/BridgeFactory_Test.java | 4 +- .../java_remote/java_remote_bridge_Test.java | 6 +- .../star/comp/urlresolver/UrlResolver_Test.java | 6 +- ridljar/com/sun/star/uno/UnoRuntime.java | 5 +- ridljar/test/com/sun/star/uno/UnoRuntime_Test.java | 8 +- sal/osl/unx/process.c | 173 +++++++++------------ sal/osl/unx/signal.c | 92 +++++++++++ ure/source/uretest/JavaClient.java | 10 +- 49 files changed, 341 insertions(+), 290 deletions(-) diff --git a/bridges/source/cpp_uno/gcc3_macosx_powerpc/uno2cpp.cxx b/bridges/source/cpp_uno/gcc3_macosx_powerpc/uno2cpp.cxx index 0f0fdbf351ca..e3f4d36e3962 100644 --- a/bridges/source/cpp_uno/gcc3_macosx_powerpc/uno2cpp.cxx +++ b/bridges/source/cpp_uno/gcc3_macosx_powerpc/uno2cpp.cxx @@ -110,6 +110,9 @@ static void callVirtualMethod( /* set up a pointer to the stack parameter area */ __asm__ ( "addi %0,r1,24" : "=r" (p) : /* no inputs */ ); + // #i94421#, work around compiler error: + volatile long * pCopy = p; + (void) pCopy; // avoid warning about unused variable // never called // if (! pAdjustedThisPtr )CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something diff --git a/bridges/test/com/sun/star/lib/TestBed.java b/bridges/test/com/sun/star/lib/TestBed.java index 7242b56438f0..5e2c5e7859c8 100644 --- a/bridges/test/com/sun/star/lib/TestBed.java +++ b/bridges/test/com/sun/star/lib/TestBed.java @@ -130,7 +130,7 @@ public final class TestBed { throws com.sun.star.uno.Exception { XConnector connector = Connector.create(context); - XBridgeFactory factory = (XBridgeFactory) UnoRuntime.queryInterface( + XBridgeFactory factory = UnoRuntime.queryInterface( XBridgeFactory.class, context.getServiceManager().createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", context)); @@ -169,7 +169,7 @@ public final class TestBed { = Bootstrap.createInitialComponentContext(null); XAcceptor acceptor = Acceptor.create(context); XBridgeFactory factory - = (XBridgeFactory) UnoRuntime.queryInterface( + = UnoRuntime.queryInterface( XBridgeFactory.class, context.getServiceManager().createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", context)); diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug107753_Test.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug107753_Test.java index a2c4122d3017..2c7e314afc82 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug107753_Test.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug107753_Test.java @@ -68,22 +68,19 @@ public final class Bug107753_Test extends ComplexTestCase { protected boolean run(XComponentContext context) throws Throwable { boolean success = true; - XTransport transport = (XTransport) UnoRuntime.queryInterface( + XTransport transport = UnoRuntime.queryInterface( XTransport.class, getBridge(context).getInstance("Transport")); Object obj1a = new XType1() {}; - XType1 obj1b = (XType1) UnoRuntime.queryInterface(XType1.class, - obj1a); + XType1 obj1b = UnoRuntime.queryInterface(XType1.class, obj1a); success &= test("obj1a == obj1b", obj1a == obj1b); Object obj2a = new XType2() {}; - XType2 obj2b = (XType2) UnoRuntime.queryInterface(XType2.class, - obj2a); + XType2 obj2b = UnoRuntime.queryInterface(XType2.class, obj2a); success &= test("obj2a == obj2b", obj2a == obj2b); Object obj3a = transport.getType1(); - XType1 obj3b = (XType1) UnoRuntime.queryInterface(XType1.class, - obj3a); + XType1 obj3b = UnoRuntime.queryInterface(XType1.class, obj3a); success &= test( "obj3a != obj3b; only meaningful as long as different proxy" + " instances are used for different UNO interfaces of one UNO" @@ -91,8 +88,7 @@ public final class Bug107753_Test extends ComplexTestCase { obj3a != obj3b); Object obj4a = transport.getType2(); - XType2 obj4b = (XType2) UnoRuntime.queryInterface(XType2.class, - obj4a); + XType2 obj4b = UnoRuntime.queryInterface(XType2.class, obj4a); success &= test( "obj4a != obj4b; only meaningful as long as different proxy" + " instances are used for different UNO interfaces of one UNO" diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug108825_Test.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug108825_Test.java index 6e9d97f7034d..0585e1c8f650 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug108825_Test.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug108825_Test.java @@ -68,7 +68,7 @@ public final class Bug108825_Test extends ComplexTestCase { } protected boolean run(XComponentContext context) throws Throwable { - XTest test = (XTest) UnoRuntime.queryInterface( + XTest test = UnoRuntime.queryInterface( XTest.class, getBridge(context).getInstance("Test")); // Send the XObject that is held on the server side amidst two // dummies that are not held on the server side; then wait for the diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug110892_Test.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug110892_Test.java index 76bd9d37a10c..1a537895b0ed 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug110892_Test.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug110892_Test.java @@ -71,7 +71,7 @@ public final class Bug110892_Test extends ComplexTestCase { } protected boolean run(XComponentContext context) throws Throwable { - XTest test = (XTest) UnoRuntime.queryInterface( + XTest test = UnoRuntime.queryInterface( XTest.class, getBridge(context).getInstance("Test")); test.start(new ClientObject()); synchronized (lock) { diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug111153_Test.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug111153_Test.java index d1f09509d9a3..40eccdba2cc6 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug111153_Test.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug111153_Test.java @@ -63,7 +63,7 @@ public final class Bug111153_Test extends ComplexTestCase { } protected boolean run(XComponentContext context) throws Throwable { - XTransport t = (XTransport) UnoRuntime.queryInterface( + XTransport t = UnoRuntime.queryInterface( XTransport.class, getBridge(context).getInstance("Transport")); XDerived d = new XDerived() {}; t.setDerived(d); diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug51323_Test.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug51323_Test.java index 32bfe9d832a3..247bf65ba185 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug51323_Test.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug51323_Test.java @@ -67,7 +67,7 @@ public final class Bug51323_Test extends ComplexTestCase { protected boolean run(XComponentContext context) throws Throwable { XConnection connection = Connector.create(context).connect(getConnectionDescription()); - XBridgeFactory factory = (XBridgeFactory) UnoRuntime.queryInterface( + XBridgeFactory factory = UnoRuntime.queryInterface( XBridgeFactory.class, context.getServiceManager().createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", context)); diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug92174_Test.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug92174_Test.java index 292dabde4758..13b61447c320 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug92174_Test.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug92174_Test.java @@ -55,7 +55,7 @@ public final class Bug92174_Test extends ComplexTestCase { } protected boolean run(XComponentContext context) throws Throwable { - XTransport t = (XTransport) UnoRuntime.queryInterface( + XTransport t = UnoRuntime.queryInterface( XTransport.class, getBridge(context).getInstance("Transport")); t.setDerived(new XDerived() { public void fn() {} diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug97697_Test.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug97697_Test.java index f235ccfd6475..2fdd457f0dcb 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug97697_Test.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug97697_Test.java @@ -72,7 +72,7 @@ public final class Bug97697_Test extends ComplexTestCase { } protected boolean run(XComponentContext context) throws Throwable { - XTransport transport = (XTransport) UnoRuntime.queryInterface( + XTransport transport = UnoRuntime.queryInterface( XTransport.class, getBridge(context).getInstance("Transport")); try { transport.getAny(); diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug98508_Test.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug98508_Test.java index b713deaa352e..79e373014c4a 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug98508_Test.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/Bug98508_Test.java @@ -76,7 +76,7 @@ public final class Bug98508_Test extends ComplexTestCase { protected boolean run(XComponentContext context) throws Throwable { Test98508Interface ifc - = (Test98508Interface) UnoRuntime.queryInterface( + = UnoRuntime.queryInterface( Test98508Interface.class, getBridge(context).getInstance("")); try { diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/MethodIdTest.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/MethodIdTest.java index c22811502e14..407164c66c7f 100755 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/MethodIdTest.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/MethodIdTest.java @@ -64,7 +64,7 @@ public final class MethodIdTest extends ComplexTestCase { } protected boolean run(XComponentContext context) throws Throwable { - XTest t = (XTest) UnoRuntime.queryInterface( + XTest t = UnoRuntime.queryInterface( XTest.class, getBridge(context).getInstance("Test")); return t.f129() == 129; } diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/PolyStructTest.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/PolyStructTest.java index 2f17041a52fb..1c9e387ddb32 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/PolyStructTest.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/PolyStructTest.java @@ -61,7 +61,7 @@ public final class PolyStructTest extends ComplexTestCase { } protected boolean run(XComponentContext context) throws Throwable { - TestTransport t = (TestTransport) UnoRuntime.queryInterface( + TestTransport t = UnoRuntime.queryInterface( TestTransport.class, getBridge(context).getInstance("")); assertEquals( diff --git a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/StopMessageDispatcherTest.java b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/StopMessageDispatcherTest.java index 7590a89fdd0e..37fb8ffee05b 100644 --- a/bridges/test/com/sun/star/lib/uno/bridges/java_remote/StopMessageDispatcherTest.java +++ b/bridges/test/com/sun/star/lib/uno/bridges/java_remote/StopMessageDispatcherTest.java @@ -63,7 +63,7 @@ public final class StopMessageDispatcherTest extends ComplexTestCase { } protected boolean run(XComponentContext context) throws Throwable { - XTest test = (XTest) UnoRuntime.queryInterface( + XTest test = UnoRuntime.queryInterface( XTest.class, getBridge(context).getInstance("Test")); Thread[] threads = new Thread[101]; int n = Thread.enumerate(threads); diff --git a/bridges/test/java_uno/acquire/TestAcquire.java b/bridges/test/java_uno/acquire/TestAcquire.java index 7d54c00d480d..e219b3adbf72 100644 --- a/bridges/test/java_uno/acquire/TestAcquire.java +++ b/bridges/test/java_uno/acquire/TestAcquire.java @@ -71,7 +71,7 @@ public final class TestAcquire { private static void execClient(XComponentContext context, String url) throws Exception { - XTest test = (XTest) UnoRuntime.queryInterface( + XTest test = UnoRuntime.queryInterface( XTest.class, UnoUrlResolver.create(context).resolve(url)); WaitUnreachable u; @@ -184,7 +184,7 @@ public final class TestAcquire { throws Exception { XAcceptor acceptor = Acceptor.create(context); - XBridgeFactory factory = (XBridgeFactory) UnoRuntime.queryInterface( + XBridgeFactory factory = UnoRuntime.queryInterface( XBridgeFactory.class, context.getServiceManager().createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", context)); diff --git a/bridges/test/java_uno/any/TestRemote.java b/bridges/test/java_uno/any/TestRemote.java index db33efc139e9..ec533054579d 100644 --- a/bridges/test/java_uno/any/TestRemote.java +++ b/bridges/test/java_uno/any/TestRemote.java @@ -49,7 +49,7 @@ public final class TestRemote { } protected boolean run(XComponentContext context) throws Throwable { - XTransport transport = (XTransport) UnoRuntime.queryInterface( + XTransport transport = UnoRuntime.queryInterface( XTransport.class, getBridge(context).getInstance("Transport")); return TestAny.test(transport, true); } diff --git a/bridges/test/java_uno/equals/TestEquals.java b/bridges/test/java_uno/equals/TestEquals.java index 31b735473c9b..38c9500629e3 100644 --- a/bridges/test/java_uno/equals/TestEquals.java +++ b/bridges/test/java_uno/equals/TestEquals.java @@ -91,10 +91,10 @@ public final class TestEquals { } protected boolean run(XComponentContext context) throws Throwable { - XTestFrame f = (XTestFrame) UnoRuntime.queryInterface( + XTestFrame f = UnoRuntime.queryInterface( XTestFrame.class, getBridge(context).getInstance("TestFrame")); XAcceptor acceptor = Acceptor.create(context); - XBridgeFactory factory = (XBridgeFactory) UnoRuntime.queryInterface( + XBridgeFactory factory = UnoRuntime.queryInterface( XBridgeFactory.class, context.getServiceManager().createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", context)); @@ -160,17 +160,15 @@ public final class TestEquals { public void run() { try { Object test1Aa = object1; - XBase test1Ab = (XBase) - UnoRuntime.queryInterface( - XBase.class, test1Aa); - XDerived test1Ac = (XDerived) + XBase test1Ab = UnoRuntime.queryInterface( + XBase.class, test1Aa); + XDerived test1Ac = UnoRuntime.queryInterface( XDerived.class, test1Aa); Object test2Aa = object2; - XBase test2Ab = (XBase) - UnoRuntime.queryInterface( - XBase.class, test2Aa); - XDerived test2Ac = (XDerived) + XBase test2Ab = UnoRuntime.queryInterface( + XBase.class, test2Aa); + XDerived test2Ac = UnoRuntime.queryInterface( XDerived.class, test2Aa); @@ -182,16 +180,14 @@ public final class TestEquals { null, params); XMultiComponentFactory factory = context.getServiceManager(); - XImplementationLoader loader - = (XImplementationLoader) + XImplementationLoader loader = UnoRuntime.queryInterface( XImplementationLoader.class, factory.createInstanceWithContext( "com.sun.star.loader." + "SharedLibrary", context)); - XSingleComponentFactory factory2 - = (XSingleComponentFactory) + XSingleComponentFactory factory2 = UnoRuntime.queryInterface( XSingleComponentFactory.class, loader.activate( @@ -199,7 +195,7 @@ public final class TestEquals { + "testequals.impl", "", "../lib/testequals.uno", null)); - XTestInterface test = (XTestInterface) + XTestInterface test = UnoRuntime.queryInterface( XTestInterface.class, factory2.createInstanceWithContext( @@ -211,17 +207,15 @@ public final class TestEquals { PROTOCOL_DESCRIPTION); Object test1Ba = test.get(INSTANCE1); - XBase test1Bb = (XBase) - UnoRuntime.queryInterface( - XBase.class, test1Ba); - XDerived test1Bc = (XDerived) + XBase test1Bb = UnoRuntime.queryInterface( + XBase.class, test1Ba); + XDerived test1Bc = UnoRuntime.queryInterface( XDerived.class, test1Ba); Object test2Ba = test.get(INSTANCE2); - XBase test2Bb = (XBase) - UnoRuntime.queryInterface( - XBase.class, test2Ba); - XDerived test2Bc = (XDerived) + XBase test2Bb = UnoRuntime.queryInterface( + XBase.class, test2Ba); + XDerived test2Bc = UnoRuntime.queryInterface( XDerived.class, test2Ba); diff --git a/bridges/test/java_uno/nativethreadpool/Relay.java b/bridges/test/java_uno/nativethreadpool/Relay.java index b7e304c4a3c9..03cf6795c596 100644 --- a/bridges/test/java_uno/nativethreadpool/Relay.java +++ b/bridges/test/java_uno/nativethreadpool/Relay.java @@ -63,7 +63,7 @@ public final class Relay implements XRelay, XSource { final XAcceptor acceptor = Acceptor.create(context); final XBridgeFactory factory; try { - factory = (XBridgeFactory) UnoRuntime.queryInterface( + factory = UnoRuntime.queryInterface( XBridgeFactory.class, context.getServiceManager().createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", context)); diff --git a/bridges/test/testclient.java b/bridges/test/testclient.java index 244264fa8686..e1733bbc8b10 100644 --- a/bridges/test/testclient.java +++ b/bridges/test/testclient.java @@ -121,7 +121,7 @@ public class testclient XConnector xConnector = - ( XConnector ) UnoRuntime.queryInterface( XConnector.class , x ); + UnoRuntime.queryInterface( XConnector.class , x ); XConnection xConnection = xConnector.connect(args[0]); @@ -138,7 +138,7 @@ public class testclient System.out.println( "after building bridge" ); // Object rInitialObject = m_bridge.mapInterfaceFrom(rootOid, XInterface.class); -// XTestFactory rFactory = (XTestFactory ) +// XTestFactory rFactory = // UnoRuntime.queryInterface(XTestFactory.class,rInitialObject ); // XCallMe callMerFactory-> diff --git a/cpputools/source/regcomplazy/regcomplazy.cxx b/cpputools/source/regcomplazy/regcomplazy.cxx index 69fd77446156..abcb2c187c08 100755 --- a/cpputools/source/regcomplazy/regcomplazy.cxx +++ b/cpputools/source/regcomplazy/regcomplazy.cxx @@ -131,6 +131,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) sBuffer.append(pBuffer, readSize); } } + fclose(fDescr); + fDescr = 0; // just to be sure noone tries to use the file ever after } OString sDescr = sBuffer.makeStringAndClear(); diff --git a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java index c5037b2f1566..d80b8a6b9df0 100644 --- a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java +++ b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java @@ -67,7 +67,7 @@ import java.util.Random; Other services can be inserted into the service manager by using its XSet interface:
-        XSet xSet = (XSet)UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory );
+        XSet xSet = UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory );
         // insert the service manager
         xSet.insert( aSingleComponentFactory );
     
@@ -108,20 +108,20 @@ public class Bootstrap { static public XComponentContext createInitialComponentContext( Hashtable context_entries ) throws Exception { - XImplementationLoader xImpLoader = (XImplementationLoader)UnoRuntime.queryInterface( + XImplementationLoader xImpLoader = UnoRuntime.queryInterface( XImplementationLoader.class, new JavaLoader() ); // Get the factory of the ServiceManager - XSingleComponentFactory smgr_fac = (XSingleComponentFactory)UnoRuntime.queryInterface( + XSingleComponentFactory smgr_fac = UnoRuntime.queryInterface( XSingleComponentFactory.class, xImpLoader.activate( "com.sun.star.comp.servicemanager.ServiceManager", null, null, null ) ); // Create an instance of the ServiceManager - XMultiComponentFactory xSMgr = (XMultiComponentFactory)UnoRuntime.queryInterface( + XMultiComponentFactory xSMgr = UnoRuntime.queryInterface( XMultiComponentFactory.class, smgr_fac.createInstanceWithContext( null ) ); // post init loader - XInitialization xInit = (XInitialization)UnoRuntime.queryInterface( + XInitialization xInit = UnoRuntime.queryInterface( XInitialization.class, xImpLoader ); Object[] args = new Object [] { xSMgr }; xInit.initialize( args ); @@ -137,12 +137,12 @@ public class Bootstrap { XComponentContext xContext = new ComponentContext( context_entries, null ); // post init smgr - xInit = (XInitialization)UnoRuntime.queryInterface( + xInit = UnoRuntime.queryInterface( XInitialization.class, xSMgr ); args = new Object [] { null, xContext }; // no registry, default context xInit.initialize( args ); - XSet xSet = (XSet)UnoRuntime.queryInterface( XSet.class, xSMgr ); + XSet xSet = UnoRuntime.queryInterface( XSet.class, xSMgr ); // insert the service manager xSet.insert( smgr_fac ); // and basic jurt factories @@ -159,7 +159,7 @@ public class Bootstrap { */ static public XMultiServiceFactory createSimpleServiceManager() throws Exception { - return (XMultiServiceFactory)UnoRuntime.queryInterface( + return UnoRuntime.queryInterface( XMultiServiceFactory.class, createInitialComponentContext( null ).getServiceManager() ); } @@ -206,7 +206,7 @@ public class Bootstrap { NativeLibraryLoader.loadLibrary( Bootstrap.class.getClassLoader(), "juh" ); m_loaded_juh = true; } - return (XComponentContext)UnoRuntime.queryInterface( + return UnoRuntime.queryInterface( XComponentContext.class, cppuhelper_bootstrap( ini_file, pairs, Bootstrap.class.getClassLoader() ) ); @@ -283,7 +283,7 @@ public class Bootstrap { try { // try to connect to office Object context = xUrlResolver.resolve( sConnect ); - xContext = (XComponentContext) UnoRuntime.queryInterface( + xContext = UnoRuntime.queryInterface( XComponentContext.class, context); if ( xContext == null ) throw new BootstrapException( "no component context!" ); diff --git a/javaunohelper/com/sun/star/comp/helper/ComponentContext.java b/javaunohelper/com/sun/star/comp/helper/ComponentContext.java index 938cc0543901..1c3df0d4844b 100644 --- a/javaunohelper/com/sun/star/comp/helper/ComponentContext.java +++ b/javaunohelper/com/sun/star/comp/helper/ComponentContext.java @@ -101,7 +101,7 @@ public class ComponentContext implements XComponentContext, XComponent { o = ((ComponentContextEntry)o).m_value; } - m_xSMgr = (XMultiComponentFactory)UnoRuntime.queryInterface( + m_xSMgr = UnoRuntime.queryInterface( XMultiComponentFactory.class, o ); } if (m_xSMgr != null) @@ -114,7 +114,7 @@ public class ComponentContext implements XComponentContext, XComponent } // listen for delegate - XComponent xComp = (XComponent)UnoRuntime.queryInterface( + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, m_xDelegate ); if (xComp != null) { @@ -154,7 +154,7 @@ public class ComponentContext implements XComponentContext, XComponent else { XSingleComponentFactory xCompFac = - (XSingleComponentFactory)UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XSingleComponentFactory.class, entry.m_lateInit ); if (xCompFac != null) { @@ -185,7 +185,7 @@ public class ComponentContext implements XComponentContext, XComponent else // inited in the meantime { // dispose fresh service instance - XComponent xComp = (XComponent)UnoRuntime.queryInterface( + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, xInstance ); if (xComp != null) { @@ -253,7 +253,7 @@ public class ComponentContext implements XComponentContext, XComponent o = ((ComponentContextEntry)o).m_value; } - XComponent xComp = (XComponent)UnoRuntime.queryInterface( XComponent.class, o ); + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, o ); if (xComp != null) { if (name.equals( TDMGR_NAME )) @@ -272,7 +272,7 @@ public class ComponentContext implements XComponentContext, XComponent // smgr if (m_bDisposeSMgr) { - XComponent xComp = (XComponent)UnoRuntime.queryInterface( + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, m_xSMgr ); if (xComp != null) { diff --git a/javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java b/javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java index 4b5db3753da3..9523fbba7716 100644 --- a/javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java +++ b/javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java @@ -124,7 +124,7 @@ public class RegistryServiceFactory { Object obj = createRegistryServiceFactory( writeRegistryFile, readRegistryFile, readOnly, RegistryServiceFactory.class.getClassLoader() ); - return (XMultiServiceFactory) UnoRuntime.queryInterface( + return UnoRuntime.queryInterface( XMultiServiceFactory.class, obj ); } diff --git a/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java b/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java index eda51f8cb1f7..a1bf4d3a168c 100644 --- a/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java +++ b/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java @@ -85,7 +85,7 @@ public class SharedLibraryLoader { XMultiServiceFactory smgr, XRegistryKey regKey ) { - return (XSingleServiceFactory) UnoRuntime.queryInterface( + return UnoRuntime.queryInterface( XSingleServiceFactory.class, component_getFactory( DEFAULT_LIBRARY, DEFAULT_IMPLEMENTATION, smgr, regKey, @@ -110,7 +110,7 @@ public class SharedLibraryLoader { XMultiServiceFactory smgr, XRegistryKey regKey ) { - return (XSingleServiceFactory) UnoRuntime.queryInterface( + return UnoRuntime.queryInterface( XSingleServiceFactory.class, component_getFactory( libName, impName, smgr, regKey, diff --git a/javaunohelper/com/sun/star/comp/juhtest/SmoketestCommandEnvironment.java b/javaunohelper/com/sun/star/comp/juhtest/SmoketestCommandEnvironment.java index cafa7e0a412d..a508a209ad2c 100644 --- a/javaunohelper/com/sun/star/comp/juhtest/SmoketestCommandEnvironment.java +++ b/javaunohelper/com/sun/star/comp/juhtest/SmoketestCommandEnvironment.java @@ -119,7 +119,6 @@ class InteractionImpl implements com.sun.star.task.XInteractionHandler if (approve) { com.sun.star.task.XInteractionApprove xApprove = - (com.sun.star.task.XInteractionApprove) UnoRuntime.queryInterface(com.sun.star.task.XInteractionApprove.class, conts[i]); if (xApprove != null) xApprove.select(); @@ -129,7 +128,6 @@ class InteractionImpl implements com.sun.star.task.XInteractionHandler else if (abort) { com.sun.star.task.XInteractionAbort xAbort = - (com.sun.star.task.XInteractionAbort) UnoRuntime.queryInterface(com.sun.star.task.XInteractionAbort.class, conts[i]); if (xAbort != null) xAbort.select(); diff --git a/javaunohelper/com/sun/star/lib/uno/helper/Factory.java b/javaunohelper/com/sun/star/lib/uno/helper/Factory.java index 6eb261ff0eb8..5842c8eaf7f4 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/Factory.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/Factory.java @@ -210,7 +210,7 @@ public class Factory throws com.sun.star.uno.Exception { Object inst = instantiate( xContext ); - XInitialization xInit = (XInitialization)UnoRuntime.queryInterface( + XInitialization xInit = UnoRuntime.queryInterface( XInitialization.class, inst ); if (null == xInit) { diff --git a/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java b/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java index 44a6be5e5f7a..d7bc61cbcbad 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java @@ -715,7 +715,7 @@ public class InterfaceContainer implements Cloneable try { Object o= aIt.next(); - XEventListener evtListener= (XEventListener) UnoRuntime.queryInterface( + XEventListener evtListener= UnoRuntime.queryInterface( XEventListener.class, o); if( evtListener != null ) evtListener.disposing( evt ); diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java index b4b2d02ab148..d77c1600def3 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java @@ -671,7 +671,7 @@ XMultiPropertySet // We try to get an XInterface of setVal and set an XInterface type. if (setVal instanceof XInterface) { - XInterface xint= (XInterface) UnoRuntime.queryInterface(XInterface.class, setVal); + XInterface xint= UnoRuntime.queryInterface(XInterface.class, setVal); if (xint != null) convObj= new Any(new Type(XInterface.class), xint); } diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java index af33c5ea3ee9..40c69a90f8a6 100644 --- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java +++ b/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java @@ -143,13 +143,13 @@ public final class PropertySetMixin { idlClass = getReflection(type.getTypeName()); XTypeDescription ifc; try { - ifc = (XTypeDescription) UnoRuntime.queryInterface( + ifc = UnoRuntime.queryInterface( XTypeDescription.class, - (((XHierarchicalNameAccess) UnoRuntime.queryInterface( - XHierarchicalNameAccess.class, - context.getValueByName( - "/singletons/com.sun.star.reflection." - + "theTypeDescriptionManager"))). + (UnoRuntime.queryInterface( + XHierarchicalNameAccess.class, + context.getValueByName( + "/singletons/com.sun.star.reflection." + + "theTypeDescriptionManager")). getByHierarchicalName(type.getTypeName()))); } catch (NoSuchElementException e) { throw new RuntimeException( @@ -585,7 +585,7 @@ public final class PropertySetMixin { private XIdlClass getReflection(String typeName) { XIdlReflection refl; try { - refl = (XIdlReflection) UnoRuntime.queryInterface( + refl = UnoRuntime.queryInterface( XIdlReflection.class, context.getServiceManager().createInstanceWithContext( "com.sun.star.reflection.CoreReflection", context)); @@ -599,8 +599,7 @@ public final class PropertySetMixin { try { return refl.forName(typeName); } finally { - XComponent comp = (XComponent) UnoRuntime.queryInterface( - XComponent.class, refl); + XComponent comp = UnoRuntime.queryInterface(XComponent.class, refl); if (comp != null) { comp.dispose(); } @@ -610,9 +609,8 @@ public final class PropertySetMixin { private void initProperties( XTypeDescription type, HashMap map, ArrayList handleNames, HashSet seen) { - XInterfaceTypeDescription2 ifc = (XInterfaceTypeDescription2) - UnoRuntime.queryInterface( - XInterfaceTypeDescription2.class, resolveTypedefs(type)); + XInterfaceTypeDescription2 ifc = UnoRuntime.queryInterface( + XInterfaceTypeDescription2.class, resolveTypedefs(type)); if (seen.add(ifc.getName())) { XTypeDescription[] bases = ifc.getBaseTypes(); for (int i = 0; i < bases.length; ++i) { @@ -622,11 +620,10 @@ public final class PropertySetMixin { for (int i = 0; i < members.length; ++i) { if (members[i].getTypeClass() == TypeClass.INTERFACE_ATTRIBUTE) { - XInterfaceAttributeTypeDescription2 attr - = ((XInterfaceAttributeTypeDescription2) - UnoRuntime.queryInterface( - XInterfaceAttributeTypeDescription2.class, - members[i])); + XInterfaceAttributeTypeDescription2 attr = + UnoRuntime.queryInterface( + XInterfaceAttributeTypeDescription2.class, + members[i]); short attrAttribs = 0; if (attr.isBound()) { attrAttribs |= PropertyAttribute.BOUND; @@ -685,7 +682,7 @@ public final class PropertySetMixin { break; } attrAttribs |= n; - t = ((XStructTypeDescription) UnoRuntime.queryInterface( + t = (UnoRuntime.queryInterface( XStructTypeDescription.class, t)). getTypeArguments()[0]; } @@ -747,14 +744,14 @@ public final class PropertySetMixin { object, illegalArgumentPosition); } - XIdlField2 f = (XIdlField2) UnoRuntime.queryInterface( + XIdlField2 f = UnoRuntime.queryInterface( XIdlField2.class, idlClass.getField(name)); Object[] o = new Object[] { new Any(type, UnoRuntime.queryInterface(type, object)) }; Object v = wrapValue( value, - ((XIdlField2) UnoRuntime.queryInterface( - XIdlField2.class, idlClass.getField(name))).getType(), + UnoRuntime.queryInterface( + XIdlField2.class, idlClass.getField(name)).getType(), (p.property.Attributes & PropertyAttribute.MAYBEAMBIGUOUS) != 0, isAmbiguous, (p.property.Attributes & PropertyAttribute.MAYBEDEFAULT) != 0, @@ -807,7 +804,7 @@ public final class PropertySetMixin { if (p == null) { throw new UnknownPropertyException(name, object); } - XIdlField2 field = (XIdlField2) UnoRuntime.queryInterface( + XIdlField2 field = UnoRuntime.queryInterface( XIdlField2.class, idlClass.getField(name)); Object value; try { @@ -848,12 +845,12 @@ public final class PropertySetMixin { XIdlClass ambiguous = getReflection(typeName); try { isAmbiguous = AnyConverter.toBoolean( - ((XIdlField2) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XIdlField2.class, - ambiguous.getField("IsAmbiguous"))).get(value)); - value = ((XIdlField2) UnoRuntime.queryInterface( - XIdlField2.class, - ambiguous.getField("Value"))).get(value); + ambiguous.getField("IsAmbiguous")).get(value)); + value = UnoRuntime.queryInterface( + XIdlField2.class, + ambiguous.getField("Value")).get(value); } catch (com.sun.star.lang.IllegalArgumentException e) { throw new RuntimeException( "unexpected" @@ -867,12 +864,12 @@ public final class PropertySetMixin { XIdlClass defaulted = getReflection(typeName); try { isDefaulted = AnyConverter.toBoolean( - ((XIdlField2) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XIdlField2.class, - defaulted.getField("IsDefaulted"))).get(value)); - value = ((XIdlField2) UnoRuntime.queryInterface( - XIdlField2.class, - defaulted.getField("Value"))).get(value); + defaulted.getField("IsDefaulted")).get(value)); + value = UnoRuntime.queryInterface( + XIdlField2.class, + defaulted.getField("Value")).get(value); } catch (com.sun.star.lang.IllegalArgumentException e) { throw new RuntimeException( "unexpected" @@ -886,16 +883,16 @@ public final class PropertySetMixin { XIdlClass optional = getReflection(typeName); try { boolean present = AnyConverter.toBoolean( - ((XIdlField2) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XIdlField2.class, - optional.getField("IsPresent"))).get(value)); + optional.getField("IsPresent")).get(value)); if (!present) { value = Any.VOID; break; } - value = ((XIdlField2) UnoRuntime.queryInterface( - XIdlField2.class, - optional.getField("Value"))).get(value); + value = UnoRuntime.queryInterface( + XIdlField2.class, + optional.getField("Value")).get(value); } catch (com.sun.star.lang.IllegalArgumentException e) { throw new RuntimeException( "unexpected" @@ -932,15 +929,15 @@ public final class PropertySetMixin { Object[] strct = new Object[1]; type.createObject(strct); try { - XIdlField2 field = (XIdlField2) UnoRuntime.queryInterface( + XIdlField2 field = UnoRuntime.queryInterface( XIdlField2.class, type.getField("Value")); field.set( strct, wrapValue( value, field.getType(), false, false, wrapDefaulted, isDefaulted, wrapOptional)); - ((XIdlField2) UnoRuntime.queryInterface( - XIdlField2.class, type.getField("IsAmbiguous"))).set( + UnoRuntime.queryInterface( + XIdlField2.class, type.getField("IsAmbiguous")).set( strct, new Boolean(isAmbiguous)); } catch (com.sun.star.lang.IllegalArgumentException e) { throw new RuntimeException( @@ -959,15 +956,15 @@ public final class PropertySetMixin { Object[] strct = new Object[1]; type.createObject(strct); try { - XIdlField2 field = (XIdlField2) UnoRuntime.queryInterface( + XIdlField2 field = UnoRuntime.queryInterface( XIdlField2.class, type.getField("Value")); field.set( strct, wrapValue( value, field.getType(), wrapAmbiguous, isAmbiguous, false, false, wrapOptional)); - ((XIdlField2) UnoRuntime.queryInterface( - XIdlField2.class, type.getField("IsDefaulted"))).set( + UnoRuntime.queryInterface( + XIdlField2.class, type.getField("IsDefaulted")).set( strct, new Boolean(isDefaulted)); } catch (com.sun.star.lang.IllegalArgumentException e) { throw new RuntimeException( @@ -986,11 +983,11 @@ public final class PropertySetMixin { type.createObject(strct); boolean present = !AnyConverter.isVoid(value); try { - ((XIdlField2) UnoRuntime.queryInterface( - XIdlField2.class, type.getField("IsPresent"))).set( + UnoRuntime.queryInterface( + XIdlField2.class, type.getField("IsPresent")).set( strct, new Boolean(present)); if (present) { - XIdlField2 field = (XIdlField2) UnoRuntime.queryInterface( + XIdlField2 field = UnoRuntime.queryInterface( XIdlField2.class, type.getField("Value")); field.set( strct, @@ -1018,9 +1015,8 @@ public final class PropertySetMixin { private static XTypeDescription resolveTypedefs(XTypeDescription type) { while (type.getTypeClass() == TypeClass.TYPEDEF) { - type = ((XIndirectTypeDescription) UnoRuntime.queryInterface( - XIndirectTypeDescription.class, type)). - getReferencedType(); + type = UnoRuntime.queryInterface( + XIndirectTypeDescription.class, type).getReferencedType(); } return type; } diff --git a/javaunohelper/test/com/sun/star/comp/helper/Bootstrap_Test.java b/javaunohelper/test/com/sun/star/comp/helper/Bootstrap_Test.java index 9c330539e620..b94b85771d8d 100644 --- a/javaunohelper/test/com/sun/star/comp/helper/Bootstrap_Test.java +++ b/javaunohelper/test/com/sun/star/comp/helper/Bootstrap_Test.java @@ -62,7 +62,7 @@ public class Bootstrap_Test { "no /singletons/com.sun.star.reflection.theTypeDescriptionManager!" ); } - XMultiServiceFactory msf = (XMultiServiceFactory)UnoRuntime.queryInterface( + XMultiServiceFactory msf = UnoRuntime.queryInterface( XMultiServiceFactory.class, xContext.getServiceManager() ); String services[] = msf.getAvailableServiceNames(); System.out.println("Available services are:"); @@ -74,7 +74,7 @@ public class Bootstrap_Test { for ( int i=0; inull * @see #queryInterface(Type, Object) */ - public static Object queryInterface(Class zInterface, Object object) { - return queryInterface(new Type(zInterface), object); + @SuppressWarnings("unchecked") + public static T queryInterface(Class zInterface, Object object) { + return (T) queryInterface(new Type(zInterface), object); } /** diff --git a/ridljar/test/com/sun/star/uno/UnoRuntime_Test.java b/ridljar/test/com/sun/star/uno/UnoRuntime_Test.java index 06af7828039e..a9eef19b0a64 100644 --- a/ridljar/test/com/sun/star/uno/UnoRuntime_Test.java +++ b/ridljar/test/com/sun/star/uno/UnoRuntime_Test.java @@ -54,7 +54,7 @@ public final class UnoRuntime_Test extends ComplexTestCase { // Test if a delegator object has the same OID as its creator: Test4 test4 = new Test4(); - Ifc ifc = (Ifc) UnoRuntime.queryInterface(Ifc.class, test4); + Ifc ifc = UnoRuntime.queryInterface(Ifc.class, test4); assure( "Test4", UnoRuntime.generateOid(test4).equals(UnoRuntime.generateOid(ifc))); @@ -64,19 +64,19 @@ public final class UnoRuntime_Test extends ComplexTestCase { // Test if a query for an interface which is not supported returns null: assure( "Test1", - (Ifc) UnoRuntime.queryInterface(Ifc.class, new Test1()) == null); + UnoRuntime.queryInterface(Ifc.class, new Test1()) == null); // Test if a query for an interface which is supported through // IQueryInterface succeeds: assure( "Test2", - (Ifc) UnoRuntime.queryInterface(Ifc.class, new Test2()) != null); + UnoRuntime.queryInterface(Ifc.class, new Test2()) != null); // Test if a query for an interface which is directly supported (through // inheritance) succeeds: assure( "Test3", - (Ifc) UnoRuntime.queryInterface(Ifc.class, new Test3()) != null); + UnoRuntime.queryInterface(Ifc.class, new Test3()) != null); } public void test_areSame() { diff --git a/sal/osl/unx/process.c b/sal/osl/unx/process.c index e5faf46548a6..a1f47cdf76a5 100644 --- a/sal/osl/unx/process.c +++ b/sal/osl/unx/process.c @@ -466,7 +466,7 @@ static void ChildStatusProc(void *pData) if ((pid = fork()) == 0) { /* Child */ - close(channel[0]); + if (channel[0] != -1) close(channel[0]); if ((data.m_uid != (uid_t)-1) && ((data.m_uid != getuid()) || (data.m_gid != getgid()))) { @@ -500,32 +500,32 @@ static void ChildStatusProc(void *pData) /* Connect std IO to pipe ends */ /* Write end of stdInput not used in child process */ - close( stdInput[1] ); + if (stdInput[1] != -1) close( stdInput[1] ); /* Read end of stdOutput not used in child process */ - close( stdOutput[0] ); + if (stdOutput[0] != -1) close( stdOutput[0] ); /* Read end of stdError not used in child process */ - close( stdError[0] ); + if (stdError[0] != -1) close( stdError[0] ); /* Redirect pipe ends to std IO */ if ( stdInput[0] != STDIN_FILENO ) { dup2( stdInput[0], STDIN_FILENO ); - close( stdInput[0] ); + if (stdInput[0] != -1) close( stdInput[0] ); } if ( stdOutput[1] != STDOUT_FILENO ) { dup2( stdOutput[1], STDOUT_FILENO ); - close( stdOutput[1] ); + if (stdOutput[1] != -1) close( stdOutput[1] ); } if ( stdError[1] != STDERR_FILENO ) { dup2( stdError[1], STDERR_FILENO ); - close( stdError[1] ); + if (stdError[1] != -1) close( stdError[1] ); } pid=execv(data.m_pszArgs[0], (sal_Char **)data.m_pszArgs); @@ -539,7 +539,7 @@ static void ChildStatusProc(void *pData) /* if we reach here, something went wrong */ write(channel[1], &errno, sizeof(errno)); - close(channel[1]); + if (channel[1] != -1) close(channel[1]); _exit(255); } @@ -547,12 +547,12 @@ static void ChildStatusProc(void *pData) { /* Parent */ int status; - close(channel[1]); + if (channel[1] != -1) close(channel[1]); /* Close unused pipe ends */ - close( stdInput[0] ); - close( stdOutput[1] ); - close( stdError[1] ); + if (stdInput[0] != -1) close( stdInput[0] ); + if (stdOutput[1] != -1) close( stdOutput[1] ); + if (stdError[1] != -1) close( stdError[1] ); while (((i = read(channel[0], &status, sizeof(status))) < 0)) { @@ -560,7 +560,7 @@ static void ChildStatusProc(void *pData) break; } - close(channel[0]); + if (channel[0] != -1) close(channel[0]); if ((pid > 0) && (i == 0)) @@ -646,9 +646,9 @@ static void ChildStatusProc(void *pData) if ( pdata->m_pErrorRead ) *pdata->m_pErrorRead = NULL; - close( stdInput[1] ); - close( stdOutput[0] ); - close( stdError[0] ); + if (stdInput[1] != -1) close( stdInput[1] ); + if (stdOutput[0] != -1) close( stdOutput[0] ); + if (stdError[0] != -1) close( stdError[0] ); //if pid > 0 then a process was created, even if it later failed //e.g. bash searching for a command to execute, and we still @@ -1124,15 +1124,6 @@ struct osl_procStat unsigned long nswap; /* ? */ unsigned long cnswap; /* ? */ - /* from 'statm' */ - long size; /* numbers of pages in memory */ - long resident; /* number of resident pages */ - long share; /* number of shared pages */ - long trs; /* text resident size */ - long lrs; /* library resident size */ - long drs; /* data resident size */ - long dt; /* ditry pages */ - /* from 'status' */ int ruid; /* real uid */ int euid; /* effective uid */ @@ -1155,9 +1146,10 @@ struct osl_procStat osl_getProcStat *********************************************/ -void osl_getProcStat(pid_t pid, struct osl_procStat* procstat) +sal_Bool osl_getProcStat(pid_t pid, struct osl_procStat* procstat) { int fd = 0; + sal_Bool bRet = sal_False; char name[PATH_MAX + 1]; snprintf(name, sizeof(name), "/proc/%u/stat", pid); @@ -1166,11 +1158,13 @@ void osl_getProcStat(pid_t pid, struct osl_procStat* procstat) char* tmp=0; char prstatbuf[512]; memset(prstatbuf,0,512); - read(fd,prstatbuf,511); + bRet = read(fd,prstatbuf,511) == 511; close(fd); /*printf("%s\n\n",prstatbuf);*/ + if (!bRet) + return sal_False; tmp = strrchr(prstatbuf, ')'); *tmp = '\0'; @@ -1198,57 +1192,35 @@ void osl_getProcStat(pid_t pid, struct osl_procStat* procstat) &procstat->wchan, &procstat->nswap, &procstat->cnswap ); } -} - -/********************************************** - osl_getProcStatm - *********************************************/ - -void osl_getProcStatm(pid_t pid, struct osl_procStat* procstat) -{ - int fd = 0; - char name[PATH_MAX + 1]; - snprintf(name, sizeof(name), "/proc/%u/statm", pid); - - if ((fd = open(name,O_RDONLY)) >=0 ) - { - char prstatmbuf[512]; - memset(prstatmbuf,0,512); - read(fd,prstatmbuf,511); - - close(fd); - - /* printf("\n\n%s\n\n",prstatmbuf);*/ - - sscanf(prstatmbuf,"%li %li %li %li %li %li %li", - &procstat->size, &procstat->resident, &procstat->share, - &procstat->trs, &procstat->lrs, &procstat->drs, - &procstat->dt - ); - } + return bRet; } /********************************************** osl_getProcStatus *********************************************/ -void osl_getProcStatus(pid_t pid, struct osl_procStat* procstat) +sal_Bool osl_getProcStatus(pid_t pid, struct osl_procStat* procstat) { int fd = 0; char name[PATH_MAX + 1]; snprintf(name, sizeof(name), "/proc/%u/status", pid); + sal_Bool bRet = sal_False; + if ((fd = open(name,O_RDONLY)) >=0 ) { char* tmp=0; char prstatusbuf[512]; memset(prstatusbuf,0,512); - read(fd,prstatusbuf,511); + bRet = read(fd,prstatusbuf,511) == 511; close(fd); /* printf("\n\n%s\n\n",prstatusbuf);*/ + if (!bRet) + return sal_False; + tmp = strstr(prstatusbuf,"Uid:"); if(tmp) { @@ -1290,6 +1262,7 @@ void osl_getProcStatus(pid_t pid, struct osl_procStat* procstat) ); } } + return bRet; } #endif @@ -1439,56 +1412,54 @@ oslProcessError SAL_CALL osl_getProcessInfo(oslProcess Process, oslProcessData F #elif defined(LINUX) -/* int fd = 0;*/ - struct osl_procStat procstat; - memset(&procstat,0,sizeof(procstat)); + if ( (Fields & osl_Process_CPUTIMES) || (Fields & osl_Process_HEAPUSAGE) ) + { + struct osl_procStat procstat; + memset(&procstat,0,sizeof(procstat)); - osl_getProcStat(pid, &procstat); - osl_getProcStatm(pid, &procstat); - osl_getProcStatus(pid, &procstat); + if ( (Fields & osl_Process_CPUTIMES) && osl_getProcStat(pid, &procstat) ) + { + /* + * mfe: + * We calculate only time of the process proper. + * Threads are processes, we do not consider their time here! + * (For this, cutime and cstime should be used, it seems not + * to work in 2.0.36) + */ + + long clktck; + unsigned long hz; + unsigned long userseconds; + unsigned long systemseconds; + + clktck = sysconf(_SC_CLK_TCK); + if (clktck < 0) { + return osl_Process_E_Unknown; + } + hz = (unsigned long) clktck; - if ( Fields & osl_Process_CPUTIMES) - { - /* - * mfe: - * We calculate only time of the process proper. - * Threads are processes, we do not consider their time here! - * (For this, cutime and cstime should be used, it seems not - * to work in 2.0.36) - */ - - long clktck; - unsigned long hz; - unsigned long userseconds; - unsigned long systemseconds; - - clktck = sysconf(_SC_CLK_TCK); - if (clktck < 0) { - return osl_Process_E_Unknown; - } - hz = (unsigned long) clktck; + userseconds = procstat.utime/hz; + systemseconds = procstat.stime/hz; - userseconds = procstat.utime/hz; - systemseconds = procstat.stime/hz; + pInfo->UserTime.Seconds = userseconds; + pInfo->UserTime.Nanosec = procstat.utime - (userseconds * hz); + pInfo->SystemTime.Seconds = systemseconds; + pInfo->SystemTime.Nanosec = procstat.stime - (systemseconds * hz); - pInfo->UserTime.Seconds = userseconds; - pInfo->UserTime.Nanosec = procstat.utime - (userseconds * hz); - pInfo->SystemTime.Seconds = systemseconds; - pInfo->SystemTime.Nanosec = procstat.stime - (systemseconds * hz); + pInfo->Fields |= osl_Process_CPUTIMES; + } - pInfo->Fields |= osl_Process_CPUTIMES; - } + if ( (Fields & osl_Process_HEAPUSAGE) && osl_getProcStatus(pid, &procstat) ) + { + /* + * mfe: + * vm_data (found in status) shows the size of the data segment + * it a rough approximation of the core heap size + */ + pInfo->HeapUsage = procstat.vm_data*1024; - if (Fields & osl_Process_HEAPUSAGE) - { - /* - * mfe: - * vm_data (found in status) shows the size of the data segment - * it a rough approximation of the core heap size - */ - pInfo->HeapUsage = procstat.vm_data*1024; - - pInfo->Fields |= osl_Process_HEAPUSAGE; + pInfo->Fields |= osl_Process_HEAPUSAGE; + } } return (pInfo->Fields == Fields) ? osl_Process_E_None : osl_Process_E_Unknown; diff --git a/sal/osl/unx/signal.c b/sal/osl/unx/signal.c index 77633dd81269..35884e11c9ba 100644 --- a/sal/osl/unx/signal.c +++ b/sal/osl/unx/signal.c @@ -46,6 +46,7 @@ #ifdef LINUX #include +#include #define INCLUDE_BACKTRACE #define STACKTYPE "Linux" #endif @@ -392,6 +393,88 @@ static int fputs_xml( const char *string, FILE *stream ) #define REPORTENV_PARAM "-crashreportenv:" +#if defined SAL_ENABLE_CRASH_REPORT && defined INCLUDE_BACKTRACE && \ + defined LINUX + +typedef struct +{ + const char *name; + ElfW(Off) offset; +} dynamic_entry; + +static int +callback(struct dl_phdr_info *info, size_t size, void *data) +{ + const ElfW(Phdr) *pDynamic = NULL; + + if (size == sizeof(struct dl_phdr_info)) + { + int i; + for (i = 0; i < info->dlpi_phnum; ++i) + { + if (info->dlpi_phdr[i].p_type == PT_DYNAMIC) + { + pDynamic = &(info->dlpi_phdr[i]); + break; + } + } + } + + if (pDynamic) + { + char buffer[100]; + int len; + char exe[PATH_MAX]; + const char *dsoname = info->dlpi_name; + + dynamic_entry* entry = (dynamic_entry*)data; + + if (strcmp(dsoname, "") == 0) + { + snprintf(buffer, sizeof(buffer), "/proc/%d/exe", getpid()); + if ((len = readlink(buffer, exe, PATH_MAX)) != -1) + { + exe[len] = '\0'; + dsoname = exe; + } + } + + if (strcmp(dsoname, entry->name) == 0) + { + entry->offset = pDynamic->p_offset; + return 1; + } + } + return 0; +} + +/* Get the location of the .dynamic section offset for the given elf file. + * i.e. same as the "Offset" value shown for DYNAMIC from readelf -l foo + * + * We want to know this value so that if the binaries have been modifed + * by prelink then we can still process the call stack on server side + * by comparing this value to that of an "un-prelinked but known to be + * otherwise equivalent" version of those binaries and adjust the call + * stack addresses by the differences between .dynamic addresses so as + * to be able to map the prelinked addresses back to the unprelinked + * addresses + * + * cmc@openoffice.org + */ +static ElfW(Off) +dynamic_section_offset(const char *name) +{ + dynamic_entry entry; + + entry.name = name; + entry.offset = 0; + + dl_iterate_phdr(callback, &entry); + + return entry.offset; +} +#endif + static int ReportCrash( int Signal ) { #ifdef SAL_ENABLE_CRASH_REPORT @@ -572,6 +655,11 @@ static int ReportCrash( int Signal ) if ( dl_info.dli_fbase && dl_info.dli_fname ) { +#ifdef LINUX + ElfW(Off) dynamic_offset = dynamic_section_offset(dl_info.dli_fname); + fprintf( stackout, " 0x%" SAL_PRI_SIZET "x:", dynamic_offset); +#endif + fprintf( stackout, " %s + 0x%" SAL_PRI_PTRDIFFT "x", dl_info.dli_fname, (char*)stackframes[iFrame] - (char*)dl_info.dli_fbase @@ -583,6 +671,10 @@ static int ReportCrash( int Signal ) if ( dli_fdir ) fprintf( xmlout, " path=\"%s\"", dli_fdir ); + +#ifdef LINUX + fprintf( xmlout, " dynamicoffset=\"0x%" SAL_PRI_SIZET "x\"", dynamic_offset ); +#endif } else fprintf( stackout, " ????????" ); diff --git a/ure/source/uretest/JavaClient.java b/ure/source/uretest/JavaClient.java index e7b6a6ed54d2..fbb35a910c96 100644 --- a/ure/source/uretest/JavaClient.java +++ b/ure/source/uretest/JavaClient.java @@ -50,7 +50,7 @@ public final class JavaClient { if (manager == null) { throw new NullPointerException("no service manager"); } - XBridgeFactory factory = (XBridgeFactory) UnoRuntime.queryInterface( + XBridgeFactory factory = UnoRuntime.queryInterface( XBridgeFactory.class, manager.createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", context)); @@ -63,11 +63,9 @@ public final class JavaClient { Connector.create(context).connect( url.getConnectionAndParametersAsString()), null); - Data d = - ((XServer) UnoRuntime.queryInterface( - XServer.class, bridge.getInstance(url.getRootOid()))).getData(); - ((XComponent) UnoRuntime.queryInterface(XComponent.class, bridge)). - dispose(); + Data d = UnoRuntime.queryInterface( + XServer.class, bridge.getInstance(url.getRootOid())).getData(); + UnoRuntime.queryInterface(XComponent.class, bridge).dispose(); if (!d.m1.equals("Hello") || d.m2 != 42) { throw new RuntimeException("Data object contains bad values"); } -- cgit From cf428a5632a759e5e2f2f71a0a0df4415a948322 Mon Sep 17 00:00:00 2001 From: Ivo Hinkelmann Date: Thu, 17 Sep 2009 13:53:54 +0000 Subject: CWS-TOOLING: integrate CWS encsig09 2009-09-14 15:11:29 +0200 oc r276125 : #i105049# MacroSignatur needs Macro 2009-09-09 17:09:46 +0200 jl r276005 : #i103989# could not signe encrypted doc containing a formular object 2009-09-09 13:11:24 +0200 jl r275985 : #i103989# could not signe encrypted doc containing a formular object 2009-09-08 15:54:02 +0200 mav r275934 : #i103906# fix the automation test scenario ( tempfile should be writable for the user ) 2009-09-07 14:01:39 +0200 mav r275895 : #i103906# fix the problem with reload 2009-09-07 09:34:48 +0200 mav r275871 : #i104786# do the ODF version check only for ODF documents 2009-09-07 08:19:06 +0200 mav r275870 : #i104389# fix text 2009-09-06 22:24:21 +0200 mav r275867 : #i104786# check the consistency of ODF version 2009-09-06 22:23:24 +0200 mav r275866 : #i104786# check the consistency of ODF version 2009-09-06 22:23:00 +0200 mav r275865 : #i104786# check the consistency of ODF version 2009-09-06 22:22:36 +0200 mav r275864 : #i104786# check the consistency of ODF version 2009-09-06 22:22:03 +0200 mav r275863 : #i104786# check the consistency of ODF version 2009-09-02 17:09:30 +0200 mav r275722 : #i104715# let repairing mechanics use the streams correctly 2009-09-01 16:52:49 +0200 mav r275670 : #i104389# notify user not to trust the corrupted document 2009-09-01 16:31:37 +0200 mav r275668 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:30:32 +0200 mav r275667 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:22:13 +0200 jl r275666 : #i104339# small content change 2009-09-01 14:20:42 +0200 jl r275660 : #i103519# remove some debug output 2009-09-01 13:51:52 +0200 jl r275659 : #i103519# NSS uses '\' for escaping in distinguished names 2009-09-01 12:49:47 +0200 mav r275655 : #i104389# use zip-mode to read from jar files 2009-09-01 12:40:22 +0200 mav r275653 : #i104389# use zip-mode to read from jar files 2009-09-01 12:32:29 +0200 mav r275652 : #i104389# use constants 2009-08-31 21:58:00 +0200 mav r275637 : #i10000# fix warning 2009-08-31 21:11:17 +0200 mav r275636 : #i104227# adding of scripting signature removes the document signature 2009-08-31 20:55:05 +0200 mav r275635 : #i103905# ZipStorage supports Compressed property 2009-08-31 20:53:55 +0200 mav r275634 : #i103905# adjust macro signature transfer to usage of ZipStorage 2009-08-31 15:30:49 +0200 jl r275609 : #i103989# warning is shown as long the user does not click 'OK' 2009-08-31 14:36:10 +0200 jl r275608 : #i103989# changed warning text when signing macro and there is a document signature. This warning is only displayed once 2009-08-31 13:34:41 +0200 mav r275603 : #i104452# disable macros in repaired documents 2009-08-31 13:33:42 +0200 mav r275602 : #i104452# disable macros in repaired documents 2009-08-31 13:03:56 +0200 jl r275600 : #i45212# signature dialog could not be started when using read-only documents 2009-08-31 09:26:13 +0200 mav r275583 : #i104578# store the additional entry as the last one to workaround parsing problem in OOo3.1 and later 2009-08-30 20:54:25 +0200 mav r275562 : #i10000# adopt for unix 2009-08-30 10:56:00 +0200 mav r275561 : CWS-TOOLING: rebase CWS encsig09 to trunk@275331 (milestone: DEV300:m56) 2009-08-28 16:34:00 +0200 mav r275539 : #i104578# write necessary info in manifest.xml for ODF1.2 encrypted document 2009-08-28 14:04:22 +0200 mav r275533 : #104587# fix handling of readonly streams 2009-08-28 13:58:10 +0200 mav r275531 : #i104389# fix the broken document handling 2009-08-28 11:40:39 +0200 mav r275522 : #i104389# fix the signature streams check 2009-08-27 21:48:12 +0200 mav r275509 : #i103927# show the warning 2009-08-27 21:47:48 +0200 mav r275508 : #i103927# show the warning 2009-08-27 16:45:59 +0200 jl r275495 : #i45212# remove unused variable 2009-08-27 16:34:00 +0200 jl r275494 : #i103989# 2009-08-27 13:54:28 +0200 jl r275482 : #i103519# fixed replacement of 'S' by 'ST' 2009-08-27 12:32:21 +0200 mav r275472 : #i10000# fix warning 2009-08-27 11:58:11 +0200 mav r275467 : #i104389# handle the entry path correctly 2009-08-26 17:18:35 +0200 jl r275438 : #i103519# subject and issuer distinguished names were not properly displayed. The strings were obtained by system functions (Windows, NSS), which use quotes to escape the values, when they contain special characters 2009-08-26 11:00:20 +0200 mav r275403 : #i10000# fix warnings 2009-08-26 08:25:45 +0200 mav r275392 : #i10000# fix warning 2009-08-26 08:02:22 +0200 mav r275391 : #i10000# adopt for linux 2009-08-26 07:40:30 +0200 mav r275390 : #i10000# fix warning 2009-08-26 07:35:28 +0200 mav r275389 : #i10000# use correct include file name 2009-08-25 15:01:41 +0200 jl r275356 : #i103989# better check for mimetype of streams 2009-08-25 09:07:09 +0200 mav r275335 : CWS-TOOLING: rebase CWS encsig09 to trunk@274622 (milestone: DEV300:m54) 2009-08-24 18:17:02 +0200 mav r275329 : #i103927# check the nonencrypted streams 2009-08-24 18:14:14 +0200 mav r275328 : #i103927# check the nonencrypted streams 2009-08-24 17:59:34 +0200 mav r275327 : #i103927#,#i104389# check the package consistency and nonencrypted streams 2009-08-24 16:18:28 +0200 jl r275323 : #i103989# added comment 2009-08-24 13:08:47 +0200 jl r275305 : #i45212# #i66276# only write the X509Certificate element once and allow to add remove several certificates at a time 2009-08-21 12:57:28 +0200 ufi r275239 : 104339 2009-08-21 08:39:05 +0200 jl r275213 : #i10398# comparing URIs of signed files with the 'element list' 2009-08-20 13:39:47 +0200 jl r275178 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:35:39 +0200 jl r275177 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:29:06 +0200 jl r275176 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:26:21 +0200 jl r275175 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 12:05:09 +0200 ufi r275170 : i104339 2009-08-19 12:24:54 +0200 jl r275146 : #i10398# displaying 'old signature' icon and status in signature dialog 2009-08-18 15:18:48 +0200 jl r275111 : #i103989# document signatures containing manifest.xml are now validated according to the final ODF1.2 spec 2009-08-18 11:41:06 +0200 mav r275087 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-18 11:35:13 +0200 mav r275085 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-14 17:32:41 +0200 jl r274999 : #i103989# using c14n tranformation for XML streams 2009-08-14 15:27:43 +0200 jl r274987 : #i103989# remove special handling for encrypted document streams in UriBindingHelper::OpenInputStream, since we use zip storage this is not necessary anymore 2009-08-14 15:08:10 +0200 jl r274983 : #i103989# Showing a message when adding or removing a macro signature, that the document signature will be removed 2009-08-14 14:57:27 +0200 jl r274982 : #i103989# accesing Sequence at invalid index 2009-08-11 08:55:02 +0200 mav r274846 : #i103905# let signing service know if there is already a valid document signature 2009-08-10 11:33:37 +0200 jl r274799 : #i103905# do not truncate the stream 2009-08-10 10:43:47 +0200 mav r274797 : #i103905# provide the storage version 2009-08-07 16:58:46 +0200 jl r274780 : #i103989# 2009-08-07 16:56:19 +0200 jl r274779 : #i103989# using odf version string etc. 2009-08-07 15:20:53 +0200 mav r274771 : #i103905# provide the storage version 2009-08-07 15:19:12 +0200 mav r274770 : #i103905# provide the storage version 2009-08-07 12:41:45 +0200 mav r274758 : #103930# do not store thumbnail in case of encrypted document 2009-08-07 12:36:52 +0200 mav r274757 : #i103905# provide the storage version 2009-08-07 12:15:54 +0200 mav r274754 : #i103760# the signed state is not lost on saving 2009-08-07 12:06:19 +0200 mav r274753 : #i103760# avoid warning regarding signature removal on export 2009-08-07 12:06:01 +0200 mav r274752 : #i103760# avoid warning regarding signature removal on export 2009-08-06 08:47:34 +0200 mav r274703 : #i103905# allow to transport ODF version to the signing component 2009-08-05 21:34:42 +0200 mav r274701 : #i103905# allow to transport ODF version to the signing component 2009-08-05 15:48:17 +0200 mav r274683 : #i103905# allow to transport ODF version to the signing component 2009-08-05 14:58:12 +0200 jl r274673 : #i103989# documentsignature now signes all streams except documentsignatures.xml, all streams are processed as binary files 2009-08-05 12:00:32 +0200 mav r274648 : #i103905# allow to transport ODF version to the signing component 2009-08-04 10:57:04 +0200 jl r274612 : #i103989# added XInitialization 2009-07-31 10:32:27 +0200 mav r274516 : #i103905# use zip storage to sign documents 2009-07-30 14:01:33 +0200 mav r274489 : #i103906# optimize the usage of temporary medium 2009-07-30 14:00:28 +0200 mav r274488 : #i103906# optimize the usage of temporary medium 2009-07-30 13:59:09 +0200 mav r274487 : #i103906# optimize the usage of temporary medium 2009-07-30 13:50:44 +0200 mav r274485 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:53 +0200 mav r274484 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:13 +0200 mav r274483 : #i103906# optimize the usage of temporary medium 2009-07-30 13:47:09 +0200 mav r274482 : #i103905#,#i103906# let the signing process use zip-storage; optimize the usage of temporary medium 2009-07-21 09:10:31 +0200 mav r274159 : CWS-TOOLING: rebase CWS encsig09 to trunk@273468 (milestone: DEV300:m51) 2009-05-05 08:39:01 +0200 mav r271496 : #i100832# allow to sign macros only when there are any --- offapi/com/sun/star/embed/Storage.idl | 13 ++++ .../star/security/DocumentSignatureInformation.idl | 19 +++++ .../task/DocumentMacroConfirmationRequest2.idl | 83 ++++++++++++++++++++++ offapi/com/sun/star/task/makefile.mk | 1 + 4 files changed, 116 insertions(+) create mode 100644 offapi/com/sun/star/task/DocumentMacroConfirmationRequest2.idl diff --git a/offapi/com/sun/star/embed/Storage.idl b/offapi/com/sun/star/embed/Storage.idl index b7c85707cf7f..70e91a66e765 100644 --- a/offapi/com/sun/star/embed/Storage.idl +++ b/offapi/com/sun/star/embed/Storage.idl @@ -347,6 +347,19 @@ service Storage

*/ [property, optional, readonly] boolean HasEncryptedEntries; + + // ----------------------------------------------------------------------- + /** allows to detect if the storage contains nonencrypted entries. + +

+ In case it is set to the storage itself and/or a tree of + substorages contains nonencrypted streams. Usually in case this + property is supported the implementation supports + XEncryptionProtectedSource interface. +

+ */ + [property, optional, readonly] boolean HasNonEncryptedEntries; + }; //============================================================================ diff --git a/offapi/com/sun/star/security/DocumentSignatureInformation.idl b/offapi/com/sun/star/security/DocumentSignatureInformation.idl index da418ebac2d4..4ed6d972705c 100644 --- a/offapi/com/sun/star/security/DocumentSignatureInformation.idl +++ b/offapi/com/sun/star/security/DocumentSignatureInformation.idl @@ -59,6 +59,25 @@ struct DocumentSignatureInformation CertificateValidity. */ long CertificateStatus; + /* indicates what content of a document is signed. +

+ This value can be ignored when this struct is returned as part of + a macro signature validation. + As of OpenOffice.org 3.2 and ODF 1.2 the document signature comprises + all files except the signature file itself. + Signatures in OOo 2.x were only + applied to the files in the root of the document, except mimetype, the + Pictures and ObjectReplacements/Objects folder. That is, macros + were not part of the document signature. + OOo 3.0 signed everthing, execept mimetype and the META-INF folder. +

+ If PartialDocumentSignature is true, then the signature was created by OOo + with a version less then 3.2. In this case, not all files are signed. The + signature can still be regarded as valid, as long as SignatureIsValid is true + and the certificate could be validated. However, users should be notified about + the fact, that not everything in this document is signed. + */ + boolean PartialDocumentSignature; }; diff --git a/offapi/com/sun/star/task/DocumentMacroConfirmationRequest2.idl b/offapi/com/sun/star/task/DocumentMacroConfirmationRequest2.idl new file mode 100644 index 000000000000..422f1ab2a9d0 --- /dev/null +++ b/offapi/com/sun/star/task/DocumentMacroConfirmationRequest2.idl @@ -0,0 +1,83 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: DocumentMacroConfirmationRequest.idl,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __com_sun_star_task_DocumentMacroConfirmationRequest2_idl__ +#define __com_sun_star_task_DocumentMacroConfirmationRequest2_idl__ + +#include +#include +#include + + +//============================================================================= + +module com { module sun { module star { module task { + +//============================================================================= + +/** describes the request to approve or deny the execution of macros contained in + a document. + */ +exception DocumentMacroConfirmationRequest2 : ClassifiedInteractionRequest +{ + /** specifies the URL of the document which contains macros whose execution + should be approved or rejected. + */ + string DocumentURL; + + /** refers to the zip-storage related to the last commited version of the + document. + + This storage is necessary e.g. for displaying the existing signatures to + the user, to allow him a decision whether or not to trust those signatures + and thus the signed macros. + + @see ::com::sun::star::security::XDocumentDigitalSignatures::showScriptingContentSignatures + */ + ::com::sun::star::embed::XStorage + DocumentZipStorage; + + /** contains informations about the ODF version of the document + */ + string DocumentVersion; + + /** contains informations about the signatures in the document + */ + sequence< ::com::sun::star::security::DocumentSignatureInformation > + DocumentSignatureInformation; +}; + +//============================================================================= + +}; }; }; }; + +//============================================================================= + +#endif diff --git a/offapi/com/sun/star/task/makefile.mk b/offapi/com/sun/star/task/makefile.mk index 1559901f740c..5b82671072bc 100644 --- a/offapi/com/sun/star/task/makefile.mk +++ b/offapi/com/sun/star/task/makefile.mk @@ -45,6 +45,7 @@ PACKAGE=com$/sun$/star$/task IDLFILES=\ ClassifiedInteractionRequest.idl\ DocumentMacroConfirmationRequest.idl\ + DocumentMacroConfirmationRequest2.idl\ DocumentPasswordRequest.idl\ DocumentMSPasswordRequest.idl\ ErrorCodeRequest.idl\ -- cgit From e06358d4e625da233e1181b3d1ef1c4159b7f6f0 Mon Sep 17 00:00:00 2001 From: Jens-Heiner Rechtien Date: Thu, 17 Sep 2009 14:41:33 +0000 Subject: CWS-TOOLING: integrate CWS kso32fixes2 2009-09-14 kso #i104767# - 64 bit build breaker 2009-09-14 kso #i14767# - compiler warning 2009-09-08 kso i104767# - Removed obsolete header. 2009-09-08 kso i104767# - Removed obsolete header include. 2009-09-08 kso #i104767# - Fixed build breaker. 2009-09-07 kso #i104767# - merged in dev300 m57. 2009-09-07 kso #i104767# - support for system credentials usage 2009-09-07 kso #i104767# - support for system credentials usage 2009-09-07 kso #i104767# - support for system credentials usage 2009-09-07 kso #i104767# - support for system credentials usage 2009-09-07 kso #i104767# - support for system credentials usage 2009-09-07 Kai Sommerfeld #i104767# - support for system credentials usage 2009-09-07 Kai Sommerfeld #i104767# - support for system credentials usage 2009-09-07 ks93798 #i104767# - adaptions for NTLM SSO --- offapi/com/sun/star/task/makefile.mk | 3 +- offapi/com/sun/star/ucb/makefile.mk | 230 ++++++++++++++++++----------------- 2 files changed, 118 insertions(+), 115 deletions(-) diff --git a/offapi/com/sun/star/task/makefile.mk b/offapi/com/sun/star/task/makefile.mk index 5b82671072bc..dc54f6fd3883 100644 --- a/offapi/com/sun/star/task/makefile.mk +++ b/offapi/com/sun/star/task/makefile.mk @@ -80,7 +80,8 @@ IDLFILES=\ XStatusIndicatorSupplier.idl\ XAbortChannel.idl\ XInteractionRequestStringResolver.idl\ - InteractionRequestStringResolver.idl + InteractionRequestStringResolver.idl\ + XUrlContainer.idl # ------------------------------------------------------------------ diff --git a/offapi/com/sun/star/ucb/makefile.mk b/offapi/com/sun/star/ucb/makefile.mk index 2cf5394dcaf4..19320b716634 100644 --- a/offapi/com/sun/star/ucb/makefile.mk +++ b/offapi/com/sun/star/ucb/makefile.mk @@ -45,6 +45,7 @@ IDLFILES=\ AlreadyInitializedException.idl\ AnyCompareFactory.idl\ AuthenticationRequest.idl\ + URLAuthenticationRequest.idl\ CachedContentResultSet.idl\ CachedContentResultSetFactory.idl\ CachedContentResultSetStub.idl\ @@ -99,7 +100,7 @@ IDLFILES=\ FTPContent.idl\ FTPContentProvider.idl\ GlobalTransferCommandArgument.idl\ - GIOContentProvider.idl\ + GIOContentProvider.idl\ GnomeVFSContentProvider.idl\ GnomeVFSDocumentContent.idl\ GnomeVFSFolderContent.idl\ @@ -142,125 +143,126 @@ IDLFILES=\ LockType.idl\ MissingInputStreamException.idl\ MissingPropertiesException.idl\ - NameClash.idl\ - NameClashException.idl\ - NameClashResolveRequest.idl\ - NumberedSortingInfo.idl\ - ODMAContent.idl\ - ODMAContentProvider.idl\ - OpenCommandArgument.idl\ - OpenCommandArgument2.idl\ - OpenMode.idl\ - OutgoingMessageState.idl\ - PackageContentProvider.idl\ - PackageFolderContent.idl\ - PackageStreamContent.idl\ - PersistentPropertySet.idl\ - PostCommandArgument.idl\ - PostCommandArgument2.idl\ - Priority.idl\ - PropertiesManager.idl\ - PropertySetRegistry.idl\ - PropertyValueInfo.idl\ - PropertyValueState.idl\ - RecipientInfo.idl\ - RememberAuthentication.idl\ - RemoteAccessContentProvider.idl\ - RemoteContentProviderAcceptor.idl\ - RemoteContentProviderChangeAction.idl\ - RemoteContentProviderChangeEvent.idl\ - RemoteProxyContentProvider.idl\ - ResultSetException.idl\ + NameClash.idl\ + NameClashException.idl\ + NameClashResolveRequest.idl\ + NumberedSortingInfo.idl\ + ODMAContent.idl\ + ODMAContentProvider.idl\ + OpenCommandArgument.idl\ + OpenCommandArgument2.idl\ + OpenMode.idl\ + OutgoingMessageState.idl\ + PackageContentProvider.idl\ + PackageFolderContent.idl\ + PackageStreamContent.idl\ + PersistentPropertySet.idl\ + PostCommandArgument.idl\ + PostCommandArgument2.idl\ + Priority.idl\ + PropertiesManager.idl\ + PropertySetRegistry.idl\ + PropertyValueInfo.idl\ + PropertyValueState.idl\ + RecipientInfo.idl\ + RememberAuthentication.idl\ + RemoteAccessContentProvider.idl\ + RemoteContentProviderAcceptor.idl\ + RemoteContentProviderChangeAction.idl\ + RemoteContentProviderChangeEvent.idl\ + RemoteProxyContentProvider.idl\ + ResultSetException.idl\ Rule.idl\ - RuleAction.idl\ - RuleOperator.idl\ - RuleSet.idl\ - RuleTerm.idl\ - SearchCommandArgument.idl\ - SearchCriterium.idl\ - SearchInfo.idl\ - SearchRecursion.idl\ - SendInfo.idl\ - SendMediaTypes.idl\ - ServiceNotFoundException.idl\ - SimpleFileAccess.idl\ - SortedDynamicResultSetFactory.idl\ - SortingInfo.idl\ - Store.idl\ - SynchronizePolicy.idl\ - TransferCommandOperation.idl\ - TransferInfo.idl\ - TransferResult.idl\ + RuleAction.idl\ + RuleOperator.idl\ + RuleSet.idl\ + RuleTerm.idl\ + SearchCommandArgument.idl\ + SearchCriterium.idl\ + SearchInfo.idl\ + SearchRecursion.idl\ + SendInfo.idl\ + SendMediaTypes.idl\ + ServiceNotFoundException.idl\ + SimpleFileAccess.idl\ + SortedDynamicResultSetFactory.idl\ + SortingInfo.idl\ + Store.idl\ + SynchronizePolicy.idl\ + TransferCommandOperation.idl\ + TransferInfo.idl\ + TransferResult.idl\ TransientDocumentsContentProvider.idl\ TransientDocumentsRootContent.idl\ TransientDocumentsDocumentContent.idl\ TransientDocumentsFolderContent.idl\ TransientDocumentsStreamContent.idl\ - UniversalContentBroker.idl\ - UnsupportedCommandException.idl\ - UnsupportedDataSinkException.idl\ - UnsupportedNameClashException.idl\ - UnsupportedOpenModeException.idl\ - VerificationMode.idl\ - WebDAVContentProvider.idl\ - WebDAVDocumentContent.idl\ - WebDAVFolderContent.idl\ - WelcomeDynamicResultSetStruct.idl\ - XAnyCompare.idl\ - XAnyCompareFactory.idl\ - XCachedContentResultSetFactory.idl\ - XCachedContentResultSetStubFactory.idl\ - XCachedDynamicResultSetFactory.idl\ - XCachedDynamicResultSetStubFactory.idl\ - XCommandEnvironment.idl\ - XCommandInfo.idl\ - XCommandInfoChangeListener.idl\ - XCommandInfoChangeNotifier.idl\ - XCommandProcessor.idl\ - XCommandProcessor2.idl\ - XContent.idl\ - XContentAccess.idl\ - XContentCreator.idl\ - XContentEventListener.idl\ - XContentIdentifier.idl\ - XContentIdentifierFactory.idl\ - XContentIdentifierMapping.idl\ - XContentProvider.idl\ - XContentProviderFactory.idl\ - XContentProviderManager.idl\ - XContentProviderSupplier.idl\ - XContentTransmitter.idl\ - XDataContainer.idl\ - XDynamicResultSet.idl\ - XDynamicResultSetListener.idl\ - XFetchProvider.idl\ - XFetchProviderForContentAccess.idl\ - XFileIdentifierConverter.idl\ - XInteractionCookieHandling.idl\ - XInteractionHandlerSupplier.idl\ - XInteractionReplaceExistingData.idl\ - XInteractionSupplyAuthentication.idl\ - XInteractionSupplyName.idl\ - XParameterizedContentProvider.idl\ - XPersistentPropertySet.idl\ - XProgressHandler.idl\ - XPropertyMatcher.idl\ - XPropertyMatcherFactory.idl\ - XPropertySetRegistry.idl\ - XPropertySetRegistryFactory.idl\ - XRecycler.idl\ - XRemoteContentProviderAcceptor.idl\ - XRemoteContentProviderActivator.idl\ - XRemoteContentProviderChangeListener.idl\ - XRemoteContentProviderChangeNotifier.idl\ - XRemoteContentProviderConnectionControl.idl\ - XRemoteContentProviderDistributor.idl\ - XRemoteContentProviderDoneListener.idl\ - XRemoteContentProviderSupplier.idl\ - XSimpleFileAccess.idl\ - XSimpleFileAccess2.idl\ - XSimpleFileAccess3.idl\ - XSortedDynamicResultSetFactory.idl\ + UniversalContentBroker.idl\ + UnsupportedCommandException.idl\ + UnsupportedDataSinkException.idl\ + UnsupportedNameClashException.idl\ + UnsupportedOpenModeException.idl\ + VerificationMode.idl\ + WebDAVContentProvider.idl\ + WebDAVDocumentContent.idl\ + WebDAVFolderContent.idl\ + WelcomeDynamicResultSetStruct.idl\ + XAnyCompare.idl\ + XAnyCompareFactory.idl\ + XCachedContentResultSetFactory.idl\ + XCachedContentResultSetStubFactory.idl\ + XCachedDynamicResultSetFactory.idl\ + XCachedDynamicResultSetStubFactory.idl\ + XCommandEnvironment.idl\ + XCommandInfo.idl\ + XCommandInfoChangeListener.idl\ + XCommandInfoChangeNotifier.idl\ + XCommandProcessor.idl\ + XCommandProcessor2.idl\ + XContent.idl\ + XContentAccess.idl\ + XContentCreator.idl\ + XContentEventListener.idl\ + XContentIdentifier.idl\ + XContentIdentifierFactory.idl\ + XContentIdentifierMapping.idl\ + XContentProvider.idl\ + XContentProviderFactory.idl\ + XContentProviderManager.idl\ + XContentProviderSupplier.idl\ + XContentTransmitter.idl\ + XDataContainer.idl\ + XDynamicResultSet.idl\ + XDynamicResultSetListener.idl\ + XFetchProvider.idl\ + XFetchProviderForContentAccess.idl\ + XFileIdentifierConverter.idl\ + XInteractionCookieHandling.idl\ + XInteractionHandlerSupplier.idl\ + XInteractionReplaceExistingData.idl\ + XInteractionSupplyAuthentication.idl\ + XInteractionSupplyAuthentication2.idl\ + XInteractionSupplyName.idl\ + XParameterizedContentProvider.idl\ + XPersistentPropertySet.idl\ + XProgressHandler.idl\ + XPropertyMatcher.idl\ + XPropertyMatcherFactory.idl\ + XPropertySetRegistry.idl\ + XPropertySetRegistryFactory.idl\ + XRecycler.idl\ + XRemoteContentProviderAcceptor.idl\ + XRemoteContentProviderActivator.idl\ + XRemoteContentProviderChangeListener.idl\ + XRemoteContentProviderChangeNotifier.idl\ + XRemoteContentProviderConnectionControl.idl\ + XRemoteContentProviderDistributor.idl\ + XRemoteContentProviderDoneListener.idl\ + XRemoteContentProviderSupplier.idl\ + XSimpleFileAccess.idl\ + XSimpleFileAccess2.idl\ + XSimpleFileAccess3.idl\ + XSortedDynamicResultSetFactory.idl\ XSourceInitialization.idl\ XWebDAVCommandEnvironment.idl \ CertificateValidationRequest.idl -- cgit From f139877d515036d2653843e8683e021a45fbe811 Mon Sep 17 00:00:00 2001 From: Jens-Heiner Rechtien Date: Fri, 18 Sep 2009 09:04:40 +0000 Subject: #i10000#: files added (and removed) missing from integration of CWS kso32fixes2 --- offapi/com/sun/star/task/XUrlContainer.idl | 92 ++++++++++++++++++++++ .../com/sun/star/ucb/URLAuthenticationRequest.idl | 58 ++++++++++++++ .../star/ucb/XInteractionSupplyAuthentication2.idl | 79 +++++++++++++++++++ 3 files changed, 229 insertions(+) create mode 100644 offapi/com/sun/star/task/XUrlContainer.idl create mode 100644 offapi/com/sun/star/ucb/URLAuthenticationRequest.idl create mode 100644 offapi/com/sun/star/ucb/XInteractionSupplyAuthentication2.idl diff --git a/offapi/com/sun/star/task/XUrlContainer.idl b/offapi/com/sun/star/task/XUrlContainer.idl new file mode 100644 index 000000000000..93839e68fb07 --- /dev/null +++ b/offapi/com/sun/star/task/XUrlContainer.idl @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: XPasswordContainer.idl,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_task_XUrlContainer_idl__ +#define __com_sun_star_task_XUrlContainer_idl__ + +#ifndef __com_sun_star_uno_XInterface_idl__ +#include +#endif + +#ifndef __com_sun_star_task_XInteractionHandler_idl__ +#include +#endif + + +//============================================================================= + +module com { module sun { module star { module task { + +//============================================================================= +/** Allows to store and retrieve URLs. URLs can be stored persistently or + until end of OOo session. +*/ +/*published*/ interface XUrlContainer : com::sun::star::uno::XInterface +{ + //------------------------------------------------------------------------- + /** Add a URL to the container. + + @param Url URL to add to the container + @param MakePersistent indicates whether the URL shall be stored + persistently or just in memory (until end of + OOo session) + */ + void addUrl( [in] string Url, [in] boolean MakePersistent ); + + //------------------------------------------------------------------------- + /** Lookup a URL in the container. + + @param Url URL to lookup. + @returns Best matched URL or empty string. + */ + string findUrl( [in] string Url ); + + //------------------------------------------------------------------------- + /** Remove a URL from the container. + + @param Url URL to remove. + */ + void removeUrl( [in] string Url ); + + //------------------------------------------------------------------------- + /** Get all URLs. + + @param OnlyPersistent Only URLs taht are stored persistently shall + be returned. + @returns List of URLs. + */ + sequence getUrls( [in] boolean OnlyPersistent ); + +}; + +//============================================================================= + +}; }; }; }; + +#endif diff --git a/offapi/com/sun/star/ucb/URLAuthenticationRequest.idl b/offapi/com/sun/star/ucb/URLAuthenticationRequest.idl new file mode 100644 index 000000000000..1b19830df81e --- /dev/null +++ b/offapi/com/sun/star/ucb/URLAuthenticationRequest.idl @@ -0,0 +1,58 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: AuthenticationRequest.idl,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_ucb_URLAuthenticationRequest_idl__ +#define __com_sun_star_ucb_URLAuthenticationRequest_idl__ + +#ifndef __com_sun_star_ucb_AuthenticationRequest_idl__ +#include +#endif + + +//============================================================================= + +module com { module sun { module star { module ucb { + +//============================================================================= +/** An error specifing lack of correct authentication data (e.g., to log into + an account). +*/ +/*published*/ exception URLAuthenticationRequest : AuthenticationRequest +{ + //------------------------------------------------------------------------- + /** The URL for which authentication is requested. + */ + string URL; +}; + +//============================================================================= + +}; }; }; }; + +#endif diff --git a/offapi/com/sun/star/ucb/XInteractionSupplyAuthentication2.idl b/offapi/com/sun/star/ucb/XInteractionSupplyAuthentication2.idl new file mode 100644 index 000000000000..a3c4bdb3d5f3 --- /dev/null +++ b/offapi/com/sun/star/ucb/XInteractionSupplyAuthentication2.idl @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: XInteractionSupplyAuthentication.idl,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef __com_sun_star_ucb_XInteractionSupplyAuthentication2_idl__ +#define __com_sun_star_ucb_XInteractionSupplyAuthentication2_idl__ + +#ifndef __com_sun_star_ucb_XInteractionSupplyAuthentication_idl__ +#include +#endif + + + +//============================================================================= + +module com { module sun { module star { module ucb { + +//============================================================================= +/** An interaction continuation handing back some authentication data. + +

This continuation is typically used in conjunction with + AuthenticationRequest.

+*/ +/*published*/ interface XInteractionSupplyAuthentication2 : XInteractionSupplyAuthentication +{ + //------------------------------------------------------------------------- + /** Specifies if 'system credentials' can be obtained and used by the issuer + of the authentiction request. + + @param Default + Returns the default behavior for system credentials handling (to be + initially displayed to the user). + + @returns + if the issuer is able to obtain and use system credentials. + otherwise. + */ + boolean canUseSystemCredentials( [out] boolean Default ); + + //------------------------------------------------------------------------- + /** Set a new 'use system credentials' value to hand back. + + @param UseSystemCredentials + means the request issuer shall obtain and use system credentials. + */ + void setUseSystemCredentials( [in] boolean UseSystemCredentials ); + +}; + +//============================================================================= + +}; }; }; }; + +#endif -- cgit -- cgit From edb896d16c218926b5e107d06e4dadadce4d6a51 Mon Sep 17 00:00:00 2001 From: Ivo Hinkelmann Date: Fri, 18 Sep 2009 12:40:04 +0000 Subject: CWS-TOOLING: integrate CWS cmcfixes63 2009-09-16 11:24:47 +0200 cmc r276193 : #i105118# remove overly const warnings for -Wall 2009-09-15 18:04:24 +0200 cmc r276183 : #i105089# fix include 2009-09-15 14:30:55 +0200 cmc r276176 : #i105090# fix includes for s390x bridge --- bridges/source/cpp_uno/gcc3_linux_s390x/except.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/bridges/source/cpp_uno/gcc3_linux_s390x/except.cxx b/bridges/source/cpp_uno/gcc3_linux_s390x/except.cxx index 6141efd7964a..e474dce7268c 100644 --- a/bridges/source/cpp_uno/gcc3_linux_s390x/except.cxx +++ b/bridges/source/cpp_uno/gcc3_linux_s390x/except.cxx @@ -33,6 +33,7 @@ #include "precompiled_bridges.hxx" #include +#include #include #include #include -- cgit From d1571f12a39db6a0eae46450a28ba665129a0165 Mon Sep 17 00:00:00 2001 From: Ivo Hinkelmann Date: Fri, 18 Sep 2009 14:37:01 +0000 Subject: CWS-TOOLING: integrate CWS mingwport24 2009-09-13 02:15:22 +0200 tono r276097 : i#105033: mingw port: accept incomplete deflib 2009-09-12 15:14:34 +0200 tono r276096 : i#105012: mingw port: $(PATH) should be quoted 2009-09-12 15:12:49 +0200 tono r276095 : i#105011: mingw port: berkeleydb fix 2009-09-12 15:11:39 +0200 tono r276094 : i#105010: mingw port: decline libdl 2009-09-12 15:10:21 +0200 tono r276093 : i#105009: mingw port: sal/osl/w32/file_dirvol.cxx needs ctype.h 2009-09-12 15:08:27 +0200 tono r276092 : reverting changes to revise log messages 2009-09-12 11:55:48 +0200 tono r276090 : i#105014: mingw port: change to latest w32api and mingw runtime 2009-09-12 11:52:12 +0200 tono r276089 : i#105013: mingw port: fix gas error in call.s in bridges 2009-09-12 11:42:04 +0200 tono r276088 : mingw port: should be quoted 2009-09-12 11:35:35 +0200 tono r276087 : mingw port: berkeleydb fix 2009-09-12 11:32:34 +0200 tono r276086 : mingw port: decline libdl 2009-09-12 11:20:50 +0200 tono r276085 : mingw port: sal/osl/w32/file_dirvol.cxx needs ctype.h --- bridges/source/cpp_uno/mingw_intel/call.s | 21 +++++++-------------- pyuno/source/loader/makefile.mk | 4 ---- sal/osl/w32/file_dirvol.cxx | 15 +++++++++------ 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/bridges/source/cpp_uno/mingw_intel/call.s b/bridges/source/cpp_uno/mingw_intel/call.s index b4a9ba031cf5..47327d9a4650 100644 --- a/bridges/source/cpp_uno/mingw_intel/call.s +++ b/bridges/source/cpp_uno/mingw_intel/call.s @@ -1,7 +1,6 @@ .text .globl _privateSnippetExecutorGeneral - .type _privateSnippetExecutorGeneral,@function _privateSnippetExecutorGeneral: .LFBg: movl %esp,%ecx @@ -19,10 +18,9 @@ _privateSnippetExecutorGeneral: leave ret .LFEg: - .size _privateSnippetExecutorGeneral,.-_privateSnippetExecutorGeneral + .long .-_privateSnippetExecutorGeneral .globl _privateSnippetExecutorVoid - .type _privateSnippetExecutorVoid,@function _privateSnippetExecutorVoid: .LFBv: movl %esp,%ecx @@ -38,10 +36,9 @@ _privateSnippetExecutorVoid: leave ret .LFEv: - .size _privateSnippetExecutorVoid,.-_privateSnippetExecutorVoid + .long .-_privateSnippetExecutorVoid .globl _privateSnippetExecutorHyper - .type _privateSnippetExecutorHyper,@function _privateSnippetExecutorHyper: .LFBh: movl %esp,%ecx @@ -60,10 +57,9 @@ _privateSnippetExecutorHyper: leave ret .LFEh: - .size _privateSnippetExecutorHyper,.-_privateSnippetExecutorHyper + .long .-_privateSnippetExecutorHyper .globl _privateSnippetExecutorFloat - .type _privateSnippetExecutorFloat,@function _privateSnippetExecutorFloat: .LFBf: movl %esp,%ecx @@ -81,10 +77,9 @@ _privateSnippetExecutorFloat: leave ret .LFEf: - .size _privateSnippetExecutorFloat,.-_privateSnippetExecutorFloat + .long .-_privateSnippetExecutorFloat .globl _privateSnippetExecutorDouble - .type _privateSnippetExecutorDouble,@function _privateSnippetExecutorDouble: .LFBd: movl %esp,%ecx @@ -102,10 +97,9 @@ _privateSnippetExecutorDouble: leave ret .LFEd: - .size _privateSnippetExecutorDouble,.-_privateSnippetExecutorDouble + .long .-_privateSnippetExecutorDouble .globl _privateSnippetExecutorClass - .type _privateSnippetExecutorClass,@function _privateSnippetExecutorClass: .LFBc: movl %esp,%ecx @@ -123,9 +117,9 @@ _privateSnippetExecutorClass: leave ret $4 .LFEc: - .size _privateSnippetExecutorClass,.-_privateSnippetExecutorClass + .long .-_privateSnippetExecutorClass - .section .eh_frame,"a",@progbits + .section .eh_frame,"dr" .Lframe1: .long .LECIE1-.LSCIE1 # length .LSCIE1: @@ -265,4 +259,3 @@ _privateSnippetExecutorClass: .uleb128 5 .align 4 .LEFDEc: - .section .note.GNU-stack,"",@progbits diff --git a/pyuno/source/loader/makefile.mk b/pyuno/source/loader/makefile.mk index 6acb867618be..6e4f96ed7014 100644 --- a/pyuno/source/loader/makefile.mk +++ b/pyuno/source/loader/makefile.mk @@ -110,11 +110,7 @@ $(DLLDEST)$/%.py: %.py $(DLLDEST)$/pyuno_services.rdb : makefile.mk $(DLLDEST)$/$(DLLPRE)$(TARGET)$(DLLPOST) -rm -f $@ $(DLLDEST)$/pyuno_services.tmp $(DLLDEST)$/pyuno_services.rdb -.IF "$(GUI)$(COM)"=="WNTGCC" - cd $(DLLDEST) && sh -c "export PATH='$(PATH):$(OUT)$/bin'; $(REGCOMP) -register -r pyuno_services.tmp -wop $(foreach,i,$(COMPONENTS) -c $(i))" -.ELSE cd $(DLLDEST) && $(REGCOMP) -register -r pyuno_services.tmp -wop $(foreach,i,$(COMPONENTS) -c $(i)) -.ENDIF # "$(GUI)$(COM)"=="WNTGCC" cd $(DLLDEST) && mv pyuno_services.tmp pyuno_services.rdb .ENDIF # L10N_framework diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx index 53aa1c40cd2b..5ea839ae215d 100644 --- a/sal/osl/w32/file_dirvol.cxx +++ b/sal/osl/w32/file_dirvol.cxx @@ -45,6 +45,9 @@ #include "rtl/ustring.hxx" #include +#ifdef __MINGW32__ +#include +#endif //##################################################### #define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0]))) @@ -718,9 +721,9 @@ oslFileError SAL_CALL osl_createDirectory(rtl_uString* strPath) sal_Int32 nLen = rtl_uString_getLength( strSysPath ); if ( - ( pBuffer[0] >= 'A' && pBuffer[0] <= 'Z' || - pBuffer[0] >= 'a' && pBuffer[0] <= 'z' ) && - pBuffer[1] == ':' && ( nLen ==2 || nLen == 3 && pBuffer[2] == '\\' ) + ( ( pBuffer[0] >= 'A' && pBuffer[0] <= 'Z' ) || + ( pBuffer[0] >= 'a' && pBuffer[0] <= 'z' ) ) && + pBuffer[1] == ':' && ( nLen ==2 || ( nLen == 3 && pBuffer[2] == '\\' ) ) ) SetLastError( ERROR_ALREADY_EXISTS ); @@ -1151,8 +1154,8 @@ bool is_floppy_volume_mount_point(const rtl::OUString& path) { // determines if a volume mount point shows to a floppy // disk by comparing the unique volume names - static const LPWSTR FLOPPY_A = L"A:\\"; - static const LPWSTR FLOPPY_B = L"B:\\"; + static const LPCWSTR FLOPPY_A = L"A:\\"; + static const LPCWSTR FLOPPY_B = L"B:\\"; rtl::OUString p(path); osl::systemPathEnsureSeparator(p); @@ -1177,7 +1180,7 @@ bool is_floppy_volume_mount_point(const rtl::OUString& path) //################################################ static bool is_floppy_drive(const rtl::OUString& path) { - static const LPWSTR FLOPPY_DRV_LETTERS = TEXT("AaBb"); + static const LPCWSTR FLOPPY_DRV_LETTERS = TEXT("AaBb"); // we must take into account that even a floppy // drive may be mounted to a directory so checking -- cgit From b81122b799730e80904701680e003f7e2b1bd231 Mon Sep 17 00:00:00 2001 From: Ivo Hinkelmann Date: Fri, 18 Sep 2009 15:39:21 +0000 Subject: CWS-TOOLING: integrate CWS impressaccessibility3 2009-09-18 16:10:59 +0200 af r276289 : #i102525# Fixed some minor compilation problems. 2009-09-17 14:11:23 +0200 af r276243 : #i102525# Fixed F1 shortcut for help view. 2009-09-16 16:20:58 +0200 af r276205 : #i102525# Removing const to make Solaris linker happy. 2009-09-16 16:13:25 +0200 af r276204 : #i90690# Initializing variable to avoid compilation problem. 2009-09-15 19:10:04 +0200 af r276186 : #i90825# Replace edit source proxy when an outliner object is set. 2009-09-15 11:12:07 +0200 af r276160 : #i90690# Broadcast accessibility events when the current slide is changed. 2009-09-15 09:37:48 +0200 af r276148 : #i102525# Fixed Solaris compilation problem. 2009-09-14 18:12:40 +0200 af r276142 : #i102525# Added missing implementation for some font related functions. 2009-09-14 18:02:05 +0200 af r276139 : #i102525# Added accessibility support. 2009-09-14 17:30:13 +0200 af r276136 : #i102525# Added support for interface XPane2 to panes. 2009-09-14 17:00:27 +0200 af r276133 : #i102525# Added XPane2 interface. 2009-09-14 16:13:04 +0200 af r276131 : #i50376# Make the focus indicator visible when the slide sorter has the focus. --- offapi/com/sun/star/drawing/framework/XPane2.idl | 79 +++++++++++++++++++++++ offapi/com/sun/star/drawing/framework/makefile.mk | 1 + 2 files changed, 80 insertions(+) create mode 100644 offapi/com/sun/star/drawing/framework/XPane2.idl diff --git a/offapi/com/sun/star/drawing/framework/XPane2.idl b/offapi/com/sun/star/drawing/framework/XPane2.idl new file mode 100644 index 000000000000..d1b646f73a31 --- /dev/null +++ b/offapi/com/sun/star/drawing/framework/XPane2.idl @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: XPane.idl,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __com_sun_star_drawing_framework_XPane2_idl__ +#define __com_sun_star_drawing_framework_XPane2_idl__ + +#ifndef __com_sun_star_accessibility_XAccessible_idl__ +#include +#endif + +module com { module sun { module star { module drawing { module framework { + +/** An extension of the XPane interface that adds support for + a) showing and hiding the windows that internally belong to the pane and + b) setting the accessibility object. + This is typically an optional interface. +*/ +interface XPane2 +{ + /** Return whether all windows that are used to implement the pane are + visible. + @Returns when all windows of the pane are visible. + */ + boolean isVisible (); + + /** Hide or show the pane. If there is more than one window used to + implement the pane then it is left to the implementation if one, + some, or all windows are hidden or shown as long as the pane becomes + hidden or visible. + @param bIsVisible + When then show the pane. Hide it otherwise. + */ + void setVisible ([in] boolean bIsVisible); + + /** Set the accessibility object for the pane. When there is more than + one window used to implement the pane then the given accessibility + object is usually set at the topmost window. However, the details + are implementation dependent. + @param xAccessible + May be an empty reference. + */ + void setAccessible ([in] ::com::sun::star::accessibility::XAccessible xAccessible); + + /** Return the accessibility object that is currently associated with + the windows that implement the pane. + */ + ::com::sun::star::accessibility::XAccessible getAccessible (); +}; + +}; }; }; }; }; // ::com::sun::star::drawing::framework + +#endif diff --git a/offapi/com/sun/star/drawing/framework/makefile.mk b/offapi/com/sun/star/drawing/framework/makefile.mk index 9b6706ad14d6..b5dd8cbcc936 100644 --- a/offapi/com/sun/star/drawing/framework/makefile.mk +++ b/offapi/com/sun/star/drawing/framework/makefile.mk @@ -62,6 +62,7 @@ IDLFILES= \ XControllerManager.idl \ XModuleController.idl \ XPane.idl \ + XPane2.idl \ XPaneBorderPainter.idl \ XRelocatableResource.idl \ XResource.idl \ -- cgit -- cgit