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
Improve NSUserName NSHomeDirectoryForUser #206
Conversation
According to the manpage http://linux.die.net/man/3/getlogin_r it should be more reliable.
… getpwnam_r and getpwuid_r.
fatalError("Could not get current logon name.") | ||
|
||
// maybe NSUserName should return optional string | ||
print("Could not get current logon name. \(errno) Return `unknown`.") |
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 placed workaround mentioned at https://bugs.swift.org/browse/SR-437 . If this PR fixes the issue it should be removed, I think.
@phausler It's done. |
} | ||
fatalError("Could not get current logon name.") | ||
let userName = CFCopyUserName().takeRetainedValue() | ||
return String(userName) |
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.
Do we actually have an initializer for String that takes a CFStringRef? perhaps it might be better to use the ._swiftObject
property extension on CFStringRef instead.
@phausler It seems |
seems to pass on linux just fine. I would suggest cleaning out your derived data if SourceKit is having issues. Sometimes it gets a cruft module map compilation that confuses it (primarily since we are re-defining CF and Foundation) |
Improve NSUserName NSHomeDirectoryForUser
Part 2: Update the struct definitions to match version 3.14 of the LSP spec
getlogin_r
replaced with getgetpwuid_r->name
. According to the manpage it should be more reliable.sysconf(Int32(_SC_GETPW_R_SIZE_MAX))
to get recommended size of a buffer$HOME
environment variable first