X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=list%2Flist.c;h=13493e6dc4461ebc403298c9a54e148ef72ef157;hb=8e2aee37f009e1a796e68ac36e8a1782091422e5;hp=d5cf54b6734d6d90fd09f8468133a87a2a503c29;hpb=6cf9bd920bfff6aac1b7eb63e7bf9b036fbd7486;p=my-code%2Fapi.git diff --git a/list/list.c b/list/list.c index d5cf54b..13493e6 100644 --- a/list/list.c +++ b/list/list.c @@ -83,11 +83,11 @@ int list_search_data(t_list *list,void *data,int first_bytes) { list_reset(list); - while(list->current!=NULL) { - if(first_bytes<=list->current->data_len) - if(!(memcmp(list->current->data,data,first_bytes))) return L_SUCCESS; - list_next(list); - } + do { + if(list->current!=NULL) + if(first_bytes<=list->current->data_len) + if(!(memcmp(list->current->data,data,first_bytes))) return L_SUCCESS; + } while(list_next(list)!=L_NO_NEXT_ELEMENT); return L_NO_SUCH_ELEMENT; } @@ -153,10 +153,8 @@ int list_count(t_list *list) { list_reset(list); - while(list->current!=NULL) { - list_next(list); - ++count; - } + if(list->current!=NULL) count++; + if(count) while(list_next(list)!=L_NO_NEXT_ELEMENT) count++; return count; }