Portability fixes for LSB compatibility.

diff --git a/configure b/configure
index 9633cc4..78937ab 100755
--- a/configure
+++ b/configure
@@ -15821,6 +15821,7 @@
 
 
 
+
 for ac_header in \
 	arpa/inet.h \
 	arpa/nameser.h \
@@ -15839,6 +15840,7 @@
 	linux/cdrom.h \
 	linux/hdreg.h \
 	linux/input.h \
+	linux/ioctl.h \
 	linux/joystick.h \
 	linux/major.h \
 	linux/param.h \
diff --git a/configure.ac b/configure.ac
index a605aff..6f8aaed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1078,6 +1078,7 @@
 	linux/cdrom.h \
 	linux/hdreg.h \
 	linux/input.h \
+	linux/ioctl.h \
 	linux/joystick.h \
 	linux/major.h \
 	linux/param.h \
diff --git a/dlls/d3d8/shader.c b/dlls/d3d8/shader.c
index 426051d..867e662 100644
--- a/dlls/d3d8/shader.c
+++ b/dlls/d3d8/shader.c
@@ -146,7 +146,7 @@
 
 void vshader_logp(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
   float tmp_f = fabsf(s0->w); 
-  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE;
+  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE_VAL;
   VSTRACE(("executing logp: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
 	         s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
 }
@@ -201,14 +201,14 @@
 }
 
 void vshader_rcp(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
-  d->x = d->y = d->z = d->w = (0.0f == s0->w) ? HUGE : 1.0f / s0->w;
+  d->x = d->y = d->z = d->w = (0.0f == s0->w) ? HUGE_VAL : 1.0f / s0->w;
   VSTRACE(("executing rcp: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
 	  s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
 }
 
 void vshader_rsq(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
   float tmp_f = fabsf(s0->w);
-  d->x = d->y = d->z = d->w = (0.0f == tmp_f) ? HUGE : ((1.0f != tmp_f) ? 1.0f / sqrtf(tmp_f) : 1.0f);
+  d->x = d->y = d->z = d->w = (0.0f == tmp_f) ? HUGE_VAL : ((1.0f != tmp_f) ? 1.0f / sqrtf(tmp_f) : 1.0f);
   VSTRACE(("executing rsq: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
 	  s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
 }
@@ -252,7 +252,7 @@
 
 void vshader_log(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
   float tmp_f = fabsf(s0->w); 
-  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE;
+  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE_VAL;
   VSTRACE(("executing log: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
 	  s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
 }
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 6a523c1..2a132e8 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -42,6 +42,9 @@
 #ifdef HAVE_SYS_ERRNO_H
 # include <sys/errno.h>
 #endif
+#ifdef HAVE_LINUX_IOCTL_H
+# include <linux/ioctl.h>
+#endif
 #ifdef HAVE_LINUX_JOYSTICK_H
 # include <linux/joystick.h>
 #endif
diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index 4499dd3..fc49a0b 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -53,38 +53,18 @@
 #include "ifenum.h"
 #include "ipstats.h"
 
-#ifndef TCPS_ESTABLISHED
-# define TCPS_ESTABLISHED TCP_ESTABLISHED
-#endif
-#ifndef TCPS_SYN_SENT
-# define TCPS_SYN_SENT TCP_SYN_SENT
-#endif
-#ifndef TCPS_SYN_RECEIVED
-# define TCPS_SYN_RECEIVED TCP_SYN_RECV
-#endif
-#ifndef TCPS_FIN_WAIT_1
-# define TCPS_FIN_WAIT_1 TCP_FIN_WAIT1
-#endif
-#ifndef TCPS_FIN_WAIT_2
-# define TCPS_FIN_WAIT_2 TCP_FIN_WAIT2
-#endif
-#ifndef TCPS_TIME_WAIT
-# define TCPS_TIME_WAIT TCP_TIME_WAIT
-#endif
-#ifndef TCPS_CLOSED
-# define TCPS_CLOSED TCP_CLOSE
-#endif
-#ifndef TCPS_CLOSE_WAIT
-# define TCPS_CLOSE_WAIT TCP_CLOSE_WAIT
-#endif
-#ifndef TCPS_LAST_ACK
-# define TCPS_LAST_ACK TCP_LAST_ACK
-#endif
-#ifndef TCPS_LISTEN
-# define TCPS_LISTEN TCP_LISTEN
-#endif
-#ifndef TCPS_CLOSING
-# define TCPS_CLOSING TCP_CLOSING
+#ifdef linux
+#define TCPS_ESTABLISHED  1
+#define TCPS_SYN_SENT     2
+#define TCPS_SYN_RECEIVED 3
+#define TCPS_FIN_WAIT_1   4
+#define TCPS_FIN_WAIT_2   5
+#define TCPS_TIME_WAIT    6
+#define TCPS_CLOSED       7
+#define TCPS_CLOSE_WAIT   8
+#define TCPS_LAST_ACK     9
+#define TCPS_LISTEN      10
+#define TCPS_CLOSING     11
 #endif
 
 DWORD getInterfaceStatsByName(const char *name, PMIB_IFROW entry)
diff --git a/dlls/netapi32/nbt.c b/dlls/netapi32/nbt.c
index 3cb6d63..e953ab0 100644
--- a/dlls/netapi32/nbt.c
+++ b/dlls/netapi32/nbt.c
@@ -68,9 +68,9 @@
 #include "config.h"
 #include <stdarg.h>
 
+#include "winsock2.h"
 #include "windef.h"
 #include "winbase.h"
-#include "winsock2.h"
 #include "wine/debug.h"
 #include "winreg.h"
 #include "iphlpapi.h"
diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c
index a6a2a7b..014f6d3 100644
--- a/dlls/wined3d/vertexshader.c
+++ b/dlls/wined3d/vertexshader.c
@@ -140,7 +140,7 @@
 
 void vshader_logp(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
   float tmp_f = fabsf(s0->w); 
-  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE;
+  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE_VAL;
   VSTRACE(("executing logp: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
 	         s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
 }
@@ -195,14 +195,14 @@
 }
 
 void vshader_rcp(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
-  d->x = d->y = d->z = d->w = (0.0f == s0->w) ? HUGE : 1.0f / s0->w;
+  d->x = d->y = d->z = d->w = (0.0f == s0->w) ? HUGE_VAL : 1.0f / s0->w;
   VSTRACE(("executing rcp: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
 	  s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
 }
 
 void vshader_rsq(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
   float tmp_f = fabsf(s0->w);
-  d->x = d->y = d->z = d->w = (0.0f == tmp_f) ? HUGE : ((1.0f != tmp_f) ? 1.0f / sqrtf(tmp_f) : 1.0f);
+  d->x = d->y = d->z = d->w = (0.0f == tmp_f) ? HUGE_VAL : ((1.0f != tmp_f) ? 1.0f / sqrtf(tmp_f) : 1.0f);
   VSTRACE(("executing rsq: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
 	  s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
 }
@@ -246,7 +246,7 @@
 
 void vshader_log(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
   float tmp_f = fabsf(s0->w); 
-  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE;
+  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE_VAL;
   VSTRACE(("executing log: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
 	  s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w));
 }
diff --git a/dlls/winedos/ppdev.c b/dlls/winedos/ppdev.c
index 2bca1e5..4ef847f 100644
--- a/dlls/winedos/ppdev.c
+++ b/dlls/winedos/ppdev.c
@@ -29,10 +29,13 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <errno.h>
 #ifdef HAVE_SYS_IOCTL_H
 # include <sys/ioctl.h>
 #endif
-#include <errno.h>
+#ifdef HAVE_LINUX_IOCTL_H
+# include <linux/ioctl.h>
+#endif
 #include <linux/ppdev.h>
 
 #include "winerror.h"
diff --git a/dlls/winmm/joystick/joystick.c b/dlls/winmm/joystick/joystick.c
index df45b39..2515465 100644
--- a/dlls/winmm/joystick/joystick.c
+++ b/dlls/winmm/joystick/joystick.c
@@ -45,6 +45,9 @@
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
+#ifdef HAVE_LINUX_IOCTL_H
+#include <linux/ioctl.h>
+#endif
 #ifdef HAVE_LINUX_JOYSTICK_H
 #include <linux/joystick.h>
 #define JOYDEV "/dev/js%d"
diff --git a/dlls/winsock/socket.c b/dlls/winsock/socket.c
index c70cd18..757dc54 100644
--- a/dlls/winsock/socket.c
+++ b/dlls/winsock/socket.c
@@ -1823,7 +1823,6 @@
         break;
 
     case WS_FIONBIO:
-        newcmd=FIONBIO;
         if( _get_sock_mask(s) )
         {
             /* AsyncSelect()'ed sockets are always nonblocking */
@@ -1831,11 +1830,25 @@
             SetLastError(WSAEINVAL);
             return SOCKET_ERROR;
         }
-        if (*argp)
-            _enable_event(SOCKET2HANDLE(s), 0, FD_WINE_NONBLOCKING, 0);
-        else
-            _enable_event(SOCKET2HANDLE(s), 0, 0, FD_WINE_NONBLOCKING);
-        return 0;
+        fd = get_sock_fd( s, 0, NULL );
+        if (fd != -1)
+        {
+            int ret;
+            if (*argp)
+            {
+                _enable_event(SOCKET2HANDLE(s), 0, FD_WINE_NONBLOCKING, 0);
+                ret = fcntl( fd, F_SETFL, O_NONBLOCK );
+            }
+            else
+            {
+                _enable_event(SOCKET2HANDLE(s), 0, 0, FD_WINE_NONBLOCKING);
+                ret = fcntl( fd, F_SETFL, 0 );
+            }
+            release_sock_fd( s, fd );
+            if (!ret) return 0;
+            SetLastError((errno == EBADF) ? WSAENOTSOCK : wsaErrno());
+        }
+        return SOCKET_ERROR;
 
     case WS_SIOCATMARK:
         newcmd=SIOCATMARK;
diff --git a/files/dos_fs.c b/files/dos_fs.c
index c05113b..2492adc 100644
--- a/files/dos_fs.c
+++ b/files/dos_fs.c
@@ -37,6 +37,9 @@
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
+#ifdef HAVE_LINUX_IOCTL_H
+#include <linux/ioctl.h>
+#endif
 #include <time.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
diff --git a/include/config.h.in b/include/config.h.in
index 2877a15..6c0b598 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -308,6 +308,9 @@
 /* Define to 1 if you have the <linux/input.h> header file. */
 #undef HAVE_LINUX_INPUT_H
 
+/* Define to 1 if you have the <linux/ioctl.h> header file. */
+#undef HAVE_LINUX_IOCTL_H
+
 /* Define to 1 if you have the <linux/joystick.h> header file. */
 #undef HAVE_LINUX_JOYSTICK_H
 
diff --git a/server/change.c b/server/change.c
index e520677..2d42644 100644
--- a/server/change.c
+++ b/server/change.c
@@ -79,7 +79,7 @@
 
 static void adjust_changes( int fd, unsigned int filter )
 {
-#ifdef F_NOTIFY
+#if defined(F_SETSIG) && defined(F_NOTIFY)
     unsigned int val;
     if ( 0 > fcntl( fd, F_SETSIG, SIGIO) )
         return;