2 * Copyright Timo Hirvonen
14 int dir_open(struct directory
*dir
, const char *name
)
16 int len
= strlen(name
);
18 if (len
>= sizeof(dir
->path
) - 2) {
23 dir
->d
= opendir(name
);
27 memcpy(dir
->path
, name
, len
);
28 dir
->path
[len
++] = '/';
34 void dir_close(struct directory
*dir
)
39 const char *dir_read(struct directory
*dir
)
43 char *full
= dir
->path
;
46 while ((de
= readdir(d
))) {
47 const char *name
= de
->d_name
;
48 int nlen
= strlen(name
);
50 /* just ignore too long paths
51 * + 2 -> space for \0 or / and \0
53 if (len
+ nlen
+ 2 >= sizeof(dir
->path
))
56 memcpy(full
+ len
, name
, nlen
+ 1);
57 if (lstat(full
, &dir
->st
))
61 if (S_ISLNK(dir
->st
.st_mode
)) {
62 /* argh. must stat the target */
63 if (stat(full
, &dir
->st
))
73 void ptr_array_add(struct ptr_array
*array
, void *ptr
)
75 void **ptrs
= ptrs
= array
->ptrs
;
76 int alloc
= array
->alloc
;
78 if (alloc
== array
->count
) {
79 alloc
= alloc
* 3 / 2 + 16;
80 ptrs
= xrealloc(ptrs
, alloc
* sizeof(void *));
84 ptrs
[array
->count
++] = ptr
;