GRASS 8 Programmer's Manual
8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
gis/whoami.c
Go to the documentation of this file.
1
/*!
2
* \file lib/gis/whoami.c
3
*
4
* \brief GIS Library - Login name functions.
5
*
6
* (C) 2001-2009 by the GRASS Development Team
7
*
8
* This program is free software under the GNU General Public License
9
* (>=v2). Read the file COPYING that comes with GRASS for details.
10
*
11
* \author Original author CERL
12
*/
13
#include <
unistd.h
>
14
#include <
stdlib.h
>
15
16
#ifndef _WIN32
17
#include <pwd.h>
18
#endif
19
20
#include <
grass/gis.h
>
21
22
/*!
23
* \brief Gets user's name.
24
*
25
* Returns a pointer to a string containing the user's login name.
26
*
27
* Tries getlogin() first, then goes to the password file.
28
* However, some masscomp getlogin() fails in ucb universe
29
* because the ttyname(0) rotuine fails in ucb universe.
30
* So we check for this, too.
31
*
32
* \return pointer to string ("anonymous" by default)
33
*/
34
const
char
*
G_whoami
(
void
)
35
{
36
static
int
initialized;
37
static
const
char
*
name
;
38
39
if
(
G_is_initialized
(&initialized))
40
return
name
;
41
42
#ifdef _WIN32
43
name
=
getenv
(
"USERNAME"
);
44
#endif
45
if
(!
name
|| !*
name
)
46
name
=
getenv
(
"LOGNAME"
);
47
48
if
(!
name
|| !*
name
)
49
name
=
getenv
(
"USER"
);
50
51
#ifndef _WIN32
52
if
(!
name
|| !*
name
) {
53
struct
passwd
*p =
getpwuid
(
getuid
());
54
55
if
(p && p->pw_name && *p->pw_name)
56
name
=
G_store
(p->pw_name);
57
}
58
#endif
59
60
if
(!
name
|| !*
name
)
61
name
=
"anonymous"
;
62
63
G_initialize_done
(&initialized);
64
65
return
name
;
66
}
AMI_STREAM
Definition
ami_stream.h:153
AMI_STREAM::AMI_STREAM
AMI_STREAM()
Definition
ami_stream.h:227
G_is_initialized
int G_is_initialized(int *)
Definition
counter.c:60
G_initialize_done
void G_initialize_done(int *)
Definition
counter.c:77
G_store
char * G_store(const char *)
Copy string to allocated memory.
Definition
strings.c:87
G_whoami
const char * G_whoami(void)
Gets user's name.
Definition
gis/whoami.c:34
gis.h
name
const char * name
Definition
named_colr.c:6
stdlib.h
unistd.h
lib
gis
whoami.c
Generated on Fri Apr 3 2026 06:59:54 for GRASS 8 Programmer's Manual by
1.9.8