diff options
Diffstat (limited to 'libgfortran/intrinsics/chdir.c')
-rw-r--r-- | libgfortran/intrinsics/chdir.c | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/libgfortran/intrinsics/chdir.c b/libgfortran/intrinsics/chdir.c index c4933a3d5f..14e246d410 100644 --- a/libgfortran/intrinsics/chdir.c +++ b/libgfortran/intrinsics/chdir.c @@ -1,5 +1,5 @@ /* Implementation of the CHDIR intrinsic. - Copyright (C) 2005-2014 Free Software Foundation, Inc. + Copyright (C) 2005-2015 Free Software Foundation, Inc. Contributed by François-Xavier Coudert <coudert@clipper.ens.fr> This file is part of the GNU Fortran 95 runtime library (libgfortran). @@ -26,6 +26,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "libgfortran.h" #include <errno.h> +#include <stdlib.h> #include <string.h> #ifdef HAVE_UNISTD_H @@ -44,18 +45,10 @@ void chdir_i4_sub (char *dir, GFC_INTEGER_4 *status, gfc_charlen_type dir_len) { int val; - char *str; - - /* Trim trailing spaces from paths. */ - while (dir_len > 0 && dir[dir_len - 1] == ' ') - dir_len--; - - /* Make a null terminated copy of the strings. */ - str = gfc_alloca (dir_len + 1); - memcpy (str, dir, dir_len); - str[dir_len] = '\0'; + char *str = fc_strdup (dir, dir_len); val = chdir (str); + free (str); if (status != NULL) *status = (val == 0) ? 0 : errno; @@ -69,18 +62,10 @@ void chdir_i8_sub (char *dir, GFC_INTEGER_8 *status, gfc_charlen_type dir_len) { int val; - char *str; - - /* Trim trailing spaces from paths. */ - while (dir_len > 0 && dir[dir_len - 1] == ' ') - dir_len--; - - /* Make a null terminated copy of the strings. */ - str = gfc_alloca (dir_len + 1); - memcpy (str, dir, dir_len); - str[dir_len] = '\0'; + char *str = fc_strdup (dir, dir_len); val = chdir (str); + free (str); if (status != NULL) *status = (val == 0) ? 0 : errno; |