On Monday 14 August 2006 1:45 pm, Jan Trippler wrote:
Try the statvfs() call (demo program without any checks or validations):
#include
#include #include int main(int argc, char **argv) { char *p = NULL; struct statvfs st; if (argc == 2) p = strdup(argv[1]); else p = strdup("."); statvfs(p, &st); printf("%ld\n", st.f_fsid); free(p); exit(0); }
Just a quick code nit.
Why do you do a strdup (argv[1]) and strdup(".") where a simple pointer
assignment works fine here:
if (argc == 2) p = argv[1];
else p = ".";
There are many cases where a strdup may be very necessary, especially when
the string is going to be modified. Also in the case of 'p = "."' you are
simply pointing p to a constant string. Also note that on many systems,
malloc will return a pointer to a much larger block of memory than you
asked for. In the case of ".", you are simply asking for 2 bytes, but
malloc (called by strdup) will probably give you at least 16 bytes. (I have
not looked at the efficiency of the GNU malloc for a while.
--
Jerry Feldman