arrfab / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1673465-1.patch

147e83
commit c94a5688fb1228a862b2d4a3f1239cdc0e3349e5
147e83
Author: Florian Weimer <fweimer@redhat.com>
147e83
Date:   Thu Nov 2 12:14:01 2017 +0100
147e83
147e83
    <array_length.h>: New array_length and array_end macros
147e83
147e83
diff --git a/include/array_length.h b/include/array_length.h
147e83
new file mode 100644
147e83
index 0000000000000000..cb4a8b2a56bca3ad
147e83
--- /dev/null
147e83
+++ b/include/array_length.h
147e83
@@ -0,0 +1,36 @@
147e83
+/* The array_length and array_end macros.
147e83
+   Copyright (C) 2017 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#ifndef _ARRAY_LENGTH_H
147e83
+#define _ARRAY_LENGTH_H
147e83
+
147e83
+/* array_length (VAR) is the number of elements in the array VAR.  VAR
147e83
+   must evaluate to an array, not a pointer.  */
147e83
+#define array_length(var)                                               \
147e83
+  __extension__ ({                                                      \
147e83
+    _Static_assert (!__builtin_types_compatible_p                       \
147e83
+                    (__typeof (var), __typeof (&(var)[0])),             \
147e83
+                    "argument must be an array");                       \
147e83
+    sizeof (var) / sizeof ((var)[0]);                                   \
147e83
+  })
147e83
+
147e83
+/* array_end (VAR) is a pointer one past the end of the array VAR.
147e83
+   VAR must evaluate to an array, not a pointer.  */
147e83
+#define array_end(var) (&(var)[array_length (var)])
147e83
+
147e83
+#endif /* _ARRAY_LENGTH_H */