[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Does gnulib getcwd always allocate if buf is NULL?
From: |
Paul Smith |
Subject: |
Re: Does gnulib getcwd always allocate if buf is NULL? |
Date: |
Wed, 06 Mar 2024 14:09:06 -0500 |
User-agent: |
Evolution 3.50.4 (by Flathub.org) |
On Wed, 2024-03-06 at 19:55 +0100, Reuben Thomas wrote:
> In getcwd.c I find the following comment:
>
> > In GNU, if BUF is NULL, an array is allocated with 'malloc'; the
> > array is SIZE bytes long, unless SIZE == 0, in which case it is as
> > big as necessary.
>
> However, as far as I can see from the code, it always allocates if
> BUF is NULL.
I don't think your observation contradicts the comment...is there more
to it?
Note the use of a semicolon here which means that the second clause is
"separate from" the first clause; this could be rewritten as something
like:
In GNU, if BUF is NULL, an array is allocated with 'malloc'.
If allocated, the allocated array is SIZE bytes long, unless SIZE ==
0, in which case it is as big as necessary.