A very basic obicount

This commit is contained in:
Celine Mercier
2015-05-22 17:54:34 +02:00
parent 2073f9f307
commit 0b031da28c
7 changed files with 264 additions and 128 deletions

46
src/obidmscolumn.c Normal file
View File

@ -0,0 +1,46 @@
/****************************************************************************
* OBIDMSColumn functions *
****************************************************************************/
/**
* @file obidmscolumn.h
* @author Celine Mercier
* @date 22 May 2015
* @brief Functions for the shared elements of all the OBIColumn structures.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h> /* mmap() is defined in this header */
/**
* @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, "\nmmap 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);
}