| 155 | } |
| 156 | |
| 157 | void Ini_SetString(const char *category, const char *key, const char *value, char *source) |
| 158 | { |
| 159 | char *s; |
| 160 | char buffer[120]; |
| 161 | |
| 162 | if (source == NULL || category == NULL) return; |
| 163 | |
| 164 | s = Ini_GetString(category, NULL, NULL, NULL, 0, source); |
| 165 | if (s == NULL && key != NULL) { |
| 166 | sprintf(buffer, "\r\n[%s]\r\n", category); |
| 167 | strcat(source, buffer); |
| 168 | } |
| 169 | |
| 170 | s = Ini_GetString(category, key, NULL, NULL, 0, source); |
| 171 | if (s != NULL) { |
| 172 | uint16 count = (uint16)strcspn(s, "\r\n"); |
| 173 | if (count != 0) { |
| 174 | /* Drop first line if not empty */ |
| 175 | size_t len = strlen(s + count + 1) + 1; |
| 176 | memmove(s, s + count + 1, len); |
| 177 | } |
| 178 | if (*s == '\n') { |
| 179 | /* Drop first line if empty */ |
| 180 | size_t len = strlen(s + 1) + 1; |
| 181 | memmove(s, s + 1, len); |
| 182 | } |
| 183 | } else { |
| 184 | s = Ini_GetString(category, NULL, NULL, NULL, 0, source); |
| 185 | } |
| 186 | |
| 187 | if (value != NULL) { |
| 188 | sprintf(buffer, "%s=%s\r\n", key, value); |
| 189 | memmove(s + strlen(buffer), s, strlen(s) + 1); |
| 190 | memcpy(s, buffer, strlen(buffer)); |
| 191 | } |
| 192 | } |
no test coverage detected