[RENAME_TRAILING_SLASH_BUG]: Use the rename wrapper.
[platform/upstream/coreutils.git] / src / copy.h
1 #ifndef COPY_H
2 # define COPY_H
3
4 /* Control creation of sparse files (files with holes).  */
5 enum Sparse_type
6 {
7   SPARSE_UNUSED,
8
9   /* Never create holes in DEST.  */
10   SPARSE_NEVER,
11
12   /* This is the default.  Use a crude (and sometimes inaccurate)
13      heuristic to determine if SOURCE has holes.  If so, try to create
14      holes in DEST.  */
15   SPARSE_AUTO,
16
17   /* For every sufficiently long sequence of bytes in SOURCE, try to
18      create a corresponding hole in DEST.  There is a performance penalty
19      here because CP has to search for holes in SRC.  But if the holes are
20      big enough, that penalty can be offset by the decrease in the amount
21      of data written to disk.   */
22   SPARSE_ALWAYS
23 };
24
25 enum Dereference_symlink
26 {
27   DEREF_UNDEFINED = 1,
28   DEREF_ALWAYS,
29   DEREF_NEVER,
30   DEREF_COMMAND_LINE_ARGUMENTS
31 };
32
33 # define VALID_SPARSE_MODE(Mode)        \
34   ((Mode) == SPARSE_NEVER               \
35    || (Mode) == SPARSE_AUTO             \
36    || (Mode) == SPARSE_ALWAYS)
37
38 struct cp_options
39 {
40   enum backup_type backup_type;
41
42   /* If nonzero, copy all files except (directories and, if not dereferencing
43      them, symbolic links,) as if they were regular files. */
44   int copy_as_regular;
45
46   /* If nonzero, dereference symbolic links (copy the files they point to). */
47   enum Dereference_symlink dereference;
48
49   /* If nonzero, remove each existing destination nondirectory before
50      trying to open it. */
51   int unlink_dest_before_opening;
52
53   /* If nonzero, first try to open each existing destination nondirectory,
54      then, if the open fails, unlink and try again.
55      This option must be set for `cp -f', in case the destination file
56      exists when the open is attempted.  It is irrelevant to `mv' since
57      any destination is sure to be removed before the open.  */
58   int unlink_dest_after_failed_open;
59
60   /* Setting this member is meaningful only if FORCE is also set.
61      If nonzero, copy returns nonzero upon failed unlink.
62      Otherwise, the failure still elicits a diagnostic, but it doesn't
63      change copy's return value.  This is nonzero for cp and mv, and zero
64      for install.  */
65   /* FIXME: this is now unused.  */
66   int failed_unlink_is_fatal;
67
68   /* If nonzero, create hard links instead of copying files.
69      Create destination directories as usual. */
70   int hard_link;
71
72   /* If nonzero, query before overwriting existing destinations
73      with regular files. */
74   int interactive;
75
76   /* If nonzero, rather than copying, first attempt to use rename.
77      If that fails, then resort to copying.  */
78   int move_mode;
79
80   /* This process's effective user ID.  */
81   uid_t myeuid;
82
83   /* If nonzero, when copying recursively, skip any subdirectories that are
84      on different filesystems from the one we started on. */
85   int one_file_system;
86
87   /* If nonzero, attempt to give the copies the original files' permissions,
88      owner, group, and timestamps. */
89   int preserve_owner_and_group;
90   int preserve_chmod_bits;
91   int preserve_timestamps;
92
93   /* If nonzero and any of the above (for preserve) file attributes cannot
94      be applied to a destination file, treat it as a failure and return
95      nonzero immediately.  E.g. cp -p requires this be nonzero, mv requires
96      it be zero.  */
97   int require_preserve;
98
99   /* If nonzero, copy directories recursively and copy special files
100      as themselves rather than copying their contents. */
101   int recursive;
102
103   /* If nonzero, set file mode to value of MODE.  Otherwise,
104      set it based on current umask modified by UMASK_KILL.  */
105   int set_mode;
106
107   /* Set the mode of the destination file to exactly this value
108      if USE_MODE is nonzero.  */
109   mode_t mode;
110
111   /* Control creation of sparse files.  */
112   enum Sparse_type sparse_mode;
113
114   /* If nonzero, create symbolic links instead of copying files.
115      Create destination directories as usual. */
116   int symbolic_link;
117
118   /* The bits to preserve in created files' modes. */
119   mode_t umask_kill;
120
121   /* If nonzero, do not copy a nondirectory that has an existing destination
122      with the same or newer modification time. */
123   int update;
124
125   /* If nonzero, display the names of the files before copying them. */
126   int verbose;
127
128   /* A pointer to either lstat or stat, depending on
129      whether the copy should dereference symlinks.  */
130   int (*xstat) ();
131 };
132
133 int stat ();
134 int lstat ();
135
136 /* Arrange to make lstat calls go through the wrapper function
137    on systems with an lstat function that does not dereference symlinks
138    that are specified with a trailing slash.  */
139 # if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
140 int rpl_lstat PARAMS((const char *, struct stat *));
141 #  undef lstat
142 #  define lstat rpl_lstat
143 # endif
144
145 int rename ();
146
147 /* Arrange to make rename calls go through the wrapper function
148    on systems with a rename function that fails for a source path
149    specified with a trailing slash.  */
150 # if RENAME_TRAILING_SLASH_BUG
151 int rpl_rename PARAMS((const char *, const char *));
152 #  undef rename
153 #  define rename rpl_rename
154 # endif
155
156 int
157 copy PARAMS ((const char *src_path, const char *dst_path,
158               int nonexistent_dst, const struct cp_options *options,
159               int *copy_into_self, int *rename_succeeded));
160
161 #endif