GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
home.c
Go to the documentation of this file.
1 /*
2  ****************************************************************
3  * char *
4  * G_home ()
5  *
6  * returns char pointer to home directory for user
7  * dies if can't determine
8  *
9  * char *
10  * G__home()
11  *
12  * returns char pointer to home directory for user
13  * NULL if can't determine
14  *
15  ***************************************************************/
16 #include <stdlib.h>
17 #include <string.h>
18 #include <grass/gis.h>
19 #include <grass/glocale.h>
20 
21 
32 char *G_home(void)
33 {
34  char *home = G__home();
35 
36  if (home)
37  return home;
38 
39  G_fatal_error(_("unable to determine user's home directory"));
40  return NULL;
41 }
42 
43 char *G__home(void)
44 {
45  static char *home = 0;
46 
47  if (home)
48  return home;
49 
50 #ifdef __MINGW32__
51  {
52  char buf[GPATH_MAX];
53 
54  /* TODO: we should probably check if the dir exists */
55  home = getenv("USERPROFILE");
56 
57  if (!home) {
58  sprintf(buf, "%s%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
59 
60  if (strlen(buf) >= 0)
61  home = G_store(buf);
62  }
63 
64  if (!home)
65  home = getenv("HOME");
66  }
67 #else
68  home = getenv("HOME");
69 #endif
70  return home;
71 }