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

« back to all changes in this revision

Viewing changes to tools/sfio/sfnputc.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 a character n times
 
4
**
 
5
**      Written by Kiem-Phong Vo.
 
6
*/
 
7
 
 
8
#if __STD_C
 
9
ssize_t sfnputc(reg Sfio_t* f, reg int c, reg size_t n)
 
10
#else
 
11
ssize_t sfnputc(f,c,n)
 
12
reg Sfio_t*     f;      /* file to write */
 
13
reg int         c;      /* char to be written */
 
14
reg size_t      n;      /* number of time to repeat */
 
15
#endif
 
16
{
 
17
        reg uchar*      ps;
 
18
        reg ssize_t     p, w;
 
19
        uchar           buf[128];
 
20
        reg int         local;
 
21
 
 
22
        SFMTXSTART(f,-1);
 
23
 
 
24
        GETLOCAL(f,local);
 
25
        if(SFMODE(f,local) != SF_WRITE && _sfmode(f,SF_WRITE,local) < 0)
 
26
                SFMTXRETURN(f, -1);
 
27
 
 
28
        SFLOCK(f,local);
 
29
 
 
30
        /* write into a suitable buffer */
 
31
        if((size_t)(p = (f->endb-(ps = f->next))) < n)
 
32
                { ps = buf; p = sizeof(buf); }
 
33
        if((size_t)p > n)
 
34
                p = n;
 
35
        MEMSET(ps,c,p);
 
36
        ps -= p;
 
37
 
 
38
        w = n;
 
39
        if(ps == f->next)
 
40
        {       /* simple sfwrite */
 
41
                f->next += p;
 
42
                if(c == '\n')
 
43
                        (void)SFFLSBUF(f,-1);
 
44
                goto done;
 
45
        }
 
46
 
 
47
        for(;;)
 
48
        {       /* hard write of data */
 
49
                if((p = SFWRITE(f,(Void_t*)ps,p)) <= 0 || (n -= p) <= 0)
 
50
                {       w -= n;
 
51
                        goto done;
 
52
                }
 
53
                if((size_t)p > n)
 
54
                        p = n;
 
55
        }
 
56
done :
 
57
        SFOPEN(f,local);
 
58
        SFMTXRETURN(f, w);
 
59
}