X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fmisc.c;h=7d0a7fde159d3fff69de8e447ac15f32c124f4a4;hp=c037e95941d416eaa5ea8a50d60d59bc5afd1686;hb=21c25c56356db2138816a0716d73934ac3893e89;hpb=f9a30d8f0565691424cc9fd2643a50a176dae903 diff --git a/src/misc.c b/src/misc.c index c037e959..7d0a7fde 100644 --- a/src/misc.c +++ b/src/misc.c @@ -155,39 +155,59 @@ unsigned int SimpleRND(unsigned int max) gettimeofday(¤t_time,NULL); root = root * 4253261 + current_time.tv_sec + current_time.tv_usec; - return(root % max); + return (root % max); } unsigned int RND(unsigned int max) { - return(random_linux_libc() % max); + return (random_linux_libc() % max); } unsigned int InitRND(long seed) { struct timeval current_time; - if (seed==NEW_RANDOMIZE) + if (seed == NEW_RANDOMIZE) { gettimeofday(¤t_time,NULL); srandom_linux_libc((unsigned int) current_time.tv_usec); - return((unsigned int) current_time.tv_usec); + return (unsigned int)current_time.tv_usec; } else { srandom_linux_libc((unsigned int) seed); - return((unsigned int) seed); + return (unsigned int)seed; } } -char *GetLoginName() +char *getLoginName() { struct passwd *pwd; - if (!(pwd=getpwuid(getuid()))) - return("ANONYMOUS"); + if (!(pwd = getpwuid(getuid()))) + return "ANONYMOUS"; else - return(pwd->pw_name); + return pwd->pw_name; +} + +char *getHomeDir() +{ + static char *home_dir = NULL; + + if (!home_dir) + { + if (!(home_dir = getenv("HOME"))) + { + struct passwd *pwd; + + if ((pwd = getpwuid(getuid()))) + home_dir = pwd->pw_dir; + else + home_dir = "."; + } + } + + return home_dir; } void MarkTileDirty(int x, int y)