Skip to content

Commit 5c2e757

Browse files
Leontap
authored andcommitted
Remove fchdir based dirhandle cloning code
This is no longer needed now that the fdopendir implementation exists.
1 parent 1f9097b commit 5c2e757

File tree

1 file changed

+1
-92
lines changed

1 file changed

+1
-92
lines changed

sv.c

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -14096,15 +14096,6 @@ Perl_dirp_dup(pTHX_ DIR *const dp, CLONE_PARAMS *const param)
1409614096
{
1409714097
DIR *ret;
1409814098

14099-
#if !defined(HAS_FDOPENDIR) && defined(HAS_FCHDIR) && defined(HAS_TELLDIR) && defined(HAS_SEEKDIR)
14100-
DIR *pwd;
14101-
const Direntry_t *dirent;
14102-
char smallbuf[256]; /* XXX MAXPATHLEN, surely? */
14103-
char *name = NULL;
14104-
STRLEN len = 0;
14105-
long pos;
14106-
#endif
14107-
1410814099
PERL_UNUSED_CONTEXT;
1410914100
PERL_ARGS_ASSERT_DIRP_DUP;
1411014101

@@ -14122,89 +14113,7 @@ Perl_dirp_dup(pTHX_ DIR *const dp, CLONE_PARAMS *const param)
1412214113

1412314114
ret = fdopendir(dup(my_dirfd(dp)));
1412414115

14125-
#elif defined(HAS_FCHDIR) && defined(HAS_TELLDIR) && defined(HAS_SEEKDIR)
14126-
14127-
PERL_UNUSED_ARG(param);
14128-
14129-
/* create anew */
14130-
14131-
/* open the current directory (so we can switch back) */
14132-
if (!(pwd = PerlDir_open("."))) return (DIR *)NULL;
14133-
14134-
/* chdir to our dir handle and open the present working directory */
14135-
if (fchdir(my_dirfd(dp)) < 0 || !(ret = PerlDir_open("."))) {
14136-
PerlDir_close(pwd);
14137-
return (DIR *)NULL;
14138-
}
14139-
/* Now we should have two dir handles pointing to the same dir. */
14140-
14141-
/* Be nice to the calling code and chdir back to where we were. */
14142-
/* XXX If this fails, then what? */
14143-
PERL_UNUSED_RESULT(fchdir(my_dirfd(pwd)));
14144-
14145-
/* We have no need of the pwd handle any more. */
14146-
PerlDir_close(pwd);
14147-
14148-
#ifdef DIRNAMLEN
14149-
# define d_namlen(d) (d)->d_namlen
14150-
#else
14151-
# define d_namlen(d) strlen((d)->d_name)
14152-
#endif
14153-
/* Iterate once through dp, to get the file name at the current posi-
14154-
tion. Then step back. */
14155-
pos = PerlDir_tell(dp);
14156-
if ((dirent = PerlDir_read(dp))) {
14157-
len = d_namlen(dirent);
14158-
if (len > sizeof(dirent->d_name) && sizeof(dirent->d_name) > PTRSIZE) {
14159-
/* If the len is somehow magically longer than the
14160-
* maximum length of the directory entry, even though
14161-
* we could fit it in a buffer, we could not copy it
14162-
* from the dirent. Bail out. */
14163-
PerlDir_close(ret);
14164-
return (DIR*)NULL;
14165-
}
14166-
if (len <= sizeof smallbuf) name = smallbuf;
14167-
else Newx(name, len, char);
14168-
Move(dirent->d_name, name, len, char);
14169-
}
14170-
PerlDir_seek(dp, pos);
14171-
14172-
/* Iterate through the new dir handle, till we find a file with the
14173-
right name. */
14174-
if (!dirent) /* just before the end */
14175-
for(;;) {
14176-
pos = PerlDir_tell(ret);
14177-
if (PerlDir_read(ret)) continue; /* not there yet */
14178-
PerlDir_seek(ret, pos); /* step back */
14179-
break;
14180-
}
14181-
else {
14182-
const long pos0 = PerlDir_tell(ret);
14183-
for(;;) {
14184-
pos = PerlDir_tell(ret);
14185-
if ((dirent = PerlDir_read(ret))) {
14186-
if (len == (STRLEN)d_namlen(dirent)
14187-
&& memEQ(name, dirent->d_name, len)) {
14188-
/* found it */
14189-
PerlDir_seek(ret, pos); /* step back */
14190-
break;
14191-
}
14192-
/* else we are not there yet; keep iterating */
14193-
}
14194-
else { /* This is not meant to happen. The best we can do is
14195-
reset the iterator to the beginning. */
14196-
PerlDir_seek(ret, pos0);
14197-
break;
14198-
}
14199-
}
14200-
}
14201-
#undef d_namlen
14202-
14203-
if (name && name != smallbuf)
14204-
Safefree(name);
14205-
#endif
14206-
14207-
#ifdef WIN32
14116+
#elif defined(WIN32)
1420814117
ret = win32_dirp_dup(dp, param);
1420914118
#endif
1421014119

0 commit comments

Comments
 (0)