LibreOffice Module shell (master) 1
stream_helper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#if !defined WIN32_LEAN_AND_MEAN
22# define WIN32_LEAN_AND_MEAN
23#endif
24#include <windows.h>
25
26#include <stdio.h>
27#include <objidl.h>
28#include <stream_helper.hxx>
29
31 stream(str)
32{
33 // These next few lines work around the "Seek pointer" bug found on Vista.
34 char cBuf[20];
35 unsigned long nCount;
36 ULARGE_INTEGER nNewPosition;
37 LARGE_INTEGER nMove;
38 nMove.QuadPart = 0;
39 stream->Seek( nMove, STREAM_SEEK_SET, &nNewPosition );
40 stream->Read( cBuf, 20, &nCount );
41}
42
44{
45}
46
47unsigned long BufferStream::sread (unsigned char *buf, unsigned long size)
48{
49 unsigned long newsize;
50 HRESULT hr;
51
52 hr = stream->Read (buf, size, &newsize);
53 if (hr == S_OK)
54 return newsize;
55 else
56 return static_cast<unsigned long>(0);
57}
58
60{
61 HRESULT hr;
62 LARGE_INTEGER Move;
63 ULARGE_INTEGER NewPosition;
64 Move.QuadPart = 0;
65 NewPosition.QuadPart = 0;
66
67 hr = stream->Seek (Move, STREAM_SEEK_CUR, &NewPosition);
68 if (hr == S_OK)
69 return static_cast<long>(NewPosition.QuadPart);
70 else
71 return -1;
72}
73
74long BufferStream::sseek (long offset, int origin)
75{
76 HRESULT hr;
77 LARGE_INTEGER Move;
78 DWORD dwOrigin;
79 Move.QuadPart = static_cast<__int64>(offset);
80
81 switch (origin)
82 {
83 case SEEK_CUR:
84 dwOrigin = STREAM_SEEK_CUR;
85 break;
86 case SEEK_END:
87 dwOrigin = STREAM_SEEK_END;
88 break;
89 case SEEK_SET:
90 dwOrigin = STREAM_SEEK_SET;
91 break;
92 default:
93 return -1;
94 }
95
96 hr = stream->Seek (Move, dwOrigin, nullptr);
97 if (hr == S_OK)
98 return 0;
99 else
100 return -1;
101}
102
104 file(nullptr)
105{
106 // fdo#67534: avoid locking to not interfere with soffice opening the file
107 file = _wfsopen(filename, L"rb", _SH_DENYNO);
108}
109
111{
112 if (file)
113 fclose(file);
114}
115
116unsigned long FileStream::sread (unsigned char *buf, unsigned long size)
117{
118 if (file)
119 return static_cast<unsigned long>(fread(buf, 1, size, file));
120 return 0;
121}
122
123long FileStream::stell ()
124{
125 if (file)
126 return ftell(file);
127 return -1;
128}
129
130long FileStream::sseek (long offset, int origin)
131{
132 if (file)
133 return fseek(file, offset, origin);
134 return -1;
135}
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
unsigned long sread(unsigned char *vuf, unsigned long size) override
long stell() override
long sseek(long offset, int origin) override
BufferStream(IStream *str)
~BufferStream() override
IStream * stream
int nCount
Reference< XOutputStream > stream
char Filepath_char_t
Definition: filepath.hxx:21
size
return hr