5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2007 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
22 /* Returns the username of the user. If the global variable LOGNAME
23 does not exists we will get the name from the password file. */
25 char *silc_get_username()
29 logname = getenv("LOGNAME");
35 pw = getpwuid(getuid());
39 logname = pw->pw_name;
43 return strdup(logname);
46 /* Returns the real name of ther user. */
48 char *silc_get_real_name()
50 char *realname = NULL;
53 pw = getpwuid(getuid());
55 return strdup("No Name");
57 if (strchr(pw->pw_gecos, ','))
58 *strchr(pw->pw_gecos, ',') = 0;
60 if (!strlen(pw->pw_gecos))
61 return strdup("No Name");
63 realname = strdup(pw->pw_gecos);
68 /* Return current time to struct timeval. */
70 int silc_gettimeofday(struct timeval *p)
72 return gettimeofday(p, NULL);
75 int silc_file_set_nonblock(int fd)
77 return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);