New version from uunet. Minor changes.
This commit is contained in:
parent
977d90a2d5
commit
6a2f04d860
@ -29,10 +29,10 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)size.1 6.6 (Berkeley) 7/1/91
|
||||
.\" $Id: size.1,v 1.2 1993/08/01 07:28:41 mycroft Exp $
|
||||
.\" from: @(#)size.1 6.7 (Berkeley) 3/2/92
|
||||
.\" $Id: size.1,v 1.3 1993/08/07 04:35:30 mycroft Exp $
|
||||
.\"
|
||||
.Dd July 1, 1991
|
||||
.Dd March 2, 1992
|
||||
.Dt SIZE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -43,15 +43,15 @@
|
||||
.Op Ar object_file ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Size
|
||||
displays the text, data and bss segment sizes of the given
|
||||
displays the text, data and bss segment sizes of the specified
|
||||
.Ar object_file
|
||||
in bytes (decimal), and the sum of the three segments (hexidecimal and
|
||||
decimal).
|
||||
If
|
||||
in bytes (in decimal), and the sum of the three segments (in
|
||||
decimal and hexidecimal).
|
||||
If no
|
||||
.Ar object_file
|
||||
is not given,
|
||||
is specified
|
||||
.Nm
|
||||
automatically searches for the file
|
||||
attempts to report on the file
|
||||
.Pa a.out .
|
||||
.Sh SEE ALSO
|
||||
.Xr a.out 5
|
||||
|
@ -38,30 +38,53 @@ char copyright[] =
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)size.c 4.7 (Berkeley) 6/1/90";*/
|
||||
static char rcsid[] = "$Id: size.c,v 1.3 1993/08/01 18:08:26 mycroft Exp $";
|
||||
/*static char sccsid[] = "from: @(#)size.c 5.1 (Berkeley) 3/2/92";*/
|
||||
static char rcsid[] = "$Id: size.c,v 1.4 1993/08/07 04:35:31 mycroft Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <errno.h>
|
||||
#include <a.out.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int exval;
|
||||
void err __P((const char *, ...));
|
||||
int show __P((int, char *));
|
||||
void usage __P((void));
|
||||
|
||||
main(int argc, char *argv[])
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
if (argc < 2) {
|
||||
sizeit("a.out", 0);
|
||||
exit(exval);
|
||||
}
|
||||
int ch, eval;
|
||||
|
||||
for (++argv; *argv; ++argv)
|
||||
sizeit(*argv, argc > 2);
|
||||
exit(exval);
|
||||
while ((ch = getopt(argc, argv, "")) != EOF)
|
||||
switch(ch) {
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
eval = 0;
|
||||
if (*argv)
|
||||
do {
|
||||
eval |= show(argc, *argv);
|
||||
} while (*++argv);
|
||||
else
|
||||
eval |= show(1, "a.out");
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
sizeit(char *name, int doname)
|
||||
int
|
||||
show(count, name)
|
||||
int count;
|
||||
char *name;
|
||||
{
|
||||
static int first = 1;
|
||||
struct exec head;
|
||||
@ -69,26 +92,58 @@ sizeit(char *name, int doname)
|
||||
int fd;
|
||||
|
||||
if ((fd = open(name, O_RDONLY, 0)) < 0) {
|
||||
fprintf(stderr, "size: ");
|
||||
perror(name);
|
||||
exval = 1;
|
||||
return;
|
||||
err("%s: %s", name, strerror(errno));
|
||||
return (1);
|
||||
}
|
||||
if (read(fd, (char *)&head, sizeof(head)) != sizeof(head) ||
|
||||
N_BADMAG(head)) {
|
||||
fprintf(stderr, "size: %s: not in a.out format.\n", name);
|
||||
exval = 1;
|
||||
return;
|
||||
if (read(fd, &head, sizeof(head)) != sizeof(head) || N_BADMAG(head)) {
|
||||
err("%s: not in a.out format", name);
|
||||
return (1);
|
||||
}
|
||||
(void)close(fd);
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
printf("text\tdata\tbss\tdec\thex\n");
|
||||
(void)printf("text\tdata\tbss\tdec\thex\n");
|
||||
}
|
||||
total = head.a_text + head.a_data + head.a_bss;
|
||||
printf("%lu\t%lu\t%lu\t%lu\t%lx", head.a_text, head.a_data,
|
||||
(void)printf("%lu\t%lu\t%lu\t%lu\t%lx", head.a_text, head.a_data,
|
||||
head.a_bss, total, total);
|
||||
if (doname)
|
||||
printf("\t%s", name);
|
||||
printf("\n");
|
||||
if (count > 1)
|
||||
(void)printf("\t%s", name);
|
||||
(void)printf("\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: size [file ...]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
#if __STDC__
|
||||
err(const char *fmt, ...)
|
||||
#else
|
||||
err(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
(void)fprintf(stderr, "size: ");
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
(void)fprintf(stderr, "\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user