Skip to content

Commit

Permalink
Strip HD prefix from string/char C API calls (HDFGroup#3540)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
derobins authored and brtnfld committed Sep 19, 2023
1 parent 10903da commit 997a4bd
Show file tree
Hide file tree
Showing 363 changed files with 6,159 additions and 6,348 deletions.
2 changes: 1 addition & 1 deletion c++/test/tarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ test_array_compound_array()

// Check the 2nd field's name
H5std_string field2_name = ctype_check.getMemberName(1);
if (HDstrcmp(field2_name.c_str(), "f") != 0)
if (strcmp(field2_name.c_str(), "f") != 0)
TestErrPrintf("Compound field name doesn't match!, field2_name=%s\n", field2_name.c_str());

// Get the 2nd field's datatype
Expand Down
10 changes: 5 additions & 5 deletions c++/test/tattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ test_string_attr(FileAccPropList &fapl)
// Read and verify the attribute string as a string of chars.
char flstring_att_check[ATTR_LEN];
gr_flattr1.read(fls_type, flstring_att_check);
if (HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str()) != 0)
if (strcmp(flstring_att_check, ATTRSTR_DATA.c_str()) != 0)
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",
__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check);

Expand All @@ -1614,7 +1614,7 @@ test_string_attr(FileAccPropList &fapl)
char *fl_dyn_string_att_check;
fl_dyn_string_att_check = new char[attr_size + 1];
gr_flattr1.read(fls_type, fl_dyn_string_att_check);
if (HDstrcmp(fl_dyn_string_att_check, ATTRSTR_DATA.c_str()) != 0)
if (strcmp(fl_dyn_string_att_check, ATTRSTR_DATA.c_str()) != 0)
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",
__LINE__, ATTRSTR_DATA.c_str(), fl_dyn_string_att_check);
delete[] fl_dyn_string_att_check;
Expand All @@ -1629,9 +1629,9 @@ test_string_attr(FileAccPropList &fapl)
ATTRSTR_DATA.c_str(), read_flstr1.c_str());

// Read and verify the attribute string as a string of chars.
HDstrcpy(flstring_att_check, "");
strcpy(flstring_att_check, "");
gr_flattr2.read(fls_type, flstring_att_check);
if (HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str()) != 0)
if (strcmp(flstring_att_check, ATTRSTR_DATA.c_str()) != 0)
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",
__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check);

Expand Down Expand Up @@ -1660,7 +1660,7 @@ test_string_attr(FileAccPropList &fapl)
// Read and verify the attribute string as a string of chars.
char *string_att_check;
gr_vlattr.read(vls_type, &string_att_check);
if (HDstrcmp(string_att_check, ATTRSTR_DATA.c_str()) != 0)
if (strcmp(string_att_check, ATTRSTR_DATA.c_str()) != 0)
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",
__LINE__, ATTRSTR_DATA.c_str(), string_att_check);
free(string_att_check);
Expand Down
20 changes: 10 additions & 10 deletions c++/test/titerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void printelems(const Group &group, const H5std_string &dsname, const H5s
static int
iter_strcmp(const void *s1, const void *s2)
{
return (HDstrcmp(*reinterpret_cast<const char *const *>(s1), *reinterpret_cast<const char *const *>(s2)));
return (strcmp(*reinterpret_cast<const char *const *>(s1), *reinterpret_cast<const char *const *>(s2)));
}

/*-------------------------------------------------------------------------
Expand All @@ -95,7 +95,7 @@ liter_cb(hid_t H5_ATTR_UNUSED group, const char *name, const H5L_info2_t H5_ATTR
static int count = 0;
static int count2 = 0;

HDstrcpy(info->name, name);
strcpy(info->name, name);

switch (info->command) {
case RET_ZERO:
Expand Down Expand Up @@ -162,18 +162,18 @@ test_iter_group(FileAccPropList &fapl)
DataSet dataset = file.createDataSet(name, datatype, filespace);

/* Keep a copy of the dataset names */
lnames[i] = HDstrdup(name);
check_values(lnames[i], "HDstrdup returns NULL", __LINE__, __FILE__);
lnames[i] = strdup(name);
check_values(lnames[i], "strdup returns NULL", __LINE__, __FILE__);
}

/* Create a group and named datatype under root group for testing */
Group grp(file.createGroup(GROUP1, 0));
lnames[NDATASETS] = HDstrdup("grp");
check_values(lnames[NDATASETS], "HDstrdup returns NULL", __LINE__, __FILE__);
lnames[NDATASETS] = strdup("grp");
check_values(lnames[NDATASETS], "strdup returns NULL", __LINE__, __FILE__);

datatype.commit(file, "dtype");
lnames[NDATASETS + 1] = HDstrdup("dtype");
check_values(lnames[NDATASETS], "HDstrdup returns NULL", __LINE__, __FILE__);
lnames[NDATASETS + 1] = strdup("dtype");
check_values(lnames[NDATASETS], "strdup returns NULL", __LINE__, __FILE__);

/* Sort the dataset names */
qsort(lnames, NDATASETS + 2, sizeof(char *), iter_strcmp);
Expand Down Expand Up @@ -301,7 +301,7 @@ test_iter_group(FileAccPropList &fapl)
TestErrPrintf("Group iteration function walked too far!\n");

/* Verify that the correct name is retrieved */
if(HDstrcmp(info.name, lnames[(size_t)(idx - 1)]) != 0)
if(strcmp(info.name, lnames[(size_t)(idx - 1)]) != 0)
TestErrPrintf("Group iteration function didn't return name correctly for link - lnames[%u] = '%s'!\n", (unsigned)(idx - 1), lnames[(size_t)(idx - 1)]);
} /* end while */
verify_val(ret, -1, "H5Literate", __LINE__, __FILE__);
Expand All @@ -327,7 +327,7 @@ test_iter_group(FileAccPropList &fapl)
TestErrPrintf("Group iteration function walked too far!\n");

/* Verify that the correct name is retrieved */
if(HDstrcmp(info.name, lnames[(size_t)(idx - 1)]) != 0)
if(strcmp(info.name, lnames[(size_t)(idx - 1)]) != 0)
TestErrPrintf("Group iteration function didn't return name correctly for link - lnames[%u] = '%s'!\n", (unsigned)(idx - 1), lnames[(size_t)(idx - 1)]);
} /* end while */
verify_val(ret, -1, "H5Literate", __LINE__, __FILE__);
Expand Down
2 changes: 1 addition & 1 deletion c++/test/tobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ test_get_objname_ontypes()
// Name this datatype
new_int_type.commit(grp, "IntType NATIVE_INT");
ssize_t name_len = new_int_type.getObjName(type_name); // default len
verify_val(name_len, static_cast<ssize_t>(HDstrlen("/typetests/IntType NATIVE_INT")),
verify_val(name_len, static_cast<ssize_t>(strlen("/typetests/IntType NATIVE_INT")),
"DataType::getObjName", __LINE__, __FILE__);
verify_val(type_name, "/typetests/IntType NATIVE_INT", "DataType::getObjName", __LINE__, __FILE__);

Expand Down
34 changes: 17 additions & 17 deletions c++/test/tvlstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test_vlstring_dataset()

// Read and verify the dataset string as a string of chars.
dset1.read(&string_ds_check, vlst);
if (HDstrcmp(string_ds_check, DSET1_DATA.c_str()) != 0)
if (strcmp(string_ds_check, DSET1_DATA.c_str()) != 0)
TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,string_ds_check=%s\n", __LINE__,
DSET1_DATA.c_str(), string_ds_check);

Expand Down Expand Up @@ -186,7 +186,7 @@ test_vlstring_dataset()
dset1.read(&string_ds_check, vlst);

// Verify data read.
if (HDstrcmp(string_ds_check, dynstring_ds_write) != 0)
if (strcmp(string_ds_check, dynstring_ds_write) != 0)
TestErrPrintf("VL string datasets don't match!, dynstring_ds_write=%s, string_ds_check=%s\n",
dynstring_ds_write, string_ds_check);
free(string_ds_check);
Expand Down Expand Up @@ -256,7 +256,7 @@ test_vlstring_array_dataset()

hsize_t ii;
for (ii = 0; ii < SPACE1_DIM1; ii++) {
if (HDstrcmp(string_ds_check[ii], string_ds_array[ii]) != 0)
if (strcmp(string_ds_check[ii], string_ds_array[ii]) != 0)
TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n", __LINE__,
string_ds_array[ii], string_ds_check[ii]);

Expand All @@ -282,7 +282,7 @@ test_vlstring_array_dataset()

char *rdata2;
dataset2.read(&rdata2, vlst);
if (HDstrcmp(wdata2, rdata2) != 0)
if (strcmp(wdata2, rdata2) != 0)
TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n", __LINE__, wdata2, rdata2);

// Release resources from second dataset operation.
Expand Down Expand Up @@ -355,15 +355,15 @@ test_vlstrings_special()

// Compare data read in.
for (ii = 0; ii < SPACE1_DIM1; ii++) {
size_t wlen = HDstrlen(wdata[ii]);
size_t rlen = HDstrlen(rdata[ii]);
size_t wlen = strlen(wdata[ii]);
size_t rlen = strlen(rdata[ii]);
if (wlen != rlen) {
TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%u, strlen(rdata[%d])=%u\n",
static_cast<int>(ii), static_cast<unsigned>(wlen), static_cast<int>(ii),
static_cast<unsigned>(rlen));
continue;
}
if (HDstrcmp(wdata[ii], rdata[ii]) != 0) {
if (strcmp(wdata[ii], rdata[ii]) != 0) {
TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",
static_cast<int>(ii), wdata[ii], static_cast<int>(ii), rdata[ii]);
continue;
Expand Down Expand Up @@ -562,13 +562,13 @@ test_compact_vlstring()
// Compare data read in
hsize_t i;
for (i = 0; i < SPACE1_DIM1; i++) {
if (HDstrlen(wdata[i]) != strlen(rdata[i])) {
if (strlen(wdata[i]) != strlen(rdata[i])) {
TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",
static_cast<int>(i), static_cast<int>(HDstrlen(wdata[i])), static_cast<int>(i),
static_cast<int>(HDstrlen(rdata[i])));
static_cast<int>(i), static_cast<int>(strlen(wdata[i])), static_cast<int>(i),
static_cast<int>(strlen(rdata[i])));
continue;
} // end if
if (HDstrcmp(wdata[i], rdata[i]) != 0) {
if (strcmp(wdata[i], rdata[i]) != 0) {
TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",
static_cast<int>(i), wdata[i], static_cast<int>(i), rdata[i]);
continue;
Expand Down Expand Up @@ -634,7 +634,7 @@ test_vlstring_attribute()
// Read and verify the attribute string as a string of chars.
char *string_att_check;
gr_attr.read(vlst, &string_att_check);
if (HDstrcmp(string_att_check, ATTRSTR_DATA.c_str()) != 0)
if (strcmp(string_att_check, ATTRSTR_DATA.c_str()) != 0)
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",
__LINE__, ATTRSTR_DATA.c_str(), string_att_check);

Expand All @@ -661,7 +661,7 @@ test_vlstring_attribute()
gr_attr.read(vlst, &string_att_check);

// Verify data read.
if (HDstrcmp(string_att_check, string_att_write) != 0)
if (strcmp(string_att_check, string_att_write) != 0)
TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",
string_att_write, string_att_check);

Expand Down Expand Up @@ -709,15 +709,15 @@ static void test_read_vl_string_attribute()
// Test reading "normal" sized string attribute
char *string_att_check;
att.read(vlst, &string_att_check);
if(HDstrcmp(string_att_check,ATTRSTR_DATA.c_str())!=0)
if(strcmp(string_att_check,ATTRSTR_DATA.c_str())!=0)
TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",ATTRSTR_DATA.c_str(),string_att_check);
free(string_att_check);
att.close();

// Test reading "large" sized string attribute
att = root.openAttribute("test_scalar_large");
att.read(vlst, &string_att_check);
if(HDstrcmp(string_att_check,string_att_write)!=0)
if(strcmp(string_att_check,string_att_write)!=0)
TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check);
free(string_att_check);
free(string_att_write); // Free string allocated in test_write_vl_string_attribute
Expand Down Expand Up @@ -785,7 +785,7 @@ test_vlstring_array_attribute()

hsize_t ii;
for (ii = 0; ii < SPACE1_DIM1; ii++) {
if (HDstrcmp(string_att_check[ii], string_att_array[ii]) != 0)
if (strcmp(string_att_check[ii], string_att_array[ii]) != 0)
TestErrPrintf("Line %d: Attribute data different: written=%s,read=%s\n", __LINE__,
string_att_check[ii], string_att_check[ii]);

Expand Down Expand Up @@ -834,7 +834,7 @@ read_scalar_dset(H5File &file, DataType &type, DataSpace &space, char *name, cha
dset.read(&data_read, type, space, space);
dset.close();

if (HDstrcmp(data, data_read) != 0)
if (strcmp(data, data_read) != 0)
TestErrPrintf("Expected %s for dataset %s but read %s\n", data, name, data_read);

free(data_read);
Expand Down
2 changes: 1 addition & 1 deletion fortran/test/tH5L_F03.F90
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ SUBROUTINE test_iter_group(cleanup, total_error)
lnames(ndatasets+2) = "grp0000000"

!!$
!!$ lnames[NDATASETS] = HDstrdup("grp");
!!$ lnames[NDATASETS] = strdup("grp");
!!$ CHECK(lnames[NDATASETS], NULL, "strdup");
!!$

Expand Down
8 changes: 4 additions & 4 deletions hl/c++/test/ptableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ TestCompress()

char filter_name[8];
dcpl.getFilterById(H5Z_FILTER_DEFLATE, flags, cd_nelemts, NULL, 8, filter_name, config);
if (HDstrncmp(filter_name, "deflate", 7) != 0)
if (strncmp(filter_name, "deflate", 7) != 0)
H5_FAILED();
}
catch (Exception const &) {
Expand All @@ -313,7 +313,7 @@ TestCompress()
PASSED();
#else
SKIPPED();
HDputs(" deflate filter not enabled");
puts(" deflate filter not enabled");
#endif /* H5_HAVE_FILTER_DEFLATE */
return 0;
}
Expand Down Expand Up @@ -621,7 +621,7 @@ TestHDFFV_9758()
s1[i].a = static_cast<int>(i);
s1[i].b = 1.0F * static_cast<float>(i * i);
s1[i].c = 1.0 / static_cast<double>(i + 1);
HDsnprintf(s1[i].d, STRING_LENGTH, "string%" PRIuHSIZE "", i);
snprintf(s1[i].d, STRING_LENGTH, "string%" PRIuHSIZE "", i);
s1[i].e = static_cast<int>(100 + i);
}

Expand Down Expand Up @@ -692,7 +692,7 @@ TestHDFFV_9758()

if (s2.a != s1[i].a || s2.e != s1[i].e)
goto error;
else if (HDstrcmp(s2.d, s1[i].d) != 0)
else if (strcmp(s2.d, s1[i].d) != 0)
goto error;
}
} // end of ptable block
Expand Down
4 changes: 2 additions & 2 deletions hl/src/H5LD.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ H5LD_get_dset_type_size(hid_t did, const char *fields)
goto done;

/* Get a copy of "fields" */
if (NULL == (dup_fields = HDstrdup(fields)))
if (NULL == (dup_fields = strdup(fields)))
goto done;

/* Allocate memory for a list of H5LD_memb_t pointers to store "fields" info */
Expand Down Expand Up @@ -499,7 +499,7 @@ H5LD_get_dset_elmts(hid_t did, const hsize_t *prev_dims, const hsize_t *cur_dims
goto done;

/* Make a copy of "fields" */
if (NULL == (dup_fields = HDstrdup(fields)))
if (NULL == (dup_fields = strdup(fields)))
goto done;

/* Allocate memory for the vector of H5LD_memb_t pointers */
Expand Down
4 changes: 2 additions & 2 deletions hl/src/H5LT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ H5LTtext_to_dtype(const char *text, H5LT_lang_t lang_type)
}

input_len = strlen(text);
myinput = HDstrdup(text);
myinput = strdup(text);

if ((type_id = H5LTyyparse()) < 0) {
free(myinput);
Expand Down Expand Up @@ -3267,7 +3267,7 @@ H5LTpath_valid(hid_t loc_id, const char *path, hbool_t check_object_valid)
}

/* Duplicate the path to use */
if (NULL == (tmp_path = HDstrdup(path))) {
if (NULL == (tmp_path = strdup(path))) {
ret_value = FAIL;
goto done;
}
Expand Down
4 changes: 2 additions & 2 deletions hl/tools/h5watch/extend_dset.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ main(int argc, char *argv[])
} /* end if */

/* Get the dataset name to be extended */
fname = HDstrdup(argv[1]);
dname = HDstrdup(argv[2]);
fname = strdup(argv[1]);
dname = strdup(argv[2]);
action1 = atoi(argv[3]);
action2 = atoi(argv[4]);

Expand Down
10 changes: 5 additions & 5 deletions hl/tools/h5watch/h5watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ process_cmpd_fields(hid_t fid, char *dsetname)
}

/* Make a copy of "g_list_of_fields" */
if ((g_dup_fields = HDstrdup(g_list_of_fields)) == NULL) {
if ((g_dup_fields = strdup(g_list_of_fields)) == NULL) {
error_msg("error in duplicating g_list_of_fields\n");
ret_value = FAIL;
goto done;
Expand Down Expand Up @@ -703,15 +703,15 @@ parse_command_line(int argc, const char *const *argv)

case 'f': /* --fields=<list_of_fields> */
if (g_list_of_fields == NULL) {
if ((g_list_of_fields = HDstrdup(H5_optarg)) == NULL) {
if ((g_list_of_fields = strdup(H5_optarg)) == NULL) {
error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
leave(EXIT_FAILURE);
}
}
else {
char *str;

if ((str = HDstrdup(H5_optarg)) == NULL) {
if ((str = strdup(H5_optarg)) == NULL) {
error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
leave(EXIT_FAILURE);
}
Expand Down Expand Up @@ -823,7 +823,7 @@ main(int argc, char *argv[])
* then there must have been something wrong with the file (perhaps it
* doesn't exist).
*/
if ((fname = HDstrdup(argv[H5_optind])) == NULL) {
if ((fname = strdup(argv[H5_optind])) == NULL) {
error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
h5tools_setstatus(EXIT_FAILURE);
goto done;
Expand Down Expand Up @@ -877,7 +877,7 @@ main(int argc, char *argv[])
else {
*dname = '/';
x = dname;
if ((dname = HDstrdup(dname)) == NULL) {
if ((dname = strdup(dname)) == NULL) {
error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
h5tools_setstatus(EXIT_FAILURE);
goto done;
Expand Down
Loading

0 comments on commit 997a4bd

Please sign in to comment.