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

Function PROFILE_GetPrivateProfileString

storage/connect/inihandl.cpp:1105–1157  ·  view source on GitHub ↗

* if allow_section_name_copy is TRUE, allow the copying : * - of Section names if 'section' is NULL * - of Keys in a Section if 'entry' is NULL * (see MSDN doc for GetPrivateProfileString) **********************************************************************/

Source from the content-addressed store, hash-verified

1103 * (see MSDN doc for GetPrivateProfileString)
1104 **********************************************************************/
1105static int PROFILE_GetPrivateProfileString(LPCSTR section, LPCSTR entry,
1106 LPCSTR def_val, LPSTR buffer,
1107 uint len, LPCSTR filename,
1108 BOOL allow_section_name_copy)
1109{
1110 int ret;
1111 LPSTR pDefVal = NULL;
1112
1113 if (!filename)
1114 filename = "win.ini";
1115
1116 /* strip any trailing ' ' of def_val. */
1117 if (def_val) {
1118 LPSTR p = (LPSTR)&def_val[strlen(def_val)]; // even "" works !
1119
1120 while (p > def_val)
1121 if ((*(--p)) != ' ')
1122 break;
1123
1124 if (*p == ' ') { /* ouch, contained trailing ' ' */
1125 int len = p - (LPSTR)def_val;
1126
1127 pDefVal = (LPSTR)malloc(len + 1);
1128 strncpy(pDefVal, def_val, len);
1129 pDefVal[len] = '\0';
1130 } // endif *p
1131
1132 } // endif def_val
1133
1134 if (!pDefVal)
1135 pDefVal = (LPSTR)def_val;
1136
1137 EnterCriticalSection(&PROFILE_CritSect);
1138
1139 if (PROFILE_Open(filename)) {
1140 if ((allow_section_name_copy) && (section == NULL))
1141 ret = PROFILE_GetSectionNames(buffer, len);
1142 else
1143 /* PROFILE_GetString already handles the 'entry == NULL' case */
1144 ret = PROFILE_GetString(section, entry, pDefVal, buffer, len);
1145
1146 } else {
1147 strncpy(buffer, pDefVal, len);
1148 ret = strlen(buffer);
1149 } // endif Open
1150
1151 LeaveCriticalSection(&PROFILE_CritSect);
1152
1153 if (pDefVal != def_val) /* allocated */
1154 memfree(pDefVal);
1155
1156 return ret;
1157} // end of PROFILE_GetPrivateProfileString
1158
1159/********************** API functions **********************************/
1160

Callers 2

GetPrivateProfileStringFunction · 0.85
GetPrivateProfileIntFunction · 0.85

Calls 3

PROFILE_OpenFunction · 0.85
PROFILE_GetSectionNamesFunction · 0.85
PROFILE_GetStringFunction · 0.85

Tested by

no test coverage detected