bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: Re: [PATCH] tmpdir.c (path_search_alloc): New function.
Date: Sun, 13 Sep 2020 13:12:28 +0200	[thread overview]
Message-ID: <3111347.7ZDk9rG9Yt@omega> (raw)
In-Reply-To: <20200913093334.17844-1-john@darrington.wattle.id.au>

Hi John,

As this is your first major contribution to Gnulib, can you please make sure
you have signed a copyright assignment with the FSF regarding 'GNULIB'?

> * lib/tmpdir.c (path_search_alloc): Define new function similar to
> path_search,  but which allocates the buffer for the result instead
> of relying on the caller to preallocate it.

This is a good idea, because it gets rid of an EINVAL error return.

> +/* Like path_search, except that TMPL is allocated automatically.
> +   TMPL may not be null.  *TMPL must be freed by the caller, when no longer needed.
> +   After calling this function *TMPL_LEN will be set to the lenght of *TMPL.  */
> +extern int path_search_alloc (char **tmpl, size_t *tmpl_len, const char *dir, const char *pfx,
> +                       bool try_tmpdir);

The calling convention is odd: If the caller is only meant to use *TMPL and
later free() it, why does he need *TMPL_LEN? It seems redundant to return it
from this function. And then, if *TMPL is the only output (besides the error
condition), why not make it the return value? That is:

  extern char * path_search_alloc (const char *dir, const char *pfx, bool try_tmpdir);

In case of error, this function would return NULL with errno set.

Indentation: Please make the second arglist line align better.

Typo: s/lenght/length/

> +static int
> +__path_search (char *tmpl, const char **dirx, const char *pfx, bool try_tmpdir)
> ...
> +static void
> +__impute_lengths (const char *pfx, const char *dir, size_t *plen, size_t *dlen, bool *add_slash)

Please don't choose function names that start with underscore. These function
names are in the scope of the vendor libc. And in fact, such function names
would make merging with glibc harder, since glibc already has a function
'__path_search' (defined in sysdeps/posix/tempname.c).

Also, __path_search is a misnomer now: it does not search anything; it
determines the temporary directory in which to place a temporary file.

Bruno



  reply	other threads:[~2020-09-13 11:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-13  9:33 [PATCH] tmpdir.c (path_search_alloc): New function John Darrington
2020-09-13 11:12 ` Bruno Haible [this message]
2020-09-13 12:11   ` John Darrington
2020-09-13 14:07     ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3111347.7ZDk9rG9Yt@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).