Mercurial > hg > early-roguelike
comparison srogue/mdport.c @ 120:d6b7c3fb37ea
srogue: add and use more md_* portable functions.
Privileges and memory usage checks are now more portable.
author | John "Elwin" Edwards |
---|---|
date | Fri, 02 May 2014 15:06:23 -0700 |
parents | 458df24e973d |
children | e6c8652473fe |
comparison
equal
deleted
inserted
replaced
119:458df24e973d | 120:d6b7c3fb37ea |
---|---|
406 uid_t | 406 uid_t |
407 md_getuid(void) | 407 md_getuid(void) |
408 { | 408 { |
409 #ifdef HAVE_GETUID | 409 #ifdef HAVE_GETUID |
410 return( getuid() ); | 410 return( getuid() ); |
411 #else | |
412 return(42); | |
413 #endif | |
414 } | |
415 | |
416 gid_t | |
417 md_getgid(void) | |
418 { | |
419 #ifdef HAVE_GETGID | |
420 return( getgid() ); | |
411 #else | 421 #else |
412 return(42); | 422 return(42); |
413 #endif | 423 #endif |
414 } | 424 } |
415 | 425 |
1507 #endif | 1517 #endif |
1508 } | 1518 } |
1509 | 1519 |
1510 #endif | 1520 #endif |
1511 | 1521 |
1522 long | |
1523 md_memused(void) | |
1524 { | |
1525 #ifdef _WIN32 | |
1526 MEMORYSTATUS stat; | |
1527 | |
1528 GlobalMemoryStatus(&stat); | |
1529 | |
1530 return((long)stat.dwTotalPageFile); | |
1531 #else | |
1532 return( (long)sbrk(0) ); | |
1533 #endif | |
1534 } | |
1535 | |
1536 void | |
1537 md_droppriv(void) | |
1538 { | |
1539 #if defined(HAVE_GETUID) | |
1540 uid_t realuid = getuid(); | |
1541 | |
1542 #if defined(HAVE_SETRESUID) | |
1543 if (setresuid(-1, realuid, realuid) != 0) { | |
1544 #elif defined (HAVE_SETREUID) | |
1545 if (setreuid(realuid, realuid) != 0) { | |
1546 #elif defined (HAVE_SETUID) | |
1547 if (setuid(realuid) != 0) { | |
1548 #else | |
1549 if (0) { | |
1550 #endif | |
1551 printf("Cannot change to effective uid: %d\n", realuid); | |
1552 exit(1); | |
1553 } | |
1554 #endif | |
1555 } | |
1556 | |
1557 extern uid_t playuid; | |
1558 extern gid_t playgid; | |
1559 | |
1560 void | |
1561 md_resetpriv(void) | |
1562 { | |
1563 #if defined (HAVE_SETUID) | |
1564 setuid(playuid); | |
1565 #endif | |
1566 #if defined (HAVE_SETGID) | |
1567 setgid(playgid); | |
1568 #endif | |
1569 } |