]> granicus.if.org Git - fcron/blob - u_list.h
fixed typo in install doc
[fcron] / u_list.h
1 /*
2  * FCRON - periodic command scheduler 
3  *
4  *  Copyright 2000-2014 Thibault Godouet <fcron@free.fr>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  * 
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  *  The GNU General Public License can also be found in the file
21  *  `LICENSE' that comes with the fcron source distribution.
22  */
23
24
25 /*
26  * Unordered list of generic items
27  */
28
29 #ifndef __U_LIST_H__
30 #define __U_LIST_H__
31
32 #include <ctype.h>
33 #include <unistd.h>
34 #include <sys/types.h>
35 #include "subs.h"
36
37 typedef void u_list_entry_t;
38
39 typedef struct u_list_t {
40     /* PUBLIC: */
41     int max_entries;            /* max allowed element number (0: no limit) */
42     int num_entries;            /* READ ONLY: num of entries in the list now */
43     /* PRIVATE: DO NOT ACCESS DIRECTLY */
44     int array_size;             /* size of the array (in number of entries) */
45     size_t entry_size;          /* number of element currently in the array */
46     int grow_size;              /* grow array by grow_size entries at a time */
47     u_list_entry_t *cur_entry;  /* Current entry in iteration
48                                  * (null if not in iteration, i.e. X_first() has
49                                  * not been called or we reached the list end */
50     char cur_removed;           /* >0 if cur_entry has just been removed */
51     u_list_entry_t *entries_array;      /* pointer to the actual array */
52 } u_list_t;
53
54 /* functions prototypes */
55 extern u_list_t *u_list_init(size_t entry_size, int init_size, int grow_size);
56 extern u_list_t *u_list_copy(u_list_t * list);
57 extern u_list_entry_t *u_list_add(u_list_t * list, u_list_entry_t * entry);
58 /* WARNING: - the iteration functions are not re-entrant,
59  *            i.e. there should always be a unique iteration loop based on
60  *            u_list_first()/u_list_next() running at any one time in the code
61  *          - the u_list_entry_t* returned by _first() and _next() should not
62  *            be used anymore after a _add() or a _remove_cur() */
63 extern int u_list_is_iterating(u_list_t * list);
64 extern u_list_entry_t *u_list_first(u_list_t * list);
65 extern u_list_entry_t *u_list_next(u_list_t * list);
66 extern void u_list_end_iteration(u_list_t * list);
67 extern void u_list_remove_cur(u_list_t * list);
68 extern u_list_t *u_list_destroy(u_list_t * list);
69
70 #endif                          /* __U_LIST_H__ */