Skip to content

Commit

Permalink
Fix bug with pulling identifier string
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Maccharoli committed Sep 5, 2017
1 parent d86015a commit 5da11ef
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/System.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class System {
var systemInfo = utsname()
uname(&systemInfo)

let encoding: UInt = String.Encoding.ascii.rawValue
let string = NSString(bytes: &systemInfo.machine, length: Int(_SYS_NAMELEN), encoding: encoding)
// TODO: Find the source of the extra newlines that are getting appended in the end
// the cause of this could just be a larger buffer than nessisary getting allocated
// the cause of this could just be a larger buffer than nessisary getting allocated
// and the rest of the string being zeroed out.
return (string as String?)?.components(separatedBy: "\n").first
let encoding: UInt = String.Encoding.ascii.rawValue
if let string = NSString(bytes: &systemInfo.machine, length: Int(_SYS_NAMELEN), encoding: encoding) {
return (string as String).components(separatedBy: "\0").first
}
return nil
}
}

0 comments on commit 5da11ef

Please sign in to comment.