Avoid spurious failure on x86 solaris2.9 when using c89.
[coreutils.git] / src / copy.h
blob1308962fb1b3b6eb3485bd948b01322964c3f199
1 #ifndef COPY_H
2 # define COPY_H
4 # include <stdbool.h>
5 # include "hash.h"
7 /* Control creation of sparse files (files with holes). */
8 enum Sparse_type
10 SPARSE_UNUSED,
12 /* Never create holes in DEST. */
13 SPARSE_NEVER,
15 /* This is the default. Use a crude (and sometimes inaccurate)
16 heuristic to determine if SOURCE has holes. If so, try to create
17 holes in DEST. */
18 SPARSE_AUTO,
20 /* For every sufficiently long sequence of bytes in SOURCE, try to
21 create a corresponding hole in DEST. There is a performance penalty
22 here because CP has to search for holes in SRC. But if the holes are
23 big enough, that penalty can be offset by the decrease in the amount
24 of data written to disk. */
25 SPARSE_ALWAYS
28 /* This type is used to help mv (via copy.c) distinguish these cases. */
29 enum Interactive
31 I_ALWAYS_YES = 1,
32 I_ALWAYS_NO,
33 I_ASK_USER,
34 I_UNSPECIFIED
37 /* How to handle symbolic links. */
38 enum Dereference_symlink
40 DEREF_UNDEFINED = 1,
42 /* Copy the symbolic link itself. -P */
43 DEREF_NEVER,
45 /* If the symbolic is a command line argument, then copy
46 its referent. Otherwise, copy the symbolic link itself. -H */
47 DEREF_COMMAND_LINE_ARGUMENTS,
49 /* Copy the referent of the symbolic link. -L */
50 DEREF_ALWAYS
53 # define VALID_SPARSE_MODE(Mode) \
54 ((Mode) == SPARSE_NEVER \
55 || (Mode) == SPARSE_AUTO \
56 || (Mode) == SPARSE_ALWAYS)
58 /* These options control how files are copied by at least the
59 following programs: mv (when rename doesn't work), cp, install.
60 So, if you add a new member, be sure to initialize it in
61 mv.c, cp.c, and install.c. */
62 struct cp_options
64 enum backup_type backup_type;
66 /* If true, copy all files except (directories and, if not dereferencing
67 them, symbolic links,) as if they were regular files. */
68 bool copy_as_regular;
70 /* How to handle symlinks. */
71 enum Dereference_symlink dereference;
73 /* If true, remove each existing destination nondirectory before
74 trying to open it. */
75 bool unlink_dest_before_opening;
77 /* If true, first try to open each existing destination nondirectory,
78 then, if the open fails, unlink and try again.
79 This option must be set for `cp -f', in case the destination file
80 exists when the open is attempted. It is irrelevant to `mv' since
81 any destination is sure to be removed before the open. */
82 bool unlink_dest_after_failed_open;
84 /* If true, create hard links instead of copying files.
85 Create destination directories as usual. */
86 bool hard_link;
88 /* This value is used to determine whether to prompt before removing
89 each existing destination file. It works differently depending on
90 whether move_mode is set. See code/comments in copy.c. */
91 enum Interactive interactive;
93 /* If true, rather than copying, first attempt to use rename.
94 If that fails, then resort to copying. */
95 bool move_mode;
97 /* This process's effective user ID. */
98 uid_t myeuid;
100 /* If true, when copying recursively, skip any subdirectories that are
101 on different file systems from the one we started on. */
102 bool one_file_system;
104 /* If true, attempt to give the copies the original files' permissions,
105 owner, group, and timestamps. */
106 bool preserve_ownership;
107 bool preserve_mode;
108 bool preserve_timestamps;
110 /* Enabled for mv, and for cp by the --preserve=links option.
111 If true, attempt to preserve in the destination files any
112 logical hard links between the source files. If used with cp's
113 --no-dereference option, and copying two hard-linked files,
114 the two corresponding destination files will also be hard linked.
116 If used with cp's --dereference (-L) option, then, as that option implies,
117 hard links are *not* preserved. However, when copying a file F and
118 a symlink S to F, the resulting S and F in the destination directory
119 will be hard links to the same file (a copy of F). */
120 bool preserve_links;
122 /* If true and any of the above (for preserve) file attributes cannot
123 be applied to a destination file, treat it as a failure and return
124 nonzero immediately. E.g. cp -p requires this be nonzero, mv requires
125 it be zero. */
126 bool require_preserve;
128 /* If true, copy directories recursively and copy special files
129 as themselves rather than copying their contents. */
130 bool recursive;
132 /* If true, set file mode to value of MODE. Otherwise,
133 set it based on current umask modified by UMASK_KILL. */
134 bool set_mode;
136 /* Set the mode of the destination file to exactly this value
137 if SET_MODE is nonzero. */
138 mode_t mode;
140 /* Control creation of sparse files. */
141 enum Sparse_type sparse_mode;
143 /* If true, create symbolic links instead of copying files.
144 Create destination directories as usual. */
145 bool symbolic_link;
147 /* The bits to preserve in created files' modes. */
148 mode_t umask_kill;
150 /* If true, do not copy a nondirectory that has an existing destination
151 with the same or newer modification time. */
152 bool update;
154 /* If true, display the names of the files before copying them. */
155 bool verbose;
157 /* If true, stdin is a tty. */
158 bool stdin_tty;
160 /* This is a set of destination name/inode/dev triples. Each such triple
161 represents a file we have created corresponding to a source file name
162 that was specified on the command line. Use it to avoid clobbering
163 source files in commands like this:
164 rm -rf a b c; mkdir a b c; touch a/f b/f; mv a/f b/f c
165 For now, it protects only regular files when copying (i.e. not renaming).
166 When renaming, it protects all non-directories.
167 Use dest_info_init to initialize it, or set it to NULL to disable
168 this feature. */
169 Hash_table *dest_info;
171 /* FIXME */
172 Hash_table *src_info;
175 # define XSTAT(X, Src_path, Src_sb) \
176 ((X)->dereference == DEREF_NEVER \
177 ? lstat (Src_path, Src_sb) \
178 : stat (Src_path, Src_sb))
180 /* Arrange to make lstat calls go through the wrapper function
181 on systems with an lstat function that does not dereference symlinks
182 that are specified with a trailing slash. */
183 # if ! LSTAT_FOLLOWS_SLASHED_SYMLINK
184 int rpl_lstat (const char *, struct stat *);
185 # undef lstat
186 # define lstat rpl_lstat
187 # endif
189 /* Arrange to make rename calls go through the wrapper function
190 on systems with a rename function that fails for a source path
191 specified with a trailing slash. */
192 # if RENAME_TRAILING_SLASH_BUG
193 int rpl_rename (const char *, const char *);
194 # undef rename
195 # define rename rpl_rename
196 # endif
198 bool
199 copy (const char *src_path, const char *dst_path,
200 bool nonexistent_dst, const struct cp_options *options,
201 bool *copy_into_self, bool *rename_succeeded);
203 void
204 dest_info_init (struct cp_options *);
205 void
206 src_info_init (struct cp_options *);
208 #endif