From c8095ab6d71402180c021ce6cf9867d5d8c34796 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 3 Feb 2012 22:58:33 +0100 Subject: [PATCH] stdioext: Add tentative support for Plan9. * lib/stdio-impl.h: Include . * 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 . --- ChangeLog | 18 ++++++++++++++++++ lib/fbufmode.c | 6 ++++++ lib/fpurge.c | 3 +++ lib/freadable.c | 16 ++++++++++++++++ lib/freadahead.c | 4 ++++ lib/freading.c | 4 ++++ lib/freadptr.c | 7 +++++++ lib/freadseek.c | 2 ++ lib/fseeko.c | 3 +++ lib/fseterr.c | 3 +++ lib/fwritable.c | 12 ++++++++++++ lib/fwriting.c | 4 ++++ lib/stdio-impl.h | 2 ++ m4/fpending.m4 | 5 ++++- 14 files changed, 88 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9c5a3cdc5..8508a2c64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2012-02-03 Bruno Haible + + stdioext: Add tentative support for Plan9. + * lib/stdio-impl.h: Include . + * 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 . + 2012-02-02 Jim Meyering file-has-acl: suppress a warning from gcc -Wsuggest-attribute=const diff --git a/lib/fbufmode.c b/lib/fbufmode.c index 4dfe5de2d..b48cdbb38 100644 --- a/lib/fbufmode.c +++ b/lib/fbufmode.c @@ -79,6 +79,12 @@ fbufmode (FILE *fp) 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 diff --git a/lib/fpurge.c b/lib/fpurge.c index 295d8dccf..24c28d843 100644 --- a/lib/fpurge.c +++ b/lib/fpurge.c @@ -134,6 +134,9 @@ fpurge (FILE *fp) /* 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 diff --git a/lib/freadable.c b/lib/freadable.c index 8295fc04e..f3855a4a0 100644 --- a/lib/freadable.c +++ b/lib/freadable.c @@ -21,6 +21,10 @@ #include "stdio-impl.h" +#if defined EPLAN9 /* Plan9 */ +# include +#endif + bool freadable (FILE *fp) { @@ -41,6 +45,18 @@ freadable (FILE *fp) 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 diff --git a/lib/freadahead.c b/lib/freadahead.c index 44656e523..2ba8b3448 100644 --- a/lib/freadahead.c +++ b/lib/freadahead.c @@ -80,6 +80,10 @@ freadahead (FILE *fp) 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; diff --git a/lib/freading.c b/lib/freading.c index 3fde6ea4d..e235e949f 100644 --- a/lib/freading.c +++ b/lib/freading.c @@ -62,6 +62,10 @@ freading (FILE *fp) # 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 diff --git a/lib/freadptr.c b/lib/freadptr.c index 6582cc43d..27c2285a8 100644 --- a/lib/freadptr.c +++ b/lib/freadptr.c @@ -101,6 +101,13 @@ freadptr (FILE *fp, size_t *sizep) 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. */ diff --git a/lib/freadseek.c b/lib/freadseek.c index e64aa0713..4145173e9 100644 --- a/lib/freadseek.c +++ b/lib/freadseek.c @@ -58,6 +58,8 @@ freadptrinc (FILE *fp, size_t increment) 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." diff --git a/lib/fseeko.c b/lib/fseeko.c index 55aff235b..2e988b8b5 100644 --- a/lib/fseeko.c +++ b/lib/fseeko.c @@ -89,6 +89,9 @@ fseeko (FILE *fp, off_t offset, int whence) && 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 diff --git a/lib/fseterr.c b/lib/fseterr.c index 30b41e11e..78791af3d 100644 --- a/lib/fseterr.c +++ b/lib/fseterr.c @@ -45,6 +45,9 @@ fseterr (FILE *fp) 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! diff --git a/lib/fwritable.c b/lib/fwritable.c index e107b7c27..0c9a49e8c 100644 --- a/lib/fwritable.c +++ b/lib/fwritable.c @@ -41,6 +41,18 @@ fwritable (FILE *fp) 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 diff --git a/lib/fwriting.c b/lib/fwriting.c index a6199f607..5daa09b0c 100644 --- a/lib/fwriting.c +++ b/lib/fwriting.c @@ -52,6 +52,10 @@ fwriting (FILE *fp) # 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 diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h index a065c1a61..493579537 100644 --- a/lib/stdio-impl.h +++ b/lib/stdio-impl.h @@ -26,6 +26,8 @@ # include #endif +#include /* For detecting Plan9. */ + #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ # if defined __DragonFly__ /* DragonFly */ diff --git a/m4/fpending.m4 b/m4/fpending.m4 index a818323b5..33a5c94c3 100644 --- a/m4/fpending.m4 +++ b/m4/fpending.m4 @@ -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 @@ AC_DEFUN([gl_PREREQ_FPENDING], '# Minix' \ 'fp->_ptr - fp->_buf' \ \ + '# Plan9' \ + 'fp->wp - fp->buf' \ + \ '# VMS' \ '(*fp)->_ptr - (*fp)->_base' \ \ -- 2.11.0