Warn on invalid encoding. - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 520490c05a3d2049cd9df74efdacffd459fe66a5
(DIR) parent 5482032dce9b0f38b192198665de4c9beb14b52e
(HTM) Author: Rob King <jking@deadpixi.com>
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(-)
---
(DIR) 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
(DIR) diff --git a/sam/errors.h b/sam/errors.h
@@ -59,5 +59,6 @@ typedef enum Warn{
Wnulls,
Wpwd,
Wnotnewline,
- Wbadstatus
+ Wbadstatus,
+ Wnottext
}Warn;
(DIR) 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));