ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rcollate.c
(Generate patch)

Comparing ray/src/util/rcollate.c (file contents):
Revision 2.26 by greg, Thu Aug 2 18:33:50 2018 UTC vs.
Revision 2.27 by greg, Thu Oct 18 22:59:48 2018 UTC

# Line 90 | Line 90 | static int
90   load_file(MEMLOAD *mp, FILE *fp)
91   {
92          int     fd;
93 <        off_t   skip, flen;
93 >        off_t   skip, flen, skipped;
94  
95   #if defined(_WIN32) || defined(_WIN64)
96                                  /* too difficult to fix this */
# Line 111 | Line 111 | load_file(MEMLOAD *mp, FILE *fp)
111          mp->len = (size_t)(flen - skip);
112   #ifdef MAP_FILE
113          if (mp->len > 1L<<20) {         /* map file if > 1 MByte */
114 <                mp->base = mmap(NULL, mp->len, PROT_READ, MAP_PRIVATE, fd, skip);
114 >                mp->base = mmap(NULL, flen, PROT_READ, MAP_PRIVATE, fd, 0);
115                  if (mp->base != MAP_FAILED) {
116 +                        mp->base = (char *)mp->base + skip;
117                          mp->mapped = 1;
118                          return(1);      /* mmap() success */
119                  }
# Line 124 | Line 125 | load_file(MEMLOAD *mp, FILE *fp)
125                  mp->len = 0;
126                  return(-1);
127          }
128 <        if (read(fd, (char *)mp->base, mp->len) != mp->len) {
129 <                free_load(mp);
130 <                return(-1);
128 >        skipped = skip;                 /* read() fails on really big buffers */
129 >        while (skipped < flen) {
130 >                ssize_t nread = read(fd, (char *)mp->base+(skipped-skip),
131 >                                (flen-skipped <= 1L<<30) ? flen-skipped : 1L<<30);
132 >                if (nread <= 0) {
133 >                        free_load(mp);
134 >                        return(-1);
135 >                }
136 >                skipped += nread;
137          }
138          return(1);
139   }
# Line 363 | Line 370 | do_transpose(const MEMLOAD *mp)
370                          putc(tabEOL[j >= no_columns-1], stdout);
371                  } else {                        /* binary output */
372                          putbinary((char *)mp->base +
373 <                                        (n_comp*comp_size)*(j*ni_columns + i),
373 >                            (unsigned long)(n_comp*comp_size)*(j*ni_columns + i),
374                                          comp_size, n_comp, stdout);
375                  }
376              if (ferror(stdout)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines