2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * See the COPYING file for license information.
18 * Guillaume Chazarain <guichaz@yahoo.fr>
21 /***************************************************
22 * A data structure to keep track of visited files *
23 ***************************************************/
25 #include <sys/types.h> /* dev_t, ino_t */
26 #include <sys/stat.h> /* struct stat, stat() */
27 #include <stdio.h> /* perror() */
33 * Files informations saved into
34 * the AVL to uniquely identify them.
41 /* To build and search the AVL. */
42 static gint
cmp_func(const file_info
* file1
, const file_info
* file2
)
44 if (file1
->ino
< file2
->ino
)
47 if (file1
->ino
> file2
->ino
)
50 if (file1
->dev
< file2
->dev
)
53 return file1
->dev
> file2
->dev
;
56 struct pathset
*pathset_new(void)
58 struct pathset
*set
= g_new(struct pathset
, 1);
60 set
->tree
= g_tree_new_full((GCompareDataFunc
) cmp_func
, NULL
,
66 /* Return TRUE if the file has been correctly inserted. */
67 gboolean
pathset_add(struct pathset
* set
, const gchar
* path
)
72 if (stat(path
, &st
) < 0) {
77 file
= g_new(file_info
, 1);
79 file
->dev
= st
.st_dev
;
80 file
->ino
= st
.st_ino
;
82 if (g_tree_lookup(set
->tree
, file
) != NULL
) {
87 g_tree_insert(set
->tree
, file
, file
);
91 void pathset_free(struct pathset
*set
)
93 g_tree_destroy(set
->tree
);