Commit b1127ec5 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Change grbCopyRecord to not propagate errors.

Fail early instead.
parent 039f680f
......@@ -660,11 +660,10 @@ void grb_write_var(stream_t *streamptr, int varID, int memtype, const void *data
}
int grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1)
void grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1)
{
int fileID1, fileID2;
int tsID, recID, vrecID;
long recsize;
size_t gribbuffersize;
off_t recpos;
size_t nwrite;
......@@ -683,16 +682,17 @@ int grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1)
vrecID = streamptr1->tsteps[tsID].curRecID;
recID = streamptr1->tsteps[tsID].recIDs[vrecID];
recpos = streamptr1->tsteps[tsID].records[recID].position;
recsize = streamptr1->tsteps[tsID].records[recID].size;
size_t recsize = streamptr1->tsteps[tsID].records[recID].size;
fileSetPos(fileID1, recpos, SEEK_SET);
/* round up recsize to next multiple of 8 */
gribbuffersize = (size_t)((recsize + 7) & ~7);
gribbuffersize = ((recsize + 7) & ~7);
gribbuffer = (unsigned char *) malloc(gribbuffersize);
gribbuffer = xmalloc(gribbuffersize);
fileRead(fileID1, gribbuffer, recsize);
if (fileRead(fileID1, gribbuffer, recsize) != recsize)
Error("Could not read GRIB record for copying!");
nbytes = recsize;
......@@ -705,11 +705,13 @@ int grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1)
while ( nbytes & 7 ) gribbuffer[nbytes++] = 0;
nwrite = fileWrite(fileID2, gribbuffer, nbytes);
if ( nwrite != nbytes ) perror(__func__);
if ( nwrite != nbytes )
{
perror(__func__);
Error("Could not write record for copying!");
}
free(gribbuffer);
return ((int)nwrite);
}
......
......@@ -10,7 +10,7 @@ int grbInqRecord(stream_t * streamptr, int *varID, int *levelID);
void grbDefRecord(stream_t * streamptr);
void grbReadRecord(stream_t * streamptr, double *data, int *nmiss);
void grb_write_record(stream_t * streamptr, int memtype, const void *data, int nmiss);
int grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1);
void grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1);
void grbReadVarDP(stream_t * streamptr, int varID, double *data, int *nmiss);
void grb_write_var(stream_t * streamptr, int varID, int memtype, const void *data, int nmiss);
......
......@@ -443,11 +443,8 @@ void streamCopyRecord(int streamID2, int streamID1)
#if defined (HAVE_LIBGRIB)
case FILETYPE_GRB:
case FILETYPE_GRB2:
{
/* FIXME: return value not inspected */
status = grbCopyRecord(streamptr2, streamptr1);
break;
}
grbCopyRecord(streamptr2, streamptr1);
break;
#endif
#if defined (HAVE_LIBSERVICE)
case FILETYPE_SRV:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment