This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 1.5.25-6: Win32 programs don't get correct >> redirection

Hash: SHA1

According to Jack Brennen on 12/13/2007 6:34 PM:
> sh-3.2$ echo ABCDEFGHIJKLMNOPQRST > foo.txt
> sh-3.2$ cmd /c echo UVWXYZ >> foo.txt
> sh-3.2$ cat foo.txt

This issue was discussed on the lists in May:

Cygwin 1.5.24 was incorrectly positioning fd's opened in append mode to
the last byte just before exec'ing a child process, rather than leaving
the position untouched (note that POSIX requires
open(O_RDWR|O_APPEND)/lseek to always be at position 0, but
fopen("a+")/ftell can be either 0 [as on Linux] or the end of the file [as
on BSD] - cygwin currently uses the Linux approach).

But it looks like this means that Windows programs are too stupid to
realize that they are being handed a file opened in append mode, and
blindly write to the current position, which happens to be the beginning
of the file instead of the end.

Maybe it is worth teaching cygwin's exec code that fd's in append mode
must be repositioned to the end if the child about to be spawned is a
non-cygwin program?  But how reliable is cygwin's detection of whether the
child is a cygwin process, so that we aren't violating POSIX by mistakenly
repositioning the fd when the child is a cygwin process?  Or do we make it
even more complicated, by having the pre-exec code always reposition, but
remember where it was beforehand, then cygwin children use that knowledge
to position back to the correct location?

- --
Don't work too hard, make some time for fun as well!

Eric Blake   
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at
Comment: Using GnuPG with Mozilla -


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]