remove debug fprintf
[nedit-bw.git] / fsync.patch
blob50a34ab3547da6500363ea258e5219ec3c47d8d3
1 Cc: John Karp <johnkarp@gmail.com>
2 Subject: [PATCH 2/2] Use fsync.
4 POSIX guarantees only a successfully save after a successful call to fsync.
5 So do this.
7 See SF Bug#2686300: http://sourceforge.net/tracker/?func=detail&aid=2686300&group_id=11005&atid=111005
9 Regards,
10 Bert
12 ---
14 source/file.c | 44 +++++++++++++++++++++++++++++++++++++++++---
15 util/prefFile.c | 2 ++
16 2 files changed, 43 insertions(+), 3 deletions(-)
18 diff --quilt old/source/file.c new/source/file.c
19 --- old/source/file.c
20 +++ new/source/file.c
21 @@ -1029,7 +1029,17 @@ static int doSave(WindowInfo *window)
22 #else
23 fwrite(fileString, sizeof(char), fileLen, fp);
24 ret = ferror(fp);
25 + if (0 == ret)
26 + {
27 + /* first, flush all stream buffers to the filesystem */
28 + ret = fflush(fp);
29 + }
30 #endif
31 + if (0 == ret)
32 + {
33 + /* second, synchronize filedata to disk */
34 + ret = fsync(fileno(fp));
35 + }
36 if (0 != ret)
38 DialogF(DF_ERR, window->shell, 1, "Error saving File",
39 @@ -1143,7 +1153,17 @@ int WriteBackupFile(WindowInfo *window)
40 #else
41 fwrite(fileString, sizeof(char), fileLen, fp);
42 ret = ferror(fp);
43 + if (0 == ret)
44 + {
45 + /* first, flush all stream buffers to the filesystem */
46 + ret = fflush(fp);
47 + }
48 #endif
49 + if (0 == ret)
50 + {
51 + /* second, synchronize filedata to disk */
52 + ret = fsync(fileno(fp));
53 + }
54 if (0 != ret)
56 DialogF(DF_ERR, window->shell, 1, "Error saving Backup",
57 @@ -1308,11 +1328,19 @@ static int writeBckVersion(WindowInfo *w
61 - /* close the input and output files */
62 + free(io_buffer);
64 + /* close the input file */
65 close(in_fd);
66 - close(out_fd);
68 - free(io_buffer);
69 + /* sync and close the output file */
70 + if (fdatasync(out_fd))
71 + {
72 + int ret = bckError(window, errorString(), bckname);
73 + close(out_fd);
74 + return ret;
75 + }
76 + close(out_fd);
78 #endif /* VMS */
80 @@ -1425,7 +1453,17 @@ void PrintString(const char *string, int
81 #else
82 fwrite(string, sizeof(char), length, fp);
83 ret = ferror(fp);
84 + if (0 == ret)
85 + {
86 + /* first, flush all stream buffers to the filesystem */
87 + ret = fflush(fp);
88 + }
89 #endif
90 + if (0 == ret)
91 + {
92 + /* second, synchronize filedata to disk */
93 + ret = fsync(fileno(fp));
94 + }
95 if (0 != ret)
97 DialogF(DF_ERR, parent, 1, "Error while Printing",
98 diff --quilt old/util/prefFile.c new/util/prefFile.c
99 --- old/util/prefFile.c
100 +++ new/util/prefFile.c
101 @@ -297,6 +297,8 @@ int SavePreferences(Display *display, co
102 fprintf(fp, "\n");
105 + fflush(fp);
106 + fsync(fileno(fp));
107 fclose(fp);
108 return True;