UPSCLI_SPLITNAME(3)

✨ UPSCLI_SPLITNAME ✨

okay bestie, pull up a chair πŸ’– this is upscli_splitname(3), straight outta the NUT Manual (that's Network UPS Tools, not the other kind of nut, i promise 😭). it's a lil C function that takes one messy UPS string and deconstructs it into its gorgeous little component parts. it's giving chemistry class but make it networking πŸ§ͺ✨


🌸 NAME 🌸

upscli_splitname β€” split a UPS definition into its components πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <upsclient.h>

int upscli_splitname(const char *buf, char **upsname,
        char **hostname, int *port)

like, look at her. four params. she's simple. she's iconic. she's not here to play πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• β€” upscli_splitname() takes a pointer to the raw UPS definition in buf, and hands you back pointers to dynamically allocated memory in upsname and hostname. it also copies the port number right into port. that's it. that's the whole job. no cap 🫢


🌈 FORMATTING 🌈

an UPS definition gets written according to this format, and yes it's giving choose-your-own-adventure:

<upsname>[@<hostname>[:<port>]]

so like, brackets inside brackets. very nesting-coded. very russian-doll of her πŸͺ†

now the important part: when the UPS name is not given, this function will print an error to stderr and return -1 without changing anything. no half-finished vibes, no partial glow-up. she just refuses πŸ’€

definitions that don't have an explicit port value get the default value of 3493. and the default hostname is "localhost". the defaults ate, honestly πŸ“


πŸ’œ MEMORY USAGE πŸ’œ

you must free(3) the pointers to upsname and hostname when you're done with them, or you're gonna leak memory and that's not the vibe. clean up after yourself, bestie 🧹✨


πŸ”₯ RETURN VALUE πŸ”₯

  • 0 β€” slayed, success, everything worked πŸ’…
  • -1 β€” something went wrong, an error occurred 😭

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, babe 🫢 this was Network UPS Tools 2.8.5, dated 10/07/2026, and honestly? she served. go forth and split some names πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from