| 1154 | } |
| 1155 | |
| 1156 | static int __conf_write_autoconf(const char *filename, |
| 1157 | void (*print_symbol)(FILE *, struct symbol *), |
| 1158 | const struct comment_style *comment_style) |
| 1159 | { |
| 1160 | char tmp[PATH_MAX]; |
| 1161 | FILE *file; |
| 1162 | struct symbol *sym; |
| 1163 | int ret, i; |
| 1164 | |
| 1165 | if (make_parent_dir(filename)) |
| 1166 | return -1; |
| 1167 | |
| 1168 | ret = snprintf(tmp, sizeof(tmp), "%s.tmp", filename); |
| 1169 | if (ret >= sizeof(tmp)) /* check truncation */ |
| 1170 | return -1; |
| 1171 | |
| 1172 | file = fopen(tmp, "w"); |
| 1173 | if (!file) { |
| 1174 | perror("fopen"); |
| 1175 | return -1; |
| 1176 | } |
| 1177 | |
| 1178 | conf_write_heading(file, comment_style); |
| 1179 | |
| 1180 | for_all_symbols(i, sym) |
| 1181 | if ((sym->flags & SYMBOL_WRITE) && sym->name) |
| 1182 | print_symbol(file, sym); |
| 1183 | |
| 1184 | fflush(file); |
| 1185 | /* check possible errors in conf_write_heading() and print_symbol() */ |
| 1186 | ret = ferror(file); |
| 1187 | fclose(file); |
| 1188 | if (ret) |
| 1189 | return -1; |
| 1190 | |
| 1191 | if (rename(tmp, filename)) { |
| 1192 | perror("rename"); |
| 1193 | return -1; |
| 1194 | } |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | int conf_write_autoconf(int overwrite) |
| 1200 | { |
no test coverage detected