Plan 9 from Bell Labs’s /usr/web/sources/plan9/sys/src/cmd/size.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include	<u.h>
#include	<libc.h>
#include	<bio.h>
#include	<mach.h>

int
size(char *file)
{
	int fd;
	Fhdr f;

	if((fd = open(file, OREAD)) < 0){
		fprint(2, "size: ");
		perror(file);
		return 1;
	}
	if(crackhdr(fd, &f)) {
		print("%ldt + %ldd + %ldb = %ld\t%s\n", f.txtsz, f.datsz,
			f.bsssz, f.txtsz+f.datsz+f.bsssz, file);
		close(fd);
		return 0;
	}
	fprint(2, "size: %s not an a.out\n", file);
	close(fd);
	return 1;
}

void
main(int argc, char *argv[])
{
	char *err;
	int i;

	ARGBEGIN {
	default:
		fprint(2, "usage: size [a.out ...]\n");
		exits("usage");
	} ARGEND;

	err = 0;
	if(argc == 0)
		if(size("8.out"))
			err = "error";
	for(i=0; i<argc; i++)
		if(size(argv[i]))
			err = "error";
	exits(err);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.