| 1 |
/* |
| 2 |
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2026 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 13 мар. 2019 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_IO_INFILESTREAM_H_ |
| 23 |
#define LSP_PLUG_IN_IO_INFILESTREAM_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/runtime/LSPString.h> |
| 27 |
#include <lsp-plug.in/stdlib/stdio.h> |
| 28 |
#include <lsp-plug.in/io/File.h> |
| 29 |
#include <lsp-plug.in/io/Path.h> |
| 30 |
#include <lsp-plug.in/io/IInStream.h> |
| 31 |
|
| 32 |
namespace lsp |
| 33 |
{ |
| 34 |
namespace io |
| 35 |
{ |
| 36 |
/** |
| 37 |
* Input file stream. Allows to read file in byte streaming mode. |
| 38 |
*/ |
| 39 |
class InFileStream: public IInStream |
| 40 |
{ |
| 41 |
protected: |
| 42 |
File *pFD; |
| 43 |
size_t nWrapFlags; |
| 44 |
|
| 45 |
public: |
| 46 |
explicit InFileStream(); |
| 47 |
InFileStream(const InFileStream &)=delete; |
| 48 |
InFileStream(InFileStream &&)=delete; |
| 49 |
virtual ~InFileStream() override; |
| 50 |
|
| 51 |
InFileStream & operator = (const InFileStream &) = delete; |
| 52 |
InFileStream & operator = (InFileStream &&) = delete; |
| 53 |
|
| 54 |
public: // io::IInStream |
| 55 |
virtual wssize_t avail() override; |
| 56 |
virtual wssize_t position() override; |
| 57 |
virtual ssize_t read(void *dst, size_t count) override; |
| 58 |
virtual wssize_t seek(wsize_t position) override; |
| 59 |
virtual wssize_t skip(wsize_t amount) override; |
| 60 |
virtual status_t close() override; |
| 61 |
|
| 62 |
public: |
| 63 |
/** Wrap stdio file descriptor. The Reader should be in closed state. |
| 64 |
* |
| 65 |
* @param fd file descriptor |
| 66 |
* @param close close file descriptor on close() |
| 67 |
* @return status of operation |
| 68 |
*/ |
| 69 |
status_t wrap(FILE *fd, bool close); |
| 70 |
|
| 71 |
/** Wrap native file descriptor. The Reader should be in closed state. |
| 72 |
* |
| 73 |
* @param fd file descriptor |
| 74 |
* @param close close file descriptor on close() |
| 75 |
* @return status of operation |
| 76 |
*/ |
| 77 |
status_t wrap_native(fhandle_t fd, bool close); |
| 78 |
|
| 79 |
/** Wrap file descriptor. The Reader should be in closed state. |
| 80 |
* |
| 81 |
* @param fd file descriptor |
| 82 |
* @param flags wrapping flags |
| 83 |
* @return status of operation |
| 84 |
*/ |
| 85 |
status_t wrap(File *fd, size_t flags); |
| 86 |
|
| 87 |
/** Open input stream associated with file. The Reader should be in closed state. |
| 88 |
* |
| 89 |
* @param path file location path |
| 90 |
* @return status of operation |
| 91 |
*/ |
| 92 |
status_t open(const char *path); |
| 93 |
|
| 94 |
/** Open input stream associated with file. The Reader should be in closed state. |
| 95 |
* |
| 96 |
* @param path file location path |
| 97 |
* @return status of operation |
| 98 |
*/ |
| 99 |
status_t open(const LSPString *path); |
| 100 |
|
| 101 |
/** Open input stream associated with file. Before open currently open stream is closed and it's |
| 102 |
* state is reset. |
| 103 |
* |
| 104 |
* @param path file location path |
| 105 |
* @return status of operation |
| 106 |
*/ |
| 107 |
status_t open(const Path *path); |
| 108 |
}; |
| 109 |
|
| 110 |
} /* namespace io */ |
| 111 |
} /* namespace lsp */ |
| 112 |
|
| 113 |
#endif /* LSP_PLUG_IN_IO_INFILESTREAM_H_ */ |