2012-06-25 14:51:44 +00:00
|
|
|
#include <qpdf/qpdf-config.h> // include first for large file support
|
2022-02-04 21:31:31 +00:00
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/Pl_StdioFile.hh>
|
2022-02-04 21:31:31 +00:00
|
|
|
|
2009-09-26 18:36:04 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
2023-05-20 11:22:32 +00:00
|
|
|
#include <cerrno>
|
2009-09-26 18:36:04 +00:00
|
|
|
#include <stdexcept>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2019-06-22 01:32:47 +00:00
|
|
|
Pl_StdioFile::Members::Members(FILE* f) :
|
|
|
|
file(f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
Pl_StdioFile::Pl_StdioFile(char const* identifier, FILE* f) :
|
2022-07-26 11:37:50 +00:00
|
|
|
Pipeline(identifier, nullptr),
|
2019-06-22 01:32:47 +00:00
|
|
|
m(new Members(f))
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Pl_StdioFile::~Pl_StdioFile()
|
|
|
|
{
|
2022-04-15 23:44:07 +00:00
|
|
|
// Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-05-03 21:43:07 +00:00
|
|
|
Pl_StdioFile::write(unsigned char const* buf, size_t len)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
size_t so_far = 0;
|
|
|
|
while (len > 0) {
|
2022-02-08 14:18:08 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl_StdioFile::finish()
|
|
|
|
{
|
2019-06-22 01:32:47 +00:00
|
|
|
if ((fflush(m->file) == -1) && (errno == EBADF)) {
|
2022-02-08 14:18:08 +00:00
|
|
|
throw std::logic_error(this->identifier + ": Pl_StdioFile::finish: stream already closed");
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
}
|