fixed typos and other minor things
This commit is contained in:
13
src/obidms.c
13
src/obidms.c
@ -8,17 +8,17 @@
|
||||
#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.
|
||||
* Internal function building the directory name from an OBIDMS name.
|
||||
*
|
||||
* The function build the directory name corresponding to a OBIDMS.
|
||||
* The function builds the directory name corresponding to an OBIDMS.
|
||||
* It checks also that the name is not too long.
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
@ -30,7 +30,7 @@
|
||||
* @retvalue NULL if an error occurs
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
*
|
||||
* @since May 2015
|
||||
@ -58,6 +58,7 @@ 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
|
||||
@ -111,6 +112,7 @@ OBIDMS_p obi_create_dms(const char *name) {
|
||||
return obi_open_dms(name);
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_p obi_open_dms(const char *name) {
|
||||
OBIDMS_p dms=NULL;
|
||||
char *dirdbname;
|
||||
@ -162,6 +164,7 @@ OBIDMS_p obi_open_dms(const char *name) {
|
||||
return dms;
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_p obi_dms(const char *name) {
|
||||
int exist = obi_dms_exists(name);
|
||||
|
||||
|
76
src/obidms.h
76
src/obidms.h
@ -35,43 +35,18 @@ typedef struct OBIDMS {
|
||||
*/
|
||||
} OBIDMS_t, *OBIDMS_p;
|
||||
|
||||
/**
|
||||
* @defgroup OBIDMSErrors OBIDMS related error codes
|
||||
*
|
||||
* Error codes set in errno following an error related
|
||||
* to the manipulation of an OBIDMS.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define OBIDMS_EXIST_ERROR (1) /**< Try to create an OBIDMS with a name
|
||||
* that corresponds to an existing OBIDMS
|
||||
*/
|
||||
#define OBIDMS_NOT_EXIST_ERROR (2) /**< Try to open a non-existing OBIDMS
|
||||
*/
|
||||
#define OBIDMS_LONG_NAME_ERROR (3) /**< The specified OBIDMS name is too long
|
||||
*/
|
||||
#define OBIDMS_MEMORY_ERROR (4) /**< A memory error occurred during allocation
|
||||
*/
|
||||
#define OBIDMS_UNKNOWN_ERROR (5) /**< Not determined error
|
||||
*/
|
||||
#define OBIDMS_ACCESS_ERROR (6) /**< Permission error for accessing to the database
|
||||
*/
|
||||
#define OBIDMS_BAD_ENDIAN_ERROR (7) /**< The opened data structure does not corresponds
|
||||
* to the endianess of the platform.
|
||||
*/
|
||||
/**@}*/
|
||||
|
||||
/*@
|
||||
* @brief Check if a OBIDMS exist
|
||||
* @brief Checks if an OBIDMS exists
|
||||
*
|
||||
* @param 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`
|
||||
* @param 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`.
|
||||
*
|
||||
* @return an integer value indicating the status of the database
|
||||
* @retvalue 1 the database exist
|
||||
* @retvalue 0 the database does not exist
|
||||
* @retvalue -1 an error occurs
|
||||
* @retvalue -1 an error occured
|
||||
*
|
||||
* @see obi_close_dms()
|
||||
* @since May 2015
|
||||
@ -79,15 +54,16 @@ typedef struct OBIDMS {
|
||||
*/
|
||||
int obi_dms_exists(const char* name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create a new OBITools Data Management instance (OBIDMS).
|
||||
* @brief Creates a new OBITools Data Management instance (OBIDMS).
|
||||
*
|
||||
* A `DMS` is implemented as a directory. This function takes care
|
||||
* to check if a directory with this name does not already exist
|
||||
* before creating the new database
|
||||
* A `DMS` is implemented as a directory. This function checks
|
||||
* 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
|
||||
* the actual directory name used to store the DMS will be
|
||||
* @param 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`
|
||||
*
|
||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||
@ -96,7 +72,7 @@ int obi_dms_exists(const char* name);
|
||||
* ###Error values
|
||||
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||
*
|
||||
* @see obi_close_dms()
|
||||
* @since May 2015
|
||||
@ -104,11 +80,12 @@ int obi_dms_exists(const char* name);
|
||||
*/
|
||||
OBIDMS_p obi_create_dms(const char *name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Open an existing OBITools Data Management instance (OBIDMS).
|
||||
* @brief Opens an existing OBITools Data Management instance (OBIDMS).
|
||||
*
|
||||
* @param name a pointer to a C string containing the name of the database
|
||||
* the actual directory name used to store the DMS will be
|
||||
* @param 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`
|
||||
*
|
||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||
@ -117,7 +94,7 @@ OBIDMS_p obi_create_dms(const char *name);
|
||||
* ###Error values
|
||||
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||
*
|
||||
* @see obi_close_dms()
|
||||
* @since May 2015
|
||||
@ -125,14 +102,15 @@ OBIDMS_p obi_create_dms(const char *name);
|
||||
*/
|
||||
OBIDMS_p obi_open_dms(const char *name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create a new OBIDMS instance.
|
||||
* @brief Creates a new OBIDMS instance.
|
||||
*
|
||||
* If the database already exist this function open it, otherwise it
|
||||
* creates a new databse.
|
||||
* 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
|
||||
* the actual directory name used to store the DMS is
|
||||
* @param 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`
|
||||
*
|
||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||
@ -140,7 +118,7 @@ OBIDMS_p obi_open_dms(const char *name);
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||
*
|
||||
* @see obi_close_dms()
|
||||
* @since May 2015
|
||||
@ -148,8 +126,9 @@ OBIDMS_p obi_open_dms(const char *name);
|
||||
*/
|
||||
OBIDMS_p obi_dms(const char *name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Close an opened OBITools Data Management instance (OBIDMS).
|
||||
* @brief Closes an opened OBITools Data Management instance (OBIDMS).
|
||||
*
|
||||
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
||||
*
|
||||
@ -165,4 +144,5 @@ OBIDMS_p obi_dms(const char *name);
|
||||
*/
|
||||
int obi_close_dms(OBIDMS_p dms);
|
||||
|
||||
|
||||
#endif /* OBIDMS_H_ */
|
||||
|
@ -1,9 +1,9 @@
|
||||
/****************************************************************************
|
||||
* OBIDMSColumn functions *
|
||||
* OBIDMS_column functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidmscolumn.h
|
||||
* @file OBIDMS_column.h
|
||||
* @author Celine Mercier
|
||||
* @date 22 May 2015
|
||||
* @brief Functions for the shared elements of all the OBIColumn structures.
|
||||
@ -16,17 +16,17 @@
|
||||
#include <sys/mman.h> /* mmap() is defined in this header */
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
/*************************************************************************
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
*
|
||||
***********************************************************************/
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function building the file name for a column.
|
||||
*
|
||||
* The function build the file name corresponding to a column of an OBIDMS.
|
||||
* The function builds the file name corresponding to a column of an OBIDMS.
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
*
|
||||
@ -36,12 +36,13 @@
|
||||
* @retvalue NULL if an error occurs
|
||||
*
|
||||
* ###Error values
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
||||
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
static char *build_column_name(const char *name,obiversion_t version);
|
||||
static char *build_column_name(const char *name, obiversion_t version);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function building the file name for a version column file.
|
||||
@ -64,6 +65,7 @@ static char *build_column_name(const char *name,obiversion_t version);
|
||||
*/
|
||||
static char *build_version_name(const char *name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function returning a new column version number
|
||||
* in the `dms` database
|
||||
@ -82,6 +84,7 @@ static char *build_version_name(const char *name);
|
||||
*/
|
||||
static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function creating a new column version file
|
||||
* in the `dms` database
|
||||
@ -99,11 +102,12 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block);
|
||||
*/
|
||||
static int create_version(OBIDMS_p dms,char *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 R I V A T E F U N C T I O N S
|
||||
*
|
||||
***********************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
static char *build_column_name(const char *name,obiversion_t version) {
|
||||
|
||||
@ -134,6 +138,7 @@ static char *build_version_name(const char *name) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
||||
|
||||
off_t locsize=sizeof(bool) + sizeof(obiversion_t);
|
||||
@ -164,13 +169,16 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
||||
}
|
||||
|
||||
//open the version file
|
||||
versionfd = openat(directoryfd,versionfile,O_RDWR);
|
||||
//versionfd = openat(directoryfd, versionfile, O_RDWR);
|
||||
versionfd = open(versionfile, O_RDWR);
|
||||
|
||||
|
||||
if (versionfd < 0) {
|
||||
free(versionfile);
|
||||
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
return create_version(dms,name);
|
||||
return create_version(dms, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -180,7 +188,7 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
||||
}
|
||||
|
||||
// Test if the version file size is ok
|
||||
if (lseek(versionfd,SEEK_END,0) < locsize)
|
||||
if (lseek(versionfd, SEEK_END, 0) < locsize)
|
||||
{
|
||||
close(versionfd);
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
@ -189,7 +197,7 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
||||
}
|
||||
|
||||
// prepare the file for locking
|
||||
if (lseek(versionfd,SEEK_SET,0) != 0)
|
||||
if (lseek(versionfd, SEEK_SET, 0) != 0)
|
||||
{
|
||||
close(versionfd);
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
@ -216,7 +224,7 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
||||
}
|
||||
|
||||
// check if endianess is correct
|
||||
if (little != obi_is_little_end())
|
||||
if (little != obi_is_little_endian())
|
||||
{
|
||||
close(versionfd);
|
||||
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
||||
@ -275,6 +283,7 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
||||
return newversion;
|
||||
}
|
||||
|
||||
|
||||
static int create_version(OBIDMS_p dms,char *name) {
|
||||
off_t locsize=sizeof(bool) + sizeof(obiversion_t);
|
||||
obiversion_t version=0;
|
||||
@ -295,10 +304,15 @@ static int create_version(OBIDMS_p dms,char *name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
versionfd = openat(directoryfd,
|
||||
versionfile,
|
||||
O_RDWR|O_CREAT|O_EXCL,
|
||||
666);
|
||||
//versionfd = openat(directoryfd,
|
||||
// versionfile,
|
||||
// O_RDWR|O_CREAT|O_EXCL,
|
||||
// 666);
|
||||
|
||||
versionfd = open(versionfile,
|
||||
O_RDWR|O_CREAT|O_EXCL,
|
||||
666);
|
||||
|
||||
|
||||
if (versionfd < 0) {
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
@ -331,7 +345,7 @@ static int create_version(OBIDMS_p dms,char *name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
little = obi_is_little_end();
|
||||
little = obi_is_little_endian();
|
||||
|
||||
if (write(versionfd, &little, sizeof(bool)) < sizeof(bool))
|
||||
{
|
||||
@ -372,6 +386,7 @@ static int create_version(OBIDMS_p dms,char *name) {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* 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
|
||||
@ -397,7 +412,9 @@ obiversion_t obi_latest_version(OBIDMS_p dms,char *name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
versionfd = openat(directoryfd,versionfile,O_RDWR);
|
||||
//versionfd = openat(directoryfd,versionfile,O_RDWR);
|
||||
versionfd = open(versionfile,O_RDWR);
|
||||
|
||||
if (versionfd < 0) {
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
free(versionfile);
|
||||
@ -428,7 +445,7 @@ obiversion_t obi_latest_version(OBIDMS_p dms,char *name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (little != obi_is_little_end())
|
||||
if (little != obi_is_little_endian())
|
||||
{
|
||||
close(versionfd);
|
||||
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
||||
@ -450,20 +467,20 @@ obiversion_t obi_latest_version(OBIDMS_p dms,char *name) {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
size_t obi_get_platform_header_size()
|
||||
{
|
||||
return getpagesize() * 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
char *name,
|
||||
OBIType_t type,
|
||||
size_t nbelement)
|
||||
size_t nbelements)
|
||||
{
|
||||
OBIDMSColumn_p newcolumn=NULL;
|
||||
OBIDMSColumnHeader_p header;
|
||||
OBIDMS_column_p newcolumn=NULL;
|
||||
OBIDMS_column_header_p header;
|
||||
size_t filesize;
|
||||
obiversion_t version;
|
||||
char * columnfile;
|
||||
@ -480,7 +497,7 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
hsize = obi_get_platform_header_size();
|
||||
dsize = obi_array_sizeof(type,nbelement);
|
||||
dsize = obi_array_sizeof(type,nbelements);
|
||||
|
||||
filesize = hsize + dsize;
|
||||
|
||||
@ -494,10 +511,14 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
||||
|
||||
columnfile = build_column_name(name,version);
|
||||
|
||||
columnfd = openat(directoryfd,
|
||||
columnfile,
|
||||
O_RDWR|O_CREAT|O_EXCL,
|
||||
666);
|
||||
//columnfd = openat(directoryfd,
|
||||
// columnfile,
|
||||
// O_RDWR|O_CREAT|O_EXCL,
|
||||
// 666);
|
||||
|
||||
columnfd = open(columnfile,
|
||||
O_RDWR|O_CREAT|O_EXCL,
|
||||
666);
|
||||
|
||||
if (ftruncate(columnfd,filesize) < 0)
|
||||
{
|
||||
@ -507,7 +528,7 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newcolumn = (OBIDMSColumn_p) malloc(sizeof(OBIDMSColumn_t));
|
||||
newcolumn = (OBIDMS_column_p) malloc(sizeof(OBIDMS_column_t));
|
||||
|
||||
if (newcolumn)
|
||||
{
|
||||
@ -556,9 +577,9 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
||||
newcolumn->writable= true;
|
||||
|
||||
header = newcolumn->header;
|
||||
header->little_endian = obi_is_little_end();
|
||||
header->little_endian = obi_is_little_endian();
|
||||
header->header_size = hsize;
|
||||
header->line_count = nbelement;
|
||||
header->line_count = nbelements;
|
||||
header->line_used = 0;
|
||||
header->data_type = type;
|
||||
header->creation_date = time(NULL);
|
||||
@ -571,7 +592,6 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if( access( fname, F_OK ) != -1 ) {
|
||||
// // file exists
|
||||
// } else {
|
||||
|
@ -1,12 +1,12 @@
|
||||
/****************************************************************************
|
||||
* OBIDMSColumn header file *
|
||||
* OBIDMS_column header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obidmscolumn.h
|
||||
* @author Celine Mercier
|
||||
* @date 12 May 2015
|
||||
* @brief Header file for the shared elements of all the OBIColumn structures.
|
||||
* @brief Header file for the shared elements of all the OBIDMS column structures.
|
||||
*/
|
||||
|
||||
#ifndef OBIDMSCOLUMN_H_
|
||||
@ -34,10 +34,10 @@ typedef int32_t obiversion_t; /**< Used to store the column version number
|
||||
* @brief OBIColumnHeader structure.
|
||||
*/
|
||||
|
||||
typedef struct OBIDMSColumnHeader {
|
||||
typedef struct OBIDMS_column_header {
|
||||
bool little_endian; /**< endianess of the column:
|
||||
- `true` on little endian platform
|
||||
- `false` on big endian platform
|
||||
- `true` on little endian platforms
|
||||
- `false` on big endian platforms
|
||||
|
||||
@see obi_is_little_end()
|
||||
*/
|
||||
@ -52,41 +52,42 @@ typedef struct OBIDMSColumnHeader {
|
||||
*/
|
||||
char comments[1]; /**< comments stored as a classical
|
||||
zero end C string. T
|
||||
The size of the comment is just limited
|
||||
The size of the comment is only limited
|
||||
by the header size
|
||||
*/
|
||||
} OBIDMSColumnHeader_t, *OBIDMSColumnHeader_p;
|
||||
} OBIDMS_column_header_t, *OBIDMS_column_header_p;
|
||||
|
||||
/**
|
||||
* @brief Structure describing a Column of the OBITools DMS
|
||||
*
|
||||
* A data structure of this type is returned by the functions
|
||||
* creating, opening or cloning an OBIDMSColumn.
|
||||
* creating, opening or cloning an OBIDMS_column.
|
||||
*/
|
||||
typedef struct OBIDMSColumn {
|
||||
typedef struct OBIDMS_column {
|
||||
OBIDMS_p dms ; /**< A pointer to a DMS instance
|
||||
*/
|
||||
OBIDMSColumnHeader_p header; /**< A pointer to the header of the column
|
||||
OBIDMS_column_header_p header; /**< A pointer to the header of the column
|
||||
*/
|
||||
void* data; /**< A `void` pointer to the beginning of the
|
||||
* data.
|
||||
*
|
||||
* @attention never use this member directly
|
||||
* outside of the code of the
|
||||
* low level functions
|
||||
* of the OBITools DMS
|
||||
* @warning never use this member directly
|
||||
* outside of the code of the
|
||||
* low level functions
|
||||
* of the OBITools DMS
|
||||
*/
|
||||
bool writable;/**< Indicates if the column is writable or not.
|
||||
* - `true` the column is writable
|
||||
* - `false` the column is read-only
|
||||
*
|
||||
* A column is writable only by its creator
|
||||
* until he closes it.
|
||||
* until it closes it.
|
||||
*/
|
||||
} OBIDMSColumn_t, *OBIDMSColumn_p;
|
||||
} OBIDMS_column_t, *OBIDMS_column_p;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the header size in bytes of a column on this platform.
|
||||
* @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
|
||||
@ -99,27 +100,25 @@ typedef struct OBIDMSColumn {
|
||||
size_t obi_get_platform_header_size();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create a column.
|
||||
* @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 type the OBIType code used to create the column
|
||||
* @param nbelement the number of element to be stored
|
||||
* @param nbelements the number of elements to be stored
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
|
||||
OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
char* name,
|
||||
OBIType_t type,
|
||||
size_t nbelement);
|
||||
size_t nbelements);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return the latest column version in the `dms` database
|
||||
* @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
|
||||
@ -130,5 +129,4 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
||||
obiversion_t obi_latest_version(OBIDMS_p dms,char *name);
|
||||
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_H_ */
|
||||
|
@ -11,26 +11,54 @@
|
||||
/**
|
||||
* @brief The declaration of the external variable `obi_errno`.
|
||||
*
|
||||
* `obi_errno` is an equivalent of `errno` for the system level error
|
||||
* but for for error generated by the C layer of the OBITools framework.
|
||||
* `obi_errno` is an equivalent of `errno` for the system level error,
|
||||
* but for errors generated by the C layer of the OBITools framework.
|
||||
*
|
||||
* @todo We have to look for defining this variable as thread specific.
|
||||
* @todo We have to look into defining this variable as thread specific.
|
||||
*/
|
||||
extern int obi_errno;
|
||||
|
||||
|
||||
/**
|
||||
* @brief set the global `obi_errno` variable with
|
||||
* @brief Sets the global `obi_errno` variable with
|
||||
* the specified `err` code
|
||||
*
|
||||
* This function is defined as a macro to reduce the risk
|
||||
* to increase the problem generating the error by calling
|
||||
* of increasing the problem generating the error by calling
|
||||
* a new function.
|
||||
*
|
||||
* @param err the error code as an integer value
|
||||
* @param err The error code as an integer value.
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
#define obi_set_errno(err) (obi_errno = (err))
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup OBIDMSErrors OBIDMS related error codes
|
||||
*
|
||||
* Error codes set in errno following an error related
|
||||
* to the manipulation of an OBIDMS.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define OBIDMS_EXIST_ERROR (1) /**< Trying to create an OBIDMS with a name
|
||||
* that corresponds to an existing OBIDMS
|
||||
*/
|
||||
#define OBIDMS_NOT_EXIST_ERROR (2) /**< Trying to open a non-existing OBIDMS
|
||||
*/
|
||||
#define OBIDMS_LONG_NAME_ERROR (3) /**< The specified OBIDMS name is too long
|
||||
*/
|
||||
#define OBIDMS_MEMORY_ERROR (4) /**< A memory error occurred during allocation
|
||||
*/
|
||||
#define OBIDMS_UNKNOWN_ERROR (5) /**< Undetermined error
|
||||
*/
|
||||
#define OBIDMS_ACCESS_ERROR (6) /**< Permission error trying to access the database
|
||||
*/
|
||||
#define OBIDMS_BAD_ENDIAN_ERROR (7) /**< The opened data structure does not corresponds
|
||||
* to the endianess of the platform.
|
||||
*/
|
||||
/**@}*/
|
||||
|
||||
#endif /* OBIERRNO_H_ */
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
#include "obilittlebigman.h"
|
||||
|
||||
bool obi_is_little_end()
|
||||
{
|
||||
|
||||
bool obi_is_little_endian() {
|
||||
union { int entier;
|
||||
char caractere[4] ;
|
||||
} test;
|
||||
|
@ -11,17 +11,17 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* Test is the architecture of the processor is little endian.
|
||||
* Test if the architecture of the processor is little endian.
|
||||
*
|
||||
* ##Two classes of CPU architecture can be define:
|
||||
* ##Two classes of CPU architecture can be defined:
|
||||
* - little endian
|
||||
* - big endian
|
||||
*
|
||||
* They describe the way the processor store multi-byte values
|
||||
* in memory. Considering an 32 bits integer value encoded in
|
||||
* hexadecimal `0x11223344`. This value needs four bytes to be
|
||||
* stored. These for bytes will have consecutive addresses in memory.
|
||||
* Let says that these addresses will be : 01, 02, 03, and 04
|
||||
* They describe the way the processor stores multi-byte values
|
||||
* in memory. If we consider a 32 bits integer value encoded in
|
||||
* hexadecimal `0x11223344`, this value needs four bytes to be
|
||||
* stored. These four bytes will have consecutive addresses in memory.
|
||||
* Let's say that these addresses will be : 01, 02, 03, and 04
|
||||
*
|
||||
* ###A big endian architecture will store our integer with the following schema:
|
||||
*
|
||||
@ -29,7 +29,7 @@
|
||||
* ---------|------|------|------|------
|
||||
* value | Ox11 | Ox22 | 0x33 | 0x44
|
||||
*
|
||||
* In this architecture the last address (the end of the representation) is
|
||||
* In this architecture, the last address (the end of the representation) is
|
||||
* used to store the byte of higher weight (BIG ENDian)
|
||||
*
|
||||
* ###A little endian architecture will store our integer with the following schema:
|
||||
@ -38,7 +38,7 @@
|
||||
* ---------|------|------|------|------
|
||||
* value | Ox44 | Ox33 | 0x22 | 0x11
|
||||
*
|
||||
* In this architecture the last address is
|
||||
* In this architecture, the last address is
|
||||
* used to store the byte of lighter weight (LITTLE ENDian)
|
||||
*
|
||||
* @return a `bool` value:
|
||||
@ -48,7 +48,7 @@
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
bool obi_is_little_end();
|
||||
bool obi_is_little_endian();
|
||||
|
||||
|
||||
#endif /* OBILITTLEBIGMAN_H_ */
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <obitypes.h>
|
||||
|
||||
|
||||
size_t obi_sizeof(OBIType_t type) {
|
||||
size_t size=0;
|
||||
|
||||
@ -33,12 +34,12 @@ size_t obi_sizeof(OBIType_t type) {
|
||||
}
|
||||
|
||||
|
||||
size_t obi_array_sizeof(OBIType_t type,size_t nbelement) {
|
||||
size_t obi_array_sizeof(OBIType_t type, size_t nbelements) {
|
||||
size_t size;
|
||||
size_t rsize;
|
||||
size_t psize;
|
||||
|
||||
size = obi_sizeof(type) * nbelement;
|
||||
size = obi_sizeof(type) * nbelements;
|
||||
|
||||
psize= getpagesize();
|
||||
rsize= size % psize;
|
||||
@ -47,7 +48,6 @@ size_t obi_array_sizeof(OBIType_t type,size_t nbelement) {
|
||||
if (rsize)
|
||||
size = (size / psize) * psize + psize;
|
||||
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define OBIInt_NA (INT32_MIN)
|
||||
#define OBIFloat_NA (NAN)
|
||||
#define OBIIdx_NA (SIZE_MAX)
|
||||
@ -28,7 +29,7 @@ typedef enum {
|
||||
|
||||
|
||||
/**
|
||||
* @brief enum OBITypes for the data type of the OBIColumns.
|
||||
* @brief enum OBITypes for the data type of the OBIDMS columns.
|
||||
*/
|
||||
|
||||
typedef enum OBIType {
|
||||
@ -60,18 +61,18 @@ size_t obi_sizeof(OBIType_t type);
|
||||
/**
|
||||
* @brief returns the size requested to store an array of OBIType
|
||||
*
|
||||
* The returned size is enouth large to store an array of size nbelement
|
||||
* The returned size is large enough to store an array of size nbelement
|
||||
* but rounded at a multiple of the memory page size.
|
||||
*
|
||||
* @param type the OBIType code used as query
|
||||
* @param nbelement the number of element to be stored
|
||||
* @param nbelement the number of elements to be stored
|
||||
*
|
||||
* @return the size in bytes of the type
|
||||
* @return the size in bytes of the array
|
||||
* @retval 0 on error (unknown type)
|
||||
*
|
||||
* @since May 2015
|
||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||
*/
|
||||
size_t obi_array_sizeof(OBIType_t type,size_t nbelement);
|
||||
size_t obi_array_sizeof(OBIType_t type, size_t nbelements);
|
||||
|
||||
#endif /* OBITYPES_H_ */
|
||||
|
Reference in New Issue
Block a user