Handle streams separately in tree_add_track()
[cmus.git] / load_dir.h
blob009e4c22a137b2852903f42c34c8d65af1f871d4
1 /*
2 * Copyright Timo Hirvonen
3 */
5 #ifndef _LOAD_DIR_H
6 #define _LOAD_DIR_H
8 #include <sys/stat.h>
9 #include <stdlib.h>
10 #include <dirent.h>
12 struct directory {
13 DIR *d;
14 int len;
15 /* we need stat information for symlink targets */
16 int is_link;
17 /* stat() information. ie. for the symlink target */
18 struct stat st;
19 char path[1024];
22 int dir_open(struct directory *dir, const char *name);
23 void dir_close(struct directory *dir);
24 const char *dir_read(struct directory *dir);
27 struct ptr_array {
28 /* allocated with malloc(). contains pointers */
29 void *ptrs;
30 int alloc;
31 int count;
34 /* ptr_array.ptrs is either char ** or struct dir_entry ** */
35 struct dir_entry {
36 mode_t mode;
37 char name[0];
40 #define PTR_ARRAY(name) struct ptr_array name = { NULL, 0, 0 }
42 void ptr_array_add(struct ptr_array *array, void *ptr);
44 static inline void ptr_array_plug(struct ptr_array *array)
46 ptr_array_add(array, NULL);
47 array->count--;
50 static inline void ptr_array_sort(struct ptr_array *array,
51 int (*cmp)(const void *a, const void *b))
53 int count = array->count;
54 if (count)
55 qsort(array->ptrs, count, sizeof(void *), cmp);
58 #endif