fix du
This commit is contained in:
parent
4dc1a5d86c
commit
ecc41bec15
@ -52,7 +52,7 @@ int change(const char *file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
fprintf(stderr, "chown: unable to stat %s: %s\n", file, strerror(errno));
|
fprintf(stderr, "chown: unable to chown %s: %s\n", file, strerror(errno));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -11,20 +11,37 @@ unsigned int s_flag;
|
|||||||
unsigned int b_flag;
|
unsigned int b_flag;
|
||||||
unsigned int m_flag;
|
unsigned int m_flag;
|
||||||
|
|
||||||
void print(long size, const char *filename) {
|
void print(double size, const char *filename) {
|
||||||
|
char c = 0;
|
||||||
|
|
||||||
|
if (h_flag) {
|
||||||
|
if (size < 1048576)
|
||||||
|
c = 'K';
|
||||||
|
|
||||||
|
else if (size < 1073741824) {
|
||||||
|
size = size / 1048576;
|
||||||
|
c = 'M';
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (size < 1099511627776) {
|
||||||
|
size = size / 1073741824;
|
||||||
|
c = 'G';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Kb */
|
/* Kb */
|
||||||
if (!b_flag)
|
else if (!b_flag)
|
||||||
size = size / 1024;
|
size = size / 1024;
|
||||||
|
|
||||||
/* Mb */
|
/* Mb */
|
||||||
else if (m_flag)
|
else if (m_flag)
|
||||||
size = size / 1048576;
|
size = size / 1048576;
|
||||||
|
|
||||||
printf("%ld\t%s\n", size, filename);
|
printf("%.1f%c\t%s\n", size, c, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
long du(const char *path, int recurs_flag) {
|
double du(const char *path, int recurs_flag) {
|
||||||
long sum = 0;
|
double sum = 0;
|
||||||
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (lstat(path, &sb) != 0) {
|
if (lstat(path, &sb) != 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user