-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added userName and fullUserName to ProcessInfo #1431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Marked NSFullUserName() as Unimplemented
Foundation/NSPathUtilities.swift
Outdated
@@ -588,6 +588,10 @@ public func NSUserName() -> String { | |||
return userName._swiftObject | |||
} | |||
|
|||
public func NSFullUserName() -> String { | |||
NSUnimplemented() | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use something like the following to extract the gecos info?
public func NSFullUserName() -> String {
let euid = _CFGetEUID()
let uid = euid != 0 ? euid : getuid()
var pwd = passwd()
let maxSize = sysconf(Int32(_SC_GETPW_R_SIZE_MAX))
let buf = UnsafeMutablePointer<Int8>.allocate(capacity: maxSize)
defer { buf.deallocate() }
var ptr: UnsafeMutablePointer<passwd>? = nil
if getpwuid_r(uid, &pwd, buf, maxSize, &ptr) == 0 {
if let gecos = pwd.pw_gecos {
return String(cString: gecos)
}
}
return ""
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to leave the NSFullUserName implementation for other Pull Request/Contributor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this, shouldn't this code be implemented in Core Foundation in a function similar to CFCopyUserName and made portable between multiple platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably keep it in Swift and only add it into CF if the multi-platform support became too messy and a lot easier to write using the C preprocessor.
CFCopyFullUserName implemented for POSIX OS. TODO: Add Windows implementation.
Added NSFullUserName() and underlying implementation in CFCopyFullUserName() for POSIX OS. |
#error Don't know how to compute full user name on this platform | ||
#endif | ||
if (!result) | ||
result = (CFStringRef)CFRetain(CFSTR("")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit here: please always use { }
or make one line for if
statements.
Other than minor style point, looks good to me. |
Updated style with braces on if statements. |
@swift-ci test and merge |
1 similar comment
@swift-ci test and merge |
Uh oh!
There was an error while loading. Please reload this page.