summaryrefslogtreecommitdiff
path: root/extra/perror.c
diff options
context:
space:
mode:
authorunknown <reggie@bob.(none)>2005-01-31 23:02:32 -0600
committerunknown <reggie@bob.(none)>2005-01-31 23:02:32 -0600
commit199375cbc94eda3d60b9c038037e19a7e9cdf8f4 (patch)
treea237af2b9e58dd972c851b7b23ce21c2e0505a0c /extra/perror.c
parent4b88e07159d297dfa3a3e89f988e65e86610a9bd (diff)
downloadmariadb-git-199375cbc94eda3d60b9c038037e19a7e9cdf8f4.tar.gz
Bug #7390 perror.exe doesn't work
perror.c: Copy output of strerr to temp buffer to prevent system overwrite on Windows extra/perror.c: Copy output of strerr to temp buffer to prevent system overwrite on Windows
Diffstat (limited to 'extra/perror.c')
-rw-r--r--extra/perror.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/extra/perror.c b/extra/perror.c
index 1bd4b203120..fc10d8eaecc 100644
--- a/extra/perror.c
+++ b/extra/perror.c
@@ -184,6 +184,7 @@ int main(int argc,char *argv[])
{
int error,code,found;
const char *msg;
+ char *unknown_error = 0;
MY_INIT(argv[0]);
if (get_options(&argc,&argv))
@@ -212,7 +213,12 @@ int main(int argc,char *argv[])
string 'Unknown Error'. To avoid printing it we try to find the
error string by asking for an impossible big error message.
*/
- const char *unknown_error= strerror(10000);
+ msg = strerror(10000);
+
+ /* allocate a buffer for unknown_error since strerror always returns the same pointer
+ on some platforms such as Windows */
+ unknown_error = malloc( strlen(msg)+1 );
+ strcpy( unknown_error, msg );
for ( ; argc-- > 0 ; argv++)
{
@@ -262,6 +268,11 @@ int main(int argc,char *argv[])
}
}
}
+
+ /* if we allocated a buffer for unknown_error, free it now */
+ if (unknown_error)
+ free(unknown_error);
+
exit(error);
return error;
}