diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2014-05-22 06:51:25 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2014-05-22 06:51:25 +0300 |
commit | 4269f19c09163d6ef65043171eeccc9c521d9b5f (patch) | |
tree | b97492f2a8d9b9b3d41f020dde39ac89bad83229 /libgfortran/runtime/string.c | |
parent | d5c67efda0d5e2d42abd49c0d58bb39a038d20ec (diff) | |
download | gcc-4269f19c09163d6ef65043171eeccc9c521d9b5f.zip gcc-4269f19c09163d6ef65043171eeccc9c521d9b5f.tar.gz gcc-4269f19c09163d6ef65043171eeccc9c521d9b5f.tar.bz2 |
PR 60324 Handle long path names, don't use PATH_MAX.
From-SVN: r210738
Diffstat (limited to 'libgfortran/runtime/string.c')
-rw-r--r-- | libgfortran/runtime/string.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libgfortran/runtime/string.c b/libgfortran/runtime/string.c index a7f68bf..5beb0fb 100644 --- a/libgfortran/runtime/string.c +++ b/libgfortran/runtime/string.c @@ -90,6 +90,49 @@ cf_strcpy (char *dest, gfc_charlen_type dest_len, const char *src) } +#ifndef HAVE_STRNLEN +static size_t +strnlen (const char *s, size_t maxlen) +{ + for (size_t ii = 0; ii < maxlen; ii++) + { + if (s[ii] == '\0') + return ii; + } + return maxlen; +} +#endif + + +#ifndef HAVE_STRNDUP +static char * +strndup (const char *s, size_t n) +{ + size_t len = strnlen (s, n); + char *p = malloc (len + 1); + if (!p) + return NULL; + memcpy (p, s, len); + p[len] = '\0'; + return p; +} +#endif + + +/* Duplicate a non-null-terminated Fortran string to a malloced + null-terminated C string. */ + +char * +fc_strdup (const char *src, gfc_charlen_type src_len) +{ + gfc_charlen_type n = fstrlen (src, src_len); + char *p = strndup (src, n); + if (!p) + os_error ("Memory allocation failed in fc_strdup"); + return p; +} + + /* Given a fortran string and an array of st_option structures, search through the array to find a match. If the option is not found, we generate an error if no default is provided. */ |