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 #if defined(__CYGWIN__)
47 /* Fix for cygwin "hang" bug when browsing /
48 * Windows treats // as a network path.
50 if (strcmp(full
, "//") == 0)
54 while ((de
= readdir(d
))) {
55 const char *name
= de
->d_name
;
56 int nlen
= strlen(name
);
58 /* just ignore too long paths
59 * + 2 -> space for \0 or / and \0
61 if (len
+ nlen
+ 2 >= sizeof(dir
->path
))
64 memcpy(full
+ len
, name
, nlen
+ 1);
65 if (lstat(full
, &dir
->st
))
69 if (S_ISLNK(dir
->st
.st_mode
)) {
70 /* argh. must stat the target */
71 if (stat(full
, &dir
->st
))
81 void ptr_array_add(struct ptr_array
*array
, void *ptr
)
83 void **ptrs
= ptrs
= array
->ptrs
;
84 int alloc
= array
->alloc
;
86 if (alloc
== array
->count
) {
87 alloc
= alloc
* 3 / 2 + 16;
88 ptrs
= xrealloc(ptrs
, alloc
* sizeof(void *));
92 ptrs
[array
->count
++] = ptr
;