Re: struct list_head

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 07, 2002 at 08:39:00AM +0530, Sridhar N wrote:
> Hi,
> 	I need a to use a singly-linked list in my program, and since a 
> doubly-linked list is provided in linux/list.h, i thought of using it.  But i 
> don't know how to use it.  I have a structure of nodes that i want to link, 
> say
> 
> struct foo {
> 	int foo1;
> 	int foo2;
> 	char * foo3;
> 	struct list_head list;
> };
> 
> How do I add a new node or initialize it. Seeing list.h didn't help me :-(


You can initialize using 2 ways:

LIST_HEAD_INIT() and LIST_HEAD()
The first one initialize the pointers of a struct list_head
and the second one will create a struct and then initialize.

To add or remove elements you can use list_add() and list_del().

Which element will have struct list_head inside, so if you
have the list_head pointer, you can use list_entry() to get 
the pointer to element and to iterate over the list use 
list_for_each().

Regards,
-- 
Flávio Bruno Leitner <flavio@conectiva.com.br>

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux