File: endian.c

package info (click to toggle)
uni2ascii 4.18-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 788 kB
  • sloc: ansic: 5,605; tcl: 1,914; sh: 786; python: 53; makefile: 43
file content (46 lines) | stat: -rw-r--r-- 1,523 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Time-stamp: <2010-08-29 20:55:45 poser>
 *
 * Copyright (C) 2003 William J. Poser.
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 3 of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 * or go to the web page:  http://www.gnu.org/licenses/gpl.txt.
 */

#include "u2a_endian.h"

/* Returns a value indicating the endianness of the machine */

short Get_Endianness() {
  unsigned int qp = 0x0f0d0501;	/* By definition, msb = 0f, lsb = 01 */
  char *bp;
  bp = (char *) &qp;		/* bp now points at first byte of 4 byte sequence */

  if((bp[0] == 0x01) &&	/* 1234 pattern */
     (bp[1] == 0x05) &&
     (bp[2] == 0x0d) &&
     (bp[3] == 0x0f)) return(E_LITTLE_ENDIAN);

  if((bp[3] == 0x01) &&	/* 4321 pattern */
     (bp[2] == 0x05) &&
     (bp[1] == 0x0d) &&
     (bp[0] == 0x0f)) return(E_BIG_ENDIAN);

  if((bp[2] == 0x01) &&	/* 3412 pattern */
     (bp[3] == 0x05) &&
     (bp[0] == 0x0d) &&
     (bp[1] == 0x0f)) return(E_PDP_ENDIAN);

  return(E_UNKNOWN_ENDIAN);

}