Commit 19ce2474 authored by Peter Pentchev's avatar Peter Pentchev

Add a HAVE_STRERROR definition to the config files and roll out our

own strerror(3) implementation if needed.
parent 28fedf43
......@@ -6,6 +6,8 @@ Change log for hexer, the multi-view binary editor
make them actually acceptable to today's Vim
- add a config.posix file to reflect a modern POSIX-like system
- bring config.linux up to date
- add a HAVE_STRERROR definition to the config files and roll out
our own strerror() function if needed
0.1.4c
- the last version released by Sascha Demetrio <demetrio@cs.uni-sb.de>
......@@ -69,6 +69,9 @@ char *alloca();
#define ERESTARTSYS EINTR
#endif
extern char *
strerror();
extern char *
exh_skip_expression();
......@@ -1246,10 +1249,6 @@ exhcmd_exit(hedit, args)
int cant_write_f = 0;
long k;
char *errormsg;
extern int sys_nerr;
#ifndef BSD
extern char *sys_errlist[];
#endif
extern int errno;
char *skip, *p;
......@@ -1264,11 +1263,8 @@ exhcmd_exit(hedit, args)
} else {
k = b_write_buffer_to_file(i->hedit->buffer, i->path);
if (k < 0) {
if (!errno || errno >= sys_nerr)
errormsg = "unknown error";
else
errormsg = sys_errlist[errno];
he_message(0, "@Aberror writing file@~ `%s': %s", i->path, errormsg);
he_message(0, "@Aberror writing file@~ `%s': %s", i->path,
strerror(errno));
cant_write_f = 1;
} else {
he_message(0, "wrote `%s' - 0x%lx (%li) bytes", i->path, k, k);
......
......@@ -10,6 +10,7 @@
#define HAVE_FLOAT_H 0
#define HAVE_ALLOCA 0
#define NEED_ALLOCA_H 0
#define HAVE_STRERROR 0
#define USE_STDARG 0
......@@ -10,6 +10,7 @@
#define HAVE_FLOAT_H 1
#define HAVE_ALLOCA 0
#define NEED_ALLOCA_H 0
#define HAVE_STRERROR 1
#define USE_STDARG 1
......@@ -10,6 +10,7 @@
#define HAVE_FLOAT_H 1
#define HAVE_ALLOCA 1
#define NEED_ALLOCA_H 1
#define HAVE_STRERROR 1
#define USE_STDARG 1
......@@ -10,6 +10,7 @@
#define HAVE_FLOAT_H 1
#define HAVE_ALLOCA 0
#define NEED_ALLOCA_H 0
#define HAVE_STRERROR 1
#define USE_STDARG 1
......@@ -10,6 +10,7 @@
#define HAVE_FLOAT_H 0
#define HAVE_ALLOCA 1
#define NEED_ALLOCA_H 1
#define HAVE_STRERROR 1
#define USE_STDARG 0
......@@ -67,11 +67,8 @@
extern int errno;
#ifndef BSD
extern char *sys_errlist[];
#endif
extern int sys_nerr;
extern mkstemp();
extern char *strerror();
const struct buffer_s NO_BUFFER = { 0, 0, 0, 0, 0, 0 };
......@@ -221,10 +218,7 @@ he_open_buffer(name, path)
no_file_f = 1;
break;
default:
if (errno >= sys_nerr) /* unknown error */
he_message(1, "`%s': @Abunknown error@~", path);
else
he_message(1, "`%s': @Ab%s@~", path, sys_errlist[errno]);
he_message(1, "`%s': @Ab%s@~", path, strerror(errno));
return -1;
}
if (!no_file_f ? access(path, W_OK) : 0)
......@@ -233,10 +227,7 @@ he_open_buffer(name, path)
read_only = 1;
break;
default:
if (errno >= sys_nerr) /* unknown error */
he_message(1, "`%s': @Abunknown error@~", path);
else
he_message(1, "`%s': @Ab%s@~", path, sys_errlist[errno]);
he_message(1, "`%s': @Ab%s@~", path, strerror(errno));
return -1;
}
}
......@@ -249,10 +240,7 @@ he_open_buffer(name, path)
buffer->hedit->buffer_name = strdup(name);
if (path && !no_file_f) {
if (!(fp = fopen(path, "r"))) {
if (errno >= sys_nerr) /* unknown error */
he_message(1, "`%s': @Abunknown error@~", path);
else
he_message(1, "`%s': @Ab%s@~", path, sys_errlist[errno]);
he_message(1, "`%s': @Ab%s@~", path, strerror(errno));
free((char *)buffer->hedit->buffer_name);
free((char *)buffer->hedit);
free((char *)buffer);
......@@ -267,10 +255,7 @@ he_open_buffer(name, path)
if (path) {
buffer->path = strdup(path);
if (!getcwd(cwd, PATH_MAX)) {
if (errno >= sys_nerr)
he_message(0, "@Abcan't get cwd: unknown error");
else
he_message(0, "@Abcan't get cwd: %s@~", sys_errlist[errno]);
he_message(0, "@Abcan't get cwd: %s@~", strerror(errno));
buffer->fullpath = strdup(path);
} else {
buffer->fullpath =
......
......@@ -45,6 +45,8 @@
#include "config.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "tio.h"
......@@ -215,6 +217,30 @@ util_strsort(list)
}
/* util_strsort */
#if !HAVE_STRERROR
#ifndef BSD
extern const char * const sys_errlist[];
#endif
extern const int sys_nerr;
/*
* We are using an error buffer instead of just returning the result from
* strerror(3) to avoid constness warnings. Yes, this makes this function
* not-thread-safe. Well, strerror(3) isn't.
*/
static char errbuf[512];
char *
strerror(int errnum)
{
if (errnum >= sys_nerr)
strcpy(errbuf, "Unknown error");
else
snprintf(errbuf, sizeof(errbuf), "%s", sys_errlist[errnum]);
return (errbuf);
}
#endif /* HAVE_STRERROR */
/* end of util.c */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment