summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-10-15 20:15:26 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-10-15 20:15:26 (GMT)
commita4671842801cada7d59345c44ee324252a362956 (patch)
treee81b9cfe2df51e3f3c8eab5820490289d655c8e2
parent6a516752c7ef1bf237b1aa196ee6e902eb7ad2cd (diff)
downloadhdf5-a4671842801cada7d59345c44ee324252a362956.zip
hdf5-a4671842801cada7d59345c44ee324252a362956.tar.gz
hdf5-a4671842801cada7d59345c44ee324252a362956.tar.bz2
[svn-r7642] Purpose:
Code cleanup Description: Remove unused 'HD5c2fstr' routine and clean up coding for other routines. Platforms tested: h5committest
-rw-r--r--fortran/src/H5f90kit.c73
1 files changed, 27 insertions, 46 deletions
diff --git a/fortran/src/H5f90kit.c b/fortran/src/H5f90kit.c
index 5ea1bb6..a25645b 100644
--- a/fortran/src/H5f90kit.c
+++ b/fortran/src/H5f90kit.c
@@ -21,36 +21,10 @@
/*
* Routines from HDF4 to deal with C-FORTRAN issues.
*
- * HD5c2fstr -- convert a C string into a Fortran string IN PLACE
* HD5f2cstring -- convert a Fortran string to a C string
+ * HD5packFstring -- convert a C string into a Fortran string
*/
-/* ------------------------------- HDc2fstr -------------------------------
-NAME
- HD5c2fstr -- convert a C string into a Fortran string IN PLACE
-USAGE
- int HD5c2fstr(str, len)
- char * str; IN: string to convert
- int len; IN: length of Fortran string
-RETURNS
- SUCCEED
-DESCRIPTION
- Change a C string (NULL terminated) into a Fortran string.
- Basically, all that is done is that the NULL is ripped out
- and the string is padded with spaces
-
----------------------------------------------------------------------------*/
-int
-HD5c2fstr(char *str, int len)
-{
- int i;
-
- i=(int)HDstrlen(str);
- for (; i < len; i++)
- str[i] = ' ';
- return 0;
-} /* HD5c2fstr */
-
/* ----------------------------- HDf2cstring ------------------------------ */
/*
NAME
@@ -68,20 +42,27 @@ DESCRIPTION
---------------------------------------------------------------------------*/
char *
-HD5f2cstring(_fcd fdesc, int len)
+HD5f2cstring(_fcd fdesc, size_t len)
{
- char *cstr = NULL;
- char *str;
- int i;
+ char *cstr; /* C string to return */
+ char *str; /* Pointer to FORTRAN string */
+ int i; /* Local index variable */
+ /* Search for the end of the string */
str = _fcdtocp(fdesc);
- /* This should be equivalent to the above test -QAK */
- for(i=len-1; i>=0 && !isgraph((int)str[i]); i--)
+ for(i=(int)len-1; i>=0 && !isgraph((int)str[i]); i--)
/*EMPTY*/;
- cstr = (char *) HDmalloc( (size_t)(i + 2));
- if (cstr == NULL) return NULL;
- cstr[i + 1] = '\0';
+
+ /* Allocate C string */
+ if ((cstr = HDmalloc( (size_t)(i + 2))) == NULL)
+ return NULL;
+
+ /* Copy text from FORTRAN to C string */
HDmemcpy(cstr,str,(size_t)(i+1));
+
+ /* Terminate C string */
+ cstr[i + 1] = '\0';
+
return cstr;
} /* HD5f2cstring */
@@ -105,17 +86,17 @@ DESCRIPTION
support one of these.
---------------------------------------------------------------------------*/
-int
-HD5packFstring(char *src, char *dest, int len)
+void
+HD5packFstring(char *src, char *dest, size_t dst_len)
{
- int sofar;
-
- for (sofar = 0; (sofar < len) && (*src != '\0'); sofar++)
- *dest++ = *src++;
+ size_t src_len=HDstrlen(src);
- while (sofar++ < len)
- *dest++ = ' ';
+ /* Copy over the string information, up to the length of the src */
+ /* (Don't copy the NUL terminator from the C string to the FORTRAN string */
+ HDmemcpy(dest,src,MIN(src_len,dst_len));
- return 0;
-} /* HD5packFstring */
+ /* Pad out any remaining space in the FORTRAN string with ' 's */
+ if(src_len<dst_len)
+ HDmemset(&dest[src_len],' ',dst_len-src_len);
+} /* HD5packFstring */