comparison rogue3/mdport.c @ 252:3d4252fa2ed3

Use more portable random seed generation. The new function md_random_seed() has replaced time() + getpid() and similar methods. Putting everything in mdport.c slightly reduces the warnings and workarounds.
author John "Elwin" Edwards
date Sat, 28 Jan 2017 15:49:41 -0500
parents 12e070d1a780
children 8b6aba552f6f
comparison
equal deleted inserted replaced
251:e7862a021609 252:3d4252fa2ed3
100 #include <ctype.h> 100 #include <ctype.h>
101 #include <fcntl.h> 101 #include <fcntl.h>
102 #include <limits.h> 102 #include <limits.h>
103 #include <sys/stat.h> 103 #include <sys/stat.h>
104 #include <signal.h> 104 #include <signal.h>
105 #include <time.h>
105 106
106 #define NOOP(x) (x += 0) 107 #define NOOP(x) (x += 0)
107 108
108 static int pass_ctrl_keypad = 1; 109 static int pass_ctrl_keypad = 1;
109 110
410 { 411 {
411 #ifdef HAVE_GETUID 412 #ifdef HAVE_GETUID
412 return( getuid() ); 413 return( getuid() );
413 #else 414 #else
414 return(42); 415 return(42);
415 #endif
416 }
417
418 pid_t
419 md_getpid(void)
420 {
421 #ifdef _WIN32
422 return( _getpid() );
423 #else
424 return( getpid() );
425 #endif 416 #endif
426 } 417 }
427 418
428 char * 419 char *
429 md_getusername(void) 420 md_getusername(void)
1610 break; 1601 break;
1611 #endif 1602 #endif
1612 1603
1613 return ret; 1604 return ret;
1614 } 1605 }
1606
1607 unsigned int
1608 md_random_seed(void)
1609 {
1610 unsigned int seed;
1611 seed = (unsigned int) time((time_t *) NULL);
1612 #ifdef _WIN32
1613 seed += _getpid();
1614 #else
1615 seed += getpid();
1616 #endif
1617 return seed;
1618 }