| 940 | } |
| 941 | |
| 942 | int conf_write(const char *name) |
| 943 | { |
| 944 | FILE *out; |
| 945 | struct symbol *sym; |
| 946 | struct menu *menu; |
| 947 | const char *str; |
| 948 | char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; |
| 949 | char *env; |
| 950 | int i; |
| 951 | bool need_newline = false; |
| 952 | |
| 953 | if (!name) |
| 954 | name = conf_get_configname(); |
| 955 | |
| 956 | if (!*name) { |
| 957 | fprintf(stderr, "config name is empty\n"); |
| 958 | return -1; |
| 959 | } |
| 960 | |
| 961 | if (is_dir(name)) { |
| 962 | fprintf(stderr, "%s: Is a directory\n", name); |
| 963 | return -1; |
| 964 | } |
| 965 | |
| 966 | if (make_parent_dir(name)) |
| 967 | return -1; |
| 968 | |
| 969 | env = getenv("KCONFIG_OVERWRITECONFIG"); |
| 970 | if (env && *env) { |
| 971 | *tmpname = 0; |
| 972 | out = fopen(name, "w"); |
| 973 | } else { |
| 974 | snprintf(tmpname, sizeof(tmpname), "%s.%d.tmp", |
| 975 | name, (int)getpid()); |
| 976 | out = fopen(tmpname, "w"); |
| 977 | } |
| 978 | if (!out) |
| 979 | return 1; |
| 980 | |
| 981 | conf_write_heading(out, &comment_style_pound); |
| 982 | |
| 983 | if (!conf_get_changed()) |
| 984 | sym_clear_all_valid(); |
| 985 | |
| 986 | menu = rootmenu.list; |
| 987 | while (menu) { |
| 988 | sym = menu->sym; |
| 989 | if (!sym) { |
| 990 | if (!menu_is_visible(menu)) |
| 991 | goto next; |
| 992 | str = menu_get_prompt(menu); |
| 993 | fprintf(out, "\n" |
| 994 | "#\n" |
| 995 | "# %s\n" |
| 996 | "#\n", str); |
| 997 | need_newline = false; |
| 998 | } else if (!(sym->flags & SYMBOL_CHOICE) && |
| 999 | !(sym->flags & SYMBOL_WRITTEN)) { |
no test coverage detected