1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #pragma warning(push, 1)
31 #include "internal/stream_helper.hxx"
33 BufferStream::BufferStream(IStream
*str
) :
36 // These next few lines work around the "Seek pointer" bug found on Vista.
39 ULARGE_INTEGER nNewPosition
;
42 stream
->Seek( nMove
, STREAM_SEEK_SET
, &nNewPosition
);
43 stream
->Read( cBuf
, 20, &nCount
);
46 BufferStream::~BufferStream()
50 unsigned long BufferStream::sread (unsigned char *buf
, unsigned long size
)
52 unsigned long newsize
;
55 hr
= stream
->Read (buf
, size
, &newsize
);
57 return (unsigned long)newsize
;
59 return (unsigned long)0;
62 long BufferStream::stell ()
66 ULARGE_INTEGER NewPosition
;
68 NewPosition
.QuadPart
= 0;
70 hr
= ((IStream
*)stream
)->Seek (Move
, STREAM_SEEK_CUR
, &NewPosition
);
72 return (long) NewPosition
.QuadPart
;
77 long BufferStream::sseek (long offset
, int origin
)
82 Move
.QuadPart
= (__int64
)offset
;
87 dwOrigin
= STREAM_SEEK_CUR
;
90 dwOrigin
= STREAM_SEEK_END
;
93 dwOrigin
= STREAM_SEEK_SET
;
99 hr
= stream
->Seek (Move
, dwOrigin
, NULL
);
106 FileStream::FileStream(const char *filename
) :
109 // fdo#67534: avoid locking to not interfere with soffice opening the file
110 file
= _fsopen(filename
, "rb", _SH_DENYNO
);
113 FileStream::~FileStream()
119 unsigned long FileStream::sread (unsigned char *buf
, unsigned long size
)
122 return static_cast<unsigned long>(fread(buf
, 1, size
, file
));
126 long FileStream::stell ()
133 long FileStream::sseek (long offset
, int origin
)
136 return fseek(file
, offset
, origin
);
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */