Fix warnings inspired by lint, a commercial lint and WARNS=4.
This commit is contained in:
parent
ece5764570
commit
8bd08b5fac
@ -4,6 +4,5 @@
|
||||
PROG= cp
|
||||
SRCS= cp.c utils.c
|
||||
CFLAGS+= -DVM_AND_BUFFER_CACHE_SYNCHRONIZED
|
||||
WARNS= 0
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
14
bin/cp/cp.c
14
bin/cp/cp.c
@ -82,9 +82,12 @@ static const char rcsid[] =
|
||||
*--(p).p_end = 0; \
|
||||
}
|
||||
|
||||
PATH_T to = { to.p_path, "", "" };
|
||||
static char emptystring[] = "";
|
||||
|
||||
int Rflag, iflag, pflag, rflag, fflag, vflag;
|
||||
PATH_T to = { to.p_path, emptystring, "" };
|
||||
|
||||
int iflag, pflag, fflag;
|
||||
static int Rflag, rflag, vflag;
|
||||
|
||||
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
||||
|
||||
@ -241,7 +244,8 @@ copy(char *argv[], enum op type, int fts_options)
|
||||
struct stat to_stat;
|
||||
FTS *ftsp;
|
||||
FTSENT *curr;
|
||||
int base = 0, dne, badcp, nlen, rval;
|
||||
int base = 0, dne, badcp, rval;
|
||||
size_t nlen;
|
||||
char *p, *target_mid;
|
||||
mode_t mask, mode;
|
||||
|
||||
@ -267,6 +271,7 @@ copy(char *argv[], enum op type, int fts_options)
|
||||
warnx("%s: directory causes a cycle", curr->fts_path);
|
||||
badcp = rval = 1;
|
||||
continue;
|
||||
default:
|
||||
}
|
||||
|
||||
/*
|
||||
@ -370,7 +375,8 @@ copy(char *argv[], enum op type, int fts_options)
|
||||
}
|
||||
if (!S_ISDIR(curr->fts_statp->st_mode) &&
|
||||
S_ISDIR(to_stat.st_mode)) {
|
||||
warnx("cannot overwrite directory %s with non-directory %s",
|
||||
warnx("cannot overwrite directory %s with "
|
||||
"non-directory %s",
|
||||
to.p_path, curr->fts_path);
|
||||
badcp = rval = 1;
|
||||
continue;
|
||||
|
@ -35,15 +35,13 @@
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
char *p_end; /* pointer to NULL at end of path */
|
||||
char *target_end; /* pointer to end of target base */
|
||||
char p_path[PATH_MAX]; /* pointer to the start of a path */
|
||||
char *p_end; /* pointer to NULL at end of path */
|
||||
char *target_end; /* pointer to end of target base */
|
||||
char p_path[PATH_MAX]; /* pointer to the start of a path */
|
||||
} PATH_T;
|
||||
|
||||
extern PATH_T to;
|
||||
extern int iflag, pflag, fflag, vflag;
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
extern int iflag, pflag, fflag;
|
||||
|
||||
__BEGIN_DECLS
|
||||
int copy_fifo(struct stat *, int);
|
||||
|
@ -41,7 +41,6 @@ static const char rcsid[] =
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
@ -115,7 +114,7 @@ copy_file(FTSENT *entp, int dne)
|
||||
if (to_fd == -1) {
|
||||
warn("%s", to.p_path);
|
||||
(void)close(from_fd);
|
||||
return (1);;
|
||||
return (1);
|
||||
}
|
||||
|
||||
rval = 0;
|
||||
@ -191,19 +190,19 @@ int
|
||||
copy_link(FTSENT *p, int exists)
|
||||
{
|
||||
int len;
|
||||
char link[PATH_MAX];
|
||||
char llink[PATH_MAX];
|
||||
|
||||
if ((len = readlink(p->fts_path, link, sizeof(link) - 1)) == -1) {
|
||||
if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) {
|
||||
warn("readlink: %s", p->fts_path);
|
||||
return (1);
|
||||
}
|
||||
link[len] = '\0';
|
||||
llink[len] = '\0';
|
||||
if (exists && unlink(to.p_path)) {
|
||||
warn("unlink: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (symlink(link, to.p_path)) {
|
||||
warn("symlink: %s", link);
|
||||
if (symlink(llink, to.p_path)) {
|
||||
warn("symlink: %s", llink);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
@ -237,9 +236,6 @@ copy_special(struct stat *from_stat, int exists)
|
||||
return (pflag ? setfile(from_stat, 0) : 0);
|
||||
}
|
||||
|
||||
#define RETAINBITS \
|
||||
(S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
|
||||
int
|
||||
setfile(struct stat *fs, int fd)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user