mescc: Mes C Library: Have write behave well with buffered reads.

* lib/mes/write.c: New file.
* build-aux/configure-lib.sh (libc_mini_SOURCES): Add it.
(libc_mini_shared_SOURCES): New variable.
(libc_mini_SOURCES, libmes_SOURCES): Use it.
(libmes_SOURCES): Add lib/linux/lseek.c, lib/posix/write.c.
(libc_tcc_SOURCES): Remove lib/linux/lseek.c.
* lib/posix/write.c (write): Correct for read buffer.
* lib/stdio/fwrite.c (fwrite): Remove read buffer correction.
* simple.sh: Update.
This commit is contained in:
Jan Nieuwenhuizen 2019-07-28 13:01:37 +02:00
parent ef29ade04b
commit 1bb64ec48f
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
5 changed files with 69 additions and 27 deletions

View File

@ -29,47 +29,60 @@ fi
. ./config.sh
libc_mini_SOURCES="
libc_mini_shared_SOURCES="
lib/mes/eputs.c
lib/mes/oputs.c
"
if test $mes_libc = mes; then
libc_mini_SOURCES="$libc_mini_SOURCES
lib/posix/write.c
lib/string/strlen.c
lib/stdlib/puts.c
lib/stdlib/exit.c
libc_mini_shared_SOURCES="$libc_mini_shared_SOURCES
lib/$mes_kernel/$mes_cpu-mes-$compiler/mini.c
lib/stdlib/exit.c
lib/stdlib/puts.c
lib/string/strlen.c
"
fi
libc_mini_SOURCES="$libc_mini_shared_SOURCES"
if test $mes_libc = mes; then
libc_mini_SOURCES="$libc_mini_SOURCES
lib/mes/write.c
"
fi
libmes_SOURCES="
$libc_mini_SOURCES
$libc_mini_shared_SOURCES
lib/ctype/isnumber.c
lib/mes/abtol.c
lib/mes/itoa.c
lib/mes/ltoa.c
lib/mes/ltoab.c
lib/mes/ultoa.c
lib/mes/utoa.c
lib/mes/eputc.c
lib/mes/fdgetc.c
lib/mes/fdputc.c
lib/mes/fdputs.c
lib/mes/fdungetc.c
lib/mes/itoa.c
lib/mes/ltoa.c
lib/mes/ltoab.c
lib/mes/mes_open.c
lib/mes/ntoab.c
lib/mes/oputc.c
lib/mes/ultoa.c
lib/mes/utoa.c
"
if test $mes_libc = mes; then
libmes_SOURCES="$libmes_SOURCES
lib/stdlib/atoi.c
lib/ctype/isdigit.c
lib/ctype/isspace.c
lib/ctype/isxdigit.c
lib/posix/write.c
lib/stdlib/atoi.c
"
if test $mes_kernel = linux; then
libmes_SOURCES="$libmes_SOURCES
lib/linux/lseek.c
"
fi
else
libmes_SOURCES="$libmes_SOURCES
"
@ -192,7 +205,6 @@ lib/$mes_cpu-mes-$compiler/setjmp.c
if test $mes_kernel = linux; then
libc_tcc_SOURCES="$libc_tcc_SOURCES
lib/linux/close.c
lib/linux/lseek.c
lib/linux/rmdir.c
lib/linux/stat.c
"

36
lib/mes/write.c Normal file
View File

@ -0,0 +1,36 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <errno.h>
ssize_t
write (int filedes, void const *buffer, size_t size)
{
int r = _write (filedes, buffer, size);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}

View File

@ -18,21 +18,17 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib-mini.h>
#include <mes/lib.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
ssize_t
write (int filedes, void const *buffer, size_t size)
{
#if 0 // !MES_MINI
// FIXME: libc-mini has no __buffered_read_clear, lseek.
// and libc includes libc-mini...how to override?
// Let's hope everyone uses fwrite, or lseek for RDWR
// semantics...
size_t skip = __buffered_read_clear (filedes);
if (skip)
lseek (filedes, -skip, SEEK_CUR);
#endif
int r = _write (filedes, buffer, size);
if (r < 0)
{

View File

@ -36,11 +36,7 @@ fwrite (void const *data, size_t size, size_t count, FILE * stream)
if (!size || !count)
return 0;
// FIXME: should be in write, but that's libc-mini.
int filedes = (long) stream;
size_t skip = __buffered_read_clear (filedes);
if (skip)
lseek (filedes, -skip, SEEK_CUR);
int bytes = write (filedes, data, size * count);
if (__mes_debug () > 2)

View File

@ -93,7 +93,7 @@ MES_DEBUG=2 MES=out-system-libc/mes sh -x scripts/mescc -m $mes_bits -nostdlib\
\
lib/linux/$mes_cpu-mes-mescc/mini.c\
\
lib/posix/write.c\
lib/mes/write.c\
lib/string/strlen.c\
\
scaffold/hello.c
@ -197,6 +197,8 @@ $CC -g -D HAVE_CONFIG_H=1 -I include -I include/$mes_kernel/$mes_cpu\
lib/string/strcpy.c\
lib/string/strncmp.c\
\
lib/linux/lseek.c\
\
lib/linux/access.c\
lib/linux/brk.c\
lib/linux/chmod.c\
@ -252,7 +254,7 @@ MES_DEBUG=2 MES=out-mes/mes sh -x scripts/mescc -m $mes_bits -nostdlib\
\
lib/linux/$mes_cpu-mes-mescc/mini.c\
\
lib/posix/write.c\
lib/mes/write.c\
lib/string/strlen.c\
\
scaffold/hello.c