1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-28 08:02:54 +00:00

Use err(3).

This commit is contained in:
Philippe Charnier 1997-08-11 07:31:28 +00:00
parent c002b33b60
commit db4f31b740
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28072
3 changed files with 25 additions and 23 deletions

View File

@ -38,10 +38,10 @@
.Nm strings
.Nd find printable strings in a file
.Sh SYNOPSIS
.Nm strings
.Nm
.Op Fl afo
.Op Fl n Ar number
.Op Ar file ...
.Op Ar
.Sh DESCRIPTION
.Nm Strings
displays the sequences of printable characters in each of the specified
@ -53,12 +53,12 @@ The options are as follows:
.Bl -tag -width Ds
.It Fl a
By default,
.Nm strings
.Nm
only searches the text and data segments of object files.
The
.Fl a
option causes
.Nm strings
.Nm
to search the entire object file.
.It Fl f
Each string is preceded by the name of the file

View File

@ -38,10 +38,10 @@
.Nm strings
.Nd find printable strings in a file
.Sh SYNOPSIS
.Nm strings
.Nm
.Op Fl afo
.Op Fl n Ar number
.Op Ar file ...
.Op Ar
.Sh DESCRIPTION
.Nm Strings
displays the sequences of printable characters in each of the specified
@ -53,12 +53,12 @@ The options are as follows:
.Bl -tag -width Ds
.It Fl a
By default,
.Nm strings
.Nm
only searches the text and data segments of object files.
The
.Fl a
option causes
.Nm strings
.Nm
to search the entire object file.
.It Fl f
Each string is preceded by the name of the file

View File

@ -32,20 +32,24 @@
*/
#ifndef lint
static char copyright[] =
static const char copyright[] =
"@(#) Copyright (c) 1980, 1987, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)strings.c 8.2 (Berkeley) 1/28/94";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <a.out.h>
#include <ctype.h>
#include <errno.h>
#include <err.h>
#include <fcntl.h>
#include <locale.h>
#include <stdio.h>
@ -55,8 +59,8 @@ static char sccsid[] = "@(#)strings.c 8.2 (Berkeley) 1/28/94";
#define DEF_LEN 4 /* default minimum string length */
#define ISSTR(ch) (isalnum(ch) || ispunct(ch) || \
isspace(ch) && (!iscntrl(ch) || ch == '\t') || \
isascii(ch) && isprint(ch))
(isspace(ch) && (!iscntrl(ch) || ch == '\t')) || \
(isascii(ch) && isprint(ch)))
typedef struct exec EXEC; /* struct exec cast */
@ -66,8 +70,10 @@ static int hcnt, /* head count */
read_len; /* length to read */
static u_char hbfr[sizeof(EXEC)]; /* buffer for struct exec */
static void usage();
int getch __P((void));
static void usage __P((void));
int
main(argc, argv)
int argc;
char **argv;
@ -128,23 +134,18 @@ main(argc, argv)
if (minlen == -1)
minlen = DEF_LEN;
else if (minlen < 1) {
(void)fprintf(stderr, "strings: length less than 1\n");
exit (1);
}
else if (minlen < 1)
errx(1, "length less than 1");
if (!(bfr = malloc((u_int)minlen))) {
(void)fprintf(stderr, "strings: %s\n", strerror(errno));
exit(1);
}
if (!(bfr = malloc((u_int)minlen)))
errx(1, "malloc");
bfr[minlen] = '\0';
file = "stdin";
do {
if (*argv) {
file = *argv++;
if (!freopen(file, "r", stdin)) {
(void)fprintf(stderr,
"strings: %s: %s\n", file, strerror(errno));
warn("%s", file);
exitcode = 1;
goto nextfile;
}
@ -199,6 +200,7 @@ nextfile: ;
* getch --
* get next character from wherever
*/
int
getch()
{
++foff;