Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!brl-adm!caip!think!mit-eddie!genrad!decvax!cwruecmp!rynes From: rynes@cwruecmp.UUCP Newsgroups: net.bugs.4bsd Subject: Re: Bizzar Modem Problems Message-ID: <1530@cwruecmp.UUCP> Date: Sat, 19-Jul-86 17:55:33 EDT Article-I.D.: cwruecmp.1530 Posted: Sat Jul 19 17:55:33 1986 Date-Received: Sun, 20-Jul-86 07:51:02 EDT References: <1529@cwruecmp.UUCP> Reply-To: rynes@cwruecmp.UUCP (Edward M. Rynes Esq.) Distribution: net Organization: CWRU Dept. Epid. & Biostat., Cleveland, OH Lines: 65 The following program fragment is supposed to remake directories that have many unused entries in them. (uucp/news spool directories) The first pass apears to run fine. But in the second pass all of the `stat's fail (bad address). Something in the first pass appears to be screwing up the directory. Am I missing something? /* First pass -- copy all non-empty files */ for(dent=readdir(dp); dent; dent=readdir(dp)){ if(!strcmp(dent->d_name, ".") || ! strcmp(dent->d_name, "..")) continue; if(dent->d_ino != 0){ sprintf(pent, "%s/%s", path, dent->d_name); sprintf(tpent, "%s/%s", ptmp, dent->d_name); link(pent, tpent); } } closedir(dp); unlink(path); if(rename(ptmp, path)){ fprintf(stderr,"Can't rename directory!\n"); exit(-1); } /* Second pass -- trim sub directories */ if((dp=opendir(path)) == NULL){ fprintf(stderr, "Can't access `%s'!\n", path); exit(3); } for(dent=readdir(dp); dent; dent=readdir(dp)){ if(!strcmp(dent->d_name, ".") || ! strcmp(dent->d_name, "..")) continue; sprintf(pent, "%s/%s", path, dent->d_name); if(stat(pent, buf)) perror("trimdirs"); if(buf && buf->st_mode & S_IFDIR) trimdir(path, dent->d_name); } closedir(dp); -- ______________________________________________________________________________ Edward Rynes Facilities Manager | "The next time, I dedicate Dept. of Computer Eng. and Science | My life's work to the friends I make. Case Western Reserve University | I give them what they want to hear. Cleveland, Ohio 44106 | They think I'm up to something weird. ...!decvax!cwruecmp!rynes | And up rears the head of fear in me." rynes@case.csnet (216) 368-6471 | Kate Bush ______________________________________________________________________________