size.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <mach.h>
  13. int
  14. size(char *file)
  15. {
  16. int fd;
  17. Fhdr f;
  18. if((fd = open(file, OREAD)) < 0){
  19. fprint(2, "size: ");
  20. perror(file);
  21. return 1;
  22. }
  23. if(crackhdr(fd, &f)) {
  24. print("%ldt + %ldd + %ldb = %ld\t%s\n", f.txtsz, f.datsz,
  25. f.bsssz, f.txtsz+f.datsz+f.bsssz, file);
  26. close(fd);
  27. return 0;
  28. }
  29. fprint(2, "size: %s not an a.out\n", file);
  30. close(fd);
  31. return 1;
  32. }
  33. void
  34. main(int argc, char *argv[])
  35. {
  36. char *err;
  37. int i;
  38. ARGBEGIN {
  39. default:
  40. fprint(2, "usage: size [a.out ...]\n");
  41. exits("usage");
  42. } ARGEND;
  43. err = 0;
  44. if(argc == 0)
  45. if(size("8.out"))
  46. err = "error";
  47. for(i=0; i<argc; i++)
  48. if(size(argv[i]))
  49. err = "error";
  50. exits(err);
  51. }