comparison rogue5/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 600873555ec0
children 8b6aba552f6f
comparison
equal deleted inserted replaced
251:e7862a021609 252:3d4252fa2ed3
96 #include <ctype.h> 96 #include <ctype.h>
97 #include <fcntl.h> 97 #include <fcntl.h>
98 #include <limits.h> 98 #include <limits.h>
99 #include <sys/stat.h> 99 #include <sys/stat.h>
100 #include <signal.h> 100 #include <signal.h>
101 #include <time.h>
101 #include "extern.h" 102 #include "extern.h"
102 103
103 #if !defined(PATH_MAX) && defined(_MAX_PATH) 104 #if !defined(PATH_MAX) && defined(_MAX_PATH)
104 #define PATH_MAX _MAX_PATH 105 #define PATH_MAX _MAX_PATH
105 #endif 106 #endif
406 { 407 {
407 #ifdef HAVE_GETUID 408 #ifdef HAVE_GETUID
408 return( getuid() ); 409 return( getuid() );
409 #else 410 #else
410 return(42); 411 return(42);
411 #endif
412 }
413
414 pid_t
415 md_getpid(void)
416 {
417 #ifdef _WIN32
418 return( _getpid() );
419 #else
420 return( getpid() );
421 #endif 412 #endif
422 } 413 }
423 414
424 char * 415 char *
425 md_getusername(void) 416 md_getusername(void)
1491 #ifdef SIGTSTP 1482 #ifdef SIGTSTP
1492 kill(0, SIGTSTP); /* send actual signal and suspend process */ 1483 kill(0, SIGTSTP); /* send actual signal and suspend process */
1493 #endif 1484 #endif
1494 } 1485 }
1495 1486
1487 unsigned int
1488 md_random_seed(void)
1489 {
1490 unsigned int seed;
1491 seed = (unsigned int) time((time_t *) NULL);
1492 #ifdef _WIN32
1493 seed += _getpid();
1494 #else
1495 seed += getpid();
1496 #endif
1497 return seed;
1498 }
1499
1496 #if defined(CHECKTIME) 1500 #if defined(CHECKTIME)
1497 void 1501 void
1498 md_start_checkout_timer(int time) 1502 md_start_checkout_timer(int time)
1499 { 1503 {
1500 int checkout(); 1504 int checkout();