2 A bug in the interface between SDCC and tdlib.
7 #pragma disable_warning 85
8 #pragma disable_warning 196
11 * Dale Schumacher 399 Beacon Ave.
12 * (alias: Dalnefre') St. Paul, MN 55104
13 * dal@syntel.UUCP United States of America
15 * Altered to use stdarg, made the core function vfprintf.
16 * Hooked into the stdio package using 'inside information'
17 * Altered sizeof() assumptions, now assumes all integers except chars
19 * sizeof(xxx) == sizeof(long) or sizeof(xxx) == sizeof(short)
27 typedef unsigned char uchar
;
28 typedef signed long fpos_t;
29 /* when you add or change fields here, be sure to change the initialization
30 * in stdio_init and fopen */
32 uchar
*bufpos
; /* the next byte to write to or read from */
33 uchar
*bufread
; /* the end of data returned by last read() */
34 uchar
*bufwrite
; /* highest address writable by macro */
35 uchar
*bufstart
; /* the start of the buffer */
36 uchar
*bufend
; /* the end of the buffer; ie the byte after
37 the last malloc()ed byte */
38 int fd
; /* the file descriptor associated with the stream */
40 char unbuf
[8]; /* The buffer for 'unbuffered' streams */
41 struct __stdio_file
* next
;
44 typedef struct __stdio_file
FILE;
46 int fputc(int c
, FILE *stream
)
51 int fflush(FILE *stream
)
58 #define __MODE_BUF 0x03
60 extern char *__ltostr(long __value
, int __radix
)
65 extern char *__ultostr(unsigned long value
, int __radix
)
70 #if !defined(__SDCC_pic14) // Pseudo-stack size limit
72 * Output the given field in the manner specified by the arguments. Return
73 * the number of characters output.
75 static int prtfld(FILE * op
, size_t maxlen
, size_t ct
, unsigned char *buf
, int ljustf
, char sign
,
76 char pad
, int width
, int preci
, int buffer_mode
)
81 #if !(defined (__SDCC_mcs51) && defined (__SDCC_MODEL_SMALL)) && !defined (__SDCC_pdk14) && !defined (__SDCC_pdk15)
82 int _vfnprintf(FILE * op
, size_t maxlen
, const char *fmt
, va_list ap
)
84 register int i
, ljustf
, lval
, preci
, dpoint
, width
, radix
, cnt
= 0;
86 register char *ptmp
, *add
;
91 /* This speeds things up a bit for unbuffered */
92 buffer_mode
= (op
->mode
& __MODE_BUF
);
93 op
->mode
&= (~__MODE_BUF
);
96 if (buffer_mode
== _IONBF
)
98 ljustf
= 0; /* left justify flag */
99 sign
= '\0'; /* sign char & status */
100 pad
= ' '; /* justification padding char */
101 width
= -1; /* min field width */
102 dpoint
= 0; /* found decimal point */
103 preci
= -1; /* max data width */
104 radix
= 10; /* number base */
105 ptmp
= tmp
; /* pointer to area to print */
107 lval
= (sizeof(int) == sizeof(long)); /* long value flagged */
108 fmtnxt
:for (i
= 0, ++fmt
;;
110 if (*fmt
< '0' || *fmt
> '9')
116 else if (!i
&& (pad
== ' ')) {
123 case '\0': /* early EOS */
127 case '-': /* left justification */
132 case '+': /* leading sign flag */
140 case '*': /* parameter width value */
144 else if ((width
= i
) < 0) {
150 case '.': /* secondary width field */
154 case 'l': /* long data */
158 case 'h': /* short data */
162 case 'd': /* Signed decimal */
164 ptmp
= __ltostr((long) ((lval
) ?
166 va_arg(ap
, int)), 10);
169 case 'b': /* Unsigned binary */
173 case 'o': /* Unsigned octal */
177 case 'p': /* Pointer */
178 lval
= (sizeof(char *) == sizeof(long));
184 case 'X': /* Unsigned hexadecimal 'ABC' */
188 case 'x': /* Unsigned hexadecimal 'abc' */
192 case 'u': /* Unsigned decimal */
194 val
= lval
? va_arg(ap
, unsigned long) :
195 va_arg(ap
, unsigned int);
196 ptmp
= __ultostr(val
, radix
< 0 ? -radix
: radix
);
201 else if (radix
== 8) {
204 } else if (radix
== 16)
206 else if (radix
== -16)
211 ptmp
= strcat(tmp
, ptmp
);
216 case '!': /* inline Character */
217 if ((i
= fmt
[1]) != 0)
221 case 'c': /* Character */
232 case 's': /* String */
233 ptmp
= va_arg(ap
, char *);
239 prtfld(op
, maxlen
, cnt
, (unsigned char *) ptmp
,
240 ljustf
, sign
, pad
, width
, preci
,
244 default: /* unknown character */
249 /* normal char out */
253 if (*fmt
== '\n' && buffer_mode
== _IOLBF
)
258 op
->mode
|= buffer_mode
;
259 if (buffer_mode
== _IONBF
)
261 if (buffer_mode
== _IOLBF
)
262 op
->bufwrite
= op
->bufstart
;