File xview-strerror.patch of Package xview

quick-n-dirty port from sys_errlist to strerror
== to be applied after xview-debian.patch ==

--- a/lib/libxview/base/xv_error.c	2021-06-15 17:29:47.911178345 +0200
+++ b/lib/libxview/base/xv_error.c	2021-06-15 17:59:42.347367541 +0200
@@ -11,6 +11,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <xview/pkg_public.h>
 #include <X11/Xlib.h>
 #include <xview_private/i18n_impl.h>
@@ -117,11 +118,7 @@
     switch (layer) {
       case ERROR_SYSTEM:
 	layer_name = XV_MSG("System");
-	if ((int) errno < sys_nerr)
-	    sprintf(layer_msg, "%s", sys_errlist[(int) errno]);
-	else
-	    sprintf(layer_msg, XV_MSG("unix error %d"), 
-		(int) errno);
+	sprintf(layer_msg, "%s", strerror((int) errno));
 	break;
       case ERROR_SERVER:
 	layer_name = XV_MSG("Server");
--- a/lib/libxview/textsw/es_file.c	2021-06-15 17:29:47.971178616 +0200
+++ b/lib/libxview/textsw/es_file.c	2021-06-15 18:04:55.976854113 +0200
@@ -97,6 +97,7 @@
 #include <sys/stat.h>
 #include <sys/file.h>
 #include <stdio.h>
+#include <string.h>
 #ifdef __linux__
 #include <unistd.h>
 #endif
@@ -290,7 +291,7 @@
 	    (void) strcat(error_buf, XV_MSG("alloc failure"));
 	    break;
 	  default:
-	    if (errno <= 0 || errno >= sys_nerr)
+	    if (errno <= 0)
 		goto Default;
 	    (void) sprintf(first_free_in_buf, 
 #ifdef OW_I18N
@@ -298,7 +299,7 @@
 #else
 			XV_MSG("file '%s': %s"),
 #endif
-			   file_name, sys_errlist[errno]);
+			   file_name, strerror(errno));
 	    break;
 	}
 	break;
--- a/lib/libxview/textsw/txt_file.c	2021-06-15 17:29:48.064166782 +0200
+++ b/lib/libxview/textsw/txt_file.c	2021-06-15 18:10:37.459618422 +0200
@@ -1109,7 +1109,7 @@
 	    XV_MSG("Unable to Include File."));
 	notice_msg2 = XV_MSG("An INTERNAL ERROR has occurred.");
     }
-    sys_msg = (errno > 0 && errno < sys_nerr) ? sys_errlist[errno] : NULL;
+    sys_msg = (errno > 0) ? strerror(errno) : NULL;
 
     frame = (Frame)FRAME_FROM_FOLIO_OR_VIEW(view);
     text_notice = (Xv_Notice)xv_get(frame, 
@@ -1211,7 +1211,7 @@
 	    XV_MSG("Unable to Include File."));
 	notice_msg2 = XV_MSG("An INTERNAL ERROR has occurred.");
     }
-    sys_msg = (errno > 0 && errno < sys_nerr) ? sys_errlist[errno] : NULL;
+    sys_msg = (errno > 0) ? strerror(errno) : NULL;
 
     frame = FRAME_FROM_FOLIO_OR_VIEW(view);
     text_notice = (Xv_Notice)xv_get(frame, 
@@ -2289,7 +2289,7 @@
 		   (might_not_be_dir ? 
 		   XV_MSG("Unable to access file") : 
 		   XV_MSG("Unable to cd to directory")));
-    sys_msg = (errno > 0 && errno < sys_nerr) ? sys_errlist[errno] : NULL;
+    sys_msg = (errno > 0) ? strerror(errno) : NULL;
 
     frame = FRAME_FROM_FOLIO_OR_VIEW(textsw);
     text_notice = (Xv_Notice)xv_get(frame, 
@@ -2394,7 +2394,7 @@
 		   XV_MSG("Cannot cd to directory")),
 		   full_pathname);
     free(full_pathname);
-    sys_msg = (errno > 0 && errno < sys_nerr) ? sys_errlist[errno] : NULL;
+    sys_msg = (errno > 0) ? strerror(errno) : NULL;
     if (sys_msg)
 	strcat(err_msgs, sys_msg);
     return (result);

openSUSE Build Service is sponsored by