File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -211,16 +211,32 @@ void table_add_row(struct table *t, int row_id)
211211
212212struct table * table_init (void )
213213{
214- struct table * t ;
214+ struct table * t = malloc ( sizeof ( struct table )) ;
215215
216- t = malloc (sizeof (struct table ));
217216 if (!t )
218217 return NULL ;
219218
220219 memset (t , 0 , sizeof (struct table ));
220+
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+ return NULL ;
230+
231+ if (table_add_columns (t , c , num_columns )) {
232+ table_free (t );
233+ return NULL ;
234+ }
235+
236+ return t ;
237+
238+ }
239+
224240static int table_add_column (struct table * t , struct table_column * c )
225241{
226242 struct table_column * new_columns ;
Original file line number Diff line number Diff line change @@ -146,4 +146,16 @@ void table_add_row(struct table *t, int row);
146146void table_print (struct table * t );
147147void 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_ */
You can’t perform that action at this time.
0 commit comments