Re: Better alternative to strncpy in QEMU.

2021-04-13 Thread Paolo Bonzini
On 12/04/21 06:51, Thomas Huth wrote: I think this is pretty much the same as g_strlcpy() from the glib: https://developer.gnome.org/glib/2.66/glib-String-Utility-Functions.html#g-strlcpy So I guess Paolo had something different in mind when adding this task? Yes, I did. strncpy is used

Re: Better alternative to strncpy in QEMU.

2021-04-12 Thread Chetan
Hello All, > I'm not sure what's the improvement over strncpy() here? Paolo, could you > elaborate? > (Note that we also have some functions like strpadcpy() in QEMU already, > which can be used in similar ways) Ok Thanks, I'll wait for Paolo to clarify if the functions are needed, if yes then wh

Re: Better alternative to strncpy in QEMU.

2021-04-12 Thread Peter Maydell
On Sun, 11 Apr 2021 at 14:52, Chetan wrote: > char *qemu_strncpy(char destination[], char source[], size_t destination_size) > { > /* Looping through the array and copying the characters from > * source to destination. > */ > for (int i = 0; i < strlen(source); i++) { > d

RE: Better alternative to strncpy in QEMU.

2021-04-12 Thread Bruno Piazera Larsen
Im not sure about what "better version" means, but my guess would be a faster or more reliable version. If that's the case: > for (int i = 0; i < strlen(source); i++) { Since you're going on ebyte at a time, there's no need to know how big the array is. As a stopping condition you could use

Re: Better alternative to strncpy in QEMU.

2021-04-11 Thread Thomas Huth
On 11/04/2021 15.50, Chetan wrote: Hello All, This mail is in reference to one of the tasks mentioned in '/Contribute/BiteSizedTasks/' in QEMU wiki, under '/API conversion/' which states to introduce a better alternative to strncpy function. Looks like this task has been added by Paolo, so I

Better alternative to strncpy in QEMU.

2021-04-11 Thread Chetan
Hello All, This mail is in reference to one of the tasks mentioned in ' *Contribute/BiteSizedTasks*' in QEMU wiki, under '*API conversion*' which states to introduce a better alternative to strncpy function. I've drafted and tested below implementation for the same. Before proceeding with any chan