A very basic obicount
This commit is contained in:
46
src/obidmscolumn.c
Normal file
46
src/obidmscolumn.c
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user