diff options
Diffstat (limited to 'applets/applet_tables.c')
-rw-r--r-- | applets/applet_tables.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/applets/applet_tables.c b/applets/applet_tables.c index 858429ac2..b997194ad 100644 --- a/applets/applet_tables.c +++ b/applets/applet_tables.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <sys/types.h> | 10 | #include <sys/types.h> |
11 | #include <sys/stat.h> | 11 | #include <sys/stat.h> |
12 | #include <fcntl.h> | 12 | #include <fcntl.h> |
13 | #include <limits.h> | ||
13 | #include <stdlib.h> | 14 | #include <stdlib.h> |
14 | #include <string.h> | 15 | #include <string.h> |
15 | #include <stdio.h> | 16 | #include <stdio.h> |
@@ -62,6 +63,7 @@ int main(int argc, char **argv) | |||
62 | { | 63 | { |
63 | int i, j; | 64 | int i, j; |
64 | unsigned MAX_APPLET_NAME_LEN = 1; | 65 | unsigned MAX_APPLET_NAME_LEN = 1; |
66 | char tmp1[PATH_MAX], tmp2[PATH_MAX]; | ||
65 | 67 | ||
66 | // In find_applet_by_name(), before linear search, narrow it down | 68 | // In find_applet_by_name(), before linear search, narrow it down |
67 | // by looking at N "equidistant" names. With ~350 applets: | 69 | // by looking at N "equidistant" names. With ~350 applets: |
@@ -85,7 +87,8 @@ int main(int argc, char **argv) | |||
85 | 87 | ||
86 | if (!argv[1]) | 88 | if (!argv[1]) |
87 | return 1; | 89 | return 1; |
88 | i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666); | 90 | snprintf(tmp1, PATH_MAX, "%s.%u.new", argv[1], (int) getpid()); |
91 | i = open(tmp1, O_WRONLY | O_TRUNC | O_CREAT, 0666); | ||
89 | if (i < 0) | 92 | if (i < 0) |
90 | return 1; | 93 | return 1; |
91 | dup2(i, 1); | 94 | dup2(i, 1); |
@@ -210,12 +213,21 @@ int main(int argc, char **argv) | |||
210 | // fclose(fp); | 213 | // fclose(fp); |
211 | // } | 214 | // } |
212 | // if (strcmp(line_old, line_new) != 0) { | 215 | // if (strcmp(line_old, line_new) != 0) { |
213 | fp = fopen(argv[2], "w"); | 216 | snprintf(tmp2, PATH_MAX, "%s.%u.new", argv[2], (int) getpid()); |
217 | fp = fopen(tmp2, "w"); | ||
214 | if (!fp) | 218 | if (!fp) |
215 | return 1; | 219 | return 1; |
216 | fputs(line_new, fp); | 220 | fputs(line_new, fp); |
221 | if (fclose(fp)) | ||
222 | return 1; | ||
217 | // } | 223 | // } |
218 | } | 224 | } |
219 | 225 | ||
226 | if (fclose(stdout)) | ||
227 | return 1; | ||
228 | if (rename(tmp1, argv[1])) | ||
229 | return 1; | ||
230 | if (rename(tmp2, argv[2])) | ||
231 | return 1; | ||
220 | return 0; | 232 | return 0; |
221 | } | 233 | } |