Commit to fix handling of Fl_Preferences UUID values on 64-bit WinXX and *nix systems.
Not tested as thoroughly as I would like - I don't have a 64-bit big-endian system... git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7707 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
b010bce1af
commit
b15ececeb6
@ -137,11 +137,17 @@ const char *Fl_Preferences::newUUID()
|
||||
b[5] = (unsigned char)(r>>8);
|
||||
b[6] = (unsigned char)(r>>16);
|
||||
b[7] = (unsigned char)(r>>24);
|
||||
unsigned int a = (unsigned int)&t; // four more bytes
|
||||
b[8] = (unsigned char)a;
|
||||
b[9] = (unsigned char)(a>>8);
|
||||
b[10] = (unsigned char)(a>>16);
|
||||
b[11] = (unsigned char)(a>>24);
|
||||
// Now we try to find 4 more "random" bytes. We extract the
|
||||
// lower 4 bytes from the address of t - it is created on the
|
||||
// stack so *might* be in a different place each time...
|
||||
// This is now done via a union to make it compile OK on 64-bit systems.
|
||||
union { void *pv; unsigned char a[sizeof(void*)]; } v;
|
||||
v.pv = (void *)(&t);
|
||||
// NOTE: This assume that all WinXX systems are little-endian
|
||||
b[8] = v.a[0];
|
||||
b[9] = v.a[1];
|
||||
b[10] = v.a[2];
|
||||
b[11] = v.a[3];
|
||||
TCHAR name[MAX_COMPUTERNAME_LENGTH + 1]; // only used to make last four bytes
|
||||
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
|
||||
// GetComputerName() does not depend on any extra libs, and returns something
|
||||
@ -156,7 +162,9 @@ const char *Fl_Preferences::newUUID()
|
||||
b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]);
|
||||
}
|
||||
#else
|
||||
#warning Unix implementation incomplete!
|
||||
# if defined(__GNUC__)
|
||||
# warning Unix implementation of Fl_Preferences::newUUID() incomplete!
|
||||
# endif /*__GNUC__*/
|
||||
// #include <uuid/uuid.h>
|
||||
// void uuid_generate(uuid_t out);
|
||||
unsigned char b[16];
|
||||
@ -175,6 +183,24 @@ const char *Fl_Preferences::newUUID()
|
||||
b[9] = (unsigned char)(a>>8);
|
||||
b[10] = (unsigned char)(a>>16);
|
||||
b[11] = (unsigned char)(a>>24);
|
||||
// Now we try to find 4 more "random" bytes. We extract the
|
||||
// lower 4 bytes from the address of t - it is created on the
|
||||
// stack so *might* be in a different place each time...
|
||||
// This is now done via a union to make it compile OK on 64-bit systems.
|
||||
union { void *pv; unsigned char a[sizeof(void*)]; } v;
|
||||
v.pv = (void *)(&t);
|
||||
// NOTE: May need to handle big- or little-endian systems here
|
||||
# if WORDS_BIGENDIAN
|
||||
b[8] = v.a[sizeof(void*) - 1];
|
||||
b[9] = v.a[sizeof(void*) - 2];
|
||||
b[10] = v.a[sizeof(void*) - 3];
|
||||
b[11] = v.a[sizeof(void*) - 4];
|
||||
# else /* data ordered for a little-endian system */
|
||||
b[8] = v.a[0];
|
||||
b[9] = v.a[1];
|
||||
b[10] = v.a[2];
|
||||
b[11] = v.a[3];
|
||||
# endif
|
||||
char name[80]; // last four bytes
|
||||
gethostname(name, 79);
|
||||
memcpy(b+12, name, 4);
|
||||
|
Loading…
x
Reference in New Issue
Block a user