Obtain hw.model from the sysctl tool
Saves building our own tool to do the same job!
This commit is contained in:
parent
b71b8e3972
commit
74f2dd7d38
@ -1,17 +0,0 @@
|
|||||||
/*
|
|
||||||
This software is in the public domain, furnished "as is", without technical
|
|
||||||
support, and with no warranty, express or implied, as to its usefulness for
|
|
||||||
any purpose.
|
|
||||||
*/
|
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
char buf[32];
|
|
||||||
size_t sz = sizeof(buf);
|
|
||||||
int r = sysctlbyname("hw.model", buf, &sz, NULL, 0);
|
|
||||||
if (r == 0)
|
|
||||||
printf("%.*s", sz, buf);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
@ -21,13 +21,12 @@
|
|||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# The output of the command is in the form of: `MacBook2,1'
|
||||||
|
# This yields: "MacBook", 2, 1
|
||||||
def hw_model_output
|
def hw_model_output
|
||||||
require 'fileutils'
|
model=`/usr/sbin/sysctl hw.model`.match /hw.model: (\w+)(\d+),(\d+)/
|
||||||
HOMEBREW_CACHE.mkpath
|
yield model[1], model[2].to_i, model[3].to_i
|
||||||
exe=HOMEBREW_CACHE+'hw.model'
|
|
||||||
Kernel.system "gcc -Os #{File.dirname __FILE__}/hw.model.c -o #{exe}" unless exe.file?
|
|
||||||
/(.*)(\d+),(\d+)/ =~ `#{exe}`
|
|
||||||
yield $1, $2.to_i, $3.to_i
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# http://support.apple.com/kb/HT3696
|
# http://support.apple.com/kb/HT3696
|
||||||
@ -35,11 +34,11 @@ end
|
|||||||
def hw_model
|
def hw_model
|
||||||
hw_model_output do |model, major, minor|
|
hw_model_output do |model, major, minor|
|
||||||
case model
|
case model
|
||||||
when "iMac"
|
when "iMac"
|
||||||
if major <=4
|
if major <= 4
|
||||||
:core1
|
:core1
|
||||||
else
|
else
|
||||||
$unknown_hw_model=true if major >8
|
$unknown_hw_model=true if major > 8
|
||||||
:core2
|
:core2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user