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.23 by schorsch, Sun Mar 6 01:13:18 2016 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 138 | Line 145 | load_file(MEMLOAD *mp, FILE *fp)
145   static RECINDEX *
146   index_records(const MEMLOAD *mp, int nw_rec)
147   {
148 +        int             nall = 0;
149          RECINDEX        *rp;
150          char            *cp, *mend;
151          int             n;
# Line 146 | Line 154 | index_records(const MEMLOAD *mp, int nw_rec)
154                  return(NULL);
155          if (nw_rec <= 0)
156                  return(NULL);
157 <        rp = (RECINDEX *)malloc(sizeof(RECINDEX) + mp->len/(2*nw_rec)*sizeof(char *));
157 >        nall = 1000;
158 >        rp = (RECINDEX *)malloc(sizeof(RECINDEX) + nall*sizeof(char *));
159          if (rp == NULL)
160                  return(NULL);
161          rp->nw_rec = nw_rec;
# Line 158 | Line 167 | index_records(const MEMLOAD *mp, int nw_rec)
167                          ++cp;
168                  if (cp >= mend)
169                          break;
170 +                if (rp->nrecs >= nall) {
171 +                        nall += nall>>1;        /* get more record space */
172 +                        rp = (RECINDEX *)realloc(rp,
173 +                                        sizeof(RECINDEX) + nall*sizeof(char *));
174 +                        if (rp == NULL)
175 +                                return(NULL);
176 +                }
177                  rp->rec[rp->nrecs++] = cp;      /* point to first non-white */
178                  n = rp->nw_rec;
179                  while (++cp < mend)             /* find end of record */
# Line 353 | Line 369 | do_transpose(const MEMLOAD *mp)
369                          print_record(rp, j*ni_columns + i);
370                          putc(tabEOL[j >= no_columns-1], stdout);
371                  } else {                        /* binary output */
372 <                        fwrite((char *)mp->base +
373 <                                        (n_comp*comp_size)*(j*ni_columns + i),
374 <                                        n_comp*comp_size, 1, stdout);
372 >                        putbinary((char *)mp->base +
373 >                            (unsigned long)(n_comp*comp_size)*(j*ni_columns + i),
374 >                                        comp_size, n_comp, stdout);
375                  }
376              if (ferror(stdout)) {
377                  fprintf(stderr, "Error writing to stdout\n");
# Line 432 | Line 448 | done:
448   static int
449   headline(char *s, void *p)
450   {
451 <        static char     fmt[32];
451 >        static char     fmt[MAXFMTLEN];
452          int             n;
453  
454          if (formatval(fmt, s)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines