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
11 source/file.c | 30 ++++++++++++++++++++++++------
12 1 file changed, 24 insertions(+), 6 deletions(-)
14 diff --quilt old/source/file.c new/source/file.c
17 @@ -932,6 +932,7 @@ static int doSave(WindowInfo *window)
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 */
31 - write(fileno(fp), fileString, fileLen);
32 + if (0 > write(fileno(fp), fileString, fileLen))
37 fwrite(fileString, sizeof(char), fileLen, fp);
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];
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 */
59 - write(fileno(fp), fileString, fileLen);
60 + if (0 > write(fileno(fp), fileString, fileLen))
65 fwrite(fileString, sizeof(char), fileLen, fp);
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 */
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
84 /* write to the file */
87 - write(fileno(fp), string, length);
88 + if (0 > write(fileno(fp), string, length))
93 fwrite(string, sizeof(char), length, fp);
99 DialogF(DF_ERR, parent, 1, "Error while Printing",
100 "%s not printed:\n%s", "OK", jobName, errorString());