remove unnecessary strcmp wrapper, use typecasting instead
This commit is contained in:
parent
cfbfa07e85
commit
81d0ebc3e8
6 changed files with 6 additions and 52 deletions
1
Makefile
1
Makefile
|
@ -25,7 +25,6 @@ CPPFLAGS += -DEXECUTOR_PATH=\"${EXECUTOR_PATH}\"
|
|||
|
||||
|
||||
LIBIFUPDOWN_SRC = \
|
||||
libifupdown/compar.c \
|
||||
libifupdown/list.c \
|
||||
libifupdown/dict.c \
|
||||
libifupdown/interface.c \
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* libifupdown/compar.c
|
||||
* Purpose: comparators
|
||||
*
|
||||
* Copyright (c) 2020 Maximilian Wilhelm <max@sdn.clinic>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* This software is provided 'as is' and without any warranty, express or
|
||||
* implied. In no event shall the authors be liable for any damages arising
|
||||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "libifupdown/compar.h"
|
||||
|
||||
int
|
||||
compar_str (const void *a, const void *b)
|
||||
{
|
||||
const char *str_a = (const char *)a;
|
||||
const char *str_b = (const char *)b;
|
||||
|
||||
return strcmp (str_a, str_b);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* libifupdown/compar.h
|
||||
* Purpose: Comparators
|
||||
*
|
||||
* Copyright (c) 2020 Maximilian Wilhelm <max@sdn.clinic>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* This software is provided 'as is' and without any warranty, express or
|
||||
* implied. In no event shall the authors be liable for any damages arising
|
||||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef LIBIFUPDOWN_COMPAR_H__GUARD
|
||||
#define LIBIFUPDOWN_COMPAR_H__GUARD
|
||||
|
||||
int compar_str (const void *a, const void *b);
|
||||
|
||||
#endif
|
|
@ -53,7 +53,7 @@ lif_dict_add(struct lif_dict *dict, const char *key, void *data)
|
|||
|
||||
struct lif_dict_entry *
|
||||
lif_dict_add_once(struct lif_dict *dict, const char *key, void *data,
|
||||
int (*compar)(const void *, const void *))
|
||||
lif_dict_cmp_t compar)
|
||||
{
|
||||
struct lif_list *existing = lif_dict_find_all(dict, key);
|
||||
if (existing != NULL)
|
||||
|
|
|
@ -35,10 +35,12 @@ struct lif_dict_entry {
|
|||
#define LIF_DICT_FOREACH_SAFE(iter, iter_next, dict) \
|
||||
LIF_LIST_FOREACH_SAFE((iter), (iter_next), (dict)->list.head)
|
||||
|
||||
typedef int (*lif_dict_cmp_t)(const void *, const void *);
|
||||
|
||||
extern void lif_dict_init(struct lif_dict *dict);
|
||||
extern void lif_dict_fini(struct lif_dict *dict);
|
||||
extern struct lif_dict_entry *lif_dict_add(struct lif_dict *dict, const char *key, void *data);
|
||||
extern struct lif_dict_entry *lif_dict_add_once(struct lif_dict *dict, const char *key, void *data, int (*compar)(const void *, const void *));
|
||||
extern struct lif_dict_entry *lif_dict_add_once(struct lif_dict *dict, const char *key, void *data, lif_dict_cmp_t compar);
|
||||
extern struct lif_dict_entry *lif_dict_find(struct lif_dict *dict, const char *key);
|
||||
extern struct lif_list *lif_dict_find_all(struct lif_dict *dict, const char *key);
|
||||
extern void lif_dict_delete(struct lif_dict *dict, const char *key);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "libifupdown/interface-file.h"
|
||||
#include "libifupdown/fgetline.h"
|
||||
#include "libifupdown/tokenize.h"
|
||||
#include "libifupdown/compar.h"
|
||||
|
||||
bool
|
||||
lif_interface_file_parse(struct lif_dict *collection, const char *filename)
|
||||
|
@ -146,7 +145,8 @@ lif_interface_file_parse(struct lif_dict *collection, const char *filename)
|
|||
{
|
||||
/* Copy word1 to not mangle *token */
|
||||
char *addon = strndup(token, word_end - token);
|
||||
lif_dict_add_once(&cur_iface->vars, "use", addon, compar_str);
|
||||
if (lif_dict_add_once(&cur_iface->vars, "use", addon, (lif_dict_cmp_t) strcmp) == NULL)
|
||||
free(addon);
|
||||
|
||||
/* pass requires as compatibility env vars to appropriate executors (bridge, bond) */
|
||||
if (!strcmp(addon, "dhcp"))
|
||||
|
|
Loading…
Reference in a new issue