AMPI #952: update ROMIO to MPICH2-1.4.1p1
[charm.git] / src / libs / ck-libs / ampi / romio / adio / ad_piofs / ad_piofs_read.c
blobc25e7e17e2f3cc36c96340a53a31eff22ec6458f
1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
4 * Copyright (C) 1997 University of Chicago.
5 * See COPYRIGHT notice in top-level directory.
6 */
8 #include "ad_piofs.h"
10 void ADIOI_PIOFS_ReadContig(ADIO_File fd, void *buf, int count,
11 MPI_Datatype datatype, int file_ptr_type,
12 ADIO_Offset offset, ADIO_Status *status, int *error_code)
14 int err=-1, datatype_size, len;
15 #ifndef PRINT_ERR_MSG
16 static char myname[] = "ADIOI_PIOFS_READCONTIG";
17 #endif
19 MPI_Type_size(datatype, &datatype_size);
20 len = datatype_size * count;
22 if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
23 if (fd->fp_sys_posn != offset) {
24 llseek(fd->fd_sys, offset, SEEK_SET);
26 err = read(fd->fd_sys, buf, len);
27 fd->fp_sys_posn = offset + err;
28 /* individual file pointer not updated */
30 else { /* read from curr. location of ind. file pointer */
31 if (fd->fp_sys_posn != fd->fp_ind) {
32 llseek(fd->fd_sys, fd->fp_ind, SEEK_SET);
34 err = read(fd->fd_sys, buf, len);
35 fd->fp_ind += err;
36 fd->fp_sys_posn = fd->fp_ind;
39 #ifdef HAVE_STATUS_SET_BYTES
40 if (err != -1) MPIR_Status_set_bytes(status, datatype, err);
41 #endif
43 if (err == -1) {
44 #ifdef MPICH2
45 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
46 "**io %s", strerror(errno));
47 #elif defined(PRINT_ERR_MSG)
48 *error_code = MPI_ERR_UNKNOWN;
49 #else
50 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
51 myname, "I/O Error", "%s", strerror(errno));
52 ADIOI_Error(fd, *error_code, myname);
53 #endif
55 else *error_code = MPI_SUCCESS;