Mercurial > pidgin
comparison libpurple/win32/libc_interface.c @ 24578:ef70bcdae73f
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
I modified it to use g_return_val_if_reached() because we need to track down
and fix the places where invalid fds are being used.
Fixes #7608
| author | Daniel Atallah <daniel.atallah@gmail.com> |
|---|---|
| date | Tue, 02 Dec 2008 02:06:19 +0000 |
| parents | a9db0aec7e59 |
| children | 0ea515a3f70c |
comparison
equal
deleted
inserted
replaced
| 24577:3cae90524840 | 24578:ef70bcdae73f |
|---|---|
| 349 * We need to figure out whether fd is a file or socket handle. | 349 * We need to figure out whether fd is a file or socket handle. |
| 350 */ | 350 */ |
| 351 int wpurple_read(int fd, void *buf, unsigned int size) { | 351 int wpurple_read(int fd, void *buf, unsigned int size) { |
| 352 int ret; | 352 int ret; |
| 353 | 353 |
| 354 if (fd < 0) { | |
| 355 errno = EBADF; | |
| 356 g_return_val_if_reached(-1); | |
| 357 } | |
| 358 | |
| 354 if(wpurple_is_socket(fd)) { | 359 if(wpurple_is_socket(fd)) { |
| 355 if((ret = recv(fd, buf, size, 0)) == SOCKET_ERROR) { | 360 if((ret = recv(fd, buf, size, 0)) == SOCKET_ERROR) { |
| 356 errno = WSAGetLastError(); | 361 errno = WSAGetLastError(); |
| 357 if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS) | 362 if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS) |
| 358 errno = EAGAIN; | 363 errno = EAGAIN; |
| 388 } | 393 } |
| 389 return ret; | 394 return ret; |
| 390 } | 395 } |
| 391 | 396 |
| 392 int wpurple_write(int fd, const void *buf, unsigned int size) { | 397 int wpurple_write(int fd, const void *buf, unsigned int size) { |
| 398 | |
| 399 if (fd < 0) { | |
| 400 errno = EBADF; | |
| 401 g_return_val_if_reached(-1); | |
| 402 } | |
| 393 | 403 |
| 394 if(wpurple_is_socket(fd)) | 404 if(wpurple_is_socket(fd)) |
| 395 return wpurple_send(fd, buf, size, 0); | 405 return wpurple_send(fd, buf, size, 0); |
| 396 else | 406 else |
| 397 return _write(fd, buf, size); | 407 return _write(fd, buf, size); |
| 410 } | 420 } |
| 411 } | 421 } |
| 412 | 422 |
| 413 int wpurple_close(int fd) { | 423 int wpurple_close(int fd) { |
| 414 int ret; | 424 int ret; |
| 425 | |
| 426 if (fd < 0) { | |
| 427 errno = EBADF; | |
| 428 g_return_val_if_reached(-1); | |
| 429 } | |
| 415 | 430 |
| 416 if( wpurple_is_socket(fd) ) { | 431 if( wpurple_is_socket(fd) ) { |
| 417 if( (ret = closesocket(fd)) == SOCKET_ERROR ) { | 432 if( (ret = closesocket(fd)) == SOCKET_ERROR ) { |
| 418 errno = WSAGetLastError(); | 433 errno = WSAGetLastError(); |
| 419 return -1; | 434 return -1; |
