MCPcopy Create free account
hub / github.com/NetHack/NetHack / do_write_config_file

Function do_write_config_file

src/cfgfiles.c:168–210  ·  view source on GitHub ↗

#saveoptions - save config options into file */

Source from the content-addressed store, hash-verified

166
167/* #saveoptions - save config options into file */
168int
169do_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;

Callers

nothing calls this directly

Calls 8

wait_synchFunction · 0.85
paranoid_queryFunction · 0.85
strbuf_initFunction · 0.85
all_options_strbufFunction · 0.85
fwriteFunction · 0.85
fcloseFunction · 0.85
strbuf_emptyFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected