Source: psutils
Source-Version: 1.17-28
Severity: important
Tags: patch

Hi!

The patch in #595239 seems to have introduced a regression, only
for kfreebsd-i386, although this might imply not completely LFS safe
operation on the rest of the 32-bit architectures. Attached is an
updated patch which should fix it, the relevant changes are the
switch of types for sizeheaders.

The failed build log:

  
<https://buildd.debian.org/fetch.cgi?pkg=psutils&arch=kfreebsd-i386&ver=1.17-28&stamp=1289868758&file=log&as=raw>


I'd also ask you to consider removing the -Werror flag, as it can
trigger build failure on toolchain updates for example. While it's
always good to build stuff with -Werror during development, it's not
so much for releases and such. And although in this case it revealed
a true problem, that might not be usually the case.

thanks,
guillem
---
 psnup.c    |    2 -
 psresize.c |    2 -
 psspec.c   |    2 -
 psspec.h   |    2 -
 psutil.c   |   69 +++++++++++++++++++++++++++++++++----------------------------
 psutil.h   |    6 ++---
 6 files changed, 45 insertions(+), 38 deletions(-)

--- a/psutil.c
+++ b/psutil.c
@@ -5,7 +5,10 @@
  * utilities for PS programs
  */
 
+
 /*
+ *  Daniele Giacomini appun...@gmail.com 2010-09-02
+ *    Changed to using ftello() and fseeko()
  *  AJCD 6/4/93
  *    Changed to using ftell() and fseek() only (no length calculations)
  *  Hunter Goatley    31-MAY-1993 23:33
@@ -13,6 +16,9 @@
  *  Hunter Goatley     2-MAR-1993 14:41
  *    Added VMS support.
  */
+
+#define _FILE_OFFSET_BITS 64
+
 #include "psutil.h"
 #include "pserror.h"
 #include "patchlev.h"
@@ -20,6 +26,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <stdio.h>
 
 #define iscomment(x,y) (strncmp(x,y,strlen(y)) == 0)
 
@@ -33,14 +40,14 @@ extern int pageno;
 
 static char buffer[BUFSIZ];
 static long bytes = 0;
-static long pagescmt = 0;
-static long headerpos = 0;
-static long endsetup = 0;
-static long beginprocset = 0;		/* start of pstops procset */
-static long endprocset = 0;
+static off_t pagescmt = 0;
+static off_t headerpos = 0;
+static off_t endsetup = 0;
+static off_t beginprocset = 0;		/* start of pstops procset */
+static off_t endprocset = 0;
 static int outputpage = 0;
 static int maxpages = 100;
-static long *pageptr;
+static off_t *pageptr;
 
 /* list of paper sizes supported */
 static Paper papersizes[] = {
@@ -94,15 +101,15 @@ FILE *seekable(FILE *fp)
 #if defined(WINNT)
   struct _stat fs ;
 #else
-  long fpos;
+  off_t fpos;
 #endif
 
 #if defined(WINNT)
   if (_fstat(fileno(fp), &fs) == 0 && (fs.st_mode&_S_IFREG) != 0)
     return (fp);
 #else
-  if ((fpos = ftell(fp)) >= 0)
-    if (!fseek(fp, 0L, SEEK_END) && !fseek(fp, fpos, SEEK_SET))
+  if ((fpos = ftello(fp)) >= 0)
+    if (!fseeko(fp, (off_t) 0, SEEK_END) && !fseeko(fp, fpos, SEEK_SET))
       return (fp);
 #endif
 
@@ -127,7 +134,7 @@ FILE *seekable(FILE *fp)
 
   /* discard the input file, and rewind the temporary */
   (void) fclose(fp);
-  if (fseek(ft, 0L, SEEK_SET) != 0)
+  if (fseeko(ft, (off_t) 0, SEEK_SET) != 0)
     return (NULL) ;
 
   return (ft);
@@ -137,10 +144,10 @@ FILE *seekable(FILE *fp)
 
 /* copy input file from current position upto new position to output file,
  * ignoring the lines starting at something ignorelist points to */
-static int fcopy(long upto, long *ignorelist)
+static int fcopy(off_t upto, off_t *ignorelist)
 {
-  long here = ftell(infile);
-  long bytes_left;
+  off_t here = ftello(infile);
+  off_t bytes_left;
 
   if (ignorelist != NULL) {
     while (*ignorelist > 0 && *ignorelist < here)
@@ -151,7 +158,7 @@ static int fcopy(long upto, long *ignore
       if (!r || fgets(buffer, BUFSIZ, infile) == NULL)
 	return 0;
       ignorelist++;
-      here = ftell(infile);
+      here = ftello(infile);
       while (*ignorelist > 0 && *ignorelist < here)
 	ignorelist++;
     }
@@ -172,27 +179,27 @@ static int fcopy(long upto, long *ignore
 }
 
 /* build array of pointers to start/end of pages */
-void scanpages(long *sizeheaders)
+void scanpages(off_t *sizeheaders)
 {
    register char *comment = buffer+2;
    register int nesting = 0;
-   register long int record;
+   register off_t record;
 
    if (sizeheaders)
      *sizeheaders = 0;
 
-   if ((pageptr = (long *)malloc(sizeof(long)*maxpages)) == NULL)
+   if ((pageptr = (off_t *)malloc(sizeof(off_t)*maxpages)) == NULL)
       message(FATAL, "out of memory\n");
    pages = 0;
-   fseek(infile, 0L, SEEK_SET);
-   while (record = ftell(infile), fgets(buffer, BUFSIZ, infile) != NULL)
+   fseeko(infile, (off_t) 0, SEEK_SET);
+   while (record = ftello(infile), fgets(buffer, BUFSIZ, infile) != NULL)
       if (*buffer == '%') {
 	 if (buffer[1] == '%') {
 	    if (nesting == 0 && iscomment(comment, "Page:")) {
 	       if (pages >= maxpages-1) {
 		  maxpages *= 2;
-		  if ((pageptr = (long *)realloc((char *)pageptr,
-					     sizeof(long)*maxpages)) == NULL)
+		  if ((pageptr = (off_t *)realloc((char *)pageptr,
+					     sizeof(off_t)*maxpages)) == NULL)
 		     message(FATAL, "out of memory\n");
 	       }
 	       pageptr[pages++] = record;
@@ -219,7 +226,7 @@ void scanpages(long *sizeheaders)
 	    } else if (headerpos == 0 && iscomment(comment, "Pages:"))
 	       pagescmt = record;
 	    else if (headerpos == 0 && iscomment(comment, "EndComments"))
-	       headerpos = ftell(infile);
+	       headerpos = ftello(infile);
 	    else if (iscomment(comment, "BeginDocument") ||
 		     iscomment(comment, "BeginBinary") ||
 		     iscomment(comment, "BeginFile"))
@@ -231,23 +238,23 @@ void scanpages(long *sizeheaders)
 	    else if (nesting == 0 && iscomment(comment, "EndSetup"))
 	       endsetup = record;
 	    else if (nesting == 0 && iscomment(comment, "BeginProlog"))
-	       headerpos = ftell(infile);
+	       headerpos = ftello(infile);
 	    else if (nesting == 0 &&
 		       iscomment(comment, "BeginProcSet: PStoPS"))
 	       beginprocset = record;
 	    else if (beginprocset && !endprocset &&
 		     iscomment(comment, "EndProcSet"))
-	       endprocset = ftell(infile);
+	       endprocset = ftello(infile);
 	    else if (nesting == 0 && (iscomment(comment, "Trailer") ||
 				      iscomment(comment, "EOF"))) {
-	       fseek(infile, record, SEEK_SET);
+	       fseeko(infile, record, SEEK_SET);
 	       break;
 	    }
 	 } else if (headerpos == 0 && buffer[1] != '!')
 	    headerpos = record;
       } else if (headerpos == 0)
 	 headerpos = record;
-   pageptr[pages] = ftell(infile);
+   pageptr[pages] = ftello(infile);
    if (endsetup == 0 || endsetup > pageptr[0])
       endsetup = pageptr[0];
 }
@@ -255,7 +262,7 @@ void scanpages(long *sizeheaders)
 /* seek a particular page */
 void seekpage(int p)
 {
-   fseek(infile, pageptr[p], SEEK_SET);
+   fseeko(infile, pageptr[p], SEEK_SET);
    if (fgets(buffer, BUFSIZ, infile) != NULL &&
        iscomment(buffer, "%%Page:")) {
       char *start, *end;
@@ -332,9 +339,9 @@ void writepage(int p)
 }
 
 /* write from start of file to end of header comments */
-void writeheader(int p, long *ignore)
+void writeheader(int p, off_t *ignore)
 {
-   fseek(infile, 0L, SEEK_SET);
+   fseeko(infile, (off_t) 0, SEEK_SET);
    if (pagescmt) {
       if (!fcopy(pagescmt, ignore) || fgets(buffer, BUFSIZ, infile) == NULL)
 	 message(FATAL, "I/O error in header\n");
@@ -351,7 +358,7 @@ int writepartprolog(void)
    if (beginprocset && !fcopy(beginprocset, NULL))
       message(FATAL, "I/O error in prologue\n");
    if (endprocset)
-      fseek(infile, endprocset, SEEK_SET);
+      fseeko(infile, endprocset, SEEK_SET);
    writeprolog();
    return !beginprocset;
 }
@@ -373,7 +380,7 @@ void writesetup(void)
 /* write trailer */
 void writetrailer(void)
 {
-   fseek(infile, pageptr[pages], SEEK_SET);
+   fseeko(infile, pageptr[pages], SEEK_SET);
    while (fgets(buffer, BUFSIZ, infile) != NULL) {
       writestring(buffer);
    }
--- a/psutil.h
+++ b/psutil.h
@@ -4,7 +4,7 @@
  *
  * utilities for PS programs
  */
-
+#define _FILE_OFFSET_BITS 64
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
@@ -32,13 +32,13 @@ extern void seekpage(int p);
 extern void writepageheader(char *label, int p);
 extern void writepagesetup(void);
 extern void writepagebody(int p);
-extern void writeheader(int p, long *ignorelist);
+extern void writeheader(int p, off_t *ignorelist);
 extern int writepartprolog(void);
 extern void writeprolog(void);
 extern void writesetup(void);
 extern void writetrailer(void);
 extern void writeemptypage(void);
-extern void scanpages(long *sizeheaders);
+extern void scanpages(off_t *sizeheaders);
 extern void writestring(char *s);
 
 /* These variables are imported from the client program (e.g. psbook, psnup,
--- a/psspec.c
+++ b/psspec.c
@@ -143,7 +143,7 @@ void pstops(int modulo, int pps, int nob
   pstops_write(modulo, pps, nobind, specs, draw, NULL);
 }
 
-void pstops_write(int modulo, int pps, int nobind, PageSpec *specs, double draw, long *ignorelist)
+void pstops_write(int modulo, int pps, int nobind, PageSpec *specs, double draw, off_t *ignorelist)
 {
    int thispg, maxpage;
    int pageindex = 0;
--- a/psspec.h
+++ b/psspec.h
@@ -29,4 +29,4 @@ extern double singledimen(char *str, voi
 extern void pstops(int modulo, int pps, int nobind, PageSpec *specs,
 		   double draw);
 extern void pstops_write(int modulo, int pps, int nobind, PageSpec *specs,
-                         double draw, long *ignorelist);
+                         double draw, off_t *ignorelist);
--- a/psnup.c
+++ b/psnup.c
@@ -88,7 +88,7 @@ main(int argc, char *argv[])
    double iwidth, iheight ;			/* input paper size */
    double tolerance = 100000;			/* layout tolerance */
    Paper *paper = NULL;
-   long sizeheaders[20];			/* headers to remove */
+   off_t sizeheaders[20];			/* headers to remove */
    int opt;
 
 #ifdef DEBIAN
--- a/psresize.c
+++ b/psresize.c
@@ -61,7 +61,7 @@ main(int argc, char *argv[])
    int rotate;
    double inwidth = -1;
    double inheight = -1;
-   long sizeheaders[20];			/* headers to remove */
+   off_t sizeheaders[20];			/* headers to remove */
    Paper *paper = NULL;
    PageSpec *specs;
    int opt;

Reply via email to