Now that printf and scanf contain no FILE*-specific code, we can move them into

core (and split them up).
This commit is contained in:
David Given 2019-06-15 13:53:20 +02:00
parent 9109d7af7f
commit 1387c8713b
36 changed files with 141 additions and 155 deletions

View file

@ -39,6 +39,8 @@ for _, plat in ipairs(vars.plats) do
"./core/math/*.c", "./core/math/*.c",
"./core/math/*.e", "./core/math/*.e",
"./core/misc/*.c", "./core/misc/*.c",
"./core/printf/*.c",
"./core/scanf/*.c",
"./core/setjmp/*.c", "./core/setjmp/*.c",
"./core/setjmp/*.e", "./core/setjmp/*.e",
"./core/stdlib/*.c", "./core/stdlib/*.c",
@ -57,7 +59,6 @@ for _, plat in ipairs(vars.plats) do
"./core/stdlib/ext_fmt.h", "./core/stdlib/ext_fmt.h",
"./core/time/loc_time.h", "./core/time/loc_time.h",
"./sys/malloc/malloc.h", "./sys/malloc/malloc.h",
"./sys/stdio/loc_incl.h",
}, },
vars = { plat = plat } vars = { plat = plat }
} }

View file

@ -7,7 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include "loc_incl.h" #include "doprnt.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO
@ -44,15 +44,13 @@ gnum(register const char* f, int* ip, va_list* app)
#define set_pointer(flags) /* compilation might continue */ #define set_pointer(flags) /* compilation might continue */
#endif #endif
int (*_doprnt_put)(int c);
#define PUTC(c) \ #define PUTC(c) \
do \ do \
{ \ { \
int i = putc(c, stream); \ if (_doprnt_put(c)) \
if (i == EOF) \ return -1; \
{ \
if (ferror(stream)) \
return -1; \
} \
} while (0) } while (0)
/* print an ordinal number */ /* print an ordinal number */
@ -157,7 +155,7 @@ o_print(va_list* ap, int flags, char* s, char c, int precision, int is_signed)
return s; return s;
} }
int _doprnt(register const char* fmt, va_list ap, void (*put)(int)) int _doprnt(register const char* fmt, va_list ap)
{ {
register char* s; register char* s;
register int j; register int j;
@ -176,7 +174,7 @@ int _doprnt(register const char* fmt, va_list ap, void (*put)(int))
PUTC('\r'); PUTC('\r');
} }
#endif #endif
put(c); PUTC(c);
nrchars++; nrchars++;
continue; continue;
} }
@ -263,7 +261,7 @@ int _doprnt(register const char* fmt, va_list ap, void (*put)(int))
nrchars++; nrchars++;
} }
#endif #endif
put(c); PUTC(c);
nrchars++; nrchars++;
continue; continue;
case 'n': case 'n':
@ -366,32 +364,32 @@ int _doprnt(register const char* fmt, va_list ap, void (*put)(int))
{ {
j--; j--;
nrchars++; nrchars++;
put(*s1++); PUTC(*s1++);
} }
else else
{ {
j -= 2; j -= 2;
nrchars += 2; nrchars += 2;
put(*s1++); PUTC(*s1++);
put(*s1++); PUTC(*s1++);
} }
} }
do do
{ {
put(zfill); PUTC(zfill);
} while (--i); } while (--i);
} }
nrchars += j; nrchars += j;
while (--j >= 0) while (--j >= 0)
{ {
put(*s1++); PUTC(*s1++);
} }
if (i > 0) if (i > 0)
nrchars += i; nrchars += i;
while (--i >= 0) while (--i >= 0)
put(zfill); PUTC(zfill);
} }
return nrchars; return nrchars;
} }

View file

@ -1,29 +1,5 @@
/* #ifndef DOPRNT_H
* loc_incl.h - local include file for stdio library #define DOPRNT_H
*/
/* $Id$ */
#include <stdio.h>
#include <ack/config.h>
#define fileno(p) ((p)->_fd)
#define io_testflag(p,x) ((p)->_flags & (x))
#include <stdarg.h>
int _doprnt(const char *format, va_list ap, void (*put)(int c));
int _doscan(const char *format, va_list ap, int (*get)(void), void (*unget)(int c));
char *_i_compute(unsigned long val, int base, char *s, int nrdigits);
char *_f_print(va_list *ap, int flags, char *s, char c, int precision);
extern void __register_stdio_cleanup(void);
FILE *popen(const char *command, const char *type);
FILE *fdopen(int fd, const char *mode);
#if ACKCONF_WANT_STDIO_FLOAT
char *_ecvt(long double value, int ndigit, int *decpt, int *sign);
char *_fcvt(long double value, int ndigit, int *decpt, int *sign);
#endif
#define FL_LJUST 0x0001 /* left-justify field */ #define FL_LJUST 0x0001 /* left-justify field */
#define FL_SIGN 0x0002 /* sign in signed conversions */ #define FL_SIGN 0x0002 /* sign in signed conversions */
@ -38,3 +14,15 @@ char *_fcvt(long double value, int ndigit, int *decpt, int *sign);
#define FL_SIGNEDCONV 0x0400 /* may contain a sign */ #define FL_SIGNEDCONV 0x0400 /* may contain a sign */
#define FL_NOASSIGN 0x0800 /* do not assign (in scanf) */ #define FL_NOASSIGN 0x0800 /* do not assign (in scanf) */
#define FL_NOMORE 0x1000 /* all flags collected */ #define FL_NOMORE 0x1000 /* all flags collected */
extern int (*_doprnt_put)(int c);
extern int _doprnt(register const char* fmt, va_list ap);
extern char* _f_print(va_list* ap, int flags, char* s, char c, int precision);
#if ACKCONF_WANT_STDIO_FLOAT
char *_ecvt(long double value, int ndigit, int *decpt, int *sign);
char *_fcvt(long double value, int ndigit, int *decpt, int *sign);
#endif
#endif

View file

@ -5,7 +5,7 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h" #include "doprnt.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_STDIO_FLOAT #if ACKCONF_WANT_STDIO && ACKCONF_WANT_STDIO_FLOAT

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -3,7 +3,7 @@
*/ */
/* $Id$ */ /* $Id$ */
#include "loc_incl.h" #include <stdio.h>
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -0,0 +1,23 @@
/*
* sprintf - print formatted output on an array
*/
/* $Id$ */
#include <stdio.h>
#include <stdarg.h>
#if ACKCONF_WANT_STDIO
int snprintf(char* s, size_t len, const char* format, ...)
{
va_list ap;
int retval;
va_start(ap, format);
retval = vsnprintf(s, len, format, ap);
va_end(ap);
return retval;
}
#endif

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -5,21 +5,23 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h" #include "doprnt.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO
static FILE* vfprintf_stream; static FILE* vfprintf_stream;
static void vfprintf_putc(int c) static int vfprintf_putc(int c)
{ {
putc(c, vfprintf_stream); putc(c, vfprintf_stream);
return ferror(vfprintf_stream);
} }
int vfprintf(FILE* stream, const char* format, va_list arg) int vfprintf(FILE* stream, const char* format, va_list arg)
{ {
vfprintf_stream = stream; vfprintf_stream = stream;
return _doprnt(format, arg, vfprintf_putc); _doprnt_put = vfprintf_putc;
return _doprnt(format, arg);
} }
#endif #endif

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -5,20 +5,21 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h" #include "doprnt.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO
static char* output_buffer; static char* output_buffer;
static size_t output_buffer_len; static size_t output_buffer_len;
static void snprintf_putc(int c) static int snprintf_putc(int c)
{ {
if (output_buffer_len) if (output_buffer_len)
{ {
*output_buffer++ = c; *output_buffer++ = c;
output_buffer_len--; output_buffer_len--;
} }
return 0;
} }
int vsnprintf(char* s, size_t len, const char* format, va_list ap) int vsnprintf(char* s, size_t len, const char* format, va_list ap)
@ -27,7 +28,8 @@ int vsnprintf(char* s, size_t len, const char* format, va_list ap)
output_buffer = s; output_buffer = s;
output_buffer_len = len; output_buffer_len = len;
retval = _doprnt(format, ap, snprintf_putc); _doprnt_put = snprintf_putc;
retval = _doprnt(format, ap);
snprintf_putc('\0'); snprintf_putc('\0');
return retval; return retval;

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -7,7 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h" #include "doscan.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO
@ -26,14 +26,16 @@
static char Xtable[NR_CHARS]; static char Xtable[NR_CHARS];
static char inp_buf[NUMLEN]; static char inp_buf[NUMLEN];
int (*_doscan_get)(void);
void (*_doscan_unget)(int c);
/* Collect a number of characters which constitite an ordinal number. /* Collect a number of characters which constitite an ordinal number.
* When the type is 'i', the base can be 8, 10, or 16, depending on the * When the type is 'i', the base can be 8, 10, or 16, depending on the
* first 1 or 2 characters. This means that the base must be adjusted * first 1 or 2 characters. This means that the base must be adjusted
* according to the format of the number. At the end of the function, base * according to the format of the number. At the end of the function, base
* is then set to 0, so strtol() will get the right argument. * is then set to 0, so strtol() will get the right argument.
*/ */
static char* static char* o_collect(register int c, char type, int width, int* basep)
o_collect(register int c, char type, int width, int* basep, int (*get)(void), void (*unget)(int c))
{ {
register char* bufp = inp_buf; register char* bufp = inp_buf;
register int base; register int base;
@ -62,14 +64,14 @@ o_collect(register int c, char type, int width, int* basep, int (*get)(void), vo
{ {
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
} }
if (width && c == '0' && base == 16) if (width && c == '0' && base == 16)
{ {
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
if (c != 'x' && c != 'X') if (c != 'x' && c != 'X')
{ {
if (type == 'i') if (type == 'i')
@ -79,7 +81,7 @@ o_collect(register int c, char type, int width, int* basep, int (*get)(void), vo
{ {
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
} }
} }
else if (type == 'i') else if (type == 'i')
@ -94,14 +96,14 @@ o_collect(register int c, char type, int width, int* basep, int (*get)(void), vo
{ {
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
} }
else else
break; break;
} }
if (width && c != EOF) if (width && c != EOF)
unget(c); _doscan_unget(c);
if (type == 'i') if (type == 'i')
base = 0; base = 0;
*basep = base; *basep = base;
@ -118,8 +120,7 @@ o_collect(register int c, char type, int width, int* basep, int (*get)(void), vo
* not necessary, although the use of the width field can cause incomplete * not necessary, although the use of the width field can cause incomplete
* numbers to be passed to strtod(). (e.g. 1.3e+) * numbers to be passed to strtod(). (e.g. 1.3e+)
*/ */
static char* static char* f_collect(register int c, register int width)
f_collect(register int c, register int width, int (*get)(void), void (*unget)(int c))
{ {
register char* bufp = inp_buf; register char* bufp = inp_buf;
int digit_seen = 0; int digit_seen = 0;
@ -128,7 +129,7 @@ f_collect(register int c, register int width, int (*get)(void), void (*unget)(in
{ {
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
} }
while (width && isdigit(c)) while (width && isdigit(c))
@ -136,26 +137,26 @@ f_collect(register int c, register int width, int (*get)(void), void (*unget)(in
digit_seen++; digit_seen++;
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
} }
if (width && c == '.') if (width && c == '.')
{ {
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
while (width && isdigit(c)) while (width && isdigit(c))
{ {
digit_seen++; digit_seen++;
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
} }
} }
if (!digit_seen) if (!digit_seen)
{ {
if (width && c != EOF) if (width && c != EOF)
unget(c); _doscan_unget(c);
return inp_buf - 1; return inp_buf - 1;
} }
else else
@ -165,30 +166,30 @@ f_collect(register int c, register int width, int (*get)(void), void (*unget)(in
{ {
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
if (width && (c == '+' || c == '-')) if (width && (c == '+' || c == '-'))
{ {
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
} }
while (width && isdigit(c)) while (width && isdigit(c))
{ {
digit_seen++; digit_seen++;
*bufp++ = c; *bufp++ = c;
if (--width) if (--width)
c = get(); c = _doscan_get();
} }
if (!digit_seen) if (!digit_seen)
{ {
if (width && c != EOF) if (width && c != EOF)
unget(c); _doscan_unget(c);
return inp_buf - 1; return inp_buf - 1;
} }
} }
if (width && c != EOF) if (width && c != EOF)
unget(c); _doscan_unget(c);
*bufp = '\0'; *bufp = '\0';
return bufp - 1; return bufp - 1;
} }
@ -198,7 +199,7 @@ f_collect(register int c, register int width, int (*get)(void), void (*unget)(in
* the routine that does the scanning * the routine that does the scanning
*/ */
int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int c)) int _doscan(const char* format, va_list ap)
{ {
int done = 0; /* number of items done */ int done = 0; /* number of items done */
int nrchars = 0; /* number of characters read */ int nrchars = 0; /* number of characters read */
@ -225,15 +226,15 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
{ {
while (isspace(*format)) while (isspace(*format))
format++; /* skip whitespace */ format++; /* skip whitespace */
ic = get(); ic = _doscan_get();
nrchars++; nrchars++;
while (isspace(ic)) while (isspace(ic))
{ {
ic = get(); ic = _doscan_get();
nrchars++; nrchars++;
} }
if (ic != EOF) if (ic != EOF)
unget(ic); _doscan_unget(ic);
nrchars--; nrchars--;
} }
if (!*format) if (!*format)
@ -241,12 +242,12 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
if (*format != '%') if (*format != '%')
{ {
ic = get(); ic = _doscan_get();
nrchars++; nrchars++;
if (ic != *format++) if (ic != *format++)
{ {
if (ic != EOF) if (ic != EOF)
unget(ic); _doscan_unget(ic);
nrchars--; nrchars--;
break; /* error */ break; /* error */
} }
@ -255,7 +256,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
format++; format++;
if (*format == '%') if (*format == '%')
{ {
ic = get(); ic = _doscan_get();
nrchars++; nrchars++;
if (ic == '%') if (ic == '%')
{ {
@ -298,7 +299,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
{ {
do do
{ {
ic = get(); ic = _doscan_get();
nrchars++; nrchars++;
} while (isspace(ic)); } while (isspace(ic));
if (ic == EOF) if (ic == EOF)
@ -306,7 +307,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
} }
else if (kind != 'n') else if (kind != 'n')
{ /* %c or %[ */ { /* %c or %[ */
ic = get(); ic = _doscan_get();
if (ic == EOF) if (ic == EOF)
break; /* outer while */ break; /* outer while */
nrchars++; nrchars++;
@ -343,7 +344,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
if (!width) if (!width)
return done; return done;
str = o_collect(ic, kind, width, &base, get, unget); str = o_collect(ic, kind, width, &base);
if (str < inp_buf if (str < inp_buf
|| (str == inp_buf || (str == inp_buf
&& (*str == '-' && (*str == '-'
@ -384,7 +385,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
*str++ = (char)ic; *str++ = (char)ic;
if (--width) if (--width)
{ {
ic = get(); ic = _doscan_get();
nrchars++; nrchars++;
} }
} }
@ -392,7 +393,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
if (width) if (width)
{ {
if (ic != EOF) if (ic != EOF)
unget(ic); _doscan_unget(ic);
nrchars--; nrchars--;
} }
break; break;
@ -410,7 +411,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
*str++ = (char)ic; *str++ = (char)ic;
if (--width) if (--width)
{ {
ic = get(); ic = _doscan_get();
nrchars++; nrchars++;
} }
} }
@ -420,7 +421,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
if (width) if (width)
{ {
if (ic != EOF) if (ic != EOF)
unget(ic); _doscan_unget(ic);
nrchars--; nrchars--;
} }
break; break;
@ -467,7 +468,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
if (!*format || !(Xtable[ic] ^ reverse)) if (!*format || !(Xtable[ic] ^ reverse))
{ {
if (ic != EOF) if (ic != EOF)
unget(ic); _doscan_unget(ic);
return done; return done;
} }
@ -480,7 +481,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
*str++ = (char)ic; *str++ = (char)ic;
if (--width) if (--width)
{ {
ic = get(); ic = _doscan_get();
nrchars++; nrchars++;
} }
} while (width && ic != EOF && (Xtable[ic] ^ reverse)); } while (width && ic != EOF && (Xtable[ic] ^ reverse));
@ -488,7 +489,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
if (width) if (width)
{ {
if (ic != EOF) if (ic != EOF)
unget(ic); _doscan_unget(ic);
nrchars--; nrchars--;
} }
if (!(flags & FL_NOASSIGN)) if (!(flags & FL_NOASSIGN))
@ -507,7 +508,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int
if (!width) if (!width)
return done; return done;
str = f_collect(ic, width, get, unget); str = f_collect(ic, width);
if (str < inp_buf if (str < inp_buf
|| (str == inp_buf || (str == inp_buf

View file

@ -0,0 +1,23 @@
#ifndef DOSCAN_H
#define DOSCAN_H
#define FL_LJUST 0x0001 /* left-justify field */
#define FL_SIGN 0x0002 /* sign in signed conversions */
#define FL_SPACE 0x0004 /* space in signed conversions */
#define FL_ALT 0x0008 /* alternate form */
#define FL_ZEROFILL 0x0010 /* fill with zero's */
#define FL_SHORT 0x0020 /* optional h */
#define FL_LONG 0x0040 /* optional l */
#define FL_LONGDOUBLE 0x0080 /* optional L */
#define FL_WIDTHSPEC 0x0100 /* field width is specified */
#define FL_PRECSPEC 0x0200 /* precision is specified */
#define FL_SIGNEDCONV 0x0400 /* may contain a sign */
#define FL_NOASSIGN 0x0800 /* do not assign (in scanf) */
#define FL_NOMORE 0x1000 /* all flags collected */
extern int (*_doscan_get)(void);
extern void (*_doscan_unget)(int c);
extern int _doscan(const char* format, va_list ap);
#endif

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -6,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include "loc_incl.h" #include "doscan.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO
@ -35,7 +35,9 @@ int sscanf(const char* s, const char* format, ...)
va_start(ap, format); va_start(ap, format);
input_buffer = s; input_buffer = s;
retval = _doscan(format, ap, sscanf_getc, sscanf_ungetc); _doscan_get = sscanf_getc;
_doscan_unget = sscanf_ungetc;
retval = _doscan(format, ap);
va_end(ap); va_end(ap);

View file

@ -5,7 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "loc_incl.h" #include "doscan.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO
@ -24,7 +24,9 @@ static void vfscanf_ungetc(int c)
int vfscanf(FILE* stream, const char* format, va_list ap) int vfscanf(FILE* stream, const char* format, va_list ap)
{ {
vfscanf_stream = stream; vfscanf_stream = stream;
return _doscan(format, ap, vfscanf_getc, vfscanf_ungetc); _doscan_get = vfscanf_getc;
_doscan_unget = vfscanf_ungetc;
return _doscan(format, ap);
} }
#endif #endif

View file

@ -56,4 +56,7 @@ extern int fileno(FILE *_stream);
extern FILE* fdopen(int fildes, const char *type); extern FILE* fdopen(int fildes, const char *type);
#define fileno(stream) ((stream)->_fd) #define fileno(stream) ((stream)->_fd)
#define io_testflag(p,x) ((p)->_flags & (x))
extern void __register_stdio_cleanup(void);
#endif #endif

View file

@ -76,6 +76,9 @@ extern int feof(FILE *_stream);
extern int ferror(FILE *_stream); extern int ferror(FILE *_stream);
extern void perror(const char *_s); extern void perror(const char *_s);
/* Internal function used by several places which is approximately itoa(). */
extern char *_i_compute(unsigned long val, int base, char *s, int nrdigits);
#if ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_EMULATED_FILE
#include <ack/emufile.h> #include <ack/emufile.h>
#else #else

View file

@ -6,7 +6,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../stdio/loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -6,7 +6,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -6,7 +6,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -6,7 +6,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -8,7 +8,6 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -7,7 +7,6 @@
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -6,7 +6,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -6,7 +6,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -4,7 +4,6 @@
/* $Id$ */ /* $Id$ */
#include <stdio.h> #include <stdio.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE

View file

@ -1,41 +0,0 @@
/*
* sprintf - print formatted output on an array
*/
/* $Id$ */
#include <stdio.h>
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
static char* output_buffer;
static size_t output_buffer_len;
static void snprintf_putc(int c)
{
if (output_buffer_len)
{
*output_buffer++ = c;
output_buffer_len--;
}
}
int snprintf(char* s, size_t len, const char* format, ...)
{
va_list ap;
int retval;
va_start(ap, format);
output_buffer = s;
output_buffer_len = len;
retval = _doprnt(format, ap, snprintf_putc);
snprintf_putc('\0');
va_end(ap);
return retval;
}
#endif

View file

@ -7,7 +7,6 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -7,7 +7,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO #if ACKCONF_WANT_STDIO

View file

@ -4,7 +4,6 @@
/* $Id$ */ /* $Id$ */
#include <stdio.h> #include <stdio.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE