Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OBITools3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OBITools
OBITools3
Commits
d1324618
Commit
d1324618
authored
May 26, 2015
by
Eric Coissac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Makes few cleanning and adds an obi_dms C constructor
parent
9f69f767
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
53 deletions
+90
-53
src/obidms.c
src/obidms.c
+49
-0
src/obidms.h
src/obidms.h
+40
-0
src/obidmscolumn.c
src/obidmscolumn.c
+0
-33
src/obidmscolumn.h
src/obidmscolumn.h
+1
-20
No files found.
src/obidms.c
View file @
d1324618
...
...
@@ -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
)
{
...
...
src/obidms.h
View file @
d1324618
...
...
@@ -61,6 +61,23 @@ typedef struct OBIDMS {
*/
/**@}*/
/*@
* @brief Check if a OBIDMS exist
*
* @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
*
* @see obi_close_dms()
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
int
obi_dms_exists
(
const
char
*
name
);
/**
* @brief Create a new OBITools Data Management instance (OBIDMS).
...
...
@@ -108,6 +125,29 @@ OBIDMS_p obi_create_dms(const char *name);
*/
OBIDMS_p
obi_open_dms
(
const
char
*
name
);
/**
* @brief Create a new OBIDMS instance.
*
* If the database already exist this function open it, otherwise it
* creates a new databse.
*
* @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
* @retval NULL on error and the `obi_errno`variable is set.
*
* ###Error values
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
*
* @see obi_close_dms()
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
OBIDMS_p
obi_dms
(
const
char
*
name
);
/**
* @brief Close an opened OBITools Data Management instance (OBIDMS).
*
...
...
src/obidmscolumn.c
View file @
d1324618
...
...
@@ -579,36 +579,3 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
// }
/************************************************************************
************************************************************************
************************************************************************/
/**
* @brief Reads a memory block from a file.
*
* * @param file The file that should be mapped.
* * @param size The number of bytes that should be mapped.
* * @param start The position at which the mapping should start.
* @return A pointer on the first element of the block.
*/
char
*
obi_map_read_only
(
int
file
,
int
start
,
int
size
)
{
char
*
map
;
map
=
(
char
*
)
mmap
(
0
,
size
,
PROT_READ
,
MAP_PRIVATE
,
file
,
start
);
if
(
map
==
MAP_FAILED
)
{
fprintf
(
stderr
,
"
\n
mmap read-only error
\n
"
);
exit
(
1
);
}
return
(
map
);
}
/**
* @brief Unmaps a memory block.
*
* * @param size The size of the block that should be unmapped.
*/
void
obi_unmap
(
int
size
)
{
munmap
(
0
,
size
);
}
src/obidmscolumn.h
View file @
d1324618
...
...
@@ -23,22 +23,6 @@
#include <obierrno.h>
#include <obilittlebigman.h>
/**
* @brief Value separator in OBIDMSColumn files.
*/
static
const
char
SEPARATOR
=
'\n'
;
/**
* @brief Header size in OBIDMSColumn files.
*/
static
const
int
HEADER_SIZE
=
4096
;
/**
* @brief Number of bytes to map
*/
static
const
int
BUFFER_SIZE
=
4
;
#define OBIDMS_MAX_COLNAME (128)
/**< The maximum length of an OBIDMS column name
*/
...
...
@@ -63,7 +47,7 @@ typedef struct OBIDMSColumnHeader {
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 */
char
name
[
OBIDMS_MAX_COLNAME
];
/**< The column name as a NULL
char
name
[
OBIDMS_MAX_COLNAME
+
1
];
/**< The column name as a NULL
* terminated string.
*/
char
comments
[
1
];
/**< comments stored as a classical
...
...
@@ -145,9 +129,6 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
*/
obiversion_t
obi_latest_version
(
OBIDMS_p
dms
,
char
*
name
);
char
*
obi_map_read_only
(
int
file
,
int
start
,
int
size
);
void
obi_unmap
(
int
size
);
#endif
/* OBIDMSCOLUMN_H_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment