libc: Introduce __errordecl()

Define __errordecl and replace __attribute__((__error__("foo")))
with __errordecl. Make sure __errordecl is a no-op on clang, as it
generates a compile time warning.

Change-Id: Ifa1a2d3afd6881de9d479fc2adac6737871a2949
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index de2e3e3..67fd597 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -50,11 +50,8 @@
 extern int  creat(const char*  path, mode_t  mode);
 
 #if defined(__BIONIC_FORTIFY)
-
-extern void __creat_error()
-    __attribute__((__error__ ("called with O_CREAT, but missing mode")));
-extern void __too_many_args_error()
-    __attribute__((__error__ ("too many arguments")));
+__errordecl(__creat_error, "called with O_CREAT, but missing mode");
+__errordecl(__too_many_args_error, "too many arguments");
 extern int __open_real(const char *pathname, int flags, ...)
     __asm__(__USER_LABEL_PREFIX__ "open");
 extern int __open_2(const char *, int);
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index aca6d9f..154a86c 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -486,10 +486,8 @@
 
 extern char *__fgets_real(char *, int, FILE *)
     __asm__(__USER_LABEL_PREFIX__ "fgets");
-extern void __fgets_too_big_error()
-    __attribute__((__error__("fgets called with size bigger than buffer")));
-extern void __fgets_too_small_error()
-    __attribute__((__error__("fgets called with size less than zero")));
+__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
+__errordecl(__fgets_too_small_error, "fgets called with size less than zero");
 extern char *__fgets_chk(char *, int, FILE *, size_t);
 
 __BIONIC_FORTIFY_INLINE
diff --git a/libc/include/string.h b/libc/include/string.h
index 1691b16..3c9fc21 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -87,10 +87,8 @@
 
 #if defined(__BIONIC_FORTIFY)
 
-extern void __memcpy_dest_size_error()
-    __attribute__((__error__("memcpy called with size bigger than destination")));
-extern void __memcpy_src_size_error()
-    __attribute__((__error__("memcpy called with size bigger than source")));
+__errordecl(__memcpy_dest_size_error, "memcpy called with size bigger than destination");
+__errordecl(__memcpy_src_size_error, "memcpy called with size bigger than source");
 
 __BIONIC_FORTIFY_INLINE
 void *memcpy (void* __restrict dest, const void* __restrict src, size_t copy_amount) {
@@ -120,8 +118,7 @@
     return __builtin___strcpy_chk(dest, src, __bos(dest));
 }
 
-extern void __strncpy_error()
-    __attribute__((__error__("strncpy called with size bigger than buffer")));
+__errordecl(__strncpy_error, "strncpy called with size bigger than buffer");
 
 __BIONIC_FORTIFY_INLINE
 char *strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
@@ -149,8 +146,7 @@
 
 extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t)
     __asm__(__USER_LABEL_PREFIX__ "strlcpy");
-extern void __strlcpy_error()
-    __attribute__((__error__("strlcpy called with size bigger than buffer")));
+__errordecl(__strlcpy_error, "strlcpy called with size bigger than buffer");
 extern size_t __strlcpy_chk(char *, const char *, size_t, size_t);
 
 __BIONIC_FORTIFY_INLINE
@@ -179,8 +175,7 @@
 
 extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t)
     __asm__(__USER_LABEL_PREFIX__ "strlcat");
-extern void __strlcat_error()
-    __attribute__((__error__("strlcat called with size bigger than buffer")));
+__errordecl(__strlcat_error, "strlcat called with size bigger than buffer");
 extern size_t __strlcat_chk(char* __restrict, const char* __restrict, size_t, size_t);
 
 
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index c710356..78513e3 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -330,6 +330,12 @@
 #define __wur
 #endif
 
+#if __GNUC_PREREQ__(4, 3)
+#define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg)))
+#else
+#define __errordecl(name, msg) extern void name(void)
+#endif
+
 /*
  * Macros for manipulating "link sets".  Link sets are arrays of pointers
  * to objects, which are gathered up by the linker.
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 4e8beb6..da49e1a 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -134,8 +134,7 @@
 extern mode_t __umask_chk(mode_t);
 extern mode_t __umask_real(mode_t)
     __asm__(__USER_LABEL_PREFIX__ "umask");
-extern void __umask_error()
-    __attribute__((__error__("umask called with invalid mode")));
+__errordecl(__umask_error, "umask called with invalid mode");
 
 __BIONIC_FORTIFY_INLINE
 mode_t umask(mode_t mode) {