Warn on invalid encoding. - sam - An updated version of the sam text editor. | |
git clone git://vernunftzentrum.de/sam.git | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 520490c05a3d2049cd9df74efdacffd459fe66a5 | |
parent 5482032dce9b0f38b192198665de4c9beb14b52e | |
Author: Rob King <[email protected]> | |
Date: Mon, 3 Oct 2016 22:15:35 -0500 | |
Warn on invalid encoding. | |
Diffstat: | |
sam/error.c | 1 + | |
sam/errors.h | 3 ++- | |
sam/io.c | 5 +++++ | |
3 files changed, 8 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/sam/error.c b/sam/error.c | |
@@ -62,6 +62,7 @@ static char *wmsg[]={ | |
"can't run pwd", | |
"last char not newline", | |
"exit status not 0", | |
+ "file is not text" | |
}; | |
void | |
diff --git a/sam/errors.h b/sam/errors.h | |
@@ -59,5 +59,6 @@ typedef enum Warn{ | |
Wnulls, | |
Wpwd, | |
Wnotnewline, | |
- Wbadstatus | |
+ Wbadstatus, | |
+ Wnottext | |
}Warn; | |
diff --git a/sam/io.c b/sam/io.c | |
@@ -88,6 +88,11 @@ readio(File *f, int *nulls, int setdate) | |
n = read(io, buf, BLOCKSIZE); | |
while (n > 0){ | |
size_t w = mbsrtowcs(wbuf, &bp, BLOCKSIZE, &ps); | |
+ if ((ssize_t)w < 0){ | |
+ *nulls = true; | |
+ warn(Wnottext); | |
+ return nt; | |
+ } | |
Finsert(f, tmprstr(wbuf, w), p); | |
memset(buf, 0, sizeof(buf)); |