270b14ff5476b2c6e23d4f07fcc9ebf7ec27b98b
[silc.git] / lib / silcutil / symbian / silcsymbianutil.cpp
1 /*
2
3   silcsymbianutil.cpp
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2006 Pekka Riikonen
8
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.
12
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.
17
18 */
19
20 #include "silc.h"
21 #include <e32std.h>
22 #include <e32svr.h>
23
24 extern "C" {
25
26 /* Returns the username of the user. */
27
28 char *silc_get_username()
29 {
30   char *logname = NULL;
31
32   logname = getlogin();
33   if (!logname) {
34     struct passwd *pw;
35
36     pw = getpwuid(getuid());
37     if (!pw)
38       return strdup("User");
39
40     logname = pw->pw_name;
41   }
42
43   return strdup(logname);
44 }
45
46 /* Returns the real name of ther user. */
47
48 char *silc_get_real_name()
49 {
50   char *realname = NULL;
51   struct passwd *pw;
52
53   pw = getpwuid(getuid());
54   if (!pw)
55     return strdup("No Name");
56
57   if (strchr(pw->pw_gecos, ','))
58     *strchr(pw->pw_gecos, ',') = 0;
59
60   if (!strlen(pw->pw_gecos))
61     return strdup("No Name");
62
63   realname = strdup(pw->pw_gecos);
64
65   return realname;
66 }
67
68 /* Return current time to struct timeval. */
69
70 int silc_gettimeofday(struct timeval *p)
71 {
72   return gettimeofday(p, NULL);
73 }
74
75 int silc_file_set_nonblock(int fd)
76 {
77   return 0;
78 }
79
80 void silc_symbian_usleep(long microseconds)
81 {
82   User::After(microseconds / 1000);
83 }
84
85 void silc_symbian_debug(const char *function, int line, char *string)
86 {
87   RDebug::Print(_L("%s:%d: %s"), function, line, string);
88 }
89
90 } /* extern "C" */