2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-16 09:37:08 +00:00
qpdf/libqpdf/Pl_StdioFile.cc
Jay Berkenbilt 5d4cad9c02 ABI change: fix use of off_t, size_t, and integer types
Significantly improve the code's use of off_t for file offsets, size_t
for memory sizes, and integer types in cases where there has to be
compatibility with external interfaces.  Rework sections of the code
that would have prevented qpdf from working on files larger than 2 (or
maybe 4) GB in size.
2012-06-20 15:20:26 -04:00

50 lines
780 B
C++

#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, size_t 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");
}
}