fixed typos and other minor things
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user