[Coco] more libs

Willard Goosey goosey at virgo.sdc.org
Thu May 26 17:24:56 EDT 2011


Window_SaveRestore_fncs.lzh  I haven't used these, I don't know if
they're actually useful or not...

Also, here's my make.default, setnuid.c, and getenv.c

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
-------------- next part --------------
* Default rules for "make".  This file is read before the "makefile"
*    This program is in the Public Domain.
*
* Compiler name and flags.  Used by default rules below.
CC = cc252
CFLAGS = -dOS9
CCFLAGS = -dOS9
* Linker name and flags
LINK = rlink
LFLAGS =
* Assembler name and flags.
RMA = rma
RFLAGS = 

*generic include-file utility
INCL = include

*L1 assembler
ASM = asm
ASIZE = \#40K
AFLAGS = u

* Pascal name and flags.
PC = pascal
PFLAGS = \#40K :f
*the pound is backslashed to keep make from reading the rest
*of the line as a comment.
*Actual arguements to pascal must be preceded by a : 
*PFLAGS must contain a : for the O= arguement used in the default
*macro.  
*See OS-9 Pascal Reference Manual 2-3 thu 2-5, 3-4, 4-9 thu 4-10
PTRANS = /dd/cmds/pascalt.prun
PSINT = pascals

*AS11 68hc11 assembler
*doesn't support any flags
A11 = as11

*MASM macro assembler
MASM = masm
MFLAGS = -L

* Directories to use for executables and .r files.
* Note: ODIR is relative to current exec dir; RDIR is  relative to data dir
ODIR =                              
RDIR =.

* When trying to find implicit source files, Make will append each suffix
*   in turn until it finds a source file that exists, and for which
*   there is a rule defined below.
.SUFFIXES: .r .a .c .asm .p .prun .pi .a11 .a11i .masm

* .c specifies how to build a no-extension file from a .c file
* .c.r specifies how to compile .c files into .r files.
.c:;$(CC) $(CFLAGS) $(LFLAGS) $< -f=$(ODIR/)$@
.r:;$(LINK) $(LFLAGS) $< -o=$(ODIR/)$@
.c.r:;$(CC) $(CFLAGS) -r $<
.a.r:;$(RMA) $(RFLAGS) $< -o=$(RDIR/)$@
*
.asm:;$(ASM) $(ASIZE) $< $(AFLAGS) o=$(ODIR/)$@

* 08/30/2k4 asm support
* because the L1 assembler is necessary for just about anything
* that's not a program module

* 08/29/2k7 nitros asm support
* asm now accepts mixed case labels, IF u option is specified
* std defs file has mixed case labels. ;-)
* also asm very picky about option order
* must be asm size infile options
*
.p:;$(PC) $(PFLAGS) O=$(ODIR/)$@ < $< > $@.lst 
.p.prun:;$(PC) $(PFLAGS) O=$(RDIR/)$@ < $< > $*.lst 
*
.pi:;$(INCL) $< ! $(PC) $(PFLAGS) O=$(ODIR/)$@ > $@.lst 
.pi.prun:;$(INCL) $< ! $(PC) $(PFLAGS) O=$(RDIR/)$@ > $*.lst 
*
.prun.asm:;$(PSINT) $(PTRANS) S20K < $*.s
* 
* 09/10/2k1 pascal compiler support (hey why not?)
* Note:  notice (and be aware of) the PFLAGS hack here.  If pascal
* has any arguements, they must be proceded by 1 (and exactly 1)colon 
* character.  So, if PFLAGS is changed, LEAVE the : or the O= will break!

* 07/08/2k8 working on support for pascal native code
* translator and linkage editor
* rules for .p->.prun (source to pcode)
* .prun->.asm (pcode to assembly) *note required script file*
*    then the regular asm->exe rule applies :-)

* 3/14/2k9 Pascal with Include (foo.pi)
*
.a11:;$(A11) $< > $*.lst
.a11.s19:;$(A11) $< > $*.lst 
          copy m.out $(RDIR/)$@
          del m.out
.a11i:;$(INCL) $< $*.a11
       $(A11) $*.a11 > $*.lst
       del $*.a11
.a11i.s19:;$(INCL) $< $*.a11
           $(A11) $*.a11 > $*.lst
           copy m.out $(RDIR/)$@
           del m.out $*.a11

*3/13/2k9 as11 support
*as11 accepts no flags, always writes list file to stdout
*and output into an s19 file named m.out

.masm:;$(MASM) $< $(MFLAGS),o=$(ODIR/)$@
*7/24/2k9 masm support
*masm is a very powerful, if old school, macro assembler
*masm options seperated by commas, not spaces.  Beware

*           
* Notes: RDIR support here is a bit of a hack.  A macro such as
*   $(RDIR/) will expand the same as $(RDIR), except that a trailing
*   slash will be added, but only if RDIR is not null.  So,
*   If RDIR = RELS, then $(RDIR/) will be "RELS/", but if RDIR =
*   then $(RDIR/) will be null.



-------------- next part --------------
/*
 "getenv.c" - environment variable reading/setting functions.
 updated 8/6/90 by Mike Sweet
 updated 12/11/2k9 by Willard Goosey
 ---compare with the length of the string were looking for
 ---not the string from _ENVFILE
*/
/*#define DEBUG 1*/

char *_ENVFILE=0; /* this global pointer holds the current ENV.FILE contents. */
static char envstr[81];

static char *readenv()
{
 register int path,len;

 if (!(_ENVFILE=malloc(1024)))
  return(0);

 if ((path=open("/dd/sys/env.file",1))==-1)
  {
   free(_ENVFILE);
   _ENVFILE=0;
   return(0);
  };

 if ((len=read(path,_ENVFILE,1023))<0)
  {
   close(path);
   free(_ENVFILE);
   _ENVFILE=0;
   return(0);
  };

 _ENVFILE[len]=0;
 close(path);
 return(_ENVFILE);
}



static char *findenv(s)
char *s;
{
 char *temp;
 register int len;

 if (!_ENVFILE)
  readenv();

 temp=_ENVFILE;

 while (temp)
  {
   if (temp[0]!='*') /* ignore commented lines */
    {
     len=0;
     while ((temp[len]!=' ') && (temp[len]!='='))
      len++;
/*do this compare with len(s) chars, not len(temp) chars*/
     if (strnucmp(temp,s,strlen(s))==0)
      {
#ifdef DEBUG
      printf("matched %s with %s",s,temp);
#endif
       temp+=len;
       while (*temp && *temp!='=')
        temp++;
       temp++;
       while (*temp && *temp==' ')
        temp++;
       return(temp);
      };
    };
   if (temp=strchr(temp,13))
    temp++;
  };
 return(0);
}


char *getenv(s)
char *s;
{
 register char *temp;

 temp=findenv(s);
 strncpy(envstr,temp,(char *)strchr(temp,13)-temp);
 return(envstr);
} 



putenv(v,s)
char *v,*s;
{
 register char *temp;
 int len,slen,path;

 slen=strlen(s);

 if (temp=findenv(v))
  {
   len=(char *)strchr(temp,13)-temp;
   movemem(temp+slen,temp+len,strlen(temp+len)+1);
   movemem(temp,s,slen);
  }
 else if (_ENVFILE)
  {
   if ((strlen(v)+strlen(_ENVFILE)+slen+2)>1023)
    return;
   strcat(_ENVFILE,v);
   strcat(_ENVFILE,"=");
   strcat(_ENVFILE,s);
   strcat(_ENVFILE,"\n");
  }
 else
  return;

 if ((path=open("/dd/sys/env.file",2))==-1)
  return;

 write(path,_ENVFILE,strlen(_ENVFILE));
 close(path);
 return;
}
-------------- next part --------------
/*setnuid() for UNIXLIB
 *
 *Willard Goosey
 *goosey at sdc.org
 *12/12/2010
 *
 * int setnuid(n)
 * returns old uid or -1 on failure
 * sets uid = n
 * under OS-9/6X09, setuid system call always succeeds
 * but setuid() C call only allows success if uid already = 0
 * OS-9/6X09 is normally run by user 0 anyway...
 * but this gives no indication if setuid() fails.
 */

/*Kreider C lib has asetuid() which always succeeds so we can
 *use it here if we're using Kreider's C lib.  If you're not,
 *you should be.
 *1/12/2011
 *set the #define if you are using Kreider's lib 1/23/2011
 */
#define KREIDER

int setnuid(n)
    int n;
{
    int old,r;

    old=getuid();
#ifdef KREIDER
    asetuid(n);
#else
    r=setuid(n);
    if(r<0) 
      old=r;
#endif
    return old;
}


More information about the Coco mailing list