/src/clamav/libclamav/fpu.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  *  Copyright (C) 2013-2024 Cisco Systems, Inc. and/or its affiliates. All rights reserved.  | 
3  |  |  *  Copyright (C) 2013 Sourcefire, Inc.  | 
4  |  |  *  | 
5  |  |  *  Authors: Steven Morgan <smorgan@sourcefire.com>  | 
6  |  |  *  | 
7  |  |  *  This program is free software; you can redistribute it and/or modify  | 
8  |  |  *  it under the terms of the GNU General Public License version 2 as  | 
9  |  |  *  published by the Free Software Foundation.  | 
10  |  |  *  | 
11  |  |  *  This program is distributed in the hope that it will be useful,  | 
12  |  |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
13  |  |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  | 
14  |  |  *  GNU General Public License for more details.  | 
15  |  |  *  | 
16  |  |  *  You should have received a copy of the GNU General Public License  | 
17  |  |  *  along with this program; if not, write to the Free Software  | 
18  |  |  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  | 
19  |  |  *  MA 02110-1301, USA.  | 
20  |  |  */  | 
21  |  |  | 
22  |  | #include "others.h"  | 
23  |  | #include "fpu.h"  | 
24  |  |  | 
25  |  | /* the character representation of the double below is "elleemme" or "emmeelle" upon depending  | 
26  |  |    whether floating point little endian or big endian(IEEE-754) is in effect. */  | 
27  |  | int get_fpu_endian(void)  | 
28  | 0  | { | 
29  |  | #ifdef _WIN32  | 
30  |  |     return FPU_ENDIAN_LITTLE;  | 
31  |  | #else  | 
32  | 0  |     const char* fpu_le = "elleemme";  | 
33  | 0  |     const char* fpu_be = "emmeelle";  | 
34  | 0  |     const union sd { | 
35  | 0  |         double d;  | 
36  | 0  |         char mem[8];  | 
37  | 0  |     } u_md = {3815911171354501045744583353695226502220105394563506259449467213186125718792664588210662403287568710818873279842508553551908601408568128557088985172985437412593385138085986771664896.0}; | 
38  | 0  |     if (!memcmp(u_md.mem, fpu_le, 8)) { | 
39  | 0  |         cli_dbgmsg("fpu: Floating point little endian detected.\n"); | 
40  | 0  |         return FPU_ENDIAN_LITTLE;  | 
41  | 0  |     } else if (!memcmp(u_md.mem, fpu_be, 8)) { | 
42  | 0  |         cli_dbgmsg("fpu: Floating point big endian detected.\n"); | 
43  | 0  |         return FPU_ENDIAN_BIG;  | 
44  | 0  |     } else { | 
45  | 0  |         cli_dbgmsg("fpu: Floating point endian detection failed. " | 
46  | 0  |                    "Bytes: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x \n",  | 
47  | 0  |                    u_md.mem[0], u_md.mem[1], u_md.mem[2], u_md.mem[3],  | 
48  | 0  |                    u_md.mem[4], u_md.mem[5], u_md.mem[6], u_md.mem[7]);  | 
49  | 0  |     }  | 
50  | 0  |     return FPU_ENDIAN_UNKNOWN;  | 
51  | 0  | #endif  | 
52  | 0  | }  |