in src/odbc/rsodbc/rsini.cpp [107:206]
int RsIni::getPrivateProfileStringWithFullPath(const char *pSectionName, const char *pKey, const char *pDflt, char *pReturn, int iSize, char *pFullFilePath)
{
FILE *fp;
char buffer[INI_BUFFER_SIZE];
char search[INI_KEY_SIZE];
char *pChar = NULL;
int iStrCode = -1;
int iSizeLeft = 0;
char *pNextWrite;
fp = fopen(pFullFilePath, "r");
if (fp == NULL)
{
strncpy(pReturn, pDflt, iSize);
return((iSize <= strlen(pDflt)) ? iSize : strlen(pDflt));
}
iSizeLeft = iSize - 1;
pReturn[0] = '\0';
pNextWrite = pReturn;
snprintf(search, INI_KEY_SIZE, "[%s]", pSectionName);
while (fgets(buffer, INI_BUFFER_SIZE, fp) != 0)
{
if (buffer[strlen(buffer) - 1] == '\n')
buffer[strlen(buffer) - 1] = '\0';
if (isCommentLine(buffer))
continue;
if ((iStrCode = _stricmp(search, buffer)) == 0)
break;
} // Loop to find section
if (iStrCode == 0)
{
iStrCode = -1;
if (pKey != NULL)
strncpy(search, pKey, INI_KEY_SIZE);
while (fgets(buffer, INI_BUFFER_SIZE, fp) != 0)
{
if (buffer[strlen(buffer) - 1] == '\n')
buffer[strlen(buffer) - 1] = '\0';
if (isCommentLine(buffer))
continue;
if (isSection(buffer))
break;
if (pKey == NULL)
{
strncpy(pNextWrite, buffer, iSizeLeft);
iSizeLeft = iSizeLeft - strlen(buffer) - 1;
if (iSizeLeft <= 1)
{
pNextWrite += strlen(buffer) + 1;
*pNextWrite = '\0';
pReturn[iSize - 1] = '\0';
iSizeLeft = 0;
break;
}
else
{
pNextWrite += strlen(buffer) + 1;
*pNextWrite = '\0';
}
}
else
{
if ((pChar = strchr(buffer, '=')) == 0)
continue;
*pChar++ = '\0';
if ((iStrCode = _stricmp(search, trim_whitespaces(buffer))) == 0)
break;
}
} // Loop for key
if (iStrCode == 0)
{
fclose(fp);
if (pChar)
strncpy(pReturn, trim_whitespaces(pChar), iSize);
return((iSize <= strlen(pChar)) ? iSize : strlen(pChar));
} // Key found
} // Section found
fclose(fp);
if (pKey == NULL)
return(iSize - iSizeLeft);
strncpy(pReturn, pDflt, iSize);
return((iSize <= strlen(pDflt)) ? iSize : strlen(pDflt));
}