Changeset 2497


Ignore:
Timestamp:
Dec 18, 2005, 12:25:44 PM (20 years ago)
Author:
bird
Message:

Fixes #24

  • chdir() crash in fts.c.
  • dirfd() problem in fts.c which prevent us from getting

any results in child directories.

Location:
branches/libc-0.6/src/emx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/ChangeLog.LIBC

    r2496 r2497  
    552005-12-18: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    66    - libc:
     7        o #24: Fixed chdir() crash in fts.c.
     8        o #24: Fixed dirfd() problem in fts.c which prevent us from getting
     9          any results in child directories.
    710        o #22: Added DosFindFirst() as fallback when DosQueryPathInfo() fails
    811          to query the symlink EA in the path resolver. This problem occurs
  • branches/libc-0.6/src/emx/src/lib/bsd/gen/fts.c

    r2496 r2497  
    4040#endif
    4141#ifndef __EMX__
     42# define HAVE_FCHDIR
     43# define HAVE_DIRFD
    4244# define IS_SLASH(ch)   ( (ch) == '/' )
    4345#else
    4446# define NEED_STRRSLASH
     47# define HAVE_FCHDIR
     48# undef HAVE_DIRFD
    4549# define IS_SLASH(ch)   ( (ch) == '/' || (ch) == '\\' )
    4650#endif
     
    224228         * descriptor we run anyway, just more slowly.
    225229         */
     230#ifdef HAVE_FCHDIR
    226231        if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0)
    227                 SET(FTS_NOCHDIR);
     232#else
     233        if (!ISSET(FTS_NOCHDIR) && (sp->fts_rdir = getcwd(NULL, 0)) != NULL)
     234#endif
     235            SET(FTS_NOCHDIR);
    228236
    229237        return (sp);
     
    314322        /* Return to original directory, save errno if necessary. */
    315323        if (!ISSET(FTS_NOCHDIR)) {
     324#ifdef HAVE_FCHDIR
    316325                saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
    317326                (void)_close(sp->fts_rfd);
     327#else
     328                saved_errno = chdir(sp->fts_rdir) ? errno : 0;
     329                free(sp->fts_rdir); sp->fts_rdir = NULL;
     330#endif
    318331
    319332                /* Set errno and return. */
     
    375388                p->fts_info = fts_stat(sp, p, 1);
    376389                if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
     390#ifdef HAVE_FCHDIR
    377391                        if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) {
    378392                                p->fts_errno = errno;
     
    380394                        } else
    381395                                p->fts_flags |= FTS_SYMFOLLOW;
     396#endif
    382397                }
    383398                return (p);
     
    389404                if (instr == FTS_SKIP ||
    390405                    (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
     406#ifdef HAVE_FCHDIR
    391407                        if (p->fts_flags & FTS_SYMFOLLOW)
    392408                                (void)_close(p->fts_symfd);
     409#endif
    393410                        if (sp->fts_child) {
    394411                                fts_lfree(sp->fts_child);
     
    447464                 */
    448465                if (p->fts_level == FTS_ROOTLEVEL) {
     466#ifdef HAVE_FCHDIR
    449467                        if (FCHDIR(sp, sp->fts_rfd)) {
     468#else
     469                        if (FCHDIR(sp, sp->fts_rdir)) {
     470#endif
    450471                                SET(FTS_STOP);
    451472                                return (NULL);
     
    465486                        p->fts_info = fts_stat(sp, p, 1);
    466487                        if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
     488#ifdef HAVE_FCHDIR
    467489                                if ((p->fts_symfd =
    468490                                    _open(".", O_RDONLY, 0)) < 0) {
     
    471493                                } else
    472494                                        p->fts_flags |= FTS_SYMFOLLOW;
     495#endif
    473496                        }
    474497                        p->fts_instr = FTS_NOINSTR;
     
    504527         */
    505528        if (p->fts_level == FTS_ROOTLEVEL) {
     529#ifdef HAVE_FCHDIR
    506530                if (FCHDIR(sp, sp->fts_rfd)) {
     531#else
     532                if (FCHDIR(sp, sp->fts_rdir)) {
     533#endif
    507534                        SET(FTS_STOP);
    508535                        return (NULL);
    509536                }
     537#ifdef HAVE_FCHDIR
    510538        } else if (p->fts_flags & FTS_SYMFOLLOW) {
    511539                if (FCHDIR(sp, p->fts_symfd)) {
     
    517545                }
    518546                (void)_close(p->fts_symfd);
     547#else
     548        (void)saved_errno;
     549#endif
    519550        } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
    520551            fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
     
    554585{
    555586        FTSENT *p;
     587#ifdef HAVE_FCHDIR
    556588        int fd;
    557 
     589#else
     590        char *pszRoot;
     591        int rc;
     592#endif
    558593        if (instr != 0 && instr != FTS_NAMEONLY) {
    559594                errno = EINVAL;
     
    607642                return (sp->fts_child = fts_build(sp, instr));
    608643
     644#ifdef HAVE_FCHDIR
    609645        if ((fd = _open(".", O_RDONLY, 0)) < 0)
     646#else
     647        if ((pszRoot = getcwd(NULL, 0)) == NULL)
     648#endif
    610649                return (NULL);
    611650        sp->fts_child = fts_build(sp, instr);
     651#ifdef HAVE_FCHDIR
    612652        if (fchdir(fd))
    613653                return (NULL);
    614654        (void)_close(fd);
     655#else
     656        rc = chdir(pszRoot);
     657        free(pszRoot);
     658        if (rc)
     659            return NULL;
     660#endif
    615661        return (sp->fts_child);
    616662}
     
    740786        cderrno = 0;
    741787        if (nlinks || type == BREAD) {
     788#ifdef HAVE_DIRFD
    742789                if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
     790#else
     791                if (fts_safe_changedir(sp, cur, -1, cur->fts_accpath)) {
     792#endif
    743793                        if (nlinks && type == BREAD)
    744794                                cur->fts_errno = errno;
     
    905955        if (descend && (type == BCHILD || !nitems) &&
    906956            (cur->fts_level == FTS_ROOTLEVEL ?
     957#ifdef HAVE_FCHDIR
    907958            FCHDIR(sp, sp->fts_rfd) :
     959#else
     960            FCHDIR(sp, sp->fts_rdir) :
     961#endif
    908962            fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
    909963                cur->fts_info = FTS_ERR;
     
    12071261        if (ISSET(FTS_NOCHDIR))
    12081262                return (0);
     1263#ifdef HAVE_FCHDIR
    12091264        if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0)
    12101265                return (-1);
    12111266        if (_fstat(newfd, &sb)) {
     1267#else
     1268        (void)newfd;
     1269        if (_stat(path, &sb)) {
     1270#endif
    12121271                ret = -1;
    12131272                goto bail;
     
    12181277                goto bail;
    12191278        }
     1279#ifdef HAVE_FCHDIR
    12201280        ret = fchdir(newfd);
     1281#else
     1282        ret = chdir(path);
     1283#endif
    12211284bail:
     1285#ifdef HAVE_FCHDIR
    12221286        oerrno = errno;
    12231287        if (fd < 0)
    12241288                (void)_close(newfd);
    12251289        errno = oerrno;
     1290#else
     1291        (void)oerrno;
     1292#endif
    12261293        return (ret);
    12271294}
Note: See TracChangeset for help on using the changeset viewer.