Skip to content

Commit 62fa91b

Browse files
committed
ADDED: library(unix): mkfifo/2
1 parent 99c04a5 commit 62fa91b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

unix.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <stdlib.h>
4141
#include <unistd.h>
4242
#include <sys/types.h>
43+
#include <sys/stat.h>
4344
#include <sys/wait.h>
4445
#include <fcntl.h>
4546
#include <assert.h>
@@ -310,6 +311,22 @@ pl_environ(term_t l)
310311
return PL_unify_nil(t);
311312
}
312313

314+
static foreign_t
315+
pl_mkfifo(term_t Path, term_t Mode)
316+
{ char *pathname;
317+
mode_t mode;
318+
319+
if ( !PL_get_chars(Path, &pathname, CVT_ALL|BUF_MALLOC|REP_MB) )
320+
return FALSE;
321+
if ( !PL_get_integer(Mode, (int *)&mode) )
322+
return pl_error("mkfifo", 2, NULL, ERR_ARGTYPE, 1, Mode, "mode");
323+
if ( !mkfifo(pathname, mode) < 0 )
324+
return pl_error("mkfifo", 2, NULL, ERR_ERRNO, errno, "create", "fifo", Path);
325+
326+
PL_free(pathname);
327+
return TRUE;
328+
}
329+
313330

314331
/*******************************
315332
* DEAMON IO *
@@ -527,6 +544,7 @@ install_unix()
527544
PL_register_foreign("dup", 2, pl_dup, 0);
528545
PL_register_foreign("detach_IO", 1, pl_detach_IO, 0);
529546
PL_register_foreign("environ", 1, pl_environ, 0);
547+
PL_register_foreign("mkfifo", 2, pl_mkfifo, 0);
530548
#ifdef HAVE_PRCTL
531549
PL_register_foreign("prctl", 1, pl_prctl, 0);
532550
#endif

unix.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
dup/2, % +From, +To
4545
detach_IO/0,
4646
detach_IO/1, % +Stream
47-
environ/1 % -[Name=Value]
47+
environ/1, % -[Name=Value]
48+
mkfifo/2 % +Path, +Mode
4849
]).
4950

5051
/** <module> Unix specific operations

0 commit comments

Comments
 (0)