Skip to content

Commit 7b5e202

Browse files
committed
util: add table_init_with_columns() function
This combined table_init() and table_add_columns() functions. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent eb12965 commit 7b5e202

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

util/table.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ struct table *table_init(void)
221221
return t;
222222
}
223223

224+
struct table *table_init_with_columns(struct table_column *c, int num_columns)
225+
{
226+
struct table *t = table_init();
227+
228+
if (t) {
229+
if (!table_add_columns(t, c, num_columns))
230+
return t;
231+
table_free(t);
232+
}
233+
234+
return NULL;
235+
}
236+
224237
static int table_add_column(struct table *t, struct table_column *c)
225238
{
226239
struct table_column *new_columns;

util/table.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,16 @@ void table_add_row(struct table *t, int row);
146146
void table_print(struct table *t);
147147
void table_free(struct table *t);
148148

149+
/**
150+
* table_init_with_columns() - Allocate a table instance with column definitions
151+
* @c: Column definitions
152+
* @num_columns:Number of columns
153+
*
154+
* This is a function combined table_init() and table_add_columns().
155+
*
156+
* Return: The table instance, or NULL if unsuccessful. If allocated, the caller
157+
* is responsible to free the table.
158+
*/
159+
struct table *table_init_with_columns(struct table_column *c, int num_columns);
160+
149161
#endif /* _TABLE_H_ */

0 commit comments

Comments
 (0)