re-fresh
[nedit-bw.git] / fix-error-case-in-IBM_FWRITE_BUG.patch
blob0482106ab434d7e98228491611cc2657d264806f
1 Subject: [PATCH 1/2] IBM_FWRITE_BUG: fix error detection
3 If you use write(fileno(fp), ...) you can't expect, that ferror(fp) is
4 meaningful.
6 Regards,
7 Bert
9 ---
11 source/file.c | 30 ++++++++++++++++++++++++------
12 1 file changed, 24 insertions(+), 6 deletions(-)
14 diff --quilt old/source/file.c new/source/file.c
15 --- old/source/file.c
16 +++ new/source/file.c
17 @@ -932,6 +932,7 @@ static int doSave(WindowInfo *window)
18 struct stat statbuf;
19 FILE *fp;
20 int fileLen, result;
21 + int ret;
23 /* Get the full name of the file */
24 strcpy(fullname, window->path);
25 @@ -1019,12 +1020,17 @@ static int doSave(WindowInfo *window)
28 /* write to the file */
29 + ret = 0;
30 #ifdef IBM_FWRITE_BUG
31 - write(fileno(fp), fileString, fileLen);
32 + if (0 > write(fileno(fp), fileString, fileLen))
33 + {
34 + ret = 1;
35 + }
36 #else
37 fwrite(fileString, sizeof(char), fileLen, fp);
38 + ret = ferror(fp);
39 #endif
40 - if (ferror(fp))
41 + if (0 != ret)
43 DialogF(DF_ERR, window->shell, 1, "Error saving File",
44 "%s not saved:\n%s", "OK", window->filename, errorString());
45 @@ -1083,6 +1089,7 @@ int WriteBackupFile(WindowInfo *window)
46 char name[MAXPATHLEN];
47 FILE *fp;
48 int fd, fileLen;
49 + int ret;
51 /* Generate a name for the autoSave file */
52 backupFileName(window, name, sizeof(name));
53 @@ -1127,12 +1134,17 @@ int WriteBackupFile(WindowInfo *window)
54 fileString[fileLen++] = '\n'; /* null terminator no longer needed */
56 /* write out the file */
57 + ret = 0;
58 #ifdef IBM_FWRITE_BUG
59 - write(fileno(fp), fileString, fileLen);
60 + if (0 > write(fileno(fp), fileString, fileLen))
61 + {
62 + ret = 1;
63 + }
64 #else
65 fwrite(fileString, sizeof(char), fileLen, fp);
66 + ret = ferror(fp);
67 #endif
68 - if (ferror(fp))
69 + if (0 != ret)
71 DialogF(DF_ERR, window->shell, 1, "Error saving Backup",
72 "Error while saving backup for %s:\n%s\n"
73 @@ -1375,6 +1387,7 @@ void PrintString(const char *string, int
74 char tmpFileName[L_tmpnam]; /* L_tmpnam defined in stdio.h */
75 FILE *fp;
76 int fd;
77 + int ret;
79 /* Generate a temporary file name */
80 /* If the glibc is used, the linker issues a warning at this point. This is
81 @@ -1403,12 +1416,17 @@ void PrintString(const char *string, int
82 #endif
84 /* write to the file */
85 + ret = 0;
86 #ifdef IBM_FWRITE_BUG
87 - write(fileno(fp), string, length);
88 + if (0 > write(fileno(fp), string, length))
89 + {
90 + ret = 1;
91 + }
92 #else
93 fwrite(string, sizeof(char), length, fp);
94 + ret = ferror(fp);
95 #endif
96 - if (ferror(fp))
97 + if (0 != ret)
99 DialogF(DF_ERR, parent, 1, "Error while Printing",
100 "%s not printed:\n%s", "OK", jobName, errorString());