]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: cleanup get functions
authorKarel Zak <kzak@redhat.com>
Mon, 19 Sep 2016 11:39:03 +0000 (13:39 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 19 Sep 2016 11:39:03 +0000 (13:39 +0200)
The patch introduces tiny API changes (int -> size_t) for

scols_table_get_ncols
scols_table_get_nlines

Addresses: https://github.com/karelzak/util-linux/issues/349
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/cell.c
libsmartcols/src/column.c
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/line.c
libsmartcols/src/table.c

index 3d613f4473c2046320deba59d7e9f493247e3352..f2525cc4c528b6056f9657f4cb5afbed546becc1 100644 (file)
@@ -120,7 +120,7 @@ int scols_cell_set_userdata(struct libscols_cell *ce, void *data)
  */
 void *scols_cell_get_userdata(struct libscols_cell *ce)
 {
-       return ce ? ce->userdata : NULL;
+       return ce->userdata;
 }
 
 /**
@@ -182,7 +182,7 @@ int scols_cell_set_color(struct libscols_cell *ce, const char *co)
  */
 const char *scols_cell_get_color(const struct libscols_cell *ce)
 {
-       return ce ? ce->color : NULL;
+       return ce->color;
 }
 
 /**
@@ -207,11 +207,11 @@ int scols_cell_set_flags(struct libscols_cell *ce, int flags)
  * scols_cell_get_flags:
  * @ce: a pointer to a struct libscols_cell instance
  *
- * Returns: the current flags or -1 in case of an error.
+ * Returns: the current flags
  */
 int scols_cell_get_flags(const struct libscols_cell *ce)
 {
-       return ce ? ce->flags : -1;
+       return ce->flags;
 }
 
 /**
index 3d4017fdc28abdf7db0be96e17108b8f69ae275e..c83fe1e68e943045e80a13af61db140cb7869830 100644 (file)
@@ -140,8 +140,7 @@ int scols_column_set_whint(struct libscols_column *cl, double whint)
  */
 double scols_column_get_whint(struct libscols_column *cl)
 {
-       assert(cl);
-       return cl ? cl->width_hint : -EINVAL;
+       return cl->width_hint;
 }
 
 /**
@@ -177,8 +176,7 @@ int scols_column_set_flags(struct libscols_column *cl, int flags)
  */
 int scols_column_get_flags(struct libscols_column *cl)
 {
-       assert(cl);
-       return cl ? cl->flags : -EINVAL;
+       return cl->flags;
 }
 
 /**
@@ -190,7 +188,7 @@ int scols_column_get_flags(struct libscols_column *cl)
  */
 struct libscols_cell *scols_column_get_header(struct libscols_column *cl)
 {
-       return cl ? &cl->header : NULL;
+       return &cl->header;
 }
 
 /**
@@ -226,8 +224,7 @@ int scols_column_set_color(struct libscols_column *cl, const char *co)
  */
 const char *scols_column_get_color(struct libscols_column *cl)
 {
-       assert(cl);
-       return cl ? cl->color : NULL;
+       return cl->color;
 }
 
 
@@ -259,15 +256,13 @@ int scols_column_set_cmpfunc(struct libscols_column *cl,
  *
  * Gets the value of @cl's flag hidden.
  *
- * Returns: hidden flag value, negative value in case of an error.
+ * Returns: 0 or 1
  *
  * Since: 2.27
  */
 int scols_column_is_hidden(struct libscols_column *cl)
 {
-       if (!cl)
-               return -EINVAL;
-       return cl->flags & SCOLS_FL_HIDDEN;
+       return cl->flags & SCOLS_FL_HIDDEN ? 1 : 0;
 }
 
 /**
@@ -276,13 +271,11 @@ int scols_column_is_hidden(struct libscols_column *cl)
  *
  * Gets the value of @cl's flag trunc.
  *
- * Returns: trunc flag value, negative value in case of an error.
+ * Returns: 0 or 1
  */
 int scols_column_is_trunc(struct libscols_column *cl)
 {
-       if (!cl)
-               return -EINVAL;
-       return cl->flags & SCOLS_FL_TRUNC;
+       return cl->flags & SCOLS_FL_TRUNC ? 1 : 0;
 }
 /**
  * scols_column_is_tree:
@@ -290,13 +283,11 @@ int scols_column_is_trunc(struct libscols_column *cl)
  *
  * Gets the value of @cl's flag tree.
  *
- * Returns: tree flag value, negative value in case of an error.
+ * Returns: 0 or 1
  */
 int scols_column_is_tree(struct libscols_column *cl)
 {
-       if (!cl)
-               return -EINVAL;
-       return cl->flags & SCOLS_FL_TREE;
+       return cl->flags & SCOLS_FL_TREE ? 1 : 0;
 }
 /**
  * scols_column_is_right:
@@ -304,13 +295,11 @@ int scols_column_is_tree(struct libscols_column *cl)
  *
  * Gets the value of @cl's flag right.
  *
- * Returns: right flag value, negative value in case of an error.
+ * Returns: 0 or 1
  */
 int scols_column_is_right(struct libscols_column *cl)
 {
-       if (!cl)
-               return -EINVAL;
-       return cl->flags & SCOLS_FL_RIGHT;
+       return cl->flags & SCOLS_FL_RIGHT ? 1 : 0;
 }
 /**
  * scols_column_is_strict_width:
@@ -318,13 +307,11 @@ int scols_column_is_right(struct libscols_column *cl)
  *
  * Gets the value of @cl's flag strict_width.
  *
- * Returns: strict_width flag value, negative value in case of an error.
+ * Returns: 0 or 1
  */
 int scols_column_is_strict_width(struct libscols_column *cl)
 {
-       if (!cl)
-               return -EINVAL;
-       return cl->flags & SCOLS_FL_STRICTWIDTH;
+       return cl->flags & SCOLS_FL_STRICTWIDTH ? 1 : 0;
 }
 /**
  * scols_column_is_noextremes:
@@ -332,13 +319,11 @@ int scols_column_is_strict_width(struct libscols_column *cl)
  *
  * Gets the value of @cl's flag no_extremes.
  *
- * Returns: no_extremes flag value, negative value in case of an error.
+ * Returns: 0 or 1
  */
 int scols_column_is_noextremes(struct libscols_column *cl)
 {
-       if (!cl)
-               return -EINVAL;
-       return cl->flags & SCOLS_FL_NOEXTREMES;
+       return cl->flags & SCOLS_FL_NOEXTREMES ? 1 : 0;
 }
 /**
  * scols_column_is_wrap:
@@ -346,15 +331,13 @@ int scols_column_is_noextremes(struct libscols_column *cl)
  *
  * Gets the value of @cl's flag wrap.
  *
- * Returns: wrap flag value, negative value in case of an error.
+ * Returns: 0 or 1
  *
  * Since: 2.28
  */
 int scols_column_is_wrap(struct libscols_column *cl)
 {
-       if (!cl)
-               return -EINVAL;
-       return cl->flags & SCOLS_FL_WRAP;
+       return cl->flags & SCOLS_FL_WRAP ? 1 : 0;
 }
 /**
  * scols_column_is_wrapnl:
@@ -362,13 +345,11 @@ int scols_column_is_wrap(struct libscols_column *cl)
  *
  * Gets the value of @cl's flag wrap.
  *
- * Returns: wrapnl flag value, negative value in case of an error.
+ * Returns: 0 or 1
  *
  * Since: 2.29
  */
 int scols_column_is_wrapnl(struct libscols_column *cl)
 {
-       if (!cl)
-               return -EINVAL;
-       return cl->flags & SCOLS_FL_WRAPNL;
+       return cl->flags & SCOLS_FL_WRAPNL ? 1 : 0;
 }
index 41f514d711d90b4b098c8c4eb2cc413e8da65b73..c5ff1738475fcb80664f868af840ed034afe4206 100644 (file)
@@ -228,8 +228,8 @@ extern struct libscols_column *scols_table_new_column(struct libscols_table *tb,
 extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl);
 extern char *scols_table_get_column_separator(struct libscols_table *tb);
 extern char *scols_table_get_line_separator(struct libscols_table *tb);
-extern int scols_table_get_ncols(struct libscols_table *tb);
-extern int scols_table_get_nlines(struct libscols_table *tb);
+extern size_t scols_table_get_ncols(struct libscols_table *tb);
+extern size_t scols_table_get_nlines(struct libscols_table *tb);
 extern struct libscols_column *scols_table_get_column(struct libscols_table *tb, size_t n);
 extern int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln);
 extern int scols_table_remove_line(struct libscols_table *tb, struct libscols_line *ln);
index a0e3a856c78c69cb3e50f68b461dbe20dd651af7..365f6648a1868b794dffd502f14f581ce1816450 100644 (file)
@@ -168,12 +168,11 @@ int scols_line_set_userdata(struct libscols_line *ln, void *data)
  * scols_line_get_userdata:
  * @ln: a pointer to a struct libscols_line instance
  *
- * Returns: 0, a negative value in case of an error.
+ * Returns: user data
  */
 void *scols_line_get_userdata(struct libscols_line *ln)
 {
-       assert(ln);
-       return ln ? ln->userdata : NULL;
+       return ln->userdata;
 }
 
 /**
@@ -307,18 +306,18 @@ int scols_line_set_color(struct libscols_line *ln, const char *co)
  */
 const char *scols_line_get_color(struct libscols_line *ln)
 {
-       return ln ? ln->color : NULL;
+       return ln->color;
 }
 
 /**
  * scols_line_get_ncells:
  * @ln: a pointer to a struct libscols_line instance
  *
- * Returns: @ln's number of cells
+ * Returns: @ln's number of cells or a negative value in case of an error.
  */
 size_t scols_line_get_ncells(struct libscols_line *ln)
 {
-       return ln ? ln->ncells : 0;
+       return ln->ncells;
 }
 
 /**
index c0cf24636f57f6e62f5d1444abdf0b6e15209368..c41c6a12cae10b4284a64deb1b982875f559548f 100644 (file)
@@ -336,11 +336,11 @@ int scols_table_next_column(struct libscols_table *tb,
  * scols_table_get_ncols:
  * @tb: table
  *
- * Returns: the ncols table member, a negative number in case of an error.
+ * Returns: the ncols table member
  */
-int scols_table_get_ncols(struct libscols_table *tb)
+size_t scols_table_get_ncols(struct libscols_table *tb)
 {
-       return tb ? (int)tb->ncols : -EINVAL;
+       return tb->ncols;
 }
 
 /**
@@ -349,9 +349,9 @@ int scols_table_get_ncols(struct libscols_table *tb)
  *
  * Returns: the nlines table member, a negative number in case of an error.
  */
-int scols_table_get_nlines(struct libscols_table *tb)
+size_t scols_table_get_nlines(struct libscols_table *tb)
 {
-       return tb ? (int)tb->nlines : -EINVAL;
+       return tb->nlines;
 }
 
 /**
@@ -384,7 +384,7 @@ int scols_table_set_stream(struct libscols_table *tb, FILE *stream)
  */
 FILE *scols_table_get_stream(struct libscols_table *tb)
 {
-       return tb ? tb->out: NULL;
+       return tb->out;
 }
 
 /**
@@ -495,7 +495,6 @@ int scols_table_remove_line(struct libscols_table *tb,
  */
 void scols_table_remove_lines(struct libscols_table *tb)
 {
-       assert(tb);
        if (!tb)
                return;
 
@@ -919,7 +918,7 @@ int scols_table_enable_nowrap(struct libscols_table *tb, int enable)
  */
 int scols_table_colors_wanted(struct libscols_table *tb)
 {
-       return tb && tb->colors_wanted;
+       return tb->colors_wanted;
 }
 
 /**
@@ -930,7 +929,7 @@ int scols_table_colors_wanted(struct libscols_table *tb)
  */
 int scols_table_is_empty(struct libscols_table *tb)
 {
-       return !tb || !tb->nlines;
+       return !tb->nlines;
 }
 
 /**
@@ -941,7 +940,7 @@ int scols_table_is_empty(struct libscols_table *tb)
  */
 int scols_table_is_ascii(struct libscols_table *tb)
 {
-       return tb && tb->ascii;
+       return tb->ascii;
 }
 
 /**
@@ -952,7 +951,7 @@ int scols_table_is_ascii(struct libscols_table *tb)
  */
 int scols_table_is_noheadings(struct libscols_table *tb)
 {
-       return tb && tb->no_headings;
+       return tb->no_headings;
 }
 
 /**
@@ -963,7 +962,7 @@ int scols_table_is_noheadings(struct libscols_table *tb)
  */
 int scols_table_is_export(struct libscols_table *tb)
 {
-       return tb && tb->format == SCOLS_FMT_EXPORT;
+       return tb->format == SCOLS_FMT_EXPORT;
 }
 
 /**
@@ -974,7 +973,7 @@ int scols_table_is_export(struct libscols_table *tb)
  */
 int scols_table_is_raw(struct libscols_table *tb)
 {
-       return tb && tb->format == SCOLS_FMT_RAW;
+       return tb->format == SCOLS_FMT_RAW;
 }
 
 /**
@@ -987,7 +986,7 @@ int scols_table_is_raw(struct libscols_table *tb)
  */
 int scols_table_is_json(struct libscols_table *tb)
 {
-       return tb && tb->format == SCOLS_FMT_JSON;
+       return tb->format == SCOLS_FMT_JSON;
 }
 
 
@@ -995,11 +994,11 @@ int scols_table_is_json(struct libscols_table *tb)
  * scols_table_is_maxout
  * @tb: table
  *
- * Returns: 1 if output maximization is enabled, negative value in case of an error.
+ * Returns: 1 if output maximization is enabled or 0
  */
 int scols_table_is_maxout(struct libscols_table *tb)
 {
-       return tb && tb->maxout;
+       return tb->maxout;
 }
 
 /**
@@ -1010,7 +1009,7 @@ int scols_table_is_maxout(struct libscols_table *tb)
  */
 int scols_table_is_tree(struct libscols_table *tb)
 {
-       return tb && tb->ntreecols > 0;
+       return tb->ntreecols > 0;
 }
 
 /**
@@ -1050,8 +1049,6 @@ int scols_table_set_line_separator(struct libscols_table *tb, const char *sep)
  */
 char *scols_table_get_column_separator(struct libscols_table *tb)
 {
-       if (!tb)
-               return NULL;
        return tb->colsep;
 }
 
@@ -1063,8 +1060,6 @@ char *scols_table_get_column_separator(struct libscols_table *tb)
  */
 char *scols_table_get_line_separator(struct libscols_table *tb)
 {
-       if (!tb)
-               return NULL;
        return tb->linesep;
 
 }