GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
char * getenv()
char * G_home(void)
user&#39;s home directory
Definition: home.c:32
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
return NULL
Definition: dbfopen.c:1394
char * G__home(void)
Definition: home.c:43
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.