home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!mdw033.cc.monash.edu.au!int233p
- From: int233p@mdw033.cc.monash.edu.au (Mr A.J. Bucknell)
- Subject: Trying to write my own ls
- Message-ID: <1992Sep9.125031.17878@monu6.cc.monash.edu.au>
- Summary: Help with inodes and struct direct
- Keywords: inodes
- Sender: news@monu6.cc.monash.edu.au (Usenet system)
- Organization: Monash University
- Date: Wed, 9 Sep 1992 12:50:31 GMT
- Lines: 29
-
- I am trying to write a small program that lists the files and subdirectories
- of a specified directory. I have got the following program running, and it
- works fine when I run it on the home directory, but when I run it on any other
- directory, it gives incorrect file sizes. Can anyone point my error ? The
- code is :
-
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/dir.h>
- #include <sys/stat.h>
-
- void main(int argc, char *argv[])
- {
- struct stat buf;
- DIR *dirp;
- struct direct *dp;
-
- dirp = opendir(argv[1]);
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
- {
- stat(dp->d_name, &buf);
- printf("%-15s%8d\n", dp->d_name, buf.st_size);
- }
- closedir(dirp);
- }
-
- Thanks in advance for any help. Replies via email, or to here if you think its
- of interest to others.
-