<commit_before>extern crate pty;
extern crate libc;

use self::pty::prelude::*;

use std::ffi::CString;

use std::io::prelude::*;
use std::process::{Command, Stdio};
use std::ptr;
use std::string::String;

fn main() {
    let fork = Fork::from_ptmx().unwrap();

    if let Some(mut master) = fork.is_parent().ok() {
        let mut string = String::new();

        master.read_to_string(&mut string).unwrap_or_else(|e| panic!(e));

        let output = Command::new("tty")
            .stdin(Stdio::inherit())
            .output()
            .unwrap()
            .stdout;

        let parent_tty = String::from_utf8_lossy(&output);
        let child_tty = string.trim();

        println!("child_tty(\"{}\")[{}] != \"{}\" => {}", child_tty, child_tty.len(), "", child_tty != "");
        assert!(child_tty != "");
        assert!(child_tty != parent_tty);

        let mut parent_tty_dir: Vec<&str> = parent_tty.split("/").collect();
        let mut child_tty_dir: Vec<&str> = child_tty.split("/").collect();

        parent_tty_dir.pop();
        child_tty_dir.pop();

        assert_eq!(parent_tty_dir, child_tty_dir);
    } else {
        let mut ptrs = [CString::new("tty").unwrap().as_ptr(), ptr::null()];
        let _ = unsafe { libc::execvp(*ptrs.as_ptr(), ptrs.as_mut_ptr()) };
    }
}<commit_msg>fix feeing of memory problem in example 'new.rs'<commit_after>extern crate pty;
extern crate libc;

use self::pty::prelude::*;

use std::io::prelude::*;
use std::process::{Command, Stdio};

fn main() {
    let fork = Fork::from_ptmx().unwrap();

    if let Some(mut master) = fork.is_parent().ok() {
        let mut string = String::new();

        master.read_to_string(&mut string).unwrap_or_else(|e| panic!(e));

        let output = Command::new("tty")
            .stdin(Stdio::inherit())
            .output()
            .unwrap()
            .stdout;
        let output_str = String::from_utf8_lossy(&output);

        let parent_tty = output_str.trim();
        let child_tty = string.trim();

        println!("child_tty(\"{}\")[{}] != \"{}\" => {}", child_tty, child_tty.len(), "", child_tty != "");
        assert!(child_tty != "");
        assert!(child_tty != parent_tty);

        let mut parent_tty_dir: Vec<&str> = parent_tty.split("/").collect();
        let mut child_tty_dir: Vec<&str> = child_tty.split("/").collect();

        parent_tty_dir.pop();
        child_tty_dir.pop();

        assert_eq!(parent_tty_dir, child_tty_dir);
    } else {
        let _ = Command::new("tty").status();
    }
}
{'fraction_non_alphanumeric': 0.1919271863870202, 'fraction_numerical': 0.0007914523149980214, 'mean_word_length': 2.8536585365853657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4961407', 'n_tokens_mistral': 850, 'n_tokens_neox': 836, 'n_words': 157}