File: Pl_StdioFile.cc

package info (click to toggle)
qpdf 12.3.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 72,644 kB
  • sloc: cpp: 59,031; perl: 12,172; ansic: 6,809; sh: 1,231; python: 1,041; xml: 43; makefile: 42
file content (56 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <qpdf/qpdf-config.h> // include first for large file support

#include <qpdf/Pl_StdioFile.hh>

#include <qpdf/QUtil.hh>
#include <qpdf/Util.hh>

#include <cerrno>
#include <stdexcept>

using namespace qpdf;

class Pl_StdioFile::Members
{
  public:
    Members(FILE* f) :
        file(f)
    {
    }
    Members(Members const&) = delete;
    ~Members() = default;

    FILE* file;
};

Pl_StdioFile::Pl_StdioFile(char const* identifier, FILE* f) :
    Pipeline(identifier, nullptr),
    m(std::make_unique<Members>(f))
{
}

// Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer
Pl_StdioFile::~Pl_StdioFile() = default;

void
Pl_StdioFile::write(unsigned char const* buf, size_t len)
{
    size_t so_far = 0;
    while (len > 0) {
        so_far = fwrite(buf, 1, len, m->file);
        if (so_far == 0) {
            QUtil::throw_system_error(this->identifier + ": Pl_StdioFile::write");
        } else {
            buf += so_far;
            len -= so_far;
        }
    }
}

void
Pl_StdioFile::finish()
{
    util::assertion(
        !(fflush(m->file) == -1 && errno == EBADF),
        identifier + ": Pl_StdioFile::finish: stream already closed");
}