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

Re: psutils and pipes bug



   Date: Thu, 30 May 1996 12:29:03 -0500
   From: Lukas Nellen <lukas@teorica0.ifisicacu.unam.mx>

   Unfortunately, that doesn't solve the problem. Could the problem be
   related to the libraries you link psutils with? The version of libc on
   my system is:
	   libc5           5.2.18-6 
   which is the only shared library used by psnup and pstops. Or could
   there be another difference between our systems which might be
   relevant? 

The problem seems to be one or both of: (1) a change in the way psutils
decides whether a file is seekable or not, and (2) libc's (possibly changed)
optimization of fseeks.

Specifically, the current version of psutils decides whether a file is
seekable by SEEK_CUR with 0 as the arg (which is a no-op seek to the current
position), checking to see whether this generates an error.  Libc, however,
optimizes this fseek away (i.e., without calling lseek), and doesn't generate
an error.

The attached patch seems like a reasonable fix.  It tests seekability by
seeking to EOF and back to the current point, checking for errors.

(I'm also Cc:'ing Angus (author of psutils) on this.)

--Mike

P.S.  One of the debian.* files mentions dwarf@polaris.com as the package
maintainer.  Is this really the same as dwarf@polaris.net or a typo?


--- psutil.c~	Mon Feb 19 11:27:19 1996
+++ psutil.c	Thu May 30 17:15:16 1996
@@ -82,6 +82,7 @@
    FILE *ft;
    long r, w;
    char *p;
+   long fp_pos;
 #if defined(WINNT)
    struct _stat fs ;
 #endif
@@ -90,8 +91,9 @@
    if (_fstat(fileno(fp), &fs) == 0 && (fs.st_mode&_S_IFREG) != 0)
      return (fp);
 #else
-   if (!fseek(fp, 0L, SEEK_CUR))
-     return (fp);
+   if ((fp_pos = ftell(fp)) >= 0)
+      if (!fseek(fp, 0L, SEEK_END) && !fseek(fp, fp_pos, SEEK_SET))
+	 return (fp);
 #endif
 
 #if defined(MSDOS)


Reply to: