* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)du.c 5.7 (Berkeley) %G%";
int crossmounts
, kvalue
, listdirs
, listfiles
, maxfiles
, numfiles
;
char path
[MAXPATHLEN
+ 1];
extern int optind
, errno
;
char *malloc(), top
[MAXPATHLEN
+ 1];
listdirs
= crossmounts
= 1;
while ((ch
= getopt(argc
, argv
, "aksx")) != EOF
)
listfiles
= listdirs
= 0;
"usage: du [-aksx] [name ...]\n");
files
= (ID
*)malloc((u_int
)(sizeof(ID
) * (maxfiles
= 128)));
(void)fprintf(stderr
, "du: %s: %s\n",
(void)fprintf(stderr
, "du: %s: %s\n", arg
, strerror(errno
));
if ((info
.st_mode
&S_IFMT
) != S_IFDIR
) {
(void)printf("%ld\t%s\n", kvalue
?
howmany(info
.st_blocks
, 2) : info
.st_blocks
, arg
);
if (!listfiles
&& !listdirs
)
(void)printf("%lu\t%s\n",
kvalue
? howmany(total
, 2) : total
, path
);
register struct dirent
*dp
;
for (fp
= files
+ numfiles
- 1; fp
>= files
; --fp
)
if (info
.st_ino
== fp
->inode
&&
if (numfiles
== maxfiles
)
files
= (ID
*)realloc((char *)files
,
(u_int
)(sizeof(ID
) * (maxfiles
+= 128)));
files
[numfiles
].inode
= info
.st_ino
;
files
[numfiles
].dev
= info
.st_dev
;
if ((info
.st_mode
&S_IFMT
) == S_IFDIR
) {
if (info
.st_dev
!= device
&& !crossmounts
)
(void)fprintf(stderr
, "du: %s: %s\n",
if (!(dir
= opendir("."))) {
(void)fprintf(stderr
, "du: %s: %s\n",
(void)fprintf(stderr
, "du: ..: %s\n",
while (dp
= readdir(dir
)) {
if (dp
->d_name
[0] == '.' && (!dp
->d_name
[1] ||
dp
->d_name
[1] == '.' && !dp
->d_name
[2]))
bcopy(dp
->d_name
, endp
, dp
->d_namlen
+ 1);
if (lstat(dp
->d_name
, &info
)) {
(void)fprintf(stderr
, "du: %s: %s\n", path
,
(void)fprintf(stderr
, "du: ..: %s\n", strerror(errno
));
(void)printf("%lu\t%s\n",
kvalue
? howmany(total
, 2) : total
, path
);
(void)printf("%lu\t%s\n",
kvalue
? howmany(total
, 2) : total
, path
);