Skip to content

Commit

Permalink
It works
Browse files Browse the repository at this point in the history
on my laptop
  • Loading branch information
hibariya committed Jul 2, 2015
0 parents commit bcc4401
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
target
11 changes: 11 additions & 0 deletions Cargo.toml
@@ -0,0 +1,11 @@
[package]
name = "pty"
version = "0.1.0"
authors = ["Hika Hibariya <hibariya@gmail.com>"]
repository = "https://github.com/hibariya/pty-rs"
homepage = "https://github.com/hibariya/pty-rs"
license="MIT"
description='Fork with new PTY'

[dependencies]
libc='0.1'
21 changes: 21 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Hika Hibariya

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
17 changes: 17 additions & 0 deletions README.md
@@ -0,0 +1,17 @@
# PTY

## Usage

Add this to your `Cargo.toml`:

```toml
[dependencies]

pty = "0.1.0"
```

and this to your crate root:

```rust
extern crate pty;
```
42 changes: 42 additions & 0 deletions src/lib.rs
@@ -0,0 +1,42 @@
extern crate libc;

extern {
fn posix_openpt(flags: libc::c_int) -> libc::c_int;
fn grantpt(fd: libc::c_int) -> libc::c_int;
fn unlockpt(fd: libc::c_int) -> libc::c_int;
fn ptsname(fd: libc::c_int) -> *mut libc::c_schar;
}

pub fn fork() -> (libc::pid_t, libc::c_int)
{
let pty_master = unsafe { posix_openpt(libc::O_RDWR) };

unsafe { grantpt(pty_master) };
unsafe { unlockpt(pty_master) };

let pts_name = unsafe { ptsname(pty_master) };
let pid = unsafe { libc::fork() };

if pid == 0 {
unsafe { libc::setsid() };

let pty_slave = unsafe { libc::open(pts_name, libc::O_RDWR, 0) };

unsafe { libc::close(pty_master) };

unsafe { libc::dup2(pty_slave, libc::STDIN_FILENO) };
unsafe { libc::dup2(pty_slave, libc::STDOUT_FILENO) };
unsafe { libc::dup2(pty_slave, libc::STDERR_FILENO) };

unsafe { libc::close(pty_slave) };

return (0, -1);
}
else {
return (pid, pty_master);
}
}

#[test]
fn it_works() {
}

0 comments on commit bcc4401

Please sign in to comment.