summaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2011-01-22 15:30:59 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2011-01-22 15:30:59 +0000
commita562641c0dfbee57550a4b4d99f82acd3da99503 (patch)
tree03bbe2fa5c59a96c823f83b08089d54bbe0fe85b /libgfortran/intrinsics
parent3edafd46128542d863667585f9a89284fdbd1af2 (diff)
downloadgcc-a562641c0dfbee57550a4b4d99f82acd3da99503.tar.gz
2011-01-22 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 169126 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@169127 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r--libgfortran/intrinsics/gerror.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/libgfortran/intrinsics/gerror.c b/libgfortran/intrinsics/gerror.c
index ccb5c3efd41..6feadc9b7c7 100644
--- a/libgfortran/intrinsics/gerror.c
+++ b/libgfortran/intrinsics/gerror.c
@@ -43,16 +43,17 @@ PREFIX(gerror) (char * msg, gfc_charlen_type msg_len)
int p_len;
char *p;
- memset (msg, ' ', msg_len); /* Blank the string. */
-
- p = strerror (errno);
- if (p == NULL)
- return;
-
+ p = gf_strerror (errno, msg, msg_len);
p_len = strlen (p);
- if (msg_len < p_len)
- memcpy (msg, p, msg_len);
- else
- memcpy (msg, p, p_len);
+ /* The returned pointer p might or might not be the same as the msg
+ argument. */
+ if (p != msg)
+ {
+ if (msg_len < p_len)
+ p_len = msg_len;
+ memcpy (msg, p, p_len);
+ }
+ if (msg_len > p_len)
+ memset (&msg[p_len], ' ', msg_len - p_len);
}
#endif