+#if !ENABLE_FEATURE_NON_POSIX_CP
+ if (!(flags & (FILEUTILS_FORCE|FILEUTILS_INTERACTIVE))) {
+ /* Either it exists, or the *path* doesnt exist */
+ bb_perror_msg("can't create '%s'", dest);
+ return -1;
+ }
+#endif
+ // else: act as if -f is always in effect.
+ // We don't want "can't create" msg, we want unlink to be done
+ // (silently unless -i). Why? POSIX cp usually succeeds with
+ // O_TRUNC open of existing file, and user is left ignorantly happy.
+ // With above block unconditionally enabled, non-POSIX cp
+ // will complain a lot more than POSIX one.
+
+ /* TODO: maybe we should do it only if ctty is present? */
+ if (flags & FILEUTILS_INTERACTIVE) {
+ // We would not do POSIX insanity. -i asks,
+ // then _unlinks_ the offender. Presto.
+ // (No "opening without O_EXCL", no "unlink only if -f")
+ // Or else we will end up having 3 open()s!
+ fprintf(stderr, "%s: overwrite '%s'? ", applet_name, dest);
+ if (!bb_ask_confirmation())
+ return 0; /* not allowed to overwrite */
+ }
+ if (unlink(dest) < 0) {
+#if ENABLE_FEATURE_VERBOSE_CP_MESSAGE
+ if (e == errno && e == ENOENT) {
+ /* e == ENOTDIR is similar: path has non-dir component,
+ * but in this case we don't even reach copy_file() */
+ bb_error_msg("can't create '%s': Path does not exist", dest);
+ return -1; /* error */
+ }
+#endif
+ errno = e; /* do not use errno from unlink */
+ bb_perror_msg("can't create '%s'", dest);
+ return -1; /* error */
+ }
+#if ENABLE_FEATURE_CP_LONG_OPTIONS
+ if (flags & FILEUTILS_RMDEST)
+ if (flags & FILEUTILS_VERBOSE)
+ printf("removed '%s'\n", dest);
+#endif
+ return 1; /* ok (to try again) */
+}