delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/02/25/12:08:16

From: VGris AT aironet DOT com ("Griswold, Victor")
Subject: Cygnus Win32 B17.1 'readdir': Return of empty (0-length) string
25 Feb 1997 12:08:16 -0800 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <199702251806.NAA23547.cygnus.gnu-win32@telxon>
Mime-Version: 1.0
Original-To: "'Cygnus:GNU-WIN32'" <gnu-win32 AT cygnus DOT com>
X-Priority: 3
X-Mailer: Internet Mail Service (5.0.1389.3)
Original-Sender: owner-gnu-win32 AT cygnus DOT com

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 AT aironet DOT com
	(MIME) Victor DOT Griswold AT pobox DOT com




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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019