Diff for /libaitcfg/src/aitcfg.c between versions 1.4.4.1 and 1.7

version 1.4.4.1, 2012/04/02 14:39:02 version 1.7, 2012/07/25 15:24:20
Line 104  cfg_SetErr(int eno, char *estr, ...) Line 104  cfg_SetErr(int eno, char *estr, ...)
   
   
 /*  /*
    * cfgInitConfig() - Init config root
    *
    * @cfg = Config root
    * return: -1 error or 0 ok
    */
   int
   cfgInitConfig(cfg_root_t * __restrict cfg)
   {
           if (!cfg)
                   return -1;
   
           pthread_mutex_init(&cfg->rc_mtx, NULL);
   
           SLIST_INIT(cfg);
           RB_INIT(cfg);
           return 0;
   }
   
   /*
  * cfgLoadConfig() - Load config from file   * cfgLoadConfig() - Load config from file
  *   *
  * @cfgName = Config filename   * @cfgName = Config filename
Line 119  cfgLoadConfig(const char *cfgName, cfg_root_t * __rest Line 138  cfgLoadConfig(const char *cfgName, cfg_root_t * __rest
         if (!cfgName || !cfg) {          if (!cfgName || !cfg) {
                 cfg_SetErr(EINVAL, "Invalid parameter(s)");                  cfg_SetErr(EINVAL, "Invalid parameter(s)");
                 return -1;                  return -1;
        } else {        } else
#ifdef HAVE_LIBPTHREAD                cfgInitConfig(cfg);
                pthread_mutex_init(&cfg->rc_mtx, NULL); 
#endif 
                SLIST_INIT(cfg); 
                RB_INIT(cfg); 
        } 
   
         f = fopen(cfgName, "r");          f = fopen(cfgName, "r");
         if (!f) {          if (!f) {
Line 140  cfgLoadConfig(const char *cfgName, cfg_root_t * __rest Line 154  cfgLoadConfig(const char *cfgName, cfg_root_t * __rest
 }  }
   
 /*  /*
 * cfgUnloadConfig() - Unload config from memory and free resources * cfgClearConfig() - Clear config and free resources
  *   *
  * @cfg = Config root   * @cfg = Config root
  * return: none   * return: none
  */   */
 void  void
cfgUnloadConfig(cfg_root_t * __restrict cfg)cfgClearConfig(cfg_root_t * __restrict cfg)
 {  {
         struct tagCfg *av;          struct tagCfg *av;
   
Line 160  cfgUnloadConfig(cfg_root_t * __restrict cfg) Line 174  cfgUnloadConfig(cfg_root_t * __restrict cfg)
                 AIT_FREE_VAL(&av->cfg_val);                  AIT_FREE_VAL(&av->cfg_val);
                 AIT_FREE_VAL(&av->cfg_attr);                  AIT_FREE_VAL(&av->cfg_attr);
                 AIT_FREE_VAL(&av->cfg_sec);                  AIT_FREE_VAL(&av->cfg_sec);
                free(av);                io_free(av);
         }          }
         cfg->rbh_root = NULL;          cfg->rbh_root = NULL;
         CFG_RC_UNLOCK(cfg);          CFG_RC_UNLOCK(cfg);
   
 #ifdef HAVE_LIBPTHREAD  
         pthread_mutex_destroy(&cfg->rc_mtx);  
 #endif  
 }  }
   
 #if 0  
 /*  /*
 * CreateConfig() Create config file from memory * cfgUnloadConfig() - Unload config from memory and destroy resources
 * @csConfigName = New config filename *
 * @cfg = Head list element * @cfg = Config root
 * return: 0 ok; -1 error:: can`t save new config * return: none
*/ */
int CreateConfig(const char *csConfigName, sl_config * __restrict cfg)void
 cfgUnloadConfig(cfg_root_t * __restrict cfg)
 {  {
        FILE *f;        if (!cfg)
        int ret;                return;
   
        if (!csConfigName || !cfg)        cfgClearConfig(cfg);
                return -1;        pthread_mutex_destroy(&cfg->rc_mtx);
 
        f = fopen(csConfigName, "wt"); 
        if (!f) { 
                LOGERR; 
                return -1; 
        } 
         
        ret ^= ret; 
        ret = WriteConfig(f, cfg); 
 
        fclose(f); 
        return ret; 
 }  }
   
 /*  /*
 * cfg_CreateConfig() Create config file from memory without whitespaces! * cfgCreateConfig() - Create config file from memory
  *
  * @csConfigName = New config filename   * @csConfigName = New config filename
 * @cfg = Head list element * @cfg = Config root
 * return: 0 ok; -1 error:: can`t save new config * @whitespace = Additional whitespace characters to file
*/ * return: -1 error or 0 ok
int cfg_CreateConfig(const char *csConfigName, sl_config * __restrict cfg) */
 int
 cfgCreateConfig(const char *csConfigName, cfg_root_t * __restrict cfg, int whitespace)
 {  {
         FILE *f;          FILE *f;
         int ret;          int ret;
Line 212  int cfg_CreateConfig(const char *csConfigName, sl_conf Line 213  int cfg_CreateConfig(const char *csConfigName, sl_conf
         if (!csConfigName || !cfg)          if (!csConfigName || !cfg)
                 return -1;                  return -1;
   
        f = fopen(csConfigName, "wt");        f = fopen(csConfigName, "w");
         if (!f) {          if (!f) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
         }          }
                   
        ret ^= ret;        ret = cfgWriteConfig(f, cfg, whitespace);
        ret = cfg_WriteConfig(f, cfg); 
   
         fclose(f);          fclose(f);
         return ret;          return ret;
 }  }
 #endif  

Removed from v.1.4.4.1  
changed lines
  Added in v.1.7


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>