Commit ed662077 by Celine Mercier

fixed bugs and typos in the obidms and obidmscolumn source and header

files
parent 9f9c20aa
......@@ -5,7 +5,10 @@
* @Author: coissac
*/
#include <obidms.h>
#include <stdlib.h>
#include <stdio.h>
#include "obidms.h"
/************************************************************************
......@@ -23,10 +26,10 @@
*
* @warning The returned pointer has to be freed by the caller.
*
* @param name the name of the OBIDMS
* @param dms_name the name of the OBIDMS
*
* @return a pointer to the directory name
* @retvalue <dirdbname> if everything is ok
* @retvalue <directory_name> if everything is ok
* @retvalue NULL if an error occurs
*
* ###Error values
......@@ -36,96 +39,110 @@
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
static char *build_directory_name(const char *name) {
static char *build_directory_name(const char *dms_name);
/***********************************************************************
*
* 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
*
***********************************************************************/
char *dirdbname;
static char *build_directory_name(const char *dms_name)
{
char *directory_name;
// Build the database directory name
if (asprintf(&dirdbname,"%s.obidms",name) < 0)
if (asprintf(&directory_name, "%s.obidms", dms_name) < 0)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
return NULL;
}
// Test if the database name is not too long
if (strlen(dirdbname) >= OBIDMS_MAX_NAME)
if (strlen(directory_name) >= OBIDMS_MAX_NAME)
{
obi_set_errno(OBIDMS_LONG_NAME_ERROR);
free(dirdbname);
free(directory_name);
return NULL;
}
return dirdbname;
return directory_name;
}
/***********************************************************************
/*********************************************************************
*
* 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
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
*
***********************************************************************/
*********************************************************************/
int obi_dms_exists(const char* name) {
int obi_dms_exists(const char* dms_name)
{
struct stat buffer;
char *dirdbname;
int exist;
char *directory_name;
int exists;
// Build and check the directory name
dirdbname = build_directory_name(name);
if (dirdbname==NULL)
directory_name = build_directory_name(dms_name);
if (directory_name == NULL)
return -1;
exist = stat(dirdbname,&buffer);
exists = stat(directory_name, &buffer);
free(dirdbname);
free(directory_name);
if(exist == 0)
if(exists == 0)
return 1;
else // -1
return 0;
}
OBIDMS_p obi_create_dms(const char *name) {
char *dirdbname;
OBIDMS_p obi_create_dms(const char* dms_name)
{
char *directory_name;
// Build and check the directory name
dirdbname = build_directory_name(name);
if (dirdbname==NULL)
directory_name = build_directory_name(dms_name);
if (directory_name == NULL)
return NULL;
// Try to create the directory
if (mkdir(dirdbname,0x777) < 0)
if (mkdir(directory_name, 0x777) < 0)
{
if (errno==EEXIST)
if (errno == EEXIST)
obi_set_errno(OBIDMS_EXIST_ERROR);
else
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
free(dirdbname);
free(directory_name);
return NULL;
}
free(dirdbname);
free(directory_name);
return obi_open_dms(name);
return obi_open_dms(dms_name);
}
OBIDMS_p obi_open_dms(const char *name) {
OBIDMS_p dms=NULL;
char *dirdbname;
DIR *directory;
OBIDMS_p obi_open_dms(const char* dms_name)
{
OBIDMS_p dms;
char* directory_name;
DIR* directory;
dms = NULL;
// Build and check the directory name
dirdbname = build_directory_name(name);
if (dirdbname==NULL)
directory_name = build_directory_name(dms_name);
if (directory_name == NULL)
return NULL;
// try to open the directory
directory = opendir(dirdbname);
if (directory==NULL) {
directory = opendir(directory_name);
if (directory == NULL) {
switch (errno) {
case ENOENT:
obi_set_errno(OBIDMS_NOT_EXIST_ERROR);
......@@ -142,37 +159,38 @@ OBIDMS_p obi_open_dms(const char *name) {
default:
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
}
free(dirdbname);
free(directory_name);
return NULL;
}
// Allocate the data structure
dms = (OBIDMS_p) malloc(sizeof(OBIDMS_t));
if (dms==NULL)
if (dms == NULL)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
free(dirdbname);
free(directory_name);
return NULL;
}
// Initialise the data structure
strcpy(dms->dirname,dirdbname);
dms->directory=directory;
// Initialize the data structure
strcpy(dms->directory_name, directory_name);
dms->directory = directory;
free(dirdbname);
free(directory_name);
return dms;
}
OBIDMS_p obi_dms(const char *name) {
int exist = obi_dms_exists(name);
OBIDMS_p obi_dms(const char* dms_name)
{
int exists = obi_dms_exists(dms_name);
switch (exist) {
switch (exists) {
case 0:
return obi_create_dms(name);
return obi_create_dms(dms_name);
case 1:
return obi_open_dms(name);
return obi_open_dms(dms_name);
};
return NULL;
......@@ -180,8 +198,8 @@ OBIDMS_p obi_dms(const char *name) {
}
int obi_close_dms(OBIDMS_p dms) {
int obi_close_dms(OBIDMS_p dms)
{
if (dms != NULL)
{
if (closedir(dms->directory) < 0)
......@@ -190,9 +208,7 @@ int obi_close_dms(OBIDMS_p dms) {
free(dms);
return -1;
}
free(dms);
}
return 0;
......
......@@ -15,31 +15,31 @@
#include <string.h>
#include <stdio.h>
#include <obierrno.h>
#include "obierrno.h"
#define OBIDMS_MAX_NAME (2048) /**< The maximum length of an OBIDMS name
*/
/** @brief A structure decribing an OBIDMS instance
/** @brief A structure describing an OBIDMS instance
*
* A pointer to this structure is returned on creation
* and opening of an OBITools Data Management System (DMS)
*/
typedef struct OBIDMS {
char dirname[OBIDMS_MAX_NAME+1]; /**< The name of the directory
* containing the DMS
*/
DIR *directory; /**< A directory entry usable to
* refer and scan the database directory
*/
char directory_name[OBIDMS_MAX_NAME+1]; /**< The name of the directory
* containing the DMS
*/
DIR* directory; /**< A directory entry usable to
* refer and scan the database directory
*/
} OBIDMS_t, *OBIDMS_p;
/*@
* @brief Checks if an OBIDMS exists
*
* @param name a pointer to a C string containing the name of the database.
* @param dms_name a pointer to a C string containing the name of the database.
* The actual directory name used to store the DMS will be
* `<name>.obidms`.
*
......@@ -52,7 +52,7 @@ typedef struct OBIDMS {
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
int obi_dms_exists(const char* name);
int obi_dms_exists(const char* dms_name);
/**
......@@ -62,7 +62,7 @@ int obi_dms_exists(const char* name);
* if a directory with this name does not already exist
* before creating the new database.
*
* @param name a pointer to a C string containing the name of the database.
* @param dms_name a pointer to a C string containing the name of the database.
* The actual directory name used to store the DMS will be
* `<name>.obidms`
*
......@@ -78,13 +78,13 @@ int obi_dms_exists(const char* name);
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
OBIDMS_p obi_create_dms(const char *name);
OBIDMS_p obi_create_dms(const char *dms_name);
/**
* @brief Opens an existing OBITools Data Management instance (OBIDMS).
*
* @param name a pointer to a C string containing the name of the database.
* @param dms_name a pointer to a C string containing the name of the database.
* The actual directory name used to store the DMS will be
* `<name>.obidms`
*
......@@ -100,7 +100,7 @@ OBIDMS_p obi_create_dms(const char *name);
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
OBIDMS_p obi_open_dms(const char *name);
OBIDMS_p obi_open_dms(const char *dms_name);
/**
......@@ -109,7 +109,7 @@ OBIDMS_p obi_open_dms(const char *name);
* If the database already exists, this function opens it, otherwise it
* creates a new database.
*
* @param name a pointer to a C string containing the name of the database.
* @param dms_name a pointer to a C string containing the name of the database.
* The actual directory name used to store the DMS is
* `<name>.obidms`
*
......@@ -124,7 +124,7 @@ OBIDMS_p obi_open_dms(const char *name);
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
OBIDMS_p obi_dms(const char *name);
OBIDMS_p obi_dms(const char *dms_name);
/**
......
......@@ -18,10 +18,10 @@
#include <stdbool.h>
#include <time.h>
#include <obidms.h>
#include <obitypes.h>
#include <obierrno.h>
#include <obilittlebigman.h>
#include "obidms.h"
#include "obitypes.h"
#include "obierrno.h"
#include "obilittlebigman.h"
#define OBIDMS_MAX_COLNAME (128) /**< The maximum length of an OBIDMS column name
......@@ -43,7 +43,7 @@ typedef struct OBIDMS_column_header {
*/
int header_size; /**< size of the header in bytes */
size_t line_count; /**< number of lines of data */
size_t line_used; /**< number of lines of data used*/
size_t lines_used; /**< number of lines of data used*/
OBIType_t data_type; /**< type of the data */
time_t creation_date; /**< date of creation of the file */
obiversion_t version; /**< version of the OBIColumn */
......@@ -89,8 +89,8 @@ typedef struct OBIDMS_column {
/**
* @brief Returns the header size in bytes of a column on this platform.
*
* Header size is defined as a multiple of the memory page size.
* Up to now the header size is defined as one time the page size
* The header size is defined as a multiple of the memory page size.
* Up to now the header size is defined as one time the page size.
*
* @return a `size_t` value corresponding to the header size in bytes
*
......@@ -104,29 +104,29 @@ size_t obi_get_platform_header_size();
* @brief Creates a column.
*
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
* @param name the name of the new column
* @param column_name the name of the new column
* @param type the OBIType code used to create the column
* @param nbelements the number of elements to be stored
* @param nb_elements the number of elements to be stored
*
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
char* name,
char* column_name,
OBIType_t type,
size_t nbelements);
size_t nb_elements);
/**
* @brief Returns the latest column version in the `dms` database
*
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
* @param name the name of the column
* @param column_name the name of the column
*
* @return the bigger version number used for this column
* @return -1 if the column does not exist
*/
obiversion_t obi_latest_version(OBIDMS_p dms,char *name);
obiversion_t obi_get_latest_version_number(OBIDMS_p dms, char *column_name);
#endif /* OBIDMSCOLUMN_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment