mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-20 00:33:57 +00:00
Use err(3).
This commit is contained in:
parent
474cc7fe23
commit
f296f8ebb4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28564
|
@ -32,13 +32,17 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -50,27 +54,26 @@ static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
|
|||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fnmatch.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char *filename;
|
||||
int cflag, pflag;
|
||||
|
||||
void usage __P((void));
|
||||
static void usage __P((void));
|
||||
int decode __P((void));
|
||||
int decode2 __P((int));
|
||||
|
||||
extern int optind;
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
extern int errno;
|
||||
int rval, ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "cp")) != -1) {
|
||||
|
@ -82,7 +85,7 @@ main(argc, argv)
|
|||
pflag = 1; /* print output to stdout */
|
||||
break;
|
||||
default:
|
||||
(void)usage();
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
|
@ -93,8 +96,7 @@ main(argc, argv)
|
|||
rval = 0;
|
||||
do {
|
||||
if (!freopen(filename = *argv, "r", stdin)) {
|
||||
(void)fprintf(stderr, "uudecode: %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
warn("%s", *argv);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -130,7 +132,6 @@ int
|
|||
decode2(flag)
|
||||
int flag;
|
||||
{
|
||||
extern int errno;
|
||||
struct passwd *pw;
|
||||
register int n;
|
||||
register char ch, *p;
|
||||
|
@ -145,8 +146,7 @@ decode2(flag)
|
|||
if (flag) /* no error */
|
||||
return(0);
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"uudecode: %s: no \"begin\" line\n", filename);
|
||||
warnx("%s: no \"begin\" line", filename);
|
||||
return(1);
|
||||
}
|
||||
} while (strncmp(buf, "begin ", 6) ||
|
||||
|
@ -157,21 +157,18 @@ decode2(flag)
|
|||
/* handle ~user/file format */
|
||||
if (buf[0] == '~') {
|
||||
if (!(p = index(buf, '/'))) {
|
||||
(void)fprintf(stderr, "uudecode: %s: illegal ~user.\n",
|
||||
filename);
|
||||
warnx("%s: illegal ~user", filename);
|
||||
return(1);
|
||||
}
|
||||
*p++ = NULL;
|
||||
if (!(pw = getpwnam(buf + 1))) {
|
||||
(void)fprintf(stderr, "uudecode: %s: no user %s.\n",
|
||||
filename, buf);
|
||||
warnx("%s: no user %s", filename, buf);
|
||||
return(1);
|
||||
}
|
||||
n = strlen(pw->pw_dir);
|
||||
n1 = strlen(p);
|
||||
if (n + n1 + 2 > MAXPATHLEN) {
|
||||
(void)fprintf(stderr, "uudecode: %s: path too long.\n",
|
||||
filename);
|
||||
warnx("%s: path too long", filename);
|
||||
return(1);
|
||||
}
|
||||
bcopy(p, buf + n + 1, n1 + 1);
|
||||
|
@ -185,8 +182,7 @@ decode2(flag)
|
|||
|
||||
else if (!freopen(buf, "w", stdout) ||
|
||||
fchmod(fileno(stdout), mode&0666)) {
|
||||
(void)fprintf(stderr, "uudecode: %s: %s: %s\n", buf,
|
||||
filename, strerror(errno));
|
||||
warn("%s: %s", buf, filename);
|
||||
return(1);
|
||||
}
|
||||
strcpy(buffn, buf); /* store file name from header line */
|
||||
|
@ -194,8 +190,7 @@ decode2(flag)
|
|||
/* for each input line */
|
||||
for (;;) {
|
||||
if (!fgets(p = buf, sizeof(buf), stdin)) {
|
||||
(void)fprintf(stderr, "uudecode: %s: short file.\n",
|
||||
filename);
|
||||
warnx("%s: short file", filename);
|
||||
return(1);
|
||||
}
|
||||
#define DEC(c) (((c) - ' ') & 077) /* single character decode */
|
||||
|
@ -204,9 +199,9 @@ decode2(flag)
|
|||
|
||||
#define OUT_OF_RANGE \
|
||||
{ \
|
||||
(void)fprintf(stderr, \
|
||||
"uudecode:\n\tinput file: %s\n\tencoded file: %s\n\t%s: [%d-%d]\n", \
|
||||
filename, buffn, "character out of range", 1 + ' ', 077 + ' ' + 1); \
|
||||
warnx( \
|
||||
"\n\tinput file: %s\n\tencoded file: %s\n\tcharacter out of range: [%d-%d]", \
|
||||
filename, buffn, 1 + ' ', 077 + ' ' + 1); \
|
||||
return(1); \
|
||||
}
|
||||
|
||||
|
@ -258,14 +253,13 @@ decode2(flag)
|
|||
if (fgets(buf, sizeof(buf), stdin) == NULL ||
|
||||
(strcmp(buf, "end") && strcmp(buf, "end\n") &&
|
||||
strcmp(buf, "end\r\n"))) {
|
||||
(void)fprintf(stderr, "uudecode: %s: no \"end\" line.\n",
|
||||
filename);
|
||||
warnx("%s: no \"end\" line", filename);
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: uudecode [-cp] [file ...]\n");
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)uuencode.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $Id$
|
||||
.\" $Id: uuencode.1,v 1.5 1997/02/22 19:57:36 peter Exp $
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt UUENCODE 1
|
||||
|
@ -45,7 +45,7 @@
|
|||
.Ar name
|
||||
.Nm uudecode
|
||||
.Op Fl cp
|
||||
.Op Ar file ...
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
.Nm Uuencode
|
||||
and
|
||||
|
@ -127,6 +127,8 @@ The encoded form of the file is expanded by 35% (3 bytes become 4 plus
|
|||
control information).
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Nm uudecode
|
||||
and
|
||||
.Nm uuencode
|
||||
utilities appeared in
|
||||
.Bx 4.0 .
|
||||
|
|
|
@ -32,13 +32,17 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)uuencode.c 8.2 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -49,18 +53,20 @@ static char sccsid[] = "@(#)uuencode.c 8.2 (Berkeley) 4/2/94";
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void encode __P((void));
|
||||
static void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
extern int optind;
|
||||
extern int errno;
|
||||
struct stat sb;
|
||||
int mode;
|
||||
char *strerror();
|
||||
|
||||
while (getopt(argc, argv, "") != -1)
|
||||
usage();
|
||||
|
@ -69,11 +75,8 @@ main(argc, argv)
|
|||
|
||||
switch(argc) {
|
||||
case 2: /* optional first argument is input file */
|
||||
if (!freopen(*argv, "r", stdin) || fstat(fileno(stdin), &sb)) {
|
||||
(void)fprintf(stderr, "uuencode: %s: %s.\n",
|
||||
*argv, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (!freopen(*argv, "r", stdin) || fstat(fileno(stdin), &sb))
|
||||
err(1, "%s", *argv);
|
||||
#define RWX (S_IRWXU|S_IRWXG|S_IRWXO)
|
||||
mode = sb.st_mode & RWX;
|
||||
++argv;
|
||||
|
@ -90,10 +93,8 @@ main(argc, argv)
|
|||
(void)printf("begin %o %s\n", mode, *argv);
|
||||
encode();
|
||||
(void)printf("end\n");
|
||||
if (ferror(stdout)) {
|
||||
(void)fprintf(stderr, "uuencode: write error.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (ferror(stdout))
|
||||
errx(1, "write error");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -103,13 +104,14 @@ main(argc, argv)
|
|||
/*
|
||||
* copy from in to out, encoding as you go along.
|
||||
*/
|
||||
void
|
||||
encode()
|
||||
{
|
||||
register int ch, n;
|
||||
register char *p;
|
||||
char buf[80];
|
||||
|
||||
while (n = fread(buf, 1, 45, stdin)) {
|
||||
while ((n = fread(buf, 1, 45, stdin))) {
|
||||
ch = ENC(n);
|
||||
if (putchar(ch) == EOF)
|
||||
break;
|
||||
|
@ -134,15 +136,14 @@ encode()
|
|||
if (putchar('\n') == EOF)
|
||||
break;
|
||||
}
|
||||
if (ferror(stdin)) {
|
||||
(void)fprintf(stderr, "uuencode: read error.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (ferror(stdin))
|
||||
errx(1, "read error");
|
||||
ch = ENC('\0');
|
||||
(void)putchar(ch);
|
||||
(void)putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,"usage: uuencode [infile] remotefile\n");
|
||||
|
|
Loading…
Reference in a new issue