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