lib/cfg_parse.c
/**
 * This function saves a complete cfg_struct to a file.
 * Comments are not preserved.
 * @param cfg Pointer to cfg_struct to save.
 * @param filename String containing filename to open and parse.
 * @return EXIT_SUCCESS (0) on success, or EXIT_FAILURE if file could not be opened or a write error occurred.
 */
This function saves a complete cfg_struct to a file.
Comments are not preserved.
@param cfg Pointer to cfg_struct to save.
@param filename String containing filename to open and parse.
@return EXIT_SUCCESS (0) on success, or EXIT_FAILURE if file could not be opened or a write error occurred.
This function saves a complete cfg_struct to a file . Comments are not preserved . @param cfg Pointer to cfg_struct to save . @param filename String containing filename to open and parse . @return EXIT_SUCCESS ( 0 ) on success or EXIT_FAILURE if file could not be opened or a write error occurred .
int cfg_save(const struct cfg_struct *cfg, const char *filename)
{
  FILE *fp;
  struct cfg_node *temp;
  if (cfg == NULL || filename == NULL) return EXIT_FAILURE;
  fp = fopen(filename, "w");
  if (fp == NULL) return EXIT_FAILURE;
  temp = cfg->head;
  while (temp != NULL)
  {
    if (fprintf(fp,"%s=%s\n",temp->key,temp->value) < 0) { 
      fclose(fp);
      return EXIT_FAILURE;
    }
    temp = temp->next;
  }
  fclose(fp);
  return EXIT_SUCCESS;
}
int cfg_save ( const struct cfg_struct * cfg , const char * filename ) { FILE * fp ; struct cfg_node * temp ; if ( cfg == NULL || filename == NULL ) return EXIT_FAILURE ; fp = fopen ( filename , " " ) ; if ( fp == NULL ) return EXIT_FAILURE ; temp = cfg -> head ; while ( temp != NULL ) { if ( fprintf ( fp , " \n " , temp -> key , temp -> value ) < 0 ) { fclose ( fp ) ; return EXIT_FAILURE ; } temp = temp -> next ; } fclose ( fp ) ; return EXIT_SUCCESS ; }
This function saves a complete cfg_struct to a file.
This function saves a complete cfg_struct to a file .
/* safety check: null input */ /* open output file for writing */ /* point at first item in list */ /* step through the list, dumping each key-value pair to disk */