From: Karel Zak Date: Wed, 18 Apr 2018 12:45:21 +0000 (+0200) Subject: findmnt: use scols_column_set_json_type() X-Git-Tag: v2.33-rc1~303 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a645e3658095e7e7dbdebbc938ddb85bbbc02bb;p=thirdparty%2Futil-linux.git findmnt: use scols_column_set_json_type() Signed-off-by: Karel Zak --- diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 184b6f7d7b..4d55cde33d 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -1606,6 +1606,7 @@ int main(int argc, char *argv[]) scols_table_set_name(table, "filesystems"); for (i = 0; i < ncolumns; i++) { + struct libscols_column *cl; int fl = get_column_flags(i); int id = get_column_id(i); @@ -1617,11 +1618,32 @@ int main(int argc, char *argv[]) "is not enabled"), get_column_name(i)); goto leave; } - if (!scols_table_new_column(table, get_column_name(i), - get_column_whint(i), fl)) { + cl = scols_table_new_column(table, get_column_name(i), + get_column_whint(i), fl); + if (!cl) { warn(_("failed to allocate output column")); goto leave; } + + if (flags & FL_JSON) { + switch (id) { + case COL_SIZE: + case COL_AVAIL: + case COL_USED: + if (!(flags & FL_BYTES)) + break; + /* fallthrough */ + case COL_ID: + case COL_FREQ: + case COL_PASSNO: + case COL_TID: + scols_column_set_json_type(cl, SCOLS_JSON_NUMBER); + break; + default: + scols_column_set_json_type(cl, SCOLS_JSON_STRING); + break; + } + } } /*