icinga2/lib/base/stdiostream.cpp

59 lines
1.2 KiB
C++
Raw Permalink Normal View History

Replace all existing copyright headers with `SPDX` headers I've used the following command to replace the original copyright header lines in a C-style comment block: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` For files that use shell-style comments (#) like CMakeLists.txt, I've used this command: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` And for SQL files: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ```
2026-01-27 09:06:40 -05:00
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-2.0-or-later
2014-05-25 10:23:35 -04:00
#include "base/stdiostream.hpp"
#include "base/objectlock.hpp"
using namespace icinga;
2012-11-26 02:29:26 -05:00
/**
* Constructor for the StdioStream class.
*
* @param innerStream The inner stream.
* @param ownsStream Whether the new object owns the inner stream. If true
* the stream's destructor deletes the inner stream.
*/
2013-03-16 16:18:53 -04:00
StdioStream::StdioStream(std::iostream *innerStream, bool ownsStream)
2013-04-04 10:08:02 -04:00
: m_InnerStream(innerStream), m_OwnsStream(ownsStream)
{ }
StdioStream::~StdioStream()
{
Close();
}
size_t StdioStream::Read(void *buffer, size_t size)
{
2013-03-01 06:07:52 -05:00
ObjectLock olock(this);
2013-04-04 10:08:02 -04:00
m_InnerStream->read(static_cast<char *>(buffer), size);
return m_InnerStream->gcount();
}
void StdioStream::Write(const void *buffer, size_t size)
{
2013-03-01 06:07:52 -05:00
ObjectLock olock(this);
m_InnerStream->write(static_cast<const char *>(buffer), size);
}
void StdioStream::Close()
{
Stream::Close();
if (m_OwnsStream) {
2012-11-23 06:34:06 -05:00
delete m_InnerStream;
m_OwnsStream = false;
}
}
bool StdioStream::IsDataAvailable() const
{
return !IsEof();
}
bool StdioStream::IsEof() const
{
return !m_InnerStream->good();
}