- char newdestName[NAME_MAX];
-
- if (argc < 3) {
- fprintf(stderr, "Usage: %s", mv_usage);
- exit (FALSE);
- }
- argc--;
- argv++;
-
- destName = argv[argc - 1];
- dirFlag = isDirectory(destName);
-
- if ((argc > 3) && dirFlag==FALSE) {
- fprintf(stderr, "%s: not a directory\n", destName);
- exit (FALSE);
- }
-
- while (argc-- > 1) {
- srcName = *(argv++);
- skipName = strrchr(srcName, '/');
- if (skipName)
- skipName++;
- strcpy(newdestName, destName);
- if (dirFlag==TRUE) {
- strcat(newdestName, "/");
- if ( skipName != NULL)
- strcat(newdestName, strstr(srcName, skipName));
+ struct stat dest_stat;
+ int dest_exists = 1;
+
+ if (stat(dest, &dest_stat) < 0) {
+ if (errno != ENOENT) {
+ perror_msg("unable to stat `%s'", dest);
+ return -1;
+ }
+ dest_exists = 0;
+ }
+
+ if (dest_exists && !(flags & FILEUTILS_FORCE) &&
+ ((access(dest, W_OK) < 0 && isatty(0)) ||
+ (flags & FILEUTILS_INTERACTIVE))) {
+ fprintf(stderr, "mv: overwrite `%s'? ", dest);
+ if (!ask_confirmation())
+ return 0;