Difference between pages "r6:Function:slist new" and "r6:Function:slist new head"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 4: Line 4:


==Prototype==
==Prototype==
  int slist_new( struct slist_state **ss,
  struct slist_element *slist_new_head( struct slist_state *ss, void *user_data );
                void (*user_data_delete_function)(void *user_data, void *user_state),
                void *user_state );


==Parameters==
==Parameters==
''struct slist_state **ss''
''struct slist_state *ss''
: A pointer to a pointer onto which is allocated the state which represents an slist.  Set to NULL if slist creation fails.
: An slist state as allocated by ''[[r6:Function:slist_new|slist_new]]''.


''void (*user_data_delete_function)(void *user_data, void *user_state)''
''void *user_data''
: A callback function, which can be NULL.  This function is called with the user data void pointer from each element after that element is logically deleted, giving the user an opportunity to delete any allocated state.
: A void pointer of user data which will be placed into the list in the new head element.
 
''void *user_state''
: This is passed to each call of ''user_data_delete_function'' as the second argument to that function.  The user is expected to use this to pass state information into his delete function.


==Return Value==
==Return Value==
Returns 1 on successful list creation, 0 otherwise.  On failure, ''*ss'' will also be set to NULL.
Returns a pointer to the new slist element.  If element creation failed, which can only happen because of memory allocation failure, the return value is NULL.


==Notes==
==Notes==
This function instantiates a slist.  The values of ''user_data_delete_function'' and ''user_state'' are stored in the slist state for later use by ''[[r6:Function:slist_delete|slist_delete]]'', ''[[r6:Function:slist_delete_element|slist_delete_element]]'' and ''[[r6:Function:slist_delete_all_elements|slist_delete_all_elements]]''.
This function creates a new slist element holding ''user_data'' and links it into the slist as the head element.


==See Also==
==See Also==
* [[r6:API:SList|SList]]
* [[r6:API:SList|SList]]
* [[r6:Function:slist_delete|slist_delete]]
* [[r6:Function:slist_new_next|slist_new_next]]

Latest revision as of 14:07, 4 January 2015

Source Files

/src/slist/slist_new.c
/inc/liblfds.h

Prototype

struct slist_element *slist_new_head( struct slist_state *ss, void *user_data );

Parameters

struct slist_state *ss

An slist state as allocated by slist_new.

void *user_data

A void pointer of user data which will be placed into the list in the new head element.

Return Value

Returns a pointer to the new slist element. If element creation failed, which can only happen because of memory allocation failure, the return value is NULL.

Notes

This function creates a new slist element holding user_data and links it into the slist as the head element.

See Also