4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 12:29:32 +08:00

* fhandler.h (dirent_states): Add dirent_isroot, dirent_saw_cygdrive,

dirent_saw_dev.
* dir.cc (opendir): Don't zero __flags here.  Push that responsibility to
opendir methods.
(seekdir): Preserve dirent_isrrot in __flags.
(rewinddir): Ditto.
* fhandler_disk_file.cc (fhandler_disk_file::opendir): Set dirent_isroot
appropriately.
(fhandler_disk_file::readdir): Fill in "cygdrive" and "dev" if it is the root
dir and they are missing.
* fhandler_process.cc (fhandler_process::opendir): Set __flags here.
* fhandler_virtual.cc (fhandler_virtual::opendir): Set __flags here.
This commit is contained in:
Christopher Faylor 2005-08-19 16:18:42 +00:00
parent 82ef66c933
commit 358063ace3
6 changed files with 77 additions and 21 deletions

View File

@ -1,3 +1,18 @@
2005-08-19 Christopher Faylor <cgf@timesys.com>
* fhandler.h (dirent_states): Add dirent_isroot, dirent_saw_cygdrive,
dirent_saw_dev.
* dir.cc (opendir): Don't zero __flags here. Push that responsibility
to opendir methods.
(seekdir): Preserve dirent_isrrot in __flags.
(rewinddir): Ditto.
* fhandler_disk_file.cc (fhandler_disk_file::opendir): Set
dirent_isroot appropriately.
(fhandler_disk_file::readdir): Fill in "cygdrive" and "dev" if it is
the root dir and they are missing.
* fhandler_process.cc (fhandler_process::opendir): Set __flags here.
* fhandler_virtual.cc (fhandler_virtual::opendir): Set __flags here.
2005-08-19 Christopher Faylor <cgf@timesys.com>
* winsup.h (create_pipe): Declare new function.

View File

@ -59,7 +59,7 @@ opendir (const char *name)
}
if (res)
res->__flags = 0;
/* nothing */;
else if (fh)
delete fh;
return res;
@ -169,7 +169,7 @@ seekdir64 (DIR *dir, _off64_t loc)
if (dir->__d_cookie != __DIRENT_COOKIE)
return;
dir->__flags = 0;
dir->__flags &= dirent_isroot;
return ((fhandler_base *) dir->__fh)->seekdir (dir, loc);
}
@ -190,7 +190,7 @@ rewinddir (DIR *dir)
if (dir->__d_cookie != __DIRENT_COOKIE)
return;
dir->__flags = 0;
dir->__flags &= dirent_isroot;
return ((fhandler_base *) dir->__fh)->rewinddir (dir);
}

View File

@ -40,10 +40,13 @@ struct __acl32;
enum dirent_states
{
dirent_ok = 0,
dirent_saw_dot = 1,
dirent_saw_dot_dot = 2,
dirent_saw_eof = 4
dirent_ok = 0x0000,
dirent_saw_dot = 0x0001,
dirent_saw_dot_dot = 0x0002,
dirent_saw_eof = 0x0004,
dirent_isroot = 0x0008,
dirent_saw_cygdrive = 0x0010,
dirent_saw_dev = 0x0020
};
enum conn_state

View File

@ -1287,6 +1287,7 @@ fhandler_disk_file::opendir ()
DIR *dir;
DIR *res = NULL;
size_t len;
path_conv rootdir ("/");
if (!pc.isdir ())
set_errno (ENOTDIR);
@ -1332,7 +1333,7 @@ fhandler_disk_file::opendir ()
dir->__d_dirhash = get_namehash ();
res = dir;
dir->__flags = strcasematch (pc, rootdir) ? dirent_isroot : 0;
}
syscall_printf ("%p = opendir (%s)", res, get_name ());
@ -1370,15 +1371,36 @@ fhandler_disk_file::readdir (DIR *dir)
return res;
else if (!FindNextFileA (dir->__handle, &buf))
{
DWORD lasterr = GetLastError ();
FindClose (dir->__handle);
dir->__handle = INVALID_HANDLE_VALUE;
/* POSIX says you shouldn't set errno when readdir can't
find any more files; so, if another error we leave it set. */
if (lasterr != ERROR_NO_MORE_FILES)
seterrno_from_win_error (__FILE__, __LINE__, lasterr);
syscall_printf ("%p = readdir (%p)", res, dir);
return res;
bool added = false;
if (!(dir->__flags & dirent_isroot))
/* nothing */;
else if (!(dir->__flags & dirent_saw_dev))
{
strcpy (buf.cFileName, "dev");
added = true;
}
else if (!(dir->__flags & dirent_saw_cygdrive)
&& mount_table->cygdrive_len > 1)
{
strcpy (buf.cFileName, mount_table->cygdrive + 1);
buf.cFileName[mount_table->cygdrive_len - 2] = '\0';
added = true;
}
if (added)
buf.dwFileAttributes = 0;
else
{
DWORD lasterr = GetLastError ();
FindClose (dir->__handle);
dir->__handle = INVALID_HANDLE_VALUE;
/* POSIX says you shouldn't set errno when readdir can't
find any more files; so, if another error we leave it set. */
if (lasterr != ERROR_NO_MORE_FILES)
seterrno_from_win_error (__FILE__, __LINE__, lasterr);
syscall_printf ("%p = readdir (%p)", res, dir);
return res;
}
}
/* Check for Windows shortcut. If it's a Cygwin or U/WIN
@ -1403,11 +1425,22 @@ fhandler_disk_file::readdir (DIR *dir)
fnunmunge (dir->__d_dirent->d_name, buf.cFileName);
else
strcpy (dir->__d_dirent->d_name, buf.cFileName);
if (!(dir->__flags && dirent_isroot))
/* nothing */;
else
{
if (strcasematch (dir->__d_dirent->d_name, "dev"))
dir->__flags |= dirent_saw_dev;
if (strlen (dir->__d_dirent->d_name) == mount_table->cygdrive_len - 2
&& strncasematch (dir->__d_dirent->d_name, mount_table->cygdrive + 1,
mount_table->cygdrive_len - 2))
dir->__flags |= dirent_saw_cygdrive;
}
dir->__d_position++;
res = dir->__d_dirent;
syscall_printf ("%p = readdir (%p) (%s)",
&dir->__d_dirent, dir, buf.cFileName);
syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir,
buf.cFileName);
return res;
}

View File

@ -200,8 +200,12 @@ DIR *
fhandler_process::opendir ()
{
DIR *dir = fhandler_virtual::opendir ();
if (dir && fileid == PROCESS_FD)
fill_filebuf ();
if (dir)
{
if (fileid == PROCESS_FD)
fill_filebuf ();
dir->__flags = 0;
}
return dir;
}

View File

@ -84,6 +84,7 @@ fhandler_virtual::opendir ()
dir->__d_dirhash = get_namehash ();
dir->__flags = dirent_saw_dot | dirent_saw_dot_dot;
res = dir;
res->__flags = 0;
}
}