/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#include "sfhdr.h"2223/* Write out a long value in a portable format24**25** Written by Kiem-Phong Vo.26*/2728#if __STD_C29int _sfputl(Sfio_t* f, Sflong_t v)30#else31int _sfputl(f,v)32Sfio_t* f; /* write a portable long to this stream */33Sflong_t v; /* the value to be written */34#endif35{36#define N_ARRAY (2*sizeof(Sflong_t))37reg uchar *s, *ps;38reg ssize_t n, p;39uchar c[N_ARRAY];40SFMTXDECL(f);4142SFMTXENTER(f,-1);43if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)44SFMTXRETURN(f, -1);45SFLOCK(f,0);4647s = ps = &(c[N_ARRAY-1]);48if(v < 0)49{ /* add 1 to avoid 2-complement problems with -SF_MAXINT */50v = -(v+1);51*s = (uchar)(SFSVALUE(v) | SF_SIGN);52}53else *s = (uchar)(SFSVALUE(v));54v = (Sfulong_t)v >> SF_SBITS;5556while(v > 0)57{ *--s = (uchar)(SFUVALUE(v) | SF_MORE);58v = (Sfulong_t)v >> SF_UBITS;59}60n = (ps-s)+1;6162if(n > 8 || SFWPEEK(f,ps,p) < n)63n = SFWRITE(f,(Void_t*)s,n); /* write the hard way */64else65{ switch(n)66{67case 8 : *ps++ = *s++;68case 7 : *ps++ = *s++;69case 6 : *ps++ = *s++;70case 5 : *ps++ = *s++;71case 4 : *ps++ = *s++;72case 3 : *ps++ = *s++;73case 2 : *ps++ = *s++;74case 1 : *ps++ = *s++;75}76f->next = ps;77}7879SFOPEN(f,0);80SFMTXRETURN(f, n);81}828384