[comp.sys.atari.st] I/O redirection to the printer

UI0T@DKAUNI2.BITNET ("Thomas Koenig") (12/16/89)

I am having a strange problem with I/O redirection.  To redirect
standard output to the printer, I wrote the following test program:

#include <stdio.h>
#include <tos.h>    /* Turbo - C 's header for TOS stuff */

main()
{
    int    oldstd;
    int    printhandle;

    oldstd      = Fdup (1);
    printhandle = Fdup (3);
    printf("oldstd = %d, printhandle = %d\n",oldstd,printhandle);

    Fclose (1);
    Fforce (1, printhandle);
    printf("Hello, world!\n");
/*    Cconws("Hello, world!\n");    */

    Fclose (1);
    Fforce (1, oldstd);
    Fclose (oldstd);
    Fclose (printhandle);
}

This program worked as it should; it printed out
Hello, world!
on the printer.  However, when I commented out the printf statement
and used Cconws instead, it seemed to go into an endless loop; I
could still move the mouse around, but that was it for at least 10
minutes (I did not wait any longer).  Oh, by the way, the printer WAS
online and ready.  Without the I/O redirection, Cconws worked fine;
it printed out "Hello, world" on the screen.  No accessories or
memory resident programs were active at the time.

The problem with Cconws occured both with Turbo C V1.1 and with
equivalent code (calls to the GEMDOS library) in SPC Modula V2.0.

I am using a Mega ST2 with TOS 1.2 (1.4 has not made it here yet)  and
a Megafile 60 hard drive.

Is there something wrong with my code (but WHY did printf work,
then?), can anybody reproduce this strange behaviour, is this a bug
in TOS 1.2 which has/has not been fixed in TOS 1.4, ... , in short:
 WHAT IS GOING ON?

Any help appreciated.

Thomas  Koenig                   UI0T@DKAUNI2.BITNET
                                 UI0T%DKAUNI2.BITNET@CUNYVM.CUNY.EDU
(soon: new address, old machine) UI0T@IBM3090.RZ.UNI-KARLSRUHE.DBP.DE
'Ich dachte nicht, ich untersuchte.'            Wilhelm Conrad Roentgen

roland@cochise (12/19/89)

Hallo Thomas,

UI0T@DKAUNI2.BITNET ("Thomas Koenig") writes:

>I am having a strange problem with I/O redirection.  To redirect
>standard output to the printer, I wrote the following test program:

I think You just re-discovered one of the older bugs of TOS.
I have hit upon this problem when trying to redirect the messages
from Turbo-C ( commandline version ) to a file. For the compiler TCC
this worked fine, however, the linker put out only NULs. ( Substituting
ALN as linker solved this problem. )

A little disassembling showed that the linker used Cconout() for
basic output, whereas TCC relied on Fwrite( 1, ... ).

>    Fclose (1);
>    Fforce (1, printhandle);
>    printf("Hello, world!\n");
>/*    Cconws("Hello, world!\n");    */

So try:
     Fwrite( 1, "Hello world!\n", 13 ) ; /* modulo correct ordering */

( This should work, and I suppose that the printf() is based on 
  F