[PATCH v4 2/2] io: Use gnulib fts implementation (BZ 22944, BZ 20331)

Andreas Schwab schwab@suse.de
Wed Apr 1 08:37:05 GMT 2026


On Mär 31 2026, Adhemerval Zanella wrote:

> +static void
> +fd_ring_clear (I_ring *fd_ring)
> +{
> +  while ( ! i_ring_empty (fd_ring))
> +    {
> +      int fd = i_ring_pop (fd_ring);
> +      if (0 <= fd)
             fd >= 0

> +static void
> +internal_function
> +cwd_advance_fd (FTSOBJ *sp, int fd, bool chdir_down_one)
> +{
> +  int old = sp->fts_cwd_fd;
> +  fts_assert (old != fd || old == AT_FDCWD);
> +
> +  if (chdir_down_one)
> +    {
> +      /* Push "old" onto the ring.
> +         If the displaced file descriptor is non-negative, close it.  */
> +      int prev_fd_in_slot = i_ring_push (&sp->fts_fd_ring, old);
> +      fd_ring_print (sp, stderr, "post-push");
> +      if (0 <= prev_fd_in_slot)
             prev_fd_in_slot >= 0

> +        close (prev_fd_in_slot); /* ignore any close failure */
> +    }
> +  else if ( ! ISSET (FTS_NOCHDIR))
> +    {
> +      if (0 <= old)
             old >= 0

> +                if ( ! (options & FTS_VERBATIM))
> +                  {
> +                    /* If there are two or more trailing slashes, trim all but one,
> +                       but don't change "//" to "/", and do map "///" to "/".  */
> +                    char const *v = *argv;
> +                    if (2 < len && v[len - 1] == '/')
                           len > 2

> +                      while (1 < len && v[len - 2] == '/')
                                len >= 2

> +        int saved_errno = 0;
> +        if (ISSET(FTS_CWDFD))
> +          {
> +            if (0 <= sp->fts_cwd_fd)
                   sp->fts_cwd_fd >= 0

> +#if ! (2 < __GLIBC__ + (3 <= __GLIBC_MINOR__))
          __GLIBC__ + (__GLIBC_MINOR__ >= 3) > 2

> +fd_ring_check (FTSOBJ const *sp)
> +{
> +  if (!fts_debug)
> +    return;
> +
> +  /* Make a writable copy.  */
> +  I_ring fd_w = sp->fts_fd_ring;
> +
> +  int cwd_fd = sp->fts_cwd_fd;
> +  cwd_fd = fcntl (cwd_fd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
> +  struct devino dot = getdevino (cwd_fd);
> +  fprintf (stderr, "===== check ===== cwd: "PRINT_DEVINO"\n",
> +           dot.dev, dot.ino);
> +  while ( ! i_ring_empty (&fd_w))
> +    {
> +      int fd = i_ring_pop (&fd_w);
> +      if (0 <= fd)
             fd >= 0

> +        if (FSTATAT (sp->fts_cwd_fd, p->fts_accpath, sbp, flags) < 0)
> +          {
> +            if (follow && errno == ENOENT
> +                && 0 <= FSTATAT (sp->fts_cwd_fd, p->fts_accpath, sbp,
> +                                 AT_SYMLINK_NOFOLLOW))
                      FSTATAT (sp->fts_cwd_fd, p->fts_accpath, sbp,
                               AT_SYMLINK_NOFOLLOW) >= 0

> +  if (epsilon < tuning->growth_threshold
> +      && tuning->growth_threshold < 1 - epsilon
> +      && 1 + epsilon < tuning->growth_factor
            tuning->growth_factor > 1 + epsilon

> +      && 0 <= tuning->shrink_threshold
            tuning->shrink_threshold >= 0

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Libc-alpha mailing list