EMILE/libemile/emile_second_get_configuration.c

50 lines
920 B
C
Raw Normal View History

2005-11-27 23:45:18 +00:00
/*
*
2007-08-24 09:27:29 +00:00
* (c) 2005-2007 Laurent Vivier <Laurent@lvivier.info>
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"
char* emile_second_get_configuration(int fd)
{
2007-08-24 09:27:29 +00:00
char *conf = NULL;
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
off_t offset;
2005-11-27 23:45:18 +00:00
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
{
offset = lseek(fd, FIRST_LEVEL_SIZE, SEEK_SET);
ret = read(fd, &header, sizeof(header));
if (!EMILE_COMPAT(EMILE_06_SIGNATURE, read_long(&header.signature)))
goto exit;
}
if (ret != sizeof(header))
goto exit;
2005-11-28 20:54:29 +00:00
2005-11-27 23:45:18 +00:00
size = read_short(&header.conf_size);
conf = (char*)malloc(size);
if (conf == NULL)
2007-08-24 09:27:29 +00:00
goto exit;
2005-11-27 23:45:18 +00:00
ret = read(fd, conf, size);
if (ret != size)
return NULL;
2007-08-24 09:27:29 +00:00
exit:
lseek(fd, offset, SEEK_SET);
2005-11-27 23:45:18 +00:00
return conf;
}