diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2023-09-15 22:13:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 22:13:18 (GMT) |
commit | 44a00ef876ad3e1922847e93feac57c479217fbe (patch) | |
tree | 5e9fc677913a06a71eba1342633f92e93bd07a6c /tools/lib/h5tools_str.c | |
parent | 59a90368cdb696205bdf15040d1a48b4f69af97f (diff) | |
download | hdf5-44a00ef876ad3e1922847e93feac57c479217fbe.zip hdf5-44a00ef876ad3e1922847e93feac57c479217fbe.tar.gz hdf5-44a00ef876ad3e1922847e93feac57c479217fbe.tar.bz2 |
Strip HD prefix from string/char C API calls (#3540)
* Strip HD prefix from string/char C API calls
* HD(f)(put|get)(s|c)
* HDstr*
* HDv*printf
* HD(s)(print|scan)f
* HDperror
But NOT:
* HDstrcase*
* HDvasprintf
* HDstrtok_r
* HDstrndup
As those are not C99 and have portability work-around
implementations. They will be handled later.
* Fix th5_system.c screwup
Diffstat (limited to 'tools/lib/h5tools_str.c')
-rw-r--r-- | tools/lib/h5tools_str.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 507c6ef..5ef86fb 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -106,7 +106,7 @@ h5tools_str_append(h5tools_str_t *str /*in,out*/, const char *fmt, ...) if (!str->s || str->nalloc <= 0) h5tools_str_reset(str); - if (HDstrlen(fmt) == 0) + if (strlen(fmt) == 0) /* nothing to print */ return str->s; @@ -117,17 +117,17 @@ h5tools_str_append(h5tools_str_t *str /*in,out*/, const char *fmt, ...) size_t avail = str->nalloc - str->len; va_start(ap, fmt); - nchars = HDvsnprintf(str->s + str->len, avail, fmt, ap); + nchars = vsnprintf(str->s + str->len, avail, fmt, ap); va_end(ap); - /* Note: HDvsnprintf() behaves differently on Windows as Unix, when + /* Note: vsnprintf() behaves differently on Windows as Unix, when * buffer is smaller than source string. On Unix, this function * returns length of the source string and copy string up to the * buffer size with NULL at the end of the buffer. However on * Windows with the same condition, this function returns -1 and * doesn't add NULL at the end of the buffer. * Because of this different return results, the strlen of the new string - * is used to handle when HDvsnprintf() returns -1 on Windows due + * is used to handle when vsnprintf() returns -1 on Windows due * to lack of buffer size, so try one more time after realloc more * buffer size before return NULL. */ @@ -135,7 +135,7 @@ h5tools_str_append(h5tools_str_t *str /*in,out*/, const char *fmt, ...) /* failure, such as bad format */ return NULL; - if ((size_t)nchars >= avail || (0 == nchars && (HDstrcmp(fmt, "%s") != 0))) { + if ((size_t)nchars >= avail || (0 == nchars && (strcmp(fmt, "%s") != 0))) { /* Truncation return value as documented by C99, or zero return value with either of the * following conditions, each of which indicates that the proper C99 return value probably * should have been positive when the format string is @@ -230,14 +230,14 @@ h5tools_str_fmt(h5tools_str_t *str /*in,out*/, size_t start, const char *fmt) assert(fmt); /* If the format string is simply "%s" then don't bother doing anything */ - if (!HDstrcmp(fmt, "%s")) + if (!strcmp(fmt, "%s")) return str->s; /* * Save the input value if there is a `%' anywhere in FMT. Otherwise * don't bother because we don't need a temporary copy. */ - if (HDstrchr(fmt, '%')) { + if (strchr(fmt, '%')) { size_t n = sizeof(_temp); if (str->len - start + 1 > n) { n = str->len - start + 1; @@ -245,7 +245,7 @@ h5tools_str_fmt(h5tools_str_t *str /*in,out*/, size_t start, const char *fmt) assert(temp); } - HDstrncpy(temp, str->s + start, n - 1); + strncpy(temp, str->s + start, n - 1); temp[n - 1] = '\0'; } @@ -669,8 +669,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai H5TOOLS_START_DEBUG(" "); /* Build default formats for long long types */ if (!fmt_llong[0]) { - HDsnprintf(fmt_llong, sizeof(fmt_llong), "%%lld"); - HDsnprintf(fmt_ullong, sizeof(fmt_ullong), "%%llu"); + snprintf(fmt_llong, sizeof(fmt_llong), "%%lld"); + snprintf(fmt_ullong, sizeof(fmt_ullong), "%%llu"); } /* Append value depending on data type */ @@ -741,10 +741,10 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai quote = '\0'; if (H5Tis_variable_str(type)) { /* cp_vp is the pointer into the struct where a `char*' is stored. So we have - * to dereference the pointer to get the `char*' to pass to HDstrlen(). */ + * to dereference the pointer to get the `char*' to pass to strlen(). */ s = *(char **)((void *)cp_vp); if (s != NULL) - size = HDstrlen(s); + size = strlen(s); } else { s = cp_vp; @@ -1494,7 +1494,7 @@ h5tools_escape(char *s /*in,out*/, size_t size) size_t i; const char *escape; char octal[8]; - size_t n = HDstrlen(s); + size_t n = strlen(s); for (i = 0; i < n; i++) { switch (s[i]) { @@ -1533,7 +1533,7 @@ h5tools_escape(char *s /*in,out*/, size_t size) break; default: if (!isprint(s[i])) { - HDsnprintf(octal, sizeof(octal), "\\%03o", (unsigned char)s[i]); + snprintf(octal, sizeof(octal), "\\%03o", (unsigned char)s[i]); escape = octal; } else @@ -1543,7 +1543,7 @@ h5tools_escape(char *s /*in,out*/, size_t size) } if (escape) { - size_t esc_size = HDstrlen(escape); + size_t esc_size = strlen(escape); if (n + esc_size + 1 > size) /*would overflow*/ @@ -1601,26 +1601,26 @@ h5tools_str_replace(const char *string, const char *substr, const char *replacem char *head = NULL; if (substr == NULL || replacement == NULL) - return HDstrdup(string); - newstr = HDstrdup(string); + return strdup(string); + newstr = strdup(string); head = newstr; - while ((tok = HDstrstr(head, substr))) { + while ((tok = strstr(head, substr))) { char *oldstr; oldstr = newstr; - newstr = (char *)malloc(HDstrlen(oldstr) - HDstrlen(substr) + HDstrlen(replacement) + 1); + newstr = (char *)malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1); if (newstr == NULL) { free(oldstr); return NULL; } memcpy(newstr, oldstr, (size_t)(tok - oldstr)); - memcpy(newstr + (tok - oldstr), replacement, HDstrlen(replacement)); - memcpy(newstr + (tok - oldstr) + HDstrlen(replacement), tok + HDstrlen(substr), - HDstrlen(oldstr) - HDstrlen(substr) - (size_t)(tok - oldstr)); - memset(newstr + HDstrlen(oldstr) - HDstrlen(substr) + HDstrlen(replacement), 0, 1); + memcpy(newstr + (tok - oldstr), replacement, strlen(replacement)); + memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr), + strlen(oldstr) - strlen(substr) - (size_t)(tok - oldstr)); + memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1); /* move back head right after the last replacement */ - head = newstr + (tok - oldstr) + HDstrlen(replacement); + head = newstr + (tok - oldstr) + strlen(replacement); free(oldstr); } |