diff --git a/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.c b/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.c index ca47c32..ba35ed8 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.c +++ b/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.c @@ -23,13 +23,15 @@ int fd_table_get_min_index() { { bitmap++; min_index += 8; + if (min_index >= MAX_FDS) + return -1; } tmp = *bitmap; while (tmp & 0x80) { - tmp << 1; + tmp <<= 1; min_index++; } @@ -47,7 +49,7 @@ void fd_table_clear(int index) { fd_table.w32_ios[index]->table_index = -1; fd_table.w32_ios[index] = NULL; - FD_SET(index, &(fd_table.occupied)); + FD_CLR(index, &(fd_table.occupied)); } void w32posix_initialize() { @@ -134,6 +136,7 @@ int w32_close(int fd) { fd_table_clear(pio->table_index); if ((pio->type == LISTEN_FD) || (pio->type == SOCK_FD)) { socketio_close(pio); + return 0; } else return -1; diff --git a/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32posix.h b/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32posix.h index 7b3b606..4b6fc7f 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32posix.h +++ b/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32posix.h @@ -6,16 +6,22 @@ #include //File Descriptor definitions +#if !defined(MAX_FDS) #define MAX_FDS 128 //a 2^n number +#endif typedef struct w32_fd_set_ { unsigned char bitmap[MAX_FDS >> 3]; }w32_fd_set; #define fd_set w32_fd_set +#undef FD_ZERO #define FD_ZERO(set) (memset( (set), 0, sizeof(w32_fd_set))) +#undef FD_SET #define FD_SET(fd,set) ( (set)->bitmap[(fd) >> 3] |= (0x80 >> ((fd) % 8))) +#undef FD_ISSET #define FD_ISSET(fd, set) (( (set)->bitmap[(fd) >> 3] & (0x80 >> ((fd) % 8)))?1:0) +#undef FD_CLR #define FD_CLR(fd, set) ((set)->bitmap[(fd) >> 3] &= (~(0x80 >> ((fd) % 8)))) #define STDIN_FILENO 0 @@ -25,8 +31,8 @@ typedef struct w32_fd_set_ { //fcntl commands #define F_GETFL 0x1 #define F_SETFL 0x2 -#define F_GETFL 0x4 -#define F_SETFL 0x8 +#define F_GETFD 0x4 +#define F_SETFD 0x8 //fd status flags #define O_NONBLOCK 0x1