#saveoptions - save config options into file */
| 166 | |
| 167 | /* #saveoptions - save config options into file */ |
| 168 | int |
| 169 | do_write_config_file(void) |
| 170 | { |
| 171 | FILE *fp; |
| 172 | char tmp[BUFSZ]; |
| 173 | |
| 174 | if (!configfile[0]) { |
| 175 | pline("Strange, could not figure out config file name."); |
| 176 | return ECMD_OK; |
| 177 | } |
| 178 | if (flags.suppress_alert < FEATURE_NOTICE_VER(3,7,0)) { |
| 179 | pline("Warning: saveoptions is highly experimental!"); |
| 180 | wait_synch(); |
| 181 | pline("Some settings are not saved!"); |
| 182 | wait_synch(); |
| 183 | pline("All manual customization and comments are removed" |
| 184 | " from the file!"); |
| 185 | wait_synch(); |
| 186 | } |
| 187 | #define overwrite_prompt "Overwrite config file %.*s?" |
| 188 | Sprintf(tmp, overwrite_prompt, |
| 189 | (int) (BUFSZ - sizeof overwrite_prompt - 2), configfile); |
| 190 | #undef overwrite_prompt |
| 191 | if (!paranoid_query(TRUE, tmp)) |
| 192 | return ECMD_OK; |
| 193 | |
| 194 | fp = fopen(configfile, "w"); |
| 195 | if (fp) { |
| 196 | size_t len, wrote; |
| 197 | strbuf_t buf; |
| 198 | |
| 199 | strbuf_init(&buf); |
| 200 | all_options_strbuf(&buf); |
| 201 | len = strlen(buf.str); |
| 202 | wrote = fwrite(buf.str, 1, len, fp); |
| 203 | fclose(fp); |
| 204 | strbuf_empty(&buf); |
| 205 | if (wrote != len) |
| 206 | pline("An error occurred, wrote only partial data (%zu/%zu).", |
| 207 | wrote, len); |
| 208 | } |
| 209 | return ECMD_OK; |
| 210 | } |
| 211 | #endif /* SFCTOOL */ |
| 212 | |
| 213 | /* remember the name of the file we're accessing; |
nothing calls this directly
no test coverage detected