* include/sys/dirent.h (dirent): Remvoe old_d_ino.
(DIR): Make __d_dirhash a 64 bit value. Remove __d_data and __d_u. Add
__flags.
* dir.cc (opendir_states): New enum.
(opendir): Clear new DIR __flags field.
(readdir): Fill in '.' and '..' entries if we hit EOF and we haven't seen them
already. Nuke setting of old_d_ino.
(rewinddir): Reset DIR __flags field.
(seekdir64): Ditto.
* fhandler_disk_file.cc (fhandler_cygdrive::fhandler_cygdrive): Remove special
handling of "." and ".." since they are now handled automatically.
2003-09-07 Christopher Faylor <cgf@redhat.com>
+ Throughout, remove __d_u.__d_data fields from DIR structure.
+ * include/sys/dirent.h (dirent): Remvoe old_d_ino.
+ (DIR): Make __d_dirhash a 64 bit value. Remove __d_data and __d_u.
+ Add __flags.
+ * dir.cc (opendir_states): New enum.
+ (opendir): Clear new DIR __flags field.
+ (readdir): Fill in '.' and '..' entries if we hit EOF and we haven't
+ seen them already. Nuke setting of old_d_ino.
+ (rewinddir): Reset DIR __flags field.
+ (seekdir64): Ditto.
+ * fhandler_disk_file.cc (fhandler_cygdrive::fhandler_cygdrive): Remove
+ special handling of "." and ".." since they are now handled
+ automatically.
+
+2003-09-07 Christopher Faylor <cgf@redhat.com>
+
* include/cygwin/in.h: Don't define ipv6 stuff unless we call for it
specifically since it isn't really implemented yet.
return dir->__d_dirent->d_fd;
}
+enum opendir_states
+{
+ opendir_ok = 0,
+ opendir_saw_dot = 1,
+ opendir_saw_dot_dot = 2,
+ opendir_saw_eof = 4
+};
+
/* opendir: POSIX 5.1.2.1 */
extern "C" DIR *
opendir (const char *name)
res = NULL;
}
- if (!res && fh)
+ if (res)
+ res->__flags = 0;
+ else if (fh)
delete fh;
return res;
}
return NULL;
}
- dirent *res = ((fhandler_base *) dir->__d_u.__d_data.__fh)->readdir (dir);
+ dirent *res = ((fhandler_base *) dir->__fh)->readdir (dir);
+
+ if (!res)
+ {
+ if (!(dir->__flags & opendir_saw_dot))
+ {
+ res = dir->__d_dirent;
+ strcpy (res->d_name, ".");
+ dir->__flags |= opendir_saw_dot;
+ }
+ else if (!(dir->__flags & opendir_saw_dot_dot))
+ {
+ res = dir->__d_dirent;
+ strcpy (res->d_name, "..");
+ dir->__flags |= opendir_saw_dot_dot;
+ }
+ }
if (res)
{
if (res->d_name[0] == '.')
{
if (res->d_name[1] == '\0')
- dir->__d_dirent->d_ino = dir->__d_dirhash;
+ {
+ dir->__d_dirent->d_ino = dir->__d_dirhash;
+ dir->__flags |= opendir_saw_dot;
+ }
else if (res->d_name[1] != '.' || res->d_name[2] != '\0')
goto hashit;
else
{
+ dir->__flags |= opendir_saw_dot_dot;
char *p, up[strlen (dir->__d_dirname) + 1];
strcpy (up, dir->__d_dirname);
if (!(p = strrchr (up, '\\')))
dir->__d_dirent->d_ino = hash_path_name (dino, res->d_name);
}
}
- dir->__d_dirent->old_d_ino = dir->__d_dirent->d_ino; // just truncate
return res;
}
if (dir->__d_cookie != __DIRENT_COOKIE)
return 0;
- return ((fhandler_base *) dir->__d_u.__d_data.__fh)->telldir (dir);
+ return ((fhandler_base *) dir->__fh)->telldir (dir);
}
/* telldir */
if (dir->__d_cookie != __DIRENT_COOKIE)
return;
- return ((fhandler_base *) dir->__d_u.__d_data.__fh)->seekdir (dir, loc);
+ dir->__flags = 0;
+ return ((fhandler_base *) dir->__fh)->seekdir (dir, loc);
}
/* seekdir */
if (dir->__d_cookie != __DIRENT_COOKIE)
return;
- return ((fhandler_base *) dir->__d_u.__d_data.__fh)->rewinddir (dir);
+ dir->__flags = 0;
+ return ((fhandler_base *) dir->__fh)->rewinddir (dir);
}
/* closedir: POSIX 5.1.2.1 */
/* Reset the marker in case the caller tries to use `dir' again. */
dir->__d_cookie = 0;
- int res = ((fhandler_base *) dir->__d_u.__d_data.__fh)->closedir (dir);
+ int res = ((fhandler_base *) dir->__fh)->closedir (dir);
cygheap->fdtab.release (dir->__d_dirent->d_fd);
fd = this;
fd->set_nohandle (true);
dir->__d_dirent->d_fd = fd;
- dir->__d_u.__d_data.__fh = this;
+ dir->__fh = this;
/* FindFirstFile doesn't seem to like duplicate /'s. */
len = strlen (dir->__d_dirname);
if (len == 0 || isdirsep (dir->__d_dirname[len - 1]))
else
strcat (dir->__d_dirname, "\\*"); /**/
dir->__d_cookie = __DIRENT_COOKIE;
- dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
+ dir->__handle = INVALID_HANDLE_VALUE;
dir->__d_position = 0;
dir->__d_dirhash = get_namehash ();
HANDLE handle;
struct dirent *res = NULL;
- if (dir->__d_u.__d_data.__handle == INVALID_HANDLE_VALUE
+ if (dir->__handle == INVALID_HANDLE_VALUE
&& dir->__d_position == 0)
{
handle = FindFirstFileA (dir->__d_dirname, &buf);
DWORD lasterr = GetLastError ();
- dir->__d_u.__d_data.__handle = handle;
+ dir->__handle = handle;
if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES))
{
seterrno_from_win_error (__FILE__, __LINE__, lasterr);
return res;
}
}
- else if (dir->__d_u.__d_data.__handle == INVALID_HANDLE_VALUE)
+ else if (dir->__handle == INVALID_HANDLE_VALUE)
return res;
- else if (!FindNextFileA (dir->__d_u.__d_data.__handle, &buf))
+ else if (!FindNextFileA (dir->__handle, &buf))
{
DWORD lasterr = GetLastError ();
- (void) FindClose (dir->__d_u.__d_data.__handle);
- dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
+ (void) 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)
void
fhandler_disk_file::rewinddir (DIR *dir)
{
- if (dir->__d_u.__d_data.__handle != INVALID_HANDLE_VALUE)
+ if (dir->__handle != INVALID_HANDLE_VALUE)
{
- (void) FindClose (dir->__d_u.__d_data.__handle);
- dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
+ (void) FindClose (dir->__handle);
+ dir->__handle = INVALID_HANDLE_VALUE;
}
dir->__d_position = 0;
}
fhandler_disk_file::closedir (DIR *dir)
{
int res = 0;
- if (dir->__d_u.__d_data.__handle != INVALID_HANDLE_VALUE &&
- FindClose (dir->__d_u.__d_data.__handle) == 0)
+ if (dir->__handle != INVALID_HANDLE_VALUE &&
+ FindClose (dir->__handle) == 0)
{
__seterrno ();
res = -1;
void
fhandler_cygdrive::set_drives ()
{
- const int len = 1 + 26 * DRVSZ;
- char *p = (char *) crealloc ((void *) win32_path_name,
- sizeof (".") + sizeof ("..") + len);
+ const int len = 2 + 26 * DRVSZ;
+ char *p = (char *) crealloc ((void *) win32_path_name, len);
win32_path_name = pdrive = p;
- strcpy (p, ".");
- strcpy (p + sizeof ("."), "..");
- p += sizeof (".") + sizeof ("..");
ndrives = GetLogicalDriveStrings (len, p) / DRVSZ;
}
res = dir->__d_dirent;
goto out;
}
- if (dir->__d_u.__d_data.__handle == INVALID_HANDLE_VALUE
+ if (dir->__handle == INVALID_HANDLE_VALUE
&& dir->__d_position == 0)
{
handle = open_key (path + 1, KEY_READ, false);
- dir->__d_u.__d_data.__handle = handle;
+ dir->__handle = handle;
}
- if (dir->__d_u.__d_data.__handle == INVALID_HANDLE_VALUE)
+ if (dir->__handle == INVALID_HANDLE_VALUE)
goto out;
if (dir->__d_position < SPECIAL_DOT_FILE_COUNT)
{
/* For the moment, the type of key is ignored here. when write access is added,
* maybe add an extension for the type of each value?
*/
- error = RegEnumValue ((HKEY) dir->__d_u.__d_data.__handle,
+ error = RegEnumValue ((HKEY) dir->__handle,
(dir->__d_position & ~REG_ENUM_VALUES_MASK) >> 16,
buf, &buf_size, NULL, NULL, NULL, NULL);
else
error =
- RegEnumKeyEx ((HKEY) dir->__d_u.__d_data.__handle, dir->__d_position -
+ RegEnumKeyEx ((HKEY) dir->__handle, dir->__d_position -
SPECIAL_DOT_FILE_COUNT, buf, &buf_size, NULL, NULL, NULL,
NULL);
if (error == ERROR_NO_MORE_ITEMS
}
if (error != ERROR_SUCCESS && error != ERROR_MORE_DATA)
{
- RegCloseKey ((HKEY) dir->__d_u.__d_data.__handle);
- dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
+ RegCloseKey ((HKEY) dir->__handle);
+ dir->__handle = INVALID_HANDLE_VALUE;
if (error != ERROR_NO_MORE_ITEMS)
seterrno_from_win_error (__FILE__, __LINE__, error);
goto out;
void
fhandler_registry::rewinddir (DIR * dir)
{
- if (dir->__d_u.__d_data.__handle != INVALID_HANDLE_VALUE)
+ if (dir->__handle != INVALID_HANDLE_VALUE)
{
- (void) RegCloseKey ((HKEY) dir->__d_u.__d_data.__handle);
- dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
+ (void) RegCloseKey ((HKEY) dir->__handle);
+ dir->__handle = INVALID_HANDLE_VALUE;
}
dir->__d_position = 0;
return;
fhandler_registry::closedir (DIR * dir)
{
int res = 0;
- if (dir->__d_u.__d_data.__handle != INVALID_HANDLE_VALUE &&
- RegCloseKey ((HKEY) dir->__d_u.__d_data.__handle) != ERROR_SUCCESS)
+ if (dir->__handle != INVALID_HANDLE_VALUE &&
+ RegCloseKey ((HKEY) dir->__handle) != ERROR_SUCCESS)
{
__seterrno ();
res = -1;
fd = this;
fd->set_nohandle (true);
dir->__d_dirent->d_fd = fd;
- dir->__d_u.__d_data.__fh = this;
+ dir->__fh = this;
dir->__d_cookie = __DIRENT_COOKIE;
- dir->__d_u.__d_data.__handle = INVALID_HANDLE_VALUE;
+ dir->__handle = INVALID_HANDLE_VALUE;
dir->__d_position = 0;
dir->__d_dirhash = get_namehash ();
/* Posix dirent.h for WIN32.
- Copyright 2001 Red Hat, Inc.
+ Copyright 2001, 2002, 2003 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
__ino64_t d_ino; /* still junk but with more bits */
long d_fd; /* File descriptor of open directory.
Used since Cygwin 1.3.3. */
- __ino32_t old_d_ino; /* Just for compatibility, it's junk */
+ unsigned __flags; /* Used internally. */
char d_name[256]; /* FIXME: use NAME_MAX? */
};
#else
long d_version;
ino_t d_ino;
long d_fd;
- unsigned long old_d_ino;
+ unsigned long __unused;
char d_name[256];
};
#else
#define __DIRENT_COOKIE 0xdede4242
+#pragma pack(push,4)
typedef struct __DIR
{
/* This is first to set alignment in non _COMPILING_NEWLIB case. */
struct dirent *__d_dirent;
char *__d_dirname; /* directory name with trailing '*' */
_off_t __d_position; /* used by telldir/seekdir */
- unsigned long __d_dirhash; /* hash of directory name for use by
- readdir */
- union
- {
-#ifdef __INSIDE_CYGWIN__
- struct
- {
- void *__handle;
- void *__fh;
- } __d_data;
-#endif
- char __d_filler[16];
- } __d_u;
+ __ino64_t __d_dirhash; /* hash of directory name for use by readdir */
+ void *__handle;
+ void *__fh;
+ unsigned __flags;
} DIR;
+#pragma pack(pop)
DIR *opendir (const char *);
struct dirent *readdir (DIR *);