]> Savannah Git Hosting - gnulib.git/commitdiff
stdioext: Add tentative support for Plan9.
authorBruno Haible <bruno@clisp.org>
Fri, 3 Feb 2012 21:58:33 +0000 (22:58 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 3 Feb 2012 21:58:33 +0000 (22:58 +0100)
* 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 <staal1978@gmail.com>.

14 files changed:
ChangeLog
lib/fbufmode.c
lib/fpurge.c
lib/freadable.c
lib/freadahead.c
lib/freading.c
lib/freadptr.c
lib/freadseek.c
lib/fseeko.c
lib/fseterr.c
lib/fwritable.c
lib/fwriting.c
lib/stdio-impl.h
m4/fpending.m4

index 9c5a3cdc5cc9ef43d1b3a736396778e8829b9f19..8508a2c64f4782d36dc5cef0a69c41e86e3a0164 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2012-02-03  Bruno Haible  <bruno@clisp.org>
+
+       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 <staal1978@gmail.com>.
+
 2012-02-02  Jim Meyering  <meyering@redhat.com>
 
        file-has-acl: suppress a warning from gcc -Wsuggest-attribute=const
index 4dfe5de2dd55610f9f455849254f2447bdc2f4b3..b48cdbb3875ab0ac9f4ac01f416fa6eede01e38d 100644 (file)
@@ -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
index 295d8dccf783276bd38f2cb890e3d87ae9ace7ca..24c28d843c054d98a0976d71341594e4d8cadb28 100644 (file)
@@ -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
index 8295fc04e2ad8c163e80fc0035e7a1855163a9f9..f3855a4a03f16218f8fcf2bd4e44f9de24a54df4 100644 (file)
 
 #include "stdio-impl.h"
 
+#if defined EPLAN9                  /* Plan9 */
+# include <fcntl.h>
+#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
index 44656e5237caeeace5f3a5464ed8f6f3ca222213..2ba8b344884e312e9a5c841a0a291ececc69c524 100644 (file)
@@ -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;
index 3fde6ea4d04e84f5e087ff350cccab1a69376ee7..e235e949f42997fd34d1eee058b96cf3b5abcbdc 100644 (file)
@@ -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
index 6582cc43dcfadae7cd746703326969c16736cc19..27c2285a8cad6f9c3fb47a17d5d3e0247b9f8ca8 100644 (file)
@@ -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.  */
index e64aa07137b41c77ff7861842cf6fcbc5ff38a62..4145173e9e1fd3e30c54ecfa4c8104fb9663a3a3 100644 (file)
@@ -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."
index 55aff235bf935adb18bb19ae5aa823c7aea430b9..2e988b8b527ce16b3cb92272f2a6dc23b3838985 100644 (file)
@@ -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
index 30b41e11eaa5cd1d744a0f8de3e83abbf6726707..78791af3dca25a141092e297ec40394866d4c78a 100644 (file)
@@ -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!
index e107b7c27d3353231fd6e2f7730390b326f4ff9e..0c9a49e8c7be88d8f8fdf11de2fe07908707e9cf 100644 (file)
@@ -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
index a6199f607a469abb945773171cc92124413629e4..5daa09b0c922e256453a09a053cc35f4115a41c3 100644 (file)
@@ -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
index a065c1a61a6c2a9f6ae949f5ca4acfbd126448b7..49357953742acdf89c40c472ad1bd09a8e522819 100644 (file)
@@ -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 */
index a818323b54c4db0bdfb2cce1be562bc5ed569239..33a5c94c3a3732abfda755f55670c19a889e6bab 100644 (file)
@@ -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'                                  \
                                                                         \