[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fpurge.c on Plan9/APE
From: |
Bruno Haible |
Subject: |
Re: fpurge.c on Plan9/APE |
Date: |
Fri, 03 Feb 2012 23:08:26 +0100 |
User-agent: |
KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; ) |
Jens Staal wrote:
> I think the problem basically is that I do not fully understand what is
> done in all those other OSes defined in fpurge.c and what is expected
> from this function....
Yes, it's not easy to understand the various stdioext operations.
Here is a tentative port to Plan9. Before you can assume that it is usable
for GNU m4 or GNU coreutils, you need to run the testsuite, though.
I have prepared a testdir for you, through
$ ./gnulib-tool --create-testdir --dir=/tmp/testdir-stdioext \
--with-tests --single-configure \
fseterr freadable fwritable fbufmode freading fwriting freadptr \
freadseek freadahead fpurge fseeko ftello fpending
Please download it from
http://www.haible.de/bruno/gnu/testdir-stdioext.tar.gz
and report the test suite results from
$ ./configure
$ make
$ make check
2012-02-03 Bruno Haible <address@hidden>
stdioext: Add tentative support for Plan9.
* lib/stdio-impl.h: Include <errno.h>.
* lib/fseterr.c (fseterr) [EPLAN9]: Add conditional code.
* lib/freadable.c (freadable): Likewise.
* lib/fwritable.c (fwritable): Likewise.
* lib/fbufmode.c (fbufmode): Likewise.
* lib/freading.c (freading): Likewise.
* lib/fwriting.c (fwriting): Likewise.
* lib/freadptr.c (freadptr): Likewise.
* lib/freadseek.c (freadptrinc): Likewise.
* lib/freadahead.c (freadahead): Likewise.
* lib/fpurge.c (fpurge): Likewise.
* lib/fseeko.c (rpl_fseeko): Likewise.
* m4/fpending.m4 (gl_PREREQ_FPENDING): Add a variant for Plan9.
Reported by Jens Staal <address@hidden>.
--- lib/fbufmode.c.orig Fri Feb 3 22:54:04 2012
+++ lib/fbufmode.c Fri Feb 3 21:30:15 2012
@@ -79,6 +79,12 @@
if (fp->__linebuf)
return _IOLBF;
return (fp->__bufsize > 0 ? _IOFBF : _IONBF);
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->flags & 2 /* LINEBUF */)
+ return _IOLBF;
+ if (fp->bufl)
+ return _IOFBF;
+ return _IONBF;
#else
# error "Please port gnulib fbufmode.c to your platform! Look at the setvbuf
implementation."
#endif
--- lib/fpurge.c.orig Fri Feb 3 22:54:04 2012
+++ lib/fpurge.c Fri Feb 3 22:30:44 2012
@@ -134,6 +134,9 @@
/* Nothing in the buffer, next putc is nontrivial. */
fp->__put_limit = fp->__buffer;
return 0;
+# elif defined EPLAN9 /* Plan9 */
+ fp->rp = fp->wp = fp->lp = fp->buf;
+ return 0;
# else
# error "Please port gnulib fpurge.c to your platform! Look at the
definitions of fflush, setvbuf and ungetc on your system, then report this to
bug-gnulib."
# endif
--- lib/freadable.c.orig Fri Feb 3 22:54:04 2012
+++ lib/freadable.c Fri Feb 3 21:25:10 2012
@@ -21,6 +21,10 @@
#include "stdio-impl.h"
+#if defined EPLAN9 /* Plan9 */
+# include <fcntl.h>
+#endif
+
bool
freadable (FILE *fp)
{
@@ -41,6 +45,18 @@
return (fp->_Mode & 0x1 /* _MOPENR */) != 0;
#elif defined __MINT__ /* Atari FreeMiNT */
return fp->__mode.__read;
+#elif defined EPLAN9 /* Plan9 */
+ int fd = fp->fd;
+ if (fd >= 0)
+ {
+ int flags = fcntl (fd, F_GETFL, NULL);
+ if (flags >= 0)
+ {
+ flags &= O_ACCMODE;
+ return (flags == O_RDONLY || flags == O_RDWR);
+ }
+ }
+ return 0;
#else
# error "Please port gnulib freadable.c to your platform! Look at the
definition of fopen, fdopen on your system, then report this to bug-gnulib."
#endif
--- lib/freadahead.c.orig Fri Feb 3 22:54:04 2012
+++ lib/freadahead.c Fri Feb 3 22:21:18 2012
@@ -80,6 +80,10 @@
return (fp->__pushed_back
? fp->__get_limit - fp->__pushback_bufp + 1
: fp->__get_limit - fp->__bufp);
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->state == 4 /* WR */ || fp->rp >= fp->wp)
+ return 0;
+ return fp->wp - fp->rp;
#elif defined SLOW_BUT_NO_HACKS /* users can define this */
abort ();
return 0;
--- lib/freading.c.orig Fri Feb 3 22:54:04 2012
+++ lib/freading.c Fri Feb 3 22:01:21 2012
@@ -62,6 +62,10 @@
# else
return (fp->__buffer < fp->__get_limit /*|| fp->__bufp == fp->__put_limit
??*/);
# endif
+# elif defined EPLAN9 /* Plan9 */
+ if (fp->state == 0 /* CLOSED */ || fp->state == 4 /* WR */)
+ return 0;
+ return (fp->state == 3 /* RD */ && (fp->bufl == 0 || fp->rp < fp->wp));
# else
# error "Please port gnulib freading.c to your platform!"
# endif
--- lib/freadptr.c.orig Fri Feb 3 22:54:04 2012
+++ lib/freadptr.c Fri Feb 3 22:06:58 2012
@@ -101,6 +101,13 @@
return NULL;
*sizep = size;
return fp->__bufp;
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->state == 4 /* WR */)
+ return NULL;
+ if (fp->rp >= fp->wp)
+ return NULL;
+ *sizep = fp->wp - fp->rp;
+ return fp->rp;
#elif defined SLOW_BUT_NO_HACKS /* users can define this */
/* This implementation is correct on any ANSI C platform. It is just
awfully slow. */
--- lib/freadseek.c.orig Fri Feb 3 22:54:04 2012
+++ lib/freadseek.c Fri Feb 3 22:07:42 2012
@@ -58,6 +58,8 @@
fp->_Next += increment;
#elif defined __MINT__ /* Atari FreeMiNT */
fp->__bufp += increment;
+#elif defined EPLAN9 /* Plan9 */
+ fp->rp += increment;
#elif defined SLOW_BUT_NO_HACKS /* users can define this */
#else
#error "Please port gnulib freadseek.c to your platform! Look at the
definition of getc, getc_unlocked on your system, then report this to
bug-gnulib."
--- lib/fseeko.c.orig Fri Feb 3 22:54:04 2012
+++ lib/fseeko.c Fri Feb 3 22:41:25 2012
@@ -89,6 +89,9 @@
&& fp->__get_limit == fp->__bufp
&& fp->__put_limit == fp->__bufp
&& !fp->__pushed_back)
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->rp == fp->buf
+ && fp->wp == fp->buf)
#else
#error "Please port gnulib fseeko.c to your platform! Look at the code in
fpurge.c, then report this to bug-gnulib."
#endif
--- lib/fseterr.c.orig Fri Feb 3 22:54:04 2012
+++ lib/fseterr.c Fri Feb 3 21:10:30 2012
@@ -45,6 +45,9 @@
fp->_Mode |= 0x200 /* _MERR */;
#elif defined __MINT__ /* Atari FreeMiNT */
fp->__error = 1;
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->state != 0 /* CLOSED */)
+ fp->state = 5 /* ERR */;
#elif 0 /* unknown */
/* Portable fallback, based on an idea by Rich Felker.
Wow! 6 system calls for something that is just a bit operation!
--- lib/fwritable.c.orig Fri Feb 3 22:54:04 2012
+++ lib/fwritable.c Fri Feb 3 21:24:52 2012
@@ -41,6 +41,18 @@
return (fp->_Mode & 0x2 /* _MOPENW */) != 0;
#elif defined __MINT__ /* Atari FreeMiNT */
return fp->__mode.__write;
+#elif defined EPLAN9 /* Plan9 */
+ int fd = fp->fd;
+ if (fd >= 0)
+ {
+ int flags = fcntl (fd, F_GETFL, NULL);
+ if (flags >= 0)
+ {
+ flags &= O_ACCMODE;
+ return (flags == O_WRONLY || flags == O_RDWR);
+ }
+ }
+ return 0;
#else
# error "Please port gnulib fwritable.c to your platform! Look at the
definition of fopen, fdopen on your system, then report this to bug-gnulib."
#endif
--- lib/fwriting.c.orig Fri Feb 3 22:54:04 2012
+++ lib/fwriting.c Fri Feb 3 22:00:28 2012
@@ -52,6 +52,10 @@
# else
return (fp->__buffer < fp->__put_limit /*|| fp->__bufp == fp->__get_limit
??*/);
# endif
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->state == 0 /* CLOSED */ || fp->state == 3 /* RD */)
+ return 0;
+ return (fp->state == 4 /* WR */ && (fp->bufl == 0 || fp->wp < fp->rp));
#else
# error "Please port gnulib fwriting.c to your platform!"
#endif
--- lib/stdio-impl.h.orig Fri Feb 3 22:54:04 2012
+++ lib/stdio-impl.h Fri Feb 3 21:02:41 2012
@@ -26,6 +26,8 @@
# include <sys/param.h>
#endif
+#include <errno.h> /* For detecting Plan9. */
+
#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD,
DragonFly, MacOS X, Cygwin */
# if defined __DragonFly__ /* DragonFly */
--- m4/fpending.m4.orig Fri Feb 3 22:54:04 2012
+++ m4/fpending.m4 Fri Feb 3 22:53:44 2012
@@ -1,4 +1,4 @@
-# serial 18
+# serial 19
# Copyright (C) 2000-2001, 2004-2012 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
@@ -61,6 +61,9 @@
'# Minix' \
'fp->_ptr - fp->_buf' \
\
+ '# Plan9' \
+ 'fp->wp - fp->buf' \
+ \
'# VMS' \
'(*fp)->_ptr - (*fp)->_base' \
\