home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / util_src / printstk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-29  |  1.7 KB  |  93 lines

  1. /* 
  2.  * utility to print the value of _stksize from gcc-cc1.ttp
  3.  *
  4.  *    Usage: printstk [<filename>]
  5.  *        if <filename> is not specified defaults to .\gcc-cc1.ttp
  6.  *    ++jrb
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unixlib.h>
  12. #include <string.h>
  13. #include <st-out.h>
  14.  
  15. long lseek(int, long, int);
  16.  
  17. long find_offset (fd, fn)
  18. int fd;
  19. char *fn;
  20. {
  21.     struct aexec head;
  22.     struct asym  sym;
  23.     
  24.     if(read(fd, &head, sizeof(head)) != sizeof(head))
  25.     {
  26.     perror(fn);
  27.     exit(2);
  28.     }
  29.     if(head.a_magic != CMAGIC)
  30.     {
  31.     fprintf(stderr,"Invalid magic number %x\n", head.a_magic);
  32.     exit(3);
  33.     }
  34.     if(head.a_syms == 0)
  35.     {
  36.     fprintf(stderr,"%s: no symbol table\n", fn);
  37.     exit(4);
  38.     }
  39.     if(lseek(fd, head.a_text+head.a_data, 1) != 
  40.        (head.a_text+head.a_data+sizeof(head)))
  41.     {
  42.     perror(fn);
  43.     exit(5);
  44.     }
  45.     do {
  46.     if(read(fd, &sym, sizeof(sym)) != sizeof(sym))
  47.     {
  48.         fprintf(stderr, "symbol _stksize not found\n");
  49.         exit(6);
  50.     }
  51.     } while(strncmp("__stksiz", sym.a_name, 8) != 0);
  52.     
  53.     if( !(sym.a_type & A_DATA) )
  54.     {
  55.     fprintf(stderr, "symbol _stksize is undefined\n");
  56.     exit(9);
  57.     }
  58.     return sym.a_value + sizeof(head);
  59. }
  60.  
  61. int main(argc, argv)
  62. int argc;
  63. char **argv;
  64. {
  65.     int fd;
  66.     long stksize, offset;
  67.     char fn[FILENAME_MAX];
  68.     
  69.     if(argc > 1)
  70.     (void) strcpy(fn, *++argv);
  71.     else
  72.     (void) strcpy(fn, "gcc-cc1.ttp");
  73.     
  74.     if((fd = open(fn, 0)) < 0)
  75.     {
  76.     perror(fn);
  77.     exit(1);
  78.     }
  79.     
  80.     offset = find_offset(fd, fn);
  81.     
  82.     if(lseek(fd, offset, 0) != offset)
  83.     {
  84.     perror(fn);
  85.     exit(7);
  86.     }
  87.     read(fd, &stksize, sizeof(long));
  88.     printf("%s: stksize is %ld (%dK)\n", fn, stksize, (int)(stksize/1024));
  89.     
  90.     return close(fd);
  91. }
  92.  
  93.