Lines Matching refs:cf
80 struct cfile *cf;
85 if (!(cf = malloc(sizeof (*cf)))) {
92 cf->n_kv = 0;
93 cf->kvlist = 0;
99 cfile_free(cf);
118 cfile_free(cf);
129 cfile_free(cf);
134 if (cf->n_kv == alloced) {
136 cf->kvlist=realloc((char *)cf->kvlist,
138 if (cf->kvlist==NULL) {
141 cfile_free(cf);
147 if (!(cf->kvlist[cf->n_kv].key = strdup(key)) ||
148 !(cf->kvlist[cf->n_kv].value = strdup(p))) {
151 cf->n_kv++; /* maybe one strdup() worked */
152 cfile_free(cf);
157 cf->n_kv++;
161 return cf;
164 const char *cfile_getstring(cfile cf,const char *key,const char *def)
168 for (opt = 0; opt < cf->n_kv; opt++) {
169 if (*key == cf->kvlist[opt].key[0] &&
170 !strcmp(key, cf->kvlist[opt].key))
171 return cf->kvlist[opt].value;
176 int cfile_getint(cfile cf,const char *key,int def)
178 const char *val = cfile_getstring(cf, key, (char *)0);
185 int cfile_getswitch(cfile cf,const char *key,int def)
187 const char *val = cfile_getstring(cf, key, (char *)0);
202 void cfile_free(cfile cf)
206 if (cf->kvlist) {
207 for (opt = 0; opt < cf->n_kv; opt++) {
208 if (cf->kvlist[opt].key)
209 free(cf->kvlist[opt].key);
210 if (cf->kvlist[opt].value)
211 free(cf->kvlist[opt].value);
213 free(cf->kvlist);
215 free(cf);