30 #include <sys/types.h> 42 static int cmp_dirent(
const void *,
const void *);
43 static int get_perm(
char *);
44 static void sort_dirent(
dbDirent *,
int);
81 len = strlen(entry->d_name);
87 path =
db_malloc(strlen(dirname) + max + 2);
98 for (i = 0; i <
count; i++) {
105 sprintf(path,
"%s/%s", dirname, entry->d_name);
106 dirent[i].
perm = get_perm(path);
112 sort_dirent(dirent, *n);
128 for (i = 0; i <
count; i++)
134 static int get_perm(
char *
path)
140 if (access(path,
R_OK) == 0)
142 if (access(path,
W_OK) == 0)
144 if (access(path,
X_OK) == 0)
150 static int cmp_dirent(
const void *aa,
const void *bb)
159 static void sort_dirent(
dbDirent * a,
int n)
161 qsort(a, n,
sizeof(
dbDirent), cmp_dirent);
181 for (i = 0; i <
count; i++)
int db_isdir(const char *)
Test if path is a directory.
void db_init_string(dbString *)
Initialize dbString.
char * db_get_string(const dbString *)
Get string.
dbDirent * db_dirent(const char *dirname, int *n)
Read directory and build an array of dbDirent's.
void db_free(void *)
Free allocated memory.
void db_syserror(const char *)
Report system error.
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
void db_free_dirent_array(dbDirent *dirent, int count)
Free dbDirent.
void db_clear_error(void)
Clear error status.
void * db_calloc(int, int)
Allocate memory.
dbDirent * db_alloc_dirent_array(int count)
Allocate dirent array.
void * db_malloc(int)
Allocate memory.
void db_free_string(dbString *)
Free allocated space for dbString.