90 |
|
load_file(MEMLOAD *mp, FILE *fp) |
91 |
|
{ |
92 |
|
int fd; |
93 |
< |
off_t skip, flen; |
93 |
> |
off_t skip, flen, fpos; |
94 |
|
|
95 |
|
#if defined(_WIN32) || defined(_WIN64) |
96 |
|
/* too difficult to fix this */ |
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 |
|
} |
120 |
< |
mp->base = NULL; /* fall back to reading it in... */ |
120 |
> |
mp->base = NULL; /* else fall back to reading it in... */ |
121 |
|
} |
122 |
|
#endif |
123 |
|
if (lseek(fd, skip, SEEK_SET) != skip || |
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 |
> |
fpos = skip; |
129 |
> |
while (fpos < flen) { /* read() fails if n > 2 GBytes */ |
130 |
> |
ssize_t nread = read(fd, (char *)mp->base+(fpos-skip), |
131 |
> |
(flen-fpos < 1L<<24) ? flen-fpos : 1L<<24); |
132 |
> |
if (nread <= 0) { |
133 |
> |
free_load(mp); |
134 |
> |
return(-1); |
135 |
> |
} |
136 |
> |
fpos += nread; |
137 |
|
} |
138 |
|
return(1); |
139 |
|
} |
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 |
> |
(size_t)(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"); |
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)) { |