Thu, 09 Feb 2006 04:17:56 +0000
[gaim-migrate @ 15563]
This is the soon-to-be-infamous nonblocking network activity patch that I've been working on. Feel free to yell at me if this makes you unhappy.
| 3712 | 1 | /* |
|
5913
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
2 | * gaim |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
3 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
4 | * File: libc_interface.c |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
5 | * Date: October 14, 2002 |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
6 | * Description: libc interface for Windows api |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
7 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
8 | * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com> |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
9 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
10 | * This program is free software; you can redistribute it and/or modify |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
11 | * it under the terms of the GNU General Public License as published by |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
12 | * the Free Software Foundation; either version 2 of the License, or |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
13 | * (at your option) any later version. |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
14 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
15 | * This program is distributed in the hope that it will be useful, |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
18 | * GNU General Public License for more details. |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
19 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
20 | * You should have received a copy of the GNU General Public License |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
21 | * along with this program; if not, write to the Free Software |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
23 | * |
| 3712 | 24 | */ |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
25 | #include <winsock2.h> |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
26 | #include <ws2tcpip.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
27 | #include <io.h> |
| 3712 | 28 | #include <stdlib.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
29 | #include <stdio.h> |
| 3712 | 30 | #include <errno.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
31 | #include <sys/timeb.h> |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
32 | #include <sys/stat.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
33 | #include <time.h> |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9611
diff
changeset
|
34 | #include <glib.h> |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
35 | #include "debug.h" |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
36 | #include "libc_internal.h" |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
37 | #if GLIB_CHECK_VERSION(2,6,0) |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
38 | # include <glib/gstdio.h> |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
39 | #else |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
40 | #define g_remove remove |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
41 | #define g_rename rename |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
42 | #define g_stat stat |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9611
diff
changeset
|
43 | #endif |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
44 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
45 | * PROTOS |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
46 | */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
47 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
48 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
49 | * LOCALS |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
50 | */ |
| 3712 | 51 | |
| 52 | static char errbuf[1024]; | |
| 53 | ||
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
54 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
55 | * CODE |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
56 | */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
57 | |
| 3712 | 58 | /* helpers */ |
| 59 | static int wgaim_is_socket( int fd ) { | |
| 60 | int optval; | |
| 61 | unsigned int optlen = sizeof(int); | |
| 62 | ||
| 63 | if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) { | |
| 64 | int error = WSAGetLastError(); | |
| 65 | if( error == WSAENOTSOCK ) | |
| 66 | return FALSE; | |
| 67 | else { | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
68 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_is_socket: getsockopt returned error: %d\n", error); |
| 3712 | 69 | return FALSE; |
| 70 | } | |
| 71 | } | |
| 72 | return TRUE; | |
| 73 | } | |
| 74 | ||
| 75 | /* socket.h */ | |
| 76 | int wgaim_socket (int namespace, int style, int protocol) { | |
| 77 | int ret; | |
| 78 | ||
| 79 | ret = socket( namespace, style, protocol ); | |
| 80 | ||
| 81 | if( ret == INVALID_SOCKET ) { | |
| 82 | errno = WSAGetLastError(); | |
| 83 | return -1; | |
| 84 | } | |
| 85 | return ret; | |
| 86 | } | |
| 87 | ||
| 88 | int wgaim_connect(int socket, struct sockaddr *addr, u_long length) { | |
| 89 | int ret; | |
| 90 | ||
| 91 | ret = connect( socket, addr, length ); | |
| 92 | ||
| 93 | if( ret == SOCKET_ERROR ) { | |
| 94 | errno = WSAGetLastError(); | |
| 95 | if( errno == WSAEWOULDBLOCK ) | |
| 96 | errno = WSAEINPROGRESS; | |
| 97 | return -1; | |
| 98 | } | |
| 99 | return 0; | |
| 100 | } | |
| 101 | ||
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
102 | int wgaim_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlenptr) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
103 | if(getsockopt(socket, level, optname, optval, optlenptr) == SOCKET_ERROR ) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
104 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
105 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
106 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
107 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
108 | } |
| 3712 | 109 | |
| 9611 | 110 | int wgaim_setsockopt(int socket, int level, int optname, const void *optval, socklen_t optlen) { |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
111 | if(setsockopt(socket, level, optname, optval, optlen) == SOCKET_ERROR ) { |
| 3712 | 112 | errno = WSAGetLastError(); |
| 113 | return -1; | |
| 114 | } | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
115 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
116 | } |
| 3712 | 117 | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
118 | int wgaim_getsockname(int socket, struct sockaddr *addr, socklen_t *lenptr) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
119 | if(getsockname(socket, addr, lenptr) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
120 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
121 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
122 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
123 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
124 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
125 | |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
126 | int wgaim_bind(int socket, struct sockaddr *addr, socklen_t length) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
127 | if(bind(socket, addr, length) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
128 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
129 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
130 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
131 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
132 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
133 | |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
134 | int wgaim_listen(int socket, unsigned int n) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
135 | if(listen(socket, n) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
136 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
137 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
138 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
139 | return 0; |
| 3712 | 140 | } |
| 141 | ||
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
142 | int wgaim_sendto(int socket, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) { |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
143 | int ret; |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
144 | if ((ret = sendto(socket, buf, len, flags, to, tolen) |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
145 | ) == SOCKET_ERROR) { |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
146 | errno = WSAGetLastError(); |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
147 | return -1; |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
148 | } |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
149 | return ret; |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
150 | } |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
151 | |
| 3712 | 152 | /* fcntl.h */ |
| 153 | /* This is not a full implementation of fcntl. Update as needed.. */ | |
| 154 | int wgaim_fcntl(int socket, int command, int val) { | |
| 155 | switch( command ) { | |
| 156 | case F_SETFL: | |
| 157 | { | |
| 158 | int ret=0; | |
| 159 | ||
| 160 | switch( val ) { | |
| 161 | case O_NONBLOCK: | |
| 162 | { | |
| 163 | u_long imode=1; | |
| 164 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 165 | break; | |
| 166 | } | |
| 167 | case 0: | |
| 168 | { | |
| 169 | u_long imode=0; | |
| 170 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 171 | break; | |
| 172 | } | |
| 173 | default: | |
| 174 | errno = EINVAL; | |
| 175 | return -1; | |
| 176 | }/*end switch*/ | |
| 177 | if( ret == SOCKET_ERROR ) { | |
| 178 | errno = WSAGetLastError(); | |
| 179 | return -1; | |
| 180 | } | |
| 181 | return 0; | |
| 182 | } | |
| 183 | default: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
184 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_fcntl: Unsupported command\n"); |
| 3712 | 185 | return -1; |
| 186 | }/*end switch*/ | |
| 187 | } | |
| 188 | ||
| 189 | /* sys/ioctl.h */ | |
| 190 | int wgaim_ioctl(int fd, int command, void* val) { | |
| 191 | switch( command ) { | |
| 192 | case FIONBIO: | |
| 193 | { | |
| 194 | if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) { | |
| 195 | errno = WSAGetLastError(); | |
| 196 | return -1; | |
| 197 | } | |
| 198 | return 0; | |
| 199 | } | |
|
11364
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
200 | case SIOCGIFCONF: |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
201 | { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
202 | INTERFACE_INFO InterfaceList[20]; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
203 | unsigned long nBytesReturned; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
204 | if (WSAIoctl(fd, SIO_GET_INTERFACE_LIST, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
205 | 0, 0, &InterfaceList, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
206 | sizeof(InterfaceList), &nBytesReturned, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
207 | 0, 0) == SOCKET_ERROR) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
208 | errno = WSAGetLastError(); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
209 | return -1; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
210 | } else { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
211 | int i; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
212 | struct ifconf *ifc = val; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
213 | char *tmp = ifc->ifc_buf; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
214 | int nNumInterfaces = |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
215 | nBytesReturned / sizeof(INTERFACE_INFO); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
216 | for (i = 0; i < nNumInterfaces; i++) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
217 | INTERFACE_INFO ii = InterfaceList[i]; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
218 | struct ifreq *ifr = (struct ifreq *) tmp; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
219 | struct sockaddr_in *sa = (struct sockaddr_in *) &ifr->ifr_addr; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
220 | |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
221 | sa->sin_family = ii.iiAddress.AddressIn.sin_family; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
222 | sa->sin_port = ii.iiAddress.AddressIn.sin_port; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
223 | sa->sin_addr.s_addr = ii.iiAddress.AddressIn.sin_addr.s_addr; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
224 | tmp += sizeof(struct ifreq); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
225 | |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
226 | /* Make sure that we can fit in the original buffer */ |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
227 | if (tmp >= (ifc->ifc_buf + ifc->ifc_len + sizeof(struct ifreq))) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
228 | break; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
229 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
230 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
231 | /* Replace the length with the actually used length */ |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
232 | ifc->ifc_len = ifc->ifc_len - (ifc->ifc_buf - tmp); |
|
12488
72878a4bf35a
[gaim-migrate @ 14800]
Daniel Atallah <datallah@pidgin.im>
parents:
11543
diff
changeset
|
233 | return 0; |
|
11364
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
234 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
235 | } |
| 3712 | 236 | default: |
| 237 | errno = EINVAL; | |
| 238 | return -1; | |
| 239 | }/*end switch*/ | |
| 240 | } | |
| 241 | ||
| 242 | /* arpa/inet.h */ | |
| 243 | int wgaim_inet_aton(const char *name, struct in_addr *addr) { | |
| 244 | if((addr->s_addr = inet_addr(name)) == INADDR_NONE) | |
| 245 | return 0; | |
| 246 | else | |
| 247 | return 1; | |
| 248 | } | |
| 249 | ||
| 250 | /* netdb.h */ | |
| 251 | struct hostent* wgaim_gethostbyname(const char *name) { | |
| 252 | struct hostent *hp; | |
| 253 | ||
| 254 | if((hp = gethostbyname(name)) == NULL) { | |
| 255 | errno = WSAGetLastError(); | |
| 256 | return NULL; | |
| 257 | } | |
| 258 | return hp; | |
| 259 | } | |
| 260 | ||
| 261 | /* string.h */ | |
| 262 | char* wgaim_strerror( int errornum ) { | |
| 263 | if( errornum > WSABASEERR ) { | |
| 264 | sprintf( errbuf, "Windows socket error #%d", errornum ); | |
| 265 | return errbuf; | |
| 266 | } | |
| 267 | else | |
| 268 | return strerror( errornum ); | |
| 269 | } | |
| 270 | ||
| 271 | /* unistd.h */ | |
| 272 | ||
| 273 | /* | |
| 274 | * We need to figure out whether fd is a file or socket handle. | |
| 275 | */ | |
| 276 | int wgaim_read(int fd, void *buf, unsigned int size) { | |
| 277 | int ret; | |
| 278 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
279 | if(wgaim_is_socket(fd)) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
280 | if((ret = recv(fd, buf, size, 0)) == SOCKET_ERROR) { |
| 3712 | 281 | errno = WSAGetLastError(); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
282 | if(errno == WSAEWOULDBLOCK) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
283 | errno = EAGAIN; |
| 3712 | 284 | return -1; |
| 285 | } | |
|
11543
e7218de0b500
[gaim-migrate @ 13798]
Daniel Atallah <datallah@pidgin.im>
parents:
11431
diff
changeset
|
286 | #if 0 |
| 3712 | 287 | else if( ret == 0 ) { |
| 288 | /* connection has been gracefully closed */ | |
| 289 | errno = WSAENOTCONN; | |
| 290 | return -1; | |
| 291 | } | |
|
11543
e7218de0b500
[gaim-migrate @ 13798]
Daniel Atallah <datallah@pidgin.im>
parents:
11431
diff
changeset
|
292 | #endif |
| 3712 | 293 | else { |
| 294 | /* success reading socket */ | |
| 295 | return ret; | |
| 296 | } | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
297 | } else { |
| 3712 | 298 | /* fd is not a socket handle.. pass it off to read */ |
| 299 | return read(fd, buf, size); | |
| 300 | } | |
| 301 | } | |
| 302 | ||
| 303 | int wgaim_write(int fd, const void *buf, unsigned int size) { | |
| 304 | int ret; | |
| 305 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
306 | if(wgaim_is_socket(fd)) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
307 | if((ret = send(fd, buf, size, 0)) == SOCKET_ERROR) { |
| 3712 | 308 | errno = WSAGetLastError(); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
309 | if(errno == WSAEWOULDBLOCK) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
310 | errno = EAGAIN; |
| 3712 | 311 | return -1; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
312 | } else { |
| 3712 | 313 | /* success */ |
| 314 | return ret; | |
| 315 | } | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
316 | } else |
| 3712 | 317 | return write(fd, buf, size); |
| 318 | } | |
| 319 | ||
|
12749
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
320 | int wgaim_recv(int fd, void *buf, size_t len, int flags) { |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
321 | int ret; |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
322 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
323 | if((ret = recv(fd, buf, len, flags)) == SOCKET_ERROR) { |
|
12749
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
324 | errno = WSAGetLastError(); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
325 | if(errno == WSAEWOULDBLOCK) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
326 | errno = EAGAIN; |
|
12749
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
327 | return -1; |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
328 | } else { |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
329 | return ret; |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
330 | } |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
331 | } |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
332 | |
| 3712 | 333 | int wgaim_close(int fd) { |
| 334 | int ret; | |
| 335 | ||
| 336 | if( wgaim_is_socket(fd) ) { | |
| 337 | if( (ret = closesocket(fd)) == SOCKET_ERROR ) { | |
| 338 | errno = WSAGetLastError(); | |
| 339 | return -1; | |
| 340 | } | |
| 341 | else | |
| 342 | return 0; | |
| 343 | } | |
| 344 | else | |
| 345 | return close(fd); | |
| 346 | } | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
347 | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
348 | int wgaim_gethostname(char *name, size_t size) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
349 | if(gethostname(name, size) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
350 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
351 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
352 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
353 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
354 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
355 | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
356 | /* sys/time.h */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
357 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
358 | int wgaim_gettimeofday(struct timeval *p, struct timezone *z) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
359 | int res = 0; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
360 | struct _timeb timebuffer; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
361 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
362 | if (z != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
363 | _tzset(); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
364 | z->tz_minuteswest = _timezone/60; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
365 | z->tz_dsttime = _daylight; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
366 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
367 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
368 | if (p != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
369 | _ftime(&timebuffer); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
370 | p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
371 | p->tv_usec = timebuffer.millitm*1000; /* microseconds */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
372 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
373 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
374 | return res; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
375 | } |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
376 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
377 | /* stdio.h */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
378 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
379 | int wgaim_rename (const char *oldname, const char *newname) { |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
380 | struct stat oldstat, newstat; |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
381 | |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
382 | if(g_stat(oldname, &oldstat) == 0) { |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
383 | /* newname exists */ |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
384 | if(g_stat(newname, &newstat) == 0) { |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
385 | /* oldname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
386 | if(_S_ISDIR(oldstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
387 | if(!_S_ISDIR(newstat.st_mode)) { |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
388 | return g_rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
389 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
390 | /* newname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
391 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
392 | /* This is not quite right.. If newname is empty and |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
393 | is not a sub dir of oldname, newname should be |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
394 | deleted and oldname should be renamed. |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
395 | */ |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
396 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_rename does not behave here as it should\n"); |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
397 | return g_rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
398 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
399 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
400 | /* oldname is not a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
401 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
402 | /* newname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
403 | if(_S_ISDIR(newstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
404 | errno = EISDIR; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
405 | return -1; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
406 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
407 | /* newname is not a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
408 | else { |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9611
diff
changeset
|
409 | g_remove(newname); |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
410 | return g_rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
411 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
412 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
413 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
414 | /* newname doesn't exist */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
415 | else |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
416 | return g_rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
417 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
418 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
419 | /* oldname doesn't exist */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
420 | errno = ENOENT; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
421 | return -1; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
422 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
423 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
424 | } |
|
5113
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
425 | |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
426 | /* time.h */ |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
427 | |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
428 | struct tm * wgaim_localtime_r (const time_t *time, struct tm *resultp) { |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
429 | struct tm* tmptm; |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
430 | |
|
5474
eec4dad3e035
[gaim-migrate @ 5868]
Herman Bloggs <herman@bluedigits.com>
parents:
5113
diff
changeset
|
431 | if(!time) |
|
5913
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
432 | return NULL; |
|
5113
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
433 | tmptm = localtime(time); |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
434 | if(resultp && tmptm) |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
435 | return memcpy(resultp, tmptm, sizeof(struct tm)); |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
436 | else |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
437 | return NULL; |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
438 | } |