[comp.sys.atari.st] Weird Problem with I/O Red.

bkr@mcshh.hanse.de (Bjoern Kriews) (07/15/90)

Hello Netland !

I'm having trouble with GEMDOS I/O redirection and the internal memory
problem (Tos 1.4, Poolfix3 installed):

I have a little linkable shell module which I use with many of my programs
to call other programs with redirections in a shell-independent way.
The code looks somekind like this (input red.):

      sav=Fdup(0);
      fh=Fopen(new_in,0);
      Fforce(0,fh);
      Pexec(...);
      Fforce(0,sav);        Do I have to Fclose(0) before ???
      Fclose(fh);    
      ...                   Do I have to Fclose(sav) here ???   May I ???

This works wonderful, until I call the program doing the redirections
from any shell with an input redirection on itself. Everything still 
works fine until I leave my CLI  - getting the well known message
'Out of internal memory... Use FOLDR100 to get more'
(Didn't matter which CLI I tried - gulam, gp, command...)
Using FOLDR100 up to 900 folders didn't change anything.


Tracing my code, I encountered a return value of -65 (internal error)
in my Fclose() call. I first removed the Fforce(0,sav) but it didn't
mattter. Then I took a closer look at the docs, noticing that Fdup
does only work on handle 0-5. Realizing that Fdup probably takes the
associated physical handles from BASPAG->p_stdfh I found out, that
the following piece of code is a way to get the 'Out of...' message
immediately - just compile and type 'thisprog <anyfile' from your cli:

- all examples are in Turbo C, I'm working with TOS

  #include <tos.h>

  main(void)
  {
    return Fdup(0);
  }

I had to get my code to work and added these:

                                              / pretend successful exec
  #define Fdup(x)     (_BasPag->p_stdfh[x])  / 
  #define Fforce(x,y) (_BasPag->p_stdfh[x]=y,0)

It worked, giving me no more 'System Halted' messages but still left me
alone with my 'Internal Error' return codes.

Could anyone please describe a real clean way of doing redirection when
it is possible that the standard handles are already redirected ?
What about re-forcing stdhandles and closing them afterwards ?

Perhaps some Atari Official can give some statements ? 
  [ERROR -65]
  [Fdup'ing an already Fdup'ed handle]

Any help is strongly appreciated,

  Bjoern
  

/// Bjoern Kriews     D-2000 Hamburg 76  |  bkr@mcshh.hanse.de  (World)
\\\ Stormsweg 6       +49 40 227 79 07   |  >>> So what ?