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

Function PROFILE_Open

storage/connect/inihandl.cpp:439–560  ·  view source on GitHub ↗

* PROFILE_Open * * Open a profile file, checking the cached file first. ***********************************************************************/

Source from the content-addressed store, hash-verified

437 * Open a profile file, checking the cached file first.
438 ***********************************************************************/
439static BOOL PROFILE_Open(LPCSTR filename)
440{
441//char buffer[MAX_PATHNAME_LEN];
442//char *p;
443 FILE *file = NULL;
444 int i, j;
445 struct stat buf;
446 PROFILE *tempProfile;
447
448 if (trace(2))
449 htrc("PROFILE_Open: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES);
450
451 /* First time around */
452 if (!CurProfile)
453 for (i = 0; i < N_CACHED_PROFILES; i++) {
454 MRUProfile[i] = (PROFILE*)malloc(sizeof(PROFILE));
455
456 if (MRUProfile[i] == NULL)
457 break;
458
459 MRUProfile[i]->changed=FALSE;
460 MRUProfile[i]->section=NULL;
461// MRUProfile[i]->dos_name=NULL;
462// MRUProfile[i]->unix_name=NULL;
463 MRUProfile[i]->filename=NULL;
464 MRUProfile[i]->mtime=0;
465 } // endfor i
466
467 /* Check for a match */
468 for (i = 0; i < N_CACHED_PROFILES; i++) {
469 if (trace(2))
470 htrc("MRU=%s i=%d\n", SVP(MRUProfile[i]->filename), i);
471
472 if (MRUProfile[i]->filename && !strcmp(filename, MRUProfile[i]->filename)) {
473 if (i) {
474 PROFILE_FlushFile();
475 tempProfile = MRUProfile[i];
476
477 for (j = i; j > 0; j--)
478 MRUProfile[j] = MRUProfile[j-1];
479
480 CurProfile=tempProfile;
481 } // endif i
482
483 if (!stat(CurProfile->filename, &buf) && CurProfile->mtime == buf.st_mtime) {
484 if (trace(2))
485 htrc("(%s): already opened (mru=%d)\n", filename, i);
486
487 } else {
488 if (trace(2))
489 htrc("(%s): already opened, needs refreshing (mru=%d)\n", filename, i);
490
491 } // endif stat
492
493 return TRUE;
494 } // endif filename
495
496 } // endfor i

Calls 5

PROFILE_FlushFileFunction · 0.85
PROFILE_ReleaseFileFunction · 0.85
PROFILE_LoadFunction · 0.85
htrcFunction · 0.70
statClass · 0.70

Tested by

no test coverage detected