cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
container_classes.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #include "cddefines.h"
5 
8 void do_dump_state(const void* buf, size_t nelem, size_t size, FILE* out, int32 magic)
9 {
10  DEBUG_ENTRY( "do_dump_state()" );
11 
12  bool lgErr = ( fwrite( &magic, sizeof(int32), 1, out ) != 1 );
13  int32 help = (int32)sizeof(size_t);
14  lgErr = lgErr || ( fwrite( &help, sizeof(int32), 1, out ) != 1 );
15  lgErr = lgErr || ( fwrite( &size, sizeof(size_t), 1, out ) != 1 );
16  lgErr = lgErr || ( fwrite( buf, size, nelem, out ) != nelem );
17  if( lgErr )
18  {
19  fprintf( ioQQQ, " I/O error while dumping state!\n" );
20  cdEXIT(EXIT_FAILURE);
21  }
22 }
23 
28 void do_restore_state(void* buf, size_t nelem, size_t size, FILE *in, int32 magic)
29 {
30  DEBUG_ENTRY( "do_restore_state()" );
31 
32  int32 help = 0;
33  size_t help2 = 0;
34  bool lgErr = ( fread( &help, sizeof(int32), 1, in ) != 1 );
35  // this checks for correct version and prevents mixing up old style and new style data
36  // it also prevents mixing up data from big-endian and little-endian machines.
37  lgErr = lgErr || ( help != magic );
38  lgErr = lgErr || ( fread( &help, sizeof(int32), 1, in ) != 1 );
39  // this prevents mixing up data from 32-bit and 64-bit systems
40  lgErr = lgErr || ( help != (int32)sizeof(size_t) );
41  lgErr = lgErr || ( fread( &help2, sizeof(size_t), 1, in ) != 1 );
42  // this may guard against reading an older, incompatible version of the array
43  lgErr = lgErr || ( help2 != size );
44  lgErr = lgErr || ( fread( buf, size, nelem, in ) != nelem );
45  if( lgErr )
46  {
47  fprintf( ioQQQ, " Error while restoring state!\n" );
48  cdEXIT(EXIT_FAILURE);
49  }
50 }

Generated for cloudy by doxygen 1.8.1.1