[hackers] [sbase] [PATCH 00/10] IO improvements and some bug fixes

From: Michael Forney <mforney_AT_mforney.org>
Date: Sun, 4 Dec 2016 21:55:02 -0800

I finally got around to addressing the issues with fread I raised at the end of
http://lists.suckless.org/dev/1504/26580.html.

This patch series eliminates several uses of fread/fwrite where plain read/write
are more appropriate. To help with the common case of writing an entire buffer
to a file descriptor, I added a writeall function (which works similar to
plan9's standard write function and the Write/write_all functions in go/rust).
All users of concat were better suited to work on plain file descriptors except
for tail, so I switched concat to a read/writeall loop, and tail to use a
fgetc/fputc loop.

The result should be more efficient (no copy between read/write buffers, and
data is processed as it comes in), and is roughly the same complexity as before.
In most cases, we now pull in less of stdio, so statically linked binaries get
smaller. Additionally, cat/tee on a pipe/terminal is now usable.

Along the way, I found and fixed several bugs, mostly dealing with error
checking.

I've been running with these patches for a couple days now and haven't noticed
any regressions.

Michael Forney (10):
  crypt: Add some missing error checks for cryptsum
  od: Fix buffer overflow if -N flag is larger than BUFSIZ
  libutil: Add writeall utility function
  Don't use buffered IO (fread) when not appropriate
  tail: Use getc and putc instead of concat
  xinstall: Check result of fchmod
  concat: Use plain read/write instead of buffered stdio
  cp: Only call chmod with -p or -a
  tail: Use fstat in case file is removed
  cp: Check result of utimensat

 Makefile | 3 ++-
 cat.c | 34 ++++++++++------------------------
 cksum.c | 31 +++++++++++++++++--------------
 crypt.h | 2 +-
 libutil/concat.c | 24 ++++++++++++++----------
 libutil/cp.c | 52 ++++++++++++++++++++++------------------------------
 libutil/crypt.c | 47 ++++++++++++++++++++++++++---------------------
 libutil/writeall.c | 21 +++++++++++++++++++++
 od.c | 47 ++++++++++++++++++++++++++++-------------------
 sponge.c | 31 +++++++++++++++++--------------
 tail.c | 38 ++++++++++++++++++++------------------
 tee.c | 39 +++++++++++++++++++--------------------
 text.h | 1 -
 util.h | 4 ++++
 xinstall.c | 26 +++++++++++++-------------
 15 files changed, 214 insertions(+), 186 deletions(-)
 create mode 100644 libutil/writeall.c

-- 
2.11.0
Received on Mon Dec 05 2016 - 06:55:02 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 05 2016 - 07:00:20 CET