4 #include <grass/dbmi.h>
10 #include <sys/types.h>
22 static int get_perm();
23 static void sort_dirent();
49 return (dbDirent *)
NULL;
58 len = strlen(entry->d_name);
64 path =
db_malloc(strlen(dirname) + max + 2);
67 return (dbDirent *)
NULL;
72 return (dbDirent *)
NULL;
75 for (i = 0; i < count; i++) {
82 sprintf(path,
"%s/%s", dirname, entry->d_name);
83 dirent[i].perm = get_perm(path);
84 dirent[i].isdir = (
db_isdir(path) == DB_OK);
89 sort_dirent(dirent, *n);
105 for (i = 0; i < count; i++)
111 static int get_perm(
char *path)
117 if (access(path,
R_OK) == 0)
119 if (access(path,
W_OK) == 0)
121 if (access(path,
X_OK) == 0)
127 static int cmp_dirent(
const void *aa,
const void *bb)
129 const dbDirent *a = aa;
130 const dbDirent *
b = bb;
136 static void sort_dirent(dbDirent * a,
int n)
138 qsort(a, n,
sizeof(dbDirent), cmp_dirent);
152 dirent = (dbDirent *)
db_calloc(count,
sizeof(dbDirent));
156 for (i = 0; i < count; i++)