humansize: Use uintmax_t for size
du(1) breaks on 32-bit size_t for files greater than 4G.
This commit is contained in:
parent
68fb6754ba
commit
2d6cde1862
|
@ -1,11 +1,12 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
|
|
||||||
char *
|
char *
|
||||||
humansize(size_t n)
|
humansize(uintmax_t n)
|
||||||
{
|
{
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
const char postfixes[] = "BKMGTPE";
|
const char postfixes[] = "BKMGTPE";
|
||||||
|
@ -16,7 +17,7 @@ humansize(size_t n)
|
||||||
size /= 1024;
|
size /= 1024;
|
||||||
|
|
||||||
if (!i)
|
if (!i)
|
||||||
snprintf(buf, sizeof(buf), "%zu", n);
|
snprintf(buf, sizeof(buf), "%ju", n);
|
||||||
else
|
else
|
||||||
snprintf(buf, sizeof(buf), "%.1f%c", size, postfixes[i]);
|
snprintf(buf, sizeof(buf), "%.1f%c", size, postfixes[i]);
|
||||||
|
|
||||||
|
|
2
util.h
2
util.h
|
@ -66,7 +66,7 @@ int eregcomp(regex_t *, const char *, int);
|
||||||
void enmasse(int, char **, int (*)(const char *, const char *, int));
|
void enmasse(int, char **, int (*)(const char *, const char *, int));
|
||||||
void fnck(const char *, const char *, int (*)(const char *, const char *, int), int);
|
void fnck(const char *, const char *, int (*)(const char *, const char *, int), int);
|
||||||
mode_t getumask(void);
|
mode_t getumask(void);
|
||||||
char *humansize(size_t);
|
char *humansize(uintmax_t);
|
||||||
mode_t parsemode(const char *, mode_t, mode_t);
|
mode_t parsemode(const char *, mode_t, mode_t);
|
||||||
void putword(FILE *, const char *);
|
void putword(FILE *, const char *);
|
||||||
#undef strtonum
|
#undef strtonum
|
||||||
|
|
Loading…
Reference in New Issue
Block a user