summaryrefslogtreecommitdiff
path: root/src/common/long.c
blob: 071a944cf0a199eef75cf9b1844054b7ee5ebf9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 *  long.c -- functions for handling long values on 16-bit computers.
 */

#include "../h/gsupport.h"

/*
 * 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 = (int)(len % (long)MaxInt);
   for (p = s, loopnum = (int)(len / (long)MaxInt); loopnum; loopnum--) {
       n = fwrite(p,sizeof(char),MaxInt,file);
       tally += (long)n;
       p += MaxInt;
   }
   if (leftover) {
      n = fwrite(p,sizeof(char),leftover,file);
      tally += (long)n;
      }
   if (tally != len)
      return -1;
   else return tally;
   }