From 0868a7d0bd4402321cf683f6acecc264fd8f8040 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 15 Jan 1997 04:35:01 +0000 Subject: [PATCH] Add struct dir_list and is_ancestor. --- src/copy.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/copy.c b/src/copy.c index b984df4..529bc71 100644 --- a/src/copy.c +++ b/src/copy.c @@ -98,12 +98,31 @@ struct flag int (*xstat) (); }; +struct dir_list +{ + struct dir_list *parent; + ino_t ino; + dev_t dev; +}; + int full_write (); int euidaccess (); /* The invocation name of this program. */ extern char *program_name; +static int +is_ancestor (const struct stat *sb, const struct dir_list *ancestors) +{ + while (ancestors != 0) + { + if (ancestors->ino == sb->st_ino && ancestors->dev == sb->st_dev) + return 1; + ancestors = ancestors->parent; + } + return 0; +} + /* Read the contents of the directory SRC_PATH_IN, and recursively copy the contents to DST_PATH_IN. NEW_DST is nonzero if DST_PATH_IN is a directory that was created previously in the @@ -113,7 +132,7 @@ extern char *program_name; static int copy_dir (const char *src_path_in, const char *dst_path_in, int new_dst, const struct stat *src_sb, struct dir_list *ancestors, - struct flag *x) + const struct flag *x) { char *name_space; char *namep; @@ -349,9 +368,10 @@ ret2: devices and inodes of parent directories of SRC_PATH. Return 0 if successful, 1 if an error occurs. */ -int -copy (const char *src_path, const char *dst_path, int new_dst, dev_t device, - struct dir_list *ancestors, struct flag *x) +static int +copy_internal (const char *src_path, const char *dst_path, + int new_dst, dev_t device, struct dir_list *ancestors, + const struct flag *x) { struct stat src_sb; struct stat dst_sb; @@ -765,3 +785,19 @@ un_backup: } return 1; } + +/* Copy the file SRC_PATH to the file DST_PATH. The files may be of + any type. NONEXISTENT_DST should be nonzero if the file DST_PATH is + not to exist (e.g., because its parent directory was just created); + NONEXISTENT_DST should be zero if DST_PATH might already exist. + DEVICE is the device number of the parent directory, or 0 if the + parent of this file is not known. ANCESTORS points to a linked, null + terminated list of devices and inodes of parent directories of SRC_PATH. + Return 0 if successful, 1 if an error occurs. */ + +int +copy (const char *src_path, const char *dst_path, int nonexistent_dst, + const struct flag *x) +{ + copy_internal (src_path, dst_path, ... , x); +} -- 2.7.4