da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1992-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Glenn Fowler
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Research
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner"[-?@(#)$Id: cp (AT&T Research) 2010-01-20 $\n]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+NAME?cp - copy files]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+DESCRIPTION?If the last argument names an existing directory, \bcp\b"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" copies each \afile\a into a file with the same name in that"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" directory. Otherwise, if only two files are given, \bcp\b copies"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" the first onto the second. It is an error if the last argument is"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" not a directory and more than two files are given. By default"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" directories are not copied.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[a:archive?Preserve as much as possible of the structure and attributes of"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" the original files in the copy. Equivalent to \b--physical\b"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" \b--preserve\b \b--recursive\b.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[p:preserve?Preserve file owner, group, permissions and timestamps.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[h:hierarchy|parents?Form the name of each destination file by appending"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" to the target directory a slash and the specified source file name."
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" The last argument must be an existing directory. Missing destination"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" directories are created.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[H:metaphysical?Follow command argument symbolic links, otherwise don't"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" follow.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[l:link?Make hard links to destination files instead of copies.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[L:logical|dereference?Follow symbolic links and copy the files"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" they point to.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[P|d:physical|nodereference?Don't follow symbolic links; copy symbolic"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" rather than the files they point to.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+NAME?ln - link files]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+DESCRIPTION?If the last argument names an existing directory, \bln\b"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" links each \afile\a into a file with the same name in that"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" directory. Otherwise, if only two files are given, \bln\b links"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" the first onto the second. It is an error if the last argument is"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" not a directory and more than two files are given. By default"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" directories are not linked.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+NAME?mv - rename files]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+DESCRIPTION?If the last argument names an existing directory, \bmv\b"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" renames each \afile\a into a file with the same name in that"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" directory. Otherwise, if only two files are given, \bmv\b renames"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" the first onto the second. It is an error if the last argument is"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" not a directory and more than two files are given. If a source and"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" destination file reside on different filesystems then \bmv\b copies"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" the file contents to the destination and then deletes the source"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[f:force?Replace existing destination files.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[i:interactive|prompt?Prompt whether to replace existing destination files."
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" An affirmative response (\by\b or \bY\b) replaces the file, a quit"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" response (\bq\b or \bQ\b) exits immediately, and all other"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" responses skip the file.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[r|R:recursive?Operate on the contents of directories recursively.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[s:symlink|symbolic-link?Make symbolic links to destination files.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[u:update?Replace a destination file only if its modification time is older"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" than the corresponding source file modification time.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[v:verbose?Print the name of each file before operating on it.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[b:backup?Make backups of files that are about to be replaced. See"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" \b--suffix\b and \b--version-control\b for more information.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[F:fsync|sync?\bfsync\b(2) each file after it is copied.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[S:backup-suffix|suffix?A backup file is made by renaming the file to the"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" same name with the backup suffix appended. The backup suffix is"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" determined in this order: this option, the \bSIMPLE_BACKUP_SUFFIX\b,"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" environment variable, or the default value \b~\b.]:[suffix]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[V:backup-type|version-control?The backup type is determined in this order:"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" this option, the \bVERSION_CONTROL\b environment variable, or the"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" default value \bexisting\b. \atype\a may be one of:]:[type]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" [+numbered|t?Always make numbered backups. The numbered backup"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" suffix is \b.\aSNS\a, where \aS\a is the"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" \bbackup-suffix\b and \aN\a is the version number,"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" starting at 1, incremented with each version.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" [+existing|nil?Make numbered backups of files that already"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" have them, otherwise simple backups.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" [+simple|never?Always make simple backups.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[x|X|l:xdev|local|mount|one-file-system?Do not descend into directories in"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" different filesystems than their parents.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"\nsource destination\n"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"file ... directory\n"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+SEE ALSO?\bpax\b(1), \bfsync\b(2), \brename\b(2), \bunlink\b(2),"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin" \bremove\b(3)]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define BAK_existing 1 /* number if already else simple*/
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#define INITSTATE pathsiz /* (re)init state before this */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * preserve support
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinpreserve(State_t* state, const char* path, struct stat* ns, struct stat* os)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (tmxtouch(path, tmxgetatime(os), tmxgetmtime(os), TMX_NOTIME, 0))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot reset access and modify times", path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin n = ((ns->st_uid != os->st_uid) << 1) | (ns->st_gid != os->st_gid);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin switch (n)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot reset group to %s", path, fmtgid(os->st_gid));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot reset owner to %s", path, fmtuid(os->st_uid));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot reset owner to %s and group to %s", path, fmtuid(os->st_uid), fmtgid(os->st_gid));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * visit a single file and state.op to the destination
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (*base)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((state->postsiz + len) > state->pathsiz && !(state->path = newof(state->path, char, state->pathsiz = roundof(state->postsiz + len, PATH_CHUNK), 0)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (state->hierarchy && ent->fts_level == 0 && strchr(base, '/'))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot create directory -- %s ignored", state->path, ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *e++ = '/';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (state->preserve && state->op != LN || ent->fts_level > 0 && (ent->fts_statp->st_mode & S_IRWXU) != S_IRWXU)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((ent->fts_statp->st_mode & S_IPERM) != (st.st_mode & S_IPERM) && chmod(state->path, ent->fts_statp->st_mode & S_IPERM))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot reset directory mode to %s", state->path, fmtmode(st.st_mode & S_IPERM, 0) + 1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(1, "%s: directory -- copying as plain file", ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(2, "%s: cannot search directory", ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /*FALLTHROUGH*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(2, "%s: not a directory -- %s ignored", state->path, ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (mkdir(state->path, (ent->fts_statp->st_mode & S_IPERM)|(ent->fts_info == FTS_D ? S_IRWXU : 0)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot create directory -- %s ignored", state->path, ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(2, "%s: cannot copy non-terminal symbolic link", ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (state->update && !S_ISDIR(st.st_mode) && (unsigned long)ent->fts_statp->st_mtime < (unsigned long)st.st_mtime)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * target is in top 3d view
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (st.st_dev == ent->fts_statp->st_dev && st.st_ino == ent->fts_statp->st_ino)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * let rename() handle it
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(2, "%s: identical to %s", state->path, ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(2, "%s: cannot %s existing directory", state->path, state->opname);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (astquery(-1, "%s %s? ", state->opname, state->path) < 0 || sh_checksig(state->context))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(2, "%s: cannot %s existing file", state->path, state->opname);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fmtmode(st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO), 0) + 1;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (astquery(-1, "override protection %s for %s? ", protection, state->path) < 0 || sh_checksig(state->context))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (!rm)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(2, "%s: cannot %s %s protection", state->path, state->opname, protection);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin e = (char*)dot;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fts = fts_open((char**)e, FTS_NOCHDIR|FTS_ONEPATH|FTS_PHYSICAL|FTS_NOPOSTORDER|FTS_NOSTAT|FTS_NOSEEDOTDIR, NiL))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (strneq(s, sub->fts_name, n) && sub->fts_name[n] == '.' && strneq(sub->fts_name + n + 1, state->suffix, state->suflen) && (m = strtol(sub->fts_name + n + state->suflen + 1, &e, 10)) && streq(e, state->suffix) && m > v)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *--s = '/';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(state->tmp, "%s.%s%d%s", state->path, state->suffix, v + 1, state->suffix);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /*FALLTHROUGH*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(state->tmp, "%s%s", state->path, state->suffix);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|3, "%s: out of space", state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot backup to %s", state->path, s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot remove", state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (errno != EXDEV && (rm || S_ISDIR(ent->fts_statp->st_mode)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot rename to %s", ent->fts_path, state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /*FALLTHROUGH*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((n = pathgetlink(ent->fts_path, state->text, sizeof(state->text) - 1)) < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot read symbolic link text", ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot copy symbolic link to %s", ent->fts_path, state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (state->op == CP || S_ISREG(ent->fts_statp->st_mode) || S_ISDIR(ent->fts_statp->st_mode))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (ent->fts_statp->st_size > 0 && (rfd = open(ent->fts_path, O_RDONLY|O_BINARY)) < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot read", ent->fts_path);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin else if ((wfd = open(state->path, st.st_mode ? (state->wflags & ~O_EXCL) : state->wflags, ent->fts_statp->st_mode & state->perm)) < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot write", state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: %s read stream error", ent->fts_path, state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(op = sfnew(NiL, NiL, SF_UNBOUND, wfd, SF_WRITE)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: %s write stream error", ent->fts_path, state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (sfsync(op) || state->sync && fsync(wfd) || sfclose(op))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: %s %s error", ent->fts_path, state->path, n == 1 ? ERROR_translate(0, 0, 0, "read") : n == 2 ? ERROR_translate(0, 0, 0, "write") : ERROR_translate(0, 0, 0, "io"));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (S_ISBLK(ent->fts_statp->st_mode) || S_ISCHR(ent->fts_statp->st_mode) || S_ISFIFO(ent->fts_statp->st_mode))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (mknod(state->path, ent->fts_statp->st_mode, idevice(ent->fts_statp)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot copy special file to %s", ent->fts_path, state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(2, "%s: cannot copy -- unknown file type 0%o", ent->fts_path, S_ITYPE(ent->fts_statp->st_mode));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((ent->fts_statp->st_mode & state->perm) != (st.st_mode & state->perm) && chmod(state->path, ent->fts_statp->st_mode & state->perm))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot reset mode to %s", state->path, fmtmode(st.st_mode & state->perm, 0) + 1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|1, "%s: cannot remove", ent->fts_path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(ERROR_SYSTEM|2, "%s: cannot link to %s", ent->fts_path, state->path);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin cmdinit(argc, argv, context, ERROR_CATALOG, ERROR_NOTIFY);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (!(sh = CMD_CONTEXT(context)) || !(state = (State_t*)sh->ptr))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin state->wflags = O_WRONLY|O_CREAT|O_TRUNC|O_BINARY;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin standard = !strcmp(astconf("CONFORMANCE", NiL, NiL), "standard");
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin error(ERROR_SYSTEM|3, "%s: out of space", state->path);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin state->opname = state->op == CP ? ERROR_translate(0, 0, 0, "overwrite") : ERROR_translate(0, 0, 0, "replace");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(1, "%s not implemented on this system", opt_info.name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (*argv && streq(*argv, "-") && !streq(*(argv - 1), "--"))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(v = (char**)stkalloc(stkstd, (argc + 2) * sizeof(char*))))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(file = backup_type) && !(backup_type = getenv("VERSION_CONTROL")))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (!state->suffix && !(state->suffix = getenv("SIMPLE_BACKUP_SUFFIX")))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (*s == '/')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(!*s || *s == '.' && (!*++s || *s == '.' && !*++s)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (!(state->directory = !stat(file, &st) && S_ISDIR(st.st_mode)) && argc > 1)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if ((state->fs3d = fs3d(FS3D_TEST)) && strmatch(file, "...|*/...|.../*"))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (state->pathsiz < roundof(state->postsiz + 2, PATH_CHUNK) && !(state->path = newof(state->path, char, state->pathsiz = roundof(state->postsiz + 2, PATH_CHUNK), 0)))
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if (state->directory && state->path[state->postsiz - 1] != '/')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin error(3, "%s: last argument must be a directory", file);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin state->perm = state->uid ? S_IPERM : (S_IPERM & ~S_ISVTX);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while (!sh_checksig(context) && (ent = fts_read(fts)) && !visit(state, ent));
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin error(ERROR_SYSTEM|2, "%s: cannot link to %s", *argv, state->path);