test/run_gzip: migrate from class Error to C++ exceptions
This commit is contained in:
parent
a17abc5557
commit
db6c0d54cf
@ -20,47 +20,43 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "fs/io/GzipOutputStream.hxx"
|
#include "fs/io/GzipOutputStream.hxx"
|
||||||
#include "fs/io/StdioOutputStream.hxx"
|
#include "fs/io/StdioOutputStream.hxx"
|
||||||
|
#include "system/Error.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "util/Error.hxx"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
Copy(OutputStream &dest, int src, Error &error)
|
Copy(OutputStream &dest, int src)
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
ssize_t nbytes = read(src, buffer, sizeof(buffer));
|
ssize_t nbytes = read(src, buffer, sizeof(buffer));
|
||||||
if (nbytes <= 0) {
|
if (nbytes <= 0) {
|
||||||
if (nbytes < 0) {
|
if (nbytes < 0)
|
||||||
error.SetErrno();
|
throw MakeErrno("read() failed");
|
||||||
return false;
|
|
||||||
} else
|
return;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dest.Write(buffer, nbytes);
|
dest.Write(buffer, nbytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
CopyGzip(OutputStream &_dest, int src, Error &error)
|
CopyGzip(OutputStream &_dest, int src)
|
||||||
{
|
{
|
||||||
GzipOutputStream dest(_dest);
|
GzipOutputStream dest(_dest);
|
||||||
if (!Copy(dest, src, error))
|
Copy(dest, src);
|
||||||
return false;
|
|
||||||
|
|
||||||
dest.Flush();
|
dest.Flush();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
CopyGzip(FILE *_dest, int src, Error &error)
|
CopyGzip(FILE *_dest, int src)
|
||||||
{
|
{
|
||||||
StdioOutputStream dest(_dest);
|
StdioOutputStream dest(_dest);
|
||||||
return CopyGzip(dest, src, error);
|
CopyGzip(dest, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -72,12 +68,7 @@ main(int argc, gcc_unused char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Error error;
|
CopyGzip(stdout, STDIN_FILENO);
|
||||||
if (!CopyGzip(stdout, STDIN_FILENO, error)) {
|
|
||||||
fprintf(stderr, "%s\n", error.GetMessage());
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
LogError(e);
|
LogError(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user