{
fin = fdopen(fd, "r");
if (!fin)
- SN_THROW(IOErrorException(sformat("fdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
{
fin = fopen(name.c_str(), "re");
if (!fin)
- SN_THROW(IOErrorException(sformat("fopen failed errno:%d (%s)", errno,
- stringerror(errno).c_str())));
+ SN_THROW(IOErrorException(sformat("fopen '%s' for reading failed, errno:%d (%s)",
+ name.c_str(), errno, stringerror(errno).c_str())));
}
fin = nullptr;
if (fclose(tmp) != 0)
- SN_THROW(IOErrorException(sformat("fclose failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fclose failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
{
gz_file = gzdopen(fd, "r");
if (!gz_file)
- SN_THROW(IOErrorException(sformat("gzdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("gzdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
{
int fd = fileno(fin);
if (fd < 0)
- SN_THROW(IOErrorException(sformat("fileno failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fileno failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
fd = dup(fd);
if (fd < 0)
- SN_THROW(IOErrorException(sformat("dup failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("dup failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
gz_file = gzdopen(fd, "r");
if (!gz_file)
- SN_THROW(IOErrorException(sformat("gzdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("gzdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
fclose(fin);
{
int fd = open(name.c_str(), O_RDONLY | O_CLOEXEC | O_LARGEFILE);
if (fd < 0)
- SN_THROW(IOErrorException(sformat("open failed errno:%d (%s)", errno,
- stringerror(errno).c_str())));
+ SN_THROW(IOErrorException(sformat("open '%s' for reading failed, errno:%d (%s)",
+ name.c_str(), errno, stringerror(errno).c_str())));
gz_file = gzdopen(fd, "r");
if (!gz_file)
- SN_THROW(IOErrorException(sformat("gzdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("gzdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
int r = gzclose(tmp);
if (r != Z_OK)
- SN_THROW(IOErrorException(sformat("gzclose failed errnum:%d", r)));
+ SN_THROW(IOErrorException(sformat("gzclose failed, errnum:%d", r)));
}
int errnum = 0;
const char* msg = gzerror(gz_file, &errnum);
- SN_THROW(IOErrorException(sformat("gzread failed errno:%d (%s)", errnum, msg)));
+ SN_THROW(IOErrorException(sformat("gzread failed, errnum:%d (%s)", errnum, msg)));
}
buffer_read = 0;
{
fout = fdopen(fd, "w");
if (!fout)
- SN_THROW(IOErrorException(sformat("fdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
{
fout = fopen(name.c_str(), "we");
if (!fout)
- SN_THROW(IOErrorException(sformat("fopen failed errno:%d (%s)", errno,
- stringerror(errno).c_str())));
+ SN_THROW(IOErrorException(sformat("fopen '%s' for writing failed, errno:%d (%s)",
+ name.c_str(), errno, stringerror(errno).c_str())));
}
AsciiFileWriter::Impl::None::write_line(const string& line)
{
if (fprintf(fout, "%s\n", line.c_str()) != (int)(line.size() + 1))
- SN_THROW(IOErrorException(sformat("fprintf failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fprintf failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
fout = nullptr;
if (fclose(tmp) != 0)
- SN_THROW(IOErrorException(sformat("fclose failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fclose failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
{
gz_file = gzdopen(fd, "w");
if (!gz_file)
- SN_THROW(IOErrorException(sformat("gzdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("gzdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
{
int fd = fileno(fout);
if (fd < 0)
- SN_THROW(IOErrorException(sformat("fileno failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fileno failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
fd = dup(fd);
if (fd < 0)
- SN_THROW(IOErrorException(sformat("dup failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("dup failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
gz_file = gzdopen(fd, "w");
if (!gz_file)
- SN_THROW(IOErrorException(sformat("gzdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("gzdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
fclose(fout);
{
int fd = open(name.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_LARGEFILE, 0666);
if (fd < 0)
- SN_THROW(IOErrorException(sformat("open failed errno:%d (%s)", errno,
- stringerror(errno).c_str())));
+ SN_THROW(IOErrorException(sformat("open '%s' for writing failed, errno:%d (%s)",
+ name.c_str(), errno, stringerror(errno).c_str())));
gz_file = gzdopen(fd, "w");
if (!gz_file)
- SN_THROW(IOErrorException(sformat("gzdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("gzdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
int r = gzclose(tmp);
if (r != Z_OK)
- SN_THROW(IOErrorException(sformat("gzclose failed errnum:%d", r)));
+ SN_THROW(IOErrorException(sformat("gzclose failed, errnum:%d", r)));
}
void
AsciiFileWriter::Impl::Gzip::write_buffer()
{
+ if (buffer_fill == 0)
+ return;
+
int r = gzwrite(gz_file, buffer.data(), buffer_fill);
- if (r <= 0)
+ if (r < (int)(buffer_fill))
{
int errnum = 0;
const char* msg = gzerror(gz_file, &errnum);
- SN_THROW(IOErrorException(sformat("gzwrite failed errno:%d (%s)", errnum, msg)));
+ SN_THROW(IOErrorException(sformat("gzwrite failed, errnum:%d (%s)", errnum, msg)));
}
buffer_fill = 0;
{
fout = fdopen(fd, "w");
if (!fout)
- SN_THROW(IOErrorException(sformat("fdopen failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fdopen failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
{
fout = fopen(name.c_str(), "we");
if (!fout)
- SN_THROW(IOErrorException(sformat("fopen failed errno:%d (%s)", errno,
- stringerror(errno).c_str())));
+ SN_THROW(IOErrorException(sformat("fopen '%s' for writing failed, errno:%d (%s)",
+ name.c_str(), errno, stringerror(errno).c_str())));
}
fout = nullptr;
if (fclose(tmp) != 0)
- SN_THROW(IOErrorException(sformat("fclose failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("fclose failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
return;
if (unlink(name.c_str()) != 0)
- SN_THROW(IOErrorException(sformat("unlink failed errno:%d (%s)", errno,
+ SN_THROW(IOErrorException(sformat("unlink failed, errno:%d (%s)", errno,
stringerror(errno).c_str())));
}
else