]> git.notmuchmail.org Git - notmuch/blob - lib/filenames.c
version: bump to 0.15
[notmuch] / lib / filenames.c
1 /* filenames.c - Iterator for a list of filenames
2  *
3  * Copyright © 2010 Intel Corporation
4  *
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.
9  *
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.
14  *
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/ .
17  *
18  * Author: Carl Worth <cworth@cworth.org>
19  */
20
21 #include "notmuch-private.h"
22
23 struct _notmuch_filenames {
24     notmuch_string_node_t *iterator;
25 };
26
27 /* The notmuch_filenames_t iterates over a notmuch_string_list_t of
28  * file names */
29 notmuch_filenames_t *
30 _notmuch_filenames_create (const void *ctx,
31                            notmuch_string_list_t *list)
32 {
33     notmuch_filenames_t *filenames;
34
35     filenames = talloc (ctx, notmuch_filenames_t);
36     if (unlikely (filenames == NULL))
37         return NULL;
38
39     filenames->iterator = list->head;
40     (void) talloc_reference (filenames, list);
41
42     return filenames;
43 }
44
45 notmuch_bool_t
46 notmuch_filenames_valid (notmuch_filenames_t *filenames)
47 {
48     if (filenames == NULL)
49         return FALSE;
50
51     return (filenames->iterator != NULL);
52 }
53
54 const char *
55 notmuch_filenames_get (notmuch_filenames_t *filenames)
56 {
57     if ((filenames == NULL) || (filenames->iterator == NULL))
58         return NULL;
59
60     return filenames->iterator->string;
61 }
62
63 void
64 notmuch_filenames_move_to_next (notmuch_filenames_t *filenames)
65 {
66     if ((filenames == NULL) || (filenames->iterator == NULL))
67         return;
68
69     filenames->iterator = filenames->iterator->next;
70 }
71
72 void
73 notmuch_filenames_destroy (notmuch_filenames_t *filenames)
74 {
75     talloc_free (filenames);
76 }