Qore Programming Language  1.7.0
StderrOutputStream.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  StderrOutputStream.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2016 - 2022 Qore Technologies, s.r.o.
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_STDERROUTPUTSTREAM_H
33 #define _QORE_STDERROUTPUTSTREAM_H
34 
35 #include "qore/OutputStream.h"
36 
41 
42 public:
43  DLLLOCAL StderrOutputStream() {
44  }
45 
46  DLLLOCAL const char *getName() override {
47  return "StderrOutputStream";
48  }
49 
50  DLLLOCAL bool isClosed() override {
51  return false;
52  }
53 
54  DLLLOCAL void close(ExceptionSink* xsink) override {
55  return;
56  }
57 
58  DLLLOCAL void write(const void *ptr, int64 count, ExceptionSink *xsink) override {
59  assert(count >= 0);
60  if (count < 0)
61  return;
62  const char* current = reinterpret_cast<const char*>(ptr);
63  int64 blockCount = count / WRITE_BLOCK_SIZE;
64  for (int64 i = 0; i < blockCount; i++) {
65  fwrite(current, WRITE_BLOCK_SIZE, 1, stderr);
66  current = (current + WRITE_BLOCK_SIZE);
67  count -= WRITE_BLOCK_SIZE;
68  }
69  fwrite(ptr, count, 1, stderr);
70  }
71 private:
72  static const int WRITE_BLOCK_SIZE = 1024;
73 };
74 
75 #endif // _QORE_STDERROUTPUTSTREAM_H
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
Interface for private data of output streams.
Definition: OutputStream.h:44
Private data for the Qore::StderrOutputStream class.
Definition: StderrOutputStream.h:40
DLLLOCAL void close(ExceptionSink *xsink) override
Flushes any buffered (unwritten) bytes, closes the output stream and releases resources.
Definition: StderrOutputStream.h:54
DLLLOCAL const char * getName() override
Returns the name of the class.
Definition: StderrOutputStream.h:46
DLLLOCAL void write(const void *ptr, int64 count, ExceptionSink *xsink) override
Writes bytes to the output stream.
Definition: StderrOutputStream.h:58
DLLLOCAL bool isClosed() override
Returns true is the stream has been closed.
Definition: StderrOutputStream.h:50
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260