Makes few cleanning and adds an obi_dms C constructor
This commit is contained in:
49
src/obidms.c
49
src/obidms.c
@ -7,6 +7,14 @@
|
||||
|
||||
#include <obidms.h>
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* Internal function building the directory name from a OBIDMS name.
|
||||
*
|
||||
@ -50,6 +58,33 @@ static char *build_directory_name(const char *name) {
|
||||
return dirdbname;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
int obi_dms_exists(const char* name) {
|
||||
struct stat buffer;
|
||||
char *dirdbname;
|
||||
int exist;
|
||||
|
||||
// Build and check the directory name
|
||||
dirdbname = build_directory_name(name);
|
||||
if (dirdbname==NULL)
|
||||
return -1;
|
||||
|
||||
exist = stat(dirdbname,&buffer);
|
||||
|
||||
free(dirdbname);
|
||||
|
||||
if(exist == 0)
|
||||
return 1;
|
||||
else // -1
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_p obi_create_dms(const char *name) {
|
||||
char *dirdbname;
|
||||
|
||||
@ -127,6 +162,20 @@ OBIDMS_p obi_open_dms(const char *name) {
|
||||
return dms;
|
||||
}
|
||||
|
||||
OBIDMS_p obi_dms(const char *name) {
|
||||
int exist = obi_dms_exists(name);
|
||||
|
||||
switch (exist) {
|
||||
case 0:
|
||||
return obi_create_dms(name);
|
||||
case 1:
|
||||
return obi_open_dms(name);
|
||||
};
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int obi_close_dms(OBIDMS_p dms) {
|
||||
|
||||
|
Reference in New Issue
Block a user