Bizzar Modem Problems

rynes at cwruecmp.UUCP rynes at cwruecmp.UUCP
Sun Jul 20 07:55:33 AEST 1986


  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?



	<path is the original directory>
	<ptmp is a newly created temp directory>
	<dp = opendir(path)>

	/* 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 at case.csnet	(216) 368-6471	|			Kate Bush
______________________________________________________________________________



More information about the Comp.bugs.4bsd.ucb-fixes mailing list