Mercurial > pidgin.yaz
changeset 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 | 9f3be32d0913 |
children | a03e74b9b257 |
files | libgaim/internal.h libgaim/win32/libc_interface.c libgaim/win32/libc_interface.h |
diffstat | 3 files changed, 127 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/libgaim/internal.h Mon Nov 06 07:52:17 2006 +0000 +++ b/libgaim/internal.h Mon Nov 06 20:29:24 2006 +0000 @@ -129,10 +129,6 @@ # include <glib/gstdio.h> #endif -#ifdef _WIN32 -#include "win32dep.h" -#endif - #if !GLIB_CHECK_VERSION(2,6,0) # define g_freopen freopen # define g_fopen fopen @@ -146,12 +142,20 @@ # define g_open open #endif +#if !GLIB_CHECK_VERSION(2,8,0) +# define g_access access +#endif + #if !GLIB_CHECK_VERSION(2,10,0) # define g_slice_new(type) g_new(type, 1) # define g_slice_new0(type) g_new0(type, 1) # define g_slice_free(type, mem) g_free(mem) #endif +#ifdef _WIN32 +#include "win32dep.h" +#endif + /* ugly ugly ugly */ /* This is a workaround for the fact that G_GINT64_MODIFIER and G_GSIZE_FORMAT * are only defined in Glib >= 2.4 */
--- a/libgaim/win32/libc_interface.c Mon Nov 06 07:52:17 2006 +0000 +++ b/libgaim/win32/libc_interface.c Mon Nov 06 20:29:24 2006 +0000 @@ -232,6 +232,44 @@ return 1; } +/* Thanks to GNU wget for this inet_ntop() implementation */ +const char * +wgaim_inet_ntop (int af, const void *src, char *dst, socklen_t cnt) +{ + /* struct sockaddr can't accomodate struct sockaddr_in6. */ + union { + struct sockaddr_in6 sin6; + struct sockaddr_in sin; + } sa; + DWORD dstlen = cnt; + size_t srcsize; + + ZeroMemory(&sa, sizeof(sa)); + switch (af) + { + case AF_INET: + sa.sin.sin_family = AF_INET; + sa.sin.sin_addr = *(struct in_addr *) src; + srcsize = sizeof (sa.sin); + break; + case AF_INET6: + sa.sin6.sin6_family = AF_INET6; + sa.sin6.sin6_addr = *(struct in6_addr *) src; + srcsize = sizeof (sa.sin6); + break; + default: + abort (); + } + + if (WSAAddressToString ((struct sockaddr *) &sa, srcsize, NULL, dst, &dstlen) != 0) + { + errno = WSAGetLastError(); + return NULL; + } + return (const char *) dst; +} + + /* netdb.h */ struct hostent* wgaim_gethostbyname(const char *name) { struct hostent *hp; @@ -988,3 +1026,72 @@ return ""; } +#if !GLIB_CHECK_VERSION(2,8,0) +/** + * g_access: + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) + * @mode: as in access() + * + * A wrapper for the POSIX access() function. This function is used to + * test a pathname for one or several of read, write or execute + * permissions, or just existence. On Windows, the underlying access() + * function in the C library only checks the READONLY attribute, and + * does not look at the ACL at all. Software that needs to handle file + * permissions on Windows more exactly should use the Win32 API. + * + * See the C library manual for more details about access(). + * + * Returns: zero if the pathname refers to an existing file system + * object that has all the tested permissions, or -1 otherwise or on + * error. + * + * Since: 2.8 + */ +int +wgaim_g_access (const gchar *filename, + int mode) +{ + if (G_WIN32_HAVE_WIDECHAR_API ()) + { + wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); + int retval; + int save_errno; + + if (wfilename == NULL) + { + errno = EINVAL; + return -1; + } + + retval = _waccess (wfilename, mode); + save_errno = errno; + + g_free (wfilename); + + errno = save_errno; + return retval; + } + else + { + gchar *cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL); + int retval; + int save_errno; + + if (cp_filename == NULL) + { + errno = EINVAL; + return -1; + } + + retval = access (cp_filename, mode); + save_errno = errno; + + g_free (cp_filename); + + errno = save_errno; + return retval; + } +} +#endif + +
--- a/libgaim/win32/libc_interface.h Mon Nov 06 07:52:17 2006 +0000 +++ b/libgaim/win32/libc_interface.h Mon Nov 06 20:29:24 2006 +0000 @@ -72,15 +72,16 @@ #define fcntl( fd, command, val ) \ wgaim_fcntl( fd, command, val ) -#if !GLIB_CHECK_VERSION(2,6,0) -# define open( args... ) _open( args ) -#endif - /* arpa/inet.h */ int wgaim_inet_aton(const char *name, struct in_addr *addr); #define inet_aton( name, addr ) \ wgaim_inet_aton( name, addr ) +const char * +wgaim_inet_ntop (int af, const void *src, char *dst, socklen_t cnt); +#define inet_ntop( af, src, dst, cnt ) \ +wgaim_inet_ntop( af, src, dst, cnt ) + /* netdb.h */ struct hostent* wgaim_gethostbyname(const char *name); #define gethostbyname( name ) \ @@ -120,6 +121,13 @@ #define close( fd ) \ wgaim_close( fd ) +#if !GLIB_CHECK_VERSION(2,8,0) +int wgaim_g_access(const gchar *filename, int mode); +#undef g_access +#define g_access( filename, mode) \ +wgaim_g_access( filename, mode ) +#endif + #ifndef sleep #define sleep(x) Sleep((x)*1000) #endif @@ -153,9 +161,6 @@ /* sys/stat.h */ -#if !GLIB_CHECK_VERSION(2,6,0) -#define mkdir(a,b) _mkdir((a)) -#endif #define fchmod(a,b) /* time.h */