summaryrefslogtreecommitdiff
path: root/libc/stdio2
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdio2')
-rw-r--r--libc/stdio2/Makefile6
-rw-r--r--libc/stdio2/printf.c35
-rw-r--r--libc/stdio2/stdio.c73
-rw-r--r--libc/stdio2/stdio.h4
4 files changed, 90 insertions, 28 deletions
diff --git a/libc/stdio2/Makefile b/libc/stdio2/Makefile
index ef96567..f77df3a 100644
--- a/libc/stdio2/Makefile
+++ b/libc/stdio2/Makefile
@@ -2,6 +2,10 @@
TOP=..
include $(TOP)/Make.defs
+ifneq ($(LIB_CPU),i86)
+CFLAGS=$(CCFLAGS) $(LIBDEFS) -DFLOATS
+endif
+
ASRC=stdio.c
AOBJ=_stdio_init.o fputc.o fgetc.o fflush.o fgets.o gets.o fputs.o \
puts.o fread.o fwrite.o fopen.o fclose.o fseek.o rewind.o ftell.o \
@@ -28,6 +32,8 @@ transfer:
clean:
rm -f *.o libc.a
+$(OBJ): stdio.h
+
$(AOBJ): $(ASRC)
$(CC) $(CFLAGS) -c -DL_$* -o $@ $(ASRC)
diff --git a/libc/stdio2/printf.c b/libc/stdio2/printf.c
index 0d107a4..5a5744d 100644
--- a/libc/stdio2/printf.c
+++ b/libc/stdio2/printf.c
@@ -115,6 +115,11 @@ static FILE string[1] =
#endif
#ifdef L_vfprintf
+
+#ifdef FLOATS
+int (*__fp_print)() = 0;
+#endif
+
static int
prtfld(op, buf, ljustf, sign, pad, width, preci, buffer_mode)
register FILE *op;
@@ -197,9 +202,6 @@ register va_list ap;
register char *ptmp;
char tmp[64], *ltostr(), *ultostr();
int buffer_mode;
-#if FLOATS
- double fx;
-#endif
/* This speeds things up a bit for unbuffered */
buffer_mode = (op->mode&__MODE_BUF);
@@ -314,18 +316,6 @@ register va_list ap;
hash=1;
goto fmtnxt;
-#if FLOATS
- case 'e': /* float */
- case 'f':
- case 'g':
- case 'E':
- case 'G':
- fx = va_arg(ap, double);
- fp_print(fx, *fmt, preci, ptmp);
- preci = -1;
- goto printit;
-#endif
-
case 'c': /* Character */
ptmp[0] = va_arg(ap, int);
ptmp[1] = '\0';
@@ -341,6 +331,21 @@ register va_list ap;
sign, pad, width, preci, buffer_mode);
break;
+#if FLOATS
+ case 'e': /* float */
+ case 'f':
+ case 'g':
+ case 'E':
+ case 'G':
+ if ( __fp_print )
+ {
+ (*__fp_print)(&va_arg(ap, double), *fmt, preci, ptmp);
+ preci = -1;
+ goto printit;
+ }
+ /* FALLTHROUGH if no floating printf available */
+#endif
+
default: /* unknown character */
goto charout;
}
diff --git a/libc/stdio2/stdio.c b/libc/stdio2/stdio.c
index fa10644..bab246b 100644
--- a/libc/stdio2/stdio.c
+++ b/libc/stdio2/stdio.c
@@ -15,21 +15,29 @@
extern FILE *__IO_list; /* For fflush at exit */
-#ifndef __AS386_16__
-#define Inline_init __io_init_vars()
-#else
+#ifdef __AS386_16__
+#define Inline_init
+#endif
+
+#ifdef __AS386_32__
#define Inline_init
#endif
+#ifndef Inline_init
+#define Inline_init __io_init_vars()
+#endif
+
#ifdef L__stdio_init
+#define buferr (stderr->unbuf) /* Stderr is unbuffered */
+
FILE *__IO_list = 0; /* For fflush at exit */
static char bufin[BUFSIZ];
static char bufout[BUFSIZ];
+#ifndef buferr
static char buferr[BUFSIZ];
-
-/* #define buferr (stderr->unbuf) /* Stderr is unbuffered */
+#endif
FILE stdin[1] =
{
@@ -51,20 +59,32 @@ FILE stderr[1] =
/* Call the stdio initiliser; it's main job it to call atexit */
-#ifndef __AS386_16__
-#define STATIC
-#else
+#ifdef __AS386_16__
#define STATIC static
#asm
loc 1 ! Make sure the pointer is in the correct segment
auto_func: ! Label for bcc -M to work.
.word ___io_init_vars ! Pointer to the autorun function
- .word no_op ! Space filler cause segs are padded to 4 bytes.
.text ! So the function after is also in the correct seg.
#endasm
#endif
+#ifdef __AS386_32__
+#define STATIC static
+
+#asm
+ loc 1 ! Make sure the pointer is in the correct segment
+auto_func: ! Label for bcc -M to work.
+ .long ___io_init_vars ! Pointer to the autorun function
+ .text ! So the function after is also in the correct seg.
+#endasm
+#endif
+
+#ifndef STATIC
+#define STATIC
+#endif
+
STATIC int
__stdio_close_all()
{
@@ -85,9 +105,11 @@ STATIC void
__io_init_vars()
{
#ifndef __AS386_16__
+#ifndef __AS386_32__
static int first_time = 1;
if( !first_time ) return ; first_time = 1;
#endif
+#endif
if (isatty(1))
stdout->mode |= _IOLBF;
atexit(__stdio_close_all);
@@ -483,10 +505,32 @@ long offset;
int ref;
{
/* Use fflush to sync the pointers */
- /*
- * TODO: if __MODE_READING and no ungetc ever done can just move
- * pointer
- */
+
+#if 0
+ /* if __MODE_READING and no ungetc ever done can just move pointer */
+ /* This needs testing! */
+
+ if ( (fp->mode &(__MODE_READING | __MODE_UNGOT)) == __MODE_READING &&
+ ( ref == SEEK_SET || ref == SEEK_CUR )
+ {
+ long fpos = lseek(fp->fd, 0L, SEEK_CUR);
+ if( fpos == -1 ) return EOF;
+
+ if( ref == SEEK_CUR )
+ {
+ ref = SEEK_SET;
+ offset = fpos + offset + fp->bufpos - fp->bufread;
+ }
+ if( ref == SEEK_SET )
+ {
+ if ( offset < fpos && offset >= fpos + fp->bufstart - fp->bufread )
+ {
+ fp->bufpos = offset - fpos + fp->bufread;
+ return 0;
+ }
+ }
+ }
+#endif
if (fflush(fp) == EOF)
return EOF;
@@ -756,6 +800,9 @@ FILE *fp;
if ((fp->mode & (__MODE_READ | __MODE_ERR)) != __MODE_READ)
return EOF;
+ /* Can't do fast fseeks */
+ fp->mode |= __MODE_UNGOT;
+
if( fp->bufpos > fp->bufstart )
return *--fp->bufpos = (unsigned char) c;
else if( fp->bufread == fp->bufstart )
diff --git a/libc/stdio2/stdio.h b/libc/stdio2/stdio.h
index ba70b1d..98ca38a 100644
--- a/libc/stdio2/stdio.h
+++ b/libc/stdio2/stdio.h
@@ -61,7 +61,11 @@ struct __stdio_file {
typedef struct __stdio_file FILE;
+#ifdef __AS386_16__
#define BUFSIZ (256)
+#else
+#define BUFSIZ (2048)
+#endif
extern FILE stdin[1];
extern FILE stdout[1];