summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-01-23 21:49:28 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-01-23 21:49:28 +0000
commit1c5905c271fdf62f5d6be00662751c5ebeee6dba (patch)
tree3bdb56b5a0c17f9bdcc1eee13cb1c29e30e15b53
parent64aac5a92f5a6e49b46f320202aef13277e3640b (diff)
downloadperl-1c5905c271fdf62f5d6be00662751c5ebeee6dba.tar.gz
on windows, set seek position to end for files opened in append mode
(improves compatibility with Unix, avoids buffering issues) p4raw-id: //depot/perl@4868
-rw-r--r--win32/win32.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 78955fc046..710a047cd2 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2049,6 +2049,7 @@ win32_fopen(const char *filename, const char *mode)
{
dTHXo;
WCHAR wMode[MODE_SIZE], wBuffer[MAX_PATH];
+ FILE *f;
if (!*filename)
return NULL;
@@ -2059,9 +2060,14 @@ win32_fopen(const char *filename, const char *mode)
if (USING_WIDE()) {
A2WHELPER(mode, wMode, sizeof(wMode));
A2WHELPER(filename, wBuffer, sizeof(wBuffer));
- return _wfopen(PerlDir_mapW(wBuffer), wMode);
+ f = _wfopen(PerlDir_mapW(wBuffer), wMode);
}
- return fopen(PerlDir_mapA(filename), mode);
+ else
+ f = fopen(PerlDir_mapA(filename), mode);
+ /* avoid buffering headaches for child processes */
+ if (f && *mode == 'a')
+ win32_fseek(f, 0, SEEK_END);
+ return f;
}
#ifndef USE_SOCKETS_AS_HANDLES
@@ -2074,11 +2080,17 @@ win32_fdopen(int handle, const char *mode)
{
dTHXo;
WCHAR wMode[MODE_SIZE];
+ FILE *f;
if (USING_WIDE()) {
A2WHELPER(mode, wMode, sizeof(wMode));
- return _wfdopen(handle, wMode);
+ f = _wfdopen(handle, wMode);
}
- return fdopen(handle, (char *) mode);
+ else
+ f = fdopen(handle, (char *) mode);
+ /* avoid buffering headaches for child processes */
+ if (f && *mode == 'a')
+ win32_fseek(f, 0, SEEK_END);
+ return f;
}
DllExport FILE *