bin/xbps-query: use fwrite directly.

Avoids allocations and an unnecessary loop (and printf usage, fputs
would have been enough).

Closes: #401 [via git-merge-pr]
This commit is contained in:
Érico Nogueira 2021-05-12 10:22:12 -03:00 committed by Duncan Overbruck
parent 08ad0c2a9b
commit b18499a62d
No known key found for this signature in database
GPG Key ID: 335C1D17EC3D6E35

View File

@ -106,17 +106,7 @@ print_value_obj(const char *keyname, xbps_object_t obj,
xbps_humanize_number(size, (int64_t)xbps_data_size(obj));
printf("%s%s%s%s: %s\n", indent, bold, keyname, reset, size);
} else {
FILE *f;
char buf[BUFSIZ-1];
void *data;
data = xbps_data_data(obj);
f = fmemopen(data, xbps_data_size(obj), "r");
assert(f);
while (fgets(buf, sizeof(buf), f))
printf("%s", buf);
fclose(f);
free(data);
fwrite(xbps_data_data_nocopy(obj), 1, xbps_data_size(obj), stdout);
}
break;
default: