Recursive folder creation for MH 6.6, patch [comp.mail.mh]

Craig Leres leres at ace.ee.lbl.gov
Sun Dec 17 11:16:46 AEST 1989


Archive-name: mh-makedir/leres
Original-posting-by: leres at ace.ee.lbl.gov (Craig Leres)
Original-subject: Re: Hierarchical folders in MH
Reposted-by: emv at math.lsa.umich.edu (Edward Vielmetti)

[This is a patch to MH-6.6 from comp.mail.mh.]

Peter Marvit writes:
> I have a patch which will allow recursve folder creation.  I've sent it on
> to John Romnie to be incorporated into the "official" MH6.6.  If readers of
> this list want the patch ahead of time, mail me.  More than 5 requests
> means I'll post it.
>
> Oh, it may have to wait till after 2 Jan, since I'm leaving on vacation in
> two days ;-)

Well perhaps while we're waiting for you to post your version people
will be interested in looking at mine...

		Craig

------ sbr/makedir.c
/* @(#) $Header: makedir.c,v 1.3 89/12/14 21:13:03 leres Exp $ (LBL) */
/* makedir.c - make a directory */

#include "../h/mh.h"
#include <stdio.h>
#include <errno.h>

extern int errno;


makedir(dir)
	register char *dir;
{
	register int i, pid;
	register char *cp;
	char temp[BUFSIZ];

	m_update();
	(void) fflush(stdout);

#ifdef	BSD42
	if (getuid() == geteuid()) {
		errno = 0;
		if ((i = mkdir(dir, 0755)) < 0 && errno == ENOENT) {
			/* Attempt to create higher level directories */
			cp = strcpy(temp, dir);
			if (*cp == '/')
				++cp;
			while (cp = index(cp, '/')) {
				*cp = '\0';
				errno = 0;
				if ((i = mkdir(temp, 0755)) < 0 &&
				    errno != EEXIST)
					break;
				*cp++ = '/';
			}
			if (i >= 0)
				i = mkdir(temp, 0755);
		}
		if (i < 0) {
			advise(dir, "unable to create directory");
			return(0);
		}
	} else
#endif	BSD42
		switch (pid = vfork()) {

		case NOTOK:
			advise("fork", "unable to");
			return(0);

		case OK:
			(void) setgid(getgid());
			(void) setuid(getuid());

			execl("/bin/mkdir", "mkdir", dir, NULLCP);
			execl("/usr/bin/mkdir", "mkdir", dir, NULLCP);
			fprintf(stderr, "unable to exec ");
			perror("mkdir");
			_exit(-1);

		default:
			if (pidXwait(pid, "mkdir"))
				return(0);
			break;
		}

	if ((cp = m_find("folder-protect")) == NULL)
		cp = foldprot;
	(void) chmod(dir, atooi(cp));
	return(1);
}



More information about the Alt.sources.patches mailing list