mirror of
https://github.com/vivier/EMILE.git
synced 2025-04-05 15:37:07 +00:00
Skip first level if it exists
This commit is contained in:
parent
b9431c6cf7
commit
23de41a929
@ -1,38 +1,49 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||
* (c) 2005-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libemile.h"
|
||||
#include "emile.h"
|
||||
|
||||
char* emile_second_get_configuration(int fd)
|
||||
{
|
||||
char *conf;
|
||||
char *conf = NULL;
|
||||
emile_l2_header_t header;
|
||||
int ret;
|
||||
int size;
|
||||
off_t offset;
|
||||
|
||||
memset(&header, 0, sizeof(header));
|
||||
|
||||
ret = read(fd, &header, sizeof(header));
|
||||
if (ret != sizeof(header))
|
||||
return NULL;
|
||||
|
||||
if (!EMILE_COMPAT(EMILE_06_SIGNATURE, read_long(&header.signature)))
|
||||
return NULL;
|
||||
{
|
||||
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;
|
||||
|
||||
size = read_short(&header.conf_size);
|
||||
conf = (char*)malloc(size);
|
||||
if (conf == NULL)
|
||||
return NULL;
|
||||
goto exit;
|
||||
|
||||
ret = read(fd, conf, size);
|
||||
if (ret != size)
|
||||
return NULL;
|
||||
|
||||
exit:
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
return conf;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||
* (c) 2005-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
@ -20,19 +20,27 @@ int emile_second_set_configuration(int fd, char *configuration)
|
||||
int ret;
|
||||
int size;
|
||||
int len;
|
||||
off_t offset;
|
||||
|
||||
if (configuration == NULL)
|
||||
return EEMILE_CANNOT_READ_SECOND;
|
||||
|
||||
len = strlen (configuration) + 1; /* + 1 for ending 0 */
|
||||
|
||||
memset(&header, 0, sizeof(header));
|
||||
|
||||
ret = read(fd, &header, sizeof(header));
|
||||
if (!EMILE_COMPAT(EMILE_06_SIGNATURE, read_long(&header.signature)))
|
||||
{
|
||||
offset = lseek(fd, FIRST_LEVEL_SIZE, SEEK_SET);
|
||||
ret = read(fd, &header, sizeof(header));
|
||||
if (!EMILE_COMPAT(EMILE_06_SIGNATURE, read_long(&header.signature)))
|
||||
return EEMILE_INVALID_SECOND;
|
||||
}
|
||||
|
||||
if (ret != sizeof(header))
|
||||
return EEMILE_CANNOT_READ_SECOND;
|
||||
|
||||
if (!EMILE_COMPAT(EMILE_06_SIGNATURE, read_long(&header.signature)))
|
||||
return EEMILE_INVALID_SECOND;
|
||||
|
||||
size = read_short(&header.conf_size);
|
||||
if (len > size)
|
||||
return EEMILE_INVALID_SECOND;
|
||||
|
Loading…
x
Reference in New Issue
Block a user