1//
2// FileStream_POSIX.h
3//
4// Library: Foundation
5// Package: Streams
6// Module: FileStream
7//
8// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
9//
10// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_FileStream_POSIX_INCLUDED
18#define Foundation_FileStream_POSIX_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/BufferedBidirectionalStreamBuf.h"
23#include <istream>
24#include <ostream>
25
26
27namespace Poco {
28
29
30class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
31 /// This stream buffer handles Fileio
32{
33public:
34 FileStreamBuf();
35 /// Creates a FileStreamBuf.
36
37 ~FileStreamBuf();
38 /// Destroys the FileStream.
39
40 void open(const std::string& path, std::ios::openmode mode);
41 /// Opens the given file in the given mode.
42
43 bool close();
44 /// Closes the File stream buffer. Returns true if successful,
45 /// false otherwise.
46
47 std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
48 /// Change position by offset, according to way and mode.
49
50 std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
51 /// Change to specified position, according to mode.
52
53protected:
54 enum
55 {
56 BUFFER_SIZE = 4096
57 };
58
59 int readFromDevice(char* buffer, std::streamsize length);
60 int writeToDevice(const char* buffer, std::streamsize length);
61
62private:
63 std::string _path;
64 int _fd;
65 std::streamoff _pos;
66};
67
68
69} // namespace Poco
70
71
72#endif // Foundation_FileStream_WIN32_INCLUDED
73