diff options
Diffstat (limited to 'src/base/director.c')
| -rw-r--r-- | src/base/director.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/base/director.c b/src/base/director.c index dfcc9cb..49522de 100644 --- a/src/base/director.c +++ b/src/base/director.c @@ -21,24 +21,31 @@ director_t *loadDirector(char *s) DIR *dir; struct dirent *item; char path[STR_PATH_SIZE]; + assert(s != 0); + new = malloc(sizeof(director_t)); memset(new, 0, sizeof(director_t)); + new->list = newList(); + #ifndef __WIN32__ if (s[0] == '/') #else if (s[1] == ':') #endif strcpy(path, s); + else { // this is really correct aproach getcwd(path, STR_PATH_SIZE); strcat(path, "/"); strcat(path, s); } + new->path = strdup(path); dir = opendir(new->path); + if (dir == NULL) { free(new->path); free(new); @@ -47,13 +54,16 @@ director_t *loadDirector(char *s) while ((item = readdir(dir)) != NULL) addList(new->list, strdup(item->d_name)); + closedir(dir); + return new; } void destroyDirector(director_t * p) { assert(p != NULL); + destroyListItem(p->list, free); free(p->path); free(p); |