wip: working on extern in VM
- Feat: add writer externs writing fns - Feat: add VM reader functions
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#include <common/fzl_extern.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <vm/internals/reader.h>
|
||||
|
||||
// Read external lib names
|
||||
bool vm_rd_extern_libs(fzl_vm_reader_t *reader, FILE *fd)
|
||||
{
|
||||
if (!reader || !fd)
|
||||
return false;
|
||||
|
||||
uint16_t libs_count = reader->extern_libs_count;
|
||||
if (!libs_count)
|
||||
return true;
|
||||
|
||||
reader->extern_libs = malloc(sizeof(char *) * libs_count);
|
||||
if (!reader->extern_libs)
|
||||
return false;
|
||||
|
||||
memset(reader->extern_libs, 0, sizeof(char *) * libs_count);
|
||||
|
||||
bool ok = false;
|
||||
uint16_t name_sz = 0;
|
||||
char name[256];
|
||||
for (uint16_t i = 0; i < libs_count; i++)
|
||||
{
|
||||
memset(name, 0, sizeof(name));
|
||||
|
||||
ok = vm_rd_u16(fd, 1, &name_sz);
|
||||
if (!ok || name_sz < 1)
|
||||
return false;
|
||||
|
||||
ok = vm_rd_char(fd, name_sz, name);
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
char *val = malloc(sizeof(char) * name_sz);
|
||||
if (!val)
|
||||
return false;
|
||||
|
||||
memset(val, 0, sizeof(char) * name_sz);
|
||||
memcpy(val, name, sizeof(char) * name_sz);
|
||||
reader->extern_libs[i] = val;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user