Mercurial > pidgin.yaz
comparison libgaim/win32/libc_interface.c @ 14912:390519f29a11
[gaim-migrate @ 17684]
g_access() is GTK >= 2.8 - add a wrapper (for wingaim I included the code from glib to deal with filename encoding issues)
Add inet_ntop() implementation for wingaim.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Mon, 06 Nov 2006 20:29:24 +0000 |
parents | ab8a105eff62 |
children |
comparison
equal
deleted
inserted
replaced
14911:9f3be32d0913 | 14912:390519f29a11 |
---|---|
230 return 0; | 230 return 0; |
231 else | 231 else |
232 return 1; | 232 return 1; |
233 } | 233 } |
234 | 234 |
235 /* Thanks to GNU wget for this inet_ntop() implementation */ | |
236 const char * | |
237 wgaim_inet_ntop (int af, const void *src, char *dst, socklen_t cnt) | |
238 { | |
239 /* struct sockaddr can't accomodate struct sockaddr_in6. */ | |
240 union { | |
241 struct sockaddr_in6 sin6; | |
242 struct sockaddr_in sin; | |
243 } sa; | |
244 DWORD dstlen = cnt; | |
245 size_t srcsize; | |
246 | |
247 ZeroMemory(&sa, sizeof(sa)); | |
248 switch (af) | |
249 { | |
250 case AF_INET: | |
251 sa.sin.sin_family = AF_INET; | |
252 sa.sin.sin_addr = *(struct in_addr *) src; | |
253 srcsize = sizeof (sa.sin); | |
254 break; | |
255 case AF_INET6: | |
256 sa.sin6.sin6_family = AF_INET6; | |
257 sa.sin6.sin6_addr = *(struct in6_addr *) src; | |
258 srcsize = sizeof (sa.sin6); | |
259 break; | |
260 default: | |
261 abort (); | |
262 } | |
263 | |
264 if (WSAAddressToString ((struct sockaddr *) &sa, srcsize, NULL, dst, &dstlen) != 0) | |
265 { | |
266 errno = WSAGetLastError(); | |
267 return NULL; | |
268 } | |
269 return (const char *) dst; | |
270 } | |
271 | |
272 | |
235 /* netdb.h */ | 273 /* netdb.h */ |
236 struct hostent* wgaim_gethostbyname(const char *name) { | 274 struct hostent* wgaim_gethostbyname(const char *name) { |
237 struct hostent *hp; | 275 struct hostent *hp; |
238 | 276 |
239 if((hp = gethostbyname(name)) == NULL) { | 277 if((hp = gethostbyname(name)) == NULL) { |
986 | 1024 |
987 gaim_debug_warning("wgaim", "could not find a match for Windows timezone \"%s\"\n", tzname); | 1025 gaim_debug_warning("wgaim", "could not find a match for Windows timezone \"%s\"\n", tzname); |
988 return ""; | 1026 return ""; |
989 } | 1027 } |
990 | 1028 |
1029 #if !GLIB_CHECK_VERSION(2,8,0) | |
1030 /** | |
1031 * g_access: | |
1032 * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) | |
1033 * @mode: as in access() | |
1034 * | |
1035 * A wrapper for the POSIX access() function. This function is used to | |
1036 * test a pathname for one or several of read, write or execute | |
1037 * permissions, or just existence. On Windows, the underlying access() | |
1038 * function in the C library only checks the READONLY attribute, and | |
1039 * does not look at the ACL at all. Software that needs to handle file | |
1040 * permissions on Windows more exactly should use the Win32 API. | |
1041 * | |
1042 * See the C library manual for more details about access(). | |
1043 * | |
1044 * Returns: zero if the pathname refers to an existing file system | |
1045 * object that has all the tested permissions, or -1 otherwise or on | |
1046 * error. | |
1047 * | |
1048 * Since: 2.8 | |
1049 */ | |
1050 int | |
1051 wgaim_g_access (const gchar *filename, | |
1052 int mode) | |
1053 { | |
1054 if (G_WIN32_HAVE_WIDECHAR_API ()) | |
1055 { | |
1056 wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); | |
1057 int retval; | |
1058 int save_errno; | |
1059 | |
1060 if (wfilename == NULL) | |
1061 { | |
1062 errno = EINVAL; | |
1063 return -1; | |
1064 } | |
1065 | |
1066 retval = _waccess (wfilename, mode); | |
1067 save_errno = errno; | |
1068 | |
1069 g_free (wfilename); | |
1070 | |
1071 errno = save_errno; | |
1072 return retval; | |
1073 } | |
1074 else | |
1075 { | |
1076 gchar *cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL); | |
1077 int retval; | |
1078 int save_errno; | |
1079 | |
1080 if (cp_filename == NULL) | |
1081 { | |
1082 errno = EINVAL; | |
1083 return -1; | |
1084 } | |
1085 | |
1086 retval = access (cp_filename, mode); | |
1087 save_errno = errno; | |
1088 | |
1089 g_free (cp_filename); | |
1090 | |
1091 errno = save_errno; | |
1092 return retval; | |
1093 } | |
1094 } | |
1095 #endif | |
1096 | |
1097 |