so who has mkdir and rmdir for system V

ado at elsie.UUCP ado at elsie.UUCP
Sun Jul 13 08:37:55 AEST 1986


In article <1885 at brl-smoke.ARPA>, gwyn at BRL.ARPA (VLD/VMB) writes:
> int
> mkdir( dirname )
> 	char	*dirname;
> 	{
> ...
> 	(void) strcat( strcpy( buf, "mkdir 2>/dev/null " ), dirname );
> 	retval = system( buf );	/* assuming your system() works right */
> ...

The above can use a bit of idiot proofing--especially against meta characters
in dirname.  Below is the version of "mkdir" that went out with the time zone
stuff.

	#

	/*LINTLIBRARY*/

	#include "stdio.h"

	#ifdef OJBECTID
	static char	sccsid[] = "@(#)mkdir.c	7.2";
	#endif

	extern FILE *	popen();

	mkdir(name)
	char *	name;
	{
		register FILE *	fp;
		register int	c;
		register int	oops;

		if ((fp = popen("sh", "w")) == NULL)
			return -1;
		(void) fputs("mkdir 2>&- '", fp);
		if (name != NULL)
			while ((c = *name++) != '\0')
				if (c == '\'')
					(void) fputs("'\\''", fp);
				else	(void) fputc(c, fp);
		(void) fputs("'\n", fp);
		oops = ferror(fp);
		return (pclose(fp) == 0 && !oops) ? 0 : -1;
	}
--
UNIX and System V are an AT&T Bell Laboratories (or AT&T registered) trademarks.
--
	UUCP: ..decvax!seismo!elsie!ado   ARPA: elsie!ado at seismo.ARPA
	DEC, VAX, Elsie & Ado are Digital, Borden & Ampex trademarks.



More information about the Comp.unix.wizards mailing list