X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Received: by 10.66.230.161 with SMTP id sz1mr2348499pac.18.1364330845532; Tue, 26 Mar 2013 13:47:25 -0700 (PDT) X-Received: by 10.49.60.170 with SMTP id i10mr622520qer.41.1364330845109; Tue, 26 Mar 2013 13:47:25 -0700 (PDT) Newsgroups: comp.os.msdos.djgpp Date: Tue, 26 Mar 2013 13:47:24 -0700 (PDT) In-Reply-To: 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> <5f806b56-af98-4f72-8984-a944be9348a4 AT googlegroups DOT com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <6b49a77b-dcba-4c23-8a29-4ac0263e7713@googlegroups.com> Subject: Re: DJGPP scandir and alphasort example code From: Georg Potthast Cc: djgpp AT delorie DOT com Injection-Date: Tue, 26 Mar 2013 20:47:25 +0000 Content-Type: text/plain; charset=ISO-8859-1 Bytes: 3319 Lines: 58 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id r2QL02fE002348 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 Precedence: bulk Am Dienstag, 26. März 2013 19:20:43 UTC+1 schrieb RayeR: > Yes this static version doesn't crash. > > Maybe you can try to copy some files with long names to your rootdir to reproduce the bug... I do have long filenames in C:\ e.g. "VirtualBox-3.2.10-66523-Win.exe". It does not crash though. The glob() is used to determine the number of entries in the directory. In the static version posted this is limited to 2048 entries. Anyway below is what I wanted to post. Maybe someone can tell what is wrong with the glob() usage part. DIR *dirptr; struct dirent *dir_entry; int tdirsize = sizeof(struct dirent); register int i=0; int si=0; size_t cnt; #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 ((dirptr = opendir(dirname)) == NULL) return -1; #endif if ((*namelist = (struct dirent **) calloc(cnt, sizeof(struct dirent *))) == NULL) return -1;