1/* 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ken Smith of The State University of New York at Buffalo. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 31 unchanged lines hidden (view full) --- 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; 46#endif 47static const char rcsid[] = |
48 "$FreeBSD: head/bin/mv/mv.c 77409 2001-05-29 18:20:36Z imp $"; |
49#endif /* not lint */ 50 51#include <sys/param.h> 52#include <sys/time.h> 53#include <sys/wait.h> 54#include <sys/stat.h> 55#include <sys/mount.h> 56 57#include <err.h> 58#include <errno.h> 59#include <fcntl.h> |
60#include <limits.h> |
61#include <stdio.h> 62#include <stdlib.h> 63#include <string.h> 64#include <sysexits.h> 65#include <unistd.h> 66 67#include "pathnames.h" 68 --- 9 unchanged lines hidden (view full) --- 78main(argc, argv) 79 int argc; 80 char *argv[]; 81{ 82 register int baselen, len, rval; 83 register char *p, *endp; 84 struct stat sb; 85 int ch; |
86 char path[PATH_MAX]; |
87 88 while ((ch = getopt(argc, argv, "fiv")) != -1) 89 switch (ch) { 90 case 'i': 91 iflg = 1; 92 fflg = 0; 93 break; 94 case 'f': --- 38 unchanged lines hidden (view full) --- 133 * may have trailing slashes. 134 */ 135 p = *argv + strlen(*argv); 136 while (p != *argv && p[-1] == '/') 137 --p; 138 while (p != *argv && p[-1] != '/') 139 --p; 140 |
141 if ((baselen + (len = strlen(p))) >= PATH_MAX) { |
142 warnx("%s: destination pathname too long", *argv); 143 rval = 1; 144 } else { 145 memmove(endp, p, (size_t)len + 1); 146 if (do_move(*argv, path)) 147 rval = 1; 148 } 149 } --- 47 unchanged lines hidden (view full) --- 197 if (!rename(from, to)) { 198 if (vflg) 199 printf("%s -> %s\n", from, to); 200 return (0); 201 } 202 203 if (errno == EXDEV) { 204 struct statfs sfs; |
205 char path[PATH_MAX]; |
206 207 /* Can't mv(1) a mount point. */ 208 if (realpath(from, path) == NULL) { 209 warnx("cannot resolve %s: %s", from, path); 210 return (1); 211 } 212 if (!statfs(path, &sfs) && !strcmp(path, sfs.f_mntonname)) { 213 warnx("cannot rename a mount point"); --- 167 unchanged lines hidden --- |