martin 99/10/23 14:23:20
Modified: src/lib/apr/file_io/unix dir.c Log: The readdir_r() function in Linux does return with a zero return even when end-of-file was reached and dir->entry was set to NULL. Handle this situation graefully and "fake" an EOF condition. (This modification was required to get mod_speling running). Revision Changes Path 1.13 +12 -2 apache-2.0/src/lib/apr/file_io/unix/dir.c Index: dir.c =================================================================== RCS file: /export/home/cvs/apache-2.0/src/lib/apr/file_io/unix/dir.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- dir.c 1999/10/23 20:15:16 1.12 +++ dir.c 1999/10/23 21:23:20 1.13 @@ -124,8 +124,13 @@ */ ap_status_t ap_readdir(struct dir_t *thedir) { -#if APR_HAS_THREADS && _POSIX_THREAD_SAFE_FUNCTIONS - return readdir_r(thedir->dirstruct, thedir->entry, &thedir->entry); +#if APR_HAS_THREADS && _POSIX_THREAD_SAFE_FUNCTIONS + ap_status_t ret; + ret = readdir_r(thedir->dirstruct, thedir->entry, &thedir->entry); + /* Avoid the Linux problem where at end-of-directory thedir->entry + * is set to NULL, but ret = APR_SUCCESS. + */ + return (ret == APR_SUCCESS && thedir->entry == NULL) ? APR_ENOENT : ret; #else thedir->entry = readdir(thedir->dirstruct); @@ -288,6 +293,11 @@ */ ap_status_t ap_get_dir_filename(char **new, struct dir_t *thedir) { + /* Detect End-Of-File */ + if (thedir == NULL || thedir->entry == NULL) { + *new = NULL; + return APR_ENOENT; + } (*new) = ap_pstrdup(thedir->cntxt, thedir->entry->d_name); return APR_SUCCESS; }