libudev-list.c revision 912541b0246ef315d4d851237483b98c9dd3f992
/*
* libudev - interface to udev device information
*
* Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
*
* 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.
*/
#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 */
{
char *list;
return (struct udev_list_entry *)list;
}
{
}
/* 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 */
{
}
/* 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 */
unsigned int add;
if (add < 1)
add = 64;
list->entries = realloc(list->entries, (list->entries_max + add) * sizeof(struct udev_list_entry *));
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
*
* Returns: the next entry from the list, #NULL is no more entries are found.
*/
{
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
*
* Returns: the entry where @name matched, #NULL if no matching entry is found.
*/
UDEV_EXPORT 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
*
* 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
*
* 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;
}