|
21 | 21 | #ifdef HAVE_SYS_STAT_H |
22 | 22 | #include <sys/stat.h> |
23 | 23 | #endif |
| 24 | +#include <unistd.h> /* lseek() */ |
| 25 | + |
24 | 26 | #include "ncdispatch.h" |
25 | 27 | #include "netcdf_mem.h" |
26 | 28 | #include "ncwinpath.h" |
@@ -2175,7 +2177,6 @@ openmagic(struct MagicFile* file) |
2175 | 2177 | } |
2176 | 2178 | #ifdef USE_PARALLEL |
2177 | 2179 | if (file->use_parallel) { |
2178 | | - MPI_Status mstatus; |
2179 | 2180 | int retval; |
2180 | 2181 | MPI_Offset size; |
2181 | 2182 | MPI_Comm comm = MPI_COMM_WORLD; |
@@ -2206,17 +2207,17 @@ openmagic(struct MagicFile* file) |
2206 | 2207 | {status = errno; goto done;} |
2207 | 2208 | /* Get its length */ |
2208 | 2209 | { |
2209 | | -#ifdef _MSC_VER |
2210 | 2210 | int fd = fileno(file->fp); |
| 2211 | +#ifdef _MSC_VER |
2211 | 2212 | __int64 len64 = _filelengthi64(fd); |
2212 | 2213 | if(len64 < 0) |
2213 | 2214 | {status = errno; goto done;} |
2214 | 2215 | file->filelen = (long long)len64; |
2215 | 2216 | #else |
2216 | | - long size; |
2217 | | - if((status = fseek(file->fp, 0L, SEEK_END)) < 0) |
| 2217 | + off_t size; |
| 2218 | + size = lseek(fd, 0, SEEK_END); |
| 2219 | + if(size == -1) |
2218 | 2220 | {status = errno; goto done;} |
2219 | | - size = ftell(file->fp); |
2220 | 2221 | file->filelen = (long long)size; |
2221 | 2222 | #endif |
2222 | 2223 | rewind(file->fp); |
@@ -2249,12 +2250,8 @@ readmagic(struct MagicFile* file, long pos, char* magic) |
2249 | 2250 | if (file->use_parallel) { |
2250 | 2251 | MPI_Status mstatus; |
2251 | 2252 | int retval; |
2252 | | - MPI_Offset offset; |
2253 | | - offset = pos; |
2254 | | - if((retval = MPI_File_seek(file->fh, offset, MPI_SEEK_SET)) != MPI_SUCCESS) |
2255 | | - {status = NC_EPARINIT; goto done;} |
2256 | | - if((retval = MPI_File_read(file->fh, magic, MAGIC_NUMBER_LEN, MPI_CHAR, |
2257 | | - &mstatus)) != MPI_SUCCESS) |
| 2253 | + if((retval = MPI_File_read_at_all(file->fh, pos, magic, |
| 2254 | + MAGIC_NUMBER_LEN, MPI_CHAR, &mstatus)) != MPI_SUCCESS) |
2258 | 2255 | {status = NC_EPARINIT; goto done;} |
2259 | 2256 | goto done; |
2260 | 2257 | } |
@@ -2293,7 +2290,6 @@ closemagic(struct MagicFile* file) |
2293 | 2290 | if(file->inmemory) goto done; /* noop*/ |
2294 | 2291 | #ifdef USE_PARALLEL |
2295 | 2292 | if (file->use_parallel) { |
2296 | | - MPI_Status mstatus; |
2297 | 2293 | int retval; |
2298 | 2294 | if((retval = MPI_File_close(&file->fh)) != MPI_SUCCESS) |
2299 | 2295 | {status = NC_EPARINIT; goto done;} |
|
0 commit comments