* Authors: the Amanda Development Team. Its members are listed in a
* file named AUTHORS, in the root directory of this distribution.
*/
-/* $Id: list_dir.c,v 1.17 2002/03/24 19:25:51 jrjackson Exp $
+/* $Id: list_dir.c,v 1.19 2006/07/05 11:22:49 martinea Exp $
*
* manage directory listings from index files
*/
DIR_ITEM *dir_last = NULL; /* last dir entry */
DIR_ITEM *cur_list = NULL; /* current dir entry,for speeding up search */
-DIR_ITEM *get_dir_list()
+DIR_ITEM *
+get_dir_list(void)
{
return dir_list;
}
-void clear_dir_list P((void))
+void
+clear_dir_list(void)
{
DIR_ITEM *this;
/* It's true because the output of the index file is sorted */
/* Maybe it could be more efficient if the index was sorted when */
/* it is generated */
-int add_dir_list_item(dump, path)
-DUMP_ITEM *dump;
-char *path;
+
+int
+add_dir_list_item(
+ DUMP_ITEM * dump,
+ const char *path)
{
DIR_ITEM *cur;
if (dir_list == NULL)
{
- dir_list = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+ dir_list = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
dir_list->next = NULL;
dir_list->dump = dump;
dir_list->path = stralloc(path);
return 0; /* added */
}
- if(strcmp(path,dir_last->path) == 0)
+ if (strcmp(path, "/") != 0 &&
+ strcmp(path, dir_last->path) == 0) {
return 0; /* found */
+ }
/* add at head of list */
if(strcmp(path,dir_list->path) < 0)
{
- cur_list = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+ cur_list = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
cur_list->next = dir_list;
cur_list->dump = dump;
cur_list->path = stralloc(path);
cur_list=cur_list->next;
}
- if(strcmp(path,cur_list->next->path) == 0)
+ if (cur_list->next && strcmp(path, cur_list->next->path) == 0)
{
cur_list=cur_list->next;
return 0; /* found */
}
/* add at cur_list */
- cur = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+ cur = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
cur->next = cur_list->next;
cur->dump = dump;
cur->path = stralloc(path);
}
else /* add at end of list */
{
- dir_last->next = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+ dir_last->next = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
dir_last=dir_last->next;
dir_last->next = NULL;
dir_last->dump = dump;