Subject: errno Patch for GNU/Linux (glibc)

From: Bernhard Reiter <[email-masked]>
Date: Mon, 23 Feb 2015 10:11:39 +0100

Hello,

got notice that on modern glibc systems errno.h must be used otherwise
there will be compliation errors like:

gcc -o statist statist.o menue.o procs.o funcs.o data.o plot.o 
memory_handling.o -lm
/usr/bin/ld: errno: TLS definition in /lib/i386-linux-gnu/libc.so.6 
section .tbss mismatches non-TLS reference in statist.o
/lib/i386-linux-gnu/libc.so.6: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [statist] Fehler 1

The attached patch tries to resolve the situation.

Best,
Bernhard

-- 
www.intevation.de/~bernhard (CEO)    www.fsfe.org (Founding GA Member)
Intevation GmbH, Osnabrück, Germany; Amtsgericht Osnabrück, HRB 18998
Owned and run by Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner
Modern GNU Libc implementations require that errno is declared by errno.h.
This patch attempts to fix the situation.
 2015-02-23 [email-masked]

diff -ru statist-1.0.1/src/iodefs.c statist-1.0.1-new/src/iodefs.c
--- statist-1.0.1/src/iodefs.c	2015-02-23 09:59:25.584967451 +0100
+++ statist-1.0.1-new/src/iodefs.c	2015-02-23 09:44:23.768304822 +0100
@@ -9,11 +9,10 @@
 **  $Id: iodefs.c,v 1.2 2000/07/20 14:39:50 breiter Rel $
 ***************************************************************/
 
+#include <errno.h>
 #include<stdio.h>
 #include<string.h>
 
-extern int errno;
-
 #define FOPEN(name, mode, fp)                                     \
   if ((fp = fopen(name, mode))==NULL) {                           \
     fprintf(stderr, 								\
diff -ru statist-1.0.1/src/statist.c statist-1.0.1-new/src/statist.c
--- statist-1.0.1/src/statist.c	2015-02-23 09:59:25.588967401 +0100
+++ statist-1.0.1-new/src/statist.c	2015-02-23 09:53:20.517556969 +0100
@@ -293,13 +293,13 @@

-void out_err(int errno, char *modulname, int lno, char *fmt, ...) {
+void out_err(int errn, char *modulname, int lno, char *fmt, ...) {
   va_list argptr;
   int error;
   char where[128];
 
   va_start(argptr, fmt);
-  switch (errno) {
+  switch (errn) {
     case WAR: strcpy(line, 
     		_("> statist-warning ",
 		  "> statist-Warnung ") );
@@ -322,7 +322,7 @@
       break;
   }
 
-  error = errno;
+  error = errn;
   if (lno != 0) {
     sprintf(where, 
     		_("(Modul %15s, line %i):\n  ",
diff -ru statist-1.0.1/src/statist.h statist-1.0.1-new/src/statist.h
--- statist-1.0.1/src/statist.h	2015-02-23 09:59:25.588967401 +0100
+++ statist-1.0.1-new/src/statist.h	2015-02-23 09:51:37.542851537 +0100
@@ -13,6 +13,7 @@
 ***************************************************************/
 
 #include <stdio.h>
+#include <errno.h>
 
 #include "gettext.h"
 #include "memory_handling.h"
@@ -109,9 +110,9 @@
 
 #ifdef SUNOS
 extern char *sys_errlist[];
-#define STRERROR(errno) sys_errlist[errno]
+#define STRERROR(errn) sys_errlist[errn]
 #else
-#define STRERROR(errno) strerror(errno)
+#define STRERROR(errn) strerror(errn)
 #endif
 
 #ifdef DEBUG
@@ -240,7 +241,6 @@
 } SORTREC;

-extern int errno;
 extern void mywait();
 extern BOOLEAN myexist(char *name);
 #ifdef STATIST_X
@@ -252,7 +252,7 @@
 #endif
 extern void out_d(char *fmt, ...);
 extern void out_r(char *fmt, ...);
-extern void out_err(int errno, char *modul, int lno, char *fmt, ...);
+extern void out_err(int errn, char *modul, int lno, char *fmt, ...);
 extern void print_histo(REAL x[], int y[], int n);
 extern void finish();