[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Question about FILE * structures in the Hurd



On Wed, May 26, 1999 at 12:56:07PM -0400, Roland McGrath was heard to say:
> The Hurd and Linux use the same libc (shared source), but not exactly the same.
> GNU/Linux uses libio as its stdio implementation, while the Hurd still uses
> the original GNU libc stdio; eventually the Hurd will change to use the
> same libio code now used on Linux.

  Ah, I see.

> Emacs also does this (see its src/dispnew.c).  What works on the Hurd now is:
> 
> 	#define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
> 
> A configure check for this would do fine. 

  Done.  I've implemented a new configure check for this situation.
Unfortunately something seems to be failing in make install (when producing the
temporary tree to build the Debian package), I'm not sure what's up with that
but I think it's an unrelated problem..

  I've attached a diff against Guile's configure.in and libguile/filesys.c .

> It is a bad kludge that programs look into stdio internals like this, and
> the Right Thing is to add a new stdio function to glibc that returns this
> (e.g. `size_t fpending_output_count(FILE *);').  That was the plan long ago
> but it never seem to have happened and I can't now find any place a
> particular name for the function was suggested.  

  Yeah, I agree.  I didn't write it though, I'm just compiling it :-)

  Daniel

-- 
  If you wish to live wisely, ignore sayings--including this one.
--- guile-core-1.3-orig/configure.in	Wed May 26 16:23:33 1999
+++ guile-core-1.3/configure.in	Wed May 26 16:24:45 1999
@@ -363,15 +363,22 @@
 	AC_MSG_RESULT(gptr)
 	AC_DEFINE_UNQUOTED(FILE_CNT_GPTR, $scm_cv_struct_file_gptr)
 else
-AC_CACHE_VAL(scm_cv_struct_file_readptr,
+AC_CACHE_VAL(scm_cv_struct_file_method,
 	AC_TRY_COMPILE([#include <stdio.h>],
 			[FILE *f = stdin; f->_IO_read_ptr = f->_IO_read_end;],
-			scm_cv_struct_file_readptr=1))
-if test "$scm_cv_struct_file_readptr"; then
+			scm_cv_struct_file_method="_IO_read_ptr",
+	AC_TRY_COMPILE([#include <stdio.h>],
+			[FILE *f = stdin; f->__bufp = f->__buffer;],
+			scm_cv_struct_file_method="__bufp")))
+if test "$scm_cv_struct_file_method" = "_IO_read_ptr"; then
 	AC_MSG_RESULT(read_ptr)
-	AC_DEFINE_UNQUOTED(FILE_CNT_READPTR, $scm_cv_struct_file_readptr)
+	AC_DEFINE_UNQUOTED(FILE_CNT_READPTR, $scm_cv_struct_file_method)
+else if test "$scm_cv_struct_file_method" = "__bufp"; then
+	AC_MSG_RESULT(bufp)
+	AC_DEFINE_UNQUOTED(FILE_CNT_BUFP, $scm_cv_struct_file_method)
 else
 	AC_MSG_RESULT(we couldn't do it!)
+fi
 fi
 fi
 fi
--- guile-core-1.3-orig/libguile/filesys.c	Thu Dec 17 17:54:34 1998
+++ guile-core-1.3/libguile/filesys.c	Wed May 26 16:24:45 1999
@@ -1056,11 +1056,16 @@
 #   ifdef FILE_CNT_READPTR
   if (f->_IO_read_end != f->_IO_read_ptr)
     return 1;
+# else
+#   ifdef FILE_CNT_BUFP
+  if (f->__bufp != f->__buffer)
+    return 1;
 #   else
-  Configure.in could not guess the name of the correct field in a FILE *.
-  This function needs to be ported to your system.
-  It should return zero iff no characters are waiting to be read.;
+#error Configure.in could not guess the name of the correct field in a FILE *. \
+       This function needs to be ported to your system. \
+       It should return zero iff no characters are waiting to be read.
 #   endif
+#  endif
 #  endif
 # endif
 
--- guile-core-1.3-orig/libguile/scmconfig.h.in	Wed May 26 16:23:35 1999
+++ guile-core-1.3/libguile/scmconfig.h.in	Wed May 26 16:24:45 1999
@@ -112,6 +112,11 @@
    waiting to be read.  */
 #undef FILE_CNT_READPTR
 
+/* Define this if your stdio has __bufp and __buffer fields
+   which can be compared to give the number of buffered characters
+   waiting to be read.  */
+#undef FILE_CNT_BUFP
+
 /* Define this if your system defines struct linger, for use with the
    getsockopt and setsockopt system calls.  */
 #undef HAVE_STRUCT_LINGER

Reply to: