1 /*
2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3 */
4
5 #include <stdio.h>
6 #include <dirent.h>
7 #include <string.h>
8 #include "amp_config.h"
9 #include "amp_platform.h"
10 #include "aos_system.h"
11 #include "aos/kv.h"
12 #include <stdio.h>
13 #include <sys/stat.h>
14
15 #define LEN 128
16 char tmp_key[LEN] = {0};
17 char tmp_val[LEN] = {0};
18
aos_kv_set(const char * key,const void * value,int len,int sync)19 int aos_kv_set(const char *key, const void *value, int len, int sync)
20 {
21 printf("[key] %s [value] %s [len] %d\r\n", key, (char *)value, len);
22
23 FILE *fp = fopen(key, "wb");
24 if (fp == NULL) {
25 return -1;
26 }
27 fwrite(value, 1, len, fp);
28 fclose(fp);
29 return 0;
30 }
31
aos_kv_get(const char * key,void * buffer,int * buffer_len)32 int aos_kv_get(const char *key, void *buffer, int *buffer_len)
33 {
34 FILE *fp = fopen(key, "rb");
35 if (fp == NULL) {
36 return -1;
37 }
38
39 fread(buffer, *buffer_len, 1, fp);
40
41 fclose(fp);
42 return 0;
43 }
44
aos_kv_del(const char * key)45 int aos_kv_del(const char *key)
46 {
47 remove(key);
48 return 0;
49 }
50