-/* $OpenBSD: json.c,v 1.6 2023/04/26 20:53:17 claudio Exp $ */
+/* $OpenBSD: json.c,v 1.7 2023/04/26 21:17:24 claudio Exp $ */
/*
* Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
{
if (stack[level].count++ > 0)
if (!eb)
- eb = fprintf(jsonfh, ",\n") == -1;
+ eb = fprintf(jsonfh, ",\n") < 0;
if (!eb)
- eb = fprintf(jsonfh, "\t%.*s", level, indent) == -1;
+ eb = fprintf(jsonfh, "\t%.*s", level, indent) < 0;
}
static void
if (stack[level].type == ARRAY)
return;
if (!eb)
- eb = fprintf(jsonfh, "\"%s\": ", name) == -1;
+ eb = fprintf(jsonfh, "\"%s\": ", name) < 0;
}
static int
jsonfh = fh;
eb = 0;
- eb = fprintf(jsonfh, "{\n") == -1;
+ eb = fprintf(jsonfh, "{\n") < 0;
}
int
while (level > 0)
json_do_end();
if (!eb)
- eb = fprintf(jsonfh, "\n}\n") == -1;
+ eb = fprintf(jsonfh, "\n}\n") < 0;
return -eb;
}
do_comma_indent();
do_name(name);
if (!eb)
- eb = fprintf(jsonfh, "[\n") == -1;
+ eb = fprintf(jsonfh, "[\n") < 0;
if (++level >= JSON_MAX_STACK)
errx(1, "json stack too deep");
do_comma_indent();
do_name(name);
if (!eb)
- eb = fprintf(jsonfh, "{\n") == -1;
+ eb = fprintf(jsonfh, "{\n") < 0;
if (++level >= JSON_MAX_STACK)
errx(1, "json stack too deep");
{
if (stack[level].type == ARRAY) {
if (!eb)
- eb = fprintf(jsonfh, "\n%.*s]", level, indent) == -1;
+ eb = fprintf(jsonfh, "\n%.*s]", level, indent) < 0;
} else if (stack[level].type == OBJECT) {
if (!eb)
- eb = fprintf(jsonfh, "\n%.*s}", level, indent) == -1;
+ eb = fprintf(jsonfh, "\n%.*s}", level, indent) < 0;
} else {
errx(1, "json bad stack state");
}
do_name(name);
if (!eb)
- eb = fprintf(jsonfh, "\"") == -1;
+ eb = fprintf(jsonfh, "\"") < 0;
va_start(ap, fmt);
if (!eb)
- eb = vfprintf(jsonfh, fmt, ap) == -1;
+ eb = vfprintf(jsonfh, fmt, ap) < 0;
va_end(ap);
if (!eb)
- eb = fprintf(jsonfh, "\"") == -1;
+ eb = fprintf(jsonfh, "\"") < 0;
}
void
do_comma_indent();
do_name(name);
if (!eb)
- eb = fprintf(jsonfh, "\"") == -1;
+ eb = fprintf(jsonfh, "\"") < 0;
for (i = 0; i < len; i++)
if (!eb)
- eb = fprintf(jsonfh, "%02x", *(data + i)) == -1;
+ eb = fprintf(jsonfh, "%02x", *(data + i)) < 0;
if (!eb)
- eb = fprintf(jsonfh, "\"") == -1;
+ eb = fprintf(jsonfh, "\"") < 0;
}
void
do_name(name);
if (v) {
if (!eb)
- eb = fprintf(jsonfh, "true") == -1;
+ eb = fprintf(jsonfh, "true") < 0;
} else {
if (!eb)
- eb = fprintf(jsonfh, "false") == -1;
+ eb = fprintf(jsonfh, "false") < 0;
}
}
do_comma_indent();
do_name(name);
if (!eb)
- eb = fprintf(jsonfh, "%llu", v) == -1;
+ eb = fprintf(jsonfh, "%llu", v) < 0;
}
void
do_comma_indent();
do_name(name);
if (!eb)
- eb = fprintf(jsonfh, "%lld", v) == -1;
+ eb = fprintf(jsonfh, "%lld", v) < 0;
}
void
do_comma_indent();
do_name(name);
if (!eb)
- eb = fprintf(jsonfh, "%f", v) == -1;
+ eb = fprintf(jsonfh, "%f", v) < 0;
}