| 912 | } |
| 913 | |
| 914 | int conf_write(const char *name) |
| 915 | { |
| 916 | FILE *out; |
| 917 | struct symbol *sym; |
| 918 | struct menu *menu; |
| 919 | const char *str; |
| 920 | char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; |
| 921 | char *env; |
| 922 | int i; |
| 923 | bool need_newline = false; |
| 924 | |
| 925 | if (!name) |
| 926 | name = conf_get_configname(); |
| 927 | |
| 928 | if (!*name) { |
| 929 | fprintf(stderr, "config name is empty\n"); |
| 930 | return -1; |
| 931 | } |
| 932 | |
| 933 | if (is_dir(name)) { |
| 934 | fprintf(stderr, "%s: Is a directory\n", name); |
| 935 | return -1; |
| 936 | } |
| 937 | |
| 938 | if (make_parent_dir(name)) |
| 939 | return -1; |
| 940 | |
| 941 | env = getenv("KCONFIG_OVERWRITECONFIG"); |
| 942 | if (env && *env) { |
| 943 | *tmpname = 0; |
| 944 | out = fopen(name, "w"); |
| 945 | } else { |
| 946 | snprintf(tmpname, sizeof(tmpname), "%s.%d.tmp", |
| 947 | name, (int)getpid()); |
| 948 | out = fopen(tmpname, "w"); |
| 949 | } |
| 950 | if (!out) |
| 951 | return 1; |
| 952 | |
| 953 | conf_write_heading(out, &comment_style_pound); |
| 954 | |
| 955 | if (!conf_get_changed()) |
| 956 | sym_clear_all_valid(); |
| 957 | |
| 958 | menu = rootmenu.list; |
| 959 | while (menu) { |
| 960 | sym = menu->sym; |
| 961 | if (!sym) { |
| 962 | if (!menu_is_visible(menu)) |
| 963 | goto next; |
| 964 | str = menu_get_prompt(menu); |
| 965 | fprintf(out, "\n" |
| 966 | "#\n" |
| 967 | "# %s\n" |
| 968 | "#\n", str); |
| 969 | need_newline = false; |
| 970 | } else if (!(sym->flags & SYMBOL_CHOICE) && |
| 971 | !(sym->flags & SYMBOL_WRITTEN)) { |
no test coverage detected