10 void list_print(struct mail_list
*lst
)
17 for (n
= 0; n
< lst
->n
; n
++) {
18 fprintf(stderr
, "[%u] ", n
);
19 print_mail_header(&lst
->list
[n
].hdr
);
24 * Allocate a list via malloc of n_elem elements
26 * @param[in|out] n_elem number of elements in the list
27 * @param[in] limit max number of elements
29 * @retval Pointer to the new allocated list or NULL on error
31 struct mail_list
*list_create(size_t n_elem
, size_t limit
)
33 struct mail_list
*lst
;
41 lst
= malloc(sizeof(struct mail_list
) + n_elem
* sizeof(struct mail_entry
));
43 fprintf(stderr
, "%s - MALLOC: %s", __func__
, strerror(errno
));
48 fprintf(stderr
, "%s - MALLOC: item %lu [%lu]\n", __func__
,
49 (unsigned long) n_elem
,
50 (unsigned long) (sizeof(struct mail_list
) + n_elem
* sizeof(struct mail_entry
)));
59 void list_free(struct mail_list
*lst
)
65 fprintf(stderr
, "%s - FREE: list\n", __func__
);
70 int list_add_entry(struct mail_list
*lst
, struct mail_entry
*entry
)
74 if (lst
->nfree
< LIST_LIMIT
) {
77 memcpy(&lst
->list
[n
], entry
, sizeof(struct mail_entry
));
79 /* Update 1st free slot index */