| cvs.gedasymbols.org/archives/browse.cgi | search | 
| X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f | 
| X-Received: | by 10.224.172.200 with SMTP id m8mr8380600qaz.0.1364320776978; | 
| Tue, 26 Mar 2013 10:59:36 -0700 (PDT) | |
| X-Received: | by 10.49.30.100 with SMTP id r4mr1120857qeh.32.1364320776942; Tue, | 
| 26 Mar 2013 10:59:36 -0700 (PDT) | |
| Newsgroups: | comp.os.msdos.djgpp | 
| Date: | Tue, 26 Mar 2013 10:59:36 -0700 (PDT) | 
| In-Reply-To: | <D85EE936F5F24E8E8E2EA7C8C3FB79C5@dev.null> | 
| Complaints-To: | groups-abuse AT google DOT com | 
| Injection-Info: | glegroupsg2000goo.googlegroups.com; posting-host=2.173.27.66; posting-account=v5xbdQoAAAAOGc9Ccc-kLZyobvPlN3Qr | 
| NNTP-Posting-Host: | 2.173.27.66 | 
| References: | <261476b1-c137-495d-95df-a92075cd9960 AT googlegroups DOT com> | 
| <2245ebea-be44-4a40-8b2f-7ef5e0e67157 AT googlegroups DOT com> <D85EE936F5F24E8E8E2EA7C8C3FB79C5 AT dev DOT null> | |
| User-Agent: | G2/1.0 | 
| MIME-Version: | 1.0 | 
| Message-ID: | <5f806b56-af98-4f72-8984-a944be9348a4@googlegroups.com> | 
| Subject: | Re: DJGPP scandir and alphasort example code | 
| From: | Georg Potthast <dosusb AT googlemail DOT com> | 
| Cc: | djgpp AT delorie DOT com | 
| Injection-Date: | Tue, 26 Mar 2013 17:59:36 +0000 | 
| Bytes: | 3859 | 
| Lines: | 99 | 
| To: | djgpp AT delorie DOT com | 
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp | 
| X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id r2QIF241015697 | 
| Reply-To: | djgpp AT delorie DOT com | 
| Errors-To: | nobody AT delorie DOT com | 
| X-Mailing-List: | djgpp AT delorie DOT com | 
| X-Unsubscribes-To: | listserv AT delorie DOT com | 
Am Dienstag, 26. März 2013 16:46:34 UTC+1 schrieb Gisle Vanem:
> "RayeR" <glaux AT centrum DOT cz> wrote:
> 
> 
> 
> > App stack: [0009d688..0001d68c]  Exceptn stack: [0001d59c..0001b65c]
> 
> > 
> 
> > Call frame traceback EIPs:
> 
> >  0x00004254
> 
> >  0x00001ffb
> 
> >  0x00003cd4
> 
> > 
> 
> > C:\1sc>
> 
> > 
> 
> > All directory from root was listed, it crashed after...
> 
> 
> 
> I can verify this. Lookng at the code, it seems the author
> 
> got really confused about his own use of pointers :-). The 
> 
> code around "struct dirent *(*namelist[])" in scandir() is rather 
> 
> messy even for a C-expert.
> 
> 
> 
> Anyway, the last free in scandirtest.c should IMHO be:
> 
>   free(*namelist);
> 
> 
> 
> and not 'free(namelist)' .
> 
> 
> 
> --gv
I doubt that this is required. I took the code from the Linux man page:
http://linux.die.net/man/3/alphasort
On my PC I cannot reproduce the crash, even on the C: drive. But I do believe that the crash occurs on your PCs.
I would suspect the use of glob() to find the amount of entries in the directory to be the cause of the problem. Try using a fixed number instead to verify that:
	DIR *dirptr;
	struct dirent *dir_entry;
	int tdirsize = sizeof(struct dirent);
	register int i=0;
	int si=0;
#if 0
	size_t cnt;
        glob_t glob_results;
        char *wildcard;
	char *wildcardpos;
	wildcard=calloc(_POSIX_PATH_MAX,sizeof(char));
	if ((dirptr = opendir(dirname)) == NULL)
		return -1;
	//read number of entries in directory
	strcpy(wildcard,dirname);
	//remove trailing slash
	wildcardpos=strrchr(wildcard,'\\');
	if (strlen(wildcardpos)==strlen(wildcard)) wildcard[strlen(wildcard)-1]='\0'; //printf("hier");
	//add * for all entries
	strcat(wildcard,"\\*");
	if(glob(wildcard, GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_NOSORT, NULL, &glob_results) == 0)
	cnt = glob_results.gl_pathc +2; //add two for . and ..
	globfree(&glob_results);
	free(wildcard);
	
	//dynamic tdir array allocation
	static struct dirent *tdir;
	tdir = (struct dirent*) calloc(cnt,sizeof(struct dirent));
#else
	static struct dirent *tdir[2048];
	if ((dirp = opendir(dirname)) == NULL)
	return -1;
#endif
	if ((*namelist = (struct dirent **) calloc(cnt, sizeof(struct dirent *)))
		== NULL)
		return -1;
| webmaster | delorie software privacy | 
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |