#include #include #include #include #include struct file_entry { struct file_entry *next; char name[0]; }; static struct file_entry *the_list; static int add_new_file_entry(const char *fn) { int len = strlen(fn); struct file_entry *new; new = malloc(sizeof(*new) + len + 1); if ( new == NULL ) return 0; strcpy(new->name, fn); new->next = the_list; the_list = new; return 1; } int main(int argc, char **argv) { DIR *d; struct dirent *f; struct file_entry *t; d = opendir("."); if ( d == NULL ) { perror("diropen()"); return 1; } while ( (f = readdir(d)) ) add_new_file_entry(f->d_name); closedir(d); for(t=the_list; t; t=t->next) printf("Entry: %s\n", t->name); return 0; }