Changeset 1966 for trunk/src


Ignore:
Timestamp:
May 6, 2005, 1:24:48 AM (21 years ago)
Author:
bird
Message:

There is a bunch of things here we don't support, fchdir related mostly. Hope this'll work...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/bsd/gen/fts.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1965 r1966  
    3939#endif /* LIBC_SCCS and not lint */
    4040#endif
     41
     42
     43
     44
     45
     46
     47
    4148
    4249#include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/lib/libc/gen/fts.c,v 1.27 2004/06/08 06:23:23 das Exp $");
     50__FBSDID("$FreeBSD: src/lib/libc/gen/fts.c,v 1.27 2004/06/08 06:23:23 das Exp $");
    4451
    4552#include "namespace.h"
     
    7582#define SET(opt)        (sp->fts_options |= (opt))
    7683
     84
    7785#define FCHDIR(sp, fd)  (!ISSET(FTS_NOCHDIR) && fchdir(fd))
     86
     87
     88
    7889
    7990/* fts_build flags */
     
    94105};
    95106
     107
    96108/*
    97109 * The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it
     
    110122        0
    111123};
     124
    112125
    113126FTS *
     
    212225         * descriptor we run anyway, just more slowly.
    213226         */
     227
    214228        if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0)
    215                 SET(FTS_NOCHDIR);
     229#else
     230        if (!ISSET(FTS_NOCHDIR) && (sp->fts_rdir = getcwd(NULL, 0)) != NULL)
     231#endif
     232            SET(FTS_NOCHDIR);
    216233
    217234        return (sp);
     
    224241}
    225242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
     255
     256
     257
     258
     259
     260
    226261static void
    227262fts_load(sp, p)
     
    241276        len = p->fts_pathlen = p->fts_namelen;
    242277        memmove(sp->fts_path, p->fts_name, len + 1);
     278
     279
     280
    243281        if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
     282
    244283                len = strlen(++cp);
    245284                memmove(p->fts_name, cp, len + 1);
     
    280319        /* Return to original directory, save errno if necessary. */
    281320        if (!ISSET(FTS_NOCHDIR)) {
     321
    282322                saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
    283323                (void)_close(sp->fts_rfd);
     324
     325
     326
     327
    284328
    285329                /* Set errno and return. */
     
    297341}
    298342
     343
    299344/*
    300345 * Special case of "/" at the end of the path so that slashes aren't
     
    302347 */
    303348#define NAPPEND(p)                                                      \
    304         (p->fts_path[p->fts_pathlen - 1] == '/'                         \
     349        (                      \
    305350            ? p->fts_pathlen - 1 : p->fts_pathlen)
    306351
     
    341386                p->fts_info = fts_stat(sp, p, 1);
    342387                if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
     388
    343389                        if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) {
    344390                                p->fts_errno = errno;
     
    346392                        } else
    347393                                p->fts_flags |= FTS_SYMFOLLOW;
     394
    348395                }
    349396                return (p);
     
    355402                if (instr == FTS_SKIP ||
    356403                    (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
     404
    357405                        if (p->fts_flags & FTS_SYMFOLLOW)
    358406                                (void)_close(p->fts_symfd);
     407
    359408                        if (sp->fts_child) {
    360409                                fts_lfree(sp->fts_child);
     
    413462                 */
    414463                if (p->fts_level == FTS_ROOTLEVEL) {
     464
    415465                        if (FCHDIR(sp, sp->fts_rfd)) {
     466
     467
     468
    416469                                SET(FTS_STOP);
    417470                                return (NULL);
     
    431484                        p->fts_info = fts_stat(sp, p, 1);
    432485                        if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
     486
    433487                                if ((p->fts_symfd =
    434488                                    _open(".", O_RDONLY, 0)) < 0) {
     
    437491                                } else
    438492                                        p->fts_flags |= FTS_SYMFOLLOW;
     493
    439494                        }
    440495                        p->fts_instr = FTS_NOINSTR;
     
    470525         */
    471526        if (p->fts_level == FTS_ROOTLEVEL) {
     527
    472528                if (FCHDIR(sp, sp->fts_rfd)) {
     529
     530
     531
    473532                        SET(FTS_STOP);
    474533                        return (NULL);
    475534                }
     535
    476536        } else if (p->fts_flags & FTS_SYMFOLLOW) {
    477537                if (FCHDIR(sp, p->fts_symfd)) {
     
    483543                }
    484544                (void)_close(p->fts_symfd);
     545
     546
     547
    485548        } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
    486549            fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
     
    520583{
    521584        FTSENT *p;
     585
    522586        int fd;
    523 
     587#else
     588        char *pszRoot;
     589        int rc;
     590#endif
    524591        if (instr != 0 && instr != FTS_NAMEONLY) {
    525592                errno = EINVAL;
     
    569636         * fts_read will work.
    570637         */
    571         if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' ||
     638        if (p->fts_level != FTS_ROOTLEVEL || ||
    572639            ISSET(FTS_NOCHDIR))
    573640                return (sp->fts_child = fts_build(sp, instr));
    574641
     642
    575643        if ((fd = _open(".", O_RDONLY, 0)) < 0)
     644
     645
     646
    576647                return (NULL);
    577648        sp->fts_child = fts_build(sp, instr);
     649
    578650        if (fchdir(fd))
    579651                return (NULL);
    580652        (void)_close(fd);
     653
     654
     655
     656
     657
     658
    581659        return (sp->fts_child);
    582660}
     
    653731                oflag = DTF_HIDEW | DTF_NODUP | DTF_REWIND;
    654732#else
     733
    655734#define __opendir2(path, flag) opendir(path)
    656735#endif
     
    705784        cderrno = 0;
    706785        if (nlinks || type == BREAD) {
     786
    707787                if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
     788
     789
     790
    708791                        if (nlinks && type == BREAD)
    709792                                cur->fts_errno = errno;
     
    870953        if (descend && (type == BCHILD || !nitems) &&
    871954            (cur->fts_level == FTS_ROOTLEVEL ?
     955
    872956            FCHDIR(sp, sp->fts_rfd) :
     957
     958
     959
    873960            fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
    874961                cur->fts_info = FTS_ERR;
     
    11721259        if (ISSET(FTS_NOCHDIR))
    11731260                return (0);
     1261
    11741262        if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0)
    11751263                return (-1);
    11761264        if (_fstat(newfd, &sb)) {
     1265
     1266
     1267
     1268
    11771269                ret = -1;
    11781270                goto bail;
     
    11831275                goto bail;
    11841276        }
     1277
    11851278        ret = fchdir(newfd);
     1279
     1280
     1281
    11861282bail:
     1283
    11871284        oerrno = errno;
    11881285        if (fd < 0)
    11891286                (void)_close(newfd);
    11901287        errno = oerrno;
     1288
     1289
     1290
    11911291        return (ret);
    11921292}
     
    12021302
    12031303        priv = (struct _fts_private *)sp;
     1304
     1305
     1306
     1307
     1308
    12041309        /*
    12051310         * If this node's device is different from the previous, grab
     
    12231328                }
    12241329        }
     1330
    12251331        return (priv->ftsp_linksreliable);
    12261332}
Note: See TracChangeset for help on using the changeset viewer.