modified: makefile
[GalaxyCodeBases.git] / c_cpp / etc / md5_sha / endian.c
blob87a1d233b79569653f07e4364c2c03ff6d8597f5
1 /*
2 * endian - Determine the byte order of a long on your machine.
4 * @(#) $Revision: 13.1 $
5 * @(#) $Id: endian.c,v 13.1 2006/08/14 03:16:33 chongo Exp $
6 * @(#) $Source: /usr/local/src/cmd/hash/RCS/endian.c,v $
8 * Big Endian: Amdahl, 68k, Pyramid, Mips, Sparc, ...
9 * Little Endian: Vax, 32k, Spim (Dec Mips), i386, i486, ...
11 * This file was written by Landon Curt Noll.
13 * This code has been placed in the public domain. Please do not
14 * copyright this code.
16 * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO
17 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
18 * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
19 * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
21 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
22 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * chongo (was here) /\oo/\
26 * http://www.isthe.com/chongo/index.html
28 * Share and enjoy! :-)
30 * See shsdrvr.c and md5drvr.c for version and modification history.
33 #include <stdio.h>
34 #include <stdlib.h>
36 /* byte order array */
37 char byte[8] = { (char)0x12, (char)0x36, (char)0x48, (char)0x59,
38 (char)0x01, (char)0x23, (char)0x45, (char)0x67 };
40 /*ARGSUSED*/
41 int
42 main(int argc, char *argv[])
44 /* pointers into the byte order array */
45 int *intp = (int *)byte;
47 /* usage */
48 if (argc != 1) {
49 fprintf(stderr, "usage: %s\n", argv[0]);
50 exit(1);
53 /* Print the standard <machine/endian.h> defines */
54 printf("#undef BIG_ENDIAN\n");
55 printf("#define BIG_ENDIAN\t4321\n");
56 printf("#undef LITTLE_ENDIAN\n");
57 printf("#define LITTLE_ENDIAN\t1234\n");
59 /* Determine byte order */
60 printf("#undef BYTE_ORDER\n");
61 if (intp[0] == 0x12364859) {
62 /* Most Significant Byte first */
63 printf("#define BYTE_ORDER\tBIG_ENDIAN\n");
64 } else if (intp[0] == 0x59483612) {
65 /* Least Significant Byte first */
66 printf("#define BYTE_ORDER\tLITTLE_ENDIAN\n");
67 } else {
68 fprintf(stderr, "Unknown int Byte Order, set BYTE_ORDER in Makefile\n");
69 exit(2);
71 exit(0);