home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / icon / Source / Common / C / Long < prev    next >
Encoding:
Text File  |  1990-07-19  |  788 b   |  50 lines

  1. /*
  2.  *  common.c -- functions common to several modules.
  3.  */
  4.  
  5. #include "../h/config.h"
  6. #include "../h/cpuconf.h"
  7. #include <ctype.h>
  8.  
  9. #if IntBits == 16
  10. /*
  11.  * Long strlen
  12.  */
  13.  
  14. long lstrlen(s)
  15. char *s;
  16. {
  17.     long l = 0;
  18.     while(*s++) l++;
  19.     return l;
  20. }
  21. #endif                    /* IntBits */
  22.  
  23. /* 
  24.  * Write a long string in int-sized chunks.
  25.  */
  26.  
  27. long longwrite(s,len,file)
  28. FILE *file;
  29. char *s;
  30. long len;
  31. {
  32.    long tally = 0;
  33.    int n = 0;
  34.    int leftover, loopnum;
  35.    char *p;
  36.  
  37.    leftover = len % MaxInt;
  38.    for (p = s, loopnum = len/MaxInt; loopnum; loopnum--) {
  39.        n = fwrite(p,sizeof(char),MaxInt,file);
  40.        tally += n;
  41.        p += MaxInt;
  42.    }
  43.    if (leftover)
  44.       n = fwrite(p,sizeof(char),leftover,file);
  45.    tally += n;
  46.    if (tally != len)
  47.       return -1;
  48.    else return tally;
  49.    }
  50.