diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-19 23:27:12 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-19 23:27:12 +0200 |
commit | 26fbe7f1e68bb0c96da32491efcf3696fe6c299b (patch) | |
tree | c4d95289187a64e9c7517bf73d8208026c3d2fb3 /gl/xsize.h | |
parent | 5f79e3e9f62ca5487d9881973149136ba1d19d3e (diff) | |
download | monitoring-plugins-26fbe7f1e68bb0c96da32491efcf3696fe6c299b.tar.gz |
Sync with the latest Gnulib code (6f2d632)
Diffstat (limited to 'gl/xsize.h')
-rw-r--r-- | gl/xsize.h | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -1,6 +1,6 @@ | |||
1 | /* xsize.h -- Checked size_t computations. | 1 | /* xsize.h -- Checked size_t computations. |
2 | 2 | ||
3 | Copyright (C) 2003, 2008, 2009, 2010 Free Software Foundation, Inc. | 3 | Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -13,8 +13,7 @@ | |||
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software Foundation, | 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | 17 | ||
19 | #ifndef _XSIZE_H | 18 | #ifndef _XSIZE_H |
20 | #define _XSIZE_H | 19 | #define _XSIZE_H |
@@ -28,6 +27,11 @@ | |||
28 | # include <stdint.h> | 27 | # include <stdint.h> |
29 | #endif | 28 | #endif |
30 | 29 | ||
30 | _GL_INLINE_HEADER_BEGIN | ||
31 | #ifndef XSIZE_INLINE | ||
32 | # define XSIZE_INLINE _GL_INLINE | ||
33 | #endif | ||
34 | |||
31 | /* The size of memory objects is often computed through expressions of | 35 | /* The size of memory objects is often computed through expressions of |
32 | type size_t. Example: | 36 | type size_t. Example: |
33 | void* p = malloc (header_size + n * element_size). | 37 | void* p = malloc (header_size + n * element_size). |
@@ -49,7 +53,7 @@ | |||
49 | ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) | 53 | ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) |
50 | 54 | ||
51 | /* Sum of two sizes, with overflow check. */ | 55 | /* Sum of two sizes, with overflow check. */ |
52 | static inline size_t | 56 | XSIZE_INLINE size_t |
53 | #if __GNUC__ >= 3 | 57 | #if __GNUC__ >= 3 |
54 | __attribute__ ((__pure__)) | 58 | __attribute__ ((__pure__)) |
55 | #endif | 59 | #endif |
@@ -60,7 +64,7 @@ xsum (size_t size1, size_t size2) | |||
60 | } | 64 | } |
61 | 65 | ||
62 | /* Sum of three sizes, with overflow check. */ | 66 | /* Sum of three sizes, with overflow check. */ |
63 | static inline size_t | 67 | XSIZE_INLINE size_t |
64 | #if __GNUC__ >= 3 | 68 | #if __GNUC__ >= 3 |
65 | __attribute__ ((__pure__)) | 69 | __attribute__ ((__pure__)) |
66 | #endif | 70 | #endif |
@@ -70,7 +74,7 @@ xsum3 (size_t size1, size_t size2, size_t size3) | |||
70 | } | 74 | } |
71 | 75 | ||
72 | /* Sum of four sizes, with overflow check. */ | 76 | /* Sum of four sizes, with overflow check. */ |
73 | static inline size_t | 77 | XSIZE_INLINE size_t |
74 | #if __GNUC__ >= 3 | 78 | #if __GNUC__ >= 3 |
75 | __attribute__ ((__pure__)) | 79 | __attribute__ ((__pure__)) |
76 | #endif | 80 | #endif |
@@ -80,7 +84,7 @@ xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) | |||
80 | } | 84 | } |
81 | 85 | ||
82 | /* Maximum of two sizes, with overflow check. */ | 86 | /* Maximum of two sizes, with overflow check. */ |
83 | static inline size_t | 87 | XSIZE_INLINE size_t |
84 | #if __GNUC__ >= 3 | 88 | #if __GNUC__ >= 3 |
85 | __attribute__ ((__pure__)) | 89 | __attribute__ ((__pure__)) |
86 | #endif | 90 | #endif |
@@ -93,7 +97,7 @@ xmax (size_t size1, size_t size2) | |||
93 | 97 | ||
94 | /* Multiplication of a count with an element size, with overflow check. | 98 | /* Multiplication of a count with an element size, with overflow check. |
95 | The count must be >= 0 and the element size must be > 0. | 99 | The count must be >= 0 and the element size must be > 0. |
96 | This is a macro, not an inline function, so that it works correctly even | 100 | This is a macro, not a function, so that it works correctly even |
97 | when N is of a wider type and N > SIZE_MAX. */ | 101 | when N is of a wider type and N > SIZE_MAX. */ |
98 | #define xtimes(N, ELSIZE) \ | 102 | #define xtimes(N, ELSIZE) \ |
99 | ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) | 103 | ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) |
@@ -105,4 +109,6 @@ xmax (size_t size1, size_t size2) | |||
105 | #define size_in_bounds_p(SIZE) \ | 109 | #define size_in_bounds_p(SIZE) \ |
106 | ((SIZE) != SIZE_MAX) | 110 | ((SIZE) != SIZE_MAX) |
107 | 111 | ||
112 | _GL_INLINE_HEADER_END | ||
113 | |||
108 | #endif /* _XSIZE_H */ | 114 | #endif /* _XSIZE_H */ |