| 1182 | } |
| 1183 | |
| 1184 | static int __conf_write_autoconf(const char *filename, |
| 1185 | void (*print_symbol)(FILE *, struct symbol *), |
| 1186 | const struct comment_style *comment_style) |
| 1187 | { |
| 1188 | char tmp[PATH_MAX]; |
| 1189 | FILE *file; |
| 1190 | struct symbol *sym; |
| 1191 | int ret, i; |
| 1192 | |
| 1193 | if (make_parent_dir(filename)) |
| 1194 | return -1; |
| 1195 | |
| 1196 | ret = snprintf(tmp, sizeof(tmp), "%s.tmp", filename); |
| 1197 | if (ret >= sizeof(tmp)) /* check truncation */ |
| 1198 | return -1; |
| 1199 | |
| 1200 | file = fopen(tmp, "w"); |
| 1201 | if (!file) { |
| 1202 | perror("fopen"); |
| 1203 | return -1; |
| 1204 | } |
| 1205 | |
| 1206 | conf_write_heading(file, comment_style); |
| 1207 | |
| 1208 | int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL; |
| 1209 | for_all_symbols(i, sym) |
| 1210 | if (((sym->flags & SYMBOL_WRITE) || (print_negatives && sym->type != S_STRING)) && sym->name) |
| 1211 | print_symbol(file, sym); |
| 1212 | |
| 1213 | fflush(file); |
| 1214 | /* check possible errors in conf_write_heading() and print_symbol() */ |
| 1215 | ret = ferror(file); |
| 1216 | fclose(file); |
| 1217 | if (ret) |
| 1218 | return -1; |
| 1219 | |
| 1220 | if (rename(tmp, filename)) { |
| 1221 | perror("rename"); |
| 1222 | return -1; |
| 1223 | } |
| 1224 | |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
| 1228 | int conf_write_autoconf(int overwrite) |
| 1229 | { |
no test coverage detected