Skip to content
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

Merged
merged 6 commits into from Jan 2, 2016

Conversation

HeMet
Copy link
Contributor

@HeMet HeMet commented Jan 2, 2016

  • getlogin_r replaced with get getpwuid_r->name. According to the manpage it should be more reliable.
  • use sysconf(Int32(_SC_GETPW_R_SIZE_MAX)) to get recommended size of a buffer
  • for the current user check $HOME environment variable first

fatalError("Could not get current logon name.")

// maybe NSUserName should return optional string
print("Could not get current logon name. \(errno) Return `unknown`.")
Copy link
Contributor Author

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.

@HeMet
Copy link
Contributor Author

HeMet commented Jan 2, 2016

@phausler It's done.

}
fatalError("Could not get current logon name.")
let userName = CFCopyUserName().takeRetainedValue()
return String(userName)
Copy link
Member

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.

@HeMet
Copy link
Contributor Author

HeMet commented Jan 2, 2016

@phausler It seems public init<T>(_ instance: T) was used. I replaced it with ._swiftObject. It passes the tests, but crashes SourceKit repeatedly.

@phausler
Copy link
Member

phausler commented Jan 2, 2016

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)

phausler added a commit that referenced this pull request Jan 2, 2016
Improve NSUserName NSHomeDirectoryForUser
@phausler phausler merged commit 5e7d9e4 into apple:master Jan 2, 2016
@HeMet HeMet deleted the nsusername-v2 branch January 3, 2016 07:22
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
Part 2: Update the struct definitions to match version 3.14 of the LSP spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants