Move stdio into (mostly) sys.

This commit is contained in:
David Given 2018-06-23 18:54:40 +02:00
parent af22b7ea85
commit 6a729b846a
58 changed files with 183 additions and 66 deletions

View file

@ -45,6 +45,7 @@ for _, plat in ipairs(vars.plats) do
"./core/misc/*.c",
"./sys/malloc/*.c",
"./sys/exit/*.c",
"./sys/stdio/*.c",
"./assert/*.c",
"./stdio/*.c",
"./stdlib/*.c",
@ -60,7 +61,7 @@ for _, plat in ipairs(vars.plats) do
"./sys/malloc/malloc.h",
"./core/math/localmath.h",
"./core/stdlib/ext_fmt.h",
"./stdio/loc_incl.h",
"./sys/stdio/loc_incl.h",
"./time/loc_time.h",
},
vars = { plat = plat }

View file

@ -4,7 +4,6 @@
/* $Id$ */
#include <stdio.h>
#include "loc_incl.h"
void rewind(FILE* stream)
{

View file

@ -34,4 +34,8 @@
#define ACKCONF_WANT_MALLOC 1
#endif
#ifndef ACKCONF_WANT_STDIO
#define ACKCONF_WANT_STDIO 1
#endif
#endif

View file

@ -9,6 +9,7 @@
#ifndef _STDDEF_H
#define _STDDEF_H
#include <ack/config.h>
#include <stdint.h>
#define NULL 0

View file

@ -1,52 +0,0 @@
loc_incl.h
tmpfile.c
tmpnam.c
rename.c
remove.c
fopen.c
freopen.c
setbuf.c
setvbuf.c
perror.c
fprintf.c
printf.c
sprintf.c
vfprintf.c
vprintf.c
vsprintf.c
doprnt.c
icompute.c
fscanf.c
scanf.c
sscanf.c
doscan.c
fgetc.c
fgets.c
getc.c
getchar.c
gets.c
putc.c
putchar.c
fputc.c
puts.c
fputs.c
ungetc.c
fread.c
fwrite.c
fgetpos.c
fsetpos.c
rewind.c
fseek.c
ftell.c
clearerr.c
feof.c
ferror.c
fileno.c
fltpr.c
ecvt.c
fillbuf.c
fclose.c
flushbuf.c
fflush.c
isatty.c
data.c

View file

@ -1,10 +0,0 @@
clean:
rm -f tmpfile.o tmpnam.o rename.o remove.o fopen.o freopen.o \
setbuf.o setvbuf.o perror.o fprintf.o printf.o sprintf.o \
vfprintf.o vprintf.o vsprintf.o doprnt.o icompute.o \
fscanf.o scanf.o sscanf.o doscan.o fgetc.o fgets.o getc.o \
getchar.o gets.o putc.o putchar.o fputc.o puts.o fputs.o \
ungetc.o fread.o fwrite.o fgetpos.o fsetpos.o rewind.o \
fseek.o ftell.o clearerr.o feof.o ferror.o fileno.o \
fltpr.o ecvt.o gcvt.o fillbuf.o fclose.o flushbuf.o \
fflush.o isatty.o data.o OLIST

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
void(clearerr)(FILE* stream)
{
clearerr(stream);
}
#endif

View file

@ -5,6 +5,8 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
struct __iobuf __stdin = {
0, 0, _IOREAD, 0,
(unsigned char*)NULL, (unsigned char*)NULL,
@ -26,3 +28,5 @@ FILE* __iotab[FOPEN_MAX] = {
&__stderr,
0
};
#endif

View file

@ -9,6 +9,8 @@
#include <string.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
/* gnum() is used to get the width and precision fields of a format. */
static const char*
gnum(register const char* f, int* ip, va_list* app)
@ -393,3 +395,5 @@ int _doprnt(register const char* fmt, va_list ap, FILE* stream)
}
return nrchars;
}
#endif

View file

@ -9,6 +9,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
#if _EM_WSIZE == _EM_PSIZE
#define set_pointer(flags) /* nothing */
#elif _EM_LSIZE == _EM_PSIZE
@ -540,3 +542,5 @@ int _doscan(register FILE* stream, const char* format, va_list ap)
}
return conv || (ic != EOF) ? done : EOF;
}
#endif

View file

@ -8,6 +8,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int fclose(FILE* fp)
{
register int i, retval = 0;
@ -30,3 +32,5 @@ int fclose(FILE* fp)
free((void*)fp);
return retval;
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdlib.h>
#include "../stdio/loc_incl.h"
#if ACKCONF_WANT_STDIO
FILE* fdopen(int fd, const char* mode)
{
register int i;
@ -63,3 +65,5 @@ FILE* fdopen(int fd, const char* mode)
__iotab[i] = stream;
return stream;
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int(feof)(FILE* stream)
{
return feof(stream);
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int(ferror)(FILE* stream)
{
return ferror(stream);
}
#endif

View file

@ -8,6 +8,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int fflush(FILE* stream)
{
int count, c1, i, retval = 0;
@ -86,3 +88,5 @@ void __register_stdio_cleanup(void)
atexit(cleanup);
}
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int fgetc(FILE* stream)
{
return getc(stream);
}
#endif

View file

@ -5,6 +5,8 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
char* fgets(char* s, register int n, register FILE* stream)
{
register int ch;
@ -30,3 +32,5 @@ char* fgets(char* s, register int n, register FILE* stream)
*ptr = '\0';
return s;
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int(fileno)(FILE* stream)
{
return stream->_fd;
}
#endif

View file

@ -8,6 +8,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int __fillbuf(register FILE* stream)
{
static unsigned char ch[FOPEN_MAX];
@ -77,3 +79,5 @@ int __fillbuf(register FILE* stream)
return *stream->_ptr++;
}
#endif

View file

@ -7,7 +7,7 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO_FLOAT
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_STDIO_FLOAT
static char*
_pfloat(long double r, register char* s, int n, int flags)

View file

@ -8,6 +8,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
static int
do_write(int d, char* buf, int nbytes)
{
@ -148,3 +150,5 @@ int __flushbuf(int c, FILE* stream)
}
return (unsigned char)c;
}
#endif

View file

@ -10,6 +10,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
#define PMODE 0666
/* Since the O_CREAT flag is not available on all systems, we can't get it
@ -112,3 +114,5 @@ FILE* fopen(const char* name, const char* mode)
__iotab[i] = stream;
return stream;
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int fprintf(FILE* stream, const char* format, ...)
{
va_list ap;
@ -20,3 +22,5 @@ int fprintf(FILE* stream, const char* format, ...)
return retval;
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int fputc(int c, FILE* stream)
{
return putc(c, stream);
}
#endif

View file

@ -5,6 +5,8 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int fputs(register const char* s, register FILE* stream)
{
register int i = 0;
@ -17,3 +19,5 @@ int fputs(register const char* s, register FILE* stream)
return i;
}
#endif

View file

@ -5,6 +5,8 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
size_t
fread(void* ptr, size_t size, size_t nmemb, register FILE* stream)
{
@ -29,3 +31,5 @@ fread(void* ptr, size_t size, size_t nmemb, register FILE* stream)
return ndone;
}
#endif

View file

@ -9,6 +9,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
#define PMODE 0666
/* Do not "optimize" this file to use the open with O_CREAT if the file
@ -92,3 +94,5 @@ FILE* freopen(const char* name, const char* mode, FILE* stream)
stream->_flags = flags;
return stream;
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int fscanf(FILE* stream, const char* format, ...)
{
va_list ap;
@ -20,3 +22,5 @@ int fscanf(FILE* stream, const char* format, ...)
return retval;
}
#endif

View file

@ -8,6 +8,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int fseek(FILE* stream, long int offset, int whence)
{
int adjust = 0;
@ -38,3 +40,5 @@ int fseek(FILE* stream, long int offset, int whence)
stream->_ptr = stream->_buf;
return ((pos == -1) ? -1 : 0);
}
#endif

View file

@ -8,6 +8,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
long ftell(FILE* stream)
{
long result;
@ -30,3 +32,5 @@ long ftell(FILE* stream)
result += (long)adjust;
return result;
}
#endif

View file

@ -5,6 +5,8 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
size_t
fwrite(const void* ptr, size_t size, size_t nmemb,
register FILE* stream)
@ -28,3 +30,5 @@ fwrite(const void* ptr, size_t size, size_t nmemb,
}
return ndone;
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int(getc)(FILE* stream)
{
return getc(stream);
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int(getchar)(void)
{
return getchar();
}
#endif

View file

@ -5,6 +5,8 @@
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
/* This routine is used in doprnt.c as well as in tmpfile.c and tmpnam.c. */
char* _i_compute(unsigned long val, int base, char* s, int nrdigits)
@ -18,3 +20,5 @@ char* _i_compute(unsigned long val, int base, char* s, int nrdigits)
*s++ = (c > 9 ? c - 10 + 'a' : c + '0');
return s;
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int printf(const char* format, ...)
{
va_list ap;
@ -20,3 +22,5 @@ int printf(const char* format, ...)
return retval;
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int(putc)(int c, FILE* stream)
{
return putc(c, stream);
}
#endif

View file

@ -5,7 +5,11 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int(putchar)(int c)
{
return putchar(c);
}
#endif

View file

@ -5,6 +5,8 @@
#include <stdio.h>
#if ACKCONF_WANT_STDIO
int puts(register const char* s)
{
register FILE* file = stdout;
@ -21,3 +23,5 @@ int puts(register const char* s)
return EOF;
return i + 1;
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int scanf(const char* format, ...)
{
va_list ap;
@ -20,3 +22,5 @@ int scanf(const char* format, ...)
return retval;
}
#endif

View file

@ -6,7 +6,11 @@
#include <stdio.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
void setbuf(register FILE* stream, char* buf)
{
(void)setvbuf(stream, buf, (buf ? _IOFBF : _IONBF), (size_t)BUFSIZ);
}
#endif

View file

@ -7,7 +7,7 @@
#include <stdlib.h>
#include "loc_incl.h"
extern void (*_clean)(void);
#if ACKCONF_WANT_STDIO
int setvbuf(register FILE* stream, char* buf, int mode, size_t size)
{
@ -53,3 +53,5 @@ int setvbuf(register FILE* stream, char* buf, int mode, size_t size)
return retval;
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int snprintf(char* s, size_t len, const char* format, ...)
{
va_list ap;
@ -28,3 +30,5 @@ int snprintf(char* s, size_t len, const char* format, ...)
return retval;
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int sprintf(char* s, const char* format, ...)
{
va_list ap;
@ -28,3 +30,5 @@ int sprintf(char* s, const char* format, ...)
return retval;
}
#endif

View file

@ -8,6 +8,8 @@
#include <string.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int sscanf(const char* s, const char* format, ...)
{
va_list ap;
@ -28,3 +30,5 @@ int sscanf(const char* s, const char* format, ...)
return retval;
}
#endif

View file

@ -9,6 +9,8 @@
#include <string.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
FILE* tmpfile(void)
{
static char name_buffer[L_tmpnam] = "/tmp/tmp.";
@ -28,3 +30,5 @@ FILE* tmpfile(void)
(void)remove(name_buffer);
return file;
}
#endif

View file

@ -9,6 +9,8 @@
#include <unistd.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
char* tmpnam(char* s)
{
static char name_buffer[L_tmpnam] = "/tmp/tmp.";
@ -30,3 +32,5 @@ char* tmpnam(char* s)
else
return name_buffer;
}
#endif

View file

@ -6,6 +6,8 @@
#include <stdio.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int ungetc(int ch, FILE* stream)
{
unsigned char* p;
@ -25,3 +27,5 @@ int ungetc(int ch, FILE* stream)
*p = (unsigned char)ch;
return ch;
}
#endif

View file

@ -7,7 +7,11 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int vfprintf(FILE* stream, const char* format, va_list arg)
{
return _doprnt(format, arg, stream);
}
#endif

View file

@ -7,7 +7,11 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int vprintf(const char* format, va_list arg)
{
return _doprnt(format, arg, stdout);
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int vsnprintf(char* s, size_t len, const char* format, va_list arg)
{
int retval;
@ -23,3 +25,5 @@ int vsnprintf(char* s, size_t len, const char* format, va_list arg)
return retval;
}
#endif

View file

@ -7,6 +7,8 @@
#include <stdarg.h>
#include "loc_incl.h"
#if ACKCONF_WANT_STDIO
int vsprintf(char* s, const char* format, va_list arg)
{
int retval;
@ -23,3 +25,5 @@ int vsprintf(char* s, const char* format, va_list arg)
return retval;
}
#endif