Mercurial > pidgin
comparison libpurple/protocols/gg/gg-utils.c @ 15373:5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 20 Jan 2007 02:32:10 +0000 |
parents | |
children | 32c366eeeb99 |
comparison
equal
deleted
inserted
replaced
15372:f79e0f4df793 | 15373:5fe8042783c1 |
---|---|
1 /** | |
2 * @file gg-utils.c | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
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 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 | |
23 | |
24 #include "gg-utils.h" | |
25 | |
26 | |
27 /* uin_t ggp_str_to_uin(const char *str) {{{ */ | |
28 uin_t ggp_str_to_uin(const char *str) | |
29 { | |
30 char *tmp; | |
31 long num; | |
32 | |
33 if (!str) | |
34 return 0; | |
35 | |
36 errno = 0; | |
37 num = strtol(str, &tmp, 10); | |
38 | |
39 if (*str == '\0' || *tmp != '\0') | |
40 return 0; | |
41 | |
42 if ((errno == ERANGE || (num == LONG_MAX || num == LONG_MIN)) | |
43 #if (LONG_MAX > UINT_MAX) | |
44 || num > (long)UINT_MAX | |
45 #endif | |
46 || num < 0) | |
47 return 0; | |
48 | |
49 return (uin_t) num; | |
50 } | |
51 /* }}} */ | |
52 | |
53 /* unsigned int ggp_array_size(char **array) {{{ */ | |
54 unsigned int ggp_array_size(char **array) | |
55 { | |
56 unsigned int i; | |
57 | |
58 for (i = 0; array[i] != NULL && i < UINT_MAX; i++) | |
59 {} | |
60 | |
61 return i; | |
62 } | |
63 /* }}} */ | |
64 | |
65 /* char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) {{{ */ | |
66 char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) | |
67 { | |
68 gchar *msg; | |
69 GError *err = NULL; | |
70 | |
71 if (locstr == NULL) | |
72 return NULL; | |
73 | |
74 msg = g_convert_with_fallback(locstr, strlen(locstr), encdst, encsrc, | |
75 "?", NULL, NULL, &err); | |
76 if (err != NULL) { | |
77 gaim_debug_error("gg", "Error converting from %s to %s: %s\n", | |
78 encsrc, encdst, err->message); | |
79 g_error_free(err); | |
80 } | |
81 | |
82 /* Just in case? */ | |
83 if (msg == NULL) | |
84 msg = g_strdup(locstr); | |
85 | |
86 return msg; | |
87 } | |
88 /* }}} */ | |
89 | |
90 /* ggp_get_uin(GaimAccount *account) {{{ */ | |
91 uin_t ggp_get_uin(GaimAccount *account) | |
92 { | |
93 return ggp_str_to_uin(gaim_account_get_username(account)); | |
94 } | |
95 /* }}} */ | |
96 | |
97 /* char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) {{{ */ | |
98 char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) | |
99 { | |
100 GaimBuddy *buddy; | |
101 gchar *str_uin; | |
102 | |
103 str_uin = g_strdup_printf("%lu", (unsigned long int)uin); | |
104 | |
105 buddy = gaim_find_buddy(gaim_connection_get_account(gc), str_uin); | |
106 if (buddy != NULL) { | |
107 g_free(str_uin); | |
108 return g_strdup(gaim_buddy_get_alias(buddy)); | |
109 } else { | |
110 return str_uin; | |
111 } | |
112 } | |
113 /* }}} */ | |
114 | |
115 | |
116 /* vim: set ts=8 sts=0 sw=8 noet: */ |