2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/Pl_StdioFile.hh>
|
2009-09-26 18:36:04 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
#include <stdexcept>
|
2008-04-29 12:55:25 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
Pl_StdioFile::Pl_StdioFile(char const* identifier, FILE* f) :
|
|
|
|
Pipeline(identifier, 0),
|
|
|
|
file(f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Pl_StdioFile::~Pl_StdioFile()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-20 15:20:57 +00:00
|
|
|
Pl_StdioFile::write(unsigned char* buf, size_t len)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
size_t so_far = 0;
|
|
|
|
while (len > 0)
|
|
|
|
{
|
|
|
|
so_far = fwrite(buf, 1, len, this->file);
|
|
|
|
if (so_far == 0)
|
|
|
|
{
|
2009-09-26 18:36:04 +00:00
|
|
|
QUtil::throw_system_error(
|
|
|
|
this->identifier + ": Pl_StdioFile::write");
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf += so_far;
|
|
|
|
len -= so_far;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_StdioFile::finish()
|
|
|
|
{
|
|
|
|
if (fileno(this->file) != -1)
|
|
|
|
{
|
|
|
|
fflush(this->file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-26 18:36:04 +00:00
|
|
|
throw std::logic_error(
|
|
|
|
this->identifier +
|
|
|
|
": Pl_StdioFile::finish: stream already closed");
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
}
|