<commit_before>package kenv

import (
	"syscall"
	"unsafe"
)

const (
	SYS_KENV = 390

	GET   = 0
	SET   = 1
	UNSET = 2
	DUMP  = 3

//	MNAMELEN = 128 /* Maximum name length (for the syscall) */
//	MVALLEN  = 128 /* Maximum value length (for the syscall) */
)

func Get(name string) ([]byte, error) {
	buf := make([]byte, 1024)

	if err := kenv(GET, name, buf); err != nil {
		return nil, err
	} else {
		return buf, nil
	}

}

func Set(name string, value string) error {
	return kenv(SET, name, []byte(value))
}

func Unset(name string) error {
	return kenv(UNSET, name, nil)
}

func Dump() ([]byte, error) {
	_null := unsafe.Pointer(nil)

	if envlen, e := kenv_sys(DUMP, _null, _null, 0); e != nil {
		return nil, e
	} else {
		buf := make([]byte, envlen+1)
		if e2 := kenv(DUMP, "", buf); e2 != nil {
			return nil, e2
		} else {
			return buf, nil
		}
	}
}

func kenv(action int, name string, value []byte) (err error) {

	if action == GET {
		if _name, e := syscall.BytePtrFromString(name); e != nil {
			err = e
			return
		} else {
			if _, e2 := kenv_sys(GET, unsafe.Pointer(_name), unsafe.Pointer(&value[0]), len(value)); e2 != nil {
				err = e2
				return
			} else {
				return nil
			}
		}
	}

	if action == SET {
		if _name, e := syscall.BytePtrFromString(name); e != nil {
			err = e
			return
		} else {
			if _, e2 := kenv_sys(SET, unsafe.Pointer(_name), unsafe.Pointer(&value[0]), len(value)); e2 != nil {
				err = e2
				return
			} else {
				return nil
			}
		}
	}
	if action == UNSET {
		_null := unsafe.Pointer(nil)

		if _name, e := syscall.BytePtrFromString(name); e != nil {
			err = e
			return
		} else {
			if _, e2 := kenv_sys(UNSET, unsafe.Pointer(_name), _null, 0); e2 != nil {
				err = e2
				return
			} else {
				return nil
			}
		}
	}

	if action == DUMP {
		_null := unsafe.Pointer(nil)

		if _, e := kenv_sys(DUMP, _null, unsafe.Pointer(&value[0]), len(value)); e != nil {
			err = e
			return
		} else {
			return nil
		}
	}

	return nil
}

func kenv_sys(what int, name unsafe.Pointer, value unsafe.Pointer, size int) (ret int, err error) {
	r1, _, e := syscall.Syscall6(SYS_KENV, uintptr(what), uintptr(name), uintptr(value), uintptr(size), 0, 0)
	if e != 0 {
		err = syscall.Errno(e)
		ret = -1
	} else {
		err = nil
		ret = int(r1)
	}

	return
}<commit_msg>kenv updates<commit_after>package kenv

import (
	"syscall"
	"unsafe"
)

const (
	SYS_KENV = 390

	GET   = 0
	SET   = 1
	UNSET = 2
	DUMP  = 3
)

func Get(name string) ([]byte, error) {
	var (
		buf  = make([]byte, 1024)
		bptr *byte
		err  error
	)

	if bptr, err = syscall.BytePtrFromString(name); err != nil {
		return nil, err
	}

	if _, err = kenv_sys(GET, unsafe.Pointer(bptr), unsafe.Pointer(&buf[0]), len(buf)); err != nil {
		return nil, err
	}

	return buf, nil
}

func Set(name string, value string) error {
	var (
		bptr *byte
		err  error
		bslc []byte = []byte(value)
	)

	if bptr, err = syscall.BytePtrFromString(name); err != nil {
		return err
	}

	if _, err = kenv_sys(SET, unsafe.Pointer(bptr), unsafe.Pointer(&bslc[0]), len(bslc)); err != nil {
		return err
	}

	return nil
}

func Unset(name string) error {
	var (
		bptr *byte
		err  error
	)

	if bptr, err = syscall.BytePtrFromString(name); err != nil {
		return err
	}

	if _, err = kenv_sys(UNSET, unsafe.Pointer(bptr), unsafe.Pointer(nil), 0); err != nil {
		return err
	}

	return nil
}

func Dump() ([]byte, error) {
	var (
		envlen int
		err    error
	)

	if envlen, err = kenv_sys(DUMP, unsafe.Pointer(nil), unsafe.Pointer(nil), 0); err != nil {
		return nil, err
	}

	buf := make([]byte, envlen+1)
	if _, err = kenv_sys(DUMP, unsafe.Pointer(nil), unsafe.Pointer(&buf[0]), len(buf)); err != nil {
		return nil, err
	}

	return buf, nil
}

func kenv_sys(what int, name unsafe.Pointer, value unsafe.Pointer, size int) (int, error) {
	ret, _, err := syscall.Syscall6(SYS_KENV, uintptr(what), uintptr(name), uintptr(value), uintptr(size), 0, 0)
	if err != 0 {
		return -1, syscall.Errno(err)
	}
	return int(ret), nil
}
{'fraction_non_alphanumeric': 0.1566958698372966, 'fraction_numerical': 0.01602002503128911, 'mean_word_length': 3.02416918429003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '606657', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1538, 'n_words': 438}