/***********************************************************************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 _sfputu(Sfio_t* f, Sfulong_t v)30#else31int _sfputu(f,v)32Sfio_t* f; /* write a portable ulong to this stream */33Sfulong_t v; /* the unsigned value to be written */34#endif35{36#define N_ARRAY (2*sizeof(Sfulong_t))37reg uchar *s, *ps;38reg ssize_t n, p;39uchar c[N_ARRAY];40SFMTXDECL(f);4142SFMTXENTER(f, -1);4344if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)45SFMTXRETURN(f, -1);46SFLOCK(f,0);4748/* code v as integers in base SF_UBASE */49s = ps = &(c[N_ARRAY-1]);50*s = (uchar)SFUVALUE(v);51while((v >>= SF_UBITS) )52*--s = (uchar)(SFUVALUE(v) | SF_MORE);53n = (ps-s)+1;5455if(n > 8 || SFWPEEK(f,ps,p) < n)56n = SFWRITE(f,(Void_t*)s,n); /* write the hard way */57else58{ switch(n)59{60case 8 : *ps++ = *s++;61case 7 : *ps++ = *s++;62case 6 : *ps++ = *s++;63case 5 : *ps++ = *s++;64case 4 : *ps++ = *s++;65case 3 : *ps++ = *s++;66case 2 : *ps++ = *s++;67case 1 : *ps++ = *s++;68}69f->next = ps;70}7172SFOPEN(f,0);73SFMTXRETURN(f, (int)n);74}757677