-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlfs_js.c
60 lines (51 loc) · 1.51 KB
/
lfs_js.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* javascript wrapper for littlefs
* C wrappers
*/
#include "lfs.h"
#include <string.h>
#include <stdlib.h>
#include <emscripten.h>
// javascript binding functions
EMSCRIPTEN_KEEPALIVE
lfs_t *lfs_new(void) {
return malloc(sizeof(lfs_t));
}
EMSCRIPTEN_KEEPALIVE
const struct lfs_config *lfs_new_config(
int (*read)(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, void *buffer, lfs_size_t size),
int (*prog)(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, const void *buffer, lfs_size_t size),
int (*erase)(const struct lfs_config *c, lfs_block_t block),
int (*sync)(const struct lfs_config *c),
lfs_size_t read_size,
lfs_size_t prog_size,
lfs_size_t block_size,
lfs_size_t block_count,
lfs_size_t lookahead) {
struct lfs_config *cfg = malloc(sizeof(struct lfs_config));
memset(cfg, 0, sizeof(struct lfs_config));
cfg->read = read;
cfg->prog = prog;
cfg->erase = erase;
cfg->sync = sync;
cfg->read_size = read_size;
cfg->prog_size = prog_size;
cfg->block_size = block_size;
cfg->block_count = block_count;
cfg->lookahead = lookahead;
return cfg;
}
EMSCRIPTEN_KEEPALIVE
struct lfs_info *lfs_new_info(void) {
return malloc(sizeof(struct lfs_info));
}
EMSCRIPTEN_KEEPALIVE
struct lfs_file *lfs_new_file(void) {
return malloc(sizeof(struct lfs_file));
}
EMSCRIPTEN_KEEPALIVE
struct lfs_dir *lfs_new_dir(void) {
return malloc(sizeof(struct lfs_dir));
}