@@ -438,6 +438,49 @@ pub fn mkdir<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
438
438
Errno :: result ( res) . map ( drop)
439
439
}
440
440
441
+ /// Creates new fifo special file (named pipe) with path `path` and access rights `mode`.
442
+ ///
443
+ /// # Errors
444
+ ///
445
+ /// There are several situations where mkfifo might fail:
446
+ ///
447
+ /// - current user has insufficient rights in the parent directory
448
+ /// - the path already exists
449
+ /// - the path name is too long (longer than `PATH_MAX`, usually 4096 on linux, 1024 on OS X)
450
+ ///
451
+ /// For a full list consult
452
+ /// [posix specification](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mkfifo.html)
453
+ ///
454
+ /// # Example
455
+ ///
456
+ /// ```rust
457
+ /// extern crate tempdir;
458
+ /// extern crate nix;
459
+ ///
460
+ /// use nix::unistd;
461
+ /// use nix::sys::stat;
462
+ /// use tempdir::TempDir;
463
+ ///
464
+ /// fn main() {
465
+ /// let tmp_dir = TempDir::new("test_fifo").unwrap();
466
+ /// let fifo_path = tmp_dir.path().join("foo.pipe");
467
+ ///
468
+ /// // create new fifo and give read, write and execute rights to the owner
469
+ /// match unistd::mkfifo(&fifo_path, stat::S_IRWXU) {
470
+ /// Ok(_) => println!("created {:?}", fifo_path),
471
+ /// Err(err) => println!("Error creating fifo: {}", err),
472
+ /// }
473
+ /// }
474
+ /// ```
475
+ #[ inline]
476
+ pub fn mkfifo < P : ?Sized + NixPath > ( path : & P , mode : Mode ) -> Result < ( ) > {
477
+ let res = try!( path. with_nix_path ( |cstr| {
478
+ unsafe { libc:: mkfifo ( cstr. as_ptr ( ) , mode. bits ( ) as mode_t ) }
479
+ } ) ) ;
480
+
481
+ Errno :: result ( res) . map ( drop)
482
+ }
483
+
441
484
/// Returns the current directory as a PathBuf
442
485
///
443
486
/// Err is returned if the current user doesn't have the permission to read or search a component
0 commit comments