685299dc6ddbfd749b8d9c381178cd0046404a80
[platform/core/security/drm-service-core-tizen.git] / tadcore / TADCCore / TADC_Sub.cpp
1 /*
2  * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "TADC_Sub.h"
18
19 unsigned int htons_(unsigned int hostshort)
20 {
21         BYTE    *pBuffer;
22         unsigned int    nResult;
23
24         nResult = 0;
25         pBuffer = (LPBYTE)&hostshort;
26         nResult = (((pBuffer[0] << 8) & 0xFF00) | (pBuffer[1] & 0x00FF));
27
28         return nResult;
29 }
30
31 DWORD htonl_(DWORD hostlong)
32 {
33         DWORD   nResult = hostlong >> 16;
34         unsigned int    upper   = (unsigned int)nResult & 0x0000FFFF;
35         unsigned int    lower   = (unsigned int)hostlong & 0x0000FFFF;
36
37         upper   = htons_(upper);
38         lower   = htons_(lower);
39     nResult     = 0x10000 * lower + upper;
40
41         return nResult;
42 }
43
44 INT64 _hton64( INT64 n64host )
45 {
46         INT64   result;
47         LPBYTE   p;
48         short   n64Test;
49         int      n32High, n32Low;
50
51         static int  isLittleEndian = -1;
52
53         if( isLittleEndian == -1 )
54         {
55                 n64Test = 0x01;
56                 p = (LPBYTE)&n64Test;
57
58                 if( p[ 0 ] == 0x01 )
59                 {
60                         isLittleEndian = 1;
61                 }
62                 else
63                 {
64                         isLittleEndian = 0;
65                 }
66         }
67
68         if( isLittleEndian == 1 )
69         {
70                 n32Low = (INT32)( n64host & 0xFFFFFFFF );
71                 n32High = (INT32)( n64host >> 32 );
72
73                 n32Low = htonl_( n32Low );
74                 n32High = htonl_( n32High );
75
76                 result = ( (INT64)n32Low << 32 ) | n32High;
77                 return result;
78         }
79         else
80         {
81                 return n64host;
82         }
83 }