]>
Commit | Line | Data |
---|---|---|
832b75ed GG |
1 | /* |
2 | * int64.h | |
3 | * | |
4 | * Home page of code is: http://smartmontools.sourceforge.net | |
5 | * | |
6 | * Copyright (C) 2002-6 Bruce Allen <smartmontools-support@lists.sourceforge.net> | |
7 | * Copyright (C) 2004-6 Christian Franke | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2, or (at your option) | |
12 | * any later version. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * (for example COPYING); if not, write to the Free | |
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
17 | * | |
18 | */ | |
19 | ||
20 | #ifndef INT64_H_ | |
21 | #define INT64_H_ | |
22 | ||
23 | #define INT64_H_CVSID "$Id: int64.h,v 1.13 2006/04/12 14:54:28 ballen4705 Exp $\n" | |
24 | ||
25 | // 64 bit integer typedefs | |
26 | ||
27 | #ifdef HAVE_INTTYPES_H | |
28 | #include <inttypes.h> | |
29 | #else | |
30 | #ifdef HAVE_STDINT_H | |
31 | #include <stdint.h> | |
32 | #else | |
33 | #ifdef HAVE_SYS_INTTYPES_H | |
34 | #include <sys/inttypes.h> | |
35 | #else | |
36 | #ifdef HAVE_SYS_INT_TYPES_H | |
37 | #include <sys/int_types.h> | |
38 | #else | |
39 | #if defined(_WIN32) && defined(_MSC_VER) | |
40 | // for MSVC 6.0 | |
41 | typedef __int64 int64_t; | |
42 | typedef unsigned __int64 uint64_t; | |
43 | #else | |
44 | // for systems with above includes missing (like ix86-pc-linux-gnulibc1), | |
45 | // default to GCC if types are undefined in types.h | |
46 | #include <sys/types.h> | |
47 | #ifndef HAVE_INT64_T | |
48 | typedef long long int64_t; | |
49 | #endif | |
50 | #ifndef HAVE_UINT64_T | |
51 | typedef unsigned long long uint64_t; | |
52 | #endif | |
53 | #endif // _WIN32 && _MSC_VER | |
54 | #endif // HAVE_SYS_INT_TYPES_H | |
55 | #endif // HAVE_SYS_INTTYPES_H | |
56 | #endif // HAVE_STDINT_H | |
57 | #endif // HAVE_INTTYPES_H | |
58 | ||
59 | // 64 bit integer format strings | |
60 | ||
61 | #if defined(_WIN32) && defined(_MSC_VER) | |
62 | // for MSVC 6.0 | |
63 | #define PRId64 "I64d" | |
64 | #define PRIu64 "I64u" | |
65 | #define PRIx64 "I64x" | |
66 | #endif // _WIN32 && _MSC_VER | |
67 | ||
68 | // If macros not defined in inttypes.h, fix here. Default is GCC | |
69 | // style | |
70 | #ifndef PRId64 | |
71 | #define PRId64 "lld" | |
72 | #endif // ndef PRId64 | |
73 | ||
74 | #ifndef PRIu64 | |
75 | #define PRIu64 "llu" | |
76 | #endif // ndef PRIu64 | |
77 | ||
78 | #ifndef PRIx64 | |
79 | #define PRIx64 "llx" | |
80 | #endif // ndef PRIx64 | |
81 | ||
82 | ||
83 | #if defined(_WIN32) && defined(_MSC_VER) | |
84 | // for MSVC 6.0: "unsigned __int64 -> double" conversion not implemented (why?-) | |
85 | __inline double uint64_to_double(uint64_t ull) { | |
86 | return ((int64_t)ull >= 0 ? (double)(int64_t)ull : | |
87 | ((double)(int64_t)(ull - 9223372036854775808UI64)) + 9223372036854775808.0); | |
88 | } | |
89 | #else | |
90 | #define uint64_to_double(ull) ((double)(ull)) | |
91 | #endif // _WIN32 && _MSC_VER | |
92 | ||
93 | ||
94 | #endif // INT64_H |