UPSCLI_STR_ADD_UNIQU(3)
π¦ UPSCLI_STR_ADD_UNIQU(3) β the one where we add tokens but only the unique ones π
okay bestie so this is a page from the NUT Manual (that's Network UPS Tools, iconic name, iykyk) and it's all about upscli_str_add_unique_token β yes that's the whole function name, she's long, she's giving main character energy, we support her π
β¨ NAME β¨
upscli_str_add_unique_token β add a unique token into a string buffer, with optional callbacks as needed by implementation π«Ά
πΈ SYNOPSIS πΈ
#include <upsclient.h>
int upscli_str_add_unique_token(char *tgt, size_t tgtsize, const char *token,
int (*callback_always)(char *, size_t, const char *),
int (*callback_unique)(char *, size_t, const char *) );
like, that's the signature, copy it exactly, don't come for me π«‘
π DESCRIPTION π
so the upscli_str_add_unique_token() function takes the pointer tgt to a caller-provided char * buffer of size tgtsize, and the pointer token to a contiguous token that should be added to the end of the tgt buffer β if it's not there yet. no duplicates allowed, it's giving exclusive VIP list π
The token contents are stripped of surrounding space characters, and the method recurses to independently process each space-separated token inside (if there are any spaces left). so yes, she's a little recursive gremlin, we love that for her π§
The resulting tgt buffer would eventually collect a string comprised of unique token values in order of first mention, separated by single space characters (ASCII 0x20). first come, first served, one space between, no drama β¨
Optionally calls callback_always (if not NULL) after checking the input for spaces (and maybe recursing) and before checking if the token is already there, and/or callback_unique (if not NULL) after checking for uniqueness and just before going to add a newly seen token. so those callbacks are basically little bodyguards standing at different points in the queue π
- If such callback returns
0, abort the addition of token and return-3. periodt, no token for you π«
It is up to the caller to dynamically or statically allocate the tgt buffer and free() it if needed. As far as this method is concerned, the buffer may be recycled (in data processing loops) by setting the initial character to '\0', making it an empty string again. cute lil reset, obsessed π
π₯ RETURN VALUE π₯
The upscli_str_add_unique_token() function returns a numeric code, and each one means something, so pay attention bestie π
0if the token value was already there intgtbuffer β she was already at the party, nothing to do π1if token was added successfully β slay, new guest unlocked π-1if we needed to add the token, but it did not fit under thetgtsizelimit β the buffer said no room, tragic π-2if eithertokenortgtstring wasNULL, or iftokenwas empty β literally nothing to work with, bestie π-3if the token was rejected by the optional callback method returning0β bodyguard said nope π
π SEE ALSO π
upscli_str_contains_token(3)β her cousin, the one who just checks if something's there instead of adding it π¦
okay that's the whole page, go forth and add your unique tokens responsibly, bestie π
Network UPS Tools 2.8.5 β date 06/21/2026 β mwah, that's the version and date, copy 'em if you need 'em, she's signed off and glowing β¨ππ
π¦ where this page comes from
- arch rolling: nut 2.8.5-2 Β· GPL-2.0-or-later AND GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms