Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hardlink: move global variables to control structure #783

Merged
merged 3 commits into from
May 2, 2019

Conversation

kerolasa
Copy link
Member

Usual variable scope tidy up, accompanied with a compiler warning fix.

lseek(fd, 0, SEEK_SET);

for (fsize = st.st_size; fsize > 0;
fsize -= NIOBUF) {
char iobuf1[NIOBUF] = { 0 };
char iobuf2[NIOBUF] = { 0 };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if move these bufferes to this nested scope is the right thing. Maybe it would be better to keep in global scope as it's used very often.

It would be also nice to use standard BUFSIZ rather than obscure NIOBUF (but, please in separated patch;-)).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved IO buffers to ctl in commit 007b987.

And commit e2aa5d8 retired NIOBUF combined with sizeof() calls to make code determine available sizes. That is probably better than repeating magic values here and there.

This fixes two standards compliancy warnings.

hardlink.c:65:7: warning: ISO C forbids zero-size array ‘name’ [-Wpedantic]

Reference: https://en.wikipedia.org/wiki/Flexible_array_member
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Well, sort of.  Due to use of ctl values in atexit() print_summary() there
is need for global control structure.

Secondly couple variables can be moved to more restricted scope, namely the
PCRE variables are now in main().

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
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: util-linux#783
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
@karelzak karelzak merged commit e2aa5d8 into util-linux:master May 2, 2019
@karelzak
Copy link
Collaborator

karelzak commented May 2, 2019

Merged and fixed two compiler warnings. Thanks.

(Well, we had already -rc1, but hardlink is new in the release and this changes has no impact to functionality and we have regression tests.)

@kerolasa kerolasa deleted the hardlink branch May 4, 2019 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants