aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/shared/memzip/lexermemzip.c
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2022-06-19 19:47:51 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2022-06-19 19:47:51 +0530
commit4fd287655a72b9aea14cdac715ad5b90ed082ed2 (patch)
tree65d393bc0e699dd12d05b29ba568e04cea666207 /circuitpython/shared/memzip/lexermemzip.c
parent0150f70ce9c39e9e6dd878766c0620c85e47bed0 (diff)
add circuitpython code
Diffstat (limited to 'circuitpython/shared/memzip/lexermemzip.c')
-rw-r--r--circuitpython/shared/memzip/lexermemzip.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/circuitpython/shared/memzip/lexermemzip.c b/circuitpython/shared/memzip/lexermemzip.c
new file mode 100644
index 0000000..c1f21c1
--- /dev/null
+++ b/circuitpython/shared/memzip/lexermemzip.c
@@ -0,0 +1,18 @@
+#include <stdlib.h>
+
+#include "py/lexer.h"
+#include "py/runtime.h"
+#include "py/mperrno.h"
+#include "memzip.h"
+
+mp_lexer_t *mp_lexer_new_from_file(const char *filename)
+{
+ void *data;
+ size_t len;
+
+ if (memzip_locate(filename, &data, &len) != MZ_OK) {
+ mp_raise_OSError(MP_ENOENT);
+ }
+
+ return mp_lexer_new_from_str_len(qstr_from_str(filename), (const char *)data, (mp_uint_t)len, 0);
+}