Bug#861736:
Herethe code ofthismethod
/*--------------------------------------------------------------------*/
static NXstatus NXinternalopen(CONSTCHAR *userfilename, NXaccess am,
pFileStack fileStack);
/*----------------------------------------------------------------------*/
NXstatus NXopen(CONSTCHAR *userfilename, NXaccess am, NXhandle *gHandle){
int status;
pFileStack fileStack = NULL;
*gHandle = NULL;
fileStack = makeFileStack();
if(fileStack == NULL){
NXReportError("ERROR: no memory to create filestack");
return NX_ERROR;
}
status = NXinternalopen(userfilename,am,fileStack);
if(status == NX_OK){
*gHandle = fileStack;
}
return status;
so lets's see the internalopen
static NXstatus NXinternalopen(CONSTCHAR *userfilename, NXaccess am, pFileStack fileStack)
{
return LOCKED_CALL(NXinternalopenImpl(userfilename, am, fileStack));
}
/*-----------------------------------------------------------------------*/
static NXstatus NXinternalopenImpl(CONSTCHAR *userfilename, NXaccess am, pFileStack fileStack)
{
int hdf_type=0;
int iRet=0;
NXhandle hdf5_handle = NULL;
pNexusFunction fHandle = NULL;
NXstatus retstat = NX_ERROR;
char error[1024];
char *filename = NULL;
int my_am = (am & NXACCMASK_REMOVEFLAGS);
/* configure fortify
iFortifyScope = Fortify_EnterScope();
Fortify_CheckAllMemory();
*/
/*
allocate data
*/
fHandle = (pNexusFunction)malloc(sizeof(NexusFunction));
if (fHandle == NULL) {
NXReportError("ERROR: no memory to create Function structure");
return NX_ERROR;
}
memset(fHandle, 0, sizeof(NexusFunction)); /* so any functions we miss are NULL */
/*
test the strip flag. Elimnate it for the rest of the tests to work
*/
fHandle->stripFlag = 1;
if(am & NXACC_NOSTRIP){
fHandle->stripFlag = 0;
am = (NXaccess)(am & ~NXACC_NOSTRIP);
}
fHandle->checkNameSyntax = 0;
if (am & NXACC_CHECKNAMESYNTAX) {
fHandle->checkNameSyntax = 1;
am = (NXaccess)(am & ~NXACC_CHECKNAMESYNTAX);
}
if (my_am==NXACC_CREATE) {
/* HDF4 will be used ! */
hdf_type=1;
filename = strdup(userfilename);
} else if (my_am==NXACC_CREATE4) {
/* HDF4 will be used ! */
hdf_type=1;
filename = strdup(userfilename);
} else if (my_am==NXACC_CREATE5) {
/* HDF5 will be used ! */
hdf_type=2;
filename = strdup(userfilename);
} else if (my_am==NXACC_CREATEXML) {
/* XML will be used ! */
hdf_type=3;
filename = strdup(userfilename);
} else {
filename = locateNexusFileInPath((char *)userfilename);
if(filename == NULL){
NXReportError("Out of memory in NeXus-API");
free(fHandle);
return NX_ERROR;
}
/* check file type hdf4/hdf5/XML for reading */
iRet = determineFileType(filename);
if(iRet < 0) {
snprintf(error,1023,"failed to open %s for reading",
filename);
NXReportError(error);
free(filename);
return NX_ERROR;
}
if(iRet == 0){
snprintf(error,1023,"failed to determine filetype for %s ",
filename);
NXReportError(error);
free(filename);
free(fHandle);
return NX_ERROR;
}
hdf_type = iRet;
}
if(filename == NULL){
NXReportError("Out of memory in NeXus-API");
return NX_ERROR;
}
if (hdf_type==1) {
/* HDF4 type */
#ifdef HDF4
NXhandle hdf4_handle = NULL;
retstat = NX4open((const char *)filename,am,&hdf4_handle);
if(retstat != NX_OK){
free(fHandle);
free(filename);
return retstat;
}
fHandle->pNexusData=hdf4_handle;
NX4assignFunctions(fHandle);
pushFileStack(fileStack,fHandle,filename);
#else
NXReportError(
"ERROR: Attempt to create HDF4 file when not linked with HDF4");
retstat = NX_ERROR;
#endif /* HDF4 */
free(filename);
return retstat;
} else if (hdf_type==2) {
/* HDF5 type */
#ifdef HDF5
retstat = NX5open(filename,am,&hdf5_handle);
if(retstat != NX_OK){
free(fHandle);
free(filename);
return retstat;
}
fHandle->pNexusData=hdf5_handle;
NX5assignFunctions(fHandle);
pushFileStack(fileStack,fHandle, filename);
#else
NXReportError(
"ERROR: Attempt to create HDF5 file when not linked with HDF5");
retstat = NX_ERROR;
#endif /* HDF5 */
free(filename);
return retstat;
} else if(hdf_type == 3){
/*
XML type
*/
#ifdef NXXML
NXhandle xmlHandle = NULL;
retstat = NXXopen(filename,am,&xmlHandle);
if(retstat != NX_OK){
free(fHandle);
free(filename);
return retstat;
}
fHandle->pNexusData=xmlHandle;
NXXassignFunctions(fHandle);
pushFileStack(fileStack,fHandle, filename);
#else
NXReportError(
"ERROR: Attempt to create XML file when not linked with XML");
retstat = NX_ERROR;
#endif
} else {
NXReportError(
"ERROR: Format not readable by this NeXus library");
retstat = NX_ERROR;
}
if (filename != NULL) {
free(filename);
}
return retstat;
}
Reply to: