@@ -247,50 +247,49 @@ static void ctl_query_cleanup_real_args(const umf_ctl_node_t *n, void *real_arg,
247247/*
248248 * ctl_exec_query_read -- (internal) calls the read callback of a node
249249 */
250- static int ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
251- umf_ctl_query_source_t source , void * arg ,
252- size_t size , umf_ctl_index_utlist_t * indexes ,
253- const char * extra_name ,
254- umf_ctl_query_type_t query_type ) {
250+ static umf_result_t ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
251+ umf_ctl_query_source_t source ,
252+ void * arg , size_t size ,
253+ umf_ctl_index_utlist_t * indexes ,
254+ const char * extra_name ,
255+ umf_ctl_query_type_t query_type ) {
255256 (void )query_type ;
256257 assert (n != NULL );
257258 assert (n -> cb [CTL_QUERY_READ ] != NULL );
258259 assert (MAX_CTL_QUERY_TYPE != query_type );
259260
260261 if (arg == NULL ) {
261- errno = EINVAL ;
262- return -1 ;
262+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
263263 }
264-
265264 return n -> cb [CTL_QUERY_READ ](ctx , source , arg , size , indexes , extra_name ,
266265 MAX_CTL_QUERY_TYPE );
267266}
268267
269268/*
270269 * ctl_exec_query_write -- (internal) calls the write callback of a node
271270 */
272- static int ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
273- umf_ctl_query_source_t source , void * arg ,
274- size_t size , umf_ctl_index_utlist_t * indexes ,
275- const char * extra_name ,
276- umf_ctl_query_type_t query_type ) {
271+ static umf_result_t ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
272+ umf_ctl_query_source_t source ,
273+ void * arg , size_t size ,
274+ umf_ctl_index_utlist_t * indexes ,
275+ const char * extra_name ,
276+ umf_ctl_query_type_t query_type ) {
277277 (void )query_type ;
278278 assert (n != NULL );
279279 assert (n -> cb [CTL_QUERY_WRITE ] != NULL );
280280 assert (MAX_CTL_QUERY_TYPE != query_type );
281281
282282 if (arg == NULL ) {
283- errno = EINVAL ;
284- return -1 ;
283+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
285284 }
286285
287286 void * real_arg = ctl_query_get_real_args (n , arg , source );
288287 if (real_arg == NULL ) {
289- return -1 ;
288+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
290289 }
291290
292- int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , size , indexes ,
293- extra_name , MAX_CTL_QUERY_TYPE );
291+ umf_result_t ret = n -> cb [CTL_QUERY_WRITE ](
292+ ctx , source , real_arg , size , indexes , extra_name , MAX_CTL_QUERY_TYPE );
294293 ctl_query_cleanup_real_args (n , real_arg , source );
295294
296295 return ret ;
@@ -299,11 +298,12 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
299298/*
300299 * ctl_exec_query_runnable -- (internal) calls the run callback of a node
301300 */
302- static int ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
303- umf_ctl_query_source_t source , void * arg ,
304- size_t size , umf_ctl_index_utlist_t * indexes ,
305- const char * extra_name ,
306- umf_ctl_query_type_t query_type ) {
301+ static umf_result_t ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
302+ umf_ctl_query_source_t source ,
303+ void * arg , size_t size ,
304+ umf_ctl_index_utlist_t * indexes ,
305+ const char * extra_name ,
306+ umf_ctl_query_type_t query_type ) {
307307 (void )query_type ;
308308 assert (n != NULL );
309309 assert (n -> cb [CTL_QUERY_RUNNABLE ] != NULL );
@@ -312,24 +312,25 @@ static int ctl_exec_query_runnable(void *ctx, const umf_ctl_node_t *n,
312312 extra_name , MAX_CTL_QUERY_TYPE );
313313}
314314
315- static int ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
316- umf_ctl_query_source_t source , void * arg ,
317- size_t size , umf_ctl_index_utlist_t * indexes ,
318- const char * extra_name ,
319- umf_ctl_query_type_t query_type ) {
315+ static umf_result_t ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
316+ umf_ctl_query_source_t source ,
317+ void * arg , size_t size ,
318+ umf_ctl_index_utlist_t * indexes ,
319+ const char * extra_name ,
320+ umf_ctl_query_type_t query_type ) {
320321 assert (n != NULL );
321322 assert (n -> cb [CTL_QUERY_SUBTREE ] != NULL );
322323 assert (MAX_CTL_QUERY_TYPE != query_type );
323324 return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , size , indexes , extra_name ,
324325 query_type );
325326}
326327
327- typedef int (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
328- umf_ctl_query_source_t source , void * arg ,
329- size_t size ,
330- umf_ctl_index_utlist_t * indexes ,
331- const char * extra_name ,
332- umf_ctl_query_type_t query_type );
328+ typedef umf_result_t (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
329+ umf_ctl_query_source_t source ,
330+ void * arg , size_t size ,
331+ umf_ctl_index_utlist_t * indexes ,
332+ const char * extra_name ,
333+ umf_ctl_query_type_t query_type );
333334
334335static umf_ctl_exec_query_t ctl_exec_query [MAX_CTL_QUERY_TYPE ] = {
335336 ctl_exec_query_read ,
@@ -342,12 +343,11 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
342343 * ctl_query -- (internal) parses the name and calls the appropriate methods
343344 * from the ctl tree
344345 */
345- int ctl_query (struct ctl * ctl , void * ctx , umf_ctl_query_source_t source ,
346- const char * name , umf_ctl_query_type_t type , void * arg ,
347- size_t size ) {
346+ umf_result_t ctl_query (struct ctl * ctl , void * ctx ,
347+ umf_ctl_query_source_t source , const char * name ,
348+ umf_ctl_query_type_t type , void * arg , size_t size ) {
348349 if (name == NULL ) {
349- errno = EINVAL ;
350- return -1 ;
350+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
351351 }
352352
353353 /*
@@ -358,10 +358,10 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
358358 umf_ctl_index_utlist_t * indexes = NULL ;
359359 indexes = Zalloc (sizeof (* indexes ));
360360 if (!indexes ) {
361- return -1 ;
361+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
362362 }
363363
364- int ret = -1 ;
364+ umf_result_t ret = UMF_RESULT_ERROR_UNKNOWN ;
365365 size_t name_offset = 0 ;
366366
367367 const umf_ctl_node_t * n =
@@ -377,7 +377,7 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
377377 if (n == NULL ||
378378 (n -> type != CTL_NODE_LEAF && n -> type != CTL_NODE_SUBTREE ) ||
379379 n -> cb [n -> type == CTL_NODE_SUBTREE ? CTL_QUERY_SUBTREE : type ] == NULL ) {
380- errno = EINVAL ;
380+ ret = UMF_RESULT_ERROR_INVALID_ARGUMENT ;
381381 goto out ;
382382 }
383383
@@ -436,24 +436,24 @@ static int ctl_parse_query(char *qbuf, char **name, char **value) {
436436/*
437437 * ctl_load_config -- executes the entire query collection from a provider
438438 */
439- static int ctl_load_config (struct ctl * ctl , void * ctx , char * buf ) {
440- int r = 0 ;
439+ static umf_result_t ctl_load_config (struct ctl * ctl , void * ctx , char * buf ) {
440+ umf_result_t ret = UMF_RESULT_SUCCESS ;
441441 char * sptr = NULL ; /* for internal use of strtok */
442442 char * name ;
443443 char * value ;
444444 char * qbuf = strtok_r (buf , CTL_STRING_QUERY_SEPARATOR , & sptr );
445445
446446 while (qbuf != NULL ) {
447- r = ctl_parse_query (qbuf , & name , & value );
448- if (r != 0 ) {
449- return -1 ;
447+ int parse_res = ctl_parse_query (qbuf , & name , & value );
448+ if (parse_res != 0 ) {
449+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
450450 }
451451
452- r = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
453- value , 0 );
452+ ret = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
453+ value , 0 );
454454
455- if (r < 0 && ctx != NULL ) {
456- return -1 ;
455+ if (ret != UMF_RESULT_SUCCESS && ctx != NULL ) {
456+ return ret ;
457457 }
458458
459459 qbuf = strtok_r (NULL , CTL_STRING_QUERY_SEPARATOR , & sptr );
@@ -465,14 +465,14 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
465465/*
466466 * ctl_load_config_from_string -- loads obj configuration from string
467467 */
468- int ctl_load_config_from_string (struct ctl * ctl , void * ctx ,
469- const char * cfg_string ) {
468+ umf_result_t ctl_load_config_from_string (struct ctl * ctl , void * ctx ,
469+ const char * cfg_string ) {
470470 char * buf = Strdup (cfg_string );
471471 if (buf == NULL ) {
472- return -1 ;
472+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
473473 }
474474
475- int ret = ctl_load_config (ctl , ctx , buf );
475+ umf_result_t ret = ctl_load_config (ctl , ctx , buf );
476476
477477 umf_ba_global_free (buf );
478478 return ret ;
@@ -485,9 +485,9 @@ int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
485485 * the size of the file, reads its content and sanitizes it for ctl_load_config.
486486 */
487487#ifndef _WIN32 // TODO: implement for Windows
488- int ctl_load_config_from_file (struct ctl * ctl , void * ctx ,
489- const char * cfg_file ) {
490- int ret = -1 ;
488+ umf_result_t ctl_load_config_from_file (struct ctl * ctl , void * ctx ,
489+ const char * cfg_file ) {
490+ umf_result_t ret = UMF_RESULT_ERROR_UNKNOWN ;
491491 long fsize = 0 ;
492492 char * buf = NULL ;
493493
@@ -608,7 +608,6 @@ int ctl_arg_integer(const void *arg, void *dest, size_t dest_size) {
608608 * (uint8_t * )dest = (uint8_t )val ;
609609 break ;
610610 default :
611- errno = EINVAL ;
612611 return -1 ;
613612 }
614613
0 commit comments