~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to tools/sfio/sfputm.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include        "sfhdr.h"
 
2
 
 
3
/*      Write out an unsigned long value in a portable format.
 
4
**
 
5
**      Written by Kiem-Phong Vo.
 
6
*/
 
7
 
 
8
#if __STD_C
 
9
int _sfputm(reg Sfio_t* f, Sfulong_t v, Sfulong_t max)
 
10
#else
 
11
int _sfputm(f,v,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 */
 
15
#endif
 
16
{
 
17
#define N_ARRAY         (2*sizeof(Sfulong_t))
 
18
        reg uchar       *s, *ps;
 
19
        reg ssize_t     n, p;
 
20
        uchar           c[N_ARRAY];
 
21
 
 
22
        SFMTXSTART(f, -1);
 
23
 
 
24
        if(v > max || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) )
 
25
                SFMTXRETURN(f, -1);
 
26
        SFLOCK(f,0);
 
27
 
 
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 )
 
32
        {       v >>= SF_BBITS;
 
33
                *--s = (uchar)SFBVALUE(v);
 
34
        }
 
35
        n = (ps-s)+1;
 
36
 
 
37
        if(n > 8 || SFWPEEK(f,ps,p) < n)
 
38
                n = SFWRITE(f,(Void_t*)s,n); /* write the hard way */
 
39
        else
 
40
        {       switch(n)
 
41
                {
 
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++;
 
50
                }
 
51
                f->next = ps;
 
52
        }
 
53
 
 
54
        SFOPEN(f,0);
 
55
        SFMTXRETURN(f, (int)n);
 
56
}