本文整理汇总了C++中HDstrlen函数的典型用法代码示例。如果您正苦于以下问题:C++ HDstrlen函数的具体用法?C++ HDstrlen怎么用?C++ HDstrlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HDstrlen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HDc2fstr
/*
NAME
HDc2fstr -- convert a C string into a Fortran string IN PLACE
USAGE
intn HDc2fstr(str, len)
char * str; IN: string to convert
intn 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
---------------------------------------------------------------------------*/
intn
HDc2fstr(char *str, intn len)
{
int i;
i=(int)HDstrlen(str);
for (; i < len; i++)
str[i] = ' ';
return SUCCEED;
} /* HDc2fstr */
示例2: h5_cleanup
/*-------------------------------------------------------------------------
* Function: h5_cleanup
*
* Purpose: Cleanup temporary test files.
* base_name contains the list of test file names.
* The file access property list is also closed.
*
* Return: Non-zero if cleanup actions were performed; zero otherwise.
*
* Programmer: Albert Cheng
* May 28, 1998
*
* Modifications:
* Albert Cheng, 2000-09-09
* Added the explicite base_name argument to replace the
* global variable FILENAME.
*
*-------------------------------------------------------------------------
*/
int
h5_cleanup(const char *base_name[], hid_t fapl)
{
char filename[1024];
char temp[2048];
int i, j;
int retval=0;
hid_t driver;
if (GetTestCleanup()){
for (i = 0; base_name[i]; i++) {
if (h5_fixname(base_name[i], fapl, filename, sizeof(filename)) == NULL)
continue;
driver = H5Pget_driver(fapl);
if (driver == H5FD_FAMILY) {
for (j = 0; /*void*/; j++) {
HDsnprintf(temp, sizeof temp, filename, j);
if (HDaccess(temp, F_OK) < 0)
break;
HDremove(temp);
}
} else if (driver == H5FD_CORE) {
hbool_t backing; /* Whether the core file has backing store */
H5Pget_fapl_core(fapl,NULL,&backing);
/* If the file was stored to disk with bacing store, remove it */
if(backing)
HDremove(filename);
} else if (driver == H5FD_MULTI) {
H5FD_mem_t mt;
assert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES);
for (mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) {
HDsnprintf(temp, sizeof temp, "%s-%c.h5",
filename, multi_letters[mt]);
HDremove(temp); /*don't care if it fails*/
}
} else {
HDremove(filename);
}
}
retval = 1;
}
H5Pclose(fapl);
return retval;
}
示例3: AddTest
/*
* Setup a test function and add it to the list of tests.
* It must have no parameters and returns void.
* TheName--short test name.
* If the name starts with '-', do not run it by default.
* TheCall--the test routine.
* Cleanup--the cleanup routine for the test.
* TheDescr--Long description of the test.
* Parameters--pointer to extra parameters. Use NULL if none used.
* Since only the pointer is copied, the contents should not change.
* Return: Void
* exit EXIT_FAILURE if error is encountered.
*/
void
AddTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), const char *TheDescr, const void *Parameters)
{
/* Sanity checking */
if (Index >= MAXNUMOFTESTS) {
printf("Too many tests added, increase MAXNUMOFTESTS(%d).\n",
MAXNUMOFTESTS);
exit(EXIT_FAILURE);
} /* end if */
if (HDstrlen(TheDescr) >= MAXTESTDESC) {
printf("Test description too long, increase MAXTESTDESC(%d).\n",
MAXTESTDESC);
exit(EXIT_FAILURE);
} /* end if */
if (HDstrlen(TheName) >= MAXTESTNAME) {
printf("Test name too long, increase MAXTESTNAME(%d).\n",
MAXTESTNAME);
exit(EXIT_FAILURE);
} /* end if */
/* Set up test function */
HDstrcpy(Test[Index].Description, TheDescr);
if (*TheName != '-'){
HDstrcpy(Test[Index].Name, TheName);
Test[Index].SkipFlag = 0;
}
else { /* skip test by default */
HDstrcpy(Test[Index].Name, TheName+1);
Test[Index].SkipFlag = 1;
}
Test[Index].Call = TheCall;
Test[Index].Cleanup = Cleanup;
Test[Index].NumErrors = -1;
Test[Index].Parameters = Parameters;
/* Increment test count */
Index++;
}
示例4: test_vl_string
/*
* test_vl_string
* Tests variable-length string datatype with UTF-8 strings.
*/
void test_vl_string(hid_t fid, const char *string)
{
hid_t type_id, space_id, dset_id;
hsize_t dims = 1;
hsize_t size; /* Number of bytes used */
char *read_buf[1];
herr_t ret;
/* Create dataspace for datasets */
space_id = H5Screate_simple(RANK, &dims, NULL);
CHECK(space_id, FAIL, "H5Screate_simple");
/* Create a datatype to refer to */
type_id = H5Tcopy(H5T_C_S1);
CHECK(type_id, FAIL, "H5Tcopy");
ret = H5Tset_size(type_id, H5T_VARIABLE);
CHECK(ret, FAIL, "H5Tset_size");
/* Create a dataset */
dset_id = H5Dcreate2(fid, VL_DSET1_NAME, type_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dset_id, FAIL, "H5Dcreate2");
/* Write dataset to disk */
ret = H5Dwrite(dset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &string);
CHECK(ret, FAIL, "H5Dwrite");
/* Make certain the correct amount of memory will be used */
ret = H5Dvlen_get_buf_size(dset_id, type_id, space_id, &size);
CHECK(ret, FAIL, "H5Dvlen_get_buf_size");
VERIFY(size, (hsize_t)HDstrlen(string) + 1, "H5Dvlen_get_buf_size");
/* Read dataset from disk */
ret = H5Dread(dset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf);
CHECK(ret, FAIL, "H5Dread");
/* Compare data read in */
VERIFY(HDstrcmp(string, read_buf[0]), 0, "strcmp");
/* Reclaim the read VL data */
ret = H5Dvlen_reclaim(type_id, space_id, H5P_DEFAULT, read_buf);
CHECK(ret, FAIL, "H5Dvlen_reclaim");
/* Close all */
ret = H5Dclose(dset_id);
CHECK(ret, FAIL, "H5Dclose");
ret = H5Tclose(type_id);
CHECK(ret, FAIL, "H5Tclose");
ret = H5Sclose(space_id);
CHECK(ret, FAIL, "H5Sclose");
}
示例5: H5O_attr_size
/*--------------------------------------------------------------------------
NAME
H5O_attr_size
PURPOSE
Return the raw message size in bytes
USAGE
size_t H5O_attr_size(f, mesg)
H5F_t *f; IN: pointer to the HDF5 file struct
const void *mesg; IN: Pointer to the source attribute struct
RETURNS
Size of message on success, 0 on failure
DESCRIPTION
This function returns the size of the raw attribute message on
success. (Not counting the message type or size fields, only the data
portion of the message). It doesn't take into account alignment.
*
* Modified:
* Robb Matzke, 17 Jul 1998
* Added padding between message parts for alignment.
--------------------------------------------------------------------------*/
static size_t
H5O_attr_size(const H5F_t UNUSED *f, const void *_mesg)
{
const H5A_t *attr = (const H5A_t *)_mesg;
size_t name_len;
unsigned version; /* Attribute version */
hbool_t type_shared; /* Flag to indicate that a shared datatype is used for this attribute */
size_t ret_value = 0;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_attr_size);
assert(attr);
name_len = HDstrlen(attr->name)+1;
/* Check whether datatype is shared */
if(H5T_committed(attr->dt))
type_shared = TRUE;
else
type_shared = FALSE;
/* Check which version to write out */
if(type_shared)
version = H5O_ATTR_VERSION_NEW; /* Write out new version if shared datatype */
else
version = H5O_ATTR_VERSION;
if(version < H5O_ATTR_VERSION_NEW)
ret_value = 1 + /*version */
1 + /*reserved */
2 + /*name size inc. null */
2 + /*type size */
2 + /*space size */
H5O_ALIGN(name_len) + /*attribute name */
H5O_ALIGN(attr->dt_size) + /*data type */
H5O_ALIGN(attr->ds_size) + /*data space */
attr->data_size; /*the data itself */
else
ret_value = 1 + /*version */
1 + /*flags */
2 + /*name size inc. null */
2 + /*type size */
2 + /*space size */
name_len + /*attribute name */
attr->dt_size + /*data type */
attr->ds_size + /*data space */
attr->data_size; /*the data itself */
FUNC_LEAVE_NOAPI(ret_value);
}
示例6: H5L_build_name
/*--------------------------------------------------------------------------
* Function: H5L_build_name
*
* Purpose: Prepend PREFIX to FILE_NAME and store in FULL_NAME
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Vailin Choi, April 2, 2008
*
* Modification: Raymond Lu, 14 Jan. 2009
* Added support for OpenVMS pathname
--------------------------------------------------------------------------*/
static herr_t
H5L_build_name(char *prefix, char *file_name, char **full_name/*out*/)
{
size_t prefix_len; /* length of prefix */
size_t fname_len; /* Length of external link file name */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
prefix_len = HDstrlen(prefix);
fname_len = HDstrlen(file_name);
/* Allocate a buffer to hold the filename + prefix + possibly the delimiter + terminating null byte */
if(NULL == (*full_name = (char *)H5MM_malloc(prefix_len + fname_len + 2)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate filename buffer")
/* Compose the full file name */
HDsnprintf(*full_name, (prefix_len + fname_len + 2), "%s%s%s", prefix,
(H5_CHECK_DELIMITER(prefix[prefix_len - 1]) ? "" : H5_DIR_SEPS), file_name);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5L_build_name() */
示例7: test_refstr_own
/****************************************************************
**
** test_refstr_own(): Test basic H5RS (ref-counted strings) code.
** Tests transferring ownership of dynamically allocated strings
** to ref-counted strings.
**
****************************************************************/
static void
test_refstr_own(void)
{
H5RS_str_t *rs; /* Ref-counted string created */
char *s; /* Pointer to string to transfer */
const char *t; /* Temporary pointers to string */
int cmp; /* Comparison value */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing Transferring Ref-Counted Strings\n"));
/* Initialize buffer */
s = (char *)H5FL_BLK_MALLOC(str_buf,HDstrlen("foo") + 1);
CHECK(s, NULL, "H5FL_BLK_MALLOC");
HDstrcpy(s, "foo");
/* Transfer ownership of dynamically allocated string to ref-counted string */
rs=H5RS_own(s);
CHECK(rs, NULL, "H5RS_own");
/* Get pointer to raw string in ref-counted string */
t=H5RS_get_str(rs);
CHECK(t, NULL, "H5RS_get_str");
VERIFY(t, s, "transferring");
cmp=HDstrcmp(s,t);
VERIFY(cmp, 0, "HDstrcmp");
/* Increment reference count (should NOT duplicate string) */
ret=H5RS_incr(rs);
CHECK(ret, FAIL, "H5RS_incr");
/* Change the buffer initially wrapped */
*s='F';
/* Get pointer to raw string in ref-counted string */
t=H5RS_get_str(rs);
CHECK(t, NULL, "H5RS_get_str");
VERIFY(t, s, "transferring");
cmp=HDstrcmp(t,s);
VERIFY(cmp, 0, "HDstrcmp");
/* Decrement reference count for string */
ret=H5RS_decr(rs);
CHECK(ret, FAIL, "H5RS_decr");
ret=H5RS_decr(rs);
CHECK(ret, FAIL, "H5RS_decr");
} /* end test_refstr_own() */
示例8: H5MM_strdup
/*-------------------------------------------------------------------------
* Function: H5MM_strdup
*
* Purpose: Duplicates a string. If the string to be duplicated is the
* null pointer, then return null. If the string to be duplicated
* is the empty string then return a new empty string.
*
* Return: Success: Ptr to a new string (or null if no string).
*
* Failure: abort()
*
* Programmer: Robb Matzke
* [email protected]
* Jul 10 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
char *
H5MM_strdup(const char *s)
{
char *ret_value;
FUNC_ENTER_NOAPI(H5MM_strdup, NULL)
if(!s)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "null string")
if(NULL == (ret_value = (char *)H5MM_malloc(HDstrlen(s) + 1)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
HDstrcpy(ret_value, s);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MM_strdup() */
示例9: H5O_name_size
/*-------------------------------------------------------------------------
* Function: H5O_name_size
*
* Purpose: Returns the size of the raw message in bytes not
* counting the message typ or size fields, but only the data
* fields. This function doesn't take into account
* alignment.
*
* Return: Success: Message data size in bytes w/o alignment.
*
* Failure: Negative
*
* Programmer: Robb Matzke
* [email protected]
* Aug 12 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static size_t
H5O_name_size(const H5F_t H5_ATTR_UNUSED *f, hbool_t H5_ATTR_UNUSED disable_shared, const void *_mesg)
{
const H5O_name_t *mesg = (const H5O_name_t *) _mesg;
size_t ret_value;
FUNC_ENTER_NOAPI_NOINIT_NOERR
/* check args */
HDassert(f);
HDassert(mesg);
ret_value = mesg->s ? HDstrlen(mesg->s) + 1 : 0;
FUNC_LEAVE_NOAPI(ret_value)
}
示例10: H5MM_xstrdup
/*-------------------------------------------------------------------------
* Function: H5MM_xstrdup
*
* Purpose: Duplicates a string. If the string to be duplicated is the
* null pointer, then return null. If the string to be duplicated
* is the empty string then return a new empty string.
*
* Return: Success: Ptr to a new string (or null if no string).
*
* Failure: abort()
*
* Programmer: Robb Matzke
* [email protected]
* Jul 10 1997
*
*-------------------------------------------------------------------------
*/
char *
H5MM_xstrdup(const char *s)
{
char *ret_value = NULL;
/* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5MM_xstrdup)
if(s) {
ret_value = (char *)H5MM_malloc(HDstrlen(s) + 1);
HDassert(ret_value);
HDstrcpy(ret_value, s);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MM_xstrdup() */
示例11: diff_basename
/*-------------------------------------------------------------------------
* Function: diff_basename
*
* Purpose: Returns a pointer to the last component absolute name
*
* Programmer: Pedro Vicente, [email protected]
*
* Date: May 9, 2003
*
*-------------------------------------------------------------------------
*/
const char*
diff_basename(const char *name)
{
size_t i;
if (name==NULL)
return NULL;
/* Find the end of the base name */
i = HDstrlen(name);
while (i>0 && '/'==name[i-1])
--i;
/* Skip backward over base name */
while (i>0 && '/'!=name[i-1])
--i;
return(name+i);
}
示例12: H5MM_xstrdup
/*-------------------------------------------------------------------------
* Function: H5MM_xstrdup
*
* Purpose: Duplicates a string. If the string to be duplicated is the
* null pointer, then return null. If the string to be duplicated
* is the empty string then return a new empty string.
*
* Return: Success: Ptr to a new string (or null if no string).
*
* Failure: abort()
*
* Programmer: Robb Matzke
* [email protected]
* Jul 10 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
char *
H5MM_xstrdup(const char *s)
{
char *ret_value=NULL;
/* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5MM_xstrdup);
if (s) {
ret_value = H5MM_malloc(HDstrlen(s) + 1);
assert (ret_value);
HDstrcpy(ret_value, s);
} /* end if */
#ifdef LATER
done:
#endif /* LATER */
FUNC_LEAVE_NOAPI(ret_value);
}
示例13: getTmpName
int
getTmpName(char **pname)
{
int length;
static int count = 0;
char s[32];
(void) sprintf(s, "%she%d.%d", TDIR, (int)getpid(), count);
count++;
length = (int)HDstrlen(s);
if (length <= 0)
return FAIL;
*pname = (char *) HDmalloc(length + 1);
HDstrcpy(*pname, s);
return length;
}
示例14: generate_symbols
/*-------------------------------------------------------------------------
* Function: generate_symbols
*
* Purpose: Initializes the global dataset infomration arrays.
*
* Parameters: N/A
*
* Return: Success: 0
* Failure: Can't fail
*
*-------------------------------------------------------------------------
*/
int
generate_symbols(void)
{
unsigned u, v; /* Local index variables */
for(u = 0; u < NLEVELS; u++) {
symbol_info[u] = (symbol_info_t *)HDmalloc(symbol_count[u] * sizeof(symbol_info_t));
for(v = 0; v < symbol_count[u]; v++) {
char name_buf[64];
generate_name(name_buf, u, v);
symbol_info[u][v].name = (char *)HDmalloc(HDstrlen(name_buf) + 1);
HDstrcpy(symbol_info[u][v].name, name_buf);
symbol_info[u][v].dsid = -1;
symbol_info[u][v].nrecords = 0;
} /* end for */
} /* end for */
return 0;
} /* end generate_symbols() */
示例15: H5_bandwidth
/*-------------------------------------------------------------------------
* Function: H5_bandwidth
*
* Purpose: Prints the bandwidth (bytes per second) in a field 10
* characters wide widh four digits of precision like this:
*
* NaN If <=0 seconds
* 1234. TB/s
* 123.4 TB/s
* 12.34 GB/s
* 1.234 MB/s
* 4.000 kB/s
* 1.000 B/s
* 0.000 B/s If NBYTES==0
* 1.2345e-10 For bandwidth less than 1
* 6.7893e+94 For exceptionally large values
* 6.678e+106 For really big values
*
* Return: void
*
* Programmer: Robb Matzke
* Wednesday, August 5, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
H5_bandwidth(char *buf/*out*/, double nbytes, double nseconds)
{
double bw;
if (nseconds<=0.0) {
HDstrcpy(buf, " NaN");
} else {
bw = nbytes/nseconds;
if (fabs(bw) < 0.0000000001) {
/* That is == 0.0, but direct comparison between floats is bad */
HDstrcpy(buf, "0.000 B/s");
} else if (bw<1.0) {
sprintf(buf, "%10.4e", bw);
} else if (bw<1024.0) {
sprintf(buf, "%05.4f", bw);
HDstrcpy(buf+5, " B/s");
} else if (bw<1024.0*1024.0) {
sprintf(buf, "%05.4f", bw/1024.0);
HDstrcpy(buf+5, " kB/s");
} else if (bw<1024.0*1024.0*1024.0) {
sprintf(buf, "%05.4f", bw/(1024.0*1024.0));
HDstrcpy(buf+5, " MB/s");
} else if (bw<1024.0*1024.0*1024.0*1024.0) {
sprintf(buf, "%05.4f",
bw/(1024.0*1024.0*1024.0));
HDstrcpy(buf+5, " GB/s");
} else if (bw<1024.0*1024.0*1024.0*1024.0*1024.0) {
sprintf(buf, "%05.4f",
bw/(1024.0*1024.0*1024.0*1024.0));
HDstrcpy(buf+5, " TB/s");
} else {
sprintf(buf, "%10.4e", bw);
if (HDstrlen(buf)>10) {
sprintf(buf, "%10.3e", bw);
}
}
}
} /* end H5_bandwidth() */