Index: fhandler_proc.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_proc.cc,v
retrieving revision 1.2
diff -u -3 -p -u -p -a -b -B -r1.2 fhandler_proc.cc
--- fhandler_proc.cc	3 May 2002 02:43:45 -0000	1.2
+++ fhandler_proc.cc	3 May 2002 11:52:15 -0000
@@ -92,7 +92,19 @@ fhandler_proc::get_proc_fhandler (const 
       if (p->pid == pid)
         return FH_PROCESS;
     }
+
+    bool has_subdir = false;
+    while (*path)
+            if (SLASH_P (*path++))
+                has_subdir = true;
+
+    if (has_subdir)
+        /* The user is trying to access a non-existent subdirectory of /proc. */
   return FH_BAD;
+    else
+        /* Return FH_PROC so that we can return EROFS if the user is trying to create
+           a file. */
+        return FH_PROC;
 }
 
 /* Returns 0 if path doesn't exist, >0 if path is a directory,
@@ -203,13 +215,13 @@ fhandler_proc::open (path_conv *pc, int 
 
   if (!*path)
     {
-      if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+      if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
         {
           set_errno (EEXIST);
           res = 0;
           goto out;
         }
-      else if (mode & O_WRONLY)
+      else if (flags & O_WRONLY)
         {
           set_errno (EISDIR);
           res = 0;
@@ -229,13 +241,13 @@ fhandler_proc::open (path_conv *pc, int 
         proc_file_no = i;
         if (proc_fhandlers[i] != FH_PROC)
           {
-            if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+            if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
               {
                 set_errno (EEXIST);
                 res = 0;
                 goto out;
               }
-            else if (mode & O_WRONLY)
+            else if (flags & O_WRONLY)
               {
                 set_errno (EISDIR);
                 res = 0;
@@ -251,7 +263,7 @@ fhandler_proc::open (path_conv *pc, int 
 
   if (proc_file_no == -1)
     {
-      if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+      if (flags & O_CREAT)
         {
           set_errno (EROFS);
           res = 0;
@@ -264,9 +276,9 @@ fhandler_proc::open (path_conv *pc, int 
           goto out;
         }
     }
-  if (mode & O_WRONLY)
+  if (flags & O_WRONLY)
     {
-      set_errno (EROFS);
+      set_errno (EACCES);
       res = 0;
       goto out;
     }
Index: fhandler_process.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_process.cc,v
retrieving revision 1.3
diff -u -3 -p -u -p -a -b -B -r1.3 fhandler_process.cc
--- fhandler_process.cc	3 May 2002 02:43:45 -0000	1.3
+++ fhandler_process.cc	3 May 2002 11:52:15 -0000
@@ -133,13 +133,13 @@ fhandler_process::open (path_conv *pc, i
 
   if (*path == 0)
     {
-      if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+      if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
         {
           set_errno (EEXIST);
           res = 0;
           goto out;
         }
-      else if (mode & O_WRONLY)
+      else if (flags & O_WRONLY)
         {
           set_errno (EISDIR);
           res = 0;
@@ -161,7 +161,7 @@ fhandler_process::open (path_conv *pc, i
     }
   if (process_file_no == -1)
     {
-      if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+      if (flags & O_CREAT)
         {
           set_errno (EROFS);
           res = 0;
@@ -174,9 +174,9 @@ fhandler_process::open (path_conv *pc, i
           goto out;
         }
     }
-  if (mode & O_WRONLY)
+  if (flags & O_WRONLY)
     {
-      set_errno (EROFS);
+      set_errno (EACCES);
       res = 0;
       goto out;
     }
Index: fhandler_registry.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_registry.cc,v
retrieving revision 1.2
diff -u -3 -p -u -p -a -b -B -r1.2 fhandler_registry.cc
--- fhandler_registry.cc	3 May 2002 02:43:45 -0000	1.2
+++ fhandler_registry.cc	3 May 2002 11:52:16 -0000
@@ -318,13 +318,13 @@ fhandler_registry::open (path_conv *pc, 
   path = get_name () + proc_len + 1 + registry_len;
   if (!*path)
     {
-      if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+      if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
         {
           set_errno (EEXIST);
           res = 0;
           goto out;
         }
-      else if (mode & O_WRONLY)
+      else if (flags & O_WRONLY)
         {
           set_errno (EISDIR);
           res = 0;
@@ -351,13 +351,13 @@ fhandler_registry::open (path_conv *pc, 
         if (path_prefix_p
             (registry_listing[i], path, strlen (registry_listing[i])))
           {
-            if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+            if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
               {
                 set_errno (EEXIST);
                 res = 0;
                 goto out;
               }
-            else if (mode & O_WRONLY)
+            else if (flags & O_WRONLY)
               {
                 set_errno (EISDIR);
                 res = 0;
@@ -370,7 +370,7 @@ fhandler_registry::open (path_conv *pc, 
               }
           }
 
-      if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
+      if (flags & O_CREAT)
         {
           set_errno (EROFS);
           res = 0;
@@ -384,15 +384,16 @@ fhandler_registry::open (path_conv *pc, 
         }
     }
 
-  hKey = open_key (path, KEY_READ, true);
-  if (hKey == (HKEY) INVALID_HANDLE_VALUE)
+  if (flags & O_WRONLY)
     {
+      set_errno (EACCES);
       res = 0;
       goto out;
     }
-  if (mode & O_WRONLY)
+
+  hKey = open_key (path, KEY_READ, true);
+  if (hKey == (HKEY) INVALID_HANDLE_VALUE)
     {
-      set_errno (EROFS);
       res = 0;
       goto out;
     }
Index: fhandler_virtual.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_virtual.cc,v
retrieving revision 1.2
diff -u -3 -p -u -p -a -b -B -r1.2 fhandler_virtual.cc
--- fhandler_virtual.cc	3 May 2002 02:43:45 -0000	1.2
+++ fhandler_virtual.cc	3 May 2002 11:52:17 -0000
@@ -133,6 +133,7 @@ int
 fhandler_virtual::dup (fhandler_base * child)
 {
   fhandler_virtual *fhproc_child = (fhandler_virtual *) child;
+  // FIXME: this is broken
   fhproc_child->filebuf = new char[filesize];
   fhproc_child->bufalloc = fhproc_child->filesize = filesize;
   fhproc_child->position = position;
@@ -176,7 +177,7 @@ fhandler_virtual::read (void *ptr, size_
 int
 fhandler_virtual::write (const void *ptr, size_t len)
 {
-  set_errno (EROFS);
+  set_errno (EACCES);
   return -1;
 }
 
Index: path.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/path.cc,v
retrieving revision 1.203
diff -u -3 -p -u -p -a -b -B -r1.203 path.cc
--- path.cc	3 May 2002 02:43:45 -0000	1.203
+++ path.cc	3 May 2002 11:52:27 -0000
@@ -525,13 +525,11 @@ path_conv::check (const char *src, unsig
               int file_type = fh->exists (path_copy);
               switch (file_type)
                 {
-                  case 0:
-                    error = ENOENT;
-		    break;
                   case 1:
                   case 2:
                     fileattr = FILE_ATTRIBUTE_DIRECTORY;
 		    break;
+                  default:
                   case -1:
                     fileattr = 0;
                 }
