Browse Source

stdio: skip empty iovec when buffering is disabled

When buffering on a FILE is disabled we still send both iovecs, even
though the first one is always empty. Clean things up by skipping the
empty iovec instead.
Casey Connolly 1 month ago
parent
commit
fde29c04ad
1 changed files with 5 additions and 0 deletions
  1. 5 0
      src/stdio/__stdio_write.c

+ 5 - 0
src/stdio/__stdio_write.c

@@ -11,6 +11,11 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
 	size_t rem = iov[0].iov_len + iov[1].iov_len;
 	int iovcnt = 2;
 	ssize_t cnt;
+
+	if (!iov->iov_len) {
+		iov++;
+		iovcnt--;
+	}
 	for (;;) {
 		cnt = syscall(SYS_writev, f->fd, iov, iovcnt);
 		if (cnt == rem) {