aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/intrinsics/env.c')
-rw-r--r--libgfortran/intrinsics/env.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/libgfortran/intrinsics/env.c b/libgfortran/intrinsics/env.c
index 9f45073..ffdc54a 100644
--- a/libgfortran/intrinsics/env.c
+++ b/libgfortran/intrinsics/env.c
@@ -52,27 +52,19 @@ PREFIX(getenv) (char * name, char * value, gfc_charlen_type name_len,
else
memset (value, ' ', value_len); /* Blank the string. */
- /* Trim trailing spaces from name. */
- while (name_len > 0 && name[name_len - 1] == ' ')
- name_len--;
-
/* Make a null terminated copy of the string. */
- name_nt = gfc_alloca (name_len + 1);
- memcpy (name_nt, name, name_len);
- name_nt[name_len] = '\0';
+ name_nt = fc_strdup (name, name_len);
res = getenv(name_nt);
+ free (name_nt);
+
/* If res is NULL, it means that the environment variable didn't
exist, so just return. */
if (res == NULL)
return;
- res_len = strlen(res);
- if (value_len < res_len)
- memcpy (value, res, value_len);
- else
- memcpy (value, res, res_len);
+ cf_strcpy (value, value_len, res);
}
@@ -127,18 +119,14 @@ get_environment_variable_i4 (char *name, char *value, GFC_INTEGER_4 *length,
}
if ((!trim_name) || *trim_name)
- {
- /* Trim trailing spaces from name. */
- while (name_len > 0 && name[name_len - 1] == ' ')
- name_len--;
- }
- /* Make a null terminated copy of the name. */
- name_nt = gfc_alloca (name_len + 1);
- memcpy (name_nt, name, name_len);
- name_nt[name_len] = '\0';
+ name_nt = fc_strdup (name, name_len);
+ else
+ name_nt = fc_strdup_notrim (name, name_len);
res = getenv(name_nt);
+ free (name_nt);
+
if (res == NULL)
stat = GFC_NAME_DOES_NOT_EXIST;
else