As discusses a little while back on tech-userlevel:
If stdout is a tty, use vis(3) to print any filenames to prevent garbage from being printed if the filename contains control- or other non-printable characters. While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.
This commit is contained in:
parent
9254350d6a
commit
458ed23412
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: cat.c,v 1.35 2002/09/13 18:07:52 thorpej Exp $ */
|
/* $NetBSD: cat.c,v 1.36 2003/08/04 22:31:21 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
@ -47,7 +47,7 @@ __COPYRIGHT(
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
|
static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: cat.c,v 1.35 2002/09/13 18:07:52 thorpej Exp $");
|
__RCSID("$NetBSD: cat.c,v 1.36 2003/08/04 22:31:21 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -63,8 +63,9 @@ __RCSID("$NetBSD: cat.c,v 1.35 2002/09/13 18:07:52 thorpej Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
int bflag, eflag, fflag, lflag, nflag, sflag, tflag, vflag;
|
int bflag, eflag, fflag, lflag, nflag, sflag, stdout_ok, tflag, vflag;
|
||||||
int rval;
|
int rval;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
|
|
||||||
@ -73,6 +74,7 @@ void cook_args(char *argv[]);
|
|||||||
void cook_buf(FILE *);
|
void cook_buf(FILE *);
|
||||||
void raw_args(char *argv[]);
|
void raw_args(char *argv[]);
|
||||||
void raw_cat(int);
|
void raw_cat(int);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -121,6 +123,8 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
if (lflag) {
|
if (lflag) {
|
||||||
stdout_lock.l_len = 0;
|
stdout_lock.l_len = 0;
|
||||||
stdout_lock.l_start = 0;
|
stdout_lock.l_start = 0;
|
||||||
@ -153,7 +157,10 @@ cook_args(char **argv)
|
|||||||
fp = stdin;
|
fp = stdin;
|
||||||
else if ((fp = fopen(*argv,
|
else if ((fp = fopen(*argv,
|
||||||
fflag ? "rf" : "r")) == NULL) {
|
fflag ? "rf" : "r")) == NULL) {
|
||||||
warn("%s", *argv);
|
char *fn;
|
||||||
|
fn = printescaped(*argv);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
++argv;
|
++argv;
|
||||||
continue;
|
continue;
|
||||||
@ -229,7 +236,10 @@ cook_buf(FILE *fp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ferror(fp)) {
|
if (ferror(fp)) {
|
||||||
warn("%s", filename);
|
char *fn;
|
||||||
|
fn = printescaped(filename);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
clearerr(fp);
|
clearerr(fp);
|
||||||
}
|
}
|
||||||
@ -241,6 +251,7 @@ void
|
|||||||
raw_args(char **argv)
|
raw_args(char **argv)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
char *fn;
|
||||||
|
|
||||||
fd = fileno(stdin);
|
fd = fileno(stdin);
|
||||||
filename = "stdin";
|
filename = "stdin";
|
||||||
@ -260,13 +271,17 @@ raw_args(char **argv)
|
|||||||
}
|
}
|
||||||
if (!S_ISREG(st.st_mode)) {
|
if (!S_ISREG(st.st_mode)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
warnx("%s: not a regular file", *argv);
|
fn = printescaped(*argv);
|
||||||
|
warnx("%s: not a regular file", fn);
|
||||||
|
free(fn);
|
||||||
goto skipnomsg;
|
goto skipnomsg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
|
else if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
|
||||||
skip:
|
skip:
|
||||||
warn("%s", *argv);
|
fn = printescaped(*argv);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
skipnomsg:
|
skipnomsg:
|
||||||
rval = 1;
|
rval = 1;
|
||||||
++argv;
|
++argv;
|
||||||
@ -290,6 +305,7 @@ raw_cat(int rfd)
|
|||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
ssize_t nr, nw, off;
|
ssize_t nr, nw, off;
|
||||||
int wfd;
|
int wfd;
|
||||||
|
char *fn;
|
||||||
|
|
||||||
wfd = fileno(stdout);
|
wfd = fileno(stdout);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
@ -308,7 +324,33 @@ raw_cat(int rfd)
|
|||||||
if ((nw = write(wfd, buf + off, (size_t)nr)) < 0)
|
if ((nw = write(wfd, buf + off, (size_t)nr)) < 0)
|
||||||
err(1, "stdout");
|
err(1, "stdout");
|
||||||
if (nr < 0) {
|
if (nr < 0) {
|
||||||
warn("%s", filename);
|
fn = printescaped(filename);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
135
bin/chio/chio.c
135
bin/chio/chio.c
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: chio.c,v 1.19 2002/06/11 05:33:51 itojun Exp $ */
|
/* $NetBSD: chio.c,v 1.20 2003/08/04 22:31:21 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1996, 1998, 1999 The NetBSD Foundation, Inc.
|
* Copyright (c) 1996, 1998, 1999 The NetBSD Foundation, Inc.
|
||||||
@ -46,7 +46,7 @@
|
|||||||
__COPYRIGHT(
|
__COPYRIGHT(
|
||||||
"@(#) Copyright (c) 1996, 1998, 1999\
|
"@(#) Copyright (c) 1996, 1998, 1999\
|
||||||
The NetBSD Foundation, Inc. All rights reserved.");
|
The NetBSD Foundation, Inc. All rights reserved.");
|
||||||
__RCSID("$NetBSD: chio.c,v 1.19 2002/06/11 05:33:51 itojun Exp $");
|
__RCSID("$NetBSD: chio.c,v 1.20 2003/08/04 22:31:21 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
@ -63,10 +63,13 @@ __RCSID("$NetBSD: chio.c,v 1.19 2002/06/11 05:33:51 itojun Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
|
||||||
|
int stdout_ok;
|
||||||
|
|
||||||
int main(int, char *[]);
|
int main(int, char *[]);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
static void cleanup(void);
|
static void cleanup(void);
|
||||||
@ -75,6 +78,7 @@ static int parse_element_unit(const char *);
|
|||||||
static int parse_special(const char *);
|
static int parse_special(const char *);
|
||||||
static int is_special(const char *);
|
static int is_special(const char *);
|
||||||
static const char *bits_to_string(int, const char *);
|
static const char *bits_to_string(int, const char *);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
static int do_move(const char *, int, char **);
|
static int do_move(const char *, int, char **);
|
||||||
static int do_exchange(const char *, int, char **);
|
static int do_exchange(const char *, int, char **);
|
||||||
@ -154,6 +158,7 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
@ -161,6 +166,9 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
usage();
|
usage();
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
/* Get the default changer if not already specified. */
|
/* Get the default changer if not already specified. */
|
||||||
if (changer_name == NULL)
|
if (changer_name == NULL)
|
||||||
@ -169,18 +177,21 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Open the changer device. */
|
/* Open the changer device. */
|
||||||
if ((changer_fd = open(changer_name, O_RDWR, 0600)) == -1)
|
if ((changer_fd = open(changer_name, O_RDWR, 0600)) == -1)
|
||||||
err(1, "%s: open", changer_name);
|
err(EXIT_FAILURE, "%s: open", printescaped(changer_name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
/* Register cleanup function. */
|
/* Register cleanup function. */
|
||||||
if (atexit(cleanup))
|
if (atexit(cleanup))
|
||||||
err(1, "can't register cleanup function");
|
err(EXIT_FAILURE, "can't register cleanup function");
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
/* Find the specified command. */
|
/* Find the specified command. */
|
||||||
for (i = 0; commands[i].cc_name != NULL; ++i)
|
for (i = 0; commands[i].cc_name != NULL; ++i)
|
||||||
if (strcmp(*argv, commands[i].cc_name) == 0)
|
if (strcmp(*argv, commands[i].cc_name) == 0)
|
||||||
break;
|
break;
|
||||||
if (commands[i].cc_name == NULL)
|
if (commands[i].cc_name == NULL)
|
||||||
errx(1, "unknown command: %s", *argv);
|
errx(EXIT_FAILURE, "unknown command: %s", *argv);
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
/* Skip over the command name and call handler. */
|
/* Skip over the command name and call handler. */
|
||||||
++argv; --argc;
|
++argv; --argc;
|
||||||
@ -204,9 +215,11 @@ do_move(const char *cname, int argc, char **argv)
|
|||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
warnx("%s: too few arguments", cname);
|
warnx("%s: too few arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
} else if (argc > 5) {
|
} else if (argc > 5) {
|
||||||
warnx("%s: too many arguments", cname);
|
warnx("%s: too many arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
(void)memset(&cmd, 0, sizeof(cmd));
|
(void)memset(&cmd, 0, sizeof(cmd));
|
||||||
|
|
||||||
@ -234,7 +247,7 @@ do_move(const char *cname, int argc, char **argv)
|
|||||||
cmd.cm_flags |= CM_INVERT;
|
cmd.cm_flags |= CM_INVERT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errx(1, "%s: inappropriate modifier `%s'",
|
errx(EXIT_FAILURE, "%s: inappropriate modifier `%s'",
|
||||||
cname, *argv);
|
cname, *argv);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
@ -242,7 +255,8 @@ do_move(const char *cname, int argc, char **argv)
|
|||||||
|
|
||||||
/* Send command to changer. */
|
/* Send command to changer. */
|
||||||
if (ioctl(changer_fd, CHIOMOVE, &cmd))
|
if (ioctl(changer_fd, CHIOMOVE, &cmd))
|
||||||
err(1, "%s: CHIOMOVE", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOMOVE", printescaped(changer_name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -263,9 +277,11 @@ do_exchange(const char *cname, int argc, char **argv)
|
|||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
warnx("%s: too few arguments", cname);
|
warnx("%s: too few arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
} else if (argc > 8) {
|
} else if (argc > 8) {
|
||||||
warnx("%s: too many arguments", cname);
|
warnx("%s: too many arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
(void)memset(&cmd, 0, sizeof(cmd));
|
(void)memset(&cmd, 0, sizeof(cmd));
|
||||||
|
|
||||||
@ -317,7 +333,7 @@ do_exchange(const char *cname, int argc, char **argv)
|
|||||||
cmd.ce_flags |= CE_INVERT2;
|
cmd.ce_flags |= CE_INVERT2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errx(1, "%s: inappropriate modifier `%s'",
|
errx(EXIT_FAILURE, "%s: inappropriate modifier `%s'",
|
||||||
cname, *argv);
|
cname, *argv);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
@ -325,7 +341,8 @@ do_exchange(const char *cname, int argc, char **argv)
|
|||||||
|
|
||||||
/* Send command to changer. */
|
/* Send command to changer. */
|
||||||
if (ioctl(changer_fd, CHIOEXCHANGE, &cmd))
|
if (ioctl(changer_fd, CHIOEXCHANGE, &cmd))
|
||||||
err(1, "%s: CHIOEXCHANGE", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOEXCHANGE", printescaped(changer_name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -346,9 +363,11 @@ do_position(const char *cname, int argc, char **argv)
|
|||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
warnx("%s: too few arguments", cname);
|
warnx("%s: too few arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
} else if (argc > 3) {
|
} else if (argc > 3) {
|
||||||
warnx("%s: too many arguments", cname);
|
warnx("%s: too many arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
(void)memset(&cmd, 0, sizeof(cmd));
|
(void)memset(&cmd, 0, sizeof(cmd));
|
||||||
|
|
||||||
@ -368,7 +387,7 @@ do_position(const char *cname, int argc, char **argv)
|
|||||||
cmd.cp_flags |= CP_INVERT;
|
cmd.cp_flags |= CP_INVERT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errx(1, "%s: inappropriate modifier `%s'",
|
errx(EXIT_FAILURE, "%s: inappropriate modifier `%s'",
|
||||||
cname, *argv);
|
cname, *argv);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
@ -376,7 +395,8 @@ do_position(const char *cname, int argc, char **argv)
|
|||||||
|
|
||||||
/* Send command to changer. */
|
/* Send command to changer. */
|
||||||
if (ioctl(changer_fd, CHIOPOSITION, &cmd))
|
if (ioctl(changer_fd, CHIOPOSITION, &cmd))
|
||||||
err(1, "%s: CHIOPOSITION", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOPOSITION", printescaped(changer_name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -386,22 +406,27 @@ static int
|
|||||||
do_params(const char *cname, int argc, char **argv)
|
do_params(const char *cname, int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct changer_params data;
|
struct changer_params data;
|
||||||
|
char *cn;
|
||||||
|
|
||||||
/* No arguments to this command. */
|
/* No arguments to this command. */
|
||||||
if (argc) {
|
if (argc) {
|
||||||
warnx("%s: no arguements expected", cname);
|
warnx("%s: no arguements expected", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cn = printescaped(changer_name);
|
||||||
|
|
||||||
/* Get params from changer and display them. */
|
/* Get params from changer and display them. */
|
||||||
(void)memset(&data, 0, sizeof(data));
|
(void)memset(&data, 0, sizeof(data));
|
||||||
if (ioctl(changer_fd, CHIOGPARAMS, &data))
|
if (ioctl(changer_fd, CHIOGPARAMS, &data))
|
||||||
err(1, "%s: CHIOGPARAMS", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOGPARAMS", cn);
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
#define PLURAL(n) (n) > 1 ? "s" : ""
|
#define PLURAL(n) (n) > 1 ? "s" : ""
|
||||||
|
|
||||||
(void)printf("%s: %d slot%s, %d drive%s, %d picker%s",
|
(void)printf("%s: %d slot%s, %d drive%s, %d picker%s",
|
||||||
changer_name,
|
cn,
|
||||||
data.cp_nslots, PLURAL(data.cp_nslots),
|
data.cp_nslots, PLURAL(data.cp_nslots),
|
||||||
data.cp_ndrives, PLURAL(data.cp_ndrives),
|
data.cp_ndrives, PLURAL(data.cp_ndrives),
|
||||||
data.cp_npickers, PLURAL(data.cp_npickers));
|
data.cp_npickers, PLURAL(data.cp_npickers));
|
||||||
@ -411,8 +436,9 @@ do_params(const char *cname, int argc, char **argv)
|
|||||||
|
|
||||||
#undef PLURAL
|
#undef PLURAL
|
||||||
|
|
||||||
(void)printf("\n%s: current picker: %d\n", changer_name,
|
(void)printf("\n%s: current picker: %d\n", cn, data.cp_curpicker);
|
||||||
data.cp_curpicker);
|
|
||||||
|
free(cn);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -422,18 +448,24 @@ static int
|
|||||||
do_getpicker(const char *cname, int argc, char **argv)
|
do_getpicker(const char *cname, int argc, char **argv)
|
||||||
{
|
{
|
||||||
int picker;
|
int picker;
|
||||||
|
char *cn;
|
||||||
|
|
||||||
/* No arguments to this command. */
|
/* No arguments to this command. */
|
||||||
if (argc) {
|
if (argc) {
|
||||||
warnx("%s: no arguments expected", cname);
|
warnx("%s: no arguments expected", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cn = printescaped(changer_name);
|
||||||
|
|
||||||
/* Get current picker from changer and display it. */
|
/* Get current picker from changer and display it. */
|
||||||
if (ioctl(changer_fd, CHIOGPICKER, &picker))
|
if (ioctl(changer_fd, CHIOGPICKER, &picker))
|
||||||
err(1, "%s: CHIOGPICKER", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOGPICKER", cn);
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
(void)printf("%s: current picker: %d\n", changer_name, picker);
|
(void)printf("%s: current picker: %d\n", cn, picker);
|
||||||
|
free(cn);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -446,16 +478,18 @@ do_setpicker(const char *cname, int argc, char **argv)
|
|||||||
if (argc < 1) {
|
if (argc < 1) {
|
||||||
warnx("%s: too few arguments", cname);
|
warnx("%s: too few arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
} else if (argc > 1) {
|
} else if (argc > 1) {
|
||||||
warnx("%s: too many arguments", cname);
|
warnx("%s: too many arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
picker = parse_element_unit(*argv);
|
picker = parse_element_unit(*argv);
|
||||||
|
|
||||||
/* Set the changer picker. */
|
/* Set the changer picker. */
|
||||||
if (ioctl(changer_fd, CHIOSPICKER, &picker))
|
if (ioctl(changer_fd, CHIOSPICKER, &picker))
|
||||||
err(1, "%s: CHIOSPICKER", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOSPICKER", printescaped(changer_name));
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -469,6 +503,7 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
int i, chet, count, echet, flags, have_ucount, have_unit;
|
int i, chet, count, echet, flags, have_ucount, have_unit;
|
||||||
int schet, ucount, unit;
|
int schet, ucount, unit;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
char *cn;
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
have_ucount = 0;
|
have_ucount = 0;
|
||||||
@ -487,15 +522,19 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
if (argc > 4) {
|
if (argc > 4) {
|
||||||
warnx("%s: too many arguments", cname);
|
warnx("%s: too many arguments", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cn = printescaped(changer_name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get params from changer. Specifically, we need the element
|
* Get params from changer. Specifically, we need the element
|
||||||
* counts.
|
* counts.
|
||||||
*/
|
*/
|
||||||
(void)memset(&data, 0, sizeof(data));
|
(void)memset(&data, 0, sizeof(data));
|
||||||
if (ioctl(changer_fd, CHIOGPARAMS, &data))
|
if (ioctl(changer_fd, CHIOGPARAMS, &data))
|
||||||
err(1, "%s: CHIOGPARAMS", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOGPARAMS", cn);
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
schet = CHET_MT;
|
schet = CHET_MT;
|
||||||
echet = CHET_DT;
|
echet = CHET_DT;
|
||||||
@ -509,10 +548,13 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
warnx("%s: malformed command line", cname);
|
warnx("%s: malformed command line", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
if (parse_special(argv[0]) != SW_VOLTAGS)
|
if (parse_special(argv[0]) != SW_VOLTAGS)
|
||||||
errx(1, "%s: inappropriate special word: %s",
|
errx(EXIT_FAILURE,
|
||||||
|
"%s: inappropriate special word: %s",
|
||||||
cname, argv[0]);
|
cname, argv[0]);
|
||||||
|
/* NOTREACHED */
|
||||||
flags |= CESR_VOLTAGS;
|
flags |= CESR_VOLTAGS;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -526,6 +568,7 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
have_ucount) {
|
have_ucount) {
|
||||||
warnx("%s: malformed command line", cname);
|
warnx("%s: malformed command line", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
schet = echet = parse_element_type(argv[0]);
|
schet = echet = parse_element_type(argv[0]);
|
||||||
continue;
|
continue;
|
||||||
@ -538,6 +581,7 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
if (schet != echet) {
|
if (schet != echet) {
|
||||||
warnx("%s: malformed command line", cname);
|
warnx("%s: malformed command line", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
i = parse_element_unit(argv[0]);
|
i = parse_element_unit(argv[0]);
|
||||||
@ -551,6 +595,7 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
warnx("%s: malformed command line", cname);
|
warnx("%s: malformed command line", cname);
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,8 +623,9 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
else {
|
else {
|
||||||
(void)printf("%s: no %s elements\n",
|
(void)printf("%s: no %s elements\n",
|
||||||
changer_name,
|
cn,
|
||||||
elements[chet].et_name);
|
elements[chet].et_name);
|
||||||
|
free(cn);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -599,14 +645,16 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((unit + ucount) > count)
|
if ((unit + ucount) > count)
|
||||||
errx(1, "%s: unvalid unit/count %d/%d",
|
errx(EXIT_FAILURE, "%s: unvalid unit/count %d/%d",
|
||||||
cname, unit, ucount);
|
cname, unit, ucount);
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
size = ucount * sizeof(struct changer_element_status);
|
size = ucount * sizeof(struct changer_element_status);
|
||||||
|
|
||||||
/* Allocate storage for the status bytes. */
|
/* Allocate storage for the status bytes. */
|
||||||
if ((ces = malloc(size)) == NULL)
|
if ((ces = malloc(size)) == NULL)
|
||||||
errx(1, "can't allocate status storage");
|
errx(EXIT_FAILURE, "can't allocate status storage");
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
(void)memset(ces, 0, size);
|
(void)memset(ces, 0, size);
|
||||||
(void)memset(&cmd, 0, sizeof(cmd));
|
(void)memset(&cmd, 0, sizeof(cmd));
|
||||||
@ -624,7 +672,8 @@ do_status(const char *cname, int argc, char **argv)
|
|||||||
|
|
||||||
if (ioctl(changer_fd, CHIOGSTATUS, &cmd)) {
|
if (ioctl(changer_fd, CHIOGSTATUS, &cmd)) {
|
||||||
free(ces);
|
free(ces);
|
||||||
err(1, "%s: CHIOGSTATUS", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOGSTATUS", cn);
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dump the status for each element of this type. */
|
/* Dump the status for each element of this type. */
|
||||||
@ -670,7 +719,8 @@ do_ielem(const char *cname, int argc, char **argv)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (ioctl(changer_fd, CHIOIELEM, NULL))
|
if (ioctl(changer_fd, CHIOIELEM, NULL))
|
||||||
err(1, "%s: CHIOIELEM", changer_name);
|
err(EXIT_FAILURE, "%s: CHIOIELEM", printescaped(changer_name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -699,6 +749,7 @@ do_cdlu(const char *cname, int argc, char **argv)
|
|||||||
|
|
||||||
if (argc < 1 || argc > 2)
|
if (argc < 1 || argc > 2)
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
|
|
||||||
for (i = 0; cdlu_subcmds[i].sw_name != NULL; i++) {
|
for (i = 0; cdlu_subcmds[i].sw_name != NULL; i++) {
|
||||||
if (strcmp(argv[0], cdlu_subcmds[i].sw_name) == 0) {
|
if (strcmp(argv[0], cdlu_subcmds[i].sw_name) == 0) {
|
||||||
@ -708,6 +759,7 @@ do_cdlu(const char *cname, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (cdlu_subcmds[i].sw_name == NULL)
|
if (cdlu_subcmds[i].sw_name == NULL)
|
||||||
usage();
|
usage();
|
||||||
|
/*NOTREACHED*/
|
||||||
|
|
||||||
if (strcmp(argv[0], "abort") == 0)
|
if (strcmp(argv[0], "abort") == 0)
|
||||||
cmd.slot = 0;
|
cmd.slot = 0;
|
||||||
@ -719,7 +771,8 @@ do_cdlu(const char *cname, int argc, char **argv)
|
|||||||
* XXX handling for cdlu; think about this some more.
|
* XXX handling for cdlu; think about this some more.
|
||||||
*/
|
*/
|
||||||
if (ioctl(changer_fd, CDIOCLOADUNLOAD, &cmd))
|
if (ioctl(changer_fd, CDIOCLOADUNLOAD, &cmd))
|
||||||
err(1, "%s: CDIOCLOADUNLOAD", changer_name);
|
err(EXIT_FAILURE, "%s: CDIOCLOADUNLOAD", printescaped(changer_name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -733,7 +786,7 @@ parse_element_type(const char *cp)
|
|||||||
if (strcmp(elements[i].et_name, cp) == 0)
|
if (strcmp(elements[i].et_name, cp) == 0)
|
||||||
return (elements[i].et_type);
|
return (elements[i].et_type);
|
||||||
|
|
||||||
errx(1, "invalid element type `%s'", cp);
|
errx(EXIT_FAILURE, "invalid element type `%s'", cp);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,7 +798,7 @@ parse_element_unit(const char *cp)
|
|||||||
|
|
||||||
i = (int)strtol(cp, &p, 10);
|
i = (int)strtol(cp, &p, 10);
|
||||||
if ((i < 0) || (*p != '\0'))
|
if ((i < 0) || (*p != '\0'))
|
||||||
errx(1, "invalid unit number `%s'", cp);
|
errx(EXIT_FAILURE, "invalid unit number `%s'", cp);
|
||||||
|
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
@ -759,7 +812,7 @@ parse_special(const char *cp)
|
|||||||
if (val)
|
if (val)
|
||||||
return (val);
|
return (val);
|
||||||
|
|
||||||
errx(1, "invalid modifier `%s'", cp);
|
errx(EXIT_FAILURE, "invalid modifier `%s'", cp);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -826,3 +879,27 @@ usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: chmod.c,v 1.28 2002/07/07 11:44:02 bjh21 Exp $ */
|
/* $NetBSD: chmod.c,v 1.29 2003/08/04 22:31:22 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993, 1994
|
* Copyright (c) 1989, 1993, 1994
|
||||||
@ -44,12 +44,13 @@ __COPYRIGHT(
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)chmod.c 8.8 (Berkeley) 4/1/94";
|
static char sccsid[] = "@(#)chmod.c 8.8 (Berkeley) 4/1/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: chmod.c,v 1.28 2002/07/07 11:44:02 bjh21 Exp $");
|
__RCSID("$NetBSD: chmod.c,v 1.29 2003/08/04 22:31:22 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -60,9 +61,13 @@ __RCSID("$NetBSD: chmod.c,v 1.28 2002/07/07 11:44:02 bjh21 Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
int main(int, char *[]);
|
int stdout_ok;
|
||||||
void usage(void);
|
|
||||||
|
int main(int, char *[]);
|
||||||
|
void usage(void);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -71,7 +76,7 @@ main(int argc, char *argv[])
|
|||||||
FTSENT *p;
|
FTSENT *p;
|
||||||
mode_t *set;
|
mode_t *set;
|
||||||
int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval;
|
int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval;
|
||||||
char *mode;
|
char *mode, *fn;
|
||||||
int (*change_mode)(const char *, mode_t);
|
int (*change_mode)(const char *, mode_t);
|
||||||
|
|
||||||
setprogname(argv[0]);
|
setprogname(argv[0]);
|
||||||
@ -131,11 +136,15 @@ done: argv += optind;
|
|||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
fts_options = FTS_PHYSICAL;
|
fts_options = FTS_PHYSICAL;
|
||||||
if (Rflag) {
|
if (Rflag) {
|
||||||
if (hflag)
|
if (hflag) {
|
||||||
errx(1,
|
errx(EXIT_FAILURE,
|
||||||
"the -R and -h options may not be specified together.");
|
"the -R and -h options may not be specified together.");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
if (Hflag)
|
if (Hflag)
|
||||||
fts_options |= FTS_COMFOLLOW;
|
fts_options |= FTS_COMFOLLOW;
|
||||||
if (Lflag) {
|
if (Lflag) {
|
||||||
@ -150,11 +159,15 @@ done: argv += optind;
|
|||||||
change_mode = chmod;
|
change_mode = chmod;
|
||||||
|
|
||||||
mode = *argv;
|
mode = *argv;
|
||||||
if ((set = setmode(mode)) == NULL)
|
if ((set = setmode(mode)) == NULL) {
|
||||||
errx(1, "invalid file mode: %s", mode);
|
errx(EXIT_FAILURE, "invalid file mode: %s", mode);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL)
|
if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL) {
|
||||||
err(1, "fts_open");
|
err(EXIT_FAILURE, "fts_open");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
|
for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
|
||||||
switch (p->fts_info) {
|
switch (p->fts_info) {
|
||||||
case FTS_D:
|
case FTS_D:
|
||||||
@ -162,14 +175,18 @@ done: argv += optind;
|
|||||||
(void)fts_set(ftsp, p, FTS_SKIP);
|
(void)fts_set(ftsp, p, FTS_SKIP);
|
||||||
break;
|
break;
|
||||||
case FTS_DNR: /* Warn, chmod, continue. */
|
case FTS_DNR: /* Warn, chmod, continue. */
|
||||||
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
|
fn = printescaped(p->fts_path);
|
||||||
|
warnx("%s: %s", fn, strerror(p->fts_errno));
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
break;
|
break;
|
||||||
case FTS_DP: /* Already changed at FTS_D. */
|
case FTS_DP: /* Already changed at FTS_D. */
|
||||||
continue;
|
continue;
|
||||||
case FTS_ERR: /* Warn, continue. */
|
case FTS_ERR: /* Warn, continue. */
|
||||||
case FTS_NS:
|
case FTS_NS:
|
||||||
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
|
fn = printescaped(p->fts_path);
|
||||||
|
warnx("%s: %s", fn, strerror(p->fts_errno));
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
continue;
|
continue;
|
||||||
case FTS_SL: /* Ignore. */
|
case FTS_SL: /* Ignore. */
|
||||||
@ -188,12 +205,16 @@ done: argv += optind;
|
|||||||
}
|
}
|
||||||
if ((*change_mode)(p->fts_accpath,
|
if ((*change_mode)(p->fts_accpath,
|
||||||
getmode(set, p->fts_statp->st_mode)) && !fflag) {
|
getmode(set, p->fts_statp->st_mode)) && !fflag) {
|
||||||
warn("%s", p->fts_path);
|
fn = printescaped(p->fts_path);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (errno)
|
if (errno) {
|
||||||
err(1, "fts_read");
|
err(EXIT_FAILURE, "fts_read");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
exit(rval);
|
exit(rval);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
@ -207,3 +228,27 @@ usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
108
bin/cp/cp.c
108
bin/cp/cp.c
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: cp.c,v 1.32 2002/12/16 14:44:14 jrf Exp $ */
|
/* $NetBSD: cp.c,v 1.33 2003/08/04 22:31:22 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988, 1993, 1994
|
* Copyright (c) 1988, 1993, 1994
|
||||||
@ -47,7 +47,7 @@ __COPYRIGHT(
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95";
|
static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: cp.c,v 1.32 2002/12/16 14:44:14 jrf Exp $");
|
__RCSID("$NetBSD: cp.c,v 1.33 2003/08/04 22:31:22 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -88,14 +88,14 @@ __RCSID("$NetBSD: cp.c,v 1.32 2002/12/16 14:44:14 jrf Exp $");
|
|||||||
PATH_T to = { to.p_path, "" };
|
PATH_T to = { to.p_path, "" };
|
||||||
|
|
||||||
uid_t myuid;
|
uid_t myuid;
|
||||||
int Rflag, fflag, iflag, pflag, rflag, vflag;
|
int Rflag, fflag, iflag, pflag, rflag, stdout_ok, vflag;
|
||||||
mode_t myumask;
|
mode_t myumask;
|
||||||
|
|
||||||
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
||||||
|
|
||||||
int main(int, char *[]);
|
int main(int, char *[]);
|
||||||
int copy(char *[], enum op, int);
|
int copy(char *[], enum op, int);
|
||||||
int mastercmp(const FTSENT **, const FTSENT **);
|
int mastercmp(const FTSENT **, const FTSENT **);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -153,14 +153,20 @@ main(int argc, char *argv[])
|
|||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
|
fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
|
||||||
if (rflag) {
|
if (rflag) {
|
||||||
if (Rflag)
|
if (Rflag) {
|
||||||
errx(1,
|
errx(EXIT_FAILURE,
|
||||||
"the -R and -r options may not be specified together.");
|
"the -R and -r options may not be specified together.");
|
||||||
if (Hflag || Lflag || Pflag)
|
/* NOTREACHED */
|
||||||
errx(1,
|
}
|
||||||
|
if (Hflag || Lflag || Pflag) {
|
||||||
|
errx(EXIT_FAILURE,
|
||||||
"the -H, -L, and -P options may not be specified with the -r option.");
|
"the -H, -L, and -P options may not be specified with the -r option.");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
fts_options &= ~FTS_PHYSICAL;
|
fts_options &= ~FTS_PHYSICAL;
|
||||||
fts_options |= FTS_LOGICAL;
|
fts_options |= FTS_LOGICAL;
|
||||||
}
|
}
|
||||||
@ -184,8 +190,10 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Save the target base in "to". */
|
/* Save the target base in "to". */
|
||||||
target = argv[--argc];
|
target = argv[--argc];
|
||||||
if (strlen(target) > MAXPATHLEN)
|
if (strlen(target) > MAXPATHLEN) {
|
||||||
errx(1, "%s: name too long", target);
|
errx(EXIT_FAILURE, "%s: name too long", printescaped(target));
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
(void)strcpy(to.p_path, target);
|
(void)strcpy(to.p_path, 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) {
|
||||||
@ -213,8 +221,10 @@ main(int argc, char *argv[])
|
|||||||
* In (2), the real target is not directory, but "directory/source".
|
* In (2), the real target is not directory, but "directory/source".
|
||||||
*/
|
*/
|
||||||
r = stat(to.p_path, &to_stat);
|
r = stat(to.p_path, &to_stat);
|
||||||
if (r == -1 && errno != ENOENT)
|
if (r == -1 && errno != ENOENT) {
|
||||||
err(1, "%s", to.p_path);
|
err(EXIT_FAILURE, "%s", printescaped(to.p_path));
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
|
if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
|
||||||
/*
|
/*
|
||||||
* Case (1). Target is not a directory.
|
* Case (1). Target is not a directory.
|
||||||
@ -235,8 +245,10 @@ main(int argc, char *argv[])
|
|||||||
r = stat(*argv, &tmp_stat);
|
r = stat(*argv, &tmp_stat);
|
||||||
else
|
else
|
||||||
r = lstat(*argv, &tmp_stat);
|
r = lstat(*argv, &tmp_stat);
|
||||||
if (r == -1)
|
if (r == -1) {
|
||||||
err(1, "%s", *argv);
|
err(EXIT_FAILURE, "%s", printescaped(*argv));
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
if (S_ISDIR(tmp_stat.st_mode) && (Rflag || rflag))
|
if (S_ISDIR(tmp_stat.st_mode) && (Rflag || rflag))
|
||||||
type = DIR_TO_DNE;
|
type = DIR_TO_DNE;
|
||||||
@ -262,23 +274,27 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
FTS *ftsp;
|
FTS *ftsp;
|
||||||
FTSENT *curr;
|
FTSENT *curr;
|
||||||
int base, dne, nlen, rval;
|
int base, dne, nlen, rval;
|
||||||
char *p, *tmp;
|
char *p, *tmp, *fn;
|
||||||
|
|
||||||
base = 0; /* XXX gcc -Wuninitialized (see comment below) */
|
base = 0; /* XXX gcc -Wuninitialized (see comment below) */
|
||||||
|
|
||||||
if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
|
if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
|
||||||
err(1, "%s", argv[0]);
|
err(EXIT_FAILURE, "%s", printescaped(argv[0]));
|
||||||
|
/* NOTREACHED */
|
||||||
for (rval = 0; (curr = fts_read(ftsp)) != NULL;) {
|
for (rval = 0; (curr = fts_read(ftsp)) != NULL;) {
|
||||||
switch (curr->fts_info) {
|
switch (curr->fts_info) {
|
||||||
case FTS_NS:
|
case FTS_NS:
|
||||||
case FTS_DNR:
|
case FTS_DNR:
|
||||||
case FTS_ERR:
|
case FTS_ERR:
|
||||||
warnx("%s: %s",
|
fn = printescaped(curr->fts_path);
|
||||||
curr->fts_path, strerror(curr->fts_errno));
|
warnx("%s: %s", fn, strerror(curr->fts_errno));
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
continue;
|
continue;
|
||||||
case FTS_DC: /* Warn, continue. */
|
case FTS_DC: /* Warn, continue. */
|
||||||
warnx("%s: directory causes a cycle", curr->fts_path);
|
fn = printescaped(curr->fts_path);
|
||||||
|
warnx("%s: directory causes a cycle", fn);
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -290,8 +306,12 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
if (type != FILE_TO_FILE) {
|
if (type != FILE_TO_FILE) {
|
||||||
if ((curr->fts_namelen +
|
if ((curr->fts_namelen +
|
||||||
to.target_end - to.p_path + 1) > MAXPATHLEN) {
|
to.target_end - to.p_path + 1) > MAXPATHLEN) {
|
||||||
warnx("%s/%s: name too long (not copied)",
|
char *tn;
|
||||||
to.p_path, curr->fts_name);
|
tn = printescaped(to.p_path);
|
||||||
|
fn = printescaped(curr->fts_name);
|
||||||
|
warnx("%s/%s: name too long (not copied)", tn, fn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -357,8 +377,13 @@ 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)) {
|
||||||
|
char *tn;
|
||||||
|
tn = printescaped(to.p_path);
|
||||||
|
fn = printescaped(curr->fts_path);
|
||||||
warnx("cannot overwrite directory %s with non-directory %s",
|
warnx("cannot overwrite directory %s with non-directory %s",
|
||||||
to.p_path, curr->fts_path);
|
tn, fn);
|
||||||
|
free(tn);
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -379,9 +404,12 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
break;
|
break;
|
||||||
case S_IFDIR:
|
case S_IFDIR:
|
||||||
if (!Rflag && !rflag) {
|
if (!Rflag && !rflag) {
|
||||||
if (curr->fts_info == FTS_D)
|
if (curr->fts_info == FTS_D) {
|
||||||
|
fn = printescaped(curr->fts_path);
|
||||||
warnx("%s is a directory (not copied).",
|
warnx("%s is a directory (not copied).",
|
||||||
curr->fts_path);
|
fn);
|
||||||
|
free(fn);
|
||||||
|
}
|
||||||
(void)fts_set(ftsp, curr, FTS_SKIP);
|
(void)fts_set(ftsp, curr, FTS_SKIP);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
break;
|
break;
|
||||||
@ -405,10 +433,14 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
if (dne) {
|
if (dne) {
|
||||||
if (mkdir(to.p_path,
|
if (mkdir(to.p_path,
|
||||||
curr->fts_statp->st_mode | S_IRWXU) < 0)
|
curr->fts_statp->st_mode | S_IRWXU) < 0)
|
||||||
err(1, "%s", to.p_path);
|
err(EXIT_FAILURE, "%s",
|
||||||
|
printescaped(to.p_path));
|
||||||
|
/* NOTREACHED */
|
||||||
} else if (!S_ISDIR(to_stat.st_mode)) {
|
} else if (!S_ISDIR(to_stat.st_mode)) {
|
||||||
errno = ENOTDIR;
|
errno = ENOTDIR;
|
||||||
err(1, "%s", to.p_path);
|
err(EXIT_FAILURE, "%s",
|
||||||
|
printescaped(to.p_path));
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (curr->fts_info == FTS_DP) /* Second pass */
|
else if (curr->fts_info == FTS_DP) /* Second pass */
|
||||||
@ -427,7 +459,9 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
warnx("directory %s encountered when not expected.", curr->fts_path);
|
fn = printescaped(curr->fts_path);
|
||||||
|
warnx("directory %s encountered when not expected.", fn);
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -455,11 +489,19 @@ copy(char *argv[], enum op type, int fts_options)
|
|||||||
rval = 1;
|
rval = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (vflag)
|
if (vflag) {
|
||||||
(void)printf("%s -> %s\n", curr->fts_path, to.p_path);
|
char *tn;
|
||||||
|
fn = printescaped(curr->fts_path);
|
||||||
|
tn = printescaped(to.p_path);
|
||||||
|
(void)printf("%s -> %s\n", fn, tn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errno) {
|
||||||
|
err(EXIT_FAILURE, "fts_read");
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
if (errno)
|
|
||||||
err(1, "fts_read");
|
|
||||||
return (rval);
|
return (rval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: extern.h,v 1.6 2001/09/13 09:53:59 wiz Exp $ */
|
/* $NetBSD: extern.h,v 1.7 2003/08/04 22:31:22 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -46,7 +46,7 @@ typedef struct {
|
|||||||
|
|
||||||
extern PATH_T to;
|
extern PATH_T to;
|
||||||
extern uid_t myuid;
|
extern uid_t myuid;
|
||||||
extern int fflag, iflag, pflag;
|
extern int fflag, iflag, pflag, stdout_ok;
|
||||||
extern mode_t myumask;
|
extern mode_t myumask;
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
@ -59,6 +59,7 @@ int copy_special(struct stat *, int);
|
|||||||
int set_utimes(const char *, struct stat *);
|
int set_utimes(const char *, struct stat *);
|
||||||
int setfile(struct stat *, int);
|
int setfile(struct stat *, int);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
|
char *printescaped(const char *);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif /* !_EXTERN_H_ */
|
#endif /* !_EXTERN_H_ */
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: utils.c,v 1.23 2003/01/20 05:29:53 simonb Exp $ */
|
/* $NetBSD: utils.c,v 1.24 2003/08/04 22:31:22 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -38,7 +38,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
|
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: utils.c,v 1.23 2003/01/20 05:29:53 simonb Exp $");
|
__RCSID("$NetBSD: utils.c,v 1.24 2003/08/04 22:31:22 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -55,6 +55,7 @@ __RCSID("$NetBSD: utils.c,v 1.23 2003/01/20 05:29:53 simonb Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
@ -336,3 +337,27 @@ usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: date.c,v 1.35 2001/09/16 13:35:52 wiz Exp $ */
|
/* $NetBSD: date.c,v 1.36 2003/08/04 22:31:22 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1985, 1987, 1988, 1993
|
* Copyright (c) 1985, 1987, 1988, 1993
|
||||||
@ -44,7 +44,7 @@ __COPYRIGHT(
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
|
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: date.c,v 1.35 2001/09/16 13:35:52 wiz Exp $");
|
__RCSID("$NetBSD: date.c,v 1.36 2003/08/04 22:31:22 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -138,7 +138,8 @@ badformat(void)
|
|||||||
static void
|
static void
|
||||||
badtime(void)
|
badtime(void)
|
||||||
{
|
{
|
||||||
errx(1, "illegal time");
|
errx(EXIT_FAILURE, "illegal time");
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ATOI2(s) ((s) += 2, ((s)[-2] - '0') * 10 + ((s)[-1] - '0'))
|
#define ATOI2(s) ((s) += 2, ((s)[-2] - '0') * 10 + ((s)[-1] - '0'))
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: args.c,v 1.21 2002/11/29 13:11:10 lukem Exp $ */
|
/* $NetBSD: args.c,v 1.22 2003/08/04 22:31:23 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -42,7 +42,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94";
|
static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: args.c,v 1.21 2002/11/29 13:11:10 lukem Exp $");
|
__RCSID("$NetBSD: args.c,v 1.22 2003/08/04 22:31:23 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -109,20 +109,28 @@ jcl(char **argv)
|
|||||||
in.dbsz = out.dbsz = 512;
|
in.dbsz = out.dbsz = 512;
|
||||||
|
|
||||||
while ((oper = *++argv) != NULL) {
|
while ((oper = *++argv) != NULL) {
|
||||||
if ((arg = strchr(oper, '=')) == NULL)
|
if ((arg = strchr(oper, '=')) == NULL) {
|
||||||
errx(1, "unknown operand %s", oper);
|
errx(EXIT_FAILURE, "unknown operand %s", oper);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
*arg++ = '\0';
|
*arg++ = '\0';
|
||||||
if (!*arg)
|
if (!*arg) {
|
||||||
errx(1, "no value specified for %s", oper);
|
errx(EXIT_FAILURE, "no value specified for %s", oper);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
tmp.name = oper;
|
tmp.name = oper;
|
||||||
if (!(ap = (struct arg *)bsearch(&tmp, args,
|
if (!(ap = (struct arg *)bsearch(&tmp, args,
|
||||||
sizeof(args)/sizeof(struct arg), sizeof(struct arg),
|
sizeof(args)/sizeof(struct arg), sizeof(struct arg),
|
||||||
c_arg)))
|
c_arg))) {
|
||||||
errx(1, "unknown operand %s", tmp.name);
|
errx(EXIT_FAILURE, "unknown operand %s", tmp.name);
|
||||||
if (ddflags & ap->noset)
|
/* NOTREACHED */
|
||||||
errx(1,
|
}
|
||||||
|
if (ddflags & ap->noset) {
|
||||||
|
errx(EXIT_FAILURE,
|
||||||
"%s: illegal argument combination or already set",
|
"%s: illegal argument combination or already set",
|
||||||
tmp.name);
|
tmp.name);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
ddflags |= ap->set;
|
ddflags |= ap->set;
|
||||||
ap->f(arg);
|
ap->f(arg);
|
||||||
}
|
}
|
||||||
@ -148,8 +156,10 @@ jcl(char **argv)
|
|||||||
* Block/unblock requires cbs and vice-versa.
|
* Block/unblock requires cbs and vice-versa.
|
||||||
*/
|
*/
|
||||||
if (ddflags & (C_BLOCK|C_UNBLOCK)) {
|
if (ddflags & (C_BLOCK|C_UNBLOCK)) {
|
||||||
if (!(ddflags & C_CBS))
|
if (!(ddflags & C_CBS)) {
|
||||||
errx(1, "record operations require cbs");
|
errx(EXIT_FAILURE, "record operations require cbs");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
cfunc = ddflags & C_BLOCK ? block : unblock;
|
cfunc = ddflags & C_BLOCK ? block : unblock;
|
||||||
} else if (ddflags & C_CBS) {
|
} else if (ddflags & C_CBS) {
|
||||||
if (ddflags & (C_ASCII|C_EBCDIC)) {
|
if (ddflags & (C_ASCII|C_EBCDIC)) {
|
||||||
@ -160,9 +170,11 @@ jcl(char **argv)
|
|||||||
ddflags |= C_BLOCK;
|
ddflags |= C_BLOCK;
|
||||||
cfunc = block;
|
cfunc = block;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
errx(1,
|
errx(EXIT_FAILURE,
|
||||||
"cbs meaningless if not doing record operations");
|
"cbs meaningless if not doing record operations");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
cfunc = def;
|
cfunc = def;
|
||||||
|
|
||||||
@ -274,7 +286,8 @@ static void
|
|||||||
f_conv(char *arg)
|
f_conv(char *arg)
|
||||||
{
|
{
|
||||||
|
|
||||||
errx(1, "conv option disabled");
|
errx(EXIT_FAILURE, "conv option disabled");
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
#else /* NO_CONV */
|
#else /* NO_CONV */
|
||||||
|
|
||||||
@ -309,10 +322,14 @@ f_conv(char *arg)
|
|||||||
tmp.name = strsep(&arg, ",");
|
tmp.name = strsep(&arg, ",");
|
||||||
if (!(cp = (struct conv *)bsearch(&tmp, clist,
|
if (!(cp = (struct conv *)bsearch(&tmp, clist,
|
||||||
sizeof(clist)/sizeof(struct conv), sizeof(struct conv),
|
sizeof(clist)/sizeof(struct conv), sizeof(struct conv),
|
||||||
c_conv)))
|
c_conv))) {
|
||||||
errx(1, "unknown conversion %s", tmp.name);
|
errx(EXIT_FAILURE, "unknown conversion %s", tmp.name);
|
||||||
if (ddflags & cp->noset)
|
/* NOTREACHED */
|
||||||
errx(1, "%s: illegal conversion combination", tmp.name);
|
}
|
||||||
|
if (ddflags & cp->noset) {
|
||||||
|
errx(EXIT_FAILURE, "%s: illegal conversion combination", tmp.name);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
ddflags |= cp->set;
|
ddflags |= cp->set;
|
||||||
if (cp->ctab)
|
if (cp->ctab)
|
||||||
ctab = cp->ctab;
|
ctab = cp->ctab;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: conv.c,v 1.14 2001/11/26 00:13:23 lukem Exp $ */
|
/* $NetBSD: conv.c,v 1.15 2003/08/04 22:31:23 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -42,7 +42,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94";
|
static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: conv.c,v 1.14 2001/11/26 00:13:23 lukem Exp $");
|
__RCSID("$NetBSD: conv.c,v 1.15 2003/08/04 22:31:23 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -103,10 +103,10 @@ def_close(void)
|
|||||||
/* Build a smaller version (i.e. for a miniroot) */
|
/* Build a smaller version (i.e. for a miniroot) */
|
||||||
/* These can not be called, but just in case... */
|
/* These can not be called, but just in case... */
|
||||||
static const char no_block[] = "unblock and -DNO_CONV?";
|
static const char no_block[] = "unblock and -DNO_CONV?";
|
||||||
void block(void) { errx(1, "%s", no_block + 2); }
|
void block(void) { errx(EXIT_FAILURE, "%s", no_block + 2); }
|
||||||
void block_close(void) { errx(1, "%s", no_block + 2); }
|
void block_close(void) { errx(EXIT_FAILURE, "%s", no_block + 2); }
|
||||||
void unblock(void) { errx(1, "%s", no_block); }
|
void unblock(void) { errx(EXIT_FAILURE, "%s", no_block); }
|
||||||
void unblock_close(void) { errx(1, "%s", no_block); }
|
void unblock_close(void) { errx(EXIT_FAILURE, "%s", no_block); }
|
||||||
#else /* NO_CONV */
|
#else /* NO_CONV */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
87
bin/dd/dd.c
87
bin/dd/dd.c
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: dd.c,v 1.29 2002/09/04 04:21:54 enami Exp $ */
|
/* $NetBSD: dd.c,v 1.30 2003/08/04 22:31:23 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
|
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: dd.c,v 1.29 2002/09/04 04:21:54 enami Exp $");
|
__RCSID("$NetBSD: dd.c,v 1.30 2003/08/04 22:31:23 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -131,13 +131,16 @@ setup(void)
|
|||||||
} else {
|
} else {
|
||||||
in.fd = open(in.name, O_RDONLY, 0);
|
in.fd = open(in.name, O_RDONLY, 0);
|
||||||
if (in.fd < 0)
|
if (in.fd < 0)
|
||||||
err(1, "%s", in.name);
|
err(EXIT_FAILURE, "%s", printescaped(in.name));
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
getfdtype(&in);
|
getfdtype(&in);
|
||||||
|
|
||||||
if (files_cnt > 1 && !(in.flags & ISTAPE))
|
if (files_cnt > 1 && !(in.flags & ISTAPE)) {
|
||||||
errx(1, "files is not supported for non-tape devices");
|
errx(EXIT_FAILURE, "files is not supported for non-tape devices");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
if (out.name == NULL) {
|
if (out.name == NULL) {
|
||||||
/* No way to check for read access here. */
|
/* No way to check for read access here. */
|
||||||
@ -156,8 +159,10 @@ setup(void)
|
|||||||
out.fd = open(out.name, O_WRONLY | OFLAGS, DEFFILEMODE);
|
out.fd = open(out.name, O_WRONLY | OFLAGS, DEFFILEMODE);
|
||||||
out.flags |= NOREAD;
|
out.flags |= NOREAD;
|
||||||
}
|
}
|
||||||
if (out.fd < 0)
|
if (out.fd < 0) {
|
||||||
err(1, "%s", out.name);
|
err(EXIT_FAILURE, "%s", printescaped(out.name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getfdtype(&out);
|
getfdtype(&out);
|
||||||
@ -167,13 +172,17 @@ setup(void)
|
|||||||
* record oriented I/O, only need a single buffer.
|
* record oriented I/O, only need a single buffer.
|
||||||
*/
|
*/
|
||||||
if (!(ddflags & (C_BLOCK|C_UNBLOCK))) {
|
if (!(ddflags & (C_BLOCK|C_UNBLOCK))) {
|
||||||
if ((in.db = malloc(out.dbsz + in.dbsz - 1)) == NULL)
|
if ((in.db = malloc(out.dbsz + in.dbsz - 1)) == NULL) {
|
||||||
err(1, NULL);
|
err(EXIT_FAILURE, NULL);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
out.db = in.db;
|
out.db = in.db;
|
||||||
} else if ((in.db =
|
} else if ((in.db =
|
||||||
malloc((u_int)(MAX(in.dbsz, cbsz) + cbsz))) == NULL ||
|
malloc((u_int)(MAX(in.dbsz, cbsz) + cbsz))) == NULL ||
|
||||||
(out.db = malloc((u_int)(out.dbsz + cbsz))) == NULL)
|
(out.db = malloc((u_int)(out.dbsz + cbsz))) == NULL) {
|
||||||
err(1, NULL);
|
err(EXIT_FAILURE, NULL);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
in.dbp = in.db;
|
in.dbp = in.db;
|
||||||
out.dbp = out.db;
|
out.dbp = out.db;
|
||||||
|
|
||||||
@ -198,7 +207,8 @@ setup(void)
|
|||||||
if (ddflags & (C_LCASE|C_UCASE)) {
|
if (ddflags & (C_LCASE|C_UCASE)) {
|
||||||
#ifdef NO_CONV
|
#ifdef NO_CONV
|
||||||
/* Should not get here, but just in case... */
|
/* Should not get here, but just in case... */
|
||||||
errx(1, "case conv and -DNO_CONV");
|
errx(EXIT_FAILURE, "case conv and -DNO_CONV");
|
||||||
|
/* NOTREACHED */
|
||||||
#else /* NO_CONV */
|
#else /* NO_CONV */
|
||||||
u_int cnt;
|
u_int cnt;
|
||||||
|
|
||||||
@ -233,8 +243,10 @@ getfdtype(IO *io)
|
|||||||
struct mtget mt;
|
struct mtget mt;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (fstat(io->fd, &sb))
|
if (fstat(io->fd, &sb)) {
|
||||||
err(1, "%s", io->name);
|
err(EXIT_FAILURE, "%s", printescaped(io->name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
if (S_ISCHR(sb.st_mode))
|
if (S_ISCHR(sb.st_mode))
|
||||||
io->flags |= ioctl(io->fd, MTIOCGET, &mt) ? ISCHR : ISTAPE;
|
io->flags |= ioctl(io->fd, MTIOCGET, &mt) ? ISCHR : ISTAPE;
|
||||||
else if (lseek(io->fd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE)
|
else if (lseek(io->fd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE)
|
||||||
@ -273,13 +285,18 @@ dd_in(void)
|
|||||||
|
|
||||||
/* Read error. */
|
/* Read error. */
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
|
char *fn;
|
||||||
|
|
||||||
|
fn = printescaped(in.name);
|
||||||
/*
|
/*
|
||||||
* If noerror not specified, die. POSIX requires that
|
* If noerror not specified, die. POSIX requires that
|
||||||
* the warning message be followed by an I/O display.
|
* the warning message be followed by an I/O display.
|
||||||
*/
|
*/
|
||||||
if (!(flags & C_NOERROR))
|
if (!(flags & C_NOERROR)) {
|
||||||
err(1, "%s", in.name);
|
err(EXIT_FAILURE, "%s", fn);
|
||||||
warn("%s", in.name);
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
warn("%s", fn);
|
||||||
summary();
|
summary();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -290,7 +307,7 @@ dd_in(void)
|
|||||||
*/
|
*/
|
||||||
if (!(in.flags & (ISPIPE|ISTAPE)) &&
|
if (!(in.flags & (ISPIPE|ISTAPE)) &&
|
||||||
lseek(in.fd, (off_t)in.dbsz, SEEK_CUR))
|
lseek(in.fd, (off_t)in.dbsz, SEEK_CUR))
|
||||||
warn("%s", in.name);
|
warn("%s", fn);
|
||||||
|
|
||||||
/* If sync not specified, omit block and continue. */
|
/* If sync not specified, omit block and continue. */
|
||||||
if (!(ddflags & C_SYNC))
|
if (!(ddflags & C_SYNC))
|
||||||
@ -300,6 +317,8 @@ dd_in(void)
|
|||||||
in.dbcnt += in.dbrcnt = in.dbsz;
|
in.dbcnt += in.dbrcnt = in.dbsz;
|
||||||
++st.in_full;
|
++st.in_full;
|
||||||
|
|
||||||
|
free(fn);
|
||||||
|
|
||||||
/* Handle full input blocks. */
|
/* Handle full input blocks. */
|
||||||
} else if (n == in.dbsz) {
|
} else if (n == in.dbsz) {
|
||||||
in.dbcnt += in.dbrcnt = n;
|
in.dbcnt += in.dbrcnt = n;
|
||||||
@ -368,10 +387,14 @@ dd_close(void)
|
|||||||
* may be shared among with other processes and close(2) just
|
* may be shared among with other processes and close(2) just
|
||||||
* decreases the reference count.
|
* decreases the reference count.
|
||||||
*/
|
*/
|
||||||
if (out.fd == STDOUT_FILENO && fsync(out.fd) == -1 && errno != EINVAL)
|
if (out.fd == STDOUT_FILENO && fsync(out.fd) == -1 && errno != EINVAL) {
|
||||||
err(1, "fsync stdout");
|
err(EXIT_FAILURE, "fsync stdout");
|
||||||
if (close(out.fd) == -1)
|
/* NOTREACHED */
|
||||||
err(1, "close");
|
}
|
||||||
|
if (close(out.fd) == -1) {
|
||||||
|
err(EXIT_FAILURE, "close");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -400,12 +423,18 @@ dd_out(int force)
|
|||||||
outp = out.db;
|
outp = out.db;
|
||||||
for (n = force ? out.dbcnt : out.dbsz;; n = out.dbsz) {
|
for (n = force ? out.dbcnt : out.dbsz;; n = out.dbsz) {
|
||||||
for (cnt = n;; cnt -= nw) {
|
for (cnt = n;; cnt -= nw) {
|
||||||
|
char *fn;
|
||||||
|
|
||||||
|
fn = printescaped(out.name);
|
||||||
nw = bwrite(out.fd, outp, cnt);
|
nw = bwrite(out.fd, outp, cnt);
|
||||||
if (nw <= 0) {
|
if (nw <= 0) {
|
||||||
if (nw == 0)
|
if (nw == 0)
|
||||||
errx(1, "%s: end of device", out.name);
|
errx(EXIT_FAILURE,
|
||||||
|
"%s: end of device", fn);
|
||||||
|
/* NOTREACHED */
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
err(1, "%s", out.name);
|
err(EXIT_FAILURE, "%s", fn);
|
||||||
|
/* NOTREACHED */
|
||||||
nw = 0;
|
nw = 0;
|
||||||
}
|
}
|
||||||
outp += nw;
|
outp += nw;
|
||||||
@ -422,12 +451,14 @@ dd_out(int force)
|
|||||||
break;
|
break;
|
||||||
if (out.flags & ISCHR && !warned) {
|
if (out.flags & ISCHR && !warned) {
|
||||||
warned = 1;
|
warned = 1;
|
||||||
warnx("%s: short write on character device",
|
warnx("%s: short write on character device", fn);
|
||||||
out.name);
|
|
||||||
}
|
}
|
||||||
if (out.flags & ISTAPE)
|
if (out.flags & ISTAPE)
|
||||||
errx(1, "%s: short write on tape device",
|
errx(EXIT_FAILURE,
|
||||||
out.name);
|
"%s: short write on tape device", fn);
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
|
free(fn);
|
||||||
}
|
}
|
||||||
if ((out.dbcnt -= n) < out.dbsz)
|
if ((out.dbcnt -= n) < out.dbsz)
|
||||||
break;
|
break;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: extern.h,v 1.13 2001/11/26 00:13:24 lukem Exp $ */
|
/* $NetBSD: extern.h,v 1.14 2003/08/04 22:31:23 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -55,6 +55,7 @@ void terminate(int);
|
|||||||
void unblock(void);
|
void unblock(void);
|
||||||
void unblock_close(void);
|
void unblock_close(void);
|
||||||
ssize_t bwrite(int, const void *, size_t);
|
ssize_t bwrite(int, const void *, size_t);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
extern IO in, out;
|
extern IO in, out;
|
||||||
extern STAT st;
|
extern STAT st;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: misc.c,v 1.14 2001/11/26 00:56:33 enami Exp $ */
|
/* $NetBSD: misc.c,v 1.15 2003/08/04 22:31:23 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -42,10 +42,11 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
|
static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: misc.c,v 1.14 2001/11/26 00:56:33 enami Exp $");
|
__RCSID("$NetBSD: misc.c,v 1.15 2003/08/04 22:31:23 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ __RCSID("$NetBSD: misc.c,v 1.14 2001/11/26 00:56:33 enami Exp $");
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "dd.h"
|
#include "dd.h"
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
@ -118,3 +120,27 @@ terminate(int notused)
|
|||||||
exit(0);
|
exit(0);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (isatty(STDOUT_FILENO))
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: position.c,v 1.12 2001/11/26 00:56:33 enami Exp $ */
|
/* $NetBSD: position.c,v 1.13 2003/08/04 22:31:23 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -42,7 +42,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94";
|
static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: position.c,v 1.12 2001/11/26 00:56:33 enami Exp $");
|
__RCSID("$NetBSD: position.c,v 1.13 2003/08/04 22:31:23 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -54,6 +54,7 @@ __RCSID("$NetBSD: position.c,v 1.12 2001/11/26 00:56:33 enami Exp $");
|
|||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -74,9 +75,12 @@ pos_in(void)
|
|||||||
/* If not a pipe or tape device, try to seek on it. */
|
/* If not a pipe or tape device, try to seek on it. */
|
||||||
if (!(in.flags & (ISPIPE|ISTAPE))) {
|
if (!(in.flags & (ISPIPE|ISTAPE))) {
|
||||||
if (lseek(in.fd,
|
if (lseek(in.fd,
|
||||||
(off_t)in.offset * (off_t)in.dbsz, SEEK_CUR) == -1)
|
(off_t)in.offset * (off_t)in.dbsz, SEEK_CUR) == -1) {
|
||||||
err(1, "%s", in.name);
|
err(EXIT_FAILURE, "%s", printescaped(in.name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -101,7 +105,8 @@ pos_in(void)
|
|||||||
--files_cnt;
|
--files_cnt;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
errx(1, "skip reached end of input");
|
errx(EXIT_FAILURE, "skip reached end of input");
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -111,13 +116,17 @@ pos_in(void)
|
|||||||
*/
|
*/
|
||||||
if (ddflags & C_NOERROR) {
|
if (ddflags & C_NOERROR) {
|
||||||
if (!warned) {
|
if (!warned) {
|
||||||
warn("%s", in.name);
|
char * fn;
|
||||||
|
fn = printescaped(in.name);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
warned = 1;
|
warned = 1;
|
||||||
summary();
|
summary();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
err(1, "%s", in.name);
|
err(EXIT_FAILURE, "%s", printescaped(in.name));
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +144,8 @@ pos_out(void)
|
|||||||
if (!(out.flags & ISTAPE)) {
|
if (!(out.flags & ISTAPE)) {
|
||||||
if (lseek(out.fd,
|
if (lseek(out.fd,
|
||||||
(off_t)out.offset * (off_t)out.dbsz, SEEK_SET) == -1)
|
(off_t)out.offset * (off_t)out.dbsz, SEEK_SET) == -1)
|
||||||
err(1, "%s", out.name);
|
err(EXIT_FAILURE, "%s", printescaped(out.name));
|
||||||
|
/* NOTREACHED */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +155,8 @@ pos_out(void)
|
|||||||
t_op.mt_count = out.offset;
|
t_op.mt_count = out.offset;
|
||||||
|
|
||||||
if (ioctl(out.fd, MTIOCTOP, &t_op) < 0)
|
if (ioctl(out.fd, MTIOCTOP, &t_op) < 0)
|
||||||
err(1, "%s", out.name);
|
err(EXIT_FAILURE, "%s", printescaped(out.name));
|
||||||
|
/* NOTREACHED */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +166,8 @@ pos_out(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
err(1, "%s", out.name);
|
err(EXIT_FAILURE, "%s", printescaped(out.name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If reach EOF, fill with NUL characters; first, back up over
|
* If reach EOF, fill with NUL characters; first, back up over
|
||||||
@ -165,11 +177,13 @@ pos_out(void)
|
|||||||
t_op.mt_op = MTBSR;
|
t_op.mt_op = MTBSR;
|
||||||
t_op.mt_count = 1;
|
t_op.mt_count = 1;
|
||||||
if (ioctl(out.fd, MTIOCTOP, &t_op) == -1)
|
if (ioctl(out.fd, MTIOCTOP, &t_op) == -1)
|
||||||
err(1, "%s", out.name);
|
err(EXIT_FAILURE, "%s", printescaped(out.name));
|
||||||
|
/* NOTREACHED */
|
||||||
|
|
||||||
while (cnt++ < out.offset)
|
while (cnt++ < out.offset)
|
||||||
if ((n = bwrite(out.fd, out.db, out.dbsz)) != out.dbsz)
|
if ((n = bwrite(out.fd, out.db, out.dbsz)) != out.dbsz)
|
||||||
err(1, "%s", out.name);
|
err(EXIT_FAILURE, "%s", printescaped(out.name));
|
||||||
|
/* NOTREACHED */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: echo.c,v 1.9 2001/07/29 22:36:11 wiz Exp $ */
|
/* $NetBSD: echo.c,v 1.10 2003/08/04 22:31:23 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
@ -44,15 +44,23 @@ __COPYRIGHT(
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)echo.c 8.1 (Berkeley) 5/31/93";
|
static char sccsid[] = "@(#)echo.c 8.1 (Berkeley) 5/31/93";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: echo.c,v 1.9 2001/07/29 22:36:11 wiz Exp $");
|
__RCSID("$NetBSD: echo.c,v 1.10 2003/08/04 22:31:23 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
|
int stdout_ok;
|
||||||
|
|
||||||
int main(int, char *[]);
|
int main(int, char *[]);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
int
|
int
|
||||||
@ -60,6 +68,7 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int nflag;
|
int nflag;
|
||||||
|
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
/* This utility may NOT do getopt(3) option parsing. */
|
/* This utility may NOT do getopt(3) option parsing. */
|
||||||
if (*++argv && !strcmp(*argv, "-n")) {
|
if (*++argv && !strcmp(*argv, "-n")) {
|
||||||
++argv;
|
++argv;
|
||||||
@ -69,7 +78,10 @@ main(int argc, char *argv[])
|
|||||||
nflag = 0;
|
nflag = 0;
|
||||||
|
|
||||||
while (*argv) {
|
while (*argv) {
|
||||||
(void)printf("%s", *argv);
|
char *n;
|
||||||
|
n = printescaped(*argv);
|
||||||
|
(void)printf("%s", n);
|
||||||
|
free(n);
|
||||||
if (*++argv)
|
if (*++argv)
|
||||||
(void)putchar(' ');
|
(void)putchar(' ');
|
||||||
}
|
}
|
||||||
@ -78,3 +90,27 @@ main(int argc, char *argv[])
|
|||||||
exit(0);
|
exit(0);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: kill.c,v 1.21 2002/11/25 14:23:07 christos Exp $ */
|
/* $NetBSD: kill.c,v 1.22 2003/08/04 22:31:24 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988, 1993, 1994
|
* Copyright (c) 1988, 1993, 1994
|
||||||
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)kill.c 8.4 (Berkeley) 4/28/95";
|
static char sccsid[] = "@(#)kill.c 8.4 (Berkeley) 4/28/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: kill.c,v 1.21 2002/11/25 14:23:07 christos Exp $");
|
__RCSID("$NetBSD: kill.c,v 1.22 2003/08/04 22:31:24 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -92,8 +92,11 @@ main(int argc, char *argv[])
|
|||||||
if (isdigit((unsigned char)**argv) == 0)
|
if (isdigit((unsigned char)**argv) == 0)
|
||||||
usage();
|
usage();
|
||||||
numsig = strtol(*argv, &ep, 10);
|
numsig = strtol(*argv, &ep, 10);
|
||||||
if (*ep != '\0')
|
if (*ep != '\0') {
|
||||||
errx(1, "illegal signal number: %s", *argv);
|
errx(EXIT_FAILURE, "illegal signal number: %s",
|
||||||
|
*argv);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
if (numsig >= 128)
|
if (numsig >= 128)
|
||||||
numsig -= 128;
|
numsig -= 128;
|
||||||
if (numsig <= 0 || numsig >= NSIG)
|
if (numsig <= 0 || numsig >= NSIG)
|
||||||
@ -124,8 +127,11 @@ main(int argc, char *argv[])
|
|||||||
nosig(*argv);
|
nosig(*argv);
|
||||||
} else if (isdigit((unsigned char)**argv)) {
|
} else if (isdigit((unsigned char)**argv)) {
|
||||||
numsig = strtol(*argv, &ep, 10);
|
numsig = strtol(*argv, &ep, 10);
|
||||||
if (!*argv || *ep)
|
if (!*argv || *ep) {
|
||||||
errx(1, "illegal signal number: %s", *argv);
|
errx(EXIT_FAILURE, "illegal signal number: %s",
|
||||||
|
*argv);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
if (numsig < 0 || numsig >= NSIG)
|
if (numsig < 0 || numsig >= NSIG)
|
||||||
nosig(*argv);
|
nosig(*argv);
|
||||||
} else
|
} else
|
||||||
|
67
bin/ln/ln.c
67
bin/ln/ln.c
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: ln.c,v 1.21 2002/12/27 03:50:05 jrf Exp $ */
|
/* $NetBSD: ln.c,v 1.22 2003/08/04 22:31:24 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1987, 1993, 1994
|
* Copyright (c) 1987, 1993, 1994
|
||||||
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94";
|
static char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: ln.c,v 1.21 2002/12/27 03:50:05 jrf Exp $");
|
__RCSID("$NetBSD: ln.c,v 1.22 2003/08/04 22:31:24 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -56,11 +56,14 @@ __RCSID("$NetBSD: ln.c,v 1.21 2002/12/27 03:50:05 jrf Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
int fflag; /* Unlink existing files. */
|
int fflag; /* Unlink existing files. */
|
||||||
int hflag; /* Check new name for symlink first. */
|
int hflag; /* Check new name for symlink first. */
|
||||||
int sflag; /* Symbolic, not hard, link. */
|
int sflag; /* Symbolic, not hard, link. */
|
||||||
int vflag; /* Verbose output */
|
int vflag; /* Verbose output */
|
||||||
|
int stdout_ok; /* stdout connected to a terminal */
|
||||||
|
|
||||||
/* System link call. */
|
/* System link call. */
|
||||||
int (*linkf)(const char *, const char *);
|
int (*linkf)(const char *, const char *);
|
||||||
char linkch;
|
char linkch;
|
||||||
@ -68,6 +71,7 @@ char linkch;
|
|||||||
int linkit(char *, char *, int);
|
int linkit(char *, char *, int);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
int main(int, char *[]);
|
int main(int, char *[]);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -95,6 +99,7 @@ main(int argc, char *argv[])
|
|||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
argv += optind;
|
argv += optind;
|
||||||
@ -119,18 +124,26 @@ main(int argc, char *argv[])
|
|||||||
exit(linkit(argv[0], argv[1], 0));
|
exit(linkit(argv[0], argv[1], 0));
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
/* ln target1 target2 directory */
|
/* ln target1 target2 directory */
|
||||||
sourcedir = argv[argc - 1];
|
sourcedir = argv[argc - 1];
|
||||||
if (hflag && lstat(sourcedir, &sb) == 0 && S_ISLNK(sb.st_mode)) {
|
if (hflag && lstat(sourcedir, &sb) == 0 && S_ISLNK(sb.st_mode)) {
|
||||||
/* we were asked not to follow symlinks, but found one at
|
/* we were asked not to follow symlinks, but found one at
|
||||||
the target--simulate "not a directory" error */
|
the target--simulate "not a directory" error */
|
||||||
errno = ENOTDIR;
|
errno = ENOTDIR;
|
||||||
err(1, "%s", sourcedir);
|
err(EXIT_FAILURE, "%s", printescaped(sourcedir));
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
if (stat(sourcedir, &sb))
|
if (stat(sourcedir, &sb)) {
|
||||||
err(1, "%s", sourcedir);
|
err(EXIT_FAILURE, "%s", printescaped(sourcedir));
|
||||||
if (!S_ISDIR(sb.st_mode))
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
if (!S_ISDIR(sb.st_mode)) {
|
||||||
usage();
|
usage();
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
for (exitval = 0; *argv != sourcedir; ++argv)
|
for (exitval = 0; *argv != sourcedir; ++argv)
|
||||||
exitval |= linkit(*argv, sourcedir, 1);
|
exitval |= linkit(*argv, sourcedir, 1);
|
||||||
exit(exitval);
|
exit(exitval);
|
||||||
@ -142,11 +155,17 @@ linkit(char *target, char *source, int isdir)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *p, path[MAXPATHLEN];
|
char *p, path[MAXPATHLEN];
|
||||||
|
char *sn, *tn;
|
||||||
|
|
||||||
|
sn = printescaped(source);
|
||||||
|
tn = printescaped(target);
|
||||||
|
|
||||||
if (!sflag) {
|
if (!sflag) {
|
||||||
/* If target doesn't exist, quit now. */
|
/* If target doesn't exist, quit now. */
|
||||||
if (stat(target, &sb)) {
|
if (stat(target, &sb)) {
|
||||||
warn("%s", target);
|
warn("%s", tn);
|
||||||
|
free(sn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,7 +179,9 @@ linkit(char *target, char *source, int isdir)
|
|||||||
p = target;
|
p = target;
|
||||||
else
|
else
|
||||||
++p;
|
++p;
|
||||||
(void)snprintf(path, sizeof(path), "%s/%s", source, p);
|
p = printescaped(p);
|
||||||
|
(void)snprintf(path, sizeof(path), "%s/%s", sn, p);
|
||||||
|
free(p);
|
||||||
source = path;
|
source = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +195,10 @@ linkit(char *target, char *source, int isdir)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (vflag)
|
if (vflag)
|
||||||
(void)printf("%s %c> %s\n", source, linkch, target);
|
(void)printf("%s %c> %s\n", sn, linkch, tn);
|
||||||
|
|
||||||
|
free(sn);
|
||||||
|
free(tn);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,3 +212,27 @@ usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: mkdir.c,v 1.29 2003/03/10 23:33:10 lukem Exp $ */
|
/* $NetBSD: mkdir.c,v 1.30 2003/08/04 22:31:24 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1983, 1992, 1993
|
* Copyright (c) 1983, 1992, 1993
|
||||||
@ -43,12 +43,13 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1992, 1993\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)mkdir.c 8.2 (Berkeley) 1/25/94";
|
static char sccsid[] = "@(#)mkdir.c 8.2 (Berkeley) 1/25/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: mkdir.c,v 1.29 2003/03/10 23:33:10 lukem Exp $");
|
__RCSID("$NetBSD: mkdir.c,v 1.30 2003/08/04 22:31:24 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -57,10 +58,14 @@ __RCSID("$NetBSD: mkdir.c,v 1.29 2003/03/10 23:33:10 lukem Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
|
int stdout_ok; /* stdout connected to a terminal */
|
||||||
|
|
||||||
int mkpath(char *, mode_t, mode_t);
|
int mkpath(char *, mode_t, mode_t);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
int main(int, char *[]);
|
int main(int, char *[]);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -88,20 +93,28 @@ main(int argc, char *argv[])
|
|||||||
pflag = 1;
|
pflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
if ((set = setmode(optarg)) == NULL)
|
if ((set = setmode(optarg)) == NULL) {
|
||||||
errx(1, "invalid file mode: %s", optarg);
|
errx(EXIT_FAILURE, "invalid file mode: %s",
|
||||||
|
printescaped(optarg));
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
mode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO);
|
mode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
free(set);
|
free(set);
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
if (*argv == NULL)
|
if (*argv == NULL) {
|
||||||
usage();
|
usage();
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
for (exitval = EXIT_SUCCESS; *argv != NULL; ++argv) {
|
for (exitval = EXIT_SUCCESS; *argv != NULL; ++argv) {
|
||||||
char *slash;
|
char *slash;
|
||||||
@ -127,7 +140,10 @@ main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) != 0 &&
|
if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) != 0 &&
|
||||||
chmod(*argv, mode) == -1) {
|
chmod(*argv, mode) == -1) {
|
||||||
warn("%s", *argv);
|
char *fn;
|
||||||
|
fn = printescaped(*argv);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
exitval = EXIT_FAILURE;
|
exitval = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,11 +163,12 @@ int
|
|||||||
mkpath(char *path, mode_t mode, mode_t dir_mode)
|
mkpath(char *path, mode_t mode, mode_t dir_mode)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *slash;
|
char *slash, *fn;
|
||||||
int done, rv;
|
int done, rv;
|
||||||
|
|
||||||
done = 0;
|
done = 0;
|
||||||
slash = path;
|
slash = path;
|
||||||
|
fn = printescaped(path);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
slash += strspn(slash, "/");
|
slash += strspn(slash, "/");
|
||||||
@ -172,13 +189,15 @@ mkpath(char *path, mode_t mode, mode_t dir_mode)
|
|||||||
if (stat(path, &sb) < 0) {
|
if (stat(path, &sb) < 0) {
|
||||||
/* Not there; use mkdir()s error */
|
/* Not there; use mkdir()s error */
|
||||||
errno = sverrno;
|
errno = sverrno;
|
||||||
warn("%s", path);
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!S_ISDIR(sb.st_mode)) {
|
if (!S_ISDIR(sb.st_mode)) {
|
||||||
/* Is there, but isn't a directory */
|
/* Is there, but isn't a directory */
|
||||||
errno = ENOTDIR;
|
errno = ENOTDIR;
|
||||||
warn("%s", path);
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (done) {
|
} else if (done) {
|
||||||
@ -193,7 +212,8 @@ mkpath(char *path, mode_t mode, mode_t dir_mode)
|
|||||||
*/
|
*/
|
||||||
if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) != 0 &&
|
if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) != 0 &&
|
||||||
chmod(path, mode) == -1) {
|
chmod(path, mode) == -1) {
|
||||||
warn("%s", path);
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,6 +223,8 @@ mkpath(char *path, mode_t mode, mode_t dir_mode)
|
|||||||
}
|
}
|
||||||
*slash = '/';
|
*slash = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(fn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,3 +237,27 @@ usage(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
130
bin/mv/mv.c
130
bin/mv/mv.c
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: mv.c,v 1.29 2003/07/13 08:25:47 itojun Exp $ */
|
/* $NetBSD: mv.c,v 1.30 2003/08/04 22:31:25 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993, 1994
|
* Copyright (c) 1989, 1993, 1994
|
||||||
@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
|
static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: mv.c,v 1.29 2003/07/13 08:25:47 itojun Exp $");
|
__RCSID("$NetBSD: mv.c,v 1.30 2003/08/04 22:31:25 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -65,17 +65,19 @@ __RCSID("$NetBSD: mv.c,v 1.29 2003/07/13 08:25:47 itojun Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
|
||||||
int fflg, iflg, vflg;
|
int fflg, iflg, vflg;
|
||||||
int stdin_ok;
|
int stdin_ok, stdout_ok;
|
||||||
|
|
||||||
int copy(char *, char *);
|
int copy(char *, char *);
|
||||||
int do_move(char *, char *);
|
int do_move(char *, char *);
|
||||||
int fastcopy(char *, char *, struct stat *);
|
int fastcopy(char *, char *, struct stat *);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
int main(int, char *[]);
|
int main(int, char *[]);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -112,6 +114,7 @@ main(int argc, char *argv[])
|
|||||||
usage();
|
usage();
|
||||||
|
|
||||||
stdin_ok = isatty(STDIN_FILENO);
|
stdin_ok = isatty(STDIN_FILENO);
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the stat on the target fails or the target isn't a directory,
|
* If the stat on the target fails or the target isn't a directory,
|
||||||
@ -139,7 +142,9 @@ main(int argc, char *argv[])
|
|||||||
++p;
|
++p;
|
||||||
|
|
||||||
if ((baselen + (len = strlen(p))) >= MAXPATHLEN) {
|
if ((baselen + (len = strlen(p))) >= MAXPATHLEN) {
|
||||||
warnx("%s: destination pathname too long", *argv);
|
char *fn = printescaped(*argv);
|
||||||
|
warnx("%s: destination pathname too long", fn);
|
||||||
|
free(fn);
|
||||||
rval = 1;
|
rval = 1;
|
||||||
} else {
|
} else {
|
||||||
memmove(endp, p, len + 1);
|
memmove(endp, p, len + 1);
|
||||||
@ -156,6 +161,10 @@ do_move(char *from, char *to)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char modep[15];
|
char modep[15];
|
||||||
|
char *fn, *tn;
|
||||||
|
|
||||||
|
fn = printescaped(from);
|
||||||
|
tn = printescaped(to);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (1) If the destination path exists, the -f option is not specified
|
* (1) If the destination path exists, the -f option is not specified
|
||||||
@ -176,27 +185,34 @@ do_move(char *from, char *to)
|
|||||||
|
|
||||||
if (iflg) {
|
if (iflg) {
|
||||||
if (access(from, F_OK)) {
|
if (access(from, F_OK)) {
|
||||||
warn("rename %s", from);
|
warn("rename %s", fn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
(void)fprintf(stderr, "overwrite %s? ", to);
|
(void)fprintf(stderr, "overwrite %s? ", tn);
|
||||||
} else if (stdin_ok && access(to, W_OK) && !stat(to, &sb)) {
|
} else if (stdin_ok && access(to, W_OK) && !stat(to, &sb)) {
|
||||||
if (access(from, F_OK)) {
|
if (access(from, F_OK)) {
|
||||||
warn("rename %s", from);
|
warn("rename %s", fn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
strmode(sb.st_mode, modep);
|
strmode(sb.st_mode, modep);
|
||||||
(void)fprintf(stderr, "override %s%s%s/%s for %s? ",
|
(void)fprintf(stderr, "override %s%s%s/%s for %s? ",
|
||||||
modep + 1, modep[9] == ' ' ? "" : " ",
|
modep + 1, modep[9] == ' ' ? "" : " ",
|
||||||
user_from_uid(sb.st_uid, 0),
|
user_from_uid(sb.st_uid, 0),
|
||||||
group_from_gid(sb.st_gid, 0), to);
|
group_from_gid(sb.st_gid, 0), tn);
|
||||||
} else
|
} else
|
||||||
ask = 0;
|
ask = 0;
|
||||||
if (ask) {
|
if (ask) {
|
||||||
if ((ch = getchar()) != EOF && ch != '\n')
|
if ((ch = getchar()) != EOF && ch != '\n')
|
||||||
while (getchar() != '\n');
|
while (getchar() != '\n');
|
||||||
if (ch != 'y' && ch != 'Y')
|
if (ch != 'y' && ch != 'Y') {
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,12 +231,16 @@ do_move(char *from, char *to)
|
|||||||
*/
|
*/
|
||||||
if (!rename(from, to)) {
|
if (!rename(from, to)) {
|
||||||
if (vflg)
|
if (vflg)
|
||||||
printf("%s -> %s\n", from, to);
|
printf("%s -> %s\n", fn, tn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno != EXDEV) {
|
if (errno != EXDEV) {
|
||||||
warn("rename %s to %s", from, to);
|
warn("rename %s to %s", fn, tn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +252,9 @@ do_move(char *from, char *to)
|
|||||||
*/
|
*/
|
||||||
if (!lstat(to, &sb)) {
|
if (!lstat(to, &sb)) {
|
||||||
if ((S_ISDIR(sb.st_mode)) ? rmdir(to) : unlink(to)) {
|
if ((S_ISDIR(sb.st_mode)) ? rmdir(to) : unlink(to)) {
|
||||||
warn("can't remove %s", to);
|
warn("can't remove %s", tn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,9 +264,15 @@ do_move(char *from, char *to)
|
|||||||
* as a file hierarchy rooted in the destination path...
|
* as a file hierarchy rooted in the destination path...
|
||||||
*/
|
*/
|
||||||
if (lstat(from, &sb)) {
|
if (lstat(from, &sb)) {
|
||||||
warn("%s", from);
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
|
|
||||||
return (S_ISREG(sb.st_mode) ?
|
return (S_ISREG(sb.st_mode) ?
|
||||||
fastcopy(from, to, &sb) : copy(from, to));
|
fastcopy(from, to, &sb) : copy(from, to));
|
||||||
}
|
}
|
||||||
@ -256,32 +284,44 @@ fastcopy(char *from, char *to, struct stat *sbp)
|
|||||||
static u_int blen;
|
static u_int blen;
|
||||||
static char *bp;
|
static char *bp;
|
||||||
int nread, from_fd, to_fd;
|
int nread, from_fd, to_fd;
|
||||||
|
char *fn, *tn;
|
||||||
|
|
||||||
|
fn = printescaped(from);
|
||||||
|
tn = printescaped(to);
|
||||||
|
|
||||||
if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
|
if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
|
||||||
warn("%s", from);
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if ((to_fd =
|
if ((to_fd =
|
||||||
open(to, O_CREAT | O_TRUNC | O_WRONLY, sbp->st_mode)) < 0) {
|
open(to, O_CREAT | O_TRUNC | O_WRONLY, sbp->st_mode)) < 0) {
|
||||||
warn("%s", to);
|
warn("%s", tn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
(void)close(from_fd);
|
(void)close(from_fd);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (!blen && !(bp = malloc(blen = sbp->st_blksize))) {
|
if (!blen && !(bp = malloc(blen = sbp->st_blksize))) {
|
||||||
warn(NULL);
|
warn(NULL);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
while ((nread = read(from_fd, bp, blen)) > 0)
|
while ((nread = read(from_fd, bp, blen)) > 0)
|
||||||
if (write(to_fd, bp, nread) != nread) {
|
if (write(to_fd, bp, nread) != nread) {
|
||||||
warn("%s", to);
|
warn("%s", tn);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
warn("%s", from);
|
warn("%s", fn);
|
||||||
err: if (unlink(to))
|
err: if (unlink(to))
|
||||||
warn("%s: remove", to);
|
warn("%s: remove", tn);
|
||||||
(void)close(from_fd);
|
(void)close(from_fd);
|
||||||
(void)close(to_fd);
|
(void)close(to_fd);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
(void)close(from_fd);
|
(void)close(from_fd);
|
||||||
@ -299,30 +339,36 @@ err: if (unlink(to))
|
|||||||
#else
|
#else
|
||||||
if (futimes(to_fd, tval))
|
if (futimes(to_fd, tval))
|
||||||
#endif
|
#endif
|
||||||
warn("%s: set times", to);
|
warn("%s: set times", tn);
|
||||||
if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) {
|
if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) {
|
||||||
if (errno != EPERM)
|
if (errno != EPERM)
|
||||||
warn("%s: set owner/group", to);
|
warn("%s: set owner/group", tn);
|
||||||
sbp->st_mode &= ~(S_ISUID | S_ISGID);
|
sbp->st_mode &= ~(S_ISUID | S_ISGID);
|
||||||
}
|
}
|
||||||
if (fchmod(to_fd, sbp->st_mode))
|
if (fchmod(to_fd, sbp->st_mode))
|
||||||
warn("%s: set mode", to);
|
warn("%s: set mode", tn);
|
||||||
if (fchflags(to_fd, sbp->st_flags) && (errno != EOPNOTSUPP))
|
if (fchflags(to_fd, sbp->st_flags) && (errno != EOPNOTSUPP))
|
||||||
warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
|
warn("%s: set flags (was: 0%07o)", tn, sbp->st_flags);
|
||||||
|
|
||||||
if (close(to_fd)) {
|
if (close(to_fd)) {
|
||||||
warn("%s", to);
|
warn("%s", tn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlink(from)) {
|
if (unlink(from)) {
|
||||||
warn("%s: remove", from);
|
warn("%s: remove", fn);
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vflg)
|
if (vflg)
|
||||||
printf("%s -> %s\n", from, to);
|
printf("%s -> %s\n", fn, tn);
|
||||||
|
|
||||||
|
free(fn);
|
||||||
|
free(tn);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,3 +425,27 @@ usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: pwd.c,v 1.14 2001/09/16 22:11:56 wiz Exp $ */
|
/* $NetBSD: pwd.c,v 1.15 2003/08/04 22:31:25 jschauma Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1991, 1993, 1994
|
* Copyright (c) 1991, 1993, 1994
|
||||||
@ -43,12 +43,13 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)pwd.c 8.3 (Berkeley) 4/1/94";
|
static char sccsid[] = "@(#)pwd.c 8.3 (Berkeley) 4/1/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: pwd.c,v 1.14 2001/09/16 22:11:56 wiz Exp $");
|
__RCSID("$NetBSD: pwd.c,v 1.15 2003/08/04 22:31:25 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -56,16 +57,21 @@ __RCSID("$NetBSD: pwd.c,v 1.14 2001/09/16 22:11:56 wiz Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
|
int stdout_ok; /* stdout connected to a terminal */
|
||||||
|
|
||||||
static char *getcwd_logical(char *, size_t);
|
static char *getcwd_logical(char *, size_t);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
int main(int, char *[]);
|
int main(int, char *[]);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ch, lFlag;
|
int ch, lFlag;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
char *pn;
|
||||||
|
|
||||||
setprogname(argv[0]);
|
setprogname(argv[0]);
|
||||||
lFlag = 0;
|
lFlag = 0;
|
||||||
@ -95,7 +101,11 @@ main(int argc, char *argv[])
|
|||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
err(EXIT_FAILURE, NULL);
|
err(EXIT_FAILURE, NULL);
|
||||||
|
|
||||||
(void)printf("%s\n", p);
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
|
pn = printescaped(p);
|
||||||
|
(void)printf("%s\n", pn);
|
||||||
|
free(pn);
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
@ -147,3 +157,27 @@ usage(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
111
bin/rm/rm.c
111
bin/rm/rm.c
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: rm.c,v 1.34 2003/03/01 07:57:33 enami Exp $ */
|
/* $NetBSD: rm.c,v 1.35 2003/08/04 22:31:25 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1990, 1993, 1994, 2003
|
* Copyright (c) 1990, 1993, 1994, 2003
|
||||||
@ -43,29 +43,32 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)rm.c 8.8 (Berkeley) 4/27/95";
|
static char sccsid[] = "@(#)rm.c 8.8 (Berkeley) 4/27/95";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: rm.c,v 1.34 2003/03/01 07:57:33 enami Exp $");
|
__RCSID("$NetBSD: rm.c,v 1.35 2003/08/04 22:31:25 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <locale.h>
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <fts.h>
|
#include <fts.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
int dflag, eval, fflag, iflag, Pflag, stdin_ok, vflag, Wflag;
|
int dflag, eval, fflag, iflag, Pflag, stdin_ok, stdout_ok, vflag, Wflag;
|
||||||
|
|
||||||
int check(char *, char *, struct stat *);
|
int check(char *, char *, struct stat *);
|
||||||
void checkdot(char **);
|
void checkdot(char **);
|
||||||
|
char *printescaped(const char *);
|
||||||
void rm_file(char **);
|
void rm_file(char **);
|
||||||
void rm_overwrite(char *, struct stat *);
|
void rm_overwrite(char *, struct stat *);
|
||||||
void rm_tree(char **);
|
void rm_tree(char **);
|
||||||
@ -136,6 +139,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (*argv) {
|
if (*argv) {
|
||||||
stdin_ok = isatty(STDIN_FILENO);
|
stdin_ok = isatty(STDIN_FILENO);
|
||||||
|
stdout_ok = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
if (rflag)
|
if (rflag)
|
||||||
rm_tree(argv);
|
rm_tree(argv);
|
||||||
@ -153,7 +157,8 @@ rm_tree(char **argv)
|
|||||||
FTS *fts;
|
FTS *fts;
|
||||||
FTSENT *p;
|
FTSENT *p;
|
||||||
int flags, needstat, rval;
|
int flags, needstat, rval;
|
||||||
|
char *fn;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove a file hierarchy. If forcing removal (-f), or interactive
|
* Remove a file hierarchy. If forcing removal (-f), or interactive
|
||||||
* (-i) or can't ask anyway (stdin_ok), don't stat the file.
|
* (-i) or can't ask anyway (stdin_ok), don't stat the file.
|
||||||
@ -175,16 +180,19 @@ rm_tree(char **argv)
|
|||||||
(int (*)(const FTSENT **, const FTSENT **))NULL)))
|
(int (*)(const FTSENT **, const FTSENT **))NULL)))
|
||||||
err(1, NULL);
|
err(1, NULL);
|
||||||
while ((p = fts_read(fts)) != NULL) {
|
while ((p = fts_read(fts)) != NULL) {
|
||||||
|
|
||||||
switch (p->fts_info) {
|
switch (p->fts_info) {
|
||||||
case FTS_DNR:
|
case FTS_DNR:
|
||||||
if (!fflag || p->fts_errno != ENOENT) {
|
if (!fflag || p->fts_errno != ENOENT) {
|
||||||
warnx("%s: %s",
|
fn = printescaped(p->fts_path);
|
||||||
p->fts_path, strerror(p->fts_errno));
|
warnx("%s: %s", fn, strerror(p->fts_errno));
|
||||||
|
free(fn);
|
||||||
eval = 1;
|
eval = 1;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
case FTS_ERR:
|
case FTS_ERR:
|
||||||
errx(1, "%s: %s", p->fts_path, strerror(p->fts_errno));
|
errx(EXIT_FAILURE, "%s: %s", printescaped(p->fts_path),
|
||||||
|
strerror(p->fts_errno));
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
case FTS_NS:
|
case FTS_NS:
|
||||||
/*
|
/*
|
||||||
@ -194,8 +202,9 @@ rm_tree(char **argv)
|
|||||||
if (fflag && NONEXISTENT(p->fts_errno))
|
if (fflag && NONEXISTENT(p->fts_errno))
|
||||||
continue;
|
continue;
|
||||||
if (needstat) {
|
if (needstat) {
|
||||||
warnx("%s: %s",
|
fn = printescaped(p->fts_path);
|
||||||
p->fts_path, strerror(p->fts_errno));
|
warnx("%s: %s", fn, strerror(p->fts_errno));
|
||||||
|
free(fn);
|
||||||
eval = 1;
|
eval = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -248,10 +257,15 @@ rm_tree(char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (rval != 0) {
|
if (rval != 0) {
|
||||||
warn("%s", p->fts_path);
|
fn = printescaped(p->fts_path);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
eval = 1;
|
eval = 1;
|
||||||
} else if (vflag)
|
} else if (vflag) {
|
||||||
(void)printf("%s\n", p->fts_path);
|
fn = printescaped(p->fts_path);
|
||||||
|
(void)printf("%s\n", fn);
|
||||||
|
free(fn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (errno)
|
if (errno)
|
||||||
err(1, "fts_read");
|
err(1, "fts_read");
|
||||||
@ -262,7 +276,7 @@ rm_file(char **argv)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int rval;
|
int rval;
|
||||||
char *f;
|
char *f, *fn;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove a file. POSIX 1003.2 states that, by default, attempting
|
* Remove a file. POSIX 1003.2 states that, by default, attempting
|
||||||
@ -275,19 +289,25 @@ rm_file(char **argv)
|
|||||||
sb.st_mode = S_IFWHT|S_IWUSR|S_IRUSR;
|
sb.st_mode = S_IFWHT|S_IWUSR|S_IRUSR;
|
||||||
} else {
|
} else {
|
||||||
if (!fflag || !NONEXISTENT(errno)) {
|
if (!fflag || !NONEXISTENT(errno)) {
|
||||||
warn("%s", f);
|
fn = printescaped(f);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
eval = 1;
|
eval = 1;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (Wflag) {
|
} else if (Wflag) {
|
||||||
warnx("%s: %s", f, strerror(EEXIST));
|
fn = printescaped(f);
|
||||||
|
warnx("%s: %s", fn, strerror(EEXIST));
|
||||||
|
free(fn);
|
||||||
eval = 1;
|
eval = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR(sb.st_mode) && !dflag) {
|
if (S_ISDIR(sb.st_mode) && !dflag) {
|
||||||
warnx("%s: is a directory", f);
|
fn = printescaped(f);
|
||||||
|
warnx("%s: is a directory", fn);
|
||||||
|
free(fn);
|
||||||
eval = 1;
|
eval = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -303,11 +323,16 @@ rm_file(char **argv)
|
|||||||
rval = unlink(f);
|
rval = unlink(f);
|
||||||
}
|
}
|
||||||
if (rval && (!fflag || !NONEXISTENT(errno))) {
|
if (rval && (!fflag || !NONEXISTENT(errno))) {
|
||||||
warn("%s", f);
|
fn = printescaped(f);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
eval = 1;
|
eval = 1;
|
||||||
}
|
}
|
||||||
if (vflag && rval == 0)
|
if (vflag && rval == 0) {
|
||||||
(void)printf("%s\n", f);
|
fn = printescaped(f);
|
||||||
|
(void)printf("%s\n", fn);
|
||||||
|
free(fn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,6 +354,7 @@ rm_overwrite(char *file, struct stat *sbp)
|
|||||||
off_t len;
|
off_t len;
|
||||||
int fd, wlen;
|
int fd, wlen;
|
||||||
char buf[8 * 1024];
|
char buf[8 * 1024];
|
||||||
|
char *fn;
|
||||||
|
|
||||||
fd = -1;
|
fd = -1;
|
||||||
if (sbp == NULL) {
|
if (sbp == NULL) {
|
||||||
@ -360,7 +386,9 @@ rm_overwrite(char *file, struct stat *sbp)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
err: eval = 1;
|
err: eval = 1;
|
||||||
warn("%s", file);
|
fn = printescaped(file);
|
||||||
|
warn("%s", fn);
|
||||||
|
free(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -368,11 +396,14 @@ check(char *path, char *name, struct stat *sp)
|
|||||||
{
|
{
|
||||||
int ch, first;
|
int ch, first;
|
||||||
char modep[15];
|
char modep[15];
|
||||||
|
char *fn;
|
||||||
|
|
||||||
/* Check -i first. */
|
/* Check -i first. */
|
||||||
if (iflag)
|
if (iflag) {
|
||||||
(void)fprintf(stderr, "remove %s? ", path);
|
fn = printescaped(path);
|
||||||
else {
|
(void)fprintf(stderr, "remove '%s'? ", fn);
|
||||||
|
free(fn);
|
||||||
|
} else {
|
||||||
/*
|
/*
|
||||||
* If it's not a symbolic link and it's unwritable and we're
|
* If it's not a symbolic link and it's unwritable and we're
|
||||||
* talking to a terminal, ask. Symbolic links are excluded
|
* talking to a terminal, ask. Symbolic links are excluded
|
||||||
@ -383,10 +414,12 @@ check(char *path, char *name, struct stat *sp)
|
|||||||
!(access(name, W_OK) && (errno != ETXTBSY)))
|
!(access(name, W_OK) && (errno != ETXTBSY)))
|
||||||
return (1);
|
return (1);
|
||||||
strmode(sp->st_mode, modep);
|
strmode(sp->st_mode, modep);
|
||||||
(void)fprintf(stderr, "override %s%s%s/%s for %s? ",
|
fn = printescaped(path);
|
||||||
|
(void)fprintf(stderr, "override %s%s%s/%s for '%s'? ",
|
||||||
modep + 1, modep[9] == ' ' ? "" : " ",
|
modep + 1, modep[9] == ' ' ? "" : " ",
|
||||||
user_from_uid(sp->st_uid, 0),
|
user_from_uid(sp->st_uid, 0),
|
||||||
group_from_gid(sp->st_gid, 0), path);
|
group_from_gid(sp->st_gid, 0), fn);
|
||||||
|
free(fn);
|
||||||
}
|
}
|
||||||
(void)fflush(stderr);
|
(void)fflush(stderr);
|
||||||
|
|
||||||
@ -436,6 +469,30 @@ checkdot(char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: rmdir.c,v 1.17 2001/09/16 21:21:14 wiz Exp $ */
|
/* $NetBSD: rmdir.c,v 1.18 2003/08/04 22:31:25 jschauma Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993, 1994
|
* Copyright (c) 1992, 1993, 1994
|
||||||
@ -43,10 +43,12 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94";
|
static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: rmdir.c,v 1.17 2001/09/16 21:21:14 wiz Exp $");
|
__RCSID("$NetBSD: rmdir.c,v 1.18 2003/08/04 22:31:25 jschauma Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
@ -54,10 +56,14 @@ __RCSID("$NetBSD: rmdir.c,v 1.17 2001/09/16 21:21:14 wiz Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
int rm_path(char *);
|
int stdout_ok; /* stdout connected to a terminal */
|
||||||
void usage(void);
|
|
||||||
int main(int, char *[]);
|
int rm_path(char *);
|
||||||
|
void usage(void);
|
||||||
|
int main(int, char *[]);
|
||||||
|
char *printescaped(const char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -83,6 +89,8 @@ main(int argc, char *argv[])
|
|||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
stdout_ok = isatty(STDIN_FILENO);
|
||||||
|
|
||||||
for (errors = 0; *argv; argv++) {
|
for (errors = 0; *argv; argv++) {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@ -93,7 +101,10 @@ main(int argc, char *argv[])
|
|||||||
*++p = '\0';
|
*++p = '\0';
|
||||||
|
|
||||||
if (rmdir(*argv) < 0) {
|
if (rmdir(*argv) < 0) {
|
||||||
warn("%s", *argv);
|
char *dn;
|
||||||
|
dn = printescaped(*argv);
|
||||||
|
warn("%s", dn);
|
||||||
|
free(dn);
|
||||||
errors = 1;
|
errors = 1;
|
||||||
} else if (pflag)
|
} else if (pflag)
|
||||||
errors |= rm_path(*argv);
|
errors |= rm_path(*argv);
|
||||||
@ -115,7 +126,10 @@ rm_path(char *path)
|
|||||||
*++p = '\0';
|
*++p = '\0';
|
||||||
|
|
||||||
if (rmdir(path) < 0) {
|
if (rmdir(path) < 0) {
|
||||||
warn("%s", path);
|
char *pn;
|
||||||
|
pn = printescaped(path);
|
||||||
|
warn("%s", pn);
|
||||||
|
free(pn);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,3 +144,27 @@ usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
printescaped(const char *src)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *retval;
|
||||||
|
|
||||||
|
len = strlen(src);
|
||||||
|
if (len != 0 && SIZE_T_MAX/len <= 4) {
|
||||||
|
errx(EXIT_FAILURE, "%s: name too long", src);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = (char *)malloc(4*len+1);
|
||||||
|
if (retval != NULL) {
|
||||||
|
if (stdout_ok)
|
||||||
|
(void)strvis(retval, src, VIS_NL | VIS_CSTYLE);
|
||||||
|
else
|
||||||
|
(void)strcpy(retval, src);
|
||||||
|
return retval;
|
||||||
|
} else
|
||||||
|
errx(EXIT_FAILURE, "out of memory!");
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user