Branch data Line data Source code
1 : : /**
2 : : * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3 : : * storing and accessing finite element mesh data.
4 : : *
5 : : * Copyright 2004 Sandia Corporation. Under the terms of Contract
6 : : * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7 : : * retains certain rights in this software.
8 : : *
9 : : * This library is free software; you can redistribute it and/or
10 : : * modify it under the terms of the GNU Lesser General Public
11 : : * License as published by the Free Software Foundation; either
12 : : * version 2.1 of the License, or (at your option) any later version.
13 : : *
14 : : */
15 : :
16 : : #include <stdlib.h>
17 : : #include <string.h>
18 : : #include <H5Ipublic.h>
19 : : #include <H5Tpublic.h>
20 : : #include "file-handle.h"
21 : : #include "status.h"
22 : : #include "util.h"
23 : :
24 : : #define FILE_HANDLE_MAGIC 0xFEEDFEED
25 : :
26 : 8745 : int mhdf_check_valid_file( FileHandle* handle, mhdf_Status* status )
27 : : {
28 [ + + ]: 8745 : if( !handle )
29 : : {
30 : 3 : mhdf_setFail( status, "NULL file handle." );
31 : 3 : return 0;
32 : : }
33 : :
34 [ - + ]: 8742 : if( handle->magic != FILE_HANDLE_MAGIC )
35 : : {
36 : 0 : mhdf_setFail( status, "Invalid file handle." );
37 : 0 : return 0;
38 : : }
39 : :
40 : 8742 : return 1;
41 : : }
42 : :
43 : 107 : FileHandle* mhdf_alloc_FileHandle( hid_t hdf_table, hid_t id_type, mhdf_Status* status )
44 : : {
45 : : FileHandle* rval;
46 : :
47 : : /* check that id_type is sane */
48 [ + + ]: 107 : if( id_type == -1 ) { id_type = H5T_NATIVE_ULONG; }
49 [ - + ]: 105 : else if( H5T_INTEGER != H5Tget_class( id_type ) )
50 : : {
51 : 0 : mhdf_setFail( status, "Invalid ID type: not integer class" );
52 : 0 : return 0;
53 : : }
54 : :
55 : 107 : rval = (FileHandle*)mhdf_malloc( sizeof( FileHandle ), status );
56 [ - + ]: 107 : if( !rval ) return NULL;
57 : :
58 : 107 : rval->magic = FILE_HANDLE_MAGIC;
59 : 107 : rval->hdf_handle = hdf_table;
60 : 107 : rval->open_handle_count = 0;
61 : 107 : rval->id_type = id_type;
62 : 107 : rval->max_id = 0L;
63 : 107 : return rval;
64 : : }
|