shithub: riscv

Download patch

ref: 3932622c292dbf4ce5f65fa2a6fb6b3a3c77f174
parent: 032d64429f21143141dfa9646a73dfe6f1008b3b
author: cinap_lenrek <[email protected]>
date: Fri Dec 2 19:25:58 EST 2022

iconv: revert copying extra data on input

I think this is better done by a shell script
doing the extra copying as it breaks use cases
where we want to consume bitmaps in a loop
from a file-descriptor.

--- a/sys/man/1/crop
+++ b/sys/man/1/crop
@@ -114,11 +114,8 @@
 .I Iconv
 changes the format of pixels in the image
 .I file
-(default standard input) and writes the resulting image to standard
-output.  Any extra data following the source image is copied verbatim,
-which allows converting fonts without losing subfont header and
-character information.  Pixels in the image are converted according to
-the channel descriptor
+(default standard input) and writes the resulting image to standard output.
+Pixels in the image are converted according to the channel descriptor
 .IR chandesc ,
 (see
 .IR image (6)).
--- a/sys/src/cmd/iconv.c
+++ b/sys/src/cmd/iconv.c
@@ -40,10 +40,9 @@
 main(int argc, char *argv[])
 {
 	char *tostr, *file;
-	int fd, uncompressed, r;
+	int fd, uncompressed;
 	ulong tochan;
 	Memimage *m, *n;
-	uchar extra[8192];
 
 	tostr = nil;
 	uncompressed = 0;
@@ -61,20 +60,24 @@
 	memimageinit();
 
 	file = "<stdin>";
-	fd = 0;
+	m = nil;
+
 	switch(argc){
 	case 0:
+		m = readmemimage(0);
 		break;
 	case 1:
-		fd = open(file = argv[0], OREAD);
+		file = argv[0];
+		fd = open(file, OREAD);
 		if(fd < 0)
 			sysfatal("can't open %s: %r", file);
+		m = readmemimage(fd);
+		close(fd);
 		break;
 	default:
 		usage();
 	}
 
-	m = readmemimage(fd);
 	if(m == nil)
 		sysfatal("can't read %s: %r", file);
 
@@ -95,15 +98,5 @@
 		writeuncompressed(1, n);
 	else
 		writememimage(1, n);
-
-	for(;;){
-		if((r = read(fd, extra, sizeof(extra))) < 0)
-			sysfatal("read failed: %r");
-		if(r == 0)
-			break;
-		if(write(1, extra, r) != r)
-			sysfatal("write failed: %r");
-	}
-
 	exits(nil);
 }