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++)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void * db_calloc(int n, int m)
dbDirent * db_dirent(const char *dirname, int *n)
void db_free_dirent_array(dbDirent *dirent, int count)
void db_syserror(const char *s)
void db_clear_error(void)
dbDirent * db_alloc_dirent_array(int count)
char * db_get_string(dbString *x)
int db_set_string(dbString *x, const char *s)
int db_isdir(const char *path)
void db_free_string(dbString *x)
void db_init_string(dbString *x)