File qclib.handle.hostnames.with.less.than.8.characters.in.presence.of.hypfs.patch of Package qclib-devel.2591
---
query_capacity_data.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
--- a/query_capacity_data.c
+++ b/query_capacity_data.c
@@ -563,28 +563,42 @@ int qc_set_attr_float(struct qc_handle *
return 0;
}
-// Sets attribute 'id' in layer as pointed to by 'hdl'
+// Sets string attribute 'id' in layer as pointed to by 'hdl', stripping trailing blanks
int qc_set_attr_string(struct qc_handle *hdl, enum qc_attr_id id, char *str, unsigned int str_len, char src) {
- char *ptr;
+ char *ptr, *p;
if ((ptr = qc_set_attr(hdl, id, string, src)) == NULL)
return -1;
ptr[str_len] = '\0';
strncpy(ptr, str, str_len);
+ // strip trailing blanks
+ for (p = &ptr[str_len - 1]; *p == ' ' && p != ptr; --p)
+ *p = '\0';
return 0;
}
-// Sets attribute 'id' in layer as pointed to by 'hdl'
+// Sets ebcdic string attribute 'id' in layer as pointed to by 'hdl'
+// Note: Copy content to temporary buffer for conversion first, as we do not want to modify the source data.
int qc_set_attr_ebcdic_string(struct qc_handle *hdl, enum qc_attr_id id, unsigned char *str,
unsigned int str_len, iconv_t *cd, char src) {
char *buf;
+ int rc;
- if (qc_set_attr_string(hdl, id, (char *)str, str_len, src))
+ buf = malloc(str_len + 1);
+ if (!buf) {
+ qc_debug(hdl, "Error: Memory allocation error\n");
return -1;
- buf = qc_get_attr_value_string(hdl, id);
+ }
+ memset(buf, '\0', str_len + 1);
+ memcpy(buf, str, str_len);
+ if ((rc = qc_ebcdic_to_ascii(hdl, cd, buf, str_len)) == 0) {
+ if (qc_set_attr_string(hdl, id, (char *)buf, str_len, src))
+ rc = -2;
+ }
+ free(buf);
- return qc_ebcdic_to_ascii(hdl, cd, buf, str_len);
+ return rc;
}
// Certain parts assume that empty strings might also consist of spaces