From 950e5182708845213196dac7baab16420a2423d1 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 29 Aug 2001 02:41:47 +0000 Subject: [PATCH] __PHYSFS_platformGetUserDir() checks some win32 standard environment variables, now. Added some headers so that most of this compiles with Cygwin, too. --- platform/win32.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/platform/win32.c b/platform/win32.c index 9da2e17..0d7f0e1 100644 --- a/platform/win32.c +++ b/platform/win32.c @@ -12,7 +12,8 @@ #include #include - +#include +#include #define __PHYSICSFS_INTERNAL__ #include "physfs_internal.h" @@ -106,9 +107,48 @@ char *__PHYSFS_platformGetUserName(void) } /* __PHYSFS_platformGetUserName */ +static char *copyEnvironmentVariable(const char *varname) +{ + const char *envr = getenv(varname); + char *retval = NULL; + + if (envr != NULL) + { + retval = malloc(strlen(envr) + 1); + if (retval != NULL) + strcpy(retval, envr); + } /* if */ + + return(retval); +} /* copyEnvironmentVariable */ + + char *__PHYSFS_platformGetUserDir(void) { - return(NULL); /* no user dir on win32. */ + char *home = copyEnvironmentVariable("HOME"); + const char *homedrive = getenv("HOMEDRIVE"); + const char *homepath = getenv("HOMEPATH"); + + if (home != NULL) + return(home); + + if ((homedrive != NULL) && (homepath != NULL)) + { + char *retval = (char *) malloc(strlen(homedrive)+strlen(homepath)+2); + if (retval != NULL) + { + strcpy(retval, homedrive); + if ((homepath[0] != '\\') && + (homedrive[strlen(homedrive)-1] != '\\')) + { + strcat(retval, "\\"); + } /* if */ + strcat(retval, homepath); + return(retval); + } /* if */ + } /* if */ + + return(NULL); /* fall through to default rules. */ } /* __PHYSFS_platformGetUserDir */