-
Notifications
You must be signed in to change notification settings - Fork 1
/
thrak.c
executable file
·86 lines (58 loc) · 2.41 KB
/
thrak.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/************************************************************************************************************
NAME
thrak.c
DESCRIPTION
Helper functions for writing PHP extensions.
AUTHOR
Christian Vigh, 11/2014.
HISTORY
tbd
************************************************************************************************************/
# include "thrak.h"
# include <zend_alloc.h>
/*-----------------------------------------------------------------------------------------------------------
Global variables.
*-----------------------------------------------------------------------------------------------------------*/
int thrak_machine_endianness ;
/*===========================================================================================================
NAME
thrak_initialize - initializes the thrak utility package.
*===========================================================================================================*/
void thrak_initialize ( THRAK_INIT_FUNC_ARGS )
{
thrak_machine_endianness = thrak_get_machine_endianness ( ) ;
}
/*===========================================================================================================
NAME
thrak_shutdown - Shutdows the thrak utility package.
*===========================================================================================================*/
void thrak_shutdown ( THRAK_SHUTDOWN_FUNC_ARGS )
{
}
/*===========================================================================================================
NAME
thrak_get_machine_endianness - Returns the machine endianness.
PROTOTYPE
endianness = thrak_machine_endianness ( ) ;
DESCRIPTION
Returns the endianness of the current machine.
RETURNS
One of the constants LITTLE_ENDIAN or BIG_ENDIAN.
*===========================================================================================================*/
int thrak_get_machine_endianness ( )
{
unsigned char bytes [ sizeof ( unsigned int ) ] ;
unsigned int test_value = 0 ;
unsigned int current_value = 0x00 ;
int i ;
for ( i = 0 ; i < sizeof ( unsigned int ) ; i ++ )
{
current_value ++ ;
test_value = ( test_value << 8 ) | current_value ;
}
* ( ( unsigned int * ) bytes ) = test_value ;
if ( bytes [0] == current_value )
return ( LITTLE_ENDIAN ) ;
else
return ( BIG_ENDIAN ) ;
}