fixed: df ls dd

This commit is contained in:
Your Name 2024-03-02 14:07:19 +03:00
parent 0e63796bb1
commit d1f34a926f
3 changed files with 9 additions and 14 deletions

4
TODO
View File

@ -1,6 +1,7 @@
With "micro-" prefix
*Todo:
*du - b
tail
expr
uniq
@ -8,8 +9,6 @@ od
tr
cut
shuf
df
dd
stty
stat
sort
@ -19,6 +18,7 @@ sha*
md5
Other:
watch
ps
sysctl
ping

View File

@ -13,15 +13,14 @@ unsigned int h_flag;
unsigned int s_flag;
unsigned int c_flag;
unsigned int b_flag;
char n_flag = '\n';
off_t total;
void print(off_t size, const char *filename) {
if (h_flag)
printf("%s\t%s%c", mu_humansize(size, 1024), filename, n_flag);
printf("%s\t%s\n", mu_humansize(size, 1024), filename);
else
printf("%jd\t%s%c", (intmax_t)size / 1024, filename, n_flag);
printf("%jd\t%s\n", (intmax_t)size / 1024, filename);
}
off_t du(const char *path, int recurs_flag) {
@ -66,7 +65,7 @@ off_t du(const char *path, int recurs_flag) {
/* Get file size */
else {
sum = 512 * sb.st_blocks + 512;
sum = sb.st_blocks * 512;
if (c_flag)
total += sum;
@ -81,7 +80,7 @@ off_t du(const char *path, int recurs_flag) {
int main(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "hsbc0")) != -1) {
while ((opt = getopt(argc, argv, "hsbc")) != -1) {
switch (opt) {
case 'h':
h_flag = 1;
@ -95,12 +94,8 @@ int main(int argc, char **argv) {
c_flag = 1;
break;
case '0':
n_flag = '\0';
break;
default:
printf("du [src1 src2...]\n\t[-h Sizes in human readable format]\n\t[-s Display only a total for each argument]\n\t[-c produce a grand total]\n\t[-0 end each output line with NUL, not newline]\n");
printf("du [src1 src2...]\n\t[-h Sizes in human readable format]\n\t[-s Display only a total for each argument]\n\t[-c produce a grand total]\n");
return 0;
}
}

View File

@ -204,12 +204,12 @@ int print(const struct d_node *node) {
ret += printf("%7ju ", (uintmax_t)node->stats.st_ino);
if (s_flag) {
off_t size = 512 * node->stats.st_blocks + 512;
off_t size = 512 * node->stats.st_blocks;
if (h_flag)
ret += printf("%7s ", mu_humansize(size, 1024));
else
ret += printf("%7ju ", (uintmax_t)size);
ret += printf("%7ju ", (uintmax_t)size / 1024);
}
if (l_flag) {