1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 /* Write out a long value in a portable format
26 ** Written by Kiem-Phong Vo.
30 int _sfputl(Sfio_t
* f
, Sflong_t v
)
33 Sfio_t
* f
; /* write a portable long to this stream */
34 Sflong_t v
; /* the value to be written */
37 #define N_ARRAY (2*sizeof(Sflong_t))
44 if(f
->mode
!= SF_WRITE
&& _sfmode(f
,SF_WRITE
,0) < 0)
48 s
= ps
= &(c
[N_ARRAY
-1]);
50 { /* add 1 to avoid 2-complement problems with -SF_MAXINT */
52 *s
= (uchar
)(SFSVALUE(v
) | SF_SIGN
);
54 else *s
= (uchar
)(SFSVALUE(v
));
55 v
= (Sfulong_t
)v
>> SF_SBITS
;
58 { *--s
= (uchar
)(SFUVALUE(v
) | SF_MORE
);
59 v
= (Sfulong_t
)v
>> SF_UBITS
;
63 if(n
> 8 || SFWPEEK(f
,ps
,p
) < n
)
64 n
= SFWRITE(f
,(Void_t
*)s
,n
); /* write the hard way */
68 case 8 : *ps
++ = *s
++;
69 case 7 : *ps
++ = *s
++;
70 case 6 : *ps
++ = *s
++;
71 case 5 : *ps
++ = *s
++;
72 case 4 : *ps
++ = *s
++;
73 case 3 : *ps
++ = *s
++;
74 case 2 : *ps
++ = *s
++;
75 case 1 : *ps
++ = *s
++;