4
0

testpad.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Find out if we need the pad field in the header for this machine
  2. Copyright (C) 1991 Free Software Foundation
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License as
  5. published by the Free Software Foundation; either version 2, or (at
  6. your option) any later version.
  7. This program is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include <stdio.h>
  16. struct inc
  17. {
  18. char a[20];
  19. char b[20];
  20. };
  21. struct test1
  22. {
  23. char a;
  24. struct inc in[5];
  25. };
  26. struct test2
  27. {
  28. char a;
  29. char b;
  30. struct inc in[5];
  31. };
  32. void
  33. main ()
  34. {
  35. struct test1 t1;
  36. struct test2 t2;
  37. int t1diff, t2diff;
  38. FILE *fp = fopen ("testpad.h", "w");
  39. if (fp == 0)
  40. {
  41. fprintf (stderr, "testpad: cannot open ");
  42. fflush (stderr);
  43. perror ("testpad.h");
  44. exit (1);
  45. }
  46. t1diff = (char *) &t1.in[0] - (char *) &t1;
  47. t2diff = (char *) &t2.in[0] - (char *) &t2;
  48. if (t2diff == t1diff + 1)
  49. fprintf (fp, "#define NEEDPAD\n");
  50. else if (t1diff != t2diff)
  51. fprintf (stderr, "Cannot determine padding for tar struct, \n\
  52. will try with none.\n");
  53. fclose (fp);
  54. exit (0);
  55. }