Mercurial > pidgin.yaz
annotate src/win32/libc_interface.c @ 5798:217d24d11b6e
[gaim-migrate @ 6223]
<SimGuy> it was partly my stupidity :)
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 07 Jun 2003 09:09:11 +0000 |
parents | 0b355ec51083 |
children | 9657e243d001 |
rev | line source |
---|---|
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
1 /* |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
2 * libc_interface.c |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
3 * |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
4 * Author: Herman Bloggs <hermanator12002@yahoo.com> |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
5 * Date: October 14, 2002 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
6 * Description: Commonly used libc routines. |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
7 */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
8 #include <winsock.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
9 #include <io.h> |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
10 #include <stdlib.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
11 #include <stdio.h> |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
12 #include <errno.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
13 #include <sys/timeb.h> |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
14 #include <sys/stat.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
15 #include <time.h> |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
16 #include "libc_internal.h" |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
17 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
18 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
19 * PROTOS |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
20 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
21 extern void debug_printf(char * fmt, ...); |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
22 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
23 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
24 * LOCALS |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
25 */ |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
26 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
27 static char errbuf[1024]; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
28 |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
29 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
30 * CODE |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
31 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
32 |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
33 /* helpers */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
34 static int wgaim_is_socket( int fd ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
35 int optval; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
36 unsigned int optlen = sizeof(int); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
37 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
38 if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
39 int error = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
40 if( error == WSAENOTSOCK ) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
41 return FALSE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
42 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
43 debug_printf("wgaim_read: getsockopt returned error: %d\n", error); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
44 return FALSE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
45 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
46 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
47 return TRUE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
48 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
49 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
50 /* socket.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
51 int wgaim_socket (int namespace, int style, int protocol) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
52 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
53 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
54 ret = socket( namespace, style, protocol ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
55 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
56 if( ret == INVALID_SOCKET ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
57 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
58 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
59 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
60 return ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
61 } |
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 int wgaim_connect(int socket, struct sockaddr *addr, u_long length) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
64 int ret; |
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 ret = connect( socket, addr, length ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
67 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
68 if( ret == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
69 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
70 if( errno == WSAEWOULDBLOCK ) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
71 errno = WSAEINPROGRESS; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
72 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
73 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
74 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
75 } |
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 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
|
78 int ret; |
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 ret = getsockopt( socket, level, optname, optval, optlenptr ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
81 if( ret == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
82 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
83 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
84 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
85 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
86 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
87 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
88 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
89 /* fcntl.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
90 /* This is not a full implementation of fcntl. Update as needed.. */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
91 int wgaim_fcntl(int socket, int command, int val) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
92 switch( command ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
93 case F_SETFL: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
94 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
95 int ret=0; |
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 switch( val ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
98 case O_NONBLOCK: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
99 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
100 u_long imode=1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
101 ret = ioctlsocket(socket, FIONBIO, &imode); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
102 break; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
103 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
104 case 0: |
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 u_long imode=0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
107 ret = ioctlsocket(socket, FIONBIO, &imode); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
108 break; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
109 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
110 default: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
111 errno = EINVAL; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
112 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
113 }/*end switch*/ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
114 if( ret == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
115 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
116 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
117 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
118 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
119 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
120 default: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
121 debug_printf("wgaim_fcntl: Unsupported command\n"); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
122 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
123 }/*end switch*/ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
124 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
125 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
126 /* sys/ioctl.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
127 int wgaim_ioctl(int fd, int command, void* val) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
128 switch( command ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
129 case FIONBIO: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
130 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
131 if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == 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: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
138 errno = EINVAL; |
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 /* arpa/inet.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
144 int wgaim_inet_aton(const char *name, struct in_addr *addr) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
145 if((addr->s_addr = inet_addr(name)) == INADDR_NONE) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
146 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
147 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
148 return 1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
149 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
150 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
151 /* netdb.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
152 struct hostent* wgaim_gethostbyname(const char *name) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
153 struct hostent *hp; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
154 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
155 if((hp = gethostbyname(name)) == NULL) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
156 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
157 return NULL; |
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 return hp; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
160 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
161 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
162 /* string.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
163 char* wgaim_strerror( int errornum ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
164 if( errornum > WSABASEERR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
165 sprintf( errbuf, "Windows socket error #%d", errornum ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
166 return errbuf; |
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 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
169 return strerror( errornum ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
170 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
171 |
4193
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
172 /* From glibc 2.2.5 */ |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
173 char* wgaim_strsep(char **stringp, const char *delim) { |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
174 char *begin, *end; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
175 |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
176 begin = *stringp; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
177 if (begin == NULL) |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
178 return NULL; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
179 |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
180 /* A frequent case is when the delimiter string contains only one |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
181 character. Here we don't need to call the expensive `strpbrk' |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
182 function and instead work using `strchr'. */ |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
183 if (delim[0] == '\0' || delim[1] == '\0') { |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
184 char ch = delim[0]; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
185 |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
186 if (ch == '\0') |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
187 end = NULL; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
188 else { |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
189 if (*begin == ch) |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
190 end = begin; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
191 else if (*begin == '\0') |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
192 end = NULL; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
193 else |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
194 end = strchr (begin + 1, ch); |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
195 } |
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 else |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
198 /* Find the end of the token. */ |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
199 end = strpbrk (begin, delim); |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
200 |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
201 if (end) { |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
202 /* Terminate the token and set *STRINGP past NUL character. */ |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
203 *end++ = '\0'; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
204 *stringp = end; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
205 } |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
206 else |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
207 /* No more delimiters; this is the last token. */ |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
208 *stringp = NULL; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
209 |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
210 return begin; |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
211 } |
c297b9d4f67c
[gaim-migrate @ 4424]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3777
diff
changeset
|
212 |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
213 /* unistd.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
214 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
215 /* |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
216 * 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
|
217 */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
218 int wgaim_read(int fd, void *buf, unsigned int size) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
219 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
220 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
221 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
222 if( (ret = recv(fd, buf, size, 0)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
223 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
224 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
225 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
226 else if( ret == 0 ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
227 /* connection has been gracefully closed */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
228 errno = WSAENOTCONN; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
229 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
230 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
231 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
232 /* success reading socket */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
233 return ret; |
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 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
236 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
237 /* fd is not a socket handle.. pass it off to read */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
238 return read(fd, buf, size); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
239 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
240 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
241 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
242 int wgaim_write(int fd, const void *buf, unsigned int size) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
243 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
244 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
245 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
246 if( (ret = send(fd, buf, size, 0)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
247 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
248 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
249 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
250 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
251 /* success */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
252 return ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
253 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
254 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
255 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
256 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
257 return write(fd, buf, size); |
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 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
260 int wgaim_close(int fd) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
261 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
262 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
263 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
264 if( (ret = closesocket(fd)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
265 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
266 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
267 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
268 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
269 return 0; |
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 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
272 return close(fd); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
273 } |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
274 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
275 /* sys/time.h */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
276 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
277 int wgaim_gettimeofday(struct timeval *p, struct timezone *z) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
278 int res = 0; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
279 struct _timeb timebuffer; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
280 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
281 if (z != 0) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
282 _tzset(); |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
283 z->tz_minuteswest = _timezone/60; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
284 z->tz_dsttime = _daylight; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
285 } |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
286 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
287 if (p != 0) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
288 _ftime(&timebuffer); |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
289 p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
290 p->tv_usec = timebuffer.millitm*1000; /* microseconds */ |
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 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
293 return res; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
294 } |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
295 |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
296 /* stdio.h */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
297 |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
298 int wgaim_rename (const char *oldname, const char *newname) { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
299 struct _stat oldstat, newstat; |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
300 |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
301 if(_stat(oldname, &oldstat) == 0) { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
302 /* newname exists */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
303 if(_stat(newname, &newstat) == 0) { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
304 /* oldname is a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
305 if(_S_ISDIR(oldstat.st_mode)) { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
306 if(!_S_ISDIR(newstat.st_mode)) { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
307 return rename(oldname, newname); |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
308 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
309 /* newname is a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
310 else { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
311 /* This is not quite right.. If newname is empty and |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
312 is not a sub dir of oldname, newname should be |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
313 deleted and oldname should be renamed. |
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 debug_printf("Warning: wgaim_rename does not behave here as it should\n"); |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
316 return rename(oldname, newname); |
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 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
319 /* oldname is not a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
320 else { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
321 /* newname is a dir */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
322 if(_S_ISDIR(newstat.st_mode)) { |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
323 errno = EISDIR; |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
324 return -1; |
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 not 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 remove(newname); |
5084
a96653493416
[gaim-migrate @ 5439]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4905
diff
changeset
|
329 return rename(oldname, newname); |
4905
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
330 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
331 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
332 } |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
333 /* newname doesn't exist */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
334 else |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
335 return rename(oldname, newname); |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
336 } |
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 /* oldname doesn't exist */ |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
339 errno = ENOENT; |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
340 return -1; |
86037d6bf80f
[gaim-migrate @ 5239]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4193
diff
changeset
|
341 } |
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 } |
5113
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
344 |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
345 /* time.h */ |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
346 |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
347 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
|
348 struct tm* tmptm; |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
349 |
5474
0b355ec51083
[gaim-migrate @ 5868]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5113
diff
changeset
|
350 if(!time) |
0b355ec51083
[gaim-migrate @ 5868]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5113
diff
changeset
|
351 return; |
5113
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
352 tmptm = localtime(time); |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
353 if(resultp && tmptm) |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
354 return memcpy(resultp, tmptm, sizeof(struct tm)); |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
355 else |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
356 return NULL; |
bac62d8d386f
[gaim-migrate @ 5476]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5084
diff
changeset
|
357 } |