EMILE/libemile/emile_second_get_configuration.c

54 lines
947 B
C
Raw Normal View History

2005-11-27 23:45:18 +00:00
/*
*
* (c) 2005-2007 Laurent Vivier <Laurent@Vivier.EU>
2005-11-27 23:45:18 +00:00
*
*/
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
2007-08-24 09:27:29 +00:00
#include <string.h>
2005-11-27 23:45:18 +00:00
#include "libemile.h"
#include "emile.h"
2007-09-08 23:09:14 +00:00
int8_t* emile_second_get_configuration(int fd)
2005-11-27 23:45:18 +00:00
{
2007-10-21 01:26:48 +00:00
int8_t *conf;
2005-11-27 23:45:18 +00:00
emile_l2_header_t header;
int ret;
int size;
2007-08-24 09:27:29 +00:00
memset(&header, 0, sizeof(header));
2005-11-27 23:45:18 +00:00
2007-08-24 09:27:29 +00:00
ret = read(fd, &header, sizeof(header));
if (!EMILE_COMPAT(EMILE_06_SIGNATURE, read_long(&header.signature)))
2007-08-24 09:27:29 +00:00
{
2007-10-21 01:26:48 +00:00
off_t offset;
2007-08-24 09:27:29 +00:00
offset = lseek(fd, FIRST_LEVEL_SIZE, SEEK_SET);
ret = read(fd, &header, sizeof(header));
if (!EMILE_COMPAT(EMILE_06_SIGNATURE, read_long(&header.signature)))
2007-10-21 01:26:48 +00:00
{
lseek(fd, offset, SEEK_SET);
2008-08-07 19:32:11 +00:00
return NULL;
2007-10-21 01:26:48 +00:00
}
2007-08-24 09:27:29 +00:00
}
if (ret != sizeof(header))
2007-10-21 01:26:48 +00:00
return NULL;
2005-11-28 20:54:29 +00:00
2005-11-27 23:45:18 +00:00
size = read_short(&header.conf_size);
2007-09-08 23:09:14 +00:00
conf = (int8_t*)malloc(size);
2005-11-27 23:45:18 +00:00
if (conf == NULL)
2007-10-21 01:26:48 +00:00
return NULL;
2005-11-27 23:45:18 +00:00
ret = read(fd, conf, size);
if (ret != size)
2007-10-21 01:26:48 +00:00
{
free(conf);
2005-11-27 23:45:18 +00:00
return NULL;
2007-10-21 01:26:48 +00:00
}
2005-11-27 23:45:18 +00:00
return conf;
}