This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v2 2/5] Get rid of "gdb_dirbuf" and use "getcwd (NULL, 0)"
- From: Pedro Alves <palves at redhat dot com>
- To: Sergio Durigan Junior <sergiodj at redhat dot com>, GDB Patches <gdb-patches at sourceware dot org>
- Date: Wed, 20 Sep 2017 13:24:41 +0100
- Subject: Re: [PATCH v2 2/5] Get rid of "gdb_dirbuf" and use "getcwd (NULL, 0)"
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0F26581DFA
- References: <20170912042325.14927-1-sergiodj@redhat.com> <20170919042842.9210-1-sergiodj@redhat.com> <20170919042842.9210-3-sergiodj@redhat.com>
On 09/19/2017 05:28 AM, Sergio Durigan Junior wrote:
> Currently we have "current_directory" and "gdb_dirbuf" globals, which
> means that we basically have two possible places to consult when we
> want to know GDB's current working directory.
>
> This is not ideal and can lead to confusion. Moreover, the way we're
> using "gdb_difbuf" along with "getcwd" is problematic because we
> declare the buffer with "1024" elements hardcoded, which does not take
> into account longer pathnames that are possible in many filesystems.
> Using "PATH_MAX" would also not be a solution because of portability
> problems. Therefore, the best solution is to rely on the fact that
> "getcwd (NULL, 0)" will "do the right thing" and return a
> heap-allocated string containing the full path. With the new "getcwd"
> module from gnulib, it is now possible to do that without worrying
> about breaking some target.
s/target/host/
> --- a/gdb/cli/cli-cmds.c
> +++ b/gdb/cli/cli-cmds.c
> @@ -382,13 +382,16 @@ pwd_command (char *args, int from_tty)
> {
> if (args)
> error (_("The \"pwd\" command does not take an argument: %s"), args);
> - if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
> +
> + gdb::unique_xmalloc_ptr<char> cwd (getcwd (NULL, 0));
> +
> + if (cwd.get () == NULL)
No need for get() here:
if (cwd == NULL)
> diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c
> index 977b6e274d..1e4c09352f 100644
> --- a/gdb/mi/mi-cmd-env.c
> +++ b/gdb/mi/mi-cmd-env.c
> @@ -73,12 +73,12 @@ mi_cmd_env_pwd (const char *command, char **argv, int argc)
> }
>
> /* Otherwise the mi level is 2 or higher. */
> -
> - if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
> + gdb::unique_xmalloc_ptr<char> cwd (getcwd (NULL, 0));
> + if (cwd.get () == NULL)
Ditto.
Otherwise OK.
Thanks,
Pedro Alves