diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-06 23:02:15 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-06 23:02:15 -0400 |
| commit | a38d023da11ffb5a5d7aca480d121129315eb64f (patch) | |
| tree | 3628f1e9ab5669a120e2e4a49730ed6ef1e7a2bf /examples/file.tm | |
| parent | 6cc556279168d7d3c31e00b587660d2811712be2 (diff) | |
Update files and add new dependency printer tool
Diffstat (limited to 'examples/file.tm')
| -rw-r--r-- | examples/file.tm | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/examples/file.tm b/examples/file.tm index 4f4d8645..7def4187 100644 --- a/examples/file.tm +++ b/examples/file.tm @@ -6,6 +6,8 @@ use <stdio.h> use <sys/mman.h> use <sys/stat.h> use <unistd.h> +use <unistr.h> +use libunistring.so enum FileReadResult(Success(text:Text), Failure(reason:Text)) @@ -45,6 +47,8 @@ func read(path:Text)->FileReadResult: do { just_read = read(fd, buf, chunk_size); if (just_read > 0) { + if (u8_check(buf, just_read) != NULL) + break; contents = Texts(contents, Text$from_strn(buf, just_read)); buf = GC_MALLOC_ATOMIC(chunk_size); } @@ -132,7 +136,7 @@ struct LineReader(_file:@Memory): memcpy(line, buf, len); line[len] = '\0'; if (buf) free(buf); - Text$from_strn(line, len); + u8_check(line, len) ? Text("") : Text$from_strn(line, len); }) ):Text return Success(line) |
