diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-02-01 22:59:06 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-02-01 22:59:06 +0000 |
| commit | 6d4e1eae16b84918009625a866104ec26a234277 (patch) | |
| tree | a340a8a547a60c9f63c8dfafe8909242f9c9bbd8 /src/director.c | |
nahranie tarballu tuxanci-ng na SVN server
Dusan Durech ( Oroborus )
git-svn-id: http://opensvn.csie.org/tuxanci_ng@1 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/director.c')
| -rwxr-xr-x | src/director.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/director.c b/src/director.c new file mode 100755 index 0000000..9c11cb2 --- /dev/null +++ b/src/director.c @@ -0,0 +1,64 @@ + +#include <dirent.h> +#include <sys/types.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <assert.h> + +#include "list.h" +#include "string_length.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(); + + if( s[0] == '/' ) + { + strcpy(path, s); + } + else + { + getcwd(path, STR_PATH_SIZE); + strcat(path, s+1); + } + + new->path = strdup(path); + + dir = opendir(new->path); + + 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); +} + + |