X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fshared%2Flist_op.c;h=660dfbbc9ed4d5034eea9fad433493e9d4864aa0;hp=19e5e4605892de81d369fcbe0329d30bd2c74c3a;hb=6ef2f786c6c8ead94841b5f93baf9f43421f08c8;hpb=301048b51990573e58a30dc4a5bb4ec285cad554 diff --git a/src/shared/list_op.c b/src/shared/list_op.c index 19e5e46..660dfbb 100755 --- a/src/shared/list_op.c +++ b/src/shared/list_op.c @@ -1,4 +1,5 @@ -/* @(#) $Id$ */ +/* @(#) $Id: ./src/shared/list_op.c, 2011/09/08 dcid Exp $ + */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. @@ -9,13 +10,13 @@ * Foundation */ -/* Common API for dealing with lists */ +/* Common API for dealing with lists */ #include "shared.h" -/* Create the list +/* Create the list * Return NULL on error */ OSList *OSList_Create() @@ -25,14 +26,14 @@ OSList *OSList_Create() my_list = calloc(1, sizeof(OSList)); if(!my_list) return(NULL); - + my_list->first_node = NULL; my_list->last_node = NULL; my_list->cur_node = NULL; my_list->currently_size = 0; my_list->max_size = 0; my_list->free_data_function = NULL; - + return(my_list); } @@ -47,7 +48,7 @@ int OSList_SetMaxSize(OSList *list, int max_size) { return(0); } - + /* Minimum size is 1 */ if(max_size <= 1) { @@ -69,7 +70,7 @@ int OSList_SetFreeDataPointer(OSList *list, void *free_data_function) { return(0); } - + list->free_data_function = free_data_function; return(1); } @@ -103,12 +104,12 @@ OSListNode *OSList_GetNextNode(OSList *list) { if(list->cur_node == NULL) return(NULL); - + list->cur_node = list->cur_node->next; - + return(list->cur_node); } - + /* Get the prev node from the list * Returns NULL at the beginning @@ -122,11 +123,11 @@ OSListNode *OSList_GetPrevNode(OSList *list) return(list->cur_node); } - + /* Get the currently node. * Returns null when no currently node is available - */ + */ OSListNode *OSList_GetCurrentlyNode(OSList *list) { return(list->cur_node); @@ -137,15 +138,15 @@ OSListNode *OSList_GetCurrentlyNode(OSList *list) void OSList_DeleteOldestNode(OSList *list) { OSListNode *next; - + if(list->first_node) { next = list->first_node->next; if(next) next->prev = NULL; else - list->last_node = next; - + list->last_node = next; + free(list->first_node); list->first_node = next; } @@ -215,14 +216,14 @@ void OSList_DeleteCurrentlyNode(OSList *list) { OSListNode *prev; OSListNode *next; - + if(list->cur_node == NULL) return; - + prev = list->cur_node->prev; next = list->cur_node->next; - + /* Setting the previous node of the next one * and the next node of the previous one.. :) */ @@ -246,7 +247,7 @@ void OSList_DeleteCurrentlyNode(OSList *list) list->last_node = NULL; list->first_node = NULL; } - + /* Freeing the node memory */ free(list->cur_node); @@ -262,7 +263,7 @@ void OSList_DeleteCurrentlyNode(OSList *list) */ int OSList_AddData(OSList *list, void *data) { - OSListNode *newnode; + OSListNode *newnode; /* Allocating memory for new node */ @@ -283,20 +284,20 @@ int OSList_AddData(OSList *list, void *data) { list->first_node = newnode; } - + /* If we have a last node, set the next to new node */ if(list->last_node) { list->last_node->next = newnode; } - - + + /* newnode become last node */ list->last_node = newnode; /* Increment list size */ list->currently_size++; - + /* if currently_size higher than the maximum size, remove the * oldest node (first one) */ @@ -314,10 +315,10 @@ int OSList_AddData(OSList *list, void *data) { list->free_data_function(list->first_node->data); } - + /* Clearing the memory */ free(list->first_node); - + /* First node become the ex first->next */ list->first_node = newnode; @@ -325,7 +326,7 @@ int OSList_AddData(OSList *list, void *data) list->currently_size--; } } - + return(1); }