lib/cfg_parse.c
/**
 * This function deletes a key-value pair from a cfg_struct.
 * If the key does not exist, the function does nothing.
 * @param cfg Pointer to cfg_struct to search.
 * @param key String containing key to search for.
 */
This function deletes a key-value pair from a cfg_struct.
If the key does not exist, the function does nothing.
@param cfg Pointer to cfg_struct to search.
@param key String containing key to search for.
This function deletes a key - value pair from a cfg_struct . If the key does not exist the function does nothing . @param cfg Pointer to cfg_struct to search . @param key String containing key to search for .
void cfg_delete(struct cfg_struct *cfg, const char *key)
{
  unsigned int i, len;
  char *tkey;
  struct cfg_node *temp, *temp2 = NULL;
  if (cfg == NULL || key == NULL) return;
  tkey = cfg_trim(key);
  if (! strcmp(tkey,"")) { free(tkey); return; }
  len = strlen(tkey);
  for (i = 0; i < len; i++)
    tkey[i] = tolower(tkey[i]);
  temp = cfg->head;
  while (temp != NULL)
  {
    if (! strcmp(tkey, temp->key))
    {
      free(tkey);
      if (temp == cfg->head)
      {
        cfg->head = temp->next;
      } else {
        temp2->next = temp->next;
      }
      free(temp->value);
      free(temp->key);
      free(temp);
      return;
    }
    temp2 = temp;
    temp = temp->next;
  }
  free(tkey);
}
void cfg_delete ( struct cfg_struct * cfg , const char * key ) { unsigned int i , len ; char * tkey ; struct cfg_node * temp , * temp2 = NULL ; if ( cfg == NULL || key == NULL ) return ; tkey = cfg_trim ( key ) ; if ( ! strcmp ( tkey , " " ) ) { free ( tkey ) ; return ; } len = strlen ( tkey ) ; for ( i = 0 ; i < len ; i ++ ) tkey [ i ] = tolower ( tkey [ i ] ) ; temp = cfg -> head ; while ( temp != NULL ) { if ( ! strcmp ( tkey , temp -> key ) ) { free ( tkey ) ; if ( temp == cfg -> head ) { cfg -> head = temp -> next ; } else { temp2 -> next = temp -> next ; } free ( temp -> value ) ; free ( temp -> key ) ; free ( temp ) ; return ; } temp2 = temp ; temp = temp -> next ; } free ( tkey ) ; }
This function deletes a key-value pair from a cfg_struct.
This function deletes a key - value pair from a cfg_struct .
/* safety check: null input */ /* trim input key */ /* Exclude empty key */ /* Lowercase key */ /* set pointer to start of list */ /* search list for existing key */ /* cleanup trimmed key */ /* first element */ /* splice out element */ /* delete element */ /* not found */ /* cleanup trimmed key */