Add command line switch "-c"/"--check" #53
No reviewers
Labels
No labels
announcement
bug
build
CI
dependencies
documentation
duplicate
enhancement
experience feedback
feature request
github_actions
help wanted
install
invalid
Long-term
optimization
portability
question
target-specific
test issue
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Cyan4973/xxHash!53
Loading…
Reference in a new issue
No description provided.
Delete branch "wip/check-files"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR is related to @beckermr's PR #21. Since it's simple and has many possibility to extend such as multi processing by
xargs, I don't say this PR replaces PR #21.New command line switches
This PR adds the following command line switches
-c/--check: read XXH32/64 sums from FILEs and check them.--quiet: Don't print OK.--status: Don't output anything to stdout/stderr.--strict: Treat any invalid line as error.--warn: Show warning message for invalid line.Example
Basic goal
xxhsum -cmimicsmd5sum -c.md5sum.xxhsum -cshould accept, all valid, non-empty output which generated byxxhsum <filenames>orxxhsum -H0 <filenames>.xxhsum -cdetects xxHash bit width by first valid xxhsum line. And it doesn't allow mixed bit width in same.xxhfile.xxhsum -cdoes't support little endian mode.Todo
MAX_LINE_LENGTH)Since I don't review/test this PR much, any suggestion is welcome even cosmetic one.
It's a very great PR @t-mat !
A few minor things that could be improved before merge :
You don't need to cover every possible error case for a first release,
but at least having the nominal scenario covered is a good thing.
Just add a test in
Makefile, which mimics your already provided examples,add the test within
test-alltag, and it will be good to go.It can indeed be an issue if some files get very long path, which is not that uncommon.
Plus, it would make you free of some
MAX_PATHorPATH_MAXmacros you are detecting.g++compilation test<inttypes.h>andPRIuMAX?What's the impact on Windows platform ? (currently untested)
Sure. I'll add 32/64 bit normal scenario with xxhash repository files, and try to add invalid or mismatch hash line.
Right. I'll implement it. Should I keep it less than 32KiBytes or so?
Oops.
PRIuMAX! I should change it first.No. It's my mistake. Since all of them are C99 feature, if we use standard C99,
size_tand%zupair is better choice. If compiler doesn't have it, we can fall back to C89/90unsigned longand%lupair.For a single filename, yes that sounds reasonable.
Yes we should.
What is unclear for me though is what we gain from using
%zu.According to C99 (N1256): 7.19.6.1/6, it says:
Since we can't say
size_tis any specific primitive type such asusigned int,unsigned long, norunsigned long long, using%zuforsize_tprovides better consistency than%iu,%du,%lu,%llu.If we use
%zufor C99/11 (and newer MSVC), it's simply safe and optimal. Also it gracefully reduces tedious and tricky work such as (reasonably but strange) MSVC versions and target platform(win32/64) detection, etc. After that, we can forget about modern platforms, and only focus on legacy ones.For legacy platform, I think we can suppose they support
%lluin highly possibility. Because xxHash already requires 64 bit or greaterunsigned long long.It means their standard library may support
%lluspecifier to provide better support forunsigned long long. For example MSVC 2005 or later supportunsigned long longand%llu, but MSVC 2003 or earlier don't supportunsigned long longand%lluand we can't compile xxhash for latter legacy compilers without patches.So in the following new definition, I suppose basically platform which supports
unsigned long longalso supports%llueven they don't provide fully compliant C99 spec.If we find legacy platform which only provide
unsigned long longand don't support%lluspecifier, we can add detection macro and definition easily.This is not a perfect solution, but I hope this form helps future PRs which try to port xxHash for their legacy platforms.
I understand what
%zuis about.It's just that I'm not sure if it brings any value to use it.
I'm also not sure where you intend to use it, since the current PR doesn't mention
%zuanywhere.In which case does it make sense to display a value which must be
size_ttype, as opposed to some simplerU32type ?It it is only matter of printf()
size_tline numberSince md5sum has error checking code for size_t overflow (here is an actual md5sum code), I followed it in brain-dead mode.
But frankly I'm not sure there is a needs for huge line number or not (may be pipe mode?). So I think we can also simply do it with
U32 lineNumber;.I agree. 4 billion lines ought to be enough for everyone ... ugh ...
Well, let's keep this overflow check just in case ...
Sure, it would be better for code and mental health :)
So since I realize
uint32_tintroduces same problem (It requiresPRIu32. Also sizeof(uint32_t) != sizeof(unsigned int) in ILP64), I would like to use the following code:Looks good to me !
I've updated PR partially. Todos are:
unsigned longfor line number.I've add stdin mode (
xxhsum -c -) and Makefile target for testing.Here is an actual test log on Travis. Perhaps you feel it's bulky, if so I'll add --quiet option for basic testing commands. It prevents to output 'OK' lines.
There are potential problematic implementations:
That's fine, it's for tests.
Looks fine to me.
Looks good to me too.
It could be run automatically at the end of the test.
Is it ready for merge @t-mat ?
Or do you still want to complete "Add usage message for usage() and usage_advanced()." ?
oops. I've waited Travis, and yes, it's ready to merge 👍
I've read some
md5sumrelated documents, and it seems good enough for now.Maybe we'll need manpage for
xxhsumbut it should be another PR.👍