Cleanup some style(9) issues.
- Whitespace. - Comments. - Wrap long lines. MFC after: 2 weeks X-MFC-with: r284105,r284106 Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
parent
02d6f9793e
commit
70ea701e53
27
bin/cp/cp.c
27
bin/cp/cp.c
@ -75,8 +75,8 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
#define STRIP_TRAILING_SLASH(p) { \
|
#define STRIP_TRAILING_SLASH(p) { \
|
||||||
while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
|
while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
|
||||||
*--(p).p_end = 0; \
|
*--(p).p_end = 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static char emptystring[] = "";
|
static char emptystring[] = "";
|
||||||
@ -188,7 +188,7 @@ main(int argc, char *argv[])
|
|||||||
if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
|
if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
|
||||||
errx(1, "%s: name too long", target);
|
errx(1, "%s: name too long", target);
|
||||||
to.p_end = to.p_path + strlen(to.p_path);
|
to.p_end = to.p_path + strlen(to.p_path);
|
||||||
if (to.p_path == to.p_end) {
|
if (to.p_path == to.p_end) {
|
||||||
*to.p_end++ = '.';
|
*to.p_end++ = '.';
|
||||||
*to.p_end = 0;
|
*to.p_end = 0;
|
||||||
}
|
}
|
||||||
@ -245,10 +245,10 @@ main(int argc, char *argv[])
|
|||||||
type = FILE_TO_FILE;
|
type = FILE_TO_FILE;
|
||||||
|
|
||||||
if (have_trailing_slash && type == FILE_TO_FILE) {
|
if (have_trailing_slash && type == FILE_TO_FILE) {
|
||||||
if (r == -1)
|
if (r == -1) {
|
||||||
errx(1, "directory %s does not exist",
|
errx(1, "directory %s does not exist",
|
||||||
to.p_path);
|
to.p_path);
|
||||||
else
|
} else
|
||||||
errx(1, "%s is not a directory", to.p_path);
|
errx(1, "%s is not a directory", to.p_path);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -299,8 +299,8 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* If we are in case (2) or (3) above, we need to append the
|
* If we are in case (2) or (3) above, we need to append the
|
||||||
* source name to the target name.
|
* source name to the target name.
|
||||||
*/
|
*/
|
||||||
if (type != FILE_TO_FILE) {
|
if (type != FILE_TO_FILE) {
|
||||||
/*
|
/*
|
||||||
* Need to remember the roots of traversals to create
|
* Need to remember the roots of traversals to create
|
||||||
@ -379,7 +379,8 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
mode = curr->fts_statp->st_mode;
|
mode = curr->fts_statp->st_mode;
|
||||||
if ((mode & (S_ISUID | S_ISGID | S_ISTXT)) ||
|
if ((mode & (S_ISUID | S_ISGID | S_ISTXT)) ||
|
||||||
((mode | S_IRWXU) & mask) != (mode & mask))
|
((mode | S_IRWXU) & mask) != (mode & mask))
|
||||||
if (chmod(to.p_path, mode & mask) != 0){
|
if (chmod(to.p_path, mode & mask) !=
|
||||||
|
0) {
|
||||||
warn("chmod: %s", to.p_path);
|
warn("chmod: %s", to.p_path);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
}
|
}
|
||||||
@ -387,7 +388,7 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not an error but need to remember it happened */
|
/* Not an error but need to remember it happened. */
|
||||||
if (stat(to.p_path, &to_stat) == -1)
|
if (stat(to.p_path, &to_stat) == -1)
|
||||||
dne = 1;
|
dne = 1;
|
||||||
else {
|
else {
|
||||||
@ -413,7 +414,7 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
|
|
||||||
switch (curr->fts_statp->st_mode & S_IFMT) {
|
switch (curr->fts_statp->st_mode & S_IFMT) {
|
||||||
case S_IFLNK:
|
case S_IFLNK:
|
||||||
/* Catch special case of a non-dangling symlink */
|
/* Catch special case of a non-dangling symlink. */
|
||||||
if ((fts_options & FTS_LOGICAL) ||
|
if ((fts_options & FTS_LOGICAL) ||
|
||||||
((fts_options & FTS_COMFOLLOW) &&
|
((fts_options & FTS_COMFOLLOW) &&
|
||||||
curr->fts_level == 0)) {
|
curr->fts_level == 0)) {
|
||||||
@ -438,7 +439,7 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
* modified by the umask. Trade-off between being
|
* modified by the umask. Trade-off between being
|
||||||
* able to write the directory (if from directory is
|
* able to write the directory (if from directory is
|
||||||
* 555) and not causing a permissions race. If the
|
* 555) and not causing a permissions race. If the
|
||||||
* umask blocks owner writes, we fail..
|
* umask blocks owner writes, we fail.
|
||||||
*/
|
*/
|
||||||
if (dne) {
|
if (dne) {
|
||||||
if (mkdir(to.p_path,
|
if (mkdir(to.p_path,
|
||||||
@ -467,7 +468,7 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
break;
|
break;
|
||||||
case S_IFSOCK:
|
case S_IFSOCK:
|
||||||
warnx("%s is a socket (not copied).",
|
warnx("%s is a socket (not copied).",
|
||||||
curr->fts_path);
|
curr->fts_path);
|
||||||
break;
|
break;
|
||||||
case S_IFIFO:
|
case S_IFIFO:
|
||||||
if (Rflag && !sflag) {
|
if (Rflag && !sflag) {
|
||||||
|
@ -57,15 +57,19 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#define cp_pct(x, y) ((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
|
#define cp_pct(x, y) ((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
|
||||||
|
|
||||||
/* Memory strategy threshold, in pages: if physmem is larger then this, use a
|
/*
|
||||||
* large buffer */
|
* Memory strategy threshold, in pages: if physmem is larger then this, use a
|
||||||
|
* large buffer.
|
||||||
|
*/
|
||||||
#define PHYSPAGES_THRESHOLD (32*1024)
|
#define PHYSPAGES_THRESHOLD (32*1024)
|
||||||
|
|
||||||
/* Maximum buffer size in bytes - do not allow it to grow larger than this */
|
/* Maximum buffer size in bytes - do not allow it to grow larger than this. */
|
||||||
#define BUFSIZE_MAX (2*1024*1024)
|
#define BUFSIZE_MAX (2*1024*1024)
|
||||||
|
|
||||||
/* Small (default) buffer size in bytes. It's inefficient for this to be
|
/*
|
||||||
* smaller than MAXPHYS */
|
* Small (default) buffer size in bytes. It's inefficient for this to be
|
||||||
|
* smaller than MAXPHYS.
|
||||||
|
*/
|
||||||
#define BUFSIZE_SMALL (MAXPHYS)
|
#define BUFSIZE_SMALL (MAXPHYS)
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -109,7 +113,7 @@ copy_file(const FTSENT *entp, int dne)
|
|||||||
goto done;
|
goto done;
|
||||||
} else if (iflag) {
|
} else if (iflag) {
|
||||||
(void)fprintf(stderr, "overwrite %s? %s",
|
(void)fprintf(stderr, "overwrite %s? %s",
|
||||||
to.p_path, YESNO);
|
to.p_path, YESNO);
|
||||||
checkch = ch = getchar();
|
checkch = ch = getchar();
|
||||||
while (ch != '\n' && ch != EOF)
|
while (ch != '\n' && ch != EOF)
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
@ -119,24 +123,27 @@ copy_file(const FTSENT *entp, int dne)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fflag) {
|
if (fflag) {
|
||||||
/* remove existing destination file name,
|
/*
|
||||||
* create a new file */
|
* Remove existing destination file name create a new
|
||||||
(void)unlink(to.p_path);
|
* file.
|
||||||
if (!lflag && !sflag) {
|
*/
|
||||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
(void)unlink(to.p_path);
|
||||||
fs->st_mode & ~(S_ISUID | S_ISGID));
|
if (!lflag && !sflag) {
|
||||||
}
|
to_fd = open(to.p_path,
|
||||||
|
O_WRONLY | O_TRUNC | O_CREAT,
|
||||||
|
fs->st_mode & ~(S_ISUID | S_ISGID));
|
||||||
|
}
|
||||||
} else if (!lflag && !sflag) {
|
} else if (!lflag && !sflag) {
|
||||||
/* overwrite existing destination file name */
|
/* Overwrite existing destination file name. */
|
||||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
|
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
|
||||||
}
|
}
|
||||||
} else if (!lflag && !sflag) {
|
} else if (!lflag && !sflag) {
|
||||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
||||||
fs->st_mode & ~(S_ISUID | S_ISGID));
|
fs->st_mode & ~(S_ISUID | S_ISGID));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lflag && !sflag && to_fd == -1) {
|
if (!lflag && !sflag && to_fd == -1) {
|
||||||
warn("%s", to.p_path);
|
warn("%s", to.p_path);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
@ -147,20 +154,20 @@ copy_file(const FTSENT *entp, int dne)
|
|||||||
|
|
||||||
if (!lflag && !sflag) {
|
if (!lflag && !sflag) {
|
||||||
/*
|
/*
|
||||||
* Mmap and write if less than 8M (the limit is so we don't totally
|
* Mmap and write if less than 8M (the limit is so we don't
|
||||||
* trash memory on big files. This is really a minor hack, but it
|
* totally trash memory on big files. This is really a minor
|
||||||
* wins some CPU back.
|
* hack, but it wins some CPU back.
|
||||||
* Some filesystems, such as smbnetfs, don't support mmap,
|
* Some filesystems, such as smbnetfs, don't support mmap,
|
||||||
* so this is a best-effort attempt.
|
* so this is a best-effort attempt.
|
||||||
*/
|
*/
|
||||||
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
|
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
|
||||||
if (S_ISREG(fs->st_mode) && fs->st_size > 0 &&
|
if (S_ISREG(fs->st_mode) && fs->st_size > 0 &&
|
||||||
fs->st_size <= 8 * 1024 * 1024 &&
|
fs->st_size <= 8 * 1024 * 1024 &&
|
||||||
(p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
|
(p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
|
||||||
MAP_SHARED, from_fd, (off_t)0)) != MAP_FAILED) {
|
MAP_SHARED, from_fd, (off_t)0)) != MAP_FAILED) {
|
||||||
wtotal = 0;
|
wtotal = 0;
|
||||||
for (bufp = p, wresid = fs->st_size; ;
|
for (bufp = p, wresid = fs->st_size; ;
|
||||||
bufp += wcount, wresid -= (size_t)wcount) {
|
bufp += wcount, wresid -= (size_t)wcount) {
|
||||||
wcount = write(to_fd, bufp, wresid);
|
wcount = write(to_fd, bufp, wresid);
|
||||||
if (wcount <= 0)
|
if (wcount <= 0)
|
||||||
break;
|
break;
|
||||||
@ -205,7 +212,7 @@ copy_file(const FTSENT *entp, int dne)
|
|||||||
wtotal = 0;
|
wtotal = 0;
|
||||||
while ((rcount = read(from_fd, buf, bufsize)) > 0) {
|
while ((rcount = read(from_fd, buf, bufsize)) > 0) {
|
||||||
for (bufp = buf, wresid = rcount; ;
|
for (bufp = buf, wresid = rcount; ;
|
||||||
bufp += wcount, wresid -= wcount) {
|
bufp += wcount, wresid -= wcount) {
|
||||||
wcount = write(to_fd, bufp, wresid);
|
wcount = write(to_fd, bufp, wresid);
|
||||||
if (wcount <= 0)
|
if (wcount <= 0)
|
||||||
break;
|
break;
|
||||||
@ -242,7 +249,7 @@ copy_file(const FTSENT *entp, int dne)
|
|||||||
rval = 1;
|
rval = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Don't remove the target even after an error. The target might
|
* Don't remove the target even after an error. The target might
|
||||||
* not be a regular file, or its attributes might be important,
|
* not be a regular file, or its attributes might be important,
|
||||||
@ -345,7 +352,7 @@ setfile(struct stat *fs, int fd)
|
|||||||
fdval = fd != -1;
|
fdval = fd != -1;
|
||||||
islink = !fdval && S_ISLNK(fs->st_mode);
|
islink = !fdval && S_ISLNK(fs->st_mode);
|
||||||
fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
||||||
S_IRWXU | S_IRWXG | S_IRWXO;
|
S_IRWXU | S_IRWXG | S_IRWXO;
|
||||||
|
|
||||||
tspec[0] = fs->st_atim;
|
tspec[0] = fs->st_atim;
|
||||||
tspec[1] = fs->st_mtim;
|
tspec[1] = fs->st_mtim;
|
||||||
@ -360,7 +367,7 @@ setfile(struct stat *fs, int fd)
|
|||||||
else {
|
else {
|
||||||
gotstat = 1;
|
gotstat = 1;
|
||||||
ts.st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
ts.st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
||||||
S_IRWXU | S_IRWXG | S_IRWXO;
|
S_IRWXU | S_IRWXG | S_IRWXO;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Changing the ownership probably won't succeed, unless we're root
|
* Changing the ownership probably won't succeed, unless we're root
|
||||||
@ -484,7 +491,7 @@ preserve_dir_acls(struct stat *fs, char *source_dir, char *dest_dir)
|
|||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the file is a link we will not follow it
|
* If the file is a link we will not follow it.
|
||||||
*/
|
*/
|
||||||
if (S_ISLNK(fs->st_mode)) {
|
if (S_ISLNK(fs->st_mode)) {
|
||||||
aclgetf = acl_get_link_np;
|
aclgetf = acl_get_link_np;
|
||||||
@ -543,8 +550,10 @@ usage(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
(void)fprintf(stderr, "%s\n%s\n",
|
(void)fprintf(stderr, "%s\n%s\n",
|
||||||
"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpsvx] source_file target_file",
|
"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpsvx] "
|
||||||
" cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpsvx] source_file ... "
|
"source_file target_file",
|
||||||
"target_directory");
|
" cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpsvx] "
|
||||||
|
"source_file ... "
|
||||||
|
"target_directory");
|
||||||
exit(EX_USAGE);
|
exit(EX_USAGE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user