-/* $OpenBSD: utils.c,v 1.41 2018/09/07 07:11:16 martijn Exp $ */
+/* $OpenBSD: utils.c,v 1.42 2018/09/07 07:14:25 martijn Exp $ */
/* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */
/*-
#include "extern.h"
+int copy_overwrite(void);
+
int
copy_file(FTSENT *entp, int dne)
{
static char *buf;
static char *zeroes;
struct stat to_stat, *fs;
- int ch, checkch, from_fd, rcount, rval, to_fd, wcount;
+ int from_fd, rcount, rval, to_fd, wcount;
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
char *p;
#endif
(void)unlink(to.p_path);
/*
- * If the file exists and we're interactive, verify with the user.
* If the file DNE, set the mode to be the from file, minus setuid
* bits, modified by the umask; arguably wrong, but it makes copying
* executables work right and it's been that way forever. (The
* modified by the umask.)
*/
if (!dne && !fflag) {
- if (iflag) {
- (void)fprintf(stderr, "overwrite %s? ", to.p_path);
- checkch = ch = getchar();
- while (ch != '\n' && ch != EOF)
- ch = getchar();
- if (checkch != 'y' && checkch != 'Y') {
- (void)close(from_fd);
- return (2);
- }
- }
+ if (!copy_overwrite()) {
+ (void)close(from_fd);
+ return 2;
+ }
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
} else
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
return (pflag ? setfile(from_stat, -1) : 0);
}
+/*
+ * If the file exists and we're interactive, verify with the user.
+ */
+int
+copy_overwrite(void)
+{
+ int ch, checkch;
+
+ if (iflag) {
+ (void)fprintf(stderr, "overwrite %s? ", to.p_path);
+ checkch = ch = getchar();
+ while (ch != '\n' && ch != EOF)
+ ch = getchar();
+ if (checkch != 'y' && checkch != 'Y')
+ return (0);
+ }
+ return 1;
+}
int
setfile(struct stat *fs, int fd)