home *** CD-ROM | disk | FTP | other *** search
- /*
- * make endiandef.h include file for this host
- *
- * Andy Duplain, August 1992.
- */
- #include <stdlib.h>
- #include <stdio.h>
-
- union {
- int i;
- char c[4];
- } word;
-
- int main(void)
- {
- FILE *ofp;
- register i;
-
- if (sizeof(int) != 4) {
- fprintf(stderr, "Sorry pal, you cannot use this program on this host (sizeof(int) != 4)\n");
- exit(1);
- }
- #ifdef UNIX
- ofp = fopen("endiandef.h", "w");
- #else
- ofp = fopen("h.endiandef", "w");
- #endif
- if (!ofp) {
- perror("endiandef.h");
- exit(1);
- }
- word.i = 0x01020304;
-
- fprintf(ofp, "/*\n * endiandef.h\tdefines for local host byte sex.\n */\n");
- fprintf(ofp, "#ifndef __ENDIANDEF_H\n#define __ENDIANDEF_H\n");
- for (i = 0; i < 4; i++) {
- fprintf(ofp, "#define BYTE%dSHIFT %d\n", i, (word.c[i] - 1) * 8);
- }
-
- if (word.c[0] == 1 && word.c[1] == 2 && word.c[2] == 3 && word.c[3] == 4)
- fprintf(ofp, "#define BIGENDIAN\n");
- else
- fprintf(ofp, "#undef BIGENDIAN\n");
-
- if (word.c[0] == 4 && word.c[1] == 3 && word.c[2] == 2 && word.c[3] == 1)
- fprintf(ofp, "#define LITTLEENDIAN\n");
- else
- fprintf(ofp, "#undef LITTLEENDIAN\n");
-
- fprintf(ofp, "#endif /* __ENDIANDEF_H */\n");
- fclose(ofp);
- exit(0);
- }
-