bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read-file


From: Paul Eggert
Subject: Re: read-file
Date: Fri, 16 Jun 2006 11:18:57 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Simon Josefsson <address@hidden> writes:

> +  if (buf)
> +    buf[size] = '\0';

The file reading code returns NULL if the file was empty?  But the
comments makes it sound like it will return xstrdup (""), and that
would be more consistent.  You might also add a test case, to read
from /dev/null.

> +  if (out)
> +    rc = fclose (stream);
> +  else
> +    {
> +      /* On failure, preserve the original errno value. */
> +      int save_errno = errno;
> +      rc = fclose (stream);
> +      errno = save_errno;
> +    }
> +
> +  if (rc != 0)
> +    {
> +      int save_errno = errno;
> +      free (out);
> +      errno = save_errno;
> +      return NULL;
> +    }

The following replacement code is a bit clearer, at least to my eyes:

  save_errno = errno;

  if (fclose (stream) != 0)
    {
      if (out)
        {
          save_errno = errno;
          free (out);
        }
      errno = save_errno;
      return NULL;
    }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]