3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on vdu.cc by Jacques Gelinas
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <sys/types.h>
34 __extension__ typedef long long longlong;
36 static int vdu_onedir (char const *path, longlong *size)
39 int dirfd = open (path,O_RDONLY); // A handle to speed up
42 fprintf (stderr,"Can't open directory %s (%s)\n",path
50 fprintf (stderr,"Can't open (opendir) directory %s (%s)\n",path
59 while ((ent=readdir(dir))!=NULL){
61 if (lstat(ent->d_name,&st)==-1){
62 fprintf (stderr,"Can't stat %s/%s (%s)\n",path
63 ,ent->d_name,strerror(errno));
66 }else if (S_ISREG(st.st_mode)){
67 if (st.st_nlink == 1){
68 dirsize += st.st_size;
70 }else if (S_ISDIR(st.st_mode) && st.st_dev == dirst.st_dev){
71 if (strcmp(ent->d_name,".")!=0
72 && strcmp(ent->d_name,"..")!=0){
73 char *tmp = malloc(strlen(path) + strlen(ent->d_name) + 2);
78 strcat(tmp, ent->d_name);
79 ret = vdu_onedir(tmp,&dirsize);
94 int main (int argc, char *argv[])
98 fprintf (stderr,"vdu version %s\n",VERSION);
99 fprintf (stderr,"vdu directory ...\n\n");
101 ,"Compute the size of a directory tree, ignoring files\n"
102 "with more than one link.\n");
107 for (i=1; i<argc && ret != -1; i++){
111 ret = vdu_onedir (argv[i],&size);
113 printf ("%s\t%ldK\n",argv[i],ksize);