Changeset 1966


Ignore:
Timestamp:
May 6, 2005, 1:24:48 AM (20 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#ifndef __EMX__
     42# define HAVE_FCHDIR
     43# define NEED_STRRSLASH
     44# define IS_SLASH(ch)   ( (ch) == '/' || (ch) == '\\' )
     45#else
     46# define IS_SLASH(ch)   ( (ch) == '/' )
     47#endif
    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#ifdef HAVE_FCHDIR
    7785#define FCHDIR(sp, fd)  (!ISSET(FTS_NOCHDIR) && fchdir(fd))
     86#else
     87#define FCHDIR(sp, rdir) (!ISSET(FTS_NOCHDIR) && chdir(rdir))
     88#endif
    7889
    7990/* fts_build flags */
     
    94105};
    95106
     107#ifndef __EMX__
    96108/*
    97109 * The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it
     
    110122        0
    111123};
     124#endif /* !__EMX__ */
    112125
    113126FTS *
     
    212225         * descriptor we run anyway, just more slowly.
    213226         */
     227#ifdef HAVE_FCHDIR
    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#ifdef NEED_STRRSLASH
     244static char *strrslash(register char *psz)
     245{
     246    register char ch;
     247    char *pszLast = NULL;
     248    for (; (ch = *psz); psz++)
     249        switch (ch)
     250        {
     251            case '/':
     252            case '\\':
     253            case ':':
     254                pszLast = psz;
     255                break;
     256        }
     257    return pszLast;
     258}
     259#endif
     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#ifdef NEED_STRRSLASH
     279        if ((cp = strrslash(p->fts_name)) && (cp != p->fts_name || cp[1])) {
     280#else
    243281        if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
     282#endif
    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#ifdef HAVE_FCHDIR
    282322                saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
    283323                (void)_close(sp->fts_rfd);
     324#else
     325                saved_errno = chdir(sp->fts_rdir) ? errno : 0;
     326                free(sp->fts_rdir); sp->fts_rdir = NULL;
     327#endif
    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        (IS_SLASH(p->fts_path[p->fts_pathlen - 1])                      \
    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#ifdef HAVE_FCHDIR
    343389                        if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) {
    344390                                p->fts_errno = errno;
     
    346392                        } else
    347393                                p->fts_flags |= FTS_SYMFOLLOW;
     394#endif
    348395                }
    349396                return (p);
     
    355402                if (instr == FTS_SKIP ||
    356403                    (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
     404#ifdef HAVE_FCHDIR
    357405                        if (p->fts_flags & FTS_SYMFOLLOW)
    358406                                (void)_close(p->fts_symfd);
     407#endif
    359408                        if (sp->fts_child) {
    360409                                fts_lfree(sp->fts_child);
     
    413462                 */
    414463                if (p->fts_level == FTS_ROOTLEVEL) {
     464#ifdef HAVE_FCHDIR
    415465                        if (FCHDIR(sp, sp->fts_rfd)) {
     466#else
     467                        if (FCHDIR(sp, sp->fts_rdir)) {
     468#endif
    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#ifdef HAVE_FCHDIR
    433487                                if ((p->fts_symfd =
    434488                                    _open(".", O_RDONLY, 0)) < 0) {
     
    437491                                } else
    438492                                        p->fts_flags |= FTS_SYMFOLLOW;
     493#endif
    439494                        }
    440495                        p->fts_instr = FTS_NOINSTR;
     
    470525         */
    471526        if (p->fts_level == FTS_ROOTLEVEL) {
     527#ifdef HAVE_FCHDIR
    472528                if (FCHDIR(sp, sp->fts_rfd)) {
     529#else
     530                if (FCHDIR(sp, sp->fts_rdir)) {
     531#endif
    473532                        SET(FTS_STOP);
    474533                        return (NULL);
    475534                }
     535#ifdef HAVE_FCHDIR
    476536        } else if (p->fts_flags & FTS_SYMFOLLOW) {
    477537                if (FCHDIR(sp, p->fts_symfd)) {
     
    483543                }
    484544                (void)_close(p->fts_symfd);
     545#else
     546        (void)saved_errno;
     547#endif
    485548        } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
    486549            fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
     
    520583{
    521584        FTSENT *p;
     585#ifdef HAVE_FCHDIR
    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 || IS_SLASH(p->fts_accpath[0]) ||
    572639            ISSET(FTS_NOCHDIR))
    573640                return (sp->fts_child = fts_build(sp, instr));
    574641
     642#ifdef HAVE_FCHDIR
    575643        if ((fd = _open(".", O_RDONLY, 0)) < 0)
     644#else
     645        if ((pszRoot = getcwd(NULL, 0)) == NULL)
     646#endif
    576647                return (NULL);
    577648        sp->fts_child = fts_build(sp, instr);
     649#ifdef HAVE_FCHDIR
    578650        if (fchdir(fd))
    579651                return (NULL);
    580652        (void)_close(fd);
     653#else
     654        rc = chdir(pszRoot);
     655        free(pszRoot);
     656        if (rc)
     657            return NULL;
     658#endif
    581659        return (sp->fts_child);
    582660}
     
    653731                oflag = DTF_HIDEW | DTF_NODUP | DTF_REWIND;
    654732#else
     733        (void)(oflag);
    655734#define __opendir2(path, flag) opendir(path)
    656735#endif
     
    705784        cderrno = 0;
    706785        if (nlinks || type == BREAD) {
     786#ifdef HAVE_FCHDIR
    707787                if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
     788#else
     789                if (fts_safe_changedir(sp, cur, dirfd(dirp), cur->fts_accpath)) {
     790#endif
    708791                        if (nlinks && type == BREAD)
    709792                                cur->fts_errno = errno;
     
    870953        if (descend && (type == BCHILD || !nitems) &&
    871954            (cur->fts_level == FTS_ROOTLEVEL ?
     955#ifdef HAVE_FCHDIR
    872956            FCHDIR(sp, sp->fts_rfd) :
     957#else
     958            FCHDIR(sp, sp->fts_rdir) :
     959#endif
    873960            fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
    874961                cur->fts_info = FTS_ERR;
     
    11721259        if (ISSET(FTS_NOCHDIR))
    11731260                return (0);
     1261#ifdef HAVE_FCHDIR
    11741262        if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0)
    11751263                return (-1);
    11761264        if (_fstat(newfd, &sb)) {
     1265#else
     1266        (void)newfd;
     1267        if (_stat(path, &sb)) {
     1268#endif
    11771269                ret = -1;
    11781270                goto bail;
     
    11831275                goto bail;
    11841276        }
     1277#ifdef HAVE_FCHDIR
    11851278        ret = fchdir(newfd);
     1279#else
     1280        ret = chdir(path);
     1281#endif
    11861282bail:
     1283#ifdef HAVE_FCHDIR
    11871284        oerrno = errno;
    11881285        if (fd < 0)
    11891286                (void)_close(newfd);
    11901287        errno = oerrno;
     1288#else
     1289        (void)oerrno;
     1290#endif
    11911291        return (ret);
    11921292}
     
    12021302
    12031303        priv = (struct _fts_private *)sp;
     1304#ifdef __EMX__
     1305        /* we don't have reliable links */
     1306        priv->ftsp_linksreliable = 0;
     1307        (void)cpp;
     1308#else
    12041309        /*
    12051310         * If this node's device is different from the previous, grab
     
    12231328                }
    12241329        }
     1330#endif
    12251331        return (priv->ftsp_linksreliable);
    12261332}
Note: See TracChangeset for help on using the changeset viewer.