X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fhelper%2Freplacements.h;h=d20b5f66b2db9019082451dfb09ddc6ac40e1d0c;hp=069519d1a8906f6e027532d05a3f4a9c15598995;hb=af7cdfd82bf47fde9c183c3ff5d14422fc737f24;hpb=edfca66467b93c737f632f7233a01bf281b684e9 diff --git a/src/helper/replacements.h b/src/helper/replacements.h index 069519d1a8..d20b5f66b2 100644 --- a/src/helper/replacements.h +++ b/src/helper/replacements.h @@ -31,27 +31,7 @@ #endif #include "types.h" - -#if BUILD_ECOSBOARD -#include -#include -#include -#endif - -/* include necessary headers for socket functionality */ -#ifdef _WIN32 -#include -#else -#include -#include -#include -#include -#include -#endif - -#ifdef HAVE_SYS_PARAM_H -#include /* for MIN/MAX macros */ -#endif +#include "system.h" /* MIN,MAX macros */ #ifndef MIN @@ -84,10 +64,9 @@ struct timeval { /* gettimeofday() */ #ifndef HAVE_GETTIMEOFDAY - #ifdef _WIN32 struct timezone { - int tz_minuteswest; + int tz_minuteswest; int tz_dsttime; }; #endif @@ -96,9 +75,11 @@ struct timezone; extern int gettimeofday(struct timeval *tv, struct timezone *tz); #endif +#ifndef IN_REPLACEMENTS_C /**** clear_malloc & fill_malloc ****/ void *clear_malloc(size_t size); void *fill_malloc(size_t size); +#endif /* * Now you have 3 ways for the malloc function: @@ -161,6 +142,12 @@ void usleep(int us); #include #include +/* win32 systems do not support ETIMEDOUT */ + +#ifndef ETIMEDOUT +#define ETIMEDOUT WSAETIMEDOUT +#endif + #if IS_MINGW == 1 static __inline unsigned char inb(unsigned short int port) { @@ -175,33 +162,36 @@ static __inline void outb(unsigned char value, unsigned short int port) } #endif /* IS_MINGW */ + +int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv); + #endif /* _WIN32 */ /* generic socket functions for Windows and Posix */ static __inline int write_socket( int handle, const void *buffer, unsigned int count ) { #ifdef _WIN32 - return send(handle, buffer, count, 0); + return send(handle, buffer, count, 0); #else - return write(handle, buffer, count); + return write(handle, buffer, count); #endif } static __inline int read_socket( int handle, void *buffer, unsigned int count ) { #ifdef _WIN32 - return recv(handle, buffer, count, 0); + return recv(handle, buffer, count, 0); #else - return read(handle, buffer, count); + return read(handle, buffer, count); #endif } static __inline int close_socket(int sock) { #ifdef _WIN32 - return closesocket(sock); + return closesocket(sock); #else - return close(sock); + return close(sock); #endif } @@ -216,6 +206,15 @@ static __inline void socket_nonblock(int fd) #endif } +static __inline int socket_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv) +{ +#ifdef _WIN32 + return win_select(max_fd, rfds, wfds, efds, tv); +#else + return select(max_fd, rfds, wfds, efds, tv); +#endif +} + #ifndef HAVE_ELF_H typedef struct @@ -229,9 +228,9 @@ typedef struct u32 e_shoff; /* Section header table file offset */ u32 e_flags; /* Processor-specific flags */ u16 e_ehsize; /* ELF header size in bytes */ - u16 e_phentsize; /* Program header table entry size */ + u16 e_phentsize; /* Program header table entry size */ u16 e_phnum; /* Program header table entry count */ - u16 e_shentsize; /* Section header table entry size */ + u16 e_shentsize; /* Section header table entry size */ u16 e_shnum; /* Section header table entry count */ u16 e_shstrndx; /* Section header string table index */ } Elf32_Ehdr;