On Sat, 2015-01-31 at 00:39 +0100, Rasmus Villemoes wrote: > On Fri, Jan 30 2015, Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote: > >> >> * Return: > >> >> - * The amount of the characters processed to the destination buffer, or > >> >> - * %-ENOMEM if the size of buffer is not enough to put an escaped character is > >> >> - * returned. > >> >> - * > >> >> - * Even in the case of error @dst pointer will be updated to point to the byte > >> >> - * after the last processed character. > >> >> + * The total size of the escaped output that would be generated for > >> >> + * the given input and flags. To check whether the output was > >> >> + * truncated, compare the return value to osz. There is room left in > >> >> + * dst for a '\0' terminator if and only if ret < osz. > >> >> */ > >> >> -int string_escape_mem(const char *src, size_t isz, char **dst, size_t osz, > >> >> - unsigned int flags, const char *esc) > >> >> +size_t string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, > >> >> + unsigned int flags, const char *esc) > >> > > >> > I prefer to leave the prototype the same. int for return is okay. dst > >> > should be updated accordingly. > >> > >> Please explain exactly what you think the return value should be, and > >> what *dst should be set to. > > > > Return value like you proposed, *dst is incremented by it. > > The more I think about it, the less I like having dst being char**. > > (1) It is unlike most other functions taking buffer+size arguments. > (2) It is inconvenient. Callers doing > > char escaped[SOME_SIZE]; > > or > > char *escaped = kmalloc(likely_big_enough); > > can't just pass &escaped; they would need to use an extra dummy variable. > > (3) With the return value telling the size of the would-be generated > output, it is redundant. > > In fact, I dislike it so much that I'm not going to sign off on a patch > where dst is still char**. Fair enough, though there usual case when temporary variable is already present (at least current users). Let's proceed with char *dst. -- Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> Intel Finland Oy -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html