stream_fcommon.c 1.15 KB
Newer Older
1
2
#include <stdlib.h>

3
#include "cdi_int.h"
4
5
6
7
8
#include "dmemory.h"
#include "file.h"
#include "stream_fcommon.h"


9
10
void streamFCopyRecord(stream_t *streamptr2, stream_t *streamptr1, const char *container_name)
{
11
12
13
14
15
16
17
18
19
20
21
22
  int fileID1 = streamptr1->fileID;
  int fileID2 = streamptr2->fileID;

  int tsID    = streamptr1->curTsID;
  int vrecID  = streamptr1->tsteps[tsID].curRecID;
  int recID   = streamptr1->tsteps[tsID].recIDs[vrecID];
  off_t recpos  = streamptr1->tsteps[tsID].records[recID].position;
  size_t recsize = streamptr1->tsteps[tsID].records[recID].size;

  if (fileSetPos(fileID1, recpos, SEEK_SET) != 0)
    Error("Cannot seek input file for %s record copy!", container_name);

23
  char *buffer = (char *) Malloc(recsize);
24
25
26
27
28
29
30

  if (fileRead(fileID1, buffer, recsize) != recsize)
    Error("Failed to read record from %s file for copying!", container_name);

  if (fileWrite(fileID2, buffer, recsize) != recsize)
    Error("Failed to write record to %s file when copying!", container_name);

31
  Free(buffer);
32
33
34
35
36
37
38
39
40
41
42
}

/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */