/***********************************************************************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 an unsigned long value in a portable format.24**25** Written by Kiem-Phong Vo.26*/2728#if __STD_C29int _sfputm(Sfio_t* f, Sfulong_t v, Sfulong_t m)30#else31int _sfputm(f,v,m)32Sfio_t* f; /* write a portable ulong to this stream */33Sfulong_t v; /* the unsigned value to be written */34Sfulong_t m; /* the max value of the range */35#endif36{37#define N_ARRAY (2*sizeof(Sfulong_t))38reg uchar *s, *ps;39reg ssize_t n, p;40uchar c[N_ARRAY];41SFMTXDECL(f);4243SFMTXENTER(f, -1);4445if(v > m || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) )46SFMTXRETURN(f, -1);47SFLOCK(f,0);4849/* code v as integers in base SF_UBASE */50s = ps = &(c[N_ARRAY-1]);51*s = (uchar)SFBVALUE(v);52while((m >>= SF_BBITS) > 0 )53{ v >>= SF_BBITS;54*--s = (uchar)SFBVALUE(v);55}56n = (ps-s)+1;5758if(n > 8 || SFWPEEK(f,ps,p) < n)59n = SFWRITE(f,(Void_t*)s,n); /* write the hard way */60else61{ switch(n)62{63case 8 : *ps++ = *s++;64case 7 : *ps++ = *s++;65case 6 : *ps++ = *s++;66case 5 : *ps++ = *s++;67case 4 : *ps++ = *s++;68case 3 : *ps++ = *s++;69case 2 : *ps++ = *s++;70case 1 : *ps++ = *s++;71}72f->next = ps;73}7475SFOPEN(f,0);76SFMTXRETURN(f, (int)n);77}787980