From 9aeaead257f9b5d53f2abc63383e96f0f38d94cc Mon Sep 17 00:00:00 2001 From: arnaud convers <arnaud.convers@sansano.usm.cl> Date: Sat, 30 Apr 2016 14:00:44 -0300 Subject: [PATCH] tarea1 - fourth commit - corrections kernel style --- listdir.c | 56 +++++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/listdir.c b/listdir.c index 72b84d2..d322d00 100644 --- a/listdir.c +++ b/listdir.c @@ -8,13 +8,10 @@ struct list_node *listdir(const char *path) dir = opendir(path); //Returns a NULL pointer if the path is not correct - if (dir == NULL) - { + if (dir == NULL) { //Path isn't correct or is the path of a file return NULL; - } - else - { + } else { struct dirent *actualfile = NULL; actualfile = readdir(dir); @@ -26,13 +23,12 @@ struct list_node *listdir(const char *path) //If the folder is empty, there are only two elements inside //We return a NULL pointer if the folder is empty. int compt = 0; - while(actualfile != NULL) - { + while (actualfile != NULL) { compt++; actualfile = readdir(dir); } - if (compt == 2) - { + + if (compt == 2) { //The folder is empty return NULL; } @@ -41,11 +37,9 @@ struct list_node *listdir(const char *path) rewinddir(dir); actualfile = readdir(dir); - while(actualfile != NULL) - { + while (actualfile != NULL) { //We do not consider the parent folder and the actual folder - if (strcmp(actualfile->d_name,".") != 0 && strcmp(actualfile->d_name,"..") != 0) - { + if (strcmp(actualfile->d_name,".") != 0 && strcmp(actualfile->d_name,"..") != 0) { struct list_node *new = NULL; new = malloc(sizeof(struct list_node)); @@ -56,8 +50,7 @@ struct list_node *listdir(const char *path) aux = malloc(sizeof(struct list_node)); aux = files; - if (actualfile->d_type == DT_DIR) - { + if (actualfile->d_type == DT_DIR) { new->is_dir = 1; //We always place the folder at the beginning of the list. //But if the file is empty, we put a null pointer @@ -67,19 +60,14 @@ struct list_node *listdir(const char *path) else new->next = files; files = new ; - } - else if (actualfile->d_type == DT_REG) - { + } else if (actualfile->d_type == DT_REG) { new->is_dir = 0; //If there is no file yet in the list - if (files->name == NULL) - { + if (files->name == NULL) { files = new; files->next = NULL; - } - else - { + } else { aux = files; while(aux->next != NULL) aux = aux->next; @@ -100,16 +88,11 @@ void printdir(struct list_node *list) printf("\n"); struct list_node *aux = NULL; aux = list; - while(aux != NULL) - { + while (aux != NULL) { if (aux->is_dir) - { printf("%s/ \n",aux->name); - } else - { printf("%s\n",aux->name); - } aux = aux->next; } } @@ -121,10 +104,8 @@ void printdir(struct list_node *list) //automatically, it is not in the heap void suppr(struct list_node **list) { - if(list !=NULL) - { - if(*list != NULL) - { + if (list !=NULL) { + if (*list != NULL) { struct list_node **aux = list; free((**aux).name); (**aux).name = NULL; @@ -137,10 +118,8 @@ void suppr(struct list_node **list) //Erase all nodes of a given list of the heap memory void clean_dirlist(struct list_node **list) { - if(list != NULL) - { - if(*list != NULL) - { + if (list != NULL) { + if (*list != NULL) { struct list_node **aux1 = NULL; aux1 = malloc(sizeof(struct list_node)); aux1 = list; @@ -149,8 +128,7 @@ void clean_dirlist(struct list_node **list) aux2 = malloc(sizeof(struct list_node)); aux2 = &((**aux1).next); - while(*aux1 != NULL) - { + while(*aux1 != NULL) { suppr(aux1); aux1 = aux2; aux2 = &((**aux1).next); -- GitLab