Blame lib/cycle-check.h

Packit 709fb3
/* help detect directory cycles efficiently
Packit 709fb3
Packit 709fb3
   Copyright (C) 2003-2004, 2006, 2009-2017 Free Software Foundation, Inc.
Packit 709fb3
Packit 709fb3
   This program is free software: you can redistribute it and/or modify
Packit 709fb3
   it under the terms of the GNU General Public License as published by
Packit 709fb3
   the Free Software Foundation; either version 3 of the License, or
Packit 709fb3
   (at your option) any later version.
Packit 709fb3
Packit 709fb3
   This program is distributed in the hope that it will be useful,
Packit 709fb3
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 709fb3
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 709fb3
   GNU General Public License for more details.
Packit 709fb3
Packit 709fb3
   You should have received a copy of the GNU General Public License
Packit 709fb3
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 709fb3
Packit 709fb3
/* Written by Jim Meyering */
Packit 709fb3
Packit 709fb3
#ifndef CYCLE_CHECK_H
Packit 709fb3
# define CYCLE_CHECK_H 1
Packit 709fb3
Packit 709fb3
# include <stdint.h>
Packit 709fb3
# include <stdbool.h>
Packit 709fb3
# include "dev-ino.h"
Packit 709fb3
# include "same-inode.h"
Packit 709fb3
Packit 709fb3
struct cycle_check_state
Packit 709fb3
{
Packit 709fb3
  struct dev_ino dev_ino;
Packit 709fb3
  uintmax_t chdir_counter;
Packit 709fb3
  int magic;
Packit 709fb3
};
Packit 709fb3
Packit 709fb3
void cycle_check_init (struct cycle_check_state *state);
Packit 709fb3
bool cycle_check (struct cycle_check_state *state, struct stat const *sb);
Packit 709fb3
Packit 709fb3
# define CYCLE_CHECK_REFLECT_CHDIR_UP(State, SB_dir, SB_subdir) \
Packit 709fb3
  do                                                            \
Packit 709fb3
    {                                                           \
Packit 709fb3
      /* You must call cycle_check at least once before using this macro.  */ \
Packit 709fb3
      if ((State)->chdir_counter == 0)                          \
Packit 709fb3
        abort ();                                               \
Packit 709fb3
      if (SAME_INODE ((State)->dev_ino, SB_subdir))             \
Packit 709fb3
        {                                                       \
Packit 709fb3
          (State)->dev_ino.st_dev = (SB_dir).st_dev;            \
Packit 709fb3
          (State)->dev_ino.st_ino = (SB_dir).st_ino;            \
Packit 709fb3
        }                                                       \
Packit 709fb3
    }                                                           \
Packit 709fb3
  while (0)
Packit 709fb3
Packit 709fb3
#endif