Thread-safe alternative to strerror.

Add MR_strerror as a thread-safe alternative to strerror.
The current implementation wraps strerror_r(), strerror_s()
or sys_errlist as appropriate for the platform.  Bug #340.

configure.ac:
runtime/mercury_conf.h.in:
	Check for strerror_r, strerror_s.

	Delete irrelevant code in the sockets test for the external debugger.

runtime/mercury_runtime_util.c:
runtime/mercury_runtime_util.h:
	Add MR_strerror and use it.

library/io.m:
	Use MR_strerror.  In particular, mercury_output_error was not
	thread-safe.

	Pass errno to mercury_output_error explicitly for clarity.

	Delete req_lock parameter in ML_maybe_make_err_msg macro which is not
	needed any more.

compiler/prog_event.m:
runtime/mercury_deep_profiling.c:
runtime/mercury_misc.c:
runtime/mercury_term_size.c:
runtime/mercury_trace_base.c:
trace/mercury_trace_cmd_developer.c:
trace/mercury_trace_cmd_exp.c:
trace/mercury_trace_cmd_misc.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
	Use MR_strerror.

compiler/notes/coding_standards.html:
	Update coding standard.

extras/net/sockets.m:
extras/net/tcp.m:
	Use MR_strerror.

NEWS:
	Announce change.
This commit is contained in:
Peter Wang
2014-06-24 12:38:02 +10:00
parent ea922846e5
commit 31d3897e22
20 changed files with 216 additions and 134 deletions

View File

@@ -399,6 +399,7 @@ MR_write_complexity_proc(MR_ComplexityProc *proc)
int num_slots;
MR_ComplexityPastSlots *past_slots;
char *cmd_buf;
char errbuf[MR_STRERROR_BUF_SIZE];
full_proc_name_len = strlen(proc->MR_clp_full_proc_name);
full_proc_name = MR_malloc(100 + full_proc_name_len);
@@ -422,7 +423,8 @@ MR_write_complexity_proc(MR_ComplexityProc *proc)
if (! MR_have_printed_complexity_dirs_error) {
fprintf(stderr, "%s: cannot create %s and %s: %s\n",
MR_progname, MR_COMPLEXITY_ARGS_DIR,
MR_COMPLEXITY_DATA_DIR, strerror(errno));
MR_COMPLEXITY_DATA_DIR,
MR_strerror(errno, errbuf, sizeof(errbuf)));
/* there is no point in aborting */
MR_have_printed_complexity_dirs_error = MR_TRUE;
return;
@@ -440,7 +442,8 @@ MR_write_complexity_proc(MR_ComplexityProc *proc)
fp = fopen(args_filename, "w");
if (fp == NULL) {
fprintf(stderr, "%s: cannot open %s: %s\n",
MR_progname, args_filename, strerror(errno));
MR_progname, args_filename,
MR_strerror(errno, errbuf, sizeof(errbuf)));
/* there is no point in aborting */
return;
}
@@ -458,7 +461,8 @@ MR_write_complexity_proc(MR_ComplexityProc *proc)
fp = fopen(tmp_filename, "w");
if (fp == NULL) {
fprintf(stderr, "%s: cannot open %s: %s\n",
MR_progname, tmp_filename, strerror(errno));
MR_progname, tmp_filename,
MR_strerror(errno, errbuf, sizeof(errbuf)));
/* there is no point in aborting */
return;
}
@@ -484,7 +488,8 @@ MR_write_complexity_proc(MR_ComplexityProc *proc)
fp = fopen(data_filename, data_filemode);
if (fp == NULL) {
fprintf(stderr, "%s: cannot open %s: %s\n",
MR_progname, data_filename, strerror(errno));
MR_progname, data_filename,
MR_strerror(errno, errbuf, sizeof(errbuf)));
/* there is no point in aborting */
return;
}