test/run_input: make variables more local

This commit is contained in:
Max Kellermann 2014-11-25 07:51:33 +01:00
parent 951bad46e0
commit b19e5720cc

View File

@ -54,11 +54,6 @@ tag_save(FILE *file, const Tag &tag)
static int static int
dump_input_stream(InputStream *is) dump_input_stream(InputStream *is)
{ {
Error error;
char buffer[4096];
size_t num_read;
ssize_t num_written;
is->Lock(); is->Lock();
/* print meta data */ /* print meta data */
@ -76,7 +71,9 @@ dump_input_stream(InputStream *is)
delete tag; delete tag;
} }
num_read = is->Read(buffer, sizeof(buffer), error); Error error;
char buffer[4096];
size_t num_read = is->Read(buffer, sizeof(buffer), error);
if (num_read == 0) { if (num_read == 0) {
if (error.IsDefined()) if (error.IsDefined())
LogError(error); LogError(error);
@ -84,11 +81,12 @@ dump_input_stream(InputStream *is)
break; break;
} }
num_written = write(1, buffer, num_read); ssize_t num_written = write(1, buffer, num_read);
if (num_written <= 0) if (num_written <= 0)
break; break;
} }
Error error;
if (!is->Check(error)) { if (!is->Check(error)) {
LogError(error); LogError(error);
is->Unlock(); is->Unlock();
@ -102,10 +100,6 @@ dump_input_stream(InputStream *is)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Error error;
InputStream *is;
int ret;
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: run_input URI\n"); fprintf(stderr, "Usage: run_input URI\n");
return EXIT_FAILURE; return EXIT_FAILURE;
@ -129,6 +123,7 @@ int main(int argc, char **argv)
archive_plugin_init_all(); archive_plugin_init_all();
#endif #endif
Error error;
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
LogError(error); LogError(error);
return 2; return 2;
@ -139,7 +134,8 @@ int main(int argc, char **argv)
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
is = InputStream::OpenReady(argv[1], mutex, cond, error); InputStream *is = InputStream::OpenReady(argv[1], mutex, cond, error);
int ret;
if (is != NULL) { if (is != NULL) {
ret = dump_input_stream(is); ret = dump_input_stream(is);
delete is; delete is;