Bug #8470 bogus `errno' decalaration in include/my_sys.h
Submitted: 12 Feb 2005 11:43 Modified: 5 Apr 2005 8:07
Reporter: Paul Kranenburg Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.2 alpha OS:Solaris (Solaris 9)
Assigned to: CPU Architecture:Any

[12 Feb 2005 11:43] Paul Kranenburg
Description:
When building the client archive on Solaris 9, the header file `include/my_sys.h' emits the declaration `extern int errno' on line 205. Since the system header file <errno.h> has already been included at this point, which defines `errno' as a
pointer dereference, this leads to a bogus declaration.

By a stroke of good fortune, this does not produce bad code on this version of
the system, so I've marked this report non-critical. However, I suggest to fix
this before the luck runs out.

How to repeat:
Build 5.0.2 from source on a Solaris 9 system.

Suggested fix:
Always use <errno.h> to declare the `errno' variable on systems where this
header file is available.
[5 Apr 2005 8:07] Joerg Bruehe
This is already fixed in 5.0.3 (23 Mar 2005).

The main problem is that there may be users compiling MySQL from source even for (old) platforms that do not follow C standards, so a plain '#include <errno.h>' was considered dangerous for these users.

This is the change done:

--- 1.139/include/my_sys.h      Sun Feb 27 16:53:09 2005
+++ 1.140/include/my_sys.h      Thu Mar  3 12:35:35 2005
@@ -206,11 +206,13 @@
 #endif
 #endif /* MSDOS */
 
+#ifndef errno                          /* did we already get it? */
 #ifdef HAVE_ERRNO_AS_DEFINE
 #include <errno.h>                     /* errno is a define */
 #else
 extern int errno;                      /* declare errno */
 #endif
+#endif                                 /* #ifndef errno */
 extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
 extern char *home_dir;                 /* Home directory for user */
 extern char *my_progname;              /* program-name (printed in errors) */
[27 Aug 2009 17:51] Mark Callaghan
RedHat/CentOS are not fond of this fix and remove it with a patch. From
 mysql-errno.patch in mysql-5.0.82sp1-1.el5.centos.src.rpm

iff -Naur mysql-5.0.67.orig/include/my_sys.h mysql-5.0.67/include/my_sys.h
--- mysql-5.0.67.orig/include/my_sys.h  2008-08-04 08:19:12.000000000 -0400
+++ mysql-5.0.67/include/my_sys.h       2008-08-23 14:39:08.000000000 -0400
@@ -208,13 +208,8 @@
 #endif
 #endif /* MSDOS */
 
-#ifndef errno                          /* did we already get it? */
-#ifdef HAVE_ERRNO_AS_DEFINE
 #include <errno.h>                     /* errno is a define */
-#else
-extern int errno;                      /* declare errno */
-#endif
-#endif                                 /* #ifndef errno */
+
 extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
 extern char *home_dir;                 /* Home directory for user */
 extern const char *my_progname;                /* program-name (printed in errors) */