From 787e2334ba6d03fd45c84b9718dc5e0f98977948 Mon Sep 17 00:00:00 2001 From: wkliao Date: Wed, 6 Dec 2023 13:32:55 -0600 Subject: [PATCH] check error code returned --- src/drivers/ncmpio/ncmpio_close.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/drivers/ncmpio/ncmpio_close.c b/src/drivers/ncmpio/ncmpio_close.c index b44da3d3b..b167906a7 100644 --- a/src/drivers/ncmpio/ncmpio_close.c +++ b/src/drivers/ncmpio/ncmpio_close.c @@ -183,23 +183,35 @@ ncmpio_close(void *ncdp) /* obtain file size */ off_t file_size = lseek(fd, 0, SEEK_END); /* truncate file size to header size, if larger than header */ - if (file_size > ncp->xsz) - ftruncate(fd, ncp->xsz); + if (file_size > ncp->xsz && ftruncate(fd, ncp->xsz) < 0) { + err = ncmpii_error_posix2nc("ftruncate"); + if (status == NC_NOERR) status = err; + } close(fd); } #else MPI_File fh; - err = MPI_File_open(MPI_COMM_SELF, ncp->path, MPI_MODE_RDWR, MPI_INFO_NULL, &fh); - if (err == MPI_SUCCESS) { + int mpireturn; + mpireturn = MPI_File_open(MPI_COMM_SELF, ncp->path, MPI_MODE_RDWR, MPI_INFO_NULL, &fh); + if (mpireturn == MPI_SUCCESS) { /* obtain file size */ MPI_Offset *file_size; MPI_File_seek(fh, 0, MPI_SEEK_END); MPI_File_get_position(fh, &file_size); /* truncate file size to header size, if larger than header */ - if (file_size > ncp->xsz) - MPI_File_set_size(fh, ncp->xsz); + if (file_size > ncp->xsz} { + mpireturn = MPI_File_set_size(fh, ncp->xsz); + if (mpireturn != MPI_SUCCESS) { + err = ncmpii_error_mpi2nc(mpireturn,"MPI_File_set_size"); + if (status == NC_NOERR) status = err; + } + } MPI_File_close(&fh); } + else { + err = ncmpii_error_mpi2nc(mpireturn,"MPI_File_open"); + if (status == NC_NOERR) status = err; + } #endif } MPI_Barrier(ncp->comm);