]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: retire NIOBUF in favour of more common BUFSIZ
authorSami Kerola <kerolasa@iki.fi>
Wed, 1 May 2019 19:04:24 +0000 (20:04 +0100)
committerSami Kerola <kerolasa@iki.fi>
Wed, 1 May 2019 19:19:19 +0000 (20:19 +0100)
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 <kzak@redhat.com>
Reference: https://github.com/karelzak/util-linux/pull/783
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/hardlink.c

index 6a0d0c3615b9808ed95edbf73c095ce3860d4fea..3354273cbda4b518741defd6628e77ebcaec12be 100644 (file)
@@ -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);