Initial release
This commit is contained in:
parent
096e02c7fb
commit
f8b3987e79
61
src/mkfifo.c
Normal file
61
src/mkfifo.c
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/* mkfifo.c */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
extern char * optarg;
|
||||||
|
extern int optind;
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* mkfifo */
|
||||||
|
static int _mkfifo(char const * pathname, mode_t mode)
|
||||||
|
{
|
||||||
|
if(mkfifo(pathname, mode) == -1)
|
||||||
|
{
|
||||||
|
perror("mkfifo");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* usage */
|
||||||
|
static int usage(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: mkfifo [-m mode] file...\n\
|
||||||
|
-m create fifo with the specified mode value\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* main */
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
mode_t mode = 0777;
|
||||||
|
int errcode = 0;
|
||||||
|
int o;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
while((o = getopt(argc, argv, "m:")) != -1)
|
||||||
|
{
|
||||||
|
switch(o)
|
||||||
|
{
|
||||||
|
case 'm':
|
||||||
|
if((mode = strtol(optarg, NULL, 8)) > 0777)
|
||||||
|
return usage();
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(argc == optind)
|
||||||
|
return usage();
|
||||||
|
for(i = optind; i < argc; i++)
|
||||||
|
if(_mkfifo(argv[i], mode) == 2)
|
||||||
|
errcode = 2;
|
||||||
|
return errcode;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user