---
name: "ustr_const"
section: "3"
platform: "linux"
package: "libustr-dev"
version: "1.0.4-6.1"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/ustr_const"
---

# ustr\_const(3)

ustr string library constants

## NAME

ustr\_const - ustr string library constants

## SYNOPSIS

\#include "ustr.h"

**USTR\_CONF\_INCLUDE\_CODEONLY\_HEADERS**\
 **USTR\_CONF\_USE\_EOS\_MARK**\
 **USTR\_CONF\_USE\_ASSERT**\
 **USTR\_CONF\_COMPILE\_USE\_ATTRIBUTES**\
 **USTR\_CONF\_COMPILE\_TYPEDEF**\
 **USTR\_CONF\_COMPILE\_USE\_INLINE**

**USTR\_BEG\_CONST1**\
 **USTR\_BEG\_CONST2**\
 **USTR\_BEG\_CONST4**\
 **USTR\_BEG\_FIXED1**\
 **USTR\_BEG\_FIXED2**\
 **USTR\_BEG\_FIXED4**\
 **USTR\_BEG\_FIXED8**\
 **USTR\_END\_ALOCDx**\
 **USTR\_END\_CONSTx**\
 **USTR\_END\_FIXEDx**

**USTR\_FLAG\_PARSE\_NUM\_DEF**\
 **USTR\_FLAG\_PARSE\_NUM\_SEP**\
 **USTR\_FLAG\_PARSE\_NUM\_OVERFLOW**\
 **USTR\_FLAG\_PARSE\_NUM\_SPACE**\
 **USTR\_FLAG\_PARSE\_NUM\_NO\_BEG\_ZERO**\
 **USTR\_FLAG\_PARSE\_NUM\_NO\_BEG\_PM**\
 **USTR\_FLAG\_PARSE\_NUM\_NO\_NEGATIVE**\
 **USTR\_FLAG\_PARSE\_NUM\_EXACT**\
 **USTR\_TYPE\_PARSE\_NUM\_ERR\_NONE**\
 **USTR\_TYPE\_PARSE\_NUM\_ERR\_ONLY\_S**\
 **USTR\_TYPE\_PARSE\_NUM\_ERR\_ONLY\_SPM**\
 **USTR\_TYPE\_PARSE\_NUM\_ERR\_ONLY\_SPMX**\
 **USTR\_TYPE\_PARSE\_NUM\_ERR\_OOB**\
 **USTR\_TYPE\_PARSE\_NUM\_ERR\_OVERFLOW**\
 **USTR\_TYPE\_PARSE\_NUM\_ERR\_NEGATIVE**\
 **USTR\_TYPE\_PARSE\_NUM\_ERR\_BEG\_ZERO**

**USTR\_FLAG\_SPLIT\_DEF**\
 **USTR\_FLAG\_SPLIT\_RET\_SEP**\
 **USTR\_FLAG\_SPLIT\_RET\_NON**\
 **USTR\_FLAG\_SPLIT\_KEEP\_CONFIG**

**USTR\_NULL**\
 **USTR\_POOL\_NULL**\
 **USTR\_TRUE**\
 **USTR\_FALSE**

**USTR\_CNTL\_OPT\_GET\_REF\_BYTES**\
 **USTR\_CNTL\_OPT\_SET\_REF\_BYTES**\
 **USTR\_CNTL\_OPT\_GET\_HAS\_SIZE**\
 **USTR\_CNTL\_OPT\_SET\_HAS\_SIZE**\
 **USTR\_CNTL\_OPT\_GET\_EXACT\_BYTES**\
 **USTR\_CNTL\_OPT\_SET\_EXACT\_BYTES**\
 **USTR\_CNTL\_OPT\_GET\_MEM**\
 **USTR\_CNTL\_OPT\_SET\_MEM**\
 **USTR\_CNTL\_OPT\_GET\_MC\_M\_SCRUB**\
 **USTR\_CNTL\_OPT\_SET\_MC\_M\_SCRUB**\
 **USTR\_CNTL\_OPT\_GET\_MC\_F\_SCRUB**\
 **USTR\_CNTL\_OPT\_SET\_MC\_F\_SCRUB**\
 **USTR\_CNTL\_OPT\_GET\_MC\_R\_SCRUB**\
 **USTR\_CNTL\_OPT\_SET\_MC\_R\_SCRUB**\
 **USTR\_CNTL\_OPT\_GET\_FMT**\
 **USTR\_CNTL\_OPT\_SET\_FMT**

**USTR\_POOL\_LL\_CNTL\_GET\_FREE\_CMP**\
 **USTR\_POOL\_LL\_CNTL\_SET\_FREE\_CMP**\
 **USTR\_POOL\_LL\_CNTL\_GET\_REALLOC**\
 **USTR\_POOL\_LL\_CNTL\_SET\_REALLOC**

## DESCRIPTION

## Compile switch constants

**Constant:**  USTR\_CONF\_INCLUDE\_CODEONLY\_HEADERS

**Explanation:**

  This switch controls whether all the code will be included as inline functions. Having this be non-zero means that you don't have to link against the library.

**Constant:**  USTR\_CONF\_USE\_EOS\_MARK

**Explanation:**

  This switch turns on End of String markers, so any bounds overflow will be noticed by ustr\_assert\_valid().

**Note:**

  Changing this will not do anything useful unless USTR\_CONF\_INCLUDE\_CODEONLY\_HEADERS is non-zero.

**Constant:**  USTR\_CONF\_USE\_ASSERT

**Explanation:**

  This switch turns USTR\_ASSERT() calls on, so the code within them will be evaluated. Note that there are many calls to ustr\_assert\_valid() within USTR\_ASSERT() macros and that call is relatively expensive.

**Note:**

  Changing this will not do anything useful unless USTR\_CONF\_INCLUDE\_CODEONLY\_HEADERS is non-zero.

**Constant:**  USTR\_CONF\_COMPILE\_USE\_ATTRIBUTES

**Explanation:**

  This switch controls whether gcc type \_\_attribute\_\_() statements are used in the public headers headers for the library. If the value is 1 then if they are supported by the compiler that built the library they will be used, if the value is 0 they won't be used at all.

**Constant:**  USTR\_CONF\_COMPILE\_TYPEDEF

**Explanation:**

  This switch controls whether typedef will be used for the structs in the public headers for the library. If the value is 1 then they will be used, if the value is 0 they won't be used at all (and your code will have to use struct tags instead -- note all libraries using ustr should compile without this option set).\
 **Constant:**  USTR\_CONF\_COMPILE\_USE\_INLINE

**Explanation:**

  This switch controls whether inline functions will be used in a few cases where the function bodies are very small.

**Note:**

  In some cases this is used so that GCC can eliminate calls to strlen(), for the \*\_cstr() functions.

## Constants to created fixed/read-only Ustr's

**Constant:**  USTR\_BEG\_CONST1

**Explanation:**

  This macro is a constant C-style string of the first byte of a constant/read-only Ustr that has a length in the range 0-255.

**Constant:**  USTR\_BEG\_CONST2

**Explanation:**

  This macro is a constant C-style string of the first byte of a constant/read-only Ustr that has a length in the range 0-65535.

**Constant:**  USTR\_BEG\_CONST4

**Explanation:**

  This macro is a constant C-style string of the first byte of a constant/read-only Ustr that has a length in the range 0-4294967295.

**Constant:**  USTR\_BEG\_FIXED1

**Explanation:**

  This macro is a constant C-style string of the first byte of a fixed Ustr that has a length in the range 0-255.

**Constant:**  USTR\_BEG\_FIXED2

**Explanation:**

  This macro is a constant C-style string of the first byte of a fixed Ustr that has a length in the range 0-65535.

**Constant:**  USTR\_BEG\_FIXED4

**Explanation:**

  This macro is a constant C-style string of the first byte of a fixed Ustr that has a length in the range 0-4294967295.

**Constant:**  USTR\_BEG\_FIXED8

**Explanation:**

  This macro is a constant C-style string of the first byte of a fixed Ustr that has a length in the range 0-18446744073709551615.

**Note:**

  This macro is only available if the Ustr code was compiled in a 64bit environment.

**Constant:**  USTR\_END\_ALOCDx

**Explanation:**

  This macro is a constant C-style string of the last bytes of an allocated Ustr.

**Note:**

  Unless USTR\_CONF\_USE\_EOS\_MARK is non-zero, this is just the NIL byte.

**Constant:**  USTR\_END\_CONSTx

**Explanation:**

  This macro is a constant C-style string of the last bytes of a constant/read-only Ustr.

**Note:**

  Unless USTR\_CONF\_USE\_EOS\_MARK is non-zero, this is just the NIL byte.

**Constant:**  USTR\_END\_FIXEDx

**Explanation:**

  This macro is a constant C-style string of the last bytes of a fixed Ustr.

**Note:**

  Unless USTR\_CONF\_USE\_EOS\_MARK is non-zero, this is just the NIL byte.

## Constants to use with parsing numbers: ustr\_parse\_uintmaxx, etc.

**Constant:**  USTR\_FLAG\_PARSE\_NUM\_DEF

**Explanation:**

  Default flags, this is merely 0 but can be used as live documentation.

**Constant:**  USTR\_FLAG\_PARSE\_NUM\_SEP

**Explanation:**

  This flag allows the parsing (and ignoring) of the separator character, at arbitrary pointers in the number, so "1234" and "1\_234" would both parse the same (assuming "\_" is the separator).

**Constant:**  USTR\_FLAG\_PARSE\_NUM\_OVERFLOW

**Explanation:**

  This flag turns on the overflow checking, in other words without it USTR\_TYPE\_PARSE\_NUM\_ERR\_OVERFLOW will never be returned as an error code.

**Constant:**  USTR\_FLAG\_PARSE\_NUM\_SPACE

**Explanation:**

  This flag allows one or more ' ' (Space) characters before the number or number prefix (Plus Sign, Hyphen).

**Note:**

  Other forms of whitespace don't count, this just affects ' '.

**Constant:**  USTR\_FLAG\_PARSE\_NUM\_NO\_BEG\_ZERO

**Explanation:**

  This flag disallows one or more '0' (Digit Zero) characters before the number.

**Constant:**  USTR\_FLAG\_PARSE\_NUM\_NO\_BEG\_PM

**Explanation:**

  This flag disallows a plus or a minus character before the number.

**Constant:**  USTR\_FLAG\_PARSE\_NUM\_NO\_NEGATIVE

**Explanation:**

  This flag disallows negative values.

**Constant:**  USTR\_FLAG\_PARSE\_NUM\_EXACT

**Explanation:**

  This flag makes the parsing functions return an error if the entire string doesn't contain the number being parsed.

**Constant:**  USTR\_TYPE\_PARSE\_NUM\_ERR\_NONE

**Explanation:**

  This error code has the value 0, and means that no error occurred parsing the number.

**Constant:**  USTR\_TYPE\_PARSE\_NUM\_ERR\_ONLY\_S

**Explanation:**

  This error code means that the Ustr string consisted only of spaces.

**Constant:**  USTR\_TYPE\_PARSE\_NUM\_ERR\_ONLY\_SPM

**Explanation:**

  This error code means that the Ustr string consisted only spaces, and a plus or minus sign.

**Constant:**  USTR\_TYPE\_PARSE\_NUM\_ERR\_ONLY\_SPMX

**Explanation:**

  This error code means that the Ustr string consisted of only spaces, a plus or minus sign and a "0x" base 16 prefix.\
 **Constant:**  USTR\_TYPE\_PARSE\_NUM\_ERR\_OOB

**Explanation:**

  This error code means that the Ustr string had characters in it that where out of bounds from the working base.

**Note:**

  Without the USTR\_FLAG\_PARSE\_NUM\_EXACT, this error is ignored as soon as any number is parsed.\
\
   This out of bounds includes the Ustr string "++" as well as "4A", when parsing in a base less than 11.

**Constant:**  USTR\_TYPE\_PARSE\_NUM\_ERR\_OVERFLOW

**Explanation:**

  This error code means that the number parsed from the Ustr string would overflow the type it is being parsed into, this is only returned when the USTR\_FLAG\_PARSE\_NUM\_OVERFLOW flag was passed to the parse function.

**Constant:**  USTR\_TYPE\_PARSE\_NUM\_ERR\_NEGATIVE

**Explanation:**

  This error code means that the number parsed from the Vstr string starts with a '-' (Hyphen) character when it is supposed to be an unsigned number.

**Constant:**  USTR\_TYPE\_PARSE\_NUM\_ERR\_BEG\_ZERO

**Explanation:**

  This error code means that the number parsed from the Vstr string starts with a '0' (Digit Zero) character, when the USTR\_FLAG\_PARSE\_NUM\_NO\_BEG\_ZERO flag was passed to the parse function.

## Constants to pass to ustr\_split\*

**Constant:**  USTR\_FLAG\_SPLIT\_DEF

**Explanation:**

  Default flags, this is merely 0 but can be used as live documentation.

**Constant:**  USTR\_FLAG\_SPLIT\_RET\_SEP

**Explanation:**

  Return the separator along with the tokens. For example splitting "a,b," using separator "," will return the tokens "a," and "b," whereas without this flag only "a" and "b" would be returned.\
\
     .br **Constant:**  USTR\_FLAG\_SPLIT\_RET\_NON

**Explanation:**

  Return empty tokens. For example: splitting "a,,b" with separator "," will return the tokens {"a" "" "b"}.\
 **Constant:**  USTR\_FLAG\_SPLIT\_KEEP\_CONFIG

**Explanation:**

  Force the returned Ustr's to have same configuration parameters as the Ustr string that is being split.

## Misc constants to use in code

**Constant:**  USTR\_NULL

**Explanation:**

  This macro is merely 0 cast to (struct Ustr \*), and can be used anywhere NULL would be but "returns" the correct type.

**Constant:**  USTR\_POOL\_NULL

**Explanation:**

  This macro is merely 0 cast to (struct Ustr\_pool \*), and can be used anywhere NULL would be but "returns" the correct type.

**Constant:**  USTR\_TRUE

**Explanation:**

  This macro is 1, but shows the intent that a boolean value is expected and not a number.

**Constant:**  USTR\_FALSE

**Explanation:**

  This macro is 0, but shows the intent that a boolean value is expected and not a number.

## Constants passed to ustr\_cntl\_opt()

**Constant:**  USTR\_CNTL\_OPT\_GET\_REF\_BYTES

Parameter**\[1\]**: Number of bytes for default reference count in Ustr\
 Type**\[1\]**: size\_t \*

**Explanation:**

  This option will get the default number of bytes used for a reference count when creating Ustr's.

**Constant:**  USTR\_CNTL\_OPT\_SET\_REF\_BYTES

Parameter**\[1\]**: Number of bytes for default reference count in Ustr\
 Type**\[1\]**: size\_t

**Explanation:**

  This option will set the default number of bytes used for a reference count when creating Ustr's.

**Note:**

  For a single instance, the ustr\_dupx\_\*() functions can be used.

**Constant:**  USTR\_CNTL\_OPT\_GET\_HAS\_SIZE

Parameter**\[1\]**: Default flag for whether to include an explicit size in a Ustr\
 Type**\[1\]**: int \*

**Explanation:**

  This option will get the default flag for whether to store an explicit size in created Ustr's.

**Constant:**  USTR\_CNTL\_OPT\_SET\_HAS\_SIZE

Parameter**\[1\]**: Default flag for whether to include an explicit size in a Ustr\
 Type**\[1\]**: int

**Explanation:**

  This option will set the default flag for whether to store an explicit size in created Ustr's.

**Note:**

  For a single instance, the ustr\_dupx\_\*() functions can be used.

**Constant:**  USTR\_CNTL\_OPT\_GET\_EXACT\_BYTES

Parameter**\[1\]**: Default flag for whether to exactly allocate memory\
 Type**\[1\]**: int \*

**Explanation:**

  This option will get the default flag for whether to exactly allocate memory when a Ustr needs to be resized.

**Constant:**  USTR\_CNTL\_OPT\_SET\_EXACT\_BYTES

Parameter**\[1\]**: Default flag for whether to exactly allocate memory\
 Type**\[1\]**: int

**Explanation:**

  This option will set the default flag for whether to exactly allocate memory when a Ustr needs to be resized.

**Note:**

  For a single instance, the ustr\_dupx\_\*() functions can be used.

**Constant:**  USTR\_CNTL\_OPT\_GET\_MEM\
 Parameter**\[1\]**: Pointer to colleciton of function pointers for system allocation\
 Type**\[1\]**: struct Ustr\_cntl\_mem \*

**Explanation:**

  This option will get the "system" allocation functions (malloc, realloc, free) for allocated Ustr's.

**Note:**

  As you would expect the default values are: malloc, realloc, free.

**Constant:**  USTR\_CNTL\_OPT\_SET\_MEM\
 Parameter**\[1\]**: Pointer to colleciton of function pointers for system allocation\
 Type**\[1\]**: const struct Ustr\_cntl\_mem \*

**Explanation:**

  This option will set the "system" allocation functions (malloc, realloc, free) for allocated Ustr's.

**Note:**

  If this option is set after a Ustr has been created, then when freeing or reallocating the existing Ustr the given functions will be used. So they must either be compatible with the default or you must ensure that nothing is allocated before they are set.

**Constant:**  USTR\_CNTL\_OPT\_GET\_MC\_M\_SCRUB

Parameter**\[1\]**: Flag for whether to include an explicit size in a Ustr\
 Type**\[1\]**: int \*

**Explanation:**

  This option will get the flag for whether to "scrub" data allocated via. malloc check.

**Note:**

  Malloc check has to be enabled for this to mean anything, Ie. USTR\_CNTL\_MALLOC\_LVL() must be positive.

**Constant:**  USTR\_CNTL\_OPT\_SET\_MC\_M\_SCRUB

Parameter**\[1\]**: Flag for whether to include an explicit size in a Ustr\
 Type**\[1\]**: int

**Explanation:**

  This option will set the flag for whether to "scrub" data allocated via. malloc check.

**Note:**

  Malloc check has to be enabled for this to mean anything, Ie. USTR\_CNTL\_MALLOC\_LVL() must be positive.

**Constant:**  USTR\_CNTL\_OPT\_GET\_MC\_F\_SCRUB

Parameter**\[1\]**: Flag for whether to include an explicit size in a Ustr\
 Type**\[1\]**: int \*

**Explanation:**

  This option will get the flag for whether to "scrub" data freed via. malloc check.

**Note:**

  Malloc check has to be enabled for this to mean anything, Ie. USTR\_CNTL\_MALLOC\_LVL() must be positive.

**Constant:**  USTR\_CNTL\_OPT\_SET\_MC\_F\_SCRUB

Parameter**\[1\]**: Flag for whether to include an explicit size in a Ustr\
 Type**\[1\]**: int

**Explanation:**

  This option will set the flag for whether to "scrub" data freed via. malloc check.

**Note:**

  Malloc check has to be enabled for this to mean anything, Ie. USTR\_CNTL\_MALLOC\_LVL() must be positive.

**Constant:**  USTR\_CNTL\_OPT\_GET\_MC\_R\_SCRUB

Parameter**\[1\]**: Flag for whether to include an explicit size in a Ustr\
 Type**\[1\]**: int \*

**Explanation:**

  This option will get the flag for whether to "scrub" data reallocated via. malloc check. This is done by turning all reallocations into a malloc() and free(), and so is even more costly than normal scrubbing.

**Note:**

  Malloc check has to be enabled for this to mean anything, Ie. USTR\_CNTL\_MALLOC\_LVL() must be positive.

**Constant:**  USTR\_CNTL\_OPT\_SET\_MC\_R\_SCRUB

Parameter**\[1\]**: Flag for whether to include an explicit size in a Ustr\
 Type**\[1\]**: int

**Explanation:**

  This option will set the flag for whether to "scrub" data reallocated via. malloc check. This is done by turning all reallocations into a malloc() and free(), and so is even more costly than normal scrubbing.

**Note:**

  Malloc check has to be enabled for this to mean anything, Ie. USTR\_CNTL\_MALLOC\_LVL() must be positive.

**Constant:**  USTR\_CNTL\_OPT\_GET\_FMT\
 Parameter**\[1\]**: Pointer to colleciton of function pointers for system formatting\
 Type**\[1\]**: struct Ustr\_cntl\_fmt \*

**Explanation:**

  This option will get the system formatting functions (vsnprintf) for Ustr's.\
\
   There are two functions, the first is always called and the second is likely called (always with the exact same arguments) if the length passed to the first call was not big enough.

**Note:**

  As you would expect the default values are: vsnprintf and vsnprintf

**Constant:**  USTR\_CNTL\_OPT\_SET\_FMT\
 Parameter**\[1\]**: Pointer to colleciton of function pointers for system formatting\
 Type**\[1\]**: const struct Ustr\_cntl\_fmt \*

**Explanation:**

  This option will set the system formatting functions (vsnprintf) for Ustr's.

## Constants passed to ustr\_pool\_ll\_cntl()

**Constant:**  USTR\_POOL\_LL\_CNTL\_GET\_FREE\_CMP

Parameter**\[1\]**: Number of pointers to compare to in the pool\
 Type**\[1\]**: unsigned int \*

**Explanation:**

  This option will get the number of comparisons done on a pool free operation.

**Constant:**  USTR\_POOL\_LL\_CNTL\_SET\_FREE\_CMP

Parameter**\[1\]**: Number of pointers to compare to in the pool\
 Type**\[1\]**: unsigned int

**Explanation:**

  This option will set the number of comparisons done on a pool free operation.

**Note:**

  The default is a small non-zero value, as it's significantly common to have very short lived ustr's ... however this doesn't mean that you can't forget to take references even with pool allocated ustrs.

**Constant:**  USTR\_POOL\_LL\_CNTL\_GET\_REALLOC

Parameter**\[1\]**: Flag for if we should call realloc()\
 Type**\[1\]**: int \*

**Explanation:**

  This option will get the flag for if we call realloc() to make data bigger, or revert to just allocating anew each time.

**Constant:**  USTR\_POOL\_LL\_CNTL\_SET\_REALLOC

Parameter**\[1\]**: Flag for if we should call realloc()\
 Type**\[1\]**: int

**Explanation:**

  This option will set the flag for if we call realloc() to make data bigger, or revert to just allocating anew each time.

**Note:**

  As with USTR\_POOL\_LL\_CNTL\_SET\_FREE\_CMP this option means you can't assume that pool allocated data is never freed until ustr\_pool\_free() is called, and again it is due to there being significant speed improvements for not making that assumption. Instead of disabling this option, just take areference (which will also make sure the ustr isn't modified behind your back).

## SEE ALSO

[**ustr**(3)](/ustr/3.md)
