| 1 |
/* |
| 2 |
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2025 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 14 нояб. 2017 г. |
| 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 |
#include <lsp-plug.in/io/IOutStream.h> |
| 23 |
#include <lsp-plug.in/common/status.h> |
| 24 |
|
| 25 |
namespace lsp |
| 26 |
{ |
| 27 |
namespace io |
| 28 |
{ |
| 29 |
|
| 30 |
IOutStream::IOutStream() |
| 31 |
{ |
| 32 |
nErrorCode = STATUS_OK; |
| 33 |
} |
| 34 |
|
| 35 |
IOutStream::~IOutStream() |
| 36 |
{ |
| 37 |
nErrorCode = STATUS_OK; |
| 38 |
} |
| 39 |
|
| 40 |
wssize_t IOutStream::position() |
| 41 |
{ |
| 42 |
return - set_error(STATUS_NOT_IMPLEMENTED); |
| 43 |
} |
| 44 |
|
| 45 |
ssize_t IOutStream::write(const void *buf, size_t count) |
| 46 |
{ |
| 47 |
return - set_error(STATUS_NOT_IMPLEMENTED); |
| 48 |
} |
| 49 |
|
| 50 |
ssize_t IOutStream::writeb(int v) |
| 51 |
{ |
| 52 |
uint8_t b = v; |
| 53 |
return write(&b, 1); |
| 54 |
} |
| 55 |
|
| 56 |
status_t IOutStream::write_byte(int v) |
| 57 |
{ |
| 58 |
uint8_t b = v; |
| 59 |
ssize_t n = write(&b, 1); |
| 60 |
if (n == 1) |
| 61 |
return STATUS_OK; |
| 62 |
return (n < 0) ? status_t(n) : STATUS_IO_ERROR; |
| 63 |
} |
| 64 |
|
| 65 |
wssize_t IOutStream::seek(wsize_t position) |
| 66 |
{ |
| 67 |
return - set_error(STATUS_NOT_IMPLEMENTED); |
| 68 |
} |
| 69 |
|
| 70 |
status_t IOutStream::flush() |
| 71 |
{ |
| 72 |
return - set_error(STATUS_NOT_IMPLEMENTED); |
| 73 |
} |
| 74 |
|
| 75 |
status_t IOutStream::close() |
| 76 |
{ |
| 77 |
return set_error(STATUS_OK); |
| 78 |
} |
| 79 |
|
| 80 |
status_t finalize(io::IOutStream *os, size_t wrap_flags) |
| 81 |
{ |
| 82 |
if (os == NULL) |
| 83 |
return STATUS_OK; |
| 84 |
status_t res = (wrap_flags & WRAP_CLOSE) ? os->close() : STATUS_OK; |
| 85 |
if (wrap_flags & WRAP_DELETE) |
| 86 |
delete os; |
| 87 |
return res; |
| 88 |
} |
| 89 |
|
| 90 |
} /* namespace ws */ |
| 91 |
} /* namespace lsp */ |