1 /* filenames.c - Iterator for a list of filenames
3 * Copyright © 2010 Intel Corporation
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: Carl Worth <cworth@cworth.org>
21 #include "notmuch-private.h"
23 struct _notmuch_filenames {
24 notmuch_filename_node_t *iterator;
27 /* Create a new notmuch_filename_list_t object, with 'ctx' as its
30 * This function can return NULL in case of out-of-memory.
32 notmuch_filename_list_t *
33 _notmuch_filename_list_create (const void *ctx)
35 notmuch_filename_list_t *list;
37 list = talloc (ctx, notmuch_filename_list_t);
38 if (unlikely (list == NULL))
42 list->tail = &list->head;
48 _notmuch_filename_list_add_filename (notmuch_filename_list_t *list,
51 /* Create and initialize new node. */
52 notmuch_filename_node_t *node = talloc (list,
53 notmuch_filename_node_t);
55 node->filename = talloc_strdup (node, filename);
58 /* Append the node to the list. */
60 list->tail = &node->next;
64 _notmuch_filename_list_destroy (notmuch_filename_list_t *list)
69 /* The notmuch_filenames_t is an iterator object for a
70 * notmuch_filename_list_t */
72 _notmuch_filenames_create (const void *ctx,
73 notmuch_filename_list_t *list)
75 notmuch_filenames_t *filenames;
77 filenames = talloc (ctx, notmuch_filenames_t);
78 if (unlikely (filenames == NULL))
81 filenames->iterator = list->head;
82 (void) talloc_reference (filenames, list);
88 notmuch_filenames_valid (notmuch_filenames_t *filenames)
90 if (filenames == NULL)
93 return (filenames->iterator != NULL);
97 notmuch_filenames_get (notmuch_filenames_t *filenames)
99 if (filenames->iterator == NULL)
102 return filenames->iterator->filename;
106 notmuch_filenames_move_to_next (notmuch_filenames_t *filenames)
108 if (filenames->iterator == NULL)
111 filenames->iterator = filenames->iterator->next;
115 notmuch_filenames_destroy (notmuch_filenames_t *filenames)
117 talloc_free (filenames);