diff --git a/lib/compat.c b/lib/compat.c index 1ceeff29..2074921f 100644 --- a/lib/compat.c +++ b/lib/compat.c @@ -50,6 +50,7 @@ struct MinList __filelist = { (struct MinNode *) &__filelist.mlh_Tail, NULL, (st #include #include #include +#include #endif @@ -155,11 +156,17 @@ int smb2_getaddrinfo(const char *node, const char*service, #if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) struct hostent *host; int i, ip[4]; +#endif +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) sin = calloc(1, sizeof(struct sockaddr_in)); +#else + sin = malloc(sizeof(struct sockaddr_in)); +#endif sin->sin_len = sizeof(struct sockaddr_in); sin->sin_family=AF_INET; +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) /* Some error checking would be nice */ if (sscanf(node, "%d.%d.%d.%d", ip, ip+1, ip+2, ip+3) == 4) { for (i = 0; i < 4; i++) { @@ -183,10 +190,6 @@ int smb2_getaddrinfo(const char *node, const char*service, *res = calloc(1, sizeof(struct addrinfo)); #else - sin = malloc(sizeof(struct sockaddr_in)); - sin->sin_len = sizeof(struct sockaddr_in); - sin->sin_family=AF_INET; - /* Some error checking would be nice */ sin->sin_addr.s_addr = inet_addr(node); @@ -311,11 +314,9 @@ ssize_t readv (int fd, const struct iovec *vector, int count) #endif #ifdef NEED_POLL -#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) -#include int poll(struct pollfd *fds, unsigned int nfds, int timo) { - struct timeval timeout, *toptr = 0; + struct timeval timeout, *toptr; fd_set ifds, ofds, efds, *ip, *op; unsigned int i, maxfd = 0; int rc; @@ -323,6 +324,7 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) FD_ZERO(&ifds); FD_ZERO(&ofds); FD_ZERO(&efds); +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) op = ip = 0; for (i = 0; i < nfds; ++i) { int fd = fds[i].fd; @@ -341,49 +343,8 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) if (fd > maxfd) { maxfd = fd; } - } - - if(timo >= 0) { - toptr = &timeout; - timeout.tv_sec = (unsigned)timo / 1000; - timeout.tv_usec = ((unsigned)timo % 1000) * 1000; - } - - rc = select(maxfd + 1, ip, op, &efds, toptr); - if(rc <= 0) - return rc; - - rc = 0; - for (i = 0; i < nfds; ++i) { - int fd = fds[i].fd; - short events = fds[i].events; - short revents = 0; - if (fd < 0) - continue; - if(events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) - revents |= POLLIN; - if(events & POLLOUT && FD_ISSET(fd, &ofds)) - revents |= POLLOUT; - if(FD_ISSET(fd, &efds)) - revents |= POLLHUP; - if (revents) { - fds[i].revents = revents; - rc++; - } } - return rc; -} #else -int poll(struct pollfd *fds, unsigned int nfds, int timo) -{ - struct timeval timeout, *toptr; - fd_set ifds, ofds, efds, *ip, *op; - unsigned int i, maxfd = 0; - int rc; - - FD_ZERO(&ifds); - FD_ZERO(&ofds); - FD_ZERO(&efds); for (i = 0, op = ip = 0; i < nfds; ++i) { fds[i].revents = 0; if(fds[i].events & (POLLIN|POLLPRI)) { @@ -399,7 +360,16 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) maxfd = fds[i].fd; } } +#endif +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) + if(timo >= 0) { + toptr = &timeout; + timeout.tv_sec = (unsigned)timo / 1000; + timeout.tv_usec = ((unsigned)timo % 1000) * 1000; + } + +#else if(timo < 0) { toptr = NULL; } else { @@ -416,6 +386,7 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) timeout.tv_sec = timo / 1000; timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; #endif +#endif } rc = select(maxfd + 1, ip, op, &efds, toptr); @@ -423,6 +394,26 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) if(rc <= 0) return rc; +#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__) + rc = 0; + for (i = 0; i < nfds; ++i) { + int fd = fds[i].fd; + short events = fds[i].events; + short revents = 0; + if (fd < 0) + continue; + if(events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) + revents |= POLLIN; + if(events & POLLOUT && FD_ISSET(fd, &ofds)) + revents |= POLLOUT; + if(FD_ISSET(fd, &efds)) + revents |= POLLHUP; + if (revents) { + fds[i].revents = revents; + rc++; + } + } +#else if(rc > 0) { for (i = 0; i < nfds; ++i) { int fd = fds[i].fd; @@ -434,10 +425,10 @@ int poll(struct pollfd *fds, unsigned int nfds, int timo) fds[i].revents |= POLLHUP; } } +#endif return rc; } #endif -#endif #ifdef NEED_STRDUP char *strdup(const char *s)