Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-05

Where does Write(Ln) actually write to?

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jonas Maebe
to leledumbo
leledumbo wrote 6 lines
I'm almost there to have Write(Ln) works for my OS. I've made SysInitStdIO call OpenStdIO(Output,fmOutput,StdOutputHandle); and calling Write(Ln) gives no error (i.e. IOResult = 0). But where does it actually write to? If I can

access the buffer, I can display it on the screen.

It writes to whatever the text file variable called "stdout" in rtl/ inc/systemh.inc is assigned to. Standard I/O is indeed buffered, see the routines in rtl/inc/text.inc. The actual writing from the buffer to the associated file/device is done by FileWriteFunc(), which calls Do_Write() (the latter is an OS-specific function that you have to implement).

Also note that if textrec.FlushFunc is nil, then write(ln) will not automatically flush after each operation. As you can see in FileOpenFunc(), it is only assigned in case Do_Isdevice() returns true for the handle of the opened "file".

Jonas

Reply by email

leledumbo
to Jonas Maebe
Jonas Maebe-2 wrote 13 lines
It writes to whatever the text file variable called "stdout" in rtl/ inc/systemh.inc is assigned to. Standard I/O is indeed buffered, see the routines in rtl/inc/text.inc. The actual writing from the buffer to the associated file/device is done by FileWriteFunc(), which calls Do_Write() (the latter is an OS-specific function that you have to implement). Also note that if textrec.FlushFunc is nil, then write(ln) will not automatically flush after each operation. As you can see in FileOpenFunc(), it is only assigned in case Do_Isdevice() returns true for the handle of the opened "file".

Roger that, implementation begins...

View this message in context: http://www.nabble.com/Where-does-Write%28Ln%29-actually-write-to--tp23380791p23495593.html Sent from the Free Pascal - General mailing list .

Reply by email

Tomas Hajny
to leledumbo
leledumbo wrote 15 lines
Jonas Maebe-2 wrote: > > It writes to whatever the text file variable called "stdout" in rtl/ > inc/systemh.inc is assigned to. Standard I/O is indeed buffered, see > the routines in rtl/inc/text.inc. The actual writing from the buffer > to the associated file/device is done by FileWriteFunc(), which calls > Do_Write() (the latter is an OS-specific function that you have to > implement). > > Also note that if textrec.FlushFunc is nil, then write(ln) will not > automatically flush after each operation. As you can see in > FileOpenFunc(), it is only assigned in case Do_Isdevice() returns true > for the handle of the opened "file". Roger that, implementation begins...

I guess that you should have a look at some of the other Do_??? functions, in particular Do_Open coming to my mind. Unfortunately, the description for these functions in our Wiki
(http://wiki.freepascal.org/System_unit_structure) has not been finished yet. :-(

Tomas

Reply by email

leledumbo
to Tomas Hajny
Tomas Hajny wrote 7 lines
I guess that you should have a look at some of the other Do_??? functions, in particular Do_Open coming to my mind. Unfortunately, the description for these functions in our Wiki (http://wiki.freepascal.org/System_unit_structure) has not been finished yet. :-(

Currently, I implement them as empty functions just to make the rtl compiles without choking. I agree that wiki things need to be finished, I feel lost on what those things do.

View this message in context: http://www.nabble.com/Where-does-Write%28Ln%29-actually-write-to--tp23380791p23501613.html Sent from the Free Pascal - General mailing list .

Reply by email

Tomas Hajny
to leledumbo
leledumbo wrote
It works... but only for the first call, after that IOResult gives 103. Does rtl closes stdout handle after every write or what?

No, certainly not. As suggested yesterday, you need to implement some of the other Do_* functions, at least Do_Open, otherwise some of the fields in the TextRec/FileRec are not initialized properly (e.g. the input/output mode). Just have a look at one of the existing implementations.

Tomas

Reply by email