-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Make the CLI summary data use a human readable format instead of raw bytes #2696
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
Changes from all commits
49dd77b
e93fdd3
4792532
9da459f
2342122
e4e7358
dcfaf26
b63b497
dbb3cd2
91840eb
d67d965
fdcfc18
a1d128a
10748cb
23b6c67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,12 @@ int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg, const | |
| #define STRDUP(s) strdup(s) | ||
| #endif | ||
|
|
||
| /* | ||
| * Take a size in bytes and output a human readable string. Maximum | ||
| * buffer size is 8 but it's usually 7. Example: "123.4G" | ||
| */ | ||
| char* humanSize(unsigned long long size, char* str); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch to a more descriptive name? Maybe add a little comment here describing what it does?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open to naming suggestions. I will definitely add a description though, that's easy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
|
|
||
| /** | ||
| * Calls platform's equivalent of stat() on filename and writes info to statbuf. | ||
| * Returns success (1) or failure (0). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintfwas standardized in C99, so it's not guaranteed to be available in all the environments we want Zstd to build.You could consider rewriting this to not require an intermediate buffer if you just output a rescaled float value and a (static) suffix string that are then passed to the
DISPLAYLEVEL()call with"%.1f%s". But maybe that would lead to poor results for small inputs ("you compressed 123.0B" feels weird).A worst case alternative is that you just wrap this in an
#if POSIX_PLATFORM_VERSION >= 200112Land provide a fallback#elseimplementation.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see references to
fprintf()all over the code base so I just assumedsnprintf()was valid.util.c.includes<stdio.h>forfprintf(), can we rely on that, but notsnprintf()?C is not my forte, so I may need some guidance on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As C has evolved, they've introduced new functions into the same header. C90 has
fprintf()but not necessarilysnprintf().snprintf()was only standardized (and guaranteed to be present) in C99. Zstd restricts itself to the features guaranteed to be present in C90 (or at least has fallbacks to handle that strict case), so that we can be sure it will compile on all C90-conforming platforms.