MCPcopy Create free account
hub / github.com/MariaDB/server / PROFILE_Load

Function PROFILE_Load

storage/connect/inihandl.cpp:247–346  ·  view source on GitHub ↗

* PROFILE_Load * * Load a profile tree from a file. ***********************************************************************/

Source from the content-addressed store, hash-verified

245 * Load a profile tree from a file.
246 ***********************************************************************/
247static PROFILESECTION *PROFILE_Load( FILE *file )
248{
249 char buffer[PROFILE_MAX_LINE_LEN];
250 char *p, *p2;
251 int line = 0;
252 PROFILESECTION *section, *first_section;
253 PROFILESECTION* *next_section;
254 PROFILEKEY *key, *prev_key, **next_key;
255
256 first_section = (PROFILESECTION*)malloc(sizeof(*section));
257
258 if (first_section == NULL)
259 return NULL;
260
261 first_section->name[0] = 0;
262 first_section->key = NULL;
263 first_section->next = NULL;
264 next_section = &first_section->next;
265 next_key = &first_section->key;
266 prev_key = NULL;
267
268 while (fgets(buffer, PROFILE_MAX_LINE_LEN, file)) {
269 line++;
270 p = buffer;
271
272 while (*p && PROFILE_isspace(*p))
273 p++;
274
275 if (*p == '[') { /* section start */
276 if (!(p2 = strrchr( p, ']'))) {
277 fprintf(stderr, "Invalid section header at line %d: '%s'\n",
278 line, p);
279 } else {
280 *p2 = '\0';
281 p++;
282
283 if (!(section = (PROFILESECTION*)malloc(sizeof(*section) + strlen(p))))
284 break;
285
286 strcpy(section->name, p);
287 section->key = NULL;
288 section->next = NULL;
289 *next_section = section;
290 next_section = &section->next;
291 next_key = &section->key;
292 prev_key = NULL;
293
294 if (trace(2))
295 htrc("New section: '%s'\n",section->name);
296
297 continue;
298 } // endif p2
299
300 } // endif p
301
302 p2 = p + strlen(p) - 1;
303
304 while ((p2 > p) && ((*p2 == '\n') || PROFILE_isspace(*p2)))

Callers 1

PROFILE_OpenFunction · 0.85

Calls 2

PROFILE_isspaceFunction · 0.85
htrcFunction · 0.70

Tested by

no test coverage detected