fix portability issue with strerror_r()
If _GNU_SOURCE is defined on linux, then strerror_r() is an alternate, non-POSIX version. Undefine _GNU_SOURCE when including <string.h> in ConfigManager.cpp to get the POSIX version of strerror_r(), and initialize the error string buffer to "unknown error" so that the code does not crash whichever version of the library function is being used, or strerror_r() fails for some reason.
This commit is contained in:
parent
05555a23a8
commit
01dd7cef45
|
@ -1,3 +1,8 @@
|
|||
// necessary to get portable strerror_r
|
||||
#undef _GNU_SOURCE
|
||||
#include <string.h>
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
#include "ConfigManager.h"
|
||||
extern "C" {
|
||||
#include "../common/iniparser.h"
|
||||
|
@ -759,8 +764,8 @@ void SaveConfigFile()
|
|||
{
|
||||
FILE *f = fopen(configFile, "w");
|
||||
if (f == NULL) {
|
||||
char err_buf[4096];
|
||||
char* err_msg = strerror_r(errno, err_buf, 4096);
|
||||
char err_msg[4096] = "unknown error";
|
||||
strerror_r(errno, err_msg, 4096);
|
||||
fprintf(stderr, "Configuration file '%s' could not be written to: %s\n", configFile, err_msg);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue