From 767a2a9e38792456dac9107b9a75b732a4edf32b Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 10 Apr 2022 05:12:21 +0300 Subject: [PATCH] =?UTF-8?q?make=20=E2=80=A2file.MapBytes=20follow=20spec?= =?UTF-8?q?=20&=20fix=20error=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/system.md | 6 +----- src/utils/file.c | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/system.md b/docs/system.md index 71c600fb..327aec38 100644 --- a/docs/system.md +++ b/docs/system.md @@ -14,7 +14,7 @@ See [the BQN specification](https://mlochbaum.github.io/BQN/spec/system.html) fo | `•name` | | | `•wdpath` | | | `•Exit` | | -| `•file` | Fields: `path`, `At`, `List`, `Bytes`, `Chars`, `Lines`, `Type`, `Name`; has extensions | +| `•file` | Fields: `path`, `At`, `List`, `Bytes`, `Chars`, `Lines`, `Type`, `Name`, `MapBytes` | | `•FChars` | | | `•FBytes` | | | `•FLines` | | @@ -38,10 +38,6 @@ See [the BQN specification](https://mlochbaum.github.io/BQN/spec/system.html) fo # CBQN-specific system functions and extensions -## `•file.MapBytes` - -`mmap`s file at path `𝕩` as an 8-bit signed integer array; Use `•bit._cast` to interpret as other types, and `↓`/`↑` to select only a part of the file. - ## `•term` `•term.OutRaw` and `•term.ErrRaw` output the given bytes directly to the specific stream, without any trailing newline. May be removed once a proper interface for stream I/O has been made. diff --git a/src/utils/file.c b/src/utils/file.c index 24107c15..126cdc27 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -249,7 +249,7 @@ DEF_FREE(mmapH) { B info_c1(B,B); static Arr* mmapH_slice(B x, usz s, usz ia) { - TySlice* r = m_arr(sizeof(TySlice), t_i8slice, ia); + TySlice* r = m_arr(sizeof(TySlice), t_c8slice, ia); r->a = c(MmapHolder,x)->a + s; r->p = a(x); return (Arr*)r; @@ -260,8 +260,8 @@ B mmap_file(B path) { dec(path); int fd = open(p, 0); freeCStr(p); - u64 len = lseek(fd, 0, SEEK_END); if (fd==-1) thrF("Failed to open file: %S", strerror(errno)); + u64 len = lseek(fd, 0, SEEK_END); u8* data = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); // TODO count in heap usage if (data==MAP_FAILED) { @@ -292,7 +292,7 @@ void mmap_init() { TIi(t_mmapH,print) = farr_print; TIi(t_mmapH,isArr) = true; TIi(t_mmapH,arrD1) = true; - TIi(t_mmapH,elType) = el_i8; + TIi(t_mmapH,elType) = el_c8; // use default canStore } #else