The lpar_find_lst_lpar Function

There is still another way of accessing items in a list lpar. You can call the function lpar_find_lst_lpar with a specific lpar id, and the function return the lpar in the list that has that id, or the value LPAR_NULL if such an lpar was not found.

Note: If there is more than one lpar in a list with the same id, lpar_find_lst_lpar returns the last instance of that id in the list.

 

This is especially convenient when only some lpars in a list (for example, a list of statistics) are of interest to you. The loop that accessed the stats list in our example could be replaced with these four lines:

lpar = lpar_find_lst_lpar(stats, LPAR_INT_MATCHESRET);
printf("%d matching records\n", lpar_get_int(lpar));
lpar = lpar_find_lst_lpar(stats, LPAR_DBL_SEARCHTIME);
printf("Lookup took %.2f seconds\n", lpar_get_dbl(lpar));

We chose not to test the return value against LPAR_NULL, since the stats list returned by lkt_dbsearch (in the non-error case) always contains these lpars.

The lpar returned by lpar_find_lst_lpar is not a copy of the list lpar, it is the same lpar, using the same memory, as the lpar in the list. That means that this lpar must not be destroyed with lpar_destroy. It is automatically destroyed when the list is destroyed. This also means that any lpar returned by lpar_find_lst_lpar must not be used after the associated list is destroyed.