diff options
| author | Tomas Chvatal (scarabeus) <tomas.chvatal@gmail.com> | 2008-10-22 22:50:54 +0200 |
|---|---|---|
| committer | Tomas Chvatal (scarabeus) <tomas.chvatal@gmail.com> | 2008-10-22 22:50:54 +0200 |
| commit | e12753d2ec9db83ec08bb9db63902a82fb245cdd (patch) | |
| tree | 6e4a63b790d6335f969f88b797a927e0fb25f37a /src/base/director.c~ | |
| parent | 0b4d9821c7333b8c4bdf7e0eeb750aef502a1137 (diff) | |
X
Diffstat (limited to 'src/base/director.c~')
| -rw-r--r-- | src/base/director.c~ | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/base/director.c~ b/src/base/director.c~ new file mode 100644 index 0000000..a4c8496 --- /dev/null +++ b/src/base/director.c~ @@ -0,0 +1,61 @@ + +#include <dirent.h> +#include <sys/types.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <unistd.h> +#include <assert.h> + +#include "main.h" +#include "list.h" + +typedef struct director_struct +{ + char *path; + list_t *list; +} director_t; + +director_t* loadDirector(char *s) +{ + director_t *new; + 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); + return NULL; + } + + 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); +} |