On Thu, Jan 26, 2012, Jan Klemkow wrote:

> I miss some std libc functions in OpenBSD. So, I deside to implement a
> few of them by myself. This is a diff for getdelim(3) and getline(3).

it is too late for this release, I'd advise sending again once 5.1 is
released.

> At the moment this patch breaks the build, because some programs has
> there own getline() function. I do not know the best solution for this
> problem now. In my opinion you could rename the self-made functions
> to get the std libc function into the source tree. And then, replace
> some of them with the std libc functions. I think, you have to choose
> a decition individually for every case.

yes, a diff that at least renames all private functions should also be
submitted, separately, to make it possible to apply this.

> Index: getdelim.c

> +     if (lineptr == NULL || n == NULL) {
> +             errno = EINVAL;
> +             return -1;
> +     }

well, if the standard requires such checks, then ok.

> +
> +     /* the application has to ensure this, bus we check this here, too. */
> +     if (delim < 0)
> +             return -1;
> +
> +     if (fp == NULL)
> +             return -1;

but these should not be checked.  we do not typically check for
undefined behavior.

> +
> +                     *lineptr = realloc(*lineptr, *n);
> +
> +                     if (*lineptr == NULL) {
> +                             FUNLOCKFILE(fp);
> +                             errno = ENOMEM;
> +                             return -1;

the standard doesn't say what happens to the pointer if allocation
fails.  boo.  but i think leaking memory is bad.  free the original
pointer, then set *lineptr to NULL.

> +     *(*lineptr + (char) offset) = '\0';

that char cast cannot be correct.

Reply via email to