X-Git-Url: https://git.openafs.org/?p=openafs.git;a=blobdiff_plain;f=src%2Faklog%2Flinked_list.c;h=06494825a3c3a66f35667cf6399a817064408270;hp=0d4ba0b4cbab8b8c9b7db3e0876298c0e760ccac;hb=9547615445ccbe07d8f6d7baeb7fd0315354fce0;hpb=cef225f20e88cffaaa4a4a7dfc74d39137bc4e64 diff --git a/src/aklog/linked_list.c b/src/aklog/linked_list.c index 0d4ba0b..0649482 100644 --- a/src/aklog/linked_list.c +++ b/src/aklog/linked_list.c @@ -1,22 +1,18 @@ -/* +/* * $Id$ - * + * * This file contains general linked list routines. - * + * * Copyright 1990,1991 by the Massachusetts Institute of Technology * For distribution and copying rights, see the file "mit-copyright.h" */ -#if !defined(lint) && !defined(SABER) -static char *rcsid_list_c = "$Id$"; -#endif /* lint || SABER */ +#include +#include -#include -#include "linked_list.h" +#include -#ifndef NULL -#define NULL 0 -#endif +#include "linked_list.h" #ifndef TRUE #define TRUE 1 @@ -26,11 +22,8 @@ static char *rcsid_list_c = "$Id$"; #define FALSE 0 #endif -char *calloc(); - -#ifdef __STDC__ void ll_init(linked_list *list) - /* + /* * Requires: * List must point to a linked list structure. It is not acceptable * to pass a null pointer to this routine. @@ -40,10 +33,6 @@ void ll_init(linked_list *list) * Initializes the list to be one with no elements. If list is * NULL, prints an error message and causes the program to crash. */ -#else -void ll_init(list) - linked_list *list; -#endif /* __STDC__ */ { if (list == NULL) { fprintf(stderr, "Error: calling ll_init with null pointer.\n"); @@ -51,34 +40,24 @@ void ll_init(list) } /* This sets everything to zero, which is what we want. */ -#ifdef WINDOWS - memset(list, 0, sizeof(linked_list)); -#else bzero((char *)list, sizeof(linked_list)); -#endif /* WINDOWS */ } -#ifdef __STDC__ ll_node *ll_add_node(linked_list *list, ll_end which_end) /* * Modifies: * list - * Effects: + * Effects: * Adds a node to one end of the list (as specified by which_end) * and returns a pointer to the node added. which_end is of type - * ll_end and should be either ll_head or ll_tail as specified in - * list.h. If there is not enough memory to allocate a node, + * ll_end and should be either ll_head or ll_tail as specified in + * list.h. If there is not enough memory to allocate a node, * the program returns NULL. */ -#else -ll_node *ll_add_node(list, which_end) - linked_list *list; - ll_end which_end; -#endif /* __STDC__ */ { ll_node *node = NULL; - - if ((node = (ll_node *)calloc(1, sizeof(ll_node))) != NULL) { + + if ((node = calloc(1, sizeof(ll_node))) != NULL) { if (list->nelements == 0) { list->first = node; list->last = node; @@ -105,28 +84,22 @@ ll_node *ll_add_node(list, which_end) list->nelements++; } } - + return(node); } -#ifdef __STDC__ int ll_delete_node(linked_list *list, ll_node *node) - /* - * Modifies: + /* + * Modifies: * list * Effects: - * If node is in list, deletes node and returns LL_SUCCESS. + * If node is in list, deletes node and returns LL_SUCCESS. * Otherwise, returns LL_FAILURE. If node contains other data, * it is the responsibility of the caller to free it. Also, since * this routine frees node, after the routine is called, "node" * won't point to valid data. */ -#else -int ll_delete_node(list, node) - linked_list *list; - ll_node *node; -#endif /* __STDC__ */ { int status = LL_SUCCESS; ll_node *cur_node = NULL; @@ -166,14 +139,7 @@ int ll_delete_node(list, node) /* ll_add_data is a macro defined in linked_list.h */ /* This routine maintains a list of strings preventing duplication. */ -#ifdef __STDC__ int ll_string(linked_list *list, ll_s_action action, char *string) -#else -int ll_string(list, action, string) - linked_list *list; - ll_s_action action; - char *string; -#endif /* __STDC__ */ { int status = LL_SUCCESS; ll_node *cur_node; @@ -181,21 +147,20 @@ int ll_string(list, action, string) switch(action) { case ll_s_check: /* Scan the list until we find the string in question */ - for (cur_node = list->first; cur_node && (status == FALSE); + for (cur_node = list->first; cur_node && (status == FALSE); cur_node = cur_node->next) status = (strcmp(string, cur_node->data) == 0); break; case ll_s_add: /* Add a string to the list. */ if (!ll_string(list, ll_s_check, string)) { - if (cur_node = ll_add_node(list, ll_tail)) { + if ((cur_node = ll_add_node(list, ll_tail))) { char *new_string; - if (new_string = (char *)calloc(strlen(string) + 1, - sizeof(char))) { + if ((new_string = calloc(strlen(string) + 1, sizeof(char)))) { strcpy(new_string, string); ll_add_data(cur_node, new_string); } - else + else status = LL_FAILURE; } else