diff options
| author | Alejandro Colomar <alx@nginx.com> | 2022-10-27 13:22:19 +0200 |
|---|---|---|
| committer | Alejandro Colomar <alx@nginx.com> | 2022-11-16 13:09:18 +0100 |
| commit | e25c63995d5d52bcbd9c51c5f9ff14cb30bacf6b (patch) | |
| tree | 283d83efe6fbe74d1c252ef627fb3096ea100813 /src/nxt_string.h | |
| parent | a0c0126b3b616fb2a0cf252c51300455f7899ba3 (diff) | |
| download | unit-str-v4.tar.gz unit-str-v4.tar.bz2 | |
Added nxt_usts2str() to make C strings from nxt_str_t.str-v4
This function is identical to nxt_ustr2str(), except that it takes
a nxt_str_t structure as input, instead of a 'u_char *' and a size.
The documentation of the function:
/*
* SYNOPSIS
* void nxt_usts2str(char dst[restrict .src->length+1],
* const nxt_str_t *restrict src);
*
* ARGUMENTS
* dst Pointer to the first byte of the destination buffer.
* src Pointer to the source Unterminated STring Structure.
*
* DESCRIPTION
* Copy a string from the source nxt_str_t, which may be
* not-NUL-terminated, into a NUL-terminated string in the
* destination buffer.
*
* CAVEATS
* If the destination buffer is not wider than the source buffer
* at least by 1 byte, the behavior is undefined.
*
* EXAMPLES
* nxt_str_t src = nxt_string("0123456789");
* char dst[src.length + 1];
*
* nxt_usts2str(dst, &src);
*
* SEE ALSO
* ustr2str(3), strlcpy(3), strscpy(9)
*/
Suggested-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
Diffstat (limited to 'src/nxt_string.h')
| -rw-r--r-- | src/nxt_string.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/nxt_string.h b/src/nxt_string.h index 62459987..ae5d3179 100644 --- a/src/nxt_string.h +++ b/src/nxt_string.h @@ -122,6 +122,8 @@ typedef struct { NXT_EXPORT inline void nxt_ustr2str(char *restrict dst, const u_char *restrict src, size_t length); +NXT_EXPORT inline void nxt_usts2str(char *restrict dst, + const nxt_str_t *restrict src); NXT_EXPORT nxt_str_t *nxt_str_alloc(nxt_mp_t *mp, size_t length); NXT_EXPORT nxt_str_t *nxt_str_dup(nxt_mp_t *mp, nxt_str_t *dst, @@ -179,4 +181,11 @@ nxt_ustr2str(char *restrict dst, const u_char *restrict src, size_t length) } +inline void +nxt_usts2str(char *restrict dst, const nxt_str_t *restrict src) +{ + nxt_ustr2str(dst, src->start, src->length); +} + + #endif /* _NXT_STRING_H_INCLUDED_ */ |
