libudev-list.c revision 29804cc1e0f37ee34301530fd7f1eb8550be464e
/***
This file is part of systemd.
Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
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>
#include <stddef.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "libudev.h"
#include "libudev-private.h"
/**
* SECTION:libudev-list
* @short_description: list operation
*
* Libudev list operations.
*/
/**
* udev_list_entry:
*
* Opaque object representing one entry in a list. An entry contains
* contains a name, and optionally a value.
*/
struct udev_list_entry {
struct udev_list_node node;
char *name;
char *value;
int num;
};
/* the list's head points to itself if empty */
{
}
{
}
struct udev_list_node *prev,
struct udev_list_node *next)
{
}
{
}
{
}
/* return list entry which embeds this node */
{
}
{
}
/* insert entry into a list as the last element */
{
/* inserting before the list head make the node the last node in the list */
}
/* insert entry into a list, before a given existing entry */
static void udev_list_entry_insert_before(struct udev_list_entry *new, struct udev_list_entry *entry)
{
}
/* binary search in sorted array */
{
first = 0;
unsigned int i;
int cmp;
if (cmp < 0)
last = i;
else if (cmp > 0)
first = i+1;
else
return i;
}
/* not found, return negative insertion-index+1 */
return -(first+1);
}
struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *name, const char *value)
{
struct udev_list_entry *entry;
int i = 0;
/* lookup existing name or insertion-index */
if (i >= 0) {
return entry;
}
return NULL;
return entry;
}
}
/* add new name */
return NULL;
return NULL;
}
return NULL;
}
}
/* allocate or enlarge sorted array if needed */
struct udev_list_entry **entries;
unsigned int add;
if (add < 1)
add = 64;
return NULL;
}
}
/* the negative i returned the insertion index */
i = (-i)-1;
/* insert into sorted list */
if ((unsigned int)i < list->entries_cur)
else
/* insert into sorted array */
list->entries_cur++;
} else {
}
return entry;
}
{
int i;
/* remove entry from sorted array */
if (i >= 0) {
list->entries_cur--;
}
}
}
{
struct udev_list_entry *entry_loop;
struct udev_list_entry *entry_tmp;
list->entries_cur = 0;
list->entries_max = 0;
}
{
return NULL;
}
/**
* udev_list_entry_get_next:
* @list_entry: current entry
*
* Get the next entry from the list.
*
* Returns: udev_list_entry, #NULL if no more entries are available.
*/
{
struct udev_list_node *next;
if (list_entry == NULL)
return NULL;
/* empty list or no more entries */
return NULL;
return list_node_to_entry(next);
}
/**
* udev_list_entry_get_by_name:
* @list_entry: current entry
* @name: name string to match
*
* 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)
{
int i;
if (list_entry == NULL)
return NULL;
return NULL;
if (i < 0)
return NULL;
}
/**
* udev_list_entry_get_name:
* @list_entry: current entry
*
* Get the name of a list entry.
*
* Returns: the name string of this entry.
*/
{
if (list_entry == NULL)
return NULL;
return list_entry->name;
}
/**
* udev_list_entry_get_value:
* @list_entry: current entry
*
* Get the value of list entry.
*
* Returns: the value string of this entry.
*/
{
if (list_entry == NULL)
return NULL;
return list_entry->value;
}
{
if (list_entry == NULL)
return -EINVAL;
return list_entry->num;
}
{
if (list_entry == NULL)
return;
}