On 08/10/15 14:40, Ed Schouten wrote: > Hi Xin, > > 2015-08-10 23:31 GMT+02:00 Xin LI <delp...@freebsd.org>: >> + argp[0] = strdup(RCSDIFF); >> + argp[1] = strdup(filename); >> ... >> + free(argp[1]); >> + free(argp[0]); > >> + argp[0] = strdup(CHECKOUT); >> + argp[1] = strdup("-l"); >> + argp[2] = strdup(filename); >> ... >> + free(argp[2]); >> + free(argp[1]); >> + free(argp[0]); > > There's no need to call strdup() here, right? As far as I know, > execve() and posix_spawn() don't modify the arguments/environment. > These functions should use "const char *const *" as its argument type, > but that cannot be used, as it would cause compiler errors if "char > **" is passed in. > > See the table close to the bottom of this article: > > http://pubs.opengroup.org/onlinepubs/9699919799/functions/execve.html
Do you have a better solution for this? No, this is not ideal but I didn't find a better alternative (or maybe I have missed something obvious?) I think with the current POSIX definition of the interface, we have only two options: either strdup() or cast away const (I'd rather hide this kind of uglyness in the library), no? Cheers, -- Xin LI <delp...@delphij.net> https://www.delphij.net/ FreeBSD - The Power to Serve! Live free or die
signature.asc
Description: OpenPGP digital signature