annotate src/win32/libc_interface.c @ 6928:6ed0a1c045b4

[gaim-migrate @ 7475] Added support for invisible plugins. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 24 Sep 2003 01:28:33 +0000
parents 26b739bc9f1a
children 5e7ffea3f76a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
25 #include <winsock.h>
3777
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
26 #include <io.h>
3712
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
27 #include <stdlib.h>
3777
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
28 #include <stdio.h>
3712
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
29 #include <errno.h>
3777
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
30 #include <sys/timeb.h>
4905
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
31 #include <sys/stat.h>
3777
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
32 #include <time.h>
6425
26b739bc9f1a [gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5913
diff changeset
33 #include "debug.h"
3777
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
34 #include "libc_internal.h"
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
35
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
36 /*
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
37 * PROTOS
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
38 */
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
39
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
40 /*
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
41 * LOCALS
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
42 */
3712
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
43
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
44 static char errbuf[1024];
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
45
3777
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 * CODE
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
3712
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
50 /* helpers */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
51 static int wgaim_is_socket( int fd ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
52 int optval;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
53 unsigned int optlen = sizeof(int);
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
54
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
55 if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
56 int error = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
57 if( error == WSAENOTSOCK )
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
58 return FALSE;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
59 else {
6425
26b739bc9f1a [gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5913
diff changeset
60 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
61 return FALSE;
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 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
64 return TRUE;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
65 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
66
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
67 /* socket.h */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
68 int wgaim_socket (int namespace, int style, int protocol) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
69 int ret;
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 ret = socket( namespace, style, protocol );
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
72
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
73 if( ret == INVALID_SOCKET ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
74 errno = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
75 return -1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
76 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
77 return 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
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
80 int wgaim_connect(int socket, struct sockaddr *addr, u_long length) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
81 int ret;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
82
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
83 ret = connect( socket, addr, length );
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 if( ret == SOCKET_ERROR ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
86 errno = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
87 if( errno == WSAEWOULDBLOCK )
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
88 errno = WSAEINPROGRESS;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
89 return -1;
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 return 0;
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
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
94 int wgaim_getsockopt(int socket, int level, int optname, void *optval, unsigned int *optlenptr) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
95 int ret;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
96
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
97 ret = getsockopt( socket, level, optname, optval, optlenptr );
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
98 if( ret == SOCKET_ERROR ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
99 errno = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
100 return -1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
101 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
102
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
103 return 0;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
104 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
105
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
106 /* fcntl.h */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
107 /* This is not a full implementation of fcntl. Update as needed.. */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
108 int wgaim_fcntl(int socket, int command, int val) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
109 switch( command ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
110 case F_SETFL:
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
111 {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
112 int ret=0;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
113
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
114 switch( val ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
115 case O_NONBLOCK:
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
116 {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
117 u_long imode=1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
118 ret = ioctlsocket(socket, FIONBIO, &imode);
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
119 break;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
120 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
121 case 0:
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
122 {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
123 u_long imode=0;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
124 ret = ioctlsocket(socket, FIONBIO, &imode);
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
125 break;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
126 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
127 default:
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
128 errno = EINVAL;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
129 return -1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
130 }/*end switch*/
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
131 if( ret == SOCKET_ERROR ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
132 errno = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
133 return -1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
134 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
135 return 0;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
136 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
137 default:
6425
26b739bc9f1a [gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5913
diff changeset
138 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_fcntl: Unsupported command\n");
3712
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
139 return -1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
140 }/*end switch*/
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
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
143 /* sys/ioctl.h */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
144 int wgaim_ioctl(int fd, int command, void* 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 FIONBIO:
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 if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
149 errno = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
150 return -1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
151 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
152 return 0;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
153 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
154 default:
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
155 errno = EINVAL;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
156 return -1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
157 }/*end switch*/
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
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
160 /* arpa/inet.h */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
161 int wgaim_inet_aton(const char *name, struct in_addr *addr) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
162 if((addr->s_addr = inet_addr(name)) == INADDR_NONE)
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
163 return 0;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
164 else
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 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
167
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
168 /* netdb.h */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
169 struct hostent* wgaim_gethostbyname(const char *name) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
170 struct hostent *hp;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
171
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
172 if((hp = gethostbyname(name)) == NULL) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
173 errno = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
174 return NULL;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
175 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
176 return hp;
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 /* string.h */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
180 char* wgaim_strerror( int errornum ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
181 if( errornum > WSABASEERR ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
182 sprintf( errbuf, "Windows socket error #%d", errornum );
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
183 return errbuf;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
184 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
185 else
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
186 return strerror( errornum );
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
4193
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
189 /* From glibc 2.2.5 */
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
190 char* wgaim_strsep(char **stringp, const char *delim) {
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
191 char *begin, *end;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
192
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
193 begin = *stringp;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
194 if (begin == NULL)
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
195 return NULL;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
196
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
197 /* A frequent case is when the delimiter string contains only one
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
198 character. Here we don't need to call the expensive `strpbrk'
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
199 function and instead work using `strchr'. */
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
200 if (delim[0] == '\0' || delim[1] == '\0') {
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
201 char ch = delim[0];
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
202
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
203 if (ch == '\0')
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
204 end = NULL;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
205 else {
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
206 if (*begin == ch)
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
207 end = begin;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
208 else if (*begin == '\0')
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
209 end = NULL;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
210 else
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
211 end = strchr (begin + 1, ch);
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
212 }
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
213 }
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
214 else
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
215 /* Find the end of the token. */
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
216 end = strpbrk (begin, delim);
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
217
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
218 if (end) {
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
219 /* Terminate the token and set *STRINGP past NUL character. */
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
220 *end++ = '\0';
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
221 *stringp = end;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
222 }
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
223 else
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
224 /* No more delimiters; this is the last token. */
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
225 *stringp = NULL;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
226
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
227 return begin;
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
228 }
c297b9d4f67c [gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3777
diff changeset
229
3712
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
230 /* unistd.h */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
231
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 * 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
234 */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
235 int wgaim_read(int fd, void *buf, unsigned int size) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
236 int ret;
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 if( wgaim_is_socket(fd) ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
239 if( (ret = recv(fd, buf, size, 0)) == SOCKET_ERROR ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
240 errno = WSAGetLastError();
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 if( ret == 0 ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
244 /* connection has been gracefully closed */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
245 errno = WSAENOTCONN;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
246 return -1;
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 /* success reading socket */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
250 return ret;
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 else {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
254 /* fd is not a socket handle.. pass it off to read */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
255 return read(fd, buf, size);
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 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
258
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
259 int wgaim_write(int fd, const void *buf, unsigned int size) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
260 int ret;
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 if( wgaim_is_socket(fd) ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
263 if( (ret = send(fd, buf, size, 0)) == SOCKET_ERROR ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
264 errno = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
265 return -1;
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 else {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
268 /* success */
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
269 return ret;
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 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
273 else
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
274 return write(fd, buf, size);
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
275 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
276
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
277 int wgaim_close(int fd) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
278 int ret;
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 if( wgaim_is_socket(fd) ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
281 if( (ret = closesocket(fd)) == SOCKET_ERROR ) {
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
282 errno = WSAGetLastError();
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
283 return -1;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
284 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
285 else
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
286 return 0;
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
287 }
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
288 else
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
289 return close(fd);
ac6ca3890c53 [gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff changeset
290 }
3777
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
291
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
292 /* sys/time.h */
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
293
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
294 int wgaim_gettimeofday(struct timeval *p, struct timezone *z) {
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
295 int res = 0;
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
296 struct _timeb timebuffer;
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
297
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
298 if (z != 0) {
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
299 _tzset();
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
300 z->tz_minuteswest = _timezone/60;
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
301 z->tz_dsttime = _daylight;
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
302 }
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
303
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
304 if (p != 0) {
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
305 _ftime(&timebuffer);
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
306 p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
307 p->tv_usec = timebuffer.millitm*1000; /* microseconds */
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
308 }
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
309
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
310 return res;
10ffafd1c91f [gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3712
diff changeset
311 }
4905
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
312
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
313 /* stdio.h */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
314
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
315 int wgaim_rename (const char *oldname, const char *newname) {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
316 struct _stat oldstat, newstat;
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 if(_stat(oldname, &oldstat) == 0) {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
319 /* newname exists */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
320 if(_stat(newname, &newstat) == 0) {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
321 /* oldname is a dir */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
322 if(_S_ISDIR(oldstat.st_mode)) {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
323 if(!_S_ISDIR(newstat.st_mode)) {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
324 return rename(oldname, newname);
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
325 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
326 /* newname is a dir */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
327 else {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
328 /* This is not quite right.. If newname is empty and
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
329 is not a sub dir of oldname, newname should be
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
330 deleted and oldname should be renamed.
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
331 */
6425
26b739bc9f1a [gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5913
diff changeset
332 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_rename does not behave here as it should\n");
4905
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
333 return rename(oldname, newname);
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
334 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
335 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
336 /* oldname is not a dir */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
337 else {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
338 /* newname is a dir */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
339 if(_S_ISDIR(newstat.st_mode)) {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
340 errno = EISDIR;
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
341 return -1;
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
342 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
343 /* newname is not a dir */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
344 else {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
345 remove(newname);
5084
a96653493416 [gaim-migrate @ 5439]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4905
diff changeset
346 return rename(oldname, newname);
4905
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
347 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
348 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
349 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
350 /* newname doesn't exist */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
351 else
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
352 return rename(oldname, newname);
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
353 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
354 else {
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
355 /* oldname doesn't exist */
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
356 errno = ENOENT;
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
357 return -1;
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
358 }
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
359
86037d6bf80f [gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4193
diff changeset
360 }
5113
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
361
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
362 /* time.h */
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
363
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
364 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
365 struct tm* tmptm;
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
366
5474
0b355ec51083 [gaim-migrate @ 5868]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5113
diff changeset
367 if(!time)
5913
9657e243d001 [gaim-migrate @ 6345]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5474
diff changeset
368 return NULL;
5113
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
369 tmptm = localtime(time);
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
370 if(resultp && tmptm)
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
371 return memcpy(resultp, tmptm, sizeof(struct tm));
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
372 else
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
373 return NULL;
bac62d8d386f [gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5084
diff changeset
374 }