-/*
- * libudev - interface to udev device information
- *
- * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- */
+/***
+ This file is part of systemd.
+
+ Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
#include <stdio.h>
#include <stdlib.h>
}
/* return list entry which embeds this node */
-static struct udev_list_entry *list_node_to_entry(struct udev_list_node *node)
+static inline struct udev_list_entry *list_node_to_entry(struct udev_list_node *node)
{
- char *list;
-
- list = (char *)node;
- list -= offsetof(struct udev_list_entry, node);
- return (struct udev_list_entry *)list;
+ return container_of(node, struct udev_list_entry, node);
}
void udev_list_init(struct udev *udev, struct udev_list *list, bool unique)
{
- memset(list, 0x00, sizeof(struct udev_list));
+ memzero(list, sizeof(struct udev_list));
list->udev = udev;
list->unique = unique;
udev_list_node_init(&list->node);
}
/* insert entry into a list as the last element */
-void udev_list_entry_append(struct udev_list_entry *new, struct udev_list *list)
+static void udev_list_entry_append(struct udev_list_entry *new, struct udev_list *list)
{
/* inserting before the list head make the node the last node in the list */
udev_list_node_insert_between(&new->node, list->node.prev, &list->node);
}
/* insert entry into a list, before a given existing entry */
-void udev_list_entry_insert_before(struct udev_list_entry *new, struct udev_list_entry *entry)
+static void udev_list_entry_insert_before(struct udev_list_entry *new, struct udev_list_entry *entry)
{
udev_list_node_insert_between(&new->node, entry->node.prev, &entry->node);
new->list = entry->list;
}
/* add new name */
- entry = calloc(1, sizeof(struct udev_list_entry));
+ entry = new0(struct udev_list_entry, 1);
if (entry == NULL)
return NULL;
entry->name = strdup(name);
if (list->unique) {
/* allocate or enlarge sorted array if needed */
if (list->entries_cur >= list->entries_max) {
+ struct udev_list_entry **entries;
unsigned int add;
add = list->entries_max;
if (add < 1)
add = 64;
- list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
- if (list->entries == NULL) {
+ entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
+ if (entries == NULL) {
free(entry->name);
free(entry->value);
+ free(entry);
return NULL;
}
+ list->entries = entries;
list->entries_max += add;
}
* udev_list_entry_get_next:
* @list_entry: current entry
*
- * Returns: the next entry from the list, #NULL is no more entries are found.
+ * Get the next entry from the list.
+ *
+ * Returns: udev_list_entry, #NULL if no more entries are available.
*/
_public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry)
{
* @list_entry: current entry
* @name: name string to match
*
- * Returns: the entry where @name matched, #NULL if no matching entry is found.
+ * Lookup an entry in the list with a certain name.
+ *
+ * Returns: udev_list_entry, #NULL if no matching entry is found.
*/
_public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name)
{
* udev_list_entry_get_name:
* @list_entry: current entry
*
+ * Get the name of a list entry.
+ *
* Returns: the name string of this entry.
*/
_public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry)
* udev_list_entry_get_value:
* @list_entry: current entry
*
+ * Get the value of list entry.
+ *
* Returns: the value string of this entry.
*/
_public_ const char *udev_list_entry_get_value(struct udev_list_entry *list_entry)