#include /* for printf */ #include /* for struct dirent */ #include /* for struct dirent */ #include /* for lstat, struct stat */ #include /* for malloc */ #include /* for strdup */ #include #include #include "error_handling.h" typedef struct _ckdu_tree_entry { char * name; /* INSERT CODE HERE */ struct _ckdu_tree_entry * next; struct _ckdu_tree_entry * child; } ckdu_tree_entry; void initialize_tree_entry(ckdu_tree_entry * entry /* INSERT CODE HERE */) { /* INSERT CODE HERE */ } void crawl_tree(ckdu_tree_entry * root, const char * dirname) { /* INSERT CODE HERE */ } void print_tree(const ckdu_tree_entry * root) { /* INSERT CODE HERE */ } int main() { DIR * dir; struct dirent * entry; struct stat props; errno = 0; dir = opendir("."); if (! dir) { handle_opendir_error(errno, "."); return 1; } do { errno = 0; entry = readdir(dir); if (! entry) { if (errno) { handle_readdir_error(errno, "."); return 1; } break; } if (! strcmp(entry->d_name, ".") || ! strcmp(entry->d_name, "..")) { continue; } errno = 0; if (lstat(entry->d_name, &props)) { handle_stat_error(errno, ".", entry->d_name); return 1; } printf("%10u %s\n", (unsigned int)props.st_size, entry->d_name); } while (dir); closedir(dir); return 0; }