simplify get_macos_uuid()
also remove a magic number 37 by replacing it with NHUUIDSZ
This commit is contained in:
+1
-1
@@ -1175,7 +1175,7 @@ struct instance_globals_saved_n {
|
||||
/* dungeon.c */
|
||||
int n_dgns; /* number of dungeons (also used in mklev.c and do.c) */
|
||||
/* files.c */
|
||||
char nhuuid[37];
|
||||
char nhuuid[NHUUIDSZ];
|
||||
/* mkroom.c */
|
||||
int nroom;
|
||||
/* region.c */
|
||||
|
||||
@@ -709,6 +709,10 @@ enum nhcb_calls {
|
||||
NUM_NHCB
|
||||
};
|
||||
|
||||
#ifdef NHUUID
|
||||
#define NHUUIDSZ 37
|
||||
#endif
|
||||
|
||||
struct plinemsg_type {
|
||||
xint16 msgtype; /* one of MSGTYP_foo */
|
||||
struct nhregex *regex;
|
||||
|
||||
+5
-28
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "hack.h"
|
||||
|
||||
void free_macos_uuid(void);
|
||||
void get_macos_uuid(char *);
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -14,44 +13,22 @@ void get_macos_uuid(char *);
|
||||
/* #import <Foundation/Foundation.h> */
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
static const char *macos_uuid = 0;
|
||||
|
||||
void
|
||||
free_macos_uuid(void)
|
||||
{
|
||||
if (macos_uuid) {
|
||||
free((genericptr_t) macos_uuid);
|
||||
macos_uuid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
get_macos_uuid(char *target)
|
||||
{
|
||||
NSString *uuidString = [[NSUUID UUID] UUIDString];
|
||||
const char *str_uuid, *src;
|
||||
char *dst;
|
||||
const char *str_uuid;
|
||||
int i;
|
||||
|
||||
if (macos_uuid)
|
||||
free_macos_uuid();
|
||||
|
||||
/* str_uuid = [uuidString cStringUsingEncoding:NSUTF8StringEncoding]; */
|
||||
str_uuid = [uuidString cStringUsingEncoding:NSASCIIStringEncoding];
|
||||
macos_uuid = dupstr(str_uuid);
|
||||
|
||||
if (macos_uuid) {
|
||||
src = macos_uuid;
|
||||
dst = target;
|
||||
for (i = 0; i < 36; ++i) {
|
||||
*dst = *src;
|
||||
++src;
|
||||
++dst;
|
||||
if (str_uuid && target) {
|
||||
for (i = 0; i < (NHUUIDSZ -1 ); ++i) {
|
||||
target[i] = str_uuid[i];
|
||||
}
|
||||
dst[36] = '\0';
|
||||
target[(NHUUIDSZ - 1)] = '\0';
|
||||
}
|
||||
free_macos_uuid();
|
||||
macos_uuid = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -843,15 +843,13 @@ sys_random_seed(void)
|
||||
|
||||
#if defined(MACOS) && defined(NHUUID)
|
||||
extern void get_macos_uuid(char *); /* sys/unix/macuuid.m */
|
||||
extern void free_macos_uuid(void); /* sys/unix/macuuid.m */
|
||||
#endif
|
||||
|
||||
void
|
||||
get_nhuuid(void)
|
||||
{
|
||||
#if defined(NHUUID)
|
||||
char struuid[37] = { 0 };
|
||||
char *struuidptr = &struuid[0];
|
||||
char struuid[NHUUIDSZ] = { 0 };
|
||||
#if defined(LINUX) && defined(NHUUID)
|
||||
uuid_t binuuid;
|
||||
#endif
|
||||
@@ -866,8 +864,8 @@ get_nhuuid(void)
|
||||
uuid_unparse(binuuid, struuid);
|
||||
#endif /* MACOS || LINUX */
|
||||
|
||||
if (*struuidptr)
|
||||
Snprintf(svn.nhuuid, sizeof svn.nhuuid, "%s", struuidptr);
|
||||
if (struuid[0])
|
||||
Snprintf(svn.nhuuid, sizeof svn.nhuuid, "%s", struuid);
|
||||
|
||||
#endif /* NHUUID */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user