Fix coding style according to tizen rule
[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                 n64Test = 0x01;
55                 p = (LPBYTE)&n64Test;
56
57                 if (p[0] == 0x01)
58                         isLittleEndian = 1;
59                 else
60                         isLittleEndian = 0;
61         }
62
63         if (isLittleEndian == 1) {
64                 n32Low = (INT32)(n64host & 0xFFFFFFFF);
65                 n32High = (INT32)(n64host >> 32);
66
67                 n32Low = htonl_(n32Low);
68                 n32High = htonl_(n32High);
69
70                 result = ((INT64)n32Low << 32) | n32High;
71                 return result;
72         } else {
73                 return n64host;
74         }
75 }