Hello Joro,
I think I spot another problem with your code. I discovered it when I tried
to use similar trick in my own code...
Georgi Kodinov wrote:
> #At file:///home/kgeorge/mysql/work/wl5366-5.5/ based on
> revid:georgi.kodinov@stripped
...
> +
> + do
> + {
> + rc= getpwnam_r(name, pwd_arg, buf, buf_size, &ret);
> +
> + if (rc == ERANGE)
> + {
> + /*
> + The buffer specified by the buffer and bufsize argu-
> + ments was insufficiently sized to store the result.
> + The caller should retry with a larger buffer.
> + */
> + buf= (char *) ((*to_free) ?
> + realloc(*to_free, buf_size * 2) :
> + malloc(buf_size * 2));
> +
> + if (!buf)
> + {
> + free(*to_free);
> + *to_free= NULL;
> + return NULL;
> + }
> +
> + *to_free= buf;
> + buf_size*= 2;
> + continue;
I think the intention here is that the loop will repeat, so that a call to
getpwnam_r() with a bigger buffer will be made again. But continue will move
to the end of the loop and terminate it, since condition is always false...
> + }
> + } while (0);
> +
> + if (rc)
> + {
> + free(to_free);
> + *to_free= NULL;
> + return NULL;
> + }
> +
> + return ret;
> +#else
> + return NULL;
> +#endif
> +}
Rafal