* as a service.
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/port/copydir.c,v 1.10 2004/12/31 22:03:53 pgsql Exp $
+ *   $PostgreSQL: pgsql/src/port/copydir.c,v 1.11 2005/03/24 02:11:20 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
        return -1;
    }
 
+   errno = 0;
    while ((xlde = readdir(xldir)) != NULL)
    {
        snprintf(fromfl, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
            FreeDir(xldir);
            return -1;
        }
+       errno = 0;
+   }
+#ifdef WIN32
+
+   /*
+    * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
+    * not in released version
+    */
+   if (GetLastError() == ERROR_NO_MORE_FILES)
+       errno = 0;
+#endif
+   if (errno)
+   {
+       ereport(WARNING,
+               (errcode_for_file_access(),
+                errmsg("could not read directory \"%s\": %m", fromdir)));
+       FreeDir(xldir);
+       return -1;
    }
 
    FreeDir(xldir);
 
  * Win32 (NT, Win2k, XP).  replace() doesn't work on Win95/98/Me.
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/port/dirmod.c,v 1.36 2005/02/22 04:43:16 momjian Exp $
+ *   $PostgreSQL: pgsql/src/port/dirmod.c,v 1.37 2005/03/24 02:11:20 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
    dir = opendir(path);
    if (dir == NULL)
+   {
+#ifndef FRONTEND
+       elog(WARNING, "could not open directory \"%s\": %m", path);
+#else
+       fprintf(stderr, _("could not open directory \"%s\": %s\n"),
+               path, strerror(errno));
+#endif
        return NULL;
+   }
 
    filenames = (char **) palloc(fnsize * sizeof(char *));
 
+   errno = 0;
    while ((file = readdir(dir)) != NULL)
    {
        if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
            }
            filenames[numnames++] = pstrdup(file->d_name);
        }
+       errno = 0;
+   }
+#ifdef WIN32
+
+   /*
+    * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
+    * not in released version
+    */
+   if (GetLastError() == ERROR_NO_MORE_FILES)
+       errno = 0;
+#endif
+   if (errno)
+   {
+#ifndef FRONTEND
+       elog(WARNING, "could not read directory \"%s\": %m", path);
+#else
+       fprintf(stderr, _("could not read directory \"%s\": %s\n"),
+               path, strerror(errno));
+#endif
    }
 
    filenames[numnames] = NULL;
 #ifndef FRONTEND
    elog(WARNING, "could not remove file or directory \"%s\": %m", filepath);
 #else
-   fprintf(stderr, _("could not remove file or directory \"%s\": %s\n"), filepath, strerror(errno));
+   fprintf(stderr, _("could not remove file or directory \"%s\": %s\n"),
+           filepath, strerror(errno));
 #endif
    fnames_cleanup(filenames);
    return false;