]> git.lyx.org Git - lyx.git/blob - src/support/userinfo.C
Add Windows-specific code to userinfo.C.
[lyx.git] / src / support / userinfo.C
1 /**
2  * \file userinfo.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/userinfo.h"
14 #include "support/environment.h"
15
16 #include <boost/assert.hpp>
17
18 #if defined (_WIN32)
19 # include "gettext.h"
20 # include <lmcons.h>
21 # include <windows.h>
22 #else
23 # include <pwd.h>
24 # include <unistd.h>
25 #endif
26 #include <sys/types.h>
27
28 using std::string;
29
30 namespace lyx {
31 namespace support {
32
33 string const user_name()
34 {
35 #if defined (_WIN32)
36
37         char name[UNLEN + 1];
38         DWORD size = UNLEN + 1;
39         if (!GetUserName(name, &size))
40                 return _("Unknown user");
41         return name;
42 #else
43         struct passwd * pw(getpwuid(geteuid()));
44         BOOST_ASSERT(pw);
45
46         string name = pw->pw_gecos;
47         if (name.empty())
48                 name = pw->pw_name;
49         return name;
50 #endif
51 }
52
53
54 string const user_email()
55 {
56         string email = getEnv("EMAIL_ADDRESS");
57         if (email.empty())
58                 email = getEnv("EMAIL");
59         return email;
60 }
61
62 } // namespace support
63 } // namespace lyx