Date: Thu, 30 Nov 1995 03:49:24 -0800 From: Julian Elischer <julian@ref.tfs.com> To: hackers@freebsd.org Subject: seekdir broken.. Message-ID: <199511301149.DAA11852@ref.tfs.com>
next in thread | raw e-mail | index | archive | help
The following code attempts to read a directory, in small gulps.. it seems silly, but there is a reason for doing this in WINE. The code THINKS it;s stepping through the directory.. but in fact as we can see, the seekdir is having NO effect at all, so we just keep getting the first two entries over and over.. any ideas? this breaks WINE big-time.. I'm AMAZED nothing else breaks.. the readdir code is SHIT! you can't read two directories at once because it uses static elements! ---------------------------------- #include <sys/types.h> #include <dirent.h> DIR *dir; /* * Loop through a directory, looking for something */ main() { int num = 0; while(1) { /* * Look for something that might match */ num = readd(num, "*.c"); printf("-%d-\n",num ); /* * Nope that aint it, keep trying */ } } /* * scan through a directory looking for something that matches a pattern p */ int readd(int tell,char *pat) { int i; struct dirent *ent; dir = opendir("."); /* * Start where we left off, of where we are asked to */ seekdir(dir, tell); /* * pretend we hit on every 2nd item */ for ( i = 1; i< 3;i++) { printf("[%d] ", tell = telldir(dir)); if ( ! (ent = readdir(dir))) { printf("[%d] ",telldir(dir)); printf("exiting\n"); exit(1); } printf("<%s>",ent->d_name); } closedir(dir); return(tell); } ------------------end of test program----------- under OSF1 the output in /tmp (2 files) is: [0] <.>[12] <..>-12- [12] <..>[24] <dtst.c>-24- [24] <dtst.c>[120] <dtst>-120- [120] <dtst>[512] [512] exiting under freeBSD the output is: [1] <.>[2] <..>-2- [4] <.>[5] <..>-5- [7] <.>[8] <..>-8- [10] <.>[11] <..>-11- [13] <.>[14] <..>-14- [16] <.>[17] <..>-17- [19] <.>[20] <..>-20- [22] <.>[23] <..>-23- [25] <.>[26] <..>-26- [28] <.>[29] <..>-29- (etc. forever..) I think I'm going over to see what NetBSD have done about this.. julian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199511301149.DAA11852>