On Sat, Nov 9, 2024 at 12:52 PM Hans de Goede <hdegoede@xxxxxxxxxx> wrote: > On 9-Nov-24 5:30 AM, Andy Shevchenko wrote: > > On Sat, Nov 9, 2024 at 1:24 AM Hans de Goede <hdegoede@xxxxxxxxxx> wrote: ... > >> +static void power_supply_escape_spaces(const char *str, char *buf, size_t bufsize) > >> +{ > >> + strscpy(buf, str, bufsize); > >> + strreplace(buf, ' ', '_'); > >> +} > > > > The bufsize in all cases here is sizeof(buf), making the above to be a > > macro we may switch to 2-argument strscpy(). FTR, it embeds the check > > that buf is an array. > > I did think about this already, but using a macro makes this harder > to read just to save 2 sizeof() calls. So I prefer doing things > this way. ... > >> + char escaped_label[32]; > > > > Even more, the but size seems also the same, can we have buf defined > > inside the above? > > No not really, its address would need to be returned then, requiring > it to be static, at which point we get race conditions when multiple > threads use the same function at the same time. I meant a macro case, but it's not a big deal after all. Perhaps we can evolve a macro in the generic headers if there are enough users, like #define str_copy_and_replace(...) ... -- With Best Regards, Andy Shevchenko