// 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() {
		 := .Text()
		if !strings.Contains(, ":") {
			continue
		}

		 := strings.SplitN(, ": ", 2)
		switch strings.TrimSpace([0]) {
		case "Model Name", "model name":
			 = [1]
		case "CPU MHz", "cpu MHz":
			 = [1]
		}
	}

	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"
}