Re: freopen/fread/popen bug

2015-02-27 Thread Achim Gratz
Eric Blake writes: >> What's really happening is that we need to peek at the first few bytes >> of f before deciding which program to call in popen. After peeking, >> there's a call to fseek(f,0,0) before the popen, with the intention that >> the child receives a file pointer set to the beginning

Re: freopen/fread/popen bug

2015-02-27 Thread A L
> Thanks (and thanks to Corinna and Eric) for correcting my misconceptions. You're welcome. I only wanted to follow up that (I don't know what the heck happened to my head, but) when I was referring to file descriptors, I was consistently and mistakenly using "1" where "0" should have been used:

Re: freopen/fread/popen bug

2015-02-27 Thread Ken Brown
On 2/27/2015 11:20 AM, A L wrote: I think that would create an unacceptable performance penalty for the child process. The child process would not be affected at all! FILE* will be unbuffered only in your application, yet "cat" will read from a file descriptor "1" (and may or may not apply an

Re: freopen/fread/popen bug

2015-02-27 Thread A L
> I think that would create an unacceptable performance penalty for the child > process. The child process would not be affected at all! FILE* will be unbuffered only in your application, yet "cat" will read from a file descriptor "1" (and may or may not apply any buffering on top of it, such as

Re: freopen/fread/popen bug

2015-02-27 Thread Eric Blake
On 02/27/2015 05:40 AM, Ken Brown wrote: >> Wrong expectations. Keep in mind that the default read mode using >> stdio functions is buffered. So your fread fills the buffer in f. >> The buffer is typically something like 1K or 4K. If the file is >> shorter than that, the file pointer will be set

Re: freopen/fread/popen bug

2015-02-27 Thread Corinna Vinschen
On Feb 27 07:40, Ken Brown wrote: > On 2/27/2015 3:43 AM, Corinna Vinschen wrote: > >On Feb 26 22:05, Ken Brown wrote: > >>I'm not sure exactly where the bug is, but here's what happens (STC at the > >>end): > >> > >>1. I use freopen to open a file "foo" and associate it with stdin. > >> > >>2. I

Re: freopen/fread/popen bug

2015-02-27 Thread Ken Brown
On 2/27/2015 3:43 AM, Corinna Vinschen wrote: On Feb 26 22:05, Ken Brown wrote: I'm not sure exactly where the bug is, but here's what happens (STC at the end): 1. I use freopen to open a file "foo" and associate it with stdin. 2. I use fread to read a byte from foo. 3. I call popen, expectin

Re: freopen/fread/popen bug

2015-02-27 Thread Corinna Vinschen
On Feb 26 22:05, Ken Brown wrote: > I'm not sure exactly where the bug is, but here's what happens (STC at the > end): > > 1. I use freopen to open a file "foo" and associate it with stdin. > > 2. I use fread to read a byte from foo. > > 3. I call popen, expecting the child process to have foo

freopen/fread/popen bug

2015-02-26 Thread Ken Brown
I'm not sure exactly where the bug is, but here's what happens (STC at the end): 1. I use freopen to open a file "foo" and associate it with stdin. 2. I use fread to read a byte from foo. 3. I call popen, expecting the child process to have foo as its stdin, with the file-position indicator po

Re: popen bug [patch]

2006-08-22 Thread Jeff Johnston
Patch checked in. Thanks. -- Jeff J. Eric Blake wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Cygwin popen does not match Linux popen when stdout is closed. ... Oops - when stdout is closed, and the pipe is output on child, cygwin popen mistakenly lost the pipe in both processes.

Re: popen bug [patch]

2006-08-22 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > Cygwin popen does not match Linux popen when stdout is closed. ... > Oops - when stdout is closed, and the pipe is output on child, cygwin > popen mistakenly lost the pipe in both processes. > > > The real world case that found this: > cygwin$ echo '

popen bug

2006-08-18 Thread Eric Blake
Cygwin popen does not match Linux popen when stdout is closed. In cygwin window 1: $ cat foo.c #include #include int main() { FILE *f; f = popen("sleep 30", "r"); if (!f) return 1; getc(f); if (pclose(f)) return 2; return 0; } $ ./foo >&- In cygwin window 2, durin