summaryrefslogtreecommitdiff
path: root/test/run_gzip.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-11-10 12:58:03 +0100
committerMax Kellermann <max@musicpd.org>2016-11-10 12:58:03 +0100
commitdb6c0d54cfc2eb9741b4e5c7634f41eecb2d4703 (patch)
treed627f20dae9befcaf599139f81b9da49f221be23 /test/run_gzip.cxx
parenta17abc55573d1026533219567b3714a5298afdc9 (diff)
test/run_gzip: migrate from class Error to C++ exceptions
Diffstat (limited to 'test/run_gzip.cxx')
-rw-r--r--test/run_gzip.cxx37
1 files changed, 14 insertions, 23 deletions
diff --git a/test/run_gzip.cxx b/test/run_gzip.cxx
index 70aa10484..c3a31f47b 100644
--- a/test/run_gzip.cxx
+++ b/test/run_gzip.cxx
@@ -20,47 +20,43 @@
#include "config.h"
#include "fs/io/GzipOutputStream.hxx"
#include "fs/io/StdioOutputStream.hxx"
+#include "system/Error.hxx"
#include "Log.hxx"
-#include "util/Error.hxx"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-static bool
-Copy(OutputStream &dest, int src, Error &error)
+static void
+Copy(OutputStream &dest, int src)
{
while (true) {
char buffer[4096];
ssize_t nbytes = read(src, buffer, sizeof(buffer));
if (nbytes <= 0) {
- if (nbytes < 0) {
- error.SetErrno();
- return false;
- } else
- return true;
+ if (nbytes < 0)
+ throw MakeErrno("read() failed");
+
+ return;
}
dest.Write(buffer, nbytes);
}
}
-static bool
-CopyGzip(OutputStream &_dest, int src, Error &error)
+static void
+CopyGzip(OutputStream &_dest, int src)
{
GzipOutputStream dest(_dest);
- if (!Copy(dest, src, error))
- return false;
-
+ Copy(dest, src);
dest.Flush();
- return true;
}
-static bool
-CopyGzip(FILE *_dest, int src, Error &error)
+static void
+CopyGzip(FILE *_dest, int src)
{
StdioOutputStream dest(_dest);
- return CopyGzip(dest, src, error);
+ CopyGzip(dest, src);
}
int
@@ -72,12 +68,7 @@ main(int argc, gcc_unused char **argv)
}
try {
- Error error;
- if (!CopyGzip(stdout, STDIN_FILENO, error)) {
- fprintf(stderr, "%s\n", error.GetMessage());
- return EXIT_FAILURE;
- }
-
+ CopyGzip(stdout, STDIN_FILENO);
return EXIT_SUCCESS;
} catch (const std::exception &e) {
LogError(e);