MOAB: Mesh Oriented datABase  (version 5.3.1)
file-handle.c
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #include <stdlib.h>
00017 #include <string.h>
00018 #include <H5Ipublic.h>
00019 #include <H5Tpublic.h>
00020 #include "file-handle.h"
00021 #include "status.h"
00022 #include "util.h"
00023 
00024 #define FILE_HANDLE_MAGIC 0xFEEDFEED
00025 
00026 int mhdf_check_valid_file( FileHandle* handle, mhdf_Status* status )
00027 {
00028     if( !handle )
00029     {
00030         mhdf_setFail( status, "NULL file handle." );
00031         return 0;
00032     }
00033 
00034     if( handle->magic != FILE_HANDLE_MAGIC )
00035     {
00036         mhdf_setFail( status, "Invalid file handle." );
00037         return 0;
00038     }
00039 
00040     return 1;
00041 }
00042 
00043 FileHandle* mhdf_alloc_FileHandle( hid_t hdf_table, hid_t id_type, mhdf_Status* status )
00044 {
00045     FileHandle* rval;
00046 
00047     /* check that id_type is sane */
00048     if( id_type == -1 ) { id_type = H5T_NATIVE_ULONG; }
00049     else if( H5T_INTEGER != H5Tget_class( id_type ) )
00050     {
00051         mhdf_setFail( status, "Invalid ID type: not integer class" );
00052         return 0;
00053     }
00054 
00055     rval = (FileHandle*)mhdf_malloc( sizeof( FileHandle ), status );
00056     if( !rval ) return NULL;
00057 
00058     rval->magic = FILE_HANDLE_MAGIC;
00059     rval->hdf_handle = hdf_table;
00060     rval->open_handle_count = 0;
00061     rval->id_type = id_type;
00062     rval->max_id = 0L;
00063     return rval;
00064 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines