Mirror of git://git.busybox.net/busybox with our patches on top
Source
xxxxxxxxxx
/* vi: set sw=4 ts=4: */
/*
* Mini du implementation for busybox
*
*
* Copyright (C) 1999,2000,2001 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
static unsigned long disp_hr = KILOBYTE;
typedef void (Display) (long, char *);
static int du_depth = 0;
static int count_hardlinks = 0;
static Display *print;
static void print_normal(long size, char *filename)
{
unsigned long base;
switch (disp_hr) {
case MEGABYTE:
base = KILOBYTE;
break;
case KILOBYTE:
base = 1;
break;
default:
base = 0;
}
printf("%s\t%s\n", make_human_readable_str(size, base), filename);
printf("%ld\t%s\n", size, filename);
}
static void print_summary(long size, char *filename)
{
if (du_depth == 1) {
printf("summary\n");
print_normal(size, filename);
}
}
/* tiny recursive du */
static long du(char *filename)
{
struct stat statbuf;
long sum;
int len;
if ((lstat(filename, &statbuf)) != 0) {
perror_msg_and_die("%s", filename);
}
du_depth++;
sum = (statbuf.st_blocks >> 1);
/* Don't add in stuff pointed to by symbolic links */
if (S_ISLNK(statbuf.st_mode)) {