This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Cygnus Win32 B17.1 'readdir': Return of empty (0-length) string


Gentlemen:

	It is possible for the 'readdir' call in b17.1 to return an
empty (0-length, _not_ NULL) string as an entry in a directory.  This
behavior was uncovered while porting CVS 1.9 to WinNT, and has so far
been unreproducible via a simple program outside of CVS (though it
happens frequently within execution of CVS directory-recursive
commands).  A short test program is listed below.

	An additional characteristics of this behavior is that it
(almost?) always seems to show up immediately after "." and ".." are
returned (before the files & subdirectories are enumerated).

	This behavior might be a transient artifact of heavy "temporary
file" creation/deletion activity in the directory being enumerated under
the FAT filesystem.  I have experienced much trouble over the years with
FAT directories doubly-listing files (i.e. re-ordering the directory) if
there happens to be creation and/or deletion taking place while a
'readdir' is in progress.  Even if this is the cause of the problem, I
would suggest that 'readdir' should filter-out such "empty" directory
entries because programs written to the expected Unix behavior can
become quite confused when returned a 0-length 'd_name'.

======start
readdir_bug.c================================================
#include <stdio.h>
#include <errno.h>
#include <dirent.h>


int main(int argc, char* argv[]) {
	DIR *dir;
	struct dirent *entry;

	if (argc != 2) {
		fprintf(stderr, "usage:  %s <dir>\n", argv[0]);
		return 1;
	}

	dir = opendir(argv[1]);
	if (dir == NULL) {
		fprintf(stderr, "opendir of \"%s\" failed:  errno =
%d\n", argv[1], errno);
		exit(1);
	}

	entry = readdir(dir);
	while (entry != NULL) {
		printf("entry->d_name == \"%s\"\n", entry->d_name);
		entry = readdir(dir);
	}
	(void)closedir(dir);

	return 0;
}
======end readdir_bug.c================================================

Victor J. Griswold, D.Sc.
Aironet Wireless Communications, Inc.
voice:	330-664-7987
fax:	330-664-7301
email:	(MS-Mail) vgris@aironet.com
	(MIME) Victor.Griswold@pobox.com




-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]