Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!ctisbv!pim From: pim@ctisbv.UUCP (Pim Zandbergen) Newsgroups: news.software.b Subject: Re: C news vs B news speed Message-ID: <781@ctisbv.UUCP> Date: 13 Jul 89 17:28:28 GMT References: <1989Jul9.223927.29156@elroy.jpl.nasa.gov> <1989Jul12.210254.8631@utzoo.uucp> Reply-To: pim@ctisbv.UUCP (Pim Zandbergen) Organization: CTI Software BV, The Hague, The Netherlands Lines: 49 In article <1989Jul12.210254.8631@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: [ about rewriting spacefor in C ] >I'm contemplating doing some of this myself, in fact, although if I do >use C for spacefor, it will probably popen("df") to do the actual space >finding -- that job is just too system-dependent. The following works for me on AT&T System V/386 r 3.2, System V r 3.1.1 on the AT&T 3B2, SCO Xenix, Microport System V/AT, AIX for the IBM PC RT. _______________________________________________________________________________ #include #include #include main() { struct stat statbuf; struct ustat ustatbuf; if (stat("/usr/spool/news", &statbuf) < 0) { perror("cannot fstat"); exit(1); } if (ustat(statbuf.st_dev, &ustatbuf) < 0) { perror("cannot ustat"); exit(1); } printf("%ld free blocks\n", (long)(ustatbuf.f_tfree)); printf("%ld free inodes\n", (long)(ustatbuf.f_tinode)); } _______________________________________________________________________________ It should be noted, however, that this program reports the real number of free blocks, which is not necessarely in 512 byte units. I know of no system call that reports the blocksize of a filesystem *and* is present in all the mentioned flavours of System V (no statfs(2) in AIX nor in uPort V/AT). -- --------------------+----------------------+----------------------------------- Pim Zandbergen | phone: +31 70 542302 | CTI Software BV pim@ctisbv.UUCP | fax : +31 70 512837 | Laan Copes van Cattenburch 70 ...!uunet!mcvax!hp4nl!ctisbv!pim | 2585 GD The Hague, The Netherlands