summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn van Groningen2006-03-23 11:36:44 +0000
committerJohn van Groningen2006-03-23 11:36:44 +0000
commita1e41900441b79275649e1034e958e74bf1ff7db (patch)
treea33728464f9d7c61c53a08aca7e1fccd58362492
parentremove some duplicate code (diff)
change file mode if stdio is reopened
-rw-r--r--wfileIO3.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/wfileIO3.c b/wfileIO3.c
index 36958da..d929380 100644
--- a/wfileIO3.c
+++ b/wfileIO3.c
@@ -450,6 +450,15 @@ static OS(DWORD,ULONG) file_action_reopen[] ={
#endif
};
+static int clear_masks_for_stdio_reopen[6]={
+ ~ (1<<F_READ_DATA), /* F_READ_TEXT */
+ ~ ((1<<F_WRITE_DATA) | (1<<F_APPEND_DATA)), /* F_WRITE_TEXT */
+ ~ ((1<<F_WRITE_DATA) | (1<<F_APPEND_DATA)), /* F_APPEND_TEXT */
+ ~ (1<<F_READ_TEXT), /* F_READ_DATA */
+ ~ ((1<<F_WRITE_TEXT) | (1<<F_APPEND_TEXT)), /* F_WRITE_DATA */
+ ~ ((1<<F_WRITE_TEXT) | (1<<F_APPEND_TEXT)) /* F_APPEND_DATA */
+};
+
CLEAN_BOOL re_open_file (struct file *f,unsigned int file_mode)
{
if (file_mode>5)
@@ -460,6 +469,14 @@ CLEAN_BOOL re_open_file (struct file *f,unsigned int file_mode)
IO_error ("freopen: stderr can't be opened for reading");
if (f==&file_table[2])
IO_error ("freopen: file not open");
+ if (f==&file_table[1]){
+ int m;
+
+ m=file_table[1].file_mode;
+ m &= clear_masks_for_stdio_reopen[file_mode];
+ m |= 1<<file_mode;
+ file_table[1].file_mode=m;
+ }
return CLEAN_TRUE;
} else {
long file_length;