Index: /trunk/include/slib.h
===================================================================
--- /trunk/include/slib.h	(revision 7)
+++ /trunk/include/slib.h	(revision 8)
@@ -349,4 +349,6 @@
   int sl_read (SL_TICKET ticket, void * buf, size_t count);
 
+  int sl_read_timeout_prep (SL_TICKET ticket);
+
   int sl_read_timeout (SL_TICKET ticket, void * buf, 
 		       size_t count, int timeout);
Index: /trunk/src/sh_files.c
===================================================================
--- /trunk/src/sh_files.c	(revision 7)
+++ /trunk/src/sh_files.c	(revision 8)
@@ -229,6 +229,5 @@
 	      tmp = sh_util_safe_name (ptr->name);
 #endif
-	      sh_error_handle ((-1),  FIL__, __LINE__, 0, MSG_FI_CHK,
-			       tmp);
+	      sh_error_handle ((-1),  FIL__, __LINE__, 0, MSG_FI_CHK, tmp);
 	    }
 
@@ -1457,7 +1456,9 @@
     }
 
-  sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_CHK,
-		   tmpname);
-  
+  if (flag_err_info == SL_TRUE)
+    {
+      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_CHK, tmpname);
+    }
+
   /* ---- check input ----
    */
Index: /trunk/src/sh_hash.c
===================================================================
--- /trunk/src/sh_hash.c	(revision 7)
+++ /trunk/src/sh_hash.c	(revision 8)
@@ -71,34 +71,40 @@
 static char * unquote_string (char * str)
 {
-  int    i = 0, j, k = 0, len;
-  char * tmp;
+  int    i = 0, j, k = 0, len, t1, t2, l2;
+  char * tmp = NULL;
 
   SL_ENTER(_("unquote_string"));
 
-  if (str == NULL)
-    {
-      SL_RETURN(NULL, _("unquote_string"));
-    }
-
-  len = sl_strlen(str);
-
-  tmp = SH_ALLOC(len + 1);
-  for (j = 0; j <= len; ++j)
-    {
-      if (str[j] == QUOTE_CHAR && j < (len-2))
-	{
-	  if (sh_util_hexchar(str[j+1]) >= 0 && sh_util_hexchar(str[j+2]) >= 0)
-	    {
-	      i = 16 * sh_util_hexchar(str[j+1]) + sh_util_hexchar(str[j+2]);
-	      tmp[k] = i; j += 2;
-	    }
-	  else
+  if (str != NULL)
+    {
+      len = sl_strlen(str);
+      l2  = len - 2;
+      tmp = SH_ALLOC(len + 1);
+
+      for (j = 0; j <= len; ++j)
+	{
+	  if (str[j] != QUOTE_CHAR)
 	    {
 	      tmp[k] = str[j];
 	    }
-	}
-      else
-	tmp[k] = str[j];
-      ++k;
+	  else if (str[j] == QUOTE_CHAR && j < l2)
+	    {
+	      t1 = sh_util_hexchar(str[j+1]);
+	      t2 = sh_util_hexchar(str[j+2]);
+	      if ((t1|t2) >= 0)
+		{
+		  i = 16 * t1 + t2;
+		  tmp[k] = i; 
+		  j += 2;
+		}
+	      else
+		{
+		  tmp[k] = str[j];
+		}
+	    }
+	  else
+	    tmp[k] = str[j];
+	  ++k;
+	}
     }
   SL_RETURN(tmp, _("unquote_string"));
@@ -306,5 +312,6 @@
 
 /* must fit an int              */
-#define TABSIZE 2048  
+/* #define TABSIZE 2048         */
+#define TABSIZE 65536
 
 /* must fit an unsigned short   */
@@ -386,4 +393,5 @@
  *
  **************************************************************/
+
 static int hashfunc(char *s) 
 {
@@ -392,6 +400,7 @@
   for ( ; *s; s++) 
     n = 31 * n + *s; 
-  return n % TABSIZE; 
+  return n & 0xFFFF;/* % TABSIZE*/; 
 } 
+
 
 int hashreport_missing( char *fullpath, int level)
@@ -635,10 +644,10 @@
   SL_ENTER(_("hashsearch"));
 
-  if (!s)
-    SL_RETURN( NULL, _("hashsearch"));
-
-  for (p = tab[hashfunc(s)]; p; p = p->next) 
-    if ((p->fullpath != NULL) && (0 == strcmp(s, p->fullpath))) 
-      SL_RETURN( p, _("hashsearch")); 
+  if (s)
+    {
+      for (p = tab[hashfunc(s)]; p; p = p->next)
+	if ((p->fullpath != NULL) && (0 == strcmp(s, p->fullpath))) 
+	  SL_RETURN( p, _("hashsearch"));
+    } 
   SL_RETURN( NULL, _("hashsearch"));
 } 
@@ -672,6 +681,5 @@
 	{
 	  if (p && p->fullpath && 
-	      0 == strcmp(s->fullpath, p->fullpath) &&
-	      strlen(s->fullpath) == strlen(p->fullpath))
+	      0 == strcmp(s->fullpath, p->fullpath))
 	    {
 	      q = p->next;
@@ -3064,14 +3072,14 @@
 int hash_remove_tree (char * s) 
 {
-  sh_file_t * p;
-  int         len;
-  int         i;
+  sh_file_t *  p;
+  size_t       len;
+  unsigned int i;
 
   SL_ENTER(_("hash_remove_tree"));
 
-  if (!s)
+  if (!s || *s == '\0')
     SL_RETURN ((-1), _("hash_remove_tree"));
-  else
-    len = sl_strlen(s);
+
+  len = sl_strlen(s);
 
   if (IsInit != 1) 
@@ -3082,5 +3090,5 @@
       for (p = tab[i]; p; p = p->next)
 	{
-	  if (sl_strncmp(s, p->fullpath, len) == 0)
+	  if (p->fullpath && 0 == strncmp(s, p->fullpath, len))
 	    { 
 	      p->allignore  = S_TRUE;
Index: /trunk/src/sh_prelink.c
===================================================================
--- /trunk/src/sh_prelink.c	(revision 7)
+++ /trunk/src/sh_prelink.c	(revision 8)
@@ -74,21 +74,21 @@
 int sh_prelink_iself (SL_TICKET fd, off_t size, int alert_timeout)
 {
-   long status;
-   char magic[4];
-   if (size < 42)
-	return S_FALSE;
-   status = sl_read_timeout (fd, magic, 4, alert_timeout);
-   (void) sl_rewind(fd);
-   if (status == 4)
-     {
-       /*@-usedef@*/
-       if (magic[0] == (char) 0x7f &&
-	   magic[1] == 'E'  &&
-	   magic[2] == 'L'  &&
-	   magic[3] == 'F')
-	 return S_TRUE;
-       /*@+usedef@*/
-     }
-   return S_FALSE;
+  long status;
+  char magic[4];
+  if (size < 42)
+    return S_FALSE;
+  status = sl_read_timeout (fd, magic, 4, alert_timeout);
+  (void) sl_rewind(fd);
+  if (status == 4)
+    {
+      /*@-usedef@*/
+      if (magic[0] == (char) 0x7f &&
+	  magic[1] == 'E'  &&
+	  magic[2] == 'L'  &&
+	  magic[3] == 'F')
+	return S_TRUE;
+      /*@+usedef@*/
+    }
+  return S_FALSE;
 }
 
@@ -242,4 +242,7 @@
    */
   tiger_fd = task.pipeTI;
+
+  sl_read_timeout_prep (task.pipeTI);
+
   strcpy(file_hash,                        /* known to fit */
 	 sh_tiger_generic_hash (path, TIGER_FD, 0, alert_timeout));
Index: /trunk/src/sh_tiger0.c
===================================================================
--- /trunk/src/sh_tiger0.c	(revision 7)
+++ /trunk/src/sh_tiger0.c	(revision 8)
@@ -95,4 +95,5 @@
 SL_TICKET tiger_fd = (-1);
 
+static sh_byte buffer[PRIV_MAX + 72];
 
 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
@@ -108,11 +109,13 @@
 {
   SL_TICKET  fd;
-  int  i, j;
+  int  i, j, tt;
   int  count = 0;
   int  blk;
   char    * tmp;
   sh_byte * bptr;
-  sh_byte buffer[PRIV_MAX + 72];
+  /* sh_byte buffer[PRIV_MAX + 72]; */
   sh_byte bbuf[64];
+
+  static int lockflag = SL_FALSE;
 
   unsigned long pages_read;
@@ -148,16 +151,16 @@
   SL_ENTER(_("sh_tiger_hash_val"));
 
-  if (what == TIGER_FILE || what == TIGER_FD) 
-    {
-      if (what == TIGER_FILE)
+  if (what == TIGER_FD || what == TIGER_FILE) 
+    {
+      if (what == TIGER_FD)
+	{
+	  fd = tiger_fd;
+	  TPT((0,FIL__, __LINE__, _("msg=<TIGER_FD>, fd=<%ld>\n"), tiger_fd));
+	}
+      else
 	{
 	  TPT((0,FIL__, __LINE__, _("msg=<TIGER_FILE>, path=<%s>\n"),
 	       (filename == NULL ? _("(null)") : filename) ));
 	  fd = sl_open_read (filename, SL_YESPRIV);
-	}
-      else
-	{
-	  fd = tiger_fd;
-	  TPT((0,FIL__, __LINE__, _("msg=<TIGER_FD>, fd=<%ld>\n"), tiger_fd));
 	}
 
@@ -174,12 +177,16 @@
       
 #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
-    if (skey->mlock_failed == SL_FALSE) 
+    if (lockflag == SL_FALSE && skey->mlock_failed == SL_FALSE) 
       {
         if ( (-1) == sh_unix_mlock((char *)buffer,(PRIV_MAX)*sizeof(sh_byte))) 
           skey->mlock_failed = SL_TRUE;
+	lockflag = SL_TRUE;
       }
 #else
-    if (skey->mlock_failed == SL_FALSE)
-      skey->mlock_failed = SL_TRUE;
+    if (lockflag == SL_FALSE && skey->mlock_failed == SL_FALSE)
+      {
+	skey->mlock_failed = SL_TRUE;
+	lockflag = SL_TRUE;
+      }
 #endif
 
@@ -190,5 +197,5 @@
     pages_read = 0;
 
-    while (1 == 1) 
+    while (1) 
       {
 	if (timeout > 0)
@@ -217,9 +224,9 @@
 			       count, MSG_E_READ, tmp);
 	    SH_FREE(tmp);
-	    (void) sh_unix_munlock((char*)buffer, (PRIV_MAX)*sizeof(sh_byte));
+	    memset (bbuf,   0, 64);
+	    memset (buffer, 0, PRIV_MAX);
+
 	    SL_RETURN( NULL, _("sh_tiger_hash_val"));
 	  }
-
-	/* TPT((0, FIL__, __LINE__ , _("msg=<Read %ld bytes>\n"), count)); */
 
 	blk      = (count / 64); /* number of 64-byte words */
@@ -228,14 +235,17 @@
 	 * count cannot be negative here, see 'if (SL_ISERROR (count))'
 	 */
-	ncount = (unsigned long) (count - ((count/64)*64));
+	tt = blk*64;
+
+	ncount = (unsigned long) (count - tt);
+
+	nblocks += blk;
+	sh.statistics.bytes_hashed += tt;
 	
-	bptr = buffer;
+	bptr = buffer; tt = 0;
 	for (i = 0; i < blk; ++i)
 	  {
-	    bptr = &buffer[64 * i];
+	    bptr = &buffer[tt]; tt += 64;
 	    
 	    tiger_t(TIGER_CAST bptr, 64, res);
-	    ++nblocks;
-	    sh.statistics.bytes_hashed += 64;
 	    
 #ifdef TIGER_DBG
@@ -252,6 +262,5 @@
 	    memset (bbuf,   0, 64);
 	    memset (buffer, 0, PRIV_MAX);
-	    (void) sh_unix_munlock( (char *) buffer, 
-				    (PRIV_MAX) * sizeof(sh_byte));
+
 	    SL_RETURN( NULL, _("sh_tiger_hash_val"));
 	  }
@@ -268,6 +277,12 @@
     /* copy incomplete block
      */
-    j = 0; for (i = 0; i < 64; ++i) 
-      bbuf[i] = (sh_byte) '\0';
+    j = 0; 
+    for (i = 0; i < 64; i += 4) 
+      {
+	bbuf[i]   = (sh_byte) '\0';
+	bbuf[i+1] = (sh_byte) '\0';
+	bbuf[i+2] = (sh_byte) '\0';
+	bbuf[i+3] = (sh_byte) '\0';
+      }
     for (i = (count/64) * 64; i < count; ++i)
       /*@-usedef@*/bbuf[j++] = buffer[i];/*@+usedef@*/
@@ -304,5 +319,12 @@
 	sh.statistics.bytes_hashed += 64;
 	++nblocks; ncount = 0;
-        memset(bbuf, 0, 56 ); 
+	for (i = 0; i < 56; i += 4) 
+	  {
+	    bbuf[i]   = (sh_byte) '\0';
+	    bbuf[i+1] = (sh_byte) '\0';
+	    bbuf[i+2] = (sh_byte) '\0';
+	    bbuf[i+3] = (sh_byte) '\0';
+	  }
+        /* memset(bbuf, 0, 56 ); */ 
       }
 
@@ -327,8 +349,21 @@
 #endif
 
-    memset (bbuf,   0, 64);
-    memset (buffer, 0, PRIV_MAX);
-
-    (void) sh_unix_munlock( (char *) buffer, (PRIV_MAX) * sizeof(sh_byte));
+    for (i = 0; i < 64; i += 4) 
+      {
+	bbuf[i]   = (sh_byte) '\0';
+	bbuf[i+1] = (sh_byte) '\0';
+	bbuf[i+2] = (sh_byte) '\0';
+	bbuf[i+3] = (sh_byte) '\0';
+      }
+
+    bptr = buffer;
+
+    memcpy(bptr, bbuf,    64); bptr +=   64;
+    memcpy(bptr, bbuf,    64); bptr +=   64;
+    memcpy(bptr, buffer, 128); bptr +=  128;
+    memcpy(bptr, buffer, 256); bptr +=  256;
+    memcpy(bptr, buffer, 512); bptr +=  512;
+    memcpy(bptr, buffer,1024); bptr += 1024;
+    memcpy(bptr, buffer,2048);
 
     if (what == TIGER_FILE)
@@ -343,5 +378,4 @@
   if (what == TIGER_DATA && filename != NULL) 
     {
-      /* TPT((0, FIL__, __LINE__, _("msg=<TIGER_DATA>\n"))); */
       tiger(TIGER_CAST filename,  (sh_word32) Length, res); 
       SL_RETURN(res, _("sh_tiger_hash_val"));
@@ -1158,5 +1192,5 @@
   SL_TICKET  fd;
   char * tmp;
-  uid_t   euid;
+  uid_t  euid;
 
   unsigned long pages_read;
Index: /trunk/src/sh_unix.c
===================================================================
--- /trunk/src/sh_unix.c	(revision 7)
+++ /trunk/src/sh_unix.c	(revision 8)
@@ -1194,4 +1194,25 @@
   setrlimit (RLIMIT_NPROC,   &limits);
 #endif
+#ifdef RLIMIT_MEMLOCK
+  setrlimit (RLIMIT_MEMLOCK, &limits);
+#endif
+
+#if !defined(SL_DEBUG)
+  /* no core dumps
+   */
+  limits.rlim_cur = 0;
+  limits.rlim_max = 0;
+#ifdef RLIMIT_CORE
+  setrlimit (RLIMIT_CORE,    &limits);
+#endif
+#else
+#ifdef RLIMIT_CORE
+  setrlimit (RLIMIT_CORE,    &limits);
+#endif
+#endif
+
+  limits.rlim_cur = 1024;
+  limits.rlim_max = 1024;
+
 #if defined(RLIMIT_NOFILE)
   setrlimit (RLIMIT_NOFILE,  &limits);
@@ -1199,22 +1220,4 @@
   setrlimit (RLIMIT_OFILE,   &limits);
 #endif
-#ifdef RLIMIT_MEMLOCK
-  setrlimit (RLIMIT_MEMLOCK, &limits);
-#endif
-
-#if !defined(SL_DEBUG)
-  /* no core dumps
-   */
-  limits.rlim_cur = 0;
-  limits.rlim_max = 0;
-#ifdef RLIMIT_CORE
-  setrlimit (RLIMIT_CORE,    &limits);
-#endif
-#else
-#ifdef RLIMIT_CORE
-  setrlimit (RLIMIT_CORE,    &limits);
-#endif
-#endif
-
 
   SL_RET0(_("sh_unix_setlimits"));
@@ -2696,5 +2699,5 @@
   struct stat   fbuf;
   int           stat_return;
-  register int  i;
+
   ShFileType    type;
   unsigned int  mode;
@@ -2702,5 +2705,5 @@
   char        * tmp;
   char        * tmp2;
-  /* char        * p; */
+
   char        * linknamebuf;
   int           linksize;
@@ -2710,7 +2713,4 @@
   SL_TICKET     rval_open;
   int           fd;
-#if defined(__linux__)
-  int           fd_2;
-#endif
   int           fstat_return;
 
@@ -2738,7 +2738,12 @@
    */
   tstart = time(NULL);
+
   stat_return = retry_lstat (FIL__, __LINE__, 
 			     path /* theFile->fullpath */, &buf);
 
+  fd           = -1;
+  fstat_return = -1;
+  rval_open    = -1;
+
   if (stat_return == 0 && S_ISREG(buf.st_mode)) 
     {
@@ -2747,18 +2752,13 @@
       alert_timeout = 120; /* this is per 8K block now ! */
 
-      if (path[0] == '/' && path[1] == 'p' && path[2] == 'r' &&
-	  path[3] == 'o' && path[4] == 'c' && path[5] == '/')
+      if (path[1] == 'p' && path[5] == '/' && path[2] == 'r' &&
+	  path[3] == 'o' && path[4] == 'c' && path[0] == '/')
 	{
 	  /* seven is magic */
 	  alert_timeout = 7;
 	}
-    }
-  else
-    rval_open = -1;
-
-  if (SL_ISERROR(rval_open))
-    fd = -1;
-  else
-    fd = get_the_fd(rval_open);
+
+      fd = get_the_fd(rval_open);
+    }
 
   tend = time(NULL);
@@ -2774,17 +2774,10 @@
       SH_FREE(tmp2);
     }
+
+  if (fd >= 0) 
+    fstat_return = retry_fstat (FIL__, __LINE__, fd, &fbuf);
+  else
+    fd = -1;
       
-  if (fd >= 0) 
-    {
-      fstat_return = retry_fstat (FIL__, __LINE__, fd, &fbuf);
-    }
-  else
-    {
-      fstat_return = -1;
-      fd           = -1;
-    }
-#if defined(__linux__)
-  fd_2 = fd;
-#endif
 
   /* ---  case 1: lstat failed  --- 
@@ -2809,5 +2802,5 @@
     }
 
-  /* ---  case 2: not a regular file, or [IgnoreAll]  --- 
+  /* ---  case 2: not a regular file  --- 
    */
   else if (! S_ISREG(buf.st_mode))
@@ -2906,7 +2899,8 @@
   /* --- Determine file type. ---
    */
-  for (i = 0; i < 10; ++i) theFile->c_mode[i] = '-';
+  memset (theFile->c_mode, '-', 10);
   theFile->c_mode[10] = '\0';
-  for (i = 0; i < 11; ++i) theFile->link_c_mode[i] = '-';
+
+  memset (theFile->link_c_mode, '-', 10);
   theFile->link_c_mode[10] = '\0';
 
@@ -2918,5 +2912,5 @@
   /* --- Determine file attributes. ---
    */
-  for (i = 0; i < 12; ++i) theFile->c_attributes[i] = '-';
+  memset (theFile->c_attributes, '-', 12);
   theFile->c_attributes[12] = '\0';
   theFile->attributes      =    0;
@@ -2925,5 +2919,5 @@
       theFile->c_mode[0] != 'l' )
     sh_unix_getinfo_attr(theFile->fullpath, 
-			 &theFile->attributes, theFile->c_attributes, fd_2);
+			 &theFile->attributes, theFile->c_attributes, fd);
 
 #endif
Index: /trunk/src/slib.c
===================================================================
--- /trunk/src/slib.c	(revision 7)
+++ /trunk/src/slib.c	(revision 8)
@@ -566,12 +566,11 @@
 void *sl_memset(void *s, int c, size_t n)
 {
-  size_t i;
-  volatile char *p = s;
-
-  if (s == NULL || n <= 0)
-    return s;
-  
-  for (i = 0; i < n; ++i)
-    p[i] = (char) c;
+  volatile char *p = (char *) s;
+
+  if (s != NULL)
+    {
+      while (n--)
+	*p++ = c;
+    }
   return s;
 }
@@ -1673,8 +1672,10 @@
       fd = aud_open_noatime (FIL__, __LINE__, priv, filename, 
 			     O_RDONLY|O_NONBLOCK, 0, &o_noatime);
+      /*
       if (fd >= 0) {
 	sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
 	retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags & ~O_NONBLOCK);
       }
+      */
       if (fd < 0)
 	SL_IRETURN(SL_EBADFILE, _("sl_open_file"));
@@ -2081,4 +2082,25 @@
 }
 
+int sl_read_timeout_prep (SL_TICKET ticket)
+{
+  int fd;
+  int sflags;
+
+  SL_ENTER(_("sl_read_timeout_prep"));
+
+  if (SL_ISERROR(fd = get_the_fd(ticket)))
+    {
+      TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd));
+      SL_IRETURN(fd, _("sl_read_timeout_prep"));
+    }
+
+  /* set to non-blocking mode 
+   */
+  sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
+  retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags | O_NONBLOCK);
+
+  SL_IRETURN(SL_ENONE, _("sl_read_timeout_prep"));
+}
+  
 
 int sl_read_timeout (SL_TICKET ticket, void * buf_in, size_t count, 
@@ -2087,5 +2109,5 @@
   fd_set readfds;
   struct timeval tv;
-  int sflags;
+  /* int sflags; */
   int retval;
 
@@ -2100,27 +2122,19 @@
   extern volatile int sig_termfast;
  
-  if (count < 1)
-    {
-      TPT(( 0, FIL__, __LINE__, _("msg=<range error>")));
-      return(SL_ERANGE);
-    }
-  if (buf_in == NULL)
-    {
-      TPT(( 0, FIL__, __LINE__, _("msg=<null buffer>")));
-      return (SL_ENULL);
-    }
-
-  if (SL_ISERROR(fd = get_the_fd(ticket)))
-    {
-      TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd));
-      return (fd);
+  if (buf_in == NULL || SL_ISERROR(fd = get_the_fd(ticket)))
+    {
+      if (buf_in == NULL)
+	{
+	  TPT(( 0, FIL__, __LINE__, _("msg=<null buffer>")));
+	  return (SL_ENULL);
+	}
+      if (SL_ISERROR(fd = get_the_fd(ticket)))
+	{
+	  TPT(( 0, FIL__, __LINE__, _("msg=<ticket error> errno=<%d>"), fd));
+	  return (fd);
+	}
     }
 
   buf = (char *) buf_in;
-
-  /* set to non-blocking mode 
-   */
-  sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
-  retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags | O_NONBLOCK);
 
   tstart = time(NULL);
@@ -2129,26 +2143,6 @@
   while (count > 0)
     {
-
-      if (sig_termfast == 1) 
-	{
-	  retry_fcntl(FIL__, __LINE__, fd, F_SETFL, 
-		      sflags & ~O_NONBLOCK);
-	  return (SL_EREAD);
-	}
-	  
       FD_ZERO(&readfds);
       FD_SET(fd, &readfds);
-
-      if (tdiff >= timeout)
-	{
-	  retry_fcntl(FIL__, __LINE__, fd, F_SETFL, 
-		      sflags & ~O_NONBLOCK);
-	  return (SL_TIMEOUT);
-	}
-
-      /*
-      tnow  = time(NULL);
-      tdiff = tnow - tstart;
-      */
 
       tv.tv_sec  = timeout - tdiff;
@@ -2160,5 +2154,6 @@
 	{
 	  byteread = read (fd, buf, count);
-	  if (byteread != -1 && byteread != 0) 
+
+	  if (byteread > 0) 
 	    {
 	      bytes += byteread; count -= byteread;
@@ -2182,6 +2177,4 @@
 	      else
 		{
-		  retry_fcntl(FIL__, __LINE__, fd, F_SETFL, 
-			      sflags & ~O_NONBLOCK);
 		  return (SL_EREAD);
 		}
@@ -2197,19 +2190,25 @@
       else if (retval == 0)
 	{
-	  retry_fcntl(FIL__, __LINE__, fd, F_SETFL, 
-		      sflags & ~O_NONBLOCK);
 	  return (SL_TIMEOUT);
 	}
       else
 	{
-	  retry_fcntl(FIL__, __LINE__, fd, F_SETFL, 
-		      sflags & ~O_NONBLOCK);
 	  return (SL_EREAD);
 	}
+
+      if (sig_termfast == 1) 
+	{
+	  return (SL_EREAD);
+	}
+	  
       tnow  = time(NULL);
       tdiff = tnow - tstart;
-    }
-
-  retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags & ~O_NONBLOCK);
+
+      if (tdiff > timeout)
+	{
+	  return (SL_TIMEOUT);
+	}
+    }
+
   return ((int) bytes);
 }
