tweak full user name

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32151 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-02-13 18:54:53 +00:00
parent 8d89880ace
commit a9a3fa7d3f
2 changed files with 25 additions and 13 deletions

View file

@ -1,3 +1,8 @@
2011-02-13 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPathUtilities.m: NSFullUserName() ... use short name if
no long one is available.
2011-02-13 Philippe Roussel <p.o.roussel@free.fr>
* Source/NSPointerArray.m: replace memcpy with memmove for safety.

View file

@ -1627,15 +1627,21 @@ NSFullUserName(void)
{
if (theFullUserName == nil)
{
NSString *userName = nil;
NSString *userName = NSUserName();
#if defined(__MINGW__)
struct _USER_INFO_2 *userInfo;
if (NetUserGetInfo(NULL, (unichar*)[NSUserName() cStringUsingEncoding:
if (NetUserGetInfo(NULL, (unichar*)[userName cStringUsingEncoding:
NSUnicodeStringEncoding], 2, (LPBYTE*)&userInfo) == 0)
{
userName = [NSString stringWithCharacters: userInfo->usri2_full_name
length: wcslen(userInfo->usri2_full_name)];
int length = wcslen(userInfo->usri2_full_name);
if (length > 0)
{
userName = [NSString
stringWithCharacters: userInfo->usri2_full_name
length: length];
}
}
#else
#ifdef HAVE_PWD_H
@ -1644,27 +1650,28 @@ NSFullUserName(void)
struct passwd *p;
char buf[BUFSIZ*10];
if (getpwnam_r([NSUserName() cString], &pw, buf, sizeof(buf), &p) == 0)
if (getpwnam_r([userName cString], &pw, buf, sizeof(buf), &p) == 0)
{
userName = [NSString stringWithUTF8String: pw.pw_gecos];
if (*pw.pw_gecos)
{
userName = [NSString stringWithUTF8String: pw.pw_gecos];
}
}
#else
#if defined(HAVE_GETPWNAM)
struct passwd *pw;
[gnustep_global_lock lock];
pw = getpwnam([NSUserName() cString]);
userName = [NSString stringWithUTF8String: pw->pw_gecos];
pw = getpwnam([userName cString]);
if (*pw.pw_gecos)
{
userName = [NSString stringWithUTF8String: pw->pw_gecos];
}
[gnustep_global_lock lock];
#endif /* HAVE_GETPWNAM */
#endif /* HAVE_GETPWNAM_R */
#endif /* HAVE_PWD_H */
#endif /* defined(__Win32__) else */
if (userName == nil)
{
NSLog(@"Warning: NSFullUserName not implemented\n");
userName = NSUserName();
}
ASSIGN(theFullUserName, userName);
}
return theFullUserName;