3
/* Write out an unsigned long value in a portable format.
5
** Written by Kiem-Phong Vo.
9
int _sfputm(reg Sfio_t* f, Sfulong_t v, Sfulong_t max)
12
reg Sfio_t* f; /* write a portable ulong to this stream */
13
Sfulong_t v; /* the unsigned value to be written */
14
Sfulong_t max; /* the max value of the range */
17
#define N_ARRAY (2*sizeof(Sfulong_t))
24
if(v > max || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) )
28
/* code v as integers in base SF_UBASE */
29
s = ps = &(c[N_ARRAY-1]);
30
*s = (uchar)SFBVALUE(v);
31
while((max >>= SF_BBITS) > 0 )
33
*--s = (uchar)SFBVALUE(v);
37
if(n > 8 || SFWPEEK(f,ps,p) < n)
38
n = SFWRITE(f,(Void_t*)s,n); /* write the hard way */
42
case 8 : *ps++ = *s++;
43
case 7 : *ps++ = *s++;
44
case 6 : *ps++ = *s++;
45
case 5 : *ps++ = *s++;
46
case 4 : *ps++ = *s++;
47
case 3 : *ps++ = *s++;
48
case 2 : *ps++ = *s++;
49
case 1 : *ps++ = *s++;
55
SFMTXRETURN(f, (int)n);