[Coco] basic09 - append to file

Steven Hirsch snhirsch at gmail.com
Thu Jan 13 08:00:26 EST 2011


On Wed, 12 Jan 2011, Willard Goosey wrote:

> On Wed, Jan 12, 2011 at 07:02:45PM -0500, gene heskett wrote:
>> Its Very Useful, Willard.  The Os9 kernel itself is just a collection of
>> all these little one trick ponies, and syscall allows you to do _anything_
>> the os can do, from a higher level language like basic09.  Truly the best
>> of both worlds.
>
> I don't remember exactly, but I think I must have had some C program
> blow up completely on me when I mixed unix system calls (read, write)
> with stdio calls (getc, printf).  Made me really paranoid about mixing
> "levels" of functionality.

It's not the best idea in the world if you want to keep output properly 
ordered.  The Unix/Linux _library_ routine 'fprintf' does internal 
buffering above the kernel while the _system_ call 'write' does not 
(although it does internal to the kernel under some circumstances).  So it 
is very possible to have output intermixed in an undesirable manner if you 
are not careful (e.g. by explicitly calling fflush after fwrite and before 
write).  Same applies to intermixing C++ iostream operations with either 
of the above.  One classic problem:  Write output to the console with 
'cout << "foo"', then fork a child process.  In many cases, you'll see 
duplicate "foo" displayed - one for each child forked :-).  Cure for that 
is the << flush operator prior to fork.

None of this intermixing is necessarily fatal, but you do need to be a bit 
defensive.

Steve


-- 




More information about the Coco mailing list