Mercurial > pidgin.yaz
annotate src/win32/libc_interface.c @ 10708:d0d1d631ed49
[gaim-migrate @ 12297]
Add some files I missed that are necessary for Gtk 2.4 support, actually
commit the makefile changes to compile on Gtk 2.4, fix building with Gtk 2.6
which I broke. And some Gtk 2.2 support too, which should be considered
experimental (where experimental means "almost completely broken"). Also a
couple of tweaks which might make Gaim continue working after upgrading Gtk
without rebuilding Gaim, but I haven't actually tested that.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 20 Mar 2005 17:37:31 +0000 |
parents | e46b51de549a |
children | e1840eb860e7 |
rev | line source |
---|---|
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
1 /* |
5913
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
2 * gaim |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
3 * |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
4 * File: libc_interface.c |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
5 * Date: October 14, 2002 |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
6 * Description: libc interface for Windows api |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
7 * |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
8 * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com> |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
9 * |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
13 * (at your option) any later version. |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
14 * |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
18 * GNU General Public License for more details. |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
19 * |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
23 * |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
24 */ |
8244
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
25 #include <winsock2.h> |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
26 #include <ws2tcpip.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
27 #include <io.h> |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
28 #include <stdlib.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
29 #include <stdio.h> |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
30 #include <errno.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
31 #include <sys/timeb.h> |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
32 #include <sys/stat.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
33 #include <time.h> |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9611
diff
changeset
|
34 #include <glib.h> |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5913
diff
changeset
|
35 #include "debug.h" |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
36 #include "libc_internal.h" |
10601
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
37 #if GLIB_CHECK_VERSION(2,6,0) |
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
38 # include <glib/gstdio.h> |
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
39 #else |
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
40 #define g_remove remove |
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
41 #define g_rename rename |
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
42 #define g_stat stat |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9611
diff
changeset
|
43 #endif |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
44 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
45 * PROTOS |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
46 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
47 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
48 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
49 * LOCALS |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
50 */ |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
51 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
52 static char errbuf[1024]; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
53 |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
54 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
55 * CODE |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
56 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
57 |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
58 /* helpers */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
59 static int wgaim_is_socket( int fd ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
60 int optval; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
61 unsigned int optlen = sizeof(int); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
62 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
63 if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
64 int error = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
65 if( error == WSAENOTSOCK ) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
66 return FALSE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
67 else { |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5913
diff
changeset
|
68 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_is_socket: getsockopt returned error: %d\n", error); |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
69 return FALSE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
70 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
71 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
72 return TRUE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
73 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
74 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
75 /* socket.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
76 int wgaim_socket (int namespace, int style, int protocol) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
77 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
78 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
79 ret = socket( namespace, style, protocol ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
80 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
81 if( ret == INVALID_SOCKET ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
82 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
83 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
84 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
85 return ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
86 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
87 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
88 int wgaim_connect(int socket, struct sockaddr *addr, u_long length) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
89 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
90 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
91 ret = connect( socket, addr, length ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
92 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
93 if( ret == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
94 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
95 if( errno == WSAEWOULDBLOCK ) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
96 errno = WSAEINPROGRESS; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
97 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
98 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
99 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
100 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
101 |
8244
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
102 int wgaim_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlenptr) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
103 if(getsockopt(socket, level, optname, optval, optlenptr) == SOCKET_ERROR ) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
104 errno = WSAGetLastError(); |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
105 return -1; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
106 } |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
107 return 0; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
108 } |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
109 |
9611 | 110 int wgaim_setsockopt(int socket, int level, int optname, const void *optval, socklen_t optlen) { |
8244
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
111 if(setsockopt(socket, level, optname, optval, optlen) == SOCKET_ERROR ) { |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
112 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
113 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
114 } |
8244
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
115 return 0; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
116 } |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
117 |
8244
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
118 int wgaim_getsockname(int socket, struct sockaddr *addr, socklen_t *lenptr) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
119 if(getsockname(socket, addr, lenptr) == SOCKET_ERROR) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
120 errno = WSAGetLastError(); |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
121 return -1; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
122 } |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
123 return 0; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
124 } |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
125 |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
126 int wgaim_bind(int socket, struct sockaddr *addr, socklen_t length) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
127 if(bind(socket, addr, length) == SOCKET_ERROR) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
128 errno = WSAGetLastError(); |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
129 return -1; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
130 } |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
131 return 0; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
132 } |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
133 |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
134 int wgaim_listen(int socket, unsigned int n) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
135 if(listen(socket, n) == SOCKET_ERROR) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
136 errno = WSAGetLastError(); |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
137 return -1; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
138 } |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
139 return 0; |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
140 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
141 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
142 /* fcntl.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
143 /* This is not a full implementation of fcntl. Update as needed.. */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
144 int wgaim_fcntl(int socket, int command, int val) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
145 switch( command ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
146 case F_SETFL: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
147 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
148 int ret=0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
149 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
150 switch( val ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
151 case O_NONBLOCK: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
152 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
153 u_long imode=1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
154 ret = ioctlsocket(socket, FIONBIO, &imode); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
155 break; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
156 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
157 case 0: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
158 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
159 u_long imode=0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
160 ret = ioctlsocket(socket, FIONBIO, &imode); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
161 break; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
162 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
163 default: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
164 errno = EINVAL; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
165 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
166 }/*end switch*/ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
167 if( ret == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
168 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
169 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
170 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
171 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
172 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
173 default: |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5913
diff
changeset
|
174 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_fcntl: Unsupported command\n"); |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
175 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
176 }/*end switch*/ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
177 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
178 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
179 /* sys/ioctl.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
180 int wgaim_ioctl(int fd, int command, void* val) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
181 switch( command ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
182 case FIONBIO: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
183 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
184 if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
185 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
186 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
187 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
188 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
189 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
190 default: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
191 errno = EINVAL; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
192 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
193 }/*end switch*/ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
194 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
195 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
196 /* arpa/inet.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
197 int wgaim_inet_aton(const char *name, struct in_addr *addr) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
198 if((addr->s_addr = inet_addr(name)) == INADDR_NONE) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
199 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
200 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
201 return 1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
202 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
203 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
204 /* netdb.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
205 struct hostent* wgaim_gethostbyname(const char *name) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
206 struct hostent *hp; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
207 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
208 if((hp = gethostbyname(name)) == NULL) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
209 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
210 return NULL; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
211 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
212 return hp; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
213 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
214 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
215 /* string.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
216 char* wgaim_strerror( int errornum ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
217 if( errornum > WSABASEERR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
218 sprintf( errbuf, "Windows socket error #%d", errornum ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
219 return errbuf; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
220 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
221 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
222 return strerror( errornum ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
223 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
224 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
225 /* unistd.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
226 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
227 /* |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
228 * We need to figure out whether fd is a file or socket handle. |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
229 */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
230 int wgaim_read(int fd, void *buf, unsigned int size) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
231 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
232 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
233 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
234 if( (ret = recv(fd, buf, size, 0)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
235 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
236 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
237 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
238 else if( ret == 0 ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
239 /* connection has been gracefully closed */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
240 errno = WSAENOTCONN; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
241 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
242 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
243 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
244 /* success reading socket */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
245 return ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
246 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
247 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
248 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
249 /* fd is not a socket handle.. pass it off to read */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
250 return read(fd, buf, size); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
251 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
252 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
253 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
254 int wgaim_write(int fd, const void *buf, unsigned int size) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
255 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
256 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
257 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
258 if( (ret = send(fd, buf, size, 0)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
259 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
260 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
261 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
262 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
263 /* success */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
264 return ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
265 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
266 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
267 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
268 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
269 return write(fd, buf, size); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
270 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
271 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
272 int wgaim_close(int fd) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
273 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
274 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
275 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
276 if( (ret = closesocket(fd)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
277 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
278 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
279 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
280 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
281 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
282 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
283 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
284 return close(fd); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
285 } |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
286 |
8244
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
287 int wgaim_gethostname(char *name, size_t size) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
288 if(gethostname(name, size) == SOCKET_ERROR) { |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
289 errno = WSAGetLastError(); |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
290 return -1; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
291 } |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
292 return 0; |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
293 } |
5e7ffea3f76a
[gaim-migrate @ 8967]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
294 |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
295 /* sys/time.h */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
296 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
297 int wgaim_gettimeofday(struct timeval *p, struct timezone *z) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
298 int res = 0; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
299 struct _timeb timebuffer; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
300 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
301 if (z != 0) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
302 _tzset(); |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
303 z->tz_minuteswest = _timezone/60; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
304 z->tz_dsttime = _daylight; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
305 } |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
306 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
307 if (p != 0) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
308 _ftime(&timebuffer); |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
309 p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
310 p->tv_usec = timebuffer.millitm*1000; /* microseconds */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
311 } |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
312 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
313 return res; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
314 } |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
315 |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
316 /* stdio.h */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
317 |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
318 int wgaim_rename (const char *oldname, const char *newname) { |
10601
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
319 struct stat oldstat, newstat; |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
320 |
10601
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
321 if(g_stat(oldname, &oldstat) == 0) { |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
322 /* newname exists */ |
10601
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
323 if(g_stat(newname, &newstat) == 0) { |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
324 /* oldname is a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
325 if(_S_ISDIR(oldstat.st_mode)) { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
326 if(!_S_ISDIR(newstat.st_mode)) { |
10601
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
327 return g_rename(oldname, newname); |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
328 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
329 /* newname is a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
330 else { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
331 /* This is not quite right.. If newname is empty and |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
332 is not a sub dir of oldname, newname should be |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
333 deleted and oldname should be renamed. |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
334 */ |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5913
diff
changeset
|
335 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_rename does not behave here as it should\n"); |
10601
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
336 return g_rename(oldname, newname); |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
337 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
338 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
339 /* oldname is not a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
340 else { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
341 /* newname is a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
342 if(_S_ISDIR(newstat.st_mode)) { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
343 errno = EISDIR; |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
344 return -1; |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
345 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
346 /* newname is not a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
347 else { |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9611
diff
changeset
|
348 g_remove(newname); |
10601
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
349 return g_rename(oldname, newname); |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
350 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
351 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
352 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
353 /* newname doesn't exist */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
354 else |
10601
e46b51de549a
[gaim-migrate @ 12028]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
355 return g_rename(oldname, newname); |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
356 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
357 else { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
358 /* oldname doesn't exist */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
359 errno = ENOENT; |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
360 return -1; |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
361 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
362 |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
363 } |
5113
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
364 |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
365 /* time.h */ |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
366 |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
367 struct tm * wgaim_localtime_r (const time_t *time, struct tm *resultp) { |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
368 struct tm* tmptm; |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
369 |
5474
0b355ec51083
[gaim-migrate @ 5868]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5113
diff
changeset
|
370 if(!time) |
5913
9657e243d001
[gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5474
diff
changeset
|
371 return NULL; |
5113
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
372 tmptm = localtime(time); |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
373 if(resultp && tmptm) |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
374 return memcpy(resultp, tmptm, sizeof(struct tm)); |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
375 else |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
376 return NULL; |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
377 } |