File: Pl_StdioFile.cc

package info (click to toggle)
qpdf 2.3.1-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 12,084 kB
  • sloc: cpp: 18,192; sh: 9,543; perl: 4,578; xml: 2,727; ansic: 712; makefile: 92
file content (49 lines) | stat: -rw-r--r-- 777 bytes parent folder | download | duplicates (2)
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
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QUtil.hh>
#include <stdexcept>
#include <errno.h>

Pl_StdioFile::Pl_StdioFile(char const* identifier, FILE* f) :
    Pipeline(identifier, 0),
    file(f)
{
}

Pl_StdioFile::~Pl_StdioFile()
{
}

void
Pl_StdioFile::write(unsigned char* buf, int len)
{
    size_t so_far = 0;
    while (len > 0)
    {
	so_far = fwrite(buf, 1, len, this->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()
{
    if (fileno(this->file) != -1)
    {
	fflush(this->file);
    }
    else
    {
	throw std::logic_error(
	    this->identifier +
	    ": Pl_StdioFile::finish: stream already closed");
    }
}