projects
/
openvswitch
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bridge: Always wait for MAC learning table and ports.
[openvswitch]
/
tests
/
test-json.c
diff --git
a/tests/test-json.c
b/tests/test-json.c
index 6261786db0a0e4a6139d33230b50dbd6553a7b69..f297dc205ea0c0f0d804ec6a61e094158a485fe6 100644
(file)
--- a/
tests/test-json.c
+++ b/
tests/test-json.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009
, 2010
Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-67,23
+67,17
@@
refill(FILE *file, void *buffer, size_t buffer_size, size_t *n, size_t *used)
}
static bool
}
static bool
-parse_multiple(
const char *input_file
)
+parse_multiple(
FILE *stream
)
{
struct json_parser *parser;
char buffer[BUFSIZ];
size_t n, used;
{
struct json_parser *parser;
char buffer[BUFSIZ];
size_t n, used;
- FILE *file;
bool ok;
bool ok;
- file = fopen(input_file, "r");
- if (!file) {
- ovs_fatal(errno, "Cannot open \"%s\"", input_file);
- }
-
parser = NULL;
n = used = 0;
ok = true;
parser = NULL;
n = used = 0;
ok = true;
- while (used < n || refill(
file
, buffer, sizeof buffer, &n, &used)) {
+ while (used < n || refill(
stream
, buffer, sizeof buffer, &n, &used)) {
if (!parser && isspace((unsigned char) buffer[used])) {
/* Skip white space. */
used++;
if (!parser && isspace((unsigned char) buffer[used])) {
/* Skip white space. */
used++;
@@
-113,6
+107,7
@@
int
main(int argc, char *argv[])
{
const char *input_file;
main(int argc, char *argv[])
{
const char *input_file;
+ FILE *stream;
bool ok;
set_program_name(argv[0]);
bool ok;
set_program_name(argv[0]);
@@
-146,15
+141,18
@@
main(int argc, char *argv[])
}
input_file = argv[optind];
}
input_file = argv[optind];
- if (!strcmp(input_file, "-")) {
- input_file = "/dev/stdin";
+ stream = !strcmp(input_file, "-") ? stdin : fopen(input_file, "r");
+ if (!stream) {
+ ovs_fatal(errno, "Cannot open \"%s\"", input_file);
}
if (multiple) {
}
if (multiple) {
- ok = parse_multiple(
input_file
);
+ ok = parse_multiple(
stream
);
} else {
} else {
- ok = print_and_free_json(json_from_
file(input_file
));
+ ok = print_and_free_json(json_from_
stream(stream
));
}
}
+ fclose(stream);
+
return !ok;
}
return !ok;
}