[comp.sys.atari.st.tech] MicroRTX patch and isatty

david@bdt.UUCP (David Beckemeyer) (08/14/90)

Recently it was brought to my attention that the isatty() code in
the dLibs and GCC libraries doesn't work with programs run under
Micro RTX because RTX handles the Fseek() GEMDOS call a little
differently.

Basically the isatty() code tries to do Fseek() and if it gets a
zero back, it assumes the thing isn't seekable and therefore must
be a tty.  In RTX, Fseek() returns -37 (invalid handle) on non
seekable files.  This confuses the isatty() code.   Below is a
program (uuencoded) that will patch RTX V1.13 so that RTX Fseek()
returns zero like normal GEMDOS Fseek().

This doesn't fix the whole problem, because the isatty() still
doesn't understand what to do with pipes.  Basically all the isatty()
routines that I've seen assume that if the handle is seekable, then
it's a file, otherwise it's a tty.  Well in RTX, a handle could be
a pipe, in which case it's not seekable, but it's not a tty either
(it should be treated like a file).  So what I propose is that
the isatty() code should be changed to first check to see if RTX
is running, and use the more reliable RTX calls to see if the
handle is a tty.  The following will work whether RTX is running
or not:

======== CUT HERE for new isatty code ========

#define Ftype(x) gemdos(0x101, x)

isatty(fd)
int fd;
{
	int fd_type;

	/*
	 * First use RTX Ftype() to get the handle type.
	 *
	 * If RTX isn't running this call will return -32
	 * (invalid function), and so we will just skip to
	 * the old isatty() for regular old GEMDOS.
	 *
	 * If RTX is running, then Ftype() tells us what the
	 * handle really is:
	 *	0-15	The BIOS device number (tty)
	 *	16	File
	 * 	17	Pipe
  	 */
	fd_type = Ftype(fd);
	if (fd_type >= 0)
		return(fd_type < 16);
	/*
	 * The old isatty() code...
	 */
	[ Place your favorite isatty() code here ]

======== END OF NEW isatty() code ========

Below is the start of the program that will patch RTX V1.13 so
that Fseek() will return zero on non-seekable handles which
helps current isatty() library code work with RTX (the better
solution is to fix the isatty() code as shown above).

Use this program from a command line.  Change directory to
where the RTXBOOT.PRG file is and type "rtxpatch". It modifies
the RTXBOOT.PRG (so save a copy if you're worried).

begin 644 rtxpatch.prg
M8!H   3.    Y@    8                  "IO  0@;0 8T>T '"1M "Q"
M@")(2A)G4"**)DHD64H:9OPBBDH29SP,&P!!9NP,&P!29N8,&P!'9N ,&P!6
M9MH,&P ]9@I*$V<&(\L   6,0ID@"2**)DHD64H:9OPBBDH29O(F &8R0ID@
M"2+\   %KD7M ( 4&DB"0C(@ '(@%!IG%K0!9_A32B+*%!IG"K0!9OA"*O__
M8.9"F2()T_D   6P(\$   6P+DDK20 $+PTCR   !.@O""\ DH#D@5-!/P&3
MS2\)+PU"9S\\ $I.0=[\  Q*@V8N/SP !#\\  ).N0   Q(^@$ZY   #8#]\
M  (  D)73KD   ,2/H!.N0   V!83YS.3KD   $BWOP "C\ 3KD   +</SP 
M3$Y!3E;__G "/P O/   !.QP/3\ 3D%03SU __Y*;O_^;!HO/   !/AP"3\ 
M3D%<3W !/P!P3#\ 3D%83T)G/R[__B\\  !$X'!"/P!.0=[\  H,@   1.!G
M&B\\   %%' )/P!.05Q/< $_ '!,/P!.05A/+SP   6T< 8O #\N__YP/S\ 
M3D'>_  ,#(     &9QHO/   !2)P"3\ 3D%<3W !/P!P3#\ 3D%83PQY(_P 
M  6T9B8P.0  !;B >0  !;9F&"\\   %+W )/P!.05Q/0F=P3#\ 3D%83PQY
M(_P   6T9A0,>?__   %MF8*#'G_VP  !;AG&B\\   %07 )/P!.05Q/< $_
M '!,/P!.05A/0GD   6X0GD   6V0F<_+O_^+SP  $3@<$(_ $Y!WOP "@R 
M  !$X&<:+SP   5>< D_ $Y!7$]P 3\ <$P_ $Y!6$\O/   !;1P!B\ /R[_
M_G! /P!.0=[\  P,@     9G&B\\   %;' )/P!.05Q/< $_ '!,/P!.05A/
M/R[__G ^/P!.05A/+SP   5Z< D_ $Y!7$]"9W!,/P!.05A/3EY.=4Y6  !.
MN0   O8_+@ (3KD   +^5$].7DYU3E8  $Y>3G5.5@  /RX "'!,/P!.05A/
M3EY.=4Y6__PO!S\N  AP13\ 3D%83SX ;! P!TC +P!.N0  !*Q83V B/RX 
M"$ZY   #N%1//4  "&T./RX "#\'3KD   006$\P!RX?3EY.=4Y6__PO!S\N
M  @_+@ *<D8_ 4Y!7$\^ $I 9B@_+@ (3KD   .X5$\]0  (;18_+@ (/RX 
M"DZY   $$%A/,"X "F ., =(P"\ 3KD   2L6$\N'TY>3G5.5O_X2-<@@#XN
M  @P!U9 #$   F(<Y4@P0-'\   $SB!03M!@*G!08"9P06 B<$-@'DI';0XJ
M>0  !8Q31VT(2AUF^'#_8 A*%6?X$!5(@$S7((!.7DYU3E;_^$C7(( ^+@ (
M2D=M#BIY   %C%-';0A*'6;X</]@"DH59_@P+@ *&H!,UR" 3EY.=4Y6__A(
MUR" /BX "# '5D ,0  "8DCE2#! T?P   3:(%!.T"IY   %C! 52("P1V<,
M2A5F!'#=8"92C6#L( V0N0  !8P_ $ZY   #$E1/8 Y^0V#.?D%@RGY08,9P
MVTS7((!.7DYU3E8  $JN  AL$" N  A$@#/    $YG#_8 0@+@ (3EY.=0  
M ]X   /B   #Y@  !)X   2:   $E@       ')T>&)O;W0N<')G $-A;FYO
M="!A8V-E<W,@4E180D]/5"Y04D<-"@!&<V5E:R!E<G)O<@T* %)E860@97)R
M;W(-"@!!;')E861Y('!A=&-H960-"@!0871C:"!I<R!F;W(@4E18(#$N,3,@
M;VYL>0T* $9S965K(&5R<F]R#0H 5W)I=&4@97)R;W(-"@!0871C:"!I;G-T
M86QL960-"@    600T-!4#\_/S\_/S\_/S\_/S\_/S\_/S\_/S\_/P      
M  @     3"(R!@XP" X("@P4&#@:(!P(!@@:"@H(&@8D&B F( I$#A0P%A0H
M'#(^"AP(,! $! 0$!*H !P$4 0H ,    ,X$             !@   #.    
M!@                      &AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:
L&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:
 
end
-- 
David Beckemeyer (david@bdt.uucp)	| "Yea I've got medicine..." as the 
Beckemeyer Development Tools		| cookie cocks a his Colt, "and if
P.O. Box 21575, Oakland, CA 94620	| you don't keep your mouth shut, I'm
UUCP: {uunet,ucbvax}!unisoft!bdt!david 	| gonna give you a big dose of it!"

7103_2622@uwovax.uwo.ca (Eric Smith) (08/14/90)

In article <4352@bdt.UUCP>, david@bdt.UUCP (David Beckemeyer) writes:
> Recently it was brought to my attention that the isatty() code in
> the dLibs and GCC libraries doesn't work with programs run under
> Micro RTX because RTX handles the Fseek() GEMDOS call a little
> differently.
> 
> Basically the isatty() code tries to do Fseek() and if it gets a
> zero back, it assumes the thing isn't seekable and therefore must
> be a tty.  In RTX, Fseek() returns -37 (invalid handle) on non
> seekable files.  This confuses the isatty() code.   Below is a
> program (uuencoded) that will patch RTX V1.13 so that RTX Fseek()
> returns zero like normal GEMDOS Fseek().
> 
> This doesn't fix the whole problem, because the isatty() still
> doesn't understand what to do with pipes.  Basically all the isatty()
> routines that I've seen assume that if the handle is seekable, then
> it's a file, otherwise it's a tty.  Well in RTX, a handle could be
> a pipe, in which case it's not seekable, but it's not a tty either
> (it should be treated like a file).

The GCC isatty() code has a default return value of 0, i.e. if an
error occurs, it's assumed that the handle is not a tty. Thus, if
pipes give an error (e.g. -37, as they used to in RTX) and real ttys always
return 0 from an Fseek, then it can distinguish between them. This
might be a more robust scheme than doing the same thing for ttys and
pipes (it's the solution I chose for my multitasking system).

I presume the dLibs code does something similar, since there was a message
from someone (A. Pratt, perhaps?) describing this as the "official"
way to do isatty().
--
Eric R. Smith                     email:
Dept. of Mathematics            ersmith@uwovax.uwo.ca
University of Western Ontario   ersmith@uwovax.bitnet
London, Ont. Canada N6A 5B7
ph: (519) 661-3638