view toys/mkfifo.c @ 168:14fa82969ea3

Tighten up error handling, add a umask() call so -m 123 actually works.
author Rob Landley <rob@landley.net>
date Mon, 19 Nov 2007 07:07:50 -0600
parents 714f4c051594
children 25447caf1b4b
line wrap: on
line source

/* vi: set sw=4 ts=4: */
/*
 * mkfifo.c: Create a named pipe.
 *
 * See http://www.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html
 */

#include "toys.h"

int mkfifo_main(void)
{
	char *arg;
	int i;
	mode_t mode;

	if (toys.optflags) {
		char *end;
		mode = (mode_t)strtol(toy.mkfifo.mode, &end, 8);
		if (end<=toy.mkfifo.mode || *end || mode<0 || mode>0777)
			error_exit("Invalid mode");
	} else mode = 0644;

	umask(0);
	for (i = 0; (arg = toys.optargs[i]); i++)
		if (mkfifo(arg, mode))
			perror_exit(arg);

	return 0;
}