* 'api_const' of https://github.com/ignatenkobrain/util-linux:
  libsmartcols: use const qualifier where it's possible
  debug: use const void * for ul_debugobj()
  libsmartcols: make get_line/column_separator() return const
This commit is contained in:
Karel Zak 2016-09-23 11:14:15 +02:00
commit 266eecd54e
10 changed files with 70 additions and 77 deletions

View File

@ -105,7 +105,7 @@ ul_debug(const char *mesg, ...)
}
static inline void __attribute__ ((__format__ (__printf__, 2, 3)))
ul_debugobj(void *handler, const char *mesg, ...)
ul_debugobj(const void *handler, const char *mesg, ...)
{
va_list ap;

View File

@ -310,7 +310,7 @@ struct fdisk_parttype *fdisk_label_parse_parttype(
if (!lb->nparttypes)
return NULL;
DBG(LABEL, ul_debugobj((void *) lb, "parsing '%s' (%s) partition type",
DBG(LABEL, ul_debugobj(lb, "parsing '%s' (%s) partition type",
str, lb->name));
types = lb->parttypes;
@ -321,7 +321,7 @@ struct fdisk_parttype *fdisk_label_parse_parttype(
code = strtol(str, &end, 16);
if (errno || *end != '\0') {
DBG(LABEL, ul_debugobj((void *) lb, "parsing failed: %m"));
DBG(LABEL, ul_debugobj(lb, "parsing failed: %m"));
return NULL;
}
ret = fdisk_label_get_parttype_from_code(lb, code);

View File

@ -234,6 +234,6 @@ int scols_cell_copy_content(struct libscols_cell *dest,
if (!rc)
dest->userdata = src->userdata;
DBG(CELL, ul_debugobj((void *) src, "copy into %p", dest));
DBG(CELL, ul_debugobj(src, "copy into %p", dest));
return rc;
}

View File

@ -93,7 +93,7 @@ struct libscols_column *scols_copy_column(const struct libscols_column *cl)
if (!ret)
return NULL;
DBG(COL, ul_debugobj((void *) cl, "copy to %p", ret));
DBG(COL, ul_debugobj(cl, "copy to %p", ret));
if (scols_column_set_color(ret, cl->color))
goto err;
@ -138,7 +138,7 @@ int scols_column_set_whint(struct libscols_column *cl, double whint)
*
* Returns: The width hint of column @cl, a negative value in case of an error.
*/
double scols_column_get_whint(struct libscols_column *cl)
double scols_column_get_whint(const struct libscols_column *cl)
{
return cl->width_hint;
}
@ -174,7 +174,7 @@ int scols_column_set_flags(struct libscols_column *cl, int flags)
*
* Returns: The flag mask of @cl, a negative value in case of an error.
*/
int scols_column_get_flags(struct libscols_column *cl)
int scols_column_get_flags(const struct libscols_column *cl)
{
return cl->flags;
}
@ -222,7 +222,7 @@ int scols_column_set_color(struct libscols_column *cl, const char *co)
*
* Returns: The current color setting of the column @cl.
*/
const char *scols_column_get_color(struct libscols_column *cl)
const char *scols_column_get_color(const struct libscols_column *cl)
{
return cl->color;
}
@ -260,7 +260,7 @@ int scols_column_set_cmpfunc(struct libscols_column *cl,
*
* Since: 2.27
*/
int scols_column_is_hidden(struct libscols_column *cl)
int scols_column_is_hidden(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_HIDDEN ? 1 : 0;
}
@ -273,7 +273,7 @@ int scols_column_is_hidden(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_trunc(struct libscols_column *cl)
int scols_column_is_trunc(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_TRUNC ? 1 : 0;
}
@ -285,7 +285,7 @@ int scols_column_is_trunc(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_tree(struct libscols_column *cl)
int scols_column_is_tree(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_TREE ? 1 : 0;
}
@ -297,7 +297,7 @@ int scols_column_is_tree(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_right(struct libscols_column *cl)
int scols_column_is_right(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_RIGHT ? 1 : 0;
}
@ -309,7 +309,7 @@ int scols_column_is_right(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_strict_width(struct libscols_column *cl)
int scols_column_is_strict_width(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_STRICTWIDTH ? 1 : 0;
}
@ -321,7 +321,7 @@ int scols_column_is_strict_width(struct libscols_column *cl)
*
* Returns: 0 or 1
*/
int scols_column_is_noextremes(struct libscols_column *cl)
int scols_column_is_noextremes(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_NOEXTREMES ? 1 : 0;
}
@ -335,7 +335,7 @@ int scols_column_is_noextremes(struct libscols_column *cl)
*
* Since: 2.28
*/
int scols_column_is_wrap(struct libscols_column *cl)
int scols_column_is_wrap(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_WRAP ? 1 : 0;
}
@ -349,7 +349,7 @@ int scols_column_is_wrap(struct libscols_column *cl)
*
* Since: 2.29
*/
int scols_column_is_wrapnl(struct libscols_column *cl)
int scols_column_is_wrapnl(const struct libscols_column *cl)
{
return cl->flags & SCOLS_FL_WRAPNL ? 1 : 0;
}

View File

@ -68,7 +68,7 @@ void scols_reset_iter(struct libscols_iter *itr, int direction)
*
* Returns: SCOLS_INTER_{FOR,BACK}WARD
*/
int scols_iter_get_direction(struct libscols_iter *itr)
int scols_iter_get_direction(const struct libscols_iter *itr)
{
return itr->direction;
}

View File

@ -100,7 +100,7 @@ enum {
extern struct libscols_iter *scols_new_iter(int direction);
extern void scols_free_iter(struct libscols_iter *itr);
extern void scols_reset_iter(struct libscols_iter *itr, int direction);
extern int scols_iter_get_direction(struct libscols_iter *itr);
extern int scols_iter_get_direction(const struct libscols_iter *itr);
/* init.c */
extern void scols_init_debug(int mask);
@ -139,26 +139,26 @@ extern int scols_cell_set_userdata(struct libscols_cell *ce, void *data);
extern int scols_cmpstr_cells(struct libscols_cell *a,
struct libscols_cell *b, void *data);
/* column.c */
extern int scols_column_is_tree(struct libscols_column *cl);
extern int scols_column_is_trunc(struct libscols_column *cl);
extern int scols_column_is_right(struct libscols_column *cl);
extern int scols_column_is_strict_width(struct libscols_column *cl);
extern int scols_column_is_hidden(struct libscols_column *cl);
extern int scols_column_is_noextremes(struct libscols_column *cl);
extern int scols_column_is_wrap(struct libscols_column *cl);
extern int scols_column_is_wrapnl(struct libscols_column *cl);
extern int scols_column_is_tree(const struct libscols_column *cl);
extern int scols_column_is_trunc(const struct libscols_column *cl);
extern int scols_column_is_right(const struct libscols_column *cl);
extern int scols_column_is_strict_width(const struct libscols_column *cl);
extern int scols_column_is_hidden(const struct libscols_column *cl);
extern int scols_column_is_noextremes(const struct libscols_column *cl);
extern int scols_column_is_wrap(const struct libscols_column *cl);
extern int scols_column_is_wrapnl(const struct libscols_column *cl);
extern int scols_column_set_flags(struct libscols_column *cl, int flags);
extern int scols_column_get_flags(struct libscols_column *cl);
extern int scols_column_get_flags(const struct libscols_column *cl);
extern struct libscols_column *scols_new_column(void);
extern void scols_ref_column(struct libscols_column *cl);
extern void scols_unref_column(struct libscols_column *cl);
extern struct libscols_column *scols_copy_column(const struct libscols_column *cl);
extern int scols_column_set_whint(struct libscols_column *cl, double whint);
extern double scols_column_get_whint(struct libscols_column *cl);
extern double scols_column_get_whint(const struct libscols_column *cl);
extern struct libscols_cell *scols_column_get_header(struct libscols_column *cl);
extern int scols_column_set_color(struct libscols_column *cl, const char *color);
extern const char *scols_column_get_color(struct libscols_column *cl);
extern const char *scols_column_get_color(const struct libscols_column *cl);
extern int scols_column_set_cmpfunc(struct libscols_column *cl,
int (*cmp)(struct libscols_cell *a,
@ -178,10 +178,10 @@ extern int scols_line_add_child(struct libscols_line *ln, struct libscols_line *
extern int scols_line_has_children(struct libscols_line *ln);
extern int scols_line_next_child(struct libscols_line *ln,
struct libscols_iter *itr, struct libscols_line **chld);
extern struct libscols_line *scols_line_get_parent(struct libscols_line *ln);
extern struct libscols_line *scols_line_get_parent(const struct libscols_line *ln);
extern int scols_line_set_color(struct libscols_line *ln, const char *color);
extern const char *scols_line_get_color(struct libscols_line *ln);
extern size_t scols_line_get_ncells(struct libscols_line *ln);
extern const char *scols_line_get_color(const struct libscols_line *ln);
extern size_t scols_line_get_ncells(const struct libscols_line *ln);
extern struct libscols_cell *scols_line_get_cell(struct libscols_line *ln, size_t n);
extern struct libscols_cell *scols_line_get_column_cell(
struct libscols_line *ln,
@ -190,20 +190,20 @@ extern int scols_line_set_data(struct libscols_line *ln, size_t n, const char *d
extern int scols_line_refer_data(struct libscols_line *ln, size_t n, char *data);
extern int scols_line_set_column_data(struct libscols_line *ln, struct libscols_column *cl, const char *data);
extern int scols_line_refer_column_data(struct libscols_line *ln, struct libscols_column *cl, char *data);
extern struct libscols_line *scols_copy_line(struct libscols_line *ln);
extern struct libscols_line *scols_copy_line(const struct libscols_line *ln);
/* table */
extern int scols_table_colors_wanted(struct libscols_table *tb);
extern int scols_table_colors_wanted(const struct libscols_table *tb);
extern int scols_table_set_name(struct libscols_table *tb, const char *name);
extern struct libscols_cell *scols_table_get_title(struct libscols_table *tb);
extern int scols_table_is_raw(struct libscols_table *tb);
extern int scols_table_is_ascii(struct libscols_table *tb);
extern int scols_table_is_json(struct libscols_table *tb);
extern int scols_table_is_noheadings(struct libscols_table *tb);
extern int scols_table_is_empty(struct libscols_table *tb);
extern int scols_table_is_export(struct libscols_table *tb);
extern int scols_table_is_maxout(struct libscols_table *tb);
extern int scols_table_is_tree(struct libscols_table *tb);
extern int scols_table_is_raw(const struct libscols_table *tb);
extern int scols_table_is_ascii(const struct libscols_table *tb);
extern int scols_table_is_json(const struct libscols_table *tb);
extern int scols_table_is_noheadings(const struct libscols_table *tb);
extern int scols_table_is_empty(const struct libscols_table *tb);
extern int scols_table_is_export(const struct libscols_table *tb);
extern int scols_table_is_maxout(const struct libscols_table *tb);
extern int scols_table_is_tree(const struct libscols_table *tb);
extern int scols_table_enable_colors(struct libscols_table *tb, int enable);
extern int scols_table_enable_raw(struct libscols_table *tb, int enable);
@ -226,10 +226,10 @@ extern int scols_table_remove_column(struct libscols_table *tb, struct libscols_
extern int scols_table_remove_columns(struct libscols_table *tb);
extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags);
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 size_t scols_table_get_ncols(struct libscols_table *tb);
extern size_t scols_table_get_nlines(struct libscols_table *tb);
extern const char *scols_table_get_column_separator(const struct libscols_table *tb);
extern const char *scols_table_get_line_separator(const struct libscols_table *tb);
extern size_t scols_table_get_ncols(const struct libscols_table *tb);
extern size_t scols_table_get_nlines(const 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);
@ -241,7 +241,7 @@ extern struct libscols_table *scols_copy_table(struct libscols_table *tb);
extern int scols_table_set_symbols(struct libscols_table *tb, struct libscols_symbols *sy);
extern int scols_table_set_stream(struct libscols_table *tb, FILE *stream);
extern FILE *scols_table_get_stream(struct libscols_table *tb);
extern FILE *scols_table_get_stream(const struct libscols_table *tb);
extern int scols_table_reduce_termwidth(struct libscols_table *tb, size_t reduce);
extern int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl);
@ -255,7 +255,7 @@ enum {
SCOLS_TERMFORCE_ALWAYS
};
extern int scols_table_set_termforce(struct libscols_table *tb, int force);
extern int scols_table_get_termforce(struct libscols_table *tb);
extern int scols_table_get_termforce(const struct libscols_table *tb);
extern int scols_table_set_termwidth(struct libscols_table *tb, size_t width);
extern size_t scols_table_get_termwidth(struct libscols_table *tb);

View File

@ -71,7 +71,6 @@ void scols_ref_line(struct libscols_line *ln)
*/
void scols_unref_line(struct libscols_line *ln)
{
if (ln && --ln->refcount <= 0) {
DBG(CELL, ul_debugobj(ln, "dealloc"));
list_del(&ln->ln_lines);
@ -235,7 +234,7 @@ int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child)
*
* Returns: a pointer to @ln's parent, NULL in case it has no parent or if there was an error.
*/
struct libscols_line *scols_line_get_parent(struct libscols_line *ln)
struct libscols_line *scols_line_get_parent(const struct libscols_line *ln)
{
return ln ? ln->parent : NULL;
}
@ -304,7 +303,7 @@ int scols_line_set_color(struct libscols_line *ln, const char *co)
*
* Returns: @ln's color string, NULL in case of an error.
*/
const char *scols_line_get_color(struct libscols_line *ln)
const char *scols_line_get_color(const struct libscols_line *ln)
{
return ln->color;
}
@ -315,7 +314,7 @@ const char *scols_line_get_color(struct libscols_line *ln)
*
* Returns: number of cells
*/
size_t scols_line_get_ncells(struct libscols_line *ln)
size_t scols_line_get_ncells(const struct libscols_line *ln)
{
return ln->ncells;
}
@ -432,7 +431,7 @@ int scols_line_refer_column_data(struct libscols_line *ln,
*
* Returns: A newly allocated copy of @ln, NULL in case of an error.
*/
struct libscols_line *scols_copy_line(struct libscols_line *ln)
struct libscols_line *scols_copy_line(const struct libscols_line *ln)
{
struct libscols_line *ret;
size_t i;

View File

@ -184,7 +184,7 @@ struct libscols_table {
} while(0)
static inline int scols_iter_is_last(struct libscols_iter *itr)
static inline int scols_iter_is_last(const struct libscols_iter *itr)
{
if (!itr || !itr->head || !itr->p)
return 0;

View File

@ -170,5 +170,4 @@ struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sy)
scols_unref_symbols(ret);
return NULL;
}

View File

@ -113,7 +113,6 @@ void scols_unref_table(struct libscols_table *tb)
}
}
/**
* scols_table_set_name:
* @tb: a pointer to a struct libscols_table instance
@ -228,7 +227,6 @@ int scols_table_remove_columns(struct libscols_table *tb)
return 0;
}
/**
* scols_table_new_column:
* @tb: table
@ -332,14 +330,13 @@ int scols_table_next_column(struct libscols_table *tb,
return rc;
}
/**
* scols_table_get_ncols:
* @tb: table
*
* Returns: the ncols table member
* Returns: the ncols table member.
*/
size_t scols_table_get_ncols(struct libscols_table *tb)
size_t scols_table_get_ncols(const struct libscols_table *tb)
{
return tb->ncols;
}
@ -348,9 +345,9 @@ size_t scols_table_get_ncols(struct libscols_table *tb)
* scols_table_get_nlines:
* @tb: table
*
* Returns: the nlines table member, a negative number in case of an error.
* Returns: the nlines table member.
*/
size_t scols_table_get_nlines(struct libscols_table *tb)
size_t scols_table_get_nlines(const struct libscols_table *tb)
{
return tb->nlines;
}
@ -383,7 +380,7 @@ int scols_table_set_stream(struct libscols_table *tb, FILE *stream)
*
* Returns: stream pointer, NULL in case of an error or an unset stream.
*/
FILE *scols_table_get_stream(struct libscols_table *tb)
FILE *scols_table_get_stream(const struct libscols_table *tb)
{
return tb->out;
}
@ -917,7 +914,7 @@ int scols_table_enable_nowrap(struct libscols_table *tb, int enable)
*
* Returns: 1 if colors are enabled.
*/
int scols_table_colors_wanted(struct libscols_table *tb)
int scols_table_colors_wanted(const struct libscols_table *tb)
{
return tb->colors_wanted;
}
@ -928,7 +925,7 @@ int scols_table_colors_wanted(struct libscols_table *tb)
*
* Returns: 1 if the table is empty.
*/
int scols_table_is_empty(struct libscols_table *tb)
int scols_table_is_empty(const struct libscols_table *tb)
{
return !tb->nlines;
}
@ -939,7 +936,7 @@ int scols_table_is_empty(struct libscols_table *tb)
*
* Returns: 1 if ASCII tree is enabled.
*/
int scols_table_is_ascii(struct libscols_table *tb)
int scols_table_is_ascii(const struct libscols_table *tb)
{
return tb->ascii;
}
@ -950,7 +947,7 @@ int scols_table_is_ascii(struct libscols_table *tb)
*
* Returns: 1 if header output is disabled.
*/
int scols_table_is_noheadings(struct libscols_table *tb)
int scols_table_is_noheadings(const struct libscols_table *tb)
{
return tb->no_headings;
}
@ -961,7 +958,7 @@ int scols_table_is_noheadings(struct libscols_table *tb)
*
* Returns: 1 if export output format is enabled.
*/
int scols_table_is_export(struct libscols_table *tb)
int scols_table_is_export(const struct libscols_table *tb)
{
return tb->format == SCOLS_FMT_EXPORT;
}
@ -972,7 +969,7 @@ int scols_table_is_export(struct libscols_table *tb)
*
* Returns: 1 if raw output format is enabled.
*/
int scols_table_is_raw(struct libscols_table *tb)
int scols_table_is_raw(const struct libscols_table *tb)
{
return tb->format == SCOLS_FMT_RAW;
}
@ -985,19 +982,18 @@ int scols_table_is_raw(struct libscols_table *tb)
*
* Since: 2.27
*/
int scols_table_is_json(struct libscols_table *tb)
int scols_table_is_json(const struct libscols_table *tb)
{
return tb->format == SCOLS_FMT_JSON;
}
/**
* scols_table_is_maxout
* @tb: table
*
* Returns: 1 if output maximization is enabled or 0
*/
int scols_table_is_maxout(struct libscols_table *tb)
int scols_table_is_maxout(const struct libscols_table *tb)
{
return tb->maxout;
}
@ -1008,7 +1004,7 @@ int scols_table_is_maxout(struct libscols_table *tb)
*
* Returns: returns 1 tree-like output is expected.
*/
int scols_table_is_tree(struct libscols_table *tb)
int scols_table_is_tree(const struct libscols_table *tb)
{
return tb->ntreecols > 0;
}
@ -1048,7 +1044,7 @@ int scols_table_set_line_separator(struct libscols_table *tb, const char *sep)
*
* Returns: @tb column separator, NULL in case of an error
*/
char *scols_table_get_column_separator(struct libscols_table *tb)
const char *scols_table_get_column_separator(const struct libscols_table *tb)
{
return tb->colsep;
}
@ -1059,10 +1055,9 @@ char *scols_table_get_column_separator(struct libscols_table *tb)
*
* Returns: @tb line separator, NULL in case of an error
*/
char *scols_table_get_line_separator(struct libscols_table *tb)
const char *scols_table_get_line_separator(const struct libscols_table *tb)
{
return tb->linesep;
}
static int cells_cmp_wrapper(struct list_head *a, struct list_head *b, void *data)
@ -1126,7 +1121,7 @@ int scols_table_set_termforce(struct libscols_table *tb, int force)
*
* Returns: SCOLS_TERMFORCE_{NEVER,ALWAYS,AUTO} or a negative value in case of an error.
*/
int scols_table_get_termforce(struct libscols_table *tb)
int scols_table_get_termforce(const struct libscols_table *tb)
{
return tb->termforce;
}