Пример #1
0
/*****************************************************************************
 *
 * This routine removes a XiaDefaults entry
 *
 *****************************************************************************/
HANDEL_SHARED int HANDEL_API xiaRemoveDefault(char *alias)
{
  int status = XIA_SUCCESS;

  XiaDefaults *prev    = NULL;
  XiaDefaults  *current = NULL;
  XiaDefaults  *next    = NULL;

  sprintf(info_string, "Preparing to remove default w/ alias %s", alias);
  xiaLogDebug("xiaRemoveDefault", info_string);

  if (isListEmpty(xiaDefaultsHead))
    {
      status = XIA_NO_ALIAS;
      sprintf(info_string, "Alias %s does not exist", alias);
      xiaLogError("xiaRemoveDefault", info_string, status);
      return status;
    }

  /* First check if this alias exists already? */
  prev = NULL;
  current = xiaDefaultsHead;
  next = current->next;
  while (next != NULL)
    {
      if (STREQ(alias, current->alias))
        {
          break;
        }
      /* Move to the next element */
      prev = current;
      current = next;
      next = current->next;
    }

  /* Check if we found nothing */
  if ((next == NULL) &&
      (!STREQ(current->alias, alias)))
    {
      status = XIA_NO_ALIAS;
      sprintf(info_string,"Alias %s does not exist.", alias);
      xiaLogError("xiaRemoveDefault", info_string, status);
      return status;
    }

  /* Check if match is the head of the list */
  if (current == xiaDefaultsHead)
    {
      xiaDefaultsHead = next;

    } else {

	  prev->next = next;
	}

  /* Free up the memory associated with this element */
  xiaFreeXiaDefaults(current);

  return status;
}
Пример #2
0
/*
 * Initializes the XiaDefaults structure.
 */
HANDEL_STATIC int HANDEL_API xiaInitXiaDefaultsDS(void)
{
    int status = XIA_SUCCESS;

    XiaDefaults *next;
    XiaDefaults *current = xiaDefaultsHead;

    /* Search thru the XiaDefaults LL and clear them out */
    while ((current != NULL) && (status == XIA_SUCCESS)) {
        next = current->next;

        status = xiaFreeXiaDefaults(current);
        if (status != XIA_SUCCESS) {
            xiaLogError("xiaInitXiaDefaultDS", "Error freeing default", status);
            return status;
        }

        current = next;
    }
    /* And clear out the pointer to the head of the list(the memory is freed) */
    xiaDefaultsHead = NULL;

    return status;
}