+2005-05-13 Corinna Vinschen <corinna@vinschen.de>
+
+ * autoload.cc (WNetGetResourceParentA): Import.
+ (WNetOpenEnumA): Import.
+ (WNetEnumResourceA): Import.
+ (WNetCloseEnum): Import.
+ * fhandler.h (fhandler_netdrive::telldir): Add declaration.
+ (fhandler_netdrive::seekdir): Ditto.
+ (fhandler_netdrive::closedir): Ditto.
+ * fhandler_netdrive.cc: Drop explicit including windows.h. Include
+ winnetwk.h instead of shlwapi.h. Include dirent.h.
+ (fhandler_netdrive::readdir): Implement.
+ (fhandler_netdrive::telldir): New method.
+ (fhandler_netdrive::seekdir): New method.
+ (fhandler_netdrive::closedir): Ditto.
+
2005-05-13 Christopher Faylor <cgf@timesys.com>
Remove PC_FULL from path_conv usage throughout.
LoadDLLfuncEx (waveInClose, 4, winmm, 1)
LoadDLLfunc (WNetGetResourceInformationA, 16, mpr)
+LoadDLLfunc (WNetGetResourceParentA, 12, mpr)
+LoadDLLfunc (WNetOpenEnumA, 20, mpr)
+LoadDLLfunc (WNetEnumResourceA, 16, mpr)
+LoadDLLfunc (WNetCloseEnum, 4, mpr)
LoadDLLfuncEx (UuidCreate, 4, rpcrt4, 1)
LoadDLLfuncEx (UuidCreateSequential, 4, rpcrt4, 1)
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
-#include <windows.h>
#include "winsup.h"
#include <unistd.h>
#include <stdlib.h>
#include "dtable.h"
#include "cygheap.h"
#include <assert.h>
-#include <shlwapi.h>
+#include <winnetwk.h>
+
+#include <dirent.h>
/* Returns 0 if path doesn't exist, >0 if path is a directory,
-1 if path is a file, -2 if it's a symlink. */
}
struct dirent *
-fhandler_netdrive::readdir (DIR * dir)
+fhandler_netdrive::readdir (DIR *dir)
+{
+ DWORD size;
+ NETRESOURCE *nro;
+ DWORD ret;
+
+ if (!dir->__d_position)
+ {
+ size_t len = strlen (get_name ());
+ char *namebuf, *dummy;
+ NETRESOURCE nr = { 0 }, *nro2;
+
+ if (len == 2) /* // */
+ {
+ namebuf = (char *) alloca (MAX_COMPUTERNAME_LENGTH + 3);
+ strcpy (namebuf, "\\\\");
+ size = MAX_COMPUTERNAME_LENGTH + 1;
+ if (!GetComputerName (namebuf + 2, &size))
+ {
+ __seterrno ();
+ return NULL;
+ }
+ }
+ else
+ {
+ const char *from;
+ char *to;
+ namebuf = (char *) alloca (len + 1);
+ for (to = namebuf, from = get_name (); *from; to++, from++)
+ *to = (*from == '/') ? '\\' : *from;
+ *to = '\0';
+ }
+
+ nr.lpRemoteName = namebuf;
+ nr.dwType = RESOURCETYPE_DISK;
+ size = 4096;
+ nro = (NETRESOURCE *) alloca (size);
+ ret = WNetGetResourceInformation (&nr, nro, &size, &dummy);
+ if (ret != NO_ERROR)
+ {
+ __seterrno ();
+ return NULL;
+ }
+
+ if (len == 2)
+ {
+ nro2 = nro;
+ size = 4096;
+ nro = (NETRESOURCE *) alloca (size);
+ ret = WNetGetResourceParent (nro2, nro, &size);
+ if (ret != NO_ERROR)
+ {
+ __seterrno ();
+ return NULL;
+ }
+ }
+ ret = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0,
+ nro, &dir->__handle);
+ if (ret != NO_ERROR)
+ {
+ __seterrno ();
+ dir->__handle = INVALID_HANDLE_VALUE;
+ return NULL;
+ }
+ }
+ /* FIXME: dot and dot_dot handling */
+ DWORD cnt = 1;
+ size = 16384; /* As documented in MSDN. */
+ nro = (NETRESOURCE *) alloca (size);
+ ret = WNetEnumResource (dir->__handle, &cnt, nro, &size);
+ if (ret != NO_ERROR)
+ {
+ if (ret != ERROR_NO_MORE_ITEMS)
+ __seterrno ();
+ return NULL;
+ }
+ dir->__d_position++;
+ char *bs = strrchr (nro->lpRemoteName, '\\');
+ strcpy (dir->__d_dirent->d_name, bs ? bs + 1 : nro->lpRemoteName);
+ return dir->__d_dirent;
+}
+
+_off64_t
+fhandler_netdrive::telldir (DIR *dir)
+{
+ return -1;
+}
+
+void
+fhandler_netdrive::seekdir (DIR *, _off64_t)
+{
+}
+
+int
+fhandler_netdrive::closedir (DIR *dir)
{
- return NULL;
+ if (dir->__handle != INVALID_HANDLE_VALUE)
+ WNetCloseEnum (dir->__handle);
+ dir->__handle = INVALID_HANDLE_VALUE;
+ return fhandler_virtual::closedir (dir);
}
int