Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!ames!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.unix.shell Subject: Re: Leaf directories (Re: Why is find so slow) Message-ID: <26981@mimsy.umd.edu> Date: 13 Oct 90 14:03:32 GMT References: <15052@hydra.gatech.EDU> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 28 In article flee@guardian.cs.psu.edu (Felix Lee) writes: >Leaf directories are directories with no subdirectories. A leaf >directory has a link count <= 2. It is easier than that (and harder than this, which leaves out error checking): d = opendir(dir); fstat(dirfd(d), &st); nsubdirs = st.st_nlink - 2; while ((dp = readdir(d)) != NULL) { if (need_stat_anyway || nsubdirs > 0) { get_stat(dir, dp->d_name, &st); if (S_ISDIR(st.st_mode)) nsubdirs--; } ... } (pre-POSIX programmers pwill pneed, er, will need to write (st.st_mode & S_IFMT) == S_IFDIR rather than S_ISDIR(st.st_mode)). This is susceptible to error if the file system is active, but that is no change; find has always had this problem. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris