~ubuntu-branches/ubuntu/utopic/cdrdao/utopic

« back to all changes in this revision

Viewing changes to scsilib/libschily/printf.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Suffield
  • Date: 2004-06-24 22:33:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040624223316-534onzugaeeyq61j
Tags: upstream-1.1.9
ImportĀ upstreamĀ versionĀ 1.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)printf.c 1.14 03/06/15 Copyright 1985, 1989, 1995-2003 J. Schilling */
 
2
/*
 
3
 *      Copyright (c) 1985, 1989, 1995-2003 J. Schilling
 
4
 */
 
5
/*
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along with
 
17
 * this program; see the file COPYING.  If not, write to the Free Software
 
18
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include <mconfig.h>
 
22
 
 
23
#ifdef  printf
 
24
#       define  __no_undef__
 
25
#else
 
26
#       define  printf          __nothing__
 
27
#endif
 
28
#ifdef  fprintf
 
29
#       define  __no_undef2__
 
30
#else
 
31
#       define  fprintf         __nothing2__
 
32
#endif
 
33
 
 
34
#include <stdio.h>
 
35
#include <vadefs.h>
 
36
#include <standard.h>
 
37
#include <schily.h>
 
38
 
 
39
#ifndef __no_undef__
 
40
#       undef   printf
 
41
#endif
 
42
#ifndef __no_undef2__
 
43
#       undef   fprintf
 
44
#endif
 
45
 
 
46
#define BFSIZ   256
 
47
 
 
48
typedef struct {
 
49
        short   cnt;
 
50
        char    *ptr;
 
51
        char    buf[BFSIZ];
 
52
        int     count;
 
53
        FILE    *f;
 
54
} *BUF, _BUF;
 
55
 
 
56
LOCAL   void    _bflush __PR((BUF));
 
57
LOCAL   void    _bput   __PR((char, long));
 
58
EXPORT  int     fprintf __PR((FILE *, const char *, ...))       __printflike__(2, 3);
 
59
EXPORT  int     printf  __PR((const char *, ...))               __printflike__(1, 2);
 
60
 
 
61
LOCAL void
 
62
_bflush(bp)
 
63
        register BUF    bp;
 
64
{
 
65
        bp->count += bp->ptr - bp->buf;
 
66
        if (filewrite(bp->f, bp->buf, bp->ptr - bp->buf) < 0)
 
67
                bp->count = EOF;
 
68
        bp->ptr = bp->buf;
 
69
        bp->cnt = BFSIZ;
 
70
}
 
71
 
 
72
#ifdef  PROTOTYPES
 
73
LOCAL void
 
74
_bput(char c, long l)
 
75
#else
 
76
LOCAL void
 
77
_bput(c, l)
 
78
                char    c;
 
79
                long    l;
 
80
#endif
 
81
{
 
82
        register BUF    bp = (BUF)l;
 
83
 
 
84
        *bp->ptr++ = c;
 
85
        if (--bp->cnt <= 0)
 
86
                _bflush(bp);
 
87
}
 
88
 
 
89
/* VARARGS2 */
 
90
#ifdef  PROTOTYPES
 
91
EXPORT int
 
92
printf(const char *form, ...)
 
93
#else
 
94
EXPORT int
 
95
printf(form, va_alist)
 
96
        char    *form;
 
97
        va_dcl
 
98
#endif
 
99
{
 
100
        va_list args;
 
101
        _BUF    bb;
 
102
 
 
103
        bb.ptr = bb.buf;
 
104
        bb.cnt = BFSIZ;
 
105
        bb.count = 0;
 
106
        bb.f = stdout;
 
107
#ifdef  PROTOTYPES
 
108
        va_start(args, form);
 
109
#else
 
110
        va_start(args);
 
111
#endif
 
112
        format(_bput, (long)&bb, form, args);
 
113
        va_end(args);
 
114
        if (bb.cnt < BFSIZ)
 
115
                _bflush(&bb);
 
116
        return (bb.count);
 
117
}
 
118
 
 
119
/* VARARGS3 */
 
120
#ifdef  PROTOTYPES
 
121
EXPORT int
 
122
fprintf(FILE *file, const char *form, ...)
 
123
#else
 
124
EXPORT int
 
125
fprintf(file, form, va_alist)
 
126
        FILE    *file;
 
127
        char    *form;
 
128
        va_dcl
 
129
#endif
 
130
{
 
131
        va_list args;
 
132
        _BUF    bb;
 
133
 
 
134
        bb.ptr = bb.buf;
 
135
        bb.cnt = BFSIZ;
 
136
        bb.count = 0;
 
137
        bb.f = file;
 
138
#ifdef  PROTOTYPES
 
139
        va_start(args, form);
 
140
#else
 
141
        va_start(args);
 
142
#endif
 
143
        format(_bput, (long)&bb, form, args);
 
144
        va_end(args);
 
145
        if (bb.cnt < BFSIZ)
 
146
                _bflush(&bb);
 
147
        return (bb.count);
 
148
}