// Copyright 2023 The Go 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 sysinfo

import (
	
	
	
	
	
)

func readLinuxProcCPUInfo( []byte) error {
	,  := os.Open("/proc/cpuinfo")
	if  != nil {
		return 
	}
	defer .Close()

	_,  = io.ReadFull(, )
	if  != nil &&  != io.ErrUnexpectedEOF {
		return 
	}

	return nil
}

func osCPUInfoName() string {
	 := ""
	 := ""

	// The 512-byte buffer is enough to hold the contents of CPU0
	 := make([]byte, 512)
	 := readLinuxProcCPUInfo()
	if  != nil {
		return ""
	}

	 := bufio.NewScanner(bytes.NewReader())
	for .Scan() {
		, ,  := strings.Cut(.Text(), ": ")
		if ! {
			continue
		}
		switch strings.TrimSpace() {
		case "Model Name", "model name":
			 = 
		case "CPU MHz", "cpu MHz":
			 = 
		}
	}

	if  == "" {
		return ""
	}

	if  == "" {
		return 
	}

	// The modelName field already contains the frequency information,
	// so the cpuMHz field information is not needed.
	// modelName filed example:
	//	Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
	 := [...]string{"GHz", "MHz"}
	for ,  := range  {
		if strings.Contains(, ) {
			return 
		}
	}

	return  + " @ " +  + "MHz"
}