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