Index: trunk/src/sh_cat.c
===================================================================
--- trunk/src/sh_cat.c	(revision 190)
+++ trunk/src/sh_cat.c	(revision 192)
@@ -183,5 +183,5 @@
   { MSG_FI_NOGRP,    SH_ERR_ERR,     FIL,   N_("interface=\"getgrgid\" msg=\"No such group\" group=\"%ld\" path=\"%s\"")},
   { MSG_FI_NOUSR,    SH_ERR_ERR,     FIL,   N_("interface=\"getpwuid\" msg=\"No such user\" userid=\"%ld\" path=\"%s\"")},
-  { MSG_FI_LSTAT,    SH_ERR_ERR,     FIL,   N_("interface=\"lstat\" msg=\"%s\" path=\"%s\"")},
+  { MSG_FI_STAT,     SH_ERR_ERR,     FIL,   N_("interface=\"%s\" msg=\"%s\" userid=\"%ld\" path=\"%s\"")},
   { MSG_FI_OBSC,     SH_ERR_ERR,     FIL,   N_("msg=\"Weird filename\" path=\"%s\"")},
   { MSG_FI_OBSC2,    SH_ERR_ERR,     FIL,   N_("msg=\"Weird filename\" path=\"%s/%s\"")},
@@ -271,5 +271,5 @@
   { MSG_E_HASH,      SH_ERR_ERR,     ERR,   N_("msg=\"Incorrect checksum\" path=\"%s\"")},
   { MSG_E_ACCESS,    SH_ERR_ERR,     ERR,   N_("msg=\"File not accessible\" userid=\"%ld\" path=\"%s\"")},
-  { MSG_E_READ,      SH_ERR_ERR,     ERR,   N_("msg=\"Not accessible or not a regular file\" path=\"%s\"")},
+  { MSG_E_READ,      SH_ERR_ERR,     ERR,   N_("msg=\"Not accessible or not a regular file (%s / %s)\" path=\"%s\"")},
   { MSG_E_NOTREG,    SH_ERR_ERR,     ERR,   N_("msg=\"Not a regular file\" path=\"%s\"")},
   { MSG_E_TIMEOUT,   SH_ERR_ERR,     ERR,   N_("msg=\"Timeout (%d sec) while checksumming file\" path=\"%s\"")},
@@ -512,5 +512,5 @@
   { MSG_FI_NOGRP,    SH_ERR_ERR,     FIL,   N_("msg=<No such group>, interface=<getgrgid>, group=<%ld>, path=<%s>")},
   { MSG_FI_NOUSR,    SH_ERR_ERR,     FIL,   N_("msg=<No such user>, interface=<getpwuid>, userid=<%ld>, path=<%s>")},
-  { MSG_FI_LSTAT,    SH_ERR_ERR,     FIL,   N_("msg=<%s>, interface=<lstat>, path=<%s>")},
+  { MSG_FI_STAT,     SH_ERR_ERR,     FIL,   N_("interface=<%s>, msg=<%s>, userid=<%ld>, path=<%s>")},
   { MSG_FI_OBSC,     SH_ERR_ERR,     FIL,   N_("msg=<Weird filename>, path=<%s>")},
   { MSG_FI_OBSC2,    SH_ERR_ERR,     FIL,   N_("msg=<Weird filename>, path=<%s/%s>")},
@@ -599,5 +599,5 @@
   { MSG_E_HASH,      SH_ERR_ERR,     ERR,   N_("msg=<Incorrect checksum>, path=<%s>")},
   { MSG_E_ACCESS,    SH_ERR_ERR,     ERR,   N_("msg=<File not accessible>, userid=<%ld>, path=<%s>")},
-  { MSG_E_READ,      SH_ERR_ERR,     ERR,   N_("msg=<Not accessible or not a regular file>, path=<%s>")},
+  { MSG_E_READ,      SH_ERR_ERR,     ERR,   N_("msg=<Not accessible or not a regular file (%s / %s)>, path=<%s>")},
   { MSG_E_NOTREG,    SH_ERR_ERR,     ERR,   N_("msg=<Not a regular file>, path=<%s>")},
   { MSG_E_TIMEOUT,   SH_ERR_ERR,     ERR,   N_("msg=<Timeout (%d sec) while checksumming file>, path=<%s>")},
Index: trunk/src/sh_kern.c
===================================================================
--- trunk/src/sh_kern.c	(revision 190)
+++ trunk/src/sh_kern.c	(revision 192)
@@ -487,4 +487,5 @@
   if (kmap == MAP_FAILED)
     {
+      memset(buf, '\0', len);
       return -1;
     }
@@ -593,13 +594,15 @@
 	      (sh.flag.update == S_TRUE))
 	    {
-	      sh_kern_read_data (kd, kmem_call_table[j], 
-				 (unsigned char *) &(kmem_code_table[j][0]),
-				 2 * sizeof(unsigned int));
+	      if (sh_kern_read_data (kd, kmem_call_table[j], 
+				     (unsigned char *) &(kmem_code_table[j][0]),
+				     2 * sizeof(unsigned int)))
+		status = -3;
 	    }
 	  else
 	    {
-	      sh_kern_read_data (kd, sh_syscalls[j].addr, 
-				 (unsigned char *) &(kmem_code_table[j][0]),
-				 2 * sizeof(unsigned int));
+	      if (sh_kern_read_data (kd, sh_syscalls[j].addr, 
+				     (unsigned char *) &(kmem_code_table[j][0]),
+				     2 * sizeof(unsigned int)))
+		status = -4;
 	    }
 	}
@@ -621,6 +624,7 @@
       
       memset(sh_idt_table, '\0', SH_MAXIDT*8);
-      sh_kern_read_data (kd, idt_addr, 
-			 (unsigned char *) sh_idt_table, idt_size*8);
+      if (sh_kern_read_data (kd, idt_addr, 
+			     (unsigned char *) sh_idt_table, idt_size*8))
+	status = -5;
     }
 
@@ -633,6 +637,8 @@
   if(status == 0)
     {
-      sh_kern_read_data (kd, system_call_addr, 
-			 (unsigned char *) new_system_call_code, SH_KERN_SCC);
+      if (sh_kern_read_data (kd, system_call_addr, 
+			     (unsigned char *) new_system_call_code, 
+			     SH_KERN_SCC))
+	status = -6;
     }
   
@@ -643,10 +649,12 @@
   if(status == 0)
     {
-      sh_kern_read_data (kd, proc_root, 
-			 (unsigned char *) &proc_root_dir, 
-			 sizeof(proc_root_dir));
-      sh_kern_read_data (kd, proc_root_iops, 
-			 (unsigned char *) &proc_root_inode, 
-			 sizeof(proc_root_inode));
+      if (sh_kern_read_data (kd, proc_root, 
+			     (unsigned char *) &proc_root_dir, 
+			     sizeof(proc_root_dir)))
+	status = -7;
+      if (sh_kern_read_data (kd, proc_root_iops, 
+			     (unsigned char *) &proc_root_inode, 
+			     sizeof(proc_root_inode)))
+	status = -8;
     }
   
@@ -654,26 +662,26 @@
    * Write out data to the pipe
    */
-  if(status == 0)
-    {
-      status = write(mpipe[1], &kmem_call_table, sizeof(kmem_call_table));
-
-      if(status > 0)
-	status = write(mpipe[1], &kmem_code_table, sizeof(kmem_code_table));
-
-      if(status > 0)
-	status = write(mpipe[1], &sh_idt_table, sizeof(sh_idt_table));
-
-      if(status > 0)
-	status = write(mpipe[1], new_system_call_code, SH_KERN_SCC);
-
-      if(status > 0)
-	status = write(mpipe[1], &proc_root_dir, sizeof(proc_root_dir));
-
-      if(status > 0)
-	status = write(mpipe[1], &proc_root_inode, sizeof(proc_root_inode));
-    }
+  status = write(mpipe[1], &status, sizeof(int));
+
+  if (status > 0)
+    status = write(mpipe[1], &kmem_call_table, sizeof(kmem_call_table));
+  
+  if(status > 0)
+    status = write(mpipe[1], &kmem_code_table, sizeof(kmem_code_table));
+  
+  if(status > 0)
+    status = write(mpipe[1], &sh_idt_table, sizeof(sh_idt_table));
+  
+  if(status > 0)
+    status = write(mpipe[1], new_system_call_code, SH_KERN_SCC);
+  
+  if(status > 0)
+    status = write(mpipe[1], &proc_root_dir, sizeof(proc_root_dir));
+  
+  if(status > 0)
+    status = write(mpipe[1], &proc_root_inode, sizeof(proc_root_inode));
+
   _exit( (status >= 0) ? 0 : status);
 }
-
 
 struct sh_kernel_info {
@@ -693,4 +701,5 @@
   int  status;
   long size;
+  int  errcode;
 
   /* Close reading side of pipe, and wait some milliseconds
@@ -699,10 +708,21 @@
   retry_msleep (0, ShKernDelay); /* milliseconds */
 
-  size = SH_KERN_SIZ * sizeof(unsigned long);
-
-  if (size != read(mpipe[0], &(kinfo->kmem_call_table), size))
-    status = -4;
+  if (sizeof(int) != read(mpipe[0], &errcode, sizeof(int)))
+    status = -3;
   else
     status = 0;
+
+  if (errcode)
+    status = errcode - 100;
+
+  if(status == 0)
+    {
+      size = SH_KERN_SIZ * sizeof(unsigned long);
+
+      if (size != read(mpipe[0], &(kinfo->kmem_call_table), size))
+	status = -4;
+      else
+	status = 0;
+    }
 
   if(status == 0)
@@ -1355,6 +1375,9 @@
   if ( status < 0)
     {
+      char errmsg[SH_ERRBUF_SIZE];
+      sl_snprintf(errmsg, SH_ERRBUF_SIZE, 
+		  _("error reading from /dev/kmem: %d"), status);
       sh_error_handle ((-1), FIL__, __LINE__, status, MSG_E_SUBGEN,
-		       _("error reading from /dev/kmem"),
+		       errmsg,
 		       _("kern_check_internal") );
       SL_RETURN( (-1), _("sh_kern_check_internal"));
Index: trunk/src/sh_prelink.c
===================================================================
--- trunk/src/sh_prelink.c	(revision 190)
+++ trunk/src/sh_prelink.c	(revision 192)
@@ -124,6 +124,10 @@
   if (SL_ISERROR(ticket))
     {
+      char errbuf[SH_ERRBUF_SIZE];
+      char errbuf2[SH_ERRBUF_SIZE];
+      sh_error_message(errno, errbuf2, sizeof(errbuf2));
+      sl_strlcpy(errbuf, sl_error_string(ticket), sizeof(errbuf));
       tmp = sh_util_safe_name (task->command);
-      sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, ticket, MSG_E_READ, tmp);
+      sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, ticket, MSG_E_READ, errbuf, errbuf2, tmp);
       SH_FREE(tmp);
       return;
Index: trunk/src/sh_tiger0.c
===================================================================
--- trunk/src/sh_tiger0.c	(revision 190)
+++ trunk/src/sh_tiger0.c	(revision 192)
@@ -223,4 +223,6 @@
 	if (SL_ISERROR (count)) 
 	  {
+	    int error = errno;
+
 	    if (sig_termfast == 1) {
 	      sh_unix_munlock((char *)buffer, (PRIV_MAX)*sizeof(sh_byte));
@@ -239,6 +241,12 @@
 	      }
 	    else
-	      sh_error_handle (ShDFLevel[SH_ERR_T_FILE], FIL__, __LINE__, 
-			       count, MSG_E_READ, tmp);
+	      {
+		char errbuf[SH_ERRBUF_SIZE];
+		char errbuf2[SH_ERRBUF_SIZE];
+		sl_strlcpy(errbuf, sl_error_string(count), sizeof(errbuf));
+		sh_error_message(error, errbuf2, sizeof(errbuf2));
+		sh_error_handle (ShDFLevel[SH_ERR_T_FILE], FIL__, __LINE__, 
+				 count, MSG_E_READ, errbuf, errbuf2, tmp);
+	      }
 	    SH_FREE(tmp);
 	    memset (bbuf,   0, 64);
@@ -894,4 +902,6 @@
       if (SL_ISERROR (n))
 	{
+	  int error = errno;
+
 	  if (sig_termfast == 1)
 	    {
@@ -909,6 +919,12 @@
 	    }
 	  else
-	    sh_error_handle (ShDFLevel[SH_ERR_T_FILE], FIL__, __LINE__, n,
-			     MSG_E_READ, tmp);
+	    {
+	      char errbuf[SH_ERRBUF_SIZE];
+	      char errbuf2[SH_ERRBUF_SIZE];
+	      sl_strlcpy(errbuf, sl_error_string(n), sizeof(errbuf));
+	      sh_error_message(error, errbuf2, sizeof(errbuf2));
+	      sh_error_handle (ShDFLevel[SH_ERR_T_FILE], FIL__, __LINE__, n,
+			       MSG_E_READ, errbuf, errbuf2, tmp);
+	    }
 	  SH_FREE(tmp);
 	  *Length = 0;
@@ -1424,4 +1440,6 @@
       if (SL_ISERROR (n))
 	{
+	  int error = errno;
+
 	  if (sig_termfast == 1)
 	    {
@@ -1441,6 +1459,10 @@
 	  else 
 	    {
+	      char errbuf[SH_ERRBUF_SIZE];
+	      char errbuf2[SH_ERRBUF_SIZE];
+	      sl_strlcpy(errbuf, sl_error_string(n), sizeof(errbuf));
+	      sh_error_message(error, errbuf2, sizeof(errbuf2));
 	      sh_error_handle (ShDFLevel[SH_ERR_T_FILE], FIL__, __LINE__, n,
-			       MSG_E_READ, tmp);
+			       MSG_E_READ, errbuf, errbuf2, tmp);
 	    }
 	  SH_FREE(tmp);
Index: trunk/src/sh_unix.c
===================================================================
--- trunk/src/sh_unix.c	(revision 190)
+++ trunk/src/sh_unix.c	(revision 192)
@@ -3281,4 +3281,5 @@
   struct stat   fbuf;
   int           stat_return;
+  int           stat_errno = 0;
 
   ShFileType    type;
@@ -3293,6 +3294,10 @@
 
   SL_TICKET     rval_open;
+  int           err_open = 0;
+
   int           fd;
   int           fstat_return;
+  int           fstat_errno = 0;
+
   sh_string   * content = NULL;
       
@@ -3316,4 +3321,7 @@
 			     path /* theFile->fullpath */, &buf);
 
+  if (stat_return)
+    stat_errno = errno;
+
   fd           = -1;
   fstat_return = -1;
@@ -3325,4 +3333,6 @@
     {
       rval_open = sl_open_fastread (path /* theFile->fullpath */, SL_YESPRIV);
+      if (SL_ISERROR(rval_open))
+	err_open = errno;
 
       alert_timeout = 120; /* this is per 8K block now ! */
@@ -3352,7 +3362,13 @@
 
   if (fd >= 0) 
-    fstat_return = retry_fstat (FIL__, __LINE__, fd, &fbuf);
+    {
+      fstat_return = retry_fstat (FIL__, __LINE__, fd, &fbuf);
+      if (fstat_return)
+	fstat_errno = errno;
+    }
   else
-    fd = -1;
+    {
+      fd = -1;
+    }
       
 
@@ -3370,7 +3386,11 @@
 	  if (S_FALSE == sh_ignore_chk_del(theFile->fullpath)) {
 	    char errbuf[SH_ERRBUF_SIZE];
+	    uid_t euid;
+	    (void) sl_get_euid(&euid);
 	    tmp2 = sh_util_safe_name (theFile->fullpath);
-	    sh_error_handle (level, FIL__, __LINE__, stat_return, MSG_FI_LSTAT,
-			     sh_error_message (stat_return, errbuf, sizeof(errbuf)), 
+	    sh_error_handle (level, FIL__, __LINE__, stat_return, MSG_FI_STAT,
+			     _("lstat"),
+			     sh_error_message (stat_errno, errbuf, sizeof(errbuf)),
+			     (long) euid,
 			     tmp2);
 	    SH_FREE(tmp2);
@@ -3500,8 +3520,8 @@
    */
 
-  else    /* fstat_return != 0 or !S_ISREG(fbuf.st_mode) */
+  else    /* fstat_return != 0 or !S_ISREG(fbuf.st_mode) or open() failed */
     {
       uid_t   euid;
-      int fstat_errval = errno;
+
       if (fileHash != NULL)
 	sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1);
@@ -3513,17 +3533,26 @@
 	  if (fstat_return != 0)
 	    {
+	      char errbuf[SH_ERRBUF_SIZE];
 	      (void) sl_get_euid(&euid);
-	      sh_error_handle (level, FIL__, __LINE__, fstat_errval, 
-			       MSG_E_ACCESS, (long) euid, tmp2);
+
+	      sh_error_handle (level, FIL__, __LINE__, stat_return, MSG_FI_STAT,
+			       _("fstat"),
+			       sh_error_message (fstat_errno, errbuf, sizeof(errbuf)),
+			       (long) euid,
+			       tmp2);
 	    }
 	  else if (!S_ISREG(fbuf.st_mode))
 	    {
-	      sh_error_handle (level, FIL__, __LINE__, fstat_errval, 
+	      sh_error_handle (level, FIL__, __LINE__, fstat_errno, 
 			       MSG_E_NOTREG, tmp2);
 	    }
 	  else
 	    {
-	      sh_error_handle (level, FIL__, __LINE__, fstat_errval, 
-			       MSG_E_READ, tmp2);
+	      char errbuf[SH_ERRBUF_SIZE];
+	      char errbuf2[SH_ERRBUF_SIZE];
+	      sl_strlcpy(errbuf, sl_error_string(rval_open), sizeof(errbuf));
+	      sh_error_message(err_open, errbuf2, sizeof(errbuf2));
+	      sh_error_handle (level, FIL__, __LINE__, err_open, 
+			       MSG_E_READ, errbuf, errbuf2, tmp2);
 	    }
 	  SH_FREE(tmp2);
@@ -3737,8 +3766,13 @@
 	  if (stat_return != ENOENT)
 	    { 
+	      uid_t euid;
 	      char errbuf[SH_ERRBUF_SIZE];
+
+	      (void) sl_get_euid(&euid);
 	      sh_error_handle (level, FIL__, __LINE__, stat_return, 
-			       MSG_FI_LSTAT,
+			       MSG_FI_STAT,
+			       _("lstat"),
 			       sh_error_message (stat_return,errbuf, sizeof(errbuf)), 
+			       (long) euid,
 			       tmp2);
 	    }
Index: trunk/src/slib.c
===================================================================
--- trunk/src/slib.c	(revision 190)
+++ trunk/src/slib.c	(revision 192)
@@ -1700,4 +1700,5 @@
   struct stat   lbuf;
   struct stat   buf;
+  int           errval = 0;
   int           lstat_return;
   int           stat_return;
@@ -1750,4 +1751,5 @@
   else
     lstat_return = retry_lstat(FIL__, __LINE__, filename, &lbuf);
+  errval = errno;
 #ifdef USE_SUID
   if (priv == SL_YESPRIV)
@@ -1759,9 +1761,10 @@
       lstat_return = ENOENT;
       if ( (mode == SL_OPEN_FOR_READ && lstat_return == ENOENT) ||
-	   (errno != ENOENT))
+	   (errval != ENOENT))
 	{
 	  TPT(( 0, FIL__, __LINE__, _("msg=<lstat: %s> errno=<%d>\n"), 
-	    filename, errno));
-	  SL_IRETURN(SL_EBADFILE, _("sl_open_file"));
+	    filename, errval));
+	  errno = errval;
+	  SL_IRETURN(SL_ESTAT, _("sl_open_file"));
 	}
     }
@@ -1770,6 +1773,9 @@
        ( S_ISDIR(lbuf.st_mode) || (S_IWOTH & lbuf.st_mode) ) 
       )
-    SL_IRETURN(SL_EBADFILE, _("sl_open_file"));
-
+    {
+      int retval = S_ISDIR(lbuf.st_mode) ? SL_EISDIR : SL_EBADOTH;
+      errno = 0;
+      SL_IRETURN(retval, _("sl_open_file"));
+    }
     
   /* O_NOATIME has an effect for read(). But write() ?.
@@ -1780,4 +1786,5 @@
       fd = aud_open_noatime (FIL__, __LINE__, priv, filename, 
 			     O_RDONLY|O_NONBLOCK, 0, &o_noatime);
+      errval = errno;
       if (fd >= 0) {
 	sflags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
@@ -1792,19 +1799,27 @@
 	fd = aud_open (FIL__, __LINE__, priv, filename, 
 		       O_WRONLY,                   open_mode);
+      errval = errno;
       break;
     case SL_OPEN_SAFE_RDWR:
       if (lstat_return == ENOENT)
-      	fd = aud_open (FIL__, __LINE__, priv, filename, 
-		       O_RDWR|O_CREAT|O_EXCL,      open_mode);
+	{
+	  fd = aud_open (FIL__, __LINE__, priv, filename, 
+			 O_RDWR|O_CREAT|O_EXCL,      open_mode);
+	  errval = errno;
+	}
       else
-	SL_IRETURN(SL_EBADFILE, _("sl_open_file"));
+	{
+	  errno = errval;
+	  SL_IRETURN(SL_EBADFILE, _("sl_open_file"));
+	}
       break;
     case SL_OPEN_FOR_RDWR:
       if (lstat_return == ENOENT)
-      	fd = aud_open (FIL__, __LINE__, priv, filename, 
-		       O_RDWR|O_CREAT|O_EXCL,      open_mode);
+	fd = aud_open (FIL__, __LINE__, priv, filename, 
+			 O_RDWR|O_CREAT|O_EXCL,      open_mode);
       else
 	fd = aud_open (FIL__, __LINE__, priv, filename, 
 		       O_RDWR,                     open_mode);
+      errval = errno;
       break;
     case SL_OPEN_FOR_WTRUNC:
@@ -1815,4 +1830,5 @@
 	fd = aud_open (FIL__, __LINE__, priv, filename, 
 		       O_WRONLY|O_TRUNC,           open_mode);
+      errval = errno;
       break;
     case SL_OPEN_FOR_RWTRUNC:
@@ -1823,6 +1839,8 @@
 	fd = aud_open (FIL__, __LINE__, priv, filename, 
 		       O_RDWR|O_TRUNC,             open_mode);
+      errval = errno;
       break;
     default:
+      errno = 0;
       SL_IRETURN(SL_EINTERNAL, _("sl_open_file"));
     }
@@ -1831,5 +1849,6 @@
     {
       TPT(( 0, FIL__, __LINE__, _("msg=<Error opening: %s> errno=<%d>\n"), 
-	    filename, errno));
+	    filename, errval));
+      errno = errval;
       SL_IRETURN(SL_EBADFILE, _("sl_open_file"));
     }
@@ -1840,4 +1859,5 @@
 #endif
   stat_return = retry_fstat(FIL__, __LINE__, fd, &buf);
+  errval = errno;
 #ifdef USE_SUID
   if (priv == SL_YESPRIV)
@@ -1848,6 +1868,9 @@
     {
       close (fd);
-      SL_IRETURN(SL_EBADFILE, _("sl_open_file"));
-    }
+      errno = errval;
+      SL_IRETURN(SL_EFSTAT, _("sl_open_file"));
+    }
+
+  errno = 0;
 
   if (lstat_return != ENOENT && buf.st_ino != lbuf.st_ino)
@@ -2221,4 +2244,5 @@
   /* int sflags; */
   int retval;
+  int error;
 
   int    byteread = 0;
@@ -2280,7 +2304,9 @@
 	      else
 		{
+		  error = errno;
 		  if (is_nonblocking == SL_FALSE)
 		      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 		  TPT(( 0, FIL__, __LINE__, _("msg=<read error>")));
+		  errno = error;
 		  return (SL_EREAD);
 		}
@@ -2299,11 +2325,14 @@
 	      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 	  TPT(( 0, FIL__, __LINE__, _("msg=<timeout>")));
+	  errno = 0;
 	  return (SL_TIMEOUT);
 	}
       else
 	{
+	  error = errno;
 	  if (is_nonblocking == SL_FALSE)
 	      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 	  TPT(( 0, FIL__, __LINE__, _("msg=<timeout>")));
+	  errno = error;
 	  return (SL_EREAD);
 	}
@@ -2314,4 +2343,5 @@
 	      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 	  TPT(( 0, FIL__, __LINE__, _("msg=<terminated>")));
+	  errno = 0;
 	  return (SL_EREAD);
 	}
@@ -2325,4 +2355,5 @@
 	      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
 	  TPT(( 0, FIL__, __LINE__, _("msg=<timeout>")));
+	  errno = 0;
 	  return (SL_TIMEOUT);
 	}
@@ -2544,4 +2575,5 @@
 char * sl_error_string(int errorcode)
 {
+
   switch (errorcode)
     {
@@ -2579,4 +2611,6 @@
     case SL_EBADOTH:
       return _("World writeable.");
+    case SL_EISDIR:
+      return _("Is a directory.");
     case SL_EBADFILE:
       return _("File access error.");
@@ -2588,4 +2622,6 @@
     case SL_ESTAT:
       return _("stat() failed.");
+    case SL_EFSTAT:
+      return _("fstat() failed.");
     default:
       return _("Unknown error.");
Index: trunk/src/trustfile.c
===================================================================
--- trunk/src/trustfile.c	(revision 190)
+++ trunk/src/trustfile.c	(revision 192)
@@ -1008,4 +1008,11 @@
 
 #ifdef TRUST_MAIN
+
+#if defined(HOST_IS_CYGWIN) || defined(__cygwin__) || defined(__CYGWIN32__) || defined(__CYGWIN__)
+int main()
+{
+  return 0;
+}
+#else
 int main (int argc, char * argv[])
 {
@@ -1045,5 +1052,6 @@
 }
 #endif
-
-
-
+#endif
+
+
+
