hid_t
ss_file_isopen(ss_file_t *file, /* Optional handle to a persistent File object. */
const char *name /* Optional real name of file to test for open status. */
)
{
SS_ENTER(ss_file_isopen, hid_t);
ss_gfile_t *gfile=NULL;
hid_t retval=0; /* zero is false and not a valid HDF5 file handle */
char *fixedname=NULL;
size_t i;
if (file) SS_ASSERT_MEM(file, ss_file_t);
if (file && name) {
/* Check that FILE is opened with NAME */
if (NULL==(gfile=SS_GFILE_LINK(file))) SS_ERROR(NOTFOUND);
if (gfile->cur_open>0) {
if (NULL==(fixedname=ss_file_fixname(name, NULL, NULL, 0, NULL))) SS_ERROR(FAILED);
if (!strcmp(fixedname, gfile->name)) retval = gfile->fid;
fixedname = SS_FREE(fixedname);
}
} else if (file) {
/* Check that FILE is open */
if (NULL==(gfile=SS_GFILE_LINK(file))) SS_ERROR(NOTFOUND);
if (gfile->cur_open>0) retval = gfile->fid;
} else if (name) {
/* Check that NAME is open */
if (NULL==(fixedname=ss_file_fixname(name, NULL, NULL, 0, NULL))) SS_ERROR(FAILED);
if (SS_NOSIZE!=(i=ss_gfile_find_name(fixedname))) {
gfile = SS_GFILE_IDX(i);
if (gfile->cur_open>0) retval = gfile->fid;
}
fixedname = SS_FREE(fixedname);
} else {
SS_ERROR(USAGE);
}
SS_CLEANUP:
SS_FREE(fixedname);
SS_LEAVE(retval);
}