Mon, 19 Apr 2004 04:20:24 +0000
[gaim-migrate @ 9464]
Plugins can now add menu items to the buddy context menu (Christopher O'Brien).
| 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> |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
34 | #include "debug.h" |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
35 | #include "libc_internal.h" |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
36 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
37 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
38 | * PROTOS |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
39 | */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
40 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
41 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
42 | * LOCALS |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
43 | */ |
| 3712 | 44 | |
| 45 | static char errbuf[1024]; | |
| 46 | ||
|
3777
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 | * CODE |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
49 | */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
50 | |
| 3712 | 51 | /* helpers */ |
| 52 | static int wgaim_is_socket( int fd ) { | |
| 53 | int optval; | |
| 54 | unsigned int optlen = sizeof(int); | |
| 55 | ||
| 56 | if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) { | |
| 57 | int error = WSAGetLastError(); | |
| 58 | if( error == WSAENOTSOCK ) | |
| 59 | return FALSE; | |
| 60 | else { | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
61 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_is_socket: getsockopt returned error: %d\n", error); |
| 3712 | 62 | return FALSE; |
| 63 | } | |
| 64 | } | |
| 65 | return TRUE; | |
| 66 | } | |
| 67 | ||
| 68 | /* socket.h */ | |
| 69 | int wgaim_socket (int namespace, int style, int protocol) { | |
| 70 | int ret; | |
| 71 | ||
| 72 | ret = socket( namespace, style, protocol ); | |
| 73 | ||
| 74 | if( ret == INVALID_SOCKET ) { | |
| 75 | errno = WSAGetLastError(); | |
| 76 | return -1; | |
| 77 | } | |
| 78 | return ret; | |
| 79 | } | |
| 80 | ||
| 81 | int wgaim_connect(int socket, struct sockaddr *addr, u_long length) { | |
| 82 | int ret; | |
| 83 | ||
| 84 | ret = connect( socket, addr, length ); | |
| 85 | ||
| 86 | if( ret == SOCKET_ERROR ) { | |
| 87 | errno = WSAGetLastError(); | |
| 88 | if( errno == WSAEWOULDBLOCK ) | |
| 89 | errno = WSAEINPROGRESS; | |
| 90 | return -1; | |
| 91 | } | |
| 92 | return 0; | |
| 93 | } | |
| 94 | ||
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
95 | 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
|
96 | if(getsockopt(socket, level, optname, optval, optlenptr) == SOCKET_ERROR ) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
97 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
98 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
99 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
100 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
101 | } |
| 3712 | 102 | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
103 | int wgaim_setsockopt(int socket, int level, int optname, void *optval, socklen_t optlen) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
104 | if(setsockopt(socket, level, optname, optval, optlen) == SOCKET_ERROR ) { |
| 3712 | 105 | errno = WSAGetLastError(); |
| 106 | return -1; | |
| 107 | } | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
108 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
109 | } |
| 3712 | 110 | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
111 | int wgaim_getsockname(int socket, struct sockaddr *addr, socklen_t *lenptr) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
112 | if(getsockname(socket, addr, lenptr) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
113 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
114 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
115 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
116 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
117 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
118 | |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
119 | int wgaim_bind(int socket, struct sockaddr *addr, socklen_t length) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
120 | if(bind(socket, addr, length) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
121 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
122 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
123 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
124 | return 0; |
|
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 | |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
127 | int wgaim_listen(int socket, unsigned int n) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
128 | if(listen(socket, n) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
129 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
130 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
131 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
132 | return 0; |
| 3712 | 133 | } |
| 134 | ||
| 135 | /* fcntl.h */ | |
| 136 | /* This is not a full implementation of fcntl. Update as needed.. */ | |
| 137 | int wgaim_fcntl(int socket, int command, int val) { | |
| 138 | switch( command ) { | |
| 139 | case F_SETFL: | |
| 140 | { | |
| 141 | int ret=0; | |
| 142 | ||
| 143 | switch( val ) { | |
| 144 | case O_NONBLOCK: | |
| 145 | { | |
| 146 | u_long imode=1; | |
| 147 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 148 | break; | |
| 149 | } | |
| 150 | case 0: | |
| 151 | { | |
| 152 | u_long imode=0; | |
| 153 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 154 | break; | |
| 155 | } | |
| 156 | default: | |
| 157 | errno = EINVAL; | |
| 158 | return -1; | |
| 159 | }/*end switch*/ | |
| 160 | if( ret == SOCKET_ERROR ) { | |
| 161 | errno = WSAGetLastError(); | |
| 162 | return -1; | |
| 163 | } | |
| 164 | return 0; | |
| 165 | } | |
| 166 | default: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
167 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_fcntl: Unsupported command\n"); |
| 3712 | 168 | return -1; |
| 169 | }/*end switch*/ | |
| 170 | } | |
| 171 | ||
| 172 | /* sys/ioctl.h */ | |
| 173 | int wgaim_ioctl(int fd, int command, void* val) { | |
| 174 | switch( command ) { | |
| 175 | case FIONBIO: | |
| 176 | { | |
| 177 | if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) { | |
| 178 | errno = WSAGetLastError(); | |
| 179 | return -1; | |
| 180 | } | |
| 181 | return 0; | |
| 182 | } | |
| 183 | default: | |
| 184 | errno = EINVAL; | |
| 185 | return -1; | |
| 186 | }/*end switch*/ | |
| 187 | } | |
| 188 | ||
| 189 | /* arpa/inet.h */ | |
| 190 | int wgaim_inet_aton(const char *name, struct in_addr *addr) { | |
| 191 | if((addr->s_addr = inet_addr(name)) == INADDR_NONE) | |
| 192 | return 0; | |
| 193 | else | |
| 194 | return 1; | |
| 195 | } | |
| 196 | ||
| 197 | /* netdb.h */ | |
| 198 | struct hostent* wgaim_gethostbyname(const char *name) { | |
| 199 | struct hostent *hp; | |
| 200 | ||
| 201 | if((hp = gethostbyname(name)) == NULL) { | |
| 202 | errno = WSAGetLastError(); | |
| 203 | return NULL; | |
| 204 | } | |
| 205 | return hp; | |
| 206 | } | |
| 207 | ||
| 208 | /* string.h */ | |
| 209 | char* wgaim_strerror( int errornum ) { | |
| 210 | if( errornum > WSABASEERR ) { | |
| 211 | sprintf( errbuf, "Windows socket error #%d", errornum ); | |
| 212 | return errbuf; | |
| 213 | } | |
| 214 | else | |
| 215 | return strerror( errornum ); | |
| 216 | } | |
| 217 | ||
|
4193
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
218 | /* From glibc 2.2.5 */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
219 | char* wgaim_strsep(char **stringp, const char *delim) { |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
220 | char *begin, *end; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
221 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
222 | begin = *stringp; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
223 | if (begin == NULL) |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
224 | return NULL; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
225 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
226 | /* A frequent case is when the delimiter string contains only one |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
227 | character. Here we don't need to call the expensive `strpbrk' |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
228 | function and instead work using `strchr'. */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
229 | if (delim[0] == '\0' || delim[1] == '\0') { |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
230 | char ch = delim[0]; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
231 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
232 | if (ch == '\0') |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
233 | end = NULL; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
234 | else { |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
235 | if (*begin == ch) |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
236 | end = begin; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
237 | else if (*begin == '\0') |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
238 | end = NULL; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
239 | else |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
240 | end = strchr (begin + 1, ch); |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
241 | } |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
242 | } |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
243 | else |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
244 | /* Find the end of the token. */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
245 | end = strpbrk (begin, delim); |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
246 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
247 | if (end) { |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
248 | /* Terminate the token and set *STRINGP past NUL character. */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
249 | *end++ = '\0'; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
250 | *stringp = end; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
251 | } |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
252 | else |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
253 | /* No more delimiters; this is the last token. */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
254 | *stringp = NULL; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
255 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
256 | return begin; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
257 | } |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
258 | |
| 3712 | 259 | /* unistd.h */ |
| 260 | ||
| 261 | /* | |
| 262 | * We need to figure out whether fd is a file or socket handle. | |
| 263 | */ | |
| 264 | int wgaim_read(int fd, void *buf, unsigned int size) { | |
| 265 | int ret; | |
| 266 | ||
| 267 | if( wgaim_is_socket(fd) ) { | |
| 268 | if( (ret = recv(fd, buf, size, 0)) == SOCKET_ERROR ) { | |
| 269 | errno = WSAGetLastError(); | |
| 270 | return -1; | |
| 271 | } | |
| 272 | else if( ret == 0 ) { | |
| 273 | /* connection has been gracefully closed */ | |
| 274 | errno = WSAENOTCONN; | |
| 275 | return -1; | |
| 276 | } | |
| 277 | else { | |
| 278 | /* success reading socket */ | |
| 279 | return ret; | |
| 280 | } | |
| 281 | } | |
| 282 | else { | |
| 283 | /* fd is not a socket handle.. pass it off to read */ | |
| 284 | return read(fd, buf, size); | |
| 285 | } | |
| 286 | } | |
| 287 | ||
| 288 | int wgaim_write(int fd, const void *buf, unsigned int size) { | |
| 289 | int ret; | |
| 290 | ||
| 291 | if( wgaim_is_socket(fd) ) { | |
| 292 | if( (ret = send(fd, buf, size, 0)) == SOCKET_ERROR ) { | |
| 293 | errno = WSAGetLastError(); | |
| 294 | return -1; | |
| 295 | } | |
| 296 | else { | |
| 297 | /* success */ | |
| 298 | return ret; | |
| 299 | } | |
| 300 | ||
| 301 | } | |
| 302 | else | |
| 303 | return write(fd, buf, size); | |
| 304 | } | |
| 305 | ||
| 306 | int wgaim_close(int fd) { | |
| 307 | int ret; | |
| 308 | ||
| 309 | if( wgaim_is_socket(fd) ) { | |
| 310 | if( (ret = closesocket(fd)) == SOCKET_ERROR ) { | |
| 311 | errno = WSAGetLastError(); | |
| 312 | return -1; | |
| 313 | } | |
| 314 | else | |
| 315 | return 0; | |
| 316 | } | |
| 317 | else | |
| 318 | return close(fd); | |
| 319 | } | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
320 | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
321 | int wgaim_gethostname(char *name, size_t size) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
322 | if(gethostname(name, size) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
323 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
324 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
325 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
326 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
327 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
328 | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
329 | /* sys/time.h */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
330 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
331 | int wgaim_gettimeofday(struct timeval *p, struct timezone *z) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
332 | int res = 0; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
333 | struct _timeb timebuffer; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
334 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
335 | if (z != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
336 | _tzset(); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
337 | z->tz_minuteswest = _timezone/60; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
338 | z->tz_dsttime = _daylight; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
339 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
340 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
341 | if (p != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
342 | _ftime(&timebuffer); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
343 | p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
344 | p->tv_usec = timebuffer.millitm*1000; /* microseconds */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
345 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
346 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
347 | return res; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
348 | } |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
349 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
350 | /* stdio.h */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
351 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
352 | int wgaim_rename (const char *oldname, const char *newname) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
353 | struct _stat oldstat, newstat; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
354 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
355 | if(_stat(oldname, &oldstat) == 0) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
356 | /* newname exists */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
357 | if(_stat(newname, &newstat) == 0) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
358 | /* oldname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
359 | if(_S_ISDIR(oldstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
360 | if(!_S_ISDIR(newstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
361 | return rename(oldname, newname); |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
362 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
363 | /* newname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
364 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
365 | /* This is not quite right.. If newname is empty and |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
366 | is not a sub dir of oldname, newname should be |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
367 | deleted and oldname should be renamed. |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
368 | */ |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
369 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_rename does not behave here as it should\n"); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
370 | return rename(oldname, newname); |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
371 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
372 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
373 | /* oldname is not a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
374 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
375 | /* newname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
376 | if(_S_ISDIR(newstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
377 | errno = EISDIR; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
378 | return -1; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
379 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
380 | /* newname is not a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
381 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
382 | remove(newname); |
|
5084
21d2e7ec99ce
[gaim-migrate @ 5439]
Herman Bloggs <herman@bluedigits.com>
parents:
4905
diff
changeset
|
383 | return rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
384 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
385 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
386 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
387 | /* newname doesn't exist */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
388 | else |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
389 | return rename(oldname, newname); |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
390 | } |
|
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 | /* oldname doesn't exist */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
393 | errno = ENOENT; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
394 | return -1; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
395 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
396 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
397 | } |
|
5113
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
398 | |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
399 | /* time.h */ |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
400 | |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
401 | 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
|
402 | struct tm* tmptm; |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
403 | |
|
5474
eec4dad3e035
[gaim-migrate @ 5868]
Herman Bloggs <herman@bluedigits.com>
parents:
5113
diff
changeset
|
404 | if(!time) |
|
5913
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
405 | return NULL; |
|
5113
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
406 | tmptm = localtime(time); |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
407 | if(resultp && tmptm) |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
408 | return memcpy(resultp, tmptm, sizeof(struct tm)); |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
409 | else |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
410 | return NULL; |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
411 | } |