mirror of
https://github.com/ipxe/ipxe
synced 2025-12-24 15:23:42 +03:00
[list] Add list_first_entry()
There are several points in the iPXE codebase where list_for_each_entry() is (ab)used to extract only the first entry from a list. Add a macro list_first_entry() to make this code easier to read. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -157,6 +157,19 @@ static inline int list_empty ( const struct list_head *list ) {
|
||||
list_check ( (list) ); \
|
||||
container_of ( list, type, member ); } )
|
||||
|
||||
/**
|
||||
* Get the container of the first entry in a list
|
||||
*
|
||||
* @v list List head
|
||||
* @v type Containing type
|
||||
* @v member Name of list field within containing type
|
||||
* @ret first First list entry, or NULL
|
||||
*/
|
||||
#define list_first_entry( list, type, member ) \
|
||||
( list_empty ( (list) ) ? \
|
||||
( type * ) NULL : \
|
||||
list_entry ( (list)->next, type, member ) )
|
||||
|
||||
/**
|
||||
* Iterate over entries in a list
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user