new functions to get the creation date of a column
This commit is contained in:
@ -1562,4 +1562,132 @@ size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char* obi_column_get_formatted_creation_date(OBIDMS_column_p column)
|
||||||
|
{
|
||||||
|
const char* formatted_time;
|
||||||
|
struct tm* tmp;
|
||||||
|
|
||||||
|
formatted_time = (char*) malloc(FORMATTED_TIME_LENGTH*sizeof(char));
|
||||||
|
|
||||||
|
tmp = localtime(&((column->header)->creation_date));
|
||||||
|
if (tmp == NULL)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError formatting the creation date of a column");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strftime(formatted_time, FORMATTED_TIME_LENGTH, "%c", tmp) == 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError formatting the creation date of a column");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatted_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char* obi_column_get_formatted_creation_date_from_name(OBIDMS_p dms, const char* column_name)
|
||||||
|
{
|
||||||
|
OBIDMS_column_header_p header;
|
||||||
|
OBIDMS_column_directory_p column_directory;
|
||||||
|
char* column_file_name;
|
||||||
|
int column_file_descriptor;
|
||||||
|
int column_dir_file_descriptor;
|
||||||
|
size_t header_size;
|
||||||
|
obiversion_t version_number;
|
||||||
|
const char* formatted_time;
|
||||||
|
struct tm* tmp;
|
||||||
|
|
||||||
|
// Get the column directory structure associated to the column
|
||||||
|
column_directory = obi_open_column_directory(dms, column_name);
|
||||||
|
if (column_directory == NULL)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError opening a column directory structure");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the file descriptor associated to the column directory
|
||||||
|
column_dir_file_descriptor = dirfd(column_directory->directory);
|
||||||
|
if (column_dir_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError getting the file descriptor of a column directory");
|
||||||
|
obi_close_column_directory(column_directory);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the header size
|
||||||
|
header_size = obi_get_platform_header_size();
|
||||||
|
|
||||||
|
// Get the latest version number
|
||||||
|
version_number = obi_get_latest_version_number(column_directory);
|
||||||
|
if (version_number < 0)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError getting the latest version number in a column directory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the column file name
|
||||||
|
column_file_name = build_column_file_name(column_name, version_number);
|
||||||
|
if (column_file_name == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open the column file (READ-ONLY)
|
||||||
|
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDONLY);
|
||||||
|
if (column_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError opening a column file");
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
free(column_file_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill the header structure
|
||||||
|
header = mmap(NULL,
|
||||||
|
header_size,
|
||||||
|
PROT_READ,
|
||||||
|
MAP_SHARED,
|
||||||
|
column_file_descriptor,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (header == MAP_FAILED)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError mmapping the header of a column");
|
||||||
|
close(column_file_descriptor);
|
||||||
|
free(column_file_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Check endianness?
|
||||||
|
|
||||||
|
// Format time
|
||||||
|
formatted_time = (char*) malloc(FORMATTED_TIME_LENGTH*sizeof(char));
|
||||||
|
tmp = localtime(&(header->creation_date));
|
||||||
|
if (tmp == NULL)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError formatting the creation date of a column");
|
||||||
|
close(column_file_descriptor);
|
||||||
|
free(column_file_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (strftime(formatted_time, FORMATTED_TIME_LENGTH, "%c", tmp) == 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError formatting the creation date of a column");
|
||||||
|
close(column_file_descriptor);
|
||||||
|
free(column_file_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(column_file_name);
|
||||||
|
close(column_file_descriptor);
|
||||||
|
munmap(header, header_size);
|
||||||
|
return formatted_time;
|
||||||
|
}
|
||||||
|
@ -33,7 +33,8 @@
|
|||||||
*/
|
*/
|
||||||
#define MAXIMUM_LINE_COUNT (1000000) /**< The maximum line count for the data of a column. //TODO
|
#define MAXIMUM_LINE_COUNT (1000000) /**< The maximum line count for the data of a column. //TODO
|
||||||
*/
|
*/
|
||||||
|
#define FORMATTED_TIME_LENGTH (1024) /**< The length allocated for the character string containing a formatted date
|
||||||
|
*/
|
||||||
|
|
||||||
typedef int32_t obiversion_t; /**< Used to store the column version number
|
typedef int32_t obiversion_t; /**< Used to store the column version number
|
||||||
*/
|
*/
|
||||||
@ -391,7 +392,7 @@ size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char
|
|||||||
*
|
*
|
||||||
* @param column A pointer on an OBIDMS column.
|
* @param column A pointer on an OBIDMS column.
|
||||||
*
|
*
|
||||||
* @returns The number of elements per line
|
* @returns The number of elements per line.
|
||||||
*
|
*
|
||||||
* @since July 2015
|
* @since July 2015
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
@ -399,4 +400,31 @@ size_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char
|
|||||||
size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column);
|
size_t obi_column_get_nb_elements_per_line(OBIDMS_column_p column);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Recovers the creation date of an OBIDMS column.
|
||||||
|
*
|
||||||
|
* @param column A pointer on an OBIDMS column.
|
||||||
|
*
|
||||||
|
* @returns The creation date of the column.
|
||||||
|
*
|
||||||
|
* @since October 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
char* obi_column_get_formatted_creation_date(OBIDMS_column_p column);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Recovers the creation date of an OBIDMS column from the column name.
|
||||||
|
*
|
||||||
|
* @param dms A pointer on an OBIDMS.
|
||||||
|
* @param column_name The name of an OBIDMS column.
|
||||||
|
*
|
||||||
|
* @returns The creation date of the column.
|
||||||
|
*
|
||||||
|
* @since October 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
char* obi_column_get_get_formatted_creation_date_from_name(OBIDMS_p dms, const char* column_name);
|
||||||
|
|
||||||
|
|
||||||
#endif /* OBIDMSCOLUMN_H_ */
|
#endif /* OBIDMSCOLUMN_H_ */
|
||||||
|
Reference in New Issue
Block a user