msvcrt: Fix initial position for files opened with O_APPEND flag [Bug:1899]

Vitaliy Margolen wine-patch at kievinfo.com
Thu Oct 6 23:50:32 CDT 2005


There is no need to seek to the end on open. It will be done inside write
(file.c:1991). Test shows that this is a correct behavior.

Vitaliy Margolen

changelog:
  msvcrt:
  - Fix initial position for files opened with O_APPEND flag
-------------- next part --------------
Index: dlls/msvcrt/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/file.c,v
retrieving revision 1.90
diff -u -p -r1.90 file.c
--- dlls/msvcrt/file.c	26 Sep 2005 09:54:47 -0000	1.90
+++ dlls/msvcrt/file.c	7 Oct 2005 04:46:22 -0000
@@ -1480,13 +1480,6 @@ int MSVCRT__sopen( const char *path, int
   fd = msvcrt_alloc_fd(hand, wxflag);
 
   TRACE(":fd (%d) handle (%p)\n",fd, hand);
-
-  if (fd > 0)
-  {
-    if (oflags & MSVCRT__O_APPEND)
-      _lseek(fd, 0, FILE_END);
-  }
-
   return fd;
 }
 
Index: dlls/msvcrt/tests/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/tests/file.c,v
retrieving revision 1.16
diff -u -p -r1.16 file.c
--- dlls/msvcrt/tests/file.c	25 Jun 2005 17:58:19 -0000	1.16
+++ dlls/msvcrt/tests/file.c	7 Oct 2005 04:46:22 -0000
@@ -242,6 +242,14 @@ static void test_file_write_read( void )
   ok( memcmp(mytext,btext,strlen(mytext)) == 0,
       "problems with _O_TEXT _write / _read\n");
   _close(tempfd);
+
+  memset(btext, 0, LLEN);
+  tempfd = _open(tempf,_O_APPEND|_O_RDWR); /* open for APPEND in default mode */
+  ok(tell(tempfd) == 0, "bad position %lu expecting 0\n", tell(tempfd));
+  ok(_read(tempfd,btext,LLEN) == lstrlenA(mytext), "_read _O_APPEND got bad length\n");
+  ok( memcmp(mytext,btext,strlen(mytext)) == 0, "problems with _O_APPEND _read\n");
+  _close(tempfd);
+
   ret = unlink(tempf);
   ok( ret !=-1 ,"Can't unlink '%s': %d\n", tempf, errno);
 


More information about the wine-patches mailing list