[Coco] OS-9 "C" question

Willard Goosey goosey at virgo.sdc.org
Wed Aug 7 22:01:30 EDT 2013


On Wed, Aug 07, 2013 at 09:47:20AM -0400, Bill Pierce wrote:
> 
> Hi guys,
> I'm trying to make a forked program "pipe" data back to the calling program.
> All in "C" language in OS-9 Level 2

The trick that makes this all work is that dup() always returns the
*lowest* possible path number...

Here's an old OS-9 C program of mine that does that....
-----------<lookterm2.c>-----------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <modes.h>
#define MARK "/dd/tmp/term_win"

main(argc,argv)
    char *argv[];
{
  int pipe,sin,sout,status,marker;
  char line[80];
  if((pipe=open("/pipe",3))>0)
  {
     sin=dup(0);  /*save a copy of standard in*/
     sout=dup(1); /*save a copy of standard out*/
     close(0);    /*close stdin*/
     dup(pipe);   /*path 0 is now pipe*/
     close(1);    /*close stdout*/
     dup(pipe);   /*path 1 is now pipe*/
	/*forked process inherits paths 0,1,2*/
     os9fork("ident",8,"-m term\n",1,1,0);
     close(0);	  /*parent: close pipe 0 */
     dup(sin);	  /*path 0 is now saved stdin*/
     close(1);    /*close pipe output*/
     dup(sout);   /*path 1 is now saved stdout*/

     while(readln(pipe,line,80)>0)
     {
#ifdef DEBUG
       if(argc>1)
           writeln(1,line,80);
#endif
       if(strncmp(line,"Module CRC:",11)==0)
         {
          if(strncmp(&(line[13]),argv[1],7)==0)
            {
               marker=creat(MARK,S_IWRITE);  /*unlike the raw asm */
               close(marker);                /*sys call, C creat dont */
            }                                /*bomb out if file exists */
          else
            {
               if(access(MARK,S_IREAD)==0) /*file does exist*/
                 {
                    unlink(MARK); /*delete it*/
                 }
            }
         }
          
     }
     wait(&status); /*wait for child to exit */
  }
  else
  {
    writeln(2,"Couldn't open pipe",80);
    exit(216);
  }
}
------------------<lookterm2.c>--------------------------------
BTW what this does, is take as an arguement a module CRC, asks "ident"
for the CRC of the /term descriptor, and creates an empty file in
/dd/tmp if it matches.  This let me use the same startup for both 
windint only and vdgint only boot disks...


Willard
-- 
Willard Goosey  goosey at sdc.org
Socorro, New Mexico, USA
I search my heart and find Cimmeria, land of Darkness and the Night.
  -- R.E. Howard



More information about the Coco mailing list