/*
 *  common.c -- functions common to several modules.
 */

#include "..\h\config.h"
#include "..\h\cpuconf.h"
#include <ctype.h>

#if IntBits == 16
/*
 * Long strlen
 */

long lstrlen(s)
char *s;
{
    long l = 0;
    while(*s++) l++;
    return l;
}
#endif					/* IntBits */

/* 
 * Write a long string in int-sized chunks.
 */

long longwrite(s,len,file)
FILE *file;
char *s;
long len;
{
   long tally = 0;
   int n = 0;
   int leftover, loopnum;
   char *p;

   leftover = len % MaxInt;
   for (p = s, loopnum = len/MaxInt; loopnum; loopnum--) {
       n = fwrite(p,sizeof(char),MaxInt,file);
       tally += n;
       p += MaxInt;
   }
   if (leftover)
      n = fwrite(p,sizeof(char),leftover,file);
   tally += n;
   if (tally != len)
      return -1;
   else return tally;
   }
