aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorEloy Duran2009-09-01 00:22:38 +0200
committerMax Howell2009-09-01 11:57:50 +0100
commit74f2dd7d3805c796fc120693da021738a1de704d (patch)
tree982b63863656dc25f0d087df3cf49bc87039c680 /Library
parentb71b8e39727a89b825b62d0fa734d9c03020db96 (diff)
downloadbrew-74f2dd7d3805c796fc120693da021738a1de704d.tar.bz2
Obtain hw.model from the sysctl tool
Saves building our own tool to do the same job!
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/hw.model.c17
-rw-r--r--Library/Homebrew/hw.model.rb17
2 files changed, 8 insertions, 26 deletions
diff --git a/Library/Homebrew/hw.model.c b/Library/Homebrew/hw.model.c
deleted file mode 100644
index c2507daee..000000000
--- a/Library/Homebrew/hw.model.c
+++ /dev/null
@@ -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;
-}
diff --git a/Library/Homebrew/hw.model.rb b/Library/Homebrew/hw.model.rb
index 86deebd47..9edcdd03f 100644
--- a/Library/Homebrew/hw.model.rb
+++ b/Library/Homebrew/hw.model.rb
@@ -21,13 +21,12 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# 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
- require 'fileutils'
- HOMEBREW_CACHE.mkpath
- 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
+ model=`/usr/sbin/sysctl hw.model`.match /hw.model: (\w+)(\d+),(\d+)/
+ yield model[1], model[2].to_i, model[3].to_i
end
# http://support.apple.com/kb/HT3696
@@ -35,11 +34,11 @@ end
def hw_model
hw_model_output do |model, major, minor|
case model
- when "iMac"
- if major <=4
+ when "iMac"
+ if major <= 4
:core1
else
- $unknown_hw_model=true if major >8
+ $unknown_hw_model=true if major > 8
:core2
end