From: Sami Kerola Date: Wed, 1 May 2019 19:04:24 +0000 (+0100) Subject: hardlink: retire NIOBUF in favour of more common BUFSIZ X-Git-Tag: v2.34-rc2~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2aa5d82b91b7649dc8494e2cd9a4694a8a97efb;p=thirdparty%2Futil-linux.git hardlink: retire NIOBUF in favour of more common BUFSIZ Reason to retire NIOBUF is that it is obscure local definition, while BUFSIZ is well understood and commonly used constant. Besized sizes of these are not far off, the NIOBUF was 4096 bytes and BUFSIZ tends to be 8192 bytes. Proposed-by: Karel Zak Reference: https://github.com/karelzak/util-linux/pull/783 Signed-off-by: Sami Kerola --- diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c index 6a0d0c3615..3354273cbd 100644 --- a/misc-utils/hardlink.c +++ b/misc-utils/hardlink.c @@ -42,7 +42,6 @@ #include "closestream.h" #define NHASH (1<<17) /* Must be a power of 2! */ -#define NIOBUF (1<<12) #define NBUF 64 struct hardlink_file; @@ -75,8 +74,8 @@ struct hardlink_dynstr { struct hardlink_ctl { struct hardlink_dir *dirs; struct hardlink_hash *hps[NHASH]; - char iobuf1[NIOBUF]; - char iobuf2[NIOBUF]; + char iobuf1[BUFSIZ]; + char iobuf2[BUFSIZ]; /* summary counters */ unsigned long long ndirs; unsigned long long nobjects; @@ -282,9 +281,10 @@ static void process_path(struct hardlink_ctl *ctl, const char *name) lseek(fd, 0, SEEK_SET); for (fsize = st.st_size; fsize > 0; - fsize -= NIOBUF) { + fsize -= (off_t)sizeof(ctl->iobuf1)) { ssize_t xsz; - off_t rsize = fsize >= NIOBUF ? NIOBUF : fsize; + ssize_t rsize = fsize > (ssize_t)sizeof(ctl->iobuf1) ? + sizeof(ctl->iobuf1) : fsize; if ((xsz = read(fd, ctl->iobuf1, rsize)) != rsize) warn(_("cannot read %s"), name);