Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

src/lib/list.c: merge_str_list() generalization

Make generalized __merge_str_list() with an additional find_fn argument.
This enables using function other than find_str() to check if the value
is already in the list.

Make merge_str_list() calling __merge_str_list with find_str as a last
argument.

Should not have any visible effect per se.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
  • Loading branch information...
commit 2f6732431912069d5abf6b30024eadda5af54e2c 1 parent 9f41f92
@kolyshkin kolyshkin authored
Showing with 17 additions and 7 deletions.
  1. +4 −1 include/list.h
  2. +13 −6 src/lib/list.c
View
5 include/list.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2008, Parallels, Inc. All rights reserved.
+ * Copyright (C) 2000-2011, Parallels, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -133,6 +133,9 @@ int add_str2list(list_head_t *head, const char *val);
void free_str_param(list_head_t *head);
int copy_str_param(list_head_t *dst, list_head_t *src);
char *find_str(list_head_t *head, const char *val);
+int __merge_str_list(int delall, list_head_t *old, list_head_t *add,
+ list_head_t *del, list_head_t *merged,
+ char* (*find_fn)(list_head_t*, const char*));
int merge_str_list(int delall, list_head_t *old, list_head_t *add,
list_head_t *del, list_head_t *merged);
int list_size(list_head_t *head);
View
19 src/lib/list.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2008, Parallels, Inc. All rights reserved.
+ * Copyright (C) 2000-2011, Parallels, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -203,8 +203,9 @@ int add_str2list(list_head_t *head, const char *val)
return ret;
}
-int merge_str_list(int delall, list_head_t *old, list_head_t *add,
- list_head_t *del, list_head_t *merged)
+int __merge_str_list(int delall, list_head_t *old, list_head_t *add,
+ list_head_t *del, list_head_t *merged,
+ char* (*find_fn)(list_head_t*, const char*))
{
str_param *str;
@@ -213,19 +214,25 @@ int merge_str_list(int delall, list_head_t *old, list_head_t *add,
if (!delall && !list_empty(old)) {
/* add old values */
list_for_each(str, old, list) {
- if (find_str(del, str->val))
+ if (find_fn(del, str->val))
continue;
add_str_param(merged, str->val);
}
}
if (!list_empty(add)) {
list_for_each(str, add, list) {
- if (find_str(merged, str->val))
+ if (find_fn(merged, str->val))
continue;
- if (find_str(del, str->val))
+ if (find_fn(del, str->val))
continue;
add_str_param(merged, str->val);
}
}
return 0;
}
+
+int merge_str_list(int delall, list_head_t *old, list_head_t *add,
+ list_head_t *del, list_head_t *merged)
+{
+ return __merge_str_list(delall, old, add, del, merged, find_str);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.