summaryrefslogtreecommitdiff
path: root/src/director.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/director.c')
-rwxr-xr-xsrc/director.c64
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);
+}
+
+