[hackers] [PATCH] rev, tail: replace hardcoded code by UTF8_POINT macro

From: Elie Le Vaillant <eolien55_AT_disroot.org>
Date: Thu, 19 Dec 2024 19:00:37 +0100

---
 rev.c  | 2 +-
 tail.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/rev.c b/rev.c
index 2d89df1..9ac1da6 100644
--- a/rev.c
+++ b/rev.c
_AT_@ -25,7 +25,7 @@ rev(FILE *fp)
 		lf = n && line[n - 1] == '\n';
 		i = n -= lf;
 		for (n = 0; i--;) {
-			if ((line[i] & 0xC0) == 0x80) {
+			if (UTF8_POINT(line[i])) {
 				n++;
 			} else {
 				fwrite(line + i, 1, n + 1, stdout);
diff --git a/tail.c b/tail.c
index ce3be9d..bbc5ad5 100644
--- a/tail.c
+++ b/tail.c
_AT_@ -122,7 +122,7 @@ taketail(int fd, const char *fname, size_t count)
 		case 'm':  /* runes */
 			for (p = buf + len - 1, left = count; p >= buf; p--) {
 				/* skip utf-8 continuation bytes */
-				if ((*p & 0xc0) == 0x80)
+				if (UTF8_POINT(*p))
 					continue;
 				left--;
 				if (!left)
-- 
2.47.1
Received on Thu Dec 19 2024 - 19:00:37 CET

This archive was generated by hypermail 2.3.0 : Thu Dec 19 2024 - 19:12:43 CET