<commit_before>// Copyright 2015-2017 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
	"syscall"
	"time"

	"unsafe"

	// "github.com/u-root/u-root/pkg/termios"
	"golang.org/x/sys/unix"
)

// pty support. We used to import github.com/kr/pty but what we need is not that complex.
// Thanks to <NAME> for these functions.

func ptsopen() (pty, tty *os.File, slavename string, err error) {
	p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
	if err != nil {
		return
	}

	slavename, err = ptsname(p)
	if err != nil {
		return
	}

	err = ptsunlock(p)
	if err != nil {
		return
	}

	t, err := os.OpenFile(slavename, os.O_RDWR|syscall.O_NOCTTY, 0)
	if err != nil {
		return
	}
	return p, t, slavename, nil
}

func ptsname(f *os.File) (string, error) {
	var n uintptr
	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n)))
	if err != 0 {
		return "", err
	}
	return "/dev/pts/" + strconv.Itoa(int(n)), nil
}

func ptsunlock(f *os.File) error {
	var u uintptr
	// use TIOCSPTLCK with a zero valued arg to clear the slave pty lock
	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&u)))
	if err != 0 {
		return err
	}
	return nil
}

type cgroupname string
<commit_msg>cmds/pflask: use IoctlGetInt to get ptrs index in ptsname<commit_after>// Copyright 2015-2017 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
	"syscall"
	"time"

	"unsafe"

	// "github.com/u-root/u-root/pkg/termios"
	"golang.org/x/sys/unix"
)

// pty support. We used to import github.com/kr/pty but what we need is not that complex.
// Thanks to <NAME> for these functions.

func ptsopen() (pty, tty *os.File, slavename string, err error) {
	p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
	if err != nil {
		return
	}

	slavename, err = ptsname(p)
	if err != nil {
		return
	}

	err = ptsunlock(p)
	if err != nil {
		return
	}

	t, err := os.OpenFile(slavename, os.O_RDWR|syscall.O_NOCTTY, 0)
	if err != nil {
		return
	}
	return p, t, slavename, nil
}

func ptsname(f *os.File) (string, error) {
	n, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCGPTN)
	if err != nil {
		return "", err
	}
	return "/dev/pts/" + strconv.Itoa(n), nil
}

func ptsunlock(f *os.File) error {
	var u uintptr
	// use TIOCSPTLCK with a zero valued arg to clear the slave pty lock
	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&u)))
	if err != 0 {
		return err
	}
	return nil
}

type cgroupname string

{'fraction_non_alphanumeric': 0.14589041095890412, 'fraction_numerical': 0.007876712328767124, 'mean_word_length': 3.3019145802650955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '770904', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1177, 'n_words': 342}