Use LTTngUSTLogger logger plugin in logtest regression test
[deliverable/titan.core.git] / common / userinfo.c
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Delic, Adam
11 * Szabo, Janos Zoltan – initial implementation
12 *
13 ******************************************************************************/
14 #include <time.h>
15 #include <unistd.h>
16 #ifdef MINGW
17 # include <windows.h>
18 # include <lmcons.h>
19 #else
20 # include <pwd.h>
21 #endif
22
23 #include "memory.h"
24 #include "userinfo.h"
25
26 char *get_user_info(void)
27 {
28 char *ret_val;
29 time_t t;
30 const char *current_time;
31 #ifdef MINGW
32 TCHAR user_name[UNLEN + 1], computer_name[MAX_COMPUTERNAME_LENGTH + 1];
33 DWORD buffer_size = sizeof(user_name);
34 if (GetUserName(user_name, &buffer_size)) ret_val = mcopystr(user_name);
35 else ret_val = mcopystr("unknown");
36 ret_val = mputc(ret_val, '@');
37 buffer_size = sizeof(computer_name);
38 if (GetComputerName(computer_name, &buffer_size))
39 ret_val = mputstr(ret_val, computer_name);
40 else ret_val = mputstr(ret_val, "unknown");
41 #else
42 struct passwd *p;
43 char host_name[256];
44 setpwent();
45 p = getpwuid(getuid());
46 if (p != NULL) {
47 size_t i;
48 for (i = 0; p->pw_gecos[i] != '\0'; i++) {
49 if (p->pw_gecos[i] == ',') {
50 /* Truncating additional info (e.g. phone number) after the full name */
51 p->pw_gecos[i] = '\0';
52 break;
53 }
54 }
55 ret_val = mprintf("%s (%s", p->pw_gecos, p->pw_name);
56 } else ret_val = mcopystr("Unknown User (unknown");
57 endpwent();
58 if (gethostname(host_name, sizeof(host_name)))
59 ret_val = mputstr(ret_val, "@unknown)");
60 else {
61 host_name[sizeof(host_name) - 1] = '\0';
62 ret_val = mputprintf(ret_val, "@%s)", host_name);
63 }
64 #endif
65 t = time(NULL);
66 current_time = ctime(&t);
67 ret_val = mputprintf(ret_val, " on %s", current_time);
68 return ret_val;
69 }
This page took 0.032494 seconds and 5 git commands to generate.