Tue, 27 May 2003 03:38:52 +0000
[gaim-migrate @ 5937]
This is:
-AIM over OSCAR use Christian's new, kick ass
gaim_notify_email stuff for new mail notification. This
should be good, but it's kind of a pain to test. Let me
know if you have any problems
-Minor fix to the translation README
-2 minor changes to the doxygen of 2 major header files
(this means you'll have to recompile a lot of files :-) )
-If your global proxy setting is "No Proxy" and your global
proxy host is empty, but $http_proxy is set to something,
gaim used to switch your global proxy setting to "HTTP." It
no longer does this. This makes more sense to me. If you
disagree, please let me know--this is open to debate, and
what not. Also, the use of environmental proxy settings
will be changed a bit in the next day or two
| 3712 | 1 | /* |
| 2 | * libc_interface.c | |
| 3 | * | |
| 4 | * Author: Herman Bloggs <hermanator12002@yahoo.com> | |
| 5 | * Date: October 14, 2002 | |
| 6 | * Description: Commonly used libc routines. | |
| 7 | */ | |
| 8 | #include <winsock.h> | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
9 | #include <io.h> |
| 3712 | 10 | #include <stdlib.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
11 | #include <stdio.h> |
| 3712 | 12 | #include <errno.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
13 | #include <sys/timeb.h> |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
14 | #include <sys/stat.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
15 | #include <time.h> |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
16 | #include "libc_internal.h" |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
17 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
18 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
19 | * PROTOS |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
20 | */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
21 | extern void debug_printf(char * fmt, ...); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
22 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
23 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
24 | * LOCALS |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
25 | */ |
| 3712 | 26 | |
| 27 | static char errbuf[1024]; | |
| 28 | ||
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
29 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
30 | * CODE |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
31 | */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
32 | |
| 3712 | 33 | /* helpers */ |
| 34 | static int wgaim_is_socket( int fd ) { | |
| 35 | int optval; | |
| 36 | unsigned int optlen = sizeof(int); | |
| 37 | ||
| 38 | if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) { | |
| 39 | int error = WSAGetLastError(); | |
| 40 | if( error == WSAENOTSOCK ) | |
| 41 | return FALSE; | |
| 42 | else { | |
| 43 | debug_printf("wgaim_read: getsockopt returned error: %d\n", error); | |
| 44 | return FALSE; | |
| 45 | } | |
| 46 | } | |
| 47 | return TRUE; | |
| 48 | } | |
| 49 | ||
| 50 | /* socket.h */ | |
| 51 | int wgaim_socket (int namespace, int style, int protocol) { | |
| 52 | int ret; | |
| 53 | ||
| 54 | ret = socket( namespace, style, protocol ); | |
| 55 | ||
| 56 | if( ret == INVALID_SOCKET ) { | |
| 57 | errno = WSAGetLastError(); | |
| 58 | return -1; | |
| 59 | } | |
| 60 | return ret; | |
| 61 | } | |
| 62 | ||
| 63 | int wgaim_connect(int socket, struct sockaddr *addr, u_long length) { | |
| 64 | int ret; | |
| 65 | ||
| 66 | ret = connect( socket, addr, length ); | |
| 67 | ||
| 68 | if( ret == SOCKET_ERROR ) { | |
| 69 | errno = WSAGetLastError(); | |
| 70 | if( errno == WSAEWOULDBLOCK ) | |
| 71 | errno = WSAEINPROGRESS; | |
| 72 | return -1; | |
| 73 | } | |
| 74 | return 0; | |
| 75 | } | |
| 76 | ||
| 77 | int wgaim_getsockopt(int socket, int level, int optname, void *optval, unsigned int *optlenptr) { | |
| 78 | int ret; | |
| 79 | ||
| 80 | ret = getsockopt( socket, level, optname, optval, optlenptr ); | |
| 81 | if( ret == SOCKET_ERROR ) { | |
| 82 | errno = WSAGetLastError(); | |
| 83 | return -1; | |
| 84 | } | |
| 85 | ||
| 86 | return 0; | |
| 87 | } | |
| 88 | ||
| 89 | /* fcntl.h */ | |
| 90 | /* This is not a full implementation of fcntl. Update as needed.. */ | |
| 91 | int wgaim_fcntl(int socket, int command, int val) { | |
| 92 | switch( command ) { | |
| 93 | case F_SETFL: | |
| 94 | { | |
| 95 | int ret=0; | |
| 96 | ||
| 97 | switch( val ) { | |
| 98 | case O_NONBLOCK: | |
| 99 | { | |
| 100 | u_long imode=1; | |
| 101 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 102 | break; | |
| 103 | } | |
| 104 | case 0: | |
| 105 | { | |
| 106 | u_long imode=0; | |
| 107 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 108 | break; | |
| 109 | } | |
| 110 | default: | |
| 111 | errno = EINVAL; | |
| 112 | return -1; | |
| 113 | }/*end switch*/ | |
| 114 | if( ret == SOCKET_ERROR ) { | |
| 115 | errno = WSAGetLastError(); | |
| 116 | return -1; | |
| 117 | } | |
| 118 | return 0; | |
| 119 | } | |
| 120 | default: | |
| 121 | debug_printf("wgaim_fcntl: Unsupported command\n"); | |
| 122 | return -1; | |
| 123 | }/*end switch*/ | |
| 124 | } | |
| 125 | ||
| 126 | /* sys/ioctl.h */ | |
| 127 | int wgaim_ioctl(int fd, int command, void* val) { | |
| 128 | switch( command ) { | |
| 129 | case FIONBIO: | |
| 130 | { | |
| 131 | if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) { | |
| 132 | errno = WSAGetLastError(); | |
| 133 | return -1; | |
| 134 | } | |
| 135 | return 0; | |
| 136 | } | |
| 137 | default: | |
| 138 | errno = EINVAL; | |
| 139 | return -1; | |
| 140 | }/*end switch*/ | |
| 141 | } | |
| 142 | ||
| 143 | /* arpa/inet.h */ | |
| 144 | int wgaim_inet_aton(const char *name, struct in_addr *addr) { | |
| 145 | if((addr->s_addr = inet_addr(name)) == INADDR_NONE) | |
| 146 | return 0; | |
| 147 | else | |
| 148 | return 1; | |
| 149 | } | |
| 150 | ||
| 151 | /* netdb.h */ | |
| 152 | struct hostent* wgaim_gethostbyname(const char *name) { | |
| 153 | struct hostent *hp; | |
| 154 | ||
| 155 | if((hp = gethostbyname(name)) == NULL) { | |
| 156 | errno = WSAGetLastError(); | |
| 157 | return NULL; | |
| 158 | } | |
| 159 | return hp; | |
| 160 | } | |
| 161 | ||
| 162 | /* string.h */ | |
| 163 | char* wgaim_strerror( int errornum ) { | |
| 164 | if( errornum > WSABASEERR ) { | |
| 165 | sprintf( errbuf, "Windows socket error #%d", errornum ); | |
| 166 | return errbuf; | |
| 167 | } | |
| 168 | else | |
| 169 | return strerror( errornum ); | |
| 170 | } | |
| 171 | ||
|
4193
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
172 | /* From glibc 2.2.5 */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
173 | char* wgaim_strsep(char **stringp, const char *delim) { |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
174 | char *begin, *end; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
175 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
176 | begin = *stringp; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
177 | if (begin == NULL) |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
178 | return NULL; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
179 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
180 | /* A frequent case is when the delimiter string contains only one |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
181 | character. Here we don't need to call the expensive `strpbrk' |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
182 | function and instead work using `strchr'. */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
183 | if (delim[0] == '\0' || delim[1] == '\0') { |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
184 | char ch = delim[0]; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
185 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
186 | if (ch == '\0') |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
187 | end = NULL; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
188 | else { |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
189 | if (*begin == ch) |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
190 | end = begin; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
191 | else if (*begin == '\0') |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
192 | end = NULL; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
193 | else |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
194 | end = strchr (begin + 1, ch); |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
195 | } |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
196 | } |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
197 | else |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
198 | /* Find the end of the token. */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
199 | end = strpbrk (begin, delim); |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
200 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
201 | if (end) { |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
202 | /* Terminate the token and set *STRINGP past NUL character. */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
203 | *end++ = '\0'; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
204 | *stringp = end; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
205 | } |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
206 | else |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
207 | /* No more delimiters; this is the last token. */ |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
208 | *stringp = NULL; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
209 | |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
210 | return begin; |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
211 | } |
|
0f6072a0ffa4
[gaim-migrate @ 4424]
Herman Bloggs <herman@bluedigits.com>
parents:
3777
diff
changeset
|
212 | |
| 3712 | 213 | /* unistd.h */ |
| 214 | ||
| 215 | /* | |
| 216 | * We need to figure out whether fd is a file or socket handle. | |
| 217 | */ | |
| 218 | int wgaim_read(int fd, void *buf, unsigned int size) { | |
| 219 | int ret; | |
| 220 | ||
| 221 | if( wgaim_is_socket(fd) ) { | |
| 222 | if( (ret = recv(fd, buf, size, 0)) == SOCKET_ERROR ) { | |
| 223 | errno = WSAGetLastError(); | |
| 224 | return -1; | |
| 225 | } | |
| 226 | else if( ret == 0 ) { | |
| 227 | /* connection has been gracefully closed */ | |
| 228 | errno = WSAENOTCONN; | |
| 229 | return -1; | |
| 230 | } | |
| 231 | else { | |
| 232 | /* success reading socket */ | |
| 233 | return ret; | |
| 234 | } | |
| 235 | } | |
| 236 | else { | |
| 237 | /* fd is not a socket handle.. pass it off to read */ | |
| 238 | return read(fd, buf, size); | |
| 239 | } | |
| 240 | } | |
| 241 | ||
| 242 | int wgaim_write(int fd, const void *buf, unsigned int size) { | |
| 243 | int ret; | |
| 244 | ||
| 245 | if( wgaim_is_socket(fd) ) { | |
| 246 | if( (ret = send(fd, buf, size, 0)) == SOCKET_ERROR ) { | |
| 247 | errno = WSAGetLastError(); | |
| 248 | return -1; | |
| 249 | } | |
| 250 | else { | |
| 251 | /* success */ | |
| 252 | return ret; | |
| 253 | } | |
| 254 | ||
| 255 | } | |
| 256 | else | |
| 257 | return write(fd, buf, size); | |
| 258 | } | |
| 259 | ||
| 260 | int wgaim_close(int fd) { | |
| 261 | int ret; | |
| 262 | ||
| 263 | if( wgaim_is_socket(fd) ) { | |
| 264 | if( (ret = closesocket(fd)) == SOCKET_ERROR ) { | |
| 265 | errno = WSAGetLastError(); | |
| 266 | return -1; | |
| 267 | } | |
| 268 | else | |
| 269 | return 0; | |
| 270 | } | |
| 271 | else | |
| 272 | return close(fd); | |
| 273 | } | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
274 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
275 | /* sys/time.h */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
276 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
277 | int wgaim_gettimeofday(struct timeval *p, struct timezone *z) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
278 | int res = 0; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
279 | struct _timeb timebuffer; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
280 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
281 | if (z != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
282 | _tzset(); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
283 | z->tz_minuteswest = _timezone/60; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
284 | z->tz_dsttime = _daylight; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
285 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
286 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
287 | if (p != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
288 | _ftime(&timebuffer); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
289 | p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
290 | p->tv_usec = timebuffer.millitm*1000; /* microseconds */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
291 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
292 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
293 | return res; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
294 | } |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
295 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
296 | /* stdio.h */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
297 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
298 | int wgaim_rename (const char *oldname, const char *newname) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
299 | struct _stat oldstat, newstat; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
300 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
301 | if(_stat(oldname, &oldstat) == 0) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
302 | /* newname exists */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
303 | if(_stat(newname, &newstat) == 0) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
304 | /* oldname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
305 | if(_S_ISDIR(oldstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
306 | if(!_S_ISDIR(newstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
307 | return rename(oldname, newname); |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
308 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
309 | /* newname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
310 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
311 | /* This is not quite right.. If newname is empty and |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
312 | is not a sub dir of oldname, newname should be |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
313 | deleted and oldname should be renamed. |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
314 | */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
315 | debug_printf("Warning: wgaim_rename does not behave here as it should\n"); |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
316 | return rename(oldname, newname); |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
317 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
318 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
319 | /* oldname is not a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
320 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
321 | /* newname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
322 | if(_S_ISDIR(newstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
323 | errno = EISDIR; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
324 | return -1; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
325 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
326 | /* newname is not a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
327 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
328 | remove(newname); |
|
5084
21d2e7ec99ce
[gaim-migrate @ 5439]
Herman Bloggs <herman@bluedigits.com>
parents:
4905
diff
changeset
|
329 | return rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
330 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
331 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
332 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
333 | /* newname doesn't exist */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
334 | else |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
335 | return rename(oldname, newname); |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
336 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
337 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
338 | /* oldname doesn't exist */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
339 | errno = ENOENT; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
340 | return -1; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
341 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
342 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
343 | } |
|
5113
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
344 | |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
345 | /* time.h */ |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
346 | |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
347 | struct tm * wgaim_localtime_r (const time_t *time, struct tm *resultp) { |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
348 | struct tm* tmptm; |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
349 | |
|
5474
eec4dad3e035
[gaim-migrate @ 5868]
Herman Bloggs <herman@bluedigits.com>
parents:
5113
diff
changeset
|
350 | if(!time) |
|
eec4dad3e035
[gaim-migrate @ 5868]
Herman Bloggs <herman@bluedigits.com>
parents:
5113
diff
changeset
|
351 | return; |
|
5113
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
352 | tmptm = localtime(time); |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
353 | if(resultp && tmptm) |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
354 | return memcpy(resultp, tmptm, sizeof(struct tm)); |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
355 | else |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
356 | return NULL; |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
357 | } |