mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-10 16:20:42 +00:00
Thread safety fix
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6556 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
130e7c9aa3
commit
0cfa5a834b
2 changed files with 13 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
2000-05-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSUser.m: NSHomeDirectoryForUser() protect with locks for
|
||||
thread safety.
|
||||
|
||||
2000-05-02 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* configure.in: Add check for word alignment. Also don't define
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
|
||||
#include <stdlib.h> // for getenv()
|
||||
|
@ -116,7 +117,10 @@ NSHomeDirectoryForUser(NSString *login_name)
|
|||
{
|
||||
#if !defined(__WIN32__)
|
||||
struct passwd *pw;
|
||||
|
||||
[gnustep_global_lock lock];
|
||||
pw = getpwnam ([login_name cString]);
|
||||
[gnustep_global_lock unlock];
|
||||
return [NSString stringWithCString: pw->pw_dir];
|
||||
#else
|
||||
/* Then environment variable HOMEPATH holds the home directory
|
||||
|
@ -125,6 +129,7 @@ NSHomeDirectoryForUser(NSString *login_name)
|
|||
DWORD n;
|
||||
NSString *s;
|
||||
|
||||
[gnustep_global_lock lock];
|
||||
n = GetEnvironmentVariable("HOMEPATH", buf, 1024);
|
||||
if (n > 1024)
|
||||
{
|
||||
|
@ -134,14 +139,15 @@ NSHomeDirectoryForUser(NSString *login_name)
|
|||
nb[n] = '\0';
|
||||
s = [NSString stringWithCString: nb];
|
||||
NSZoneFree(NSDefaultMallocZone(), nb);
|
||||
return s;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* null terminate it and return the string */
|
||||
buf[n] = '\0';
|
||||
return [NSString stringWithCString: buf];
|
||||
s = [NSString stringWithCString: buf];
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
return s;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue