diff options
| -rw-r--r-- | scripts/kconfig/confdata.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 9fd6430c93d2..399973e35533 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> | 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include <sys/mman.h> | ||
| 6 | #include <sys/stat.h> | 7 | #include <sys/stat.h> |
| 7 | #include <ctype.h> | 8 | #include <ctype.h> |
| 8 | #include <errno.h> | 9 | #include <errno.h> |
| @@ -36,6 +37,52 @@ static bool is_dir(const char *path) | |||
| 36 | return S_ISDIR(st.st_mode); | 37 | return S_ISDIR(st.st_mode); |
| 37 | } | 38 | } |
| 38 | 39 | ||
| 40 | /* return true if the given two files are the same, false otherwise */ | ||
| 41 | static bool is_same(const char *file1, const char *file2) | ||
| 42 | { | ||
| 43 | int fd1, fd2; | ||
| 44 | struct stat st1, st2; | ||
| 45 | void *map1, *map2; | ||
| 46 | bool ret = false; | ||
| 47 | |||
| 48 | fd1 = open(file1, O_RDONLY); | ||
| 49 | if (fd1 < 0) | ||
| 50 | return ret; | ||
| 51 | |||
| 52 | fd2 = open(file2, O_RDONLY); | ||
| 53 | if (fd2 < 0) | ||
| 54 | goto close1; | ||
| 55 | |||
| 56 | ret = fstat(fd1, &st1); | ||
| 57 | if (ret) | ||
| 58 | goto close2; | ||
| 59 | ret = fstat(fd2, &st2); | ||
| 60 | if (ret) | ||
| 61 | goto close2; | ||
| 62 | |||
| 63 | if (st1.st_size != st2.st_size) | ||
| 64 | goto close2; | ||
| 65 | |||
| 66 | map1 = mmap(NULL, st1.st_size, PROT_READ, MAP_PRIVATE, fd1, 0); | ||
| 67 | if (map1 == MAP_FAILED) | ||
| 68 | goto close2; | ||
| 69 | |||
| 70 | map2 = mmap(NULL, st2.st_size, PROT_READ, MAP_PRIVATE, fd2, 0); | ||
| 71 | if (map2 == MAP_FAILED) | ||
| 72 | goto close2; | ||
| 73 | |||
| 74 | if (bcmp(map1, map2, st1.st_size)) | ||
| 75 | goto close2; | ||
| 76 | |||
| 77 | ret = true; | ||
| 78 | close2: | ||
| 79 | close(fd2); | ||
| 80 | close1: | ||
| 81 | close(fd1); | ||
| 82 | |||
| 83 | return ret; | ||
| 84 | } | ||
| 85 | |||
| 39 | /* | 86 | /* |
| 40 | * Create the parent directory of the given path. | 87 | * Create the parent directory of the given path. |
| 41 | * | 88 | * |
| @@ -888,6 +935,13 @@ next: | |||
| 888 | fclose(out); | 935 | fclose(out); |
| 889 | 936 | ||
| 890 | if (*tmpname) { | 937 | if (*tmpname) { |
| 938 | if (is_same(name, tmpname)) { | ||
| 939 | conf_message("No change to %s", name); | ||
| 940 | unlink(tmpname); | ||
| 941 | sym_set_change_count(0); | ||
| 942 | return 0; | ||
| 943 | } | ||
| 944 | |||
| 891 | snprintf(oldname, sizeof(oldname), "%s.old", name); | 945 | snprintf(oldname, sizeof(oldname), "%s.old", name); |
| 892 | rename(name, oldname); | 946 | rename(name, oldname); |
| 893 | if (rename(tmpname, name)) | 947 | if (rename(tmpname, name)) |
