shithub: riscv

Download patch

ref: 9ed0dd3a7fc2e9242af1e17bc9fda7f6e97063f1
parent: 580605615f869d7c188816a796edf1386a23dacf
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Aug 16 07:08:55 EDT 2023

tput: use iounit(2) of the file-descriptor by default

--- a/sys/man/1/tput
+++ b/sys/man/1/tput
@@ -22,7 +22,9 @@
 will write the data read to standard output (the default is to
 discard the data).
 .PP
-A read blocksize (default is 8192) in bytes can be given with the
+A read blocksize (default is the
+.IR iounit (2)
+of file-descriptor) in bytes can be given with the
 .B -b
 .I buflen
 option.
@@ -33,7 +35,8 @@
 .SH SOURCE
 .B /sys/src/cmd/tput.c
 .SH SEE ALSO
-.IR iostats (4)
+.IR iostats (4),
+.IR iounit (2)
 .SH DIAGNOSTICS
 .I Tput
 sets error status on read error.
--- a/sys/src/cmd/tput.c
+++ b/sys/src/cmd/tput.c
@@ -2,7 +2,7 @@
 #include <libc.h>
 
 int dopipe;
-int buflen = 8192;
+int buflen;
 uvlong bc, sec;
 
 void
@@ -18,7 +18,7 @@
 	double speed;
 	int rc, cpid;
 	char *buf;
-	
+
 	ARGBEGIN {
 	case 'b':
 		buflen = atoi(EARGF(usage()));
@@ -32,9 +32,14 @@
 
 	if(argc != 0)
 		usage();
-	
+
 	bc = 0;
 	sec = 0;
+	if(buflen <= 0){
+		buflen = iounit(0);
+		if(buflen <= 0)
+			buflen = IOUNIT;
+	}
 	buf = sbrk(buflen);
 	if(buf == (void*)-1)
 		sysfatal("out of memory");