On dimanche 12 octobre 2008, Kari Laine wrote:
> On Sun, Oct 12, 2008 at 4:31 PM, Benoit Minisini <
>
> [EMAIL PROTECTED]> wrote:
> > On dimanche 12 octobre 2008, Doriano Blengino wrote:
> > > Tell me what your tests say to you - this is very interesting because I
> > > did not try if that book was true or not.
> >
> > Strange behaviours.
> >
> > If I replace INPUT OUTPUT by READ WRITE, the process does not write to
> > its standard output anymore.
> >
> > But if I replace the "tr" program by "cat", then READ WRITE works as
> > expected.
> >
> > So there is something different in "tr" that prevents him to work with
> > the READ WRITE options.
> >
> > Moreover, sometimes the first write to the "tr" process fails (with a bad
> > file
> > descriptor error message).
> >
> > All that needs some investigation...
> >
> > To test whether either WRITE or OUTPUT works without READ or INPUT I made
> > a
>
> little filter which stores it input to output file.
> Here is the filter
> -------
> #include <stdio.h>
>
> int main()
> {
> int character;
> int lask;
> FILE *nHandle;
>
> printf("program started\n");
> nHandle=fopen("/home/kari/output.txt","w");
>
> character = getc(stdin);
>
>
>         while(character != EOF)
>         {
>         //printf("%d",character);
>         fputc(character,nHandle);

--> adds 'fflush(stdout);' there.

>         character = getc(stdin);
>         }
>
> close(nHandle);
>
> }
> -------------------------

FILE, stdin and stdout are buffered streams managed by the C library on top of 
the read()/write() system calls.

If you don't use fflush(), then Gambas will not see anything until:
- A newline is written, in most cases (for example, a buffer on a terminal 
output).
- The buffer is full (usually 4096 bytes).

The condition of automatic output buffer flush can be configured in the C 
library with the setvbuf() function If I remember.

Gambas has the equivalent:

- If you open a file with READ/WRITE, you will use unbuffered streams, i.e. 
the read()/write() system calls directly.

- If you open a file with INPUT/OUTPUT, you will use buffered streams, i.e. 
the FILE structure and the fXXXX() functions of the C library. Then, you must 
use the FLUSH instruction to ensure that buffered writes are sent to the 
write() system call.

But the way file are buffered is not yet configurable.

Regards,

-- 
Benoit Minisini

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to