mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Ensure globally unique string is ok as a windoze filename (assuming that
length constraints permit). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14248 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d9b2c57fa3
commit
bde22bbc6f
2 changed files with 24 additions and 15 deletions
|
@ -1,3 +1,9 @@
|
|||
2002-08-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSProcessInfo.m: ([-globallyUniqueString]) Ensure that the
|
||||
string contains no dots, so it can be used as a filename under
|
||||
windoze.
|
||||
|
||||
2002-08-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSString.m: ([-boolValue]) Accept 'true' as well as 'YES'
|
||||
|
|
|
@ -591,31 +591,34 @@ int main(int argc, char *argv[], char *env[])
|
|||
/**
|
||||
* Returns a string which may be used as a globally unique identifier.<br />
|
||||
* The string contains the host name, the process ID, a timestamp and a
|
||||
* counter (to ensure that multiple strings generated within the same
|
||||
* process are unique).
|
||||
* counter.<br />
|
||||
* The first three values identify the process in which the string is
|
||||
* generated, while the fourth ensures that multiple strings generated
|
||||
* within the same process are unique.
|
||||
*/
|
||||
- (NSString *) globallyUniqueString
|
||||
{
|
||||
static int pid = 0;
|
||||
static int counter = 0;
|
||||
int count;
|
||||
static unsigned long counter = 0;
|
||||
int count;
|
||||
static NSString *host = nil;
|
||||
static int pid;
|
||||
static unsigned long start;
|
||||
|
||||
if (pid == 0)
|
||||
{
|
||||
#if defined(__MINGW__)
|
||||
pid = (int)GetCurrentProcessId();
|
||||
#else
|
||||
pid = (int)getpid();
|
||||
#endif
|
||||
}
|
||||
[gnustep_global_lock lock];
|
||||
if (host == nil)
|
||||
{
|
||||
pid = [self processIdentifier];
|
||||
start = (unsigned long)GSTimeNow();
|
||||
host = [[self hostName] stringByReplacingString: @"." withString: @"_"];
|
||||
RETAIN(host);
|
||||
}
|
||||
count = counter++;
|
||||
[gnustep_global_lock unlock];
|
||||
|
||||
// $$$ The format of the string is not specified by the OpenStep
|
||||
// specification.
|
||||
return [NSString stringWithFormat: @"%@_%d_%lf_%d",
|
||||
[self hostName], pid, GSTimeNow(), count];
|
||||
return [NSString stringWithFormat: @"%@_%x_%lx_%lx",
|
||||
host, pid, start, count];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue