File: load_dir.h

package info (click to toggle)
cmus 2.2.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,196 kB
  • ctags: 2,714
  • sloc: ansic: 24,078; sh: 1,024; makefile: 209; python: 26
file content (58 lines) | stat: -rw-r--r-- 1,137 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* 
 * Copyright Timo Hirvonen
 */

#ifndef _LOAD_DIR_H
#define _LOAD_DIR_H

#include <sys/stat.h>
#include <stdlib.h>
#include <dirent.h>

struct directory {
	DIR *d;
	int len;
	/* we need stat information for symlink targets */
	int is_link;
	/* stat() information. ie. for the symlink target */
	struct stat st;
	char path[1024];
};

int dir_open(struct directory *dir, const char *name);
void dir_close(struct directory *dir);
const char *dir_read(struct directory *dir);


struct ptr_array {
	/* allocated with malloc(). contains pointers */
	void *ptrs;
	int alloc;
	int count;
};

/* ptr_array.ptrs is either char ** or struct dir_entry ** */
struct dir_entry {
	mode_t mode;
	char name[0];
};

#define PTR_ARRAY(name) struct ptr_array name = { NULL, 0, 0 }

void ptr_array_add(struct ptr_array *array, void *ptr);

static inline void ptr_array_plug(struct ptr_array *array)
{
	ptr_array_add(array, NULL);
	array->count--;
}

static inline void ptr_array_sort(struct ptr_array *array,
		int (*cmp)(const void *a, const void *b))
{
	int count = array->count;
	if (count)
		qsort(array->ptrs, count, sizeof(void *), cmp);
}

#endif