123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /*
- ****************************************************************
- * char *
- * G_home ()
- *
- * returns char pointer to home directory for user
- * dies if can't determine
- *
- * char *
- * G__home()
- *
- * returns char pointer to home directory for user
- * NULL if can't determine
- *
- ***************************************************************/
- #include <stdlib.h>
- #include <string.h>
- #include <grass/gis.h>
- #include <grass/glocale.h>
- /*!
- * \brief user's home directory
- *
- * Returns a pointer to a string
- * which is the full path name of the user's home directory.
- *
- * \param ~
- * \return char *
- */
- const char *G_home(void)
- {
- const char *home = G__home();
- if (home)
- return home;
- G_fatal_error(_("unable to determine user's home directory"));
- return NULL;
- }
- const char *G__home(void)
- {
- static int initialized;
- static const char *home = 0;
- if (G_is_initialized(&initialized))
- return home;
- #ifdef __MINGW32__
- {
- char buf[GPATH_MAX];
- /* TODO: we should probably check if the dir exists */
- home = getenv("USERPROFILE");
- if (!home) {
- sprintf(buf, "%s%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
- if (strlen(buf) >= 0)
- home = G_store(buf);
- }
- if (!home)
- home = getenv("HOME");
- }
- #else
- home = getenv("HOME");
- #endif
- G_debug(2, "G__home home = %s", home);
- G_initialize_done(&initialized);
- return home;
- }
|