summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-01-15 04:35:01 +0000
committerJim Meyering <jim@meyering.net>1997-01-15 04:35:01 +0000
commit0868a7d0bd4402321cf683f6acecc264fd8f8040 (patch)
treefd965118691b0af022c1e48f9e975846312d5e5c /src
parent48be557ad67bacc0f690fc23453ee3f79abde815 (diff)
downloadcoreutils-0868a7d0bd4402321cf683f6acecc264fd8f8040.tar.xz
Add struct dir_list and is_ancestor.
Diffstat (limited to 'src')
-rw-r--r--src/copy.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/copy.c b/src/copy.c
index b984df4a8..529bc71e5 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);
+}